From 7ef9f12ae75535edc811ae43bea72b9bd4324b6b Mon Sep 17 00:00:00 2001 From: malimova Date: Fri, 12 Apr 2024 01:04:02 +0400 Subject: [PATCH] form --- .../ConfectioneryBusinessLogic/ReportLogic.cs | 2 +- .../ConfectioneryView/FormMain.Designer.cs | 37 ++++- Confectionery/ConfectioneryView/FormMain.cs | 21 ++- .../FormReportPastryComponents.Designer.cs | 130 ++++++++++++++++++ .../FormReportPastryComponents.cs | 86 ++++++++++++ .../FormReportPastryComponents.resx | 69 ++++++++++ Confectionery/ConfectioneryView/Program.cs | 8 ++ 7 files changed, 349 insertions(+), 4 deletions(-) create mode 100644 Confectionery/ConfectioneryView/FormReportPastryComponents.Designer.cs create mode 100644 Confectionery/ConfectioneryView/FormReportPastryComponents.cs create mode 100644 Confectionery/ConfectioneryView/FormReportPastryComponents.resx diff --git a/Confectionery/ConfectioneryBusinessLogic/ReportLogic.cs b/Confectionery/ConfectioneryBusinessLogic/ReportLogic.cs index a818b48..85c5ea4 100644 --- a/Confectionery/ConfectioneryBusinessLogic/ReportLogic.cs +++ b/Confectionery/ConfectioneryBusinessLogic/ReportLogic.cs @@ -8,7 +8,7 @@ using ConfectioneryContracts.ViewModels; namespace ConfectioneryBusinessLogic { - internal class ReportLogic : IReportLogic + public class ReportLogic : IReportLogic { private readonly IComponentStorage _componentStorage; private readonly IPastryStorage _productStorage; diff --git a/Confectionery/ConfectioneryView/FormMain.Designer.cs b/Confectionery/ConfectioneryView/FormMain.Designer.cs index 3c95edf..658ef3b 100644 --- a/Confectionery/ConfectioneryView/FormMain.Designer.cs +++ b/Confectionery/ConfectioneryView/FormMain.Designer.cs @@ -33,6 +33,10 @@ toolStripMenuItem = new ToolStripMenuItem(); componentsToolStripMenuItem = new ToolStripMenuItem(); pastryToolStripMenuItem = new ToolStripMenuItem(); + отчетыToolStripMenuItem = new ToolStripMenuItem(); + componentsListToolStripMenuItem = new ToolStripMenuItem(); + componentPastryToolStripMenuItem = new ToolStripMenuItem(); + ordersListToolStripMenuItem = new ToolStripMenuItem(); buttonCreateOrder = new Button(); buttonTakeOrderInWork = new Button(); buttonOrderReady = new Button(); @@ -56,7 +60,7 @@ // menuStrip // menuStrip.ImageScalingSize = new Size(24, 24); - menuStrip.Items.AddRange(new ToolStripItem[] { toolStripMenuItem }); + menuStrip.Items.AddRange(new ToolStripItem[] { toolStripMenuItem, отчетыToolStripMenuItem }); menuStrip.Location = new Point(0, 0); menuStrip.Name = "menuStrip"; menuStrip.Size = new Size(1375, 33); @@ -84,6 +88,33 @@ pastryToolStripMenuItem.Text = "Кондитерские изделия"; pastryToolStripMenuItem.Click += pastryToolStripMenuItem_Click; // + // отчетыToolStripMenuItem + // + отчетыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { componentsListToolStripMenuItem, componentPastryToolStripMenuItem, ordersListToolStripMenuItem }); + отчетыToolStripMenuItem.Name = "отчетыToolStripMenuItem"; + отчетыToolStripMenuItem.Size = new Size(88, 29); + отчетыToolStripMenuItem.Text = "Отчеты"; + // + // componentsListToolStripMenuItem + // + componentsListToolStripMenuItem.Name = "componentsListToolStripMenuItem"; + componentsListToolStripMenuItem.Size = new Size(327, 34); + componentsListToolStripMenuItem.Text = "Список компонентов"; + // + // componentPastryToolStripMenuItem + // + componentPastryToolStripMenuItem.Name = "componentPastryToolStripMenuItem"; + componentPastryToolStripMenuItem.Size = new Size(327, 34); + componentPastryToolStripMenuItem.Text = "Компоненты по изделиям"; + componentPastryToolStripMenuItem.Click += componentPastryToolStripMenuItem_Click; + // + // ordersListToolStripMenuItem + // + ordersListToolStripMenuItem.Name = "ordersListToolStripMenuItem"; + ordersListToolStripMenuItem.Size = new Size(327, 34); + ordersListToolStripMenuItem.Text = "Список заказов"; + ordersListToolStripMenuItem.Click += ordersListToolStripMenuItem_Click; + // // buttonCreateOrder // buttonCreateOrder.Anchor = AnchorStyles.Top | AnchorStyles.Right; @@ -174,5 +205,9 @@ private Button buttonRef; private ToolStripMenuItem componentsToolStripMenuItem; private ToolStripMenuItem pastryToolStripMenuItem; + private ToolStripMenuItem отчетыToolStripMenuItem; + private ToolStripMenuItem componentsListToolStripMenuItem; + private ToolStripMenuItem componentPastryToolStripMenuItem; + private ToolStripMenuItem ordersListToolStripMenuItem; } } \ No newline at end of file diff --git a/Confectionery/ConfectioneryView/FormMain.cs b/Confectionery/ConfectioneryView/FormMain.cs index 0cd8423..d2d1aee 100644 --- a/Confectionery/ConfectioneryView/FormMain.cs +++ b/Confectionery/ConfectioneryView/FormMain.cs @@ -16,12 +16,15 @@ namespace ConfectioneryView public partial class FormMain : Form { private readonly ILogger _logger; - private readonly IOrderLogic _orderLogic; - public FormMain(ILogger logger, IOrderLogic orderLogic) + private readonly IOrderLogic _orderLogic; + private readonly IReportLogic _reportLogic; + + public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic) { InitializeComponent(); _logger = logger; _orderLogic = orderLogic; + _reportLogic = reportLogic; } private void FormMain_Load(object sender, EventArgs e) { @@ -157,5 +160,19 @@ namespace ConfectioneryView { LoadData(); } + + private void componentPastryToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormReportPastryComponents)); + if (service is FormReportPastryComponents form) + { + form.ShowDialog(); + } + } + + private void ordersListToolStripMenuItem_Click(object sender, EventArgs e) + { + + } } } diff --git a/Confectionery/ConfectioneryView/FormReportPastryComponents.Designer.cs b/Confectionery/ConfectioneryView/FormReportPastryComponents.Designer.cs new file mode 100644 index 0000000..a018221 --- /dev/null +++ b/Confectionery/ConfectioneryView/FormReportPastryComponents.Designer.cs @@ -0,0 +1,130 @@ +namespace ConfectioneryView +{ + partial class FormReportPastryComponents + { + /// + /// 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() + { + DataGridViewCellStyle dataGridViewCellStyle1 = new DataGridViewCellStyle(); + DataGridViewCellStyle dataGridViewCellStyle2 = new DataGridViewCellStyle(); + DataGridViewCellStyle dataGridViewCellStyle3 = new DataGridViewCellStyle(); + dataGridView = new DataGridView(); + ColumnComponent = new DataGridViewTextBoxColumn(); + ColumnPastry = new DataGridViewTextBoxColumn(); + ColumnCount = new DataGridViewTextBoxColumn(); + buttonSaveToExcel = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.BackgroundColor = Color.AliceBlue; + dataGridViewCellStyle1.Alignment = DataGridViewContentAlignment.MiddleLeft; + dataGridViewCellStyle1.BackColor = SystemColors.Control; + dataGridViewCellStyle1.Font = new Font("Segoe UI", 9F, FontStyle.Regular, GraphicsUnit.Point); + dataGridViewCellStyle1.ForeColor = SystemColors.WindowText; + dataGridViewCellStyle1.SelectionBackColor = SystemColors.Highlight; + dataGridViewCellStyle1.SelectionForeColor = SystemColors.HighlightText; + dataGridViewCellStyle1.WrapMode = DataGridViewTriState.True; + dataGridView.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle1; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Columns.AddRange(new DataGridViewColumn[] { ColumnComponent, ColumnPastry, ColumnCount }); + dataGridViewCellStyle2.Alignment = DataGridViewContentAlignment.MiddleLeft; + dataGridViewCellStyle2.BackColor = SystemColors.Window; + dataGridViewCellStyle2.Font = new Font("Segoe UI", 9F, FontStyle.Regular, GraphicsUnit.Point); + dataGridViewCellStyle2.ForeColor = SystemColors.ControlText; + dataGridViewCellStyle2.SelectionBackColor = SystemColors.Highlight; + dataGridViewCellStyle2.SelectionForeColor = SystemColors.HighlightText; + dataGridViewCellStyle2.WrapMode = DataGridViewTriState.False; + dataGridView.DefaultCellStyle = dataGridViewCellStyle2; + dataGridView.Location = new Point(12, 141); + dataGridView.Name = "dataGridView"; + dataGridViewCellStyle3.Alignment = DataGridViewContentAlignment.MiddleLeft; + dataGridViewCellStyle3.BackColor = SystemColors.Control; + dataGridViewCellStyle3.Font = new Font("Segoe UI", 9F, FontStyle.Regular, GraphicsUnit.Point); + dataGridViewCellStyle3.ForeColor = SystemColors.WindowText; + dataGridViewCellStyle3.SelectionBackColor = SystemColors.Highlight; + dataGridViewCellStyle3.SelectionForeColor = SystemColors.HighlightText; + dataGridViewCellStyle3.WrapMode = DataGridViewTriState.True; + dataGridView.RowHeadersDefaultCellStyle = dataGridViewCellStyle3; + dataGridView.RowHeadersWidth = 62; + dataGridView.RowTemplate.Height = 33; + dataGridView.Size = new Size(875, 498); + dataGridView.TabIndex = 0; + // + // ColumnComponent + // + ColumnComponent.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + ColumnComponent.HeaderText = "Компонент"; + ColumnComponent.MinimumWidth = 8; + ColumnComponent.Name = "ColumnComponent"; + // + // ColumnPastry + // + ColumnPastry.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + ColumnPastry.HeaderText = "Изделие"; + ColumnPastry.MinimumWidth = 8; + ColumnPastry.Name = "ColumnPastry"; + // + // ColumnCount + // + ColumnCount.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + ColumnCount.HeaderText = "Количество"; + ColumnCount.MinimumWidth = 8; + ColumnCount.Name = "ColumnCount"; + // + // buttonSaveToExcel + // + buttonSaveToExcel.Location = new Point(66, 45); + buttonSaveToExcel.Name = "buttonSaveToExcel"; + buttonSaveToExcel.Size = new Size(187, 52); + buttonSaveToExcel.TabIndex = 1; + buttonSaveToExcel.Text = "Сохранить в Excel"; + buttonSaveToExcel.UseVisualStyleBackColor = true; + buttonSaveToExcel.Click += buttonSaveToExcel_Click; + // + // FormReportPastryComponents + // + AutoScaleDimensions = new SizeF(10F, 25F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(899, 651); + Controls.Add(buttonSaveToExcel); + Controls.Add(dataGridView); + Name = "FormReportPastryComponents"; + Text = "Компоненты по изделиям"; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridView; + private DataGridViewTextBoxColumn ColumnComponent; + private DataGridViewTextBoxColumn ColumnPastry; + private DataGridViewTextBoxColumn ColumnCount; + private Button buttonSaveToExcel; + } +} \ No newline at end of file diff --git a/Confectionery/ConfectioneryView/FormReportPastryComponents.cs b/Confectionery/ConfectioneryView/FormReportPastryComponents.cs new file mode 100644 index 0000000..763058d --- /dev/null +++ b/Confectionery/ConfectioneryView/FormReportPastryComponents.cs @@ -0,0 +1,86 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +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 ConfectioneryView +{ + public partial class FormReportPastryComponents : Form + { + private readonly ILogger _logger; + private readonly IReportLogic _logic; + + public FormReportPastryComponents(ILogger logger, IReportLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormReportPastryComponents_Load(object sender, EventArgs e) + { + try + { + var dict = _logic.GetPastryComponent(); + if (dict != null) + { + dataGridView.Rows.Clear(); + foreach (var elem in dict) + { + dataGridView.Rows.Add(new object[] { elem.ComponentName, "", "" }); + foreach (var listElem in elem.Pastrys) + { + dataGridView.Rows.Add(new object[] { "", listElem.Item1, listElem.Item2 }); + } + dataGridView.Rows.Add(new object[] { "Итого", "", elem.TotalCount }); + dataGridView.Rows.Add(Array.Empty()); + } + } + _logger.LogInformation("Загрузка списка кондитерских изделий по компонентам"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка кондитерских изделий по компонентам"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonSaveToExcel_Click(object sender, EventArgs e) + { + using var dialog = new SaveFileDialog + { + Filter = "xlsx|*.xlsx" + }; + if (dialog.ShowDialog() == DialogResult.OK) + { + try + { + _logic.SavePastryComponentToExcelFile(new + ReportBindingModel + { + FileName = dialog.FileName + }); + _logger.LogInformation("Сохранение списка изделий по компонентам"); + + MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, + MessageBoxIcon.Information); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения списка изделий по компонентам"); + + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + } +} diff --git a/Confectionery/ConfectioneryView/FormReportPastryComponents.resx b/Confectionery/ConfectioneryView/FormReportPastryComponents.resx new file mode 100644 index 0000000..c5d5fde --- /dev/null +++ b/Confectionery/ConfectioneryView/FormReportPastryComponents.resx @@ -0,0 +1,69 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + True + + + True + + + True + + \ No newline at end of file diff --git a/Confectionery/ConfectioneryView/Program.cs b/Confectionery/ConfectioneryView/Program.cs index b6afcc3..74a30b4 100644 --- a/Confectionery/ConfectioneryView/Program.cs +++ b/Confectionery/ConfectioneryView/Program.cs @@ -1,4 +1,6 @@ using ConfectioneryBusinessLogic; +using ConfectioneryBusinessLogic.OfficePackage.Implements; +using ConfectioneryBusinessLogic.OfficePackage; using ConfectioneryContracts.BusinessLogicsContracts; using ConfectioneryContracts.StoragesContracts; using ConfectioneryDatabaseImplement.Implements; @@ -38,6 +40,10 @@ namespace ConfectioneryView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -45,6 +51,8 @@ namespace ConfectioneryView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + //services.AddTransient(); } } } \ No newline at end of file