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 + { + /// <summary> + /// Required designer variable. + /// </summary> + private System.ComponentModel.IContainer components = null; + + /// <summary> + /// Clean up any resources being used. + /// </summary> + /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// <summary> + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// </summary> + 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 @@ +<?xml version="1.0" encoding="utf-8"?> +<root> + <!-- + Microsoft ResX Schema + + Version 2.0 + + The primary goals of this format is to allow a simple XML format + that is mostly human readable. The generation and parsing of the + various data types are done through the TypeConverter classes + associated with the data types. + + Example: + + ... ado.net/XML headers & schema ... + <resheader name="resmimetype">text/microsoft-resx</resheader> + <resheader name="version">2.0</resheader> + <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader> + <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader> + <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data> + <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data> + <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64"> + <value>[base64 mime encoded serialized .NET Framework object]</value> + </data> + <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64"> + <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value> + <comment>This is a comment</comment> + </data> + + There are any number of "resheader" rows that contain simple + name/value pairs. + + Each data row contains a name, and value. The row also contains a + type or mimetype. Type corresponds to a .NET class that support + text/value conversion through the TypeConverter architecture. + Classes that don't support this are serialized and stored with the + mimetype set. + + The mimetype is used for serialized objects, and tells the + ResXResourceReader how to depersist the object. This is currently not + extensible. For a given mimetype the value must be set accordingly: + + Note - application/x-microsoft.net.object.binary.base64 is the format + that the ResXResourceWriter will generate, however the reader can + read any of the formats listed below. + + mimetype: application/x-microsoft.net.object.binary.base64 + value : The object must be serialized with + : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter + : and then encoded with base64 encoding. + + mimetype: application/x-microsoft.net.object.soap.base64 + value : The object must be serialized with + : System.Runtime.Serialization.Formatters.Soap.SoapFormatter + : and then encoded with base64 encoding. + + mimetype: application/x-microsoft.net.object.bytearray.base64 + value : The object must be serialized into a byte array + : using a System.ComponentModel.TypeConverter + : and then encoded with base64 encoding. + --> + <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> + <xsd:import namespace="http://www.w3.org/XML/1998/namespace" /> + <xsd:element name="root" msdata:IsDataSet="true"> + <xsd:complexType> + <xsd:choice maxOccurs="unbounded"> + <xsd:element name="metadata"> + <xsd:complexType> + <xsd:sequence> + <xsd:element name="value" type="xsd:string" minOccurs="0" /> + </xsd:sequence> + <xsd:attribute name="name" use="required" type="xsd:string" /> + <xsd:attribute name="type" type="xsd:string" /> + <xsd:attribute name="mimetype" type="xsd:string" /> + <xsd:attribute ref="xml:space" /> + </xsd:complexType> + </xsd:element> + <xsd:element name="assembly"> + <xsd:complexType> + <xsd:attribute name="alias" type="xsd:string" /> + <xsd:attribute name="name" type="xsd:string" /> + </xsd:complexType> + </xsd:element> + <xsd:element name="data"> + <xsd:complexType> + <xsd:sequence> + <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> + <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" /> + </xsd:sequence> + <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" /> + <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" /> + <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" /> + <xsd:attribute ref="xml:space" /> + </xsd:complexType> + </xsd:element> + <xsd:element name="resheader"> + <xsd:complexType> + <xsd:sequence> + <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> + </xsd:sequence> + <xsd:attribute name="name" type="xsd:string" use="required" /> + </xsd:complexType> + </xsd:element> + </xsd:choice> + </xsd:complexType> + </xsd:element> + </xsd:schema> + <resheader name="resmimetype"> + <value>text/microsoft-resx</value> + </resheader> + <resheader name="version"> + <value>2.0</value> + </resheader> + <resheader name="reader"> + <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> + </resheader> + <resheader name="writer"> + <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> + </resheader> +</root> \ 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<FormSushis> 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<ILogger>(); + Application.Run(_serviceProvider.GetRequiredService<FormMain>()); } 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<Sushi>(); } - 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<ComponentViewModel> 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<OrderViewModel> 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<SushiViewModel> GetFullList() {