diff --git a/AutoWorkshopBusinessLogic/AutoWorkshopBusinessLogic.csproj b/AutoWorkshopBusinessLogic/AutoWorkshopBusinessLogic.csproj index 8483a93..9a90c74 100644 --- a/AutoWorkshopBusinessLogic/AutoWorkshopBusinessLogic.csproj +++ b/AutoWorkshopBusinessLogic/AutoWorkshopBusinessLogic.csproj @@ -7,7 +7,9 @@ + + diff --git a/AutoWorkshopBusinessLogic/BusinessLogics/ReportLogic.cs b/AutoWorkshopBusinessLogic/BusinessLogics/ReportLogic.cs new file mode 100644 index 0000000..fb84e1c --- /dev/null +++ b/AutoWorkshopBusinessLogic/BusinessLogics/ReportLogic.cs @@ -0,0 +1,142 @@ +using AutoWorkshopBusinessLogic.OfficePackage; +using AutoWorkshopBusinessLogic.OfficePackage.HelperModels; +using AutoWorkshopContracts.BindingModels; +using AutoWorkshopContracts.BusinessLogicContracts; +using AutoWorkshopContracts.SearchModels; +using AutoWorkshopContracts.StoragesContracts; +using AutoWorkshopContracts.ViewModels; + +namespace AutoWorkshopBusinessLogic.BusinessLogics +{ + public class ReportLogic : IReportLogic + { + private readonly IComponentStorage _componentStorage; + private readonly IRepairStorage _RepairStorage; + private readonly IOrderStorage _orderStorage; + private readonly IShopStorage _shopStorage; + private readonly AbstractSaveToExcel _saveToExcel; + private readonly AbstractSaveToWord _saveToWord; + private readonly AbstractSaveToPdf _saveToPdf; + + public ReportLogic(IRepairStorage RepairStorage, IComponentStorage ComponentStorage, IOrderStorage OrderStorage, IShopStorage ShopStorage, + AbstractSaveToExcel SaveToExcel, AbstractSaveToWord SaveToWord, AbstractSaveToPdf SaveToPdf) + { + _RepairStorage = RepairStorage; + _componentStorage = ComponentStorage; + _orderStorage = OrderStorage; + _shopStorage = ShopStorage; + + _saveToExcel = SaveToExcel; + _saveToWord = SaveToWord; + _saveToPdf = SaveToPdf; + } + + public List GetRepairComponents() + { + return _RepairStorage.GetFullList(). + Select(x => new ReportRepairComponentViewModel + { + RepairName = x.RepairName, + Components = x.RepairComponents.Select(x => (x.Value.Item1.ComponentName, x.Value.Item2)).ToList(), + TotalCount = x.RepairComponents.Select(x => x.Value.Item2).Sum() + }) + .ToList(); + } + + public List GetShops() + { + return _shopStorage.GetFullList().Select(x => new ReportShopsViewModel + { + ShopName = x.ShopName, + Repairs = x.ShopRepairs.Select(x => (x.Value.Item1.RepairName, x.Value.Item2)).ToList(), + TotalCount = x.ShopRepairs.Select(x => x.Value.Item2).Sum() + }).ToList(); + } + + public List GetGroupedOrders() + { + return _orderStorage.GetFullList().GroupBy(x => x.DateCreate.Date).Select(x => new ReportGroupedOrdersViewModel + { + Date = x.Key, + OrdersCount = x.Count(), + OrdersSum = x.Select(y => y.Sum).Sum() + }).ToList(); + } + + public List GetOrders(ReportBindingModel Model) + { + return _orderStorage.GetFilteredList(new OrderSearchModel { DateFrom = Model.DateFrom, DateTo = Model.DateTo }) + .Select(x => new ReportOrdersViewModel + { + Id = x.Id, + DateCreate = x.DateCreate, + RepairName = x.RepairName, + Sum = x.Sum, + Status = x.Status.ToString() + }) + .ToList(); + } + + public void SaveRepairsToWordFile(ReportBindingModel Model) + { + _saveToWord.CreateRepairsDoc(new WordRepairsInfo + { + FileName = Model.FileName, + Title = "Список ремонтов", + Repairs = _RepairStorage.GetFullList() + }); + } + + public void SaveRepairComponentToExcelFile(ReportBindingModel Model) + { + _saveToExcel.CreateReport(new ExcelRepairsInfo + { + FileName = Model.FileName, + Title = "Список ремонтов", + RepairComponents = GetRepairComponents() + }); + } + + public void SaveOrdersToPdfFile(ReportBindingModel Model) + { + _saveToPdf.CreateDoc(new PdfOrdersInfo + { + FileName = Model.FileName, + Title = "Список заказов", + DateFrom = Model.DateFrom!.Value, + DateTo = Model.DateTo!.Value, + Orders = GetOrders(Model) + }); + } + + public void SaveShopsToWordFile(ReportBindingModel model) + { + _saveToWord.CreateShopsDoc(new WordShopsInfo + { + FileName = model.FileName, + Title = "Список магазинов", + Shops = _shopStorage.GetFullList() + }); + } + + public void SaveShopsToExcelFile(ReportBindingModel model) + { + _saveToExcel.CreateShopRepairsReport(new ExcelShopsInfo + { + FileName = model.FileName, + Title = "Загруженность магазинов", + ShopRepairs = GetShops() + }); + } + + public void SaveGroupedOrdersToPdfFile(ReportBindingModel model) + { + _saveToPdf.CreateGroupedOrdersDoc(new PdfGroupedOrdersInfo + { + FileName = model.FileName, + Title = "Список заказов, объединенных по датам", + GroupedOrders = GetGroupedOrders() + }); + } + } +} diff --git a/AutoWorkshopBusinessLogic/OfficePackage/AbstractSaveToExcel.cs b/AutoWorkshopBusinessLogic/OfficePackage/AbstractSaveToExcel.cs new file mode 100644 index 0000000..66341bb --- /dev/null +++ b/AutoWorkshopBusinessLogic/OfficePackage/AbstractSaveToExcel.cs @@ -0,0 +1,165 @@ +using AutoWorkshopBusinessLogic.OfficePackage.HelperEnums; +using AutoWorkshopBusinessLogic.OfficePackage.HelperModels; + +namespace AutoWorkshopBusinessLogic.OfficePackage +{ + public abstract class AbstractSaveToExcel + { + public void CreateReport(ExcelRepairsInfo 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 RepComp in Info.RepairComponents) + { + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "A", + RowIndex = RowIndex, + Text = RepComp.RepairName, + StyleInfo = ExcelStyleInfoType.Text + }); + + RowIndex++; + + foreach (var (Component, Count) in RepComp.Components) + { + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "B", + RowIndex = RowIndex, + Text = Component, + 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 = RepComp.TotalCount.ToString(), + StyleInfo = ExcelStyleInfoType.Text + }); + RowIndex++; + } + + SaveExcel(Info); + } + + public void CreateShopRepairsReport(ExcelShopsInfo 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 ShopRep in Info.ShopRepairs) + { + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "A", + RowIndex = RowIndex, + Text = ShopRep.ShopName, + StyleInfo = ExcelStyleInfoType.Text + }); + + RowIndex++; + + foreach (var (Repair, Count) in ShopRep.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 = ShopRep.TotalCount.ToString(), + StyleInfo = ExcelStyleInfoType.Text + }); + + RowIndex++; + } + + SaveExcel(Info); + } + + protected abstract void CreateExcel(IDocumentInfo Info); + + protected abstract void InsertCellInWorksheet(ExcelCellParameters ExcelParams); + + protected abstract void MergeCells(ExcelMergeParameters ExcelParams); + + protected abstract void SaveExcel(IDocumentInfo Info); + } +} diff --git a/AutoWorkshopBusinessLogic/OfficePackage/AbstractSaveToPdf.cs b/AutoWorkshopBusinessLogic/OfficePackage/AbstractSaveToPdf.cs new file mode 100644 index 0000000..94b2490 --- /dev/null +++ b/AutoWorkshopBusinessLogic/OfficePackage/AbstractSaveToPdf.cs @@ -0,0 +1,74 @@ +using AutoWorkshopBusinessLogic.OfficePackage.HelperEnums; +using AutoWorkshopBusinessLogic.OfficePackage.HelperModels; + +namespace AutoWorkshopBusinessLogic.OfficePackage +{ + public abstract class AbstractSaveToPdf + { + public void CreateDoc(PdfOrdersInfo 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", "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.Status.ToString(), 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); + } + + public void CreateGroupedOrdersDoc(PdfGroupedOrdersInfo Info) + { + CreatePdf(Info); + CreateParagraph(new PdfParagraph { Text = Info.Title, Style = "NormalTitle", ParagraphAlignment = PdfParagraphAlignmentType.Center }); + + CreateTable(new List { "4cm", "3cm", "2cm" }); + CreateRow(new PdfRowParameters + { + Texts = new List { "Дата заказа", "Кол-во", "Сумма" }, + Style = "NormalTitle", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + + foreach (var groupedOrder in Info.GroupedOrders) + { + CreateRow(new PdfRowParameters + { + Texts = new List { groupedOrder.Date.ToShortDateString(), groupedOrder.OrdersCount.ToString(), groupedOrder.OrdersSum.ToString() }, + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Left + }); + } + + CreateParagraph(new PdfParagraph { Text = $"Итого: {Info.GroupedOrders.Sum(x => x.OrdersSum)}\t", Style = "Normal", ParagraphAlignment = PdfParagraphAlignmentType.Center }); + SavePdf(Info); + } + + protected abstract void CreatePdf(IDocumentInfo Info); + + protected abstract void CreateParagraph(PdfParagraph Paragraph); + + protected abstract void CreateTable(List Columns); + + protected abstract void CreateRow(PdfRowParameters RowParameters); + + protected abstract void SavePdf(IDocumentInfo Info); + } +} diff --git a/AutoWorkshopBusinessLogic/OfficePackage/AbstractSaveToWord.cs b/AutoWorkshopBusinessLogic/OfficePackage/AbstractSaveToWord.cs new file mode 100644 index 0000000..3ca7cd2 --- /dev/null +++ b/AutoWorkshopBusinessLogic/OfficePackage/AbstractSaveToWord.cs @@ -0,0 +1,93 @@ +using AutoWorkshopBusinessLogic.OfficePackage.HelperEnums; +using AutoWorkshopBusinessLogic.OfficePackage.HelperModels; + +namespace AutoWorkshopBusinessLogic.OfficePackage +{ + public abstract class AbstractSaveToWord + { + public void CreateRepairsDoc(WordRepairsInfo 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 Repair in Info.Repairs) + { + CreateParagraph(new WordParagraph + { + Texts = new List<(string, WordTextProperties)> { + (Repair.RepairName, new WordTextProperties { Size = "24", Bold = true}), + ("\t"+Repair.Price.ToString(), new WordTextProperties{Size = "24"}) + }, + TextProperties = new WordTextProperties + { + Size = "24", + JustificationType = WordJustificationType.Both + } + }); + } + + SaveWord(Info); + } + + public void CreateShopsDoc(WordShopsInfo 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 + } + }); + + CreateTable(new List { "3000", "3000", "3000" }); + CreateRow(new WordRowParameters + { + Texts = new List { "Название", "Адрес", "Дата открытия" }, + TextProperties = new WordTextProperties + { + Size = "24", + Bold = true, + JustificationType = WordJustificationType.Center + } + }); + + foreach (var Shop in Info.Shops) + { + CreateRow(new WordRowParameters + { + Texts = new List { Shop.ShopName, Shop.Address, Shop.OpeningDate.ToString() }, + TextProperties = new WordTextProperties + { + Size = "22", + JustificationType = WordJustificationType.Both + } + }); + } + + SaveWord(Info); + } + + protected abstract void CreateWord(IDocumentInfo Info); + + protected abstract void CreateParagraph(WordParagraph Paragraph); + + protected abstract void SaveWord(IDocumentInfo Info); + + protected abstract void CreateTable(List Colums); + + protected abstract void CreateRow(WordRowParameters RowParameters); + } +} diff --git a/AutoWorkshopBusinessLogic/OfficePackage/HelperEnums/ExcelStyleInfoType.cs b/AutoWorkshopBusinessLogic/OfficePackage/HelperEnums/ExcelStyleInfoType.cs new file mode 100644 index 0000000..8f59b3a --- /dev/null +++ b/AutoWorkshopBusinessLogic/OfficePackage/HelperEnums/ExcelStyleInfoType.cs @@ -0,0 +1,9 @@ +namespace AutoWorkshopBusinessLogic.OfficePackage.HelperEnums +{ + public enum ExcelStyleInfoType + { + Title, + Text, + TextWithBroder + } +} diff --git a/AutoWorkshopBusinessLogic/OfficePackage/HelperEnums/PdfParagraphAlignmentType.cs b/AutoWorkshopBusinessLogic/OfficePackage/HelperEnums/PdfParagraphAlignmentType.cs new file mode 100644 index 0000000..4c62f35 --- /dev/null +++ b/AutoWorkshopBusinessLogic/OfficePackage/HelperEnums/PdfParagraphAlignmentType.cs @@ -0,0 +1,9 @@ +namespace AutoWorkshopBusinessLogic.OfficePackage.HelperEnums +{ + public enum PdfParagraphAlignmentType + { + Center, + Left, + Rigth + } +} diff --git a/AutoWorkshopBusinessLogic/OfficePackage/HelperEnums/WordJustificationType.cs b/AutoWorkshopBusinessLogic/OfficePackage/HelperEnums/WordJustificationType.cs new file mode 100644 index 0000000..c3945de --- /dev/null +++ b/AutoWorkshopBusinessLogic/OfficePackage/HelperEnums/WordJustificationType.cs @@ -0,0 +1,8 @@ +namespace AutoWorkshopBusinessLogic.OfficePackage.HelperEnums +{ + public enum WordJustificationType + { + Center, + Both + } +} diff --git a/AutoWorkshopBusinessLogic/OfficePackage/HelperModels/ExcelCellParameters.cs b/AutoWorkshopBusinessLogic/OfficePackage/HelperModels/ExcelCellParameters.cs new file mode 100644 index 0000000..099e203 --- /dev/null +++ b/AutoWorkshopBusinessLogic/OfficePackage/HelperModels/ExcelCellParameters.cs @@ -0,0 +1,17 @@ +using AutoWorkshopBusinessLogic.OfficePackage.HelperEnums; + +namespace AutoWorkshopBusinessLogic.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/AutoWorkshopBusinessLogic/OfficePackage/HelperModels/ExcelMergeParameters.cs b/AutoWorkshopBusinessLogic/OfficePackage/HelperModels/ExcelMergeParameters.cs new file mode 100644 index 0000000..beffa0a --- /dev/null +++ b/AutoWorkshopBusinessLogic/OfficePackage/HelperModels/ExcelMergeParameters.cs @@ -0,0 +1,11 @@ +namespace AutoWorkshopBusinessLogic.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/AutoWorkshopBusinessLogic/OfficePackage/HelperModels/ExcelRepairsInfo.cs b/AutoWorkshopBusinessLogic/OfficePackage/HelperModels/ExcelRepairsInfo.cs new file mode 100644 index 0000000..58845ee --- /dev/null +++ b/AutoWorkshopBusinessLogic/OfficePackage/HelperModels/ExcelRepairsInfo.cs @@ -0,0 +1,13 @@ +using AutoWorkshopContracts.ViewModels; + +namespace AutoWorkshopBusinessLogic.OfficePackage.HelperModels +{ + public class ExcelRepairsInfo : IDocumentInfo + { + public string FileName { get; set; } = string.Empty; + + public string Title { get; set; } = string.Empty; + + public List RepairComponents { get; set; } = new(); + } +} diff --git a/AutoWorkshopBusinessLogic/OfficePackage/HelperModels/ExcelShopsInfo.cs b/AutoWorkshopBusinessLogic/OfficePackage/HelperModels/ExcelShopsInfo.cs new file mode 100644 index 0000000..932a172 --- /dev/null +++ b/AutoWorkshopBusinessLogic/OfficePackage/HelperModels/ExcelShopsInfo.cs @@ -0,0 +1,13 @@ +using AutoWorkshopContracts.ViewModels; + +namespace AutoWorkshopBusinessLogic.OfficePackage.HelperModels +{ + public class ExcelShopsInfo : IDocumentInfo + { + public string FileName { get; set; } = string.Empty; + + public string Title { get; set; } = string.Empty; + + public List ShopRepairs { get; set; } = new(); + } +} diff --git a/AutoWorkshopBusinessLogic/OfficePackage/HelperModels/IDocumentInfo.cs b/AutoWorkshopBusinessLogic/OfficePackage/HelperModels/IDocumentInfo.cs new file mode 100644 index 0000000..048e797 --- /dev/null +++ b/AutoWorkshopBusinessLogic/OfficePackage/HelperModels/IDocumentInfo.cs @@ -0,0 +1,9 @@ +namespace AutoWorkshopBusinessLogic.OfficePackage.HelperModels +{ + public interface IDocumentInfo + { + public string FileName { get; set; } + + public string Title { get; set; } + } +} diff --git a/AutoWorkshopBusinessLogic/OfficePackage/HelperModels/PdfGroupedOrdersInfo.cs b/AutoWorkshopBusinessLogic/OfficePackage/HelperModels/PdfGroupedOrdersInfo.cs new file mode 100644 index 0000000..f268593 --- /dev/null +++ b/AutoWorkshopBusinessLogic/OfficePackage/HelperModels/PdfGroupedOrdersInfo.cs @@ -0,0 +1,17 @@ +using AutoWorkshopContracts.ViewModels; + +namespace AutoWorkshopBusinessLogic.OfficePackage.HelperModels +{ + public class PdfGroupedOrdersInfo : IDocumentInfo + { + 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 GroupedOrders { get; set; } = new(); + } +} diff --git a/AutoWorkshopBusinessLogic/OfficePackage/HelperModels/PdfOrdersInfo.cs b/AutoWorkshopBusinessLogic/OfficePackage/HelperModels/PdfOrdersInfo.cs new file mode 100644 index 0000000..ee25fd5 --- /dev/null +++ b/AutoWorkshopBusinessLogic/OfficePackage/HelperModels/PdfOrdersInfo.cs @@ -0,0 +1,17 @@ +using AutoWorkshopContracts.ViewModels; + +namespace AutoWorkshopBusinessLogic.OfficePackage.HelperModels +{ + public class PdfOrdersInfo : IDocumentInfo + { + 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/AutoWorkshopBusinessLogic/OfficePackage/HelperModels/PdfParagraph.cs b/AutoWorkshopBusinessLogic/OfficePackage/HelperModels/PdfParagraph.cs new file mode 100644 index 0000000..f4161ee --- /dev/null +++ b/AutoWorkshopBusinessLogic/OfficePackage/HelperModels/PdfParagraph.cs @@ -0,0 +1,13 @@ +using AutoWorkshopBusinessLogic.OfficePackage.HelperEnums; + +namespace AutoWorkshopBusinessLogic.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/AutoWorkshopBusinessLogic/OfficePackage/HelperModels/PdfRowParameters.cs b/AutoWorkshopBusinessLogic/OfficePackage/HelperModels/PdfRowParameters.cs new file mode 100644 index 0000000..c019138 --- /dev/null +++ b/AutoWorkshopBusinessLogic/OfficePackage/HelperModels/PdfRowParameters.cs @@ -0,0 +1,13 @@ +using AutoWorkshopBusinessLogic.OfficePackage.HelperEnums; + +namespace AutoWorkshopBusinessLogic.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/AutoWorkshopBusinessLogic/OfficePackage/HelperModels/WordParagraph.cs b/AutoWorkshopBusinessLogic/OfficePackage/HelperModels/WordParagraph.cs new file mode 100644 index 0000000..b3cf8ef --- /dev/null +++ b/AutoWorkshopBusinessLogic/OfficePackage/HelperModels/WordParagraph.cs @@ -0,0 +1,9 @@ +namespace AutoWorkshopBusinessLogic.OfficePackage.HelperModels +{ + public class WordParagraph + { + public List<(string, WordTextProperties)> Texts { get; set; } = new(); + + public WordTextProperties? TextProperties { get; set; } + } +} diff --git a/AutoWorkshopBusinessLogic/OfficePackage/HelperModels/WordRepairsInfo.cs b/AutoWorkshopBusinessLogic/OfficePackage/HelperModels/WordRepairsInfo.cs new file mode 100644 index 0000000..6c7c0fe --- /dev/null +++ b/AutoWorkshopBusinessLogic/OfficePackage/HelperModels/WordRepairsInfo.cs @@ -0,0 +1,13 @@ +using AutoWorkshopContracts.ViewModels; + +namespace AutoWorkshopBusinessLogic.OfficePackage.HelperModels +{ + public class WordRepairsInfo : IDocumentInfo + { + public string FileName { get; set; } = string.Empty; + + public string Title { get; set; } = string.Empty; + + public List Repairs { get; set; } = new(); + } +} diff --git a/AutoWorkshopBusinessLogic/OfficePackage/HelperModels/WordRowParameters.cs b/AutoWorkshopBusinessLogic/OfficePackage/HelperModels/WordRowParameters.cs new file mode 100644 index 0000000..5395e27 --- /dev/null +++ b/AutoWorkshopBusinessLogic/OfficePackage/HelperModels/WordRowParameters.cs @@ -0,0 +1,9 @@ +namespace AutoWorkshopBusinessLogic.OfficePackage.HelperModels +{ + public class WordRowParameters + { + public List Texts { get; set; } = new(); + + public WordTextProperties TextProperties { get; set; } = new(); + } +} diff --git a/AutoWorkshopBusinessLogic/OfficePackage/HelperModels/WordShopsInfo.cs b/AutoWorkshopBusinessLogic/OfficePackage/HelperModels/WordShopsInfo.cs new file mode 100644 index 0000000..2a2f8db --- /dev/null +++ b/AutoWorkshopBusinessLogic/OfficePackage/HelperModels/WordShopsInfo.cs @@ -0,0 +1,13 @@ +using AutoWorkshopContracts.ViewModels; + +namespace AutoWorkshopBusinessLogic.OfficePackage.HelperModels +{ + public class WordShopsInfo : IDocumentInfo + { + public string FileName { get; set; } = string.Empty; + + public string Title { get; set; } = string.Empty; + + public List Shops { get; set; } = new(); + } +} diff --git a/AutoWorkshopBusinessLogic/OfficePackage/HelperModels/WordTextProperties.cs b/AutoWorkshopBusinessLogic/OfficePackage/HelperModels/WordTextProperties.cs new file mode 100644 index 0000000..33116cb --- /dev/null +++ b/AutoWorkshopBusinessLogic/OfficePackage/HelperModels/WordTextProperties.cs @@ -0,0 +1,13 @@ +using AutoWorkshopBusinessLogic.OfficePackage.HelperEnums; + +namespace AutoWorkshopBusinessLogic.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/AutoWorkshopBusinessLogic/OfficePackage/Implements/SaveToExcel.cs b/AutoWorkshopBusinessLogic/OfficePackage/Implements/SaveToExcel.cs new file mode 100644 index 0000000..deddaf2 --- /dev/null +++ b/AutoWorkshopBusinessLogic/OfficePackage/Implements/SaveToExcel.cs @@ -0,0 +1,281 @@ +using AutoWorkshopBusinessLogic.OfficePackage.HelperEnums; +using AutoWorkshopBusinessLogic.OfficePackage.HelperModels; +using DocumentFormat.OpenXml; +using DocumentFormat.OpenXml.Office2010.Excel; +using DocumentFormat.OpenXml.Office2013.Excel; +using DocumentFormat.OpenXml.Packaging; +using DocumentFormat.OpenXml.Spreadsheet; + +namespace AutoWorkshopBusinessLogic.OfficePackage.Implements +{ + public class SaveToExcel : AbstractSaveToExcel + { + private SpreadsheetDocument? _spreadsheetDocument; + private SharedStringTablePart? _shareStringPart; + private Worksheet? _worksheet; + + private static void CreateStyles(WorkbookPart WorkbookPart) + { + var sp = WorkbookPart.AddNewPart(); + sp.Stylesheet = new Stylesheet(); + + var Fonts = new Fonts() { Count = 2U, KnownFonts = true }; + + var FontUsual = new Font(); + FontUsual.Append(new FontSize() { Val = 12D }); + FontUsual.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Theme = 1U }); + FontUsual.Append(new FontName() { Val = "Times New Roman" }); + FontUsual.Append(new FontFamilyNumbering() { Val = 2 }); + FontUsual.Append(new FontScheme() { Val = FontSchemeValues.Minor }); + + var FontTitle = new Font(); + FontTitle.Append(new Bold()); + FontTitle.Append(new FontSize() { Val = 14D }); + FontTitle.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Theme = 1U }); + FontTitle.Append(new FontName() { Val = "Times New Roman" }); + FontTitle.Append(new FontFamilyNumbering() { Val = 2 }); + FontTitle.Append(new FontScheme() { Val = FontSchemeValues.Minor }); + + Fonts.Append(FontUsual); + Fonts.Append(FontTitle); + + var Fills = new Fills() { Count = 2U }; + + var Fill1 = new Fill(); + Fill1.Append(new PatternFill() { PatternType = PatternValues.None }); + + var Fill2 = new Fill(); + Fill2.Append(new PatternFill() { PatternType = PatternValues.Gray125 }); + + Fills.Append(Fill1); + Fills.Append(Fill2); + + var Borders = new Borders() { Count = 2U }; + + var BorderNoBorder = new Border(); + BorderNoBorder.Append(new LeftBorder()); + BorderNoBorder.Append(new RightBorder()); + BorderNoBorder.Append(new TopBorder()); + BorderNoBorder.Append(new BottomBorder()); + BorderNoBorder.Append(new DiagonalBorder()); + + var BorderThin = new Border(); + + var LeftBorder = new LeftBorder() { Style = BorderStyleValues.Thin }; + LeftBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Indexed = 64U }); + + var RightBorder = new RightBorder() { Style = BorderStyleValues.Thin }; + RightBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Indexed = 64U }); + + var TopBorder = new TopBorder() { Style = BorderStyleValues.Thin }; + TopBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Indexed = 64U }); + + var BottomBorder = new BottomBorder() { Style = BorderStyleValues.Thin }; + BottomBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Indexed = 64U }); + + BorderThin.Append(LeftBorder); + BorderThin.Append(RightBorder); + BorderThin.Append(TopBorder); + BorderThin.Append(BottomBorder); + BorderThin.Append(new DiagonalBorder()); + + Borders.Append(BorderNoBorder); + Borders.Append(BorderThin); + + var CellStyleFormats = new CellStyleFormats() { Count = 1U }; + var CellFormatStyle = new CellFormat() { NumberFormatId = 0U, FontId = 0U, FillId = 0U, BorderId = 0U }; + + CellStyleFormats.Append(CellFormatStyle); + + var CellFormats = new CellFormats() { Count = 3U }; + var CellFormatFont = new CellFormat() { NumberFormatId = 0U, FontId = 0U, FillId = 0U, BorderId = 0U, FormatId = 0U, ApplyFont = true }; + var CellFormatFontAndBorder = new CellFormat() { NumberFormatId = 0U, FontId = 0U, FillId = 0U, BorderId = 1U, FormatId = 0U, ApplyFont = true, ApplyBorder = true }; + var CellFormatTitle = new CellFormat() { NumberFormatId = 0U, FontId = 1U, FillId = 0U, BorderId = 0U, FormatId = 0U, Alignment = new Alignment() { Vertical = VerticalAlignmentValues.Center, WrapText = true, Horizontal = HorizontalAlignmentValues.Center }, ApplyFont = true }; + + CellFormats.Append(CellFormatFont); + CellFormats.Append(CellFormatFontAndBorder); + CellFormats.Append(CellFormatTitle); + + var CellStyles = new CellStyles() { Count = 1U }; + + CellStyles.Append(new CellStyle() { Name = "Normal", FormatId = 0U, BuiltinId = 0U }); + + var DifferentialFormats = new DocumentFormat.OpenXml.Office2013.Excel.DifferentialFormats() { Count = 0U }; + + var TableStyles = new TableStyles() { Count = 0U, DefaultTableStyle = "TableStyleMedium2", DefaultPivotStyle = "PivotStyleLight16" }; + + var StylesheetExtensionList = new StylesheetExtensionList(); + + var StylesheetExtension1 = new StylesheetExtension() { Uri = "{EB79DEF2-80B8-43e5-95BD-54CBDDF9020C}" }; + StylesheetExtension1.AddNamespaceDeclaration("x14", "http://schemas.microsoft.com/office/spreadsheetml/2009/9/main"); + StylesheetExtension1.Append(new SlicerStyles() { DefaultSlicerStyle = "SlicerStyleLight1" }); + + var StylesheetExtension2 = new StylesheetExtension() { Uri = "{9260A510-F301-46a8-8635-F512D64BE5F5}" }; + StylesheetExtension2.AddNamespaceDeclaration("x15", "http://schemas.microsoft.com/office/spreadsheetml/2010/11/main"); + StylesheetExtension2.Append(new TimelineStyles() { DefaultTimelineStyle = "TimeSlicerStyleLight1" }); + + StylesheetExtensionList.Append(StylesheetExtension1); + StylesheetExtensionList.Append(StylesheetExtension2); + + sp.Stylesheet.Append(Fonts); + sp.Stylesheet.Append(Fills); + sp.Stylesheet.Append(Borders); + sp.Stylesheet.Append(CellStyleFormats); + sp.Stylesheet.Append(CellFormats); + sp.Stylesheet.Append(CellStyles); + sp.Stylesheet.Append(DifferentialFormats); + sp.Stylesheet.Append(TableStyles); + sp.Stylesheet.Append(StylesheetExtensionList); + } + + private static uint GetStyleValue(ExcelStyleInfoType StyleInfo) + { + return StyleInfo switch + { + ExcelStyleInfoType.Title => 2U, + ExcelStyleInfoType.TextWithBroder => 1U, + ExcelStyleInfoType.Text => 0U, + _ => 0U, + }; + } + + protected override void CreateExcel(IDocumentInfo Info) + { + _spreadsheetDocument = SpreadsheetDocument.Create(Info.FileName, SpreadsheetDocumentType.Workbook); + + var WorkbookPart = _spreadsheetDocument.AddWorkbookPart(); + WorkbookPart.Workbook = new Workbook(); + + CreateStyles(WorkbookPart); + + _shareStringPart = _spreadsheetDocument.WorkbookPart!.GetPartsOfType().Any() + ? _spreadsheetDocument.WorkbookPart.GetPartsOfType().First() + : _spreadsheetDocument.WorkbookPart.AddNewPart(); + + // Создаем SharedStringTable, если его нет + if (_shareStringPart.SharedStringTable == null) + { + _shareStringPart.SharedStringTable = new SharedStringTable(); + } + + // Создаем лист в книгу + var WorksheetPart = WorkbookPart.AddNewPart(); + WorksheetPart.Worksheet = new Worksheet(new SheetData()); + + // Добавляем лист в книгу + var Sheets = _spreadsheetDocument.WorkbookPart.Workbook.AppendChild(new Sheets()); + var Sheet = new Sheet() + { + Id = _spreadsheetDocument.WorkbookPart.GetIdOfPart(WorksheetPart), + SheetId = 1, + Name = "Лист" + }; + + Sheets.Append(Sheet); + + _worksheet = WorksheetPart.Worksheet; + } + + protected override void InsertCellInWorksheet(ExcelCellParameters ExcelParams) + { + if (_worksheet == null || _shareStringPart == null) + { + return; + } + var SheetData = _worksheet.GetFirstChild(); + if (SheetData == null) + { + return; + } + + // Ищем строку, либо добавляем ее + Row row; + if (SheetData.Elements().Where(r => r.RowIndex! == ExcelParams.RowIndex).Any()) + { + row = SheetData.Elements().Where(r => r.RowIndex! == ExcelParams.RowIndex).First(); + } + else + { + row = new Row() { RowIndex = ExcelParams.RowIndex }; + SheetData.Append(row); + } + + // Ищем нужную ячейку + Cell cell; + if (row.Elements().Where(c => c.CellReference!.Value == ExcelParams.CellReference).Any()) + { + cell = row.Elements().Where(c => c.CellReference!.Value == ExcelParams.CellReference).First(); + } + else + { + // Все ячейки должны быть последовательно друг за другом расположены + // нужно определить, после какой вставлять + Cell? refCell = null; + foreach (Cell rowCell in row.Elements()) + { + if (string.Compare(rowCell.CellReference!.Value, ExcelParams.CellReference, true) > 0) + { + refCell = rowCell; + break; + } + } + + var NewCell = new Cell() { CellReference = ExcelParams.CellReference }; + row.InsertBefore(NewCell, refCell); + + cell = NewCell; + } + + // вставляем новый текст + _shareStringPart.SharedStringTable.AppendChild(new SharedStringItem(new Text(ExcelParams.Text))); + _shareStringPart.SharedStringTable.Save(); + + cell.CellValue = new CellValue((_shareStringPart.SharedStringTable.Elements().Count() - 1).ToString()); + cell.DataType = new EnumValue(CellValues.SharedString); + cell.StyleIndex = GetStyleValue(ExcelParams.StyleInfo); + } + + protected override void MergeCells(ExcelMergeParameters ExcelParams) + { + if (_worksheet == null) + { + return; + } + MergeCells MergeCells; + + if (_worksheet.Elements().Any()) + { + MergeCells = _worksheet.Elements().First(); + } + else + { + MergeCells = new MergeCells(); + + if (_worksheet.Elements().Any()) + { + _worksheet.InsertAfter(MergeCells, _worksheet.Elements().First()); + } + else + { + _worksheet.InsertAfter(MergeCells, _worksheet.Elements().First()); + } + } + + var MergeCell = new MergeCell() + { + Reference = new StringValue(ExcelParams.Merge) + }; + + MergeCells.Append(MergeCell); + } + + protected override void SaveExcel(IDocumentInfo Info) + { + if (_spreadsheetDocument == null) + return; + + _spreadsheetDocument.WorkbookPart!.Workbook.Save(); + _spreadsheetDocument.Close(); + } + } +} diff --git a/AutoWorkshopBusinessLogic/OfficePackage/Implements/SaveToPdf.cs b/AutoWorkshopBusinessLogic/OfficePackage/Implements/SaveToPdf.cs new file mode 100644 index 0000000..b1ed115 --- /dev/null +++ b/AutoWorkshopBusinessLogic/OfficePackage/Implements/SaveToPdf.cs @@ -0,0 +1,108 @@ +using AutoWorkshopBusinessLogic.OfficePackage.HelperEnums; +using AutoWorkshopBusinessLogic.OfficePackage.HelperModels; +using MigraDoc.DocumentObjectModel; +using MigraDoc.DocumentObjectModel.Tables; +using MigraDoc.Rendering; + +namespace AutoWorkshopBusinessLogic.OfficePackage.Implements +{ + public class SaveToPdf : AbstractSaveToPdf + { + private Document? _document; + private Section? _section; + private Table? _table; + + private static ParagraphAlignment GetParagraphAlignment(PdfParagraphAlignmentType Type) + { + return Type switch + { + PdfParagraphAlignmentType.Center => ParagraphAlignment.Center, + PdfParagraphAlignmentType.Left => ParagraphAlignment.Left, + PdfParagraphAlignmentType.Rigth => ParagraphAlignment.Right, + _ => ParagraphAlignment.Justify, + }; + } + + private static void DefineStyles(Document Document) + { + var Style = Document.Styles["Normal"]; + Style.Font.Name = "Times New Roman"; + Style.Font.Size = 14; + + Style = Document.Styles.AddStyle("NormalTitle", "Normal"); + Style.Font.Bold = true; + } + + protected override void CreatePdf(IDocumentInfo Info) + { + _document = new Document(); + DefineStyles(_document); + + _section = _document.AddSection(); + } + + protected override void CreateParagraph(PdfParagraph PdfParagraph) + { + if (_section == null) + return; + + var Paragraph = _section.AddParagraph(PdfParagraph.Text); + + Paragraph.Format.SpaceAfter = "1cm"; + Paragraph.Format.Alignment = GetParagraphAlignment(PdfParagraph.ParagraphAlignment); + Paragraph.Style = PdfParagraph.Style; + } + + protected override void CreateTable(List Columns) + { + if (_document == null) + return; + + _table = _document.LastSection.AddTable(); + + foreach (var Elem in Columns) + { + _table.AddColumn(Elem); + } + } + + protected override void CreateRow(PdfRowParameters RowParameters) + { + if (_table == null) + return; + + var Row = _table.AddRow(); + + for (int i = 0; i < RowParameters.Texts.Count; ++i) + { + Row.Cells[i].AddParagraph(RowParameters.Texts[i]); + + if (!string.IsNullOrEmpty(RowParameters.Style)) + { + Row.Cells[i].Style = RowParameters.Style; + } + + Unit borderWidth = 0.5; + + Row.Cells[i].Borders.Left.Width = borderWidth; + Row.Cells[i].Borders.Right.Width = borderWidth; + Row.Cells[i].Borders.Top.Width = borderWidth; + Row.Cells[i].Borders.Bottom.Width = borderWidth; + + Row.Cells[i].Format.Alignment = GetParagraphAlignment(RowParameters.ParagraphAlignment); + Row.Cells[i].VerticalAlignment = VerticalAlignment.Center; + } + } + + protected override void SavePdf(IDocumentInfo Info) + { + var Renderer = new PdfDocumentRenderer(true) + { + Document = _document + }; + + Renderer.RenderDocument(); + Renderer.PdfDocument.Save(Info.FileName); + } + } +} diff --git a/AutoWorkshopBusinessLogic/OfficePackage/Implements/SaveToWord.cs b/AutoWorkshopBusinessLogic/OfficePackage/Implements/SaveToWord.cs new file mode 100644 index 0000000..af01c8d --- /dev/null +++ b/AutoWorkshopBusinessLogic/OfficePackage/Implements/SaveToWord.cs @@ -0,0 +1,192 @@ +using AutoWorkshopBusinessLogic.OfficePackage.HelperEnums; +using AutoWorkshopBusinessLogic.OfficePackage.HelperModels; +using DocumentFormat.OpenXml; +using DocumentFormat.OpenXml.Packaging; +using DocumentFormat.OpenXml.Wordprocessing; + +namespace AutoWorkshopBusinessLogic.OfficePackage.Implements +{ + public class SaveToWord : AbstractSaveToWord + { + private WordprocessingDocument? _wordDocument; + private Body? _docBody; + + private static JustificationValues GetJustificationValues(WordJustificationType Type) + { + return Type switch + { + WordJustificationType.Both => JustificationValues.Both, + WordJustificationType.Center => JustificationValues.Center, + _ => JustificationValues.Left, + }; + } + + private static SectionProperties CreateSectionProperties() + { + var Properties = new SectionProperties(); + + var PageSize = new PageSize + { + Orient = PageOrientationValues.Portrait + }; + + Properties.AppendChild(PageSize); + return Properties; + } + + private static ParagraphProperties? CreateParagraphProperties(WordTextProperties? ParagraphProperties) + { + if (ParagraphProperties == null) + return null; + + + var Properties = new ParagraphProperties(); + + Properties.AppendChild(new Justification() + { + Val = GetJustificationValues(ParagraphProperties.JustificationType) + }); + + Properties.AppendChild(new SpacingBetweenLines + { + LineRule = LineSpacingRuleValues.Auto + }); + + Properties.AppendChild(new Indentation()); + + var ParagraphMarkRunProperties = new ParagraphMarkRunProperties(); + if (!string.IsNullOrEmpty(ParagraphProperties.Size)) + { + ParagraphMarkRunProperties.AppendChild(new FontSize { Val = ParagraphProperties.Size }); + } + + Properties.AppendChild(ParagraphMarkRunProperties); + return Properties; + } + + protected override void CreateWord(IDocumentInfo Info) + { + _wordDocument = WordprocessingDocument.Create(Info.FileName, WordprocessingDocumentType.Document); + MainDocumentPart mainPart = _wordDocument.AddMainDocumentPart(); + + mainPart.Document = new Document(); + _docBody = mainPart.Document.AppendChild(new Body()); + } + + protected override void CreateParagraph(WordParagraph Paragraph) + { + if (_docBody == null || Paragraph == null) + { + return; + } + + var DocParagraph = new Paragraph(); + DocParagraph.AppendChild(CreateParagraphProperties(Paragraph.TextProperties)); + + foreach (var Run in Paragraph.Texts) + { + var DocRun = new Run(); + + var Properties = new RunProperties(); + Properties.AppendChild(new FontSize { Val = Run.Item2.Size }); + + if (Run.Item2.Bold) + { + Properties.AppendChild(new Bold()); + } + + DocRun.AppendChild(Properties); + DocRun.AppendChild(new Text { Text = Run.Item1, Space = SpaceProcessingModeValues.Preserve }); + DocParagraph.AppendChild(DocRun); + } + + _docBody.AppendChild(DocParagraph); + } + + protected override void SaveWord(IDocumentInfo Info) + { + if (_docBody == null || _wordDocument == null) + { + return; + } + + _docBody.AppendChild(CreateSectionProperties()); + _wordDocument.MainDocumentPart!.Document.Save(); + _wordDocument.Close(); + } + + private Table? _lastTable; + + protected override void CreateTable(List Columns) + { + if (_docBody == null) + return; + + _lastTable = new Table(); + + var TableProp = new TableProperties(); + TableProp.AppendChild(new TableLayout { Type = TableLayoutValues.Fixed }); + TableProp.AppendChild(new TableBorders( + new TopBorder() { Val = new EnumValue(BorderValues.Single), Size = 4 }, + new LeftBorder() { Val = new EnumValue(BorderValues.Single), Size = 4 }, + new RightBorder() { Val = new EnumValue(BorderValues.Single), Size = 4 }, + new BottomBorder() { Val = new EnumValue(BorderValues.Single), Size = 4 }, + new InsideHorizontalBorder() { Val = new EnumValue(BorderValues.Single), Size = 4 }, + new InsideVerticalBorder() { Val = new EnumValue(BorderValues.Single), Size = 4 } + )); + TableProp.AppendChild(new TableWidth { Type = TableWidthUnitValues.Auto }); + _lastTable.AppendChild(TableProp); + + TableGrid TableGrid = new TableGrid(); + + foreach (var Column in Columns) + { + TableGrid.AppendChild(new GridColumn() { Width = Column }); + } + + _lastTable.AppendChild(TableGrid); + _docBody.AppendChild(_lastTable); + } + + protected override void CreateRow(WordRowParameters RowParameters) + { + if (_docBody == null || _lastTable == null) + return; + + TableRow DocRow = new TableRow(); + foreach (var Column in RowParameters.Texts) + { + var DocParagraph = new Paragraph(); + WordParagraph Paragraph = new WordParagraph + { + Texts = new List<(string, WordTextProperties)> { (Column, RowParameters.TextProperties) }, + TextProperties = RowParameters.TextProperties + }; + + DocParagraph.AppendChild(CreateParagraphProperties(Paragraph.TextProperties)); + + foreach (var Run in Paragraph.Texts) + { + var DocRun = new Run(); + var Properties = new RunProperties(); + + Properties.AppendChild(new FontSize { Val = Run.Item2.Size }); + if (Run.Item2.Bold) + { + Properties.AppendChild(new Bold()); + } + DocRun.AppendChild(Properties); + DocRun.AppendChild(new Text { Text = Run.Item1, Space = SpaceProcessingModeValues.Preserve }); + DocParagraph.AppendChild(DocRun); + } + + TableCell docCell = new TableCell(); + + docCell.AppendChild(DocParagraph); + DocRow.AppendChild(docCell); + } + + _lastTable.AppendChild(DocRow); + } + } +} diff --git a/AutoWorkshopContracts/BindingModels/ReportBindingModel.cs b/AutoWorkshopContracts/BindingModels/ReportBindingModel.cs new file mode 100644 index 0000000..6e1af1b --- /dev/null +++ b/AutoWorkshopContracts/BindingModels/ReportBindingModel.cs @@ -0,0 +1,11 @@ +namespace AutoWorkshopContracts.BindingModels +{ + public class ReportBindingModel + { + public string FileName { get; set; } = string.Empty; + + public DateTime? DateFrom { get; set; } + + public DateTime? DateTo { get; set; } + } +} diff --git a/AutoWorkshopContracts/BusinessLogicContracts/IReportLogic.cs b/AutoWorkshopContracts/BusinessLogicContracts/IReportLogic.cs new file mode 100644 index 0000000..44f73ae --- /dev/null +++ b/AutoWorkshopContracts/BusinessLogicContracts/IReportLogic.cs @@ -0,0 +1,28 @@ +using AutoWorkshopContracts.BindingModels; +using AutoWorkshopContracts.ViewModels; + +namespace AutoWorkshopContracts.BusinessLogicContracts +{ + public interface IReportLogic + { + List GetRepairComponents(); + + List GetOrders(ReportBindingModel Model); + + List GetShops(); + + List GetGroupedOrders(); + + void SaveRepairsToWordFile(ReportBindingModel Model); + + void SaveRepairComponentToExcelFile(ReportBindingModel Model); + + void SaveOrdersToPdfFile(ReportBindingModel Model); + + void SaveShopsToWordFile(ReportBindingModel Model); + + void SaveShopsToExcelFile(ReportBindingModel Model); + + void SaveGroupedOrdersToPdfFile(ReportBindingModel Model); + } +} diff --git a/AutoWorkshopContracts/SearchModels/OrderSearchModel.cs b/AutoWorkshopContracts/SearchModels/OrderSearchModel.cs index a808eae..6066fbd 100644 --- a/AutoWorkshopContracts/SearchModels/OrderSearchModel.cs +++ b/AutoWorkshopContracts/SearchModels/OrderSearchModel.cs @@ -3,5 +3,9 @@ public class OrderSearchModel { public int? Id { get; set; } + + public DateTime? DateFrom { get; set; } + + public DateTime? DateTo { get; set; } } } diff --git a/AutoWorkshopContracts/ViewModels/ReportGroupedOrdersViewModel.cs b/AutoWorkshopContracts/ViewModels/ReportGroupedOrdersViewModel.cs new file mode 100644 index 0000000..ef0b65d --- /dev/null +++ b/AutoWorkshopContracts/ViewModels/ReportGroupedOrdersViewModel.cs @@ -0,0 +1,11 @@ +namespace AutoWorkshopContracts.ViewModels +{ + public class ReportGroupedOrdersViewModel + { + public DateTime Date { get; set; } = DateTime.Now; + + public int OrdersCount { get; set; } + + public double OrdersSum { get; set; } + } +} diff --git a/AutoWorkshopContracts/ViewModels/ReportOrdersViewModel.cs b/AutoWorkshopContracts/ViewModels/ReportOrdersViewModel.cs new file mode 100644 index 0000000..22edff5 --- /dev/null +++ b/AutoWorkshopContracts/ViewModels/ReportOrdersViewModel.cs @@ -0,0 +1,15 @@ +namespace AutoWorkshopContracts.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; } + + public string Status { get; set; } = string.Empty; + } +} diff --git a/AutoWorkshopContracts/ViewModels/ReportRepairComponentViewModel.cs b/AutoWorkshopContracts/ViewModels/ReportRepairComponentViewModel.cs new file mode 100644 index 0000000..e926f65 --- /dev/null +++ b/AutoWorkshopContracts/ViewModels/ReportRepairComponentViewModel.cs @@ -0,0 +1,11 @@ +namespace AutoWorkshopContracts.ViewModels +{ + public class ReportRepairComponentViewModel + { + public string RepairName { get; set; } = string.Empty; + + public int TotalCount { get; set; } + + public List<(string Component, int Count)> Components { get; set; } = new(); + } +} diff --git a/AutoWorkshopContracts/ViewModels/ReportShopsViewModel.cs b/AutoWorkshopContracts/ViewModels/ReportShopsViewModel.cs new file mode 100644 index 0000000..3014d2c --- /dev/null +++ b/AutoWorkshopContracts/ViewModels/ReportShopsViewModel.cs @@ -0,0 +1,11 @@ +namespace AutoWorkshopContracts.ViewModels +{ + public class ReportShopsViewModel + { + 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/AutoWorkshopDatabaseImplement/Implements/OrderStorage.cs b/AutoWorkshopDatabaseImplement/Implements/OrderStorage.cs index b42ccd7..06674b5 100644 --- a/AutoWorkshopDatabaseImplement/Implements/OrderStorage.cs +++ b/AutoWorkshopDatabaseImplement/Implements/OrderStorage.cs @@ -4,6 +4,7 @@ using AutoWorkshopContracts.StoragesContracts; using AutoWorkshopContracts.ViewModels; using AutoWorkshopDatabaseImplement.Models; using Microsoft.EntityFrameworkCore; +using System; namespace AutoWorkshopDatabaseImplement.Implements { @@ -21,11 +22,20 @@ namespace AutoWorkshopDatabaseImplement.Implements public List GetFilteredList(OrderSearchModel Model) { - if (!Model.Id.HasValue) + if (!Model.Id.HasValue && (!Model.DateFrom.HasValue || !Model.DateTo.HasValue)) return new(); using var Context = new AutoWorkshopDatabase(); - + + if (Model.DateFrom.HasValue) + { + return Context.Orders + .Include(x => x.Repair) + .Where(x => x.DateCreate >= Model.DateFrom && x.DateCreate <= Model.DateTo) + .Select(x => x.GetViewModel) + .ToList(); + } + return Context.Orders .Include(x => x.Repair) .Where(x => x.Id == Model.Id) diff --git a/AutoWorkshopFileImplement/Implements/OrderStorage.cs b/AutoWorkshopFileImplement/Implements/OrderStorage.cs index 54f0d0b..ec98ded 100644 --- a/AutoWorkshopFileImplement/Implements/OrderStorage.cs +++ b/AutoWorkshopFileImplement/Implements/OrderStorage.cs @@ -3,7 +3,6 @@ using AutoWorkshopContracts.SearchModels; using AutoWorkshopContracts.StoragesContracts; using AutoWorkshopContracts.ViewModels; using AutoWorkshopFileImplement.Models; -using System.Reflection; namespace AutoWorkshopFileImplement.Implements { @@ -23,10 +22,13 @@ namespace AutoWorkshopFileImplement.Implements public List GetFilteredList(OrderSearchModel Model) { - if (!Model.Id.HasValue) + if (!Model.Id.HasValue && (!Model.DateFrom.HasValue || !Model.DateTo.HasValue)) return new(); - return _source.Orders.Where(x => x.Id == Model.Id).Select(x => AddRepairName(x.GetViewModel)).ToList(); + return _source.Orders + .Where(x => x.DateCreate >= Model.DateFrom && x.DateCreate <= Model.DateTo) + .Select(x => AddRepairName(x.GetViewModel)) + .ToList(); } public OrderViewModel? Delete(OrderBindingModel Model) diff --git a/AutoWorkshopImplement/Implements/OrderStorage.cs b/AutoWorkshopImplement/Implements/OrderStorage.cs index 53ee90e..264e029 100644 --- a/AutoWorkshopImplement/Implements/OrderStorage.cs +++ b/AutoWorkshopImplement/Implements/OrderStorage.cs @@ -3,6 +3,7 @@ using AutoWorkshopContracts.SearchModels; using AutoWorkshopContracts.StoragesContracts; using AutoWorkshopContracts.ViewModels; using AutoWorkshopListImplement.Models; +using System.Reflection; namespace AutoWorkshopListImplement.Implements { @@ -31,12 +32,12 @@ namespace AutoWorkshopListImplement.Implements { var Result = new List(); - if (!Model.Id.HasValue) + if (!Model.Id.HasValue && (!Model.DateFrom.HasValue || !Model.DateTo.HasValue)) return Result; foreach (var Order in _source.Orders) { - if (Order.Id == Model.Id) + if (Order.DateCreate >= Model.DateFrom && Order.DateCreate <= Model.DateTo) { Result.Add(JoinRepairName(Order.GetViewModel)); break; diff --git a/AutoWorkshopView/AutoWorkshopView.csproj b/AutoWorkshopView/AutoWorkshopView.csproj index 49bf415..1b94f45 100644 --- a/AutoWorkshopView/AutoWorkshopView.csproj +++ b/AutoWorkshopView/AutoWorkshopView.csproj @@ -18,6 +18,17 @@ + + + + + + + Always + + + Always + \ No newline at end of file diff --git a/AutoWorkshopView/Forms/FormRepairs.resx b/AutoWorkshopView/Forms/FormRepairs.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/AutoWorkshopView/Forms/FormRepairs.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/AutoWorkshopView/Forms/FormReportGroupedOrders.Designer.cs b/AutoWorkshopView/Forms/FormReportGroupedOrders.Designer.cs new file mode 100644 index 0000000..6cfd4fa --- /dev/null +++ b/AutoWorkshopView/Forms/FormReportGroupedOrders.Designer.cs @@ -0,0 +1,89 @@ +namespace AutoWorkshopView.Forms +{ + 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(); + ToPdfButton = new Button(); + CreateButton = new Button(); + Panel.SuspendLayout(); + SuspendLayout(); + // + // Panel + // + Panel.Controls.Add(ToPdfButton); + Panel.Controls.Add(CreateButton); + Panel.Dock = DockStyle.Top; + Panel.Location = new Point(0, 0); + Panel.Margin = new Padding(3, 2, 3, 2); + Panel.Name = "Panel"; + Panel.Size = new Size(849, 39); + Panel.TabIndex = 1; + // + // ToPdfButton + // + ToPdfButton.Location = new Point(425, 9); + ToPdfButton.Margin = new Padding(3, 2, 3, 2); + ToPdfButton.Name = "ToPdfButton"; + ToPdfButton.Size = new Size(360, 22); + ToPdfButton.TabIndex = 5; + ToPdfButton.Text = "В PDF"; + ToPdfButton.UseVisualStyleBackColor = true; + ToPdfButton.Click += ButtonToPdf_Click; + // + // CreateButton + // + CreateButton.Location = new Point(43, 9); + CreateButton.Margin = new Padding(3, 2, 3, 2); + CreateButton.Name = "CreateButton"; + CreateButton.Size = new Size(330, 22); + CreateButton.TabIndex = 4; + CreateButton.Text = "Сформировать"; + CreateButton.UseVisualStyleBackColor = true; + CreateButton.Click += ButtonMake_Click; + // + // FormReportGroupedOrders + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(849, 338); + Controls.Add(Panel); + Margin = new Padding(3, 2, 3, 2); + Name = "FormReportGroupedOrders"; + Text = "Объединенные по датам заказы"; + Panel.ResumeLayout(false); + ResumeLayout(false); + } + + #endregion + + private Panel Panel; + private Button ToPdfButton; + private Button CreateButton; + } +} \ No newline at end of file diff --git a/AutoWorkshopView/Forms/FormReportGroupedOrders.cs b/AutoWorkshopView/Forms/FormReportGroupedOrders.cs new file mode 100644 index 0000000..20d155d --- /dev/null +++ b/AutoWorkshopView/Forms/FormReportGroupedOrders.cs @@ -0,0 +1,75 @@ +using AutoWorkshopContracts.BindingModels; +using AutoWorkshopContracts.BusinessLogicContracts; +using Microsoft.Extensions.Logging; +using Microsoft.Reporting.WinForms; + +namespace AutoWorkshopView.Forms +{ + 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 ButtonMake_Click(object sender, EventArgs e) + { + try + { + var DataSource = _logic.GetGroupedOrders(); + var Source = new ReportDataSource("DataSetGroupedOrders", DataSource); + _reportViewer.LocalReport.DataSources.Clear(); + _reportViewer.LocalReport.DataSources.Add(Source); + + _reportViewer.RefreshReport(); + _logger.LogInformation("Загрузка списка заказов, объединенных по датам"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка заказов, объединенных по датам"); + 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 + { + System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance); + _logic.SaveGroupedOrdersToPdfFile(new ReportBindingModel + { + FileName = Dialog.FileName, + }); + + _logger.LogInformation("Сохранение списка заказов, объединенных по датам"); + MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения списка заказов, объединенных по датам"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } +} diff --git a/AutoWorkshopView/Forms/FormReportGroupedOrders.resx b/AutoWorkshopView/Forms/FormReportGroupedOrders.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/AutoWorkshopView/Forms/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/AutoWorkshopView/Forms/FormReportOrders.Designer.cs b/AutoWorkshopView/Forms/FormReportOrders.Designer.cs new file mode 100644 index 0000000..27a6825 --- /dev/null +++ b/AutoWorkshopView/Forms/FormReportOrders.Designer.cs @@ -0,0 +1,136 @@ +namespace AutoWorkshopView.Forms +{ + partial class FormReportOrders + { + /// + /// 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(); + ToPdfButton = new Button(); + CreateButton = new Button(); + ToDateTimePicker = new DateTimePicker(); + ToLabel = new Label(); + FromDateTimePicker = new DateTimePicker(); + FromLabel = new Label(); + Panel.SuspendLayout(); + SuspendLayout(); + // + // panel + // + Panel.Controls.Add(ToPdfButton); + Panel.Controls.Add(CreateButton); + Panel.Controls.Add(ToDateTimePicker); + Panel.Controls.Add(ToLabel); + Panel.Controls.Add(FromDateTimePicker); + Panel.Controls.Add(FromLabel); + Panel.Dock = DockStyle.Top; + Panel.Location = new Point(0, 0); + Panel.Margin = new Padding(3, 2, 3, 2); + Panel.Name = "Panel"; + Panel.Size = new Size(838, 39); + Panel.TabIndex = 0; + // + // ToPdfButton + // + ToPdfButton.Location = new Point(683, 7); + ToPdfButton.Margin = new Padding(3, 2, 3, 2); + ToPdfButton.Name = "ToPdfButton"; + ToPdfButton.Size = new Size(144, 22); + ToPdfButton.TabIndex = 5; + ToPdfButton.Text = "В PDF"; + ToPdfButton.UseVisualStyleBackColor = true; + ToPdfButton.Click += ButtonToPdf_Click; + // + // CreateButton + // + CreateButton.Location = new Point(474, 8); + CreateButton.Margin = new Padding(3, 2, 3, 2); + CreateButton.Name = "CreateButton"; + CreateButton.Size = new Size(144, 22); + CreateButton.TabIndex = 4; + CreateButton.Text = "Сформировать"; + CreateButton.UseVisualStyleBackColor = true; + CreateButton.Click += ButtonMake_Click; + // + // ToDateTimePicker + // + ToDateTimePicker.Location = new Point(262, 7); + ToDateTimePicker.Margin = new Padding(3, 2, 3, 2); + ToDateTimePicker.Name = "ToDateTimePicker"; + ToDateTimePicker.Size = new Size(175, 23); + ToDateTimePicker.TabIndex = 3; + // + // ToLabel + // + ToLabel.AutoSize = true; + ToLabel.Location = new Point(222, 10); + ToLabel.Name = "ToLabel"; + ToLabel.Size = new Size(21, 15); + ToLabel.TabIndex = 2; + ToLabel.Text = "по"; + // + // FromDateTimePicker + // + FromDateTimePicker.Location = new Point(32, 7); + FromDateTimePicker.Margin = new Padding(3, 2, 3, 2); + FromDateTimePicker.Name = "FromDateTimePicker"; + FromDateTimePicker.Size = new Size(175, 23); + FromDateTimePicker.TabIndex = 1; + // + // FromLabel + // + FromLabel.AutoSize = true; + FromLabel.Location = new Point(10, 10); + FromLabel.Name = "FromLabel"; + FromLabel.Size = new Size(15, 15); + FromLabel.TabIndex = 0; + FromLabel.Text = "C"; + // + // FormReportOrders + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(838, 338); + Controls.Add(Panel); + Margin = new Padding(3, 2, 3, 2); + Name = "FormReportOrders"; + Text = "Заказы"; + Panel.ResumeLayout(false); + Panel.PerformLayout(); + ResumeLayout(false); + } + + #endregion + + private Panel Panel; + private Button ToPdfButton; + private Button CreateButton; + private DateTimePicker ToDateTimePicker; + private Label ToLabel; + private DateTimePicker FromDateTimePicker; + private Label FromLabel; + } +} \ No newline at end of file diff --git a/AutoWorkshopView/Forms/FormReportOrders.cs b/AutoWorkshopView/Forms/FormReportOrders.cs new file mode 100644 index 0000000..6aa2183 --- /dev/null +++ b/AutoWorkshopView/Forms/FormReportOrders.cs @@ -0,0 +1,100 @@ +using AutoWorkshopContracts.BindingModels; +using AutoWorkshopContracts.BusinessLogicContracts; +using Microsoft.Extensions.Logging; +using Microsoft.Reporting.WinForms; + +namespace AutoWorkshopView.Forms +{ + public partial class FormReportOrders : Form + { + private readonly ReportViewer _reportViewer; + private readonly ILogger _logger; + private readonly IReportLogic _logic; + + public FormReportOrders(ILogger Logger, IReportLogic Logic) + { + InitializeComponent(); + _logger = Logger; + _logic = Logic; + + _reportViewer = new ReportViewer + { + Dock = DockStyle.Fill + }; + _reportViewer.LocalReport.LoadReportDefinition(new FileStream("ReportOrder.rdlc", FileMode.Open)); + + Controls.Clear(); + Controls.Add(_reportViewer); + Controls.Add(Panel); + } + + private void ButtonMake_Click(object sender, EventArgs e) + { + if (FromDateTimePicker.Value.Date >= ToDateTimePicker.Value.Date) + { + MessageBox.Show("Дата начала должна быть меньше даты окончания", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + try + { + var DataSource = _logic.GetOrders(new ReportBindingModel + { + DateFrom = FromDateTimePicker.Value, + DateTo = ToDateTimePicker.Value + }); + + var Source = new ReportDataSource("DataSetOrders", DataSource); + + _reportViewer.LocalReport.DataSources.Clear(); + _reportViewer.LocalReport.DataSources.Add(Source); + + var Parameters = new[] { + new ReportParameter("ReportParameterPeriod", $"c {FromDateTimePicker.Value.ToShortDateString()} по {ToDateTimePicker.Value.ToShortDateString()}") + }; + _reportViewer.LocalReport.SetParameters(Parameters); + + _reportViewer.RefreshReport(); + _logger.LogInformation("Загрузка списка заказов на период {From}-{To}", FromDateTimePicker.Value.ToShortDateString(), ToDateTimePicker.Value.ToShortDateString()); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка заказов на период"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonToPdf_Click(object sender, EventArgs e) + { + if (FromDateTimePicker.Value.Date >= ToDateTimePicker.Value.Date) + { + MessageBox.Show("Дата начала должна быть меньше даты окончания", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + using var Dialog = new SaveFileDialog { Filter = "pdf|*.pdf" }; + + if (Dialog.ShowDialog() == DialogResult.OK) + { + try + { + System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance); + _logic.SaveOrdersToPdfFile(new ReportBindingModel + { + FileName = Dialog.FileName, + DateFrom = FromDateTimePicker.Value, + DateTo = ToDateTimePicker.Value + }); + + _logger.LogInformation("Сохранение списка заказов на период {From}-{To}", FromDateTimePicker.Value.ToShortDateString(), ToDateTimePicker.Value.ToShortDateString()); + MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения списка заказов на период"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } +} diff --git a/AutoWorkshopView/Forms/FormReportOrders.resx b/AutoWorkshopView/Forms/FormReportOrders.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/AutoWorkshopView/Forms/FormReportOrders.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/AutoWorkshopView/Forms/FormReportRepairComponents.Designer.cs b/AutoWorkshopView/Forms/FormReportRepairComponents.Designer.cs new file mode 100644 index 0000000..986e18b --- /dev/null +++ b/AutoWorkshopView/Forms/FormReportRepairComponents.Designer.cs @@ -0,0 +1,115 @@ +namespace AutoWorkshopView.Forms +{ + partial class FormReportRepairComponents + { + /// + /// 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(); + ColumnRepair = new DataGridViewTextBoxColumn(); + ColumnComponent = new DataGridViewTextBoxColumn(); + ColumnCount = new DataGridViewTextBoxColumn(); + SaveToExcelButton = new Button(); + ((System.ComponentModel.ISupportInitialize)DataGridView).BeginInit(); + SuspendLayout(); + // + // DataGridView + // + DataGridView.AllowUserToAddRows = false; + DataGridView.AllowUserToDeleteRows = false; + DataGridView.AllowUserToOrderColumns = true; + DataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + DataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + DataGridView.Columns.AddRange(new DataGridViewColumn[] { ColumnRepair, ColumnComponent, ColumnCount }); + DataGridView.Dock = DockStyle.Bottom; + DataGridView.Location = new Point(0, 61); + DataGridView.Margin = new Padding(3, 2, 3, 2); + DataGridView.Name = "DataGridView"; + DataGridView.ReadOnly = true; + DataGridView.RowHeadersWidth = 51; + DataGridView.RowTemplate.Height = 29; + DataGridView.Size = new Size(494, 277); + DataGridView.TabIndex = 0; + // + // ColumnRepair + // + ColumnRepair.FillWeight = 130F; + ColumnRepair.HeaderText = "Ремонт"; + ColumnRepair.MinimumWidth = 6; + ColumnRepair.Name = "ColumnRepair"; + ColumnRepair.ReadOnly = true; + // + // ColumnComponent + // + ColumnComponent.FillWeight = 140F; + ColumnComponent.HeaderText = "Компонент"; + ColumnComponent.MinimumWidth = 6; + ColumnComponent.Name = "ColumnComponent"; + ColumnComponent.ReadOnly = true; + // + // ColumnCount + // + ColumnCount.FillWeight = 90F; + ColumnCount.HeaderText = "Количество"; + ColumnCount.MinimumWidth = 6; + ColumnCount.Name = "ColumnCount"; + ColumnCount.ReadOnly = true; + // + // SaveToExcelButton + // + SaveToExcelButton.Location = new Point(12, 11); + SaveToExcelButton.Margin = new Padding(3, 2, 3, 2); + SaveToExcelButton.Name = "SaveToExcelButton"; + SaveToExcelButton.Size = new Size(153, 36); + SaveToExcelButton.TabIndex = 1; + SaveToExcelButton.Text = "Сохранить в Excel"; + SaveToExcelButton.UseVisualStyleBackColor = true; + SaveToExcelButton.Click += ButtonSaveToExcel_Click; + // + // FormReportRepairComponents + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(494, 338); + Controls.Add(SaveToExcelButton); + Controls.Add(DataGridView); + Margin = new Padding(3, 2, 3, 2); + Name = "FormReportRepairComponents"; + Text = "Ремонт с компонентами"; + Load += FormReportRepairComponents_Load; + ((System.ComponentModel.ISupportInitialize)DataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView DataGridView; + private Button SaveToExcelButton; + private DataGridViewTextBoxColumn ColumnRepair; + private DataGridViewTextBoxColumn ColumnComponent; + private DataGridViewTextBoxColumn ColumnCount; + } +} \ No newline at end of file diff --git a/AutoWorkshopView/Forms/FormReportRepairComponents.cs b/AutoWorkshopView/Forms/FormReportRepairComponents.cs new file mode 100644 index 0000000..b87cf1a --- /dev/null +++ b/AutoWorkshopView/Forms/FormReportRepairComponents.cs @@ -0,0 +1,75 @@ +using AutoWorkshopContracts.BindingModels; +using AutoWorkshopContracts.BusinessLogicContracts; +using Microsoft.Extensions.Logging; + +namespace AutoWorkshopView.Forms +{ + public partial class FormReportRepairComponents : Form + { + private readonly ILogger _logger; + private readonly IReportLogic _logic; + + public FormReportRepairComponents(ILogger Logger, IReportLogic Logic) + { + InitializeComponent(); + + _logger = Logger; + _logic = Logic; + } + + private void FormReportRepairComponents_Load(object sender, EventArgs e) + { + try + { + var Dict = _logic.GetRepairComponents(); + + if (Dict != null) + { + DataGridView.Rows.Clear(); + + foreach (var Elem in Dict) + { + DataGridView.Rows.Add(new object[] { Elem.RepairName, "", "" }); + + foreach (var ListElem in Elem.Components) + DataGridView.Rows.Add(new object[] { "", ListElem.Item1, ListElem.Item2 }); + + DataGridView.Rows.Add(new object[] { "Итого", "", Elem.TotalCount }); + DataGridView.Rows.Add(Array.Empty()); + } + } + + _logger.LogInformation("Загрузка списка ремонтов по компонентам"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка ремонтов по компонентам"); + 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.SaveRepairComponentToExcelFile(new ReportBindingModel + { + FileName = Dialog.FileName + }); + + _logger.LogInformation("Сохранение списка ремонтов по компонентам"); + MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения списка ремонтов по компонентам"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } +} diff --git a/AutoWorkshopView/Forms/FormReportRepairComponents.resx b/AutoWorkshopView/Forms/FormReportRepairComponents.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/AutoWorkshopView/Forms/FormReportRepairComponents.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/AutoWorkshopView/Forms/FormReportShop.Designer.cs b/AutoWorkshopView/Forms/FormReportShop.Designer.cs new file mode 100644 index 0000000..fa4a2c3 --- /dev/null +++ b/AutoWorkshopView/Forms/FormReportShop.Designer.cs @@ -0,0 +1,115 @@ +namespace AutoWorkshopView.Forms +{ + partial class FormReportShop + { + /// + /// 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() + { + SaveToExcelButton = new Button(); + DataGridView = new DataGridView(); + ColumnShop = new DataGridViewTextBoxColumn(); + ColumnRepair = new DataGridViewTextBoxColumn(); + ColumnCount = new DataGridViewTextBoxColumn(); + ((System.ComponentModel.ISupportInitialize)DataGridView).BeginInit(); + SuspendLayout(); + // + // SaveToExcelButton + // + SaveToExcelButton.Location = new Point(12, 10); + SaveToExcelButton.Margin = new Padding(3, 2, 3, 2); + SaveToExcelButton.Name = "SaveToExcelButton"; + SaveToExcelButton.Size = new Size(195, 27); + SaveToExcelButton.TabIndex = 3; + SaveToExcelButton.Text = "Сохранить в Excel"; + SaveToExcelButton.UseVisualStyleBackColor = true; + SaveToExcelButton.Click += ButtonSaveToExcel_Click; + // + // DataGridView + // + DataGridView.AllowUserToAddRows = false; + DataGridView.AllowUserToDeleteRows = false; + DataGridView.AllowUserToOrderColumns = true; + DataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + DataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + DataGridView.Columns.AddRange(new DataGridViewColumn[] { ColumnShop, ColumnRepair, ColumnCount }); + DataGridView.Dock = DockStyle.Bottom; + DataGridView.Location = new Point(0, 50); + DataGridView.Margin = new Padding(3, 2, 3, 2); + DataGridView.Name = "DataGridView"; + DataGridView.ReadOnly = true; + DataGridView.RowHeadersWidth = 51; + DataGridView.RowTemplate.Height = 29; + DataGridView.Size = new Size(523, 288); + DataGridView.TabIndex = 2; + // + // ColumnShop + // + ColumnShop.FillWeight = 130F; + ColumnShop.HeaderText = "Магазин"; + ColumnShop.MinimumWidth = 6; + ColumnShop.Name = "ColumnShop"; + ColumnShop.ReadOnly = true; + // + // ColumnRepair + // + ColumnRepair.FillWeight = 140F; + ColumnRepair.HeaderText = "Ремонт"; + ColumnRepair.MinimumWidth = 6; + ColumnRepair.Name = "ColumnRepair"; + ColumnRepair.ReadOnly = true; + // + // ColumnCount + // + ColumnCount.FillWeight = 90F; + ColumnCount.HeaderText = "Количество"; + ColumnCount.MinimumWidth = 6; + ColumnCount.Name = "ColumnCount"; + ColumnCount.ReadOnly = true; + // + // FormReportShop + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(523, 338); + Controls.Add(SaveToExcelButton); + Controls.Add(DataGridView); + Margin = new Padding(3, 2, 3, 2); + Name = "FormReportShop"; + Text = "Загруженность магазинов"; + Load += FormReportShop_Load; + ((System.ComponentModel.ISupportInitialize)DataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private Button SaveToExcelButton; + private DataGridView DataGridView; + private DataGridViewTextBoxColumn ColumnShop; + private DataGridViewTextBoxColumn ColumnRepair; + private DataGridViewTextBoxColumn ColumnCount; + } +} \ No newline at end of file diff --git a/AutoWorkshopView/Forms/FormReportShop.cs b/AutoWorkshopView/Forms/FormReportShop.cs new file mode 100644 index 0000000..95530d4 --- /dev/null +++ b/AutoWorkshopView/Forms/FormReportShop.cs @@ -0,0 +1,75 @@ +using AutoWorkshopContracts.BindingModels; +using AutoWorkshopContracts.BusinessLogicContracts; +using Microsoft.Extensions.Logging; + +namespace AutoWorkshopView.Forms +{ + public partial class FormReportShop : Form + { + private readonly ILogger _logger; + private readonly IReportLogic _logic; + + public FormReportShop(ILogger Logger, IReportLogic Logic) + { + InitializeComponent(); + + _logger = Logger; + _logic = Logic; + } + + private void FormReportShop_Load(object sender, EventArgs e) + { + try + { + var Shops = _logic.GetShops(); + if (Shops != null) + { + DataGridView.Rows.Clear(); + + foreach (var Shop in Shops) + { + DataGridView.Rows.Add(new object[] { Shop.ShopName, "", "" }); + + foreach (var Repair in Shop.Repairs) + { + DataGridView.Rows.Add(new object[] { "", Repair.Item1, Repair.Item2 }); + } + + DataGridView.Rows.Add(new object[] { "Итого", "", Shop.TotalCount }); + DataGridView.Rows.Add(Array.Empty()); + } + } + + _logger.LogInformation("Загрузка списка ремонтов по магазинам"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка ремонтов по магазинам"); + 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.SaveShopsToExcelFile(new ReportBindingModel + { + FileName = Dialog.FileName + }); + + _logger.LogInformation("Сохранение списка ремонтов по магазинам"); + MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения списка ремонтов по магазинам"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } +} diff --git a/AutoWorkshopView/Forms/FormReportShop.resx b/AutoWorkshopView/Forms/FormReportShop.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/AutoWorkshopView/Forms/FormReportShop.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/AutoWorkshopView/MainForm.Designer.cs b/AutoWorkshopView/MainForm.Designer.cs index cdb15b3..09ab7c7 100644 --- a/AutoWorkshopView/MainForm.Designer.cs +++ b/AutoWorkshopView/MainForm.Designer.cs @@ -36,6 +36,13 @@ OperationToolStripMenuItem = new ToolStripMenuItem(); TransactionToolStripMenuItem = new ToolStripMenuItem(); SaleToolStripMenuItem = new ToolStripMenuItem(); + ReportsToolStripMenuItem = new ToolStripMenuItem(); + ReportRepairsToolStripMenuItem = new ToolStripMenuItem(); + ReportRepCompToolStripMenuItem = new ToolStripMenuItem(); + OrdersToolStripMenuItem = new ToolStripMenuItem(); + ReportShopsToolStripMenuItem = new ToolStripMenuItem(); + RepostBusyShopsToolStripMenuItem = new ToolStripMenuItem(); + ReportGroupOrdersToolStripMenuItem = new ToolStripMenuItem(); DataGridView = new DataGridView(); CreateOrderButton = new Button(); TakeInWorkButton = new Button(); @@ -49,7 +56,7 @@ // MenuStrip // MenuStrip.ImageScalingSize = new Size(20, 20); - MenuStrip.Items.AddRange(new ToolStripItem[] { ToolStripMenu, OperationToolStripMenuItem }); + MenuStrip.Items.AddRange(new ToolStripItem[] { ToolStripMenu, OperationToolStripMenuItem, ReportsToolStripMenuItem }); MenuStrip.Location = new Point(0, 0); MenuStrip.Name = "MenuStrip"; MenuStrip.Padding = new Padding(5, 2, 0, 2); @@ -67,21 +74,21 @@ // ComponentsStripMenuItem // ComponentsStripMenuItem.Name = "ComponentsStripMenuItem"; - ComponentsStripMenuItem.Size = new Size(145, 22); + ComponentsStripMenuItem.Size = new Size(180, 22); ComponentsStripMenuItem.Text = "Компоненты"; ComponentsStripMenuItem.Click += ComponentsStripMenuItem_Click; // // RepairStripMenuItem // RepairStripMenuItem.Name = "RepairStripMenuItem"; - RepairStripMenuItem.Size = new Size(145, 22); + RepairStripMenuItem.Size = new Size(180, 22); RepairStripMenuItem.Text = "Ремонты"; RepairStripMenuItem.Click += RepairsStripMenuItem_Click; // // ShopsToolStripMenuItem // ShopsToolStripMenuItem.Name = "ShopsToolStripMenuItem"; - ShopsToolStripMenuItem.Size = new Size(145, 22); + ShopsToolStripMenuItem.Size = new Size(180, 22); ShopsToolStripMenuItem.Text = "Магазины"; ShopsToolStripMenuItem.Click += ShopsToolStripMenuItem_Click; // @@ -95,10 +102,66 @@ // TransactionToolStripMenuItem // TransactionToolStripMenuItem.Name = "TransactionToolStripMenuItem"; - TransactionToolStripMenuItem.Size = new Size(125, 22); + TransactionToolStripMenuItem.Size = new Size(180, 22); TransactionToolStripMenuItem.Text = "Поставка"; TransactionToolStripMenuItem.Click += TransactionToolStripMenuItem_Click; // + // SaleToolStripMenuItem + // + SaleToolStripMenuItem.Name = "SaleToolStripMenuItem"; + SaleToolStripMenuItem.Size = new Size(180, 22); + SaleToolStripMenuItem.Text = "Продажа"; + SaleToolStripMenuItem.Click += SellToolStripMenuItem_Click; + // + // ReportsToolStripMenuItem + // + ReportsToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { ReportRepairsToolStripMenuItem, ReportRepCompToolStripMenuItem, OrdersToolStripMenuItem, ReportShopsToolStripMenuItem, RepostBusyShopsToolStripMenuItem, ReportGroupOrdersToolStripMenuItem }); + ReportsToolStripMenuItem.Name = "ReportsToolStripMenuItem"; + ReportsToolStripMenuItem.Size = new Size(60, 20); + ReportsToolStripMenuItem.Text = "Отчёты"; + // + // ReportRepairsToolStripMenuItem + // + ReportRepairsToolStripMenuItem.Name = "ReportRepairsToolStripMenuItem"; + ReportRepairsToolStripMenuItem.Size = new Size(219, 22); + ReportRepairsToolStripMenuItem.Text = "Ремонты"; + ReportRepairsToolStripMenuItem.Click += ComponentsToolStripMenuItem_Click; + // + // ReportRepCompToolStripMenuItem + // + ReportRepCompToolStripMenuItem.Name = "ReportRepCompToolStripMenuItem"; + ReportRepCompToolStripMenuItem.Size = new Size(219, 22); + ReportRepCompToolStripMenuItem.Text = "Ремонт с компонентами"; + ReportRepCompToolStripMenuItem.Click += ComponentRepairToolStripMenuItem_Click; + // + // OrdersToolStripMenuItem + // + OrdersToolStripMenuItem.Name = "OrdersToolStripMenuItem"; + OrdersToolStripMenuItem.Size = new Size(219, 22); + OrdersToolStripMenuItem.Text = "Заказы"; + OrdersToolStripMenuItem.Click += OrdersToolStripMenuItem_Click; + // + // ReportShopsToolStripMenuItem + // + ReportShopsToolStripMenuItem.Name = "ReportShopsToolStripMenuItem"; + ReportShopsToolStripMenuItem.Size = new Size(219, 22); + ReportShopsToolStripMenuItem.Text = "Список магазинов"; + ReportShopsToolStripMenuItem.Click += ReportShopsToolStripMenuItem_Click; + // + // RepostBusyShopsToolStripMenuItem + // + RepostBusyShopsToolStripMenuItem.Name = "RepostBusyShopsToolStripMenuItem"; + RepostBusyShopsToolStripMenuItem.Size = new Size(219, 22); + RepostBusyShopsToolStripMenuItem.Text = "Загруженность магазинов"; + RepostBusyShopsToolStripMenuItem.Click += ReportBusyShopsToolStripMenuItem_Click; + // + // ReportGroupOrdersToolStripMenuItem + // + ReportGroupOrdersToolStripMenuItem.Name = "ReportGroupOrdersToolStripMenuItem"; + ReportGroupOrdersToolStripMenuItem.Size = new Size(219, 22); + ReportGroupOrdersToolStripMenuItem.Text = "Объединенные заказы"; + ReportGroupOrdersToolStripMenuItem.Click += ReportGroupOrdersToolStripMenuItem_Click; + // // DataGridView // DataGridView.AllowUserToAddRows = false; @@ -166,13 +229,6 @@ RefreshButton.UseVisualStyleBackColor = true; RefreshButton.Click += RefreshButton_Click; // - // SaleToolStripMenuItem - // - SaleToolStripMenuItem.Name = "SaleToolStripMenuItem"; - SaleToolStripMenuItem.Size = new System.Drawing.Size(180, 22); - SaleToolStripMenuItem.Text = "Продажа"; - SaleToolStripMenuItem.Click += new System.EventHandler(SellToolStripMenuItem_Click); - // // MainForm // AutoScaleDimensions = new SizeF(7F, 15F); @@ -213,5 +269,12 @@ private ToolStripMenuItem OperationToolStripMenuItem; private ToolStripMenuItem TransactionToolStripMenuItem; private ToolStripMenuItem SaleToolStripMenuItem; + private ToolStripMenuItem ReportsToolStripMenuItem; + private ToolStripMenuItem ReportRepairsToolStripMenuItem; + private ToolStripMenuItem ReportRepCompToolStripMenuItem; + private ToolStripMenuItem OrdersToolStripMenuItem; + private ToolStripMenuItem ReportShopsToolStripMenuItem; + private ToolStripMenuItem RepostBusyShopsToolStripMenuItem; + private ToolStripMenuItem ReportGroupOrdersToolStripMenuItem; } } \ No newline at end of file diff --git a/AutoWorkshopView/MainForm.cs b/AutoWorkshopView/MainForm.cs index 2fc730c..e5a6d7f 100644 --- a/AutoWorkshopView/MainForm.cs +++ b/AutoWorkshopView/MainForm.cs @@ -10,13 +10,15 @@ namespace AutoWorkshopView { private readonly ILogger _logger; private readonly IOrderLogic _orderLogic; - - public MainForm(ILogger Logger, IOrderLogic OrderLogic) + private readonly IReportLogic _reportLogic; + + public MainForm(ILogger Logger, IOrderLogic OrderLogic, IReportLogic ReportLogic) { InitializeComponent(); _logger = Logger; _orderLogic = OrderLogic; + _reportLogic = ReportLogic; } private void MainForm_Load(object sender, EventArgs e) @@ -196,5 +198,67 @@ namespace AutoWorkshopView Form.ShowDialog(); } } + + private void ComponentsToolStripMenuItem_Click(object sender, EventArgs e) + { + using var Dialog = new SaveFileDialog { Filter = "docx|*.docx" }; + + if (Dialog.ShowDialog() == DialogResult.OK) + { + _reportLogic.SaveRepairsToWordFile(new ReportBindingModel { FileName = Dialog.FileName }); + MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } + + private void ComponentRepairToolStripMenuItem_Click(object sender, EventArgs e) + { + var Service = Program.ServiceProvider?.GetService(typeof(FormReportRepairComponents)); + + if (Service is FormReportRepairComponents Form) + { + Form.ShowDialog(); + } + } + + private void OrdersToolStripMenuItem_Click(object sender, EventArgs e) + { + var Service = Program.ServiceProvider?.GetService(typeof(FormReportOrders)); + + if (Service is FormReportOrders Form) + { + Form.ShowDialog(); + } + } + + private void ReportShopsToolStripMenuItem_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 ReportBusyShopsToolStripMenuItem_Click(object sender, EventArgs e) + { + var Service = Program.ServiceProvider?.GetService(typeof(FormReportShop)); + + if (Service is FormReportShop Form) + { + Form.ShowDialog(); + } + } + + private void ReportGroupOrdersToolStripMenuItem_Click(object sender, EventArgs e) + { + var Service = Program.ServiceProvider?.GetService(typeof(FormReportGroupedOrders)); + + if (Service is FormReportGroupedOrders Form) + { + Form.ShowDialog(); + } + } } } diff --git a/AutoWorkshopView/Program.cs b/AutoWorkshopView/Program.cs index ec849b3..03c681e 100644 --- a/AutoWorkshopView/Program.cs +++ b/AutoWorkshopView/Program.cs @@ -1,4 +1,6 @@ using AutoWorkshopBusinessLogic.BusinessLogics; +using AutoWorkshopBusinessLogic.OfficePackage.Implements; +using AutoWorkshopBusinessLogic.OfficePackage; using AutoWorkshopContracts.BusinessLogicContracts; using AutoWorkshopContracts.BusinessLogicsContracts; using AutoWorkshopContracts.StoragesContracts; @@ -44,8 +46,13 @@ namespace AutoWorkshopView Services.AddTransient(); Services.AddTransient(); Services.AddTransient(); + Services.AddTransient(); Services.AddTransient(); + Services.AddTransient(); + Services.AddTransient(); + Services.AddTransient(); + Services.AddTransient(); Services.AddTransient(); Services.AddTransient(); @@ -57,6 +64,10 @@ namespace AutoWorkshopView Services.AddTransient(); Services.AddTransient(); Services.AddTransient(); + Services.AddTransient(); + Services.AddTransient(); + Services.AddTransient(); + Services.AddTransient(); } } } diff --git a/AutoWorkshopView/ReportGroupedOrders.rdlc b/AutoWorkshopView/ReportGroupedOrders.rdlc new file mode 100644 index 0000000..5250730 --- /dev/null +++ b/AutoWorkshopView/ReportGroupedOrders.rdlc @@ -0,0 +1,441 @@ + + + 0 + + + + System.Data.DataSet + /* Local Connection */ + + 20791c83-cee8-4a38-bbd0-245fc17cefb3 + + + + + + AutoWorkshopContractsViewModels + /* Local Query */ + + + + Date + System.DateTime + + + OrdersCount + System.Int32 + + + OrdersSum + System.Decimal + + + + AutoWorkshopContracts.ViewModels + AutoWorksReportGroupedOrdersViewModelhop + AutoWorkshopContracts.ViewModels.AutoWorksReportGroupedOrdersViewModelhop, AutoWorkshopContracts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + + + + + + + + + true + true + + + + + Отчёт по заказам + + + + 0.6cm + 16.51cm + + + Middle + 2pt + 2pt + 2pt + 2pt + + + + true + true + + + + + =Parameters!ReportParameterPeriod.Value + + + + + + + ReportParameterPeriod + 0.6cm + 0.6cm + 16.51cm + 1 + + + 2pt + 2pt + 2pt + 2pt + + + + + + + 3.90406cm + + + 3.97461cm + + + 3.65711cm + + + + + 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!OrdersCount.Value + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + =Fields!OrdersSum.Value + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + + + + + + + + + + + + After + + + + + + + DataSetGroupedOrders + 1.88242cm + 2.68676cm + 1.2cm + 11.53578cm + 2 + + + + + + true + true + + + + + Итого: + + + + 3.29409cm + 8.06542cm + 0.6cm + 2.5cm + 3 + + + 2pt + 2pt + 2pt + 2pt + + + + true + true + + + + + =Sum(Fields!OrdersSum.Value, "DataSetGroupedOrders") + + + + + + + 3.29409cm + 10.70653cm + 0.6cm + 3.48072cm + 4 + + + 2pt + 2pt + 2pt + 2pt + + + + 2in + + + + 0.6cm + 16.51cm + + + Middle + 2pt + 2pt + 2pt + 2pt + + + + true + true + + + + + =Parameters!ReportParameterPeriod.Value + + + + ReportParameterPeriod + 0.6cm + 0.6cm + 16.51cm + 1 + + + Middle + 2pt + 2pt + 2pt + 2pt + + + + + + + 2.60583cm + + + 3.262cm + + + 4.8495cm + + + 2.5cm + + + 2.5cm + + + + + 0.6cm + + + + + true + true + + + + + Номер + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + Дата создания + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + Ремонт + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + Статус + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + Сумма + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + 0.6cm + + + + + true + true + + + + + =Fields!Id.Value + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + =Fields!DateCreate.Value + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + =Fields!RepairName.Value + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + =Fields!Status.Value + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + =Fields!Sum.Value + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + + + + + + + + + + + + + + After + + + + + + + DataSetOrders + 1.9177cm + 0.79267cm + 1.2cm + 15.71733cm + 2 + + + + + + true + true + + + + + Итого: + + + + 3.46287cm + 11.51cm + 0.6cm + 2.5cm + 3 + + + 2pt + 2pt + 2pt + 2pt + + + + true + true + + + + + =Sum(Fields!Sum.Value, "DataSetOrders") + + + 2pt + 2pt + 2pt + 2pt + + + + 2in +