From 9b4045dc16a6dcdb5ead0131ea66fb9d44d72842 Mon Sep 17 00:00:00 2001 From: bekodeg Date: Wed, 14 Feb 2024 09:58:18 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BD=D0=B5=D0=B1=D0=BE=D0=BB=D1=8C=D1=88?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Forms/FormCreateOrder.Designer.cs | 2 +- .../SushiBar/Forms/FormCreateOrderLogic.cs | 17 ++- SushiBar/SushiBar/Forms/FormMain.Designer.cs | 37 ++++-- SushiBar/SushiBar/Forms/FormMain.cs | 10 ++ SushiBar/SushiBar/Forms/FormMainLogic.cs | 28 +++- .../SushiBar/Forms/FormSushis.Designer.cs | 114 +++++++++++++++++ SushiBar/SushiBar/Forms/FormSushis.cs | 35 +++++ SushiBar/SushiBar/Forms/FormSushis.resx | 120 ++++++++++++++++++ SushiBar/SushiBar/Forms/FormSushisLogic.cs | 105 +++++++++++++++ SushiBar/SushiBar/Program.cs | 2 + .../DataListSingleton.cs | 2 +- .../Implements/ComponentStorage.cs | 2 +- .../Implements/OrderStorage.cs | 2 +- .../Implements/SushiStorage.cs | 2 +- 14 files changed, 459 insertions(+), 19 deletions(-) create mode 100644 SushiBar/SushiBar/Forms/FormSushis.Designer.cs create mode 100644 SushiBar/SushiBar/Forms/FormSushis.cs create mode 100644 SushiBar/SushiBar/Forms/FormSushis.resx create mode 100644 SushiBar/SushiBar/Forms/FormSushisLogic.cs diff --git a/SushiBar/SushiBar/Forms/FormCreateOrder.Designer.cs b/SushiBar/SushiBar/Forms/FormCreateOrder.Designer.cs index 8078759..becf85e 100644 --- a/SushiBar/SushiBar/Forms/FormCreateOrder.Designer.cs +++ b/SushiBar/SushiBar/Forms/FormCreateOrder.Designer.cs @@ -122,7 +122,7 @@ Controls.Add(buttonCancel); Controls.Add(buttonSave); Name = "FormCreateOrder"; - Text = "FormCreateOrder"; + Text = "Заказ"; ResumeLayout(false); PerformLayout(); } diff --git a/SushiBar/SushiBar/Forms/FormCreateOrderLogic.cs b/SushiBar/SushiBar/Forms/FormCreateOrderLogic.cs index 35bc1e7..e9c9c0b 100644 --- a/SushiBar/SushiBar/Forms/FormCreateOrderLogic.cs +++ b/SushiBar/SushiBar/Forms/FormCreateOrderLogic.cs @@ -7,6 +7,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Windows.Forms; namespace SushiBar.Forms { @@ -24,8 +25,20 @@ namespace SushiBar.Forms } private void FormCreateOrder_Load(object sender, EventArgs e) { - _logger.LogInformation("Загрузка изделий для заказа"); - // прописать логику + try + { + var list = _logicS.ReadList(null); + if (list != null) + { + comboBoxSushi.Items.AddRange(list.ToArray()); + } + _logger.LogInformation("Загрузка суши для заказа"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки суши"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } } private void CalcSum() { diff --git a/SushiBar/SushiBar/Forms/FormMain.Designer.cs b/SushiBar/SushiBar/Forms/FormMain.Designer.cs index dbfe99d..1de243a 100644 --- a/SushiBar/SushiBar/Forms/FormMain.Designer.cs +++ b/SushiBar/SushiBar/Forms/FormMain.Designer.cs @@ -30,7 +30,9 @@ { dataGridView = new DataGridView(); menuStrip1 = new MenuStrip(); - SushiToolStripMenuItem = new ToolStripMenuItem(); + ToolStripMenuItem = new ToolStripMenuItem(); + sushiToolStripMenuItem = new ToolStripMenuItem(); + componentsToolStripMenuItem = new ToolStripMenuItem(); buttonCreateOrder = new Button(); buttonTakeOrderInWork = new Button(); buttonOrderReady = new Button(); @@ -53,19 +55,33 @@ // menuStrip1 // menuStrip1.ImageScalingSize = new Size(20, 20); - menuStrip1.Items.AddRange(new ToolStripItem[] { SushiToolStripMenuItem }); + menuStrip1.Items.AddRange(new ToolStripItem[] { ToolStripMenuItem }); menuStrip1.Location = new Point(0, 0); menuStrip1.Name = "menuStrip1"; menuStrip1.Size = new Size(1190, 28); menuStrip1.TabIndex = 1; menuStrip1.Text = "menuStrip1"; // - // SushiToolStripMenuItem + // ToolStripMenuItem // - SushiToolStripMenuItem.Name = "SushiToolStripMenuItem"; - SushiToolStripMenuItem.Size = new Size(117, 24); - SushiToolStripMenuItem.Text = "Справочники"; - SushiToolStripMenuItem.Click += SushiToolStripMenuItem_Click; + ToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { sushiToolStripMenuItem, componentsToolStripMenuItem }); + ToolStripMenuItem.Name = "ToolStripMenuItem"; + ToolStripMenuItem.Size = new Size(117, 24); + ToolStripMenuItem.Text = "Справочники"; + // + // sushiToolStripMenuItem + // + sushiToolStripMenuItem.Name = "sushiToolStripMenuItem"; + sushiToolStripMenuItem.Size = new Size(224, 26); + sushiToolStripMenuItem.Text = "Суши"; + sushiToolStripMenuItem.Click += sushiToolStripMenuItem_Click; + // + // componentsToolStripMenuItem + // + componentsToolStripMenuItem.Name = "componentsToolStripMenuItem"; + componentsToolStripMenuItem.Size = new Size(224, 26); + componentsToolStripMenuItem.Text = "Компоненты"; + componentsToolStripMenuItem.Click += componentsToolStripMenuItem_Click; // // buttonCreateOrder // @@ -131,7 +147,7 @@ Controls.Add(menuStrip1); MainMenuStrip = menuStrip1; Name = "FormMain"; - Text = "FormMain"; + Text = "Сушибар"; ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); menuStrip1.ResumeLayout(false); menuStrip1.PerformLayout(); @@ -149,5 +165,10 @@ private Button buttonOrderReady; private Button buttonIssuedOrder; private Button buttonRef; + private ToolStripMenuItem сушиToolStripMenuItem; + private ToolStripMenuItem компонентыToolStripMenuItem; + private ToolStripMenuItem ToolStripMenuItem; + private ToolStripMenuItem sushiToolStripMenuItem; + private ToolStripMenuItem componentsToolStripMenuItem; } } \ No newline at end of file diff --git a/SushiBar/SushiBar/Forms/FormMain.cs b/SushiBar/SushiBar/Forms/FormMain.cs index 101beb2..f9a5708 100644 --- a/SushiBar/SushiBar/Forms/FormMain.cs +++ b/SushiBar/SushiBar/Forms/FormMain.cs @@ -26,5 +26,15 @@ { ButtonRef_Click(sender, e); } + + private void sushiToolStripMenuItem_Click(object sender, EventArgs e) + { + SushiToolStripMenuItem_Click(sender, e); + } + + private void componentsToolStripMenuItem_Click(object sender, EventArgs e) + { + ComponentsToolStripMenuItem_Click(sender, e); + } } } diff --git a/SushiBar/SushiBar/Forms/FormMainLogic.cs b/SushiBar/SushiBar/Forms/FormMainLogic.cs index cfb0a01..bc3e58a 100644 --- a/SushiBar/SushiBar/Forms/FormMainLogic.cs +++ b/SushiBar/SushiBar/Forms/FormMainLogic.cs @@ -1,4 +1,5 @@ using Microsoft.Extensions.Logging; +using SushiBarBusinessLogic.BusinessLogics; using SushiBarContracts.BindingModels; using SushiBarContracts.BusinessLogicsContracts; using SushiView; @@ -22,10 +23,25 @@ namespace SushiBar.Forms } private void LoadData() { - _logger.LogInformation("Загрузка заказов"); - // прописать логику + try + { + var list = _orderLogic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["SushiId"].Visible = false; + dataGridView.Columns["SushiName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка заказов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки суши"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } } - private void КомпонентыToolStripMenuItem_Click(object sender, EventArgs + private void ComponentsToolStripMenuItem_Click(object sender, EventArgs e) { var service = Program.ServiceProvider?.GetService(typeof(FormComponents)); @@ -36,7 +52,11 @@ namespace SushiBar.Forms } private void SushiToolStripMenuItem_Click(object sender, EventArgs e) { - // прописать логику + var service = Program.ServiceProvider?.GetService(typeof(FormSushis)); + if (service is FormSushis form) + { + form.ShowDialog(); + } } private void ButtonCreateOrder_Click(object sender, EventArgs e) { diff --git a/SushiBar/SushiBar/Forms/FormSushis.Designer.cs b/SushiBar/SushiBar/Forms/FormSushis.Designer.cs new file mode 100644 index 0000000..cb77827 --- /dev/null +++ b/SushiBar/SushiBar/Forms/FormSushis.Designer.cs @@ -0,0 +1,114 @@ +namespace SushiBar.Forms +{ + partial class FormSushis + { + /// + /// 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() + { + dataGridView = new DataGridView(); + buttonRef = new Button(); + buttonDel = new Button(); + buttonUpd = new Button(); + buttonAdd = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Dock = DockStyle.Left; + dataGridView.Location = new Point(0, 0); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 29; + dataGridView.Size = new Size(668, 450); + dataGridView.TabIndex = 1; + // + // buttonRef + // + buttonRef.Location = new Point(674, 117); + buttonRef.Name = "buttonRef"; + buttonRef.Size = new Size(114, 29); + buttonRef.TabIndex = 8; + buttonRef.Text = "Обновить"; + buttonRef.UseVisualStyleBackColor = true; + buttonRef.Click += buttonRef_Click; + // + // buttonDel + // + buttonDel.Location = new Point(674, 82); + buttonDel.Name = "buttonDel"; + buttonDel.Size = new Size(114, 29); + buttonDel.TabIndex = 7; + buttonDel.Text = "Удалить"; + buttonDel.UseVisualStyleBackColor = true; + buttonDel.Click += buttonDel_Click; + // + // buttonUpd + // + buttonUpd.Location = new Point(674, 47); + buttonUpd.Name = "buttonUpd"; + buttonUpd.Size = new Size(114, 29); + buttonUpd.TabIndex = 6; + buttonUpd.Text = "Изменить"; + buttonUpd.UseVisualStyleBackColor = true; + buttonUpd.Click += buttonUpd_Click; + // + // buttonAdd + // + buttonAdd.Location = new Point(674, 12); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(114, 29); + buttonAdd.TabIndex = 5; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += buttonAdd_Click; + // + // FormSushis + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(buttonRef); + Controls.Add(buttonDel); + Controls.Add(buttonUpd); + Controls.Add(buttonAdd); + Controls.Add(dataGridView); + Name = "FormSushis"; + Text = "Суши"; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridView; + private Button buttonRef; + private Button buttonDel; + private Button buttonUpd; + private Button buttonAdd; + } +} \ No newline at end of file diff --git a/SushiBar/SushiBar/Forms/FormSushis.cs b/SushiBar/SushiBar/Forms/FormSushis.cs new file mode 100644 index 0000000..6a12f95 --- /dev/null +++ b/SushiBar/SushiBar/Forms/FormSushis.cs @@ -0,0 +1,35 @@ +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 SushiBar.Forms +{ + public partial class FormSushis + { + private void buttonAdd_Click(object sender, EventArgs e) + { + ButtonAdd_Click(sender, e); + } + + private void buttonUpd_Click(object sender, EventArgs e) + { + ButtonUpd_Click(sender, e); + } + + private void buttonDel_Click(object sender, EventArgs e) + { + ButtonDel_Click(sender, e); + } + + private void buttonRef_Click(object sender, EventArgs e) + { + ButtonRef_Click(sender, e); + } + } +} diff --git a/SushiBar/SushiBar/Forms/FormSushis.resx b/SushiBar/SushiBar/Forms/FormSushis.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/SushiBar/SushiBar/Forms/FormSushis.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/SushiBar/Forms/FormSushisLogic.cs b/SushiBar/SushiBar/Forms/FormSushisLogic.cs new file mode 100644 index 0000000..1b789c3 --- /dev/null +++ b/SushiBar/SushiBar/Forms/FormSushisLogic.cs @@ -0,0 +1,105 @@ +using Microsoft.Extensions.Logging; +using SushiBarContracts.BindingModels; +using SushiBarContracts.BusinessLogicsContracts; +using SushiView; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace SushiBar.Forms +{ + public partial class FormSushis : Form + { + private readonly ILogger _logger; + private readonly ISushiLogic _logic; + public FormSushis(ILogger logger, ISushiLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + private void FormSushis_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["SushiName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка суши"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки суши"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormSushi)); + if (service is FormSushi form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + private void ButtonUpd_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormSushi)); + if (service is FormSushi form) + { + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + private void ButtonDel_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Удаление компонента"); + try + { + if (!_logic.Delete(new SushiBindingModel + { + Id = id + })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления компонента"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/SushiBar/SushiBar/Program.cs b/SushiBar/SushiBar/Program.cs index 7013d20..74ce596 100644 --- a/SushiBar/SushiBar/Program.cs +++ b/SushiBar/SushiBar/Program.cs @@ -26,6 +26,8 @@ namespace SushiView ConfigureServices(services); _serviceProvider = services.BuildServiceProvider(); + ILogger logger = _serviceProvider.GetService(); + Application.Run(_serviceProvider.GetRequiredService()); } private static void ConfigureServices(ServiceCollection services) diff --git a/SushiBar/SushiBarListImplement/DataListSingleton.cs b/SushiBar/SushiBarListImplement/DataListSingleton.cs index c02c6c7..3df79fa 100644 --- a/SushiBar/SushiBarListImplement/DataListSingleton.cs +++ b/SushiBar/SushiBarListImplement/DataListSingleton.cs @@ -15,7 +15,7 @@ namespace SushiBarListImplement Sushis = new List(); } - public static DataListSingleton GetInsance() + public static DataListSingleton GetInstance() { if (_instance == null) { diff --git a/SushiBar/SushiBarListImplement/Implements/ComponentStorage.cs b/SushiBar/SushiBarListImplement/Implements/ComponentStorage.cs index e242577..1fea2c0 100644 --- a/SushiBar/SushiBarListImplement/Implements/ComponentStorage.cs +++ b/SushiBar/SushiBarListImplement/Implements/ComponentStorage.cs @@ -11,7 +11,7 @@ namespace SushiBarListImplement.Implements private readonly DataListSingleton _source; public ComponentStorage() { - _source = DataListSingleton.GetInsance(); + _source = DataListSingleton.GetInstance(); } public List GetFullList() { diff --git a/SushiBar/SushiBarListImplement/Implements/OrderStorage.cs b/SushiBar/SushiBarListImplement/Implements/OrderStorage.cs index 6635a4d..2aeb437 100644 --- a/SushiBar/SushiBarListImplement/Implements/OrderStorage.cs +++ b/SushiBar/SushiBarListImplement/Implements/OrderStorage.cs @@ -11,7 +11,7 @@ namespace SushiBarListImplement.Implements private readonly DataListSingleton _source; public OrderStorage() { - _source = DataListSingleton.GetInsance(); + _source = DataListSingleton.GetInstance(); } public List GetFullList() { diff --git a/SushiBar/SushiBarListImplement/Implements/SushiStorage.cs b/SushiBar/SushiBarListImplement/Implements/SushiStorage.cs index 7ed32ac..4e2454f 100644 --- a/SushiBar/SushiBarListImplement/Implements/SushiStorage.cs +++ b/SushiBar/SushiBarListImplement/Implements/SushiStorage.cs @@ -11,7 +11,7 @@ namespace SushiBarListImplement.Implements private readonly DataListSingleton _source; public SushiStorage() { - _source = DataListSingleton.GetInsance(); + _source = DataListSingleton.GetInstance(); } public List GetFullList() {