From 8ad6e9478eb25cf5017bee67876e501af23bb44b Mon Sep 17 00:00:00 2001 From: Oleg Shabunov Date: Wed, 3 Apr 2024 10:56:29 +0400 Subject: [PATCH 01/21] 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; } + } +} From 8447239146238685e998f98b20fbc1af95999d3a Mon Sep 17 00:00:00 2001 From: Oleg Shabunov Date: Wed, 3 Apr 2024 11:06:33 +0400 Subject: [PATCH 02/21] 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 + }; + } +} From 4330a80dd0f39c98c64ba537db0e4d9bdf8497c3 Mon Sep 17 00:00:00 2001 From: Oleg Shabunov Date: Wed, 3 Apr 2024 11:16:21 +0400 Subject: [PATCH 03/21] 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 From 57d43005e6e9c2edc815cec7a0140395674d4eff Mon Sep 17 00:00:00 2001 From: Oleg Shabunov Date: Tue, 9 Apr 2024 22:14:14 +0400 Subject: [PATCH 04/21] 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("Магазин с таким названием уже есть"); } From b4d4b6d0f447bd0d060dddf53461d83a77745c4b Mon Sep 17 00:00:00 2001 From: Oleg Shabunov Date: Tue, 9 Apr 2024 22:58:05 +0400 Subject: [PATCH 05/21] 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(); } } } From 2fa2dfe6bc415c30a9f436821ac40d5c57e19a88 Mon Sep 17 00:00:00 2001 From: Oleg Shabunov Date: Tue, 9 Apr 2024 23:29:25 +0400 Subject: [PATCH 06/21] add Shop Sale --- .../BusinessLogics/OrderLogic.cs | 22 ++++++++++++++++++- .../BusinessLogics/ShopLogic.cs | 17 ++++++++++++++ .../BindingModels/ShopBindingModel.cs | 2 ++ .../BusinessLogicContracts/IShopLogic.cs | 2 ++ .../SearchModels/SupplySearchModel.cs | 8 +++++++ .../StoragesContracts/IShopStorage.cs | 5 +++++ .../ViewModels/ShopViewModel.cs | 3 +++ AutoWorkshopDataModels/Models/IShopModel.cs | 2 ++ 8 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 AutoWorkshopContracts/SearchModels/SupplySearchModel.cs diff --git a/AutoWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs b/AutoWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs index 246c491..77a26f8 100644 --- a/AutoWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/AutoWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs @@ -13,11 +13,14 @@ namespace AutoWorkshopBusinessLogic.BusinessLogics private readonly ILogger _logger; private readonly IOrderStorage _orderStorage; + private readonly IShopStorage _shopStorage; - public OrderLogic(ILogger Logger, IOrderStorage OrderStorage) + public OrderLogic(ILogger Logger, IOrderStorage OrderStorage, IShopStorage ShopStorage) { _logger = Logger; + _orderStorage = OrderStorage; + _shopStorage = ShopStorage; } public List? ReadList(OrderSearchModel? Model) @@ -107,6 +110,23 @@ namespace AutoWorkshopBusinessLogic.BusinessLogics public bool DeliveryOrder(OrderBindingModel Model) { + var Order = _orderStorage.GetElement(new OrderSearchModel + { + Id = Model.Id + }); + + if (Order is null) + throw new ArgumentNullException(nameof(Order)); + + if (!_shopStorage.RestockingShops(new SupplyBindingModel + { + RepairId = Order.RepairId, + Count = Order.Count + })) + { + throw new ArgumentException("Недостаточно места"); + } + return ChangeOrderStatus(Model, OrderStatus.Delivered); } diff --git a/AutoWorkshopBusinessLogic/BusinessLogics/ShopLogic.cs b/AutoWorkshopBusinessLogic/BusinessLogics/ShopLogic.cs index 632228d..c28c2cb 100644 --- a/AutoWorkshopBusinessLogic/BusinessLogics/ShopLogic.cs +++ b/AutoWorkshopBusinessLogic/BusinessLogics/ShopLogic.cs @@ -158,5 +158,22 @@ namespace AutoWorkshopBusinessLogic.BusinessLogics throw new InvalidOperationException("Магазин с таким названием уже есть"); } } + + public bool Sale(SupplySearchModel Model) + { + if (!Model.PizzaId.HasValue || !Model.Count.HasValue) + return false; + + _logger.LogInformation("Проверка ремонтов во всех магазинах"); + + if (_shopStorage.Sale(Model)) + { + _logger.LogInformation("Продажа выполнена успешно"); + return true; + } + + _logger.LogInformation("Продажа не выполнена"); + return false; + } } } diff --git a/AutoWorkshopContracts/BindingModels/ShopBindingModel.cs b/AutoWorkshopContracts/BindingModels/ShopBindingModel.cs index 60e6480..119f369 100644 --- a/AutoWorkshopContracts/BindingModels/ShopBindingModel.cs +++ b/AutoWorkshopContracts/BindingModels/ShopBindingModel.cs @@ -13,5 +13,7 @@ namespace AutoWorkshopContracts.BindingModels public DateTime OpeningDate { get; set; } = DateTime.Now; public Dictionary ShopRepairs { get; set; } = new(); + + public int RepairsMaxCount { get; set; } } } diff --git a/AutoWorkshopContracts/BusinessLogicContracts/IShopLogic.cs b/AutoWorkshopContracts/BusinessLogicContracts/IShopLogic.cs index 6a0ee7f..5bf41b7 100644 --- a/AutoWorkshopContracts/BusinessLogicContracts/IShopLogic.cs +++ b/AutoWorkshopContracts/BusinessLogicContracts/IShopLogic.cs @@ -17,5 +17,7 @@ namespace AutoWorkshopContracts.BusinessLogicsContracts bool Delete(ShopBindingModel Model); bool MakeSupply(SupplyBindingModel Model); + + bool Sale(SupplySearchModel Model); } } diff --git a/AutoWorkshopContracts/SearchModels/SupplySearchModel.cs b/AutoWorkshopContracts/SearchModels/SupplySearchModel.cs new file mode 100644 index 0000000..16c6319 --- /dev/null +++ b/AutoWorkshopContracts/SearchModels/SupplySearchModel.cs @@ -0,0 +1,8 @@ +namespace PizzeriaContracts.SearchModels +{ + public class SupplySearchModel + { + public int? RepairId { get; set; } + public int? Count { get; set; } + } +} diff --git a/AutoWorkshopContracts/StoragesContracts/IShopStorage.cs b/AutoWorkshopContracts/StoragesContracts/IShopStorage.cs index dcaee83..d98fc21 100644 --- a/AutoWorkshopContracts/StoragesContracts/IShopStorage.cs +++ b/AutoWorkshopContracts/StoragesContracts/IShopStorage.cs @@ -1,6 +1,7 @@ using AutoWorkshopContracts.BindingModels; using AutoWorkshopContracts.SearchModels; using AutoWorkshopContracts.ViewModels; +using PizzeriaContracts.SearchModels; namespace AutoWorkshopContracts.StoragesContracts { @@ -17,5 +18,9 @@ namespace AutoWorkshopContracts.StoragesContracts ShopViewModel? Update(ShopBindingModel Model); ShopViewModel? Delete(ShopBindingModel Model); + + bool Sale(SupplySearchModel Model); + + bool RestockingShops(SupplyBindingModel Model); } } diff --git a/AutoWorkshopContracts/ViewModels/ShopViewModel.cs b/AutoWorkshopContracts/ViewModels/ShopViewModel.cs index b449a11..2538f00 100644 --- a/AutoWorkshopContracts/ViewModels/ShopViewModel.cs +++ b/AutoWorkshopContracts/ViewModels/ShopViewModel.cs @@ -17,5 +17,8 @@ namespace AutoWorkshopContracts.ViewModels public DateTime OpeningDate { get; set; } public Dictionary ShopRepairs { get; set; } = new(); + + [DisplayName("Вместимость")] + public int RepairsMaxCount { get; set; } } } diff --git a/AutoWorkshopDataModels/Models/IShopModel.cs b/AutoWorkshopDataModels/Models/IShopModel.cs index 0211aa8..83f1f3d 100644 --- a/AutoWorkshopDataModels/Models/IShopModel.cs +++ b/AutoWorkshopDataModels/Models/IShopModel.cs @@ -9,5 +9,7 @@ DateTime OpeningDate { get; } Dictionary ShopRepairs { get; } + + int RepairsMaxCount { get; } } } From b4c8722cd4e1fec2c0aa749aa2085dc5b4bc79c7 Mon Sep 17 00:00:00 2001 From: Oleg Shabunov Date: Tue, 9 Apr 2024 23:44:27 +0400 Subject: [PATCH 07/21] Shop File implement --- .../DataFileSingleton.cs | 14 +- .../Implements/ShopStorage.cs | 155 ++++++++++++++++++ AutoWorkshopFileImplement/Models/Shop.cs | 110 +++++++++++++ .../Implements/ShopStorage.cs | 11 ++ AutoWorkshopImplement/Models/Shop.cs | 10 +- 5 files changed, 292 insertions(+), 8 deletions(-) create mode 100644 AutoWorkshopFileImplement/Implements/ShopStorage.cs create mode 100644 AutoWorkshopFileImplement/Models/Shop.cs diff --git a/AutoWorkshopFileImplement/DataFileSingleton.cs b/AutoWorkshopFileImplement/DataFileSingleton.cs index 266f506..18a6f92 100644 --- a/AutoWorkshopFileImplement/DataFileSingleton.cs +++ b/AutoWorkshopFileImplement/DataFileSingleton.cs @@ -10,18 +10,19 @@ namespace AutoWorkshopFileImplement private readonly string ComponentFileName = "Component.xml"; private readonly string OrderFileName = "Order.xml"; private readonly string RepairFileName = "Repair.xml"; - - public List Components { get; private set; } - - public List Orders { get; private set; } - + private readonly string ShopFileName = "Shop.xml"; + + public List Components { get; private set; } + public List Orders { get; private set; } public List Repairs { get; private set; } - + public List Shops { get; private set; } + private DataFileSingleton() { Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!; Repairs = LoadData(RepairFileName, "Repair", x => Repair.Create(x)!)!; Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!; + Shops = LoadData(ShopFileName, "Shop", x => Shop.Create(x)!)!; } public static DataFileSingleton GetInstance() @@ -37,6 +38,7 @@ namespace AutoWorkshopFileImplement public void SaveComponents() => SaveData(Components, ComponentFileName, "Components", x => x.GetXElement); public void SaveRepairs() => SaveData(Repairs, RepairFileName, "Repairs", x => x.GetXElement); public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement); + public void SaveShops() => SaveData(Shops, ShopFileName, "Shops", x => x.GetXElement); private static List? LoadData(string FileName, string XmlNodeName, Func SelectFunction) { diff --git a/AutoWorkshopFileImplement/Implements/ShopStorage.cs b/AutoWorkshopFileImplement/Implements/ShopStorage.cs new file mode 100644 index 0000000..25576c9 --- /dev/null +++ b/AutoWorkshopFileImplement/Implements/ShopStorage.cs @@ -0,0 +1,155 @@ +using AutoWorkshopContracts.BindingModels; +using AutoWorkshopContracts.SearchModels; +using AutoWorkshopContracts.StoragesContracts; +using AutoWorkshopContracts.ViewModels; +using AutoWorkshopFileImplement.Models; +using PizzeriaContracts.SearchModels; + +namespace AutoWorkshopFileImplement.Implements +{ + public class ShopStorage : IShopStorage + { + private readonly DataFileSingleton _source; + + public ShopStorage() + { + _source = DataFileSingleton.GetInstance(); + } + + public List GetFullList() + { + return _source.Shops.Select(x => x.GetViewModel).ToList(); + } + + public List GetFilteredList(ShopSearchModel Model) + { + if (string.IsNullOrEmpty(Model.ShopName)) + return new(); + + return _source.Shops.Where(x => x.ShopName.Contains(Model.ShopName)).Select(x => x.GetViewModel).ToList(); + } + + public ShopViewModel? GetElement(ShopSearchModel Model) + { + if (string.IsNullOrEmpty(Model.ShopName) && !Model.Id.HasValue) + return null; + + return _source.Shops.FirstOrDefault(x => + (!string.IsNullOrEmpty(Model.ShopName) && x.ShopName == Model.ShopName) || + (Model.Id.HasValue && x.Id == Model.Id))?.GetViewModel; + } + + public ShopViewModel? Insert(ShopBindingModel Model) + { + Model.Id = _source.Shops.Count > 0 ? _source.Shops.Max(x => x.Id) + 1 : 1; + + var NewShop = Shop.Create(Model); + if (NewShop == null) + return null; + + _source.Shops.Add(NewShop); + _source.SaveShops(); + + return NewShop.GetViewModel; + } + + public ShopViewModel? Update(ShopBindingModel Model) + { + var Shop = _source.Shops.FirstOrDefault(x => x.Id == Model.Id); + if (Shop == null) + return null; + + Shop.Update(Model); + _source.SaveShops(); + + return Shop.GetViewModel; + } + + public ShopViewModel? Delete(ShopBindingModel Model) + { + var Shop = _source.Shops.FirstOrDefault(x => x.Id == Model.Id); + + if (Shop == null) + return null; + + _source.Shops.Remove(Shop); + _source.SaveShops(); + + return Shop.GetViewModel; + } + + public bool Sale(SupplySearchModel Model) + { + if (Model == null || !Model.RepairId.HasValue || !Model.Count.HasValue) + return false; + + int RemainingSpace = _source.Shops.Select(x => x.Repairs.ContainsKey(Model.RepairId.Value) ? x.Repairs[Model.RepairId.Value] : 0).Sum(); + if (RemainingSpace < Model.Count) + return false; + + var Shops = _source.Shops + .Where(x => x.Repairs.ContainsKey(Model.RepairId.Value)) + .OrderByDescending(x => x.Repairs[Model.RepairId.Value]).ToList(); + + foreach (var Shop in Shops) + { + int Residue = Model.Count.Value - Shop.Repairs[Model.RepairId.Value]; + + if (Residue > 0) + { + Shop.Repairs.Remove(Model.RepairId.Value); + Shop.RepairsUpdate(); + + Model.Count = Residue; + } + else + { + if (Residue == 0) + Shop.Repairs.Remove(Model.RepairId.Value); + else + Shop.Repairs[Model.RepairId.Value] = -Residue; + + Shop.RepairsUpdate(); + _source.SaveShops(); + + return true; + } + } + + _source.SaveShops(); + return false; + } + + public bool RestockingShops(SupplyBindingModel Model) + { + if (Model == null || _source.Shops.Select(x => x.RepairsMaxCount - x.ShopRepairs.Select(y => y.Value.Item2).Sum()).Sum() < Model.Count) + return false; + + foreach (Shop shop in _source.Shops) + { + int FreeSpaceNum = shop.RepairsMaxCount - shop.ShopRepairs.Select(x => x.Value.Item2).Sum(); + + if (FreeSpaceNum <= 0) + continue; + + FreeSpaceNum = Math.Min(FreeSpaceNum, Model.Count); + Model.Count -= FreeSpaceNum; + + if (shop.Repairs.ContainsKey(Model.RepairId)) + shop.Repairs[Model.RepairId] += FreeSpaceNum; + else + shop.Repairs.Add(Model.RepairId, FreeSpaceNum); + + shop.RepairsUpdate(); + + if (Model.Count == 0) + { + _source.SaveShops(); + return true; + } + } + + return false; + } + } +} diff --git a/AutoWorkshopFileImplement/Models/Shop.cs b/AutoWorkshopFileImplement/Models/Shop.cs new file mode 100644 index 0000000..ac2e8e0 --- /dev/null +++ b/AutoWorkshopFileImplement/Models/Shop.cs @@ -0,0 +1,110 @@ +using AutoWorkshopContracts.BindingModels; +using AutoWorkshopContracts.ViewModels; +using AutoWorkshopDataModels.Models; +using System.Xml.Linq; + +namespace AutoWorkshopFileImplement.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 Repairs { get; private set; } = new(); + + private Dictionary? _shopRepairs = null; + + public Dictionary ShopRepairs + { + get + { + if (_shopRepairs == null) + { + var Source = DataFileSingleton.GetInstance(); + _shopRepairs = Repairs.ToDictionary(x => x.Key, y => ((Source.Repairs.FirstOrDefault(z => z.Id == y.Key) as IRepairModel)!, y.Value)); + } + + return _shopRepairs; + } + } + + public int RepairsMaxCount { get; private set; } + + public static Shop? Create(ShopBindingModel? Model) + { + if (Model == null) + return null; + + return new Shop() + { + Id = Model.Id, + ShopName = Model.ShopName, + Address = Model.Address, + OpeningDate = Model.OpeningDate, + Repairs = Model.ShopRepairs.ToDictionary(x => x.Key, x => x.Value.Item2), + RepairsMaxCount = Model.RepairsMaxCount + }; + } + + public static Shop? Create(XElement Element) + { + if (Element == null) + return null; + + return new() + { + Id = Convert.ToInt32(Element.Attribute("Id")!.Value), + ShopName = Element.Element("ShopName")!.Value, + Address = Element.Element("Address")!.Value, + OpeningDate = Convert.ToDateTime(Element.Element("OpeningDate")!.Value), + Repairs = Element.Element("ShopRepairs")!.Elements("ShopRepair")!.ToDictionary(x => Convert.ToInt32(x.Element("Key")?.Value), + x => Convert.ToInt32(x.Element("Value")?.Value)), + RepairsMaxCount = Convert.ToInt32(Element.Element("RepairsMaxCount")!.Value) + }; + } + + public void Update(ShopBindingModel? Model) + { + if (Model == null) + return; + + ShopName = Model.ShopName; + Address = Model.Address; + OpeningDate = Model.OpeningDate; + RepairsMaxCount = Model.RepairsMaxCount; + Repairs = Model.ShopRepairs.ToDictionary(x => x.Key, x => x.Value.Item2); + _shopRepairs = null; + } + + public ShopViewModel GetViewModel => new() + { + Id = Id, + ShopName = ShopName, + Address = Address, + OpeningDate = OpeningDate, + ShopRepairs = ShopRepairs, + RepairsMaxCount = RepairsMaxCount + }; + + public XElement GetXElement => new( + "Shop", + new XAttribute("Id", Id), + new XElement("ShopName", ShopName), + new XElement("Address", Address), + new XElement("OpeningDate", OpeningDate.ToString()), + new XElement("ShopRepairs", Repairs.Select( + x => new XElement("ShopRepair", new XElement("Key", x.Key), new XElement("Value", x.Value))).ToArray()), + new XElement("RepairsMaxCount", RepairsMaxCount.ToString()) + ); + + public void RepairsUpdate() + { + _shopRepairs = null; + } + } +} diff --git a/AutoWorkshopImplement/Implements/ShopStorage.cs b/AutoWorkshopImplement/Implements/ShopStorage.cs index 8e6d8e7..75612c2 100644 --- a/AutoWorkshopImplement/Implements/ShopStorage.cs +++ b/AutoWorkshopImplement/Implements/ShopStorage.cs @@ -3,6 +3,7 @@ using AutoWorkshopContracts.SearchModels; using AutoWorkshopContracts.StoragesContracts; using AutoWorkshopContracts.ViewModels; using AutoWorkshopListImplement.Models; +using PizzeriaContracts.SearchModels; namespace AutoWorkshopListImplement.Implements { @@ -108,5 +109,15 @@ namespace AutoWorkshopListImplement.Implements return null; } + + public bool Sale(SupplySearchModel Model) + { + throw new NotImplementedException(); + } + + public bool RestockingShops(SupplyBindingModel Model) + { + throw new NotImplementedException(); + } } } diff --git a/AutoWorkshopImplement/Models/Shop.cs b/AutoWorkshopImplement/Models/Shop.cs index bf6eec9..a01d9b1 100644 --- a/AutoWorkshopImplement/Models/Shop.cs +++ b/AutoWorkshopImplement/Models/Shop.cs @@ -1,6 +1,7 @@ using AutoWorkshopContracts.BindingModels; using AutoWorkshopContracts.ViewModels; using AutoWorkshopDataModels.Models; +using System.Reflection; namespace AutoWorkshopListImplement.Models { @@ -16,6 +17,8 @@ namespace AutoWorkshopListImplement.Models public Dictionary ShopRepairs { get; private set; } = new(); + public int RepairsMaxCount { get; private set; } + public static Shop? Create(ShopBindingModel? Model) { if (Model is null) @@ -26,7 +29,8 @@ namespace AutoWorkshopListImplement.Models Id = Model.Id, ShopName = Model.ShopName, Address = Model.Address, - OpeningDate = Model.OpeningDate + OpeningDate = Model.OpeningDate, + RepairsMaxCount = Model.RepairsMaxCount, }; } @@ -38,6 +42,7 @@ namespace AutoWorkshopListImplement.Models ShopName = Model.ShopName; Address = Model.Address; OpeningDate = Model.OpeningDate; + RepairsMaxCount = Model.RepairsMaxCount; } public ShopViewModel GetViewModel => new() @@ -46,7 +51,8 @@ namespace AutoWorkshopListImplement.Models ShopName = ShopName, Address = Address, OpeningDate = OpeningDate, - ShopRepairs = ShopRepairs + ShopRepairs = ShopRepairs, + RepairsMaxCount = Model.RepairsMaxCount, }; } } From 5d703cb6151ea47960b3cae6e5407441584f882b Mon Sep 17 00:00:00 2001 From: Oleg Shabunov Date: Wed, 10 Apr 2024 00:26:00 +0400 Subject: [PATCH 08/21] Sell form --- .../BusinessLogics/ShopLogic.cs | 2 +- .../SearchModels/SupplySearchModel.cs | 2 +- .../StoragesContracts/IShopStorage.cs | 1 - .../Implements/ShopStorage.cs | 1 - .../Implements/ShopStorage.cs | 1 - AutoWorkshopImplement/Models/Shop.cs | 3 +- .../Forms/Shop/FormSellRepair.Designer.cs | 125 ++++++++++++++++++ AutoWorkshopView/Forms/Shop/FormSellRepair.cs | 87 ++++++++++++ .../Forms/Shop/FormSellRepair.resx | 120 +++++++++++++++++ .../Forms/Shop/FormShop.Designer.cs | 62 ++++++--- AutoWorkshopView/Forms/Shop/FormShop.cs | 5 +- AutoWorkshopView/MainForm.Designer.cs | 11 +- AutoWorkshopView/MainForm.cs | 10 ++ AutoWorkshopView/Program.cs | 1 + 14 files changed, 404 insertions(+), 27 deletions(-) create mode 100644 AutoWorkshopView/Forms/Shop/FormSellRepair.Designer.cs create mode 100644 AutoWorkshopView/Forms/Shop/FormSellRepair.cs create mode 100644 AutoWorkshopView/Forms/Shop/FormSellRepair.resx diff --git a/AutoWorkshopBusinessLogic/BusinessLogics/ShopLogic.cs b/AutoWorkshopBusinessLogic/BusinessLogics/ShopLogic.cs index c28c2cb..7886c54 100644 --- a/AutoWorkshopBusinessLogic/BusinessLogics/ShopLogic.cs +++ b/AutoWorkshopBusinessLogic/BusinessLogics/ShopLogic.cs @@ -161,7 +161,7 @@ namespace AutoWorkshopBusinessLogic.BusinessLogics public bool Sale(SupplySearchModel Model) { - if (!Model.PizzaId.HasValue || !Model.Count.HasValue) + if (!Model.RepairId.HasValue || !Model.Count.HasValue) return false; _logger.LogInformation("Проверка ремонтов во всех магазинах"); diff --git a/AutoWorkshopContracts/SearchModels/SupplySearchModel.cs b/AutoWorkshopContracts/SearchModels/SupplySearchModel.cs index 16c6319..9cd3646 100644 --- a/AutoWorkshopContracts/SearchModels/SupplySearchModel.cs +++ b/AutoWorkshopContracts/SearchModels/SupplySearchModel.cs @@ -1,4 +1,4 @@ -namespace PizzeriaContracts.SearchModels +namespace AutoWorkshopContracts.SearchModels { public class SupplySearchModel { diff --git a/AutoWorkshopContracts/StoragesContracts/IShopStorage.cs b/AutoWorkshopContracts/StoragesContracts/IShopStorage.cs index d98fc21..e79a487 100644 --- a/AutoWorkshopContracts/StoragesContracts/IShopStorage.cs +++ b/AutoWorkshopContracts/StoragesContracts/IShopStorage.cs @@ -1,7 +1,6 @@ using AutoWorkshopContracts.BindingModels; using AutoWorkshopContracts.SearchModels; using AutoWorkshopContracts.ViewModels; -using PizzeriaContracts.SearchModels; namespace AutoWorkshopContracts.StoragesContracts { diff --git a/AutoWorkshopFileImplement/Implements/ShopStorage.cs b/AutoWorkshopFileImplement/Implements/ShopStorage.cs index 25576c9..f826d22 100644 --- a/AutoWorkshopFileImplement/Implements/ShopStorage.cs +++ b/AutoWorkshopFileImplement/Implements/ShopStorage.cs @@ -3,7 +3,6 @@ using AutoWorkshopContracts.SearchModels; using AutoWorkshopContracts.StoragesContracts; using AutoWorkshopContracts.ViewModels; using AutoWorkshopFileImplement.Models; -using PizzeriaContracts.SearchModels; namespace AutoWorkshopFileImplement.Implements { diff --git a/AutoWorkshopImplement/Implements/ShopStorage.cs b/AutoWorkshopImplement/Implements/ShopStorage.cs index 75612c2..f9e6626 100644 --- a/AutoWorkshopImplement/Implements/ShopStorage.cs +++ b/AutoWorkshopImplement/Implements/ShopStorage.cs @@ -3,7 +3,6 @@ using AutoWorkshopContracts.SearchModels; using AutoWorkshopContracts.StoragesContracts; using AutoWorkshopContracts.ViewModels; using AutoWorkshopListImplement.Models; -using PizzeriaContracts.SearchModels; namespace AutoWorkshopListImplement.Implements { diff --git a/AutoWorkshopImplement/Models/Shop.cs b/AutoWorkshopImplement/Models/Shop.cs index a01d9b1..2067c44 100644 --- a/AutoWorkshopImplement/Models/Shop.cs +++ b/AutoWorkshopImplement/Models/Shop.cs @@ -1,7 +1,6 @@ using AutoWorkshopContracts.BindingModels; using AutoWorkshopContracts.ViewModels; using AutoWorkshopDataModels.Models; -using System.Reflection; namespace AutoWorkshopListImplement.Models { @@ -52,7 +51,7 @@ namespace AutoWorkshopListImplement.Models Address = Address, OpeningDate = OpeningDate, ShopRepairs = ShopRepairs, - RepairsMaxCount = Model.RepairsMaxCount, + RepairsMaxCount = RepairsMaxCount, }; } } diff --git a/AutoWorkshopView/Forms/Shop/FormSellRepair.Designer.cs b/AutoWorkshopView/Forms/Shop/FormSellRepair.Designer.cs new file mode 100644 index 0000000..26e3cea --- /dev/null +++ b/AutoWorkshopView/Forms/Shop/FormSellRepair.Designer.cs @@ -0,0 +1,125 @@ +namespace AutoWorkshopView.Forms.Shop +{ + partial class FormSellRepair + { + /// + /// 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() + { + RepairLabel = new Label(); + RepairComboBox = new ComboBox(); + CountLabel = new Label(); + CountTextBox = new TextBox(); + SellButton = new Button(); + CancelButton = new Button(); + SuspendLayout(); + // + // RepairLabel + // + RepairLabel.AutoSize = true; + RepairLabel.Location = new Point(10, 11); + RepairLabel.Name = "RepairLabel"; + RepairLabel.Size = new Size(54, 15); + RepairLabel.TabIndex = 0; + RepairLabel.Text = "Ремонт: "; + // + // RepairComboBox + // + RepairComboBox.DropDownStyle = ComboBoxStyle.DropDownList; + RepairComboBox.FormattingEnabled = true; + RepairComboBox.Location = new Point(94, 8); + RepairComboBox.Margin = new Padding(3, 2, 3, 2); + RepairComboBox.Name = "RepairComboBox"; + RepairComboBox.Size = new Size(217, 23); + RepairComboBox.TabIndex = 1; + // + // CountLabel + // + CountLabel.AutoSize = true; + CountLabel.Location = new Point(10, 41); + CountLabel.Name = "CountLabel"; + CountLabel.Size = new Size(78, 15); + CountLabel.TabIndex = 2; + CountLabel.Text = "Количество: "; + // + // CountTextBox + // + CountTextBox.Location = new Point(94, 39); + CountTextBox.Margin = new Padding(3, 2, 3, 2); + CountTextBox.Name = "CountTextBox"; + CountTextBox.Size = new Size(217, 23); + CountTextBox.TabIndex = 3; + // + // SellButton + // + SellButton.Location = new Point(117, 77); + SellButton.Margin = new Padding(3, 2, 3, 2); + SellButton.Name = "SellButton"; + SellButton.Size = new Size(92, 30); + SellButton.TabIndex = 4; + SellButton.Text = "Продать"; + SellButton.UseVisualStyleBackColor = true; + SellButton.Click += SellButton_Click; + // + // CancelButton + // + CancelButton.Location = new Point(215, 77); + CancelButton.Margin = new Padding(3, 2, 3, 2); + CancelButton.Name = "CancelButton"; + CancelButton.Size = new Size(96, 30); + CancelButton.TabIndex = 5; + CancelButton.Text = "Отмена"; + CancelButton.UseVisualStyleBackColor = true; + CancelButton.Click += ButtonCancel_Click; + // + // FormSellRepair + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(325, 122); + Controls.Add(CancelButton); + Controls.Add(SellButton); + Controls.Add(CountTextBox); + Controls.Add(CountLabel); + Controls.Add(RepairComboBox); + Controls.Add(RepairLabel); + Margin = new Padding(3, 2, 3, 2); + Name = "FormSellRepair"; + Text = "Продажа ремонтов"; + Load += FormSellRepair_Load; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label RepairLabel; + private ComboBox RepairComboBox; + private Label CountLabel; + private TextBox CountTextBox; + private Button SellButton; + private Button CancelButton; + } +} \ No newline at end of file diff --git a/AutoWorkshopView/Forms/Shop/FormSellRepair.cs b/AutoWorkshopView/Forms/Shop/FormSellRepair.cs new file mode 100644 index 0000000..91ee224 --- /dev/null +++ b/AutoWorkshopView/Forms/Shop/FormSellRepair.cs @@ -0,0 +1,87 @@ +using AutoWorkshopContracts.BusinessLogicContracts; +using AutoWorkshopContracts.BusinessLogicsContracts; +using AutoWorkshopContracts.SearchModels; +using AutoWorkshopContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace AutoWorkshopView.Forms.Shop +{ + public partial class FormSellRepair : Form + { + private readonly ILogger _logger; + + private readonly IRepairLogic _repairLogic; + private readonly IShopLogic _shopLogic; + + private List _repairList = new List(); + + public FormSellRepair(ILogger Logger, IRepairLogic RepairLogic, IShopLogic ShopLogic) + { + InitializeComponent(); + + _logger = Logger; + _repairLogic = RepairLogic; + _shopLogic = ShopLogic; + } + + private void FormSellRepair_Load(object sender, EventArgs e) + { + _repairList = _repairLogic.ReadList(null); + + if (_repairList != null) + { + RepairComboBox.DisplayMember = "RepairName"; + RepairComboBox.ValueMember = "Id"; + RepairComboBox.DataSource = _repairList; + RepairComboBox.SelectedItem = null; + + _logger.LogInformation("Загрузка ремонтов для продажи"); + } + } + + private void SellButton_Click(object sender, EventArgs e) + { + if (RepairComboBox.SelectedValue == null) + { + MessageBox.Show("Выберите ремонт", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + _logger.LogInformation("Создание покупки"); + + try + { + bool Result = _shopLogic.Sale(new SupplySearchModel + { + RepairId = Convert.ToInt32(RepairComboBox.SelectedValue), + Count = Convert.ToInt32(CountTextBox.Text) + }); + + if (Result) + { + _logger.LogInformation("Проверка пройдена, продажа проведена"); + MessageBox.Show("Продажа проведена", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information); + + DialogResult = DialogResult.OK; + Close(); + } + else + { + _logger.LogInformation("Проверка не пройдена"); + MessageBox.Show("Продажа не может быть создана.", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Warning); + } + } + 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/FormSellRepair.resx b/AutoWorkshopView/Forms/Shop/FormSellRepair.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/AutoWorkshopView/Forms/Shop/FormSellRepair.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 index a564049..962758d 100644 --- a/AutoWorkshopView/Forms/Shop/FormShop.Designer.cs +++ b/AutoWorkshopView/Forms/Shop/FormShop.Designer.cs @@ -40,13 +40,16 @@ CountColumn = new DataGridViewTextBoxColumn(); OpeningDateLabel = new Label(); OpenDateTimePicker = new DateTimePicker(); + RepairsMaxCountLabel = new Label(); + RepairsMaxCountNumericUp = new NumericUpDown(); ((System.ComponentModel.ISupportInitialize)ViewDataGrid).BeginInit(); + ((System.ComponentModel.ISupportInitialize)RepairsMaxCountNumericUp).BeginInit(); SuspendLayout(); // // NameLabel // NameLabel.AutoSize = true; - NameLabel.Location = new Point(10, 12); + NameLabel.Location = new Point(9, 9); NameLabel.Name = "NameLabel"; NameLabel.Size = new Size(65, 15); NameLabel.TabIndex = 0; @@ -54,24 +57,24 @@ // // NameTextBox // - NameTextBox.Location = new Point(112, 9); + NameTextBox.Location = new Point(105, 6); NameTextBox.Margin = new Padding(3, 2, 3, 2); NameTextBox.Name = "NameTextBox"; - NameTextBox.Size = new Size(240, 23); + NameTextBox.Size = new Size(210, 23); NameTextBox.TabIndex = 1; // // AddressTextBox // - AddressTextBox.Location = new Point(112, 36); + AddressTextBox.Location = new Point(105, 33); AddressTextBox.Margin = new Padding(3, 2, 3, 2); AddressTextBox.Name = "AddressTextBox"; - AddressTextBox.Size = new Size(240, 23); + AddressTextBox.Size = new Size(210, 23); AddressTextBox.TabIndex = 3; // // AddressLabel // AddressLabel.AutoSize = true; - AddressLabel.Location = new Point(12, 39); + AddressLabel.Location = new Point(10, 36); AddressLabel.Name = "AddressLabel"; AddressLabel.Size = new Size(46, 15); AddressLabel.TabIndex = 2; @@ -79,10 +82,10 @@ // // CancelButton // - CancelButton.Location = new Point(395, 343); + CancelButton.Location = new Point(345, 302); CancelButton.Margin = new Padding(3, 2, 3, 2); CancelButton.Name = "CancelButton"; - CancelButton.Size = new Size(114, 33); + CancelButton.Size = new Size(100, 25); CancelButton.TabIndex = 5; CancelButton.Text = "Отмена"; CancelButton.UseVisualStyleBackColor = true; @@ -90,10 +93,10 @@ // // SaveButton // - SaveButton.Location = new Point(276, 343); + SaveButton.Location = new Point(239, 302); SaveButton.Margin = new Padding(3, 2, 3, 2); SaveButton.Name = "SaveButton"; - SaveButton.Size = new Size(114, 33); + SaveButton.Size = new Size(100, 25); SaveButton.TabIndex = 6; SaveButton.Text = "Сохранить"; SaveButton.UseVisualStyleBackColor = true; @@ -106,14 +109,14 @@ ViewDataGrid.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; ViewDataGrid.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; ViewDataGrid.Columns.AddRange(new DataGridViewColumn[] { IdColumn, RepairNameColumn, CountColumn }); - ViewDataGrid.Location = new Point(10, 108); + ViewDataGrid.Location = new Point(9, 126); 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.Size = new Size(436, 172); ViewDataGrid.TabIndex = 7; // // IdColumn @@ -141,25 +144,45 @@ // OpeningDateLabel // OpeningDateLabel.AutoSize = true; - OpeningDateLabel.Location = new Point(10, 69); + OpeningDateLabel.Location = new Point(9, 63); OpeningDateLabel.Name = "OpeningDateLabel"; - OpeningDateLabel.Size = new Size(87, 15); + OpeningDateLabel.Size = new Size(90, 15); OpeningDateLabel.TabIndex = 8; - OpeningDateLabel.Text = "Дата открытия"; + OpeningDateLabel.Text = "Дата открытия:"; // // OpenDateTimePicker // - OpenDateTimePicker.Location = new Point(112, 63); + OpenDateTimePicker.Location = new Point(105, 60); OpenDateTimePicker.Margin = new Padding(3, 2, 3, 2); OpenDateTimePicker.Name = "OpenDateTimePicker"; - OpenDateTimePicker.Size = new Size(240, 23); + OpenDateTimePicker.Size = new Size(210, 23); OpenDateTimePicker.TabIndex = 9; // + // RepairsMaxCountLabel + // + RepairsMaxCountLabel.AutoSize = true; + RepairsMaxCountLabel.Location = new Point(9, 90); + RepairsMaxCountLabel.Name = "RepairsMaxCountLabel"; + RepairsMaxCountLabel.Size = new Size(83, 15); + RepairsMaxCountLabel.TabIndex = 10; + RepairsMaxCountLabel.Text = "Вместимость:"; + // + // RepairsMaxCountNumericUp + // + RepairsMaxCountNumericUp.Location = new Point(105, 87); + RepairsMaxCountNumericUp.Margin = new Padding(3, 2, 3, 2); + RepairsMaxCountNumericUp.Maximum = new decimal(new int[] { 10000, 0, 0, 0 }); + RepairsMaxCountNumericUp.Name = "RepairsMaxCountNumericUp"; + RepairsMaxCountNumericUp.Size = new Size(210, 23); + RepairsMaxCountNumericUp.TabIndex = 11; + // // FormShop // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(519, 385); + ClientSize = new Size(460, 340); + Controls.Add(RepairsMaxCountNumericUp); + Controls.Add(RepairsMaxCountLabel); Controls.Add(OpenDateTimePicker); Controls.Add(OpeningDateLabel); Controls.Add(ViewDataGrid); @@ -174,6 +197,7 @@ Text = "Магазин"; Load += FormShop_Load; ((System.ComponentModel.ISupportInitialize)ViewDataGrid).EndInit(); + ((System.ComponentModel.ISupportInitialize)RepairsMaxCountNumericUp).EndInit(); ResumeLayout(false); PerformLayout(); } @@ -192,5 +216,7 @@ private DataGridViewTextBoxColumn CountColumn; private Label OpeningDateLabel; private DateTimePicker OpenDateTimePicker; + private Label RepairsMaxCountLabel; + private NumericUpDown RepairsMaxCountNumericUp; } } \ No newline at end of file diff --git a/AutoWorkshopView/Forms/Shop/FormShop.cs b/AutoWorkshopView/Forms/Shop/FormShop.cs index deaf15f..73a055c 100644 --- a/AutoWorkshopView/Forms/Shop/FormShop.cs +++ b/AutoWorkshopView/Forms/Shop/FormShop.cs @@ -3,6 +3,7 @@ using AutoWorkshopContracts.BusinessLogicsContracts; using AutoWorkshopContracts.SearchModels; using AutoWorkshopDataModels.Models; using Microsoft.Extensions.Logging; +using System.Windows.Forms; namespace AutoWorkshopView.Forms.Shop { @@ -45,6 +46,7 @@ namespace AutoWorkshopView.Forms.Shop NameTextBox.Text = View.ShopName; AddressTextBox.Text = View.Address; OpenDateTimePicker.Value = View.OpeningDate; + RepairsMaxCountNumericUp.Value = View.RepairsMaxCount; _shopRepairs = View.ShopRepairs ?? new Dictionary(); LoadData(); @@ -103,7 +105,8 @@ namespace AutoWorkshopView.Forms.Shop Id = _id ?? 0, ShopName = NameTextBox.Text, Address = AddressTextBox.Text, - OpeningDate = OpenDateTimePicker.Value + OpeningDate = OpenDateTimePicker.Value, + RepairsMaxCount = (int)RepairsMaxCountNumericUp.Value, }; var OperationResult = _id.HasValue ? _logic.Update(Model) : _logic.Create(Model); diff --git a/AutoWorkshopView/MainForm.Designer.cs b/AutoWorkshopView/MainForm.Designer.cs index 1b03e03..cdb15b3 100644 --- a/AutoWorkshopView/MainForm.Designer.cs +++ b/AutoWorkshopView/MainForm.Designer.cs @@ -35,6 +35,7 @@ ShopsToolStripMenuItem = new ToolStripMenuItem(); OperationToolStripMenuItem = new ToolStripMenuItem(); TransactionToolStripMenuItem = new ToolStripMenuItem(); + SaleToolStripMenuItem = new ToolStripMenuItem(); DataGridView = new DataGridView(); CreateOrderButton = new Button(); TakeInWorkButton = new Button(); @@ -86,7 +87,7 @@ // // OperationToolStripMenuItem // - OperationToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { TransactionToolStripMenuItem }); + OperationToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { TransactionToolStripMenuItem, SaleToolStripMenuItem }); OperationToolStripMenuItem.Name = "OperationToolStripMenuItem"; OperationToolStripMenuItem.Size = new Size(75, 20); OperationToolStripMenuItem.Text = "Операции"; @@ -165,6 +166,13 @@ RefreshButton.UseVisualStyleBackColor = true; RefreshButton.Click += RefreshButton_Click; // + // SaleToolStripMenuItem + // + SaleToolStripMenuItem.Name = "SaleToolStripMenuItem"; + SaleToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + SaleToolStripMenuItem.Text = "Продажа"; + SaleToolStripMenuItem.Click += new System.EventHandler(SellToolStripMenuItem_Click); + // // MainForm // AutoScaleDimensions = new SizeF(7F, 15F); @@ -204,5 +212,6 @@ private ToolStripMenuItem ShopsToolStripMenuItem; private ToolStripMenuItem OperationToolStripMenuItem; private ToolStripMenuItem TransactionToolStripMenuItem; + private ToolStripMenuItem SaleToolStripMenuItem; } } \ No newline at end of file diff --git a/AutoWorkshopView/MainForm.cs b/AutoWorkshopView/MainForm.cs index e153fc8..5d1f18b 100644 --- a/AutoWorkshopView/MainForm.cs +++ b/AutoWorkshopView/MainForm.cs @@ -10,6 +10,7 @@ namespace AutoWorkshopView { private readonly ILogger _logger; private readonly IOrderLogic _orderLogic; + public MainForm(ILogger Logger, IOrderLogic OrderLogic) { InitializeComponent(); @@ -185,5 +186,14 @@ namespace AutoWorkshopView Form.ShowDialog(); } } + + private void SellToolStripMenuItem_Click(object sender, EventArgs e) + { + var Service = Program.ServiceProvider?.GetService(typeof(FormSellRepair)); + if (Service is FormSellRepair Form) + { + Form.ShowDialog(); + } + } } } diff --git a/AutoWorkshopView/Program.cs b/AutoWorkshopView/Program.cs index ed6e4bb..d0f3589 100644 --- a/AutoWorkshopView/Program.cs +++ b/AutoWorkshopView/Program.cs @@ -56,6 +56,7 @@ namespace AutoWorkshopView Services.AddTransient(); Services.AddTransient(); Services.AddTransient(); + Services.AddTransient(); } } } From ad9847c51c0d6e1bf67015a4f8307f8a59bfd1d4 Mon Sep 17 00:00:00 2001 From: Oleg Shabunov Date: Wed, 10 Apr 2024 21:49:56 +0400 Subject: [PATCH 09/21] ShopRepairs saving fix --- .../BusinessLogics/ShopLogic.cs | 25 +++++++++----- .../BusinessLogicContracts/IShopLogic.cs | 2 +- .../SearchModels/SupplySearchModel.cs | 1 + .../StoragesContracts/IShopStorage.cs | 4 +-- .../DataFileSingleton.cs | 2 +- .../Implements/ShopStorage.cs | 33 +++++++++++-------- AutoWorkshopFileImplement/Models/Shop.cs | 2 +- .../Implements/ShopStorage.cs | 2 +- AutoWorkshopView/Forms/Shop/FormSellRepair.cs | 2 +- AutoWorkshopView/MainForm.cs | 1 + 10 files changed, 45 insertions(+), 29 deletions(-) diff --git a/AutoWorkshopBusinessLogic/BusinessLogics/ShopLogic.cs b/AutoWorkshopBusinessLogic/BusinessLogics/ShopLogic.cs index 7886c54..d592f77 100644 --- a/AutoWorkshopBusinessLogic/BusinessLogics/ShopLogic.cs +++ b/AutoWorkshopBusinessLogic/BusinessLogics/ShopLogic.cs @@ -102,7 +102,7 @@ namespace AutoWorkshopBusinessLogic.BusinessLogics if (Model.Count <= 0) throw new ArgumentException("Количество ремонтов должно быть больше 0"); - var Shop = _shopStorage.GetElement(new ShopSearchModel + ShopViewModel? Shop = _shopStorage.GetElement(new ShopSearchModel { Id = Model.ShopId }); @@ -112,9 +112,9 @@ namespace AutoWorkshopBusinessLogic.BusinessLogics if (Shop.ShopRepairs.ContainsKey(Model.RepairId)) { - var OldValue = Shop.ShopRepairs[Model.RepairId]; - OldValue.Item2 += Model.Count; - Shop.ShopRepairs[Model.RepairId] = OldValue; + var RepairsNum = Shop.ShopRepairs[Model.RepairId]; + RepairsNum.Item2 += Model.Count; + Shop.ShopRepairs[Model.RepairId] = RepairsNum; } else { @@ -124,11 +124,20 @@ namespace AutoWorkshopBusinessLogic.BusinessLogics }); if (Repair == null) - throw new ArgumentException($"Поставка: Товар с id:{Model.RepairId} не найденн"); + throw new ArgumentException($"Поставка: Товар с id {Model.RepairId} не найден"); Shop.ShopRepairs.Add(Model.RepairId, (Repair, Model.Count)); } - + + _shopStorage.Update(new ShopBindingModel() + { + Id = Shop.Id, + ShopName = Shop.ShopName, + Address = Shop.Address, + OpeningDate = Shop.OpeningDate, + ShopRepairs = Shop.ShopRepairs, + RepairsMaxCount = Shop.RepairsMaxCount, + }); return true; } @@ -159,14 +168,14 @@ namespace AutoWorkshopBusinessLogic.BusinessLogics } } - public bool Sale(SupplySearchModel Model) + public bool MakeSell(SupplySearchModel Model) { if (!Model.RepairId.HasValue || !Model.Count.HasValue) return false; _logger.LogInformation("Проверка ремонтов во всех магазинах"); - if (_shopStorage.Sale(Model)) + if (_shopStorage.Sell(Model)) { _logger.LogInformation("Продажа выполнена успешно"); return true; diff --git a/AutoWorkshopContracts/BusinessLogicContracts/IShopLogic.cs b/AutoWorkshopContracts/BusinessLogicContracts/IShopLogic.cs index 5bf41b7..496037a 100644 --- a/AutoWorkshopContracts/BusinessLogicContracts/IShopLogic.cs +++ b/AutoWorkshopContracts/BusinessLogicContracts/IShopLogic.cs @@ -18,6 +18,6 @@ namespace AutoWorkshopContracts.BusinessLogicsContracts bool MakeSupply(SupplyBindingModel Model); - bool Sale(SupplySearchModel Model); + bool MakeSell(SupplySearchModel Model); } } diff --git a/AutoWorkshopContracts/SearchModels/SupplySearchModel.cs b/AutoWorkshopContracts/SearchModels/SupplySearchModel.cs index 9cd3646..e0a9731 100644 --- a/AutoWorkshopContracts/SearchModels/SupplySearchModel.cs +++ b/AutoWorkshopContracts/SearchModels/SupplySearchModel.cs @@ -3,6 +3,7 @@ public class SupplySearchModel { public int? RepairId { get; set; } + public int? Count { get; set; } } } diff --git a/AutoWorkshopContracts/StoragesContracts/IShopStorage.cs b/AutoWorkshopContracts/StoragesContracts/IShopStorage.cs index e79a487..c516d00 100644 --- a/AutoWorkshopContracts/StoragesContracts/IShopStorage.cs +++ b/AutoWorkshopContracts/StoragesContracts/IShopStorage.cs @@ -17,8 +17,8 @@ namespace AutoWorkshopContracts.StoragesContracts ShopViewModel? Update(ShopBindingModel Model); ShopViewModel? Delete(ShopBindingModel Model); - - bool Sale(SupplySearchModel Model); + + bool Sell(SupplySearchModel Model); bool RestockingShops(SupplyBindingModel Model); } diff --git a/AutoWorkshopFileImplement/DataFileSingleton.cs b/AutoWorkshopFileImplement/DataFileSingleton.cs index 18a6f92..33b0d26 100644 --- a/AutoWorkshopFileImplement/DataFileSingleton.cs +++ b/AutoWorkshopFileImplement/DataFileSingleton.cs @@ -22,7 +22,7 @@ namespace AutoWorkshopFileImplement Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!; Repairs = LoadData(RepairFileName, "Repair", x => Repair.Create(x)!)!; Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!; - Shops = LoadData(ShopFileName, "Shop", x => Shop.Create(x)!)!; + Shops = LoadData(ShopFileName, "Shop", x => Shop.Create(x)!)!; } public static DataFileSingleton GetInstance() diff --git a/AutoWorkshopFileImplement/Implements/ShopStorage.cs b/AutoWorkshopFileImplement/Implements/ShopStorage.cs index f826d22..7873b4c 100644 --- a/AutoWorkshopFileImplement/Implements/ShopStorage.cs +++ b/AutoWorkshopFileImplement/Implements/ShopStorage.cs @@ -25,7 +25,11 @@ namespace AutoWorkshopFileImplement.Implements if (string.IsNullOrEmpty(Model.ShopName)) return new(); - return _source.Shops.Where(x => x.ShopName.Contains(Model.ShopName)).Select(x => x.GetViewModel).ToList(); + return _source.Shops + .Where(x => x.ShopName + .Contains(Model.ShopName)) + .Select(x => x.GetViewModel) + .ToList(); } public ShopViewModel? GetElement(ShopSearchModel Model) @@ -35,7 +39,8 @@ namespace AutoWorkshopFileImplement.Implements return _source.Shops.FirstOrDefault(x => (!string.IsNullOrEmpty(Model.ShopName) && x.ShopName == Model.ShopName) || - (Model.Id.HasValue && x.Id == Model.Id))?.GetViewModel; + (Model.Id.HasValue && x.Id == Model.Id))? + .GetViewModel; } public ShopViewModel? Insert(ShopBindingModel Model) @@ -77,7 +82,7 @@ namespace AutoWorkshopFileImplement.Implements return Shop.GetViewModel; } - public bool Sale(SupplySearchModel Model) + public bool Sell(SupplySearchModel Model) { if (Model == null || !Model.RepairId.HasValue || !Model.Count.HasValue) return false; @@ -92,21 +97,21 @@ namespace AutoWorkshopFileImplement.Implements foreach (var Shop in Shops) { - int Residue = Model.Count.Value - Shop.Repairs[Model.RepairId.Value]; + int Slack = Model.Count.Value - Shop.Repairs[Model.RepairId.Value]; - if (Residue > 0) + if (Slack > 0) { Shop.Repairs.Remove(Model.RepairId.Value); Shop.RepairsUpdate(); - Model.Count = Residue; + Model.Count = Slack; } else { - if (Residue == 0) + if (Slack == 0) Shop.Repairs.Remove(Model.RepairId.Value); else - Shop.Repairs[Model.RepairId.Value] = -Residue; + Shop.Repairs[Model.RepairId.Value] = -Slack; Shop.RepairsUpdate(); _source.SaveShops(); @@ -124,9 +129,9 @@ namespace AutoWorkshopFileImplement.Implements if (Model == null || _source.Shops.Select(x => x.RepairsMaxCount - x.ShopRepairs.Select(y => y.Value.Item2).Sum()).Sum() < Model.Count) return false; - foreach (Shop shop in _source.Shops) + foreach (Shop Shop in _source.Shops) { - int FreeSpaceNum = shop.RepairsMaxCount - shop.ShopRepairs.Select(x => x.Value.Item2).Sum(); + int FreeSpaceNum = Shop.RepairsMaxCount - Shop.ShopRepairs.Select(x => x.Value.Item2).Sum(); if (FreeSpaceNum <= 0) continue; @@ -134,12 +139,12 @@ namespace AutoWorkshopFileImplement.Implements FreeSpaceNum = Math.Min(FreeSpaceNum, Model.Count); Model.Count -= FreeSpaceNum; - if (shop.Repairs.ContainsKey(Model.RepairId)) - shop.Repairs[Model.RepairId] += FreeSpaceNum; + if (Shop.Repairs.ContainsKey(Model.RepairId)) + Shop.Repairs[Model.RepairId] += FreeSpaceNum; else - shop.Repairs.Add(Model.RepairId, FreeSpaceNum); + Shop.Repairs.Add(Model.RepairId, FreeSpaceNum); - shop.RepairsUpdate(); + Shop.RepairsUpdate(); if (Model.Count == 0) { diff --git a/AutoWorkshopFileImplement/Models/Shop.cs b/AutoWorkshopFileImplement/Models/Shop.cs index ac2e8e0..1d72178 100644 --- a/AutoWorkshopFileImplement/Models/Shop.cs +++ b/AutoWorkshopFileImplement/Models/Shop.cs @@ -56,7 +56,7 @@ namespace AutoWorkshopFileImplement.Models if (Element == null) return null; - return new() + return new Shop() { Id = Convert.ToInt32(Element.Attribute("Id")!.Value), ShopName = Element.Element("ShopName")!.Value, diff --git a/AutoWorkshopImplement/Implements/ShopStorage.cs b/AutoWorkshopImplement/Implements/ShopStorage.cs index f9e6626..64da069 100644 --- a/AutoWorkshopImplement/Implements/ShopStorage.cs +++ b/AutoWorkshopImplement/Implements/ShopStorage.cs @@ -109,7 +109,7 @@ namespace AutoWorkshopListImplement.Implements return null; } - public bool Sale(SupplySearchModel Model) + public bool Sell(SupplySearchModel Model) { throw new NotImplementedException(); } diff --git a/AutoWorkshopView/Forms/Shop/FormSellRepair.cs b/AutoWorkshopView/Forms/Shop/FormSellRepair.cs index 91ee224..ad41bd8 100644 --- a/AutoWorkshopView/Forms/Shop/FormSellRepair.cs +++ b/AutoWorkshopView/Forms/Shop/FormSellRepair.cs @@ -51,7 +51,7 @@ namespace AutoWorkshopView.Forms.Shop try { - bool Result = _shopLogic.Sale(new SupplySearchModel + bool Result = _shopLogic.MakeSell(new SupplySearchModel { RepairId = Convert.ToInt32(RepairComboBox.SelectedValue), Count = Convert.ToInt32(CountTextBox.Text) diff --git a/AutoWorkshopView/MainForm.cs b/AutoWorkshopView/MainForm.cs index 5d1f18b..2fc730c 100644 --- a/AutoWorkshopView/MainForm.cs +++ b/AutoWorkshopView/MainForm.cs @@ -190,6 +190,7 @@ namespace AutoWorkshopView private void SellToolStripMenuItem_Click(object sender, EventArgs e) { var Service = Program.ServiceProvider?.GetService(typeof(FormSellRepair)); + if (Service is FormSellRepair Form) { Form.ShowDialog(); From b81bb26b41ab2b71601c2e418f1b44027ca47497 Mon Sep 17 00:00:00 2001 From: Oleg Shabunov Date: Wed, 10 Apr 2024 23:59:33 +0400 Subject: [PATCH 10/21] shop repair overflow fix --- AutoWorkshopBusinessLogic/BusinessLogics/ShopLogic.cs | 10 ++++++++-- AutoWorkshopFileImplement/Implements/ShopStorage.cs | 8 +++++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/AutoWorkshopBusinessLogic/BusinessLogics/ShopLogic.cs b/AutoWorkshopBusinessLogic/BusinessLogics/ShopLogic.cs index d592f77..b15cce5 100644 --- a/AutoWorkshopBusinessLogic/BusinessLogics/ShopLogic.cs +++ b/AutoWorkshopBusinessLogic/BusinessLogics/ShopLogic.cs @@ -110,6 +110,13 @@ namespace AutoWorkshopBusinessLogic.BusinessLogics if (Shop == null) throw new ArgumentException("Магазина не существует"); + int CurrentRepairsNum = Shop.ShopRepairs.Select(x => x.Value.Item2).Sum(); + if (Model.Count > Shop.RepairsMaxCount - CurrentRepairsNum) + { + _logger.LogWarning("Попытка добавить в магазин число элементов, большее RepairsMaxCount"); + return false; + } + if (Shop.ShopRepairs.ContainsKey(Model.RepairId)) { var RepairsNum = Shop.ShopRepairs[Model.RepairId]; @@ -173,8 +180,7 @@ namespace AutoWorkshopBusinessLogic.BusinessLogics if (!Model.RepairId.HasValue || !Model.Count.HasValue) return false; - _logger.LogInformation("Проверка ремонтов во всех магазинах"); - + _logger.LogInformation("Поиск ремонтов во всех магазинах"); if (_shopStorage.Sell(Model)) { _logger.LogInformation("Продажа выполнена успешно"); diff --git a/AutoWorkshopFileImplement/Implements/ShopStorage.cs b/AutoWorkshopFileImplement/Implements/ShopStorage.cs index 7873b4c..7c4d816 100644 --- a/AutoWorkshopFileImplement/Implements/ShopStorage.cs +++ b/AutoWorkshopFileImplement/Implements/ShopStorage.cs @@ -87,15 +87,17 @@ namespace AutoWorkshopFileImplement.Implements if (Model == null || !Model.RepairId.HasValue || !Model.Count.HasValue) return false; - int RemainingSpace = _source.Shops.Select(x => x.Repairs.ContainsKey(Model.RepairId.Value) ? x.Repairs[Model.RepairId.Value] : 0).Sum(); + int RemainingSpace = _source.Shops + .Select(x => x.Repairs.ContainsKey(Model.RepairId.Value) ? x.Repairs[Model.RepairId.Value] : 0) + .Sum(); if (RemainingSpace < Model.Count) return false; - var Shops = _source.Shops + var ShopsWithDesiredRepair = _source.Shops .Where(x => x.Repairs.ContainsKey(Model.RepairId.Value)) .OrderByDescending(x => x.Repairs[Model.RepairId.Value]).ToList(); - foreach (var Shop in Shops) + foreach (var Shop in ShopsWithDesiredRepair) { int Slack = Model.Count.Value - Shop.Repairs[Model.RepairId.Value]; From 81b4335193ca0ba7ef51b018a89f20981742679d Mon Sep 17 00:00:00 2001 From: Oleg Shabunov Date: Wed, 17 Apr 2024 01:07:56 +0400 Subject: [PATCH 11/21] fix ShopStorage.Sell --- .../Implements/ShopStorage.cs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/AutoWorkshopFileImplement/Implements/ShopStorage.cs b/AutoWorkshopFileImplement/Implements/ShopStorage.cs index 7c4d816..d6492b1 100644 --- a/AutoWorkshopFileImplement/Implements/ShopStorage.cs +++ b/AutoWorkshopFileImplement/Implements/ShopStorage.cs @@ -87,15 +87,16 @@ namespace AutoWorkshopFileImplement.Implements if (Model == null || !Model.RepairId.HasValue || !Model.Count.HasValue) return false; - int RemainingSpace = _source.Shops + int TotalRepairsNum = _source.Shops .Select(x => x.Repairs.ContainsKey(Model.RepairId.Value) ? x.Repairs[Model.RepairId.Value] : 0) .Sum(); - if (RemainingSpace < Model.Count) + if (TotalRepairsNum < Model.Count) return false; var ShopsWithDesiredRepair = _source.Shops .Where(x => x.Repairs.ContainsKey(Model.RepairId.Value)) - .OrderByDescending(x => x.Repairs[Model.RepairId.Value]).ToList(); + .OrderByDescending(x => x.Repairs[Model.RepairId.Value]) + .ToList(); foreach (var Shop in ShopsWithDesiredRepair) { @@ -128,7 +129,13 @@ namespace AutoWorkshopFileImplement.Implements public bool RestockingShops(SupplyBindingModel Model) { - if (Model == null || _source.Shops.Select(x => x.RepairsMaxCount - x.ShopRepairs.Select(y => y.Value.Item2).Sum()).Sum() < Model.Count) + int TotalFreeSpaceNum = _source.Shops + .Select(x => x.RepairsMaxCount - x.ShopRepairs + .Select(y => y.Value.Item2) + .Sum()) + .Sum(); + + if (TotalFreeSpaceNum < Model.Count) return false; foreach (Shop Shop in _source.Shops) @@ -137,7 +144,7 @@ namespace AutoWorkshopFileImplement.Implements if (FreeSpaceNum <= 0) continue; - + FreeSpaceNum = Math.Min(FreeSpaceNum, Model.Count); Model.Count -= FreeSpaceNum; From fe3e9171e8164d05a1a56dc8ca475a095ccdd021 Mon Sep 17 00:00:00 2001 From: Oleg Shabunov Date: Wed, 17 Apr 2024 01:23:18 +0400 Subject: [PATCH 12/21] DatabaseImplement/Models --- .../AutoWorkshopDatabase.cs | 6 +- AutoWorkshopDatabaseImplement/Models/Shop.cs | 123 ++++++++++++++++++ .../Models/ShopRepair.cs | 22 ++++ 3 files changed, 150 insertions(+), 1 deletion(-) create mode 100644 AutoWorkshopDatabaseImplement/Models/Shop.cs create mode 100644 AutoWorkshopDatabaseImplement/Models/ShopRepair.cs diff --git a/AutoWorkshopDatabaseImplement/AutoWorkshopDatabase.cs b/AutoWorkshopDatabaseImplement/AutoWorkshopDatabase.cs index ced4c8f..c14ca57 100644 --- a/AutoWorkshopDatabaseImplement/AutoWorkshopDatabase.cs +++ b/AutoWorkshopDatabaseImplement/AutoWorkshopDatabase.cs @@ -9,7 +9,7 @@ namespace AutoWorkshopDatabaseImplement { if (OptionsBuilder.IsConfigured == false) { - OptionsBuilder.UseNpgsql(@"Host=localhost;Database=AutoWorkshop;Username=postgres;Password=admin"); + OptionsBuilder.UseNpgsql(@"Host=localhost;Database=AutoWorkshop_Hard;Username=postgres;Password=admin"); } base.OnConfiguring(OptionsBuilder); @@ -25,5 +25,9 @@ namespace AutoWorkshopDatabaseImplement public virtual DbSet RepairComponents { set; get; } public virtual DbSet Orders { set; get; } + + public virtual DbSet Shops { get; set; } + + public virtual DbSet ShopRepairs { get; set; } } } diff --git a/AutoWorkshopDatabaseImplement/Models/Shop.cs b/AutoWorkshopDatabaseImplement/Models/Shop.cs new file mode 100644 index 0000000..3ad4006 --- /dev/null +++ b/AutoWorkshopDatabaseImplement/Models/Shop.cs @@ -0,0 +1,123 @@ +using AutoWorkshopContracts.BindingModels; +using AutoWorkshopContracts.ViewModels; +using AutoWorkshopDataModels.Models; +using System.ComponentModel.DataAnnotations.Schema; + +namespace AutoWorkshopDatabaseImplement.Models +{ + public class Shop : 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; } + + public int RepairsMaxCount { get; set; } + + private Dictionary? _shopRepairs = null; + + public Dictionary ShopRepairs + { + get + { + if (_shopRepairs == null) + { + if (_shopRepairs == null) + { + _shopRepairs = Repairs.ToDictionary(ShopRep => ShopRep.RepairId, ShopRep => (ShopRep.Repair as IRepairModel, ShopRep.Count)); + } + return _shopRepairs; + } + + return _shopRepairs; + } + } + + [ForeignKey("ShopId")] + public List Repairs { get; set; } = new(); + + public static Shop Create(AutoWorkshopDatabase Context, ShopBindingModel Model) + { + return new Shop() + { + Id = Model.Id, + ShopName = Model.ShopName, + Address = Model.Address, + OpeningDate = Model.OpeningDate, + Repairs = Model.ShopRepairs.Select(x => new ShopRepair + { + Repair = Context.Repairs.First(y => y.Id == x.Key), + Count = x.Value.Item2 + }).ToList(), + RepairsMaxCount = Model.RepairsMaxCount + }; + } + + public void Update(ShopBindingModel Model) + { + ShopName = Model.ShopName; + Address = Model.Address; + OpeningDate = Model.OpeningDate; + RepairsMaxCount = Model.RepairsMaxCount; + } + + public ShopViewModel GetViewModel => new() + { + Id = Id, + ShopName = ShopName, + Address = Address, + OpeningDate = OpeningDate, + ShopRepairs = ShopRepairs, + RepairsMaxCount = RepairsMaxCount + }; + + public void UpdateRepairs(AutoWorkshopDatabase Context, ShopBindingModel Model) + { + var ShopRepairs = Context.ShopRepairs + .Where(rec => rec.ShopId == Model.Id) + .ToList(); + + if (ShopRepairs != null && ShopRepairs.Count > 0) + { + Context.ShopRepairs.RemoveRange(ShopRepairs.Where(rec => !Model.ShopRepairs.ContainsKey(rec.RepairId))); + Context.SaveChanges(); + + foreach (var RepairToUpdate in ShopRepairs) + { + RepairToUpdate.Count = Model.ShopRepairs[RepairToUpdate.RepairId].Item2; + Model.ShopRepairs.Remove(RepairToUpdate.RepairId); + } + + Context.SaveChanges(); + } + + var Shop = Context.Shops.First(x => x.Id == Id); + + foreach (var ShopRepair in Model.ShopRepairs) + { + Context.ShopRepairs.Add(new ShopRepair + { + Shop = Shop, + Repair = Context.Repairs.First(x => x.Id == ShopRepair.Key), + Count = ShopRepair.Value.Item2 + }); + + Context.SaveChanges(); + } + + _shopRepairs = null; + } + + public void RepairsDictionatyUpdate(AutoWorkshopDatabase Context) + { + UpdateRepairs(Context, new ShopBindingModel + { + Id = Id, + ShopRepairs = ShopRepairs + }); + } + } +} diff --git a/AutoWorkshopDatabaseImplement/Models/ShopRepair.cs b/AutoWorkshopDatabaseImplement/Models/ShopRepair.cs new file mode 100644 index 0000000..2810e13 --- /dev/null +++ b/AutoWorkshopDatabaseImplement/Models/ShopRepair.cs @@ -0,0 +1,22 @@ +using System.ComponentModel.DataAnnotations; + +namespace AutoWorkshopDatabaseImplement.Models +{ + public class ShopRepair + { + public int Id { get; set; } + + [Required] + public int RepairId { get; set; } + + [Required] + public int ShopId { get; set; } + + [Required] + public int Count { get; set; } + + public virtual Shop Shop { get; set; } = new(); + + public virtual Repair Repair { get; set; } = new(); + } +} From 3d750ef0b27a889f6b9f74902919035c8e5a38f5 Mon Sep 17 00:00:00 2001 From: Oleg Shabunov Date: Wed, 17 Apr 2024 01:36:29 +0400 Subject: [PATCH 13/21] DatabaseImplement - ShopStorage --- .../Implements/ShopStorage.cs | 220 ++++++++++++++++++ 1 file changed, 220 insertions(+) create mode 100644 AutoWorkshopDatabaseImplement/Implements/ShopStorage.cs diff --git a/AutoWorkshopDatabaseImplement/Implements/ShopStorage.cs b/AutoWorkshopDatabaseImplement/Implements/ShopStorage.cs new file mode 100644 index 0000000..41443c0 --- /dev/null +++ b/AutoWorkshopDatabaseImplement/Implements/ShopStorage.cs @@ -0,0 +1,220 @@ +using AutoWorkshopContracts.BindingModels; +using AutoWorkshopContracts.SearchModels; +using AutoWorkshopContracts.StoragesContracts; +using AutoWorkshopContracts.ViewModels; +using AutoWorkshopDatabaseImplement.Models; +using Microsoft.EntityFrameworkCore; + +namespace AutoWorkshopDatabaseImplement.Implements +{ + public class ShopStorage : IShopStorage + { + public List GetFullList() + { + using var Context = new AutoWorkshopDatabase(); + return Context.Shops + .Include(x => x.Repairs) + .ThenInclude(x => x.Repair) + .ToList() + .Select(x => x.GetViewModel) + .ToList(); + } + + public List GetFilteredList(ShopSearchModel Model) + { + if (string.IsNullOrEmpty(Model.ShopName)) + return new(); + + using var Context = new AutoWorkshopDatabase(); + + return Context.Shops + .Include(x => x.Repairs) + .ThenInclude(x => x.Repair) + .Where(x => x.ShopName.Contains(Model.ShopName)) + .ToList() + .Select(x => x.GetViewModel) + .ToList(); + } + + public ShopViewModel? GetElement(ShopSearchModel Model) + { + if (string.IsNullOrEmpty(Model.ShopName) && !Model.Id.HasValue) + return new(); + + using var Context = new AutoWorkshopDatabase(); + + return Context.Shops + .Include(x => x.Repairs) + .ThenInclude(x => x.Repair) + .FirstOrDefault(x => (!string.IsNullOrEmpty(Model.ShopName) && x.ShopName == Model.ShopName) || + (Model.Id.HasValue && x.Id == Model.Id))? + .GetViewModel; + } + + public ShopViewModel? Insert(ShopBindingModel Model) + { + using var Context = new AutoWorkshopDatabase(); + + var NewShop = Shop.Create(Context, Model); + if (NewShop == null) + return null; + + Context.Shops.Add(NewShop); + Context.SaveChanges(); + + return NewShop.GetViewModel; + } + + public ShopViewModel? Update(ShopBindingModel Model) + { + using var Context = new AutoWorkshopDatabase(); + + using var Transaction = Context.Database.BeginTransaction(); + try + { + var Shop = Context.Shops.FirstOrDefault(x => x.Id == Model.Id); + + if (Shop == null) + return null; + + Shop.Update(Model); + Context.SaveChanges(); + Shop.UpdateRepairs(Context, Model); + + Transaction.Commit(); + return Shop.GetViewModel; + } + catch + { + Transaction.Rollback(); + throw; + } + } + + public ShopViewModel? Delete(ShopBindingModel Model) + { + using var Context = new AutoWorkshopDatabase(); + + var Shop = Context.Shops + .Include(x => x.Repairs) + .FirstOrDefault(x => x.Id == Model.Id); + + if (Shop == null) + return null; + + Context.Shops.Remove(Shop); + Context.SaveChanges(); + + return Shop.GetViewModel; + } + + public bool RestockingShops(SupplyBindingModel Model) + { + using var Context = new AutoWorkshopDatabase(); + var Transaction = Context.Database.BeginTransaction(); + + var Shops = Context.Shops + .Include(x => x.Repairs) + .ThenInclude(x => x.Repair) + .ToList() + .Where(x => x.RepairsMaxCount > x.ShopRepairs + .Select(x => x.Value.Item2).Sum()) + .ToList(); + + try + { + foreach (Shop Shop in Shops) + { + int Difference = Shop.RepairsMaxCount - Shop.ShopRepairs.Select(x => x.Value.Item2).Sum(); + int Refill = Math.Min(Difference, Model.Count); + + Model.Count -= Refill; + + if (Shop.ShopRepairs.ContainsKey(Model.RepairId)) + { + var DatePair = Shop.ShopRepairs[Model.RepairId]; + DatePair.Item2 += Refill; + Shop.ShopRepairs[Model.RepairId] = DatePair; + } + else + { + var Repair = Context.Repairs.First(x => x.Id == Model.RepairId); + Shop.ShopRepairs.Add(Model.RepairId, (Repair, Refill)); + } + + Shop.RepairsDictionatyUpdate(Context); + + if (Model.Count == 0) + { + Transaction.Commit(); + return true; + } + } + + Transaction.Rollback(); + return false; + } + catch + { + Transaction.Rollback(); + throw; + } + } + + public bool Sell(SupplySearchModel Model) + { + using var Context = new AutoWorkshopDatabase(); + var Transaction = Context.Database.BeginTransaction(); + + try + { + var Shops = Context.Shops + .Include(x => x.Repairs) + .ThenInclude(x => x.Repair) + .ToList() + .Where(x => x.ShopRepairs.ContainsKey(Model.RepairId.Value)) + .OrderByDescending(x => x.ShopRepairs[Model.RepairId.Value].Item2) + .ToList(); + + foreach (var Shop in Shops) + { + int Residue = Model.Count.Value - Shop.ShopRepairs[Model.RepairId.Value].Item2; + + if (Residue > 0) + { + Shop.ShopRepairs.Remove(Model.RepairId.Value); + Shop.RepairsDictionatyUpdate(Context); + Context.SaveChanges(); + + Model.Count = Residue; + } + else + { + if (Residue == 0) + Shop.ShopRepairs.Remove(Model.RepairId.Value); + + else + { + var DataPair = Shop.ShopRepairs[Model.RepairId.Value]; + DataPair.Item2 = -Residue; + Shop.ShopRepairs[Model.RepairId.Value] = DataPair; + } + + Shop.RepairsDictionatyUpdate(Context); + Transaction.Commit(); + + return true; + } + } + + Transaction.Rollback(); + return false; + } + catch + { + Transaction.Rollback(); + throw; + } + } + } +} From 1d24f917732ae3e8ab2190c14b460904b031df2f Mon Sep 17 00:00:00 2001 From: Oleg Shabunov Date: Wed, 17 Apr 2024 11:10:28 +0400 Subject: [PATCH 14/21] update migration --- .../Implements/ShopStorage.cs | 133 +++++++++--------- ...er.cs => 20240417061857_Shops.Designer.cs} | 81 ++++++++++- ...itialCreate.cs => 20240417061857_Shops.cs} | 61 +++++++- .../AutoWorkshopDatabaseModelSnapshot.cs | 77 ++++++++++ AutoWorkshopDatabaseImplement/Models/Shop.cs | 6 +- 5 files changed, 287 insertions(+), 71 deletions(-) rename AutoWorkshopDatabaseImplement/Migrations/{20240402181656_InitialCreate.Designer.cs => 20240417061857_Shops.Designer.cs} (68%) rename AutoWorkshopDatabaseImplement/Migrations/{20240402181656_InitialCreate.cs => 20240417061857_Shops.cs} (66%) diff --git a/AutoWorkshopDatabaseImplement/Implements/ShopStorage.cs b/AutoWorkshopDatabaseImplement/Implements/ShopStorage.cs index 41443c0..2685c94 100644 --- a/AutoWorkshopDatabaseImplement/Implements/ShopStorage.cs +++ b/AutoWorkshopDatabaseImplement/Implements/ShopStorage.cs @@ -106,60 +106,7 @@ namespace AutoWorkshopDatabaseImplement.Implements Context.SaveChanges(); return Shop.GetViewModel; - } - - public bool RestockingShops(SupplyBindingModel Model) - { - using var Context = new AutoWorkshopDatabase(); - var Transaction = Context.Database.BeginTransaction(); - - var Shops = Context.Shops - .Include(x => x.Repairs) - .ThenInclude(x => x.Repair) - .ToList() - .Where(x => x.RepairsMaxCount > x.ShopRepairs - .Select(x => x.Value.Item2).Sum()) - .ToList(); - - try - { - foreach (Shop Shop in Shops) - { - int Difference = Shop.RepairsMaxCount - Shop.ShopRepairs.Select(x => x.Value.Item2).Sum(); - int Refill = Math.Min(Difference, Model.Count); - - Model.Count -= Refill; - - if (Shop.ShopRepairs.ContainsKey(Model.RepairId)) - { - var DatePair = Shop.ShopRepairs[Model.RepairId]; - DatePair.Item2 += Refill; - Shop.ShopRepairs[Model.RepairId] = DatePair; - } - else - { - var Repair = Context.Repairs.First(x => x.Id == Model.RepairId); - Shop.ShopRepairs.Add(Model.RepairId, (Repair, Refill)); - } - - Shop.RepairsDictionatyUpdate(Context); - - if (Model.Count == 0) - { - Transaction.Commit(); - return true; - } - } - - Transaction.Rollback(); - return false; - } - catch - { - Transaction.Rollback(); - throw; - } - } + } public bool Sell(SupplySearchModel Model) { @@ -168,7 +115,7 @@ namespace AutoWorkshopDatabaseImplement.Implements try { - var Shops = Context.Shops + var ShopsWithDesiredRepair = Context.Shops .Include(x => x.Repairs) .ThenInclude(x => x.Repair) .ToList() @@ -176,28 +123,29 @@ namespace AutoWorkshopDatabaseImplement.Implements .OrderByDescending(x => x.ShopRepairs[Model.RepairId.Value].Item2) .ToList(); - foreach (var Shop in Shops) + foreach (var Shop in ShopsWithDesiredRepair) { - int Residue = Model.Count.Value - Shop.ShopRepairs[Model.RepairId.Value].Item2; + int Slack = Model.Count.Value - Shop.ShopRepairs[Model.RepairId.Value].Item2; - if (Residue > 0) + if (Slack > 0) { - Shop.ShopRepairs.Remove(Model.RepairId.Value); + Shop.ShopRepairs.Remove(Model.RepairId.Value); Shop.RepairsDictionatyUpdate(Context); Context.SaveChanges(); - Model.Count = Residue; + Model.Count = Slack; } else { - if (Residue == 0) + if (Slack == 0) + { Shop.ShopRepairs.Remove(Model.RepairId.Value); - + } else { - var DataPair = Shop.ShopRepairs[Model.RepairId.Value]; - DataPair.Item2 = -Residue; - Shop.ShopRepairs[Model.RepairId.Value] = DataPair; + var RepairAndCount = Shop.ShopRepairs[Model.RepairId.Value]; + RepairAndCount.Item2 = -Slack; + Shop.ShopRepairs[Model.RepairId.Value] = RepairAndCount; } Shop.RepairsDictionatyUpdate(Context); @@ -216,5 +164,58 @@ namespace AutoWorkshopDatabaseImplement.Implements throw; } } - } + + public bool RestockingShops(SupplyBindingModel Model) + { + using var Context = new AutoWorkshopDatabase(); + var Transaction = Context.Database.BeginTransaction(); + + var Shops = Context.Shops + .Include(x => x.Repairs) + .ThenInclude(x => x.Repair) + .ToList() + .Where(x => x.RepairsMaxCount > x.ShopRepairs + .Select(x => x.Value.Item2).Sum()) + .ToList(); + + try + { + foreach (Shop Shop in Shops) + { + int FreeSpaceNum = Shop.RepairsMaxCount - Shop.ShopRepairs.Select(x => x.Value.Item2).Sum(); + + int Refill = Math.Min(FreeSpaceNum, Model.Count); + Model.Count -= Refill; + + if (Shop.ShopRepairs.ContainsKey(Model.RepairId)) + { + var RepairAndCount = Shop.ShopRepairs[Model.RepairId]; + RepairAndCount.Item2 += Refill; + Shop.ShopRepairs[Model.RepairId] = RepairAndCount; + } + else + { + var Repair = Context.Repairs.First(x => x.Id == Model.RepairId); + Shop.ShopRepairs.Add(Model.RepairId, (Repair, Refill)); + } + + Shop.RepairsDictionatyUpdate(Context); + + if (Model.Count == 0) + { + Transaction.Commit(); + return true; + } + } + + Transaction.Rollback(); + return false; + } + catch + { + Transaction.Rollback(); + throw; + } + } + } } diff --git a/AutoWorkshopDatabaseImplement/Migrations/20240402181656_InitialCreate.Designer.cs b/AutoWorkshopDatabaseImplement/Migrations/20240417061857_Shops.Designer.cs similarity index 68% rename from AutoWorkshopDatabaseImplement/Migrations/20240402181656_InitialCreate.Designer.cs rename to AutoWorkshopDatabaseImplement/Migrations/20240417061857_Shops.Designer.cs index 06a8333..dcb69a0 100644 --- a/AutoWorkshopDatabaseImplement/Migrations/20240402181656_InitialCreate.Designer.cs +++ b/AutoWorkshopDatabaseImplement/Migrations/20240417061857_Shops.Designer.cs @@ -12,8 +12,8 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; namespace AutoWorkshopDatabaseImplement.Migrations { [DbContext(typeof(AutoWorkshopDatabase))] - [Migration("20240402181656_InitialCreate")] - partial class InitialCreate + [Migration("20240417061857_Shops")] + partial class Shops { /// protected override void BuildTargetModel(ModelBuilder modelBuilder) @@ -124,6 +124,59 @@ namespace AutoWorkshopDatabaseImplement.Migrations b.ToTable("RepairComponents"); }); + modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.Shop", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Address") + .IsRequired() + .HasColumnType("text"); + + b.Property("OpeningDate") + .HasColumnType("timestamp without time zone"); + + b.Property("RepairsMaxCount") + .HasColumnType("integer"); + + b.Property("ShopName") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Shops"); + }); + + modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.ShopRepair", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Count") + .HasColumnType("integer"); + + b.Property("RepairId") + .HasColumnType("integer"); + + b.Property("ShopId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("RepairId"); + + b.HasIndex("ShopId"); + + b.ToTable("ShopRepairs"); + }); + modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.Order", b => { b.HasOne("AutoWorkshopDatabaseImplement.Models.Repair", "Repair") @@ -154,6 +207,25 @@ namespace AutoWorkshopDatabaseImplement.Migrations b.Navigation("Repair"); }); + modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.ShopRepair", b => + { + b.HasOne("AutoWorkshopDatabaseImplement.Models.Repair", "Repair") + .WithMany() + .HasForeignKey("RepairId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("AutoWorkshopDatabaseImplement.Models.Shop", "Shop") + .WithMany("Repairs") + .HasForeignKey("ShopId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Repair"); + + b.Navigation("Shop"); + }); + modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.Component", b => { b.Navigation("RepairComponents"); @@ -165,6 +237,11 @@ namespace AutoWorkshopDatabaseImplement.Migrations b.Navigation("Orders"); }); + + modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.Shop", b => + { + b.Navigation("Repairs"); + }); #pragma warning restore 612, 618 } } diff --git a/AutoWorkshopDatabaseImplement/Migrations/20240402181656_InitialCreate.cs b/AutoWorkshopDatabaseImplement/Migrations/20240417061857_Shops.cs similarity index 66% rename from AutoWorkshopDatabaseImplement/Migrations/20240402181656_InitialCreate.cs rename to AutoWorkshopDatabaseImplement/Migrations/20240417061857_Shops.cs index dd113b0..a4f4cc6 100644 --- a/AutoWorkshopDatabaseImplement/Migrations/20240402181656_InitialCreate.cs +++ b/AutoWorkshopDatabaseImplement/Migrations/20240417061857_Shops.cs @@ -7,7 +7,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; namespace AutoWorkshopDatabaseImplement.Migrations { /// - public partial class InitialCreate : Migration + public partial class Shops : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) @@ -40,6 +40,22 @@ namespace AutoWorkshopDatabaseImplement.Migrations table.PrimaryKey("PK_Repairs", x => x.Id); }); + migrationBuilder.CreateTable( + name: "Shops", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + ShopName = table.Column(type: "text", nullable: false), + Address = table.Column(type: "text", nullable: false), + OpeningDate = table.Column(type: "timestamp without time zone", nullable: false), + RepairsMaxCount = table.Column(type: "integer", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Shops", x => x.Id); + }); + migrationBuilder.CreateTable( name: "Orders", columns: table => new @@ -91,6 +107,33 @@ namespace AutoWorkshopDatabaseImplement.Migrations onDelete: ReferentialAction.Cascade); }); + migrationBuilder.CreateTable( + name: "ShopRepairs", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + RepairId = table.Column(type: "integer", nullable: false), + ShopId = table.Column(type: "integer", nullable: false), + Count = table.Column(type: "integer", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_ShopRepairs", x => x.Id); + table.ForeignKey( + name: "FK_ShopRepairs_Repairs_RepairId", + column: x => x.RepairId, + principalTable: "Repairs", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_ShopRepairs_Shops_ShopId", + column: x => x.ShopId, + principalTable: "Shops", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + migrationBuilder.CreateIndex( name: "IX_Orders_RepairId", table: "Orders", @@ -105,6 +148,16 @@ namespace AutoWorkshopDatabaseImplement.Migrations name: "IX_RepairComponents_RepairId", table: "RepairComponents", column: "RepairId"); + + migrationBuilder.CreateIndex( + name: "IX_ShopRepairs_RepairId", + table: "ShopRepairs", + column: "RepairId"); + + migrationBuilder.CreateIndex( + name: "IX_ShopRepairs_ShopId", + table: "ShopRepairs", + column: "ShopId"); } /// @@ -116,11 +169,17 @@ namespace AutoWorkshopDatabaseImplement.Migrations migrationBuilder.DropTable( name: "RepairComponents"); + migrationBuilder.DropTable( + name: "ShopRepairs"); + migrationBuilder.DropTable( name: "Components"); migrationBuilder.DropTable( name: "Repairs"); + + migrationBuilder.DropTable( + name: "Shops"); } } } diff --git a/AutoWorkshopDatabaseImplement/Migrations/AutoWorkshopDatabaseModelSnapshot.cs b/AutoWorkshopDatabaseImplement/Migrations/AutoWorkshopDatabaseModelSnapshot.cs index 40a9aca..454b66c 100644 --- a/AutoWorkshopDatabaseImplement/Migrations/AutoWorkshopDatabaseModelSnapshot.cs +++ b/AutoWorkshopDatabaseImplement/Migrations/AutoWorkshopDatabaseModelSnapshot.cs @@ -121,6 +121,59 @@ namespace AutoWorkshopDatabaseImplement.Migrations b.ToTable("RepairComponents"); }); + modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.Shop", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Address") + .IsRequired() + .HasColumnType("text"); + + b.Property("OpeningDate") + .HasColumnType("timestamp without time zone"); + + b.Property("RepairsMaxCount") + .HasColumnType("integer"); + + b.Property("ShopName") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Shops"); + }); + + modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.ShopRepair", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Count") + .HasColumnType("integer"); + + b.Property("RepairId") + .HasColumnType("integer"); + + b.Property("ShopId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("RepairId"); + + b.HasIndex("ShopId"); + + b.ToTable("ShopRepairs"); + }); + modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.Order", b => { b.HasOne("AutoWorkshopDatabaseImplement.Models.Repair", "Repair") @@ -151,6 +204,25 @@ namespace AutoWorkshopDatabaseImplement.Migrations b.Navigation("Repair"); }); + modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.ShopRepair", b => + { + b.HasOne("AutoWorkshopDatabaseImplement.Models.Repair", "Repair") + .WithMany() + .HasForeignKey("RepairId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("AutoWorkshopDatabaseImplement.Models.Shop", "Shop") + .WithMany("Repairs") + .HasForeignKey("ShopId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Repair"); + + b.Navigation("Shop"); + }); + modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.Component", b => { b.Navigation("RepairComponents"); @@ -162,6 +234,11 @@ namespace AutoWorkshopDatabaseImplement.Migrations b.Navigation("Orders"); }); + + modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.Shop", b => + { + b.Navigation("Repairs"); + }); #pragma warning restore 612, 618 } } diff --git a/AutoWorkshopDatabaseImplement/Models/Shop.cs b/AutoWorkshopDatabaseImplement/Models/Shop.cs index 3ad4006..59aef6c 100644 --- a/AutoWorkshopDatabaseImplement/Models/Shop.cs +++ b/AutoWorkshopDatabaseImplement/Models/Shop.cs @@ -84,8 +84,10 @@ namespace AutoWorkshopDatabaseImplement.Models { Context.ShopRepairs.RemoveRange(ShopRepairs.Where(rec => !Model.ShopRepairs.ContainsKey(rec.RepairId))); Context.SaveChanges(); - - foreach (var RepairToUpdate in ShopRepairs) + + ShopRepairs = Context.ShopRepairs.Where(rec => rec.ShopId == Model.Id).ToList(); + + foreach (var RepairToUpdate in ShopRepairs) { RepairToUpdate.Count = Model.ShopRepairs[RepairToUpdate.RepairId].Item2; Model.ShopRepairs.Remove(RepairToUpdate.RepairId); From 67bffd679878e0afacc22e9156340d43365ee17b Mon Sep 17 00:00:00 2001 From: Oleg Shabunov Date: Sun, 5 May 2024 21:41:04 +0400 Subject: [PATCH 15/21] Fix Shop-Repair relationship --- .../AutoWorkshopDatabase.cs | 2 +- ...4_Fix Shop-Repair relationship.Designer.cs | 250 ++++++++++++++++++ ...0505173724_Fix Shop-Repair relationship.cs | 22 ++ .../AutoWorkshopDatabaseModelSnapshot.cs | 4 +- .../Models/Repair.cs | 5 +- AutoWorkshopDatabaseImplement/Models/Shop.cs | 14 +- 6 files changed, 290 insertions(+), 7 deletions(-) create mode 100644 AutoWorkshopDatabaseImplement/Migrations/20240505173724_Fix Shop-Repair relationship.Designer.cs create mode 100644 AutoWorkshopDatabaseImplement/Migrations/20240505173724_Fix Shop-Repair relationship.cs diff --git a/AutoWorkshopDatabaseImplement/AutoWorkshopDatabase.cs b/AutoWorkshopDatabaseImplement/AutoWorkshopDatabase.cs index c14ca57..5088a41 100644 --- a/AutoWorkshopDatabaseImplement/AutoWorkshopDatabase.cs +++ b/AutoWorkshopDatabaseImplement/AutoWorkshopDatabase.cs @@ -9,7 +9,7 @@ namespace AutoWorkshopDatabaseImplement { if (OptionsBuilder.IsConfigured == false) { - OptionsBuilder.UseNpgsql(@"Host=localhost;Database=AutoWorkshop_Hard;Username=postgres;Password=admin"); + OptionsBuilder.UseNpgsql(@"Host=localhost;Port=5000;Database=AutoWorkshop_Hard;Username=postgres;Password=admin"); } base.OnConfiguring(OptionsBuilder); diff --git a/AutoWorkshopDatabaseImplement/Migrations/20240505173724_Fix Shop-Repair relationship.Designer.cs b/AutoWorkshopDatabaseImplement/Migrations/20240505173724_Fix Shop-Repair relationship.Designer.cs new file mode 100644 index 0000000..ac63286 --- /dev/null +++ b/AutoWorkshopDatabaseImplement/Migrations/20240505173724_Fix Shop-Repair relationship.Designer.cs @@ -0,0 +1,250 @@ +// +using System; +using AutoWorkshopDatabaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace AutoWorkshopDatabaseImplement.Migrations +{ + [DbContext(typeof(AutoWorkshopDatabase))] + [Migration("20240505173724_Fix Shop-Repair relationship")] + partial class FixShopRepairrelationship + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.17") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.Component", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ComponentName") + .IsRequired() + .HasColumnType("text"); + + b.Property("Cost") + .HasColumnType("double precision"); + + b.HasKey("Id"); + + b.ToTable("Components"); + }); + + modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.Order", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Count") + .HasColumnType("integer"); + + b.Property("DateCreate") + .HasColumnType("timestamp without time zone"); + + b.Property("DateImplement") + .HasColumnType("timestamp without time zone"); + + b.Property("RepairId") + .HasColumnType("integer"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("Sum") + .HasColumnType("double precision"); + + b.HasKey("Id"); + + b.HasIndex("RepairId"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.Repair", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Price") + .HasColumnType("double precision"); + + b.Property("RepairName") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Repairs"); + }); + + modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.RepairComponent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ComponentId") + .HasColumnType("integer"); + + b.Property("Count") + .HasColumnType("integer"); + + b.Property("RepairId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("ComponentId"); + + b.HasIndex("RepairId"); + + b.ToTable("RepairComponents"); + }); + + modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.Shop", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Address") + .IsRequired() + .HasColumnType("text"); + + b.Property("OpeningDate") + .HasColumnType("timestamp without time zone"); + + b.Property("RepairsMaxCount") + .HasColumnType("integer"); + + b.Property("ShopName") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Shops"); + }); + + modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.ShopRepair", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Count") + .HasColumnType("integer"); + + b.Property("RepairId") + .HasColumnType("integer"); + + b.Property("ShopId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("RepairId"); + + b.HasIndex("ShopId"); + + b.ToTable("ShopRepairs"); + }); + + modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.Order", b => + { + b.HasOne("AutoWorkshopDatabaseImplement.Models.Repair", "Repair") + .WithMany("Orders") + .HasForeignKey("RepairId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Repair"); + }); + + modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.RepairComponent", b => + { + b.HasOne("AutoWorkshopDatabaseImplement.Models.Component", "Component") + .WithMany("RepairComponents") + .HasForeignKey("ComponentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("AutoWorkshopDatabaseImplement.Models.Repair", "Repair") + .WithMany("Components") + .HasForeignKey("RepairId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Component"); + + b.Navigation("Repair"); + }); + + modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.ShopRepair", b => + { + b.HasOne("AutoWorkshopDatabaseImplement.Models.Repair", "Repair") + .WithMany("Shops") + .HasForeignKey("RepairId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("AutoWorkshopDatabaseImplement.Models.Shop", "Shop") + .WithMany("Repairs") + .HasForeignKey("ShopId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Repair"); + + b.Navigation("Shop"); + }); + + modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.Component", b => + { + b.Navigation("RepairComponents"); + }); + + modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.Repair", b => + { + b.Navigation("Components"); + + b.Navigation("Orders"); + + b.Navigation("Shops"); + }); + + modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.Shop", b => + { + b.Navigation("Repairs"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/AutoWorkshopDatabaseImplement/Migrations/20240505173724_Fix Shop-Repair relationship.cs b/AutoWorkshopDatabaseImplement/Migrations/20240505173724_Fix Shop-Repair relationship.cs new file mode 100644 index 0000000..1738a1e --- /dev/null +++ b/AutoWorkshopDatabaseImplement/Migrations/20240505173724_Fix Shop-Repair relationship.cs @@ -0,0 +1,22 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace AutoWorkshopDatabaseImplement.Migrations +{ + /// + public partial class FixShopRepairrelationship : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + + } + } +} diff --git a/AutoWorkshopDatabaseImplement/Migrations/AutoWorkshopDatabaseModelSnapshot.cs b/AutoWorkshopDatabaseImplement/Migrations/AutoWorkshopDatabaseModelSnapshot.cs index 454b66c..7dc1d54 100644 --- a/AutoWorkshopDatabaseImplement/Migrations/AutoWorkshopDatabaseModelSnapshot.cs +++ b/AutoWorkshopDatabaseImplement/Migrations/AutoWorkshopDatabaseModelSnapshot.cs @@ -207,7 +207,7 @@ namespace AutoWorkshopDatabaseImplement.Migrations modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.ShopRepair", b => { b.HasOne("AutoWorkshopDatabaseImplement.Models.Repair", "Repair") - .WithMany() + .WithMany("Shops") .HasForeignKey("RepairId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); @@ -233,6 +233,8 @@ namespace AutoWorkshopDatabaseImplement.Migrations b.Navigation("Components"); b.Navigation("Orders"); + + b.Navigation("Shops"); }); modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.Shop", b => diff --git a/AutoWorkshopDatabaseImplement/Models/Repair.cs b/AutoWorkshopDatabaseImplement/Models/Repair.cs index e4707ba..b98ccb8 100644 --- a/AutoWorkshopDatabaseImplement/Models/Repair.cs +++ b/AutoWorkshopDatabaseImplement/Models/Repair.cs @@ -38,7 +38,10 @@ namespace AutoWorkshopDatabaseImplement.Models [ForeignKey("RepairId")] public virtual List Orders { get; set; } = new(); - + + [ForeignKey("RepairId")] + public virtual List Shops { get; set; } = new(); + public static Repair Create(AutoWorkshopDatabase Context, RepairBindingModel Model) { return new Repair() diff --git a/AutoWorkshopDatabaseImplement/Models/Shop.cs b/AutoWorkshopDatabaseImplement/Models/Shop.cs index 59aef6c..63f60b8 100644 --- a/AutoWorkshopDatabaseImplement/Models/Shop.cs +++ b/AutoWorkshopDatabaseImplement/Models/Shop.cs @@ -1,6 +1,7 @@ using AutoWorkshopContracts.BindingModels; using AutoWorkshopContracts.ViewModels; using AutoWorkshopDataModels.Models; +using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; namespace AutoWorkshopDatabaseImplement.Models @@ -8,17 +9,25 @@ namespace AutoWorkshopDatabaseImplement.Models public class Shop : IShopModel { public int Id { get; set; } - + + [Required] public string ShopName { get; set; } = string.Empty; + [Required] public string Address { get; set; } = string.Empty; + [Required] public DateTime OpeningDate { get; set; } + [Required] public int RepairsMaxCount { get; set; } + [ForeignKey("ShopId")] + public List Repairs { get; set; } = new(); + private Dictionary? _shopRepairs = null; + [NotMapped] public Dictionary ShopRepairs { get @@ -36,9 +45,6 @@ namespace AutoWorkshopDatabaseImplement.Models } } - [ForeignKey("ShopId")] - public List Repairs { get; set; } = new(); - public static Shop Create(AutoWorkshopDatabase Context, ShopBindingModel Model) { return new Shop() From 6d525876bcadbcce2854de3e531f12b283d7a0cd Mon Sep 17 00:00:00 2001 From: Oleg Shabunov Date: Sun, 5 May 2024 22:02:16 +0400 Subject: [PATCH 16/21] Shop report contacts --- .../BusinessLogicContracts/IReportLogic.cs | 12 +++++++++++- .../ViewModels/ReportGroupedOrdersViewModel.cs | 11 +++++++++++ .../ViewModels/ReportShopsViewModel.cs | 11 +++++++++++ AutoWorkshopView/MainForm.Designer.cs | 2 +- 4 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 AutoWorkshopContracts/ViewModels/ReportGroupedOrdersViewModel.cs create mode 100644 AutoWorkshopContracts/ViewModels/ReportShopsViewModel.cs diff --git a/AutoWorkshopContracts/BusinessLogicContracts/IReportLogic.cs b/AutoWorkshopContracts/BusinessLogicContracts/IReportLogic.cs index b8e10bc..44f73ae 100644 --- a/AutoWorkshopContracts/BusinessLogicContracts/IReportLogic.cs +++ b/AutoWorkshopContracts/BusinessLogicContracts/IReportLogic.cs @@ -8,11 +8,21 @@ namespace AutoWorkshopContracts.BusinessLogicContracts List GetRepairComponents(); List GetOrders(ReportBindingModel Model); - + + List GetShops(); + + List GetGroupedOrders(); + void SaveRepairsToWordFile(ReportBindingModel Model); void SaveRepairComponentToExcelFile(ReportBindingModel Model); void SaveOrdersToPdfFile(ReportBindingModel Model); + + void SaveShopsToWordFile(ReportBindingModel Model); + + void SaveShopsToExcelFile(ReportBindingModel Model); + + void SaveGroupedOrdersToPdfFile(ReportBindingModel Model); } } diff --git a/AutoWorkshopContracts/ViewModels/ReportGroupedOrdersViewModel.cs b/AutoWorkshopContracts/ViewModels/ReportGroupedOrdersViewModel.cs new file mode 100644 index 0000000..ef0b65d --- /dev/null +++ b/AutoWorkshopContracts/ViewModels/ReportGroupedOrdersViewModel.cs @@ -0,0 +1,11 @@ +namespace AutoWorkshopContracts.ViewModels +{ + public class ReportGroupedOrdersViewModel + { + public DateTime Date { get; set; } = DateTime.Now; + + public int OrdersCount { get; set; } + + public double OrdersSum { get; set; } + } +} diff --git a/AutoWorkshopContracts/ViewModels/ReportShopsViewModel.cs b/AutoWorkshopContracts/ViewModels/ReportShopsViewModel.cs new file mode 100644 index 0000000..3014d2c --- /dev/null +++ b/AutoWorkshopContracts/ViewModels/ReportShopsViewModel.cs @@ -0,0 +1,11 @@ +namespace AutoWorkshopContracts.ViewModels +{ + public class ReportShopsViewModel + { + public string ShopName { get; set; } = string.Empty; + + public int TotalCount { get; set; } + + public List<(string Repair, int Count)> Repairs { get; set; } = new(); + } +} diff --git a/AutoWorkshopView/MainForm.Designer.cs b/AutoWorkshopView/MainForm.Designer.cs index eb860d3..869fa1f 100644 --- a/AutoWorkshopView/MainForm.Designer.cs +++ b/AutoWorkshopView/MainForm.Designer.cs @@ -53,7 +53,7 @@ // MenuStrip // MenuStrip.ImageScalingSize = new Size(20, 20); - MenuStrip.Items.AddRange(new ToolStripItem[] { ToolStripMenu, OperationToolStripMenuItem }); + MenuStrip.Items.AddRange(new ToolStripItem[] { ToolStripMenu, OperationToolStripMenuItem, ReportsToolStripMenuItem }); MenuStrip.Location = new Point(0, 0); MenuStrip.Name = "MenuStrip"; MenuStrip.Padding = new Padding(5, 2, 0, 2); From 8428b895a8cba5ed8aaeb925cb66e05cb5271545 Mon Sep 17 00:00:00 2001 From: Oleg Shabunov Date: Sun, 5 May 2024 22:16:39 +0400 Subject: [PATCH 17/21] Word report implement --- .../BusinessLogics/ReportLogic.cs | 2 +- .../OfficePackage/AbstractSaveToWord.cs | 54 ++++++++++++- .../OfficePackage/HelperModels/ExcelShop.cs | 13 ++++ .../OfficePackage/HelperModels/IWordInfo.cs | 9 +++ .../HelperModels/PdfGroupedOrdersInfo.cs | 17 ++++ .../{WordInfo.cs => WordRepairsInfo.cs} | 2 +- .../HelperModels/WordRowParameters.cs | 9 +++ .../HelperModels/WordShopsInfo.cs | 13 ++++ .../OfficePackage/Implements/SaveToWord.cs | 78 ++++++++++++++++++- 9 files changed, 189 insertions(+), 8 deletions(-) create mode 100644 AutoWorkshopBusinessLogic/OfficePackage/HelperModels/ExcelShop.cs create mode 100644 AutoWorkshopBusinessLogic/OfficePackage/HelperModels/IWordInfo.cs create mode 100644 AutoWorkshopBusinessLogic/OfficePackage/HelperModels/PdfGroupedOrdersInfo.cs rename AutoWorkshopBusinessLogic/OfficePackage/HelperModels/{WordInfo.cs => WordRepairsInfo.cs} (87%) create mode 100644 AutoWorkshopBusinessLogic/OfficePackage/HelperModels/WordRowParameters.cs create mode 100644 AutoWorkshopBusinessLogic/OfficePackage/HelperModels/WordShopsInfo.cs diff --git a/AutoWorkshopBusinessLogic/BusinessLogics/ReportLogic.cs b/AutoWorkshopBusinessLogic/BusinessLogics/ReportLogic.cs index cd67301..a477afa 100644 --- a/AutoWorkshopBusinessLogic/BusinessLogics/ReportLogic.cs +++ b/AutoWorkshopBusinessLogic/BusinessLogics/ReportLogic.cs @@ -57,7 +57,7 @@ namespace AutoWorkshopBusinessLogic.BusinessLogics public void SaveRepairsToWordFile(ReportBindingModel Model) { - _saveToWord.CreateDoc(new WordInfo + _saveToWord.CreateRepairsDoc(new WordRepairsInfo { FileName = Model.FileName, Title = "Список ремонтов", diff --git a/AutoWorkshopBusinessLogic/OfficePackage/AbstractSaveToWord.cs b/AutoWorkshopBusinessLogic/OfficePackage/AbstractSaveToWord.cs index 9b98866..45023ca 100644 --- a/AutoWorkshopBusinessLogic/OfficePackage/AbstractSaveToWord.cs +++ b/AutoWorkshopBusinessLogic/OfficePackage/AbstractSaveToWord.cs @@ -5,7 +5,7 @@ namespace AutoWorkshopBusinessLogic.OfficePackage { public abstract class AbstractSaveToWord { - public void CreateDoc(WordInfo Info) + public void CreateRepairsDoc(WordRepairsInfo Info) { CreateWord(Info); @@ -37,11 +37,57 @@ namespace AutoWorkshopBusinessLogic.OfficePackage SaveWord(Info); } - - protected abstract void CreateWord(WordInfo Info); + + public void CreateShopsDoc(WordShopsInfo Info) + { + CreateWord(Info); + + CreateParagraph(new WordParagraph + { + Texts = new List<(string, WordTextProperties)> { (Info.Title, new WordTextProperties { Bold = true, Size = "24", }) }, + TextProperties = new WordTextProperties + { + Size = "24", + JustificationType = WordJustificationType.Center + } + }); + + CreateTable(new List { "3000", "3000", "3000" }); + CreateRow(new WordRowParameters + { + Texts = new List { "Название", "Адрес", "Дата открытия" }, + TextProperties = new WordTextProperties + { + Size = "24", + Bold = true, + JustificationType = WordJustificationType.Center + } + }); + + foreach (var Shop in Info.Shops) + { + CreateRow(new WordRowParameters + { + Texts = new List { Shop.ShopName, Shop.Address, Shop.OpeningDate.ToString() }, + TextProperties = new WordTextProperties + { + Size = "22", + JustificationType = WordJustificationType.Both + } + }); + } + + SaveWord(Info); + } + + protected abstract void CreateWord(IWordInfo Info); protected abstract void CreateParagraph(WordParagraph Paragraph); - protected abstract void SaveWord(WordInfo Info); + protected abstract void SaveWord(IWordInfo Info); + + protected abstract void CreateTable(List Colums); + + protected abstract void CreateRow(WordRowParameters RowParameters); } } diff --git a/AutoWorkshopBusinessLogic/OfficePackage/HelperModels/ExcelShop.cs b/AutoWorkshopBusinessLogic/OfficePackage/HelperModels/ExcelShop.cs new file mode 100644 index 0000000..110f1de --- /dev/null +++ b/AutoWorkshopBusinessLogic/OfficePackage/HelperModels/ExcelShop.cs @@ -0,0 +1,13 @@ +using AutoWorkshopContracts.ViewModels; + +namespace AutoWorkshopBusinessLogic.OfficePackage.HelperModels +{ + public class ExcelShop : IWordInfo + { + public string FileName { get; set; } = string.Empty; + + public string Title { get; set; } = string.Empty; + + public List ShopRepairs { get; set; } = new(); + } +} diff --git a/AutoWorkshopBusinessLogic/OfficePackage/HelperModels/IWordInfo.cs b/AutoWorkshopBusinessLogic/OfficePackage/HelperModels/IWordInfo.cs new file mode 100644 index 0000000..7fe5abf --- /dev/null +++ b/AutoWorkshopBusinessLogic/OfficePackage/HelperModels/IWordInfo.cs @@ -0,0 +1,9 @@ +namespace AutoWorkshopBusinessLogic.OfficePackage.HelperModels +{ + public interface IWordInfo + { + public string FileName { get; set; } + + public string Title { get; set; } + } +} diff --git a/AutoWorkshopBusinessLogic/OfficePackage/HelperModels/PdfGroupedOrdersInfo.cs b/AutoWorkshopBusinessLogic/OfficePackage/HelperModels/PdfGroupedOrdersInfo.cs new file mode 100644 index 0000000..3a0c52a --- /dev/null +++ b/AutoWorkshopBusinessLogic/OfficePackage/HelperModels/PdfGroupedOrdersInfo.cs @@ -0,0 +1,17 @@ +using AutoWorkshopContracts.ViewModels; + +namespace AutoWorkshopBusinessLogic.OfficePackage.HelperModels +{ + public class PdfGroupedOrdersInfo : IWordInfo + { + public string FileName { get; set; } = string.Empty; + + public string Title { get; set; } = string.Empty; + + public DateTime DateFrom { get; set; } + + public DateTime DateTo { get; set; } + + public List GroupedOrders { get; set; } = new(); + } +} diff --git a/AutoWorkshopBusinessLogic/OfficePackage/HelperModels/WordInfo.cs b/AutoWorkshopBusinessLogic/OfficePackage/HelperModels/WordRepairsInfo.cs similarity index 87% rename from AutoWorkshopBusinessLogic/OfficePackage/HelperModels/WordInfo.cs rename to AutoWorkshopBusinessLogic/OfficePackage/HelperModels/WordRepairsInfo.cs index b18f6b2..b8026bd 100644 --- a/AutoWorkshopBusinessLogic/OfficePackage/HelperModels/WordInfo.cs +++ b/AutoWorkshopBusinessLogic/OfficePackage/HelperModels/WordRepairsInfo.cs @@ -2,7 +2,7 @@ namespace AutoWorkshopBusinessLogic.OfficePackage.HelperModels { - public class WordInfo + public class WordRepairsInfo : IWordInfo { public string FileName { get; set; } = string.Empty; diff --git a/AutoWorkshopBusinessLogic/OfficePackage/HelperModels/WordRowParameters.cs b/AutoWorkshopBusinessLogic/OfficePackage/HelperModels/WordRowParameters.cs new file mode 100644 index 0000000..5395e27 --- /dev/null +++ b/AutoWorkshopBusinessLogic/OfficePackage/HelperModels/WordRowParameters.cs @@ -0,0 +1,9 @@ +namespace AutoWorkshopBusinessLogic.OfficePackage.HelperModels +{ + public class WordRowParameters + { + public List Texts { get; set; } = new(); + + public WordTextProperties TextProperties { get; set; } = new(); + } +} diff --git a/AutoWorkshopBusinessLogic/OfficePackage/HelperModels/WordShopsInfo.cs b/AutoWorkshopBusinessLogic/OfficePackage/HelperModels/WordShopsInfo.cs new file mode 100644 index 0000000..d18bd55 --- /dev/null +++ b/AutoWorkshopBusinessLogic/OfficePackage/HelperModels/WordShopsInfo.cs @@ -0,0 +1,13 @@ +using AutoWorkshopContracts.ViewModels; + +namespace AutoWorkshopBusinessLogic.OfficePackage.HelperModels +{ + public class WordShopsInfo : IWordInfo + { + public string FileName { get; set; } = string.Empty; + + public string Title { get; set; } = string.Empty; + + public List Shops { get; set; } = new(); + } +} diff --git a/AutoWorkshopBusinessLogic/OfficePackage/Implements/SaveToWord.cs b/AutoWorkshopBusinessLogic/OfficePackage/Implements/SaveToWord.cs index 6d9de6f..d7fe8da 100644 --- a/AutoWorkshopBusinessLogic/OfficePackage/Implements/SaveToWord.cs +++ b/AutoWorkshopBusinessLogic/OfficePackage/Implements/SaveToWord.cs @@ -64,7 +64,7 @@ namespace AutoWorkshopBusinessLogic.OfficePackage.Implements return Properties; } - protected override void CreateWord(WordInfo Info) + protected override void CreateWord(IWordInfo Info) { _wordDocument = WordprocessingDocument.Create(Info.FileName, WordprocessingDocumentType.Document); MainDocumentPart mainPart = _wordDocument.AddMainDocumentPart(); @@ -103,7 +103,7 @@ namespace AutoWorkshopBusinessLogic.OfficePackage.Implements _docBody.AppendChild(DocParagraph); } - protected override void SaveWord(WordInfo Info) + protected override void SaveWord(IWordInfo Info) { if (_docBody == null || _wordDocument == null) { @@ -114,5 +114,79 @@ namespace AutoWorkshopBusinessLogic.OfficePackage.Implements _wordDocument.MainDocumentPart!.Document.Save(); _wordDocument.Close(); } + + private Table? _lastTable; + + protected override void CreateTable(List Columns) + { + if (_docBody == null) + return; + + _lastTable = new Table(); + + var TableProp = new TableProperties(); + TableProp.AppendChild(new TableLayout { Type = TableLayoutValues.Fixed }); + TableProp.AppendChild(new TableBorders( + new TopBorder() { Val = new EnumValue(BorderValues.Single), Size = 4 }, + new LeftBorder() { Val = new EnumValue(BorderValues.Single), Size = 4 }, + new RightBorder() { Val = new EnumValue(BorderValues.Single), Size = 4 }, + new BottomBorder() { Val = new EnumValue(BorderValues.Single), Size = 4 }, + new InsideHorizontalBorder() { Val = new EnumValue(BorderValues.Single), Size = 4 }, + new InsideVerticalBorder() { Val = new EnumValue(BorderValues.Single), Size = 4 } + )); + TableProp.AppendChild(new TableWidth { Type = TableWidthUnitValues.Auto }); + _lastTable.AppendChild(TableProp); + + TableGrid TableGrid = new TableGrid(); + + foreach (var Column in Columns) + { + TableGrid.AppendChild(new GridColumn() { Width = Column }); + } + + _lastTable.AppendChild(TableGrid); + _docBody.AppendChild(_lastTable); + } + + protected override void CreateRow(WordRowParameters RowParameters) + { + if (_docBody == null || _lastTable == null) + return; + + TableRow DocRow = new TableRow(); + foreach (var Column in RowParameters.Texts) + { + var DocParagraph = new Paragraph(); + WordParagraph Paragraph = new WordParagraph + { + Texts = new List<(string, WordTextProperties)> { (Column, RowParameters.TextProperties) }, + TextProperties = RowParameters.TextProperties + }; + + DocParagraph.AppendChild(CreateParagraphProperties(Paragraph.TextProperties)); + + foreach (var Run in Paragraph.Texts) + { + var DocRun = new Run(); + var Properties = new RunProperties(); + + Properties.AppendChild(new FontSize { Val = Run.Item2.Size }); + if (Run.Item2.Bold) + { + Properties.AppendChild(new Bold()); + } + DocRun.AppendChild(Properties); + DocRun.AppendChild(new Text { Text = Run.Item1, Space = SpaceProcessingModeValues.Preserve }); + DocParagraph.AppendChild(DocRun); + } + + TableCell docCell = new TableCell(); + + docCell.AppendChild(DocParagraph); + DocRow.AppendChild(docCell); + } + + _lastTable.AppendChild(DocRow); + } } } From 10a344f0b129672b4aa1821a09632a003a32d393 Mon Sep 17 00:00:00 2001 From: Oleg Shabunov Date: Sun, 5 May 2024 22:22:55 +0400 Subject: [PATCH 18/21] Excel report implement --- .../BusinessLogics/ReportLogic.cs | 2 +- .../OfficePackage/AbstractSaveToExcel.cs | 83 ++++++++++++++++++- .../OfficePackage/AbstractSaveToWord.cs | 4 +- .../{ExcelInfo.cs => ExcelRepairsInfo.cs} | 2 +- .../{ExcelShop.cs => ExcelShopsInfo.cs} | 2 +- .../{IWordInfo.cs => IDocumentInfo.cs} | 2 +- .../HelperModels/PdfGroupedOrdersInfo.cs | 2 +- .../HelperModels/WordRepairsInfo.cs | 2 +- .../HelperModels/WordShopsInfo.cs | 2 +- .../OfficePackage/Implements/SaveToExcel.cs | 4 +- .../OfficePackage/Implements/SaveToWord.cs | 4 +- 11 files changed, 92 insertions(+), 17 deletions(-) rename AutoWorkshopBusinessLogic/OfficePackage/HelperModels/{ExcelInfo.cs => ExcelRepairsInfo.cs} (87%) rename AutoWorkshopBusinessLogic/OfficePackage/HelperModels/{ExcelShop.cs => ExcelShopsInfo.cs} (87%) rename AutoWorkshopBusinessLogic/OfficePackage/HelperModels/{IWordInfo.cs => IDocumentInfo.cs} (82%) diff --git a/AutoWorkshopBusinessLogic/BusinessLogics/ReportLogic.cs b/AutoWorkshopBusinessLogic/BusinessLogics/ReportLogic.cs index a477afa..120ecc8 100644 --- a/AutoWorkshopBusinessLogic/BusinessLogics/ReportLogic.cs +++ b/AutoWorkshopBusinessLogic/BusinessLogics/ReportLogic.cs @@ -67,7 +67,7 @@ namespace AutoWorkshopBusinessLogic.BusinessLogics public void SaveRepairComponentToExcelFile(ReportBindingModel Model) { - _saveToExcel.CreateReport(new ExcelInfo + _saveToExcel.CreateReport(new ExcelRepairsInfo { FileName = Model.FileName, Title = "Список ремонтов", diff --git a/AutoWorkshopBusinessLogic/OfficePackage/AbstractSaveToExcel.cs b/AutoWorkshopBusinessLogic/OfficePackage/AbstractSaveToExcel.cs index 04b1476..81f1bba 100644 --- a/AutoWorkshopBusinessLogic/OfficePackage/AbstractSaveToExcel.cs +++ b/AutoWorkshopBusinessLogic/OfficePackage/AbstractSaveToExcel.cs @@ -5,7 +5,7 @@ namespace AutoWorkshopBusinessLogic.OfficePackage { public abstract class AbstractSaveToExcel { - public void CreateReport(ExcelInfo Info) + public void CreateReport(ExcelRepairsInfo Info) { CreateExcel(Info); @@ -78,13 +78,88 @@ namespace AutoWorkshopBusinessLogic.OfficePackage SaveExcel(Info); } - - protected abstract void CreateExcel(ExcelInfo Info); + + public void CreateShopPizzasReport(ExcelShopsInfo Info) + { + CreateExcel(Info); + + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "A", + RowIndex = 1, + Text = Info.Title, + StyleInfo = ExcelStyleInfoType.Title + }); + + MergeCells(new ExcelMergeParameters + { + CellFromName = "A1", + CellToName = "C1" + }); + + uint RowIndex = 2; + + foreach (var ShopRep in Info.ShopRepairs) + { + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "A", + RowIndex = RowIndex, + Text = ShopRep.ShopName, + StyleInfo = ExcelStyleInfoType.Text + }); + + RowIndex++; + + foreach (var (Repair, Count) in ShopRep.Repairs) + { + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "B", + RowIndex = RowIndex, + Text = Repair, + StyleInfo = ExcelStyleInfoType.TextWithBroder + }); + + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "C", + RowIndex = RowIndex, + Text = Count.ToString(), + StyleInfo = ExcelStyleInfoType.TextWithBroder + }); + + RowIndex++; + } + + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "A", + RowIndex = RowIndex, + Text = "Итого", + StyleInfo = ExcelStyleInfoType.Text + }); + + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "C", + RowIndex = RowIndex, + Text = ShopRep.TotalCount.ToString(), + StyleInfo = ExcelStyleInfoType.Text + }); + + RowIndex++; + } + + SaveExcel(Info); + } + + protected abstract void CreateExcel(IDocumentInfo Info); protected abstract void InsertCellInWorksheet(ExcelCellParameters ExcelParams); protected abstract void MergeCells(ExcelMergeParameters ExcelParams); - protected abstract void SaveExcel(ExcelInfo Info); + protected abstract void SaveExcel(IDocumentInfo Info); } } diff --git a/AutoWorkshopBusinessLogic/OfficePackage/AbstractSaveToWord.cs b/AutoWorkshopBusinessLogic/OfficePackage/AbstractSaveToWord.cs index 45023ca..3ca7cd2 100644 --- a/AutoWorkshopBusinessLogic/OfficePackage/AbstractSaveToWord.cs +++ b/AutoWorkshopBusinessLogic/OfficePackage/AbstractSaveToWord.cs @@ -80,11 +80,11 @@ namespace AutoWorkshopBusinessLogic.OfficePackage SaveWord(Info); } - protected abstract void CreateWord(IWordInfo Info); + protected abstract void CreateWord(IDocumentInfo Info); protected abstract void CreateParagraph(WordParagraph Paragraph); - protected abstract void SaveWord(IWordInfo Info); + protected abstract void SaveWord(IDocumentInfo Info); protected abstract void CreateTable(List Colums); diff --git a/AutoWorkshopBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs b/AutoWorkshopBusinessLogic/OfficePackage/HelperModels/ExcelRepairsInfo.cs similarity index 87% rename from AutoWorkshopBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs rename to AutoWorkshopBusinessLogic/OfficePackage/HelperModels/ExcelRepairsInfo.cs index 92ea188..58845ee 100644 --- a/AutoWorkshopBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs +++ b/AutoWorkshopBusinessLogic/OfficePackage/HelperModels/ExcelRepairsInfo.cs @@ -2,7 +2,7 @@ namespace AutoWorkshopBusinessLogic.OfficePackage.HelperModels { - public class ExcelInfo + public class ExcelRepairsInfo : IDocumentInfo { public string FileName { get; set; } = string.Empty; diff --git a/AutoWorkshopBusinessLogic/OfficePackage/HelperModels/ExcelShop.cs b/AutoWorkshopBusinessLogic/OfficePackage/HelperModels/ExcelShopsInfo.cs similarity index 87% rename from AutoWorkshopBusinessLogic/OfficePackage/HelperModels/ExcelShop.cs rename to AutoWorkshopBusinessLogic/OfficePackage/HelperModels/ExcelShopsInfo.cs index 110f1de..932a172 100644 --- a/AutoWorkshopBusinessLogic/OfficePackage/HelperModels/ExcelShop.cs +++ b/AutoWorkshopBusinessLogic/OfficePackage/HelperModels/ExcelShopsInfo.cs @@ -2,7 +2,7 @@ namespace AutoWorkshopBusinessLogic.OfficePackage.HelperModels { - public class ExcelShop : IWordInfo + public class ExcelShopsInfo : IDocumentInfo { public string FileName { get; set; } = string.Empty; diff --git a/AutoWorkshopBusinessLogic/OfficePackage/HelperModels/IWordInfo.cs b/AutoWorkshopBusinessLogic/OfficePackage/HelperModels/IDocumentInfo.cs similarity index 82% rename from AutoWorkshopBusinessLogic/OfficePackage/HelperModels/IWordInfo.cs rename to AutoWorkshopBusinessLogic/OfficePackage/HelperModels/IDocumentInfo.cs index 7fe5abf..048e797 100644 --- a/AutoWorkshopBusinessLogic/OfficePackage/HelperModels/IWordInfo.cs +++ b/AutoWorkshopBusinessLogic/OfficePackage/HelperModels/IDocumentInfo.cs @@ -1,6 +1,6 @@ namespace AutoWorkshopBusinessLogic.OfficePackage.HelperModels { - public interface IWordInfo + public interface IDocumentInfo { public string FileName { get; set; } diff --git a/AutoWorkshopBusinessLogic/OfficePackage/HelperModels/PdfGroupedOrdersInfo.cs b/AutoWorkshopBusinessLogic/OfficePackage/HelperModels/PdfGroupedOrdersInfo.cs index 3a0c52a..f268593 100644 --- a/AutoWorkshopBusinessLogic/OfficePackage/HelperModels/PdfGroupedOrdersInfo.cs +++ b/AutoWorkshopBusinessLogic/OfficePackage/HelperModels/PdfGroupedOrdersInfo.cs @@ -2,7 +2,7 @@ namespace AutoWorkshopBusinessLogic.OfficePackage.HelperModels { - public class PdfGroupedOrdersInfo : IWordInfo + public class PdfGroupedOrdersInfo : IDocumentInfo { public string FileName { get; set; } = string.Empty; diff --git a/AutoWorkshopBusinessLogic/OfficePackage/HelperModels/WordRepairsInfo.cs b/AutoWorkshopBusinessLogic/OfficePackage/HelperModels/WordRepairsInfo.cs index b8026bd..6c7c0fe 100644 --- a/AutoWorkshopBusinessLogic/OfficePackage/HelperModels/WordRepairsInfo.cs +++ b/AutoWorkshopBusinessLogic/OfficePackage/HelperModels/WordRepairsInfo.cs @@ -2,7 +2,7 @@ namespace AutoWorkshopBusinessLogic.OfficePackage.HelperModels { - public class WordRepairsInfo : IWordInfo + public class WordRepairsInfo : IDocumentInfo { public string FileName { get; set; } = string.Empty; diff --git a/AutoWorkshopBusinessLogic/OfficePackage/HelperModels/WordShopsInfo.cs b/AutoWorkshopBusinessLogic/OfficePackage/HelperModels/WordShopsInfo.cs index d18bd55..2a2f8db 100644 --- a/AutoWorkshopBusinessLogic/OfficePackage/HelperModels/WordShopsInfo.cs +++ b/AutoWorkshopBusinessLogic/OfficePackage/HelperModels/WordShopsInfo.cs @@ -2,7 +2,7 @@ namespace AutoWorkshopBusinessLogic.OfficePackage.HelperModels { - public class WordShopsInfo : IWordInfo + public class WordShopsInfo : IDocumentInfo { public string FileName { get; set; } = string.Empty; diff --git a/AutoWorkshopBusinessLogic/OfficePackage/Implements/SaveToExcel.cs b/AutoWorkshopBusinessLogic/OfficePackage/Implements/SaveToExcel.cs index d030433..deddaf2 100644 --- a/AutoWorkshopBusinessLogic/OfficePackage/Implements/SaveToExcel.cs +++ b/AutoWorkshopBusinessLogic/OfficePackage/Implements/SaveToExcel.cs @@ -139,7 +139,7 @@ namespace AutoWorkshopBusinessLogic.OfficePackage.Implements }; } - protected override void CreateExcel(ExcelInfo Info) + protected override void CreateExcel(IDocumentInfo Info) { _spreadsheetDocument = SpreadsheetDocument.Create(Info.FileName, SpreadsheetDocumentType.Workbook); @@ -269,7 +269,7 @@ namespace AutoWorkshopBusinessLogic.OfficePackage.Implements MergeCells.Append(MergeCell); } - protected override void SaveExcel(ExcelInfo Info) + protected override void SaveExcel(IDocumentInfo Info) { if (_spreadsheetDocument == null) return; diff --git a/AutoWorkshopBusinessLogic/OfficePackage/Implements/SaveToWord.cs b/AutoWorkshopBusinessLogic/OfficePackage/Implements/SaveToWord.cs index d7fe8da..af01c8d 100644 --- a/AutoWorkshopBusinessLogic/OfficePackage/Implements/SaveToWord.cs +++ b/AutoWorkshopBusinessLogic/OfficePackage/Implements/SaveToWord.cs @@ -64,7 +64,7 @@ namespace AutoWorkshopBusinessLogic.OfficePackage.Implements return Properties; } - protected override void CreateWord(IWordInfo Info) + protected override void CreateWord(IDocumentInfo Info) { _wordDocument = WordprocessingDocument.Create(Info.FileName, WordprocessingDocumentType.Document); MainDocumentPart mainPart = _wordDocument.AddMainDocumentPart(); @@ -103,7 +103,7 @@ namespace AutoWorkshopBusinessLogic.OfficePackage.Implements _docBody.AppendChild(DocParagraph); } - protected override void SaveWord(IWordInfo Info) + protected override void SaveWord(IDocumentInfo Info) { if (_docBody == null || _wordDocument == null) { From 22b27835475f142496585e870a828a046c4c0cab Mon Sep 17 00:00:00 2001 From: Oleg Shabunov Date: Sun, 5 May 2024 22:32:34 +0400 Subject: [PATCH 19/21] Pdf report implement & ReportLogic --- .../BusinessLogics/ReportLogic.cs | 56 ++++++++++++++++++- .../OfficePackage/AbstractSaveToPdf.cs | 35 ++++++++++-- .../{PdfInfo.cs => PdfOrdersInfo.cs} | 2 +- .../OfficePackage/Implements/SaveToPdf.cs | 4 +- 4 files changed, 88 insertions(+), 9 deletions(-) rename AutoWorkshopBusinessLogic/OfficePackage/HelperModels/{PdfInfo.cs => PdfOrdersInfo.cs} (90%) diff --git a/AutoWorkshopBusinessLogic/BusinessLogics/ReportLogic.cs b/AutoWorkshopBusinessLogic/BusinessLogics/ReportLogic.cs index 120ecc8..2d37f47 100644 --- a/AutoWorkshopBusinessLogic/BusinessLogics/ReportLogic.cs +++ b/AutoWorkshopBusinessLogic/BusinessLogics/ReportLogic.cs @@ -13,16 +13,18 @@ namespace AutoWorkshopBusinessLogic.BusinessLogics private readonly IComponentStorage _componentStorage; private readonly IRepairStorage _RepairStorage; private readonly IOrderStorage _orderStorage; + private readonly IShopStorage _shopStorage; private readonly AbstractSaveToExcel _saveToExcel; private readonly AbstractSaveToWord _saveToWord; private readonly AbstractSaveToPdf _saveToPdf; - public ReportLogic(IRepairStorage RepairStorage, IComponentStorage ComponentStorage, IOrderStorage OrderStorage, + public ReportLogic(IRepairStorage RepairStorage, IComponentStorage ComponentStorage, IOrderStorage OrderStorage, IShopStorage ShopStorage, AbstractSaveToExcel SaveToExcel, AbstractSaveToWord SaveToWord, AbstractSaveToPdf SaveToPdf) { _RepairStorage = RepairStorage; _componentStorage = ComponentStorage; _orderStorage = OrderStorage; + _shopStorage = ShopStorage; _saveToExcel = SaveToExcel; _saveToWord = SaveToWord; @@ -41,6 +43,26 @@ namespace AutoWorkshopBusinessLogic.BusinessLogics .ToList(); } + public List GetShops() + { + return _shopStorage.GetFullList().Select(x => new ReportShopsViewModel + { + ShopName = x.ShopName, + Repairs = x.ShopRepairs.Select(x => (x.Value.Item1.RepairName, x.Value.Item2)).ToList(), + TotalCount = x.ShopRepairs.Select(x => x.Value.Item2).Sum() + }).ToList(); + } + + public List GetGroupedOrders() + { + return _orderStorage.GetFullList().GroupBy(x => x.DateCreate.Date).Select(x => new ReportGroupedOrdersViewModel + { + Date = x.Key, + OrdersCount = x.Count(), + OrdersSum = x.Select(y => y.Sum).Sum() + }).ToList(); + } + public List GetOrders(ReportBindingModel Model) { return _orderStorage.GetFilteredList(new OrderSearchModel { DateFrom = Model.DateFrom, DateTo = Model.DateTo }) @@ -77,7 +99,7 @@ namespace AutoWorkshopBusinessLogic.BusinessLogics public void SaveOrdersToPdfFile(ReportBindingModel Model) { - _saveToPdf.CreateDoc(new PdfInfo + _saveToPdf.CreateDoc(new PdfOrdersInfo { FileName = Model.FileName, Title = "Список заказов", @@ -86,5 +108,35 @@ namespace AutoWorkshopBusinessLogic.BusinessLogics Orders = GetOrders(Model) }); } + + public void SaveShopsToWordFile(ReportBindingModel model) + { + _saveToWord.CreateShopsDoc(new WordShopsInfo + { + FileName = model.FileName, + Title = "Список магазинов", + Shops = _shopStorage.GetFullList() + }); + } + + public void SaveShopsToExcelFile(ReportBindingModel model) + { + _saveToExcel.CreateShopPizzasReport(new ExcelShopsInfo + { + FileName = model.FileName, + Title = "Загруженность магазинов", + ShopRepairs = GetShops() + }); + } + + public void SaveGroupedOrdersToPdfFile(ReportBindingModel model) + { + _saveToPdf.CreateGroupedOrdersDoc(new PdfGroupedOrdersInfo + { + FileName = model.FileName, + Title = "Список заказов, объединенных по датам", + GroupedOrders = GetGroupedOrders() + }); + } } } diff --git a/AutoWorkshopBusinessLogic/OfficePackage/AbstractSaveToPdf.cs b/AutoWorkshopBusinessLogic/OfficePackage/AbstractSaveToPdf.cs index 86fd1a0..94b2490 100644 --- a/AutoWorkshopBusinessLogic/OfficePackage/AbstractSaveToPdf.cs +++ b/AutoWorkshopBusinessLogic/OfficePackage/AbstractSaveToPdf.cs @@ -5,7 +5,7 @@ namespace AutoWorkshopBusinessLogic.OfficePackage { public abstract class AbstractSaveToPdf { - public void CreateDoc(PdfInfo Info) + public void CreateDoc(PdfOrdersInfo Info) { CreatePdf(Info); CreateParagraph(new PdfParagraph { Text = Info.Title, Style = "NormalTitle", ParagraphAlignment = PdfParagraphAlignmentType.Center }); @@ -33,8 +33,35 @@ namespace AutoWorkshopBusinessLogic.OfficePackage SavePdf(Info); } - - protected abstract void CreatePdf(PdfInfo Info); + + public void CreateGroupedOrdersDoc(PdfGroupedOrdersInfo Info) + { + CreatePdf(Info); + CreateParagraph(new PdfParagraph { Text = Info.Title, Style = "NormalTitle", ParagraphAlignment = PdfParagraphAlignmentType.Center }); + + CreateTable(new List { "4cm", "3cm", "2cm" }); + CreateRow(new PdfRowParameters + { + Texts = new List { "Дата заказа", "Кол-во", "Сумма" }, + Style = "NormalTitle", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + + foreach (var groupedOrder in Info.GroupedOrders) + { + CreateRow(new PdfRowParameters + { + Texts = new List { groupedOrder.Date.ToShortDateString(), groupedOrder.OrdersCount.ToString(), groupedOrder.OrdersSum.ToString() }, + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Left + }); + } + + CreateParagraph(new PdfParagraph { Text = $"Итого: {Info.GroupedOrders.Sum(x => x.OrdersSum)}\t", Style = "Normal", ParagraphAlignment = PdfParagraphAlignmentType.Center }); + SavePdf(Info); + } + + protected abstract void CreatePdf(IDocumentInfo Info); protected abstract void CreateParagraph(PdfParagraph Paragraph); @@ -42,6 +69,6 @@ namespace AutoWorkshopBusinessLogic.OfficePackage protected abstract void CreateRow(PdfRowParameters RowParameters); - protected abstract void SavePdf(PdfInfo Info); + protected abstract void SavePdf(IDocumentInfo Info); } } diff --git a/AutoWorkshopBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs b/AutoWorkshopBusinessLogic/OfficePackage/HelperModels/PdfOrdersInfo.cs similarity index 90% rename from AutoWorkshopBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs rename to AutoWorkshopBusinessLogic/OfficePackage/HelperModels/PdfOrdersInfo.cs index 1df40e0..ee25fd5 100644 --- a/AutoWorkshopBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs +++ b/AutoWorkshopBusinessLogic/OfficePackage/HelperModels/PdfOrdersInfo.cs @@ -2,7 +2,7 @@ namespace AutoWorkshopBusinessLogic.OfficePackage.HelperModels { - public class PdfInfo + public class PdfOrdersInfo : IDocumentInfo { public string FileName { get; set; } = string.Empty; diff --git a/AutoWorkshopBusinessLogic/OfficePackage/Implements/SaveToPdf.cs b/AutoWorkshopBusinessLogic/OfficePackage/Implements/SaveToPdf.cs index 0ee1ec4..b1ed115 100644 --- a/AutoWorkshopBusinessLogic/OfficePackage/Implements/SaveToPdf.cs +++ b/AutoWorkshopBusinessLogic/OfficePackage/Implements/SaveToPdf.cs @@ -33,7 +33,7 @@ namespace AutoWorkshopBusinessLogic.OfficePackage.Implements Style.Font.Bold = true; } - protected override void CreatePdf(PdfInfo Info) + protected override void CreatePdf(IDocumentInfo Info) { _document = new Document(); DefineStyles(_document); @@ -94,7 +94,7 @@ namespace AutoWorkshopBusinessLogic.OfficePackage.Implements } } - protected override void SavePdf(PdfInfo Info) + protected override void SavePdf(IDocumentInfo Info) { var Renderer = new PdfDocumentRenderer(true) { From 1ff73bce3a69d7cba0348d02bffb3fdfea6d6988 Mon Sep 17 00:00:00 2001 From: Oleg Shabunov Date: Mon, 13 May 2024 22:38:52 +0400 Subject: [PATCH 20/21] Report forms --- AutoWorkshopView/AutoWorkshopView.csproj | 3 + .../Forms/FormReportGroupedOrders.Designer.cs | 131 ++++++ .../Forms/FormReportGroupedOrders.cs | 75 +++ .../Forms/FormReportGroupedOrders.resx | 120 +++++ .../Forms/FormReportShop.Designer.cs | 115 +++++ AutoWorkshopView/Forms/FormReportShop.cs | 75 +++ AutoWorkshopView/Forms/FormReportShop.resx | 120 +++++ AutoWorkshopView/MainForm.cs | 31 ++ AutoWorkshopView/Program.cs | 2 + AutoWorkshopView/ReportGroupedOrders.rdlc | 441 ++++++++++++++++++ 10 files changed, 1113 insertions(+) create mode 100644 AutoWorkshopView/Forms/FormReportGroupedOrders.Designer.cs create mode 100644 AutoWorkshopView/Forms/FormReportGroupedOrders.cs create mode 100644 AutoWorkshopView/Forms/FormReportGroupedOrders.resx create mode 100644 AutoWorkshopView/Forms/FormReportShop.Designer.cs create mode 100644 AutoWorkshopView/Forms/FormReportShop.cs create mode 100644 AutoWorkshopView/Forms/FormReportShop.resx create mode 100644 AutoWorkshopView/ReportGroupedOrders.rdlc diff --git a/AutoWorkshopView/AutoWorkshopView.csproj b/AutoWorkshopView/AutoWorkshopView.csproj index 8628399..1b94f45 100644 --- a/AutoWorkshopView/AutoWorkshopView.csproj +++ b/AutoWorkshopView/AutoWorkshopView.csproj @@ -26,6 +26,9 @@ Always + + Always + \ No newline at end of file diff --git a/AutoWorkshopView/Forms/FormReportGroupedOrders.Designer.cs b/AutoWorkshopView/Forms/FormReportGroupedOrders.Designer.cs new file mode 100644 index 0000000..1fe7c32 --- /dev/null +++ b/AutoWorkshopView/Forms/FormReportGroupedOrders.Designer.cs @@ -0,0 +1,131 @@ +namespace AutoWorkshopView.Forms +{ + partial class FormReportGroupedOrders + { + /// + /// 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() + { + panel = new Panel(); + labelFrom = new Label(); + dateTimePickerFrom = new DateTimePicker(); + dateTimePickerTo = new DateTimePicker(); + labelTo = new Label(); + buttonMake = new Button(); + buttonToPDF = new Button(); + panel.SuspendLayout(); + SuspendLayout(); + // + // panel + // + panel.Controls.Add(buttonToPDF); + panel.Controls.Add(buttonMake); + panel.Controls.Add(dateTimePickerTo); + panel.Controls.Add(labelTo); + panel.Controls.Add(dateTimePickerFrom); + panel.Controls.Add(labelFrom); + panel.Dock = DockStyle.Top; + panel.Location = new Point(0, 0); + panel.Name = "panel"; + panel.Size = new Size(958, 52); + panel.TabIndex = 0; + // + // labelFrom + // + labelFrom.AutoSize = true; + labelFrom.Location = new Point(12, 14); + labelFrom.Name = "labelFrom"; + labelFrom.Size = new Size(18, 20); + labelFrom.TabIndex = 0; + labelFrom.Text = "C"; + // + // dateTimePickerFrom + // + dateTimePickerFrom.Location = new Point(36, 9); + dateTimePickerFrom.Name = "dateTimePickerFrom"; + dateTimePickerFrom.Size = new Size(199, 27); + dateTimePickerFrom.TabIndex = 1; + // + // dateTimePickerTo + // + dateTimePickerTo.Location = new Point(300, 9); + dateTimePickerTo.Name = "dateTimePickerTo"; + dateTimePickerTo.Size = new Size(199, 27); + dateTimePickerTo.TabIndex = 3; + // + // labelTo + // + labelTo.AutoSize = true; + labelTo.Location = new Point(254, 14); + labelTo.Name = "labelTo"; + labelTo.Size = new Size(27, 20); + labelTo.TabIndex = 2; + labelTo.Text = "по"; + // + // buttonMake + // + buttonMake.Location = new Point(542, 10); + buttonMake.Name = "buttonMake"; + buttonMake.Size = new Size(165, 29); + buttonMake.TabIndex = 4; + buttonMake.Text = "Сформировать"; + buttonMake.UseVisualStyleBackColor = true; + buttonMake.Click += new System.EventHandler(ButtonMake_Click); + // + // buttonToPDF + // + buttonToPDF.Location = new Point(781, 9); + buttonToPDF.Name = "buttonToPDF"; + buttonToPDF.Size = new Size(165, 29); + buttonToPDF.TabIndex = 5; + buttonToPDF.Text = "В PDF"; + buttonToPDF.UseVisualStyleBackColor = true; + buttonToPDF.Click += new System.EventHandler(ButtonToPdf_Click); + // + // FormReportOrders + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(958, 450); + Controls.Add(panel); + Name = "FormReportOrders"; + Text = "Заказы"; + panel.ResumeLayout(false); + panel.PerformLayout(); + ResumeLayout(false); + + } + + #endregion + + private Panel panel; + private Button buttonToPDF; + private Button buttonMake; + private DateTimePicker dateTimePickerTo; + private Label labelTo; + private DateTimePicker dateTimePickerFrom; + private Label labelFrom; + } +} \ No newline at end of file diff --git a/AutoWorkshopView/Forms/FormReportGroupedOrders.cs b/AutoWorkshopView/Forms/FormReportGroupedOrders.cs new file mode 100644 index 0000000..64967e4 --- /dev/null +++ b/AutoWorkshopView/Forms/FormReportGroupedOrders.cs @@ -0,0 +1,75 @@ +using AutoWorkshopContracts.BindingModels; +using AutoWorkshopContracts.BusinessLogicContracts; +using Microsoft.Extensions.Logging; +using Microsoft.Reporting.WinForms; + +namespace AutoWorkshopView.Forms +{ + public partial class FormReportGroupedOrders : Form + { + private readonly ReportViewer _reportViewer; + private readonly ILogger _logger; + private readonly IReportLogic _logic; + + public FormReportGroupedOrders(ILogger Logger, IReportLogic Logic) + { + InitializeComponent(); + _logger = Logger; + _logic = Logic; + + _reportViewer = new ReportViewer + { + Dock = DockStyle.Fill + }; + _reportViewer.LocalReport.LoadReportDefinition(new FileStream("ReportGroupedOrders.rdlc", FileMode.Open)); + + Controls.Clear(); + Controls.Add(_reportViewer); + Controls.Add(panel); + } + + private void ButtonMake_Click(object sender, EventArgs e) + { + try + { + var DataSource = _logic.GetGroupedOrders(); + var Source = new ReportDataSource("DataSetGroupedOrders", DataSource); + _reportViewer.LocalReport.DataSources.Clear(); + _reportViewer.LocalReport.DataSources.Add(Source); + + _reportViewer.RefreshReport(); + _logger.LogInformation("Загрузка списка заказов, объединенных по датам"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка заказов, объединенных по датам"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonToPdf_Click(object sender, EventArgs e) + { + using var Dialog = new SaveFileDialog { Filter = "pdf|*.pdf" }; + + if (Dialog.ShowDialog() == DialogResult.OK) + { + try + { + System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance); + _logic.SaveGroupedOrdersToPdfFile(new ReportBindingModel + { + FileName = Dialog.FileName, + }); + + _logger.LogInformation("Сохранение списка заказов, объединенных по датам"); + MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения списка заказов, объединенных по датам"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } +} diff --git a/AutoWorkshopView/Forms/FormReportGroupedOrders.resx b/AutoWorkshopView/Forms/FormReportGroupedOrders.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/AutoWorkshopView/Forms/FormReportGroupedOrders.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/FormReportShop.Designer.cs b/AutoWorkshopView/Forms/FormReportShop.Designer.cs new file mode 100644 index 0000000..c7465cf --- /dev/null +++ b/AutoWorkshopView/Forms/FormReportShop.Designer.cs @@ -0,0 +1,115 @@ +namespace AutoWorkshopView.Forms +{ + partial class FormReportShop + { + /// + /// 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() + { + buttonSaveToExcel = new Button(); + dataGridView = new DataGridView(); + ColumnShop = new DataGridViewTextBoxColumn(); + ColumnRepair = new DataGridViewTextBoxColumn(); + ColumnCount = new DataGridViewTextBoxColumn(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // buttonSaveToExcel + // + buttonSaveToExcel.Location = new Point(12, 10); + buttonSaveToExcel.Margin = new Padding(3, 2, 3, 2); + buttonSaveToExcel.Name = "buttonSaveToExcel"; + buttonSaveToExcel.Size = new Size(195, 27); + buttonSaveToExcel.TabIndex = 3; + buttonSaveToExcel.Text = "Сохранить в Excel"; + buttonSaveToExcel.UseVisualStyleBackColor = true; + buttonSaveToExcel.Click += ButtonSaveToExcel_Click; + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.AllowUserToOrderColumns = true; + dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Columns.AddRange(new DataGridViewColumn[] { ColumnShop, ColumnRepair, ColumnCount }); + dataGridView.Dock = DockStyle.Bottom; + dataGridView.Location = new Point(0, 50); + dataGridView.Margin = new Padding(3, 2, 3, 2); + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 29; + dataGridView.Size = new Size(523, 288); + dataGridView.TabIndex = 2; + // + // ColumnShop + // + ColumnShop.FillWeight = 130F; + ColumnShop.HeaderText = "Магазин"; + ColumnShop.MinimumWidth = 6; + ColumnShop.Name = "ColumnShop"; + ColumnShop.ReadOnly = true; + // + // ColumnRepair + // + ColumnRepair.FillWeight = 140F; + ColumnRepair.HeaderText = "Ремонт"; + ColumnRepair.MinimumWidth = 6; + ColumnRepair.Name = "ColumnRepair"; + ColumnRepair.ReadOnly = true; + // + // ColumnCount + // + ColumnCount.FillWeight = 90F; + ColumnCount.HeaderText = "Количество"; + ColumnCount.MinimumWidth = 6; + ColumnCount.Name = "ColumnCount"; + ColumnCount.ReadOnly = true; + // + // FormReportShop + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(523, 338); + Controls.Add(buttonSaveToExcel); + Controls.Add(dataGridView); + Margin = new Padding(3, 2, 3, 2); + Name = "FormReportShop"; + Text = "Загруженность магазинов"; + Load += FormReportShop_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private Button buttonSaveToExcel; + private DataGridView dataGridView; + private DataGridViewTextBoxColumn ColumnShop; + private DataGridViewTextBoxColumn ColumnRepair; + private DataGridViewTextBoxColumn ColumnCount; + } +} \ No newline at end of file diff --git a/AutoWorkshopView/Forms/FormReportShop.cs b/AutoWorkshopView/Forms/FormReportShop.cs new file mode 100644 index 0000000..b751e0a --- /dev/null +++ b/AutoWorkshopView/Forms/FormReportShop.cs @@ -0,0 +1,75 @@ +using AutoWorkshopContracts.BindingModels; +using AutoWorkshopContracts.BusinessLogicContracts; +using Microsoft.Extensions.Logging; + +namespace AutoWorkshopView.Forms +{ + public partial class FormReportShop : Form + { + private readonly ILogger _logger; + private readonly IReportLogic _logic; + + public FormReportShop(ILogger Logger, IReportLogic Logic) + { + InitializeComponent(); + + _logger = Logger; + _logic = Logic; + } + + private void FormReportShop_Load(object sender, EventArgs e) + { + try + { + var Shops = _logic.GetShops(); + if (Shops != null) + { + dataGridView.Rows.Clear(); + + foreach (var Shop in Shops) + { + dataGridView.Rows.Add(new object[] { Shop.ShopName, "", "" }); + + foreach (var Repair in Shop.Repairs) + { + dataGridView.Rows.Add(new object[] { "", Repair.Item1, Repair.Item2 }); + } + + dataGridView.Rows.Add(new object[] { "Итого", "", Shop.TotalCount }); + dataGridView.Rows.Add(Array.Empty()); + } + } + + _logger.LogInformation("Загрузка списка ремонтов по магазинам"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка ремонтов по магазинам"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonSaveToExcel_Click(object sender, EventArgs e) + { + using var Dialog = new SaveFileDialog { Filter = "xlsx|*.xlsx" }; + if (Dialog.ShowDialog() == DialogResult.OK) + { + try + { + _logic.SaveShopsToExcelFile(new ReportBindingModel + { + FileName = Dialog.FileName + }); + + _logger.LogInformation("Сохранение списка ремонтов по магазинам"); + MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения списка ремонтов по магазинам"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } +} diff --git a/AutoWorkshopView/Forms/FormReportShop.resx b/AutoWorkshopView/Forms/FormReportShop.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/AutoWorkshopView/Forms/FormReportShop.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/MainForm.cs b/AutoWorkshopView/MainForm.cs index 05db557..cb8cc46 100644 --- a/AutoWorkshopView/MainForm.cs +++ b/AutoWorkshopView/MainForm.cs @@ -229,5 +229,36 @@ namespace AutoWorkshopView Form.ShowDialog(); } } + + private void InfoToolStripMenuItem_Click(object sender, EventArgs e) + { + using var Dialog = new SaveFileDialog { Filter = "docx|*.docx" }; + + if (Dialog.ShowDialog() == DialogResult.OK) + { + _reportLogic.SaveShopsToWordFile(new ReportBindingModel { FileName = Dialog.FileName }); + MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } + + private void BusyShopsToolStripMenuItem_Click(object sender, EventArgs e) + { + var Service = Program.ServiceProvider?.GetService(typeof(FormReportShop)); + + if (Service is FormReportShop Form) + { + Form.ShowDialog(); + } + } + + private void GroupOrdersToolStripMenuItem_Click(object sender, EventArgs e) + { + var Service = Program.ServiceProvider?.GetService(typeof(FormReportGroupedOrders)); + + if (Service is FormReportGroupedOrders Form) + { + Form.ShowDialog(); + } + } } } diff --git a/AutoWorkshopView/Program.cs b/AutoWorkshopView/Program.cs index 074d2ab..fecb046 100644 --- a/AutoWorkshopView/Program.cs +++ b/AutoWorkshopView/Program.cs @@ -66,6 +66,8 @@ namespace AutoWorkshopView Services.AddTransient(); Services.AddTransient(); Services.AddTransient(); + Services.AddTransient(); + Services.AddTransient(); } } } diff --git a/AutoWorkshopView/ReportGroupedOrders.rdlc b/AutoWorkshopView/ReportGroupedOrders.rdlc new file mode 100644 index 0000000..5250730 --- /dev/null +++ b/AutoWorkshopView/ReportGroupedOrders.rdlc @@ -0,0 +1,441 @@ + + + 0 + + + + System.Data.DataSet + /* Local Connection */ + + 20791c83-cee8-4a38-bbd0-245fc17cefb3 + + + + + + AutoWorkshopContractsViewModels + /* Local Query */ + + + + Date + System.DateTime + + + OrdersCount + System.Int32 + + + OrdersSum + System.Decimal + + + + AutoWorkshopContracts.ViewModels + AutoWorksReportGroupedOrdersViewModelhop + AutoWorkshopContracts.ViewModels.AutoWorksReportGroupedOrdersViewModelhop, AutoWorkshopContracts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + + + + + + + + + true + true + + + + + Отчёт по заказам + + + + 0.6cm + 16.51cm + + + Middle + 2pt + 2pt + 2pt + 2pt + + + + true + true + + + + + =Parameters!ReportParameterPeriod.Value + + + + + + + ReportParameterPeriod + 0.6cm + 0.6cm + 16.51cm + 1 + + + 2pt + 2pt + 2pt + 2pt + + + + + + + 3.90406cm + + + 3.97461cm + + + 3.65711cm + + + + + 0.6cm + + + + + true + true + + + + + Дата создания + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + Количество заказов + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + Общая сумма заказов + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + 0.6cm + + + + + true + true + + + + + =Fields!Date.Value + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + =Fields!OrdersCount.Value + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + =Fields!OrdersSum.Value + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + + + + + + + + + + + + After + + + + + + + DataSetGroupedOrders + 1.88242cm + 2.68676cm + 1.2cm + 11.53578cm + 2 + + + + + + true + true + + + + + Итого: + + + + 3.29409cm + 8.06542cm + 0.6cm + 2.5cm + 3 + + + 2pt + 2pt + 2pt + 2pt + + + + true + true + + + + + =Sum(Fields!OrdersSum.Value, "DataSetGroupedOrders") + + + + + + + 3.29409cm + 10.70653cm + 0.6cm + 3.48072cm + 4 + + + 2pt + 2pt + 2pt + 2pt + + + + 2in +