From 0e5c0f7f5bc684533d9335804a5ffd2be0a9d015 Mon Sep 17 00:00:00 2001 From: maxnes3 <112558334+maxnes3@users.noreply.github.com> Date: Sat, 17 Jun 2023 01:18:13 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9D=D0=B0=D1=87=D0=B0=D0=BB=20=D0=BA=D0=B0?= =?UTF-8?q?=D0=BB=20=D0=B4=D0=B5=D0=BB=D0=B0=D1=82=D1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/ReportLogic.cs | 74 ++++++++++++++++++- .../OfficePackage/AbstractSaveToExcel.cs | 73 +++++++++++++++++- .../OfficePackage/AbstractSaveToPdf.cs | 40 +++++++++- .../OfficePackage/AbstractSaveToWord.cs | 43 ++++++++++- .../OfficePackage/HelperModels/ExcelInfo.cs | 3 +- .../OfficePackage/HelperModels/PdfInfo.cs | 3 +- .../OfficePackage/HelperModels/WordInfo.cs | 3 +- .../ReportOrdersGroupedByDateViewModel.cs | 15 ++++ .../ViewModels/ReportShopComputerViewModel.cs | 17 +++++ .../ComputersShopView.csproj | 6 ++ 10 files changed, 268 insertions(+), 9 deletions(-) create mode 100644 ComputersShop/ComputersShopContracts/ViewModels/ReportOrdersGroupedByDateViewModel.cs create mode 100644 ComputersShop/ComputersShopContracts/ViewModels/ReportShopComputerViewModel.cs diff --git a/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ReportLogic.cs b/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ReportLogic.cs index 3522afa..f568aa8 100644 --- a/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ReportLogic.cs +++ b/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ReportLogic.cs @@ -18,11 +18,12 @@ namespace ComputersShopBusinessLogic.BusinessLogics private readonly IComponentStorage _componentStorage; private readonly IComputerStorage _ComputerStorage; private readonly IOrderStorage _orderStorage; + private readonly IShopStorage _shopStorage; private readonly AbstractSaveToExcel _saveToExcel; private readonly AbstractSaveToWord _saveToWord; private readonly AbstractSaveToPdf _saveToPdf; - public ReportLogic(IComputerStorage ComputerStorage, IComponentStorage componentStorage, IOrderStorage orderStorage, AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf) + public ReportLogic(IComputerStorage ComputerStorage, IComponentStorage componentStorage, IOrderStorage orderStorage, AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf, IShopStorage shopStorage) { _ComputerStorage = ComputerStorage; _componentStorage = componentStorage; @@ -30,6 +31,7 @@ namespace ComputersShopBusinessLogic.BusinessLogics _saveToExcel = saveToExcel; _saveToWord = saveToWord; _saveToPdf = saveToPdf; + _shopStorage = shopStorage; } public List<ReportComputerComponentViewModel> GetComputerComponents() @@ -107,5 +109,73 @@ namespace ComputersShopBusinessLogic.BusinessLogics Orders = GetOrders(model) }); } - } + + public List<ReportShopComputerViewModel> GetShopComputers() + { + var shops = _shopStorage.GetFullList(); + + var list = new List<ReportShopComputerViewModel>(); + + foreach (var shop in shops) + { + var record = new ReportShopComputerViewModel + { + ShopName = shop.ShopName, + Computers = new List<(string, int)>(), + TotalCount = 0 + }; + foreach (var comp in shop.Computers) + { + record.Computers.Add(new(comp.Value.Item1.ComputerName, shop.Computers[comp.Value.Item1.Id].Item2)); + record.TotalCount += shop.Computers[comp.Value.Item1.Id].Item2; + } + + list.Add(record); + } + + return list; + } + public void SaveShopDocumentToExcelFile(ReportBindingModel model) + { + _saveToExcel.CreateShopReport(new ExcelInfo + { + FileName = model.FileName, + Title = "Заполненность магазинов", + ShopComputers = GetShopComputers() + }); + } + + public List<ReportOrdersGroupedByDateViewModel> GetGroupedByDateOrders() + { + return _orderStorage.GetFullList().GroupBy(x => x.DateCreate.Date) + .Select(x => new ReportOrdersGroupedByDateViewModel + { + Date = x.Key, + Count = x.Count(), + Sum = x.Sum(y => y.Sum) + }) + .ToList(); + } + + public void SaveGroupedByDateOrders(ReportBindingModel model) + { + _saveToPdf.CreateDocWithGroupedOrders(new PdfInfo + { + FileName = model.FileName, + Title = "Заказы по дате", + GroupedOrders = GetGroupedByDateOrders(), + }); + } + + public void SaveShopsToWordFile(ReportBindingModel model) + { + _saveToWord.CreateShopsTable(new WordInfo + { + FileName = model.FileName, + Title = "Список магазинов", + Shops = _shopStorage.GetFullList() + }); + } + } +} } diff --git a/ComputersShop/ComputersShopBusinessLogic/OfficePackage/AbstractSaveToExcel.cs b/ComputersShop/ComputersShopBusinessLogic/OfficePackage/AbstractSaveToExcel.cs index ae94a41..14bf4ad 100644 --- a/ComputersShop/ComputersShopBusinessLogic/OfficePackage/AbstractSaveToExcel.cs +++ b/ComputersShop/ComputersShopBusinessLogic/OfficePackage/AbstractSaveToExcel.cs @@ -84,7 +84,78 @@ namespace ComputersShopBusinessLogic.OfficePackage SaveExcel(info); } - 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 ss in info.ShopComputers) + { + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "A", + RowIndex = rowIndex, + Text = ss.ShopName, + StyleInfo = ExcelStyleInfoType.Text + }); + rowIndex++; + + foreach (var (Computer, Count) in ss.Computers) + { + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "B", + RowIndex = rowIndex, + Text = Computer, + 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 = ss.TotalCount.ToString(), + StyleInfo = ExcelStyleInfoType.Text + }); + rowIndex++; + } + + SaveExcel(info); + } + + protected abstract void CreateExcel(ExcelInfo info); protected abstract void InsertCellInWorksheet(ExcelCellParameters excelParams); diff --git a/ComputersShop/ComputersShopBusinessLogic/OfficePackage/AbstractSaveToPdf.cs b/ComputersShop/ComputersShopBusinessLogic/OfficePackage/AbstractSaveToPdf.cs index b17bdce..fc90cb2 100644 --- a/ComputersShop/ComputersShopBusinessLogic/OfficePackage/AbstractSaveToPdf.cs +++ b/ComputersShop/ComputersShopBusinessLogic/OfficePackage/AbstractSaveToPdf.cs @@ -57,7 +57,45 @@ namespace ComputersShopBusinessLogic.OfficePackage SavePdf(info); } - protected abstract void CreatePdf(PdfInfo info); + public void CreateDocWithGroupedOrders(PdfInfo info) + { + CreatePdf(info); + CreateParagraph(new PdfParagraph + { + Text = info.Title, + Style = "NormalTitle", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + + CreateTable(new List<string> { "3cm", "3cm", "3cm" }); + + CreateRow(new PdfRowParameters + { + Texts = new List<string> { "Дата", "Количество", "Сумма" }, + Style = "NormalTitle", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + + foreach (var order in info.GroupedOrders) + { + CreateRow(new PdfRowParameters + { + Texts = new List<string> { 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); + } + + protected abstract void CreatePdf(PdfInfo info); protected abstract void CreateParagraph(PdfParagraph paragraph); diff --git a/ComputersShop/ComputersShopBusinessLogic/OfficePackage/AbstractSaveToWord.cs b/ComputersShop/ComputersShopBusinessLogic/OfficePackage/AbstractSaveToWord.cs index f26a986..982c95c 100644 --- a/ComputersShop/ComputersShopBusinessLogic/OfficePackage/AbstractSaveToWord.cs +++ b/ComputersShop/ComputersShopBusinessLogic/OfficePackage/AbstractSaveToWord.cs @@ -42,9 +42,48 @@ namespace ComputersShopBusinessLogic.OfficePackage SaveWord(info); } - protected abstract void CreateWord(WordInfo info); + public void CreateShopsTable(WordInfo info) + { + CreateWord(info); + CreateParagraph(new WordParagraph + { + Texts = new List<(string, WordTextProperties)> { (info.Title, new WordTextProperties { Bold = true, Size = "24" }) }, + TextProperties = new WordTextProperties + { + Size = "24", + JustificationType = WordJustificationType.Center + } + }); + List<(string, WordTextProperties)> shopsInfo = new() + { + { ("Название", new WordTextProperties { Bold = true, Size = "24" }) }, + { ("Адрес", new WordTextProperties { Bold = true, Size = "24" }) }, + { ("Дата открытия", new WordTextProperties { Bold = true, Size = "24" }) } + }; + foreach (var shop in info.Shops) + { + shopsInfo.Add((shop.ShopName, new WordTextProperties { Size = "20" })); + shopsInfo.Add((shop.ShopAddress, new WordTextProperties { Size = "20" })); + shopsInfo.Add((shop.DateOpening.ToString(), new WordTextProperties { Size = "20" })); + } + CreateTable(new WordParagraph + { + Texts = shopsInfo, + TextProperties = new WordTextProperties + { + Size = "24", + JustificationType = WordJustificationType.Center + } + }, 3); + SaveWord(info); - protected abstract void CreateParagraph(WordParagraph paragraph); + } + + protected abstract void CreateWord(WordInfo info); + + protected abstract void CreateTable(WordParagraph paragraph, int columnCount); + + protected abstract void CreateParagraph(WordParagraph paragraph); protected abstract void SaveWord(WordInfo info); } diff --git a/ComputersShop/ComputersShopBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs b/ComputersShop/ComputersShopBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs index 9013a05..baa83b5 100644 --- a/ComputersShop/ComputersShopBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs +++ b/ComputersShop/ComputersShopBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs @@ -12,5 +12,6 @@ namespace ComputersShopBusinessLogic.OfficePackage.HelperModels public string FileName { get; set; } = string.Empty; public string Title { get; set; } = string.Empty; public List<ReportComputerComponentViewModel> ComputerComponents { get; set; } = new(); - } + public List<ReportShopComputerViewModel> ShopComputers { get; set; } = new(); + } } diff --git a/ComputersShop/ComputersShopBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs b/ComputersShop/ComputersShopBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs index a2f2ba5..b137b64 100644 --- a/ComputersShop/ComputersShopBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs +++ b/ComputersShop/ComputersShopBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs @@ -14,5 +14,6 @@ namespace ComputersShopBusinessLogic.OfficePackage.HelperModels public DateTime DateFrom { get; set; } public DateTime DateTo { get; set; } public List<ReportOrdersViewModel> Orders { get; set; } = new(); - } + public List<ReportOrdersGroupedByDateViewModel> GroupedOrders { get; set; } = new(); + } } diff --git a/ComputersShop/ComputersShopBusinessLogic/OfficePackage/HelperModels/WordInfo.cs b/ComputersShop/ComputersShopBusinessLogic/OfficePackage/HelperModels/WordInfo.cs index b637904..54b1bf6 100644 --- a/ComputersShop/ComputersShopBusinessLogic/OfficePackage/HelperModels/WordInfo.cs +++ b/ComputersShop/ComputersShopBusinessLogic/OfficePackage/HelperModels/WordInfo.cs @@ -12,5 +12,6 @@ namespace ComputersShopBusinessLogic.OfficePackage.HelperModels public string FileName { get; set; } = string.Empty; public string Title { get; set; } = string.Empty; public List<ComputerViewModel> Computers { get; set; } = new(); - } + public List<ShopViewModel> Shops { get; set; } = new(); + } } diff --git a/ComputersShop/ComputersShopContracts/ViewModels/ReportOrdersGroupedByDateViewModel.cs b/ComputersShop/ComputersShopContracts/ViewModels/ReportOrdersGroupedByDateViewModel.cs new file mode 100644 index 0000000..d905e56 --- /dev/null +++ b/ComputersShop/ComputersShopContracts/ViewModels/ReportOrdersGroupedByDateViewModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputersShopContracts.ViewModels +{ + public class ReportOrdersGroupedByDateViewModel + { + public DateTime Date { get; set; } + public int Count { get; set; } + public double Sum { get; set; } + } +} diff --git a/ComputersShop/ComputersShopContracts/ViewModels/ReportShopComputerViewModel.cs b/ComputersShop/ComputersShopContracts/ViewModels/ReportShopComputerViewModel.cs new file mode 100644 index 0000000..23a2b9d --- /dev/null +++ b/ComputersShop/ComputersShopContracts/ViewModels/ReportShopComputerViewModel.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputersShopContracts.ViewModels +{ + public class ReportShopComputerViewModel + { + public string ShopName { get; set; } = string.Empty; + + public int TotalCount { get; set; } + + public List<(string Computer, int Count)> Computers { get; set; } = new(); + } +} diff --git a/ComputersShop/ComputersShopView/ComputersShopView.csproj b/ComputersShop/ComputersShopView/ComputersShopView.csproj index f192a2d..7a00995 100644 --- a/ComputersShop/ComputersShopView/ComputersShopView.csproj +++ b/ComputersShop/ComputersShopView/ComputersShopView.csproj @@ -28,4 +28,10 @@ <ProjectReference Include="..\ComputersShopFileImplement\ComputersShopFileImplement.csproj" /> </ItemGroup> + <ItemGroup> + <None Update="ReportOrders.rdlc"> + <CopyToOutputDirectory>Always</CopyToOutputDirectory> + </None> + </ItemGroup> + </Project> \ No newline at end of file