diff --git a/SoftwareInstallation/SoftwareInstallationBusinessLogic/ComponentLogic.cs b/SoftwareInstallation/SoftwareInstallationBusinessLogic/ComponentLogic.cs index b7cf0f5..d739f04 100644 --- a/SoftwareInstallation/SoftwareInstallationBusinessLogic/ComponentLogic.cs +++ b/SoftwareInstallation/SoftwareInstallationBusinessLogic/ComponentLogic.cs @@ -10,8 +10,7 @@ namespace SoftwareInstallationBusinessLogic.BusinessLogics { private readonly ILogger _logger; private readonly IComponentStorage _componentStorage; - public ComponentLogic(ILogger logger, IComponentStorage - componentStorage) + public ComponentLogic(ILogger logger, IComponentStorage componentStorage) { _logger = logger; _componentStorage = componentStorage; diff --git a/SoftwareInstallation/SoftwareInstallationBusinessLogic/OrderLogic.cs b/SoftwareInstallation/SoftwareInstallationBusinessLogic/OrderLogic.cs index 5c3c275..e27c78b 100644 --- a/SoftwareInstallation/SoftwareInstallationBusinessLogic/OrderLogic.cs +++ b/SoftwareInstallation/SoftwareInstallationBusinessLogic/OrderLogic.cs @@ -1,6 +1,112 @@ -namespace SoftwareInstallationBusinessLogic +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.BusinessLogicsContracts; +using SoftwareInstallationContracts.SearchModels; +using SoftwareInstallationContracts.StoragesContracts; +using SoftwareInstallationContracts.ViewModels; +using SoftwareInstallationDataModels.Enums; +using Microsoft.Extensions.Logging; + +namespace SoftwareInstallationBusinessLogic.BusinessLogics { - internal class OrderLogic + public class OrderLogic : IOrderLogic { + private readonly ILogger _logger; + private readonly IOrderStorage _orderStorage; + + public OrderLogic(ILogger logger, IOrderStorage orderStorage) + { + _logger = logger; + _orderStorage = orderStorage; + } + public bool CreateOrder(OrderBindingModel model) + { + CheckModel(model); + + if (model.Status != OrderStatus.Неизвестен) + { + throw new ArgumentException( + $"Статус заказа должен быть {OrderStatus.Неизвестен}", nameof(model)); + } + model.Status = OrderStatus.Принят; + model.DateCreate = DateTime.Now; + if (_orderStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool DeliveryOrder(OrderBindingModel model) + { + return SetOrderStatus(model, OrderStatus.Выдан); + } + + public bool FinishOrder(OrderBindingModel model) + { + return SetOrderStatus(model, OrderStatus.Выполняется); + } + + public List? ReadList(OrderSearchModel? model) + { + _logger.LogInformation("ReadList. OrderName.Id:{ Id} ", model?.Id); + var list = (model == null) ? _orderStorage.GetFullList() : + _orderStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public bool TakeOrderInWork(OrderBindingModel model) + { + return SetOrderStatus(model, OrderStatus.Выполняется); + } + private bool CheckModel(OrderBindingModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (model.Count <= 0) + { + throw new ArgumentException("Количество изделий в заказе должно быть больше 0", nameof(model.Count)); + } + if (model.Sum <= 0) + { + throw new ArgumentException("Суммарная стоимость заказа должна быть больше 0", nameof(model.Sum)); + } + if (model.DateCreate > model.DateImplement) + { + throw new ArgumentException("Время создания заказа не может быть больше времени его выполнения", nameof(model.DateImplement)); + } + return true; + } + private bool SetOrderStatus(OrderBindingModel model, OrderStatus orderStatus) + { + var viewModel = _orderStorage.GetElement(new() { Id = model.Id }); + if (viewModel == null) + { + throw new ArgumentNullException(nameof(model)); + } + if ((int)viewModel.Status + 1 != (int)orderStatus) + { + throw new ArgumentException($"Попытка перевести заказ не в следующий статус: " + + $"Текущий статус: {viewModel.Status} \n" + + $"Планируемый статус: {orderStatus} \n" + + $"Доступный статус: {(OrderStatus)((int)viewModel.Status + 1)}", + nameof(viewModel)); + } + model.Status = orderStatus; + if (_orderStorage.Update(model) == null) + { + _logger.LogWarning("Ошибка операции обновления"); + return false; + } + return true; + } } -} +} \ No newline at end of file diff --git a/SoftwareInstallation/SoftwareInstallationBusinessLogic/PackageLogic.cs b/SoftwareInstallation/SoftwareInstallationBusinessLogic/PackageLogic.cs index 6621be9..2545127 100644 --- a/SoftwareInstallation/SoftwareInstallationBusinessLogic/PackageLogic.cs +++ b/SoftwareInstallation/SoftwareInstallationBusinessLogic/PackageLogic.cs @@ -1,7 +1,114 @@ -namespace SoftwareInstallationBusinessLogic +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.BusinessLogicsContracts; +using SoftwareInstallationContracts.SearchModels; +using SoftwareInstallationContracts.StoragesContracts; +using SoftwareInstallationContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace SoftwareInstallationBusinessLogic.BusinessLogics { - public class PackageLogic + public class PackageLogic : IPackageLogic { - //ToDO + private readonly ILogger _logger; + private readonly IPackageStorage _componentStorage; + public PackageLogic(ILogger logger, IPackageStorage componentStorage) + { + _logger = logger; + _componentStorage = componentStorage; + } + + public bool Create(PackageBindingModel model) + { + CheckModel(model); + if (_componentStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Delete(PackageBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_componentStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + public PackageViewModel? ReadElement(PackageSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. PackageName:{PackageName}.Id:{ Id}", model.PackageName, model.Id); + var element = _componentStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + + public List? ReadList(PackageSearchModel? model) + { + _logger.LogInformation("ReadList. PackageName:{PackageName}.Id:{ Id} ", model?.PackageName, model?.Id); + var list = (model == null) ? _componentStorage.GetFullList() : _componentStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public bool Update(PackageBindingModel model) + { + CheckModel(model); + if (_componentStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + private void CheckModel(PackageBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.PackageName)) + { + throw new ArgumentNullException("Нет названия кондитерского изделия", + nameof(model.PackageName)); + } + if (model.Price <= 0) + { + throw new ArgumentNullException("Цена кондитерского изделия должна быть больше 0", nameof(model.Price)); + } + _logger.LogInformation("Package. PackageName:{PackageName}.Cost:{ Cost}. Id: { Id}", + model.PackageName, model.Price, model.Id); + var element = _componentStorage.GetElement(new PackageSearchModel + { + PackageName = model.PackageName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Кондитерское изделие с таким названием уже есть"); + } + } } -} +} \ No newline at end of file diff --git a/SoftwareInstallation/SoftwareInstallationListImplement/Order.cs b/SoftwareInstallation/SoftwareInstallationListImplement/Order.cs index 2de3006..8bf09c7 100644 --- a/SoftwareInstallation/SoftwareInstallationListImplement/Order.cs +++ b/SoftwareInstallation/SoftwareInstallationListImplement/Order.cs @@ -1,7 +1,69 @@ -namespace SoftwareInstallationListImplement +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.ViewModels; +using SoftwareInstallationDataModels.Models; +using SoftwareInstallationDataModels.Enums; + +namespace SoftwareInstallationListImplement.Models { - public class Order + public class Order : IOrderModel { - //ToDO + public int PackageId { get; private set; } + + public int Count { get; private set; } + + public double Sum { get; private set; } + + public OrderStatus Status { get; private set; } + + public DateTime DateCreate { get; private set; } + + public DateTime? DateImplement { get; private set; } + + public int Id { get; private set; } + + public static Order? Create(OrderBindingModel? model) + { + if (model == null) + { + return null; + } + return new Order() + { + PackageId = model.PackageId, + Count = model.Count, + Sum = model.Sum, + Status = model.Status, + DateCreate = model.DateCreate, + DateImplement = model.DateImplement, + Id = model.Id, + + }; + } + + public void Update(OrderBindingModel? model) + { + if (model == null) + { + return; + } + PackageId = model.PackageId; + Count = model.Count; + Sum = model.Sum; + Status = model.Status; + DateCreate = model.DateCreate; + DateImplement = model.DateImplement; + Id = model.Id; + } + + public OrderViewModel GetViewModel => new() + { + PackageId = PackageId, + Count = Count, + Sum = Sum, + Status = Status, + DateCreate = DateCreate, + DateImplement = DateImplement, + Id = Id, + }; } } \ No newline at end of file diff --git a/SoftwareInstallation/SoftwareInstallationListImplement/OrderStorage.cs b/SoftwareInstallation/SoftwareInstallationListImplement/OrderStorage.cs index 971d62a..d146868 100644 --- a/SoftwareInstallation/SoftwareInstallationListImplement/OrderStorage.cs +++ b/SoftwareInstallation/SoftwareInstallationListImplement/OrderStorage.cs @@ -1,7 +1,100 @@ -namespace SoftwareInstallationListImplement +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.SearchModels; +using SoftwareInstallationContracts.StoragesContracts; +using SoftwareInstallationContracts.ViewModels; +using SoftwareInstallationListImplement.Models; + +namespace SoftwareInstallationListImplement.Implements { - public class OrderStorage + public class OrderStorage : IOrderStorage { - //ToDO + private readonly DataListSingleton _source; + public OrderStorage() + { + _source = DataListSingleton.GetInstance(); + } + public OrderViewModel? Delete(OrderBindingModel model) + { + for (int i = 0; i < _source.Orders.Count; ++i) + { + if (_source.Orders[i].Id == model.Id) + { + var element = _source.Orders[i]; + _source.Orders.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + public OrderViewModel? GetElement(OrderSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + foreach (var order in _source.Orders) + { + if (model.Id.HasValue && order.Id == model.Id) + { + return order.GetViewModel; + } + } + return null; + } + public List GetFilteredList(OrderSearchModel model) + { + var result = new List(); + if (!model.Id.HasValue) + { + return result; + } + foreach (var order in _source.Orders) + { + if (order.Id == model.Id) + { + return new() { order.GetViewModel }; + } + } + return result; + } + public List GetFullList() + { + var result = new List(); + foreach (var order in _source.Orders) + { + result.Add(order.GetViewModel); + } + return result; + } + public OrderViewModel? Insert(OrderBindingModel model) + { + model.Id = 1; + foreach (var order in _source.Orders) + { + if (model.Id <= order.Id) + { + model.Id = order.Id + 1; + } + } + var newOrder = Order.Create(model); + if (newOrder == null) + { + return null; + } + _source.Orders.Add(newOrder); + return newOrder.GetViewModel; + } + public OrderViewModel? Update(OrderBindingModel model) + { + foreach (var order in _source.Orders) + { + if (order.Id == model.Id) + { + order.Update(model); + return order.GetViewModel; + } + } + return null; + } } } \ No newline at end of file diff --git a/SoftwareInstallation/SoftwareInstallationListImplement/PackageStorage.cs b/SoftwareInstallation/SoftwareInstallationListImplement/PackageStorage.cs index d2111dd..4d942c8 100644 --- a/SoftwareInstallation/SoftwareInstallationListImplement/PackageStorage.cs +++ b/SoftwareInstallation/SoftwareInstallationListImplement/PackageStorage.cs @@ -1,7 +1,108 @@ -namespace SoftwareInstallationListImplement +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.SearchModels; +using SoftwareInstallationContracts.StoragesContracts; +using SoftwareInstallationContracts.ViewModels; +using SoftwareInstallationListImplement.Models; + +namespace SoftwareInstallationListImplement.Implements { - public class PackageStorage + public class PackageStorage : IPackageStorage { - //ToDO + private readonly DataListSingleton _source; + public PackageStorage() + { + _source = DataListSingleton.GetInstance(); + } + + public PackageViewModel? Delete(PackageBindingModel model) + { + for (int i = 0; i < _source.Packages.Count; ++i) + { + if (_source.Packages[i].Id == model.Id) + { + var element = _source.Packages[i]; + _source.Packages.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + + public PackageViewModel? GetElement(PackageSearchModel model) + { + if (string.IsNullOrEmpty(model.PackageName) && !model.Id.HasValue) + { + return null; + } + foreach (var package in _source.Packages) + { + if ((!string.IsNullOrEmpty(model.PackageName) && + package.PackageName == model.PackageName) || + (model.Id.HasValue && package.Id == model.Id)) + { + return package.GetViewModel; + } + } + return null; + } + + public List GetFilteredList(PackageSearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.PackageName)) + { + return result; + } + foreach (var package in _source.Packages) + { + if (package.PackageName.Contains(model.PackageName ?? string.Empty)) + { + result.Add(package.GetViewModel); + } + } + return result; + } + + public List GetFullList() + { + var result = new List(); + foreach (var package in _source.Packages) + { + result.Add(package.GetViewModel); + } + return result; + } + + public PackageViewModel? Insert(PackageBindingModel model) + { + model.Id = 1; + foreach (var package in _source.Packages) + { + if (model.Id <= package.Id) + { + model.Id = package.Id + 1; + } + } + var newPackage = Package.Create(model); + if (newPackage == null) + { + return null; + } + _source.Packages.Add(newPackage); + return newPackage.GetViewModel; + } + + public PackageViewModel? Update(PackageBindingModel model) + { + foreach (var package in _source.Packages) + { + if (package.Id == model.Id) + { + package.Update(model); + return package.GetViewModel; + } + } + return null; + } } } \ No newline at end of file diff --git a/SoftwareInstallation/SoftwareInstallationView/FormComponent.Designer.cs b/SoftwareInstallation/SoftwareInstallationView/FormComponent.Designer.cs index b0353be..cfbc00b 100644 --- a/SoftwareInstallation/SoftwareInstallationView/FormComponent.Designer.cs +++ b/SoftwareInstallation/SoftwareInstallationView/FormComponent.Designer.cs @@ -44,6 +44,7 @@ this.buttonSave.TabIndex = 11; this.buttonSave.Text = "Сохранить"; this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); // // buttonCancel // @@ -53,6 +54,7 @@ this.buttonCancel.TabIndex = 10; this.buttonCancel.Text = "Отмена"; this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); // // textBoxCost // diff --git a/SoftwareInstallation/SoftwareInstallationView/FormComponents.Designer.cs b/SoftwareInstallation/SoftwareInstallationView/FormComponents.Designer.cs index dd80144..709c661 100644 --- a/SoftwareInstallation/SoftwareInstallationView/FormComponents.Designer.cs +++ b/SoftwareInstallation/SoftwareInstallationView/FormComponents.Designer.cs @@ -45,6 +45,7 @@ this.buttonRef.TabIndex = 13; this.buttonRef.Text = "Обновить"; this.buttonRef.UseVisualStyleBackColor = true; + this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click); // // buttonDel // @@ -55,6 +56,7 @@ this.buttonDel.TabIndex = 12; this.buttonDel.Text = "Удалить"; this.buttonDel.UseVisualStyleBackColor = true; + this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click); // // buttonUpd // @@ -65,6 +67,7 @@ this.buttonUpd.TabIndex = 11; this.buttonUpd.Text = "Изменить"; this.buttonUpd.UseVisualStyleBackColor = true; + this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click); // // buttonAdd // @@ -75,6 +78,7 @@ this.buttonAdd.TabIndex = 10; this.buttonAdd.Text = "Добавить"; this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); // // dataGridView // diff --git a/SoftwareInstallation/SoftwareInstallationView/FormCreateOrder.Designer.cs b/SoftwareInstallation/SoftwareInstallationView/FormCreateOrder.Designer.cs index 4adca17..5a3516f 100644 --- a/SoftwareInstallation/SoftwareInstallationView/FormCreateOrder.Designer.cs +++ b/SoftwareInstallation/SoftwareInstallationView/FormCreateOrder.Designer.cs @@ -54,6 +54,7 @@ this.textBoxCount.Size = new System.Drawing.Size(214, 23); this.textBoxCount.TabIndex = 14; this.textBoxCount.UseWaitCursor = true; + this.textBoxCount.Click += new System.EventHandler(this.TextBoxCount_TextChanged); // // comboBoxPackage // @@ -63,6 +64,7 @@ this.comboBoxPackage.Size = new System.Drawing.Size(214, 23); this.comboBoxPackage.TabIndex = 13; this.comboBoxPackage.UseWaitCursor = true; + this.comboBoxPackage.SelectedIndexChanged += new System.EventHandler(this.ComboBoxPackage_SelectedIndexChanged); // // buttonSave // @@ -74,6 +76,7 @@ this.buttonSave.Text = "Сохранить"; this.buttonSave.UseVisualStyleBackColor = true; this.buttonSave.UseWaitCursor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); // // buttonCancel // @@ -85,6 +88,7 @@ this.buttonCancel.Text = "Отмена"; this.buttonCancel.UseVisualStyleBackColor = true; this.buttonCancel.UseWaitCursor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); // // label3 // diff --git a/SoftwareInstallation/SoftwareInstallationView/FormCreateOrder.cs b/SoftwareInstallation/SoftwareInstallationView/FormCreateOrder.cs index 78d2faf..1e4bdcd 100644 --- a/SoftwareInstallation/SoftwareInstallationView/FormCreateOrder.cs +++ b/SoftwareInstallation/SoftwareInstallationView/FormCreateOrder.cs @@ -1,6 +1,7 @@ using SoftwareInstallationContracts.BindingModels; using SoftwareInstallationContracts.BusinessLogicsContracts; using SoftwareInstallationContracts.SearchModels; +using SoftwareInstallationContracts.ViewModels; using Microsoft.Extensions.Logging; @@ -11,17 +12,29 @@ namespace SoftwareInstallationView private readonly ILogger _logger; private readonly IPackageLogic _logicP; private readonly IOrderLogic _logicO; + private readonly List? _list; public FormCreateOrder(ILogger logger, IPackageLogic logicP, IOrderLogic logicO) { InitializeComponent(); _logger = logger; _logicP = logicP; _logicO = logicO; + _list = logicP.ReadList(null); + if (_list != null) + { + comboBoxPackage.DisplayMember = "PackageName"; + comboBoxPackage.ValueMember = "Id"; + comboBoxPackage.DataSource = _list; + comboBoxPackage.SelectedItem = null; + } } private void FormCreateOrder_Load(object sender, EventArgs e) { _logger.LogInformation("Загрузка изделий для заказа"); - // прописать логику ToDO + foreach (var el in _logicP.ReadList(null) ?? new()) + { + comboBoxPackage.Items.Add(el.PackageName); + } } private void CalcSum() { @@ -49,6 +62,10 @@ namespace SoftwareInstallationView { CalcSum(); } + private void ComboBoxPackage_SelectedIndexChanged(object sender, EventArgs e) + { + CalcSum(); + } private void ButtonSave_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(textBoxCount.Text)) diff --git a/SoftwareInstallation/SoftwareInstallationView/FormMain.Designer.cs b/SoftwareInstallation/SoftwareInstallationView/FormMain.Designer.cs index 92460c5..6dcc55b 100644 --- a/SoftwareInstallation/SoftwareInstallationView/FormMain.Designer.cs +++ b/SoftwareInstallation/SoftwareInstallationView/FormMain.Designer.cs @@ -30,7 +30,7 @@ { this.menuStrip1 = new System.Windows.Forms.MenuStrip(); this.справочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.pastryToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.packageToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.componentToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.button4 = new System.Windows.Forms.Button(); this.button3 = new System.Windows.Forms.Button(); @@ -55,23 +55,25 @@ // справочникиToolStripMenuItem // this.справочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.pastryToolStripMenuItem, + this.packageToolStripMenuItem, this.componentToolStripMenuItem}); this.справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; this.справочникиToolStripMenuItem.Size = new System.Drawing.Size(94, 20); this.справочникиToolStripMenuItem.Text = "Справочники"; // - // pastryToolStripMenuItem + // packageToolStripMenuItem // - this.pastryToolStripMenuItem.Name = "pastryToolStripMenuItem"; - this.pastryToolStripMenuItem.Size = new System.Drawing.Size(180, 22); - this.pastryToolStripMenuItem.Text = "Изделия"; + this.packageToolStripMenuItem.Name = "packageToolStripMenuItem"; + this.packageToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.packageToolStripMenuItem.Text = "Изделия"; + this.packageToolStripMenuItem.Click += new System.EventHandler(this.PackagesToolStripMenuItem_Click); // // componentToolStripMenuItem // this.componentToolStripMenuItem.Name = "componentToolStripMenuItem"; this.componentToolStripMenuItem.Size = new System.Drawing.Size(180, 22); this.componentToolStripMenuItem.Text = "Компоненты"; + this.componentToolStripMenuItem.Click += new System.EventHandler(this.ComponentsToolStripMenuItem_Click); // // button4 // @@ -82,6 +84,7 @@ this.button4.TabIndex = 12; this.button4.Text = "Обновить список"; this.button4.UseVisualStyleBackColor = true; + this.button4.Click += new System.EventHandler(this.ButtonRef_Click); // // button3 // @@ -92,6 +95,7 @@ this.button3.TabIndex = 11; this.button3.Text = "Заказ выдан"; this.button3.UseVisualStyleBackColor = true; + this.button3.Click += new System.EventHandler(this.ButtonIssuedOrder_Click); // // button2 // @@ -102,6 +106,7 @@ this.button2.TabIndex = 10; this.button2.Text = "Заказ готов"; this.button2.UseVisualStyleBackColor = true; + this.button2.Click += new System.EventHandler(this.ButtonOrderReady_Click); // // buttonTakeOrderInWork // @@ -112,6 +117,7 @@ this.buttonTakeOrderInWork.TabIndex = 9; this.buttonTakeOrderInWork.Text = "Отдать на выполнение"; this.buttonTakeOrderInWork.UseVisualStyleBackColor = true; + this.buttonTakeOrderInWork.Click += new System.EventHandler(this.ButtonTakeOrderInWork_Click); // // buttonCreateOrder // @@ -122,6 +128,7 @@ this.buttonCreateOrder.TabIndex = 8; this.buttonCreateOrder.Text = "Создать заказ"; this.buttonCreateOrder.UseVisualStyleBackColor = true; + this.buttonCreateOrder.Click += new System.EventHandler(this.ButtonCreateOrder_Click); // // dataGridView // @@ -162,7 +169,7 @@ private MenuStrip menuStrip1; private ToolStripMenuItem справочникиToolStripMenuItem; - private ToolStripMenuItem pastryToolStripMenuItem; + private ToolStripMenuItem packageToolStripMenuItem; private ToolStripMenuItem componentToolStripMenuItem; private Button button4; private Button button3; diff --git a/SoftwareInstallation/SoftwareInstallationView/FormMain.cs b/SoftwareInstallation/SoftwareInstallationView/FormMain.cs index 73d8922..70f93ed 100644 --- a/SoftwareInstallation/SoftwareInstallationView/FormMain.cs +++ b/SoftwareInstallation/SoftwareInstallationView/FormMain.cs @@ -20,21 +20,37 @@ namespace SoftwareInstallationView } private void LoadData() { - _logger.LogInformation("Загрузка заказов"); - // прописать логику ToDO + try + { + var list = _orderLogic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + } + _logger.LogInformation("Загрузка заказов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки заказов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } } - private void КомпонентыToolStripMenuItem_Click(object sender, EventArgs e) + private void ComponentsToolStripMenuItem_Click(object sender, EventArgs e) { - var service = - Program.ServiceProvider?.GetService(typeof(FormComponents)); + var service = Program.ServiceProvider?.GetService(typeof(FormComponents)); if (service is FormComponents form) { form.ShowDialog(); } } - private void ИзделияToolStripMenuItem_Click(object sender, EventArgs e) + private void PackagesToolStripMenuItem_Click(object sender, EventArgs e) { - // прописать логику + var service = Program.ServiceProvider?.GetService(typeof(FormPackages)); + if (service is FormPackages form) + { + form.ShowDialog(); + } } private void ButtonCreateOrder_Click(object sender, EventArgs e) { diff --git a/SoftwareInstallation/SoftwareInstallationView/FormPackage.Designer.cs b/SoftwareInstallation/SoftwareInstallationView/FormPackage.Designer.cs index d7cf95b..c4fe538 100644 --- a/SoftwareInstallation/SoftwareInstallationView/FormPackage.Designer.cs +++ b/SoftwareInstallation/SoftwareInstallationView/FormPackage.Designer.cs @@ -208,7 +208,7 @@ this.Controls.Add(this.groupBox1); this.Name = "FormPackage"; this.Text = "Изделие"; - this.Load += new System.EventHandler(this.FormPackage_Load_1); + this.Load += new System.EventHandler(this.FormPackage_Load); this.groupBox1.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); this.ResumeLayout(false); diff --git a/SoftwareInstallation/SoftwareInstallationView/FormPackageComponent.Designer.cs b/SoftwareInstallation/SoftwareInstallationView/FormPackageComponent.Designer.cs index 1dbad39..30f364d 100644 --- a/SoftwareInstallation/SoftwareInstallationView/FormPackageComponent.Designer.cs +++ b/SoftwareInstallation/SoftwareInstallationView/FormPackageComponent.Designer.cs @@ -44,6 +44,7 @@ this.ButtonSave.TabIndex = 11; this.ButtonSave.Text = "Сохранить"; this.ButtonSave.UseVisualStyleBackColor = true; + this.ButtonSave.Click += new System.EventHandler(this.ButtonSave_Click); // // ButtonCancel // @@ -53,6 +54,7 @@ this.ButtonCancel.TabIndex = 10; this.ButtonCancel.Text = "Отмена"; this.ButtonCancel.UseVisualStyleBackColor = true; + this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); // // textBoxCount // diff --git a/SoftwareInstallation/SoftwareInstallationView/FormPackages.Designer.cs b/SoftwareInstallation/SoftwareInstallationView/FormPackages.Designer.cs index db84241..ebcc51a 100644 --- a/SoftwareInstallation/SoftwareInstallationView/FormPackages.Designer.cs +++ b/SoftwareInstallation/SoftwareInstallationView/FormPackages.Designer.cs @@ -28,12 +28,94 @@ /// private void InitializeComponent() { - this.components = new System.ComponentModel.Container(); + this.buttonRef = new System.Windows.Forms.Button(); + this.buttonDel = new System.Windows.Forms.Button(); + this.buttonUpd = new System.Windows.Forms.Button(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // buttonRef + // + this.buttonRef.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.buttonRef.Location = new System.Drawing.Point(482, 172); + this.buttonRef.Name = "buttonRef"; + this.buttonRef.Size = new System.Drawing.Size(90, 52); + this.buttonRef.TabIndex = 14; + this.buttonRef.Text = "Обновить"; + this.buttonRef.UseVisualStyleBackColor = true; + this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click); + // + // buttonDel + // + this.buttonDel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.buttonDel.Location = new System.Drawing.Point(482, 118); + this.buttonDel.Name = "buttonDel"; + this.buttonDel.Size = new System.Drawing.Size(90, 48); + this.buttonDel.TabIndex = 13; + this.buttonDel.Text = "Удалить"; + this.buttonDel.UseVisualStyleBackColor = true; + this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click); + // + // buttonUpd + // + this.buttonUpd.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.buttonUpd.Location = new System.Drawing.Point(482, 63); + this.buttonUpd.Name = "buttonUpd"; + this.buttonUpd.Size = new System.Drawing.Size(90, 49); + this.buttonUpd.TabIndex = 12; + this.buttonUpd.Text = "Изменить"; + this.buttonUpd.UseVisualStyleBackColor = true; + this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // buttonAdd + // + this.buttonAdd.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.buttonAdd.Location = new System.Drawing.Point(482, 12); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(90, 45); + this.buttonAdd.TabIndex = 11; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // dataGridView + // + this.dataGridView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ButtonHighlight; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(12, 12); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowTemplate.Height = 25; + this.dataGridView.Size = new System.Drawing.Size(464, 417); + this.dataGridView.TabIndex = 10; + // + // FormPackages + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Text = "FormPackages"; + this.ClientSize = new System.Drawing.Size(584, 441); + this.Controls.Add(this.buttonRef); + this.Controls.Add(this.buttonDel); + this.Controls.Add(this.buttonUpd); + this.Controls.Add(this.buttonAdd); + this.Controls.Add(this.dataGridView); + this.Name = "FormPackages"; + this.Text = "Изделия"; + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + } #endregion + + private Button buttonRef; + private Button buttonDel; + private Button buttonUpd; + private Button buttonAdd; + private DataGridView dataGridView; } } \ No newline at end of file diff --git a/SoftwareInstallation/SoftwareInstallationView/FormPackages.cs b/SoftwareInstallation/SoftwareInstallationView/FormPackages.cs index 3207214..6759b73 100644 --- a/SoftwareInstallation/SoftwareInstallationView/FormPackages.cs +++ b/SoftwareInstallation/SoftwareInstallationView/FormPackages.cs @@ -1,20 +1,98 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; namespace SoftwareInstallationView { public partial class FormPackages : Form { - public FormPackages() + private readonly ILogger _logger; + private readonly IPackageLogic _logic; + public FormPackages(ILogger logger, IPackageLogic logic) { InitializeComponent(); + _logger = logger; + _logic = logic; + } + private void FormViewPackage_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["PackageName"].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(FormPackage)); + if (service is FormPackage 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(FormComponent)); + if (service is FormComponent form) + { + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + } + 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 PackageBindingModel + { + 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(); } } -} +} \ No newline at end of file diff --git a/SoftwareInstallation/SoftwareInstallationView/FormPackages.resx b/SoftwareInstallation/SoftwareInstallationView/FormPackages.resx index 1af7de1..f298a7b 100644 --- a/SoftwareInstallation/SoftwareInstallationView/FormPackages.resx +++ b/SoftwareInstallation/SoftwareInstallationView/FormPackages.resx @@ -1,64 +1,4 @@ - - - +