diff --git a/IceCreamShop/IceCreamBusinessLogic/BusinessLogics/ComponentLogic.cs b/IceCreamShop/IceCreamBusinessLogic/BusinessLogics/ComponentLogic.cs index abfb55d..62d2023 100644 --- a/IceCreamShop/IceCreamBusinessLogic/BusinessLogics/ComponentLogic.cs +++ b/IceCreamShop/IceCreamBusinessLogic/BusinessLogics/ComponentLogic.cs @@ -11,7 +11,7 @@ using IceCreamShopContracts.StoragesContracts; using IceCreamShopContracts.ViewModels; -namespace IceCreamShopBusinessLogic.BusinessLogics +namespace IceCreamBusinessLogic.BusinessLogics { public class ComponentLogic : IComponentLogic { diff --git a/IceCreamShop/IceCreamBusinessLogic/BusinessLogics/OrderLogic.cs b/IceCreamShop/IceCreamBusinessLogic/BusinessLogics/OrderLogic.cs index 974925f..be1f742 100644 --- a/IceCreamShop/IceCreamBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/IceCreamShop/IceCreamBusinessLogic/BusinessLogics/OrderLogic.cs @@ -95,8 +95,30 @@ namespace IceCreamBusinessLogic.BusinessLogics _logger.LogInformation("Order. OrderID:{Id}.Sum:{ Sum}. DocumentId: { DocumentId}", model.Id, model.Sum, model.IceCreamId); } - public bool SetNewStatus(OrderBindingModel model, OrderStatus newStatus) + public bool SetNewStatus(OrderBindingModel orderModel, OrderStatus newStatus) { + var viewModel = _orderStorage.GetElement(new OrderSearchModel + { + Id = orderModel.Id + }); + + if (viewModel == null) + { + _logger.LogWarning("Order model not found"); + return false; + } + + OrderBindingModel model = new OrderBindingModel + { + Id = viewModel.Id, + IceCreamId = viewModel.IceCreamId, + IceCreamName = viewModel.IceCreamName, + Status = viewModel.Status, + DateCreate = viewModel.DateCreate, + DateImplement = viewModel.DateImplement, + Count = viewModel.Count, + Sum = viewModel.Sum + }; CheckModel(model); if (model.Status + 1 != newStatus) { diff --git a/IceCreamShop/IceCreamBusinessLogic/BusinessLogics/ShopLogic.cs b/IceCreamShop/IceCreamBusinessLogic/BusinessLogics/ShopLogic.cs new file mode 100644 index 0000000..ec00b3b --- /dev/null +++ b/IceCreamShop/IceCreamBusinessLogic/BusinessLogics/ShopLogic.cs @@ -0,0 +1,167 @@ +using IceCreamShopContracts.BindingModels; +using IceCreamShopContracts.BusinessLogicsContracts; +using IceCreamShopContracts.SearchModels; +using IceCreamShopContracts.StoragesContracts; +using IceCreamShopContracts.ViewModels; +using AbstractIceCreamShopDataModels.Models; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace IceCreamBusinessLogic.BusinessLogics +{ + public class ShopLogic : IShopLogic + { + private readonly ILogger _logger; + private readonly IShopStorage _shopStorage; + + public ShopLogic(ILogger logger, IShopStorage shopStorage) + { + _logger = logger; + _shopStorage = shopStorage; + } + + public ShopViewModel? ReadElement(ShopSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. Shop Name:{0}.ID:{1}", model.Name, 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 List? ReadList(ShopSearchModel? model) + { + _logger.LogInformation("ReadList. Shop Name:{0}.ID:{1} ", model?.Name, 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 bool SupplyIceCreams(ShopSearchModel model, IIceCreamModel iceCream, int count) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + if (iceCream == null) + { + throw new ArgumentNullException(nameof(iceCream)); + } + + if (count <= 0) + { + throw new ArgumentNullException("Count of icecreams in supply must be more than 0", nameof(count)); + } + + var shopElement = _shopStorage.GetElement(model); + if (shopElement == null) + { + _logger.LogWarning("Required shop element not found in storage"); + return false; + } + _logger.LogInformation("Shop element found. ID: {0}, Name: {1}", shopElement.Id, shopElement.Name); + + if (shopElement.ShopIceCreams.TryGetValue(iceCream.Id, out var sameDocument)) + { + shopElement.ShopIceCreams[iceCream.Id] = (iceCream, sameDocument.Item2 + count); + _logger.LogInformation("Same icecream found by supply. Added {0} of {1} in {2} shop", count, iceCream.IceCreamName, shopElement.Name); + } + else + { + shopElement.ShopIceCreams[iceCream.Id] = (iceCream, count); + _logger.LogInformation("New icecream added by supply. Added {0} of {1} in {2} shop", count, iceCream.IceCreamName, shopElement.Name); + } + + _shopStorage.Update(new() + { + Id = shopElement.Id, + Name = shopElement.Name, + Adress = shopElement.Adress, + OpeningDate = shopElement.OpeningDate, + ShopIceCreams = shopElement.ShopIceCreams + }); + + return true; + } + + 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); + if (_shopStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + 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.Name)) + { + throw new ArgumentNullException("Нет названия магазина!", nameof(model.Name)); + } + _logger.LogInformation("Shop. Name: {0}, Adress: {1}, ID: {2}", model.Name, model.Adress, model.Id); + var element = _shopStorage.GetElement(new ShopSearchModel + { + Name = model.Name + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Магазин с таким названием уже есть"); + } + } + } +} diff --git a/IceCreamShop/IceCreamShop/FormComponent.Designer.cs b/IceCreamShop/IceCreamShop/FormComponent.Designer.cs index 02e723f..ad5ea7c 100644 --- a/IceCreamShop/IceCreamShop/FormComponent.Designer.cs +++ b/IceCreamShop/IceCreamShop/FormComponent.Designer.cs @@ -39,40 +39,43 @@ // labelName // this.labelName.AutoSize = true; - this.labelName.Location = new System.Drawing.Point(17, 10); + this.labelName.Location = new System.Drawing.Point(19, 13); this.labelName.Name = "labelName"; - this.labelName.Size = new System.Drawing.Size(62, 15); + this.labelName.Size = new System.Drawing.Size(80, 20); this.labelName.TabIndex = 0; this.labelName.Text = "Название:"; // // labelCost // this.labelCost.AutoSize = true; - this.labelCost.Location = new System.Drawing.Point(17, 42); + this.labelCost.Location = new System.Drawing.Point(19, 56); this.labelCost.Name = "labelCost"; - this.labelCost.Size = new System.Drawing.Size(38, 15); + this.labelCost.Size = new System.Drawing.Size(48, 20); this.labelCost.TabIndex = 1; this.labelCost.Text = "Цена:"; // // textBoxName // - this.textBoxName.Location = new System.Drawing.Point(85, 7); + this.textBoxName.Location = new System.Drawing.Point(97, 9); + this.textBoxName.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.textBoxName.Name = "textBoxName"; - this.textBoxName.Size = new System.Drawing.Size(223, 23); + this.textBoxName.Size = new System.Drawing.Size(254, 27); this.textBoxName.TabIndex = 2; // // textBoxCost // - this.textBoxCost.Location = new System.Drawing.Point(85, 39); + this.textBoxCost.Location = new System.Drawing.Point(97, 52); + this.textBoxCost.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.textBoxCost.Name = "textBoxCost"; - this.textBoxCost.Size = new System.Drawing.Size(100, 23); + this.textBoxCost.Size = new System.Drawing.Size(114, 27); this.textBoxCost.TabIndex = 3; // // buttonSave // - this.buttonSave.Location = new System.Drawing.Point(152, 73); + this.buttonSave.Location = new System.Drawing.Point(163, 97); + this.buttonSave.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.buttonSave.Name = "buttonSave"; - this.buttonSave.Size = new System.Drawing.Size(75, 23); + this.buttonSave.Size = new System.Drawing.Size(97, 31); this.buttonSave.TabIndex = 4; this.buttonSave.Text = "Сохранить"; this.buttonSave.UseVisualStyleBackColor = true; @@ -80,9 +83,10 @@ // // buttonCancle // - this.buttonCancle.Location = new System.Drawing.Point(233, 73); + this.buttonCancle.Location = new System.Drawing.Point(266, 97); + this.buttonCancle.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.buttonCancle.Name = "buttonCancle"; - this.buttonCancle.Size = new System.Drawing.Size(75, 23); + this.buttonCancle.Size = new System.Drawing.Size(86, 31); this.buttonCancle.TabIndex = 5; this.buttonCancle.Text = "Отмена"; this.buttonCancle.UseVisualStyleBackColor = true; @@ -90,15 +94,16 @@ // // FormComponent // - this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(327, 108); + this.ClientSize = new System.Drawing.Size(374, 144); this.Controls.Add(this.buttonCancle); this.Controls.Add(this.buttonSave); this.Controls.Add(this.textBoxCost); this.Controls.Add(this.textBoxName); this.Controls.Add(this.labelCost); this.Controls.Add(this.labelName); + this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.Name = "FormComponent"; this.Text = "Компонент"; this.Load += new System.EventHandler(this.FormComponent_Load); diff --git a/IceCreamShop/IceCreamShop/FormMain.Designer.cs b/IceCreamShop/IceCreamShop/FormMain.Designer.cs index b4ab36f..68195d4 100644 --- a/IceCreamShop/IceCreamShop/FormMain.Designer.cs +++ b/IceCreamShop/IceCreamShop/FormMain.Designer.cs @@ -38,6 +38,8 @@ this.справочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.компонентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.мороженоеToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.магазиныToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.buttonSupplyShop = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); this.menuStrip.SuspendLayout(); this.SuspendLayout(); @@ -55,7 +57,7 @@ // // buttonSetToFinish // - this.buttonSetToFinish.Location = new System.Drawing.Point(878, 225); + this.buttonSetToFinish.Location = new System.Drawing.Point(878, 149); this.buttonSetToFinish.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.buttonSetToFinish.Name = "buttonSetToFinish"; this.buttonSetToFinish.Size = new System.Drawing.Size(170, 37); @@ -66,7 +68,7 @@ // // buttonSetToDone // - this.buttonSetToDone.Location = new System.Drawing.Point(878, 160); + this.buttonSetToDone.Location = new System.Drawing.Point(878, 108); this.buttonSetToDone.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.buttonSetToDone.Name = "buttonSetToDone"; this.buttonSetToDone.Size = new System.Drawing.Size(170, 37); @@ -77,7 +79,7 @@ // // buttonSetToWork // - this.buttonSetToWork.Location = new System.Drawing.Point(878, 93); + this.buttonSetToWork.Location = new System.Drawing.Point(878, 67); this.buttonSetToWork.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.buttonSetToWork.Name = "buttonSetToWork"; this.buttonSetToWork.Size = new System.Drawing.Size(170, 37); @@ -124,7 +126,8 @@ // this.справочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.компонентыToolStripMenuItem, - this.мороженоеToolStripMenuItem}); + this.мороженоеToolStripMenuItem, + this.магазиныToolStripMenuItem}); this.справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; this.справочникиToolStripMenuItem.Size = new System.Drawing.Size(94, 20); this.справочникиToolStripMenuItem.Text = "Справочники"; @@ -143,11 +146,30 @@ this.мороженоеToolStripMenuItem.Text = "Мороженое"; this.мороженоеToolStripMenuItem.Click += new System.EventHandler(this.мороженоеToolStripMenuItem_Click); // + // магазиныToolStripMenuItem + // + this.магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem"; + this.магазиныToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.магазиныToolStripMenuItem.Text = "Магазины"; + this.магазиныToolStripMenuItem.Click += new System.EventHandler(this.магазиныToolStripMenuItem_Click); + // + // buttonSupplyShop + // + this.buttonSupplyShop.Location = new System.Drawing.Point(878, 190); + this.buttonSupplyShop.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonSupplyShop.Name = "buttonSupplyShop"; + this.buttonSupplyShop.Size = new System.Drawing.Size(170, 37); + this.buttonSupplyShop.TabIndex = 14; + this.buttonSupplyShop.Text = "Пополнение магазина"; + this.buttonSupplyShop.UseVisualStyleBackColor = true; + this.buttonSupplyShop.Click += new System.EventHandler(this.buttonSupplyShop_Click); + // // FormMain // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(1072, 347); + this.Controls.Add(this.buttonSupplyShop); this.Controls.Add(this.buttonUpdate); this.Controls.Add(this.buttonSetToFinish); this.Controls.Add(this.buttonSetToDone); @@ -178,5 +200,7 @@ private ToolStripMenuItem справочникиToolStripMenuItem; private ToolStripMenuItem компонентыToolStripMenuItem; private ToolStripMenuItem мороженоеToolStripMenuItem; + private ToolStripMenuItem магазиныToolStripMenuItem; + private Button buttonSupplyShop; } } \ No newline at end of file diff --git a/IceCreamShop/IceCreamShop/FormMain.cs b/IceCreamShop/IceCreamShop/FormMain.cs index ca6f1bd..8dd2ef8 100644 --- a/IceCreamShop/IceCreamShop/FormMain.cs +++ b/IceCreamShop/IceCreamShop/FormMain.cs @@ -69,6 +69,15 @@ namespace IceCreamShopView } } + private void магазиныToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShops)); + if (service is FormShops form) + { + form.ShowDialog(); + } + } + private void buttonCreateOrder_Click(object sender, EventArgs e) { var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); @@ -90,12 +99,6 @@ namespace IceCreamShopView var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel { Id = id, - IceCreamId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["IceCreamId"].Value), - IceCreamName = dataGridView.SelectedRows[0].Cells["IceCreamName"].Value.ToString(), - Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), - Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), - Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), - DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), }); if (!operationResult) { @@ -123,12 +126,6 @@ namespace IceCreamShopView var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel { Id = id, - IceCreamId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["IceCreamId"].Value), - IceCreamName = dataGridView.SelectedRows[0].Cells["IceCreamName"].Value.ToString(), - Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), - Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), - Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), - DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), }); if (!operationResult) { @@ -155,12 +152,6 @@ namespace IceCreamShopView var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { Id = id, - IceCreamId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["IceCreamId"].Value), - IceCreamName = dataGridView.SelectedRows[0].Cells["IceCreamName"].Value.ToString(), - Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), - Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), - Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), - DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), }); if (!operationResult) { @@ -181,5 +172,14 @@ namespace IceCreamShopView { LoadData(); } + + private void buttonSupplyShop_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShopSupply)); + if (service is FormShopSupply form) + { + form.ShowDialog(); + } + } } } diff --git a/IceCreamShop/IceCreamShop/FormShop.Designer.cs b/IceCreamShop/IceCreamShop/FormShop.Designer.cs new file mode 100644 index 0000000..356849d --- /dev/null +++ b/IceCreamShop/IceCreamShop/FormShop.Designer.cs @@ -0,0 +1,194 @@ +namespace IceCreamShopView +{ + 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() + { + this.buttonCancel = new System.Windows.Forms.Button(); + this.buttonSave = new System.Windows.Forms.Button(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.ColumnId = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.ColumnDocumentName = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.ColumnCount = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.dateTimePicker = new System.Windows.Forms.DateTimePicker(); + this.labelOpeningDate = new System.Windows.Forms.Label(); + this.textBoxAddress = new System.Windows.Forms.TextBox(); + this.textBoxName = new System.Windows.Forms.TextBox(); + this.labelAddress = new System.Windows.Forms.Label(); + this.labelName = new System.Windows.Forms.Label(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(197, 338); + this.buttonCancel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(136, 22); + this.buttonCancel.TabIndex = 21; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click); + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(39, 338); + this.buttonSave.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(136, 22); + this.buttonSave.TabIndex = 20; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click); + // + // dataGridView + // + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.ColumnId, + this.ColumnDocumentName, + this.ColumnCount}); + this.dataGridView.Location = new System.Drawing.Point(9, 106); + this.dataGridView.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(351, 225); + this.dataGridView.TabIndex = 19; + // + // ColumnId + // + this.ColumnId.HeaderText = "ID"; + this.ColumnId.MinimumWidth = 6; + this.ColumnId.Name = "ColumnId"; + this.ColumnId.Visible = false; + this.ColumnId.Width = 125; + // + // ColumnDocumentName + // + this.ColumnDocumentName.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; + this.ColumnDocumentName.HeaderText = "Документ"; + this.ColumnDocumentName.MinimumWidth = 6; + this.ColumnDocumentName.Name = "ColumnDocumentName"; + // + // ColumnCount + // + this.ColumnCount.HeaderText = "Количество"; + this.ColumnCount.MinimumWidth = 6; + this.ColumnCount.Name = "ColumnCount"; + this.ColumnCount.Width = 125; + // + // dateTimePicker + // + this.dateTimePicker.Location = new System.Drawing.Point(141, 63); + this.dateTimePicker.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.dateTimePicker.Name = "dateTimePicker"; + this.dateTimePicker.Size = new System.Drawing.Size(219, 23); + this.dateTimePicker.TabIndex = 18; + // + // labelOpeningDate + // + this.labelOpeningDate.AutoSize = true; + this.labelOpeningDate.Location = new System.Drawing.Point(9, 66); + this.labelOpeningDate.Name = "labelOpeningDate"; + this.labelOpeningDate.Size = new System.Drawing.Size(100, 15); + this.labelOpeningDate.TabIndex = 17; + this.labelOpeningDate.Text = "Время открытия:"; + // + // textBoxAddress + // + this.textBoxAddress.Location = new System.Drawing.Point(85, 36); + this.textBoxAddress.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.textBoxAddress.Name = "textBoxAddress"; + this.textBoxAddress.Size = new System.Drawing.Size(276, 23); + this.textBoxAddress.TabIndex = 16; + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(85, 11); + this.textBoxName.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(276, 23); + this.textBoxName.TabIndex = 15; + // + // labelAddress + // + this.labelAddress.AutoSize = true; + this.labelAddress.Location = new System.Drawing.Point(9, 40); + this.labelAddress.Name = "labelAddress"; + this.labelAddress.Size = new System.Drawing.Size(43, 15); + this.labelAddress.TabIndex = 14; + this.labelAddress.Text = "Адрес:"; + // + // labelName + // + this.labelName.AutoSize = true; + this.labelName.Location = new System.Drawing.Point(9, 13); + this.labelName.Name = "labelName"; + this.labelName.Size = new System.Drawing.Size(62, 15); + this.labelName.TabIndex = 13; + this.labelName.Text = "Название:"; + // + // FormShop + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(376, 372); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.dataGridView); + this.Controls.Add(this.dateTimePicker); + this.Controls.Add(this.labelOpeningDate); + this.Controls.Add(this.textBoxAddress); + this.Controls.Add(this.textBoxName); + this.Controls.Add(this.labelAddress); + this.Controls.Add(this.labelName); + this.Name = "FormShop"; + this.Text = "Магазин"; + this.Load += new System.EventHandler(this.FormShop_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Button buttonCancel; + private Button buttonSave; + private DataGridView dataGridView; + private DataGridViewTextBoxColumn ColumnId; + private DataGridViewTextBoxColumn ColumnDocumentName; + private DataGridViewTextBoxColumn ColumnCount; + private DateTimePicker dateTimePicker; + private Label labelOpeningDate; + private TextBox textBoxAddress; + private TextBox textBoxName; + private Label labelAddress; + private Label labelName; + } +} \ No newline at end of file diff --git a/IceCreamShop/IceCreamShop/FormShop.cs b/IceCreamShop/IceCreamShop/FormShop.cs new file mode 100644 index 0000000..ebca8be --- /dev/null +++ b/IceCreamShop/IceCreamShop/FormShop.cs @@ -0,0 +1,133 @@ +using IceCreamShopContracts.BusinessLogicsContracts; +using IceCreamShopContracts.BindingModels; +using IceCreamShopContracts.SearchModels; +using AbstractIceCreamShopDataModels.Models; +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 Microsoft.Extensions.Logging; + +namespace IceCreamShopView +{ + public partial class FormShop : Form + { + private readonly IShopLogic _logic; + private readonly ILogger _logger; + private Dictionary _shopIceCreams; + private int? _id; + public int Id { set { _id = value; } } + public FormShop(ILogger logger, IShopLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + _shopIceCreams = new(); + } + + 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.Name; + textBoxAddress.Text = view.Adress; + dateTimePicker.Text = view.OpeningDate.ToString(); + _shopIceCreams = view.ShopIceCreams ?? new Dictionary(); + LoadData(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки магазина"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + private void LoadData() + { + _logger.LogInformation("Загрузка мороженого магазина"); + try + { + if (_shopIceCreams != null) + { + dataGridView.Rows.Clear(); + foreach (var pc in _shopIceCreams) + { + dataGridView.Rows.Add(new object[] + { + pc.Key, + pc.Value.Item1.IceCreamName, + pc.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(textBoxAddress.Text)) + { + MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение магазина"); + try + { + var model = new ShopBindingModel + { + Id = _id ?? 0, + Name = textBoxName.Text, + Adress = textBoxAddress.Text, + OpeningDate = dateTimePicker.Value.Date + }; + 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/IceCreamShop/IceCreamShop/FormShop.resx b/IceCreamShop/IceCreamShop/FormShop.resx new file mode 100644 index 0000000..71f1c74 --- /dev/null +++ b/IceCreamShop/IceCreamShop/FormShop.resx @@ -0,0 +1,69 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + True + + + True + + + True + + \ No newline at end of file diff --git a/IceCreamShop/IceCreamShop/FormShopSupply.Designer.cs b/IceCreamShop/IceCreamShop/FormShopSupply.Designer.cs new file mode 100644 index 0000000..5c9ad57 --- /dev/null +++ b/IceCreamShop/IceCreamShop/FormShopSupply.Designer.cs @@ -0,0 +1,145 @@ +namespace IceCreamShopView +{ + partial class FormShopSupply + { + /// + /// 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() + { + this.buttonCancel = new System.Windows.Forms.Button(); + this.buttonSave = new System.Windows.Forms.Button(); + this.textBoxCount = new System.Windows.Forms.TextBox(); + this.comboBoxDocument = new System.Windows.Forms.ComboBox(); + this.comboBoxShop = new System.Windows.Forms.ComboBox(); + this.labelDocumentCount = new System.Windows.Forms.Label(); + this.labelDocument = new System.Windows.Forms.Label(); + this.labelShop = new System.Windows.Forms.Label(); + this.SuspendLayout(); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(288, 179); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(94, 29); + this.buttonCancel.TabIndex = 17; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click); + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(187, 179); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(94, 29); + this.buttonSave.TabIndex = 16; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click); + // + // textBoxCount + // + this.textBoxCount.Location = new System.Drawing.Point(131, 119); + this.textBoxCount.Name = "textBoxCount"; + this.textBoxCount.Size = new System.Drawing.Size(125, 27); + this.textBoxCount.TabIndex = 15; + // + // comboBoxDocument + // + this.comboBoxDocument.FormattingEnabled = true; + this.comboBoxDocument.Location = new System.Drawing.Point(131, 65); + this.comboBoxDocument.Name = "comboBoxDocument"; + this.comboBoxDocument.Size = new System.Drawing.Size(251, 28); + this.comboBoxDocument.TabIndex = 14; + // + // comboBoxShop + // + this.comboBoxShop.FormattingEnabled = true; + this.comboBoxShop.Location = new System.Drawing.Point(131, 15); + this.comboBoxShop.Name = "comboBoxShop"; + this.comboBoxShop.Size = new System.Drawing.Size(251, 28); + this.comboBoxShop.TabIndex = 13; + // + // labelDocumentCount + // + this.labelDocumentCount.AutoSize = true; + this.labelDocumentCount.Location = new System.Drawing.Point(9, 119); + this.labelDocumentCount.Name = "labelDocumentCount"; + this.labelDocumentCount.Size = new System.Drawing.Size(93, 20); + this.labelDocumentCount.TabIndex = 12; + this.labelDocumentCount.Text = "Количество:"; + // + // labelDocument + // + this.labelDocument.AutoSize = true; + this.labelDocument.Location = new System.Drawing.Point(9, 68); + this.labelDocument.Name = "labelDocument"; + this.labelDocument.Size = new System.Drawing.Size(97, 20); + this.labelDocument.TabIndex = 11; + this.labelDocument.Text = "Мороженое:"; + // + // labelShop + // + this.labelShop.AutoSize = true; + this.labelShop.Location = new System.Drawing.Point(9, 15); + this.labelShop.Name = "labelShop"; + this.labelShop.RightToLeft = System.Windows.Forms.RightToLeft.No; + this.labelShop.Size = new System.Drawing.Size(72, 20); + this.labelShop.TabIndex = 10; + this.labelShop.Text = "Магазин:"; + // + // FormShopSupply + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(405, 220); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.textBoxCount); + this.Controls.Add(this.comboBoxDocument); + this.Controls.Add(this.comboBoxShop); + this.Controls.Add(this.labelDocumentCount); + this.Controls.Add(this.labelDocument); + this.Controls.Add(this.labelShop); + this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.Name = "FormShopSupply"; + this.Text = "FormShopSupply"; + this.Load += new System.EventHandler(this.FormShopSupply_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Button buttonCancel; + private Button buttonSave; + private TextBox textBoxCount; + private ComboBox comboBoxDocument; + private ComboBox comboBoxShop; + private Label labelDocumentCount; + private Label labelDocument; + private Label labelShop; + } +} \ No newline at end of file diff --git a/IceCreamShop/IceCreamShop/FormShopSupply.cs b/IceCreamShop/IceCreamShop/FormShopSupply.cs new file mode 100644 index 0000000..f3d6a4f --- /dev/null +++ b/IceCreamShop/IceCreamShop/FormShopSupply.cs @@ -0,0 +1,123 @@ +using IceCreamShopContracts.BindingModels; +using IceCreamShopContracts.BusinessLogicsContracts; +using IceCreamShopContracts.SearchModels; +using Microsoft.Extensions.Logging; +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; + +namespace IceCreamShopView +{ + public partial class FormShopSupply : Form + { + private readonly ILogger _logger; + private readonly IIceCreamLogic _logicI; + private readonly IShopLogic _logicS; + public FormShopSupply(ILogger logger, IIceCreamLogic logicI, IShopLogic logicS) + { + InitializeComponent(); + _logger = logger; + _logicI = logicI; + _logicS = logicS; + } + private void buttonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxDocument.SelectedValue == null) + { + MessageBox.Show("Выберите мороженое", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxShop.SelectedValue == null) + { + MessageBox.Show("Выберите магазин", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Создание поставки"); + try + { + var operationResult = _logicS.SupplyIceCreams( + new ShopSearchModel + { + Id = Convert.ToInt32(comboBoxShop.SelectedValue), + Name = comboBoxShop.Text + }, + new IceCreamBindingModel + { + Id = Convert.ToInt32(comboBoxDocument.SelectedValue), + IceCreamName = comboBoxDocument.Text + }, + 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(); + } + + private void FormShopSupply_Load(object sender, EventArgs e) + { + _logger.LogInformation("Загрузка мороженого для пополнения"); + try + { + var list = _logicI.ReadList(null); + if (list != null) + { + comboBoxDocument.DisplayMember = "IceCreamName"; + comboBoxDocument.ValueMember = "Id"; + comboBoxDocument.DataSource = list; + comboBoxDocument.SelectedItem = null; + } + + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка мороженого"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + + _logger.LogInformation("Загрузка магазинов для пополнения"); + try + { + var list = _logicS.ReadList(null); + if (list != null) + { + comboBoxShop.DisplayMember = "Name"; + comboBoxShop.ValueMember = "Id"; + comboBoxShop.DataSource = list; + comboBoxShop.SelectedItem = null; + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка магазинов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } +} diff --git a/IceCreamShop/IceCreamShop/FormShopSupply.resx b/IceCreamShop/IceCreamShop/FormShopSupply.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/IceCreamShop/IceCreamShop/FormShopSupply.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/IceCreamShop/IceCreamShop/FormShops.Designer.cs b/IceCreamShop/IceCreamShop/FormShops.Designer.cs new file mode 100644 index 0000000..32ee769 --- /dev/null +++ b/IceCreamShop/IceCreamShop/FormShops.Designer.cs @@ -0,0 +1,120 @@ +namespace IceCreamShopView +{ + 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() + { + this.buttonUpdate = new System.Windows.Forms.Button(); + this.buttonDelete = new System.Windows.Forms.Button(); + this.buttonEdit = 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(); + // + // buttonUpdate + // + this.buttonUpdate.Location = new System.Drawing.Point(521, 290); + this.buttonUpdate.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonUpdate.Name = "buttonUpdate"; + this.buttonUpdate.Size = new System.Drawing.Size(133, 41); + this.buttonUpdate.TabIndex = 14; + this.buttonUpdate.Text = "Обновить"; + this.buttonUpdate.UseVisualStyleBackColor = true; + this.buttonUpdate.Click += new System.EventHandler(this.buttonUpdate_Click); + // + // buttonDelete + // + this.buttonDelete.Location = new System.Drawing.Point(521, 93); + this.buttonDelete.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonDelete.Name = "buttonDelete"; + this.buttonDelete.Size = new System.Drawing.Size(133, 37); + this.buttonDelete.TabIndex = 13; + this.buttonDelete.Text = "Удалить"; + this.buttonDelete.UseVisualStyleBackColor = true; + this.buttonDelete.Click += new System.EventHandler(this.buttonDelete_Click); + // + // buttonEdit + // + this.buttonEdit.Location = new System.Drawing.Point(521, 52); + this.buttonEdit.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonEdit.Name = "buttonEdit"; + this.buttonEdit.Size = new System.Drawing.Size(133, 37); + this.buttonEdit.TabIndex = 12; + this.buttonEdit.Text = "Изменить"; + this.buttonEdit.UseVisualStyleBackColor = true; + this.buttonEdit.Click += new System.EventHandler(this.buttonEdit_Click); + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(521, 11); + this.buttonAdd.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(133, 37); + this.buttonAdd.TabIndex = 11; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.buttonAdd_Click); + // + // dataGridView + // + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(12, 11); + this.dataGridView.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(491, 320); + this.dataGridView.TabIndex = 10; + // + // FormShops + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(670, 346); + this.Controls.Add(this.buttonUpdate); + this.Controls.Add(this.buttonDelete); + this.Controls.Add(this.buttonEdit); + this.Controls.Add(this.buttonAdd); + this.Controls.Add(this.dataGridView); + this.Name = "FormShops"; + this.Text = "Магазины"; + this.Load += new System.EventHandler(this.FormShops_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private Button buttonUpdate; + private Button buttonDelete; + private Button buttonEdit; + private Button buttonAdd; + private DataGridView dataGridView; + } +} \ No newline at end of file diff --git a/IceCreamShop/IceCreamShop/FormShops.cs b/IceCreamShop/IceCreamShop/FormShops.cs new file mode 100644 index 0000000..8560cca --- /dev/null +++ b/IceCreamShop/IceCreamShop/FormShops.cs @@ -0,0 +1,122 @@ +using IceCreamShopContracts.BusinessLogicsContracts; +using IceCreamShopContracts.BindingModels; +using IceCreamShop; +using Microsoft.Extensions.Logging; +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; + +namespace IceCreamShopView +{ + 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["Name"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["ShopIceCreams"].Visible = false; + } + + _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 buttonEdit_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 buttonDelete_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 buttonUpdate_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/IceCreamShop/IceCreamShop/FormShops.resx b/IceCreamShop/IceCreamShop/FormShops.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/IceCreamShop/IceCreamShop/FormShops.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/IceCreamShop/IceCreamShop/Program.cs b/IceCreamShop/IceCreamShop/Program.cs index 24dcf8a..3a34ee4 100644 --- a/IceCreamShop/IceCreamShop/Program.cs +++ b/IceCreamShop/IceCreamShop/Program.cs @@ -6,7 +6,6 @@ using IceCreamShopView; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using NLog.Extensions.Logging; -using IceCreamShopBusinessLogic.BusinessLogics; namespace IceCreamShop { @@ -40,9 +39,11 @@ namespace IceCreamShop services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -50,6 +51,9 @@ namespace IceCreamShop services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file diff --git a/IceCreamShop/IceCreamShopContracts/BindingModels/ShopBindingModel.cs b/IceCreamShop/IceCreamShopContracts/BindingModels/ShopBindingModel.cs new file mode 100644 index 0000000..25ccc61 --- /dev/null +++ b/IceCreamShop/IceCreamShopContracts/BindingModels/ShopBindingModel.cs @@ -0,0 +1,21 @@ +using AbstractIceCreamShopDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace IceCreamShopContracts.BindingModels +{ + public class ShopBindingModel : IShopModel + { + public int Id { get; set; } + public string Name { get; set; } = string.Empty; + + public string Adress { get; set; } = string.Empty; + + public DateTime OpeningDate { get; set; } + + public Dictionary ShopIceCreams { get; set; } = new(); + } +} diff --git a/IceCreamShop/IceCreamShopContracts/BusinessLogicsContracts/IShopLogic.cs b/IceCreamShop/IceCreamShopContracts/BusinessLogicsContracts/IShopLogic.cs new file mode 100644 index 0000000..364f97e --- /dev/null +++ b/IceCreamShop/IceCreamShopContracts/BusinessLogicsContracts/IShopLogic.cs @@ -0,0 +1,22 @@ +using IceCreamShopContracts.BindingModels; +using IceCreamShopContracts.SearchModels; +using IceCreamShopContracts.ViewModels; +using AbstractIceCreamShopDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace IceCreamShopContracts.BusinessLogicsContracts +{ + public interface IShopLogic + { + ShopViewModel? ReadElement(ShopSearchModel model); + List? ReadList(ShopSearchModel? model); + bool Create(ShopBindingModel model); + bool Update(ShopBindingModel model); + bool Delete(ShopBindingModel model); + bool SupplyIceCreams(ShopSearchModel model, IIceCreamModel iceCream, int count); + } +} diff --git a/IceCreamShop/IceCreamShopContracts/SearchModels/ShopSearchModel.cs b/IceCreamShop/IceCreamShopContracts/SearchModels/ShopSearchModel.cs new file mode 100644 index 0000000..3761e44 --- /dev/null +++ b/IceCreamShop/IceCreamShopContracts/SearchModels/ShopSearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace IceCreamShopContracts.SearchModels +{ + public class ShopSearchModel + { + public int? Id { get; set; } + public string? Name { get; set; } + } +} diff --git a/IceCreamShop/IceCreamShopContracts/StoragesContracts/IShopStorage.cs b/IceCreamShop/IceCreamShopContracts/StoragesContracts/IShopStorage.cs new file mode 100644 index 0000000..48fb1c9 --- /dev/null +++ b/IceCreamShop/IceCreamShopContracts/StoragesContracts/IShopStorage.cs @@ -0,0 +1,21 @@ +using IceCreamShopContracts.BindingModels; +using IceCreamShopContracts.SearchModels; +using IceCreamShopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace IceCreamShopContracts.StoragesContracts +{ + public interface IShopStorage + { + ShopViewModel? GetElement(ShopSearchModel model); + List GetFullList(); + List GetFilteredList(ShopSearchModel model); + ShopViewModel? Insert(ShopBindingModel model); + ShopViewModel? Update(ShopBindingModel model); + ShopViewModel? Delete(ShopBindingModel model); + } +} diff --git a/IceCreamShop/IceCreamShopContracts/ViewModels/ShopViewModel.cs b/IceCreamShop/IceCreamShopContracts/ViewModels/ShopViewModel.cs new file mode 100644 index 0000000..0347c63 --- /dev/null +++ b/IceCreamShop/IceCreamShopContracts/ViewModels/ShopViewModel.cs @@ -0,0 +1,23 @@ +using AbstractIceCreamShopDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace IceCreamShopContracts.ViewModels +{ + public class ShopViewModel : IShopModel + { + public int Id { get; set; } + [DisplayName("Название магазина")] + public string Name { get; set; } = string.Empty; + [DisplayName("Адрес")] + public string Adress { get; set; } = string.Empty; + [DisplayName("Дата открытия")] + public DateTime OpeningDate { get; set; } + + public Dictionary ShopIceCreams { get; set; } = new(); + } +} diff --git a/IceCreamShop/IceCreamShopDataModels/Models/IShopModel.cs b/IceCreamShop/IceCreamShopDataModels/Models/IShopModel.cs new file mode 100644 index 0000000..402a3fd --- /dev/null +++ b/IceCreamShop/IceCreamShopDataModels/Models/IShopModel.cs @@ -0,0 +1,18 @@ +using AbstractIceCreamShopDataModels.Models; +using AbstractIceCreamShopDataModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractIceCreamShopDataModels.Models +{ + public interface IShopModel : IId + { + String Name { get; } + String Adress { get; } + DateTime OpeningDate { get; } + Dictionary ShopIceCreams { get; } + } +} diff --git a/IceCreamShop/IceCreamShopListImplement/DataListSingleton.cs b/IceCreamShop/IceCreamShopListImplement/DataListSingleton.cs index 21ea776..33ef215 100644 --- a/IceCreamShop/IceCreamShopListImplement/DataListSingleton.cs +++ b/IceCreamShop/IceCreamShopListImplement/DataListSingleton.cs @@ -13,11 +13,13 @@ namespace IceCreamShopListImplement public List Components { get; set; } public List Orders { get; set; } public List iceCreams { get; set; } + public List Shops { get; set; } private DataListSingleton() { Components = new List(); Orders = new List(); iceCreams = new List(); + Shops = new List(); } public static DataListSingleton GetInstance() { diff --git a/IceCreamShop/IceCreamShopListImplement/Implements/ShopStorage.cs b/IceCreamShop/IceCreamShopListImplement/Implements/ShopStorage.cs new file mode 100644 index 0000000..c25a24c --- /dev/null +++ b/IceCreamShop/IceCreamShopListImplement/Implements/ShopStorage.cs @@ -0,0 +1,118 @@ +using IceCreamShopContracts.BindingModels; +using IceCreamShopContracts.SearchModels; +using IceCreamShopContracts.StoragesContracts; +using IceCreamShopContracts.ViewModels; +using IceCreamShopListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace IceCreamShopListImplement.Implements +{ + public class ShopStorage : IShopStorage + { + private readonly DataListSingleton _source; + + public ShopStorage() + { + _source = DataListSingleton.GetInstance(); + } + + public ShopViewModel? GetElement(ShopSearchModel model) + { + if (string.IsNullOrEmpty(model.Name) && !model.Id.HasValue) + { + return null; + } + foreach (var shop in _source.Shops) + { + if ((!string.IsNullOrEmpty(model.Name) && shop.Name == model.Name) || (model.Id.HasValue && shop.Id == model.Id)) + { + return shop.GetViewModel; + } + } + + return null; + } + + public List GetFilteredList(ShopSearchModel model) + { + var result = new List(); + + if (string.IsNullOrEmpty(model.Name)) + { + return result; + } + foreach (var shop in _source.Shops) + { + if (shop.Name.Contains(model.Name)) + { + result.Add(shop.GetViewModel); + } + } + return result; + } + + public List GetFullList() + { + var result = new List(); + foreach (var shop in _source.Shops) + { + result.Add(shop.GetViewModel); + } + return result; + } + + 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 == 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 element = _source.Shops[i]; + _source.Shops.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + } +} diff --git a/IceCreamShop/IceCreamShopListImplement/Models/Shop.cs b/IceCreamShop/IceCreamShopListImplement/Models/Shop.cs new file mode 100644 index 0000000..78d98e9 --- /dev/null +++ b/IceCreamShop/IceCreamShopListImplement/Models/Shop.cs @@ -0,0 +1,61 @@ +using AbstractIceCreamShopDataModels.Models; +using IceCreamShopContracts.BindingModels; +using IceCreamShopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace IceCreamShopListImplement.Models +{ + public class Shop : IShopModel + { + public int Id { get; private set; } + + public string Name { get; private set; } = string.Empty; + + public string Adress { get; private set; } = string.Empty; + + public DateTime OpeningDate { get; private set; } + + public Dictionary ShopIceCreams { get; private set; } = new(); + + public static Shop? Create(ShopBindingModel model) + { + if (model == null) + { + return null; + } + return new Shop() + { + Id = model.Id, + Name = model.Name, + Adress = model.Adress, + OpeningDate = model.OpeningDate, + ShopIceCreams = new() + }; + } + + public void Update(ShopBindingModel? model) + { + if (model == null) + { + return; + } + Name = model.Name; + Adress = model.Adress; + OpeningDate = model.OpeningDate; + ShopIceCreams = model.ShopIceCreams; + } + + public ShopViewModel GetViewModel => new() + { + Id = Id, + Name = Name, + Adress = Adress, + OpeningDate = OpeningDate, + ShopIceCreams = ShopIceCreams + }; + } +}