From 8742f38d93ac138e7e2db7aeff16071e137cf1fb Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Sat, 11 Mar 2023 13:27:16 +0400 Subject: [PATCH 01/16] =?UTF-8?q?=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD?= =?UTF-8?q?=D1=8B=20=D0=B0=D0=B1=D1=81=D1=82=D1=80=D0=B0=D0=BA=D1=86=D0=B8?= =?UTF-8?q?=D0=B8=20=D0=B8=20=D0=BC=D0=BE=D0=B4=D0=B5=D0=BB=D0=B8=20=D0=B4?= =?UTF-8?q?=D0=BB=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D1=8B=20=D1=81=20?= =?UTF-8?q?=D0=BE=D1=84=D0=B8=D1=81=D0=BD=D1=8B=D0=BC=D0=B8=20=D0=BF=D0=B0?= =?UTF-8?q?=D0=BA=D0=B5=D1=82=D0=B0=D0=BC=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../OfficePackage/AbstractSaveToExcel.cs | 85 +++++++++++++++++++ .../OfficePackage/AbstractSaveToPdf.cs | 61 +++++++++++++ .../OfficePackage/AbstractSaveToWord.cs | 46 ++++++++++ .../HelperEnums/ExcelStyleInfoType.cs | 15 ++++ .../HelperEnums/PdfParagraphAlignmentType.cs | 15 ++++ .../HelperEnums/WordJustificationType.cs | 14 +++ .../HelperModels/ExcelCellParameters.cs | 18 ++++ .../OfficePackage/HelperModels/ExcelInfo.cs | 16 ++++ .../HelperModels/ExcelMergeParameters.cs | 15 ++++ .../OfficePackage/HelperModels/PdfInfo.cs | 18 ++++ .../HelperModels/PdfParagraph.cs | 16 ++++ .../HelperModels/PdfRowParameters.cs | 16 ++++ .../OfficePackage/HelperModels/WordInfo.cs | 16 ++++ .../HelperModels/WordParagraph.cs | 14 +++ .../HelperModels/WordTextProperties.cs | 17 ++++ .../BindingModels/ReportBindingModel.cs | 15 ++++ .../BusinessLogicContracts/IReportLogic.cs | 24 ++++++ .../SearchModels/OrderSearchModel.cs | 3 +- .../ReportDocumentBlankViewModel.cs | 16 ++++ .../ViewModels/ReportOrdersViewModel.cs | 16 ++++ 20 files changed, 455 insertions(+), 1 deletion(-) create mode 100644 LawFirm/LawFirmBusinessLogic/OfficePackage/AbstractSaveToExcel.cs create mode 100644 LawFirm/LawFirmBusinessLogic/OfficePackage/AbstractSaveToPdf.cs create mode 100644 LawFirm/LawFirmBusinessLogic/OfficePackage/AbstractSaveToWord.cs create mode 100644 LawFirm/LawFirmBusinessLogic/OfficePackage/HelperEnums/ExcelStyleInfoType.cs create mode 100644 LawFirm/LawFirmBusinessLogic/OfficePackage/HelperEnums/PdfParagraphAlignmentType.cs create mode 100644 LawFirm/LawFirmBusinessLogic/OfficePackage/HelperEnums/WordJustificationType.cs create mode 100644 LawFirm/LawFirmBusinessLogic/OfficePackage/HelperModels/ExcelCellParameters.cs create mode 100644 LawFirm/LawFirmBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs create mode 100644 LawFirm/LawFirmBusinessLogic/OfficePackage/HelperModels/ExcelMergeParameters.cs create mode 100644 LawFirm/LawFirmBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs create mode 100644 LawFirm/LawFirmBusinessLogic/OfficePackage/HelperModels/PdfParagraph.cs create mode 100644 LawFirm/LawFirmBusinessLogic/OfficePackage/HelperModels/PdfRowParameters.cs create mode 100644 LawFirm/LawFirmBusinessLogic/OfficePackage/HelperModels/WordInfo.cs create mode 100644 LawFirm/LawFirmBusinessLogic/OfficePackage/HelperModels/WordParagraph.cs create mode 100644 LawFirm/LawFirmBusinessLogic/OfficePackage/HelperModels/WordTextProperties.cs create mode 100644 LawFirm/LawFirmContracts/BindingModels/ReportBindingModel.cs create mode 100644 LawFirm/LawFirmContracts/BusinessLogicContracts/IReportLogic.cs create mode 100644 LawFirm/LawFirmContracts/ViewModels/ReportDocumentBlankViewModel.cs create mode 100644 LawFirm/LawFirmContracts/ViewModels/ReportOrdersViewModel.cs diff --git a/LawFirm/LawFirmBusinessLogic/OfficePackage/AbstractSaveToExcel.cs b/LawFirm/LawFirmBusinessLogic/OfficePackage/AbstractSaveToExcel.cs new file mode 100644 index 0000000..116efbb --- /dev/null +++ b/LawFirm/LawFirmBusinessLogic/OfficePackage/AbstractSaveToExcel.cs @@ -0,0 +1,85 @@ +using LawFirmBusinessLogic.OfficePackage.HelperEnums; +using LawFirmBusinessLogic.OfficePackage.HelperModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace LawFirmBusinessLogic.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.ProductComponents) + { + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "A", + RowIndex = rowIndex, + Text = pc.BlankName, + StyleInfo = ExcelStyleInfoType.Text + }); + rowIndex++; + foreach (var (Document, Count) in pc.Documents) + { + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "B", + RowIndex = rowIndex, + Text = Document, + 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); + } + /// Создание excel-файла + protected abstract void CreateExcel(ExcelInfo info); + /// Добавляем новую ячейку в лист + protected abstract void InsertCellInWorksheet(ExcelCellParameters excelParams); + /// Объединение ячеек + protected abstract void MergeCells(ExcelMergeParameters excelParams); + /// Сохранение файла + protected abstract void SaveExcel(ExcelInfo info); + } +} diff --git a/LawFirm/LawFirmBusinessLogic/OfficePackage/AbstractSaveToPdf.cs b/LawFirm/LawFirmBusinessLogic/OfficePackage/AbstractSaveToPdf.cs new file mode 100644 index 0000000..7d3f571 --- /dev/null +++ b/LawFirm/LawFirmBusinessLogic/OfficePackage/AbstractSaveToPdf.cs @@ -0,0 +1,61 @@ +using LawFirmBusinessLogic.OfficePackage.HelperEnums; +using LawFirmBusinessLogic.OfficePackage.HelperModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace LawFirmBusinessLogic.OfficePackage +{ + public abstract class AbstractSaveToPdf + { + public void CreateDoc(PdfInfo info) + { + CreatePdf(info); + CreateParagraph(new PdfParagraph + { + Text = info.Title, + Style = "NormalTitle", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + CreateParagraph(new PdfParagraph + { + Text = $"с{ info.DateFrom.ToShortDateString() } по { info.DateTo.ToShortDateString() }", Style = "Normal", ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + CreateTable(new List { "2cm", "3cm", "6cm", "3cm" }); + CreateRow(new PdfRowParameters + { + Texts = new List { "Номер", "Дата заказа", "Изделие", "Сумма" }, + Style = "NormalTitle", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + foreach (var order in info.Orders) + { + CreateRow(new PdfRowParameters + { + Texts = new List { order.Id.ToString(), order.DateCreate.ToShortDateString(), order.DocumentName, 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); + } + /// Создание pdf-файла + protected abstract void CreatePdf(PdfInfo info); + /// Создание параграфа с текстом + protected abstract void CreateParagraph(PdfParagraph paragraph); + /// Создание таблицы + protected abstract void CreateTable(List columns); + /// Создание и заполнение строки + protected abstract void CreateRow(PdfRowParameters rowParameters); + /// Сохранение файла + protected abstract void SavePdf(PdfInfo info); + } +} diff --git a/LawFirm/LawFirmBusinessLogic/OfficePackage/AbstractSaveToWord.cs b/LawFirm/LawFirmBusinessLogic/OfficePackage/AbstractSaveToWord.cs new file mode 100644 index 0000000..e2faa19 --- /dev/null +++ b/LawFirm/LawFirmBusinessLogic/OfficePackage/AbstractSaveToWord.cs @@ -0,0 +1,46 @@ +using LawFirmBusinessLogic.OfficePackage.HelperEnums; +using LawFirmBusinessLogic.OfficePackage.HelperModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace LawFirmBusinessLogic.OfficePackage +{ + public abstract class AbstractSaveToWord + { + public void CreateDoc(WordInfo info) + { + CreateWord(info); + CreateParagraph(new WordParagraph + { + Texts = new List<(string, WordTextProperties)> { (info.Title, new WordTextProperties { Bold = true, Size = "24", }) }, + TextProperties = new WordTextProperties + { + Size = "24", + JustificationType = WordJustificationType.Center + } + }); + foreach (var component in info.Blanks) + { + CreateParagraph(new WordParagraph + { + Texts = new List<(string, WordTextProperties)> {(component.BlankName, new WordTextProperties { Size = "24", }) }, + TextProperties = new WordTextProperties + { + Size = "24", + JustificationType = WordJustificationType.Both + } + }); + } + SaveWord(info); + } + /// Создание doc-файла + protected abstract void CreateWord(WordInfo info); + /// Создание абзаца с текстом + protected abstract void CreateParagraph(WordParagraph paragraph); + /// Сохранение файла + protected abstract void SaveWord(WordInfo info); + } +} diff --git a/LawFirm/LawFirmBusinessLogic/OfficePackage/HelperEnums/ExcelStyleInfoType.cs b/LawFirm/LawFirmBusinessLogic/OfficePackage/HelperEnums/ExcelStyleInfoType.cs new file mode 100644 index 0000000..142e940 --- /dev/null +++ b/LawFirm/LawFirmBusinessLogic/OfficePackage/HelperEnums/ExcelStyleInfoType.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace LawFirmBusinessLogic.OfficePackage.HelperEnums +{ + public enum ExcelStyleInfoType + { + Title, + Text, + TextWithBorder + } +} diff --git a/LawFirm/LawFirmBusinessLogic/OfficePackage/HelperEnums/PdfParagraphAlignmentType.cs b/LawFirm/LawFirmBusinessLogic/OfficePackage/HelperEnums/PdfParagraphAlignmentType.cs new file mode 100644 index 0000000..4ea9a3b --- /dev/null +++ b/LawFirm/LawFirmBusinessLogic/OfficePackage/HelperEnums/PdfParagraphAlignmentType.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace LawFirmBusinessLogic.OfficePackage.HelperEnums +{ + public enum PdfParagraphAlignmentType + { + Center, + Left, + Right + } +} diff --git a/LawFirm/LawFirmBusinessLogic/OfficePackage/HelperEnums/WordJustificationType.cs b/LawFirm/LawFirmBusinessLogic/OfficePackage/HelperEnums/WordJustificationType.cs new file mode 100644 index 0000000..e87a1c0 --- /dev/null +++ b/LawFirm/LawFirmBusinessLogic/OfficePackage/HelperEnums/WordJustificationType.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace LawFirmBusinessLogic.OfficePackage.HelperEnums +{ + public enum WordJustificationType + { + Center, + Both + } +} diff --git a/LawFirm/LawFirmBusinessLogic/OfficePackage/HelperModels/ExcelCellParameters.cs b/LawFirm/LawFirmBusinessLogic/OfficePackage/HelperModels/ExcelCellParameters.cs new file mode 100644 index 0000000..01d5b2b --- /dev/null +++ b/LawFirm/LawFirmBusinessLogic/OfficePackage/HelperModels/ExcelCellParameters.cs @@ -0,0 +1,18 @@ +using LawFirmBusinessLogic.OfficePackage.HelperEnums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace LawFirmBusinessLogic.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/LawFirm/LawFirmBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs b/LawFirm/LawFirmBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs new file mode 100644 index 0000000..2394be4 --- /dev/null +++ b/LawFirm/LawFirmBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs @@ -0,0 +1,16 @@ +using LawFirmContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace LawFirmBusinessLogic.OfficePackage.HelperModels +{ + public class ExcelInfo + { + public string FileName { get; set; } = string.Empty; + public string Title { get; set; } = string.Empty; + public List ProductComponents { get; set; } = new(); + } +} diff --git a/LawFirm/LawFirmBusinessLogic/OfficePackage/HelperModels/ExcelMergeParameters.cs b/LawFirm/LawFirmBusinessLogic/OfficePackage/HelperModels/ExcelMergeParameters.cs new file mode 100644 index 0000000..122d1ea --- /dev/null +++ b/LawFirm/LawFirmBusinessLogic/OfficePackage/HelperModels/ExcelMergeParameters.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace LawFirmBusinessLogic.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/LawFirm/LawFirmBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs b/LawFirm/LawFirmBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs new file mode 100644 index 0000000..6d86ebe --- /dev/null +++ b/LawFirm/LawFirmBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs @@ -0,0 +1,18 @@ +using LawFirmContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace LawFirmBusinessLogic.OfficePackage.HelperModels +{ + public class PdfInfo + { + public string FileName { get; set; } = string.Empty; + public string Title { get; set; } = string.Empty; + public DateTime DateFrom { get; set; } + public DateTime DateTo { get; set; } + public List Orders { get; set; } = new(); + } +} diff --git a/LawFirm/LawFirmBusinessLogic/OfficePackage/HelperModels/PdfParagraph.cs b/LawFirm/LawFirmBusinessLogic/OfficePackage/HelperModels/PdfParagraph.cs new file mode 100644 index 0000000..ca367a4 --- /dev/null +++ b/LawFirm/LawFirmBusinessLogic/OfficePackage/HelperModels/PdfParagraph.cs @@ -0,0 +1,16 @@ +using LawFirmBusinessLogic.OfficePackage.HelperEnums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace LawFirmBusinessLogic.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/LawFirm/LawFirmBusinessLogic/OfficePackage/HelperModels/PdfRowParameters.cs b/LawFirm/LawFirmBusinessLogic/OfficePackage/HelperModels/PdfRowParameters.cs new file mode 100644 index 0000000..ff9980c --- /dev/null +++ b/LawFirm/LawFirmBusinessLogic/OfficePackage/HelperModels/PdfRowParameters.cs @@ -0,0 +1,16 @@ +using LawFirmBusinessLogic.OfficePackage.HelperEnums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace LawFirmBusinessLogic.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/LawFirm/LawFirmBusinessLogic/OfficePackage/HelperModels/WordInfo.cs b/LawFirm/LawFirmBusinessLogic/OfficePackage/HelperModels/WordInfo.cs new file mode 100644 index 0000000..0d6bc60 --- /dev/null +++ b/LawFirm/LawFirmBusinessLogic/OfficePackage/HelperModels/WordInfo.cs @@ -0,0 +1,16 @@ +using LawFirmContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace LawFirmBusinessLogic.OfficePackage.HelperModels +{ + public class WordInfo + { + public string FileName { get; set; } = string.Empty; + public string Title { get; set; } = string.Empty; + public List Blanks { get; set; } = new(); + } +} diff --git a/LawFirm/LawFirmBusinessLogic/OfficePackage/HelperModels/WordParagraph.cs b/LawFirm/LawFirmBusinessLogic/OfficePackage/HelperModels/WordParagraph.cs new file mode 100644 index 0000000..8579247 --- /dev/null +++ b/LawFirm/LawFirmBusinessLogic/OfficePackage/HelperModels/WordParagraph.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace LawFirmBusinessLogic.OfficePackage.HelperModels +{ + public class WordParagraph + { + public List<(string, WordTextProperties)> Texts { get; set; } = new(); + public WordTextProperties? TextProperties { get; set; } + } +} diff --git a/LawFirm/LawFirmBusinessLogic/OfficePackage/HelperModels/WordTextProperties.cs b/LawFirm/LawFirmBusinessLogic/OfficePackage/HelperModels/WordTextProperties.cs new file mode 100644 index 0000000..18fdf27 --- /dev/null +++ b/LawFirm/LawFirmBusinessLogic/OfficePackage/HelperModels/WordTextProperties.cs @@ -0,0 +1,17 @@ +using LawFirmBusinessLogic.OfficePackage.HelperEnums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace LawFirmBusinessLogic.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/LawFirm/LawFirmContracts/BindingModels/ReportBindingModel.cs b/LawFirm/LawFirmContracts/BindingModels/ReportBindingModel.cs new file mode 100644 index 0000000..5468588 --- /dev/null +++ b/LawFirm/LawFirmContracts/BindingModels/ReportBindingModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace LawFirmContracts.BindingModels +{ + public class ReportBindingModel + { + public string FileName { get; set; } = string.Empty; + public DateTime? DateFrom { get; set; } + public DateTime? DateTo { get; set; } + } +} diff --git a/LawFirm/LawFirmContracts/BusinessLogicContracts/IReportLogic.cs b/LawFirm/LawFirmContracts/BusinessLogicContracts/IReportLogic.cs new file mode 100644 index 0000000..f150ca4 --- /dev/null +++ b/LawFirm/LawFirmContracts/BusinessLogicContracts/IReportLogic.cs @@ -0,0 +1,24 @@ +using LawFirmContracts.BindingModels; +using LawFirmContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace LawFirmContracts.BusinessLogicContracts +{ + public interface IReportLogic + { + /// Получение списка компонент с указанием, в каких изделиях используются + List GetProductComponent(); + /// Получение списка заказов за определенный период + List GetOrders(ReportBindingModel model); + /// Сохранение компонент в файл-Word + void SaveComponentsToWordFile(ReportBindingModel model); + /// Сохранение компонент с указаеним продуктов в файл-Excel + void SaveProductComponentToExcelFile(ReportBindingModel model); + /// Сохранение заказов в файл-Pdf + void SaveOrdersToPdfFile(ReportBindingModel model); + } +} diff --git a/LawFirm/LawFirmContracts/SearchModels/OrderSearchModel.cs b/LawFirm/LawFirmContracts/SearchModels/OrderSearchModel.cs index 5f67a66..4578d42 100644 --- a/LawFirm/LawFirmContracts/SearchModels/OrderSearchModel.cs +++ b/LawFirm/LawFirmContracts/SearchModels/OrderSearchModel.cs @@ -9,6 +9,7 @@ namespace LawFirmContracts.SearchModels public class OrderSearchModel { public int? Id { get; set; } - + public DateTime? DateFrom { get; set; } + public DateTime? DateTo { get; set; } } } diff --git a/LawFirm/LawFirmContracts/ViewModels/ReportDocumentBlankViewModel.cs b/LawFirm/LawFirmContracts/ViewModels/ReportDocumentBlankViewModel.cs new file mode 100644 index 0000000..a494117 --- /dev/null +++ b/LawFirm/LawFirmContracts/ViewModels/ReportDocumentBlankViewModel.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace LawFirmContracts.ViewModels +{ + public class ReportDocumentBlankViewModel + { + public string BlankName { get; set; } = string.Empty; + public int TotalCount { get; set; } + public List<(string Document, int Count)> Documents { get; set; } = new(); + + } +} diff --git a/LawFirm/LawFirmContracts/ViewModels/ReportOrdersViewModel.cs b/LawFirm/LawFirmContracts/ViewModels/ReportOrdersViewModel.cs new file mode 100644 index 0000000..8d1918c --- /dev/null +++ b/LawFirm/LawFirmContracts/ViewModels/ReportOrdersViewModel.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace LawFirmContracts.ViewModels +{ + public class ReportOrdersViewModel + { + public int Id { get; set; } + public DateTime DateCreate { get; set; } + public string DocumentName { get; set; } = string.Empty; + public double Sum { get; set; } + } +} -- 2.25.1 From 90050520d86ae5b66109bdc5f843f9bac522850f Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Sat, 11 Mar 2023 13:59:30 +0400 Subject: [PATCH 02/16] =?UTF-8?q?=D0=A0=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7?= =?UTF-8?q?=D0=B0=D1=86=D0=B8=D0=B8=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D1=8B?= =?UTF-8?q?=20=D1=81=20=D0=BE=D1=84=D0=B8=D1=81=D0=BD=D1=8B=D0=BC=D0=B8=20?= =?UTF-8?q?=D0=BF=D0=B0=D0=BA=D0=B5=D1=82=D0=B0=D0=BC=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../LawFirmBusinessLogic.csproj | 2 + .../OfficePackage/Implements/SaveToExcel.cs | 313 ++++++++++++++++++ .../OfficePackage/Implements/SaveToPdf.cs | 96 ++++++ .../OfficePackage/Implements/SaveToWord.cs | 116 +++++++ 4 files changed, 527 insertions(+) create mode 100644 LawFirm/LawFirmBusinessLogic/OfficePackage/Implements/SaveToExcel.cs create mode 100644 LawFirm/LawFirmBusinessLogic/OfficePackage/Implements/SaveToPdf.cs create mode 100644 LawFirm/LawFirmBusinessLogic/OfficePackage/Implements/SaveToWord.cs diff --git a/LawFirm/LawFirmBusinessLogic/LawFirmBusinessLogic.csproj b/LawFirm/LawFirmBusinessLogic/LawFirmBusinessLogic.csproj index 8b32af9..8daf646 100644 --- a/LawFirm/LawFirmBusinessLogic/LawFirmBusinessLogic.csproj +++ b/LawFirm/LawFirmBusinessLogic/LawFirmBusinessLogic.csproj @@ -7,8 +7,10 @@ + + diff --git a/LawFirm/LawFirmBusinessLogic/OfficePackage/Implements/SaveToExcel.cs b/LawFirm/LawFirmBusinessLogic/OfficePackage/Implements/SaveToExcel.cs new file mode 100644 index 0000000..8939900 --- /dev/null +++ b/LawFirm/LawFirmBusinessLogic/OfficePackage/Implements/SaveToExcel.cs @@ -0,0 +1,313 @@ +using DocumentFormat.OpenXml.Office2010.Excel; +using DocumentFormat.OpenXml.Office2013.Excel; +using DocumentFormat.OpenXml; +using DocumentFormat.OpenXml.Packaging; +using DocumentFormat.OpenXml.Spreadsheet; +using LawFirmBusinessLogic.OfficePackage.HelperEnums; +using LawFirmBusinessLogic.OfficePackage.HelperModels; + +namespace LawFirmBusinessLogic.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.Close(); + } + + } +} diff --git a/LawFirm/LawFirmBusinessLogic/OfficePackage/Implements/SaveToPdf.cs b/LawFirm/LawFirmBusinessLogic/OfficePackage/Implements/SaveToPdf.cs new file mode 100644 index 0000000..c69df23 --- /dev/null +++ b/LawFirm/LawFirmBusinessLogic/OfficePackage/Implements/SaveToPdf.cs @@ -0,0 +1,96 @@ +using LawFirmBusinessLogic.OfficePackage.HelperEnums; +using LawFirmBusinessLogic.OfficePackage.HelperModels; +using MigraDoc.DocumentObjectModel; +using MigraDoc.Rendering; +using MigraDoc.DocumentObjectModel.Tables; + +namespace LawFirmBusinessLogic.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); + } + } +} diff --git a/LawFirm/LawFirmBusinessLogic/OfficePackage/Implements/SaveToWord.cs b/LawFirm/LawFirmBusinessLogic/OfficePackage/Implements/SaveToWord.cs new file mode 100644 index 0000000..b9dbbf2 --- /dev/null +++ b/LawFirm/LawFirmBusinessLogic/OfficePackage/Implements/SaveToWord.cs @@ -0,0 +1,116 @@ +using DocumentFormat.OpenXml; +using DocumentFormat.OpenXml.Packaging; +using DocumentFormat.OpenXml.Wordprocessing; +using LawFirmBusinessLogic.OfficePackage.HelperEnums; +using LawFirmBusinessLogic.OfficePackage.HelperModels; +using Text = DocumentFormat.OpenXml.Wordprocessing.Text; + +namespace LawFirmBusinessLogic.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.Close(); + } + } +} -- 2.25.1 From 17214cd823811ef8baf8599935adcff0f1867dd6 Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Sat, 11 Mar 2023 14:11:03 +0400 Subject: [PATCH 03/16] =?UTF-8?q?=D0=9B=D0=BE=D0=B3=D0=B8=D0=BA=D0=B0=20?= =?UTF-8?q?=D0=BE=D1=82=D1=87=D0=B5=D1=82=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/ReportLogic.cs | 110 ++++++++++++++++++ .../OfficePackage/AbstractSaveToExcel.cs | 2 +- .../OfficePackage/HelperModels/ExcelInfo.cs | 2 +- 3 files changed, 112 insertions(+), 2 deletions(-) create mode 100644 LawFirm/LawFirmBusinessLogic/BusinessLogics/ReportLogic.cs diff --git a/LawFirm/LawFirmBusinessLogic/BusinessLogics/ReportLogic.cs b/LawFirm/LawFirmBusinessLogic/BusinessLogics/ReportLogic.cs new file mode 100644 index 0000000..702c5e6 --- /dev/null +++ b/LawFirm/LawFirmBusinessLogic/BusinessLogics/ReportLogic.cs @@ -0,0 +1,110 @@ +using LawFirmBusinessLogic.OfficePackage; +using LawFirmBusinessLogic.OfficePackage.HelperModels; +using LawFirmContracts.BindingModels; +using LawFirmContracts.BusinessLogicContracts; +using LawFirmContracts.SearchModels; +using LawFirmContracts.StorageContracts; +using LawFirmContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace LawFirmBusinessLogic.BusinessLogics +{ + public class ReportLogic : IReportLogic + { + private readonly IBlankStorage _blankStorage; + private readonly IDocumentStorage _documentStorage; + private readonly IOrderStorage _orderStorage; + private readonly AbstractSaveToExcel _saveToExcel; + private readonly AbstractSaveToWord _saveToWord; + private readonly AbstractSaveToPdf _saveToPdf; + public ReportLogic(IDocumentStorage documentStorage, IBlankStorage blankStorage, IOrderStorage orderStorage, AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf) + { + _documentStorage = documentStorage; + _blankStorage = blankStorage; + _orderStorage = orderStorage; + _saveToExcel = saveToExcel; + _saveToWord = saveToWord; + _saveToPdf = saveToPdf; + } + /// Получение списка компонент с указанием, в каких изделиях используются + public List GetProductComponent() + { + var blanks = _blankStorage.GetFullList(); + var documents = _documentStorage.GetFullList(); + var list = new List(); + foreach (var blank in blanks) + { + var record = new ReportDocumentBlankViewModel + { + BlankName = blank.BlankName, + Documents = new List<(string Document, int Count)>(), + TotalCount = 0 + }; + foreach (var document in documents) + { + if (document.DocumentBlanks.ContainsKey(blank.Id)) + { + record.Documents.Add((document.DocumentName, document.DocumentBlanks[blank.Id].Item2)); + record.TotalCount += document.DocumentBlanks[blank.Id].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, + DocumentName = x.DocumentName, + Sum = x.Sum + }) + .ToList(); + } + /// Сохранение компонент в файл-Word + public void SaveComponentsToWordFile(ReportBindingModel model) + { + _saveToWord.CreateDoc(new WordInfo + { + FileName = model.FileName, + Title = "Список бланков", + Blanks = _blankStorage.GetFullList() + }); + } + /// Сохранение компонент с указаеним продуктов в файл-Excel + public void SaveProductComponentToExcelFile(ReportBindingModel model) + { + _saveToExcel.CreateReport(new ExcelInfo + { + FileName = model.FileName, + Title = "Список бланков", + DocumentBlanks = GetProductComponent() + }); + } + /// Сохранение заказов в файл-Pdf + public void SaveOrdersToPdfFile(ReportBindingModel model) + { + _saveToPdf.CreateDoc(new PdfInfo + { + FileName = model.FileName, + Title = "Список заказов", + DateFrom = model.DateFrom!.Value, + DateTo = model.DateTo!.Value, + Orders = GetOrders(model) + }); + } + + } +} diff --git a/LawFirm/LawFirmBusinessLogic/OfficePackage/AbstractSaveToExcel.cs b/LawFirm/LawFirmBusinessLogic/OfficePackage/AbstractSaveToExcel.cs index 116efbb..b7c3900 100644 --- a/LawFirm/LawFirmBusinessLogic/OfficePackage/AbstractSaveToExcel.cs +++ b/LawFirm/LawFirmBusinessLogic/OfficePackage/AbstractSaveToExcel.cs @@ -27,7 +27,7 @@ namespace LawFirmBusinessLogic.OfficePackage CellToName = "C1" }); uint rowIndex = 2; - foreach (var pc in info.ProductComponents) + foreach (var pc in info.DocumentBlanks) { InsertCellInWorksheet(new ExcelCellParameters { diff --git a/LawFirm/LawFirmBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs b/LawFirm/LawFirmBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs index 2394be4..f682fa1 100644 --- a/LawFirm/LawFirmBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs +++ b/LawFirm/LawFirmBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs @@ -11,6 +11,6 @@ namespace LawFirmBusinessLogic.OfficePackage.HelperModels { public string FileName { get; set; } = string.Empty; public string Title { get; set; } = string.Empty; - public List ProductComponents { get; set; } = new(); + public List DocumentBlanks { get; set; } = new(); } } -- 2.25.1 From 8b75f5305a214a4b36843fbc524bbf63c8375075 Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Sat, 11 Mar 2023 14:29:44 +0400 Subject: [PATCH 04/16] =?UTF-8?q?=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD?= =?UTF-8?q?=D0=B0=20=D1=84=D0=BE=D1=80=D0=BC=D0=B0=20=D0=BE=D1=82=D1=87?= =?UTF-8?q?=D0=B5=D1=82=D0=B0=20"=D0=B1=D0=BB=D0=B0=D0=BD=D0=BA=D0=B8=20?= =?UTF-8?q?=D0=BF=D0=BE=20=D0=B4=D0=BE=D0=BA=D1=83=D0=BC=D0=B5=D0=BD=D1=82?= =?UTF-8?q?=D0=B0=D0=BC"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LawFirm/LawFirm/FormMain.Designer.cs | 40 ++++++- LawFirm/LawFirm/FormMain.cs | 11 ++ .../FormReportDocumentBlanks.Designer.cs | 110 ++++++++++++++++++ LawFirm/LawFirm/FormReportDocumentBlanks.cs | 85 ++++++++++++++ LawFirm/LawFirm/FormReportDocumentBlanks.resx | 78 +++++++++++++ LawFirm/LawFirm/Program.cs | 8 ++ 6 files changed, 331 insertions(+), 1 deletion(-) create mode 100644 LawFirm/LawFirm/FormReportDocumentBlanks.Designer.cs create mode 100644 LawFirm/LawFirm/FormReportDocumentBlanks.cs create mode 100644 LawFirm/LawFirm/FormReportDocumentBlanks.resx diff --git a/LawFirm/LawFirm/FormMain.Designer.cs b/LawFirm/LawFirm/FormMain.Designer.cs index 824ad60..ce67498 100644 --- a/LawFirm/LawFirm/FormMain.Designer.cs +++ b/LawFirm/LawFirm/FormMain.Designer.cs @@ -38,6 +38,10 @@ this.buttonSetToDone = new System.Windows.Forms.Button(); this.buttonSetToFinish = new System.Windows.Forms.Button(); this.buttonUpdate = new System.Windows.Forms.Button(); + this.отчетыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.списокБланковToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.бланкиПоДокументамToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.списокЗаказовToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.menuStrip.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); this.SuspendLayout(); @@ -46,7 +50,8 @@ // this.menuStrip.ImageScalingSize = new System.Drawing.Size(20, 20); this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.справочникиToolStripMenuItem}); + this.справочникиToolStripMenuItem, + this.отчетыToolStripMenuItem}); this.menuStrip.Location = new System.Drawing.Point(0, 0); this.menuStrip.Name = "menuStrip"; this.menuStrip.Size = new System.Drawing.Size(1139, 28); @@ -136,6 +141,35 @@ this.buttonUpdate.UseVisualStyleBackColor = true; this.buttonUpdate.Click += new System.EventHandler(this.buttonUpdate_Click); // + // отчетыToolStripMenuItem + // + this.отчетыToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.списокБланковToolStripMenuItem, + this.бланкиПоДокументамToolStripMenuItem, + this.списокЗаказовToolStripMenuItem}); + this.отчетыToolStripMenuItem.Name = "отчетыToolStripMenuItem"; + this.отчетыToolStripMenuItem.Size = new System.Drawing.Size(73, 24); + this.отчетыToolStripMenuItem.Text = "Отчеты"; + // + // списокБланковToolStripMenuItem + // + this.списокБланковToolStripMenuItem.Name = "списокБланковToolStripMenuItem"; + this.списокБланковToolStripMenuItem.Size = new System.Drawing.Size(252, 26); + this.списокБланковToolStripMenuItem.Text = "Список бланков"; + // + // бланкиПоДокументамToolStripMenuItem + // + this.бланкиПоДокументамToolStripMenuItem.Name = "бланкиПоДокументамToolStripMenuItem"; + this.бланкиПоДокументамToolStripMenuItem.Size = new System.Drawing.Size(252, 26); + this.бланкиПоДокументамToolStripMenuItem.Text = "Бланки по документам"; + this.бланкиПоДокументамToolStripMenuItem.Click += new System.EventHandler(this.бланкиПоДокументамToolStripMenuItem_Click); + // + // списокЗаказовToolStripMenuItem + // + this.списокЗаказовToolStripMenuItem.Name = "списокЗаказовToolStripMenuItem"; + this.списокЗаказовToolStripMenuItem.Size = new System.Drawing.Size(252, 26); + this.списокЗаказовToolStripMenuItem.Text = "Список заказов"; + // // FormMain // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); @@ -172,5 +206,9 @@ private Button buttonSetToDone; private Button buttonSetToFinish; private Button buttonUpdate; + private ToolStripMenuItem отчетыToolStripMenuItem; + private ToolStripMenuItem списокБланковToolStripMenuItem; + private ToolStripMenuItem бланкиПоДокументамToolStripMenuItem; + private ToolStripMenuItem списокЗаказовToolStripMenuItem; } } \ No newline at end of file diff --git a/LawFirm/LawFirm/FormMain.cs b/LawFirm/LawFirm/FormMain.cs index 7c21f6a..b1d6aa1 100644 --- a/LawFirm/LawFirm/FormMain.cs +++ b/LawFirm/LawFirm/FormMain.cs @@ -69,6 +69,15 @@ namespace LawFirmView } } + private void бланкиПоДокументамToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormReportDocumentBlanks)); + if (service is FormReportDocumentBlanks form) + { + form.ShowDialog(); + } + } + private void buttonCreateOrder_Click(object sender, EventArgs e) { var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); @@ -163,5 +172,7 @@ namespace LawFirmView { LoadData(); } + + } } diff --git a/LawFirm/LawFirm/FormReportDocumentBlanks.Designer.cs b/LawFirm/LawFirm/FormReportDocumentBlanks.Designer.cs new file mode 100644 index 0000000..ba07a69 --- /dev/null +++ b/LawFirm/LawFirm/FormReportDocumentBlanks.Designer.cs @@ -0,0 +1,110 @@ +namespace LawFirmView +{ + partial class FormReportDocumentBlanks + { + /// + /// 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.dataGridView = new System.Windows.Forms.DataGridView(); + this.Blank = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.Document = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.Count = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.buttonSaveToExcel = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // dataGridView + // + this.dataGridView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.Blank, + this.Document, + this.Count}); + this.dataGridView.Location = new System.Drawing.Point(12, 37); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(776, 401); + this.dataGridView.TabIndex = 0; + // + // Blank + // + this.Blank.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; + this.Blank.HeaderText = "Бланк"; + this.Blank.MinimumWidth = 6; + this.Blank.Name = "Blank"; + // + // Document + // + this.Document.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; + this.Document.HeaderText = "Документ"; + this.Document.MinimumWidth = 6; + this.Document.Name = "Document"; + // + // Count + // + this.Count.HeaderText = "Количество"; + this.Count.MinimumWidth = 6; + this.Count.Name = "Count"; + this.Count.Width = 125; + // + // buttonSaveToExcel + // + this.buttonSaveToExcel.Location = new System.Drawing.Point(12, 2); + this.buttonSaveToExcel.Name = "buttonSaveToExcel"; + this.buttonSaveToExcel.Size = new System.Drawing.Size(220, 29); + this.buttonSaveToExcel.TabIndex = 1; + this.buttonSaveToExcel.Text = "Сохранить в Excel"; + this.buttonSaveToExcel.UseVisualStyleBackColor = true; + this.buttonSaveToExcel.Click += new System.EventHandler(this.buttonSaveToExcel_Click); + // + // FormReportDocumentBlanks + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.buttonSaveToExcel); + this.Controls.Add(this.dataGridView); + this.Name = "FormReportDocumentBlanks"; + this.Text = "Бланки по документам"; + this.Load += new System.EventHandler(this.FormReportDocumentBlanks_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView dataGridView; + private DataGridViewTextBoxColumn Blank; + private DataGridViewTextBoxColumn Document; + private DataGridViewTextBoxColumn Count; + private Button buttonSaveToExcel; + } +} \ No newline at end of file diff --git a/LawFirm/LawFirm/FormReportDocumentBlanks.cs b/LawFirm/LawFirm/FormReportDocumentBlanks.cs new file mode 100644 index 0000000..551d9d5 --- /dev/null +++ b/LawFirm/LawFirm/FormReportDocumentBlanks.cs @@ -0,0 +1,85 @@ +using LawFirmContracts.BindingModels; +using LawFirmContracts.BusinessLogicContracts; +using Microsoft.Extensions.Logging; +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 LawFirmView +{ + public partial class FormReportDocumentBlanks : Form + { + private readonly ILogger _logger; + private readonly IReportLogic _logic; + + public FormReportDocumentBlanks(ILogger logger, IReportLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormReportDocumentBlanks_Load(object sender, EventArgs e) + { + try + { + var dict = _logic.GetProductComponent(); + if (dict != null) + { + dataGridView.Rows.Clear(); + foreach (var elem in dict) + { + dataGridView.Rows.Add(new object[] { elem.BlankName, "", "" }); + foreach (var listElem in elem.Documents) + { + 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); + } + } + } + } +} diff --git a/LawFirm/LawFirm/FormReportDocumentBlanks.resx b/LawFirm/LawFirm/FormReportDocumentBlanks.resx new file mode 100644 index 0000000..0908e41 --- /dev/null +++ b/LawFirm/LawFirm/FormReportDocumentBlanks.resx @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + True + + + True + + + True + + + True + + + True + + + True + + \ No newline at end of file diff --git a/LawFirm/LawFirm/Program.cs b/LawFirm/LawFirm/Program.cs index 8babc23..70ca19c 100644 --- a/LawFirm/LawFirm/Program.cs +++ b/LawFirm/LawFirm/Program.cs @@ -1,4 +1,6 @@ using LawFirmBusinessLogic.BusinessLogics; +using LawFirmBusinessLogic.OfficePackage; +using LawFirmBusinessLogic.OfficePackage.Implements; using LawFirmContracts.BusinessLogicContracts; using LawFirmContracts.StorageContracts; using LawFirmDatabaseImplement.Implements; @@ -45,6 +47,11 @@ namespace LawFirm services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -53,6 +60,7 @@ namespace LawFirm services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); } } -- 2.25.1 From 1023239b77fce38058f1bbdfa810561bbb0c9ea2 Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Sat, 11 Mar 2023 17:17:29 +0400 Subject: [PATCH 05/16] =?UTF-8?q?=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD?= =?UTF-8?q?=D0=B0=20=D0=B2=D1=82=D0=BE=D1=80=D0=B0=D1=8F=20=D1=84=D0=BE?= =?UTF-8?q?=D1=80=D0=BC=D0=B0=20=D0=BE=D1=82=D1=87=D0=B5=D1=82=D0=B0,=20?= =?UTF-8?q?=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD=D0=B0=20=D0=BB=D0=BE?= =?UTF-8?q?=D0=B3=D0=B8=D0=BA=D0=B0=20=D1=85=D1=80=D0=B0=D0=BD=D0=B8=D0=BB?= =?UTF-8?q?=D0=B8=D1=89=D0=B0=20=D0=B7=D0=B0=D0=BA=D0=B0=D0=B7=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LawFirm/LawFirm/FormMain.Designer.cs | 67 +-- LawFirm/LawFirm/FormMain.cs | 9 + LawFirm/LawFirm/FormReportOrder.Designer.cs | 131 +++++ LawFirm/LawFirm/FormReportOrder.cs | 96 ++++ LawFirm/LawFirm/FormReportOrder.resx | 60 ++ LawFirm/LawFirm/LawFirmView.csproj | 1 + LawFirm/LawFirm/Program.cs | 1 + LawFirm/LawFirm/ReportOrders.rdlc | 529 ++++++++++++++++++ .../Implements/OrderStorage.cs | 4 +- .../Implements/OrderStorage.cs | 8 +- .../Implements/OrderStorage.cs | 6 +- 11 files changed, 868 insertions(+), 44 deletions(-) create mode 100644 LawFirm/LawFirm/FormReportOrder.Designer.cs create mode 100644 LawFirm/LawFirm/FormReportOrder.cs create mode 100644 LawFirm/LawFirm/FormReportOrder.resx create mode 100644 LawFirm/LawFirm/ReportOrders.rdlc diff --git a/LawFirm/LawFirm/FormMain.Designer.cs b/LawFirm/LawFirm/FormMain.Designer.cs index ce67498..3c8895e 100644 --- a/LawFirm/LawFirm/FormMain.Designer.cs +++ b/LawFirm/LawFirm/FormMain.Designer.cs @@ -32,16 +32,16 @@ this.справочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.бланкиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.документыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.отчетыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.списокБланковToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.бланкиПоДокументамToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.списокЗаказовToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.dataGridView = new System.Windows.Forms.DataGridView(); this.buttonCreateOrder = new System.Windows.Forms.Button(); this.buttonSetToWork = new System.Windows.Forms.Button(); this.buttonSetToDone = new System.Windows.Forms.Button(); this.buttonSetToFinish = new System.Windows.Forms.Button(); this.buttonUpdate = new System.Windows.Forms.Button(); - this.отчетыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.списокБланковToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.бланкиПоДокументамToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.списокЗаказовToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.menuStrip.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); this.SuspendLayout(); @@ -81,6 +81,36 @@ this.документыToolStripMenuItem.Text = "Документы"; this.документыToolStripMenuItem.Click += new System.EventHandler(this.документыToolStripMenuItem_Click); // + // отчетыToolStripMenuItem + // + this.отчетыToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.списокБланковToolStripMenuItem, + this.бланкиПоДокументамToolStripMenuItem, + this.списокЗаказовToolStripMenuItem}); + this.отчетыToolStripMenuItem.Name = "отчетыToolStripMenuItem"; + this.отчетыToolStripMenuItem.Size = new System.Drawing.Size(73, 24); + this.отчетыToolStripMenuItem.Text = "Отчеты"; + // + // списокБланковToolStripMenuItem + // + this.списокБланковToolStripMenuItem.Name = "списокБланковToolStripMenuItem"; + this.списокБланковToolStripMenuItem.Size = new System.Drawing.Size(252, 26); + this.списокБланковToolStripMenuItem.Text = "Список бланков"; + // + // бланкиПоДокументамToolStripMenuItem + // + this.бланкиПоДокументамToolStripMenuItem.Name = "бланкиПоДокументамToolStripMenuItem"; + this.бланкиПоДокументамToolStripMenuItem.Size = new System.Drawing.Size(252, 26); + this.бланкиПоДокументамToolStripMenuItem.Text = "Бланки по документам"; + this.бланкиПоДокументамToolStripMenuItem.Click += new System.EventHandler(this.бланкиПоДокументамToolStripMenuItem_Click); + // + // списокЗаказовToolStripMenuItem + // + this.списокЗаказовToolStripMenuItem.Name = "списокЗаказовToolStripMenuItem"; + this.списокЗаказовToolStripMenuItem.Size = new System.Drawing.Size(252, 26); + this.списокЗаказовToolStripMenuItem.Text = "Список заказов"; + this.списокЗаказовToolStripMenuItem.Click += new System.EventHandler(this.списокЗаказовToolStripMenuItem_Click); + // // dataGridView // this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; @@ -141,35 +171,6 @@ this.buttonUpdate.UseVisualStyleBackColor = true; this.buttonUpdate.Click += new System.EventHandler(this.buttonUpdate_Click); // - // отчетыToolStripMenuItem - // - this.отчетыToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.списокБланковToolStripMenuItem, - this.бланкиПоДокументамToolStripMenuItem, - this.списокЗаказовToolStripMenuItem}); - this.отчетыToolStripMenuItem.Name = "отчетыToolStripMenuItem"; - this.отчетыToolStripMenuItem.Size = new System.Drawing.Size(73, 24); - this.отчетыToolStripMenuItem.Text = "Отчеты"; - // - // списокБланковToolStripMenuItem - // - this.списокБланковToolStripMenuItem.Name = "списокБланковToolStripMenuItem"; - this.списокБланковToolStripMenuItem.Size = new System.Drawing.Size(252, 26); - this.списокБланковToolStripMenuItem.Text = "Список бланков"; - // - // бланкиПоДокументамToolStripMenuItem - // - this.бланкиПоДокументамToolStripMenuItem.Name = "бланкиПоДокументамToolStripMenuItem"; - this.бланкиПоДокументамToolStripMenuItem.Size = new System.Drawing.Size(252, 26); - this.бланкиПоДокументамToolStripMenuItem.Text = "Бланки по документам"; - this.бланкиПоДокументамToolStripMenuItem.Click += new System.EventHandler(this.бланкиПоДокументамToolStripMenuItem_Click); - // - // списокЗаказовToolStripMenuItem - // - this.списокЗаказовToolStripMenuItem.Name = "списокЗаказовToolStripMenuItem"; - this.списокЗаказовToolStripMenuItem.Size = new System.Drawing.Size(252, 26); - this.списокЗаказовToolStripMenuItem.Text = "Список заказов"; - // // FormMain // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); diff --git a/LawFirm/LawFirm/FormMain.cs b/LawFirm/LawFirm/FormMain.cs index b1d6aa1..7455cdc 100644 --- a/LawFirm/LawFirm/FormMain.cs +++ b/LawFirm/LawFirm/FormMain.cs @@ -78,6 +78,15 @@ namespace LawFirmView } } + private void списокЗаказовToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormReportOrder)); + if (service is FormReportOrder form) + { + form.ShowDialog(); + } + } + private void buttonCreateOrder_Click(object sender, EventArgs e) { var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); diff --git a/LawFirm/LawFirm/FormReportOrder.Designer.cs b/LawFirm/LawFirm/FormReportOrder.Designer.cs new file mode 100644 index 0000000..07c497c --- /dev/null +++ b/LawFirm/LawFirm/FormReportOrder.Designer.cs @@ -0,0 +1,131 @@ +namespace LawFirmView +{ + partial class FormReportOrder + { + /// + /// 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.buttonCreateToPdf = new System.Windows.Forms.Button(); + this.buttonCreateReport = new System.Windows.Forms.Button(); + this.label2 = new System.Windows.Forms.Label(); + this.label1 = new System.Windows.Forms.Label(); + this.dateTimePickerEnd = new System.Windows.Forms.DateTimePicker(); + this.dateTimePickerStart = new System.Windows.Forms.DateTimePicker(); + this.panel.SuspendLayout(); + this.SuspendLayout(); + // + // panel + // + this.panel.Controls.Add(this.buttonCreateToPdf); + this.panel.Controls.Add(this.buttonCreateReport); + this.panel.Controls.Add(this.label2); + this.panel.Controls.Add(this.label1); + this.panel.Controls.Add(this.dateTimePickerEnd); + this.panel.Controls.Add(this.dateTimePickerStart); + 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(984, 69); + this.panel.TabIndex = 0; + // + // buttonCreateToPdf + // + this.buttonCreateToPdf.Location = new System.Drawing.Point(782, 39); + this.buttonCreateToPdf.Name = "buttonCreateToPdf"; + this.buttonCreateToPdf.Size = new System.Drawing.Size(190, 27); + this.buttonCreateToPdf.TabIndex = 5; + this.buttonCreateToPdf.Text = "PDF"; + this.buttonCreateToPdf.UseVisualStyleBackColor = true; + this.buttonCreateToPdf.Click += new System.EventHandler(this.buttonCreateToPdf_Click); + // + // buttonCreateReport + // + this.buttonCreateReport.Location = new System.Drawing.Point(554, 39); + this.buttonCreateReport.Name = "buttonCreateReport"; + this.buttonCreateReport.Size = new System.Drawing.Size(190, 27); + this.buttonCreateReport.TabIndex = 4; + this.buttonCreateReport.Text = "Сформировать"; + this.buttonCreateReport.UseVisualStyleBackColor = true; + this.buttonCreateReport.Click += new System.EventHandler(this.buttonCreateReport_Click); + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(369, 9); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(56, 20); + this.label2.TabIndex = 3; + this.label2.Text = "Конец:"; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(87, 6); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(64, 20); + this.label1.TabIndex = 2; + this.label1.Text = "Начало:"; + // + // dateTimePickerEnd + // + this.dateTimePickerEnd.Location = new System.Drawing.Point(307, 39); + this.dateTimePickerEnd.Name = "dateTimePickerEnd"; + this.dateTimePickerEnd.Size = new System.Drawing.Size(187, 27); + this.dateTimePickerEnd.TabIndex = 1; + // + // dateTimePickerStart + // + this.dateTimePickerStart.Location = new System.Drawing.Point(35, 39); + this.dateTimePickerStart.Name = "dateTimePickerStart"; + this.dateTimePickerStart.Size = new System.Drawing.Size(187, 27); + this.dateTimePickerStart.TabIndex = 0; + // + // FormReportOrder + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(984, 450); + this.Controls.Add(this.panel); + this.Name = "FormReportOrder"; + this.Text = "Заказы"; + this.panel.ResumeLayout(false); + this.panel.PerformLayout(); + this.ResumeLayout(false); + + } + + #endregion + + private Panel panel; + private DateTimePicker dateTimePickerEnd; + private DateTimePicker dateTimePickerStart; + private Button buttonCreateToPdf; + private Button buttonCreateReport; + private Label label2; + private Label label1; + } +} \ No newline at end of file diff --git a/LawFirm/LawFirm/FormReportOrder.cs b/LawFirm/LawFirm/FormReportOrder.cs new file mode 100644 index 0000000..3d9046f --- /dev/null +++ b/LawFirm/LawFirm/FormReportOrder.cs @@ -0,0 +1,96 @@ +using LawFirmContracts.BindingModels; +using LawFirmContracts.BusinessLogicContracts; +using Microsoft.Extensions.Logging; +using Microsoft.Reporting.WinForms; + +namespace LawFirmView +{ + public partial class FormReportOrder : Form + { + private readonly ReportViewer reportViewer; + private readonly ILogger _logger; + private readonly IReportLogic _logic; + + public FormReportOrder(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 buttonCreateReport_Click(object sender, EventArgs e) + { + if (dateTimePickerStart.Value.Date >= dateTimePickerEnd.Value.Date) + { + MessageBox.Show("Дата начала должна быть меньше даты окончания", + "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + try + { + var dataSource = _logic.GetOrders(new ReportBindingModel + { + DateFrom = dateTimePickerStart.Value, + DateTo = dateTimePickerEnd.Value + }); + var source = new ReportDataSource("DataSetOrders", dataSource); + reportViewer.LocalReport.DataSources.Clear(); + reportViewer.LocalReport.DataSources.Add(source); + var parameters = new[] { new ReportParameter("ReportParameterPeriod", $"c{ dateTimePickerStart.Value.ToShortDateString()} по {dateTimePickerEnd.Value.ToShortDateString()}") }; + reportViewer.LocalReport.SetParameters(parameters); + reportViewer.RefreshReport(); + _logger.LogInformation("Загрузка списка заказов на период {From}-{ To}", dateTimePickerStart.Value.ToShortDateString(), dateTimePickerEnd.Value.ToShortDateString()); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка заказов на период"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + + } + + private void buttonCreateToPdf_Click(object sender, EventArgs e) + { + if (dateTimePickerStart.Value.Date >= dateTimePickerEnd.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 = dateTimePickerStart.Value, + DateTo = dateTimePickerEnd.Value + }); + _logger.LogInformation("Сохранение списка заказов на период { From} -{ To}", dateTimePickerStart.Value.ToShortDateString(),dateTimePickerEnd.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/LawFirm/LawFirm/FormReportOrder.resx b/LawFirm/LawFirm/FormReportOrder.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/LawFirm/LawFirm/FormReportOrder.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/LawFirm/LawFirm/LawFirmView.csproj b/LawFirm/LawFirm/LawFirmView.csproj index 9d320d6..c75a088 100644 --- a/LawFirm/LawFirm/LawFirmView.csproj +++ b/LawFirm/LawFirm/LawFirmView.csproj @@ -16,6 +16,7 @@ + diff --git a/LawFirm/LawFirm/Program.cs b/LawFirm/LawFirm/Program.cs index 70ca19c..1b5ecce 100644 --- a/LawFirm/LawFirm/Program.cs +++ b/LawFirm/LawFirm/Program.cs @@ -61,6 +61,7 @@ namespace LawFirm services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); } } diff --git a/LawFirm/LawFirm/ReportOrders.rdlc b/LawFirm/LawFirm/ReportOrders.rdlc new file mode 100644 index 0000000..d3766db --- /dev/null +++ b/LawFirm/LawFirm/ReportOrders.rdlc @@ -0,0 +1,529 @@ + + + 0 + + + + System.Data.DataSet + /* Local Connection */ + + 10791c83-cee8-4a38-bbd0-245fc17cefb3 + + + + + + LawFirmContractsViewModels + /* Local Query */ + + + + Id + System.Int32 + + + DateCreate + System.DateTime + + + DocumentName + System.String + + + Sum + System.Decimal + + + + LawFirmContracts.ViewModels + ReportOrdersViewModel + LawFirmContracts.ViewModels.ReportOrdersViewModel, LawFirmContracts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + + + + + + + + + true + true + + + + + =Parameters!ReportParameterPeriod.Value + + + + + + + ReportParameterPeriod + 1cm + 1cm + 21cm + + + Middle + 2pt + 2pt + 2pt + 2pt + + + + true + true + + + + + Заказы + + + + + + + 1cm + 21cm + 1 + + + Middle + 2pt + 2pt + 2pt + 2pt + + + + + + + 2.5cm + + + 3.21438cm + + + 8.23317cm + + + 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 + + + + + + + + 0.6cm + + + + + true + true + + + + + =Fields!Id.Value + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + =Fields!DateCreate.Value + + + + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + =Fields!DocumentName.Value + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + =Fields!Sum.Value + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + + + + + + + + + + + + + After + + + + + + + DataSetOrders + 2.48391cm + 0.55245cm + 1.2cm + 16.44755cm + 2 + + + + + + true + true + + + + + Итого: + + + + + + + 4cm + 12cm + 0.6cm + 2.5cm + 3 + + + 2pt + 2pt + 2pt + 2pt + + + + true + true + + + + + =Sum(Fields!Sum.Value, "DataSetOrders") + + + + + + + 4cm + 14.5cm + 0.6cm + 2.5cm + 4 + + + 2pt + 2pt + 2pt + 2pt + + + + 5.72875cm + + + + + + 2pt + 2pt + 2pt + 2pt + + + true + + @@ -387,6 +427,36 @@ + + + + true + true + + + + + =Fields!Status.Value + + + 2pt + 2pt + 2pt + 2pt + + + + @@ -397,6 +467,7 @@ + @@ -413,7 +484,7 @@ 2.48391cm 0.55245cm 1.2cm - 16.44755cm + 18.94755cm 2 - true -- 2.25.1 From 65daaa324ba67023663e0dd6f95832f0f6951ecd Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Mon, 13 Mar 2023 09:52:00 +0400 Subject: [PATCH 10/16] =?UTF-8?q?=D0=A1=D0=B4=D0=B0=D0=BD=D0=B0=20=D0=BB?= =?UTF-8?q?=D0=B0=D0=B14?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../OfficePackage/Implements/SaveToExcel.cs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/LawFirm/LawFirmBusinessLogic/OfficePackage/Implements/SaveToExcel.cs b/LawFirm/LawFirmBusinessLogic/OfficePackage/Implements/SaveToExcel.cs index 8939900..f6088a9 100644 --- a/LawFirm/LawFirmBusinessLogic/OfficePackage/Implements/SaveToExcel.cs +++ b/LawFirm/LawFirmBusinessLogic/OfficePackage/Implements/SaveToExcel.cs @@ -22,16 +22,14 @@ namespace LawFirmBusinessLogic.OfficePackage.Implements 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 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 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 }); @@ -125,15 +123,15 @@ namespace LawFirmBusinessLogic.OfficePackage.Implements }; cellFormats.Append(cellFormatFont); cellFormats.Append(cellFormatFontAndBorder); - cellFormats.Append(cellFormatTitle); var cellStyles = new CellStyles() { Count = 1U }; + 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 differentialFormats = new DocumentFormat.OpenXml.Office2013.Excel.DifferentialFormats(){ Count = 0U }; var tableStyles = new TableStyles() { -- 2.25.1 From 8a60e580e89a18cc659f174187430a703ba52d07 Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Sun, 26 Mar 2023 20:48:57 +0400 Subject: [PATCH 11/16] fix --- LawFirm/LawFirm/Program.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/LawFirm/LawFirm/Program.cs b/LawFirm/LawFirm/Program.cs index 4b5846f..011ff2e 100644 --- a/LawFirm/LawFirm/Program.cs +++ b/LawFirm/LawFirm/Program.cs @@ -61,13 +61,13 @@ namespace LawFirm services.AddTransient(); services.AddTransient(); services.AddTransient(); - } - - } -} - } -} services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + } + + } +} -- 2.25.1 From 9a7407f156d197c79da5c9802bc5608225e6085c Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Sun, 26 Mar 2023 21:03:24 +0400 Subject: [PATCH 12/16] =?UTF-8?q?=D0=9E=D1=82=D1=87=D0=B5=D1=82=20=D1=81?= =?UTF-8?q?=D0=BF=D0=B8=D1=81=D0=BA=D0=B0=20=D0=BC=D0=B0=D0=B3=D0=B0=D0=B7?= =?UTF-8?q?=D0=B8=D0=BD=D0=BE=D0=B2=20=D0=B2=20word=20=D1=84=D0=B0=D0=B9?= =?UTF-8?q?=D0=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LawFirm/LawFirm/FormMain.Designer.cs | 28 ++++--- LawFirm/LawFirm/FormMain.cs | 13 +++ .../BusinessLogics/ReportLogic.cs | 14 +++- .../OfficePackage/AbstractSaveToWord.cs | 27 +++++++ .../OfficePackage/HelperModels/WordInfo.cs | 1 + .../OfficePackage/HelperModels/WordTable.cs | 14 ++++ .../OfficePackage/Implements/SaveToWord.cs | 81 +++++++++++++++++++ .../BusinessLogicContracts/IReportLogic.cs | 2 + 8 files changed, 170 insertions(+), 10 deletions(-) create mode 100644 LawFirm/LawFirmBusinessLogic/OfficePackage/HelperModels/WordTable.cs diff --git a/LawFirm/LawFirm/FormMain.Designer.cs b/LawFirm/LawFirm/FormMain.Designer.cs index 2df0926..e9caa6d 100644 --- a/LawFirm/LawFirm/FormMain.Designer.cs +++ b/LawFirm/LawFirm/FormMain.Designer.cs @@ -32,11 +32,11 @@ this.справочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.бланкиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.документыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.магазиныToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.отчетыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.списокДокументовToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.бланкиПоДокументамToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.списокЗаказовToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.магазиныToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.dataGridView = new System.Windows.Forms.DataGridView(); this.buttonCreateOrder = new System.Windows.Forms.Button(); this.buttonSetToWork = new System.Windows.Forms.Button(); @@ -45,6 +45,7 @@ this.buttonUpdate = new System.Windows.Forms.Button(); this.buttonSupplyShop = new System.Windows.Forms.Button(); this.buttonSellDocuments = new System.Windows.Forms.Button(); + this.списокМагазиновToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.menuStrip.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); this.SuspendLayout(); @@ -85,12 +86,20 @@ this.документыToolStripMenuItem.Text = "Документы"; this.документыToolStripMenuItem.Click += new System.EventHandler(this.документыToolStripMenuItem_Click); // + // магазиныToolStripMenuItem + // + this.магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem"; + this.магазиныToolStripMenuItem.Size = new System.Drawing.Size(170, 26); + this.магазиныToolStripMenuItem.Text = "Магазины"; + this.магазиныToolStripMenuItem.Click += new System.EventHandler(this.магазиныToolStripMenuItem_Click); + // // отчетыToolStripMenuItem // this.отчетыToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.списокДокументовToolStripMenuItem, this.бланкиПоДокументамToolStripMenuItem, - this.списокЗаказовToolStripMenuItem}); + this.списокЗаказовToolStripMenuItem, + this.списокМагазиновToolStripMenuItem}); this.отчетыToolStripMenuItem.Name = "отчетыToolStripMenuItem"; this.отчетыToolStripMenuItem.Size = new System.Drawing.Size(73, 24); this.отчетыToolStripMenuItem.Text = "Отчеты"; @@ -116,13 +125,6 @@ this.списокЗаказовToolStripMenuItem.Text = "Список заказов"; this.списокЗаказовToolStripMenuItem.Click += new System.EventHandler(this.списокЗаказовToolStripMenuItem_Click); // - // магазиныToolStripMenuItem - // - this.магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem"; - this.магазиныToolStripMenuItem.Size = new System.Drawing.Size(170, 26); - this.магазиныToolStripMenuItem.Text = "Магазины"; - this.магазиныToolStripMenuItem.Click += new System.EventHandler(this.магазиныToolStripMenuItem_Click); - // // dataGridView // this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; @@ -203,6 +205,13 @@ this.buttonSellDocuments.UseVisualStyleBackColor = true; this.buttonSellDocuments.Click += new System.EventHandler(this.buttonSellDocuments_Click); // + // списокМагазиновToolStripMenuItem + // + this.списокМагазиновToolStripMenuItem.Name = "списокМагазиновToolStripMenuItem"; + this.списокМагазиновToolStripMenuItem.Size = new System.Drawing.Size(252, 26); + this.списокМагазиновToolStripMenuItem.Text = "Список магазинов"; + this.списокМагазиновToolStripMenuItem.Click += new System.EventHandler(this.списокМагазиновToolStripMenuItem_Click); + // // FormMain // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); @@ -248,5 +257,6 @@ private ToolStripMenuItem магазиныToolStripMenuItem; private Button buttonSupplyShop; private Button buttonSellDocuments; + private ToolStripMenuItem списокМагазиновToolStripMenuItem; } } \ No newline at end of file diff --git a/LawFirm/LawFirm/FormMain.cs b/LawFirm/LawFirm/FormMain.cs index 4f6ef07..513b5d8 100644 --- a/LawFirm/LawFirm/FormMain.cs +++ b/LawFirm/LawFirm/FormMain.cs @@ -104,6 +104,19 @@ namespace LawFirmView } + private void списокМагазиновToolStripMenuItem_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 магазиныToolStripMenuItem_Click(object sender, EventArgs e) { var service = Program.ServiceProvider?.GetService(typeof(FormShops)); diff --git a/LawFirm/LawFirmBusinessLogic/BusinessLogics/ReportLogic.cs b/LawFirm/LawFirmBusinessLogic/BusinessLogics/ReportLogic.cs index fdebf7e..0c5ae26 100644 --- a/LawFirm/LawFirmBusinessLogic/BusinessLogics/ReportLogic.cs +++ b/LawFirm/LawFirmBusinessLogic/BusinessLogics/ReportLogic.cs @@ -18,14 +18,16 @@ namespace LawFirmBusinessLogic.BusinessLogics private readonly IBlankStorage _blankStorage; private readonly IDocumentStorage _documentStorage; private readonly IOrderStorage _orderStorage; + private readonly IShopStorage _shopStorage; private readonly AbstractSaveToExcel _saveToExcel; private readonly AbstractSaveToWord _saveToWord; private readonly AbstractSaveToPdf _saveToPdf; - public ReportLogic(IDocumentStorage documentStorage, IBlankStorage blankStorage, IOrderStorage orderStorage, AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf) + public ReportLogic(IDocumentStorage documentStorage, IBlankStorage blankStorage, IOrderStorage orderStorage, IShopStorage shopStorage, AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf) { _documentStorage = documentStorage; _blankStorage = blankStorage; _orderStorage = orderStorage; + _shopStorage = shopStorage; _saveToExcel = saveToExcel; _saveToWord = saveToWord; _saveToPdf = saveToPdf; @@ -107,5 +109,15 @@ namespace LawFirmBusinessLogic.BusinessLogics }); } + public void SaveShopsToWordFile(ReportBindingModel model) + { + _saveToWord.CreateTableDoc(new WordInfo + { + FileName = model.FileName, + Title = "Список магазинов", + Shops = _shopStorage.GetFullList() + }); + } + } } diff --git a/LawFirm/LawFirmBusinessLogic/OfficePackage/AbstractSaveToWord.cs b/LawFirm/LawFirmBusinessLogic/OfficePackage/AbstractSaveToWord.cs index 7c5a587..02136f3 100644 --- a/LawFirm/LawFirmBusinessLogic/OfficePackage/AbstractSaveToWord.cs +++ b/LawFirm/LawFirmBusinessLogic/OfficePackage/AbstractSaveToWord.cs @@ -39,11 +39,38 @@ namespace LawFirmBusinessLogic.OfficePackage } SaveWord(info); } + + public void CreateTableDoc(WordInfo wordInfo) + { + CreateWord(wordInfo); + var list = new List(); + foreach (var shop in wordInfo.Shops) + { + list.Add(shop.Name); + list.Add(shop.Adress); + list.Add(shop.OpeningDate.ToString()); + } + //list.AddRange(wordInfo.Shops.Select(x => (x.ShopName, new WordTextProperties { Bold = true, Size = "24" }))); + var wordTable = new WordTable + { + Headers = new List { + "Название", + "Адрес", + "Дата открытия"}, + Texts = list + }; + CreateTable(wordTable); + + SaveWord(wordInfo); + + } + /// Создание doc-файла protected abstract void CreateWord(WordInfo info); /// Создание абзаца с текстом protected abstract void CreateParagraph(WordParagraph paragraph); /// Сохранение файла protected abstract void SaveWord(WordInfo info); + protected abstract void CreateTable(WordTable info); } } diff --git a/LawFirm/LawFirmBusinessLogic/OfficePackage/HelperModels/WordInfo.cs b/LawFirm/LawFirmBusinessLogic/OfficePackage/HelperModels/WordInfo.cs index 1f73a5c..5074d4f 100644 --- a/LawFirm/LawFirmBusinessLogic/OfficePackage/HelperModels/WordInfo.cs +++ b/LawFirm/LawFirmBusinessLogic/OfficePackage/HelperModels/WordInfo.cs @@ -12,5 +12,6 @@ namespace LawFirmBusinessLogic.OfficePackage.HelperModels public string FileName { get; set; } = string.Empty; public string Title { get; set; } = string.Empty; public List Documents { get; set; } = new(); + public List Shops { get; set; } = new(); } } diff --git a/LawFirm/LawFirmBusinessLogic/OfficePackage/HelperModels/WordTable.cs b/LawFirm/LawFirmBusinessLogic/OfficePackage/HelperModels/WordTable.cs new file mode 100644 index 0000000..f08b1f3 --- /dev/null +++ b/LawFirm/LawFirmBusinessLogic/OfficePackage/HelperModels/WordTable.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace LawFirmBusinessLogic.OfficePackage.HelperModels +{ + public class WordTable + { + public List Headers { get; set; } = new(); + public List Texts { get; set; } = new(); + } +} diff --git a/LawFirm/LawFirmBusinessLogic/OfficePackage/Implements/SaveToWord.cs b/LawFirm/LawFirmBusinessLogic/OfficePackage/Implements/SaveToWord.cs index b9dbbf2..ec3f0ee 100644 --- a/LawFirm/LawFirmBusinessLogic/OfficePackage/Implements/SaveToWord.cs +++ b/LawFirm/LawFirmBusinessLogic/OfficePackage/Implements/SaveToWord.cs @@ -112,5 +112,86 @@ namespace LawFirmBusinessLogic.OfficePackage.Implements _wordDocument.MainDocumentPart!.Document.Save(); _wordDocument.Close(); } + protected override void CreateTable(WordTable table) + { + if (_docBody == null || table == null) + { + return; + } + Table tab = new Table(); + TableProperties props = new TableProperties( + new TableBorders( + new TopBorder + { + Val = new EnumValue(BorderValues.Single), + Size = 12 + }, + new BottomBorder + { + Val = new EnumValue(BorderValues.Single), + Size = 12 + }, + new LeftBorder + { + Val = new EnumValue(BorderValues.Single), + Size = 12 + }, + new RightBorder + { + Val = new EnumValue(BorderValues.Single), + Size = 12 + }, + new InsideHorizontalBorder + { + Val = new EnumValue(BorderValues.Single), + Size = 12 + }, + new InsideVerticalBorder + { + Val = new EnumValue(BorderValues.Single), + Size = 12 + } + ) + ); + tab.AppendChild(props); + TableGrid tableGrid = new TableGrid(); + for (int i = 0; i < table.Headers.Count; i++) + { + tableGrid.AppendChild(new GridColumn()); + } + tab.AppendChild(tableGrid); + TableRow tableRow = new TableRow(); + foreach (var text in table.Headers) + { + tableRow.AppendChild(CreateTableCell(text)); + } + tab.AppendChild(tableRow); + int height = table.Texts.Count / table.Headers.Count; + int width = table.Headers.Count; + for (int i = 0; i < height; i++) + { + tableRow = new TableRow(); + for (int j = 0; j < width; j++) + { + var element = table.Texts[i * table.Headers.Count + j]; + tableRow.AppendChild(CreateTableCell(element)); + } + tab.AppendChild(tableRow); + } + + _docBody.AppendChild(tab); + + } + + private TableCell CreateTableCell(string element) + { + var tableParagraph = new Paragraph(); + var run = new Run(); + run.AppendChild(new Text { Text = element }); + tableParagraph.AppendChild(run); + var tableCell = new TableCell(); + tableCell.AppendChild(tableParagraph); + return tableCell; + } } } diff --git a/LawFirm/LawFirmContracts/BusinessLogicContracts/IReportLogic.cs b/LawFirm/LawFirmContracts/BusinessLogicContracts/IReportLogic.cs index 5359cf7..fcf58e2 100644 --- a/LawFirm/LawFirmContracts/BusinessLogicContracts/IReportLogic.cs +++ b/LawFirm/LawFirmContracts/BusinessLogicContracts/IReportLogic.cs @@ -20,5 +20,7 @@ namespace LawFirmContracts.BusinessLogicContracts void SaveProductComponentToExcelFile(ReportBindingModel model); /// Сохранение заказов в файл-Pdf void SaveOrdersToPdfFile(ReportBindingModel model); + // Сохранение магазинов в файл-Word + void SaveShopsToWordFile(ReportBindingModel model); } } -- 2.25.1 From ced6ecb0629eff7934ce1bbb342e3d4edfe85053 Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Sun, 26 Mar 2023 21:38:36 +0400 Subject: [PATCH 13/16] =?UTF-8?q?=D0=9E=D1=82=D1=87=D0=B5=D1=82=20=D0=BF?= =?UTF-8?q?=D0=BE=20=D0=BC=D0=B0=D0=B3=D0=B0=D0=B7=D0=B8=D0=BD=D0=B0=D0=BC?= =?UTF-8?q?=20=D0=B2=20Excel?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LawFirm/LawFirm/FormMain.Designer.cs | 30 +++-- LawFirm/LawFirm/FormMain.cs | 9 ++ .../FormReportShopDocuments.Designer.cs | 107 ++++++++++++++++++ LawFirm/LawFirm/FormReportShopDocuments.cs | 85 ++++++++++++++ LawFirm/LawFirm/FormReportShopDocuments.resx | 78 +++++++++++++ LawFirm/LawFirm/Program.cs | 1 + .../BusinessLogics/ReportLogic.cs | 30 +++++ .../OfficePackage/AbstractSaveToExcel.cs | 64 +++++++++++ .../OfficePackage/AbstractSaveToWord.cs | 1 - .../OfficePackage/HelperModels/ExcelInfo.cs | 1 + .../BusinessLogicContracts/IReportLogic.cs | 2 + .../ReportShopDocumentsViewModel.cs | 15 +++ 12 files changed, 412 insertions(+), 11 deletions(-) create mode 100644 LawFirm/LawFirm/FormReportShopDocuments.Designer.cs create mode 100644 LawFirm/LawFirm/FormReportShopDocuments.cs create mode 100644 LawFirm/LawFirm/FormReportShopDocuments.resx create mode 100644 LawFirm/LawFirmContracts/ViewModels/ReportShopDocumentsViewModel.cs diff --git a/LawFirm/LawFirm/FormMain.Designer.cs b/LawFirm/LawFirm/FormMain.Designer.cs index e9caa6d..f9a969a 100644 --- a/LawFirm/LawFirm/FormMain.Designer.cs +++ b/LawFirm/LawFirm/FormMain.Designer.cs @@ -37,6 +37,7 @@ this.списокДокументовToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.бланкиПоДокументамToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.списокЗаказовToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.списокМагазиновToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.dataGridView = new System.Windows.Forms.DataGridView(); this.buttonCreateOrder = new System.Windows.Forms.Button(); this.buttonSetToWork = new System.Windows.Forms.Button(); @@ -45,7 +46,7 @@ this.buttonUpdate = new System.Windows.Forms.Button(); this.buttonSupplyShop = new System.Windows.Forms.Button(); this.buttonSellDocuments = new System.Windows.Forms.Button(); - this.списокМагазиновToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.документыВМагазинахToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.menuStrip.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); this.SuspendLayout(); @@ -99,7 +100,8 @@ this.списокДокументовToolStripMenuItem, this.бланкиПоДокументамToolStripMenuItem, this.списокЗаказовToolStripMenuItem, - this.списокМагазиновToolStripMenuItem}); + this.списокМагазиновToolStripMenuItem, + this.документыВМагазинахToolStripMenuItem}); this.отчетыToolStripMenuItem.Name = "отчетыToolStripMenuItem"; this.отчетыToolStripMenuItem.Size = new System.Drawing.Size(73, 24); this.отчетыToolStripMenuItem.Text = "Отчеты"; @@ -107,24 +109,31 @@ // списокДокументовToolStripMenuItem // this.списокДокументовToolStripMenuItem.Name = "списокДокументовToolStripMenuItem"; - this.списокДокументовToolStripMenuItem.Size = new System.Drawing.Size(252, 26); + this.списокДокументовToolStripMenuItem.Size = new System.Drawing.Size(259, 26); this.списокДокументовToolStripMenuItem.Text = "Список документов"; this.списокДокументовToolStripMenuItem.Click += new System.EventHandler(this.списокДокументовToolStripMenuItem_Click); // // бланкиПоДокументамToolStripMenuItem // this.бланкиПоДокументамToolStripMenuItem.Name = "бланкиПоДокументамToolStripMenuItem"; - this.бланкиПоДокументамToolStripMenuItem.Size = new System.Drawing.Size(252, 26); + this.бланкиПоДокументамToolStripMenuItem.Size = new System.Drawing.Size(259, 26); this.бланкиПоДокументамToolStripMenuItem.Text = "Бланки по документам"; this.бланкиПоДокументамToolStripMenuItem.Click += new System.EventHandler(this.бланкиПоДокументамToolStripMenuItem_Click); // // списокЗаказовToolStripMenuItem // this.списокЗаказовToolStripMenuItem.Name = "списокЗаказовToolStripMenuItem"; - this.списокЗаказовToolStripMenuItem.Size = new System.Drawing.Size(252, 26); + this.списокЗаказовToolStripMenuItem.Size = new System.Drawing.Size(259, 26); this.списокЗаказовToolStripMenuItem.Text = "Список заказов"; this.списокЗаказовToolStripMenuItem.Click += new System.EventHandler(this.списокЗаказовToolStripMenuItem_Click); // + // списокМагазиновToolStripMenuItem + // + this.списокМагазиновToolStripMenuItem.Name = "списокМагазиновToolStripMenuItem"; + this.списокМагазиновToolStripMenuItem.Size = new System.Drawing.Size(259, 26); + this.списокМагазиновToolStripMenuItem.Text = "Список магазинов"; + this.списокМагазиновToolStripMenuItem.Click += new System.EventHandler(this.списокМагазиновToolStripMenuItem_Click); + // // dataGridView // this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; @@ -205,12 +214,12 @@ this.buttonSellDocuments.UseVisualStyleBackColor = true; this.buttonSellDocuments.Click += new System.EventHandler(this.buttonSellDocuments_Click); // - // списокМагазиновToolStripMenuItem + // документыВМагазинахToolStripMenuItem // - this.списокМагазиновToolStripMenuItem.Name = "списокМагазиновToolStripMenuItem"; - this.списокМагазиновToolStripMenuItem.Size = new System.Drawing.Size(252, 26); - this.списокМагазиновToolStripMenuItem.Text = "Список магазинов"; - this.списокМагазиновToolStripMenuItem.Click += new System.EventHandler(this.списокМагазиновToolStripMenuItem_Click); + this.документыВМагазинахToolStripMenuItem.Name = "документыВМагазинахToolStripMenuItem"; + this.документыВМагазинахToolStripMenuItem.Size = new System.Drawing.Size(259, 26); + this.документыВМагазинахToolStripMenuItem.Text = "Документы в магазинах"; + this.документыВМагазинахToolStripMenuItem.Click += new System.EventHandler(this.документыВМагазинахToolStripMenuItem_Click); // // FormMain // @@ -258,5 +267,6 @@ private Button buttonSupplyShop; private Button buttonSellDocuments; private ToolStripMenuItem списокМагазиновToolStripMenuItem; + private ToolStripMenuItem документыВМагазинахToolStripMenuItem; } } \ No newline at end of file diff --git a/LawFirm/LawFirm/FormMain.cs b/LawFirm/LawFirm/FormMain.cs index 513b5d8..8b2f7bd 100644 --- a/LawFirm/LawFirm/FormMain.cs +++ b/LawFirm/LawFirm/FormMain.cs @@ -117,6 +117,15 @@ namespace LawFirmView } } + private void документыВМагазинахToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormReportShopDocuments)); + if (service is FormReportShopDocuments form) + { + form.ShowDialog(); + } + } + private void магазиныToolStripMenuItem_Click(object sender, EventArgs e) { var service = Program.ServiceProvider?.GetService(typeof(FormShops)); diff --git a/LawFirm/LawFirm/FormReportShopDocuments.Designer.cs b/LawFirm/LawFirm/FormReportShopDocuments.Designer.cs new file mode 100644 index 0000000..4cf865e --- /dev/null +++ b/LawFirm/LawFirm/FormReportShopDocuments.Designer.cs @@ -0,0 +1,107 @@ +namespace LawFirmView +{ + partial class FormReportShopDocuments + { + /// + /// 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.buttonSaveToExcel = new System.Windows.Forms.Button(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.Shop = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.Document = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.Count = new System.Windows.Forms.DataGridViewTextBoxColumn(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // buttonSaveToExcel + // + this.buttonSaveToExcel.Location = new System.Drawing.Point(12, 8); + this.buttonSaveToExcel.Name = "buttonSaveToExcel"; + this.buttonSaveToExcel.Size = new System.Drawing.Size(176, 29); + this.buttonSaveToExcel.TabIndex = 0; + this.buttonSaveToExcel.Text = "Сохранить в Excel"; + this.buttonSaveToExcel.UseVisualStyleBackColor = true; + this.buttonSaveToExcel.Click += new System.EventHandler(this.buttonSaveToExcel_Click); + // + // dataGridView + // + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.Shop, + this.Document, + this.Count}); + this.dataGridView.Location = new System.Drawing.Point(12, 43); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(776, 395); + this.dataGridView.TabIndex = 1; + // + // Shop + // + this.Shop.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; + this.Shop.HeaderText = "Магазин"; + this.Shop.MinimumWidth = 6; + this.Shop.Name = "Shop"; + // + // Document + // + this.Document.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; + this.Document.HeaderText = "Документ"; + this.Document.MinimumWidth = 6; + this.Document.Name = "Document"; + // + // Count + // + this.Count.HeaderText = "Количество"; + this.Count.MinimumWidth = 6; + this.Count.Name = "Count"; + this.Count.Width = 125; + // + // FormReportShopDocuments + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.dataGridView); + this.Controls.Add(this.buttonSaveToExcel); + this.Name = "FormReportShopDocuments"; + this.Text = "Документы в магазинах"; + this.Load += new System.EventHandler(this.FormReportShopDocuments_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private Button buttonSaveToExcel; + private DataGridView dataGridView; + private DataGridViewTextBoxColumn Shop; + private DataGridViewTextBoxColumn Document; + private DataGridViewTextBoxColumn Count; + } +} \ No newline at end of file diff --git a/LawFirm/LawFirm/FormReportShopDocuments.cs b/LawFirm/LawFirm/FormReportShopDocuments.cs new file mode 100644 index 0000000..63bbb56 --- /dev/null +++ b/LawFirm/LawFirm/FormReportShopDocuments.cs @@ -0,0 +1,85 @@ +using LawFirmBusinessLogic.BusinessLogics; +using LawFirmContracts.BindingModels; +using LawFirmContracts.BusinessLogicContracts; +using Microsoft.Extensions.Logging; +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 LawFirmView +{ + public partial class FormReportShopDocuments : Form + { + private readonly ILogger _logger; + private readonly IReportLogic _logic; + + public FormReportShopDocuments(ILogger logger, IReportLogic reportLogic) + { + InitializeComponent(); + _logger = logger; + _logic = reportLogic; + } + + private void buttonSaveToExcel_Click(object sender, EventArgs e) + { + using var dialog = new SaveFileDialog + { + Filter = "xlsx|*.xlsx" + }; + if (dialog.ShowDialog() == DialogResult.OK) + { + try + { + _logic.SaveShopDocumentsToExcelFile(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); + } + } + } + + private void FormReportShopDocuments_Load(object sender, EventArgs e) + { + try + { + var dict = _logic.GetShopDocuments(); + if (dict != null) + { + dataGridView.Rows.Clear(); + foreach (var elem in dict) + { + dataGridView.Rows.Add(new object[] { elem.ShopName, "", "" }); + foreach (var listElem in elem.Documents) + { + dataGridView.Rows.Add(new object[] { "", listElem.Item1, listElem.Item2 }); + } + dataGridView.Rows.Add(new object[] { "Всего:", "", elem.Count }); + dataGridView.Rows.Add(Array.Empty()); + } + } + _logger.LogInformation("Загрузка списка магазинов с изделиями в них"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка магазинов с изделиями в них"); + + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } +} diff --git a/LawFirm/LawFirm/FormReportShopDocuments.resx b/LawFirm/LawFirm/FormReportShopDocuments.resx new file mode 100644 index 0000000..f8b9c56 --- /dev/null +++ b/LawFirm/LawFirm/FormReportShopDocuments.resx @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + True + + + True + + + True + + + True + + + True + + + True + + \ No newline at end of file diff --git a/LawFirm/LawFirm/Program.cs b/LawFirm/LawFirm/Program.cs index 011ff2e..58b4590 100644 --- a/LawFirm/LawFirm/Program.cs +++ b/LawFirm/LawFirm/Program.cs @@ -67,6 +67,7 @@ namespace LawFirm services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); } } diff --git a/LawFirm/LawFirmBusinessLogic/BusinessLogics/ReportLogic.cs b/LawFirm/LawFirmBusinessLogic/BusinessLogics/ReportLogic.cs index 0c5ae26..049e1b9 100644 --- a/LawFirm/LawFirmBusinessLogic/BusinessLogics/ReportLogic.cs +++ b/LawFirm/LawFirmBusinessLogic/BusinessLogics/ReportLogic.cs @@ -118,6 +118,36 @@ namespace LawFirmBusinessLogic.BusinessLogics Shops = _shopStorage.GetFullList() }); } + public void SaveShopDocumentsToExcelFile(ReportBindingModel model) + { + _saveToExcel.CreateShopReport(new ExcelInfo + { + FileName = model.FileName, + Title = "Список магазинов с изделиями", + ShopDocuments = GetShopDocuments() + }); + } + public List GetShopDocuments() + { + var shops = _shopStorage.GetFullList(); + var list = new List(); + foreach (var shop in shops) + { + var record = new ReportShopDocumentsViewModel + { + ShopName = shop.Name, + Documents = new List>(), + Count = 0 + }; + foreach (var furnitureCount in shop.ShopDocuments.Values) + { + record.Documents.Add(new Tuple(furnitureCount.Item1.DocumentName, furnitureCount.Item2)); + record.Count += furnitureCount.Item2; + } + list.Add(record); + } + return list; + } } } diff --git a/LawFirm/LawFirmBusinessLogic/OfficePackage/AbstractSaveToExcel.cs b/LawFirm/LawFirmBusinessLogic/OfficePackage/AbstractSaveToExcel.cs index 50dcd3b..5dff52f 100644 --- a/LawFirm/LawFirmBusinessLogic/OfficePackage/AbstractSaveToExcel.cs +++ b/LawFirm/LawFirmBusinessLogic/OfficePackage/AbstractSaveToExcel.cs @@ -27,6 +27,7 @@ namespace LawFirmBusinessLogic.OfficePackage CellToName = "C1" }); uint rowIndex = 2; + foreach (var pc in info.DocumentBlanks) { InsertCellInWorksheet(new ExcelCellParameters @@ -73,6 +74,69 @@ namespace LawFirmBusinessLogic.OfficePackage } SaveExcel(info); } + + public void CreateShopReport(ExcelInfo info) + { + CreateExcel(info); + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "A", + RowIndex = 1, + Text = info.Title, + StyleInfo = ExcelStyleInfoType.Title + }); + MergeCells(new ExcelMergeParameters + { + CellFromName = "A1", + CellToName = "C1" + }); + uint rowIndex = 2; + foreach (var pc in info.ShopDocuments) + { + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "A", + RowIndex = rowIndex, + Text = pc.ShopName, + StyleInfo = ExcelStyleInfoType.Text + }); + rowIndex++; + foreach (var (DocumentName, Count) in pc.Documents) + { + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "B", + RowIndex = rowIndex, + Text = DocumentName, + 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.Count.ToString(), + StyleInfo = ExcelStyleInfoType.Text + }); + rowIndex++; + } + SaveExcel(info); + } /// Создание excel-файла protected abstract void CreateExcel(ExcelInfo info); /// Добавляем новую ячейку в лист diff --git a/LawFirm/LawFirmBusinessLogic/OfficePackage/AbstractSaveToWord.cs b/LawFirm/LawFirmBusinessLogic/OfficePackage/AbstractSaveToWord.cs index 02136f3..69a3aee 100644 --- a/LawFirm/LawFirmBusinessLogic/OfficePackage/AbstractSaveToWord.cs +++ b/LawFirm/LawFirmBusinessLogic/OfficePackage/AbstractSaveToWord.cs @@ -50,7 +50,6 @@ namespace LawFirmBusinessLogic.OfficePackage list.Add(shop.Adress); list.Add(shop.OpeningDate.ToString()); } - //list.AddRange(wordInfo.Shops.Select(x => (x.ShopName, new WordTextProperties { Bold = true, Size = "24" }))); var wordTable = new WordTable { Headers = new List { diff --git a/LawFirm/LawFirmBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs b/LawFirm/LawFirmBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs index f682fa1..4a75226 100644 --- a/LawFirm/LawFirmBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs +++ b/LawFirm/LawFirmBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs @@ -12,5 +12,6 @@ namespace LawFirmBusinessLogic.OfficePackage.HelperModels public string FileName { get; set; } = string.Empty; public string Title { get; set; } = string.Empty; public List DocumentBlanks { get; set; } = new(); + public List ShopDocuments { get; set; } = new(); } } diff --git a/LawFirm/LawFirmContracts/BusinessLogicContracts/IReportLogic.cs b/LawFirm/LawFirmContracts/BusinessLogicContracts/IReportLogic.cs index fcf58e2..4e0fa2b 100644 --- a/LawFirm/LawFirmContracts/BusinessLogicContracts/IReportLogic.cs +++ b/LawFirm/LawFirmContracts/BusinessLogicContracts/IReportLogic.cs @@ -22,5 +22,7 @@ namespace LawFirmContracts.BusinessLogicContracts void SaveOrdersToPdfFile(ReportBindingModel model); // Сохранение магазинов в файл-Word void SaveShopsToWordFile(ReportBindingModel model); + void SaveShopDocumentsToExcelFile(ReportBindingModel model); + List GetShopDocuments(); } } diff --git a/LawFirm/LawFirmContracts/ViewModels/ReportShopDocumentsViewModel.cs b/LawFirm/LawFirmContracts/ViewModels/ReportShopDocumentsViewModel.cs new file mode 100644 index 0000000..e8a7344 --- /dev/null +++ b/LawFirm/LawFirmContracts/ViewModels/ReportShopDocumentsViewModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace LawFirmContracts.ViewModels +{ + public class ReportShopDocumentsViewModel + { + public string ShopName { get; set; } = string.Empty; + public int Count { get; set; } + public List> Documents { get; set; } = new(); + } +} -- 2.25.1 From 4b8f3eae04d365231b2abf1d88e8b34c5d7667a5 Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Sun, 26 Mar 2023 22:39:05 +0400 Subject: [PATCH 14/16] =?UTF-8?q?=D0=9E=D1=82=D1=87=D0=B5=D1=82=20=D0=BF?= =?UTF-8?q?=D0=BE=20=D0=B7=D0=B0=D0=BA=D0=B0=D0=B7=D0=B0=D0=BC=20=D0=BF?= =?UTF-8?q?=D0=BE=20=D0=B4=D0=B0=D1=82=D0=B5=20PDF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LawFirm/LawFirm/FormMain.Designer.cs | 24 +- LawFirm/LawFirm/FormMain.cs | 9 + .../LawFirm/FormReportDateOrders.Designer.cs | 131 +++++ LawFirm/LawFirm/FormReportDateOrders.cs | 97 ++++ LawFirm/LawFirm/FormReportDateOrders.resx | 60 +++ LawFirm/LawFirm/Program.cs | 2 + LawFirm/LawFirm/ReportOrdersByDate.rdlc | 460 ++++++++++++++++++ .../BusinessLogics/ReportLogic.cs | 21 + .../OfficePackage/AbstractSaveToPdf.cs | 39 ++ .../OfficePackage/HelperModels/PdfInfo.cs | 1 + .../BusinessLogicContracts/IReportLogic.cs | 4 +- .../ViewModels/ReportDateOrdersViewModel.cs | 15 + 12 files changed, 855 insertions(+), 8 deletions(-) create mode 100644 LawFirm/LawFirm/FormReportDateOrders.Designer.cs create mode 100644 LawFirm/LawFirm/FormReportDateOrders.cs create mode 100644 LawFirm/LawFirm/FormReportDateOrders.resx create mode 100644 LawFirm/LawFirm/ReportOrdersByDate.rdlc create mode 100644 LawFirm/LawFirmContracts/ViewModels/ReportDateOrdersViewModel.cs diff --git a/LawFirm/LawFirm/FormMain.Designer.cs b/LawFirm/LawFirm/FormMain.Designer.cs index f9a969a..bfda821 100644 --- a/LawFirm/LawFirm/FormMain.Designer.cs +++ b/LawFirm/LawFirm/FormMain.Designer.cs @@ -38,6 +38,7 @@ this.бланкиПоДокументамToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.списокЗаказовToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.списокМагазиновToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.документыВМагазинахToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.dataGridView = new System.Windows.Forms.DataGridView(); this.buttonCreateOrder = new System.Windows.Forms.Button(); this.buttonSetToWork = new System.Windows.Forms.Button(); @@ -46,7 +47,7 @@ this.buttonUpdate = new System.Windows.Forms.Button(); this.buttonSupplyShop = new System.Windows.Forms.Button(); this.buttonSellDocuments = new System.Windows.Forms.Button(); - this.документыВМагазинахToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.списокЗаказовПоДатеToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.menuStrip.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); this.SuspendLayout(); @@ -101,7 +102,8 @@ this.бланкиПоДокументамToolStripMenuItem, this.списокЗаказовToolStripMenuItem, this.списокМагазиновToolStripMenuItem, - this.документыВМагазинахToolStripMenuItem}); + this.документыВМагазинахToolStripMenuItem, + this.списокЗаказовПоДатеToolStripMenuItem}); this.отчетыToolStripMenuItem.Name = "отчетыToolStripMenuItem"; this.отчетыToolStripMenuItem.Size = new System.Drawing.Size(73, 24); this.отчетыToolStripMenuItem.Text = "Отчеты"; @@ -134,6 +136,13 @@ this.списокМагазиновToolStripMenuItem.Text = "Список магазинов"; this.списокМагазиновToolStripMenuItem.Click += new System.EventHandler(this.списокМагазиновToolStripMenuItem_Click); // + // документыВМагазинахToolStripMenuItem + // + this.документыВМагазинахToolStripMenuItem.Name = "документыВМагазинахToolStripMenuItem"; + this.документыВМагазинахToolStripMenuItem.Size = new System.Drawing.Size(259, 26); + this.документыВМагазинахToolStripMenuItem.Text = "Документы в магазинах"; + this.документыВМагазинахToolStripMenuItem.Click += new System.EventHandler(this.документыВМагазинахToolStripMenuItem_Click); + // // dataGridView // this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; @@ -214,12 +223,12 @@ this.buttonSellDocuments.UseVisualStyleBackColor = true; this.buttonSellDocuments.Click += new System.EventHandler(this.buttonSellDocuments_Click); // - // документыВМагазинахToolStripMenuItem + // списокЗаказовПоДатеToolStripMenuItem // - this.документыВМагазинахToolStripMenuItem.Name = "документыВМагазинахToolStripMenuItem"; - this.документыВМагазинахToolStripMenuItem.Size = new System.Drawing.Size(259, 26); - this.документыВМагазинахToolStripMenuItem.Text = "Документы в магазинах"; - this.документыВМагазинахToolStripMenuItem.Click += new System.EventHandler(this.документыВМагазинахToolStripMenuItem_Click); + this.списокЗаказовПоДатеToolStripMenuItem.Name = "списокЗаказовПоДатеToolStripMenuItem"; + this.списокЗаказовПоДатеToolStripMenuItem.Size = new System.Drawing.Size(259, 26); + this.списокЗаказовПоДатеToolStripMenuItem.Text = "Список заказов по дате"; + this.списокЗаказовПоДатеToolStripMenuItem.Click += new System.EventHandler(this.списокЗаказовПоДатеToolStripMenuItem_Click); // // FormMain // @@ -268,5 +277,6 @@ private Button buttonSellDocuments; private ToolStripMenuItem списокМагазиновToolStripMenuItem; private ToolStripMenuItem документыВМагазинахToolStripMenuItem; + private ToolStripMenuItem списокЗаказовПоДатеToolStripMenuItem; } } \ No newline at end of file diff --git a/LawFirm/LawFirm/FormMain.cs b/LawFirm/LawFirm/FormMain.cs index 8b2f7bd..90f0221 100644 --- a/LawFirm/LawFirm/FormMain.cs +++ b/LawFirm/LawFirm/FormMain.cs @@ -126,6 +126,15 @@ namespace LawFirmView } } + private void списокЗаказовПоДатеToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormReportDateOrders)); + if (service is FormReportDateOrders form) + { + form.ShowDialog(); + } + } + private void магазиныToolStripMenuItem_Click(object sender, EventArgs e) { var service = Program.ServiceProvider?.GetService(typeof(FormShops)); diff --git a/LawFirm/LawFirm/FormReportDateOrders.Designer.cs b/LawFirm/LawFirm/FormReportDateOrders.Designer.cs new file mode 100644 index 0000000..a8f19ff --- /dev/null +++ b/LawFirm/LawFirm/FormReportDateOrders.Designer.cs @@ -0,0 +1,131 @@ +namespace LawFirmView +{ + partial class FormReportDateOrders + { + /// + /// 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.buttonCreateToPdf = new System.Windows.Forms.Button(); + this.buttonCreateReport = new System.Windows.Forms.Button(); + this.label2 = new System.Windows.Forms.Label(); + this.label1 = new System.Windows.Forms.Label(); + this.dateTimePickerEnd = new System.Windows.Forms.DateTimePicker(); + this.dateTimePickerStart = new System.Windows.Forms.DateTimePicker(); + this.panel.SuspendLayout(); + this.SuspendLayout(); + // + // panel + // + this.panel.Controls.Add(this.buttonCreateToPdf); + this.panel.Controls.Add(this.buttonCreateReport); + this.panel.Controls.Add(this.label2); + this.panel.Controls.Add(this.label1); + this.panel.Controls.Add(this.dateTimePickerEnd); + this.panel.Controls.Add(this.dateTimePickerStart); + 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(978, 69); + this.panel.TabIndex = 1; + // + // buttonCreateToPdf + // + this.buttonCreateToPdf.Location = new System.Drawing.Point(769, 39); + this.buttonCreateToPdf.Name = "buttonCreateToPdf"; + this.buttonCreateToPdf.Size = new System.Drawing.Size(190, 27); + this.buttonCreateToPdf.TabIndex = 5; + this.buttonCreateToPdf.Text = "PDF"; + this.buttonCreateToPdf.UseVisualStyleBackColor = true; + this.buttonCreateToPdf.Click += new System.EventHandler(this.buttonCreateToPdf_Click); + // + // buttonCreateReport + // + this.buttonCreateReport.Location = new System.Drawing.Point(554, 39); + this.buttonCreateReport.Name = "buttonCreateReport"; + this.buttonCreateReport.Size = new System.Drawing.Size(190, 27); + this.buttonCreateReport.TabIndex = 4; + this.buttonCreateReport.Text = "Сформировать"; + this.buttonCreateReport.UseVisualStyleBackColor = true; + this.buttonCreateReport.Click += new System.EventHandler(this.buttonCreateReport_Click); + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(369, 9); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(56, 20); + this.label2.TabIndex = 3; + this.label2.Text = "Конец:"; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(87, 6); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(64, 20); + this.label1.TabIndex = 2; + this.label1.Text = "Начало:"; + // + // dateTimePickerEnd + // + this.dateTimePickerEnd.Location = new System.Drawing.Point(307, 39); + this.dateTimePickerEnd.Name = "dateTimePickerEnd"; + this.dateTimePickerEnd.Size = new System.Drawing.Size(187, 27); + this.dateTimePickerEnd.TabIndex = 1; + // + // dateTimePickerStart + // + this.dateTimePickerStart.Location = new System.Drawing.Point(35, 39); + this.dateTimePickerStart.Name = "dateTimePickerStart"; + this.dateTimePickerStart.Size = new System.Drawing.Size(187, 27); + this.dateTimePickerStart.TabIndex = 0; + // + // FormReportDateOrders + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(978, 450); + this.Controls.Add(this.panel); + this.Name = "FormReportDateOrders"; + this.Text = "Заказы по датам"; + this.panel.ResumeLayout(false); + this.panel.PerformLayout(); + this.ResumeLayout(false); + + } + + #endregion + + private Panel panel; + private Button buttonCreateToPdf; + private Button buttonCreateReport; + private Label label2; + private Label label1; + private DateTimePicker dateTimePickerEnd; + private DateTimePicker dateTimePickerStart; + } +} \ No newline at end of file diff --git a/LawFirm/LawFirm/FormReportDateOrders.cs b/LawFirm/LawFirm/FormReportDateOrders.cs new file mode 100644 index 0000000..c0c0f25 --- /dev/null +++ b/LawFirm/LawFirm/FormReportDateOrders.cs @@ -0,0 +1,97 @@ +using LawFirmContracts.BindingModels; +using LawFirmContracts.BusinessLogicContracts; +using Microsoft.Extensions.Logging; +using Microsoft.Reporting.WinForms; +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 LawFirmView +{ + public partial class FormReportDateOrders : Form + { + private readonly ReportViewer reportViewer; + + private readonly ILogger _logger; + + private readonly IReportLogic _logic; + public FormReportDateOrders(ILogger logger, IReportLogic reportLogic) + { + InitializeComponent(); + _logger = logger; + _logic = reportLogic; + reportViewer = new ReportViewer + { + Dock = DockStyle.Fill + }; + reportViewer.LocalReport.LoadReportDefinition(new FileStream("ReportOrdersByDate.rdlc", FileMode.Open)); + Controls.Clear(); + Controls.Add(reportViewer); + Controls.Add(panel); + } + + private void buttonCreateReport_Click(object sender, EventArgs e) + { + if (dateTimePickerStart.Value.Date >= dateTimePickerEnd.Value.Date) + { + MessageBox.Show("Дата начала должна быть меньше даты окончания", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + try + { + var dataSource = _logic.GetDateOrders(new ReportBindingModel + { + DateFrom = dateTimePickerStart.Value, + DateTo = dateTimePickerEnd.Value + }); + var source = new ReportDataSource("DataSetOrders", dataSource); + reportViewer.LocalReport.DataSources.Clear(); + reportViewer.LocalReport.DataSources.Add(source); + var parameters = new[] { new ReportParameter("ReportParameterPeriod", $"c {dateTimePickerStart.Value.ToShortDateString()} по {dateTimePickerEnd.Value.ToShortDateString()}") }; + reportViewer.LocalReport.SetParameters(parameters); + reportViewer.RefreshReport(); + _logger.LogInformation("Загрузка списка заказов на период {From}-{To}", dateTimePickerStart.Value.ToShortDateString(), dateTimePickerEnd.Value.ToShortDateString()); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка заказов на период"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonCreateToPdf_Click(object sender, EventArgs e) + { + if (dateTimePickerStart.Value.Date >= dateTimePickerEnd.Value.Date) + { + MessageBox.Show("Дата начала должна быть меньше даты окончания", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + using var dialog = new SaveFileDialog { Filter = "pdf|*.pdf" }; + if (dialog.ShowDialog() == DialogResult.OK) + { + try + { + _logic.SaveDateOrdersToPdfFile(new ReportBindingModel + { + FileName = dialog.FileName, + DateFrom = dateTimePickerStart.Value, + DateTo = dateTimePickerEnd.Value + }); + _logger.LogInformation("Сохранение списка заказов на период {From}-{To}", dateTimePickerStart.Value.ToShortDateString(), dateTimePickerEnd.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/LawFirm/LawFirm/FormReportDateOrders.resx b/LawFirm/LawFirm/FormReportDateOrders.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/LawFirm/LawFirm/FormReportDateOrders.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/LawFirm/LawFirm/Program.cs b/LawFirm/LawFirm/Program.cs index 58b4590..5c0f65a 100644 --- a/LawFirm/LawFirm/Program.cs +++ b/LawFirm/LawFirm/Program.cs @@ -68,6 +68,8 @@ namespace LawFirm services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + } } diff --git a/LawFirm/LawFirm/ReportOrdersByDate.rdlc b/LawFirm/LawFirm/ReportOrdersByDate.rdlc new file mode 100644 index 0000000..7ce32cb --- /dev/null +++ b/LawFirm/LawFirm/ReportOrdersByDate.rdlc @@ -0,0 +1,460 @@ + + + 0 + + + + System.Data.DataSet + /* Local Connection */ + + 10791c83-cee8-4a38-bbd0-245fc17cefb3 + + + + + + LawFirmContractsViewModels + /* Local Query */ + + + + DateCreate + System.DateTime + + + CountOrders + System.Decimal + + + TotalSumOrders + System.Double + + + + LawFirmContracts.ViewModels + ReportDateOrdersViewModel + LawFirmContracts.ViewModels.ReportDateOrdersViewModel, LawFirmContracts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + + + + + + + + + true + true + + + + + =Parameters!ReportParameterPeriod.Value + + + + + + + ReportParameterPeriod + 1cm + 1cm + 21cm + + + Middle + 2pt + 2pt + 2pt + 2pt + + + + true + true + + + + + Заказы + + + + + + + 1cm + 21cm + 1 + + + Middle + 2pt + 2pt + 2pt + 2pt + + + + + + + 3cm + + + 3cm + + + 7cm + + + + + 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!DateCreate.Value + + + + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + =Fields!CountOrders.Value + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + =Fields!SumOrders.Value + + + 2pt + 2pt + 2pt + 2pt + + + true + + + + + + + + + + + + + + + + + After + + + + + + + DataSetOrders + 2.48391cm + 0.55245cm + 1.2cm + 13cm + 2 + + + + + + true + true + + + + + Всего: + + + + + + + 4cm + 8.55245cm + 0.6cm + 2.5cm + 3 + + + 2pt + 2pt + 2pt + 2pt + + + + true + true + + + + + =Sum(Fields!SumOrders.Value, "DataSetOrders") + + + + + + + 4cm + 11.05245cm + 0.6cm + 2.5cm + 4 + + + 2pt + 2pt + 2pt + 2pt + + + + 5.72875cm + - - - - - - ReportParameterPeriod - 1cm - 1cm - 21cm - - - Middle - 2pt - 2pt - 2pt - 2pt - - true true @@ -96,7 +62,6 @@ 1cm 21cm - 1 @@ -134,7 +99,7 @@ - Дата создания + Дата @@ -166,7 +131,7 @@ - Количество заказов + Количество @@ -316,7 +281,6 @@ 2pt - true @@ -345,7 +309,7 @@ 0.55245cm 1.2cm 13cm - 2 + 1 @@ -374,7 +338,7 @@ 8.55245cm 0.6cm 2.5cm - 3 + 2 @@ -407,7 +371,7 @@ 11.05245cm 0.6cm 2.5cm - 4 + 3 diff --git a/LawFirm/LawFirmBusinessLogic/BusinessLogics/ReportLogic.cs b/LawFirm/LawFirmBusinessLogic/BusinessLogics/ReportLogic.cs index 3925d99..3423cff 100644 --- a/LawFirm/LawFirmBusinessLogic/BusinessLogics/ReportLogic.cs +++ b/LawFirm/LawFirmBusinessLogic/BusinessLogics/ReportLogic.cs @@ -123,7 +123,7 @@ namespace LawFirmBusinessLogic.BusinessLogics _saveToExcel.CreateShopReport(new ExcelInfo { FileName = model.FileName, - Title = "Список магазинов с изделиями", + Title = "Загруженность магазинов", ShopDocuments = GetShopDocuments() }); } @@ -140,17 +140,17 @@ namespace LawFirmBusinessLogic.BusinessLogics Documents = new List>(), Count = 0 }; - foreach (var furnitureCount in shop.ShopDocuments.Values) + foreach (var docCount in shop.ShopDocuments.Values) { - record.Documents.Add(new Tuple(furnitureCount.Item1.DocumentName, furnitureCount.Item2)); - record.Count += furnitureCount.Item2; + record.Documents.Add(new Tuple(docCount.Item1.DocumentName, docCount.Item2)); + record.Count += docCount.Item2; } list.Add(record); } return list; } - public List GetDateOrders(ReportBindingModel model) + public List GetDateOrders() { return _orderStorage.GetFullList().GroupBy(x => x.DateCreate.Date).Select(x => new ReportDateOrdersViewModel { @@ -164,10 +164,8 @@ namespace LawFirmBusinessLogic.BusinessLogics _saveToPdf.CreateReportDateDoc(new PdfInfo { FileName = model.FileName, - Title = "Список объединенных по дате заказов", - DateFrom = model.DateFrom!.Value, - DateTo = model.DateTo!.Value, - DateOrders = GetDateOrders(model) + Title = "Заказы по датам", + DateOrders = GetDateOrders() }); } } diff --git a/LawFirm/LawFirmBusinessLogic/OfficePackage/AbstractSaveToPdf.cs b/LawFirm/LawFirmBusinessLogic/OfficePackage/AbstractSaveToPdf.cs index 4322a00..eff0ed0 100644 --- a/LawFirm/LawFirmBusinessLogic/OfficePackage/AbstractSaveToPdf.cs +++ b/LawFirm/LawFirmBusinessLogic/OfficePackage/AbstractSaveToPdf.cs @@ -56,16 +56,10 @@ namespace LawFirmBusinessLogic.OfficePackage Style = "NormalTitle", ParagraphAlignment = PdfParagraphAlignmentType.Center }); - CreateParagraph(new PdfParagraph - { - Text = $"с{info.DateFrom.ToShortDateString()} по {info.DateTo.ToShortDateString()}", - Style = "Normal", - ParagraphAlignment = PdfParagraphAlignmentType.Center - }); CreateTable(new List { "3cm", "3cm", "7cm" }); CreateRow(new PdfRowParameters { - Texts = new List { "Дата заказа", "Количество заказов", "Сумма" }, + Texts = new List { "Дата", "Количество", "Сумма" }, Style = "NormalTitle", ParagraphAlignment = PdfParagraphAlignmentType.Center }); @@ -82,7 +76,7 @@ namespace LawFirmBusinessLogic.OfficePackage { Text = $"Итого: {info.DateOrders.Sum(x => x.SumOrders)}\t", Style = "Normal", - ParagraphAlignment = PdfParagraphAlignmentType.Right + ParagraphAlignment = PdfParagraphAlignmentType.Center }); SavePdf(info); } diff --git a/LawFirm/LawFirmContracts/BusinessLogicContracts/IReportLogic.cs b/LawFirm/LawFirmContracts/BusinessLogicContracts/IReportLogic.cs index bd47c3c..17bff04 100644 --- a/LawFirm/LawFirmContracts/BusinessLogicContracts/IReportLogic.cs +++ b/LawFirm/LawFirmContracts/BusinessLogicContracts/IReportLogic.cs @@ -24,7 +24,7 @@ namespace LawFirmContracts.BusinessLogicContracts void SaveShopsToWordFile(ReportBindingModel model); void SaveShopDocumentsToExcelFile(ReportBindingModel model); List GetShopDocuments(); - List GetDateOrders(ReportBindingModel model); + List GetDateOrders(); void SaveDateOrdersToPdfFile(ReportBindingModel model); } } -- 2.25.1 From 994595ddd54a9d4dae751617b620be7c3ac7dfcc Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Fri, 7 Apr 2023 15:50:09 +0400 Subject: [PATCH 16/16] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/ReportLogic.cs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/LawFirm/LawFirmBusinessLogic/BusinessLogics/ReportLogic.cs b/LawFirm/LawFirmBusinessLogic/BusinessLogics/ReportLogic.cs index fdebf7e..7e531af 100644 --- a/LawFirm/LawFirmBusinessLogic/BusinessLogics/ReportLogic.cs +++ b/LawFirm/LawFirmBusinessLogic/BusinessLogics/ReportLogic.cs @@ -33,7 +33,6 @@ namespace LawFirmBusinessLogic.BusinessLogics /// Получение списка компонент с указанием, в каких изделиях используются public List GetDocumentBlanks() { - var blanks = _blankStorage.GetFullList(); var documents = _documentStorage.GetFullList(); var list = new List(); foreach (var doc in documents) @@ -44,13 +43,11 @@ namespace LawFirmBusinessLogic.BusinessLogics Blanks = new List<(string Blank, int Count)>(), TotalCount = 0 }; - foreach (var blank in blanks) + foreach (var blank in doc.DocumentBlanks.Values) { - if (doc.DocumentBlanks.ContainsKey(blank.Id)) - { - record.Blanks.Add(new (blank.BlankName, doc.DocumentBlanks[blank.Id].Item2)); - record.TotalCount += doc.DocumentBlanks[blank.Id].Item2; - } + record.Blanks.Add((blank.Item1.BlankName, blank.Item2)); + record.TotalCount += blank.Item2; + } list.Add(record); } -- 2.25.1