From 123401c6193e961591bbae6092b246f9337e985d Mon Sep 17 00:00:00 2001 From: F1rsTTeaM Date: Sun, 17 Nov 2024 16:16:03 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D1=84=D0=BE=D1=80=D0=BC=D1=8B=20=D1=82=D0=BE=D0=BF?= =?UTF-8?q?=D0=BB=D0=B8=D0=B2=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Forms/FormCar.Designer.cs | 42 ++--- .../Forms/FormFuel.Designer.cs | 151 ++++++++++++++++++ .../FuelAndLubricants/Forms/FormFuel.cs | 72 +++++++++ .../FuelAndLubricants/Forms/FormFuel.resx | 120 ++++++++++++++ .../Repositories/IFuelRepository.cs | 2 +- 5 files changed, 366 insertions(+), 21 deletions(-) create mode 100644 FuelAndLubricants/FuelAndLubricants/Forms/FormFuel.Designer.cs create mode 100644 FuelAndLubricants/FuelAndLubricants/Forms/FormFuel.cs create mode 100644 FuelAndLubricants/FuelAndLubricants/Forms/FormFuel.resx diff --git a/FuelAndLubricants/FuelAndLubricants/Forms/FormCar.Designer.cs b/FuelAndLubricants/FuelAndLubricants/Forms/FormCar.Designer.cs index d41e33e..aea1ce5 100644 --- a/FuelAndLubricants/FuelAndLubricants/Forms/FormCar.Designer.cs +++ b/FuelAndLubricants/FuelAndLubricants/Forms/FormCar.Designer.cs @@ -29,8 +29,8 @@ private void InitializeComponent() { checkedListBoxDriverLicense = new CheckedListBox(); - buttonDriverCancel = new Button(); - buttonDriverSave = new Button(); + buttonCancel = new Button(); + buttonCarSave = new Button(); label3 = new Label(); textBoxCarModel = new TextBox(); label2 = new Label(); @@ -51,23 +51,25 @@ checkedListBoxDriverLicense.Size = new Size(140, 94); checkedListBoxDriverLicense.TabIndex = 17; // - // buttonDriverCancel + // buttonCancel // - buttonDriverCancel.Location = new Point(172, 232); - buttonDriverCancel.Name = "buttonDriverCancel"; - buttonDriverCancel.Size = new Size(75, 23); - buttonDriverCancel.TabIndex = 16; - buttonDriverCancel.Text = "Отмена"; - buttonDriverCancel.UseVisualStyleBackColor = true; + buttonCancel.Location = new Point(172, 232); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(75, 23); + buttonCancel.TabIndex = 16; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; // - // buttonDriverSave + // buttonCarSave // - buttonDriverSave.Location = new Point(9, 232); - buttonDriverSave.Name = "buttonDriverSave"; - buttonDriverSave.Size = new Size(75, 23); - buttonDriverSave.TabIndex = 15; - buttonDriverSave.Text = "Сохранить"; - buttonDriverSave.UseVisualStyleBackColor = true; + buttonCarSave.Location = new Point(9, 232); + buttonCarSave.Name = "buttonCarSave"; + buttonCarSave.Size = new Size(75, 23); + buttonCarSave.TabIndex = 15; + buttonCarSave.Text = "Сохранить"; + buttonCarSave.UseVisualStyleBackColor = true; + buttonCarSave.Click += ButtonCarSave_Click; // // label3 // @@ -157,8 +159,8 @@ Controls.Add(label4); Controls.Add(comboBoxCarType); Controls.Add(checkedListBoxDriverLicense); - Controls.Add(buttonDriverCancel); - Controls.Add(buttonDriverSave); + Controls.Add(buttonCancel); + Controls.Add(buttonCarSave); Controls.Add(label3); Controls.Add(textBoxCarModel); Controls.Add(label2); @@ -174,8 +176,8 @@ #endregion private CheckedListBox checkedListBoxDriverLicense; - private Button buttonDriverCancel; - private Button buttonDriverSave; + private Button buttonCancel; + private Button buttonCarSave; private Label label3; private TextBox textBoxCarModel; private Label label2; diff --git a/FuelAndLubricants/FuelAndLubricants/Forms/FormFuel.Designer.cs b/FuelAndLubricants/FuelAndLubricants/Forms/FormFuel.Designer.cs new file mode 100644 index 0000000..534b377 --- /dev/null +++ b/FuelAndLubricants/FuelAndLubricants/Forms/FormFuel.Designer.cs @@ -0,0 +1,151 @@ +namespace FuelAndLubricants.Forms +{ + partial class FormFuel + { + /// + /// 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() + { + label5 = new Label(); + numericUpDownPrice = new NumericUpDown(); + buttonCancel = new Button(); + buttonFuelSave = new Button(); + label1 = new Label(); + comboBoxFuelType = new ComboBox(); + label2 = new Label(); + numericUpDownAmount = new NumericUpDown(); + ((System.ComponentModel.ISupportInitialize)numericUpDownPrice).BeginInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownAmount).BeginInit(); + SuspendLayout(); + // + // label5 + // + label5.AutoSize = true; + label5.Location = new Point(7, 40); + label5.Name = "label5"; + label5.Size = new Size(78, 15); + label5.TabIndex = 33; + label5.Text = "Цена за литр"; + // + // numericUpDownPrice + // + numericUpDownPrice.DecimalPlaces = 2; + numericUpDownPrice.Location = new Point(105, 38); + numericUpDownPrice.Minimum = new decimal(new int[] { 1, 0, 0, 131072 }); + numericUpDownPrice.Name = "numericUpDownPrice"; + numericUpDownPrice.Size = new Size(140, 23); + numericUpDownPrice.TabIndex = 32; + numericUpDownPrice.Value = new decimal(new int[] { 1, 0, 0, 131072 }); + // + // buttonCancel + // + buttonCancel.Location = new Point(170, 106); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(75, 23); + buttonCancel.TabIndex = 28; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // buttonFuelSave + // + buttonFuelSave.Location = new Point(7, 106); + buttonFuelSave.Name = "buttonFuelSave"; + buttonFuelSave.Size = new Size(75, 23); + buttonFuelSave.TabIndex = 27; + buttonFuelSave.Text = "Сохранить"; + buttonFuelSave.UseVisualStyleBackColor = true; + buttonFuelSave.Click += ButtonFuelSave_Click; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(7, 12); + label1.Name = "label1"; + label1.Size = new Size(75, 15); + label1.TabIndex = 35; + label1.Text = "Тип топлива"; + // + // comboBoxFuelType + // + comboBoxFuelType.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxFuelType.FormattingEnabled = true; + comboBoxFuelType.Location = new Point(105, 9); + comboBoxFuelType.Name = "comboBoxFuelType"; + comboBoxFuelType.Size = new Size(140, 23); + comboBoxFuelType.TabIndex = 34; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(7, 69); + label2.Name = "label2"; + label2.Size = new Size(72, 15); + label2.TabIndex = 37; + label2.Text = "Количество"; + // + // numericUpDownAmount + // + numericUpDownAmount.DecimalPlaces = 2; + numericUpDownAmount.Location = new Point(105, 67); + numericUpDownAmount.Minimum = new decimal(new int[] { 1, 0, 0, 131072 }); + numericUpDownAmount.Name = "numericUpDownAmount"; + numericUpDownAmount.Size = new Size(140, 23); + numericUpDownAmount.TabIndex = 36; + numericUpDownAmount.Value = new decimal(new int[] { 1, 0, 0, 131072 }); + // + // FormFuel + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(256, 136); + Controls.Add(label2); + Controls.Add(numericUpDownAmount); + Controls.Add(label1); + Controls.Add(comboBoxFuelType); + Controls.Add(label5); + Controls.Add(numericUpDownPrice); + Controls.Add(buttonCancel); + Controls.Add(buttonFuelSave); + Name = "FormFuel"; + Text = "FormFuel"; + ((System.ComponentModel.ISupportInitialize)numericUpDownPrice).EndInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownAmount).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label label5; + private NumericUpDown numericUpDownPrice; + private Button buttonCancel; + private Button buttonFuelSave; + private Label label1; + private ComboBox comboBoxFuelType; + private Label label2; + private NumericUpDown numericUpDownAmount; + } +} \ No newline at end of file diff --git a/FuelAndLubricants/FuelAndLubricants/Forms/FormFuel.cs b/FuelAndLubricants/FuelAndLubricants/Forms/FormFuel.cs new file mode 100644 index 0000000..ae8ee7e --- /dev/null +++ b/FuelAndLubricants/FuelAndLubricants/Forms/FormFuel.cs @@ -0,0 +1,72 @@ +using FuelAndLubricants.Entities; +using FuelAndLubricants.Entities.Enums; +using FuelAndLubricants.Repositories; + +namespace FuelAndLubricants.Forms +{ + public partial class FormFuel : Form + { + private readonly IFuelRepository _fuelRepository; + + private int? _fuelId; + + public int Id + { + set + { + try + { + var fuel = _fuelRepository.ReadFuelByID(value); + if (fuel == null) + throw new InvalidOperationException(nameof(fuel)); + + comboBoxFuelType.SelectedItem = fuel.Fuel_Type; + numericUpDownPrice.Value = (decimal)fuel.Price_Per_Liter; + numericUpDownAmount.Value = (decimal)fuel.Amount; + + _fuelId = value; + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + } + } + public FormFuel(IFuelRepository fuelRepository) + { + InitializeComponent(); + _fuelRepository = fuelRepository ?? + throw new ArgumentNullException(nameof(fuelRepository)); + + comboBoxFuelType.DataSource = Enum.GetValues(typeof(Fuel_Type)); + } + + private void ButtonFuelSave_Click(object sender, EventArgs e) + { + try + { + if (comboBoxFuelType.SelectedIndex < 1) + throw new Exception("Имеются незаполненные поля"); + + if (_fuelId.HasValue) + _fuelRepository.UpdateFuel(CreateFuel(_fuelId.Value)); + else + _fuelRepository.CreateFuel(CreateFuel(0)); + + Close(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) => Close(); + + private Fuel_And_Lubricants CreateFuel(int id) + { + return Fuel_And_Lubricants.CreateEntity(id, (Fuel_Type)comboBoxFuelType.SelectedItem!, (float)numericUpDownPrice.Value, (float)numericUpDownAmount.Value); + } + } +} diff --git a/FuelAndLubricants/FuelAndLubricants/Forms/FormFuel.resx b/FuelAndLubricants/FuelAndLubricants/Forms/FormFuel.resx new file mode 100644 index 0000000..8b2ff64 --- /dev/null +++ b/FuelAndLubricants/FuelAndLubricants/Forms/FormFuel.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/FuelAndLubricants/FuelAndLubricants/Repositories/IFuelRepository.cs b/FuelAndLubricants/FuelAndLubricants/Repositories/IFuelRepository.cs index 5988b93..f02721c 100644 --- a/FuelAndLubricants/FuelAndLubricants/Repositories/IFuelRepository.cs +++ b/FuelAndLubricants/FuelAndLubricants/Repositories/IFuelRepository.cs @@ -8,7 +8,7 @@ public interface IFuelRepository Fuel_And_Lubricants ReadFuelByID(int id); - void CreateDriver(Fuel_And_Lubricants fuel); + void CreateFuel(Fuel_And_Lubricants fuel); void UpdateFuel(Fuel_And_Lubricants fuel);