From a5c5a3a2343433ec8151fcbb90c996ef9b883582 Mon Sep 17 00:00:00 2001 From: Petek1234 <149153720+Petek1234@users.noreply.github.com> Date: Fri, 22 Nov 2024 10:14:33 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BB=D0=B0=D0=B1=D0=B0=201=20=D1=82=D0=BE?= =?UTF-8?q?=D1=87=D0=BD=D0=BE=20=D0=B2=D1=81=D1=8F=20=D0=B3=D0=BE=D1=82?= =?UTF-8?q?=D0=BE=D0=B2=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Entities/Enums/SupppliersFuelType.cs | 13 ++++++ GasStation/GasStation/Entities/Suppliers.cs | 9 +++- .../GasStation/Forms/FormSupplier.Designer.cs | 44 ++++++++++++++----- GasStation/GasStation/Forms/FormSupplier.cs | 35 +++++++++++---- .../Implementations/SupplierRepository.cs | 3 +- 5 files changed, 82 insertions(+), 22 deletions(-) create mode 100644 GasStation/GasStation/Entities/Enums/SupppliersFuelType.cs diff --git a/GasStation/GasStation/Entities/Enums/SupppliersFuelType.cs b/GasStation/GasStation/Entities/Enums/SupppliersFuelType.cs new file mode 100644 index 0000000..9dbe489 --- /dev/null +++ b/GasStation/GasStation/Entities/Enums/SupppliersFuelType.cs @@ -0,0 +1,13 @@ +namespace GasStation.Entities.Enums; + +[Flags] +public enum SupppliersFuelType +{ + None = 0, + + Fuel_92 = 1, // 0001 + + Fuel_95 = 2, // 0010 + + Fuel_diesel = 4 // +}// diff --git a/GasStation/GasStation/Entities/Suppliers.cs b/GasStation/GasStation/Entities/Suppliers.cs index 24b3d18..d5c89bf 100644 --- a/GasStation/GasStation/Entities/Suppliers.cs +++ b/GasStation/GasStation/Entities/Suppliers.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using GasStation.Entities.Enums; namespace GasStation.Entities; @@ -12,13 +13,17 @@ public class Supplier public string Brand { get; private set; } = string.Empty; - public static Supplier CreateEntity(int id, string brand) + public SupppliersFuelType Types { get; private set; } + + public static Supplier CreateEntity(int id, string brand, SupppliersFuelType types) { return new Supplier { Id = id, - Brand = brand ?? string.Empty + Brand = brand ?? string.Empty, + + Types = types }; } } diff --git a/GasStation/GasStation/Forms/FormSupplier.Designer.cs b/GasStation/GasStation/Forms/FormSupplier.Designer.cs index 49a830c..69cbc64 100644 --- a/GasStation/GasStation/Forms/FormSupplier.Designer.cs +++ b/GasStation/GasStation/Forms/FormSupplier.Designer.cs @@ -32,27 +32,29 @@ textBoxBrand = new TextBox(); ButtonSave = new Button(); ButtonCancel = new Button(); + checkedListBoxFuelTypes = new CheckedListBox(); + label2 = new Label(); SuspendLayout(); // // label1 // label1.AutoSize = true; - label1.Location = new Point(39, 43); + label1.Location = new Point(39, 40); label1.Name = "label1"; - label1.Size = new Size(116, 15); + label1.Size = new Size(119, 15); label1.TabIndex = 0; - label1.Text = "Бренд поставщика"; + label1.Text = "Бренд поставщика:"; // // textBoxBrand // - textBoxBrand.Location = new Point(191, 40); + textBoxBrand.Location = new Point(185, 40); textBoxBrand.Name = "textBoxBrand"; - textBoxBrand.Size = new Size(125, 23); + textBoxBrand.Size = new Size(169, 23); textBoxBrand.TabIndex = 1; // // ButtonSave // - ButtonSave.Location = new Point(39, 116); + ButtonSave.Location = new Point(39, 257); ButtonSave.Name = "ButtonSave"; ButtonSave.Size = new Size(116, 30); ButtonSave.TabIndex = 2; @@ -61,7 +63,7 @@ // // ButtonCancel // - ButtonCancel.Location = new Point(191, 116); + ButtonCancel.Location = new Point(187, 257); ButtonCancel.Name = "ButtonCancel"; ButtonCancel.Size = new Size(125, 30); ButtonCancel.TabIndex = 3; @@ -69,16 +71,36 @@ ButtonCancel.UseVisualStyleBackColor = true; ButtonCancel.Click += ButtonCancel_Click; // - // FormSuppliers + // checkedListBoxFuelTypes + // + checkedListBoxFuelTypes.FormattingEnabled = true; + checkedListBoxFuelTypes.Location = new Point(185, 69); + checkedListBoxFuelTypes.Name = "checkedListBoxFuelTypes"; + checkedListBoxFuelTypes.RightToLeft = RightToLeft.No; + checkedListBoxFuelTypes.Size = new Size(169, 94); + checkedListBoxFuelTypes.TabIndex = 4; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(39, 93); + label2.Name = "label2"; + label2.Size = new Size(91, 15); + label2.TabIndex = 5; + label2.Text = "Типы топлива:"; + // + // FormSupplier // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(366, 189); + ClientSize = new Size(366, 335); + Controls.Add(label2); + Controls.Add(checkedListBoxFuelTypes); Controls.Add(ButtonCancel); Controls.Add(ButtonSave); Controls.Add(textBoxBrand); Controls.Add(label1); - Name = "FormSuppliers"; + Name = "FormSupplier"; StartPosition = FormStartPosition.CenterParent; Text = "Поставщики"; ResumeLayout(false); @@ -91,5 +113,7 @@ private TextBox textBoxBrand; private Button ButtonSave; private Button ButtonCancel; + private CheckedListBox checkedListBoxFuelTypes; + private Label label2; } } \ No newline at end of file diff --git a/GasStation/GasStation/Forms/FormSupplier.cs b/GasStation/GasStation/Forms/FormSupplier.cs index 9422a6b..41b691b 100644 --- a/GasStation/GasStation/Forms/FormSupplier.cs +++ b/GasStation/GasStation/Forms/FormSupplier.cs @@ -9,6 +9,7 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using GasStation.Entities; +using GasStation.Entities.Enums; using GasStation.Repositories; using GasStation.Repositories.Implementations; @@ -28,18 +29,20 @@ public partial class FormSupplier : Form try { var supplier = _supplierRepository.ReadSupplierById(value); - if (supplier == null) { - throw new InvalidDataException(nameof(supplier)); } - + foreach (SupppliersFuelType elem in Enum.GetValues(typeof(SupppliersFuelType))) + { + if ((elem & supplier.Types) != 0) + { + checkedListBoxFuelTypes.SetItemChecked(checkedListBoxFuelTypes.Items.IndexOf(elem), true); + } + } textBoxBrand.Text = supplier.Brand; - _supplierlId = value; } - catch (Exception ex) { MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error); @@ -52,6 +55,11 @@ public partial class FormSupplier : Form { InitializeComponent(); _supplierRepository = supplierRepository ?? throw new ArgumentNullException(nameof(supplierRepository)); + foreach (SupppliersFuelType fuelType in Enum.GetValues(typeof(SupppliersFuelType))) + { + if (fuelType == SupppliersFuelType.None) continue; + checkedListBoxFuelTypes.Items.Add(fuelType); + } } private void ButtonSave_Click(object sender, EventArgs e) @@ -64,11 +72,11 @@ public partial class FormSupplier : Form } if (_supplierlId.HasValue) { - _supplierRepository.UpdateSupplier(CreateSupplier(_supplierlId.Value)); + _supplierRepository.UpdateSupplier(CreateEntity(_supplierlId.Value)); } else { - _supplierRepository.CreateSupplier(CreateSupplier(0)); + _supplierRepository.CreateSupplier(CreateEntity(0)); } Close(); } @@ -79,7 +87,16 @@ public partial class FormSupplier : Form } } - private void ButtonCancel_Click (object sender, EventArgs e) => Close(); + private void ButtonCancel_Click(object sender, EventArgs e) => Close(); + + private Supplier CreateEntity(int id) + { + SupppliersFuelType fuelType = SupppliersFuelType.None; + foreach (var elem in checkedListBoxFuelTypes.CheckedItems) + { + fuelType |= (SupppliersFuelType)elem; + } + return Supplier.CreateEntity(id, textBoxBrand.Text, fuelType); + } - private Supplier CreateSupplier(int id) => Supplier.CreateEntity(id, textBoxBrand.Text); } diff --git a/GasStation/GasStation/Repositories/Implementations/SupplierRepository.cs b/GasStation/GasStation/Repositories/Implementations/SupplierRepository.cs index 9d7b63f..739b15d 100644 --- a/GasStation/GasStation/Repositories/Implementations/SupplierRepository.cs +++ b/GasStation/GasStation/Repositories/Implementations/SupplierRepository.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using GasStation.Entities; +using GasStation.Entities.Enums; namespace GasStation.Repositories.Implementations; @@ -20,7 +21,7 @@ public class SupplierRepository : ISupplierRepository public Supplier ReadSupplierById(int id) { - return Supplier.CreateEntity(0, string.Empty); + return Supplier.CreateEntity(0, string.Empty, SupppliersFuelType.Fuel_diesel); } public IEnumerable ReadSuppliers()