From 7ec7bd5c6b3a4de5d495eb20c080840eb08bf3b3 Mon Sep 17 00:00:00 2001 From: Marselchi Date: Fri, 5 Apr 2024 10:20:47 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A4=D1=83=D0=BB=D0=BB=204?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/ReportLogic.cs | 109 ++++ .../OfficePackage/AbstractSaveToExcel.cs | 83 +++ .../OfficePackage/AbstractSaveToPdf.cs | 42 ++ .../OfficePackage/AbstractSaveToWord.cs | 42 ++ .../HelperEnums/ExcelStyleInfoType.cs | 11 + .../HelperEnums/PdfParagraphAlignmentType.cs | 11 + .../HelperEnums/WordJustificationType.cs | 9 + .../HelperModels/ExcelCellParameters.cs | 17 + .../OfficePackage/HelperModels/ExcelInfo.cs | 13 + .../HelperModels/ExcelMergeParameters.cs | 11 + .../OfficePackage/HelperModels/PdfInfo.cs | 17 + .../HelperModels/PdfParagraph.cs | 13 + .../HelperModels/PdfRowParameters.cs | 13 + .../OfficePackage/HelperModels/WordInfo.cs | 13 + .../HelperModels/WordParagraph.cs | 9 + .../HelperModels/WordTextProperties.cs | 13 + .../OfficePackage/Implements/SaveToExcel.cs | 292 +++++++++ .../OfficePackage/Implements/SaveToPdf.cs | 109 ++++ .../OfficePackage/Implements/SaveToWord.cs | 119 ++++ .../ShipyardBusinessLogic.csproj | 2 + .../BindingModels/ReportBindingModel.cs | 11 + .../BusinessLogicsContracts/IReportLogic.cs | 18 + .../SearchModels/OrderSearchModel.cs | 2 + .../ViewModels/ReportOrdersViewModel.cs | 14 + .../ViewModels/ReportShipDetailViewModel.cs | 11 + .../Implements/OrderStorage.cs | 12 +- .../Implements/OrderStorage.cs | 9 +- .../Implements/OrderStorage.cs | 13 +- Shipyard/ShipyardView/FormMain.Designer.cs | 41 +- Shipyard/ShipyardView/FormMain.cs | 31 +- Shipyard/ShipyardView/FormMain.resx | 11 + .../ShipyardView/FormReportOrders.Designer.cs | 131 ++++ Shipyard/ShipyardView/FormReportOrders.cs | 100 +++ Shipyard/ShipyardView/FormReportOrders.resx | 120 ++++ .../FormReportShipDetails.Designer.cs | 107 ++++ .../ShipyardView/FormReportShipDetails.cs | 70 +++ .../ShipyardView/FormReportShipDetails.resx | 120 ++++ Shipyard/ShipyardView/Program.cs | 8 + ...essLogicsContracts.IDetailLogic.datasource | 10 + ...nessLogicsContracts.IOrderLogic.datasource | 10 + ...inessLogicsContracts.IShipLogic.datasource | 10 + ...toragesContracts.IDetailStorage.datasource | 10 + ...StoragesContracts.IOrderStorage.datasource | 10 + ....StoragesContracts.IShipStorage.datasource | 10 + .../Properties/Resources.Designer.cs | 63 ++ .../ShipyardView/Properties/Resources.resx | 120 ++++ Shipyard/ShipyardView/ReportOrders.rdlc | 579 ++++++++++++++++++ Shipyard/ShipyardView/ShipyardView.csproj | 20 + 48 files changed, 2613 insertions(+), 6 deletions(-) create mode 100644 Shipyard/ShipyardBusinessLogic/BusinessLogics/ReportLogic.cs create mode 100644 Shipyard/ShipyardBusinessLogic/OfficePackage/AbstractSaveToExcel.cs create mode 100644 Shipyard/ShipyardBusinessLogic/OfficePackage/AbstractSaveToPdf.cs create mode 100644 Shipyard/ShipyardBusinessLogic/OfficePackage/AbstractSaveToWord.cs create mode 100644 Shipyard/ShipyardBusinessLogic/OfficePackage/HelperEnums/ExcelStyleInfoType.cs create mode 100644 Shipyard/ShipyardBusinessLogic/OfficePackage/HelperEnums/PdfParagraphAlignmentType.cs create mode 100644 Shipyard/ShipyardBusinessLogic/OfficePackage/HelperEnums/WordJustificationType.cs create mode 100644 Shipyard/ShipyardBusinessLogic/OfficePackage/HelperModels/ExcelCellParameters.cs create mode 100644 Shipyard/ShipyardBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs create mode 100644 Shipyard/ShipyardBusinessLogic/OfficePackage/HelperModels/ExcelMergeParameters.cs create mode 100644 Shipyard/ShipyardBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs create mode 100644 Shipyard/ShipyardBusinessLogic/OfficePackage/HelperModels/PdfParagraph.cs create mode 100644 Shipyard/ShipyardBusinessLogic/OfficePackage/HelperModels/PdfRowParameters.cs create mode 100644 Shipyard/ShipyardBusinessLogic/OfficePackage/HelperModels/WordInfo.cs create mode 100644 Shipyard/ShipyardBusinessLogic/OfficePackage/HelperModels/WordParagraph.cs create mode 100644 Shipyard/ShipyardBusinessLogic/OfficePackage/HelperModels/WordTextProperties.cs create mode 100644 Shipyard/ShipyardBusinessLogic/OfficePackage/Implements/SaveToExcel.cs create mode 100644 Shipyard/ShipyardBusinessLogic/OfficePackage/Implements/SaveToPdf.cs create mode 100644 Shipyard/ShipyardBusinessLogic/OfficePackage/Implements/SaveToWord.cs create mode 100644 Shipyard/ShipyardContracts/BindingModels/ReportBindingModel.cs create mode 100644 Shipyard/ShipyardContracts/BusinessLogicsContracts/IReportLogic.cs create mode 100644 Shipyard/ShipyardContracts/ViewModels/ReportOrdersViewModel.cs create mode 100644 Shipyard/ShipyardContracts/ViewModels/ReportShipDetailViewModel.cs create mode 100644 Shipyard/ShipyardView/FormReportOrders.Designer.cs create mode 100644 Shipyard/ShipyardView/FormReportOrders.cs create mode 100644 Shipyard/ShipyardView/FormReportOrders.resx create mode 100644 Shipyard/ShipyardView/FormReportShipDetails.Designer.cs create mode 100644 Shipyard/ShipyardView/FormReportShipDetails.cs create mode 100644 Shipyard/ShipyardView/FormReportShipDetails.resx create mode 100644 Shipyard/ShipyardView/Properties/DataSources/ShipyardContracts.BusinessLogicsContracts.IDetailLogic.datasource create mode 100644 Shipyard/ShipyardView/Properties/DataSources/ShipyardContracts.BusinessLogicsContracts.IOrderLogic.datasource create mode 100644 Shipyard/ShipyardView/Properties/DataSources/ShipyardContracts.BusinessLogicsContracts.IShipLogic.datasource create mode 100644 Shipyard/ShipyardView/Properties/DataSources/ShipyardContracts.StoragesContracts.IDetailStorage.datasource create mode 100644 Shipyard/ShipyardView/Properties/DataSources/ShipyardContracts.StoragesContracts.IOrderStorage.datasource create mode 100644 Shipyard/ShipyardView/Properties/DataSources/ShipyardContracts.StoragesContracts.IShipStorage.datasource create mode 100644 Shipyard/ShipyardView/Properties/Resources.Designer.cs create mode 100644 Shipyard/ShipyardView/Properties/Resources.resx create mode 100644 Shipyard/ShipyardView/ReportOrders.rdlc diff --git a/Shipyard/ShipyardBusinessLogic/BusinessLogics/ReportLogic.cs b/Shipyard/ShipyardBusinessLogic/BusinessLogics/ReportLogic.cs new file mode 100644 index 0000000..b8a9476 --- /dev/null +++ b/Shipyard/ShipyardBusinessLogic/BusinessLogics/ReportLogic.cs @@ -0,0 +1,109 @@ +using ShipyardBusinessLogic.OfficePackage.HelperModels; +using ShipyardBusinessLogic.OfficePackage; +using ShipyardContracts.BindingModels; +using ShipyardContracts.BusinessLogicsContracts; +using ShipyardContracts.SearchModels; +using ShipyardContracts.StoragesContracts; +using ShipyardContracts.ViewModels; + +namespace ShipyardBusinessLogic.BusinessLogics +{ + public class ReportLogic : IReportLogic + { + private readonly IDetailStorage _detailStorage; + + private readonly IShipStorage _shipStorage; + + private readonly IOrderStorage _orderStorage; + + private readonly AbstractSaveToExcel _saveToExcel; + + private readonly AbstractSaveToWord _saveToWord; + + private readonly AbstractSaveToPdf _saveToPdf; + + public ReportLogic(IShipStorage shipStorage, IDetailStorage detailStorage, IOrderStorage orderStorage, + AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf) + { + _shipStorage = shipStorage; + _detailStorage = detailStorage; + _orderStorage = orderStorage; + + _saveToExcel = saveToExcel; + _saveToWord = saveToWord; + _saveToPdf = saveToPdf; + } + public List GetShipDetail() + { + + var ships = _shipStorage.GetFullList(); + + var list = new List(); + + foreach (var ship in ships) + { + var record = new ReportShipDetailViewModel + { + ShipName = ship.ShipName, + Details = new List<(string, int)>(), + TotalCount = 0 + }; + foreach (var shipDetail in ship.ShipDetails) + { + + record.Details.Add(new(shipDetail.Value.Item1.DetailName, shipDetail.Value.Item2)); + record.TotalCount += shipDetail.Value.Item2; + } + + list.Add(record); + } + + return list; + } + 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, + ShipName = x.ShipName, + OrderStatus = x.Status.ToString(), + Sum = x.Sum + }) + .ToList(); + } + + public void SaveComponentsToWordFile(ReportBindingModel model) + { + _saveToWord.CreateDoc(new WordInfo + { + FileName = model.FileName, + Title = "Список кораблей", + Ships = _shipStorage.GetFullList() + }); + } + + public void SaveProductComponentToExcelFile(ReportBindingModel model) + { + _saveToExcel.CreateReport(new ExcelInfo + { + FileName = model.FileName, + Title = "Список деталей", + ShipDetails = GetShipDetail() + }); + } + + public void SaveOrdersToPdfFile(ReportBindingModel model) + { + _saveToPdf.CreateDoc(new PdfInfo + { + FileName = model.FileName, + Title = "Список заказов", + DateFrom = model.DateFrom!.Value, + DateTo = model.DateTo!.Value, + Orders = GetOrders(model) + }); + } + } +} \ No newline at end of file diff --git a/Shipyard/ShipyardBusinessLogic/OfficePackage/AbstractSaveToExcel.cs b/Shipyard/ShipyardBusinessLogic/OfficePackage/AbstractSaveToExcel.cs new file mode 100644 index 0000000..4023258 --- /dev/null +++ b/Shipyard/ShipyardBusinessLogic/OfficePackage/AbstractSaveToExcel.cs @@ -0,0 +1,83 @@ +using ShipyardBusinessLogic.OfficePackage.HelperEnums; +using ShipyardBusinessLogic.OfficePackage.HelperModels; + +namespace ShipyardBusinessLogic.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.ShipDetails) + { + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "A", + RowIndex = rowIndex, + Text = pc.ShipName, + StyleInfo = ExcelStyleInfoType.Text + }); + rowIndex++; + + foreach (var (Detail, Count) in pc.Details) + { + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "B", + RowIndex = rowIndex, + Text = Detail, + StyleInfo = ExcelStyleInfoType.TextWithBorder + }); + + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "C", + RowIndex = rowIndex, + Text = Count.ToString(), + StyleInfo = ExcelStyleInfoType.TextWithBorder + }); + + rowIndex++; + } + + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "A", + RowIndex = rowIndex, + Text = "Итого", + StyleInfo = ExcelStyleInfoType.Text + }); + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "C", + RowIndex = rowIndex, + Text = pc.TotalCount.ToString(), + StyleInfo = ExcelStyleInfoType.Text + }); + rowIndex++; + } + + SaveExcel(info); + } + protected abstract void CreateExcel(ExcelInfo info); + protected abstract void InsertCellInWorksheet(ExcelCellParameters excelParams); + protected abstract void MergeCells(ExcelMergeParameters excelParams); + protected abstract void SaveExcel(ExcelInfo info); + } +} \ No newline at end of file diff --git a/Shipyard/ShipyardBusinessLogic/OfficePackage/AbstractSaveToPdf.cs b/Shipyard/ShipyardBusinessLogic/OfficePackage/AbstractSaveToPdf.cs new file mode 100644 index 0000000..0e10cb3 --- /dev/null +++ b/Shipyard/ShipyardBusinessLogic/OfficePackage/AbstractSaveToPdf.cs @@ -0,0 +1,42 @@ +using ShipyardBusinessLogic.OfficePackage.HelperEnums; +using ShipyardBusinessLogic.OfficePackage.HelperModels; + +namespace ShipyardBusinessLogic.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", "3cm" }); + + CreateRow(new PdfRowParameters + { + Texts = new List { "ID", "Дата заказа", "Название корабля", "Статус", "Сумма" }, + Style = "NormalTitle", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + + foreach (var order in info.Orders) + { + CreateRow(new PdfRowParameters + { + Texts = new List { order.Id.ToString(), order.DateCreate.ToShortDateString(), order.ShipName, order.OrderStatus.ToString(), order.Sum.ToString() }, + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Left + }); + } + CreateParagraph(new PdfParagraph { Text = $"Итого: {info.Orders.Sum(x => x.Sum)}\t", Style = "Normal", ParagraphAlignment = PdfParagraphAlignmentType.Right }); + + SavePdf(info); + } + 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); + } +} \ No newline at end of file diff --git a/Shipyard/ShipyardBusinessLogic/OfficePackage/AbstractSaveToWord.cs b/Shipyard/ShipyardBusinessLogic/OfficePackage/AbstractSaveToWord.cs new file mode 100644 index 0000000..762a53a --- /dev/null +++ b/Shipyard/ShipyardBusinessLogic/OfficePackage/AbstractSaveToWord.cs @@ -0,0 +1,42 @@ +using ShipyardBusinessLogic.OfficePackage.HelperEnums; +using ShipyardBusinessLogic.OfficePackage.HelperModels; + +namespace ShipyardBusinessLogic.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 ship in info.Ships) + { + CreateParagraph(new WordParagraph + { + Texts = new List<(string, WordTextProperties)> { (ship.ShipName + " ", new WordTextProperties {Bold=true, Size = "24", }), + (ship.Price.ToString(), new WordTextProperties {Size="24"})}, + TextProperties = new WordTextProperties + { + Size = "24", + JustificationType = WordJustificationType.Both + } + }); + } + + SaveWord(info); + } + protected abstract void CreateWord(WordInfo info); + protected abstract void CreateParagraph(WordParagraph paragraph); + protected abstract void SaveWord(WordInfo info); + } +} \ No newline at end of file diff --git a/Shipyard/ShipyardBusinessLogic/OfficePackage/HelperEnums/ExcelStyleInfoType.cs b/Shipyard/ShipyardBusinessLogic/OfficePackage/HelperEnums/ExcelStyleInfoType.cs new file mode 100644 index 0000000..a755855 --- /dev/null +++ b/Shipyard/ShipyardBusinessLogic/OfficePackage/HelperEnums/ExcelStyleInfoType.cs @@ -0,0 +1,11 @@ +namespace ShipyardBusinessLogic.OfficePackage.HelperEnums +{ + public enum ExcelStyleInfoType + { + Title, + + Text, + + TextWithBorder + } +} \ No newline at end of file diff --git a/Shipyard/ShipyardBusinessLogic/OfficePackage/HelperEnums/PdfParagraphAlignmentType.cs b/Shipyard/ShipyardBusinessLogic/OfficePackage/HelperEnums/PdfParagraphAlignmentType.cs new file mode 100644 index 0000000..23ce9ec --- /dev/null +++ b/Shipyard/ShipyardBusinessLogic/OfficePackage/HelperEnums/PdfParagraphAlignmentType.cs @@ -0,0 +1,11 @@ +namespace ShipyardBusinessLogic.OfficePackage.HelperEnums +{ + public enum PdfParagraphAlignmentType + { + Center, + + Left, + + Right + } +} \ No newline at end of file diff --git a/Shipyard/ShipyardBusinessLogic/OfficePackage/HelperEnums/WordJustificationType.cs b/Shipyard/ShipyardBusinessLogic/OfficePackage/HelperEnums/WordJustificationType.cs new file mode 100644 index 0000000..cf0f534 --- /dev/null +++ b/Shipyard/ShipyardBusinessLogic/OfficePackage/HelperEnums/WordJustificationType.cs @@ -0,0 +1,9 @@ +namespace ShipyardBusinessLogic.OfficePackage.HelperEnums +{ + public enum WordJustificationType + { + Center, + + Both + } +} \ No newline at end of file diff --git a/Shipyard/ShipyardBusinessLogic/OfficePackage/HelperModels/ExcelCellParameters.cs b/Shipyard/ShipyardBusinessLogic/OfficePackage/HelperModels/ExcelCellParameters.cs new file mode 100644 index 0000000..a399277 --- /dev/null +++ b/Shipyard/ShipyardBusinessLogic/OfficePackage/HelperModels/ExcelCellParameters.cs @@ -0,0 +1,17 @@ +using ShipyardBusinessLogic.OfficePackage.HelperEnums; + +namespace ShipyardBusinessLogic.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; } + } +} \ No newline at end of file diff --git a/Shipyard/ShipyardBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs b/Shipyard/ShipyardBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs new file mode 100644 index 0000000..3bf569d --- /dev/null +++ b/Shipyard/ShipyardBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs @@ -0,0 +1,13 @@ +using ShipyardContracts.ViewModels; + +namespace ShipyardBusinessLogic.OfficePackage.HelperModels +{ + public class ExcelInfo + { + public string FileName { get; set; } = string.Empty; + + public string Title { get; set; } = string.Empty; + + public List ShipDetails { get; set; } = new(); + } +} \ No newline at end of file diff --git a/Shipyard/ShipyardBusinessLogic/OfficePackage/HelperModels/ExcelMergeParameters.cs b/Shipyard/ShipyardBusinessLogic/OfficePackage/HelperModels/ExcelMergeParameters.cs new file mode 100644 index 0000000..0a67ac1 --- /dev/null +++ b/Shipyard/ShipyardBusinessLogic/OfficePackage/HelperModels/ExcelMergeParameters.cs @@ -0,0 +1,11 @@ +namespace ShipyardBusinessLogic.OfficePackage.HelperModels +{ + public class ExcelMergeParameters + { + public string CellFromName { get; set; } = string.Empty; + + public string CellToName { get; set; } = string.Empty; + + public string Merge => $"{CellFromName}:{CellToName}"; + } +} \ No newline at end of file diff --git a/Shipyard/ShipyardBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs b/Shipyard/ShipyardBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs new file mode 100644 index 0000000..7c1e229 --- /dev/null +++ b/Shipyard/ShipyardBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs @@ -0,0 +1,17 @@ +using ShipyardContracts.ViewModels; + +namespace ShipyardBusinessLogic.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(); + } +} \ No newline at end of file diff --git a/Shipyard/ShipyardBusinessLogic/OfficePackage/HelperModels/PdfParagraph.cs b/Shipyard/ShipyardBusinessLogic/OfficePackage/HelperModels/PdfParagraph.cs new file mode 100644 index 0000000..fa5cb3b --- /dev/null +++ b/Shipyard/ShipyardBusinessLogic/OfficePackage/HelperModels/PdfParagraph.cs @@ -0,0 +1,13 @@ +using ShipyardBusinessLogic.OfficePackage.HelperEnums; + +namespace ShipyardBusinessLogic.OfficePackage.HelperModels +{ + public class PdfParagraph + { + public string Text { get; set; } = string.Empty; + + public string Style { get; set; } = string.Empty; + + public PdfParagraphAlignmentType ParagraphAlignment { get; set; } + } +} \ No newline at end of file diff --git a/Shipyard/ShipyardBusinessLogic/OfficePackage/HelperModels/PdfRowParameters.cs b/Shipyard/ShipyardBusinessLogic/OfficePackage/HelperModels/PdfRowParameters.cs new file mode 100644 index 0000000..ebd3149 --- /dev/null +++ b/Shipyard/ShipyardBusinessLogic/OfficePackage/HelperModels/PdfRowParameters.cs @@ -0,0 +1,13 @@ +using ShipyardBusinessLogic.OfficePackage.HelperEnums; + +namespace ShipyardBusinessLogic.OfficePackage.HelperModels +{ + public class PdfRowParameters + { + public List Texts { get; set; } = new(); + + public string Style { get; set; } = string.Empty; + + public PdfParagraphAlignmentType ParagraphAlignment { get; set; } + } +} \ No newline at end of file diff --git a/Shipyard/ShipyardBusinessLogic/OfficePackage/HelperModels/WordInfo.cs b/Shipyard/ShipyardBusinessLogic/OfficePackage/HelperModels/WordInfo.cs new file mode 100644 index 0000000..1c39897 --- /dev/null +++ b/Shipyard/ShipyardBusinessLogic/OfficePackage/HelperModels/WordInfo.cs @@ -0,0 +1,13 @@ +using ShipyardContracts.ViewModels; + +namespace ShipyardBusinessLogic.OfficePackage.HelperModels +{ + public class WordInfo + { + public string FileName { get; set; } = string.Empty; + + public string Title { get; set; } = string.Empty; + + public List Ships { get; set; } = new(); + } +} \ No newline at end of file diff --git a/Shipyard/ShipyardBusinessLogic/OfficePackage/HelperModels/WordParagraph.cs b/Shipyard/ShipyardBusinessLogic/OfficePackage/HelperModels/WordParagraph.cs new file mode 100644 index 0000000..3c77e06 --- /dev/null +++ b/Shipyard/ShipyardBusinessLogic/OfficePackage/HelperModels/WordParagraph.cs @@ -0,0 +1,9 @@ +namespace ShipyardBusinessLogic.OfficePackage.HelperModels +{ + public class WordParagraph + { + public List<(string, WordTextProperties)> Texts { get; set; } = new(); + + public WordTextProperties? TextProperties { get; set; } + } +} \ No newline at end of file diff --git a/Shipyard/ShipyardBusinessLogic/OfficePackage/HelperModels/WordTextProperties.cs b/Shipyard/ShipyardBusinessLogic/OfficePackage/HelperModels/WordTextProperties.cs new file mode 100644 index 0000000..ee3ebd4 --- /dev/null +++ b/Shipyard/ShipyardBusinessLogic/OfficePackage/HelperModels/WordTextProperties.cs @@ -0,0 +1,13 @@ +using ShipyardBusinessLogic.OfficePackage.HelperEnums; + +namespace ShipyardBusinessLogic.OfficePackage.HelperModels +{ + public class WordTextProperties + { + public string Size { get; set; } = string.Empty; + + public bool Bold { get; set; } + + public WordJustificationType JustificationType { get; set; } + } +} \ No newline at end of file diff --git a/Shipyard/ShipyardBusinessLogic/OfficePackage/Implements/SaveToExcel.cs b/Shipyard/ShipyardBusinessLogic/OfficePackage/Implements/SaveToExcel.cs new file mode 100644 index 0000000..b9f86fc --- /dev/null +++ b/Shipyard/ShipyardBusinessLogic/OfficePackage/Implements/SaveToExcel.cs @@ -0,0 +1,292 @@ +using ShipyardBusinessLogic.OfficePackage.HelperEnums; +using ShipyardBusinessLogic.OfficePackage.HelperModels; +using DocumentFormat.OpenXml; +using DocumentFormat.OpenXml.Office2010.Excel; +using DocumentFormat.OpenXml.Office2013.Excel; +using DocumentFormat.OpenXml.Packaging; +using DocumentFormat.OpenXml.Spreadsheet; + +namespace ShipyardBusinessLogic.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.TextWithBorder => 1U, + ExcelStyleInfoType.Text => 0U, + _ => 0U, + }; + } + + protected override void CreateExcel(ExcelInfo 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(ExcelInfo info) + { + if (_spreadsheetDocument == null) + { + return; + } + _spreadsheetDocument.WorkbookPart!.Workbook.Save(); + _spreadsheetDocument.Dispose(); + } + } +} \ No newline at end of file diff --git a/Shipyard/ShipyardBusinessLogic/OfficePackage/Implements/SaveToPdf.cs b/Shipyard/ShipyardBusinessLogic/OfficePackage/Implements/SaveToPdf.cs new file mode 100644 index 0000000..dc9e667 --- /dev/null +++ b/Shipyard/ShipyardBusinessLogic/OfficePackage/Implements/SaveToPdf.cs @@ -0,0 +1,109 @@ +using ShipyardBusinessLogic.OfficePackage.HelperEnums; +using ShipyardBusinessLogic.OfficePackage.HelperModels; +using MigraDoc.DocumentObjectModel; +using MigraDoc.DocumentObjectModel.Tables; +using MigraDoc.Rendering; + +namespace ShipyardBusinessLogic.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.Right => 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(PdfInfo 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(PdfInfo info) + { + var renderer = new PdfDocumentRenderer(true) + { + Document = _document + }; + renderer.RenderDocument(); + renderer.PdfDocument.Save(info.FileName); + } + } +} \ No newline at end of file diff --git a/Shipyard/ShipyardBusinessLogic/OfficePackage/Implements/SaveToWord.cs b/Shipyard/ShipyardBusinessLogic/OfficePackage/Implements/SaveToWord.cs new file mode 100644 index 0000000..9f065f5 --- /dev/null +++ b/Shipyard/ShipyardBusinessLogic/OfficePackage/Implements/SaveToWord.cs @@ -0,0 +1,119 @@ +using ShipyardBusinessLogic.OfficePackage.HelperEnums; +using ShipyardBusinessLogic.OfficePackage.HelperModels; +using DocumentFormat.OpenXml; +using DocumentFormat.OpenXml.Packaging; +using DocumentFormat.OpenXml.Wordprocessing; + +namespace ShipyardBusinessLogic.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(WordInfo 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(WordInfo info) + { + if (_docBody == null || _wordDocument == null) + { + return; + } + _docBody.AppendChild(CreateSectionProperties()); + + _wordDocument.MainDocumentPart!.Document.Save(); + + _wordDocument.Dispose(); + } + } +} \ No newline at end of file diff --git a/Shipyard/ShipyardBusinessLogic/ShipyardBusinessLogic.csproj b/Shipyard/ShipyardBusinessLogic/ShipyardBusinessLogic.csproj index 6d51480..15f5364 100644 --- a/Shipyard/ShipyardBusinessLogic/ShipyardBusinessLogic.csproj +++ b/Shipyard/ShipyardBusinessLogic/ShipyardBusinessLogic.csproj @@ -7,7 +7,9 @@ + + diff --git a/Shipyard/ShipyardContracts/BindingModels/ReportBindingModel.cs b/Shipyard/ShipyardContracts/BindingModels/ReportBindingModel.cs new file mode 100644 index 0000000..2b7b806 --- /dev/null +++ b/Shipyard/ShipyardContracts/BindingModels/ReportBindingModel.cs @@ -0,0 +1,11 @@ +namespace ShipyardContracts.BindingModels +{ + public class ReportBindingModel + { + public string FileName { get; set; } = string.Empty; + + public DateTime? DateFrom { get; set; } + + public DateTime? DateTo { get; set; } + } +} \ No newline at end of file diff --git a/Shipyard/ShipyardContracts/BusinessLogicsContracts/IReportLogic.cs b/Shipyard/ShipyardContracts/BusinessLogicsContracts/IReportLogic.cs new file mode 100644 index 0000000..254c3f9 --- /dev/null +++ b/Shipyard/ShipyardContracts/BusinessLogicsContracts/IReportLogic.cs @@ -0,0 +1,18 @@ +using ShipyardContracts.BindingModels; +using ShipyardContracts.ViewModels; + +namespace ShipyardContracts.BusinessLogicsContracts +{ + public interface IReportLogic + { + List GetShipDetail(); + + List GetOrders(ReportBindingModel model); + + void SaveComponentsToWordFile(ReportBindingModel model); + + void SaveProductComponentToExcelFile(ReportBindingModel model); + + void SaveOrdersToPdfFile(ReportBindingModel model); + } +} \ No newline at end of file diff --git a/Shipyard/ShipyardContracts/SearchModels/OrderSearchModel.cs b/Shipyard/ShipyardContracts/SearchModels/OrderSearchModel.cs index 798e681..86beb33 100644 --- a/Shipyard/ShipyardContracts/SearchModels/OrderSearchModel.cs +++ b/Shipyard/ShipyardContracts/SearchModels/OrderSearchModel.cs @@ -3,5 +3,7 @@ public class OrderSearchModel { public int? Id { get; set; } + public DateTime? DateFrom { get; set; } + public DateTime? DateTo { get; set; } } } \ No newline at end of file diff --git a/Shipyard/ShipyardContracts/ViewModels/ReportOrdersViewModel.cs b/Shipyard/ShipyardContracts/ViewModels/ReportOrdersViewModel.cs new file mode 100644 index 0000000..e1ae998 --- /dev/null +++ b/Shipyard/ShipyardContracts/ViewModels/ReportOrdersViewModel.cs @@ -0,0 +1,14 @@ +namespace ShipyardContracts.ViewModels +{ + public class ReportOrdersViewModel + { + public int Id { get; set; } + + public DateTime DateCreate { get; set; } + + public string ShipName { get; set; } = string.Empty; + public string OrderStatus { get; set; } = string.Empty; + + public double Sum { get; set; } + } +} \ No newline at end of file diff --git a/Shipyard/ShipyardContracts/ViewModels/ReportShipDetailViewModel.cs b/Shipyard/ShipyardContracts/ViewModels/ReportShipDetailViewModel.cs new file mode 100644 index 0000000..c10209f --- /dev/null +++ b/Shipyard/ShipyardContracts/ViewModels/ReportShipDetailViewModel.cs @@ -0,0 +1,11 @@ +namespace ShipyardContracts.ViewModels +{ + public class ReportShipDetailViewModel + { + public string ShipName { get; set; } = string.Empty; + + public int TotalCount { get; set; } + + public List<(string Detail, int Count)> Details { get; set; } = new(); + } +} \ No newline at end of file diff --git a/Shipyard/ShipyardDataBaseImplement/Implements/OrderStorage.cs b/Shipyard/ShipyardDataBaseImplement/Implements/OrderStorage.cs index a9061f8..c7f4396 100644 --- a/Shipyard/ShipyardDataBaseImplement/Implements/OrderStorage.cs +++ b/Shipyard/ShipyardDataBaseImplement/Implements/OrderStorage.cs @@ -42,11 +42,19 @@ namespace ShipyardDataBaseImplement.Implements public List GetFilteredList(OrderSearchModel model) { - if (!model.Id.HasValue) + using var context = new ShipyardDataBase(); + if (!model.Id.HasValue && !model.DateFrom.HasValue) { return new(); } - using var context = new ShipyardDataBase(); + if (model.DateFrom.HasValue) + { + return context.Orders + .Include(x => x.Ship) + .Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo) + .Select(x => x.GetViewModel) + .ToList(); + } return context.Orders .Include(x => x.Ship) .Where(x => x.Id == model.Id) diff --git a/Shipyard/ShipyardFileImplement/Implements/OrderStorage.cs b/Shipyard/ShipyardFileImplement/Implements/OrderStorage.cs index b1c2636..87e0441 100644 --- a/Shipyard/ShipyardFileImplement/Implements/OrderStorage.cs +++ b/Shipyard/ShipyardFileImplement/Implements/OrderStorage.cs @@ -21,10 +21,17 @@ namespace ShipyardFileImplement.Implements public List GetFilteredList(OrderSearchModel model) { - if (!model.Id.HasValue) + if (!model.Id.HasValue && !model.DateFrom.HasValue) { return new(); } + if (model.DateFrom.HasValue) + { + return source.Orders + .Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo) + .Select(x => x.GetViewModel) + .ToList(); + } return source.Orders.Where(x => x.Id.Equals(model.Id)).Select(x => GetViewModel(x)).ToList(); } diff --git a/Shipyard/ShipyardListImplement/Implements/OrderStorage.cs b/Shipyard/ShipyardListImplement/Implements/OrderStorage.cs index 1ff3bfc..a9eab31 100644 --- a/Shipyard/ShipyardListImplement/Implements/OrderStorage.cs +++ b/Shipyard/ShipyardListImplement/Implements/OrderStorage.cs @@ -25,10 +25,21 @@ namespace ShipyardListImplement.Implements public List GetFilteredList(OrderSearchModel model) { var result = new List(); - if (!model.Id.HasValue) + if (!model.Id.HasValue && !model.DateFrom.HasValue) { return result; } + if (model.DateFrom.HasValue) + { + foreach (var order in _source.Orders) + { + if (order.DateCreate >= model.DateFrom && order.DateCreate <= model.DateTo) + { + result.Add(GetViewModel(order)); + } + } + return result; + } foreach (var order in _source.Orders) { if (order.Id == model.Id) diff --git a/Shipyard/ShipyardView/FormMain.Designer.cs b/Shipyard/ShipyardView/FormMain.Designer.cs index 940ddd5..5e9442c 100644 --- a/Shipyard/ShipyardView/FormMain.Designer.cs +++ b/Shipyard/ShipyardView/FormMain.Designer.cs @@ -33,6 +33,10 @@ toolStripMenu = new ToolStripDropDownButton(); деталиToolStripMenuItem = new ToolStripMenuItem(); кораблиToolStripMenuItem = new ToolStripMenuItem(); + отчетыToolStripMenuItem = new ToolStripDropDownButton(); + ShipsToolStripMenuItem = new ToolStripMenuItem(); + shipsDetailsToolStripMenuItem = new ToolStripMenuItem(); + ordersToolStripMenuItem = new ToolStripMenuItem(); dataGridView = new DataGridView(); buttonCreateOrder = new Button(); buttonTakeInWork = new Button(); @@ -46,7 +50,7 @@ // toolStrip // toolStrip.ImageScalingSize = new Size(20, 20); - toolStrip.Items.AddRange(new ToolStripItem[] { toolStripMenu }); + toolStrip.Items.AddRange(new ToolStripItem[] { toolStripMenu, отчетыToolStripMenuItem }); toolStrip.Location = new Point(0, 0); toolStrip.Name = "toolStrip"; toolStrip.Size = new Size(1251, 27); @@ -77,6 +81,37 @@ кораблиToolStripMenuItem.Text = "Корабли"; кораблиToolStripMenuItem.Click += КораблиToolStripMenuItem_Click; // + // отчетыToolStripMenuItem + // + отчетыToolStripMenuItem.DisplayStyle = ToolStripItemDisplayStyle.Text; + отчетыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { ShipsToolStripMenuItem, shipsDetailsToolStripMenuItem, ordersToolStripMenuItem }); + отчетыToolStripMenuItem.Image = (Image)resources.GetObject("отчетыToolStripMenuItem.Image"); + отчетыToolStripMenuItem.ImageTransparentColor = Color.Magenta; + отчетыToolStripMenuItem.Name = "отчетыToolStripMenuItem"; + отчетыToolStripMenuItem.Size = new Size(73, 24); + отчетыToolStripMenuItem.Text = "Отчёты"; + // + // ShipsToolStripMenuItem + // + ShipsToolStripMenuItem.Name = "ShipsToolStripMenuItem"; + ShipsToolStripMenuItem.Size = new Size(236, 26); + ShipsToolStripMenuItem.Text = "Список кораблей"; + ShipsToolStripMenuItem.Click += ShipsToolStripMenuItem_Click; + // + // shipsDetailsToolStripMenuItem + // + shipsDetailsToolStripMenuItem.Name = "shipsDetailsToolStripMenuItem"; + shipsDetailsToolStripMenuItem.Size = new Size(236, 26); + shipsDetailsToolStripMenuItem.Text = "Корабли по деталям"; + shipsDetailsToolStripMenuItem.Click += shipDetailsToolStripMenuItem_Click; + // + // ordersToolStripMenuItem + // + ordersToolStripMenuItem.Name = "ordersToolStripMenuItem"; + ordersToolStripMenuItem.Size = new Size(236, 26); + ordersToolStripMenuItem.Text = "Список заказов"; + ordersToolStripMenuItem.Click += ordersToolStripMenuItem_Click; + // // dataGridView // dataGridView.AllowUserToAddRows = false; @@ -177,5 +212,9 @@ private ToolStripDropDownButton toolStripMenu; private ToolStripMenuItem деталиToolStripMenuItem; private ToolStripMenuItem кораблиToolStripMenuItem; + private ToolStripDropDownButton отчетыToolStripMenuItem; + private ToolStripMenuItem ShipsToolStripMenuItem; + private ToolStripMenuItem shipsDetailsToolStripMenuItem; + private ToolStripMenuItem ordersToolStripMenuItem; } } \ No newline at end of file diff --git a/Shipyard/ShipyardView/FormMain.cs b/Shipyard/ShipyardView/FormMain.cs index 25680a7..402f6ad 100644 --- a/Shipyard/ShipyardView/FormMain.cs +++ b/Shipyard/ShipyardView/FormMain.cs @@ -11,11 +11,13 @@ namespace ShipyardView { private readonly ILogger _logger; private readonly IOrderLogic _orderLogic; - public FormMain(ILogger logger, IOrderLogic orderLogic) + private readonly IReportLogic _reportLogic; + public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic) { InitializeComponent(); _logger = logger; _orderLogic = orderLogic; + _reportLogic = reportLogic; } private void FormMain_Load(object sender, EventArgs e) { @@ -137,5 +139,32 @@ namespace ShipyardView { LoadData(); } + private void ShipsToolStripMenuItem_Click(object sender, EventArgs e) + { + using var dialog = new SaveFileDialog { Filter = "docx|*.docx" }; + if (dialog.ShowDialog() == DialogResult.OK) + { + _reportLogic.SaveComponentsToWordFile(new ReportBindingModel { FileName = dialog.FileName }); + MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } + + private void shipDetailsToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormReportShipDetails)); + if (service is FormReportShipDetails 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(); + } + } } } \ No newline at end of file diff --git a/Shipyard/ShipyardView/FormMain.resx b/Shipyard/ShipyardView/FormMain.resx index dafcbea..7e383f8 100644 --- a/Shipyard/ShipyardView/FormMain.resx +++ b/Shipyard/ShipyardView/FormMain.resx @@ -130,6 +130,17 @@ U87f4aUApcXhnrI9Jzg/laQKFntXlHM+lSQK5psL5fvbp/JvJLGCQqmSWM5JkiCT84igXGtSrruKLQ0T luAdmZxHBG37FFuWBC/j5XKOmX8WAH7rcI6ZMffPgjQwN2bXJgDo/COBTpjneQ2dML0PY3cISreGe8HM qgAAAABJRU5ErkJggg== + + + + + iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 + YQUAAAAJcEhZcwAAEnQAABJ0Ad5mH3gAAAEKSURBVEhL3ZG9DsFQHMXvczDZvIOtXsHObuhqkViI3Quw + 6CYmNoMYJJ0NBiFFIoIytOuf0+TeXP3yde+iyS+3OcP53Z4y3/dJJ4HAsiwyTVMp6BQCBIZhKAWdEcHV + vSlBmeB82NFy1KLluEWOPRC5MoHdMWhazwi4RJlALgf4EuT6BI+5kCsTrGddUY658E+QvyXYHq9UnRyC + U87f4aUApcXhnrI9Jzg/laQKFntXlHM+lSQK5psL5fvbp/JvJLGCQqmSWM5JkiCT84igXGtSrruKLQ0T + luAdmZxHBG37FFuWBC/j5XKOmX8WAH7rcI6ZMffPgjQwN2bXJgDo/COBTpjneQ2dML0PY3cISreGe8HM + qgAAAABJRU5ErkJggg== \ No newline at end of file diff --git a/Shipyard/ShipyardView/FormReportOrders.Designer.cs b/Shipyard/ShipyardView/FormReportOrders.Designer.cs new file mode 100644 index 0000000..2063bd4 --- /dev/null +++ b/Shipyard/ShipyardView/FormReportOrders.Designer.cs @@ -0,0 +1,131 @@ +namespace ShipyardView +{ + 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() + { + this.panel = new System.Windows.Forms.Panel(); + this.buttonToPdf = new System.Windows.Forms.Button(); + this.buttonMake = new System.Windows.Forms.Button(); + this.dateTimePickerTo = new System.Windows.Forms.DateTimePicker(); + this.labelTo = new System.Windows.Forms.Label(); + this.dateTimePickerFrom = new System.Windows.Forms.DateTimePicker(); + this.labelFrom = new System.Windows.Forms.Label(); + this.panel.SuspendLayout(); + this.SuspendLayout(); + // + // panel + // + this.panel.Controls.Add(this.buttonToPdf); + this.panel.Controls.Add(this.buttonMake); + this.panel.Controls.Add(this.dateTimePickerTo); + this.panel.Controls.Add(this.labelTo); + this.panel.Controls.Add(this.dateTimePickerFrom); + this.panel.Controls.Add(this.labelFrom); + this.panel.Dock = System.Windows.Forms.DockStyle.Top; + this.panel.Location = new System.Drawing.Point(0, 0); + this.panel.Name = "panel"; + this.panel.Size = new System.Drawing.Size(926, 47); + this.panel.TabIndex = 0; + // + // buttonToPdf + // + this.buttonToPdf.Location = new System.Drawing.Point(825, 7); + this.buttonToPdf.Name = "buttonToPdf"; + this.buttonToPdf.Size = new System.Drawing.Size(94, 29); + this.buttonToPdf.TabIndex = 5; + this.buttonToPdf.Text = "в Pdf"; + this.buttonToPdf.UseVisualStyleBackColor = true; + this.buttonToPdf.Click += new System.EventHandler(this.ButtonToPdf_Click); + // + // buttonMake + // + this.buttonMake.Location = new System.Drawing.Point(643, 7); + this.buttonMake.Name = "buttonMake"; + this.buttonMake.Size = new System.Drawing.Size(149, 29); + this.buttonMake.TabIndex = 4; + this.buttonMake.Text = "Сформировать"; + this.buttonMake.UseVisualStyleBackColor = true; + this.buttonMake.Click += new System.EventHandler(this.ButtonMake_Click); + // + // dateTimePickerTo + // + this.dateTimePickerTo.Location = new System.Drawing.Point(348, 9); + this.dateTimePickerTo.Name = "dateTimePickerTo"; + this.dateTimePickerTo.Size = new System.Drawing.Size(250, 27); + this.dateTimePickerTo.TabIndex = 3; + // + // labelTo + // + this.labelTo.AutoSize = true; + this.labelTo.Location = new System.Drawing.Point(292, 14); + this.labelTo.Name = "labelTo"; + this.labelTo.Size = new System.Drawing.Size(27, 20); + this.labelTo.TabIndex = 2; + this.labelTo.Text = "по"; + // + // dateTimePickerFrom + // + this.dateTimePickerFrom.Location = new System.Drawing.Point(36, 9); + this.dateTimePickerFrom.Name = "dateTimePickerFrom"; + this.dateTimePickerFrom.Size = new System.Drawing.Size(250, 27); + this.dateTimePickerFrom.TabIndex = 1; + // + // labelFrom + // + this.labelFrom.AutoSize = true; + this.labelFrom.Location = new System.Drawing.Point(12, 14); + this.labelFrom.Name = "labelFrom"; + this.labelFrom.Size = new System.Drawing.Size(18, 20); + this.labelFrom.TabIndex = 0; + this.labelFrom.Text = "C"; + // + // FormReportOrders + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(926, 450); + this.Controls.Add(this.panel); + this.Name = "FormReportOrders"; + this.Text = "Заказы"; + this.panel.ResumeLayout(false); + this.panel.PerformLayout(); + this.ResumeLayout(false); + + } + + #endregion + + private Panel panel; + private Button buttonToPdf; + private Button buttonMake; + private DateTimePicker dateTimePickerTo; + private Label labelTo; + private DateTimePicker dateTimePickerFrom; + private Label labelFrom; + } +} \ No newline at end of file diff --git a/Shipyard/ShipyardView/FormReportOrders.cs b/Shipyard/ShipyardView/FormReportOrders.cs new file mode 100644 index 0000000..313559d --- /dev/null +++ b/Shipyard/ShipyardView/FormReportOrders.cs @@ -0,0 +1,100 @@ +using Microsoft.Extensions.Logging; +using Microsoft.Reporting.WinForms; +using ShipyardContracts.BindingModels; +using ShipyardContracts.BusinessLogicsContracts; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace ShipyardView +{ + 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("ReportOrders.rdlc", FileMode.Open)); + Controls.Clear(); + Controls.Add(reportViewer); + Controls.Add(panel); + } + + private void ButtonMake_Click(object sender, EventArgs e) + { + if (dateTimePickerFrom.Value.Date >= dateTimePickerTo.Value.Date) + { + MessageBox.Show("Дата начала должна быть меньше даты окончания", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + try + { + var dataSource = _logic.GetOrders(new ReportBindingModel + { + DateFrom = dateTimePickerFrom.Value, + DateTo = dateTimePickerTo.Value + }); + var source = new ReportDataSource("DataSetOrders", dataSource); + reportViewer.LocalReport.DataSources.Clear(); + reportViewer.LocalReport.DataSources.Add(source); + var parameters = new[] { new ReportParameter("ReportParameterPeriod", + $"c {dateTimePickerFrom.Value.ToShortDateString()} по {dateTimePickerTo.Value.ToShortDateString()}") }; + reportViewer.LocalReport.SetParameters(parameters); + + reportViewer.RefreshReport(); + _logger.LogInformation("Загрузка списка заказов на период {From}-{To}", dateTimePickerFrom.Value.ToShortDateString(), dateTimePickerTo.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 (dateTimePickerFrom.Value.Date >= dateTimePickerTo.Value.Date) + { + MessageBox.Show("Дата начала должна быть меньше даты окончания", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + using var dialog = new SaveFileDialog { Filter = "pdf|*.pdf" }; + if (dialog.ShowDialog() == DialogResult.OK) + { + try + { + _logic.SaveOrdersToPdfFile(new ReportBindingModel + { + FileName = dialog.FileName, + DateFrom = dateTimePickerFrom.Value, + DateTo = dateTimePickerTo.Value + }); + _logger.LogInformation("Сохранение списка заказов на период {From}-{To}", dateTimePickerFrom.Value.ToShortDateString(), dateTimePickerTo.Value.ToShortDateString()); + MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения списка заказов на период"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } +} \ No newline at end of file diff --git a/Shipyard/ShipyardView/FormReportOrders.resx b/Shipyard/ShipyardView/FormReportOrders.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/Shipyard/ShipyardView/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/Shipyard/ShipyardView/FormReportShipDetails.Designer.cs b/Shipyard/ShipyardView/FormReportShipDetails.Designer.cs new file mode 100644 index 0000000..3c24b32 --- /dev/null +++ b/Shipyard/ShipyardView/FormReportShipDetails.Designer.cs @@ -0,0 +1,107 @@ +namespace ShipyardView +{ + partial class FormReportShipDetails + { + /// + /// 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() + { + ButtonSaveToExcel = new Button(); + dataGridView = new DataGridView(); + ShipColumn = new DataGridViewTextBoxColumn(); + DetailColumn = new DataGridViewTextBoxColumn(); + CountColumn = new DataGridViewTextBoxColumn(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // ButtonSaveToExcel + // + ButtonSaveToExcel.Location = new Point(12, 12); + ButtonSaveToExcel.Name = "ButtonSaveToExcel"; + ButtonSaveToExcel.Size = new Size(211, 32); + ButtonSaveToExcel.TabIndex = 0; + ButtonSaveToExcel.Text = "Сохранить в excel"; + ButtonSaveToExcel.UseVisualStyleBackColor = true; + ButtonSaveToExcel.Click += ButtonSaveToExcel_Click; + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.AllowUserToResizeColumns = false; + dataGridView.AllowUserToResizeRows = false; + dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Columns.AddRange(new DataGridViewColumn[] { ShipColumn, DetailColumn, CountColumn }); + dataGridView.Dock = DockStyle.Bottom; + dataGridView.Location = new Point(0, 62); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersVisible = false; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 29; + dataGridView.Size = new Size(597, 480); + dataGridView.TabIndex = 1; + // + // ShipColumn + // + ShipColumn.HeaderText = "Корабль"; + ShipColumn.MinimumWidth = 6; + ShipColumn.Name = "ShipColumn"; + // + // DetailColumn + // + DetailColumn.HeaderText = "Деталь"; + DetailColumn.MinimumWidth = 6; + DetailColumn.Name = "DetailColumn"; + // + // CountColumn + // + CountColumn.HeaderText = "Количество"; + CountColumn.MinimumWidth = 6; + CountColumn.Name = "CountColumn"; + // + // FormReportShipDetails + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(597, 542); + Controls.Add(dataGridView); + Controls.Add(ButtonSaveToExcel); + Name = "FormReportShipDetails"; + Text = "Корабли по деталям"; + Load += FormReportProductComponents_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private Button ButtonSaveToExcel; + private DataGridView dataGridView; + private DataGridViewTextBoxColumn ShipColumn; + private DataGridViewTextBoxColumn DetailColumn; + private DataGridViewTextBoxColumn CountColumn; + } +} \ No newline at end of file diff --git a/Shipyard/ShipyardView/FormReportShipDetails.cs b/Shipyard/ShipyardView/FormReportShipDetails.cs new file mode 100644 index 0000000..e8cc5d5 --- /dev/null +++ b/Shipyard/ShipyardView/FormReportShipDetails.cs @@ -0,0 +1,70 @@ +using Microsoft.Extensions.Logging; +using ShipyardContracts.BindingModels; +using ShipyardContracts.BusinessLogicsContracts; + +namespace ShipyardView +{ + public partial class FormReportShipDetails : Form + { + private readonly ILogger _logger; + + private readonly IReportLogic _logic; + + public FormReportShipDetails(ILogger logger, IReportLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormReportProductComponents_Load(object sender, EventArgs e) + { + try + { + var dict = _logic.GetShipDetail(); + if (dict != null) + { + dataGridView.Rows.Clear(); + foreach (var elem in dict) + { + dataGridView.Rows.Add(new object[] { elem.ShipName, "", "" }); + foreach (var listElem in elem.Details) + { + 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.SaveProductComponentToExcelFile(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); + } + } + } + } +} \ No newline at end of file diff --git a/Shipyard/ShipyardView/FormReportShipDetails.resx b/Shipyard/ShipyardView/FormReportShipDetails.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/Shipyard/ShipyardView/FormReportShipDetails.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/Shipyard/ShipyardView/Program.cs b/Shipyard/ShipyardView/Program.cs index 2d6ed7d..85ab374 100644 --- a/Shipyard/ShipyardView/Program.cs +++ b/Shipyard/ShipyardView/Program.cs @@ -3,6 +3,8 @@ using ShipyardBusinessLogic.BusinessLogics; using ShipyardContracts.BusinessLogicsContracts; using ShipyardContracts.StoragesContracts; using ShipyardDataBaseImplement.Implements; +using ShipyardBusinessLogic.OfficePackage.Implements; +using ShipyardBusinessLogic.OfficePackage; using NLog.Extensions.Logging; namespace ShipyardView @@ -35,6 +37,10 @@ namespace ShipyardView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -42,6 +48,8 @@ namespace ShipyardView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); } } diff --git a/Shipyard/ShipyardView/Properties/DataSources/ShipyardContracts.BusinessLogicsContracts.IDetailLogic.datasource b/Shipyard/ShipyardView/Properties/DataSources/ShipyardContracts.BusinessLogicsContracts.IDetailLogic.datasource new file mode 100644 index 0000000..afae7cd --- /dev/null +++ b/Shipyard/ShipyardView/Properties/DataSources/ShipyardContracts.BusinessLogicsContracts.IDetailLogic.datasource @@ -0,0 +1,10 @@ + + + + ShipyardContracts.BusinessLogicsContracts.IDetailLogic, ShipyardContracts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + \ No newline at end of file diff --git a/Shipyard/ShipyardView/Properties/DataSources/ShipyardContracts.BusinessLogicsContracts.IOrderLogic.datasource b/Shipyard/ShipyardView/Properties/DataSources/ShipyardContracts.BusinessLogicsContracts.IOrderLogic.datasource new file mode 100644 index 0000000..d47d7bc --- /dev/null +++ b/Shipyard/ShipyardView/Properties/DataSources/ShipyardContracts.BusinessLogicsContracts.IOrderLogic.datasource @@ -0,0 +1,10 @@ + + + + ShipyardContracts.BusinessLogicsContracts.IOrderLogic, ShipyardContracts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + \ No newline at end of file diff --git a/Shipyard/ShipyardView/Properties/DataSources/ShipyardContracts.BusinessLogicsContracts.IShipLogic.datasource b/Shipyard/ShipyardView/Properties/DataSources/ShipyardContracts.BusinessLogicsContracts.IShipLogic.datasource new file mode 100644 index 0000000..122289c --- /dev/null +++ b/Shipyard/ShipyardView/Properties/DataSources/ShipyardContracts.BusinessLogicsContracts.IShipLogic.datasource @@ -0,0 +1,10 @@ + + + + ShipyardContracts.BusinessLogicsContracts.IShipLogic, ShipyardContracts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + \ No newline at end of file diff --git a/Shipyard/ShipyardView/Properties/DataSources/ShipyardContracts.StoragesContracts.IDetailStorage.datasource b/Shipyard/ShipyardView/Properties/DataSources/ShipyardContracts.StoragesContracts.IDetailStorage.datasource new file mode 100644 index 0000000..88a84e3 --- /dev/null +++ b/Shipyard/ShipyardView/Properties/DataSources/ShipyardContracts.StoragesContracts.IDetailStorage.datasource @@ -0,0 +1,10 @@ + + + + ShipyardContracts.StoragesContracts.IDetailStorage, ShipyardContracts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + \ No newline at end of file diff --git a/Shipyard/ShipyardView/Properties/DataSources/ShipyardContracts.StoragesContracts.IOrderStorage.datasource b/Shipyard/ShipyardView/Properties/DataSources/ShipyardContracts.StoragesContracts.IOrderStorage.datasource new file mode 100644 index 0000000..c92d5a6 --- /dev/null +++ b/Shipyard/ShipyardView/Properties/DataSources/ShipyardContracts.StoragesContracts.IOrderStorage.datasource @@ -0,0 +1,10 @@ + + + + ShipyardContracts.StoragesContracts.IOrderStorage, ShipyardContracts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + \ No newline at end of file diff --git a/Shipyard/ShipyardView/Properties/DataSources/ShipyardContracts.StoragesContracts.IShipStorage.datasource b/Shipyard/ShipyardView/Properties/DataSources/ShipyardContracts.StoragesContracts.IShipStorage.datasource new file mode 100644 index 0000000..d1ef07f --- /dev/null +++ b/Shipyard/ShipyardView/Properties/DataSources/ShipyardContracts.StoragesContracts.IShipStorage.datasource @@ -0,0 +1,10 @@ + + + + ShipyardContracts.StoragesContracts.IShipStorage, ShipyardContracts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + \ No newline at end of file diff --git a/Shipyard/ShipyardView/Properties/Resources.Designer.cs b/Shipyard/ShipyardView/Properties/Resources.Designer.cs new file mode 100644 index 0000000..2c3d078 --- /dev/null +++ b/Shipyard/ShipyardView/Properties/Resources.Designer.cs @@ -0,0 +1,63 @@ +//------------------------------------------------------------------------------ +// +// Этот код создан программой. +// Исполняемая версия:4.0.30319.42000 +// +// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае +// повторной генерации кода. +// +//------------------------------------------------------------------------------ + +namespace ShipyardView.Properties { + using System; + + + /// + /// Класс ресурса со строгой типизацией для поиска локализованных строк и т.д. + /// + // Этот класс создан автоматически классом StronglyTypedResourceBuilder + // с помощью такого средства, как ResGen или Visual Studio. + // Чтобы добавить или удалить член, измените файл .ResX и снова запустите ResGen + // с параметром /str или перестройте свой проект VS. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Возвращает кэшированный экземпляр ResourceManager, использованный этим классом. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ShipyardView.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Перезаписывает свойство CurrentUICulture текущего потока для всех + /// обращений к ресурсу с помощью этого класса ресурса со строгой типизацией. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + } +} diff --git a/Shipyard/ShipyardView/Properties/Resources.resx b/Shipyard/ShipyardView/Properties/Resources.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/Shipyard/ShipyardView/Properties/Resources.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/Shipyard/ShipyardView/ReportOrders.rdlc b/Shipyard/ShipyardView/ReportOrders.rdlc new file mode 100644 index 0000000..0621e5f --- /dev/null +++ b/Shipyard/ShipyardView/ReportOrders.rdlc @@ -0,0 +1,579 @@ + + + 0 + + + + System.Data.DataSet + /* Local Connection */ + + 10791c83-cee8-4a38-bbd0-245fc17cefb3 + + + + + + ShipyardContractsViewModels + /* Local Query */ + + + + Id + System.Int32 + + + DateCreate + System.DateTime + + + ShipName + System.String + + + OrderStatus + System.String + + + Sum + System.Decimal + + + + ShipyardContracts.ViewModels + ReportOrdersViewModel + ShipyardContracts.ViewModels.ReportOrdersViewModel, ShipyardContracts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + + + + + + + + + true + true + + + + + Заказы + + + + + + + Textbox1 + 0.70583cm + 19.67885cm + + + 2pt + 2pt + 2pt + 2pt + + + + true + true + + + + + =Parameters!ReportParameterPeriod.Value + + + + + + + ReportParameterPeriod + 0.70583cm + 0.6cm + 19.67885cm + 1 + + + 2pt + 2pt + 2pt + 2pt + + + + + + + 3.90877cm + + + 4.41677cm + + + 3.30433cm + + + 2.5cm + + + 4.56494cm + + + + + 0.74083cm + + + + + true + true + + + + + ID + + + 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.74083cm + + + + + true + true + + + + + =Fields!Id.Value + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + =Fields!DateCreate.Value + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + =Fields!ShipName.Value + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + =Fields!OrderStatus.Value + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + =Fields!Sum.Value + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + + + + + + + + + + + + + + After + + + + + + + DataSetOrders + 1.87537cm + 0.98403cm + 1.48166cm + 18.69481cm + 2 + + + + + + true + true + + + + + Итого: + + + 2pt + 2pt + 2pt + 2pt + + + + true + true + + + + + =Sum(Fields!Sum.Value, "DataSetOrders") + + + 2pt + 2pt + 2pt + 2pt + + + + 2in +