From 80bf9899df3107c0b0d97775804a8a60064a25a0 Mon Sep 17 00:00:00 2001 From: malimova Date: Thu, 25 Apr 2024 23:22:35 +0400 Subject: [PATCH] =?UTF-8?q?+=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=BD=D1=8B=D0=B9=20=D1=8D=D0=BA=D1=81=D0=B5=D0=BB?= =?UTF-8?q?=D1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AbstractSaveToExcel.cs | 22 ++++--- .../ConfectioneryBusinessLogic/ReportLogic.cs | 28 ++------- .../ReportPastryComponentViewModel.cs | 4 +- .../FormReportPastryComponents.Designer.cs | 8 +-- .../FormReportPastryComponents.cs | 4 +- .../FormReportPastryComponents.resx | 62 ++++++++++++++++++- 6 files changed, 88 insertions(+), 40 deletions(-) diff --git a/Confectionery/ConfectioneryBusinessLogic/AbstractSaveToExcel.cs b/Confectionery/ConfectioneryBusinessLogic/AbstractSaveToExcel.cs index 6135ea8..40c2998 100644 --- a/Confectionery/ConfectioneryBusinessLogic/AbstractSaveToExcel.cs +++ b/Confectionery/ConfectioneryBusinessLogic/AbstractSaveToExcel.cs @@ -17,6 +17,7 @@ namespace ConfectioneryBusinessLogic.OfficePackage public void CreateReport(ExcelInfo info) { CreateExcel(info); + InsertCellInWorksheet(new ExcelCellParameters { ColumnName = "A", @@ -24,11 +25,13 @@ namespace ConfectioneryBusinessLogic.OfficePackage Text = info.Title, StyleInfo = ExcelStyleInfoType.Title }); + MergeCells(new ExcelMergeParameters { CellFromName = "A1", CellToName = "C1" }); + uint rowIndex = 2; foreach (var pc in info.PastryComponents) { @@ -36,30 +39,32 @@ namespace ConfectioneryBusinessLogic.OfficePackage { ColumnName = "A", RowIndex = rowIndex, - Text = pc.ComponentName, + Text = pc.PastryName, StyleInfo = ExcelStyleInfoType.Text }); rowIndex++; - foreach (var product in pc.Pastrys) + + foreach (var (Component, Count) in pc.Components) { InsertCellInWorksheet(new ExcelCellParameters { ColumnName = "B", RowIndex = rowIndex, - Text = product.Item1, - StyleInfo = - ExcelStyleInfoType.TextWithBroder + Text = Component, + StyleInfo = ExcelStyleInfoType.TextWithBroder }); + InsertCellInWorksheet(new ExcelCellParameters { ColumnName = "C", RowIndex = rowIndex, - Text = product.Item2.ToString(), - StyleInfo = - ExcelStyleInfoType.TextWithBroder + Text = Count.ToString(), + StyleInfo = ExcelStyleInfoType.TextWithBroder }); + rowIndex++; } + InsertCellInWorksheet(new ExcelCellParameters { ColumnName = "A", @@ -76,6 +81,7 @@ namespace ConfectioneryBusinessLogic.OfficePackage }); rowIndex++; } + SaveExcel(info); } /// diff --git a/Confectionery/ConfectioneryBusinessLogic/ReportLogic.cs b/Confectionery/ConfectioneryBusinessLogic/ReportLogic.cs index 08e255f..55a1e92 100644 --- a/Confectionery/ConfectioneryBusinessLogic/ReportLogic.cs +++ b/Confectionery/ConfectioneryBusinessLogic/ReportLogic.cs @@ -32,30 +32,12 @@ namespace ConfectioneryBusinessLogic /// public List GetPastryComponent() { - var components = _componentStorage.GetFullList(); - var products = _pastryStorage.GetFullList(); - var list = new List(); - foreach (var component in components) + return _pastryStorage.GetFullList().Select(x => new ReportPastryComponentViewModel { - var record = new ReportPastryComponentViewModel - { - ComponentName = component.ComponentName, - Pastrys = new List>(), - TotalCount = 0 - }; - foreach (var product in products) - { - if (product.PastryComponents.ContainsKey(component.Id)) - { - record.Pastrys.Add(new Tuple(product.PastryName, product.PastryComponents[component.Id].Item2)); - record.TotalCount += - product.PastryComponents[component.Id].Item2; - } - } - list.Add(record); - } - return list; + PastryName = x.PastryName, + Components = x.PastryComponents.Select(x => (x.Value.Item1.ComponentName, x.Value.Item2)).ToList(), + TotalCount = x.PastryComponents.Select(x => x.Value.Item2).Sum() + }).ToList(); } /// /// Получение списка заказов за определенный период diff --git a/Confectionery/ConfectioneryContracts/ViewModels/ReportPastryComponentViewModel.cs b/Confectionery/ConfectioneryContracts/ViewModels/ReportPastryComponentViewModel.cs index 6813316..f65c79f 100644 --- a/Confectionery/ConfectioneryContracts/ViewModels/ReportPastryComponentViewModel.cs +++ b/Confectionery/ConfectioneryContracts/ViewModels/ReportPastryComponentViewModel.cs @@ -8,8 +8,8 @@ namespace ConfectioneryContracts.ViewModels { public class ReportPastryComponentViewModel { - public string ComponentName { get; set; } = string.Empty; + public string PastryName { get; set; } = string.Empty; public int TotalCount { get; set; } - public List> Pastrys { get; set; } = new(); + public List<(string Component, int Count)> Components { get; set; } = new(); } } diff --git a/Confectionery/ConfectioneryView/FormReportPastryComponents.Designer.cs b/Confectionery/ConfectioneryView/FormReportPastryComponents.Designer.cs index a018221..d347869 100644 --- a/Confectionery/ConfectioneryView/FormReportPastryComponents.Designer.cs +++ b/Confectionery/ConfectioneryView/FormReportPastryComponents.Designer.cs @@ -44,7 +44,7 @@ dataGridView.BackgroundColor = Color.AliceBlue; dataGridViewCellStyle1.Alignment = DataGridViewContentAlignment.MiddleLeft; dataGridViewCellStyle1.BackColor = SystemColors.Control; - dataGridViewCellStyle1.Font = new Font("Segoe UI", 9F, FontStyle.Regular, GraphicsUnit.Point); + dataGridViewCellStyle1.Font = new Font("Segoe UI", 9F); dataGridViewCellStyle1.ForeColor = SystemColors.WindowText; dataGridViewCellStyle1.SelectionBackColor = SystemColors.Highlight; dataGridViewCellStyle1.SelectionForeColor = SystemColors.HighlightText; @@ -54,7 +54,7 @@ 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.Font = new Font("Segoe UI", 9F); dataGridViewCellStyle2.ForeColor = SystemColors.ControlText; dataGridViewCellStyle2.SelectionBackColor = SystemColors.Highlight; dataGridViewCellStyle2.SelectionForeColor = SystemColors.HighlightText; @@ -64,14 +64,13 @@ dataGridView.Name = "dataGridView"; dataGridViewCellStyle3.Alignment = DataGridViewContentAlignment.MiddleLeft; dataGridViewCellStyle3.BackColor = SystemColors.Control; - dataGridViewCellStyle3.Font = new Font("Segoe UI", 9F, FontStyle.Regular, GraphicsUnit.Point); + dataGridViewCellStyle3.Font = new Font("Segoe UI", 9F); 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; // @@ -115,6 +114,7 @@ Controls.Add(dataGridView); Name = "FormReportPastryComponents"; Text = "Компоненты по изделиям"; + Load += FormReportPastryComponents_Load; ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); ResumeLayout(false); } diff --git a/Confectionery/ConfectioneryView/FormReportPastryComponents.cs b/Confectionery/ConfectioneryView/FormReportPastryComponents.cs index 763058d..3d922f2 100644 --- a/Confectionery/ConfectioneryView/FormReportPastryComponents.cs +++ b/Confectionery/ConfectioneryView/FormReportPastryComponents.cs @@ -35,8 +35,8 @@ namespace ConfectioneryView 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[] { elem.PastryName, "", "" }); + foreach (var listElem in elem.Components) { dataGridView.Rows.Add(new object[] { "", listElem.Item1, listElem.Item2 }); } diff --git a/Confectionery/ConfectioneryView/FormReportPastryComponents.resx b/Confectionery/ConfectioneryView/FormReportPastryComponents.resx index c5d5fde..8a4e322 100644 --- a/Confectionery/ConfectioneryView/FormReportPastryComponents.resx +++ b/Confectionery/ConfectioneryView/FormReportPastryComponents.resx @@ -1,4 +1,64 @@ - + + +