From 454b2524f5ff2988fdcfdfdb13870be45b9dc784 Mon Sep 17 00:00:00 2001 From: "DozorovaA.A" Date: Fri, 19 May 2023 23:07:37 +0400 Subject: [PATCH] add material for orders --- .../BusinessLogics/ReportStorekeeperLogic.cs | 70 ++++++++++++ .../HelperModels/ExcelStoreKeeperInfo.cs | 20 ++++ .../HelperModels/PdfStoreKeeperInfo.cs | 18 +++ .../HelperModels/WordStoreKeeperInfo.cs | 16 +++ .../AbstractSaveToExcel.cs | 106 ++++++++++++++++++ .../AbstractSaveToPdf.cs | 91 +++++++++++++++ .../AbstractSaveToWord.cs | 87 ++++++++++++++ .../BindingModels/ReportBindingModel.cs | 15 +++ .../IReportStorekeeperLogic.cs | 43 +++++++ .../ReportFurnitureMaterialViewModel.cs | 15 +++ .../ViewModels/ReportMaterialsViewModel.cs | 16 +++ 11 files changed, 497 insertions(+) create mode 100644 FurnitureAssembly/FurnitureAssemblyBusinessLogic/BusinessLogics/ReportStorekeeperLogic.cs create mode 100644 FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/HelperModels/ExcelStoreKeeperInfo.cs create mode 100644 FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/HelperModels/PdfStoreKeeperInfo.cs create mode 100644 FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/HelperModels/WordStoreKeeperInfo.cs create mode 100644 FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/StorekeeperSaveToFile/AbstractSaveToExcel.cs create mode 100644 FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/StorekeeperSaveToFile/AbstractSaveToPdf.cs create mode 100644 FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/StorekeeperSaveToFile/AbstractSaveToWord.cs create mode 100644 FurnitureAssembly/FurnitureAssemblyContracts/BindingModels/ReportBindingModel.cs create mode 100644 FurnitureAssembly/FurnitureAssemblyContracts/BusinessLogicContracts/IReportStorekeeperLogic.cs create mode 100644 FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ReportFurnitureMaterialViewModel.cs create mode 100644 FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ReportMaterialsViewModel.cs diff --git a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/BusinessLogics/ReportStorekeeperLogic.cs b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/BusinessLogics/ReportStorekeeperLogic.cs new file mode 100644 index 0000000..be496b8 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/BusinessLogics/ReportStorekeeperLogic.cs @@ -0,0 +1,70 @@ +using FurnitureAssemblyContracts.BindingModels; +using FurnitureAssemblyContracts.StorageContracts; +using FurnitureAssemblyContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureAssemblyBusinessLogic.BusinessLogics +{ + public class ReportStorekeeperLogic : IReportStorekeeperLogic + { + private readonly IFurnitureStorage _furnitureStorage; + private readonly AbstractSaveToExcel _saveToExcel; + private readonly AbstractSaveToWord _saveToWord; + private readonly AbstractSaveToPdf _saveToPdf; + + public ReportLogic(IFurnitureStorage furnitureStorage, IOrderStorage orderStorage, + AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf) + { + _furnitureStorage = furnitureStorage; + _orderStorage = orderStorage; + _saveToExcel = saveToExcel; + _saveToWord = saveToWord; + _saveToPdf = saveToPdf; + } + public List GetFurnitureComponent() + { + var furnitures = _furnitureStorage.GetFullList(); + var list = new List(); + foreach (var furniture in furnitures) + { + var record = new ReportFurnitureComponentViewModel + { + FurnitureName = furniture.FurnitureName, + Components = new List>(), + TotalCount = 0 + }; + foreach (var componentCount in furniture.FurnitureComponents.Values) + { + record.Components.Add(new Tuple(componentCount.Item1.ComponentName, componentCount.Item2)); + record.TotalCount += componentCount.Item2; + } + list.Add(record); + } + return list; + } + + public List GetOrders(ReportBindingModel model) + { + throw new NotImplementedException(); + } + + public void SaveFurnituresToExelFile(ReportBindingModel model) + { + throw new NotImplementedException(); + } + + public void SaveFurnituresToWordFile(ReportBindingModel model) + { + throw new NotImplementedException(); + } + + public void SaveMaterialsToPdfFile(ReportBindingModel model) + { + throw new NotImplementedException(); + } + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/HelperModels/ExcelStoreKeeperInfo.cs b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/HelperModels/ExcelStoreKeeperInfo.cs new file mode 100644 index 0000000..e5ef581 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/HelperModels/ExcelStoreKeeperInfo.cs @@ -0,0 +1,20 @@ +using FurnitureAssemblyContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureAssemblyBusinessLogic.OfficePackage.HelperModels.StorekeeperModels +{ + public class ExcelStoreKeeperInfo + { + public string FileName { get; set; } = "C:\\temp\\excel_storekeeper.xlsx"; + public string Title { get; set; } = string.Empty; + public List FurnitureMaterials + { + get; + set; + } = new(); + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/HelperModels/PdfStoreKeeperInfo.cs b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/HelperModels/PdfStoreKeeperInfo.cs new file mode 100644 index 0000000..d233c2e --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/HelperModels/PdfStoreKeeperInfo.cs @@ -0,0 +1,18 @@ +using FurnitureAssemblyContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureAssemblyBusinessLogic.OfficePackage.HelperModels.StorekeeperModels +{ + public class PdfStoreKeeperInfo + { + public string FileName { get; set; } = "C:\\temp\\pdf_storekeeper.pdf"; + public string Title { get; set; } = string.Empty; + public DateTime DateFrom { get; set; } + public DateTime DateTo { get; set; } + public List Materials { get; set; } + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/HelperModels/WordStoreKeeperInfo.cs b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/HelperModels/WordStoreKeeperInfo.cs new file mode 100644 index 0000000..336709a --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/HelperModels/WordStoreKeeperInfo.cs @@ -0,0 +1,16 @@ +using FurnitureAssemblyContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureAssemblyBusinessLogic.OfficePackage.HelperModels.StorekeeperModels +{ + public class WordStoreKeeperInfo + { + public string FileName { get; set; } = "C:\\temp\\word_storekeeper.docx"; + public string Title { get; set; } = string.Empty; + public List FurnitureMaterialsList { get; set; } = new(); + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/StorekeeperSaveToFile/AbstractSaveToExcel.cs b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/StorekeeperSaveToFile/AbstractSaveToExcel.cs new file mode 100644 index 0000000..13b6667 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/StorekeeperSaveToFile/AbstractSaveToExcel.cs @@ -0,0 +1,106 @@ +using DocumentFormat.OpenXml; +using DocumentFormat.OpenXml.Office2010.Excel; +using DocumentFormat.OpenXml.Office2013.Excel; +using DocumentFormat.OpenXml.Packaging; +using DocumentFormat.OpenXml.Spreadsheet; +using FurnitureAssemblyBusinessLogic.OfficePackage.HelperEnums; +using FurnitureAssemblyBusinessLogic.OfficePackage.HelperModels; +using FurnitureAssemblyBusinessLogic.OfficePackage.HelperModels.StorekeeperModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureAssemblyBusinessLogic.OfficePackage.StorekeeperSaveToFile +{ + public abstract class AbstractSaveToExcel + { + /// + /// Создание отчета + /// + /// + public void CreateReport(ExcelStoreKeeperInfo 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 furniture in info.FurnitureMaterials) + { + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "A", + RowIndex = rowIndex, + Text = furniture.FurnitureName, + StyleInfo = ExcelStyleInfoType.Text + }); + rowIndex++; + foreach (var materials in furniture.Materials) + { + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "B", + RowIndex = rowIndex, + Text = materials.Item1, + StyleInfo = ExcelStyleInfoType.TextWithBroder + }); + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "C", + RowIndex = rowIndex, + Text = materials.Item2.ToString(), + StyleInfo = ExcelStyleInfoType.TextWithBroder + }); + rowIndex++; + } + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "A", + RowIndex = rowIndex, + Text = "Итого", + StyleInfo = ExcelStyleInfoType.Text + }); + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "C", + RowIndex = rowIndex, + Text = furniture.TotalCount.ToString(), + StyleInfo = ExcelStyleInfoType.Text + }); + rowIndex++; + } + SaveExcel(info); + } + /// + /// Создание excel-файла + /// + /// + protected abstract void CreateExcel(ExcelStoreKeeperInfo info); + /// + /// Добавляем новую ячейку в лист + /// + /// + protected abstract void InsertCellInWorksheet(ExcelCellParameters excelParams); + /// + /// Объединение ячеек + /// + /// + protected abstract void MergeCells(ExcelMergeParameters excelParams); + /// + /// Сохранение файла + /// + /// + protected abstract void SaveExcel(ExcelStoreKeeperInfo info); + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/StorekeeperSaveToFile/AbstractSaveToPdf.cs b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/StorekeeperSaveToFile/AbstractSaveToPdf.cs new file mode 100644 index 0000000..e8cec60 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/StorekeeperSaveToFile/AbstractSaveToPdf.cs @@ -0,0 +1,91 @@ +using FurnitureAssemblyBusinessLogic.OfficePackage.HelperEnums; +using FurnitureAssemblyBusinessLogic.OfficePackage.HelperModels; +using FurnitureAssemblyBusinessLogic.OfficePackage.HelperModels.StorekeeperModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureAssemblyBusinessLogic.OfficePackage.StorekeeperSaveToFile +{ + public abstract class AbstractSaveToPdf + { + public void CreateDoc(PdfStoreKeeperInfo info) + { + 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 + }); + CreateRow(new PdfRowParameters + { + Texts = new List { "Материал", "Стоимость" }, + Style = "NormalTitle", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + double sum = 0; + foreach (var material in info.Materials) + { + //CreateParagraph(new PdfParagraph + //{ + // Text = material.MaterialName, + // Style = "Normal", + // ParagraphAlignment = PdfParagraphAlignmentType.Left + //}); + //CreateTable(new List { "6cm", "3cm" }); + sum += material.Sum; + CreateRow(new PdfRowParameters + { + Texts = new List { material.MaterialName, material.Sum.ToString() }, + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Left + }); + } + + CreateParagraph(new PdfParagraph + { + Text = $"Итого: {sum}\t", + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Left + }); + SavePdf(info); + } + /// + /// Создание doc-файла + /// + /// + protected abstract void CreatePdf(PdfStoreKeeperInfo info); + /// + /// Создание параграфа с текстом + /// + /// + /// + protected abstract void CreateParagraph(PdfParagraph paragraph); + /// + /// Создание таблицы + /// + /// + /// + protected abstract void CreateTable(List columns); + /// + /// Создание и заполнение строки + /// + /// + protected abstract void CreateRow(PdfRowParameters rowParameters); + /// + /// Сохранение файла + /// + /// + protected abstract void SavePdf(PdfStoreKeeperInfo PdfStoreKeeperInfo); + } +} + diff --git a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/StorekeeperSaveToFile/AbstractSaveToWord.cs b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/StorekeeperSaveToFile/AbstractSaveToWord.cs new file mode 100644 index 0000000..547e58a --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/StorekeeperSaveToFile/AbstractSaveToWord.cs @@ -0,0 +1,87 @@ +using FurnitureAssemblyBusinessLogic.OfficePackage.HelperEnums; +using FurnitureAssemblyBusinessLogic.OfficePackage.HelperModels; +using FurnitureAssemblyBusinessLogic.OfficePackage.HelperModels.StorekeeperModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureAssemblyBusinessLogic.OfficePackage.StorekeeperSaveToFile +{ + public abstract class AbstractSaveToWord + { + public void CreateDoc(WordStoreKeeperInfo 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 + } + }); + foreach (var furniture in info.FurnitureMaterialsList) + { + CreateParagraph(new WordParagraph + { + Texts = new List<(string, WordTextProperties)> + { + (furniture.FurnitureName, new WordTextProperties { Bold = true, Size = "24", }) + }, + TextProperties = new WordTextProperties + { + Size = "24", + JustificationType = WordJustificationType.Both + } + }); + foreach (var materials in furniture.Materials) + { + CreateParagraph(new WordParagraph + { + Texts = new List<(string, WordTextProperties)> + { + (materials.Item1 + " " + materials.Item2.ToString(), new WordTextProperties { Bold = false, Size = "20", }) + }, + TextProperties = new WordTextProperties + { + Size = "20", + JustificationType = WordJustificationType.Both + } + }); + } + CreateParagraph(new WordParagraph + { + Texts = new List<(string, WordTextProperties)> + { + ("Итого " + furniture.TotalCount.ToString(), new WordTextProperties { Bold = false, Size = "24", }) + }, + TextProperties = new WordTextProperties + { + Size = "24", + JustificationType = WordJustificationType.Both + } + }); + } + SaveWord(info); + } + /// + /// Создание doc-файла + /// + /// + protected abstract void CreateWord(WordStoreKeeperInfo info); + /// + /// Создание абзаца с текстом + /// + /// + /// + protected abstract void CreateParagraph(WordParagraph paragraph); + /// + /// Сохранение файла + /// + /// + protected abstract void SaveWord(WordStoreKeeperInfo info); + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/BindingModels/ReportBindingModel.cs b/FurnitureAssembly/FurnitureAssemblyContracts/BindingModels/ReportBindingModel.cs new file mode 100644 index 0000000..629e40e --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyContracts/BindingModels/ReportBindingModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureAssemblyContracts.BindingModels +{ + public class ReportBindingModel + { + public string FileName { get; set; } = string.Empty; + public DateTime? DateFrom { get; set; } + public DateTime? DateTo { get; set; } + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/BusinessLogicContracts/IReportStorekeeperLogic.cs b/FurnitureAssembly/FurnitureAssemblyContracts/BusinessLogicContracts/IReportStorekeeperLogic.cs new file mode 100644 index 0000000..e7b31d4 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyContracts/BusinessLogicContracts/IReportStorekeeperLogic.cs @@ -0,0 +1,43 @@ +using FurnitureAssemblyContracts.BindingModels; +using FurnitureAssemblyContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureAssemblyBusinessLogic.BusinessLogics +{ + public interface IReportStorekeeperLogic + { + /// + /// Получение списка мебели с разбиением по материалам + /// + /// + List GetFurnitureComponent(); + + /// + /// Получение отчета по движению материалов за период времени + /// + /// + List GetOrders(ReportBindingModel model); + + /// + /// Сохранение отчета по гарнитурам в файл-Word + /// + /// + void SaveFurnituresToWordFile(ReportBindingModel model); + + /// + /// Сохранение отчета по гарнитурам в файл-Excel + /// + /// + void SaveFurnituresToExelFile(ReportBindingModel model); + + /// + /// Сохранение отчета о материалах в файл-Pdf + /// + /// + void SaveMaterialsToPdfFile(ReportBindingModel model); + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ReportFurnitureMaterialViewModel.cs b/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ReportFurnitureMaterialViewModel.cs new file mode 100644 index 0000000..e14608f --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ReportFurnitureMaterialViewModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureAssemblyContracts.ViewModels +{ + public class ReportFurnitureMaterialViewModel + { + public string FurnitureName { get; set; } = string.Empty; + public int TotalCount { get; set; } + public List> Materials { get; set; } = new(); + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ReportMaterialsViewModel.cs b/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ReportMaterialsViewModel.cs new file mode 100644 index 0000000..27363e7 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ReportMaterialsViewModel.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureAssemblyContracts.ViewModels +{ + public class ReportMaterialsViewModel + { + public int Id { get; set; } + public DateTime DateCreate { get; set; } + public string MaterialName { get; set; } = string.Empty; + public double Sum { get; set; } + } +}