diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs index 7084612..60a9bae 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs @@ -37,6 +37,7 @@ this.reportComponentsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.reportManufactureComponentsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.reportOrdersToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.reportStoresToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.dataGridView = new System.Windows.Forms.DataGridView(); this.buttonCreateOrder = new System.Windows.Forms.Button(); this.buttonTakeOrderInWork = new System.Windows.Forms.Button(); @@ -45,7 +46,7 @@ this.buttonRef = new System.Windows.Forms.Button(); this.buttonFillStore = new System.Windows.Forms.Button(); this.buttonSellManufacture = new System.Windows.Forms.Button(); - this.reportStoresToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.reportManufacturesInStoreToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.menuStrip.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); this.SuspendLayout(); @@ -98,7 +99,8 @@ this.reportComponentsToolStripMenuItem, this.reportManufactureComponentsToolStripMenuItem, this.reportOrdersToolStripMenuItem, - this.reportStoresToolStripMenuItem}); + this.reportStoresToolStripMenuItem, + this.reportManufacturesInStoreToolStripMenuItem}); this.reportToolStripMenuItem.Name = "reportToolStripMenuItem"; this.reportToolStripMenuItem.Size = new System.Drawing.Size(51, 20); this.reportToolStripMenuItem.Text = "Отчет"; @@ -124,6 +126,13 @@ this.reportOrdersToolStripMenuItem.Text = "Список заказов"; this.reportOrdersToolStripMenuItem.Click += new System.EventHandler(this.ReportOrdersToolStripMenuItem_Click); // + // reportStoresToolStripMenuItem + // + this.reportStoresToolStripMenuItem.Name = "reportStoresToolStripMenuItem"; + this.reportStoresToolStripMenuItem.Size = new System.Drawing.Size(218, 22); + this.reportStoresToolStripMenuItem.Text = "Список магазинов"; + this.reportStoresToolStripMenuItem.Click += new System.EventHandler(this.ReportStoresToolStripMenuItem_Click); + // // dataGridView // this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ControlLightLight; @@ -210,12 +219,12 @@ this.buttonSellManufacture.UseVisualStyleBackColor = true; this.buttonSellManufacture.Click += new System.EventHandler(this.ButtonSellManufacture_Click); // - // reportStoresToolStripMenuItem + // reportManufacturesInStoreToolStripMenuItem // - this.reportStoresToolStripMenuItem.Name = "reportStoresToolStripMenuItem"; - this.reportStoresToolStripMenuItem.Size = new System.Drawing.Size(218, 22); - this.reportStoresToolStripMenuItem.Text = "Список магазинов"; - this.reportStoresToolStripMenuItem.Click += new System.EventHandler(this.ReportStoresToolStripMenuItem_Click); + this.reportManufacturesInStoreToolStripMenuItem.Name = "reportManufacturesInStoreToolStripMenuItem"; + this.reportManufacturesInStoreToolStripMenuItem.Size = new System.Drawing.Size(218, 22); + this.reportManufacturesInStoreToolStripMenuItem.Text = "Изделия в магазинах"; + this.reportManufacturesInStoreToolStripMenuItem.Click += new System.EventHandler(this.ReportManufacturesInStoreToolStripMenuItem_Click); // // FormMain // @@ -263,5 +272,6 @@ private ToolStripMenuItem reportManufactureComponentsToolStripMenuItem; private ToolStripMenuItem reportOrdersToolStripMenuItem; private ToolStripMenuItem reportStoresToolStripMenuItem; + private ToolStripMenuItem reportManufacturesInStoreToolStripMenuItem; } } \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs index 7beff79..a568a2a 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs @@ -210,5 +210,15 @@ namespace BlacksmithWorkshopView MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); } } + + private void ReportManufacturesInStoreToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormReportManufacturesInStore)); + if (service is FormReportManufacturesInStore form) + { + form.ShowDialog(); + LoadData(); + } + } } } \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormReportManufacturesInStore.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormReportManufacturesInStore.Designer.cs new file mode 100644 index 0000000..c6d2e67 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormReportManufacturesInStore.Designer.cs @@ -0,0 +1,103 @@ +namespace BlacksmithWorkshopView +{ + partial class FormReportManufacturesInStore + { + /// + /// 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() + { + this.buttonSaveToExcel = new System.Windows.Forms.Button(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.ColumnStore = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.ColumnManufacture = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.ColumnCount = new System.Windows.Forms.DataGridViewTextBoxColumn(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // buttonSaveToExcel + // + this.buttonSaveToExcel.Location = new System.Drawing.Point(12, 6); + this.buttonSaveToExcel.Name = "buttonSaveToExcel"; + this.buttonSaveToExcel.Size = new System.Drawing.Size(188, 23); + this.buttonSaveToExcel.TabIndex = 3; + this.buttonSaveToExcel.Text = "Сохранить в Excel"; + this.buttonSaveToExcel.UseVisualStyleBackColor = true; + this.buttonSaveToExcel.Click += new System.EventHandler(this.ButtonSaveToExcel_Click); + // + // dataGridView + // + this.dataGridView.AllowUserToAddRows = false; + 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.ColumnStore, + this.ColumnManufacture, + this.ColumnCount}); + this.dataGridView.Dock = System.Windows.Forms.DockStyle.Bottom; + this.dataGridView.Location = new System.Drawing.Point(0, 45); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowTemplate.Height = 25; + this.dataGridView.Size = new System.Drawing.Size(800, 405); + this.dataGridView.TabIndex = 2; + // + // ColumnStore + // + this.ColumnStore.HeaderText = "Магазин"; + this.ColumnStore.Name = "ColumnStore"; + // + // ColumnManufacture + // + this.ColumnManufacture.HeaderText = "Изделие"; + this.ColumnManufacture.Name = "ColumnManufacture"; + // + // ColumnCount + // + this.ColumnCount.HeaderText = "Количество"; + this.ColumnCount.Name = "ColumnCount"; + // + // FormReportManufacturesInStore + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.buttonSaveToExcel); + this.Controls.Add(this.dataGridView); + this.Name = "FormReportManufacturesInStore"; + this.Text = "Изделия в магазине"; + this.Load += new System.EventHandler(this.FormReportManufacturesInStore_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private Button buttonSaveToExcel; + private DataGridView dataGridView; + private DataGridViewTextBoxColumn ColumnStore; + private DataGridViewTextBoxColumn ColumnManufacture; + private DataGridViewTextBoxColumn ColumnCount; + } +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormReportManufacturesInStore.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormReportManufacturesInStore.cs new file mode 100644 index 0000000..5cffdbe --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormReportManufacturesInStore.cs @@ -0,0 +1,70 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; + +namespace BlacksmithWorkshopView +{ + public partial class FormReportManufacturesInStore : Form + { + private readonly ILogger _logger; + private readonly IReportLogic _logic; + public FormReportManufacturesInStore(ILogger logger, IReportLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + private void ButtonSaveToExcel_Click(object sender, EventArgs e) + { + using var dialog = new SaveFileDialog + { + Filter = "xlsx|*.xlsx" + }; + if (dialog.ShowDialog() == DialogResult.OK) + { + try + { + _logic.SaveStoresToExcelFile(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); + } + } + } + + private void FormReportManufacturesInStore_Load(object sender, EventArgs e) + { + try + { + var list = _logic.GetManufacturesInStore(); + if (list != null) + { + dataGridView.Rows.Clear(); + foreach (var elem in list) + { + dataGridView.Rows.Add(new object[] { elem.StoreName, "", "" }); + foreach (var listElem in elem.Manufactures) + { + dataGridView.Rows.Add(new object[] { "", listElem.Item1, listElem.Item2}); + } + dataGridView.Rows.Add(new object[] {"Заполнено", $"{elem.HasManufactures} из {elem.MaxManufactures}", ""}); + } + } + _logger.LogInformation("Загрузка списка изделий по компонентам"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка изделий по компонентам"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormReportManufacturesInStore.resx b/BlacksmithWorkshop/BlacksmithWorkshop/FormReportManufacturesInStore.resx new file mode 100644 index 0000000..820e41c --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormReportManufacturesInStore.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/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs b/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs index e964944..0b4e84e 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs @@ -59,6 +59,7 @@ namespace BlacksmithWorkshopView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/ReportLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/ReportLogic.cs index a793215..47ac19b 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/ReportLogic.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/ReportLogic.cs @@ -59,6 +59,26 @@ namespace BlacksmithWorkShopBusinessLogic.BusinessLogics } return list; } + public List GetManufacturesInStore() + { + var stores = _storeStorage.GetFullList(); + var result = new List(); + foreach (var store in stores) + { + var record = new ReportManufactureInStoreViewModel() + { + StoreName = store.StoreName, + MaxManufactures = store.MaxManufactures, + HasManufactures = store.Manufactures.Select(x => x.Value.Item2).Sum() + }; + foreach (var manufacture in store.Manufactures) + { + record.Manufactures.Add((manufacture.Value.Item1.ManufactureName.ToString(), manufacture.Value.Item2)); + } + result.Add(record); + } + return result; + } /// /// Получение списка заказов за определенный период /// @@ -121,10 +141,23 @@ namespace BlacksmithWorkShopBusinessLogic.BusinessLogics }); } /// - /// Сохранение заказов в файл-Pdf + /// Сохранение информации о магазинах в файл-Excel /// /// - public void SaveOrdersToPdfFile(ReportBindingModel model) + public void SaveStoresToExcelFile(ReportBindingModel model) + { + _saveToExcel.CreateStoresReport(new ExcelInfo + { + FileName = model.FileName, + Title = "Список магазинов", + ManufacturesInStore = GetManufacturesInStore() + }); + } + /// + /// Сохранение заказов в файл-Pdf + /// + /// + public void SaveOrdersToPdfFile(ReportBindingModel model) { _saveToPdf.CreateDoc(new PdfInfo { diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/AbstractSaveToExcel.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/AbstractSaveToExcel.cs index c34ec4d..c1c4d8c 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/AbstractSaveToExcel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/AbstractSaveToExcel.cs @@ -1,5 +1,6 @@ using BlacksmithWorkshopBusinessLogic.OfficePackage.HelperEnums; using BlacksmithWorkshopBusinessLogic.OfficePackage.HelperModels; +using DocumentFormat.OpenXml.Drawing; namespace BlacksmithWorkshopBusinessLogic.OfficePackage { @@ -109,11 +110,95 @@ namespace BlacksmithWorkshopBusinessLogic.OfficePackage } SaveExcel(info); } - /// - /// Создание excel-файла - /// - /// - protected abstract void CreateExcel(ExcelInfo info); + /// + /// Создание отчета + /// + /// + public void CreateStoresReport(ExcelInfo info) + { + CreateExcel(info); + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "A", + RowIndex = 1, + Text = info.Title, + StyleInfo = ExcelStyleInfoType.Title + }); + MergeCells(new ExcelMergeParameters + { + CellFromName = "A1", + CellToName = "C1" + }); + uint rowIndex = 2; + foreach (var MIS in info.ManufacturesInStore) + { + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "A", + RowIndex = rowIndex, + Text = MIS.StoreName, + 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 + }); + rowIndex++; + foreach (var rec in MIS.Manufactures) + { + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "B", + RowIndex = rowIndex, + Text = rec.Item1, + StyleInfo = + ExcelStyleInfoType.TextWithBorder + }); + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "C", + RowIndex = rowIndex, + Text = rec.Item2.ToString(), + StyleInfo = + ExcelStyleInfoType.TextWithBorder + }); + rowIndex++; + } + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "A", + RowIndex = rowIndex, + Text = "Заполнено", + StyleInfo = + ExcelStyleInfoType.TextWithBorder + }); + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "B", + RowIndex = rowIndex, + Text = $"{MIS.HasManufactures} из {MIS.MaxManufactures}", + StyleInfo = + ExcelStyleInfoType.TextWithBorder + }); + rowIndex++; + } + SaveExcel(info); + } + /// + /// Создание excel-файла + /// + /// + protected abstract void CreateExcel(ExcelInfo info); /// /// Добавляем новую ячейку в лист /// diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs index f00ffb2..ae0b2b6 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs @@ -7,5 +7,6 @@ namespace BlacksmithWorkshopBusinessLogic.OfficePackage.HelperModels public string FileName { get; set; } = string.Empty; public string Title { get; set; } = string.Empty; public List ManufactureComponents { get; set; } = new(); + public List ManufacturesInStore { get; set; } = new(); } } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IReportLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IReportLogic.cs index 7a965d6..8978ef7 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IReportLogic.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IReportLogic.cs @@ -17,6 +17,12 @@ namespace BlacksmithWorkshopContracts.BusinessLogicsContracts /// List GetOrders(ReportBindingModel model); /// + /// Получение списка изделий в магазине + /// + /// + /// + List GetManufacturesInStore(); + /// /// Сохранение компонент в файл-Word /// /// @@ -36,5 +42,10 @@ namespace BlacksmithWorkshopContracts.BusinessLogicsContracts /// /// void SaveStoresToWordFile(ReportBindingModel model); + /// + /// Сохранение магазинов в файл-Excel + /// + /// + void SaveStoresToExcelFile(ReportBindingModel model); } } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ReportManufactureInStoreViewModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ReportManufactureInStoreViewModel.cs new file mode 100644 index 0000000..699f5bb --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ReportManufactureInStoreViewModel.cs @@ -0,0 +1,10 @@ +namespace BlacksmithWorkshopContracts.ViewModels +{ + public class ReportManufactureInStoreViewModel + { + public string StoreName { get; set; } = string.Empty; + public int MaxManufactures { get; set; } + public int HasManufactures { get; set; } + public List<(string, int)> Manufactures { get; set; } = new(); + } +}