From 061c030460a2ba1778e70a9a2d75590174ae00af Mon Sep 17 00:00:00 2001 From: ValAnn Date: Mon, 8 Apr 2024 00:10:47 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BA=D0=BE=D0=BC=D0=BF=D0=BB=D0=B8=D1=82,=20?= =?UTF-8?q?=D0=BD=D0=BE=20=D0=BA=D0=B0=D0=BA=D0=BE=D0=B9=20=D1=86=D0=B5?= =?UTF-8?q?=D0=BD=D0=BE=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../OfficePackage/AbstractSaveToExcel.cs | 42 ++- .../OfficePackage/AbstractSaveToPdf.cs | 60 +++- .../OfficePackage/AbstractSaveToWord.cs | 33 +- .../HelperEnums/ExcelStyleInfoType.cs | 8 +- .../HelperEnums/PdfParagraphAlignmentType.cs | 2 +- .../HelperEnums/WordJustificationType.cs | 8 +- .../HelperModels/ExcelCellParameters.cs | 1 + .../OfficePackage/HelperModels/ExcelInfo.cs | 7 +- .../HelperModels/ExcelMergeParameters.cs | 9 +- .../OfficePackage/HelperModels/PdfInfo.cs | 8 + .../HelperModels/PdfParagraph.cs | 6 + .../HelperModels/PdfRowParameters.cs | 5 + .../OfficePackage/HelperModels/WordInfo.cs | 1 + .../HelperModels/WordParagraph.cs | 8 +- .../HelperModels/WordTextProperties.cs | 1 + .../OfficePackage/Implements/SaveToExcel.cs | 217 ++++++++----- .../OfficePackage/Implements/SaveToPdf.cs | 21 +- .../OfficePackage/Implements/SaveToWord.cs | 53 +-- .../SushiBarBusinessLogic.csproj | 2 +- SushiBar/SushiBarView/FormMain.cs | 1 + .../SushiBarView/FormReportOrders.Designer.cs | 146 +++++---- SushiBar/SushiBarView/FormReportOrders.cs | 43 +-- SushiBar/SushiBarView/FormReportOrders.resx | 50 +-- SushiBar/SushiBarView/Program.cs | 1 + .../{Report.rdlc => ReportOrders.rdlc} | 306 ++++++++++-------- 25 files changed, 597 insertions(+), 442 deletions(-) rename SushiBar/SushiBarView/{Report.rdlc => ReportOrders.rdlc} (86%) diff --git a/SushiBar/SushiBarBusinessLogic_/OfficePackage/AbstractSaveToExcel.cs b/SushiBar/SushiBarBusinessLogic_/OfficePackage/AbstractSaveToExcel.cs index 026430f..7c71989 100644 --- a/SushiBar/SushiBarBusinessLogic_/OfficePackage/AbstractSaveToExcel.cs +++ b/SushiBar/SushiBarBusinessLogic_/OfficePackage/AbstractSaveToExcel.cs @@ -13,7 +13,6 @@ namespace SushiBarBusinessLogic.OfficePackage public void CreateReport(ExcelInfo info) { CreateExcel(info); - InsertCellInWorksheet(new ExcelCellParameters { ColumnName = "A", @@ -21,46 +20,40 @@ namespace SushiBarBusinessLogic.OfficePackage Text = info.Title, StyleInfo = ExcelStyleInfoType.Title }); - MergeCells(new ExcelMergeParameters { CellFromName = "A1", CellToName = "C1" }); - uint rowIndex = 2; - foreach (var pc in info.SushiComponents) + foreach (var sc in info.SushiComponents) { InsertCellInWorksheet(new ExcelCellParameters { ColumnName = "A", RowIndex = rowIndex, - Text = pc.SushiName, + Text = sc.SushiName, StyleInfo = ExcelStyleInfoType.Text }); rowIndex++; - - foreach (var (Component, Count) in pc.Components) + foreach (var component in sc.Components) { InsertCellInWorksheet(new ExcelCellParameters { ColumnName = "B", RowIndex = rowIndex, - Text = Component, + Text = component.Item1, StyleInfo = ExcelStyleInfoType.TextWithBroder }); - InsertCellInWorksheet(new ExcelCellParameters { ColumnName = "C", RowIndex = rowIndex, - Text = Count.ToString(), + Text = component.Item2.ToString(), StyleInfo = ExcelStyleInfoType.TextWithBroder }); - rowIndex++; } - InsertCellInWorksheet(new ExcelCellParameters { ColumnName = "A", @@ -72,18 +65,33 @@ namespace SushiBarBusinessLogic.OfficePackage { ColumnName = "C", RowIndex = rowIndex, - Text = pc.TotalCount.ToString(), + Text = sc.TotalCount.ToString(), StyleInfo = ExcelStyleInfoType.Text }); rowIndex++; } - SaveExcel(info); } + /// + /// Создание excel-файла + /// + /// protected abstract void CreateExcel(ExcelInfo info); - protected abstract void InsertCellInWorksheet(ExcelCellParameters excelParams); + /// + /// Добавляем новую ячейку в лист + /// + /// + protected abstract void InsertCellInWorksheet(ExcelCellParameters + excelParams); + /// + /// Объединение ячеек + /// + /// protected abstract void MergeCells(ExcelMergeParameters excelParams); + /// + /// Сохранение файла + /// + /// protected abstract void SaveExcel(ExcelInfo info); - -} + } } diff --git a/SushiBar/SushiBarBusinessLogic_/OfficePackage/AbstractSaveToPdf.cs b/SushiBar/SushiBarBusinessLogic_/OfficePackage/AbstractSaveToPdf.cs index 6dd769f..b3f0d21 100644 --- a/SushiBar/SushiBarBusinessLogic_/OfficePackage/AbstractSaveToPdf.cs +++ b/SushiBar/SushiBarBusinessLogic_/OfficePackage/AbstractSaveToPdf.cs @@ -1,10 +1,10 @@ -using System; +using SushiBarBusinessLogic.OfficePackage.HelperEnums; +using SushiBarBusinessLogic.OfficePackage.HelperModels; +using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -using SushiBarBusinessLogic.OfficePackage.HelperEnums; -using SushiBarBusinessLogic.OfficePackage.HelperModels; namespace SushiBarBusinessLogic.OfficePackage { @@ -13,35 +13,67 @@ namespace SushiBarBusinessLogic.OfficePackage public void CreateDoc(PdfInfo info) { CreatePdf(info); - CreateParagraph(new PdfParagraph { Text = info.Title, Style = "NormalTitle", ParagraphAlignment = PdfParagraphAlignmentType.Center }); - CreateParagraph(new PdfParagraph { Text = $"с {info.DateFrom.ToShortDateString()} по {info.DateTo.ToShortDateString()}", Style = "Normal", ParagraphAlignment = PdfParagraphAlignmentType.Center }); - - CreateTable(new List { "2cm", "3cm", "6cm", "3cm", "3cm" }); - - CreateRow(new PdfRowParameters + CreateParagraph(new PdfParagraph { - Texts = new List { "Номер", "Дата заказа", "Пицца", "Статус", "Сумма" }, + 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 { "1cm", "3cm", "4cm", "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.SushiName, order.Status.ToString(), order.Sum.ToString() }, + Texts = new List { order.Id.ToString(), order.DateCreate.ToShortDateString(), order.Status.ToString(), order.SushiName, order.Sum.ToString() }, Style = "Normal", ParagraphAlignment = PdfParagraphAlignmentType.Left }); } - CreateParagraph(new PdfParagraph { Text = $"Итого: {info.Orders.Sum(x => x.Sum)}\t", Style = "Normal", ParagraphAlignment = PdfParagraphAlignmentType.Rigth }); - + CreateParagraph(new PdfParagraph + { + Text = $"Итого: {info.Orders.Sum(x => x.Sum)}\t", + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Rigth + }); SavePdf(info); } + /// + /// Создание doc-файла + /// + /// protected abstract void CreatePdf(PdfInfo info); + /// + /// Создание параграфа с текстом + /// + /// + /// protected abstract void CreateParagraph(PdfParagraph paragraph); + /// + /// Создание таблицы + /// + /// + /// protected abstract void CreateTable(List columns); + /// + /// Создание и заполнение строки + /// + /// protected abstract void CreateRow(PdfRowParameters rowParameters); + /// + /// Сохранение файла + /// + /// protected abstract void SavePdf(PdfInfo info); } } diff --git a/SushiBar/SushiBarBusinessLogic_/OfficePackage/AbstractSaveToWord.cs b/SushiBar/SushiBarBusinessLogic_/OfficePackage/AbstractSaveToWord.cs index 40a8cf5..bd162a0 100644 --- a/SushiBar/SushiBarBusinessLogic_/OfficePackage/AbstractSaveToWord.cs +++ b/SushiBar/SushiBarBusinessLogic_/OfficePackage/AbstractSaveToWord.cs @@ -1,10 +1,5 @@ using SushiBarBusinessLogic.OfficePackage.HelperEnums; using SushiBarBusinessLogic.OfficePackage.HelperModels; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace SushiBarBusinessLogic.OfficePackage { @@ -13,25 +8,27 @@ namespace SushiBarBusinessLogic.OfficePackage public void CreateDoc(WordInfo info) { CreateWord(info); - CreateParagraph(new WordParagraph { - Texts = new List<(string, WordTextProperties)> { (info.Title, new WordTextProperties { Bold = true, Size = "24", }) }, + Texts = new List<(string, WordTextProperties)> + { + (info.Title, new WordTextProperties { Bold = true, Size = "24", }) + }, TextProperties = new WordTextProperties { Size = "24", JustificationType = WordJustificationType.Center } }); - foreach (var sushi in info.Sushis) { CreateParagraph(new WordParagraph { Texts = new List<(string, WordTextProperties)> { - (sushi.SushiName, new WordTextProperties { Size = "24", Bold = true}), - ("\t"+sushi.Price.ToString(), new WordTextProperties{Size = "24"}) + (sushi.SushiName, new WordTextProperties { Bold = true, Size = "24", }), + (" цена: " + sushi.Price.ToString() + " рублей", new WordTextProperties { Size = "24", }) }, + TextProperties = new WordTextProperties { Size = "24", @@ -39,11 +36,23 @@ namespace SushiBarBusinessLogic.OfficePackage } }); } - SaveWord(info); } + /// + /// Создание doc-файла + /// + /// protected abstract void CreateWord(WordInfo info); + /// + /// Создание абзаца с текстом + /// + /// + /// protected abstract void CreateParagraph(WordParagraph paragraph); + /// + /// Сохранение файла + /// + /// protected abstract void SaveWord(WordInfo info); } -} +} \ No newline at end of file diff --git a/SushiBar/SushiBarBusinessLogic_/OfficePackage/HelperEnums/ExcelStyleInfoType.cs b/SushiBar/SushiBarBusinessLogic_/OfficePackage/HelperEnums/ExcelStyleInfoType.cs index 50be760..22ada14 100644 --- a/SushiBar/SushiBarBusinessLogic_/OfficePackage/HelperEnums/ExcelStyleInfoType.cs +++ b/SushiBar/SushiBarBusinessLogic_/OfficePackage/HelperEnums/ExcelStyleInfoType.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace SushiBarBusinessLogic.OfficePackage.HelperEnums +namespace SushiBarBusinessLogic.OfficePackage.HelperEnums { public enum ExcelStyleInfoType { diff --git a/SushiBar/SushiBarBusinessLogic_/OfficePackage/HelperEnums/PdfParagraphAlignmentType.cs b/SushiBar/SushiBarBusinessLogic_/OfficePackage/HelperEnums/PdfParagraphAlignmentType.cs index ab20545..375e74d 100644 --- a/SushiBar/SushiBarBusinessLogic_/OfficePackage/HelperEnums/PdfParagraphAlignmentType.cs +++ b/SushiBar/SushiBarBusinessLogic_/OfficePackage/HelperEnums/PdfParagraphAlignmentType.cs @@ -12,4 +12,4 @@ namespace SushiBarBusinessLogic.OfficePackage.HelperEnums Left, Rigth } -} +} \ No newline at end of file diff --git a/SushiBar/SushiBarBusinessLogic_/OfficePackage/HelperEnums/WordJustificationType.cs b/SushiBar/SushiBarBusinessLogic_/OfficePackage/HelperEnums/WordJustificationType.cs index ae18d29..5f68ea2 100644 --- a/SushiBar/SushiBarBusinessLogic_/OfficePackage/HelperEnums/WordJustificationType.cs +++ b/SushiBar/SushiBarBusinessLogic_/OfficePackage/HelperEnums/WordJustificationType.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace SushiBarBusinessLogic.OfficePackage.HelperEnums +namespace SushiBarBusinessLogic.OfficePackage.HelperEnums { public enum WordJustificationType { diff --git a/SushiBar/SushiBarBusinessLogic_/OfficePackage/HelperModels/ExcelCellParameters.cs b/SushiBar/SushiBarBusinessLogic_/OfficePackage/HelperModels/ExcelCellParameters.cs index bc0514d..ffc846d 100644 --- a/SushiBar/SushiBarBusinessLogic_/OfficePackage/HelperModels/ExcelCellParameters.cs +++ b/SushiBar/SushiBarBusinessLogic_/OfficePackage/HelperModels/ExcelCellParameters.cs @@ -9,5 +9,6 @@ namespace SushiBarBusinessLogic.OfficePackage.HelperModels public string Text { get; set; } = string.Empty; public string CellReference => $"{ColumnName}{RowIndex}"; public ExcelStyleInfoType StyleInfo { get; set; } + } } diff --git a/SushiBar/SushiBarBusinessLogic_/OfficePackage/HelperModels/ExcelInfo.cs b/SushiBar/SushiBarBusinessLogic_/OfficePackage/HelperModels/ExcelInfo.cs index 4f7906e..d9b69b4 100644 --- a/SushiBar/SushiBarBusinessLogic_/OfficePackage/HelperModels/ExcelInfo.cs +++ b/SushiBar/SushiBarBusinessLogic_/OfficePackage/HelperModels/ExcelInfo.cs @@ -6,6 +6,11 @@ namespace SushiBarBusinessLogic.OfficePackage.HelperModels { public string FileName { get; set; } = string.Empty; public string Title { get; set; } = string.Empty; - public List SushiComponents { get; set; } = new(); + public List SushiComponents + { + get; + set; + } = new(); + } } diff --git a/SushiBar/SushiBarBusinessLogic_/OfficePackage/HelperModels/ExcelMergeParameters.cs b/SushiBar/SushiBarBusinessLogic_/OfficePackage/HelperModels/ExcelMergeParameters.cs index 9063db8..c3effa3 100644 --- a/SushiBar/SushiBarBusinessLogic_/OfficePackage/HelperModels/ExcelMergeParameters.cs +++ b/SushiBar/SushiBarBusinessLogic_/OfficePackage/HelperModels/ExcelMergeParameters.cs @@ -1,9 +1,16 @@ -namespace SushiBarBusinessLogic.OfficePackage.HelperModels +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SushiBarBusinessLogic.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/SushiBar/SushiBarBusinessLogic_/OfficePackage/HelperModels/PdfInfo.cs b/SushiBar/SushiBarBusinessLogic_/OfficePackage/HelperModels/PdfInfo.cs index 9bc8648..bf4b058 100644 --- a/SushiBar/SushiBarBusinessLogic_/OfficePackage/HelperModels/PdfInfo.cs +++ b/SushiBar/SushiBarBusinessLogic_/OfficePackage/HelperModels/PdfInfo.cs @@ -1,4 +1,10 @@ using SushiBarContracts.ViewModels; +using SushiBarDataModels.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; namespace SushiBarBusinessLogic.OfficePackage.HelperModels { @@ -8,6 +14,8 @@ namespace SushiBarBusinessLogic.OfficePackage.HelperModels public string Title { get; set; } = string.Empty; public DateTime DateFrom { get; set; } public DateTime DateTo { get; set; } + public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; public List Orders { get; set; } = new(); + } } diff --git a/SushiBar/SushiBarBusinessLogic_/OfficePackage/HelperModels/PdfParagraph.cs b/SushiBar/SushiBarBusinessLogic_/OfficePackage/HelperModels/PdfParagraph.cs index c94387d..4b588c7 100644 --- a/SushiBar/SushiBarBusinessLogic_/OfficePackage/HelperModels/PdfParagraph.cs +++ b/SushiBar/SushiBarBusinessLogic_/OfficePackage/HelperModels/PdfParagraph.cs @@ -1,4 +1,9 @@ using SushiBarBusinessLogic.OfficePackage.HelperEnums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; namespace SushiBarBusinessLogic.OfficePackage.HelperModels { @@ -7,5 +12,6 @@ namespace SushiBarBusinessLogic.OfficePackage.HelperModels public string Text { get; set; } = string.Empty; public string Style { get; set; } = string.Empty; public PdfParagraphAlignmentType ParagraphAlignment { get; set; } + } } diff --git a/SushiBar/SushiBarBusinessLogic_/OfficePackage/HelperModels/PdfRowParameters.cs b/SushiBar/SushiBarBusinessLogic_/OfficePackage/HelperModels/PdfRowParameters.cs index 9611ed6..ddf051f 100644 --- a/SushiBar/SushiBarBusinessLogic_/OfficePackage/HelperModels/PdfRowParameters.cs +++ b/SushiBar/SushiBarBusinessLogic_/OfficePackage/HelperModels/PdfRowParameters.cs @@ -1,4 +1,9 @@ using SushiBarBusinessLogic.OfficePackage.HelperEnums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; namespace SushiBarBusinessLogic.OfficePackage.HelperModels { diff --git a/SushiBar/SushiBarBusinessLogic_/OfficePackage/HelperModels/WordInfo.cs b/SushiBar/SushiBarBusinessLogic_/OfficePackage/HelperModels/WordInfo.cs index ae065d8..472a5aa 100644 --- a/SushiBar/SushiBarBusinessLogic_/OfficePackage/HelperModels/WordInfo.cs +++ b/SushiBar/SushiBarBusinessLogic_/OfficePackage/HelperModels/WordInfo.cs @@ -7,5 +7,6 @@ namespace SushiBarBusinessLogic.OfficePackage.HelperModels public string FileName { get; set; } = string.Empty; public string Title { get; set; } = string.Empty; public List Sushis { get; set; } = new(); + } } diff --git a/SushiBar/SushiBarBusinessLogic_/OfficePackage/HelperModels/WordParagraph.cs b/SushiBar/SushiBarBusinessLogic_/OfficePackage/HelperModels/WordParagraph.cs index 8b322ab..e6e48c1 100644 --- a/SushiBar/SushiBarBusinessLogic_/OfficePackage/HelperModels/WordParagraph.cs +++ b/SushiBar/SushiBarBusinessLogic_/OfficePackage/HelperModels/WordParagraph.cs @@ -1,4 +1,10 @@ -namespace SushiBarBusinessLogic.OfficePackage.HelperModels +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SushiBarBusinessLogic.OfficePackage.HelperModels { public class WordParagraph { diff --git a/SushiBar/SushiBarBusinessLogic_/OfficePackage/HelperModels/WordTextProperties.cs b/SushiBar/SushiBarBusinessLogic_/OfficePackage/HelperModels/WordTextProperties.cs index 0aa9cf0..ed56373 100644 --- a/SushiBar/SushiBarBusinessLogic_/OfficePackage/HelperModels/WordTextProperties.cs +++ b/SushiBar/SushiBarBusinessLogic_/OfficePackage/HelperModels/WordTextProperties.cs @@ -7,5 +7,6 @@ namespace SushiBarBusinessLogic.OfficePackage.HelperModels public string Size { get; set; } = string.Empty; public bool Bold { get; set; } public WordJustificationType JustificationType { get; set; } + } } diff --git a/SushiBar/SushiBarBusinessLogic_/OfficePackage/Implements/SaveToExcel.cs b/SushiBar/SushiBarBusinessLogic_/OfficePackage/Implements/SaveToExcel.cs index f840fb7..99c7ee3 100644 --- a/SushiBar/SushiBarBusinessLogic_/OfficePackage/Implements/SaveToExcel.cs +++ b/SushiBar/SushiBarBusinessLogic_/OfficePackage/Implements/SaveToExcel.cs @@ -1,11 +1,11 @@ using DocumentFormat.OpenXml.Office2010.Excel; using DocumentFormat.OpenXml.Office2013.Excel; +using DocumentFormat.OpenXml.Office2016.Excel; using DocumentFormat.OpenXml.Packaging; using DocumentFormat.OpenXml.Spreadsheet; using DocumentFormat.OpenXml; using SushiBarBusinessLogic.OfficePackage.HelperEnums; using SushiBarBusinessLogic.OfficePackage.HelperModels; -using SushiBarBusinessLogic.OfficePackage; namespace SushiBarBusinessLogic.OfficePackage.Implements { @@ -14,110 +14,167 @@ namespace SushiBarBusinessLogic.OfficePackage.Implements 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 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 }); - 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 }); - + 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 }); - + 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 }); - + 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 }; - + 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 }; - + 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 }; - 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 tableStyles = new TableStyles() + { + Count = 0U, + DefaultTableStyle = "TableStyleMedium2", + DefaultPivotStyle = "PivotStyleLight16" + }; var stylesheetExtensionList = new StylesheetExtensionList(); - - var stylesheetExtension1 = new StylesheetExtension() { Uri = "{EB79DEF2-80B8-43e5-95BD-54CBDDF9020C}" }; + 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}" }; + 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" }); - + stylesheetExtension2.Append(new TimelineStyles() + { + DefaultTimelineStyle = "TimeSlicerStyleLight1" + }); stylesheetExtensionList.Append(stylesheetExtension1); stylesheetExtensionList.Append(stylesheetExtension2); - sp.Stylesheet.Append(fonts); sp.Stylesheet.Append(fills); sp.Stylesheet.Append(borders); @@ -128,7 +185,11 @@ namespace SushiBarBusinessLogic.OfficePackage.Implements sp.Stylesheet.Append(tableStyles); sp.Stylesheet.Append(stylesheetExtensionList); } - + /// + /// Получение номера стиля из типа + /// + /// + /// private static uint GetStyleValue(ExcelStyleInfoType styleInfo) { return styleInfo switch @@ -139,44 +200,40 @@ namespace SushiBarBusinessLogic.OfficePackage.Implements _ => 0U, }; } - protected override void CreateExcel(ExcelInfo info) { - _spreadsheetDocument = SpreadsheetDocument.Create(info.FileName, SpreadsheetDocumentType.Workbook); - // Создаем книгу (в ней хранятся листы) + _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(); - + _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 sheets = + _spreadsheetDocument.WorkbookPart.Workbook.AppendChild(new Sheets()); var sheet = new Sheet() { - Id = _spreadsheetDocument.WorkbookPart.GetIdOfPart(worksheetPart), + 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) @@ -188,7 +245,6 @@ namespace SushiBarBusinessLogic.OfficePackage.Implements { return; } - // Ищем строку, либо добавляем ее Row row; if (sheetData.Elements().Where(r => r.RowIndex! == excelParams.RowIndex).Any()) @@ -200,8 +256,7 @@ namespace SushiBarBusinessLogic.OfficePackage.Implements row = new Row() { RowIndex = excelParams.RowIndex }; sheetData.Append(row); } - - // Ищем нужную ячейку + // Ищем нужную ячейку Cell cell; if (row.Elements().Where(c => c.CellReference!.Value == excelParams.CellReference).Any()) { @@ -220,22 +275,20 @@ namespace SushiBarBusinessLogic.OfficePackage.Implements break; } } - - var newCell = new Cell() { CellReference = excelParams.CellReference }; + 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) @@ -243,7 +296,6 @@ namespace SushiBarBusinessLogic.OfficePackage.Implements return; } MergeCells mergeCells; - if (_worksheet.Elements().Any()) { mergeCells = _worksheet.Elements().First(); @@ -251,24 +303,23 @@ namespace SushiBarBusinessLogic.OfficePackage.Implements else { mergeCells = new MergeCells(); - if (_worksheet.Elements().Any()) { - _worksheet.InsertAfter(mergeCells, _worksheet.Elements().First()); + _worksheet.InsertAfter(mergeCells, + _worksheet.Elements().First()); } else { - _worksheet.InsertAfter(mergeCells, _worksheet.Elements().First()); + _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) diff --git a/SushiBar/SushiBarBusinessLogic_/OfficePackage/Implements/SaveToPdf.cs b/SushiBar/SushiBarBusinessLogic_/OfficePackage/Implements/SaveToPdf.cs index 74c27ee..a5840f7 100644 --- a/SushiBar/SushiBarBusinessLogic_/OfficePackage/Implements/SaveToPdf.cs +++ b/SushiBar/SushiBarBusinessLogic_/OfficePackage/Implements/SaveToPdf.cs @@ -1,7 +1,6 @@ using MigraDoc.DocumentObjectModel; using MigraDoc.DocumentObjectModel.Tables; using MigraDoc.Rendering; -using SushiBarBusinessLogic.OfficePackage; using SushiBarBusinessLogic.OfficePackage.HelperEnums; using SushiBarBusinessLogic.OfficePackage.HelperModels; @@ -12,7 +11,6 @@ namespace SushiBarBusinessLogic.OfficePackage.Implements private Document? _document; private Section? _section; private Table? _table; - private static ParagraphAlignment GetParagraphAlignment(PdfParagraphAlignmentType type) { return type switch @@ -23,25 +21,24 @@ namespace SushiBarBusinessLogic.OfficePackage.Implements _ => 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) @@ -53,7 +50,6 @@ namespace SushiBarBusinessLogic.OfficePackage.Implements paragraph.Format.Alignment = GetParagraphAlignment(pdfParagraph.ParagraphAlignment); paragraph.Style = pdfParagraph.Style; } - protected override void CreateTable(List columns) { if (_document == null) @@ -61,13 +57,11 @@ namespace SushiBarBusinessLogic.OfficePackage.Implements return; } _table = _document.LastSection.AddTable(); - foreach (var elem in columns) { _table.AddColumn(elem); } } - protected override void CreateRow(PdfRowParameters rowParameters) { if (_table == null) @@ -78,24 +72,19 @@ namespace SushiBarBusinessLogic.OfficePackage.Implements 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) @@ -106,4 +95,4 @@ namespace SushiBarBusinessLogic.OfficePackage.Implements renderer.PdfDocument.Save(info.FileName); } } -} +} \ No newline at end of file diff --git a/SushiBar/SushiBarBusinessLogic_/OfficePackage/Implements/SaveToWord.cs b/SushiBar/SushiBarBusinessLogic_/OfficePackage/Implements/SaveToWord.cs index f3b14fe..6c1fc93 100644 --- a/SushiBar/SushiBarBusinessLogic_/OfficePackage/Implements/SaveToWord.cs +++ b/SushiBar/SushiBarBusinessLogic_/OfficePackage/Implements/SaveToWord.cs @@ -1,9 +1,9 @@ -using DocumentFormat.OpenXml; +using SushiBarBusinessLogic.OfficePackage.HelperEnums; +using SushiBarBusinessLogic.OfficePackage.HelperModels; +using DocumentFormat.OpenXml; using DocumentFormat.OpenXml.Packaging; using DocumentFormat.OpenXml.Wordprocessing; -using SushiBarBusinessLogic.OfficePackage; -using SushiBarBusinessLogic.OfficePackage.HelperEnums; -using SushiBarBusinessLogic.OfficePackage.HelperModels; + namespace SushiBarBusinessLogic.OfficePackage.Implements { @@ -11,8 +11,13 @@ namespace SushiBarBusinessLogic.OfficePackage.Implements { private WordprocessingDocument? _wordDocument; private Body? _docBody; - - private static JustificationValues GetJustificationValues(WordJustificationType type) + /// + /// Получение типа выравнивания + /// + /// + /// + private static JustificationValues + GetJustificationValues(WordJustificationType type) { return type switch { @@ -21,47 +26,50 @@ namespace SushiBarBusinessLogic.OfficePackage.Implements _ => 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 }); + paragraphMarkRunProperties.AppendChild(new FontSize + { + Val = paragraphProperties.Size + }); } properties.AppendChild(paragraphMarkRunProperties); - return properties; } protected override void CreateWord(WordInfo info) @@ -80,11 +88,9 @@ namespace SushiBarBusinessLogic.OfficePackage.Implements 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) @@ -92,12 +98,13 @@ namespace SushiBarBusinessLogic.OfficePackage.Implements properties.AppendChild(new Bold()); } docRun.AppendChild(properties); - - docRun.AppendChild(new Text { Text = run.Item1, Space = SpaceProcessingModeValues.Preserve }); - + docRun.AppendChild(new Text + { + Text = run.Item1, + Space = SpaceProcessingModeValues.Preserve + }); docParagraph.AppendChild(docRun); } - _docBody.AppendChild(docParagraph); } protected override void SaveWord(WordInfo info) @@ -107,9 +114,7 @@ namespace SushiBarBusinessLogic.OfficePackage.Implements return; } _docBody.AppendChild(CreateSectionProperties()); - _wordDocument.MainDocumentPart!.Document.Save(); - _wordDocument.Dispose(); } } diff --git a/SushiBar/SushiBarBusinessLogic_/SushiBarBusinessLogic.csproj b/SushiBar/SushiBarBusinessLogic_/SushiBarBusinessLogic.csproj index a9150b5..003eae4 100644 --- a/SushiBar/SushiBarBusinessLogic_/SushiBarBusinessLogic.csproj +++ b/SushiBar/SushiBarBusinessLogic_/SushiBarBusinessLogic.csproj @@ -15,7 +15,7 @@ runtime; build; native; contentfiles; analyzers; buildtransitive - + diff --git a/SushiBar/SushiBarView/FormMain.cs b/SushiBar/SushiBarView/FormMain.cs index 9ce5e68..17856df 100644 --- a/SushiBar/SushiBarView/FormMain.cs +++ b/SushiBar/SushiBarView/FormMain.cs @@ -11,6 +11,7 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using Microsoft.Extensions.DependencyInjection; +using SushiBarView.Reports; namespace SushiBarView { diff --git a/SushiBar/SushiBarView/FormReportOrders.Designer.cs b/SushiBar/SushiBarView/FormReportOrders.Designer.cs index b99e59f..5de5bb9 100644 --- a/SushiBar/SushiBarView/FormReportOrders.Designer.cs +++ b/SushiBar/SushiBarView/FormReportOrders.Designer.cs @@ -1,4 +1,4 @@ -namespace SushiBarView +namespace SushiBarView.Reports { partial class FormReportOrders { @@ -28,104 +28,102 @@ /// private void InitializeComponent() { - this.panel = new System.Windows.Forms.Panel(); - this.labelFrom = new System.Windows.Forms.Label(); - this.dateTimePickerFrom = new System.Windows.Forms.DateTimePicker(); - this.dateTimePickerTo = new System.Windows.Forms.DateTimePicker(); - this.labelTo = new System.Windows.Forms.Label(); - this.buttonMake = new System.Windows.Forms.Button(); - this.buttonToPDF = new System.Windows.Forms.Button(); - this.panel.SuspendLayout(); - this.SuspendLayout(); + panel = new Panel(); + labelFrom = new Label(); + buttonToPdf = new Button(); + dateTimePickerDateFrom = new DateTimePicker(); + labelTo = new Label(); + dateTimePickerDateTo = new DateTimePicker(); + buttonMake = new Button(); + panel.SuspendLayout(); + SuspendLayout(); // // panel // - this.panel.Controls.Add(this.buttonToPDF); - this.panel.Controls.Add(this.buttonMake); - this.panel.Controls.Add(this.dateTimePickerTo); - this.panel.Controls.Add(this.labelTo); - this.panel.Controls.Add(this.dateTimePickerFrom); - this.panel.Controls.Add(this.labelFrom); - this.panel.Dock = System.Windows.Forms.DockStyle.Top; - this.panel.Location = new System.Drawing.Point(0, 0); - this.panel.Name = "panel"; - this.panel.Size = new System.Drawing.Size(958, 52); - this.panel.TabIndex = 0; + panel.Controls.Add(labelFrom); + panel.Controls.Add(buttonToPdf); + panel.Controls.Add(dateTimePickerDateFrom); + panel.Controls.Add(labelTo); + panel.Controls.Add(dateTimePickerDateTo); + panel.Controls.Add(buttonMake); + panel.Dock = DockStyle.Top; + panel.Location = new Point(0, 0); + panel.Name = "panel"; + panel.Size = new Size(1321, 71); + panel.TabIndex = 3; // // labelFrom // - this.labelFrom.AutoSize = true; - this.labelFrom.Location = new System.Drawing.Point(12, 14); - this.labelFrom.Name = "labelFrom"; - this.labelFrom.Size = new System.Drawing.Size(18, 20); - this.labelFrom.TabIndex = 0; - this.labelFrom.Text = "C"; + labelFrom.AutoSize = true; + labelFrom.Location = new Point(16, 31); + labelFrom.Name = "labelFrom"; + labelFrom.Size = new Size(18, 20); + labelFrom.TabIndex = 3; + labelFrom.Text = "С"; // - // dateTimePickerFrom + // buttonToPdf // - this.dateTimePickerFrom.Location = new System.Drawing.Point(36, 9); - this.dateTimePickerFrom.Name = "dateTimePickerFrom"; - this.dateTimePickerFrom.Size = new System.Drawing.Size(199, 27); - this.dateTimePickerFrom.TabIndex = 1; + buttonToPdf.Location = new Point(1200, 27); + buttonToPdf.Name = "buttonToPdf"; + buttonToPdf.Size = new Size(94, 29); + buttonToPdf.TabIndex = 4; + buttonToPdf.Text = "В PDF"; + buttonToPdf.UseVisualStyleBackColor = true; + buttonToPdf.Click += ButtonToPdf_Click; // - // dateTimePickerTo + // dateTimePickerDateFrom // - this.dateTimePickerTo.Location = new System.Drawing.Point(300, 9); - this.dateTimePickerTo.Name = "dateTimePickerTo"; - this.dateTimePickerTo.Size = new System.Drawing.Size(199, 27); - this.dateTimePickerTo.TabIndex = 3; + dateTimePickerDateFrom.Location = new Point(51, 27); + dateTimePickerDateFrom.Name = "dateTimePickerDateFrom"; + dateTimePickerDateFrom.Size = new Size(250, 27); + dateTimePickerDateFrom.TabIndex = 0; // // labelTo // - this.labelTo.AutoSize = true; - this.labelTo.Location = new System.Drawing.Point(254, 14); - this.labelTo.Name = "labelTo"; - this.labelTo.Size = new System.Drawing.Size(27, 20); - this.labelTo.TabIndex = 2; - this.labelTo.Text = "по"; + labelTo.AutoSize = true; + labelTo.Location = new Point(317, 31); + labelTo.Name = "labelTo"; + labelTo.Size = new Size(29, 20); + labelTo.TabIndex = 4; + labelTo.Text = "По"; + // + // dateTimePickerDateTo + // + dateTimePickerDateTo.Location = new Point(365, 27); + dateTimePickerDateTo.Name = "dateTimePickerDateTo"; + dateTimePickerDateTo.Size = new Size(250, 27); + dateTimePickerDateTo.TabIndex = 1; // // buttonMake // - this.buttonMake.Location = new System.Drawing.Point(542, 10); - this.buttonMake.Name = "buttonMake"; - this.buttonMake.Size = new System.Drawing.Size(165, 29); - this.buttonMake.TabIndex = 4; - this.buttonMake.Text = "Сформировать"; - this.buttonMake.UseVisualStyleBackColor = true; - this.buttonMake.Click += new System.EventHandler(this.ButtonMake_Click); - // - // buttonToPDF - // - this.buttonToPDF.Location = new System.Drawing.Point(781, 9); - this.buttonToPDF.Name = "buttonToPDF"; - this.buttonToPDF.Size = new System.Drawing.Size(165, 29); - this.buttonToPDF.TabIndex = 5; - this.buttonToPDF.Text = "В PDF"; - this.buttonToPDF.UseVisualStyleBackColor = true; - this.buttonToPDF.Click += new System.EventHandler(this.ButtonToPdf_Click); + buttonMake.Location = new Point(677, 27); + buttonMake.Name = "buttonMake"; + buttonMake.Size = new Size(132, 29); + buttonMake.TabIndex = 3; + buttonMake.Text = "Сформировать"; + buttonMake.UseVisualStyleBackColor = true; + buttonMake.Click += ButtonMake_Click; // // FormReportOrders // - this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(958, 450); - this.Controls.Add(this.panel); - this.Name = "FormReportOrders"; - this.Text = "Заказы"; - this.panel.ResumeLayout(false); - this.panel.PerformLayout(); - this.ResumeLayout(false); - + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1321, 450); + Controls.Add(panel); + Name = "FormReportOrders"; + Text = "FormReportOrders"; + panel.ResumeLayout(false); + panel.PerformLayout(); + ResumeLayout(false); } #endregion - private Panel panel; - private Button buttonToPDF; + private DateTimePicker dateTimePickerDateTo; + private DateTimePicker dateTimePickerDateFrom; private Button buttonMake; - private DateTimePicker dateTimePickerTo; + private Button buttonToPdf; private Label labelTo; - private DateTimePicker dateTimePickerFrom; private Label labelFrom; } } \ No newline at end of file diff --git a/SushiBar/SushiBarView/FormReportOrders.cs b/SushiBar/SushiBarView/FormReportOrders.cs index 67151d7..ab19a11 100644 --- a/SushiBar/SushiBarView/FormReportOrders.cs +++ b/SushiBar/SushiBarView/FormReportOrders.cs @@ -1,16 +1,15 @@ using Microsoft.Extensions.Logging; +using Microsoft.Reporting.WinForms; using SushiBarContracts.BindingModels; using SushiBarContracts.BusinessLogicsContracts; -using Microsoft.Reporting.WinForms; -namespace SushiBarView +namespace SushiBarView.Reports { public partial class FormReportOrders : Form { private readonly ReportViewer reportViewer; private readonly ILogger _logger; private readonly IReportLogic _logic; - public FormReportOrders(ILogger logger, IReportLogic logic) { InitializeComponent(); @@ -20,35 +19,36 @@ namespace SushiBarView { Dock = DockStyle.Fill }; - reportViewer.LocalReport.LoadReportDefinition(new FileStream("Report.rdlc", FileMode.Open)); + var path = Directory.GetParent(Directory.GetCurrentDirectory())?.Parent?.Parent?.ToString() + "\\ReportOrders.rdlc"; + reportViewer.LocalReport.LoadReportDefinition(new FileStream(path, FileMode.Open)); + //reportViewer.LocalReport.LoadReportDefinition(new FileStream("ReportOrders.rdlc", FileMode.Open)); Controls.Clear(); Controls.Add(reportViewer); Controls.Add(panel); } - private void ButtonMake_Click(object sender, EventArgs e) { - if (dateTimePickerFrom.Value.Date >= dateTimePickerTo.Value.Date) + if (dateTimePickerDateFrom.Value.Date >= dateTimePickerDateTo.Value.Date) { - MessageBox.Show("Дата начала должна быть меньше даты окончания", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show("Дата начала должна быть меньше даты окончания", + "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } try { var dataSource = _logic.GetOrders(new ReportBindingModel { - DateFrom = dateTimePickerFrom.Value, - DateTo = dateTimePickerTo.Value + DateFrom = dateTimePickerDateFrom.Value, + DateTo = dateTimePickerDateTo.Value }); var source = new ReportDataSource("DataSetOrders", dataSource); reportViewer.LocalReport.DataSources.Clear(); reportViewer.LocalReport.DataSources.Add(source); - var parameters = new[] { new ReportParameter("ReportParameterPeriod", - $"c {dateTimePickerFrom.Value.ToShortDateString()} по {dateTimePickerTo.Value.ToShortDateString()}") }; + var parameters = new[] { new ReportParameter("ReportParameterPeriod", $"c {dateTimePickerDateFrom.Value.ToShortDateString()} по {dateTimePickerDateTo.Value.ToShortDateString()}") }; reportViewer.LocalReport.SetParameters(parameters); - reportViewer.RefreshReport(); - _logger.LogInformation("Загрузка списка заказов на период {From}-{To}", dateTimePickerFrom.Value.ToShortDateString(), dateTimePickerTo.Value.ToShortDateString()); + _logger.LogInformation("Загрузка списка заказов на период {From}-{To}", + dateTimePickerDateFrom.Value.ToShortDateString(), dateTimePickerDateTo.Value.ToShortDateString()); } catch (Exception ex) { @@ -56,15 +56,17 @@ namespace SushiBarView MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } - private void ButtonToPdf_Click(object sender, EventArgs e) { - if (dateTimePickerFrom.Value.Date >= dateTimePickerTo.Value.Date) + if (dateTimePickerDateFrom.Value.Date >= dateTimePickerDateTo.Value.Date) { MessageBox.Show("Дата начала должна быть меньше даты окончания", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } - using var dialog = new SaveFileDialog { Filter = "pdf|*.pdf" }; + using var dialog = new SaveFileDialog + { + Filter = "pdf|*.pdf" + }; if (dialog.ShowDialog() == DialogResult.OK) { try @@ -72,10 +74,11 @@ namespace SushiBarView _logic.SaveOrdersToPdfFile(new ReportBindingModel { FileName = dialog.FileName, - DateFrom = dateTimePickerFrom.Value, - DateTo = dateTimePickerTo.Value + DateFrom = dateTimePickerDateFrom.Value, + DateTo = dateTimePickerDateTo.Value }); - _logger.LogInformation("Сохранение списка заказов на период {From}-{To}", dateTimePickerFrom.Value.ToShortDateString(), dateTimePickerTo.Value.ToShortDateString()); + _logger.LogInformation("Сохранение списка заказов на период {From}-{To} ", + dateTimePickerDateFrom.Value.ToShortDateString(), dateTimePickerDateTo.Value.ToShortDateString()); MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) @@ -86,4 +89,4 @@ namespace SushiBarView } } } -} +} \ No newline at end of file diff --git a/SushiBar/SushiBarView/FormReportOrders.resx b/SushiBar/SushiBarView/FormReportOrders.resx index 1af7de1..af32865 100644 --- a/SushiBar/SushiBarView/FormReportOrders.resx +++ b/SushiBar/SushiBarView/FormReportOrders.resx @@ -1,17 +1,17 @@  - diff --git a/SushiBar/SushiBarView/Program.cs b/SushiBar/SushiBarView/Program.cs index a6135f3..1682684 100644 --- a/SushiBar/SushiBarView/Program.cs +++ b/SushiBar/SushiBarView/Program.cs @@ -10,6 +10,7 @@ using NLog.Extensions.Logging; using SushiBarBusinessLogic.OfficePackage.Implements; using SushiBarBusinessLogic.OfficePackage; using SushiBarBusinessLogic; +using SushiBarView.Reports; namespace SushiBarView { diff --git a/SushiBar/SushiBarView/Report.rdlc b/SushiBar/SushiBarView/ReportOrders.rdlc similarity index 86% rename from SushiBar/SushiBarView/Report.rdlc rename to SushiBar/SushiBarView/ReportOrders.rdlc index acc2830..2c9708a 100644 --- a/SushiBar/SushiBarView/Report.rdlc +++ b/SushiBar/SushiBarView/ReportOrders.rdlc @@ -25,6 +25,10 @@ DateCreate System.DateTime + + Status + System.String + SushiName System.String @@ -33,10 +37,6 @@ Sum System.Decimal - - Status - System.String - SushiBarContracts.ViewModels @@ -49,15 +49,18 @@ - + true true - Заказы - - 0.6cm - 16.51cm + ReportParameterPeriod + 1cm + 1cm + 21cm @@ -78,15 +83,18 @@ 2pt - + true true - =Parameters!ReportParameterPeriod.Value - - ReportParameterPeriod - 0.6cm - 0.6cm - 16.51cm + 1cm + 21cm 1 - + - - 2.60583cm - - - 3.262cm - - - 4.8495cm - 2.5cm + + 3.21438cm + + + 4.21438cm + + + 7.23317cm + 2.5cm @@ -135,7 +141,7 @@ - + true true @@ -143,70 +149,15 @@ Номер - - - 2pt - 2pt - 2pt - 2pt - - - - - - - - true - true - - - - - Дата создания - - - 2pt - 2pt - 2pt - 2pt - - - - - - - - true - true - - - - - Пицца - + + + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + Суши + + + + + + 2pt + 2pt + 2pt + 2pt + + + + + + + true true @@ -260,12 +277,15 @@ Сумма - + + + + + 2pt + 2pt + 2pt + 2pt + + + true + + @@ -374,36 +429,6 @@ - - - - true - true - - - - - =Fields!Status.Value - - - 2pt - 2pt - 2pt - 2pt - - - - @@ -458,18 +483,18 @@ DataSetOrders - 1.9177cm - 0.79267cm + 2.48391cm + 0.55245cm 1.2cm - 15.71733cm + 20.66193cm 2 + - + true true @@ -477,7 +502,9 @@ Итого: - - 3.46287cm - 11.51cm + 4cm + 12cm 0.6cm 2.5cm 3 @@ -500,7 +527,7 @@ 2pt - + true true @@ -508,15 +535,18 @@ =Sum(Fields!Sum.Value, "DataSetOrders") - - - Textbox10 - 3.46287cm - 14.01cm + 4cm + 14.5cm 0.6cm 2.5cm 4 @@ -531,10 +561,10 @@ - 2in + 5.72875cm