From 36ed1f21b081729a4293a7c0b88246e2b5ff664f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=BE=D0=BB=D0=B8=D0=BD=D0=B0=20=D0=A7=D1=83=D0=B1?= =?UTF-8?q?=D1=8B=D0=BA=D0=B8=D0=BD=D0=B0?= Date: Tue, 26 Mar 2024 18:23:37 +0400 Subject: [PATCH] =?UTF-8?q?=D1=81=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=D0=B0=20?= =?UTF-8?q?=D0=B2=D1=82=D0=BE=D1=80=D1=83=D1=8E=20=D1=84=D0=BE=D1=80=D0=BC?= =?UTF-8?q?=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ConfectioneryView/FormCreateOrder.cs | 4 +- .../ConfectioneryView/FormPastries.cs | 4 +- .../ConfectioneryView/FormShop.Designer.cs | 3 + Confectionery/ConfectioneryView/FormShop.cs | 115 +++++++++++++++- .../ConfectioneryView/FormShops.Designer.cs | 127 ++++++++++++++++++ Confectionery/ConfectioneryView/FormShops.cs | 111 +++++++++++++++ .../ConfectioneryView/FormShops.resx | 60 +++++++++ 7 files changed, 419 insertions(+), 5 deletions(-) create mode 100644 Confectionery/ConfectioneryView/FormShops.Designer.cs create mode 100644 Confectionery/ConfectioneryView/FormShops.cs create mode 100644 Confectionery/ConfectioneryView/FormShops.resx diff --git a/Confectionery/ConfectioneryView/FormCreateOrder.cs b/Confectionery/ConfectioneryView/FormCreateOrder.cs index a448d9b..b903b1b 100644 --- a/Confectionery/ConfectioneryView/FormCreateOrder.cs +++ b/Confectionery/ConfectioneryView/FormCreateOrder.cs @@ -29,7 +29,7 @@ namespace ConfectioneryView private void FormCreateOrder_Load(object sender, EventArgs e) { - _logger.LogInformation("Loading ice cream for order"); + _logger.LogInformation("Loading pastry for order"); try { var pastryList = _logicP.ReadList(null); @@ -43,7 +43,7 @@ namespace ConfectioneryView } catch (Exception ex) { - _logger.LogError(ex, "Error during loading ice cream for order"); + _logger.LogError(ex, "Error during loading pastry for order"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } diff --git a/Confectionery/ConfectioneryView/FormPastries.cs b/Confectionery/ConfectioneryView/FormPastries.cs index 7932f5b..508f6cc 100644 --- a/Confectionery/ConfectioneryView/FormPastries.cs +++ b/Confectionery/ConfectioneryView/FormPastries.cs @@ -86,7 +86,7 @@ namespace ConfectioneryView if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Deletion of ice cream"); + _logger.LogInformation("Deletion of pastry"); try { if (!_logic.Delete(new PastryBindingModel { Id = id })) @@ -97,7 +97,7 @@ namespace ConfectioneryView } catch (Exception ex) { - _logger.LogError(ex, "Ice cream deletion error"); + _logger.LogError(ex, "Pastry deletion error"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } diff --git a/Confectionery/ConfectioneryView/FormShop.Designer.cs b/Confectionery/ConfectioneryView/FormShop.Designer.cs index bb85298..dea22e8 100644 --- a/Confectionery/ConfectioneryView/FormShop.Designer.cs +++ b/Confectionery/ConfectioneryView/FormShop.Designer.cs @@ -142,6 +142,7 @@ this.buttonCancel.TabIndex = 15; this.buttonCancel.Text = "Отмена"; this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); // // buttonSave // @@ -152,6 +153,7 @@ this.buttonSave.TabIndex = 14; this.buttonSave.Text = "Сохранить"; this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); // // ColumnId // @@ -194,6 +196,7 @@ this.Controls.Add(this.labelName); this.Name = "FormShop"; this.Text = "Магазин"; + this.Load += new System.EventHandler(this.FormShop_Load); this.groupBoxPastries.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); this.ResumeLayout(false); diff --git a/Confectionery/ConfectioneryView/FormShop.cs b/Confectionery/ConfectioneryView/FormShop.cs index e872cd3..b9a3230 100644 --- a/Confectionery/ConfectioneryView/FormShop.cs +++ b/Confectionery/ConfectioneryView/FormShop.cs @@ -7,14 +7,127 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.BusinessLogicsContracts; +using ConfectioneryContracts.SearchModels; +using ConfectioneryDataModels.Models; +using Microsoft.Extensions.Logging; namespace ConfectioneryView { public partial class FormShop : Form { - public FormShop() + private readonly ILogger _logger; + + private readonly IShopLogic _logic; + + private int? _id; + + private Dictionary _shopPastries; + + public int Id { set { _id = value; } } + public FormShop(ILogger logger, IShopLogic logic) { InitializeComponent(); + _logger = logger; + _logic = logic; + _shopPastries = new Dictionary(); + } + + private void FormShop_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + _logger.LogInformation("Shop loading"); + try + { + var view = _logic.ReadElement(new ShopSearchModel { Id = _id.Value }); + if (view != null) + { + textBoxName.Text = view.ShopName; + textBoxAddress.Text = view.Address; + dateTimePicker.Value = view.DateOpening; + _shopPastries = view.ShopPastries ?? new Dictionary(); + LoadData(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Shop loading error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void LoadData() + { + _logger.LogInformation("Shop pastries loading"); + try + { + if (_shopPastries != null) + { + dataGridView.Rows.Clear(); + foreach (var pastry in _shopPastries) + { + dataGridView.Rows.Add(new object[] { pastry.Key, pastry.Value.Item1.PastryName, pastry.Value.Item2 }); + } + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Shop pastries loading error"); + 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; + } + if (string.IsNullOrEmpty(dateTimePicker.Text)) + { + MessageBox.Show("Заполните дату", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Shop saving"); + try + { + var model = new ShopBindingModel + { + Id = _id ?? 0, + ShopName = textBoxName.Text, + Address = textBoxAddress.Text, + DateOpening = dateTimePicker.Value, + ShopPastries = _shopPastries + }; + 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, "Shop saving error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); } } } diff --git a/Confectionery/ConfectioneryView/FormShops.Designer.cs b/Confectionery/ConfectioneryView/FormShops.Designer.cs new file mode 100644 index 0000000..301e6bf --- /dev/null +++ b/Confectionery/ConfectioneryView/FormShops.Designer.cs @@ -0,0 +1,127 @@ +namespace ConfectioneryView +{ + 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.buttonUpd = new System.Windows.Forms.Button(); + this.buttonDel = 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(); + // + // buttonUpd + // + this.buttonUpd.Location = new System.Drawing.Point(511, 221); + this.buttonUpd.Margin = new System.Windows.Forms.Padding(5, 4, 5, 4); + this.buttonUpd.Name = "buttonUpd"; + this.buttonUpd.Size = new System.Drawing.Size(101, 36); + this.buttonUpd.TabIndex = 16; + this.buttonUpd.Text = "Обновить"; + this.buttonUpd.UseVisualStyleBackColor = true; + this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // buttonDel + // + this.buttonDel.Location = new System.Drawing.Point(511, 158); + this.buttonDel.Margin = new System.Windows.Forms.Padding(5, 4, 5, 4); + this.buttonDel.Name = "buttonDel"; + this.buttonDel.Size = new System.Drawing.Size(101, 36); + this.buttonDel.TabIndex = 15; + this.buttonDel.Text = "Удалить"; + this.buttonDel.UseVisualStyleBackColor = true; + this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click); + // + // buttonEdit + // + this.buttonEdit.Location = new System.Drawing.Point(511, 95); + this.buttonEdit.Margin = new System.Windows.Forms.Padding(5, 4, 5, 4); + this.buttonEdit.Name = "buttonEdit"; + this.buttonEdit.Size = new System.Drawing.Size(101, 36); + this.buttonEdit.TabIndex = 14; + this.buttonEdit.Text = "Изменить"; + this.buttonEdit.UseVisualStyleBackColor = true; + this.buttonEdit.Click += new System.EventHandler(this.ButtonEdit_Click); + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(511, 37); + this.buttonAdd.Margin = new System.Windows.Forms.Padding(5, 4, 5, 4); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(101, 36); + this.buttonAdd.TabIndex = 13; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // dataGridView + // + this.dataGridView.AllowUserToAddRows = false; + this.dataGridView.AllowUserToDeleteRows = false; + this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ControlLightLight; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Dock = System.Windows.Forms.DockStyle.Left; + this.dataGridView.Location = new System.Drawing.Point(0, 0); + this.dataGridView.Margin = new System.Windows.Forms.Padding(5, 4, 5, 4); + this.dataGridView.MultiSelect = false; + this.dataGridView.Name = "dataGridView"; + this.dataGridView.ReadOnly = true; + this.dataGridView.RowHeadersVisible = false; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; + this.dataGridView.Size = new System.Drawing.Size(466, 538); + this.dataGridView.TabIndex = 17; + // + // FormShops + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(650, 538); + this.Controls.Add(this.dataGridView); + this.Controls.Add(this.buttonUpd); + this.Controls.Add(this.buttonDel); + this.Controls.Add(this.buttonEdit); + this.Controls.Add(this.buttonAdd); + 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 buttonUpd; + private Button buttonDel; + private Button buttonEdit; + private Button buttonAdd; + private DataGridView dataGridView; + } +} \ No newline at end of file diff --git a/Confectionery/ConfectioneryView/FormShops.cs b/Confectionery/ConfectioneryView/FormShops.cs new file mode 100644 index 0000000..77f6c7b --- /dev/null +++ b/Confectionery/ConfectioneryView/FormShops.cs @@ -0,0 +1,111 @@ +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 ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; + +namespace ConfectioneryView +{ + 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["ShopName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["ShopPastries"].Visible = false; + } + _logger.LogInformation("Shops loading"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Shops loading error"); + 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 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("Deletion of shop"); + try + { + if (!_logic.Delete(new ShopBindingModel { Id = id })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Shop deletion error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + + private void ButtonUpd_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/Confectionery/ConfectioneryView/FormShops.resx b/Confectionery/ConfectioneryView/FormShops.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Confectionery/ConfectioneryView/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