diff --git a/ProjectGarage/Forms/FormDriver.Designer.cs b/ProjectGarage/Forms/FormDriver.Designer.cs index a7d58d5..9415591 100644 --- a/ProjectGarage/Forms/FormDriver.Designer.cs +++ b/ProjectGarage/Forms/FormDriver.Designer.cs @@ -35,9 +35,9 @@ textBoxPhoneNum = new TextBox(); labelPhoneNum = new Label(); labelTruckID = new Label(); - textBoxTruckID = new TextBox(); buttonSaveDriver = new Button(); buttonCancelDriver = new Button(); + comboBoxTruckID = new ComboBox(); SuspendLayout(); // // labelFirstName @@ -98,13 +98,6 @@ labelTruckID.TabIndex = 6; labelTruckID.Text = "Фура"; // - // textBoxTruckID - // - textBoxTruckID.Location = new Point(120, 164); - textBoxTruckID.Name = "textBoxTruckID"; - textBoxTruckID.Size = new Size(183, 27); - textBoxTruckID.TabIndex = 7; - // // buttonSaveDriver // buttonSaveDriver.Location = new Point(20, 231); @@ -123,14 +116,22 @@ buttonCancelDriver.Text = "Отмена"; buttonCancelDriver.UseVisualStyleBackColor = true; // + // comboBoxTruckID + // + comboBoxTruckID.FormattingEnabled = true; + comboBoxTruckID.Location = new Point(120, 156); + comboBoxTruckID.Name = "comboBoxTruckID"; + comboBoxTruckID.Size = new Size(151, 28); + comboBoxTruckID.TabIndex = 10; + // // FormDriver // AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; ClientSize = new Size(333, 302); + Controls.Add(comboBoxTruckID); Controls.Add(buttonCancelDriver); Controls.Add(buttonSaveDriver); - Controls.Add(textBoxTruckID); Controls.Add(labelTruckID); Controls.Add(textBoxPhoneNum); Controls.Add(labelPhoneNum); @@ -154,8 +155,8 @@ private TextBox textBoxPhoneNum; private Label labelPhoneNum; private Label labelTruckID; - private TextBox textBoxTruckID; private Button buttonSaveDriver; private Button buttonCancelDriver; + private ComboBox comboBoxTruckID; } } \ No newline at end of file diff --git a/ProjectGarage/Forms/FormTruck.Designer.cs b/ProjectGarage/Forms/FormTruck.Designer.cs index 44a7dd9..c9c2210 100644 --- a/ProjectGarage/Forms/FormTruck.Designer.cs +++ b/ProjectGarage/Forms/FormTruck.Designer.cs @@ -101,9 +101,11 @@ // numericUpDownMaxFuel // numericUpDownMaxFuel.Location = new Point(158, 156); + numericUpDownMaxFuel.Minimum = new decimal(new int[] { 1, 0, 0, 0 }); numericUpDownMaxFuel.Name = "numericUpDownMaxFuel"; numericUpDownMaxFuel.Size = new Size(117, 27); numericUpDownMaxFuel.TabIndex = 15; + numericUpDownMaxFuel.Value = new decimal(new int[] { 1, 0, 0, 0 }); // // buttonTruckSave // @@ -113,7 +115,7 @@ buttonTruckSave.TabIndex = 16; buttonTruckSave.Text = "Сохранить"; buttonTruckSave.UseVisualStyleBackColor = true; - buttonTruckSave.Click += buttonTruckSave_Click; + buttonTruckSave.Click += ButtonTruckSave_Click; // // buttonTruckCancel // @@ -123,7 +125,7 @@ buttonTruckCancel.TabIndex = 17; buttonTruckCancel.Text = "Отмена"; buttonTruckCancel.UseVisualStyleBackColor = true; - buttonTruckCancel.Click += buttonTruckCancel_Click; + buttonTruckCancel.Click += ButtonTruckCancel_Click; // // FormTruck // diff --git a/ProjectGarage/Forms/FormTruck.cs b/ProjectGarage/Forms/FormTruck.cs index d94dff7..8fb0c4b 100644 --- a/ProjectGarage/Forms/FormTruck.cs +++ b/ProjectGarage/Forms/FormTruck.cs @@ -1,4 +1,5 @@ -using ProjectGarage.Repositories; +using ProjectGarage.Entities; +using ProjectGarage.Repositories; using System; using System.Collections.Generic; using System.ComponentModel; @@ -48,14 +49,36 @@ namespace ProjectGarage.Forms throw new ArgumentNullException(nameof(truckRepository)); } - private void buttonTruckSave_Click(object sender, EventArgs e) + private void ButtonTruckSave_Click(object sender, EventArgs e) { - + try + { + if (string.IsNullOrWhiteSpace(textBoxTruckNumbers.Text) + || string.IsNullOrWhiteSpace(textBoxTruckBrand.Text) + || string.IsNullOrWhiteSpace(textBoxTruckModel.Text)) + { + throw new Exception("Имеются незаполненные поля"); + } + if (_truckId.HasValue) + { + _truckRepository.UpdateTruck(CreateTruck(_truckId.Value)); + } + else + { + _truckRepository.CreateTruck(CreateTruck(0)); + } + Close(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } } - private void buttonTruckCancel_Click(object sender, EventArgs e) - { + private void ButtonTruckCancel_Click(object sender, EventArgs e) => Close(); - } + private Truck CreateTruck(int id) => Truck.CreateTruck(id, textBoxTruckNumbers.Text, + textBoxTruckBrand.Text, textBoxTruckModel.Text, Convert.ToInt32(numericUpDownMaxFuel.Value)); } + } diff --git a/ProjectGarage/Forms/FormTrucks.Designer.cs b/ProjectGarage/Forms/FormTrucks.Designer.cs new file mode 100644 index 0000000..8652fc6 --- /dev/null +++ b/ProjectGarage/Forms/FormTrucks.Designer.cs @@ -0,0 +1,126 @@ +namespace ProjectGarage.Forms +{ + partial class FormTrucks + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + panelFormTrucksButtons = new Panel(); + buttonUpdateTruck = new Button(); + buttonDeleteTruck = new Button(); + buttonAddTruck = new Button(); + dataGridViewTrucks = new DataGridView(); + panelFormTrucksButtons.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridViewTrucks).BeginInit(); + SuspendLayout(); + // + // panelFormTrucksButtons + // + panelFormTrucksButtons.Controls.Add(buttonUpdateTruck); + panelFormTrucksButtons.Controls.Add(buttonDeleteTruck); + panelFormTrucksButtons.Controls.Add(buttonAddTruck); + panelFormTrucksButtons.Dock = DockStyle.Right; + panelFormTrucksButtons.Location = new Point(441, 0); + panelFormTrucksButtons.Name = "panelFormTrucksButtons"; + panelFormTrucksButtons.Size = new Size(161, 360); + panelFormTrucksButtons.TabIndex = 0; + // + // buttonUpdateTruck + // + buttonUpdateTruck.BackgroundImage = Properties.Resources.каранд; + buttonUpdateTruck.BackgroundImageLayout = ImageLayout.Stretch; + buttonUpdateTruck.Location = new Point(35, 140); + buttonUpdateTruck.Name = "buttonUpdateTruck"; + buttonUpdateTruck.Size = new Size(94, 75); + buttonUpdateTruck.TabIndex = 2; + buttonUpdateTruck.UseVisualStyleBackColor = true; + buttonUpdateTruck.Click += ButtonUpdateTruck_Click; + // + // buttonDeleteTruck + // + buttonDeleteTruck.BackgroundImage = Properties.Resources.минусик; + buttonDeleteTruck.BackgroundImageLayout = ImageLayout.Stretch; + buttonDeleteTruck.Location = new Point(35, 247); + buttonDeleteTruck.Name = "buttonDeleteTruck"; + buttonDeleteTruck.Size = new Size(94, 78); + buttonDeleteTruck.TabIndex = 1; + buttonDeleteTruck.UseVisualStyleBackColor = true; + buttonDeleteTruck.Click += ButtonDeleteTruck_Click; + // + // buttonAddTruck + // + buttonAddTruck.BackgroundImage = Properties.Resources.плюсик; + buttonAddTruck.BackgroundImageLayout = ImageLayout.Stretch; + buttonAddTruck.Location = new Point(35, 23); + buttonAddTruck.Name = "buttonAddTruck"; + buttonAddTruck.Size = new Size(94, 75); + buttonAddTruck.TabIndex = 0; + buttonAddTruck.UseVisualStyleBackColor = true; + buttonAddTruck.Click += ButtonAddTruck_Click; + // + // dataGridViewTrucks + // + dataGridViewTrucks.AllowUserToAddRows = false; + dataGridViewTrucks.AllowUserToDeleteRows = false; + dataGridViewTrucks.AllowUserToResizeColumns = false; + dataGridViewTrucks.AllowUserToResizeRows = false; + dataGridViewTrucks.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridViewTrucks.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridViewTrucks.Dock = DockStyle.Fill; + dataGridViewTrucks.Location = new Point(0, 0); + dataGridViewTrucks.Name = "dataGridViewTrucks"; + dataGridViewTrucks.ReadOnly = true; + dataGridViewTrucks.RowHeadersVisible = false; + dataGridViewTrucks.RowHeadersWidth = 51; + dataGridViewTrucks.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridViewTrucks.Size = new Size(441, 360); + dataGridViewTrucks.TabIndex = 1; + // + // FormTrucks + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(602, 360); + Controls.Add(dataGridViewTrucks); + Controls.Add(panelFormTrucksButtons); + Name = "FormTrucks"; + StartPosition = FormStartPosition.CenterParent; + Text = "Фуры"; + Load += FormTrucks_Load; + panelFormTrucksButtons.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridViewTrucks).EndInit(); + ResumeLayout(false); + } + + #endregion + + private Panel panelFormTrucksButtons; + private Button buttonUpdateTruck; + private Button buttonDeleteTruck; + private Button buttonAddTruck; + private DataGridView dataGridViewTrucks; + } +} \ No newline at end of file diff --git a/ProjectGarage/Forms/FormTrucks.cs b/ProjectGarage/Forms/FormTrucks.cs new file mode 100644 index 0000000..e676c39 --- /dev/null +++ b/ProjectGarage/Forms/FormTrucks.cs @@ -0,0 +1,110 @@ +using ProjectGarage.Repositories; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using Unity; + +namespace ProjectGarage.Forms +{ + public partial class FormTrucks : Form + { + private readonly IUnityContainer _container; + + private readonly ITruckRepository _truckRepository; + + public FormTrucks(IUnityContainer container, ITruckRepository truckRepository) + { + InitializeComponent(); + _container = container ?? throw new ArgumentNullException(nameof(container)); + _truckRepository = truckRepository ?? throw new ArgumentNullException(nameof(truckRepository)); + } + private void FormTrucks_Load(object sender, EventArgs e) + { + try + { + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при закгрузке", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonAddTruck_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при добавлении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonDeleteTruck_Click(object sender, EventArgs e) + { + if (!TryGetIDFromSelectedRow(out var findid)) + { + return; + } + + if (MessageBox.Show("Удалить звпись?", "Удаление", MessageBoxButtons.YesNo) != DialogResult.Yes) + { + return; + } + + try + { + _truckRepository.DeleteTruck(findid); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при удалении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonUpdateTruck_Click(object sender, EventArgs e) + { + if (!TryGetIDFromSelectedRow(out var findid)) + { + return; + } + + try + { + var form = _container.Resolve(); + form.Id = findid; + form.ShowDialog(); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при изменении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void LoadList() => dataGridViewTrucks.DataSource = _truckRepository.ReadTrucks(); + + private bool TryGetIDFromSelectedRow(out int id) + { + id = 0; + if (dataGridViewTrucks.SelectedRows.Count < 1) + { + MessageBox.Show("Нет выбранной записи", "Ошибка", MessageBoxButtons.OK,MessageBoxIcon.Error); + return false; + } + + id = Convert.ToInt32(dataGridViewTrucks.SelectedRows[0].Cells["Id"].Value); + return true; + } + } +} diff --git a/ProjectGarage/Forms/FormTrucks.resx b/ProjectGarage/Forms/FormTrucks.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectGarage/Forms/FormTrucks.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/ProjectGarage/Properties/Resources.Designer.cs b/ProjectGarage/Properties/Resources.Designer.cs index 218e866..b9facb9 100644 --- a/ProjectGarage/Properties/Resources.Designer.cs +++ b/ProjectGarage/Properties/Resources.Designer.cs @@ -59,5 +59,35 @@ namespace ProjectGarage.Properties { resourceCulture = value; } } + + /// + /// Поиск локализованного ресурса типа System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap каранд { + get { + object obj = ResourceManager.GetObject("каранд", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Поиск локализованного ресурса типа System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap минусик { + get { + object obj = ResourceManager.GetObject("минусик", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Поиск локализованного ресурса типа System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap плюсик { + get { + object obj = ResourceManager.GetObject("плюсик", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } } } diff --git a/ProjectGarage/Properties/Resources.resx b/ProjectGarage/Properties/Resources.resx index 1af7de1..cc9719f 100644 --- a/ProjectGarage/Properties/Resources.resx +++ b/ProjectGarage/Properties/Resources.resx @@ -117,4 +117,14 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + ..\Resources\минусик.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\плюсик.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\каранд.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + \ No newline at end of file diff --git a/ProjectGarage/Repositories/ITransportationRepository.cs b/ProjectGarage/Repositories/ITransportationRepository.cs index 9d0a407..1e4c578 100644 --- a/ProjectGarage/Repositories/ITransportationRepository.cs +++ b/ProjectGarage/Repositories/ITransportationRepository.cs @@ -12,4 +12,6 @@ public interface ITransportationRepository IEnumerable ReadTransportation(DateTime? dateForm = null, DateTime? dateTo = null, int? fuelId = null, int? driverId = null, int? routeId = null); void CreateTransportation(Transportation transportation); + + void DeleteTransportation(int id); } diff --git a/ProjectGarage/Resources/каранд.jpg b/ProjectGarage/Resources/каранд.jpg new file mode 100644 index 0000000..b6a25ca Binary files /dev/null and b/ProjectGarage/Resources/каранд.jpg differ diff --git a/ProjectGarage/Resources/минусик.jpg b/ProjectGarage/Resources/минусик.jpg new file mode 100644 index 0000000..469909f Binary files /dev/null and b/ProjectGarage/Resources/минусик.jpg differ diff --git a/ProjectGarage/Resources/плюсик.jpg b/ProjectGarage/Resources/плюсик.jpg new file mode 100644 index 0000000..801481b Binary files /dev/null and b/ProjectGarage/Resources/плюсик.jpg differ diff --git a/каранд.jpg b/каранд.jpg new file mode 100644 index 0000000..b6a25ca Binary files /dev/null and b/каранд.jpg differ diff --git a/минусик.jpg b/минусик.jpg new file mode 100644 index 0000000..469909f Binary files /dev/null and b/минусик.jpg differ diff --git a/плюсик.jpg b/плюсик.jpg new file mode 100644 index 0000000..801481b Binary files /dev/null and b/плюсик.jpg differ