diff --git a/SushiBar/FormMain.Designer.cs b/SushiBar/FormMain.Designer.cs index dc347ef..070b5ab 100644 --- a/SushiBar/FormMain.Designer.cs +++ b/SushiBar/FormMain.Designer.cs @@ -32,13 +32,14 @@ ToolStripMenuItemRef = new ToolStripMenuItem(); компонентыToolStripMenuItem = new ToolStripMenuItem(); сушиToolStripMenuItem = new ToolStripMenuItem(); + магазиныToolStripMenuItem = new ToolStripMenuItem(); dataGridView = new DataGridView(); buttonCreateOrder = new Button(); buttonTakeOrderInWork = new Button(); buttonOrderReady = new Button(); buttonOrderIssued = new Button(); buttonRefreshOrders = new Button(); - магазиныToolStripMenuItem = new ToolStripMenuItem(); + buttonAddSushiInShop = new Button(); menuStrip1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); SuspendLayout(); @@ -63,17 +64,24 @@ // компонентыToolStripMenuItem // компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem"; - компонентыToolStripMenuItem.Size = new Size(224, 26); + компонентыToolStripMenuItem.Size = new Size(182, 26); компонентыToolStripMenuItem.Text = "Компоненты"; компонентыToolStripMenuItem.Click += компонентыToolStripMenuItem_Click; // // сушиToolStripMenuItem // сушиToolStripMenuItem.Name = "сушиToolStripMenuItem"; - сушиToolStripMenuItem.Size = new Size(224, 26); + сушиToolStripMenuItem.Size = new Size(182, 26); сушиToolStripMenuItem.Text = "Суши"; сушиToolStripMenuItem.Click += сушиToolStripMenuItem_Click; // + // магазиныToolStripMenuItem + // + магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem"; + магазиныToolStripMenuItem.Size = new Size(182, 26); + магазиныToolStripMenuItem.Text = "Магазины"; + магазиныToolStripMenuItem.Click += магазиныToolStripMenuItem_Click; + // // dataGridView // dataGridView.BackgroundColor = Color.White; @@ -88,7 +96,7 @@ // // buttonCreateOrder // - buttonCreateOrder.Location = new Point(923, 63); + buttonCreateOrder.Location = new Point(923, 43); buttonCreateOrder.Name = "buttonCreateOrder"; buttonCreateOrder.Size = new Size(171, 52); buttonCreateOrder.TabIndex = 2; @@ -98,7 +106,7 @@ // // buttonTakeOrderInWork // - buttonTakeOrderInWork.Location = new Point(923, 161); + buttonTakeOrderInWork.Location = new Point(923, 118); buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; buttonTakeOrderInWork.Size = new Size(171, 52); buttonTakeOrderInWork.TabIndex = 3; @@ -108,7 +116,7 @@ // // buttonOrderReady // - buttonOrderReady.Location = new Point(923, 253); + buttonOrderReady.Location = new Point(923, 191); buttonOrderReady.Name = "buttonOrderReady"; buttonOrderReady.Size = new Size(171, 52); buttonOrderReady.TabIndex = 4; @@ -118,7 +126,7 @@ // // buttonOrderIssued // - buttonOrderIssued.Location = new Point(923, 351); + buttonOrderIssued.Location = new Point(923, 264); buttonOrderIssued.Name = "buttonOrderIssued"; buttonOrderIssued.Size = new Size(171, 52); buttonOrderIssued.TabIndex = 5; @@ -135,12 +143,15 @@ buttonRefreshOrders.Text = "Обновить заказы"; buttonRefreshOrders.UseVisualStyleBackColor = true; // - // магазиныToolStripMenuItem + // buttonAddSushiInShop // - магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem"; - магазиныToolStripMenuItem.Size = new Size(224, 26); - магазиныToolStripMenuItem.Text = "Магазины"; - магазиныToolStripMenuItem.Click += магазиныToolStripMenuItem_Click; + buttonAddSushiInShop.Location = new Point(923, 359); + buttonAddSushiInShop.Name = "buttonAddSushiInShop"; + buttonAddSushiInShop.Size = new Size(171, 52); + buttonAddSushiInShop.TabIndex = 7; + buttonAddSushiInShop.Text = "Пополнить магазин"; + buttonAddSushiInShop.UseVisualStyleBackColor = true; + buttonAddSushiInShop.Click += buttonAddSushiInShop_Click; // // FormMain // @@ -148,6 +159,7 @@ AutoScaleMode = AutoScaleMode.Font; BackColor = Color.FromArgb(210, 255, 210); ClientSize = new Size(1140, 540); + Controls.Add(buttonAddSushiInShop); Controls.Add(buttonRefreshOrders); Controls.Add(buttonOrderIssued); Controls.Add(buttonOrderReady); @@ -179,5 +191,6 @@ private ToolStripMenuItem компонентыToolStripMenuItem; private ToolStripMenuItem сушиToolStripMenuItem; private ToolStripMenuItem магазиныToolStripMenuItem; + private Button buttonAddSushiInShop; } } \ No newline at end of file diff --git a/SushiBar/FormMain.cs b/SushiBar/FormMain.cs index b19cfd7..d6d9980 100644 --- a/SushiBar/FormMain.cs +++ b/SushiBar/FormMain.cs @@ -68,7 +68,7 @@ namespace SushiBarView private void магазиныToolStripMenuItem_Click(object sender, EventArgs e) { var service = Program.ServiceProvider?.GetService(typeof(FormShops)); - if(service is FormShops formShops) { formShops.ShowDialog(); } + if (service is FormShops formShops) { formShops.ShowDialog(); } } private void buttonCreateOrder_Click(object sender, EventArgs e) @@ -155,5 +155,14 @@ namespace SushiBarView { LoadData(); } + + private void buttonAddSushiInShop_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormAddSushiInShop)); + if (service is FormAddSushiInShop form) + { + form.ShowDialog(); + } + } } } diff --git a/SushiBar/Program.cs b/SushiBar/Program.cs index a973c59..ece830d 100644 --- a/SushiBar/Program.cs +++ b/SushiBar/Program.cs @@ -1,6 +1,7 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using NLog.Extensions.Logging; +using SushiBarBusinessLogic; using SushiBarBusinessLogic.BusinessLogic; using SushiBarContracts.BusinessLogicsContracts; using SushiBarContracts.StoragesContracts; @@ -29,7 +30,6 @@ namespace SushiBar ConfigureServices(services); _serviceProvider = services.BuildServiceProvider(); Application.Run(_serviceProvider.GetRequiredService()); - //Application.Run(new Form1()); } private static void ConfigureServices(ServiceCollection services) @@ -42,9 +42,13 @@ namespace SushiBar services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -54,6 +58,7 @@ namespace SushiBar services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file diff --git a/SushiBar/Shops/FormAddSushiInShop.Designer.cs b/SushiBar/Shops/FormAddSushiInShop.Designer.cs new file mode 100644 index 0000000..84dd31f --- /dev/null +++ b/SushiBar/Shops/FormAddSushiInShop.Designer.cs @@ -0,0 +1,149 @@ +namespace SushiBarView.Shops +{ + partial class FormAddSushiInShop + { + /// + /// 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() + { + comboBoxSushi = new ComboBox(); + labelSushi = new Label(); + labelShop = new Label(); + comboBoxShop = new ComboBox(); + textBoxCount = new TextBox(); + labelCount = new Label(); + buttonSave = new Button(); + buttonCancel = new Button(); + SuspendLayout(); + // + // comboBoxSushi + // + comboBoxSushi.FormattingEnabled = true; + comboBoxSushi.Location = new Point(212, 49); + comboBoxSushi.Margin = new Padding(4); + comboBoxSushi.Name = "comboBoxSushi"; + comboBoxSushi.Size = new Size(188, 30); + comboBoxSushi.TabIndex = 0; + // + // labelSushi + // + labelSushi.AutoSize = true; + labelSushi.Location = new Point(42, 57); + labelSushi.Margin = new Padding(4, 0, 4, 0); + labelSushi.Name = "labelSushi"; + labelSushi.Size = new Size(60, 22); + labelSushi.TabIndex = 1; + labelSushi.Text = "Суши: "; + // + // labelShop + // + labelShop.AutoSize = true; + labelShop.Location = new Point(42, 188); + labelShop.Margin = new Padding(4, 0, 4, 0); + labelShop.Name = "labelShop"; + labelShop.Size = new Size(86, 22); + labelShop.TabIndex = 3; + labelShop.Text = "Магазин: "; + // + // comboBoxShop + // + comboBoxShop.FormattingEnabled = true; + comboBoxShop.Location = new Point(212, 188); + comboBoxShop.Margin = new Padding(4); + comboBoxShop.Name = "comboBoxShop"; + comboBoxShop.Size = new Size(188, 30); + comboBoxShop.TabIndex = 2; + // + // textBoxCount + // + textBoxCount.Location = new Point(212, 118); + textBoxCount.Name = "textBoxCount"; + textBoxCount.Size = new Size(188, 29); + textBoxCount.TabIndex = 4; + // + // labelCount + // + labelCount.AutoSize = true; + labelCount.Location = new Point(42, 121); + labelCount.Margin = new Padding(4, 0, 4, 0); + labelCount.Name = "labelCount"; + labelCount.Size = new Size(154, 22); + labelCount.TabIndex = 5; + labelCount.Text = "Количество суши: "; + // + // buttonSave + // + buttonSave.Location = new Point(471, 174); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(107, 44); + buttonSave.TabIndex = 6; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(617, 174); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(107, 44); + buttonCancel.TabIndex = 7; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // FormAddSushiInShop + // + AutoScaleDimensions = new SizeF(10F, 22F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(762, 267); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(labelCount); + Controls.Add(textBoxCount); + Controls.Add(labelShop); + Controls.Add(comboBoxShop); + Controls.Add(labelSushi); + Controls.Add(comboBoxSushi); + Font = new Font("Candara", 10.8F, FontStyle.Regular, GraphicsUnit.Point, 204); + Margin = new Padding(4); + Name = "FormAddSushiInShop"; + Text = "FormAddSushiInShop"; + Load += FormAddSushiInShop_Load; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private ComboBox comboBoxSushi; + private Label labelSushi; + private Label labelShop; + private ComboBox comboBoxShop; + private TextBox textBoxCount; + private Label labelCount; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/SushiBar/Shops/FormAddSushiInShop.cs b/SushiBar/Shops/FormAddSushiInShop.cs new file mode 100644 index 0000000..0ce25db --- /dev/null +++ b/SushiBar/Shops/FormAddSushiInShop.cs @@ -0,0 +1,113 @@ +using Microsoft.Extensions.Logging; +using SushiBarContracts.BindingModel; +using SushiBarContracts.BusinessLogicsContracts; +using SushiBarContracts.SearchModel; + +namespace SushiBarView.Shops +{ + public partial class FormAddSushiInShop : Form + { + private readonly ILogger _logger; + private readonly IShopLogic _shopLogic; + private readonly ISushiLogic _sushiLogic; + + public FormAddSushiInShop(ILogger logger, IShopLogic shopLogic, ISushiLogic sushiLogic) + { + InitializeComponent(); + _logger = logger; + _shopLogic = shopLogic; + _sushiLogic = sushiLogic; + } + + private void buttonSave_Click(object sender, EventArgs e) + { + if (comboBoxShop.SelectedValue == null) + { + MessageBox.Show("Выберите магазин", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxSushi.SelectedValue == null) + { + MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Введите количество изделий", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Добавление изделия в магазин"); + + try + { + var operationResult = _shopLogic.AddSushiInShop( + new ShopSearchModel { Id = Convert.ToInt32(comboBoxShop.SelectedValue), ShopName = comboBoxShop.Text }, + new SushiBindingModel { Id = Convert.ToInt32(comboBoxSushi.SelectedValue), SushiName = comboBoxSushi.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 FormAddSushiInShop_Load(object sender, EventArgs e) + { + _logger.LogInformation("Загрузка магазинов"); + try + { + var listShops = _shopLogic.ReadList(null); + if (listShops != null) + { + comboBoxShop.DisplayMember = "ShopName"; + comboBoxShop.ValueMember = "Id"; + comboBoxShop.DataSource = listShops; + comboBoxShop.SelectedItem = null; + } + + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка магазинов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + + _logger.LogInformation("Загрузка суши"); + try + { + var list = _sushiLogic.ReadList(null); + if (list != null) + { + comboBoxSushi.DisplayMember = "SushiName"; + comboBoxSushi.ValueMember = "Id"; + comboBoxSushi.DataSource = list; + comboBoxSushi.SelectedItem = null; + } + + } + 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/SushiBar/Shops/FormAddSushiInShop.resx b/SushiBar/Shops/FormAddSushiInShop.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/SushiBar/Shops/FormAddSushiInShop.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/SushiBar/Shops/FormShop.Designer.cs b/SushiBar/Shops/FormShop.Designer.cs index f597a2e..b5c8502 100644 --- a/SushiBar/Shops/FormShop.Designer.cs +++ b/SushiBar/Shops/FormShop.Designer.cs @@ -31,55 +31,60 @@ buttonCancel = new Button(); buttonSave = new Button(); textBoxAddress = new TextBox(); - textBoxName = new TextBox(); labelAddress = new Label(); labelName = new Label(); dateTimePickerDateOpening = new DateTimePicker(); labelDateOpening = new Label(); + groupBoxComponents = new GroupBox(); + buttonRefresh = new Button(); + buttonDelete = new Button(); + buttonUpdate = new Button(); + buttonAdd = new Button(); + dataGridView = new DataGridView(); + ColumnId = new DataGridViewTextBoxColumn(); + ColumnSushiName = new DataGridViewTextBoxColumn(); + ColumnCount = new DataGridViewTextBoxColumn(); + textBoxName = new TextBox(); + groupBoxComponents.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); SuspendLayout(); // // buttonCancel // buttonCancel.Anchor = AnchorStyles.None; - buttonCancel.Location = new Point(421, 203); + buttonCancel.Location = new Point(710, 431); buttonCancel.Name = "buttonCancel"; buttonCancel.Size = new Size(116, 39); buttonCancel.TabIndex = 11; buttonCancel.Text = "Отмена"; buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; // // buttonSave // buttonSave.Anchor = AnchorStyles.None; - buttonSave.Location = new Point(182, 203); + buttonSave.Location = new Point(471, 431); buttonSave.Name = "buttonSave"; buttonSave.Size = new Size(116, 39); buttonSave.TabIndex = 10; buttonSave.Text = "Сохранить"; buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; // // textBoxAddress // textBoxAddress.Anchor = AnchorStyles.None; - textBoxAddress.Location = new Point(182, 86); + textBoxAddress.Location = new Point(124, 46); textBoxAddress.Name = "textBoxAddress"; - textBoxAddress.Size = new Size(355, 27); + textBoxAddress.Size = new Size(330, 27); textBoxAddress.TabIndex = 9; // - // textBoxName - // - textBoxName.Anchor = AnchorStyles.None; - textBoxName.Location = new Point(182, 20); - textBoxName.Name = "textBoxName"; - textBoxName.Size = new Size(355, 27); - textBoxName.TabIndex = 8; - // // labelAddress // labelAddress.Anchor = AnchorStyles.None; labelAddress.AutoSize = true; labelAddress.Font = new Font("Candara", 12F); - labelAddress.Location = new Point(34, 86); + labelAddress.Location = new Point(24, 46); labelAddress.Margin = new Padding(4, 0, 4, 0); labelAddress.Name = "labelAddress"; labelAddress.Size = new Size(63, 24); @@ -91,7 +96,7 @@ labelName.Anchor = AnchorStyles.None; labelName.AutoSize = true; labelName.Font = new Font("Candara", 12F); - labelName.Location = new Point(18, 23); + labelName.Location = new Point(24, 9); labelName.Margin = new Padding(4, 0, 4, 0); labelName.Name = "labelName"; labelName.Size = new Size(93, 24); @@ -100,7 +105,7 @@ // // dateTimePickerDateOpening // - dateTimePickerDateOpening.Location = new Point(182, 152); + dateTimePickerDateOpening.Location = new Point(471, 46); dateTimePickerDateOpening.Name = "dateTimePickerDateOpening"; dateTimePickerDateOpening.Size = new Size(355, 27); dateTimePickerDateOpening.TabIndex = 12; @@ -110,28 +115,131 @@ labelDateOpening.Anchor = AnchorStyles.None; labelDateOpening.AutoSize = true; labelDateOpening.Font = new Font("Candara", 12F); - labelDateOpening.Location = new Point(18, 155); + labelDateOpening.Location = new Point(471, 6); labelDateOpening.Margin = new Padding(4, 0, 4, 0); labelDateOpening.Name = "labelDateOpening"; labelDateOpening.Size = new Size(140, 24); labelDateOpening.TabIndex = 13; labelDateOpening.Text = "Дата открытия"; // + // groupBoxComponents + // + groupBoxComponents.Controls.Add(buttonRefresh); + groupBoxComponents.Controls.Add(buttonDelete); + groupBoxComponents.Controls.Add(buttonUpdate); + groupBoxComponents.Controls.Add(buttonAdd); + groupBoxComponents.Controls.Add(dataGridView); + groupBoxComponents.Location = new Point(11, 93); + groupBoxComponents.Margin = new Padding(2, 3, 2, 3); + groupBoxComponents.Name = "groupBoxComponents"; + groupBoxComponents.Padding = new Padding(2, 3, 2, 3); + groupBoxComponents.Size = new Size(443, 396); + groupBoxComponents.TabIndex = 18; + groupBoxComponents.TabStop = false; + // + // buttonRefresh + // + buttonRefresh.BackColor = Color.FromArgb(255, 192, 192); + buttonRefresh.Location = new Point(483, 330); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(127, 47); + buttonRefresh.TabIndex = 9; + buttonRefresh.Text = "Обновить"; + buttonRefresh.UseVisualStyleBackColor = false; + // + // buttonDelete + // + buttonDelete.BackColor = Color.FromArgb(255, 192, 192); + buttonDelete.Location = new Point(483, 228); + buttonDelete.Name = "buttonDelete"; + buttonDelete.Size = new Size(127, 47); + buttonDelete.TabIndex = 8; + buttonDelete.Text = "Удалить"; + buttonDelete.UseVisualStyleBackColor = false; + // + // buttonUpdate + // + buttonUpdate.BackColor = Color.FromArgb(255, 192, 192); + buttonUpdate.Location = new Point(483, 125); + buttonUpdate.Name = "buttonUpdate"; + buttonUpdate.Size = new Size(127, 47); + buttonUpdate.TabIndex = 7; + buttonUpdate.Text = "Изменить"; + buttonUpdate.UseVisualStyleBackColor = false; + // + // buttonAdd + // + buttonAdd.BackColor = Color.FromArgb(255, 192, 192); + buttonAdd.Location = new Point(483, 27); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(127, 47); + buttonAdd.TabIndex = 6; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = false; + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToResizeRows = false; + dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridView.BackgroundColor = Color.FromArgb(255, 192, 192); + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Columns.AddRange(new DataGridViewColumn[] { ColumnId, ColumnSushiName, ColumnCount }); + dataGridView.Location = new Point(13, 27); + dataGridView.Margin = new Padding(2, 3, 2, 3); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersVisible = false; + dataGridView.RowHeadersWidth = 51; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(419, 350); + dataGridView.TabIndex = 5; + // + // ColumnId + // + ColumnId.HeaderText = "id"; + ColumnId.MinimumWidth = 6; + ColumnId.Name = "ColumnId"; + ColumnId.Visible = false; + // + // ColumnSushiName + // + ColumnSushiName.HeaderText = "Название Суши"; + ColumnSushiName.MinimumWidth = 6; + ColumnSushiName.Name = "ColumnSushiName"; + // + // ColumnCount + // + ColumnCount.HeaderText = "Количество"; + ColumnCount.MinimumWidth = 6; + ColumnCount.Name = "ColumnCount"; + // + // textBoxName + // + textBoxName.Anchor = AnchorStyles.None; + textBoxName.Location = new Point(124, 6); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(330, 27); + textBoxName.TabIndex = 19; + // // FormShop // AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(571, 273); + ClientSize = new Size(849, 522); + Controls.Add(textBoxName); + Controls.Add(groupBoxComponents); Controls.Add(labelDateOpening); Controls.Add(dateTimePickerDateOpening); Controls.Add(buttonCancel); Controls.Add(buttonSave); Controls.Add(textBoxAddress); - Controls.Add(textBoxName); Controls.Add(labelAddress); Controls.Add(labelName); Name = "FormShop"; Text = "Магазин"; + Load += FormShop_Load; + groupBoxComponents.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); ResumeLayout(false); PerformLayout(); } @@ -141,10 +249,19 @@ private Button buttonCancel; private Button buttonSave; private TextBox textBoxAddress; - private TextBox textBoxName; private Label labelAddress; private Label labelName; private DateTimePicker dateTimePickerDateOpening; private Label labelDateOpening; + private GroupBox groupBoxComponents; + private Button buttonRefresh; + private Button buttonDelete; + private Button buttonUpdate; + private Button buttonAdd; + private DataGridView dataGridView; + private TextBox textBoxName; + private DataGridViewTextBoxColumn ColumnId; + private DataGridViewTextBoxColumn ColumnSushiName; + private DataGridViewTextBoxColumn ColumnCount; } } \ No newline at end of file diff --git a/SushiBar/Shops/FormShop.cs b/SushiBar/Shops/FormShop.cs index 27d8ec2..1cb7457 100644 --- a/SushiBar/Shops/FormShop.cs +++ b/SushiBar/Shops/FormShop.cs @@ -1,17 +1,9 @@ using Microsoft.Extensions.Logging; +using SushiBarContracts.BindingModel; using SushiBarContracts.BusinessLogicsContracts; using SushiBarContracts.SearchModel; using SushiBarDataModels.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 static System.Windows.Forms.VisualStyles.VisualStyleElement; namespace SushiBarView.Shops { @@ -26,7 +18,7 @@ namespace SushiBarView.Shops } private Dictionary _shopSushis; - public FormShop(ILogger logger, IShopLogic shopLogic) + public FormShop(ILogger logger, IShopLogic shopLogic) { _logger = logger; _logic = shopLogic; @@ -44,7 +36,7 @@ namespace SushiBarView.Shops var view = _logic.ReadElement(new ShopSearchModel { Id = _id.Value }); if (view != null) { - textBoxName.Text = view.Name; + textBoxName.Text = view.ShopName; textBoxAddress.Text = view.Address; dateTimePickerDateOpening.Text = view.DateOpening.ToString(); _shopSushis = view.ShopSushis ?? new Dictionary(); @@ -59,19 +51,20 @@ namespace SushiBarView.Shops } } - private void LoadData() { + private void LoadData() + { _logger.LogInformation("Загрузка изделий магазина"); try { if (_shopSushis != null) { dataGridView.Rows.Clear(); - foreach (var elem in _shopPlanes) + foreach (var elem in _shopSushis) { dataGridView.Rows.Add(new object[] { elem.Key, - elem.Value.Item1.PlaneName, + elem.Value.Item1.SushiName, elem.Value.Item2 }); } @@ -83,5 +76,51 @@ namespace SushiBarView.Shops 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($"Сохранение магазина {textBoxName.Text}"); + + try + { + var model = new ShopBindingModel + { + Id = _id ?? 0, + ShopName = textBoxName.Text, + Address = textBoxAddress.Text, + DateOpening = dateTimePickerDateOpening.Value.Date, + ShopSushis = _shopSushis + }; + 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/SushiBar/Shops/FormShop.resx b/SushiBar/Shops/FormShop.resx index af32865..4d676b5 100644 --- a/SushiBar/Shops/FormShop.resx +++ b/SushiBar/Shops/FormShop.resx @@ -117,4 +117,13 @@ 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/SushiBar/Shops/FormShops.Designer.cs b/SushiBar/Shops/FormShops.Designer.cs index d30a5f3..924eb99 100644 --- a/SushiBar/Shops/FormShops.Designer.cs +++ b/SushiBar/Shops/FormShops.Designer.cs @@ -61,6 +61,7 @@ buttonRefresh.TabIndex = 8; buttonRefresh.Text = "Обновить"; buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += buttonRefresh_Click; // // buttonRemove // @@ -71,6 +72,7 @@ buttonRemove.TabIndex = 7; buttonRemove.Text = "Удалить"; buttonRemove.UseVisualStyleBackColor = true; + buttonRemove.Click += buttonRemove_Click; // // buttonUpdate // @@ -81,6 +83,7 @@ buttonUpdate.TabIndex = 6; buttonUpdate.Text = "Изменить"; buttonUpdate.UseVisualStyleBackColor = true; + buttonUpdate.Click += buttonUpdate_Click; // // buttonAdd // @@ -106,6 +109,7 @@ Controls.Add(dataGridView); Name = "FormShops"; Text = "Магазины"; + Load += FormShops_LoadData; ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); ResumeLayout(false); } diff --git a/SushiBar/Shops/FormShops.cs b/SushiBar/Shops/FormShops.cs index b0212ad..c8f893e 100644 --- a/SushiBar/Shops/FormShops.cs +++ b/SushiBar/Shops/FormShops.cs @@ -1,4 +1,6 @@ using Microsoft.Extensions.Logging; +using SushiBar; +using SushiBarContracts.BindingModel; using SushiBarContracts.BusinessLogicsContracts; using SushiBarContracts.SearchModel; using SushiBarDataModels.Models; @@ -8,11 +10,98 @@ namespace SushiBarView.Shops { public partial class FormShops : Form { - + private readonly ILogger _logger; + private readonly IShopLogic _shopLogic; + + public FormShops(ILogger logger, IShopLogic shopLogic) + { + InitializeComponent(); + _logger = logger; + _shopLogic = shopLogic; + } + + private void FormShops_LoadData(object sender, EventArgs e) + { + LoadData(); + } 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 LoadData() + { + try + { + var list = _shopLogic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["ShopName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["ShopSushis"].Visible = false; + } + _logger.LogInformation("Загрузка магазинов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки магазинов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonUpdate_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 buttonRemove_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 (!_shopLogic.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 buttonRefresh_Click(object sender, EventArgs e) + { + LoadData(); } } } diff --git a/SushiBarBusinessLogic/ShopLogic.cs b/SushiBarBusinessLogic/ShopLogic.cs index b0fb3bf..aa57ed7 100644 --- a/SushiBarBusinessLogic/ShopLogic.cs +++ b/SushiBarBusinessLogic/ShopLogic.cs @@ -14,7 +14,7 @@ namespace SushiBarBusinessLogic private readonly ILogger _logger; private readonly IShopStorage _shopStorage; - public ShopLogic(ILogger logger, IShopStorage shopStorage) + public ShopLogic(ILogger logger, IShopStorage shopStorage) { _logger = logger; _shopStorage = shopStorage; @@ -22,7 +22,7 @@ namespace SushiBarBusinessLogic public List? ReadList(ShopSearchModel? model) { - _logger.LogInformation("ReadList. Id:{ Id}, ShopName:{ ShopName}", model?.Id, model?.Name); + _logger.LogInformation("ReadList. Id:{ Id}, ShopName:{ ShopName}", model?.Id, model?.ShopName); var list = model == null ? _shopStorage.GetFullList() : _shopStorage.GetFilteredList(model); if (list == null) { @@ -39,7 +39,7 @@ namespace SushiBarBusinessLogic { throw new ArgumentNullException(nameof(model)); } - _logger.LogInformation("ReadList. Id:{ Id}, ShopName:{ ShopName}", model.Id, model.Name); + _logger.LogInformation("ReadList. Id:{ Id}, ShopName:{ ShopName}", model.Id, model.ShopName); var element = _shopStorage.GetElement(model); if (element == null) { @@ -88,7 +88,7 @@ namespace SushiBarBusinessLogic if (model == null) throw new ArgumentNullException(nameof(model)); if(count <= 0) throw new ArgumentException(nameof(count)); - _logger.LogInformation("AddSushiInShop. ShopName:{ShopName}.Id:{ Id}", model.Name, model.Id); + _logger.LogInformation("AddSushiInShop. ShopName:{ShopName}.Id:{ Id}", model.ShopName, model.Id); var element = _shopStorage.GetElement(model); if (element == null) @@ -99,18 +99,18 @@ namespace SushiBarBusinessLogic if (element.ShopSushis.TryGetValue(sushi.Id, out var samesushi)) { element.ShopSushis[sushi.Id] = (sushi, samesushi.Item2 + count); - _logger.LogInformation("Same sushi found by supply. Added {0} of {1} in {2} shop", count, sushi.SushiName, element.Name); + _logger.LogInformation("Same sushi found by supply. Added {0} of {1} in {2} shop", count, sushi.SushiName, element.ShopName); } else { element.ShopSushis[sushi.Id] = (sushi, count); - _logger.LogInformation("New sushi added by supply. Added {0} of {1} in {2} shop", count, sushi.SushiName, element.Name); + _logger.LogInformation("New sushi added by supply. Added {0} of {1} in {2} shop", count, sushi.SushiName, element.ShopName); } _shopStorage.Update(new() { Id = element.Id, - Name = element.Name, + ShopName = element.ShopName, Address = element.Address, DateOpening = element.DateOpening, ShopSushis = element.ShopSushis @@ -124,17 +124,17 @@ namespace SushiBarBusinessLogic if(model == null) throw new ArgumentNullException($"{nameof(model)} является null"); if (!withParams) return; - if (string.IsNullOrEmpty(model.Name)) + if (string.IsNullOrEmpty(model.ShopName)) { - throw new ArgumentNullException("Нет такого магазина", nameof(model.Name)); + throw new ArgumentNullException("Нет такого магазина", nameof(model.ShopName)); } _logger.LogInformation("Shop. ShopName:{ShopName}.Address:{ Address}. Id:{ Id}", - model.Name, model.Address, model.Id); + model.ShopName, model.Address, model.Id); var element = _shopStorage.GetElement(new ShopSearchModel { - Name = model.Name, + ShopName = model.ShopName, }); - if(element != null && element.Id != model.Id && element.Name == model.Name) + if(element != null && element.Id != model.Id && element.ShopName == model.ShopName) { throw new InvalidOperationException("Такой магазин с таким названием уже есть"); } diff --git a/SushiBarContracts/BindingModel/ShopBindingModel.cs b/SushiBarContracts/BindingModel/ShopBindingModel.cs index c27c14a..ce08d0a 100644 --- a/SushiBarContracts/BindingModel/ShopBindingModel.cs +++ b/SushiBarContracts/BindingModel/ShopBindingModel.cs @@ -6,7 +6,7 @@ namespace SushiBarContracts.BindingModel public class ShopBindingModel : IShopModel { public int Id { get; set; } - public string Name { get; set; } + public string ShopName { get; set; } public string Address { get; set; } public DateTime DateOpening { get; set; } = DateTime.Now; public Dictionary ShopSushis { get; set; } = new(); diff --git a/SushiBarContracts/SearchModel/ShopSearchModel.cs b/SushiBarContracts/SearchModel/ShopSearchModel.cs index f34d7e5..e725658 100644 --- a/SushiBarContracts/SearchModel/ShopSearchModel.cs +++ b/SushiBarContracts/SearchModel/ShopSearchModel.cs @@ -3,6 +3,6 @@ public class ShopSearchModel { public int? Id { get; set; } - public string? Name { get; set; } + public string? ShopName { get; set; } } } diff --git a/SushiBarContracts/ViewModels/ShopViewModel.cs b/SushiBarContracts/ViewModels/ShopViewModel.cs index 09b0864..65f7a65 100644 --- a/SushiBarContracts/ViewModels/ShopViewModel.cs +++ b/SushiBarContracts/ViewModels/ShopViewModel.cs @@ -9,7 +9,7 @@ namespace SushiBarContracts.ViewModels public int Id { get; set; } [DisplayName("Название магазина")] - public string Name { get; set; } = string.Empty; + public string ShopName { get; set; } = string.Empty; [DisplayName("Адрес")] public string Address { get; set; } = string.Empty; diff --git a/SushiBarDataModels/IShopModel.cs b/SushiBarDataModels/IShopModel.cs index cd01a16..50200b3 100644 --- a/SushiBarDataModels/IShopModel.cs +++ b/SushiBarDataModels/IShopModel.cs @@ -4,7 +4,7 @@ namespace SushiBarDataModels { public interface IShopModel : IId { - string Name { get; } + string ShopName { get; } string Address { get; } DateTime DateOpening { get; } Dictionary ShopSushis{ get; } diff --git a/SushiBarListImplements/Implements/ShopStorage.cs b/SushiBarListImplements/Implements/ShopStorage.cs index 6320310..93cedda 100644 --- a/SushiBarListImplements/Implements/ShopStorage.cs +++ b/SushiBarListImplements/Implements/ShopStorage.cs @@ -10,7 +10,7 @@ namespace SushiBarListImplements.Implements public class ShopStorage : IShopStorage { private DataListSingleton _source; - public ShopStorage(DataListSingleton source) + public ShopStorage() { _source = DataListSingleton.GetInstance(); } @@ -28,13 +28,14 @@ namespace SushiBarListImplements.Implements public List GetFilteredList(ShopSearchModel model) { var result = new List(); - if (model == null || !model.Id.HasValue) + if (string.IsNullOrEmpty(model.ShopName)) { return result; } + foreach (var shop in _source.Shops) { - if (shop.Id == model.Id) + if (shop.ShopName.Contains(model.ShopName)) { result.Add(shop.GetViewModel); } @@ -44,13 +45,14 @@ namespace SushiBarListImplements.Implements public ShopViewModel? GetElement(ShopSearchModel model) { - if (!model.Id.HasValue) + if (string.IsNullOrEmpty(model.ShopName) && !model.Id.HasValue) { return null; } + foreach (var shop in _source.Shops) { - if (shop.Id == model.Id) + if ((!string.IsNullOrEmpty(model.ShopName) && shop.ShopName == model.ShopName) || (model.Id.HasValue && shop.Id == model.Id)) { return shop.GetViewModel; } diff --git a/SushiBarListImplements/Models/Shop.cs b/SushiBarListImplements/Models/Shop.cs index 2d034d3..28152ec 100644 --- a/SushiBarListImplements/Models/Shop.cs +++ b/SushiBarListImplements/Models/Shop.cs @@ -13,7 +13,7 @@ namespace SushiBarListImplements.Models public class Shop : IShopModel { public int Id { get; private set; } - public string Name { get; private set; } + public string ShopName { get; private set; } public string Address { get; private set; } public DateTime DateOpening { get; private set; } = DateTime.Now; public Dictionary ShopSushis @@ -28,7 +28,7 @@ namespace SushiBarListImplements.Models return new Shop() { Id = model.Id, - Name = model.Name, + ShopName = model.ShopName, Address = model.Address, DateOpening = model.DateOpening, ShopSushis = model.ShopSushis @@ -38,7 +38,7 @@ namespace SushiBarListImplements.Models public void Update(ShopBindingModel? model) { if (model == null) return; - Name = model.Name; + ShopName = model.ShopName; Address = model.Address; DateOpening = model.DateOpening; ShopSushis = model.ShopSushis; @@ -47,7 +47,7 @@ namespace SushiBarListImplements.Models public ShopViewModel GetViewModel => new() { Id = Id, - Name = Name, + ShopName = ShopName, Address = Address, DateOpening = DateOpening, ShopSushis = ShopSushis