diff --git a/LawFirm/LawFirm/FormMain.Designer.cs b/LawFirm/LawFirm/FormMain.Designer.cs index e9caa6d..f9a969a 100644 --- a/LawFirm/LawFirm/FormMain.Designer.cs +++ b/LawFirm/LawFirm/FormMain.Designer.cs @@ -37,6 +37,7 @@ this.списокДокументовToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.бланкиПоДокументамToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.списокЗаказовToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.списокМагазиновToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.dataGridView = new System.Windows.Forms.DataGridView(); this.buttonCreateOrder = new System.Windows.Forms.Button(); this.buttonSetToWork = new System.Windows.Forms.Button(); @@ -45,7 +46,7 @@ this.buttonUpdate = new System.Windows.Forms.Button(); this.buttonSupplyShop = new System.Windows.Forms.Button(); this.buttonSellDocuments = new System.Windows.Forms.Button(); - this.списокМагазиновToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.документыВМагазинахToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.menuStrip.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); this.SuspendLayout(); @@ -99,7 +100,8 @@ this.списокДокументовToolStripMenuItem, this.бланкиПоДокументамToolStripMenuItem, this.списокЗаказовToolStripMenuItem, - this.списокМагазиновToolStripMenuItem}); + this.списокМагазиновToolStripMenuItem, + this.документыВМагазинахToolStripMenuItem}); this.отчетыToolStripMenuItem.Name = "отчетыToolStripMenuItem"; this.отчетыToolStripMenuItem.Size = new System.Drawing.Size(73, 24); this.отчетыToolStripMenuItem.Text = "Отчеты"; @@ -107,24 +109,31 @@ // списокДокументовToolStripMenuItem // this.списокДокументовToolStripMenuItem.Name = "списокДокументовToolStripMenuItem"; - this.списокДокументовToolStripMenuItem.Size = new System.Drawing.Size(252, 26); + this.списокДокументовToolStripMenuItem.Size = new System.Drawing.Size(259, 26); this.списокДокументовToolStripMenuItem.Text = "Список документов"; this.списокДокументовToolStripMenuItem.Click += new System.EventHandler(this.списокДокументовToolStripMenuItem_Click); // // бланкиПоДокументамToolStripMenuItem // this.бланкиПоДокументамToolStripMenuItem.Name = "бланкиПоДокументамToolStripMenuItem"; - this.бланкиПоДокументамToolStripMenuItem.Size = new System.Drawing.Size(252, 26); + this.бланкиПоДокументамToolStripMenuItem.Size = new System.Drawing.Size(259, 26); this.бланкиПоДокументамToolStripMenuItem.Text = "Бланки по документам"; this.бланкиПоДокументамToolStripMenuItem.Click += new System.EventHandler(this.бланкиПоДокументамToolStripMenuItem_Click); // // списокЗаказовToolStripMenuItem // this.списокЗаказовToolStripMenuItem.Name = "списокЗаказовToolStripMenuItem"; - this.списокЗаказовToolStripMenuItem.Size = new System.Drawing.Size(252, 26); + this.списокЗаказовToolStripMenuItem.Size = new System.Drawing.Size(259, 26); this.списокЗаказовToolStripMenuItem.Text = "Список заказов"; this.списокЗаказовToolStripMenuItem.Click += new System.EventHandler(this.списокЗаказовToolStripMenuItem_Click); // + // списокМагазиновToolStripMenuItem + // + this.списокМагазиновToolStripMenuItem.Name = "списокМагазиновToolStripMenuItem"; + this.списокМагазиновToolStripMenuItem.Size = new System.Drawing.Size(259, 26); + this.списокМагазиновToolStripMenuItem.Text = "Список магазинов"; + this.списокМагазиновToolStripMenuItem.Click += new System.EventHandler(this.списокМагазиновToolStripMenuItem_Click); + // // dataGridView // this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; @@ -205,12 +214,12 @@ this.buttonSellDocuments.UseVisualStyleBackColor = true; this.buttonSellDocuments.Click += new System.EventHandler(this.buttonSellDocuments_Click); // - // списокМагазиновToolStripMenuItem + // документыВМагазинахToolStripMenuItem // - this.списокМагазиновToolStripMenuItem.Name = "списокМагазиновToolStripMenuItem"; - this.списокМагазиновToolStripMenuItem.Size = new System.Drawing.Size(252, 26); - this.списокМагазиновToolStripMenuItem.Text = "Список магазинов"; - this.списокМагазиновToolStripMenuItem.Click += new System.EventHandler(this.списокМагазиновToolStripMenuItem_Click); + this.документыВМагазинахToolStripMenuItem.Name = "документыВМагазинахToolStripMenuItem"; + this.документыВМагазинахToolStripMenuItem.Size = new System.Drawing.Size(259, 26); + this.документыВМагазинахToolStripMenuItem.Text = "Документы в магазинах"; + this.документыВМагазинахToolStripMenuItem.Click += new System.EventHandler(this.документыВМагазинахToolStripMenuItem_Click); // // FormMain // @@ -258,5 +267,6 @@ private Button buttonSupplyShop; private Button buttonSellDocuments; private ToolStripMenuItem списокМагазиновToolStripMenuItem; + private ToolStripMenuItem документыВМагазинахToolStripMenuItem; } } \ No newline at end of file diff --git a/LawFirm/LawFirm/FormMain.cs b/LawFirm/LawFirm/FormMain.cs index 513b5d8..8b2f7bd 100644 --- a/LawFirm/LawFirm/FormMain.cs +++ b/LawFirm/LawFirm/FormMain.cs @@ -117,6 +117,15 @@ namespace LawFirmView } } + private void документыВМагазинахToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormReportShopDocuments)); + if (service is FormReportShopDocuments form) + { + form.ShowDialog(); + } + } + private void магазиныToolStripMenuItem_Click(object sender, EventArgs e) { var service = Program.ServiceProvider?.GetService(typeof(FormShops)); diff --git a/LawFirm/LawFirm/FormReportShopDocuments.Designer.cs b/LawFirm/LawFirm/FormReportShopDocuments.Designer.cs new file mode 100644 index 0000000..4cf865e --- /dev/null +++ b/LawFirm/LawFirm/FormReportShopDocuments.Designer.cs @@ -0,0 +1,107 @@ +namespace LawFirmView +{ + partial class FormReportShopDocuments + { + /// + /// 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.Shop = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.Document = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.Count = new System.Windows.Forms.DataGridViewTextBoxColumn(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // buttonSaveToExcel + // + this.buttonSaveToExcel.Location = new System.Drawing.Point(12, 8); + this.buttonSaveToExcel.Name = "buttonSaveToExcel"; + this.buttonSaveToExcel.Size = new System.Drawing.Size(176, 29); + this.buttonSaveToExcel.TabIndex = 0; + this.buttonSaveToExcel.Text = "Сохранить в Excel"; + this.buttonSaveToExcel.UseVisualStyleBackColor = true; + this.buttonSaveToExcel.Click += new System.EventHandler(this.buttonSaveToExcel_Click); + // + // dataGridView + // + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.Shop, + this.Document, + this.Count}); + this.dataGridView.Location = new System.Drawing.Point(12, 43); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(776, 395); + this.dataGridView.TabIndex = 1; + // + // Shop + // + this.Shop.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; + this.Shop.HeaderText = "Магазин"; + this.Shop.MinimumWidth = 6; + this.Shop.Name = "Shop"; + // + // Document + // + this.Document.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; + this.Document.HeaderText = "Документ"; + this.Document.MinimumWidth = 6; + this.Document.Name = "Document"; + // + // Count + // + this.Count.HeaderText = "Количество"; + this.Count.MinimumWidth = 6; + this.Count.Name = "Count"; + this.Count.Width = 125; + // + // FormReportShopDocuments + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.dataGridView); + this.Controls.Add(this.buttonSaveToExcel); + this.Name = "FormReportShopDocuments"; + this.Text = "Документы в магазинах"; + this.Load += new System.EventHandler(this.FormReportShopDocuments_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private Button buttonSaveToExcel; + private DataGridView dataGridView; + private DataGridViewTextBoxColumn Shop; + private DataGridViewTextBoxColumn Document; + private DataGridViewTextBoxColumn Count; + } +} \ No newline at end of file diff --git a/LawFirm/LawFirm/FormReportShopDocuments.cs b/LawFirm/LawFirm/FormReportShopDocuments.cs new file mode 100644 index 0000000..63bbb56 --- /dev/null +++ b/LawFirm/LawFirm/FormReportShopDocuments.cs @@ -0,0 +1,85 @@ +using LawFirmBusinessLogic.BusinessLogics; +using LawFirmContracts.BindingModels; +using LawFirmContracts.BusinessLogicContracts; +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 LawFirmView +{ + public partial class FormReportShopDocuments : Form + { + private readonly ILogger _logger; + private readonly IReportLogic _logic; + + public FormReportShopDocuments(ILogger logger, IReportLogic reportLogic) + { + InitializeComponent(); + _logger = logger; + _logic = reportLogic; + } + + private void buttonSaveToExcel_Click(object sender, EventArgs e) + { + using var dialog = new SaveFileDialog + { + Filter = "xlsx|*.xlsx" + }; + if (dialog.ShowDialog() == DialogResult.OK) + { + try + { + _logic.SaveShopDocumentsToExcelFile(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 FormReportShopDocuments_Load(object sender, EventArgs e) + { + try + { + var dict = _logic.GetShopDocuments(); + if (dict != null) + { + dataGridView.Rows.Clear(); + foreach (var elem in dict) + { + dataGridView.Rows.Add(new object[] { elem.ShopName, "", "" }); + foreach (var listElem in elem.Documents) + { + dataGridView.Rows.Add(new object[] { "", listElem.Item1, listElem.Item2 }); + } + dataGridView.Rows.Add(new object[] { "Всего:", "", elem.Count }); + dataGridView.Rows.Add(Array.Empty()); + } + } + _logger.LogInformation("Загрузка списка магазинов с изделиями в них"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка магазинов с изделиями в них"); + + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } +} diff --git a/LawFirm/LawFirm/FormReportShopDocuments.resx b/LawFirm/LawFirm/FormReportShopDocuments.resx new file mode 100644 index 0000000..f8b9c56 --- /dev/null +++ b/LawFirm/LawFirm/FormReportShopDocuments.resx @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + True + + + True + + + True + + \ No newline at end of file diff --git a/LawFirm/LawFirm/Program.cs b/LawFirm/LawFirm/Program.cs index 011ff2e..58b4590 100644 --- a/LawFirm/LawFirm/Program.cs +++ b/LawFirm/LawFirm/Program.cs @@ -67,6 +67,7 @@ namespace LawFirm services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); } } diff --git a/LawFirm/LawFirmBusinessLogic/BusinessLogics/ReportLogic.cs b/LawFirm/LawFirmBusinessLogic/BusinessLogics/ReportLogic.cs index 0c5ae26..049e1b9 100644 --- a/LawFirm/LawFirmBusinessLogic/BusinessLogics/ReportLogic.cs +++ b/LawFirm/LawFirmBusinessLogic/BusinessLogics/ReportLogic.cs @@ -118,6 +118,36 @@ namespace LawFirmBusinessLogic.BusinessLogics Shops = _shopStorage.GetFullList() }); } + public void SaveShopDocumentsToExcelFile(ReportBindingModel model) + { + _saveToExcel.CreateShopReport(new ExcelInfo + { + FileName = model.FileName, + Title = "Список магазинов с изделиями", + ShopDocuments = GetShopDocuments() + }); + } + public List GetShopDocuments() + { + var shops = _shopStorage.GetFullList(); + var list = new List(); + foreach (var shop in shops) + { + var record = new ReportShopDocumentsViewModel + { + ShopName = shop.Name, + Documents = new List>(), + Count = 0 + }; + foreach (var furnitureCount in shop.ShopDocuments.Values) + { + record.Documents.Add(new Tuple(furnitureCount.Item1.DocumentName, furnitureCount.Item2)); + record.Count += furnitureCount.Item2; + } + list.Add(record); + } + return list; + } } } diff --git a/LawFirm/LawFirmBusinessLogic/OfficePackage/AbstractSaveToExcel.cs b/LawFirm/LawFirmBusinessLogic/OfficePackage/AbstractSaveToExcel.cs index 50dcd3b..5dff52f 100644 --- a/LawFirm/LawFirmBusinessLogic/OfficePackage/AbstractSaveToExcel.cs +++ b/LawFirm/LawFirmBusinessLogic/OfficePackage/AbstractSaveToExcel.cs @@ -27,6 +27,7 @@ namespace LawFirmBusinessLogic.OfficePackage CellToName = "C1" }); uint rowIndex = 2; + foreach (var pc in info.DocumentBlanks) { InsertCellInWorksheet(new ExcelCellParameters @@ -73,6 +74,69 @@ namespace LawFirmBusinessLogic.OfficePackage } SaveExcel(info); } + + public void CreateShopReport(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 pc in info.ShopDocuments) + { + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "A", + RowIndex = rowIndex, + Text = pc.ShopName, + StyleInfo = ExcelStyleInfoType.Text + }); + rowIndex++; + foreach (var (DocumentName, Count) in pc.Documents) + { + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "B", + RowIndex = rowIndex, + Text = DocumentName, + StyleInfo = ExcelStyleInfoType.TextWithBorder + }); + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "C", + RowIndex = rowIndex, + Text = Count.ToString(), + StyleInfo = ExcelStyleInfoType.TextWithBorder + }); + rowIndex++; + } + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "A", + RowIndex = rowIndex, + Text = "Итого", + StyleInfo = ExcelStyleInfoType.Text + }); + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "C", + RowIndex = rowIndex, + Text = pc.Count.ToString(), + StyleInfo = ExcelStyleInfoType.Text + }); + rowIndex++; + } + SaveExcel(info); + } /// Создание excel-файла protected abstract void CreateExcel(ExcelInfo info); /// Добавляем новую ячейку в лист diff --git a/LawFirm/LawFirmBusinessLogic/OfficePackage/AbstractSaveToWord.cs b/LawFirm/LawFirmBusinessLogic/OfficePackage/AbstractSaveToWord.cs index 02136f3..69a3aee 100644 --- a/LawFirm/LawFirmBusinessLogic/OfficePackage/AbstractSaveToWord.cs +++ b/LawFirm/LawFirmBusinessLogic/OfficePackage/AbstractSaveToWord.cs @@ -50,7 +50,6 @@ namespace LawFirmBusinessLogic.OfficePackage list.Add(shop.Adress); list.Add(shop.OpeningDate.ToString()); } - //list.AddRange(wordInfo.Shops.Select(x => (x.ShopName, new WordTextProperties { Bold = true, Size = "24" }))); var wordTable = new WordTable { Headers = new List { diff --git a/LawFirm/LawFirmBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs b/LawFirm/LawFirmBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs index f682fa1..4a75226 100644 --- a/LawFirm/LawFirmBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs +++ b/LawFirm/LawFirmBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs @@ -12,5 +12,6 @@ namespace LawFirmBusinessLogic.OfficePackage.HelperModels public string FileName { get; set; } = string.Empty; public string Title { get; set; } = string.Empty; public List DocumentBlanks { get; set; } = new(); + public List ShopDocuments { get; set; } = new(); } } diff --git a/LawFirm/LawFirmContracts/BusinessLogicContracts/IReportLogic.cs b/LawFirm/LawFirmContracts/BusinessLogicContracts/IReportLogic.cs index fcf58e2..4e0fa2b 100644 --- a/LawFirm/LawFirmContracts/BusinessLogicContracts/IReportLogic.cs +++ b/LawFirm/LawFirmContracts/BusinessLogicContracts/IReportLogic.cs @@ -22,5 +22,7 @@ namespace LawFirmContracts.BusinessLogicContracts void SaveOrdersToPdfFile(ReportBindingModel model); // Сохранение магазинов в файл-Word void SaveShopsToWordFile(ReportBindingModel model); + void SaveShopDocumentsToExcelFile(ReportBindingModel model); + List GetShopDocuments(); } } diff --git a/LawFirm/LawFirmContracts/ViewModels/ReportShopDocumentsViewModel.cs b/LawFirm/LawFirmContracts/ViewModels/ReportShopDocumentsViewModel.cs new file mode 100644 index 0000000..e8a7344 --- /dev/null +++ b/LawFirm/LawFirmContracts/ViewModels/ReportShopDocumentsViewModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace LawFirmContracts.ViewModels +{ + public class ReportShopDocumentsViewModel + { + public string ShopName { get; set; } = string.Empty; + public int Count { get; set; } + public List> Documents { get; set; } = new(); + } +}