From 0e9c54c487cec4f5c514157a1144b486efc25cec Mon Sep 17 00:00:00 2001 From: malimova Date: Wed, 28 Feb 2024 21:24:29 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9C=D0=BD=D0=BE=D0=B3=D0=BE=20=D0=B8=D0=B7?= =?UTF-8?q?=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD=D0=B8=D0=B9...?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ConfectioneryBusinessLogic/OrderLogic.cs | 2 +- .../FormComponent.Designer.cs | 3 + .../ConfectioneryView/FormComponent.cs | 2 + .../FormComponents.Designer.cs | 1 + .../FormCreateOrder.Designer.cs | 5 +- .../ConfectioneryView/FormCreateOrder.cs | 8 +- .../ConfectioneryView/FormMain.Designer.cs | 6 +- Confectionery/ConfectioneryView/FormMain.cs | 31 ++++-- .../ConfectioneryView/FormPastry.Designer.cs | 3 +- Confectionery/ConfectioneryView/FormPastry.cs | 25 ++++- .../FormPastryComponent.Designer.cs | 2 +- .../ConfectioneryView/FormPastrys.Designer.cs | 46 +++++---- .../ConfectioneryView/FormPastrys.cs | 96 ++++++++++++++++++- 13 files changed, 187 insertions(+), 43 deletions(-) diff --git a/Confectionery/ConfectioneryBusinessLogic/OrderLogic.cs b/Confectionery/ConfectioneryBusinessLogic/OrderLogic.cs index 7780cce..4146e4e 100644 --- a/Confectionery/ConfectioneryBusinessLogic/OrderLogic.cs +++ b/Confectionery/ConfectioneryBusinessLogic/OrderLogic.cs @@ -85,7 +85,7 @@ namespace ConfectioneryBusinessLogic { throw new ArithmeticException($"Дата выдачи заказа {model.DateImplement} не может быть раньше даты его создания {model.DateCreate}"); } - _logger.LogInformation("Sushi. SushiId:{SushiId}.Count:{Count}.Sum:{Sum}Id:{Id}", + _logger.LogInformation("Pastry. PastryId:{PastryId}.Count:{Count}.Sum:{Sum}Id:{Id}", model.PastryId, model.Count, model.Sum, model.Id); } diff --git a/Confectionery/ConfectioneryView/FormComponent.Designer.cs b/Confectionery/ConfectioneryView/FormComponent.Designer.cs index 3f8bc03..3095acf 100644 --- a/Confectionery/ConfectioneryView/FormComponent.Designer.cs +++ b/Confectionery/ConfectioneryView/FormComponent.Designer.cs @@ -76,6 +76,7 @@ buttonCreate.TabIndex = 4; buttonCreate.Text = "Создать"; buttonCreate.UseVisualStyleBackColor = true; + buttonCreate.Click += ButtonSave_Click; // // buttonCancel // @@ -85,6 +86,7 @@ buttonCancel.TabIndex = 5; buttonCancel.Text = "Отмена"; buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; // // FormComponent // @@ -99,6 +101,7 @@ Controls.Add(label1); Name = "FormComponent"; Text = "Компонент"; + Load += FormComponent_Load; ResumeLayout(false); PerformLayout(); } diff --git a/Confectionery/ConfectioneryView/FormComponent.cs b/Confectionery/ConfectioneryView/FormComponent.cs index abb3e79..5928b60 100644 --- a/Confectionery/ConfectioneryView/FormComponent.cs +++ b/Confectionery/ConfectioneryView/FormComponent.cs @@ -80,5 +80,7 @@ namespace ConfectioneryView DialogResult = DialogResult.Cancel; Close(); } + + } } \ No newline at end of file diff --git a/Confectionery/ConfectioneryView/FormComponents.Designer.cs b/Confectionery/ConfectioneryView/FormComponents.Designer.cs index e025eaa..8ada6e6 100644 --- a/Confectionery/ConfectioneryView/FormComponents.Designer.cs +++ b/Confectionery/ConfectioneryView/FormComponents.Designer.cs @@ -38,6 +38,7 @@ // // dataGridView // + dataGridView.BackgroundColor = Color.AliceBlue; dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; dataGridView.Location = new Point(12, 12); dataGridView.Name = "dataGridView"; diff --git a/Confectionery/ConfectioneryView/FormCreateOrder.Designer.cs b/Confectionery/ConfectioneryView/FormCreateOrder.Designer.cs index 453af41..d72a23a 100644 --- a/Confectionery/ConfectioneryView/FormCreateOrder.Designer.cs +++ b/Confectionery/ConfectioneryView/FormCreateOrder.Designer.cs @@ -72,7 +72,7 @@ comboBoxPastry.Name = "comboBoxPastry"; comboBoxPastry.Size = new Size(434, 33); comboBoxPastry.TabIndex = 3; - comboBoxPastry.SelectedIndexChanged += comboBoxProduct_SelectedIndexChanged; + comboBoxPastry.SelectedIndexChanged += comboBoxPastry_SelectedIndexChanged; // // textBoxCount // @@ -86,6 +86,7 @@ // textBoxSum.Location = new Point(192, 155); textBoxSum.Name = "textBoxSum"; + textBoxSum.ReadOnly = true; textBoxSum.Size = new Size(434, 31); textBoxSum.TabIndex = 5; // @@ -123,7 +124,7 @@ Controls.Add(labelCount); Controls.Add(labelName); Name = "FormCreateOrder"; - Text = "FormCreateOrder"; + Text = "Создание заказа"; Load += FormCreateOrder_Load; ResumeLayout(false); PerformLayout(); diff --git a/Confectionery/ConfectioneryView/FormCreateOrder.cs b/Confectionery/ConfectioneryView/FormCreateOrder.cs index 568f60a..c2665e7 100644 --- a/Confectionery/ConfectioneryView/FormCreateOrder.cs +++ b/Confectionery/ConfectioneryView/FormCreateOrder.cs @@ -73,15 +73,15 @@ namespace ConfectioneryView private void FormCreateOrder_Load(object sender, EventArgs e) { - _logger.LogInformation("Загрузка суши для заказа"); + _logger.LogInformation("Загрузка кондитерского изделия для заказа"); _list = _logicP.ReadList(null); if (_list != null) { - comboBoxPastry.DisplayMember = "SushiName"; + comboBoxPastry.DisplayMember = "PastryName"; comboBoxPastry.ValueMember = "Id"; comboBoxPastry.DataSource = _list; comboBoxPastry.SelectedItem = null; - _logger.LogInformation("Загрузка суши для заказа"); + _logger.LogInformation("Загрузка кондитерского изделия для заказа"); } } private void CalcSum() @@ -109,7 +109,7 @@ namespace ConfectioneryView { CalcSum(); } - private void comboBoxProduct_SelectedIndexChanged(object sender, EventArgs e) + private void comboBoxPastry_SelectedIndexChanged(object sender, EventArgs e) { CalcSum(); } diff --git a/Confectionery/ConfectioneryView/FormMain.Designer.cs b/Confectionery/ConfectioneryView/FormMain.Designer.cs index c7be7ea..7e8e56b 100644 --- a/Confectionery/ConfectioneryView/FormMain.Designer.cs +++ b/Confectionery/ConfectioneryView/FormMain.Designer.cs @@ -44,6 +44,7 @@ // // dataGridView // + dataGridView.BackgroundColor = Color.AliceBlue; dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; dataGridView.Location = new Point(12, 60); dataGridView.Name = "dataGridView"; @@ -74,12 +75,14 @@ componentsToolStripMenuItem.Name = "componentsToolStripMenuItem"; componentsToolStripMenuItem.Size = new Size(298, 34); componentsToolStripMenuItem.Text = "Компоненты"; + componentsToolStripMenuItem.Click += componentsToolStripMenuItem_Click; // // pastryToolStripMenuItem // pastryToolStripMenuItem.Name = "pastryToolStripMenuItem"; pastryToolStripMenuItem.Size = new Size(298, 34); pastryToolStripMenuItem.Text = "Кондитерские изделия"; + pastryToolStripMenuItem.Click += pastryToolStripMenuItem_Click; // // buttonCreateOrder // @@ -145,7 +148,8 @@ Controls.Add(menuStrip); MainMenuStrip = menuStrip; Name = "FormMain"; - Text = "FormMain"; + Text = "Кондитерская"; + Load += FormMain_Load; ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); menuStrip.ResumeLayout(false); menuStrip.PerformLayout(); diff --git a/Confectionery/ConfectioneryView/FormMain.cs b/Confectionery/ConfectioneryView/FormMain.cs index fd3a866..0cd8423 100644 --- a/Confectionery/ConfectioneryView/FormMain.cs +++ b/Confectionery/ConfectioneryView/FormMain.cs @@ -30,10 +30,25 @@ namespace ConfectioneryView private void LoadData() { _logger.LogInformation("Загрузка заказов"); - // прописать логику + try + { + var list = _orderLogic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["PastryId"].Visible = false; + dataGridView.Columns["PastryName"].AutoSizeMode = + DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка заказов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки заказов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } } - private void componentsToolStripMenuItem_Click(object sender, EventArgs -e) + private void componentsToolStripMenuItem_Click(object sender, EventArgs e) { var service = Program.ServiceProvider?.GetService(typeof(FormComponents)); if (service is FormComponents form) @@ -43,7 +58,6 @@ e) } private void pastryToolStripMenuItem_Click(object sender, EventArgs e) { - // прописать логику var service = Program.ServiceProvider?.GetService(typeof(FormPastrys)); if (service is FormPastrys form) { @@ -65,8 +79,7 @@ e) { if (dataGridView.SelectedRows.Count == 1) { - int id = - Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); _logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id); try { @@ -92,10 +105,8 @@ e) { if (dataGridView.SelectedRows.Count == 1) { - int id = - Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", - id); + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", id); try { var operationResult = _orderLogic.FinishOrder(new diff --git a/Confectionery/ConfectioneryView/FormPastry.Designer.cs b/Confectionery/ConfectioneryView/FormPastry.Designer.cs index 9414506..c7d6e40 100644 --- a/Confectionery/ConfectioneryView/FormPastry.Designer.cs +++ b/Confectionery/ConfectioneryView/FormPastry.Designer.cs @@ -132,6 +132,7 @@ // // dataGridView // + dataGridView.BackgroundColor = Color.AliceBlue; dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; dataGridView.Location = new Point(10, 30); dataGridView.Name = "dataGridView"; @@ -173,7 +174,7 @@ Controls.Add(label2); Controls.Add(label1); Name = "FormPastry"; - Text = "FormPastry"; + Text = "Кондитерское изделие"; Load += FormPastry_Load; groupBoxComponents.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); diff --git a/Confectionery/ConfectioneryView/FormPastry.cs b/Confectionery/ConfectioneryView/FormPastry.cs index c41c136..ec9f503 100644 --- a/Confectionery/ConfectioneryView/FormPastry.cs +++ b/Confectionery/ConfectioneryView/FormPastry.cs @@ -79,15 +79,32 @@ namespace ConfectioneryView private void FormPastry_Load(object sender, EventArgs e) { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView.AllowUserToAddRows = false; + DataGridViewTextBoxColumn Id = new DataGridViewTextBoxColumn(); + DataGridViewTextBoxColumn Component = new DataGridViewTextBoxColumn(); + DataGridViewTextBoxColumn Number = new DataGridViewTextBoxColumn(); + Component.HeaderText = "Количество"; + Number.HeaderText = "Компонент"; + Number.Name = "Number"; + Id.Name = "Id"; + dataGridView.Columns.Add(Id); + dataGridView.Columns.Add(Number); + dataGridView.Columns.Add(Component); + dataGridView.Columns["Id"].Visible = false; + + dataGridView.Columns["Number"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } if (_id.HasValue) { - _logger.LogInformation("Загрузка изделия"); + _logger.LogInformation("Загрузка суши"); try { var view = _logic.ReadElement(new PastrySearchModel { - Id = - _id.Value + Id = _id.Value }); if (view != null) { @@ -100,7 +117,7 @@ namespace ConfectioneryView } catch (Exception ex) { - _logger.LogError(ex, "Ошибка загрузки изделия"); + _logger.LogError(ex, "Ошибка загрузки суши"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } diff --git a/Confectionery/ConfectioneryView/FormPastryComponent.Designer.cs b/Confectionery/ConfectioneryView/FormPastryComponent.Designer.cs index a37e145..1f5904c 100644 --- a/Confectionery/ConfectioneryView/FormPastryComponent.Designer.cs +++ b/Confectionery/ConfectioneryView/FormPastryComponent.Designer.cs @@ -101,7 +101,7 @@ Controls.Add(label2); Controls.Add(label1); Name = "FormPastryComponent"; - Text = "FormPastryComponent"; + Text = "Компонент изделия"; ResumeLayout(false); PerformLayout(); } diff --git a/Confectionery/ConfectioneryView/FormPastrys.Designer.cs b/Confectionery/ConfectioneryView/FormPastrys.Designer.cs index 6eeeae1..2c221fb 100644 --- a/Confectionery/ConfectioneryView/FormPastrys.Designer.cs +++ b/Confectionery/ConfectioneryView/FormPastrys.Designer.cs @@ -28,79 +28,89 @@ /// private void InitializeComponent() { - dataGridView1 = new DataGridView(); + dataGridView = new DataGridView(); buttonAdd = new Button(); buttonUpd = new Button(); buttonDel = new Button(); buttonRef = new Button(); - ((System.ComponentModel.ISupportInitialize)dataGridView1).BeginInit(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); SuspendLayout(); // - // dataGridView1 + // dataGridView // - dataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; - dataGridView1.Location = new Point(12, 12); - dataGridView1.Name = "dataGridView1"; - dataGridView1.RowHeadersWidth = 62; - dataGridView1.RowTemplate.Height = 33; - dataGridView1.Size = new Size(1075, 635); - dataGridView1.TabIndex = 0; + dataGridView.BackgroundColor = Color.AliceBlue; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(12, 12); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersWidth = 62; + dataGridView.RowTemplate.Height = 33; + dataGridView.Size = new Size(916, 479); + dataGridView.TabIndex = 0; // // buttonAdd // - buttonAdd.Location = new Point(1161, 53); + buttonAdd.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonAdd.Location = new Point(975, 53); buttonAdd.Name = "buttonAdd"; buttonAdd.Size = new Size(133, 46); buttonAdd.TabIndex = 1; buttonAdd.Text = "Добавить"; buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += buttonAdd_Click; // // buttonUpd // - buttonUpd.Location = new Point(1161, 119); + buttonUpd.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonUpd.Location = new Point(975, 119); buttonUpd.Name = "buttonUpd"; buttonUpd.Size = new Size(133, 46); buttonUpd.TabIndex = 2; buttonUpd.Text = "Изменить"; buttonUpd.UseVisualStyleBackColor = true; + buttonUpd.Click += buttonUpd_Click; // // buttonDel // - buttonDel.Location = new Point(1161, 185); + buttonDel.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonDel.Location = new Point(975, 185); buttonDel.Name = "buttonDel"; buttonDel.Size = new Size(133, 45); buttonDel.TabIndex = 3; buttonDel.Text = "Удалить"; buttonDel.UseVisualStyleBackColor = true; + buttonDel.Click += buttonDel_Click; // // buttonRef // - buttonRef.Location = new Point(1161, 251); + buttonRef.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonRef.Location = new Point(975, 251); buttonRef.Name = "buttonRef"; buttonRef.Size = new Size(133, 48); buttonRef.TabIndex = 4; buttonRef.Text = "Обновить"; buttonRef.UseVisualStyleBackColor = true; + buttonRef.Click += buttonRef_Click; // // FormPastrys // AutoScaleDimensions = new SizeF(10F, 25F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(1325, 659); + ClientSize = new Size(1139, 518); Controls.Add(buttonRef); Controls.Add(buttonDel); Controls.Add(buttonUpd); Controls.Add(buttonAdd); - Controls.Add(dataGridView1); + Controls.Add(dataGridView); Name = "FormPastrys"; Text = "Кондитерские изделия"; - ((System.ComponentModel.ISupportInitialize)dataGridView1).EndInit(); + Load += FormPastrys_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); ResumeLayout(false); } #endregion - private DataGridView dataGridView1; + private DataGridView dataGridView; private Button buttonAdd; private Button buttonUpd; private Button buttonDel; diff --git a/Confectionery/ConfectioneryView/FormPastrys.cs b/Confectionery/ConfectioneryView/FormPastrys.cs index 2240405..c416875 100644 --- a/Confectionery/ConfectioneryView/FormPastrys.cs +++ b/Confectionery/ConfectioneryView/FormPastrys.cs @@ -7,14 +7,108 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using Microsoft.Extensions.Logging; +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.BusinessLogicsContracts; namespace ConfectioneryView { public partial class FormPastrys : Form { - public FormPastrys() + private readonly ILogger _logger; + private readonly IPastryLogic _logic; + public FormPastrys(ILogger logger, IPastryLogic logic) { InitializeComponent(); + _logger = logger; + _logic = logic; + } + private void FormPastrys_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["PastryComponents"].Visible = false; + dataGridView.Columns["PastryName"].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(FormPastry)); + if (service is FormPastry 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(FormPastry)); + if (service is FormPastry 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 PastryBindingModel + { + 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(); } } }