From c75f07170421cfd33f9f5757fca728a5abc0d8e2 Mon Sep 17 00:00:00 2001 From: russell Date: Fri, 24 May 2024 23:50:52 +0400 Subject: [PATCH] lab4_hard --- .../BusinessLogics/ReportLogic.cs | 102 +++-- .../OfficePackage/AbstractSaveToExcel.cs | 88 +++- .../OfficePackage/AbstractSaveToPdf.cs | 38 +- .../OfficePackage/AbstractSaveToWord.cs | 41 +- .../HelperEnums/ExcelStyleInfoType.cs | 2 +- .../HelperEnums/PdfParagraphAlignmentType.cs | 2 +- .../OfficePackage/HelperModels/ExcelInfo.cs | 2 + .../OfficePackage/HelperModels/PdfInfo.cs | 2 + .../OfficePackage/HelperModels/WordInfo.cs | 2 + .../OfficePackage/HelperModels/WordTable.cs | 9 + .../OfficePackage/Implements/SaveToExcel.cs | 2 +- .../OfficePackage/Implements/SaveToPdf.cs | 2 +- .../OfficePackage/Implements/SaveToWord.cs | 111 +++++ .../BusinessLogicsContracts/IReportLogic.cs | 33 +- .../ViewModels/ReportOrdersByDateViewModel.cs | 11 + .../ViewModels/ReportOrdersViewModel.cs | 2 +- .../ViewModels/ReportShopReportViewModel.cs | 11 + .../20240418133633_ShopAddition.Designer.cs | 4 +- .../CarRepairShopDatabaseModelSnapshot.cs | 4 +- .../Models/Repair.cs | 2 + CarRepairShop/CarRepairShopView/FormMain.cs | 32 +- .../CarRepairShopView/FormMain.designer.cs | 58 ++- .../FormReportGroupedOrders.cs | 72 +++ .../FormReportGroupedOrders.designer.cs | 91 ++++ .../FormReportGroupedOrders.resx | 120 +++++ .../FormReportRepairComponents.cs | 2 +- .../FormReportShopRepairs.cs | 70 +++ .../FormReportShopRepairs.designer.cs | 114 +++++ .../FormReportShopRepairs.resx | 120 +++++ CarRepairShop/CarRepairShopView/Program.cs | 10 +- .../ReportGroupedOrders.rdlc | 424 ++++++++++++++++++ 31 files changed, 1490 insertions(+), 93 deletions(-) create mode 100644 CarRepairShop/CarRepairShopBusinessLogic/OfficePackage/HelperModels/WordTable.cs create mode 100644 CarRepairShop/CarRepairShopContracts/ViewModels/ReportOrdersByDateViewModel.cs create mode 100644 CarRepairShop/CarRepairShopContracts/ViewModels/ReportShopReportViewModel.cs create mode 100644 CarRepairShop/CarRepairShopView/FormReportGroupedOrders.cs create mode 100644 CarRepairShop/CarRepairShopView/FormReportGroupedOrders.designer.cs create mode 100644 CarRepairShop/CarRepairShopView/FormReportGroupedOrders.resx create mode 100644 CarRepairShop/CarRepairShopView/FormReportShopRepairs.cs create mode 100644 CarRepairShop/CarRepairShopView/FormReportShopRepairs.designer.cs create mode 100644 CarRepairShop/CarRepairShopView/FormReportShopRepairs.resx create mode 100644 CarRepairShop/CarRepairShopView/ReportGroupedOrders.rdlc diff --git a/CarRepairShop/CarRepairShopBusinessLogic/BusinessLogics/ReportLogic.cs b/CarRepairShop/CarRepairShopBusinessLogic/BusinessLogics/ReportLogic.cs index 2d563c8..1dc8067 100644 --- a/CarRepairShop/CarRepairShopBusinessLogic/BusinessLogics/ReportLogic.cs +++ b/CarRepairShop/CarRepairShopBusinessLogic/BusinessLogics/ReportLogic.cs @@ -14,28 +14,27 @@ namespace CarRepairShopBusinessLogic.BusinessLogics private readonly IOrderStorage _orderStorage; + private readonly IShopStorage _shopStorage; + private readonly AbstractSaveToExcel _saveToExcel; private readonly AbstractSaveToWord _saveToWord; private readonly AbstractSaveToPdf _saveToPdf; - public ReportLogic(IRepairStorage repairStorage, IOrderStorage orderStorage, + public ReportLogic(IRepairStorage repairStorage, IComponentStorage componentStorage, IOrderStorage orderStorage, IShopStorage shopStorage, AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf) { _repairStorage = repairStorage; _orderStorage = orderStorage; + _shopStorage = shopStorage; _saveToExcel = saveToExcel; _saveToWord = saveToWord; _saveToPdf = saveToPdf; } - - /// - /// Получение списка компонент с указанием, в каких ремонтах используются - /// - /// - public List GetRepairComponent() + + public List GetRepairComponents() { var repairs = _repairStorage.GetFullList(); @@ -61,11 +60,32 @@ namespace CarRepairShopBusinessLogic.BusinessLogics return list; } - /// - /// Получение списка заказов за определенный период - /// - /// - /// + public List GetShopRepairs() + { + var shops = _shopStorage.GetFullList(); + + var list = new List(); + + foreach (var shop in shops) + { + var record = new ReportShopRepairViewModel + { + ShopName = shop.ShopName, + Repairs = new List<(string Repair, int Count)>(), + TotalCount = 0, + }; + foreach (var repair in shop.ShopRepairs) + { + record.Repairs.Add(new(repair.Value.Item1.RepairName, repair.Value.Item2)); + record.TotalCount += repair.Value.Item2; + } + + list.Add(record); + } + + return list; + } + public List GetOrders(ReportBindingModel model) { return _orderStorage.GetFilteredList(new OrderSearchModel { DateFrom = model.DateFrom, DateTo = model.DateTo }) @@ -80,10 +100,18 @@ namespace CarRepairShopBusinessLogic.BusinessLogics .ToList(); } - /// - /// Сохранение компонент в файл-Word - /// - /// + public List GetGroupedByDateOrders() + { + return _orderStorage.GetFullList().GroupBy(x => x.DateCreate.Date) + .Select(x => new ReportOrdersByDateViewModel + { + Date = x.Key, + Count = x.Count(), + Sum = x.Sum(y => y.Sum) + }) + .ToList(); + } + public void SaveRepairsToWordFile(ReportBindingModel model) { _saveToWord.CreateDoc(new WordInfo @@ -94,24 +122,36 @@ namespace CarRepairShopBusinessLogic.BusinessLogics }); } - /// - /// Сохранение компонент с указаеним продуктов в файл-Excel - /// - /// + public void SaveShopsToWordFile(ReportBindingModel model) + { + _saveToWord.CreateShopsTable(new WordInfo + { + FileName = model.FileName, + Title = "Список магазинов", + Shops = _shopStorage.GetFullList() + }); + } + public void SaveRepairComponentToExcelFile(ReportBindingModel model) { _saveToExcel.CreateReport(new ExcelInfo { FileName = model.FileName, - Title = "Список компонентов", - RepairComponents = GetRepairComponent() + Title = "Список ремонтов", + RepairComponents = GetRepairComponents() + }); + } + + public void SaveShopRepairToExcelFile(ReportBindingModel model) + { + _saveToExcel.CreateShopReport(new ExcelInfo + { + FileName = model.FileName, + Title = "Загруженность магазинов", + ShopRepairs = GetShopRepairs() }); } - /// - /// Сохранение заказов в файл-Pdf - /// - /// public void SaveOrdersToPdfFile(ReportBindingModel model) { _saveToPdf.CreateDoc(new PdfInfo @@ -123,5 +163,15 @@ namespace CarRepairShopBusinessLogic.BusinessLogics Orders = GetOrders(model) }); } + + public void SaveGroupedOrdersToPdfFile(ReportBindingModel model) + { + _saveToPdf.CreateDocWithGroupedOrders(new PdfInfo + { + FileName = model.FileName, + Title = "Заказы по датам", + GroupedOrders = GetGroupedByDateOrders() + }); + } } } \ No newline at end of file diff --git a/CarRepairShop/CarRepairShopBusinessLogic/OfficePackage/AbstractSaveToExcel.cs b/CarRepairShop/CarRepairShopBusinessLogic/OfficePackage/AbstractSaveToExcel.cs index 9380fdf..659b519 100644 --- a/CarRepairShop/CarRepairShopBusinessLogic/OfficePackage/AbstractSaveToExcel.cs +++ b/CarRepairShop/CarRepairShopBusinessLogic/OfficePackage/AbstractSaveToExcel.cs @@ -46,7 +46,7 @@ namespace CarRepairShopBusinessLogic.OfficePackage ColumnName = "B", RowIndex = rowIndex, Text = Component, - StyleInfo = ExcelStyleInfoType.TextWithBroder + StyleInfo = ExcelStyleInfoType.TextWithBorder }); InsertCellInWorksheet(new ExcelCellParameters @@ -54,9 +54,8 @@ namespace CarRepairShopBusinessLogic.OfficePackage ColumnName = "C", RowIndex = rowIndex, Text = Count.ToString(), - StyleInfo = ExcelStyleInfoType.TextWithBroder - }); - + StyleInfo = ExcelStyleInfoType.TextWithBorder + }); rowIndex++; } @@ -80,11 +79,82 @@ namespace CarRepairShopBusinessLogic.OfficePackage SaveExcel(info); } - /// - /// Создание excel-файла - /// - /// - protected abstract void CreateExcel(ExcelInfo 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 sr in info.ShopRepairs) + { + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "A", + RowIndex = rowIndex, + Text = sr.ShopName, + StyleInfo = ExcelStyleInfoType.Text + }); + rowIndex++; + + foreach (var (Repair, Count) in sr.Repairs) + { + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "B", + RowIndex = rowIndex, + Text = Repair, + 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 = sr.TotalCount.ToString(), + StyleInfo = ExcelStyleInfoType.Text + }); + rowIndex++; + } + + SaveExcel(info); + } + + /// + /// Создание excel-файла + /// + /// + protected abstract void CreateExcel(ExcelInfo info); /// /// Добавляем новую ячейку в лист diff --git a/CarRepairShop/CarRepairShopBusinessLogic/OfficePackage/AbstractSaveToPdf.cs b/CarRepairShop/CarRepairShopBusinessLogic/OfficePackage/AbstractSaveToPdf.cs index ecc1bc9..814cda2 100644 --- a/CarRepairShop/CarRepairShopBusinessLogic/OfficePackage/AbstractSaveToPdf.cs +++ b/CarRepairShop/CarRepairShopBusinessLogic/OfficePackage/AbstractSaveToPdf.cs @@ -9,7 +9,8 @@ namespace CarRepairShopBusinessLogic.OfficePackage { CreatePdf(info); CreateParagraph(new PdfParagraph { Text = info.Title, Style = "NormalTitle", ParagraphAlignment = PdfParagraphAlignmentType.Center }); - CreateParagraph(new PdfParagraph { Text = $"с {info.DateFrom.ToShortDateString()} по {info.DateTo.ToShortDateString()}", Style = "Normal", ParagraphAlignment = PdfParagraphAlignmentType.Center }); + CreateParagraph(new PdfParagraph { Text = $"с {info.DateFrom.ToShortDateString()} по {info.DateTo.ToShortDateString()}", + Style = "Normal", ParagraphAlignment = PdfParagraphAlignmentType.Center }); CreateTable(new List { "2cm", "3cm", "6cm", "4cm", "3cm" }); @@ -24,18 +25,47 @@ namespace CarRepairShopBusinessLogic.OfficePackage { CreateRow(new PdfRowParameters { - Texts = new List { order.Id.ToString(), order.DateCreate.ToShortDateString(), order.RepairName, order.OrderStatus, order.Sum.ToString() }, + Texts = new List { order.Id.ToString(), order.DateCreate.ToShortDateString(), order.RepairName, + order.OrderStatus, order.Sum.ToString() }, Style = "Normal", ParagraphAlignment = PdfParagraphAlignmentType.Left }); } - CreateParagraph(new PdfParagraph { Text = $"Итого: {info.Orders.Sum(x => x.Sum)}\t", Style = "Normal", ParagraphAlignment = PdfParagraphAlignmentType.Rigth }); + CreateParagraph(new PdfParagraph { Text = $"Итого: {info.Orders.Sum(x => x.Sum)}\t", Style = "Normal", ParagraphAlignment = PdfParagraphAlignmentType.Right }); + + SavePdf(info); + } + + public void CreateDocWithGroupedOrders(PdfInfo info) + { + CreatePdf(info); + CreateParagraph(new PdfParagraph { Text = info.Title, Style = "NormalTitle", ParagraphAlignment = PdfParagraphAlignmentType.Center }); + + CreateTable(new List { "5cm", "6cm", "5cm" }); + + CreateRow(new PdfRowParameters + { + Texts = new List { "Дата", "Количество заказов", "Сумма" }, + Style = "NormalTitle", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + + foreach (var order in info.GroupedOrders) + { + CreateRow(new PdfRowParameters + { + Texts = new List { order.Date.ToShortDateString(), order.Count.ToString(), order.Sum.ToString() }, + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Left + }); + } + CreateParagraph(new PdfParagraph { Text = $"Итого: {info.GroupedOrders.Sum(x => x.Sum)}\t", Style = "Normal", ParagraphAlignment = PdfParagraphAlignmentType.Right }); SavePdf(info); } /// - /// Создание doc-файла + /// Создание pdf-файла /// /// protected abstract void CreatePdf(PdfInfo info); diff --git a/CarRepairShop/CarRepairShopBusinessLogic/OfficePackage/AbstractSaveToWord.cs b/CarRepairShop/CarRepairShopBusinessLogic/OfficePackage/AbstractSaveToWord.cs index 20e5c7f..f1ef1d7 100644 --- a/CarRepairShop/CarRepairShopBusinessLogic/OfficePackage/AbstractSaveToWord.cs +++ b/CarRepairShop/CarRepairShopBusinessLogic/OfficePackage/AbstractSaveToWord.cs @@ -24,7 +24,7 @@ namespace CarRepairShopBusinessLogic.OfficePackage CreateParagraph(new WordParagraph { Texts = new List<(string, WordTextProperties)> {(repair.RepairName + " - ", new WordTextProperties { Size = "24", Bold = true}), - (repair.Price.ToString(), new WordTextProperties { Size = "24" })}, + (repair.Price.ToString(), new WordTextProperties { Size = "24", })}, TextProperties = new WordTextProperties { Size = "24", @@ -36,6 +36,33 @@ namespace CarRepairShopBusinessLogic.OfficePackage SaveWord(info); } + public void CreateShopsTable(WordInfo info) + { + CreateWord(info); + List> list = new List>(); + foreach (var shop in info.Shops) + { + var ls = new List + { + shop.ShopName, + shop.Address, + shop.DateOpening.ToShortDateString() + }; + list.Add(ls); + } + var wordTable = new WordTable + { + Headers = new List { + "Название", + "Адрес", + "Дата открытия"}, + Columns = 3, + RowText = list + }; + CreateTable(wordTable); + SaveWord(info); + } + /// /// Создание doc-файла /// @@ -49,6 +76,18 @@ namespace CarRepairShopBusinessLogic.OfficePackage /// protected abstract void CreateParagraph(WordParagraph paragraph); + /// + /// Создание таблицы + /// + /// + protected abstract void CreateTable(WordTable table); + + /// + /// Создание строки таблицы + /// + /// + protected abstract void CreateRow(WordParagraph paragraph); + /// /// Сохранение файла /// diff --git a/CarRepairShop/CarRepairShopBusinessLogic/OfficePackage/HelperEnums/ExcelStyleInfoType.cs b/CarRepairShop/CarRepairShopBusinessLogic/OfficePackage/HelperEnums/ExcelStyleInfoType.cs index d48e21a..759c281 100644 --- a/CarRepairShop/CarRepairShopBusinessLogic/OfficePackage/HelperEnums/ExcelStyleInfoType.cs +++ b/CarRepairShop/CarRepairShopBusinessLogic/OfficePackage/HelperEnums/ExcelStyleInfoType.cs @@ -6,6 +6,6 @@ Text, - TextWithBroder + TextWithBorder } } \ No newline at end of file diff --git a/CarRepairShop/CarRepairShopBusinessLogic/OfficePackage/HelperEnums/PdfParagraphAlignmentType.cs b/CarRepairShop/CarRepairShopBusinessLogic/OfficePackage/HelperEnums/PdfParagraphAlignmentType.cs index 4391b45..c7d6da5 100644 --- a/CarRepairShop/CarRepairShopBusinessLogic/OfficePackage/HelperEnums/PdfParagraphAlignmentType.cs +++ b/CarRepairShop/CarRepairShopBusinessLogic/OfficePackage/HelperEnums/PdfParagraphAlignmentType.cs @@ -6,6 +6,6 @@ Left, - Rigth + Right } } \ No newline at end of file diff --git a/CarRepairShop/CarRepairShopBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs b/CarRepairShop/CarRepairShopBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs index c8a5e79..a97b971 100644 --- a/CarRepairShop/CarRepairShopBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs +++ b/CarRepairShop/CarRepairShopBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs @@ -9,5 +9,7 @@ namespace CarRepairShopBusinessLogic.OfficePackage.HelperModels public string Title { get; set; } = string.Empty; public List RepairComponents { get; set; } = new(); + + public List ShopRepairs { get; set; } = new(); } } \ No newline at end of file diff --git a/CarRepairShop/CarRepairShopBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs b/CarRepairShop/CarRepairShopBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs index a5db549..fd8b7ef 100644 --- a/CarRepairShop/CarRepairShopBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs +++ b/CarRepairShop/CarRepairShopBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs @@ -13,5 +13,7 @@ namespace CarRepairShopBusinessLogic.OfficePackage.HelperModels public DateTime DateTo { get; set; } public List Orders { get; set; } = new(); + + public List GroupedOrders { get; set; } = new(); } } \ No newline at end of file diff --git a/CarRepairShop/CarRepairShopBusinessLogic/OfficePackage/HelperModels/WordInfo.cs b/CarRepairShop/CarRepairShopBusinessLogic/OfficePackage/HelperModels/WordInfo.cs index f501435..3afd1bb 100644 --- a/CarRepairShop/CarRepairShopBusinessLogic/OfficePackage/HelperModels/WordInfo.cs +++ b/CarRepairShop/CarRepairShopBusinessLogic/OfficePackage/HelperModels/WordInfo.cs @@ -9,5 +9,7 @@ namespace CarRepairShopBusinessLogic.OfficePackage.HelperModels public string Title { get; set; } = string.Empty; public List Repairs { get; set; } = new(); + + public List Shops { get; set; } = new(); } } \ No newline at end of file diff --git a/CarRepairShop/CarRepairShopBusinessLogic/OfficePackage/HelperModels/WordTable.cs b/CarRepairShop/CarRepairShopBusinessLogic/OfficePackage/HelperModels/WordTable.cs new file mode 100644 index 0000000..4bf9300 --- /dev/null +++ b/CarRepairShop/CarRepairShopBusinessLogic/OfficePackage/HelperModels/WordTable.cs @@ -0,0 +1,9 @@ +namespace CarRepairShopBusinessLogic.OfficePackage.HelperModels +{ + public class WordTable + { + public List Headers { get; set; } = new(); + public List> RowText { get; set; } = new(); + public int Columns { get; set; } + } +} diff --git a/CarRepairShop/CarRepairShopBusinessLogic/OfficePackage/Implements/SaveToExcel.cs b/CarRepairShop/CarRepairShopBusinessLogic/OfficePackage/Implements/SaveToExcel.cs index 256c920..b22a67f 100644 --- a/CarRepairShop/CarRepairShopBusinessLogic/OfficePackage/Implements/SaveToExcel.cs +++ b/CarRepairShop/CarRepairShopBusinessLogic/OfficePackage/Implements/SaveToExcel.cs @@ -144,7 +144,7 @@ namespace CarRepairShopBusinessLogic.OfficePackage.Implements return styleInfo switch { ExcelStyleInfoType.Title => 2U, - ExcelStyleInfoType.TextWithBroder => 1U, + ExcelStyleInfoType.TextWithBorder => 1U, ExcelStyleInfoType.Text => 0U, _ => 0U, }; diff --git a/CarRepairShop/CarRepairShopBusinessLogic/OfficePackage/Implements/SaveToPdf.cs b/CarRepairShop/CarRepairShopBusinessLogic/OfficePackage/Implements/SaveToPdf.cs index 5a8b329..fd6c714 100644 --- a/CarRepairShop/CarRepairShopBusinessLogic/OfficePackage/Implements/SaveToPdf.cs +++ b/CarRepairShop/CarRepairShopBusinessLogic/OfficePackage/Implements/SaveToPdf.cs @@ -20,7 +20,7 @@ namespace CarRepairShopBusinessLogic.OfficePackage.Implements { PdfParagraphAlignmentType.Center => ParagraphAlignment.Center, PdfParagraphAlignmentType.Left => ParagraphAlignment.Left, - PdfParagraphAlignmentType.Rigth => ParagraphAlignment.Right, + PdfParagraphAlignmentType.Right => ParagraphAlignment.Right, _ => ParagraphAlignment.Justify, }; } diff --git a/CarRepairShop/CarRepairShopBusinessLogic/OfficePackage/Implements/SaveToWord.cs b/CarRepairShop/CarRepairShopBusinessLogic/OfficePackage/Implements/SaveToWord.cs index 1a25789..78347ae 100644 --- a/CarRepairShop/CarRepairShopBusinessLogic/OfficePackage/Implements/SaveToWord.cs +++ b/CarRepairShop/CarRepairShopBusinessLogic/OfficePackage/Implements/SaveToWord.cs @@ -3,6 +3,7 @@ using CarRepairShopBusinessLogic.OfficePackage.HelperModels; using DocumentFormat.OpenXml; using DocumentFormat.OpenXml.Packaging; using DocumentFormat.OpenXml.Wordprocessing; +using System.Security.Cryptography; namespace CarRepairShopBusinessLogic.OfficePackage.Implements { @@ -12,6 +13,8 @@ namespace CarRepairShopBusinessLogic.OfficePackage.Implements private Body? _docBody; + private Table? table; + /// /// Получение типа выравнивания /// @@ -119,6 +122,114 @@ namespace CarRepairShopBusinessLogic.OfficePackage.Implements _docBody.AppendChild(docParagraph); } + protected override void CreateTable(WordTable table) + { + if (_docBody == null || table == null) + { + return; + } + Table docTable = new Table(); + TableProperties tableProps = new TableProperties( + new TopBorder + { + Val = new EnumValue(BorderValues.Single), + Size = 12 + }, + new BottomBorder + { + Val = new EnumValue(BorderValues.Single), + Size = 12 + }, + new LeftBorder + { + Val = new EnumValue(BorderValues.Single), + Size = 12 + }, + new RightBorder + { + Val = new EnumValue(BorderValues.Single), + Size = 12 + }, + new InsideHorizontalBorder + { + Val = new EnumValue(BorderValues.Single), + Size = 12 + }, + new InsideVerticalBorder + { + Val = new EnumValue(BorderValues.Single), + Size = 12 + }); + docTable.AppendChild(tableProps); + TableGrid tableGrid = new TableGrid(); + for (int i = 0; i < table.Columns; i++) + { + tableGrid.AppendChild(new GridColumn()); + } + docTable.AppendChild(tableGrid); + TableRow tableRow = new TableRow(); + foreach (var text in table.Headers) + { + tableRow.AppendChild(CreateTableCell(text)); + } + docTable.AppendChild(tableRow); + int height = table.RowText.Count; + int width = table.Columns; + for (int i = 0; i < height; i++) + { + tableRow = new TableRow(); + for (int j = 0; j < width; j++) + { + var element = table.RowText[i][j]; + tableRow.AppendChild(CreateTableCell(element)); + } + docTable.AppendChild(tableRow); + } + + _docBody.AppendChild(docTable); + } + + protected override void CreateRow(WordParagraph paragraph) + { + if (_docBody == null || table == null || paragraph == null) + { + return; + } + TableRow tableRow = new(); + foreach (var column in paragraph.Texts) + { + var tableParagraph = new Paragraph(); + tableParagraph.AppendChild(CreateParagraphProperties(paragraph.TextProperties)); + + var tableRun = new Run(); + var runProperties = new RunProperties(); + runProperties.AppendChild(new FontSize { Val = column.Item2.Size }); + if (column.Item2.Bold) + { + runProperties.AppendChild(new Bold()); + } + tableRun.AppendChild(runProperties); + tableRun.AppendChild(new Text { Text = column.Item1, Space = SpaceProcessingModeValues.Preserve }); + tableParagraph.AppendChild(tableRun); + + TableCell cell = new(); + cell.AppendChild(tableParagraph); + tableRow.AppendChild(cell); + } + table.AppendChild(tableRow); + } + + private TableCell CreateTableCell(string element) + { + var tableParagraph = new Paragraph(); + var run = new Run(); + run.AppendChild(new Text { Text = element }); + tableParagraph.AppendChild(run); + var tableCell = new TableCell(); + tableCell.AppendChild(tableParagraph); + return tableCell; + } + protected override void SaveWord(WordInfo info) { if (_docBody == null || _wordDocument == null) diff --git a/CarRepairShop/CarRepairShopContracts/BusinessLogicsContracts/IReportLogic.cs b/CarRepairShop/CarRepairShopContracts/BusinessLogicsContracts/IReportLogic.cs index 2ab39b7..a9e6840 100644 --- a/CarRepairShop/CarRepairShopContracts/BusinessLogicsContracts/IReportLogic.cs +++ b/CarRepairShop/CarRepairShopContracts/BusinessLogicsContracts/IReportLogic.cs @@ -5,35 +5,24 @@ namespace CarRepairShopContracts.BusinessLogicsContracts { public interface IReportLogic { - /// - /// Получение списка компонент с указанием, в каких ремонтах используются - /// - /// - List GetRepairComponent(); + List GetRepairComponents(); + + List GetShopRepairs(); - /// - /// Получение списка заказов за определенный период - /// - /// - /// List GetOrders(ReportBindingModel model); - /// - /// Сохранение компонент в файл-Word - /// - /// + List GetGroupedByDateOrders(); + void SaveRepairsToWordFile(ReportBindingModel model); - /// - /// Сохранение компонент с указаеним продуктов в файл-Excel - /// - /// + void SaveShopsToWordFile(ReportBindingModel model); + void SaveRepairComponentToExcelFile(ReportBindingModel model); - /// - /// Сохранение заказов в файл-Pdf - /// - /// + void SaveShopRepairToExcelFile(ReportBindingModel model); + void SaveOrdersToPdfFile(ReportBindingModel model); + + void SaveGroupedOrdersToPdfFile(ReportBindingModel model); } } \ No newline at end of file diff --git a/CarRepairShop/CarRepairShopContracts/ViewModels/ReportOrdersByDateViewModel.cs b/CarRepairShop/CarRepairShopContracts/ViewModels/ReportOrdersByDateViewModel.cs new file mode 100644 index 0000000..326b0f5 --- /dev/null +++ b/CarRepairShop/CarRepairShopContracts/ViewModels/ReportOrdersByDateViewModel.cs @@ -0,0 +1,11 @@ +namespace CarRepairShopContracts.ViewModels +{ + public class ReportOrdersByDateViewModel + { + public DateTime Date { get; set; } + + public int Count { get; set; } + + public double Sum { get; set; } + } +} diff --git a/CarRepairShop/CarRepairShopContracts/ViewModels/ReportOrdersViewModel.cs b/CarRepairShop/CarRepairShopContracts/ViewModels/ReportOrdersViewModel.cs index 96329ec..bb94ced 100644 --- a/CarRepairShop/CarRepairShopContracts/ViewModels/ReportOrdersViewModel.cs +++ b/CarRepairShop/CarRepairShopContracts/ViewModels/ReportOrdersViewModel.cs @@ -11,5 +11,5 @@ public string OrderStatus { get; set; } = string.Empty; public double Sum { get; set; } - } + } } \ No newline at end of file diff --git a/CarRepairShop/CarRepairShopContracts/ViewModels/ReportShopReportViewModel.cs b/CarRepairShop/CarRepairShopContracts/ViewModels/ReportShopReportViewModel.cs new file mode 100644 index 0000000..4a2a1a5 --- /dev/null +++ b/CarRepairShop/CarRepairShopContracts/ViewModels/ReportShopReportViewModel.cs @@ -0,0 +1,11 @@ +namespace CarRepairShopContracts.ViewModels +{ + public class ReportShopRepairViewModel + { + public string ShopName { get; set; } = string.Empty; + + public int TotalCount { get; set; } + + public List<(string Repair, int Count)> Repairs { get; set; } = new(); + } +} diff --git a/CarRepairShop/CarRepairShopDatabaseImplement/Migrations/20240418133633_ShopAddition.Designer.cs b/CarRepairShop/CarRepairShopDatabaseImplement/Migrations/20240418133633_ShopAddition.Designer.cs index 764e8fa..06c4668 100644 --- a/CarRepairShop/CarRepairShopDatabaseImplement/Migrations/20240418133633_ShopAddition.Designer.cs +++ b/CarRepairShop/CarRepairShopDatabaseImplement/Migrations/20240418133633_ShopAddition.Designer.cs @@ -209,7 +209,7 @@ namespace CarRepairShopDatabaseImplement.Migrations modelBuilder.Entity("CarRepairShopDatabaseImplement.Models.ShopRepair", b => { b.HasOne("CarRepairShopDatabaseImplement.Models.Repair", "Repair") - .WithMany() + .WithMany("ShopRepairs") .HasForeignKey("RepairId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); @@ -235,6 +235,8 @@ namespace CarRepairShopDatabaseImplement.Migrations b.Navigation("Components"); b.Navigation("Orders"); + + b.Navigation("ShopRepairs"); }); modelBuilder.Entity("CarRepairShopDatabaseImplement.Models.Shop", b => diff --git a/CarRepairShop/CarRepairShopDatabaseImplement/Migrations/CarRepairShopDatabaseModelSnapshot.cs b/CarRepairShop/CarRepairShopDatabaseImplement/Migrations/CarRepairShopDatabaseModelSnapshot.cs index 9867922..14310b2 100644 --- a/CarRepairShop/CarRepairShopDatabaseImplement/Migrations/CarRepairShopDatabaseModelSnapshot.cs +++ b/CarRepairShop/CarRepairShopDatabaseImplement/Migrations/CarRepairShopDatabaseModelSnapshot.cs @@ -207,7 +207,7 @@ namespace CarRepairShopDatabaseImplement.Migrations modelBuilder.Entity("CarRepairShopDatabaseImplement.Models.ShopRepair", b => { b.HasOne("CarRepairShopDatabaseImplement.Models.Repair", "Repair") - .WithMany() + .WithMany("ShopRepairs") .HasForeignKey("RepairId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); @@ -233,6 +233,8 @@ namespace CarRepairShopDatabaseImplement.Migrations b.Navigation("Components"); b.Navigation("Orders"); + + b.Navigation("ShopRepairs"); }); modelBuilder.Entity("CarRepairShopDatabaseImplement.Models.Shop", b => diff --git a/CarRepairShop/CarRepairShopDatabaseImplement/Models/Repair.cs b/CarRepairShop/CarRepairShopDatabaseImplement/Models/Repair.cs index 01a8c4a..7230d8a 100644 --- a/CarRepairShop/CarRepairShopDatabaseImplement/Models/Repair.cs +++ b/CarRepairShop/CarRepairShopDatabaseImplement/Models/Repair.cs @@ -38,6 +38,8 @@ namespace CarRepairShopDatabaseImplement.Models [ForeignKey("RepairId")] public virtual List Orders { get; set; } = new(); + [ForeignKey("RepairId")] + public virtual List ShopRepairs { get; set; } = new(); public static Repair Create(CarRepairShopDatabase context, RepairBindingModel model) { return new Repair() diff --git a/CarRepairShop/CarRepairShopView/FormMain.cs b/CarRepairShop/CarRepairShopView/FormMain.cs index fa708b6..f215514 100644 --- a/CarRepairShop/CarRepairShopView/FormMain.cs +++ b/CarRepairShop/CarRepairShopView/FormMain.cs @@ -1,5 +1,4 @@ -using CarRepairShopBusinessLogic.BusinessLogics; -using CarRepairShopContracts.BindingModels; +using CarRepairShopContracts.BindingModels; using CarRepairShopContracts.BusinessLogicsContracts; using Microsoft.Extensions.Logging; @@ -12,6 +11,7 @@ namespace CarRepairShopView private readonly IOrderLogic _orderLogic; private readonly IReportLogic _reportLogic; + public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic) { InitializeComponent(); @@ -203,5 +203,33 @@ namespace CarRepairShopView } } + + private void СписокМагазиновToolStripMenuItem_Click(object sender, EventArgs e) + { + using var dialog = new SaveFileDialog { Filter = "docx|*.docx" }; + if (dialog.ShowDialog() == DialogResult.OK) + { + _reportLogic.SaveShopsToWordFile(new ReportBindingModel { FileName = dialog.FileName }); + MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } + + private void ЗагруженностьМагазиновToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormReportShopRepairs)); + if (service is FormReportShopRepairs form) + { + form.ShowDialog(); + } + } + + private void ЗаказыПоДатамToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormReportGroupedOrders)); + if (service is FormReportGroupedOrders form) + { + form.ShowDialog(); + } + } } } \ No newline at end of file diff --git a/CarRepairShop/CarRepairShopView/FormMain.designer.cs b/CarRepairShop/CarRepairShopView/FormMain.designer.cs index ccb50b4..f1e13d0 100644 --- a/CarRepairShop/CarRepairShopView/FormMain.designer.cs +++ b/CarRepairShop/CarRepairShopView/FormMain.designer.cs @@ -38,6 +38,9 @@ this.ComponentsToolStripMenuItem = new ToolStripMenuItem(); this.ComponentRepairsToolStripMenuItem = new ToolStripMenuItem(); this.OrdersToolStripMenuItem = new ToolStripMenuItem(); + списокМагазиновToolStripMenuItem = new ToolStripMenuItem(); + загруженностьМагазиновToolStripMenuItem = new ToolStripMenuItem(); + заказыПоДатамToolStripMenuItem = new ToolStripMenuItem(); this.buttonIssuedOrder = new System.Windows.Forms.Button(); this.buttonOrderReady = new System.Windows.Forms.Button(); this.buttonTakeOrderInWork = new System.Windows.Forms.Button(); @@ -54,8 +57,7 @@ this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.справочникиToolStripMenuItem, пополнениеМагазинаToolStripMenuItem, - продажаРемонтовToolStripMenuItem}); - this.справочникиToolStripMenuItem, + продажаРемонтовToolStripMenuItem, this.отчетыToolStripMenuItem}); this.menuStrip1.Location = new System.Drawing.Point(0, 0); this.menuStrip1.Name = "menuStrip1"; @@ -88,9 +90,23 @@ this.ремонтыToolStripMenuItem.Text = "Ремонты"; this.ремонтыToolStripMenuItem.Click += new System.EventHandler(this.РемонтыToolStripMenuItem_Click); // + // магазиныToolStripMenuItem + // + магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem"; + магазиныToolStripMenuItem.Size = new Size(145, 22); + магазиныToolStripMenuItem.Text = "Магазины"; + магазиныToolStripMenuItem.Click += МагазиныToolStripMenuItem_Click; + // + // пополнениеМагазинаToolStripMenuItem + // + пополнениеМагазинаToolStripMenuItem.Name = "пополнениеМагазинаToolStripMenuItem"; + пополнениеМагазинаToolStripMenuItem.Size = new Size(143, 20); + пополнениеМагазинаToolStripMenuItem.Text = "Пополнение магазина"; + пополнениеМагазинаToolStripMenuItem.Click += ПополнениеМагазинаToolStripMenuItem_Click; + // // отчетыToolStripMenuItem // - отчетыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { ComponentsToolStripMenuItem, ComponentRepairsToolStripMenuItem, OrdersToolStripMenuItem }); + отчетыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { ComponentsToolStripMenuItem, ComponentRepairsToolStripMenuItem, OrdersToolStripMenuItem, списокМагазиновToolStripMenuItem, загруженностьМагазиновToolStripMenuItem, заказыПоДатамToolStripMenuItem }); отчетыToolStripMenuItem.Name = "отчетыToolStripMenuItem"; отчетыToolStripMenuItem.Size = new Size(60, 20); отчетыToolStripMenuItem.Text = "Отчеты"; @@ -116,19 +132,26 @@ OrdersToolStripMenuItem.Text = "Список заказов"; OrdersToolStripMenuItem.Click += OrdersToolStripMenuItem_Click; // - // магазиныToolStripMenuItem + // списокМагазиновToolStripMenuItem // - магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem"; - магазиныToolStripMenuItem.Size = new Size(145, 22); - магазиныToolStripMenuItem.Text = "Магазины"; - магазиныToolStripMenuItem.Click += МагазиныToolStripMenuItem_Click; + списокМагазиновToolStripMenuItem.Name = "списокМагазиновToolStripMenuItem"; + списокМагазиновToolStripMenuItem.Size = new Size(235, 22); + списокМагазиновToolStripMenuItem.Text = "Список магазинов"; + списокМагазиновToolStripMenuItem.Click += СписокМагазиновToolStripMenuItem_Click; + // + // загруженностьМагазиновToolStripMenuItem // - // пополнениеМагазинаToolStripMenuItem + загруженностьМагазиновToolStripMenuItem.Name = "загруженностьМагазиновToolStripMenuItem"; + загруженностьМагазиновToolStripMenuItem.Size = new Size(235, 22); + загруженностьМагазиновToolStripMenuItem.Text = "Загруженность магазинов"; + загруженностьМагазиновToolStripMenuItem.Click += ЗагруженностьМагазиновToolStripMenuItem_Click; // - пополнениеМагазинаToolStripMenuItem.Name = "пополнениеМагазинаToolStripMenuItem"; - пополнениеМагазинаToolStripMenuItem.Size = new Size(143, 20); - пополнениеМагазинаToolStripMenuItem.Text = "Пополнение магазина"; - пополнениеМагазинаToolStripMenuItem.Click += ПополнениеМагазинаToolStripMenuItem_Click; + // заказыПоДатамToolStripMenuItem + // + заказыПоДатамToolStripMenuItem.Name = "заказыПоДатамToolStripMenuItem"; + заказыПоДатамToolStripMenuItem.Size = new Size(235, 22); + заказыПоДатамToolStripMenuItem.Text = "Заказы по датам"; + заказыПоДатамToolStripMenuItem.Click += ЗаказыПоДатамToolStripMenuItem_Click; // // buttonIssuedOrder // @@ -254,13 +277,16 @@ private System.Windows.Forms.Button buttonCreateOrder; private System.Windows.Forms.DataGridView dataGridView; private System.Windows.Forms.Button buttonRef; + private ToolStripMenuItem магазиныToolStripMenuItem; + private ToolStripMenuItem пополнениеМагазинаToolStripMenuItem; + private ToolStripMenuItem продажаРемонтовToolStripMenuItem; private ToolStripMenuItem отчетыToolStripMenuItem; private ToolStripMenuItem ComponentsToolStripMenuItem; private ToolStripMenuItem ComponentRepairsToolStripMenuItem; private ToolStripMenuItem OrdersToolStripMenuItem; - private ToolStripMenuItem магазиныToolStripMenuItem; - private ToolStripMenuItem пополнениеМагазинаToolStripMenuItem; - private ToolStripMenuItem продажаРемонтовToolStripMenuItem; + private ToolStripMenuItem списокМагазиновToolStripMenuItem; + private ToolStripMenuItem загруженностьМагазиновToolStripMenuItem; + private ToolStripMenuItem заказыПоДатамToolStripMenuItem; } } diff --git a/CarRepairShop/CarRepairShopView/FormReportGroupedOrders.cs b/CarRepairShop/CarRepairShopView/FormReportGroupedOrders.cs new file mode 100644 index 0000000..edce31d --- /dev/null +++ b/CarRepairShop/CarRepairShopView/FormReportGroupedOrders.cs @@ -0,0 +1,72 @@ +using CarRepairShopContracts.BindingModels; +using CarRepairShopContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +using Microsoft.Reporting.WinForms; + +namespace CarRepairShopView +{ + public partial class FormReportGroupedOrders : Form + { + private readonly ReportViewer reportViewer; + + private readonly ILogger _logger; + + private readonly IReportLogic _logic; + + public FormReportGroupedOrders(ILogger logger, IReportLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + reportViewer = new ReportViewer + { + Dock = DockStyle.Fill + }; + reportViewer.LocalReport.LoadReportDefinition(new FileStream("ReportGroupedOrders.rdlc", FileMode.Open)); + Controls.Clear(); + Controls.Add(reportViewer); + Controls.Add(panel); + } + + private void ButtonCreateReport_Click(object sender, EventArgs e) + { + try + { + var dataSource = _logic.GetGroupedByDateOrders(); + var source = new ReportDataSource("DataSetOrders", dataSource); + reportViewer.LocalReport.DataSources.Clear(); + reportViewer.LocalReport.DataSources.Add(source); + + reportViewer.RefreshReport(); + _logger.LogInformation("Loading list of grouped orders"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Loading list of grouped orders error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonToPdf_Click(object sender, EventArgs e) + { + using var dialog = new SaveFileDialog { Filter = "pdf|*.pdf" }; + if (dialog.ShowDialog() == DialogResult.OK) + { + try + { + _logic.SaveGroupedOrdersToPdfFile(new ReportBindingModel + { + FileName = dialog.FileName, + }); + _logger.LogInformation("Saving list of grouped orders"); + MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + catch (Exception ex) + { + _logger.LogError(ex, "Saving list of grouped orders error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } +} \ No newline at end of file diff --git a/CarRepairShop/CarRepairShopView/FormReportGroupedOrders.designer.cs b/CarRepairShop/CarRepairShopView/FormReportGroupedOrders.designer.cs new file mode 100644 index 0000000..3bd7722 --- /dev/null +++ b/CarRepairShop/CarRepairShopView/FormReportGroupedOrders.designer.cs @@ -0,0 +1,91 @@ +namespace CarRepairShopView +{ + partial class FormReportGroupedOrders + { + /// + /// 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() + { + panel = new Panel(); + buttonToPdf = new Button(); + buttonCreateReport = new Button(); + panel.SuspendLayout(); + SuspendLayout(); + // + // panel + // + panel.Controls.Add(buttonToPdf); + panel.Controls.Add(buttonCreateReport); + panel.Dock = DockStyle.Top; + panel.Location = new Point(0, 0); + panel.Margin = new Padding(4, 3, 4, 3); + panel.Name = "panel"; + panel.Size = new Size(1031, 40); + panel.TabIndex = 0; + // + // buttonToPdf + // + buttonToPdf.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonToPdf.Location = new Point(188, 8); + buttonToPdf.Margin = new Padding(4, 3, 4, 3); + buttonToPdf.Name = "buttonToPdf"; + buttonToPdf.Size = new Size(139, 27); + buttonToPdf.TabIndex = 5; + buttonToPdf.Text = "В Pdf"; + buttonToPdf.UseVisualStyleBackColor = true; + buttonToPdf.Click += ButtonToPdf_Click; + // + // buttonCreateReport + // + buttonCreateReport.Location = new Point(11, 8); + buttonCreateReport.Margin = new Padding(4, 3, 4, 3); + buttonCreateReport.Name = "buttonCreateReport"; + buttonCreateReport.Size = new Size(139, 27); + buttonCreateReport.TabIndex = 4; + buttonCreateReport.Text = "Сформировать"; + buttonCreateReport.UseVisualStyleBackColor = true; + buttonCreateReport.Click += ButtonCreateReport_Click; + // + // FormReportGroupedOrders + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1031, 647); + Controls.Add(panel); + Margin = new Padding(4, 3, 4, 3); + Name = "FormReportGroupedOrders"; + StartPosition = FormStartPosition.CenterScreen; + Text = "Заказы по датам"; + panel.ResumeLayout(false); + ResumeLayout(false); + } + + #endregion + + private System.Windows.Forms.Panel panel; + private System.Windows.Forms.Button buttonToPdf; + private System.Windows.Forms.Button buttonCreateReport; + } +} \ No newline at end of file diff --git a/CarRepairShop/CarRepairShopView/FormReportGroupedOrders.resx b/CarRepairShop/CarRepairShopView/FormReportGroupedOrders.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/CarRepairShop/CarRepairShopView/FormReportGroupedOrders.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + \ No newline at end of file diff --git a/CarRepairShop/CarRepairShopView/FormReportRepairComponents.cs b/CarRepairShop/CarRepairShopView/FormReportRepairComponents.cs index 337d66d..ac2ba1a 100644 --- a/CarRepairShop/CarRepairShopView/FormReportRepairComponents.cs +++ b/CarRepairShop/CarRepairShopView/FormReportRepairComponents.cs @@ -21,7 +21,7 @@ namespace CarRepairShopView { try { - var dict = _logic.GetRepairComponent(); + var dict = _logic.GetRepairComponents(); if (dict != null) { dataGridView.Rows.Clear(); diff --git a/CarRepairShop/CarRepairShopView/FormReportShopRepairs.cs b/CarRepairShop/CarRepairShopView/FormReportShopRepairs.cs new file mode 100644 index 0000000..ad15953 --- /dev/null +++ b/CarRepairShop/CarRepairShopView/FormReportShopRepairs.cs @@ -0,0 +1,70 @@ +using CarRepairShopContracts.BindingModels; +using CarRepairShopContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; + +namespace CarRepairShopView +{ + public partial class FormReportShopRepairs : Form + { + private readonly ILogger _logger; + + private readonly IReportLogic _logic; + + public FormReportShopRepairs(ILogger logger, IReportLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormReportShopRepairs_Load(object sender, EventArgs e) + { + try + { + var dict = _logic.GetShopRepairs(); + if (dict != null) + { + dataGridView.Rows.Clear(); + foreach (var elem in dict) + { + dataGridView.Rows.Add(new object[] { elem.ShopName, "", "" }); + foreach (var listElem in elem.Repairs) + { + dataGridView.Rows.Add(new object[] { "", listElem.Item1, listElem.Item2 }); + } + dataGridView.Rows.Add(new object[] { "Итого", "", elem.TotalCount }); + dataGridView.Rows.Add(Array.Empty()); + } + } + _logger.LogInformation("Loading information on store workload"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Loading information on store workload error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonSaveToExcel_Click(object sender, EventArgs e) + { + using var dialog = new SaveFileDialog { Filter = "xlsx|*.xlsx" }; + if (dialog.ShowDialog() == DialogResult.OK) + { + try + { + _logic.SaveShopRepairToExcelFile(new ReportBindingModel + { + FileName = dialog.FileName + }); + _logger.LogInformation("Saving information on store workload"); + MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + catch (Exception ex) + { + _logger.LogError(ex, "Saving information on store workload error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } +} \ No newline at end of file diff --git a/CarRepairShop/CarRepairShopView/FormReportShopRepairs.designer.cs b/CarRepairShop/CarRepairShopView/FormReportShopRepairs.designer.cs new file mode 100644 index 0000000..999106e --- /dev/null +++ b/CarRepairShop/CarRepairShopView/FormReportShopRepairs.designer.cs @@ -0,0 +1,114 @@ +namespace CarRepairShopView +{ + partial class FormReportShopRepairs + { + /// + /// 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() + { + dataGridView = new DataGridView(); + buttonSaveToExcel = new Button(); + ColumnShop = new DataGridViewTextBoxColumn(); + ColumnRepair = new DataGridViewTextBoxColumn(); + ColumnCount = new DataGridViewTextBoxColumn(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.AllowUserToOrderColumns = true; + dataGridView.AllowUserToResizeColumns = false; + dataGridView.AllowUserToResizeRows = false; + dataGridView.BackgroundColor = SystemColors.ControlLightLight; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Columns.AddRange(new DataGridViewColumn[] { ColumnShop, ColumnRepair, ColumnCount }); + dataGridView.Dock = DockStyle.Bottom; + dataGridView.Location = new Point(0, 47); + dataGridView.Margin = new Padding(4, 3, 4, 3); + dataGridView.MultiSelect = false; + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.RowHeadersVisible = false; + dataGridView.Size = new Size(616, 510); + dataGridView.TabIndex = 0; + // + // buttonSaveToExcel + // + buttonSaveToExcel.Location = new Point(13, 10); + buttonSaveToExcel.Margin = new Padding(4, 3, 4, 3); + buttonSaveToExcel.Name = "buttonSaveToExcel"; + buttonSaveToExcel.Size = new Size(186, 27); + buttonSaveToExcel.TabIndex = 1; + buttonSaveToExcel.Text = "Сохранить в Excel"; + buttonSaveToExcel.UseVisualStyleBackColor = true; + buttonSaveToExcel.Click += ButtonSaveToExcel_Click; + // + // ColumnShop + // + ColumnShop.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + ColumnShop.HeaderText = "Магазин"; + ColumnShop.Name = "ColumnShop"; + ColumnShop.ReadOnly = true; + // + // ColumnRepair + // + ColumnRepair.HeaderText = "Ремонт"; + ColumnRepair.Name = "ColumnRepair"; + ColumnRepair.ReadOnly = true; + ColumnRepair.Width = 200; + // + // ColumnCount + // + ColumnCount.HeaderText = "Количество"; + ColumnCount.Name = "ColumnCount"; + ColumnCount.ReadOnly = true; + // + // FormReportShopRepairs + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(616, 557); + Controls.Add(buttonSaveToExcel); + Controls.Add(dataGridView); + Margin = new Padding(4, 3, 4, 3); + Name = "FormReportShopRepairs"; + StartPosition = FormStartPosition.CenterScreen; + Text = "Загруженность магазинов"; + Load += FormReportShopRepairs_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private System.Windows.Forms.DataGridView dataGridView; + private System.Windows.Forms.Button buttonSaveToExcel; + private DataGridViewTextBoxColumn ColumnShop; + private DataGridViewTextBoxColumn ColumnRepair; + private DataGridViewTextBoxColumn ColumnCount; + } +} \ No newline at end of file diff --git a/CarRepairShop/CarRepairShopView/FormReportShopRepairs.resx b/CarRepairShop/CarRepairShopView/FormReportShopRepairs.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/CarRepairShop/CarRepairShopView/FormReportShopRepairs.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + \ No newline at end of file diff --git a/CarRepairShop/CarRepairShopView/Program.cs b/CarRepairShop/CarRepairShopView/Program.cs index 09e0880..ef560e1 100644 --- a/CarRepairShop/CarRepairShopView/Program.cs +++ b/CarRepairShop/CarRepairShopView/Program.cs @@ -8,7 +8,6 @@ using NLog.Extensions.Logging; using CarRepairShopBusinessLogic.OfficePackage; using CarRepairShopBusinessLogic.OfficePackage.Implements; - namespace CarRepairShopView { internal static class Program @@ -47,10 +46,9 @@ namespace CarRepairShopView services.AddTransient(); services.AddTransient(); - services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); - services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -58,12 +56,14 @@ namespace CarRepairShopView services.AddTransient(); services.AddTransient(); services.AddTransient(); - services.AddTransient(); - services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file diff --git a/CarRepairShop/CarRepairShopView/ReportGroupedOrders.rdlc b/CarRepairShop/CarRepairShopView/ReportGroupedOrders.rdlc new file mode 100644 index 0000000..67f7eda --- /dev/null +++ b/CarRepairShop/CarRepairShopView/ReportGroupedOrders.rdlc @@ -0,0 +1,424 @@ + + + 0 + + + + System.Data.DataSet + /* Local Connection */ + + 10791c83-cee8-4a38-bbd0-245fc17cefb3 + + + + + + CarRepairShopContractsViewModels + /* Local Query */ + + + + Date + System.DateTime + + + Count + System.Int32 + + + Sum + System.Decimal + + + + CarRepairShopContracts.ViewModels + ReportOrdersByDateViewModel + CarRepairShopContracts.ViewModels.ReportOrdersByDateViewModel, CarRepairShopContracts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + + + + + + + + + true + true + + + + + Заказы по датам + + + + + + + 1cm + 21cm + + + Middle + 2pt + 2pt + 2pt + 2pt + + + + + + + 6.01401cm + + + 6.56042cm + + + 6.12687cm + + + + + 0.6cm + + + + + true + true + + + + + Дата + + + + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + Количество заказов + + + + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + Сумма + + + + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + 0.6cm + + + + + true + true + + + + + =Fields!Date.Value + + + + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + =Fields!Count.Value + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + =Fields!Sum.Value + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + + + + + + + + + + + + After + + + + + + + DataSetOrders + 1.95474cm + 1.16099cm + 1.2cm + 18.7013cm + 1 + + + + + + true + true + + + + + Всего: + + + + + + + 4cm + 11.23542cm + 0.6cm + 2.5cm + 2 + + + 2pt + 2pt + 2pt + 2pt + + + + true + true + + + + + =Sum(Fields!Sum.Value, "DataSetOrders") + + + + + + + 4cm + 13.73542cm + 0.6cm + 6.12687cm + 3 + + + 2pt + 2pt + 2pt + 2pt + + + + 5.72875cm +