From 801c2b0846c38bdf8d108d0bf689af4393e910f9 Mon Sep 17 00:00:00 2001 From: gg12 darfren Date: Sun, 24 Mar 2024 18:46:06 +0400 Subject: [PATCH] =?UTF-8?q?=D0=B1=D0=B5=D0=B7=20=D1=84=D0=BE=D1=80=D0=BC?= =?UTF-8?q?=D0=BE=D1=87=D0=BA=D0=B8=20=D0=BF=D0=B4=D1=84=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../IceCreamShop/MainForm.Designer.cs | 28 +++- IceCreamShop/IceCreamShop/MainForm.cs | 24 ++++ IceCreamShop/IceCreamShop/Program.cs | 1 + .../ReportShopsIceCreamsForm.Designer.cs | 103 ++++++++++++++ .../IceCreamShop/ReportShopsIceCreamsForm.cs | 93 +++++++++++++ .../ReportShopsIceCreamsForm.resx | 129 ++++++++++++++++++ .../BusinessLogic/ReportLogic.cs | 65 ++++++++- .../OfficePackage/AbstractSaveToExcel.cs | 64 +++++++++ .../OfficePackage/AbstractSaveToPdf.cs | 33 +++++ .../OfficePackage/AbstractSaveToWord.cs | 31 ++++- .../OfficePackage/HelperModels/ExcelInfo.cs | 6 +- .../OfficePackage/HelperModels/PdfInfo.cs | 1 + .../OfficePackage/HelperModels/WordInfo.cs | 1 + .../OfficePackage/HelperModels/WordTable.cs | 16 +++ .../OfficePackage/Implements/SaveToWord.cs | 77 +++++++++++ .../BusinessLogicsContracts/IReportLogic.cs | 5 + .../ViewModels/ReportDateOrdersViewModel.cs | 15 ++ .../ViewModels/ReportShopIceCreamViewModel.cs | 15 ++ 18 files changed, 703 insertions(+), 4 deletions(-) create mode 100644 IceCreamShop/IceCreamShop/ReportShopsIceCreamsForm.Designer.cs create mode 100644 IceCreamShop/IceCreamShop/ReportShopsIceCreamsForm.cs create mode 100644 IceCreamShop/IceCreamShop/ReportShopsIceCreamsForm.resx create mode 100644 IceCreamShop/IceCreamShopBusinessLogic/OfficePackage/HelperModels/WordTable.cs create mode 100644 IceCreamShop/IceCreamShopContracts/ViewModels/ReportDateOrdersViewModel.cs create mode 100644 IceCreamShop/IceCreamShopContracts/ViewModels/ReportShopIceCreamViewModel.cs diff --git a/IceCreamShop/IceCreamShop/MainForm.Designer.cs b/IceCreamShop/IceCreamShop/MainForm.Designer.cs index ec22665..42fbbd5 100644 --- a/IceCreamShop/IceCreamShop/MainForm.Designer.cs +++ b/IceCreamShop/IceCreamShop/MainForm.Designer.cs @@ -39,6 +39,9 @@ списокМороженногоToolStripMenuItem = new ToolStripMenuItem(); компонентыПоМороженнымToolStripMenuItem = new ToolStripMenuItem(); списокЗаказовToolStripMenuItem = new ToolStripMenuItem(); + списокМагазиновToolStripMenuItem = new ToolStripMenuItem(); + мороженноеПоМагазинамToolStripMenuItem = new ToolStripMenuItem(); + заказыПоДатамToolStripMenuItem = new ToolStripMenuItem(); DataGridView = new DataGridView(); CreateOrderButton = new Button(); TakeInWorkButton = new Button(); @@ -104,7 +107,7 @@ // // отчетыToolStripMenuItem // - отчетыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { списокМороженногоToolStripMenuItem, компонентыПоМороженнымToolStripMenuItem, списокЗаказовToolStripMenuItem }); + отчетыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { списокМороженногоToolStripMenuItem, компонентыПоМороженнымToolStripMenuItem, списокЗаказовToolStripMenuItem, списокМагазиновToolStripMenuItem, мороженноеПоМагазинамToolStripMenuItem, заказыПоДатамToolStripMenuItem }); отчетыToolStripMenuItem.Name = "отчетыToolStripMenuItem"; отчетыToolStripMenuItem.Size = new Size(73, 24); отчетыToolStripMenuItem.Text = "Отчеты"; @@ -130,6 +133,26 @@ списокЗаказовToolStripMenuItem.Text = "Список заказов"; списокЗаказовToolStripMenuItem.Click += списокЗаказовToolStripMenuItem_Click; // + // списокМагазиновToolStripMenuItem + // + списокМагазиновToolStripMenuItem.Name = "списокМагазиновToolStripMenuItem"; + списокМагазиновToolStripMenuItem.Size = new Size(305, 26); + списокМагазиновToolStripMenuItem.Text = "Список магазинов"; + списокМагазиновToolStripMenuItem.Click += списокМагазиновToolStripMenuItem_Click; + // + // мороженноеПоМагазинамToolStripMenuItem + // + мороженноеПоМагазинамToolStripMenuItem.Name = "мороженноеПоМагазинамToolStripMenuItem"; + мороженноеПоМагазинамToolStripMenuItem.Size = new Size(305, 26); + мороженноеПоМагазинамToolStripMenuItem.Text = "Мороженное по магазинам"; + мороженноеПоМагазинамToolStripMenuItem.Click += мороженноеПоМагазинамToolStripMenuItem_Click; + // + // заказыПоДатамToolStripMenuItem + // + заказыПоДатамToolStripMenuItem.Name = "заказыПоДатамToolStripMenuItem"; + заказыПоДатамToolStripMenuItem.Size = new Size(305, 26); + заказыПоДатамToolStripMenuItem.Text = "Заказы по датам"; + // // DataGridView // DataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; @@ -233,5 +256,8 @@ private ToolStripMenuItem магазиныToolStripMenuItem; private ToolStripMenuItem поставкиToolStripMenuItem; private ToolStripMenuItem продажиToolStripMenuItem; + private ToolStripMenuItem списокМагазиновToolStripMenuItem; + private ToolStripMenuItem мороженноеПоМагазинамToolStripMenuItem; + private ToolStripMenuItem заказыПоДатамToolStripMenuItem; } } \ No newline at end of file diff --git a/IceCreamShop/IceCreamShop/MainForm.cs b/IceCreamShop/IceCreamShop/MainForm.cs index fd7e8de..f3c5551 100644 --- a/IceCreamShop/IceCreamShop/MainForm.cs +++ b/IceCreamShop/IceCreamShop/MainForm.cs @@ -247,5 +247,29 @@ Program.ServiceProvider?.GetService(typeof(ReportOrdersForm)); } } + + 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(ReportShopsIceCreamsForm)); + if (service is ReportShopsIceCreamsForm form) + { + form.ShowDialog(); + } + } } } diff --git a/IceCreamShop/IceCreamShop/Program.cs b/IceCreamShop/IceCreamShop/Program.cs index 603ef77..06cea4e 100644 --- a/IceCreamShop/IceCreamShop/Program.cs +++ b/IceCreamShop/IceCreamShop/Program.cs @@ -55,6 +55,7 @@ namespace IceCreamShop services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); diff --git a/IceCreamShop/IceCreamShop/ReportShopsIceCreamsForm.Designer.cs b/IceCreamShop/IceCreamShop/ReportShopsIceCreamsForm.Designer.cs new file mode 100644 index 0000000..b8d8fed --- /dev/null +++ b/IceCreamShop/IceCreamShop/ReportShopsIceCreamsForm.Designer.cs @@ -0,0 +1,103 @@ +namespace IceCreamShop +{ + partial class ReportShopsIceCreamsForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + dataGridView = new DataGridView(); + ShopColumn = new DataGridViewTextBoxColumn(); + IceCreamColumn = new DataGridViewTextBoxColumn(); + CountColumn = new DataGridViewTextBoxColumn(); + SaveButton = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Columns.AddRange(new DataGridViewColumn[] { ShopColumn, IceCreamColumn, CountColumn }); + dataGridView.Location = new Point(12, 64); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 29; + dataGridView.Size = new Size(682, 374); + dataGridView.TabIndex = 0; + // + // ShopColumn + // + ShopColumn.HeaderText = "Магазин"; + ShopColumn.MinimumWidth = 6; + ShopColumn.Name = "ShopColumn"; + ShopColumn.Width = 250; + // + // IceCreamColumn + // + IceCreamColumn.HeaderText = "Мороженное"; + IceCreamColumn.MinimumWidth = 6; + IceCreamColumn.Name = "IceCreamColumn"; + IceCreamColumn.Width = 250; + // + // CountColumn + // + CountColumn.HeaderText = "Количество"; + CountColumn.MinimumWidth = 6; + CountColumn.Name = "CountColumn"; + CountColumn.Width = 125; + // + // SaveButton + // + SaveButton.Location = new Point(12, 29); + SaveButton.Name = "SaveButton"; + SaveButton.Size = new Size(108, 29); + SaveButton.TabIndex = 1; + SaveButton.Text = "Сохранить в"; + SaveButton.UseVisualStyleBackColor = true; + SaveButton.Click += SaveButton_Click_1; + // + // ReportShopsIceCreamsForm + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(702, 450); + Controls.Add(SaveButton); + Controls.Add(dataGridView); + Name = "ReportShopsIceCreamsForm"; + Text = "ReportShopsIceCreamsForm"; + Load += ReportShopsIceCreamsForm_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridView; + private Button SaveButton; + private DataGridViewTextBoxColumn ShopColumn; + private DataGridViewTextBoxColumn IceCreamColumn; + private DataGridViewTextBoxColumn CountColumn; + } +} \ No newline at end of file diff --git a/IceCreamShop/IceCreamShop/ReportShopsIceCreamsForm.cs b/IceCreamShop/IceCreamShop/ReportShopsIceCreamsForm.cs new file mode 100644 index 0000000..8eae605 --- /dev/null +++ b/IceCreamShop/IceCreamShop/ReportShopsIceCreamsForm.cs @@ -0,0 +1,93 @@ +using IceCreamShopContracts.BindingModels; +using IceCreamShopContracts.BusinessLogicsContracts; +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 IceCreamShop +{ + public partial class ReportShopsIceCreamsForm : Form + { + private readonly ILogger _logger; + private readonly IReportLogic _logic; + + public ReportShopsIceCreamsForm(ILogger +logger, IReportLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + + } + + private void ReportShopsIceCreamsForm_Load(object sender, EventArgs e) + { + try + { + var dict = _logic.GetShopsIceCreams(); + if (dict != null) + { + dataGridView.Rows.Clear(); + foreach (var elem in dict) + { + dataGridView.Rows.Add(new object[] { elem.ShopName, +"", "" }); + foreach (var listElem in elem.IceCreams) + { + 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 SaveButton_Click_1(object sender, EventArgs e) + { + using var dialog = new SaveFileDialog + { + Filter = "xlsx|*.xlsx" + }; + if (dialog.ShowDialog() == DialogResult.OK) + { + try + { + _logic.SaveShopsIceCreamsToExcelFile(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/IceCreamShop/IceCreamShop/ReportShopsIceCreamsForm.resx b/IceCreamShop/IceCreamShop/ReportShopsIceCreamsForm.resx new file mode 100644 index 0000000..51eccb4 --- /dev/null +++ b/IceCreamShop/IceCreamShop/ReportShopsIceCreamsForm.resx @@ -0,0 +1,129 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + \ No newline at end of file diff --git a/IceCreamShop/IceCreamShopBusinessLogic/BusinessLogic/ReportLogic.cs b/IceCreamShop/IceCreamShopBusinessLogic/BusinessLogic/ReportLogic.cs index 08903f4..d295693 100644 --- a/IceCreamShop/IceCreamShopBusinessLogic/BusinessLogic/ReportLogic.cs +++ b/IceCreamShop/IceCreamShopBusinessLogic/BusinessLogic/ReportLogic.cs @@ -18,17 +18,19 @@ namespace IceCreamShopBusinessLogic.BusinessLogic private readonly IComponentStorage _componentStorage; private readonly IIceCreamStorage _iceCreamStorage; private readonly IOrderStorage _orderStorage; + private readonly IShopStorage _shopStorage; private readonly AbstractSaveToExcel _saveToExcel; private readonly AbstractSaveToWord _saveToWord; private readonly AbstractSaveToPdf _saveToPdf; public ReportLogic(IIceCreamStorage iceCreamStorage, IComponentStorage - componentStorage, IOrderStorage orderStorage, + componentStorage, IOrderStorage orderStorage, IShopStorage shopStorage, AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf) { _iceCreamStorage = iceCreamStorage; _componentStorage = componentStorage; _orderStorage = orderStorage; + _shopStorage = shopStorage; _saveToExcel = saveToExcel; _saveToWord = saveToWord; _saveToPdf = saveToPdf; @@ -56,6 +58,67 @@ namespace IceCreamShopBusinessLogic.BusinessLogic } return list; } + + public List GetShopsIceCreams() + { + var shops = _shopStorage.GetFullList(); + var list = new List(); + foreach (var shop in shops) + { + var record = new ReportShopIceCreamViewModel + { + ShopName = shop.ShopName, + IceCreams = new List>(), + TotalCount = 0 + }; + foreach (var iceCream in shop.ShopIceCreams) + { + record.IceCreams.Add(new Tuple(iceCream.Value.Item1.IceCreamName, iceCream.Value.Item2)); + record.TotalCount += + iceCream.Value.Item2; + } + list.Add(record); + } + return list; + } + public List GetDatesOrders() + { + return _orderStorage.GetFullList().GroupBy(x => x.DateCreate.Date).Select(x => new ReportDateOrdersViewModel + { + DateOfOrders = x.Key, + Count = x.Count(), + Sum = x.Sum(y => y.Sum) + }).ToList(); + } + public void SaveDatesOrdersToPdfFile(ReportBindingModel model) + { + _saveToPdf.CreateReportDateDoc(new PdfInfo + { + FileName = model.FileName, + Title = "Заказы по датам", + DateOrders = GetDatesOrders() + }); + } + public void SaveShopsToWordFile(ReportBindingModel model) + { + var tmp = _shopStorage.GetFullList(); + _saveToWord.CreateTableDoc(new WordInfo + { + FileName = model.FileName, + Title = "Список магазинов", + Shops = _shopStorage.GetFullList() + }); + } + public void SaveShopsIceCreamsToExcelFile(ReportBindingModel model) + { + _saveToExcel.CreateShopReport(new ExcelInfo + { + FileName = model.FileName, + Title = "Загруженность магазинов", + ShopIceCreams = GetShopsIceCreams() + }); + } public List GetOrders(ReportBindingModel model) { return _orderStorage.GetFilteredList(new OrderSearchModel diff --git a/IceCreamShop/IceCreamShopBusinessLogic/OfficePackage/AbstractSaveToExcel.cs b/IceCreamShop/IceCreamShopBusinessLogic/OfficePackage/AbstractSaveToExcel.cs index 43f6ab6..3a8100c 100644 --- a/IceCreamShop/IceCreamShopBusinessLogic/OfficePackage/AbstractSaveToExcel.cs +++ b/IceCreamShop/IceCreamShopBusinessLogic/OfficePackage/AbstractSaveToExcel.cs @@ -74,6 +74,70 @@ namespace IceCreamShopBusinessLogic.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.ShopIceCreams) + { + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "A", + RowIndex = rowIndex, + Text = pc.ShopName, + StyleInfo = ExcelStyleInfoType.Text + }); + rowIndex++; + foreach (var iceCream in pc.IceCreams) + { + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "B", + RowIndex = rowIndex, + Text = iceCream.Item1, + StyleInfo = + ExcelStyleInfoType.TextWithBroder + }); + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "C", + RowIndex = rowIndex, + Text = iceCream.Item2.ToString(), + StyleInfo = + ExcelStyleInfoType.TextWithBroder + }); + rowIndex++; + } + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "A", + RowIndex = rowIndex, + Text = "Итого", + StyleInfo = ExcelStyleInfoType.Text + }); + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "C", + RowIndex = rowIndex, + Text = pc.TotalCount.ToString(), + StyleInfo = ExcelStyleInfoType.Text + }); + rowIndex++; + } + SaveExcel(info); + } protected abstract void CreateExcel(ExcelInfo info); protected abstract void InsertCellInWorksheet(ExcelCellParameters excelParams); diff --git a/IceCreamShop/IceCreamShopBusinessLogic/OfficePackage/AbstractSaveToPdf.cs b/IceCreamShop/IceCreamShopBusinessLogic/OfficePackage/AbstractSaveToPdf.cs index fd21c8c..c296017 100644 --- a/IceCreamShop/IceCreamShopBusinessLogic/OfficePackage/AbstractSaveToPdf.cs +++ b/IceCreamShop/IceCreamShopBusinessLogic/OfficePackage/AbstractSaveToPdf.cs @@ -53,6 +53,39 @@ order.DateCreate.ToShortDateString(), order.IceCreamName, order.Sum.ToString(), }); SavePdf(info); } + public void CreateReportDateDoc(PdfInfo info) + { + CreatePdf(info); + CreateParagraph(new PdfParagraph + { + Text = info.Title, + Style = "NormalTitle", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + CreateTable(new List { "3cm", "3cm", "7cm" }); + CreateRow(new PdfRowParameters + { + Texts = new List { "Дата", "Количество", "Сумма" }, + Style = "NormalTitle", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + foreach (var order in info.DateOrders) + { + CreateRow(new PdfRowParameters + { + Texts = new List { order.DateOfOrders.ToShortDateString(), order.Count.ToString(), order.Sum.ToString() }, + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Left + }); + } + CreateParagraph(new PdfParagraph + { + Text = $"Итого: {info.DateOrders.Sum(x => x.Sum)}\t", + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + SavePdf(info); + } protected abstract void CreatePdf(PdfInfo info); protected abstract void CreateParagraph(PdfParagraph paragraph); protected abstract void CreateTable(List columns); diff --git a/IceCreamShop/IceCreamShopBusinessLogic/OfficePackage/AbstractSaveToWord.cs b/IceCreamShop/IceCreamShopBusinessLogic/OfficePackage/AbstractSaveToWord.cs index 1498d75..cd2f636 100644 --- a/IceCreamShop/IceCreamShopBusinessLogic/OfficePackage/AbstractSaveToWord.cs +++ b/IceCreamShop/IceCreamShopBusinessLogic/OfficePackage/AbstractSaveToWord.cs @@ -1,4 +1,5 @@ -using IceCreamShopBusinessLogic.OfficePackage.HelperEnums; +using DocumentFormat.OpenXml.Office2010.ExcelAc; +using IceCreamShopBusinessLogic.OfficePackage.HelperEnums; using IceCreamShopBusinessLogic.OfficePackage.HelperModels; using System; using System.Collections.Generic; @@ -40,8 +41,36 @@ WordTextProperties { Bold = true, Size = "24", }) }, } SaveWord(info); } + + public void CreateTableDoc(WordInfo info) + { + CreateWord(info); + List> list = new List>(); + foreach (var shop in info.Shops) + { + var ls = new List + { + shop.ShopName, + shop.Address, + shop.DateOpen.ToShortDateString() + }; + list.Add(ls); + } + var wordTable = new WordTable + { + Headers = new List { + "Название", + "Адрес", + "Дата открытия"}, + Columns = 3, + RowText = list + }; + CreateTable(wordTable); + SaveWord(info); + } protected abstract void CreateWord(WordInfo info); protected abstract void CreateParagraph(WordParagraph paragraph); + protected abstract void CreateTable(WordTable table); protected abstract void SaveWord(WordInfo info); } diff --git a/IceCreamShop/IceCreamShopBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs b/IceCreamShop/IceCreamShopBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs index f863cff..4648738 100644 --- a/IceCreamShop/IceCreamShopBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs +++ b/IceCreamShop/IceCreamShopBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs @@ -16,6 +16,10 @@ namespace IceCreamShopBusinessLogic.OfficePackage.HelperModels get; set; } = new(); - + public List ShopIceCreams + { + get; + set; + } = new(); } } diff --git a/IceCreamShop/IceCreamShopBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs b/IceCreamShop/IceCreamShopBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs index 2986518..2df3f5b 100644 --- a/IceCreamShop/IceCreamShopBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs +++ b/IceCreamShop/IceCreamShopBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs @@ -14,5 +14,6 @@ namespace IceCreamShopBusinessLogic.OfficePackage.HelperModels public DateTime DateFrom { get; set; } public DateTime DateTo { get; set; } public List Orders { get; set; } = new(); + public List DateOrders { get; set; } = new(); } } diff --git a/IceCreamShop/IceCreamShopBusinessLogic/OfficePackage/HelperModels/WordInfo.cs b/IceCreamShop/IceCreamShopBusinessLogic/OfficePackage/HelperModels/WordInfo.cs index f00edda..208a045 100644 --- a/IceCreamShop/IceCreamShopBusinessLogic/OfficePackage/HelperModels/WordInfo.cs +++ b/IceCreamShop/IceCreamShopBusinessLogic/OfficePackage/HelperModels/WordInfo.cs @@ -12,5 +12,6 @@ namespace IceCreamShopBusinessLogic.OfficePackage.HelperModels public string FileName { get; set; } = string.Empty; public string Title { get; set; } = string.Empty; public List IceCreams { get; set; } = new(); + public List Shops { get; set; } = new(); } } diff --git a/IceCreamShop/IceCreamShopBusinessLogic/OfficePackage/HelperModels/WordTable.cs b/IceCreamShop/IceCreamShopBusinessLogic/OfficePackage/HelperModels/WordTable.cs new file mode 100644 index 0000000..2abf431 --- /dev/null +++ b/IceCreamShop/IceCreamShopBusinessLogic/OfficePackage/HelperModels/WordTable.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Numerics; +using System.Text; +using System.Threading.Tasks; + +namespace IceCreamShopBusinessLogic.OfficePackage.HelperModels +{ + public class WordTable + { + public List Headers { get; set; } = new(); + public List> RowText { get; set; } = new(); + public int Columns { get; set; } + } +} diff --git a/IceCreamShop/IceCreamShopBusinessLogic/OfficePackage/Implements/SaveToWord.cs b/IceCreamShop/IceCreamShopBusinessLogic/OfficePackage/Implements/SaveToWord.cs index 82d730e..2092e18 100644 --- a/IceCreamShop/IceCreamShopBusinessLogic/OfficePackage/Implements/SaveToWord.cs +++ b/IceCreamShop/IceCreamShopBusinessLogic/OfficePackage/Implements/SaveToWord.cs @@ -117,5 +117,82 @@ namespace IceCreamShopBusinessLogic.OfficePackage.Implements _wordDocument.Dispose(); } + + protected override void CreateTable(WordTable table) + { + if (_docBody == null || table == null) + { + return; + } + Table docTable = new Table(); + TableProperties tableProps = new TableProperties( + 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 + }); + docTable.AppendChild(tableProps); + TableGrid tableGrid = new TableGrid(); + for (int i = 0; i < table.Columns; i++) + { + tableGrid.AppendChild(new GridColumn()); + } + docTable.AppendChild(tableGrid); + TableRow tableRow = new TableRow(); + foreach (var text in table.Headers) + { + tableRow.AppendChild(CreateTableCell(text)); + } + int height = table.RowText.Count; + int width = table.Columns; + for (int i = 0; i < height; i++) + { + tableRow = new TableRow(); + for (int j = 0; j < width; j++) + { + var element = table.RowText[i][j]; + tableRow.AppendChild(CreateTableCell(element)); + } + docTable.AppendChild(tableRow); + } + + _docBody.AppendChild(docTable); + } + + 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/IceCreamShop/IceCreamShopContracts/BusinessLogicsContracts/IReportLogic.cs b/IceCreamShop/IceCreamShopContracts/BusinessLogicsContracts/IReportLogic.cs index 4657c15..e81041f 100644 --- a/IceCreamShop/IceCreamShopContracts/BusinessLogicsContracts/IReportLogic.cs +++ b/IceCreamShop/IceCreamShopContracts/BusinessLogicsContracts/IReportLogic.cs @@ -12,8 +12,13 @@ namespace IceCreamShopContracts.BusinessLogicsContracts { List GetIceCreamComponent(); List GetOrders(ReportBindingModel model); + List GetDatesOrders(); + List GetShopsIceCreams(); void SaveIceCreamToWordFile(ReportBindingModel model); void SaveIceCreamComponentToExcelFile(ReportBindingModel model); void SaveOrdersToPdfFile(ReportBindingModel model); + void SaveShopsToWordFile(ReportBindingModel model); + void SaveShopsIceCreamsToExcelFile(ReportBindingModel model); + void SaveDatesOrdersToPdfFile(ReportBindingModel model); } } diff --git a/IceCreamShop/IceCreamShopContracts/ViewModels/ReportDateOrdersViewModel.cs b/IceCreamShop/IceCreamShopContracts/ViewModels/ReportDateOrdersViewModel.cs new file mode 100644 index 0000000..834c977 --- /dev/null +++ b/IceCreamShop/IceCreamShopContracts/ViewModels/ReportDateOrdersViewModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace IceCreamShopContracts.ViewModels +{ + public class ReportDateOrdersViewModel + { + public DateTime DateOfOrders { get; set; } + public int Count { get; set; } + public double Sum { get; set; } + } +} diff --git a/IceCreamShop/IceCreamShopContracts/ViewModels/ReportShopIceCreamViewModel.cs b/IceCreamShop/IceCreamShopContracts/ViewModels/ReportShopIceCreamViewModel.cs new file mode 100644 index 0000000..a33f11d --- /dev/null +++ b/IceCreamShop/IceCreamShopContracts/ViewModels/ReportShopIceCreamViewModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace IceCreamShopContracts.ViewModels +{ + public class ReportShopIceCreamViewModel + { + public string ShopName { get; set; } = string.Empty; + public int TotalCount { get; set; } + public List> IceCreams { get; set; } = new(); + } +}