diff --git a/RenovationWork/RenovationWorkBusinessLogic/OfficePackage/AbstractSaveToExcel.cs b/RenovationWork/RenovationWorkBusinessLogic/OfficePackage/AbstractSaveToExcel.cs new file mode 100644 index 0000000..30a5f39 --- /dev/null +++ b/RenovationWork/RenovationWorkBusinessLogic/OfficePackage/AbstractSaveToExcel.cs @@ -0,0 +1,112 @@ +using RenovationWorkBusinessLogic.OfficePackage.HelperEnums; +using RenovationWorkBusinessLogic.OfficePackage.HelperModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RenovationWorkBusinessLogic.OfficePackage +{ + public abstract class AbstractSaveToExcel + { + /// + /// Создание отчета + /// + /// + public void CreateReport(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.RepairComponents) + { + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "A", + RowIndex = rowIndex, + Text = pc.ComponentName, + StyleInfo = ExcelStyleInfoType.Text + }); + rowIndex++; + + foreach (var (Repair, Count) in pc.Repairs) + { + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "B", + RowIndex = rowIndex, + Text = Repair, + StyleInfo = ExcelStyleInfoType.TextWithBroder + }); + + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "C", + RowIndex = rowIndex, + Text = Count.ToString(), + StyleInfo = ExcelStyleInfoType.TextWithBroder + }); + + rowIndex++; + } + + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "A", + RowIndex = rowIndex, + Text = "Итого", + StyleInfo = ExcelStyleInfoType.Text + }); + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "C", + RowIndex = rowIndex, + Text = pc.TotalCount.ToString(), + StyleInfo = ExcelStyleInfoType.Text + }); + rowIndex++; + } + + SaveExcel(info); + } + + /// + /// Создание excel-файла + /// + /// + protected abstract void CreateExcel(ExcelInfo info); + + /// + /// Добавляем новую ячейку в лист + /// + /// + protected abstract void InsertCellInWorksheet(ExcelCellParameters excelParams); + + /// + /// Объединение ячеек + /// + /// + protected abstract void MergeCells(ExcelMergeParameters excelParams); + + /// + /// Сохранение файла + /// + /// + protected abstract void SaveExcel(ExcelInfo info); + } +} diff --git a/RenovationWork/RenovationWorkBusinessLogic/OfficePackage/AbstractSaveToPdf.cs b/RenovationWork/RenovationWorkBusinessLogic/OfficePackage/AbstractSaveToPdf.cs new file mode 100644 index 0000000..bbbaddc --- /dev/null +++ b/RenovationWork/RenovationWorkBusinessLogic/OfficePackage/AbstractSaveToPdf.cs @@ -0,0 +1,74 @@ +using RenovationWorkBusinessLogic.OfficePackage.HelperEnums; +using RenovationWorkBusinessLogic.OfficePackage.HelperModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RenovationWorkBusinessLogic.OfficePackage +{ + public abstract class AbstractSaveToPdf + { + public void CreateDoc(PdfInfo 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 }); + + CreateTable(new List { "2cm", "3cm", "6cm", "3cm" }); + + CreateRow(new PdfRowParameters + { + Texts = new List { "Номер", "Дата заказа", "Изделие", "Сумма" }, + Style = "NormalTitle", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + + foreach (var order in info.Orders) + { + CreateRow(new PdfRowParameters + { + Texts = new List { order.Id.ToString(), order.DateCreate.ToShortDateString(), order.RepairName, order.Sum.ToString() }, + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Left + }); + } + CreateParagraph(new PdfParagraph { Text = $"Итого: {info.Orders.Sum(x => x.Sum)}\t", Style = "Normal", ParagraphAlignment = PdfParagraphAlignmentType.Rigth }); + + SavePdf(info); + } + + /// + /// Создание doc-файла + /// + /// + protected abstract void CreatePdf(PdfInfo info); + + /// + /// Создание параграфа с текстом + /// + /// + /// + protected abstract void CreateParagraph(PdfParagraph paragraph); + + /// + /// Создание таблицы + /// + /// + /// + protected abstract void CreateTable(List columns); + + /// + /// Создание и заполнение строки + /// + /// + protected abstract void CreateRow(PdfRowParameters rowParameters); + + /// + /// Сохранение файла + /// + /// + protected abstract void SavePdf(PdfInfo info); + } +} diff --git a/RenovationWork/RenovationWorkBusinessLogic/OfficePackage/AbstractSaveToWord.cs b/RenovationWork/RenovationWorkBusinessLogic/OfficePackage/AbstractSaveToWord.cs new file mode 100644 index 0000000..3596a20 --- /dev/null +++ b/RenovationWork/RenovationWorkBusinessLogic/OfficePackage/AbstractSaveToWord.cs @@ -0,0 +1,62 @@ +using RenovationWorkBusinessLogic.OfficePackage.HelperEnums; +using RenovationWorkBusinessLogic.OfficePackage.HelperModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RenovationWorkBusinessLogic.OfficePackage +{ + public abstract class AbstractSaveToWord + { + public void CreateDoc(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 + } + }); + + foreach (var component in info.Components) + { + CreateParagraph(new WordParagraph + { + Texts = new List<(string, WordTextProperties)> { (component.ComponentName, new WordTextProperties { Size = "24", }) }, + TextProperties = new WordTextProperties + { + Size = "24", + JustificationType = WordJustificationType.Both + } + }); + } + + SaveWord(info); + } + + /// + /// Создание doc-файла + /// + /// + protected abstract void CreateWord(WordInfo info); + + /// + /// Создание абзаца с текстом + /// + /// + /// + protected abstract void CreateParagraph(WordParagraph paragraph); + + /// + /// Сохранение файла + /// + /// + protected abstract void SaveWord(WordInfo info); + } +} diff --git a/RenovationWork/RenovationWorkBusinessLogic/OfficePackage/HelperEnums/ExcelStyleInfoType.cs b/RenovationWork/RenovationWorkBusinessLogic/OfficePackage/HelperEnums/ExcelStyleInfoType.cs new file mode 100644 index 0000000..5631104 --- /dev/null +++ b/RenovationWork/RenovationWorkBusinessLogic/OfficePackage/HelperEnums/ExcelStyleInfoType.cs @@ -0,0 +1,11 @@ +namespace RenovationWorkBusinessLogic.OfficePackage.HelperEnums +{ + public enum ExcelStyleInfoType + { + Title, + + Text, + + TextWithBroder + } +} diff --git a/RenovationWork/RenovationWorkBusinessLogic/OfficePackage/HelperEnums/PdfParagraphAlignmentType.cs b/RenovationWork/RenovationWorkBusinessLogic/OfficePackage/HelperEnums/PdfParagraphAlignmentType.cs new file mode 100644 index 0000000..20f27b0 --- /dev/null +++ b/RenovationWork/RenovationWorkBusinessLogic/OfficePackage/HelperEnums/PdfParagraphAlignmentType.cs @@ -0,0 +1,11 @@ +namespace RenovationWorkBusinessLogic.OfficePackage.HelperEnums +{ + public enum PdfParagraphAlignmentType + { + Center, + + Left, + + Rigth + } +} diff --git a/RenovationWork/RenovationWorkBusinessLogic/OfficePackage/HelperEnums/WordJustificationType.cs b/RenovationWork/RenovationWorkBusinessLogic/OfficePackage/HelperEnums/WordJustificationType.cs new file mode 100644 index 0000000..2da3aa7 --- /dev/null +++ b/RenovationWork/RenovationWorkBusinessLogic/OfficePackage/HelperEnums/WordJustificationType.cs @@ -0,0 +1,9 @@ +namespace RenovationWorkBusinessLogic.OfficePackage.HelperEnums +{ + public enum WordJustificationType + { + Center, + + Both + } +} diff --git a/RenovationWork/RenovationWorkBusinessLogic/OfficePackage/HelperModels/ExcelCellParameters.cs b/RenovationWork/RenovationWorkBusinessLogic/OfficePackage/HelperModels/ExcelCellParameters.cs new file mode 100644 index 0000000..3b2ce8f --- /dev/null +++ b/RenovationWork/RenovationWorkBusinessLogic/OfficePackage/HelperModels/ExcelCellParameters.cs @@ -0,0 +1,17 @@ +using RenovationWorkBusinessLogic.OfficePackage.HelperEnums; + +namespace RenovationWorkBusinessLogic.OfficePackage.HelperModels +{ + public class ExcelCellParameters + { + public string ColumnName { get; set; } = string.Empty; + + public uint RowIndex { get; set; } + + public string Text { get; set; } = string.Empty; + + public string CellReference => $"{ColumnName}{RowIndex}"; + + public ExcelStyleInfoType StyleInfo { get; set; } + } +} diff --git a/RenovationWork/RenovationWorkBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs b/RenovationWork/RenovationWorkBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs new file mode 100644 index 0000000..03d0fff --- /dev/null +++ b/RenovationWork/RenovationWorkBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs @@ -0,0 +1,18 @@ +using RenovationWorkContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RenovationWorkBusinessLogic.OfficePackage.HelperModels +{ + public class ExcelInfo + { + public string FileName { get; set; } = string.Empty; + + public string Title { get; set; } = string.Empty; + + public List RepairComponents { get; set; } = new(); + } +} diff --git a/RenovationWork/RenovationWorkBusinessLogic/OfficePackage/HelperModels/ExcelMergeParameters.cs b/RenovationWork/RenovationWorkBusinessLogic/OfficePackage/HelperModels/ExcelMergeParameters.cs new file mode 100644 index 0000000..1ed50ee --- /dev/null +++ b/RenovationWork/RenovationWorkBusinessLogic/OfficePackage/HelperModels/ExcelMergeParameters.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RenovationWorkBusinessLogic.OfficePackage.HelperModels +{ + public class ExcelMergeParameters + { + public string CellFromName { get; set; } = string.Empty; + + public string CellToName { get; set; } = string.Empty; + + public string Merge => $"{CellFromName}:{CellToName}"; + } +} diff --git a/RenovationWork/RenovationWorkBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs b/RenovationWork/RenovationWorkBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs new file mode 100644 index 0000000..a939aae --- /dev/null +++ b/RenovationWork/RenovationWorkBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs @@ -0,0 +1,22 @@ +using RenovationWorkContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RenovationWorkBusinessLogic.OfficePackage.HelperModels +{ + public class PdfInfo + { + public string FileName { get; set; } = string.Empty; + + public string Title { get; set; } = string.Empty; + + public DateTime DateFrom { get; set; } + + public DateTime DateTo { get; set; } + + public List Orders { get; set; } = new(); + } +} diff --git a/RenovationWork/RenovationWorkBusinessLogic/OfficePackage/HelperModels/PdfParagraph.cs b/RenovationWork/RenovationWorkBusinessLogic/OfficePackage/HelperModels/PdfParagraph.cs new file mode 100644 index 0000000..745c83a --- /dev/null +++ b/RenovationWork/RenovationWorkBusinessLogic/OfficePackage/HelperModels/PdfParagraph.cs @@ -0,0 +1,18 @@ +using RenovationWorkBusinessLogic.OfficePackage.HelperEnums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RenovationWorkBusinessLogic.OfficePackage.HelperModels +{ + public class PdfParagraph + { + public string Text { get; set; } = string.Empty; + + public string Style { get; set; } = string.Empty; + + public PdfParagraphAlignmentType ParagraphAlignment { get; set; } + } +} diff --git a/RenovationWork/RenovationWorkBusinessLogic/OfficePackage/HelperModels/PdfRowParameters.cs b/RenovationWork/RenovationWorkBusinessLogic/OfficePackage/HelperModels/PdfRowParameters.cs new file mode 100644 index 0000000..ab41bc7 --- /dev/null +++ b/RenovationWork/RenovationWorkBusinessLogic/OfficePackage/HelperModels/PdfRowParameters.cs @@ -0,0 +1,18 @@ +using RenovationWorkBusinessLogic.OfficePackage.HelperEnums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RenovationWorkBusinessLogic.OfficePackage.HelperModels +{ + public class PdfRowParameters + { + public List Texts { get; set; } = new(); + + public string Style { get; set; } = string.Empty; + + public PdfParagraphAlignmentType ParagraphAlignment { get; set; } + } +} diff --git a/RenovationWork/RenovationWorkBusinessLogic/OfficePackage/HelperModels/WordInfo.cs b/RenovationWork/RenovationWorkBusinessLogic/OfficePackage/HelperModels/WordInfo.cs new file mode 100644 index 0000000..56f1de7 --- /dev/null +++ b/RenovationWork/RenovationWorkBusinessLogic/OfficePackage/HelperModels/WordInfo.cs @@ -0,0 +1,18 @@ +using RenovationWorkContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RenovationWorkBusinessLogic.OfficePackage.HelperModels +{ + public class WordInfo + { + public string FileName { get; set; } = string.Empty; + + public string Title { get; set; } = string.Empty; + + public List Components { get; set; } = new(); + } +} diff --git a/RenovationWork/RenovationWorkBusinessLogic/OfficePackage/HelperModels/WordParagraph.cs b/RenovationWork/RenovationWorkBusinessLogic/OfficePackage/HelperModels/WordParagraph.cs new file mode 100644 index 0000000..f98f9f9 --- /dev/null +++ b/RenovationWork/RenovationWorkBusinessLogic/OfficePackage/HelperModels/WordParagraph.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RenovationWorkBusinessLogic.OfficePackage.HelperModels +{ + public class WordParagraph + { + public List<(string, WordTextProperties)> Texts { get; set; } = new(); + + public WordTextProperties? TextProperties { get; set; } + } +} diff --git a/RenovationWork/RenovationWorkBusinessLogic/OfficePackage/HelperModels/WordTextProperties.cs b/RenovationWork/RenovationWorkBusinessLogic/OfficePackage/HelperModels/WordTextProperties.cs new file mode 100644 index 0000000..3ea414a --- /dev/null +++ b/RenovationWork/RenovationWorkBusinessLogic/OfficePackage/HelperModels/WordTextProperties.cs @@ -0,0 +1,13 @@ +using RenovationWorkBusinessLogic.OfficePackage.HelperEnums; + +namespace RenovationWorkBusinessLogic.OfficePackage.HelperModels +{ + public class WordTextProperties + { + public string Size { get; set; } = string.Empty; + + public bool Bold { get; set; } + + public WordJustificationType JustificationType { get; set; } + } +} diff --git a/RenovationWork/RenovationWorkBusinessLogic/RenovationWorkBusinessLogic.csproj b/RenovationWork/RenovationWorkBusinessLogic/RenovationWorkBusinessLogic.csproj index 1eb990d..82052d0 100644 --- a/RenovationWork/RenovationWorkBusinessLogic/RenovationWorkBusinessLogic.csproj +++ b/RenovationWork/RenovationWorkBusinessLogic/RenovationWorkBusinessLogic.csproj @@ -14,4 +14,8 @@ + + + + diff --git a/RenovationWork/RenovationWorkContracts/BindingModels/ReportBindingModel.cs b/RenovationWork/RenovationWorkContracts/BindingModels/ReportBindingModel.cs new file mode 100644 index 0000000..b0539d3 --- /dev/null +++ b/RenovationWork/RenovationWorkContracts/BindingModels/ReportBindingModel.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RenovationWorkContracts.BindingModels +{ + public class ReportBindingModel + { + public string FileName { get; set; } = string.Empty; + + public DateTime? DateFrom { get; set; } + + public DateTime? DateTo { get; set; } + } +} diff --git a/RenovationWork/RenovationWorkContracts/BusinessLogicsContracts/IReportLogic.cs b/RenovationWork/RenovationWorkContracts/BusinessLogicsContracts/IReportLogic.cs new file mode 100644 index 0000000..681612e --- /dev/null +++ b/RenovationWork/RenovationWorkContracts/BusinessLogicsContracts/IReportLogic.cs @@ -0,0 +1,44 @@ +using RenovationWorkContracts.BindingModels; +using RenovationWorkContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RenovationWorkContracts.BusinessLogicsContracts +{ + public interface IReportLogic + { + /// + /// Получение списка компонент с указанием, в каких изделиях используются + /// + /// + List GetRepairComponent(); + + /// + /// Получение списка заказов за определенный период + /// + /// + /// + List GetOrders(ReportBindingModel model); + + /// + /// Сохранение компонент в файл-Word + /// + /// + void SaveComponentsToWordFile(ReportBindingModel model); + + /// + /// Сохранение компонент с указаеним продуктов в файл-Excel + /// + /// + void SaveRepairComponentToExcelFile(ReportBindingModel model); + + /// + /// Сохранение заказов в файл-Pdf + /// + /// + void SaveOrdersToPdfFile(ReportBindingModel model); + } +} diff --git a/RenovationWork/RenovationWorkContracts/SeatchModels/OrderSearchModel.cs b/RenovationWork/RenovationWorkContracts/SeatchModels/OrderSearchModel.cs index b3f8e78..cf870e3 100644 --- a/RenovationWork/RenovationWorkContracts/SeatchModels/OrderSearchModel.cs +++ b/RenovationWork/RenovationWorkContracts/SeatchModels/OrderSearchModel.cs @@ -9,6 +9,9 @@ namespace RenovationWorkContracts.SeatchModels public class OrderSearchModel { public int? Id { get; set; } + public DateTime? DateFrom { get; set; } + + public DateTime? DateTo { get; set; } } } diff --git a/RenovationWork/RenovationWorkContracts/ViewModels/ReportOrdersViewModel.cs b/RenovationWork/RenovationWorkContracts/ViewModels/ReportOrdersViewModel.cs new file mode 100644 index 0000000..f21057e --- /dev/null +++ b/RenovationWork/RenovationWorkContracts/ViewModels/ReportOrdersViewModel.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RenovationWorkContracts.ViewModels +{ + public class ReportOrdersViewModel + { + public int Id { get; set; } + + public DateTime DateCreate { get; set; } + + public string RepairName { get; set; } = string.Empty; + + public double Sum { get; set; } + } +} diff --git a/RenovationWork/RenovationWorkContracts/ViewModels/ReportRepairComponentViewModel.cs b/RenovationWork/RenovationWorkContracts/ViewModels/ReportRepairComponentViewModel.cs new file mode 100644 index 0000000..4b238b5 --- /dev/null +++ b/RenovationWork/RenovationWorkContracts/ViewModels/ReportRepairComponentViewModel.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RenovationWorkContracts.ViewModels +{ + public class ReportRepairComponentViewModel + { + public string ComponentName { get; set; } = string.Empty; + + public int TotalCount { get; set; } + + public List<(string Repair, int Count)> Repairs { get; set; } = new(); + } +}