From 6f865eac973d117c82adc3d3538df166983ab77d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=BA=20=D0=98=D0=B3=D0=BE=D1=80=D1=8C?= Date: Sun, 26 Mar 2023 20:03:51 +0400 Subject: [PATCH] =?UTF-8?q?=D0=B4=D0=BE=D0=B4=D0=B5=D0=BB=D0=BA=D0=B8=20?= =?UTF-8?q?=D0=BF=D0=BE=20=D1=8D=D0=BA=D1=81=D0=B5=D0=BB=D1=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...ormReportManufactureComponents.Designer.cs | 56 +++++++++++-------- .../FormReportManufactureComponents.cs | 8 +-- .../FormReportManufactureComponents.resx | 10 +--- .../BusinessLogics/ReportLogic.cs | 20 ++++--- .../OfficePackage/AbstractSaveToExcel.cs | 42 +++++++++++++- .../ReportManufactureComponentViewModel.cs | 5 +- 6 files changed, 91 insertions(+), 50 deletions(-) diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormReportManufactureComponents.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormReportManufactureComponents.Designer.cs index 277bc75..47d93aa 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormReportManufactureComponents.Designer.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormReportManufactureComponents.Designer.cs @@ -29,13 +29,13 @@ private void InitializeComponent() { this.dataGridView = new System.Windows.Forms.DataGridView(); - this.ColumnComponent = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.ColumnManufacture = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.ColumnCount = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.buttonSaveToExcel = new System.Windows.Forms.Button(); + this.ColumnManufacture = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.ColumnComponent = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.ColumnCount = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.ColumnSum = new System.Windows.Forms.DataGridViewTextBoxColumn(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); this.SuspendLayout(); - this.Load += new System.EventHandler(this.FormReportManufactureComponents_Load); // // dataGridView // @@ -43,9 +43,10 @@ this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ControlLightLight; this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { - this.ColumnComponent, this.ColumnManufacture, - this.ColumnCount}); + this.ColumnComponent, + this.ColumnCount, + this.ColumnSum}); this.dataGridView.Dock = System.Windows.Forms.DockStyle.Bottom; this.dataGridView.Location = new System.Drawing.Point(0, 45); this.dataGridView.Name = "dataGridView"; @@ -53,21 +54,6 @@ this.dataGridView.Size = new System.Drawing.Size(610, 405); this.dataGridView.TabIndex = 0; // - // ColumnComponent - // - this.ColumnComponent.HeaderText = "Компонент"; - this.ColumnComponent.Name = "ColumnComponent"; - // - // ColumnManufacture - // - this.ColumnManufacture.HeaderText = "Изделие"; - this.ColumnManufacture.Name = "ColumnManufacture"; - // - // ColumnCount - // - this.ColumnCount.HeaderText = "Количество"; - this.ColumnCount.Name = "ColumnCount"; - // // buttonSaveToExcel // this.buttonSaveToExcel.Location = new System.Drawing.Point(12, 12); @@ -78,6 +64,26 @@ this.buttonSaveToExcel.UseVisualStyleBackColor = true; this.buttonSaveToExcel.Click += new System.EventHandler(this.ButtonSaveToExcel_Click); // + // ColumnManufacture + // + this.ColumnManufacture.HeaderText = "Изделие"; + this.ColumnManufacture.Name = "ColumnManufacture"; + // + // ColumnComponent + // + this.ColumnComponent.HeaderText = "Компонент"; + this.ColumnComponent.Name = "ColumnComponent"; + // + // ColumnCount + // + this.ColumnCount.HeaderText = "Количество"; + this.ColumnCount.Name = "ColumnCount"; + // + // ColumnSum + // + this.ColumnSum.HeaderText = "Сумма"; + this.ColumnSum.Name = "ColumnSum"; + // // FormReportManufactureComponents // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); @@ -87,6 +93,7 @@ this.Controls.Add(this.dataGridView); this.Name = "FormReportManufactureComponents"; this.Text = "FormReportManufactureComponents"; + this.Load += new System.EventHandler(this.FormReportManufactureComponents_Load); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); this.ResumeLayout(false); @@ -95,9 +102,10 @@ #endregion private DataGridView dataGridView; - private DataGridViewTextBoxColumn ColumnComponent; - private DataGridViewTextBoxColumn ColumnManufacture; - private DataGridViewTextBoxColumn ColumnCount; private Button buttonSaveToExcel; + private DataGridViewTextBoxColumn ColumnManufacture; + private DataGridViewTextBoxColumn ColumnComponent; + private DataGridViewTextBoxColumn ColumnCount; + private DataGridViewTextBoxColumn ColumnSum; } } \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormReportManufactureComponents.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormReportManufactureComponents.cs index 980c8b7..9eeda51 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormReportManufactureComponents.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormReportManufactureComponents.cs @@ -24,12 +24,12 @@ namespace BlacksmithWorkshopView dataGridView.Rows.Clear(); foreach (var elem in dict) { - dataGridView.Rows.Add(new object[] { elem.ComponentName, "", "" }); - foreach (var listElem in elem.Manufactures) + dataGridView.Rows.Add(new object[] { elem.ManufactureName, "", "" }); + foreach (var listElem in elem.Components) { - dataGridView.Rows.Add(new object[] { "", listElem.Item1, listElem.Item2 }); + dataGridView.Rows.Add(new object[] { "", listElem.Item1, listElem.Item2, listElem.Item3 }); } - dataGridView.Rows.Add(new object[] { "Итого", "", elem.TotalCount }); + dataGridView.Rows.Add(new object[] { "Итого", "", elem.TotalCount, elem.TotalSum }); dataGridView.Rows.Add(Array.Empty()); } } diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormReportManufactureComponents.resx b/BlacksmithWorkshop/BlacksmithWorkshop/FormReportManufactureComponents.resx index bd4b7f6..f61b93f 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormReportManufactureComponents.resx +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormReportManufactureComponents.resx @@ -57,22 +57,16 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - True - True - - True - True - + True - + True \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/ReportLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/ReportLogic.cs index 5d78b87..5f1b64b 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/ReportLogic.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/ReportLogic.cs @@ -38,20 +38,22 @@ namespace BlacksmithWorkShopBusinessLogic.BusinessLogics var components = _componentStorage.GetFullList(); var manufactures = _manufactureStorage.GetFullList(); var list = new List(); - foreach (var component in components) + foreach (var manufacture in manufactures) { var record = new ReportManufactureComponentViewModel { - ComponentName = component.ComponentName, - Manufactures = new List<(string, int)>(), - TotalCount = 0 + ManufactureName = manufacture.ManufactureName, + Components = new List<(string, int, double)>(), + TotalCount = 0, + TotalSum = 0 }; - foreach (var manufacture in manufactures) + foreach (var component in components) { if (manufacture.ManufactureComponents.ContainsKey(component.Id)) { - record.Manufactures.Add((manufacture.ManufactureName, manufacture.ManufactureComponents[component.Id].Item2)); + record.Components.Add((component.ComponentName, manufacture.ManufactureComponents[component.Id].Item2, component.Cost * manufacture.ManufactureComponents[component.Id].Item2)); record.TotalCount += manufacture.ManufactureComponents[component.Id].Item2; + record.TotalSum += component.Cost * manufacture.ManufactureComponents[component.Id].Item2; } } list.Add(record); @@ -80,7 +82,7 @@ namespace BlacksmithWorkShopBusinessLogic.BusinessLogics .ToList(); } /// - /// Сохранение компонент в файл-Word + /// Сохранение изделий в файл-Word /// /// public void SaveComponentsToWordFile(ReportBindingModel model) @@ -93,7 +95,7 @@ namespace BlacksmithWorkShopBusinessLogic.BusinessLogics }); } /// - /// Сохранение компонент с указаеним продуктов в файл-Excel + /// Сохранение изделий с указаеним продуктов в файл-Excel /// /// public void SaveManufactureComponentToExcelFile(ReportBindingModel model) @@ -101,7 +103,7 @@ namespace BlacksmithWorkShopBusinessLogic.BusinessLogics _saveToExcel.CreateReport(new ExcelInfo { FileName = model.FileName, - Title = "Список компонент", + Title = "Список изделий", ManufactureComponents = GetManufactureComponent() }); } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/AbstractSaveToExcel.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/AbstractSaveToExcel.cs index 8a0cf7e..c34ec4d 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/AbstractSaveToExcel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/AbstractSaveToExcel.cs @@ -22,7 +22,7 @@ namespace BlacksmithWorkshopBusinessLogic.OfficePackage MergeCells(new ExcelMergeParameters { CellFromName = "A1", - CellToName = "C1" + CellToName = "D1" }); uint rowIndex = 2; foreach (var pc in info.ManufactureComponents) @@ -31,11 +31,32 @@ namespace BlacksmithWorkshopBusinessLogic.OfficePackage { ColumnName = "A", RowIndex = rowIndex, - Text = pc.ComponentName, + Text = pc.ManufactureName, StyleInfo = ExcelStyleInfoType.Text }); + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "B", + RowIndex = rowIndex, + Text = "Компонент", + StyleInfo = ExcelStyleInfoType.TextWithBorder + }); + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "C", + RowIndex = rowIndex, + Text = "Количество", + StyleInfo = ExcelStyleInfoType.TextWithBorder + }); + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "D", + RowIndex = rowIndex, + Text = "Сумма", + StyleInfo = ExcelStyleInfoType.TextWithBorder + }); rowIndex++; - foreach (var (Manufacture, Count) in pc.Manufactures) + foreach (var (Manufacture, Count, Sum) in pc.Components) { InsertCellInWorksheet(new ExcelCellParameters { @@ -53,6 +74,14 @@ namespace BlacksmithWorkshopBusinessLogic.OfficePackage StyleInfo = ExcelStyleInfoType.TextWithBorder }); + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "D", + RowIndex = rowIndex, + Text = Sum.ToString(), + StyleInfo = + ExcelStyleInfoType.TextWithBorder + }); rowIndex++; } InsertCellInWorksheet(new ExcelCellParameters @@ -69,6 +98,13 @@ namespace BlacksmithWorkshopBusinessLogic.OfficePackage Text = pc.TotalCount.ToString(), StyleInfo = ExcelStyleInfoType.Text }); + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "D", + RowIndex = rowIndex, + Text = pc.TotalSum.ToString(), + StyleInfo = ExcelStyleInfoType.Text + }); rowIndex++; } SaveExcel(info); diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ReportManufactureComponentViewModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ReportManufactureComponentViewModel.cs index 6f4f9df..85fe63f 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ReportManufactureComponentViewModel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ReportManufactureComponentViewModel.cs @@ -2,8 +2,9 @@ { public class ReportManufactureComponentViewModel { - public string ComponentName { get; set; } = string.Empty; + public string ManufactureName { get; set; } = string.Empty; public int TotalCount { get; set; } - public List<(string Manufacture, int Count)> Manufactures { get; set; } = new(); + public double TotalSum { get; set; } + public List<(string Component, int Count, double Sum)> Components { get; set; } = new(); } }