From 408a86401a04806985cac4973d6a8d71b6324b52 Mon Sep 17 00:00:00 2001 From: ekallin Date: Sat, 30 Mar 2024 18:38:45 +0300 Subject: [PATCH] =?UTF-8?q?=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D1=8F=20=D0=BA=20=D1=82=D1=80=D0=B5=D0=B1=D0=BE=D0=B2?= =?UTF-8?q?=D0=B0=D0=BD=D0=B8=D1=8F=D0=BC=20=D0=BF=D0=BE=20=D1=81=D0=BE?= =?UTF-8?q?=D1=85=D1=80=D0=B0=D0=BD=D0=B5=D0=BD=D0=B8=D1=8E=20=D0=B2=20?= =?UTF-8?q?=D0=B2=D0=BE=D1=80=D0=B4=20=D0=B8=20=D1=8D=D0=BA=D1=81=D0=B5?= =?UTF-8?q?=D0=BB=D1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SushiBar/FormReportSushiComponent.Designer.cs | 48 +++++++++---------- SushiBar/FormReportSushiComponent.cs | 6 +-- SushiBar/FormReportSushiComponent.resx | 4 +- .../OfficePackage/AbstractSaveToExcel.cs | 18 ++++--- .../OfficePackage/AbstractSaveToWord.cs | 9 +++- .../OfficePackage/Implements/SaveToExcel.cs | 48 +++++++------------ .../OfficePackage/Implements/SaveToPdf.cs | 2 +- SushiBarBusinessLogic/Reportlogic.cs | 14 +++--- .../ReportSushiComponentViewModel.cs | 4 +- 9 files changed, 70 insertions(+), 83 deletions(-) diff --git a/SushiBar/FormReportSushiComponent.Designer.cs b/SushiBar/FormReportSushiComponent.Designer.cs index 6cee7a8..587aa7c 100644 --- a/SushiBar/FormReportSushiComponent.Designer.cs +++ b/SushiBar/FormReportSushiComponent.Designer.cs @@ -29,10 +29,10 @@ private void InitializeComponent() { dataGridView1 = new DataGridView(); - Component = new DataGridViewTextBoxColumn(); - Sushi = new DataGridViewTextBoxColumn(); - Count = new DataGridViewTextBoxColumn(); buttonSaveToExcel = new Button(); + Sushi = new DataGridViewTextBoxColumn(); + Component = new DataGridViewTextBoxColumn(); + Count = new DataGridViewTextBoxColumn(); ((System.ComponentModel.ISupportInitialize)dataGridView1).BeginInit(); SuspendLayout(); // @@ -41,7 +41,7 @@ dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; dataGridView1.BackgroundColor = Color.LightGoldenrodYellow; dataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; - dataGridView1.Columns.AddRange(new DataGridViewColumn[] { Component, Sushi, Count }); + dataGridView1.Columns.AddRange(new DataGridViewColumn[] { Sushi, Component, Count }); dataGridView1.Dock = DockStyle.Bottom; dataGridView1.Location = new Point(0, 57); dataGridView1.Name = "dataGridView1"; @@ -50,24 +50,6 @@ dataGridView1.Size = new Size(800, 448); dataGridView1.TabIndex = 0; // - // Component - // - Component.HeaderText = "Компонент"; - Component.MinimumWidth = 6; - Component.Name = "Component"; - // - // Sushi - // - Sushi.HeaderText = "Суши"; - Sushi.MinimumWidth = 6; - Sushi.Name = "Sushi"; - // - // Count - // - Count.HeaderText = "Количество"; - Count.MinimumWidth = 6; - Count.Name = "Count"; - // // buttonSaveToExcel // buttonSaveToExcel.BackColor = Color.Goldenrod; @@ -79,6 +61,24 @@ buttonSaveToExcel.UseVisualStyleBackColor = false; buttonSaveToExcel.Click += ButtonSaveToExcel_Click; // + // Sushi + // + Sushi.HeaderText = "Суши"; + Sushi.MinimumWidth = 6; + Sushi.Name = "Sushi"; + // + // Component + // + Component.HeaderText = "Компонент"; + Component.MinimumWidth = 6; + Component.Name = "Component"; + // + // Count + // + Count.HeaderText = "Количество"; + Count.MinimumWidth = 6; + Count.Name = "Count"; + // // FormReportSushiComponent // AutoScaleDimensions = new SizeF(8F, 20F); @@ -88,7 +88,7 @@ Controls.Add(dataGridView1); Name = "FormReportSushiComponent"; Text = "Компоненты по изделиям"; - Load += FormReportProductComponents_Load; + Load += FormReportSushiComponents_Load; ((System.ComponentModel.ISupportInitialize)dataGridView1).EndInit(); ResumeLayout(false); } @@ -97,8 +97,8 @@ private DataGridView dataGridView1; private Button buttonSaveToExcel; - private DataGridViewTextBoxColumn Component; private DataGridViewTextBoxColumn Sushi; + private DataGridViewTextBoxColumn Component; private DataGridViewTextBoxColumn Count; } } \ No newline at end of file diff --git a/SushiBar/FormReportSushiComponent.cs b/SushiBar/FormReportSushiComponent.cs index 2019ab2..2608887 100644 --- a/SushiBar/FormReportSushiComponent.cs +++ b/SushiBar/FormReportSushiComponent.cs @@ -14,7 +14,7 @@ namespace SushiBarView _logger = logger; _logic = logic; } - private void FormReportProductComponents_Load(object sender, EventArgs e) + private void FormReportSushiComponents_Load(object sender, EventArgs e) { try { @@ -24,8 +24,8 @@ namespace SushiBarView dataGridView1.Rows.Clear(); foreach (var elem in dict) { - dataGridView1.Rows.Add(new object[] { elem.ComponentName, "", "" }); - foreach (var listElem in elem.Sushis) + dataGridView1.Rows.Add(new object[] { elem.SushiName, "", "" }); + foreach (var listElem in elem.Components) { dataGridView1.Rows.Add(new object[] { "", listElem.Item1, listElem.Item2 }); } diff --git a/SushiBar/FormReportSushiComponent.resx b/SushiBar/FormReportSushiComponent.resx index 2a73aa9..fc9c1fc 100644 --- a/SushiBar/FormReportSushiComponent.resx +++ b/SushiBar/FormReportSushiComponent.resx @@ -117,10 +117,10 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + True - + True diff --git a/SushiBarBusinessLogic/OfficePackage/AbstractSaveToExcel.cs b/SushiBarBusinessLogic/OfficePackage/AbstractSaveToExcel.cs index 8c30399..7c71989 100644 --- a/SushiBarBusinessLogic/OfficePackage/AbstractSaveToExcel.cs +++ b/SushiBarBusinessLogic/OfficePackage/AbstractSaveToExcel.cs @@ -26,33 +26,31 @@ namespace SushiBarBusinessLogic.OfficePackage CellToName = "C1" }); uint rowIndex = 2; - foreach (var pc in info.SushiComponents) + foreach (var sc in info.SushiComponents) { InsertCellInWorksheet(new ExcelCellParameters { ColumnName = "A", RowIndex = rowIndex, - Text = pc.ComponentName, + Text = sc.SushiName, StyleInfo = ExcelStyleInfoType.Text }); rowIndex++; - foreach (var product in pc.Sushis) + foreach (var component in sc.Components) { InsertCellInWorksheet(new ExcelCellParameters { ColumnName = "B", RowIndex = rowIndex, - Text = product.Item1, - StyleInfo = - ExcelStyleInfoType.TextWithBroder + Text = component.Item1, + StyleInfo = ExcelStyleInfoType.TextWithBroder }); InsertCellInWorksheet(new ExcelCellParameters { ColumnName = "C", RowIndex = rowIndex, - Text = product.Item2.ToString(), - StyleInfo = - ExcelStyleInfoType.TextWithBroder + Text = component.Item2.ToString(), + StyleInfo = ExcelStyleInfoType.TextWithBroder }); rowIndex++; } @@ -67,7 +65,7 @@ namespace SushiBarBusinessLogic.OfficePackage { ColumnName = "C", RowIndex = rowIndex, - Text = pc.TotalCount.ToString(), + Text = sc.TotalCount.ToString(), StyleInfo = ExcelStyleInfoType.Text }); rowIndex++; diff --git a/SushiBarBusinessLogic/OfficePackage/AbstractSaveToWord.cs b/SushiBarBusinessLogic/OfficePackage/AbstractSaveToWord.cs index ea07bf3..560eeeb 100644 --- a/SushiBarBusinessLogic/OfficePackage/AbstractSaveToWord.cs +++ b/SushiBarBusinessLogic/OfficePackage/AbstractSaveToWord.cs @@ -10,7 +10,10 @@ namespace SushiBarBusinessLogic.OfficePackage CreateWord(info); CreateParagraph(new WordParagraph { - Texts = new List<(string, WordTextProperties)> { (info.Title, new WordTextProperties { Bold = true, Size = "24", }) }, + Texts = new List<(string, WordTextProperties)> + { + (info.Title, new WordTextProperties { Bold = true, Size = "24", }) + }, TextProperties = new WordTextProperties { Size = "24", @@ -22,8 +25,10 @@ namespace SushiBarBusinessLogic.OfficePackage CreateParagraph(new WordParagraph { Texts = new List<(string, WordTextProperties)> { - (sushi.SushiName, new WordTextProperties { Size = "24", }) + (sushi.SushiName, new WordTextProperties { Bold = true, Size = "24", }), + (" цена: " + sushi.Price.ToString() + " рублей", new WordTextProperties { Size = "24", }) }, + TextProperties = new WordTextProperties { Size = "24", diff --git a/SushiBarBusinessLogic/OfficePackage/Implements/SaveToExcel.cs b/SushiBarBusinessLogic/OfficePackage/Implements/SaveToExcel.cs index 23d5e2b..c5ba70a 100644 --- a/SushiBarBusinessLogic/OfficePackage/Implements/SaveToExcel.cs +++ b/SushiBarBusinessLogic/OfficePackage/Implements/SaveToExcel.cs @@ -151,30 +151,24 @@ namespace SushiBarBusinessLogic.OfficePackage.Implements var tableStyles = new TableStyles() { Count = 0U, - DefaultTableStyle = - "TableStyleMedium2", + DefaultTableStyle = "TableStyleMedium2", DefaultPivotStyle = "PivotStyleLight16" }; var stylesheetExtensionList = new StylesheetExtensionList(); var stylesheetExtension1 = new StylesheetExtension() { - Uri = - "{EB79DEF2-80B8-43e5-95BD-54CBDDF9020C}" + Uri = "{EB79DEF2-80B8-43e5-95BD-54CBDDF9020C}" }; - stylesheetExtension1.AddNamespaceDeclaration("x14", - "http://schemas.microsoft.com/office/spreadsheetml/2009/9/main"); + stylesheetExtension1.AddNamespaceDeclaration("x14", "http://schemas.microsoft.com/office/spreadsheetml/2009/9/main"); stylesheetExtension1.Append(new SlicerStyles() { - DefaultSlicerStyle = - "SlicerStyleLight1" + DefaultSlicerStyle = "SlicerStyleLight1" }); var stylesheetExtension2 = new StylesheetExtension() { - Uri = - "{9260A510-F301-46a8-8635-F512D64BE5F5}" + Uri = "{9260A510-F301-46a8-8635-F512D64BE5F5}" }; - stylesheetExtension2.AddNamespaceDeclaration("x15", - "http://schemas.microsoft.com/office/spreadsheetml/2010/11/main"); + stylesheetExtension2.AddNamespaceDeclaration("x15", "http://schemas.microsoft.com/office/spreadsheetml/2010/11/main"); stylesheetExtension2.Append(new TimelineStyles() { DefaultTimelineStyle = "TimeSlicerStyleLight1" @@ -242,8 +236,7 @@ namespace SushiBarBusinessLogic.OfficePackage.Implements sheets.Append(sheet); _worksheet = worksheetPart.Worksheet; } - protected override void InsertCellInWorksheet(ExcelCellParameters - excelParams) + protected override void InsertCellInWorksheet(ExcelCellParameters excelParams) { if (_worksheet == null || _shareStringPart == null) { @@ -256,11 +249,9 @@ namespace SushiBarBusinessLogic.OfficePackage.Implements } // Ищем строку, либо добавляем ее Row row; - if (sheetData.Elements().Where(r => r.RowIndex! == - excelParams.RowIndex).Any()) + if (sheetData.Elements().Where(r => r.RowIndex! == excelParams.RowIndex).Any()) { - row = sheetData.Elements().Where(r => r.RowIndex! == - excelParams.RowIndex).First(); + row = sheetData.Elements().Where(r => r.RowIndex! == excelParams.RowIndex).First(); } else { @@ -269,21 +260,18 @@ namespace SushiBarBusinessLogic.OfficePackage.Implements } // Ищем нужную ячейку Cell cell; - if (row.Elements().Where(c => c.CellReference!.Value == - excelParams.CellReference).Any()) + if (row.Elements().Where(c => c.CellReference!.Value == excelParams.CellReference).Any()) { - cell = row.Elements().Where(c => c.CellReference!.Value == - excelParams.CellReference).First(); + cell = row.Elements().Where(c => c.CellReference!.Value == excelParams.CellReference).First(); } else { // Все ячейки должны быть последовательно друг за другом расположены // нужно определить, после какой вставлять - Cell? refCell = null; + Cell? refCell = null; foreach (Cell rowCell in row.Elements()) { - if (string.Compare(rowCell.CellReference!.Value, - excelParams.CellReference, true) > 0) + if (string.Compare(rowCell.CellReference!.Value, excelParams.CellReference, true) > 0) { refCell = rowCell; break; @@ -291,19 +279,15 @@ namespace SushiBarBusinessLogic.OfficePackage.Implements } var newCell = new Cell() { - CellReference = - excelParams.CellReference + CellReference = excelParams.CellReference }; row.InsertBefore(newCell, refCell); cell = newCell; } // вставляем новый текст - _shareStringPart.SharedStringTable.AppendChild(new - SharedStringItem(new Text(excelParams.Text))); + _shareStringPart.SharedStringTable.AppendChild(new SharedStringItem(new Text(excelParams.Text))); _shareStringPart.SharedStringTable.Save(); - cell.CellValue = new - CellValue((_shareStringPart.SharedStringTable.Elements().Count( - ) - 1).ToString()); + cell.CellValue = new CellValue((_shareStringPart.SharedStringTable.Elements().Count() - 1).ToString()); cell.DataType = new EnumValue(CellValues.SharedString); cell.StyleIndex = GetStyleValue(excelParams.StyleInfo); } diff --git a/SushiBarBusinessLogic/OfficePackage/Implements/SaveToPdf.cs b/SushiBarBusinessLogic/OfficePackage/Implements/SaveToPdf.cs index 98f6b40..a5840f7 100644 --- a/SushiBarBusinessLogic/OfficePackage/Implements/SaveToPdf.cs +++ b/SushiBarBusinessLogic/OfficePackage/Implements/SaveToPdf.cs @@ -95,4 +95,4 @@ namespace SushiBarBusinessLogic.OfficePackage.Implements renderer.PdfDocument.Save(info.FileName); } } -} \ No newline at end of file +} \ No newline at end of file diff --git a/SushiBarBusinessLogic/Reportlogic.cs b/SushiBarBusinessLogic/Reportlogic.cs index 588da4f..7397e78 100644 --- a/SushiBarBusinessLogic/Reportlogic.cs +++ b/SushiBarBusinessLogic/Reportlogic.cs @@ -37,19 +37,19 @@ namespace SushiBarBusinessLogic var components = _componentStorage.GetFullList(); var sushis = _sushiStorage.GetFullList(); var list = new List(); - foreach (var component in components) + foreach (var sushi in sushis) { var record = new ReportSushiComponentViewModel { - ComponentName = component.ComponentName, - Sushis = new List>(), + SushiName = sushi.SushiName, + Components = new List>(), TotalCount = 0 }; - foreach (var sushi in sushis) + foreach (var component in components) { if (sushi.SushiComponents.ContainsKey(component.Id)) { - record.Sushis.Add(new Tuple(sushi.SushiName, sushi.SushiComponents[component.Id].Item2)); + record.Components.Add(new Tuple(component.ComponentName, sushi.SushiComponents[component.Id].Item2)); record.TotalCount += sushi.SushiComponents[component.Id].Item2; } } @@ -85,7 +85,7 @@ namespace SushiBarBusinessLogic _saveToWord.CreateDoc(new WordInfo { FileName = model.FileName, - Title = "Список компонент", + Title = "Список суши", Sushi = _sushiStorage.GetFullList() }); } @@ -98,7 +98,7 @@ namespace SushiBarBusinessLogic _saveToExcel.CreateReport(new ExcelInfo { FileName = model.FileName, - Title = "Список компонент", + Title = "Список изделий", SushiComponents = GetSushiComponent() }); } diff --git a/SushiBarContracts/ViewModels/ReportSushiComponentViewModel.cs b/SushiBarContracts/ViewModels/ReportSushiComponentViewModel.cs index f01efcb..a9b68b4 100644 --- a/SushiBarContracts/ViewModels/ReportSushiComponentViewModel.cs +++ b/SushiBarContracts/ViewModels/ReportSushiComponentViewModel.cs @@ -2,9 +2,9 @@ { public class ReportSushiComponentViewModel { - public string ComponentName { get; set; } = string.Empty; + public string SushiName { get; set; } = string.Empty; public int TotalCount { get; set; } - public List> Sushis { get; set; } = new(); + public List> Components { get; set; } = new(); } }