From 8ad6e9478eb25cf5017bee67876e501af23bb44b Mon Sep 17 00:00:00 2001 From: Oleg Shabunov Date: Wed, 3 Apr 2024 10:56:29 +0400 Subject: [PATCH 1/5] BusinessLogic, Contracts, DataModels --- .../BusinessLogics/ShopLogic.cs | 160 ++++++++++++++++++ .../BindingModels/ShopBindingModel.cs | 17 ++ .../BindingModels/SupplyBindingModel.cs | 13 ++ .../BusinessLogicContracts/IShopLogic.cs | 21 +++ .../SearchModels/ShopSearchModel.cs | 9 + .../StoragesContracts/IShopStorage.cs | 21 +++ .../ViewModels/ShopViewModel.cs | 21 +++ AutoWorkshopDataModels/Models/IShopModel.cs | 13 ++ AutoWorkshopDataModels/Models/ISupplyModel.cs | 11 ++ 9 files changed, 286 insertions(+) create mode 100644 AutoWorkshopBusinessLogic/BusinessLogics/ShopLogic.cs create mode 100644 AutoWorkshopContracts/BindingModels/ShopBindingModel.cs create mode 100644 AutoWorkshopContracts/BindingModels/SupplyBindingModel.cs create mode 100644 AutoWorkshopContracts/BusinessLogicContracts/IShopLogic.cs create mode 100644 AutoWorkshopContracts/SearchModels/ShopSearchModel.cs create mode 100644 AutoWorkshopContracts/StoragesContracts/IShopStorage.cs create mode 100644 AutoWorkshopContracts/ViewModels/ShopViewModel.cs create mode 100644 AutoWorkshopDataModels/Models/IShopModel.cs create mode 100644 AutoWorkshopDataModels/Models/ISupplyModel.cs diff --git a/AutoWorkshopBusinessLogic/BusinessLogics/ShopLogic.cs b/AutoWorkshopBusinessLogic/BusinessLogics/ShopLogic.cs new file mode 100644 index 0000000..995d417 --- /dev/null +++ b/AutoWorkshopBusinessLogic/BusinessLogics/ShopLogic.cs @@ -0,0 +1,160 @@ +using Microsoft.Extensions.Logging; +using PizzeriaContracts.BindingModels; +using PizzeriaContracts.BusinessLogicsContracts; +using PizzeriaContracts.SearchModels; +using PizzeriaContracts.StoragesContracts; +using PizzeriaContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PizzeriaBusinessLogic.BusinessLogics +{ + public class ShopLogic : IShopLogic + { + private readonly ILogger _logger; + private readonly IShopStorage _shopStorage; + private readonly IPizzaStorage _pizzaStorage; + + public ShopLogic(ILogger logger, IShopStorage shopStorage, IPizzaStorage pizzaStorage) + { + _logger = logger; + _shopStorage = shopStorage; + _pizzaStorage = pizzaStorage; + } + + public List? ReadList(ShopSearchModel? model) + { + _logger.LogInformation("ReadList. ShopName:{ShopName}.Id:{ Id}", model?.ShopName, model?.Id); + var list = model == null ? _shopStorage.GetFullList() : _shopStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public ShopViewModel? ReadElement(ShopSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. ShopName:{ShopName}.Id:{ Id}", model.ShopName, model.Id); + var element = _shopStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + + public bool Create(ShopBindingModel model) + { + CheckModel(model); + if (_shopStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Update(ShopBindingModel model) + { + CheckModel(model); + if (_shopStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + public bool Delete(ShopBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_shopStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + public bool MakeSupply(SupplyBindingModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (model.Count <= 0) + { + throw new ArgumentException("Количество изделий должно быть больше 0"); + } + var shop = _shopStorage.GetElement(new ShopSearchModel + { + Id = model.ShopId + }); + if (shop == null) + { + throw new ArgumentException("Магазина не существует"); + } + if (shop.ShopPizzas.ContainsKey(model.PizzaId)) + { + var oldValue = shop.ShopPizzas[model.PizzaId]; + oldValue.Item2 += model.Count; + shop.ShopPizzas[model.PizzaId] = oldValue; + } + else + { + var pizza = _pizzaStorage.GetElement(new PizzaSearchModel + { + Id = model.PizzaId + }); + if (pizza == null) + { + throw new ArgumentException($"Поставка: Товар с id:{model.PizzaId} не найденн"); + } + shop.ShopPizzas.Add(model.PizzaId, (pizza, model.Count)); + } + return true; + } + + private void CheckModel(ShopBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.Adress)) + { + throw new ArgumentException("Адрес магазина длжен быть заполнен", nameof(model.Adress)); + } + if (string.IsNullOrEmpty(model.ShopName)) + { + throw new ArgumentException("Название магазина должно быть заполнено", nameof(model.ShopName)); + } + _logger.LogInformation("Shop. ShopName:{ShopName}.Address:{Address}.OpeningDate:{OpeningDate}.Id:{ Id}", model.ShopName, model.Adress, model.OpeningDate, model.Id); + var element = _shopStorage.GetElement(new ShopSearchModel + { + ShopName = model.ShopName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Магазин с таким названием уже есть"); + } + } + } +} diff --git a/AutoWorkshopContracts/BindingModels/ShopBindingModel.cs b/AutoWorkshopContracts/BindingModels/ShopBindingModel.cs new file mode 100644 index 0000000..60e6480 --- /dev/null +++ b/AutoWorkshopContracts/BindingModels/ShopBindingModel.cs @@ -0,0 +1,17 @@ +using AutoWorkshopDataModels.Models; + +namespace AutoWorkshopContracts.BindingModels +{ + public class ShopBindingModel : IShopModel + { + public int Id { get; set; } + + public string ShopName { get; set; } = string.Empty; + + public string Address { get; set; } = string.Empty; + + public DateTime OpeningDate { get; set; } = DateTime.Now; + + public Dictionary ShopRepairs { get; set; } = new(); + } +} diff --git a/AutoWorkshopContracts/BindingModels/SupplyBindingModel.cs b/AutoWorkshopContracts/BindingModels/SupplyBindingModel.cs new file mode 100644 index 0000000..cd776af --- /dev/null +++ b/AutoWorkshopContracts/BindingModels/SupplyBindingModel.cs @@ -0,0 +1,13 @@ +using AutoWorkshopDataModels.Models; + +namespace AutoWorkshopContracts.BindingModels +{ + public class SupplyBindingModel : ISupplyModel + { + public int ShopId { get; set; } + + public int RepairId { get; set; } + + public int Count { get; set; } + } +} diff --git a/AutoWorkshopContracts/BusinessLogicContracts/IShopLogic.cs b/AutoWorkshopContracts/BusinessLogicContracts/IShopLogic.cs new file mode 100644 index 0000000..6a0ee7f --- /dev/null +++ b/AutoWorkshopContracts/BusinessLogicContracts/IShopLogic.cs @@ -0,0 +1,21 @@ +using AutoWorkshopContracts.BindingModels; +using AutoWorkshopContracts.SearchModels; +using AutoWorkshopContracts.ViewModels; + +namespace AutoWorkshopContracts.BusinessLogicsContracts +{ + public interface IShopLogic + { + List? ReadList(ShopSearchModel? Model); + + ShopViewModel? ReadElement(ShopSearchModel Model); + + bool Create(ShopBindingModel Model); + + bool Update(ShopBindingModel Model); + + bool Delete(ShopBindingModel Model); + + bool MakeSupply(SupplyBindingModel Model); + } +} diff --git a/AutoWorkshopContracts/SearchModels/ShopSearchModel.cs b/AutoWorkshopContracts/SearchModels/ShopSearchModel.cs new file mode 100644 index 0000000..22aaaaa --- /dev/null +++ b/AutoWorkshopContracts/SearchModels/ShopSearchModel.cs @@ -0,0 +1,9 @@ +namespace AutoWorkshopContracts.SearchModels +{ + public class ShopSearchModel + { + public int? Id { get; set; } + + public string? ShopName { get; set; } + } +} diff --git a/AutoWorkshopContracts/StoragesContracts/IShopStorage.cs b/AutoWorkshopContracts/StoragesContracts/IShopStorage.cs new file mode 100644 index 0000000..dcaee83 --- /dev/null +++ b/AutoWorkshopContracts/StoragesContracts/IShopStorage.cs @@ -0,0 +1,21 @@ +using AutoWorkshopContracts.BindingModels; +using AutoWorkshopContracts.SearchModels; +using AutoWorkshopContracts.ViewModels; + +namespace AutoWorkshopContracts.StoragesContracts +{ + public interface IShopStorage + { + List GetFullList(); + + List GetFilteredList(ShopSearchModel Model); + + ShopViewModel? GetElement(ShopSearchModel Model); + + ShopViewModel? Insert(ShopBindingModel Model); + + ShopViewModel? Update(ShopBindingModel Model); + + ShopViewModel? Delete(ShopBindingModel Model); + } +} diff --git a/AutoWorkshopContracts/ViewModels/ShopViewModel.cs b/AutoWorkshopContracts/ViewModels/ShopViewModel.cs new file mode 100644 index 0000000..b449a11 --- /dev/null +++ b/AutoWorkshopContracts/ViewModels/ShopViewModel.cs @@ -0,0 +1,21 @@ +using AutoWorkshopDataModels.Models; +using System.ComponentModel; + +namespace AutoWorkshopContracts.ViewModels +{ + public class ShopViewModel : IShopModel + { + public int Id { get; set; } + + [DisplayName("Название")] + public string ShopName { get; set; } = string.Empty; + + [DisplayName("Адрес")] + public string Address { get; set; } = string.Empty; + + [DisplayName("Дата открытия")] + public DateTime OpeningDate { get; set; } + + public Dictionary ShopRepairs { get; set; } = new(); + } +} diff --git a/AutoWorkshopDataModels/Models/IShopModel.cs b/AutoWorkshopDataModels/Models/IShopModel.cs new file mode 100644 index 0000000..0211aa8 --- /dev/null +++ b/AutoWorkshopDataModels/Models/IShopModel.cs @@ -0,0 +1,13 @@ +namespace AutoWorkshopDataModels.Models +{ + public interface IShopModel : IId + { + string ShopName { get; } + + string Address { get; } + + DateTime OpeningDate { get; } + + Dictionary ShopRepairs { get; } + } +} diff --git a/AutoWorkshopDataModels/Models/ISupplyModel.cs b/AutoWorkshopDataModels/Models/ISupplyModel.cs new file mode 100644 index 0000000..5a12647 --- /dev/null +++ b/AutoWorkshopDataModels/Models/ISupplyModel.cs @@ -0,0 +1,11 @@ +namespace AutoWorkshopDataModels.Models +{ + public interface ISupplyModel + { + int ShopId { get; } + + int RepairId { get; } + + int Count { get; } + } +} -- 2.25.1 From 8447239146238685e998f98b20fbc1af95999d3a Mon Sep 17 00:00:00 2001 From: Oleg Shabunov Date: Wed, 3 Apr 2024 11:06:33 +0400 Subject: [PATCH 2/5] ListImplement --- AutoWorkshopImplement/DataListSingleton.cs | 3 + .../Implements/ShopStorage.cs | 112 ++++++++++++++++++ AutoWorkshopImplement/Models/Shop.cs | 52 ++++++++ 3 files changed, 167 insertions(+) create mode 100644 AutoWorkshopImplement/Implements/ShopStorage.cs create mode 100644 AutoWorkshopImplement/Models/Shop.cs diff --git a/AutoWorkshopImplement/DataListSingleton.cs b/AutoWorkshopImplement/DataListSingleton.cs index 2bec800..c210d2a 100644 --- a/AutoWorkshopImplement/DataListSingleton.cs +++ b/AutoWorkshopImplement/DataListSingleton.cs @@ -11,12 +11,15 @@ namespace AutoWorkshopListImplement public List Orders { get; set; } public List Repairs { get; set; } + + public List Shops { get; set; } private DataListSingleton() { Components = new List(); Orders = new List(); Repairs = new List(); + Shops = new List(); } public static DataListSingleton GetInstance() diff --git a/AutoWorkshopImplement/Implements/ShopStorage.cs b/AutoWorkshopImplement/Implements/ShopStorage.cs new file mode 100644 index 0000000..8e6d8e7 --- /dev/null +++ b/AutoWorkshopImplement/Implements/ShopStorage.cs @@ -0,0 +1,112 @@ +using AutoWorkshopContracts.BindingModels; +using AutoWorkshopContracts.SearchModels; +using AutoWorkshopContracts.StoragesContracts; +using AutoWorkshopContracts.ViewModels; +using AutoWorkshopListImplement.Models; + +namespace AutoWorkshopListImplement.Implements +{ + public class ShopStorage : IShopStorage + { + private readonly DataListSingleton _source; + + public ShopStorage() + { + _source = DataListSingleton.GetInstance(); + } + + public List GetFullList() + { + var Result = new List(); + + foreach (var Shop in _source.Shops) + { + Result.Add(Shop.GetViewModel); + } + + return Result; + } + + public List GetFilteredList(ShopSearchModel Model) + { + var Result = new List(); + + if (string.IsNullOrEmpty(Model.ShopName)) + return Result; + + foreach (var Shop in _source.Shops) + { + if (Shop.ShopName.Contains(Model.ShopName)) + Result.Add(Shop.GetViewModel); + } + + return Result; + } + + public ShopViewModel? GetElement(ShopSearchModel Model) + { + if (string.IsNullOrEmpty(Model.ShopName) && !Model.Id.HasValue) + return null; + + foreach (var Shop in _source.Shops) + { + if ((!string.IsNullOrEmpty(Model.ShopName) && Shop.ShopName == Model.ShopName) || + (Model.Id.HasValue && Shop.Id == Model.Id)) + { + return Shop.GetViewModel; + } + } + + return null; + } + + public ShopViewModel? Insert(ShopBindingModel Model) + { + Model.Id = 1; + + foreach (var Shop in _source.Shops) + { + if (Model.Id <= Shop.Id) + Model.Id = Shop.Id + 1; + } + + var NewShop = Shop.Create(Model); + + if (NewShop is null) + return null; + + _source.Shops.Add(NewShop); + return NewShop.GetViewModel; + } + + public ShopViewModel? Update(ShopBindingModel Model) + { + foreach (var Shop in _source.Shops) + { + if (Shop.Id == Model.Id) + { + Shop.Update(Model); + return Shop.GetViewModel; + } + } + + return null; + } + + public ShopViewModel? Delete(ShopBindingModel Model) + { + for (int i = 0; i < _source.Shops.Count; ++i) + { + if (_source.Shops[i].Id == Model.Id) + { + var Shop = _source.Shops[i]; + _source.Shops.RemoveAt(i); + + return Shop.GetViewModel; + } + } + + return null; + } + } +} diff --git a/AutoWorkshopImplement/Models/Shop.cs b/AutoWorkshopImplement/Models/Shop.cs new file mode 100644 index 0000000..bf6eec9 --- /dev/null +++ b/AutoWorkshopImplement/Models/Shop.cs @@ -0,0 +1,52 @@ +using AutoWorkshopContracts.BindingModels; +using AutoWorkshopContracts.ViewModels; +using AutoWorkshopDataModels.Models; + +namespace AutoWorkshopListImplement.Models +{ + public class Shop : IShopModel + { + public int Id { get; private set; } + + public string ShopName { get; private set; } = string.Empty; + + public string Address { get; private set; } = string.Empty; + + public DateTime OpeningDate { get; private set; } + + public Dictionary ShopRepairs { get; private set; } = new(); + + public static Shop? Create(ShopBindingModel? Model) + { + if (Model is null) + return null; + + return new Shop() + { + Id = Model.Id, + ShopName = Model.ShopName, + Address = Model.Address, + OpeningDate = Model.OpeningDate + }; + } + + public void Update(ShopBindingModel? Model) + { + if (Model is null) + return; + + ShopName = Model.ShopName; + Address = Model.Address; + OpeningDate = Model.OpeningDate; + } + + public ShopViewModel GetViewModel => new() + { + Id = Id, + ShopName = ShopName, + Address = Address, + OpeningDate = OpeningDate, + ShopRepairs = ShopRepairs + }; + } +} -- 2.25.1 From 4330a80dd0f39c98c64ba537db0e4d9bdf8497c3 Mon Sep 17 00:00:00 2001 From: Oleg Shabunov Date: Wed, 3 Apr 2024 11:16:21 +0400 Subject: [PATCH 3/5] start Shop forms --- .../Forms/Shop/FormCreateSupply.Designer.cs | 137 +++++++++++++ .../Forms/Shop/FormCreateSupply.cs | 89 ++++++++ .../Forms/Shop/FormCreateSupply.resx | 120 +++++++++++ .../Forms/Shop/FormShop.Designer.cs | 193 ++++++++++++++++++ AutoWorkshopView/Forms/Shop/FormShop.cs | 118 +++++++++++ AutoWorkshopView/Forms/Shop/FormShop.resx | 120 +++++++++++ .../Forms/Shop/FormShops.Designer.cs | 130 ++++++++++++ AutoWorkshopView/Forms/Shop/FormShops.cs | 107 ++++++++++ AutoWorkshopView/Forms/Shop/FormShops.resx | 120 +++++++++++ 9 files changed, 1134 insertions(+) create mode 100644 AutoWorkshopView/Forms/Shop/FormCreateSupply.Designer.cs create mode 100644 AutoWorkshopView/Forms/Shop/FormCreateSupply.cs create mode 100644 AutoWorkshopView/Forms/Shop/FormCreateSupply.resx create mode 100644 AutoWorkshopView/Forms/Shop/FormShop.Designer.cs create mode 100644 AutoWorkshopView/Forms/Shop/FormShop.cs create mode 100644 AutoWorkshopView/Forms/Shop/FormShop.resx create mode 100644 AutoWorkshopView/Forms/Shop/FormShops.Designer.cs create mode 100644 AutoWorkshopView/Forms/Shop/FormShops.cs create mode 100644 AutoWorkshopView/Forms/Shop/FormShops.resx diff --git a/AutoWorkshopView/Forms/Shop/FormCreateSupply.Designer.cs b/AutoWorkshopView/Forms/Shop/FormCreateSupply.Designer.cs new file mode 100644 index 0000000..ee3fdc7 --- /dev/null +++ b/AutoWorkshopView/Forms/Shop/FormCreateSupply.Designer.cs @@ -0,0 +1,137 @@ +namespace AutoWorkshopView.Forms.Shop +{ + partial class FormCreateSupply + { + /// + /// 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); + } + + private void InitializeComponent() + { + comboBoxShop = new System.Windows.Forms.ComboBox(); + labelShop = new System.Windows.Forms.Label(); + labelRepair = new System.Windows.Forms.Label(); + comboBoxRepair = new System.Windows.Forms.ComboBox(); + labelCount = new System.Windows.Forms.Label(); + textBoxCount = new System.Windows.Forms.TextBox(); + buttonCancel = new System.Windows.Forms.Button(); + buttonSave = new System.Windows.Forms.Button(); + SuspendLayout(); + // + // comboBoxShop + // + comboBoxShop.FormattingEnabled = true; + comboBoxShop.Location = new System.Drawing.Point(115, 12); + comboBoxShop.Name = "comboBoxShop"; + comboBoxShop.Size = new System.Drawing.Size(344, 28); + comboBoxShop.TabIndex = 0; + // + // labelShop + // + labelShop.AutoSize = true; + labelShop.Location = new System.Drawing.Point(12, 15); + labelShop.Name = "labelShop"; + labelShop.Size = new System.Drawing.Size(76, 20); + labelShop.TabIndex = 1; + labelShop.Text = "Магазин: "; + // + // labelRepair + // + labelRepair.AutoSize = true; + labelRepair.Location = new System.Drawing.Point(12, 49); + labelRepair.Name = "labelRepair"; + labelRepair.Size = new System.Drawing.Size(75, 20); + labelRepair.TabIndex = 2; + labelRepair.Text = "Изделие: "; + // + // comboBoxRepair + // + comboBoxRepair.FormattingEnabled = true; + comboBoxRepair.Location = new System.Drawing.Point(115, 46); + comboBoxRepair.Name = "comboBoxRepair"; + comboBoxRepair.Size = new System.Drawing.Size(344, 28); + comboBoxRepair.TabIndex = 3; + // + // labelCount + // + labelCount.AutoSize = true; + labelCount.Location = new System.Drawing.Point(12, 83); + labelCount.Name = "labelCount"; + labelCount.Size = new System.Drawing.Size(97, 20); + labelCount.TabIndex = 4; + labelCount.Text = "Количество: "; + // + // textBoxCount + // + textBoxCount.Location = new System.Drawing.Point(115, 80); + textBoxCount.Name = "textBoxCount"; + textBoxCount.Size = new System.Drawing.Size(344, 27); + textBoxCount.TabIndex = 5; + // + // buttonCancel + // + buttonCancel.Location = new System.Drawing.Point(300, 113); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new System.Drawing.Size(116, 39); + buttonCancel.TabIndex = 6; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += new System.EventHandler(ButtonCancel_Click); + // + // buttonSave + // + buttonSave.Location = new System.Drawing.Point(168, 113); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new System.Drawing.Size(116, 39); + buttonSave.TabIndex = 7; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += new System.EventHandler(ButtonSave_Click); + // + // FormCreateSupply + // + AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + ClientSize = new System.Drawing.Size(471, 164); + Controls.Add(buttonSave); + Controls.Add(buttonCancel); + Controls.Add(textBoxCount); + Controls.Add(labelCount); + Controls.Add(comboBoxRepair); + Controls.Add(labelRepair); + Controls.Add(labelShop); + Controls.Add(comboBoxShop); + Name = "FormCreateSupply"; + Text = "Создание поставки"; + Load += new System.EventHandler(FormCreateSupply_Load); + ResumeLayout(false); + PerformLayout(); + + } + +#endregion + + private ComboBox comboBoxShop; + private Label labelShop; + private Label labelRepair; + private ComboBox comboBoxRepair; + private Label labelCount; + private TextBox textBoxCount; + private Button buttonCancel; + private Button buttonSave; + } +} \ No newline at end of file diff --git a/AutoWorkshopView/Forms/Shop/FormCreateSupply.cs b/AutoWorkshopView/Forms/Shop/FormCreateSupply.cs new file mode 100644 index 0000000..ab98827 --- /dev/null +++ b/AutoWorkshopView/Forms/Shop/FormCreateSupply.cs @@ -0,0 +1,89 @@ +using AutoWorkshopContracts.BindingModels; +using AutoWorkshopContracts.BusinessLogicsContracts; +using AutoWorkshopContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace AutoWorkshopView.Forms.Shop +{ + public partial class FormCreateSupply : Form + { + private readonly ILogger _logger; + private readonly IRepairLogic _logicP; + private readonly IShopLogic _logicS; + + private List _shopList = new List(); + private List _RepairList = new List(); + + public FormCreateSupply(ILogger logger, IRepairLogic logicP, IShopLogic logicS) + { + InitializeComponent(); + _logger = logger; + _logicP = logicP; + _logicS = logicS; + } + + private void FormCreateSupply_Load(object sender, EventArgs e) + { + _shopList = _logicS.ReadList(null); + _RepairList = _logicP.ReadList(null); + if (_shopList != null) + { + comboBoxShop.DisplayMember = "ShopName"; + comboBoxShop.ValueMember = "Id"; + comboBoxShop.DataSource = _shopList; + comboBoxShop.SelectedItem = null; + _logger.LogInformation("Загрузка магазинов для поставок"); + } + if (_RepairList != null) + { + comboBoxRepair.DisplayMember = "RepairName"; + comboBoxRepair.ValueMember = "Id"; + comboBoxRepair.DataSource = _RepairList; + comboBoxRepair.SelectedItem = null; + _logger.LogInformation("Загрузка ремонтов для поставок"); + } + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (comboBoxShop.SelectedValue == null) + { + MessageBox.Show("Выберите магазин", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxRepair.SelectedValue == null) + { + MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Создание поставки"); + try + { + var operationResult = _logicS.MakeSupply(new SupplyBindingModel + { + ShopId = Convert.ToInt32(comboBoxShop.SelectedValue), + RepairId = Convert.ToInt32(comboBoxRepair.SelectedValue), + Count = Convert.ToInt32(textBoxCount.Text) + }); + if (!operationResult) + { + throw new Exception("Ошибка при создании поставки. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания поставки"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/AutoWorkshopView/Forms/Shop/FormCreateSupply.resx b/AutoWorkshopView/Forms/Shop/FormCreateSupply.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/AutoWorkshopView/Forms/Shop/FormCreateSupply.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/AutoWorkshopView/Forms/Shop/FormShop.Designer.cs b/AutoWorkshopView/Forms/Shop/FormShop.Designer.cs new file mode 100644 index 0000000..e740193 --- /dev/null +++ b/AutoWorkshopView/Forms/Shop/FormShop.Designer.cs @@ -0,0 +1,193 @@ +namespace AutoWorkshopView.Forms.Shop +{ + partial class FormShop + { + /// + /// 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() + { + labelName = new System.Windows.Forms.Label(); + textBoxName = new System.Windows.Forms.TextBox(); + textBoxAdress = new System.Windows.Forms.TextBox(); + labelAdress = new System.Windows.Forms.Label(); + buttonCancel = new System.Windows.Forms.Button(); + buttonSave = new System.Windows.Forms.Button(); + dataGridView = new System.Windows.Forms.DataGridView(); + id = new System.Windows.Forms.DataGridViewTextBoxColumn(); + RepairName = new System.Windows.Forms.DataGridViewTextBoxColumn(); + Count = new System.Windows.Forms.DataGridViewTextBoxColumn(); + label1 = new System.Windows.Forms.Label(); + dateTimeOpen = new System.Windows.Forms.DateTimePicker(); + ((System.ComponentModel.ISupportInitialize)(dataGridView)).BeginInit(); + SuspendLayout(); + // + // labelName + // + labelName.AutoSize = true; + labelName.Location = new System.Drawing.Point(11, 15); + labelName.Name = "labelName"; + labelName.Size = new System.Drawing.Size(84, 20); + labelName.TabIndex = 0; + labelName.Text = "Название: "; + // + // textBoxName + // + textBoxName.Location = new System.Drawing.Point(102, 12); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new System.Drawing.Size(276, 27); + textBoxName.TabIndex = 1; + // + // textBoxAdress + // + textBoxAdress.Location = new System.Drawing.Point(102, 59); + textBoxAdress.Name = "textBoxAdress"; + textBoxAdress.Size = new System.Drawing.Size(427, 27); + textBoxAdress.TabIndex = 3; + // + // labelAdress + // + labelAdress.AutoSize = true; + labelAdress.Location = new System.Drawing.Point(11, 61); + labelAdress.Name = "labelAdress"; + labelAdress.Size = new System.Drawing.Size(58, 20); + labelAdress.TabIndex = 2; + labelAdress.Text = "Адрес: "; + // + // buttonCancel + // + buttonCancel.Location = new System.Drawing.Point(451, 457); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new System.Drawing.Size(130, 44); + buttonCancel.TabIndex = 5; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += new System.EventHandler(buttonCancel_Click); + // + // buttonSave + // + buttonSave.Location = new System.Drawing.Point(315, 457); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new System.Drawing.Size(130, 44); + buttonSave.TabIndex = 6; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += new System.EventHandler(buttonSave_Click); + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill; + dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + id, + RepairName, + Count}); + dataGridView.Location = new System.Drawing.Point(12, 144); + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.RowHeadersBorderStyle = System.Windows.Forms.DataGridViewHeaderBorderStyle.None; + dataGridView.RowHeadersWidthSizeMode = System.Windows.Forms.DataGridViewRowHeadersWidthSizeMode.AutoSizeToDisplayedHeaders; + dataGridView.RowTemplate.Height = 29; + dataGridView.Size = new System.Drawing.Size(569, 307); + dataGridView.TabIndex = 7; + // + // id + // + id.HeaderText = "id"; + id.MinimumWidth = 6; + id.Name = "id"; + id.ReadOnly = true; + id.Visible = false; + // + // RepairName + // + RepairName.HeaderText = "Ремонт"; + RepairName.MinimumWidth = 6; + RepairName.Name = "RepairName"; + RepairName.ReadOnly = true; + // + // Count + // + Count.HeaderText = "Количество"; + Count.MinimumWidth = 6; + Count.Name = "Count"; + Count.ReadOnly = true; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new System.Drawing.Point(12, 103); + label1.Name = "label1"; + label1.Size = new System.Drawing.Size(110, 20); + label1.TabIndex = 8; + label1.Text = "Дата открытия"; + // + // dateTimeOpen + // + dateTimeOpen.Location = new System.Drawing.Point(128, 103); + dateTimeOpen.Name = "dateTimeOpen"; + dateTimeOpen.Size = new System.Drawing.Size(401, 27); + dateTimeOpen.TabIndex = 9; + // + // FormShop + // + AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + ClientSize = new System.Drawing.Size(593, 513); + Controls.Add(dateTimeOpen); + Controls.Add(label1); + Controls.Add(dataGridView); + Controls.Add(buttonSave); + Controls.Add(buttonCancel); + Controls.Add(textBoxAdress); + Controls.Add(labelAdress); + Controls.Add(textBoxName); + Controls.Add(labelName); + Name = "FormShop"; + Text = "Магазин"; + Load += new System.EventHandler(FormShop_Load); + ((System.ComponentModel.ISupportInitialize)(dataGridView)).EndInit(); + ResumeLayout(false); + PerformLayout(); + + } + + #endregion + + private Label labelName; + private TextBox textBoxName; + private TextBox textBoxAdress; + private Label labelAdress; + private Button buttonCancel; + private Button buttonSave; + private DataGridView dataGridView; + private DataGridViewTextBoxColumn id; + private DataGridViewTextBoxColumn RepairName; + private DataGridViewTextBoxColumn Count; + private Label label1; + private DateTimePicker dateTimeOpen; + } +} \ No newline at end of file diff --git a/AutoWorkshopView/Forms/Shop/FormShop.cs b/AutoWorkshopView/Forms/Shop/FormShop.cs new file mode 100644 index 0000000..5c81e21 --- /dev/null +++ b/AutoWorkshopView/Forms/Shop/FormShop.cs @@ -0,0 +1,118 @@ +using AutoWorkshopContracts.BindingModels; +using AutoWorkshopContracts.BusinessLogicsContracts; +using AutoWorkshopContracts.SearchModels; +using Microsoft.Extensions.Logging; + +namespace AutoWorkshopView.Forms.Shop +{ + public partial class FormShop : Form + { + private readonly ILogger _logger; + private readonly IShopLogic _logic; + private int? _id; + public int Id { set { _id = value; } } + private Dictionary _ShopRepairs; + private DateTime? _openingDate = null; + + public FormShop(ILogger logger, IShopLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + _ShopRepairs = new Dictionary(); + } + + private void FormShop_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + _logger.LogInformation("Загрузка магазина"); + try + { + var view = _logic.ReadElement(new ShopSearchModel + { + Id = _id.Value + }); + if (view != null) + { + textBoxName.Text = view.ShopName; + textBoxAdress.Text = view.Adress; + dateTimeOpen.Value = view.OpeningDate; + _ShopRepairs = view.ShopRepairs ?? new Dictionary(); + LoadData(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки магазина"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void LoadData() + { + _logger.LogInformation("Загрузка изделий в магазине"); + try + { + if (_ShopRepairs != null) + { + dataGridView.Rows.Clear(); + foreach (var sr in _ShopRepairs) + { + dataGridView.Rows.Add(new object[] { sr.Key, sr.Value.Item1.RepairName, sr.Value.Item2 }); + } + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки изделий магазина"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxAdress.Text)) + { + MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение магазина"); + try + { + var model = new ShopBindingModel + { + Id = _id ?? 0, + ShopName = textBoxName.Text, + Adress = textBoxAdress.Text, + OpeningDate = dateTimeOpen.Value + }; + var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения магазина"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/AutoWorkshopView/Forms/Shop/FormShop.resx b/AutoWorkshopView/Forms/Shop/FormShop.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/AutoWorkshopView/Forms/Shop/FormShop.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/AutoWorkshopView/Forms/Shop/FormShops.Designer.cs b/AutoWorkshopView/Forms/Shop/FormShops.Designer.cs new file mode 100644 index 0000000..4a2cac3 --- /dev/null +++ b/AutoWorkshopView/Forms/Shop/FormShops.Designer.cs @@ -0,0 +1,130 @@ +namespace AutoWorkshopView.Forms.Shop +{ + partial class FormShops + { + /// + /// 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() + { + ToolsPanel = new System.Windows.Forms.Panel(); + buttonRef = new System.Windows.Forms.Button(); + buttonDel = new System.Windows.Forms.Button(); + buttonUpd = new System.Windows.Forms.Button(); + buttonAdd = new System.Windows.Forms.Button(); + dataGridView = new System.Windows.Forms.DataGridView(); + ToolsPanel.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(dataGridView)).BeginInit(); + SuspendLayout(); + // + // ToolsPanel + // + ToolsPanel.Controls.Add(buttonRef); + ToolsPanel.Controls.Add(buttonDel); + ToolsPanel.Controls.Add(buttonUpd); + ToolsPanel.Controls.Add(buttonAdd); + ToolsPanel.Location = new System.Drawing.Point(608, 12); + ToolsPanel.Name = "ToolsPanel"; + ToolsPanel.Size = new System.Drawing.Size(180, 426); + ToolsPanel.TabIndex = 3; + // + // buttonRef + // + buttonRef.Location = new System.Drawing.Point(31, 206); + buttonRef.Name = "buttonRef"; + buttonRef.Size = new System.Drawing.Size(126, 36); + buttonRef.TabIndex = 3; + buttonRef.Text = "Обновить"; + buttonRef.UseVisualStyleBackColor = true; + buttonRef.Click += new System.EventHandler(ButtonRef_Click); + // + // buttonDel + // + buttonDel.Location = new System.Drawing.Point(31, 142); + buttonDel.Name = "buttonDel"; + buttonDel.Size = new System.Drawing.Size(126, 36); + buttonDel.TabIndex = 2; + buttonDel.Text = "Удалить"; + buttonDel.UseVisualStyleBackColor = true; + buttonDel.Click += new System.EventHandler(ButtonDel_Click); + // + // buttonUpd + // + buttonUpd.Location = new System.Drawing.Point(31, 76); + buttonUpd.Name = "buttonUpd"; + buttonUpd.Size = new System.Drawing.Size(126, 36); + buttonUpd.TabIndex = 1; + buttonUpd.Text = "Изменить"; + buttonUpd.UseVisualStyleBackColor = true; + buttonUpd.Click += new System.EventHandler(ButtonUpd_Click); + // + // buttonAdd + // + buttonAdd.Location = new System.Drawing.Point(31, 16); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new System.Drawing.Size(126, 36); + buttonAdd.TabIndex = 0; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += new System.EventHandler(ButtonAdd_Click); + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new System.Drawing.Point(12, 12); + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 29; + dataGridView.Size = new System.Drawing.Size(590, 426); + dataGridView.TabIndex = 2; + // + // FormShops + // + AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + ClientSize = new System.Drawing.Size(800, 450); + Controls.Add(ToolsPanel); + Controls.Add(dataGridView); + Name = "FormShops"; + Text = "Магазины"; + Load += new System.EventHandler(FormShops_Load); + ToolsPanel.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(dataGridView)).EndInit(); + ResumeLayout(false); + + } + + #endregion + + private Panel ToolsPanel; + private Button buttonRef; + private Button buttonDel; + private Button buttonUpd; + private Button buttonAdd; + private DataGridView dataGridView; + } +} \ No newline at end of file diff --git a/AutoWorkshopView/Forms/Shop/FormShops.cs b/AutoWorkshopView/Forms/Shop/FormShops.cs new file mode 100644 index 0000000..ffebdd6 --- /dev/null +++ b/AutoWorkshopView/Forms/Shop/FormShops.cs @@ -0,0 +1,107 @@ +using AutoWorkshopContracts.BindingModels; +using AutoWorkshopContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; + +namespace AutoWorkshopView.Forms.Shop +{ + public partial class FormShops : Form + { + private readonly ILogger _logger; + private readonly IShopLogic _logic; + + public FormShops(ILogger logger, IShopLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormShops_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["ShopRepairs"].Visible = false; + dataGridView.Columns["ShopName"].AutoSizeMode = + DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка магазинов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки магазинов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShop)); + if (service is FormShop form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + + private void ButtonUpd_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShop)); + if (service is FormShop form) + { + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + + private void ButtonDel_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Удаление магазина"); + try + { + if (!_logic.Delete(new ShopBindingModel + { + Id = id + })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления магазина"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/AutoWorkshopView/Forms/Shop/FormShops.resx b/AutoWorkshopView/Forms/Shop/FormShops.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/AutoWorkshopView/Forms/Shop/FormShops.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 -- 2.25.1 From 57d43005e6e9c2edc815cec7a0140395674d4eff Mon Sep 17 00:00:00 2001 From: Oleg Shabunov Date: Tue, 9 Apr 2024 22:14:14 +0400 Subject: [PATCH 4/5] fix BusinessLogic --- .../BusinessLogics/ShopLogic.cs | 178 +++++++++--------- 1 file changed, 90 insertions(+), 88 deletions(-) diff --git a/AutoWorkshopBusinessLogic/BusinessLogics/ShopLogic.cs b/AutoWorkshopBusinessLogic/BusinessLogics/ShopLogic.cs index 995d417..632228d 100644 --- a/AutoWorkshopBusinessLogic/BusinessLogics/ShopLogic.cs +++ b/AutoWorkshopBusinessLogic/BusinessLogics/ShopLogic.cs @@ -1,157 +1,159 @@ -using Microsoft.Extensions.Logging; -using PizzeriaContracts.BindingModels; -using PizzeriaContracts.BusinessLogicsContracts; -using PizzeriaContracts.SearchModels; -using PizzeriaContracts.StoragesContracts; -using PizzeriaContracts.ViewModels; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using AutoWorkshopContracts.BindingModels; +using AutoWorkshopContracts.BusinessLogicsContracts; +using AutoWorkshopContracts.SearchModels; +using AutoWorkshopContracts.StoragesContracts; +using AutoWorkshopContracts.ViewModels; +using Microsoft.Extensions.Logging; -namespace PizzeriaBusinessLogic.BusinessLogics +namespace AutoWorkshopBusinessLogic.BusinessLogics { public class ShopLogic : IShopLogic { private readonly ILogger _logger; private readonly IShopStorage _shopStorage; - private readonly IPizzaStorage _pizzaStorage; + private readonly IRepairStorage _repairStorage; - public ShopLogic(ILogger logger, IShopStorage shopStorage, IPizzaStorage pizzaStorage) + public ShopLogic(ILogger Logger, IShopStorage ShopStorage, IRepairStorage RepairStorage) { - _logger = logger; - _shopStorage = shopStorage; - _pizzaStorage = pizzaStorage; + _logger = Logger; + _shopStorage = ShopStorage; + _repairStorage = RepairStorage; } - public List? ReadList(ShopSearchModel? model) + public List? ReadList(ShopSearchModel? Model) { - _logger.LogInformation("ReadList. ShopName:{ShopName}.Id:{ Id}", model?.ShopName, model?.Id); - var list = model == null ? _shopStorage.GetFullList() : _shopStorage.GetFilteredList(model); - if (list == null) + _logger.LogInformation("ReadList. ShopName:{ShopName}.Id:{ Id}", Model?.ShopName, Model?.Id); + + var List = Model == null ? _shopStorage.GetFullList() : _shopStorage.GetFilteredList(Model); + + if (List == null) { _logger.LogWarning("ReadList return null list"); return null; } - _logger.LogInformation("ReadList. Count:{Count}", list.Count); - return list; + + _logger.LogInformation("ReadList. Count:{Count}", List.Count); + return List; } - public ShopViewModel? ReadElement(ShopSearchModel model) + public ShopViewModel? ReadElement(ShopSearchModel Model) { - if (model == null) - { - throw new ArgumentNullException(nameof(model)); - } - _logger.LogInformation("ReadElement. ShopName:{ShopName}.Id:{ Id}", model.ShopName, model.Id); - var element = _shopStorage.GetElement(model); - if (element == null) + if (Model == null) + throw new ArgumentNullException(nameof(Model)); + + _logger.LogInformation("ReadElement. ShopName:{ShopName}.Id:{ Id}", Model.ShopName, Model.Id); + + var Element = _shopStorage.GetElement(Model); + if (Element == null) { _logger.LogWarning("ReadElement element not found"); return null; } - _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); - return element; + + _logger.LogInformation("ReadElement find. Id:{Id}", Element.Id); + return Element; } - public bool Create(ShopBindingModel model) + public bool Create(ShopBindingModel Model) { - CheckModel(model); - if (_shopStorage.Insert(model) == null) + CheckModel(Model); + + if (_shopStorage.Insert(Model) == null) { _logger.LogWarning("Insert operation failed"); return false; } + return true; } - public bool Update(ShopBindingModel model) + public bool Update(ShopBindingModel Model) { - CheckModel(model); - if (_shopStorage.Update(model) == null) + CheckModel(Model); + + if (_shopStorage.Update(Model) == null) { _logger.LogWarning("Update operation failed"); return false; } + return true; } - public bool Delete(ShopBindingModel model) + public bool Delete(ShopBindingModel Model) { - CheckModel(model, false); - _logger.LogInformation("Delete. Id:{Id}", model.Id); - if (_shopStorage.Delete(model) == null) + CheckModel(Model, false); + _logger.LogInformation("Delete. Id:{Id}", Model.Id); + + if (_shopStorage.Delete(Model) == null) { _logger.LogWarning("Delete operation failed"); return false; } + return true; } - public bool MakeSupply(SupplyBindingModel model) + public bool MakeSupply(SupplyBindingModel Model) { - if (model == null) + if (Model == null) + throw new ArgumentNullException(nameof(Model)); + + if (Model.Count <= 0) + throw new ArgumentException("Количество ремонтов должно быть больше 0"); + + var Shop = _shopStorage.GetElement(new ShopSearchModel { - throw new ArgumentNullException(nameof(model)); - } - if (model.Count <= 0) - { - throw new ArgumentException("Количество изделий должно быть больше 0"); - } - var shop = _shopStorage.GetElement(new ShopSearchModel - { - Id = model.ShopId + Id = Model.ShopId }); - if (shop == null) - { + + if (Shop == null) throw new ArgumentException("Магазина не существует"); - } - if (shop.ShopPizzas.ContainsKey(model.PizzaId)) + + if (Shop.ShopRepairs.ContainsKey(Model.RepairId)) { - var oldValue = shop.ShopPizzas[model.PizzaId]; - oldValue.Item2 += model.Count; - shop.ShopPizzas[model.PizzaId] = oldValue; + var OldValue = Shop.ShopRepairs[Model.RepairId]; + OldValue.Item2 += Model.Count; + Shop.ShopRepairs[Model.RepairId] = OldValue; } else { - var pizza = _pizzaStorage.GetElement(new PizzaSearchModel + var Repair = _repairStorage.GetElement(new RepairSearchModel { - Id = model.PizzaId + Id = Model.RepairId }); - if (pizza == null) - { - throw new ArgumentException($"Поставка: Товар с id:{model.PizzaId} не найденн"); - } - shop.ShopPizzas.Add(model.PizzaId, (pizza, model.Count)); + + if (Repair == null) + throw new ArgumentException($"Поставка: Товар с id:{Model.RepairId} не найденн"); + + Shop.ShopRepairs.Add(Model.RepairId, (Repair, Model.Count)); } + return true; } - private void CheckModel(ShopBindingModel model, bool withParams = true) + private void CheckModel(ShopBindingModel Model, bool WithParams=true) { - if (model == null) - { - throw new ArgumentNullException(nameof(model)); - } - if (!withParams) - { + if (Model == null) + throw new ArgumentNullException(nameof(Model)); + + if (!WithParams) return; - } - if (string.IsNullOrEmpty(model.Adress)) + + if (string.IsNullOrEmpty(Model.Address)) + throw new ArgumentException("Адрес магазина длжен быть заполнен", nameof(Model.Address)); + + if (string.IsNullOrEmpty(Model.ShopName)) + throw new ArgumentException("Название магазина должно быть заполнено", nameof(Model.ShopName)); + + _logger.LogInformation("Shop. ShopName: {ShopName}. Address: {Address}. OpeningDate: {OpeningDate}. Id:{Id}", + Model.ShopName, Model.Address, Model.OpeningDate, Model.Id); + + var Element = _shopStorage.GetElement(new ShopSearchModel { - throw new ArgumentException("Адрес магазина длжен быть заполнен", nameof(model.Adress)); - } - if (string.IsNullOrEmpty(model.ShopName)) - { - throw new ArgumentException("Название магазина должно быть заполнено", nameof(model.ShopName)); - } - _logger.LogInformation("Shop. ShopName:{ShopName}.Address:{Address}.OpeningDate:{OpeningDate}.Id:{ Id}", model.ShopName, model.Adress, model.OpeningDate, model.Id); - var element = _shopStorage.GetElement(new ShopSearchModel - { - ShopName = model.ShopName + ShopName = Model.ShopName }); - if (element != null && element.Id != model.Id) + if (Element != null && Element.Id != Model.Id) { throw new InvalidOperationException("Магазин с таким названием уже есть"); } -- 2.25.1 From b4d4b6d0f447bd0d060dddf53461d83a77745c4b Mon Sep 17 00:00:00 2001 From: Oleg Shabunov Date: Tue, 9 Apr 2024 22:58:05 +0400 Subject: [PATCH 5/5] done Forms/Shop --- .../Forms/Shop/FormCreateSupply.Designer.cs | 177 ++++++------ .../Forms/Shop/FormCreateSupply.cs | 60 +++-- .../Forms/Shop/FormCreateSupply.resx | 50 ++-- .../Forms/Shop/FormShop.Designer.cs | 253 +++++++++--------- AutoWorkshopView/Forms/Shop/FormShop.cs | 67 +++-- AutoWorkshopView/Forms/Shop/FormShop.resx | 50 ++-- .../Forms/Shop/FormShops.Designer.cs | 142 +++++----- AutoWorkshopView/Forms/Shop/FormShops.cs | 60 +++-- AutoWorkshopView/Forms/Shop/FormShops.resx | 50 ++-- AutoWorkshopView/MainForm.Designer.cs | 33 ++- AutoWorkshopView/MainForm.cs | 21 ++ AutoWorkshopView/Program.cs | 8 + 12 files changed, 539 insertions(+), 432 deletions(-) diff --git a/AutoWorkshopView/Forms/Shop/FormCreateSupply.Designer.cs b/AutoWorkshopView/Forms/Shop/FormCreateSupply.Designer.cs index ee3fdc7..69a5844 100644 --- a/AutoWorkshopView/Forms/Shop/FormCreateSupply.Designer.cs +++ b/AutoWorkshopView/Forms/Shop/FormCreateSupply.Designer.cs @@ -20,118 +20,127 @@ base.Dispose(disposing); } + #region Windows Form Designer generated code + private void InitializeComponent() { - comboBoxShop = new System.Windows.Forms.ComboBox(); - labelShop = new System.Windows.Forms.Label(); - labelRepair = new System.Windows.Forms.Label(); - comboBoxRepair = new System.Windows.Forms.ComboBox(); - labelCount = new System.Windows.Forms.Label(); - textBoxCount = new System.Windows.Forms.TextBox(); - buttonCancel = new System.Windows.Forms.Button(); - buttonSave = new System.Windows.Forms.Button(); + ShopComboBox = new ComboBox(); + ShopLabel = new Label(); + RepairLabel = new Label(); + RepairComboBox = new ComboBox(); + CountLabel = new Label(); + CountTextbox = new TextBox(); + CancelButton = new Button(); + SaveButton = new Button(); SuspendLayout(); // - // comboBoxShop + // ShopComboBox // - comboBoxShop.FormattingEnabled = true; - comboBoxShop.Location = new System.Drawing.Point(115, 12); - comboBoxShop.Name = "comboBoxShop"; - comboBoxShop.Size = new System.Drawing.Size(344, 28); - comboBoxShop.TabIndex = 0; + ShopComboBox.DropDownStyle = ComboBoxStyle.DropDownList; + ShopComboBox.FormattingEnabled = true; + ShopComboBox.Location = new Point(101, 9); + ShopComboBox.Margin = new Padding(3, 2, 3, 2); + ShopComboBox.Name = "ShopComboBox"; + ShopComboBox.Size = new Size(302, 23); + ShopComboBox.TabIndex = 0; // - // labelShop + // ShopLabel // - labelShop.AutoSize = true; - labelShop.Location = new System.Drawing.Point(12, 15); - labelShop.Name = "labelShop"; - labelShop.Size = new System.Drawing.Size(76, 20); - labelShop.TabIndex = 1; - labelShop.Text = "Магазин: "; + ShopLabel.AutoSize = true; + ShopLabel.Location = new Point(10, 12); + ShopLabel.Name = "ShopLabel"; + ShopLabel.Size = new Size(60, 15); + ShopLabel.TabIndex = 1; + ShopLabel.Text = "Магазин: "; // - // labelRepair + // RepairLabel // - labelRepair.AutoSize = true; - labelRepair.Location = new System.Drawing.Point(12, 49); - labelRepair.Name = "labelRepair"; - labelRepair.Size = new System.Drawing.Size(75, 20); - labelRepair.TabIndex = 2; - labelRepair.Text = "Изделие: "; + RepairLabel.AutoSize = true; + RepairLabel.Location = new Point(11, 39); + RepairLabel.Name = "RepairLabel"; + RepairLabel.Size = new Size(51, 15); + RepairLabel.TabIndex = 2; + RepairLabel.Text = "Ремонт:"; // - // comboBoxRepair + // RepairComboBox // - comboBoxRepair.FormattingEnabled = true; - comboBoxRepair.Location = new System.Drawing.Point(115, 46); - comboBoxRepair.Name = "comboBoxRepair"; - comboBoxRepair.Size = new System.Drawing.Size(344, 28); - comboBoxRepair.TabIndex = 3; + RepairComboBox.DropDownStyle = ComboBoxStyle.DropDownList; + RepairComboBox.FormattingEnabled = true; + RepairComboBox.Location = new Point(101, 36); + RepairComboBox.Margin = new Padding(3, 2, 3, 2); + RepairComboBox.Name = "RepairComboBox"; + RepairComboBox.Size = new Size(302, 23); + RepairComboBox.TabIndex = 3; // - // labelCount + // CountLabel // - labelCount.AutoSize = true; - labelCount.Location = new System.Drawing.Point(12, 83); - labelCount.Name = "labelCount"; - labelCount.Size = new System.Drawing.Size(97, 20); - labelCount.TabIndex = 4; - labelCount.Text = "Количество: "; + CountLabel.AutoSize = true; + CountLabel.Location = new Point(11, 66); + CountLabel.Name = "CountLabel"; + CountLabel.Size = new Size(78, 15); + CountLabel.TabIndex = 4; + CountLabel.Text = "Количество: "; // - // textBoxCount + // CountTextbox // - textBoxCount.Location = new System.Drawing.Point(115, 80); - textBoxCount.Name = "textBoxCount"; - textBoxCount.Size = new System.Drawing.Size(344, 27); - textBoxCount.TabIndex = 5; + CountTextbox.Location = new Point(101, 63); + CountTextbox.Margin = new Padding(3, 2, 3, 2); + CountTextbox.Name = "CountTextbox"; + CountTextbox.Size = new Size(302, 23); + CountTextbox.TabIndex = 5; // - // buttonCancel + // CancelButton // - buttonCancel.Location = new System.Drawing.Point(300, 113); - buttonCancel.Name = "buttonCancel"; - buttonCancel.Size = new System.Drawing.Size(116, 39); - buttonCancel.TabIndex = 6; - buttonCancel.Text = "Отмена"; - buttonCancel.UseVisualStyleBackColor = true; - buttonCancel.Click += new System.EventHandler(ButtonCancel_Click); + CancelButton.Location = new Point(301, 100); + CancelButton.Margin = new Padding(3, 2, 3, 2); + CancelButton.Name = "CancelButton"; + CancelButton.Size = new Size(102, 29); + CancelButton.TabIndex = 6; + CancelButton.Text = "Отмена"; + CancelButton.UseVisualStyleBackColor = true; + CancelButton.Click += CancelButton_Click; // - // buttonSave + // SaveButton // - buttonSave.Location = new System.Drawing.Point(168, 113); - buttonSave.Name = "buttonSave"; - buttonSave.Size = new System.Drawing.Size(116, 39); - buttonSave.TabIndex = 7; - buttonSave.Text = "Сохранить"; - buttonSave.UseVisualStyleBackColor = true; - buttonSave.Click += new System.EventHandler(ButtonSave_Click); + SaveButton.Location = new Point(183, 100); + SaveButton.Margin = new Padding(3, 2, 3, 2); + SaveButton.Name = "SaveButton"; + SaveButton.Size = new Size(102, 29); + SaveButton.TabIndex = 7; + SaveButton.Text = "Сохранить"; + SaveButton.UseVisualStyleBackColor = true; + SaveButton.Click += SaveButton_Click; // // FormCreateSupply // - AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); - AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - ClientSize = new System.Drawing.Size(471, 164); - Controls.Add(buttonSave); - Controls.Add(buttonCancel); - Controls.Add(textBoxCount); - Controls.Add(labelCount); - Controls.Add(comboBoxRepair); - Controls.Add(labelRepair); - Controls.Add(labelShop); - Controls.Add(comboBoxShop); + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(417, 143); + Controls.Add(SaveButton); + Controls.Add(CancelButton); + Controls.Add(CountTextbox); + Controls.Add(CountLabel); + Controls.Add(RepairComboBox); + Controls.Add(RepairLabel); + Controls.Add(ShopLabel); + Controls.Add(ShopComboBox); + Margin = new Padding(3, 2, 3, 2); Name = "FormCreateSupply"; Text = "Создание поставки"; - Load += new System.EventHandler(FormCreateSupply_Load); + Load += FormCreateSupply_Load; ResumeLayout(false); PerformLayout(); - } -#endregion + #endregion - private ComboBox comboBoxShop; - private Label labelShop; - private Label labelRepair; - private ComboBox comboBoxRepair; - private Label labelCount; - private TextBox textBoxCount; - private Button buttonCancel; - private Button buttonSave; + private ComboBox ShopComboBox; + private Label ShopLabel; + private Label RepairLabel; + private ComboBox RepairComboBox; + private Label CountLabel; + private TextBox CountTextbox; + private Button CancelButton; + private Button SaveButton; } } \ No newline at end of file diff --git a/AutoWorkshopView/Forms/Shop/FormCreateSupply.cs b/AutoWorkshopView/Forms/Shop/FormCreateSupply.cs index ab98827..f9afb68 100644 --- a/AutoWorkshopView/Forms/Shop/FormCreateSupply.cs +++ b/AutoWorkshopView/Forms/Shop/FormCreateSupply.cs @@ -1,4 +1,5 @@ using AutoWorkshopContracts.BindingModels; +using AutoWorkshopContracts.BusinessLogicContracts; using AutoWorkshopContracts.BusinessLogicsContracts; using AutoWorkshopContracts.ViewModels; using Microsoft.Extensions.Logging; @@ -8,68 +9,77 @@ namespace AutoWorkshopView.Forms.Shop public partial class FormCreateSupply : Form { private readonly ILogger _logger; - private readonly IRepairLogic _logicP; - private readonly IShopLogic _logicS; + private readonly IRepairLogic _repairLogic; + private readonly IShopLogic _shopLogic; private List _shopList = new List(); private List _RepairList = new List(); - public FormCreateSupply(ILogger logger, IRepairLogic logicP, IShopLogic logicS) + public FormCreateSupply(ILogger Logger, IRepairLogic RepairLogic, IShopLogic ShopLogic) { InitializeComponent(); - _logger = logger; - _logicP = logicP; - _logicS = logicS; + + _logger = Logger; + _repairLogic = RepairLogic; + _shopLogic = ShopLogic; } private void FormCreateSupply_Load(object sender, EventArgs e) { - _shopList = _logicS.ReadList(null); - _RepairList = _logicP.ReadList(null); + _shopList = _shopLogic.ReadList(null); + _RepairList = _repairLogic.ReadList(null); + if (_shopList != null) { - comboBoxShop.DisplayMember = "ShopName"; - comboBoxShop.ValueMember = "Id"; - comboBoxShop.DataSource = _shopList; - comboBoxShop.SelectedItem = null; + ShopComboBox.DisplayMember = "ShopName"; + ShopComboBox.ValueMember = "Id"; + ShopComboBox.DataSource = _shopList; + ShopComboBox.SelectedItem = null; _logger.LogInformation("Загрузка магазинов для поставок"); } + if (_RepairList != null) { - comboBoxRepair.DisplayMember = "RepairName"; - comboBoxRepair.ValueMember = "Id"; - comboBoxRepair.DataSource = _RepairList; - comboBoxRepair.SelectedItem = null; + RepairComboBox.DisplayMember = "RepairName"; + RepairComboBox.ValueMember = "Id"; + RepairComboBox.DataSource = _RepairList; + RepairComboBox.SelectedItem = null; _logger.LogInformation("Загрузка ремонтов для поставок"); } } - private void ButtonSave_Click(object sender, EventArgs e) + private void SaveButton_Click(object sender, EventArgs e) { - if (comboBoxShop.SelectedValue == null) + if (ShopComboBox.SelectedValue == null) { MessageBox.Show("Выберите магазин", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } - if (comboBoxRepair.SelectedValue == null) + + if (RepairComboBox.SelectedValue == null) { MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } + _logger.LogInformation("Создание поставки"); + try { - var operationResult = _logicS.MakeSupply(new SupplyBindingModel + var OperationResult = _shopLogic.MakeSupply(new SupplyBindingModel { - ShopId = Convert.ToInt32(comboBoxShop.SelectedValue), - RepairId = Convert.ToInt32(comboBoxRepair.SelectedValue), - Count = Convert.ToInt32(textBoxCount.Text) + ShopId = Convert.ToInt32(ShopComboBox.SelectedValue), + RepairId = Convert.ToInt32(RepairComboBox.SelectedValue), + Count = Convert.ToInt32(CountTextbox.Text) }); - if (!operationResult) + + if (!OperationResult) { throw new Exception("Ошибка при создании поставки. Дополнительная информация в логах."); } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; Close(); } @@ -80,7 +90,7 @@ namespace AutoWorkshopView.Forms.Shop } } - private void ButtonCancel_Click(object sender, EventArgs e) + private void CancelButton_Click(object sender, EventArgs e) { DialogResult = DialogResult.Cancel; Close(); diff --git a/AutoWorkshopView/Forms/Shop/FormCreateSupply.resx b/AutoWorkshopView/Forms/Shop/FormCreateSupply.resx index 1af7de1..af32865 100644 --- a/AutoWorkshopView/Forms/Shop/FormCreateSupply.resx +++ b/AutoWorkshopView/Forms/Shop/FormCreateSupply.resx @@ -1,17 +1,17 @@  - diff --git a/AutoWorkshopView/Forms/Shop/FormShop.Designer.cs b/AutoWorkshopView/Forms/Shop/FormShop.Designer.cs index e740193..a564049 100644 --- a/AutoWorkshopView/Forms/Shop/FormShop.Designer.cs +++ b/AutoWorkshopView/Forms/Shop/FormShop.Designer.cs @@ -28,166 +28,169 @@ /// private void InitializeComponent() { - labelName = new System.Windows.Forms.Label(); - textBoxName = new System.Windows.Forms.TextBox(); - textBoxAdress = new System.Windows.Forms.TextBox(); - labelAdress = new System.Windows.Forms.Label(); - buttonCancel = new System.Windows.Forms.Button(); - buttonSave = new System.Windows.Forms.Button(); - dataGridView = new System.Windows.Forms.DataGridView(); - id = new System.Windows.Forms.DataGridViewTextBoxColumn(); - RepairName = new System.Windows.Forms.DataGridViewTextBoxColumn(); - Count = new System.Windows.Forms.DataGridViewTextBoxColumn(); - label1 = new System.Windows.Forms.Label(); - dateTimeOpen = new System.Windows.Forms.DateTimePicker(); - ((System.ComponentModel.ISupportInitialize)(dataGridView)).BeginInit(); + NameLabel = new Label(); + NameTextBox = new TextBox(); + AddressTextBox = new TextBox(); + AddressLabel = new Label(); + CancelButton = new Button(); + SaveButton = new Button(); + ViewDataGrid = new DataGridView(); + IdColumn = new DataGridViewTextBoxColumn(); + RepairNameColumn = new DataGridViewTextBoxColumn(); + CountColumn = new DataGridViewTextBoxColumn(); + OpeningDateLabel = new Label(); + OpenDateTimePicker = new DateTimePicker(); + ((System.ComponentModel.ISupportInitialize)ViewDataGrid).BeginInit(); SuspendLayout(); // - // labelName + // NameLabel // - labelName.AutoSize = true; - labelName.Location = new System.Drawing.Point(11, 15); - labelName.Name = "labelName"; - labelName.Size = new System.Drawing.Size(84, 20); - labelName.TabIndex = 0; - labelName.Text = "Название: "; + NameLabel.AutoSize = true; + NameLabel.Location = new Point(10, 12); + NameLabel.Name = "NameLabel"; + NameLabel.Size = new Size(65, 15); + NameLabel.TabIndex = 0; + NameLabel.Text = "Название: "; // - // textBoxName + // NameTextBox // - textBoxName.Location = new System.Drawing.Point(102, 12); - textBoxName.Name = "textBoxName"; - textBoxName.Size = new System.Drawing.Size(276, 27); - textBoxName.TabIndex = 1; + NameTextBox.Location = new Point(112, 9); + NameTextBox.Margin = new Padding(3, 2, 3, 2); + NameTextBox.Name = "NameTextBox"; + NameTextBox.Size = new Size(240, 23); + NameTextBox.TabIndex = 1; // - // textBoxAdress + // AddressTextBox // - textBoxAdress.Location = new System.Drawing.Point(102, 59); - textBoxAdress.Name = "textBoxAdress"; - textBoxAdress.Size = new System.Drawing.Size(427, 27); - textBoxAdress.TabIndex = 3; + AddressTextBox.Location = new Point(112, 36); + AddressTextBox.Margin = new Padding(3, 2, 3, 2); + AddressTextBox.Name = "AddressTextBox"; + AddressTextBox.Size = new Size(240, 23); + AddressTextBox.TabIndex = 3; // - // labelAdress + // AddressLabel // - labelAdress.AutoSize = true; - labelAdress.Location = new System.Drawing.Point(11, 61); - labelAdress.Name = "labelAdress"; - labelAdress.Size = new System.Drawing.Size(58, 20); - labelAdress.TabIndex = 2; - labelAdress.Text = "Адрес: "; + AddressLabel.AutoSize = true; + AddressLabel.Location = new Point(12, 39); + AddressLabel.Name = "AddressLabel"; + AddressLabel.Size = new Size(46, 15); + AddressLabel.TabIndex = 2; + AddressLabel.Text = "Адрес: "; // - // buttonCancel + // CancelButton // - buttonCancel.Location = new System.Drawing.Point(451, 457); - buttonCancel.Name = "buttonCancel"; - buttonCancel.Size = new System.Drawing.Size(130, 44); - buttonCancel.TabIndex = 5; - buttonCancel.Text = "Отмена"; - buttonCancel.UseVisualStyleBackColor = true; - buttonCancel.Click += new System.EventHandler(buttonCancel_Click); + CancelButton.Location = new Point(395, 343); + CancelButton.Margin = new Padding(3, 2, 3, 2); + CancelButton.Name = "CancelButton"; + CancelButton.Size = new Size(114, 33); + CancelButton.TabIndex = 5; + CancelButton.Text = "Отмена"; + CancelButton.UseVisualStyleBackColor = true; + CancelButton.Click += CancelButton_Click; // - // buttonSave + // SaveButton // - buttonSave.Location = new System.Drawing.Point(315, 457); - buttonSave.Name = "buttonSave"; - buttonSave.Size = new System.Drawing.Size(130, 44); - buttonSave.TabIndex = 6; - buttonSave.Text = "Сохранить"; - buttonSave.UseVisualStyleBackColor = true; - buttonSave.Click += new System.EventHandler(buttonSave_Click); + SaveButton.Location = new Point(276, 343); + SaveButton.Margin = new Padding(3, 2, 3, 2); + SaveButton.Name = "SaveButton"; + SaveButton.Size = new Size(114, 33); + SaveButton.TabIndex = 6; + SaveButton.Text = "Сохранить"; + SaveButton.UseVisualStyleBackColor = true; + SaveButton.Click += SaveButton_Click; // - // dataGridView + // ViewDataGrid // - dataGridView.AllowUserToAddRows = false; - dataGridView.AllowUserToDeleteRows = false; - dataGridView.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill; - dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; - dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { - id, - RepairName, - Count}); - dataGridView.Location = new System.Drawing.Point(12, 144); - dataGridView.Name = "dataGridView"; - dataGridView.ReadOnly = true; - dataGridView.RowHeadersBorderStyle = System.Windows.Forms.DataGridViewHeaderBorderStyle.None; - dataGridView.RowHeadersWidthSizeMode = System.Windows.Forms.DataGridViewRowHeadersWidthSizeMode.AutoSizeToDisplayedHeaders; - dataGridView.RowTemplate.Height = 29; - dataGridView.Size = new System.Drawing.Size(569, 307); - dataGridView.TabIndex = 7; + ViewDataGrid.AllowUserToAddRows = false; + ViewDataGrid.AllowUserToDeleteRows = false; + ViewDataGrid.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + ViewDataGrid.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + ViewDataGrid.Columns.AddRange(new DataGridViewColumn[] { IdColumn, RepairNameColumn, CountColumn }); + ViewDataGrid.Location = new Point(10, 108); + ViewDataGrid.Margin = new Padding(3, 2, 3, 2); + ViewDataGrid.Name = "ViewDataGrid"; + ViewDataGrid.ReadOnly = true; + ViewDataGrid.RowHeadersBorderStyle = DataGridViewHeaderBorderStyle.None; + ViewDataGrid.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.AutoSizeToDisplayedHeaders; + ViewDataGrid.RowTemplate.Height = 29; + ViewDataGrid.Size = new Size(498, 230); + ViewDataGrid.TabIndex = 7; // - // id + // IdColumn // - id.HeaderText = "id"; - id.MinimumWidth = 6; - id.Name = "id"; - id.ReadOnly = true; - id.Visible = false; + IdColumn.HeaderText = "Id"; + IdColumn.MinimumWidth = 6; + IdColumn.Name = "IdColumn"; + IdColumn.ReadOnly = true; + IdColumn.Visible = false; // - // RepairName + // RepairNameColumn // - RepairName.HeaderText = "Ремонт"; - RepairName.MinimumWidth = 6; - RepairName.Name = "RepairName"; - RepairName.ReadOnly = true; + RepairNameColumn.HeaderText = "Ремонт"; + RepairNameColumn.MinimumWidth = 6; + RepairNameColumn.Name = "RepairNameColumn"; + RepairNameColumn.ReadOnly = true; // - // Count + // CountColumn // - Count.HeaderText = "Количество"; - Count.MinimumWidth = 6; - Count.Name = "Count"; - Count.ReadOnly = true; + CountColumn.HeaderText = "Количество"; + CountColumn.MinimumWidth = 6; + CountColumn.Name = "CountColumn"; + CountColumn.ReadOnly = true; // - // label1 + // OpeningDateLabel // - label1.AutoSize = true; - label1.Location = new System.Drawing.Point(12, 103); - label1.Name = "label1"; - label1.Size = new System.Drawing.Size(110, 20); - label1.TabIndex = 8; - label1.Text = "Дата открытия"; + OpeningDateLabel.AutoSize = true; + OpeningDateLabel.Location = new Point(10, 69); + OpeningDateLabel.Name = "OpeningDateLabel"; + OpeningDateLabel.Size = new Size(87, 15); + OpeningDateLabel.TabIndex = 8; + OpeningDateLabel.Text = "Дата открытия"; // - // dateTimeOpen + // OpenDateTimePicker // - dateTimeOpen.Location = new System.Drawing.Point(128, 103); - dateTimeOpen.Name = "dateTimeOpen"; - dateTimeOpen.Size = new System.Drawing.Size(401, 27); - dateTimeOpen.TabIndex = 9; + OpenDateTimePicker.Location = new Point(112, 63); + OpenDateTimePicker.Margin = new Padding(3, 2, 3, 2); + OpenDateTimePicker.Name = "OpenDateTimePicker"; + OpenDateTimePicker.Size = new Size(240, 23); + OpenDateTimePicker.TabIndex = 9; // // FormShop // - AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); - AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - ClientSize = new System.Drawing.Size(593, 513); - Controls.Add(dateTimeOpen); - Controls.Add(label1); - Controls.Add(dataGridView); - Controls.Add(buttonSave); - Controls.Add(buttonCancel); - Controls.Add(textBoxAdress); - Controls.Add(labelAdress); - Controls.Add(textBoxName); - Controls.Add(labelName); + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(519, 385); + Controls.Add(OpenDateTimePicker); + Controls.Add(OpeningDateLabel); + Controls.Add(ViewDataGrid); + Controls.Add(SaveButton); + Controls.Add(CancelButton); + Controls.Add(AddressTextBox); + Controls.Add(AddressLabel); + Controls.Add(NameTextBox); + Controls.Add(NameLabel); + Margin = new Padding(3, 2, 3, 2); Name = "FormShop"; Text = "Магазин"; - Load += new System.EventHandler(FormShop_Load); - ((System.ComponentModel.ISupportInitialize)(dataGridView)).EndInit(); + Load += FormShop_Load; + ((System.ComponentModel.ISupportInitialize)ViewDataGrid).EndInit(); ResumeLayout(false); PerformLayout(); - } #endregion - private Label labelName; - private TextBox textBoxName; - private TextBox textBoxAdress; - private Label labelAdress; - private Button buttonCancel; - private Button buttonSave; - private DataGridView dataGridView; - private DataGridViewTextBoxColumn id; - private DataGridViewTextBoxColumn RepairName; - private DataGridViewTextBoxColumn Count; - private Label label1; - private DateTimePicker dateTimeOpen; + private Label NameLabel; + private TextBox NameTextBox; + private TextBox AddressTextBox; + private Label AddressLabel; + private Button CancelButton; + private Button SaveButton; + private DataGridView ViewDataGrid; + private DataGridViewTextBoxColumn IdColumn; + private DataGridViewTextBoxColumn RepairNameColumn; + private DataGridViewTextBoxColumn CountColumn; + private Label OpeningDateLabel; + private DateTimePicker OpenDateTimePicker; } } \ No newline at end of file diff --git a/AutoWorkshopView/Forms/Shop/FormShop.cs b/AutoWorkshopView/Forms/Shop/FormShop.cs index 5c81e21..deaf15f 100644 --- a/AutoWorkshopView/Forms/Shop/FormShop.cs +++ b/AutoWorkshopView/Forms/Shop/FormShop.cs @@ -1,6 +1,7 @@ using AutoWorkshopContracts.BindingModels; using AutoWorkshopContracts.BusinessLogicsContracts; using AutoWorkshopContracts.SearchModels; +using AutoWorkshopDataModels.Models; using Microsoft.Extensions.Logging; namespace AutoWorkshopView.Forms.Shop @@ -9,17 +10,21 @@ namespace AutoWorkshopView.Forms.Shop { private readonly ILogger _logger; private readonly IShopLogic _logic; + private int? _id; + public int Id { set { _id = value; } } - private Dictionary _ShopRepairs; + + private Dictionary _shopRepairs; private DateTime? _openingDate = null; - public FormShop(ILogger logger, IShopLogic logic) + public FormShop(ILogger Logger, IShopLogic Logic) { InitializeComponent(); - _logger = logger; - _logic = logic; - _ShopRepairs = new Dictionary(); + + _logger = Logger; + _logic = Logic; + _shopRepairs = new Dictionary(); } private void FormShop_Load(object sender, EventArgs e) @@ -27,18 +32,21 @@ namespace AutoWorkshopView.Forms.Shop if (_id.HasValue) { _logger.LogInformation("Загрузка магазина"); + try { - var view = _logic.ReadElement(new ShopSearchModel + var View = _logic.ReadElement(new ShopSearchModel { Id = _id.Value }); - if (view != null) + + if (View != null) { - textBoxName.Text = view.ShopName; - textBoxAdress.Text = view.Adress; - dateTimeOpen.Value = view.OpeningDate; - _ShopRepairs = view.ShopRepairs ?? new Dictionary(); + NameTextBox.Text = View.ShopName; + AddressTextBox.Text = View.Address; + OpenDateTimePicker.Value = View.OpeningDate; + _shopRepairs = View.ShopRepairs ?? new Dictionary(); + LoadData(); } } @@ -52,15 +60,16 @@ namespace AutoWorkshopView.Forms.Shop private void LoadData() { - _logger.LogInformation("Загрузка изделий в магазине"); + _logger.LogInformation("Загрузка ремонтов в магазине"); + try { - if (_ShopRepairs != null) + if (_shopRepairs != null) { - dataGridView.Rows.Clear(); - foreach (var sr in _ShopRepairs) + ViewDataGrid.Rows.Clear(); + foreach (var ShopRepair in _shopRepairs) { - dataGridView.Rows.Add(new object[] { sr.Key, sr.Value.Item1.RepairName, sr.Value.Item2 }); + ViewDataGrid.Rows.Add(new object[] { ShopRepair.Key, ShopRepair.Value.Item1.RepairName, ShopRepair.Value.Item2 }); } } } @@ -71,35 +80,41 @@ namespace AutoWorkshopView.Forms.Shop } } - private void buttonSave_Click(object sender, EventArgs e) + private void SaveButton_Click(object sender, EventArgs e) { - if (string.IsNullOrEmpty(textBoxName.Text)) + if (string.IsNullOrEmpty(NameTextBox.Text)) { MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } - if (string.IsNullOrEmpty(textBoxAdress.Text)) + + if (string.IsNullOrEmpty(AddressTextBox.Text)) { MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } + _logger.LogInformation("Сохранение магазина"); + try { - var model = new ShopBindingModel + var Model = new ShopBindingModel { Id = _id ?? 0, - ShopName = textBoxName.Text, - Adress = textBoxAdress.Text, - OpeningDate = dateTimeOpen.Value + ShopName = NameTextBox.Text, + Address = AddressTextBox.Text, + OpeningDate = OpenDateTimePicker.Value }; - var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); - if (!operationResult) + + var OperationResult = _id.HasValue ? _logic.Update(Model) : _logic.Create(Model); + if (!OperationResult) { throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); DialogResult = DialogResult.OK; + Close(); } catch (Exception ex) @@ -109,7 +124,7 @@ namespace AutoWorkshopView.Forms.Shop } } - private void buttonCancel_Click(object sender, EventArgs e) + private void CancelButton_Click(object sender, EventArgs e) { DialogResult = DialogResult.Cancel; Close(); diff --git a/AutoWorkshopView/Forms/Shop/FormShop.resx b/AutoWorkshopView/Forms/Shop/FormShop.resx index 1af7de1..af32865 100644 --- a/AutoWorkshopView/Forms/Shop/FormShop.resx +++ b/AutoWorkshopView/Forms/Shop/FormShop.resx @@ -1,17 +1,17 @@  - diff --git a/AutoWorkshopView/Forms/Shop/FormShops.Designer.cs b/AutoWorkshopView/Forms/Shop/FormShops.Designer.cs index 4a2cac3..4e84a6b 100644 --- a/AutoWorkshopView/Forms/Shop/FormShops.Designer.cs +++ b/AutoWorkshopView/Forms/Shop/FormShops.Designer.cs @@ -28,103 +28,109 @@ /// private void InitializeComponent() { - ToolsPanel = new System.Windows.Forms.Panel(); - buttonRef = new System.Windows.Forms.Button(); - buttonDel = new System.Windows.Forms.Button(); - buttonUpd = new System.Windows.Forms.Button(); - buttonAdd = new System.Windows.Forms.Button(); - dataGridView = new System.Windows.Forms.DataGridView(); + ToolsPanel = new Panel(); + RefreshButton = new Button(); + DeleteButton = new Button(); + UpdateButton = new Button(); + AddButton = new Button(); + ViewDataGrid = new DataGridView(); ToolsPanel.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)(dataGridView)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)ViewDataGrid).BeginInit(); SuspendLayout(); // // ToolsPanel // - ToolsPanel.Controls.Add(buttonRef); - ToolsPanel.Controls.Add(buttonDel); - ToolsPanel.Controls.Add(buttonUpd); - ToolsPanel.Controls.Add(buttonAdd); - ToolsPanel.Location = new System.Drawing.Point(608, 12); + ToolsPanel.Controls.Add(RefreshButton); + ToolsPanel.Controls.Add(DeleteButton); + ToolsPanel.Controls.Add(UpdateButton); + ToolsPanel.Controls.Add(AddButton); + ToolsPanel.Location = new Point(532, 9); + ToolsPanel.Margin = new Padding(3, 2, 3, 2); ToolsPanel.Name = "ToolsPanel"; - ToolsPanel.Size = new System.Drawing.Size(180, 426); + ToolsPanel.Size = new Size(117, 320); ToolsPanel.TabIndex = 3; // - // buttonRef + // RefreshButton // - buttonRef.Location = new System.Drawing.Point(31, 206); - buttonRef.Name = "buttonRef"; - buttonRef.Size = new System.Drawing.Size(126, 36); - buttonRef.TabIndex = 3; - buttonRef.Text = "Обновить"; - buttonRef.UseVisualStyleBackColor = true; - buttonRef.Click += new System.EventHandler(ButtonRef_Click); + RefreshButton.Location = new Point(3, 105); + RefreshButton.Margin = new Padding(3, 2, 3, 2); + RefreshButton.Name = "RefreshButton"; + RefreshButton.Size = new Size(110, 27); + RefreshButton.TabIndex = 3; + RefreshButton.Text = "Обновить"; + RefreshButton.UseVisualStyleBackColor = true; + RefreshButton.Click += RefreshButton_Click; // - // buttonDel + // DeleteButton // - buttonDel.Location = new System.Drawing.Point(31, 142); - buttonDel.Name = "buttonDel"; - buttonDel.Size = new System.Drawing.Size(126, 36); - buttonDel.TabIndex = 2; - buttonDel.Text = "Удалить"; - buttonDel.UseVisualStyleBackColor = true; - buttonDel.Click += new System.EventHandler(ButtonDel_Click); + DeleteButton.Location = new Point(3, 74); + DeleteButton.Margin = new Padding(3, 2, 3, 2); + DeleteButton.Name = "DeleteButton"; + DeleteButton.Size = new Size(110, 27); + DeleteButton.TabIndex = 2; + DeleteButton.Text = "Удалить"; + DeleteButton.UseVisualStyleBackColor = true; + DeleteButton.Click += DeleteButton_Click; // - // buttonUpd + // UpdateButton // - buttonUpd.Location = new System.Drawing.Point(31, 76); - buttonUpd.Name = "buttonUpd"; - buttonUpd.Size = new System.Drawing.Size(126, 36); - buttonUpd.TabIndex = 1; - buttonUpd.Text = "Изменить"; - buttonUpd.UseVisualStyleBackColor = true; - buttonUpd.Click += new System.EventHandler(ButtonUpd_Click); + UpdateButton.Location = new Point(3, 43); + UpdateButton.Margin = new Padding(3, 2, 3, 2); + UpdateButton.Name = "UpdateButton"; + UpdateButton.Size = new Size(110, 27); + UpdateButton.TabIndex = 1; + UpdateButton.Text = "Изменить"; + UpdateButton.UseVisualStyleBackColor = true; + UpdateButton.Click += UpdateButton_Click; // - // buttonAdd + // AddButton // - buttonAdd.Location = new System.Drawing.Point(31, 16); - buttonAdd.Name = "buttonAdd"; - buttonAdd.Size = new System.Drawing.Size(126, 36); - buttonAdd.TabIndex = 0; - buttonAdd.Text = "Добавить"; - buttonAdd.UseVisualStyleBackColor = true; - buttonAdd.Click += new System.EventHandler(ButtonAdd_Click); + AddButton.Location = new Point(3, 12); + AddButton.Margin = new Padding(3, 2, 3, 2); + AddButton.Name = "AddButton"; + AddButton.Size = new Size(110, 27); + AddButton.TabIndex = 0; + AddButton.Text = "Добавить"; + AddButton.UseVisualStyleBackColor = true; + AddButton.Click += AddButton_Click; // - // dataGridView + // ViewDataGrid // - dataGridView.AllowUserToAddRows = false; - dataGridView.AllowUserToDeleteRows = false; - dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; - dataGridView.Location = new System.Drawing.Point(12, 12); - dataGridView.Name = "dataGridView"; - dataGridView.ReadOnly = true; - dataGridView.RowHeadersWidth = 51; - dataGridView.RowTemplate.Height = 29; - dataGridView.Size = new System.Drawing.Size(590, 426); - dataGridView.TabIndex = 2; + ViewDataGrid.AllowUserToAddRows = false; + ViewDataGrid.AllowUserToDeleteRows = false; + ViewDataGrid.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + ViewDataGrid.Location = new Point(10, 9); + ViewDataGrid.Margin = new Padding(3, 2, 3, 2); + ViewDataGrid.Name = "ViewDataGrid"; + ViewDataGrid.ReadOnly = true; + ViewDataGrid.RowHeadersWidth = 51; + ViewDataGrid.RowTemplate.Height = 29; + ViewDataGrid.Size = new Size(516, 320); + ViewDataGrid.TabIndex = 2; // // FormShops // - AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); - AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - ClientSize = new System.Drawing.Size(800, 450); + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(660, 338); Controls.Add(ToolsPanel); - Controls.Add(dataGridView); + Controls.Add(ViewDataGrid); + Margin = new Padding(3, 2, 3, 2); Name = "FormShops"; Text = "Магазины"; - Load += new System.EventHandler(FormShops_Load); + Load += FormShops_Load; ToolsPanel.ResumeLayout(false); - ((System.ComponentModel.ISupportInitialize)(dataGridView)).EndInit(); + ((System.ComponentModel.ISupportInitialize)ViewDataGrid).EndInit(); ResumeLayout(false); - } #endregion private Panel ToolsPanel; - private Button buttonRef; - private Button buttonDel; - private Button buttonUpd; - private Button buttonAdd; - private DataGridView dataGridView; + private Button RefreshButton; + private Button DeleteButton; + private Button UpdateButton; + private Button AddButton; + private DataGridView ViewDataGrid; } } \ No newline at end of file diff --git a/AutoWorkshopView/Forms/Shop/FormShops.cs b/AutoWorkshopView/Forms/Shop/FormShops.cs index ffebdd6..bfad6d7 100644 --- a/AutoWorkshopView/Forms/Shop/FormShops.cs +++ b/AutoWorkshopView/Forms/Shop/FormShops.cs @@ -9,11 +9,12 @@ namespace AutoWorkshopView.Forms.Shop private readonly ILogger _logger; private readonly IShopLogic _logic; - public FormShops(ILogger logger, IShopLogic logic) + public FormShops(ILogger Logger, IShopLogic Logic) { InitializeComponent(); - _logger = logger; - _logic = logic; + + _logger = Logger; + _logic = Logic; } private void FormShops_Load(object sender, EventArgs e) @@ -25,15 +26,16 @@ namespace AutoWorkshopView.Forms.Shop { try { - var list = _logic.ReadList(null); - if (list != null) + var List = _logic.ReadList(null); + + if (List != null) { - dataGridView.DataSource = list; - dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["ShopRepairs"].Visible = false; - dataGridView.Columns["ShopName"].AutoSizeMode = - DataGridViewAutoSizeColumnMode.Fill; + ViewDataGrid.DataSource = List; + ViewDataGrid.Columns["Id"].Visible = false; + ViewDataGrid.Columns["ShopRepairs"].Visible = false; + ViewDataGrid.Columns["ShopName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; } + _logger.LogInformation("Загрузка магазинов"); } catch (Exception ex) @@ -43,27 +45,29 @@ namespace AutoWorkshopView.Forms.Shop } } - private void ButtonAdd_Click(object sender, EventArgs e) + private void AddButton_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormShop)); - if (service is FormShop form) + var Service = Program.ServiceProvider?.GetService(typeof(FormShop)); + + if (Service is FormShop Form) { - if (form.ShowDialog() == DialogResult.OK) + if (Form.ShowDialog() == DialogResult.OK) { LoadData(); } } } - private void ButtonUpd_Click(object sender, EventArgs e) + private void UpdateButton_Click(object sender, EventArgs e) { - if (dataGridView.SelectedRows.Count == 1) + if (ViewDataGrid.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormShop)); - if (service is FormShop form) + var Service = Program.ServiceProvider?.GetService(typeof(FormShop)); + if (Service is FormShop Form) { - form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - if (form.ShowDialog() == DialogResult.OK) + Form.Id = Convert.ToInt32(ViewDataGrid.SelectedRows[0].Cells["Id"].Value); + + if (Form.ShowDialog() == DialogResult.OK) { LoadData(); } @@ -71,23 +75,25 @@ namespace AutoWorkshopView.Forms.Shop } } - private void ButtonDel_Click(object sender, EventArgs e) + private void DeleteButton_Click(object sender, EventArgs e) { - if (dataGridView.SelectedRows.Count == 1) + if (ViewDataGrid.SelectedRows.Count == 1) { if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { - int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + int Id = Convert.ToInt32(ViewDataGrid.SelectedRows[0].Cells["Id"].Value); _logger.LogInformation("Удаление магазина"); + try { if (!_logic.Delete(new ShopBindingModel - { - Id = id - })) + { + Id = Id + })) { throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); } + LoadData(); } catch (Exception ex) @@ -99,7 +105,7 @@ namespace AutoWorkshopView.Forms.Shop } } - private void ButtonRef_Click(object sender, EventArgs e) + private void RefreshButton_Click(object sender, EventArgs e) { LoadData(); } diff --git a/AutoWorkshopView/Forms/Shop/FormShops.resx b/AutoWorkshopView/Forms/Shop/FormShops.resx index 1af7de1..af32865 100644 --- a/AutoWorkshopView/Forms/Shop/FormShops.resx +++ b/AutoWorkshopView/Forms/Shop/FormShops.resx @@ -1,17 +1,17 @@  - diff --git a/AutoWorkshopView/MainForm.Designer.cs b/AutoWorkshopView/MainForm.Designer.cs index 17becca..1b03e03 100644 --- a/AutoWorkshopView/MainForm.Designer.cs +++ b/AutoWorkshopView/MainForm.Designer.cs @@ -32,6 +32,9 @@ ToolStripMenu = new ToolStripMenuItem(); ComponentsStripMenuItem = new ToolStripMenuItem(); RepairStripMenuItem = new ToolStripMenuItem(); + ShopsToolStripMenuItem = new ToolStripMenuItem(); + OperationToolStripMenuItem = new ToolStripMenuItem(); + TransactionToolStripMenuItem = new ToolStripMenuItem(); DataGridView = new DataGridView(); CreateOrderButton = new Button(); TakeInWorkButton = new Button(); @@ -45,7 +48,7 @@ // MenuStrip // MenuStrip.ImageScalingSize = new Size(20, 20); - MenuStrip.Items.AddRange(new ToolStripItem[] { ToolStripMenu }); + MenuStrip.Items.AddRange(new ToolStripItem[] { ToolStripMenu, OperationToolStripMenuItem }); MenuStrip.Location = new Point(0, 0); MenuStrip.Name = "MenuStrip"; MenuStrip.Padding = new Padding(5, 2, 0, 2); @@ -55,7 +58,7 @@ // // ToolStripMenu // - ToolStripMenu.DropDownItems.AddRange(new ToolStripItem[] { ComponentsStripMenuItem, RepairStripMenuItem }); + ToolStripMenu.DropDownItems.AddRange(new ToolStripItem[] { ComponentsStripMenuItem, RepairStripMenuItem, ShopsToolStripMenuItem }); ToolStripMenu.Name = "ToolStripMenu"; ToolStripMenu.Size = new Size(94, 20); ToolStripMenu.Text = "Справочники"; @@ -74,8 +77,31 @@ RepairStripMenuItem.Text = "Ремонты"; RepairStripMenuItem.Click += RepairsStripMenuItem_Click; // + // ShopsToolStripMenuItem + // + ShopsToolStripMenuItem.Name = "ShopsToolStripMenuItem"; + ShopsToolStripMenuItem.Size = new Size(145, 22); + ShopsToolStripMenuItem.Text = "Магазины"; + ShopsToolStripMenuItem.Click += ShopsToolStripMenuItem_Click; + // + // OperationToolStripMenuItem + // + OperationToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { TransactionToolStripMenuItem }); + OperationToolStripMenuItem.Name = "OperationToolStripMenuItem"; + OperationToolStripMenuItem.Size = new Size(75, 20); + OperationToolStripMenuItem.Text = "Операции"; + // + // TransactionToolStripMenuItem + // + TransactionToolStripMenuItem.Name = "TransactionToolStripMenuItem"; + TransactionToolStripMenuItem.Size = new Size(125, 22); + TransactionToolStripMenuItem.Text = "Поставка"; + TransactionToolStripMenuItem.Click += TransactionToolStripMenuItem_Click; + // // DataGridView // + DataGridView.AllowUserToAddRows = false; + DataGridView.AllowUserToDeleteRows = false; DataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; DataGridView.Location = new Point(10, 23); DataGridView.Margin = new Padding(3, 2, 3, 2); @@ -175,5 +201,8 @@ private Button ReadyButton; private Button IssuedButton; private Button RefreshButton; + private ToolStripMenuItem ShopsToolStripMenuItem; + private ToolStripMenuItem OperationToolStripMenuItem; + private ToolStripMenuItem TransactionToolStripMenuItem; } } \ No newline at end of file diff --git a/AutoWorkshopView/MainForm.cs b/AutoWorkshopView/MainForm.cs index 66ff9a1..e153fc8 100644 --- a/AutoWorkshopView/MainForm.cs +++ b/AutoWorkshopView/MainForm.cs @@ -1,6 +1,7 @@ using AutoWorkshopContracts.BindingModels; using AutoWorkshopContracts.BusinessLogicContracts; using AutoWorkshopView.Forms; +using AutoWorkshopView.Forms.Shop; using Microsoft.Extensions.Logging; namespace AutoWorkshopView @@ -164,5 +165,25 @@ namespace AutoWorkshopView { LoadData(); } + + private void ShopsToolStripMenuItem_Click(object sender, EventArgs e) + { + var Service = Program.ServiceProvider?.GetService(typeof(FormShops)); + + if (Service is FormShops Form) + { + Form.ShowDialog(); + } + } + + private void TransactionToolStripMenuItem_Click(object sender, EventArgs e) + { + var Service = Program.ServiceProvider?.GetService(typeof(FormCreateSupply)); + + if (Service is FormCreateSupply Form) + { + Form.ShowDialog(); + } + } } } diff --git a/AutoWorkshopView/Program.cs b/AutoWorkshopView/Program.cs index c16b8be..ed1d2ab 100644 --- a/AutoWorkshopView/Program.cs +++ b/AutoWorkshopView/Program.cs @@ -1,8 +1,10 @@ using AutoWorkshopBusinessLogic.BusinessLogics; using AutoWorkshopContracts.BusinessLogicContracts; +using AutoWorkshopContracts.BusinessLogicsContracts; using AutoWorkshopContracts.StoragesContracts; using AutoWorkshopListImplement.Implements; using AutoWorkshopView.Forms; +using AutoWorkshopView.Forms.Shop; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using NLog.Extensions.Logging; @@ -37,9 +39,12 @@ namespace AutoWorkshopView Services.AddTransient(); Services.AddTransient(); Services.AddTransient(); + Services.AddTransient(); + Services.AddTransient(); Services.AddTransient(); Services.AddTransient(); + Services.AddTransient(); Services.AddTransient(); Services.AddTransient(); @@ -48,6 +53,9 @@ namespace AutoWorkshopView Services.AddTransient(); Services.AddTransient(); Services.AddTransient(); + Services.AddTransient(); + Services.AddTransient(); + Services.AddTransient(); } } } -- 2.25.1