From 450a1d6313a6954f866d24137a2f2a4e66bd93e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B0=D1=88=D0=B8=D0=BD=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC?= Date: Tue, 11 Apr 2023 00:09:25 +0400 Subject: [PATCH] LabWork04_hard :< --- .../PrecastConcretePlant/FormMain.Designer.cs | 72 +++++++-- .../PrecastConcretePlant/FormMain.cs | 73 ++++++--- .../FormReportGroupOrders.Designer.cs | 141 ++++++++++++++++++ .../FormReportGroupOrders.cs | 91 +++++++++++ .../FormReportGroupOrders.resx | 120 +++++++++++++++ .../FormReportShopReinforcedies.Designer.cs | 113 ++++++++++++++ .../FormReportShopReinforcedies.cs | 80 ++++++++++ .../FormReportShopReinforcedies.resx | 60 ++++++++ .../PrecastConcretePlant/Program.cs | 13 +- .../BusinessLogic/ReportLogic.cs | 84 ++++++++++- .../OfficePackage/AbstractSaveToExcel.cs | 121 ++++++++++++++- .../OfficePackage/AbstractSaveToPdf.cs | 56 +++++-- .../OfficePackage/AbstractSaveToWord.cs | 56 ++++++- .../OfficePackage/HelperModels/ExcelInfo.cs | 2 +- .../HelperModels/ExcelInfoReinforced.cs | 20 +++ .../OfficePackage/HelperModels/PdfInfo.cs | 2 +- .../HelperModels/PdfInfoOrders.cs | 29 ++++ .../OfficePackage/HelperModels/WordInfo.cs | 3 +- .../HelperModels/WordInfoTable.cs | 16 ++ .../OfficePackage/Implements/SaveToWord.cs | 106 +++++++++---- .../BusinessLogicsContracts/IReportLogic.cs | 5 + .../ViewModels/ReportGroupOrdersViewModel.cs | 16 ++ ... => ReportReinforcedComponentViewModel.cs} | 0 .../ReportShopReinforcedViewModel.cs | 16 ++ 24 files changed, 1207 insertions(+), 88 deletions(-) create mode 100644 PrecastConcretePlant/PrecastConcretePlant/FormReportGroupOrders.Designer.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlant/FormReportGroupOrders.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlant/FormReportGroupOrders.resx create mode 100644 PrecastConcretePlant/PrecastConcretePlant/FormReportShopReinforcedies.Designer.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlant/FormReportShopReinforcedies.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlant/FormReportShopReinforcedies.resx create mode 100644 PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OfficePackage/HelperModels/ExcelInfoReinforced.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OfficePackage/HelperModels/PdfInfoOrders.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OfficePackage/HelperModels/WordInfoTable.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ReportGroupOrdersViewModel.cs rename PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/{ReportComponentBlankViewModel.cs => ReportReinforcedComponentViewModel.cs} (100%) create mode 100644 PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ReportShopReinforcedViewModel.cs diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormMain.Designer.cs b/PrecastConcretePlant/PrecastConcretePlant/FormMain.Designer.cs index 8fdf192..ce4055a 100644 --- a/PrecastConcretePlant/PrecastConcretePlant/FormMain.Designer.cs +++ b/PrecastConcretePlant/PrecastConcretePlant/FormMain.Designer.cs @@ -37,14 +37,18 @@ 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.CreateOrderButton = new System.Windows.Forms.Button(); this.TakeOrderInWorkButton = new System.Windows.Forms.Button(); this.OrderReadyButton = new System.Windows.Forms.Button(); this.IssuedOrderButton = new System.Windows.Forms.Button(); this.UpdateListButton = new System.Windows.Forms.Button(); - this.ButtonAddReinforcedInShop = new System.Windows.Forms.Button(); this.SellReinforcedButton = new System.Windows.Forms.Button(); + this.buttonSellReinforced = new System.Windows.Forms.Button(); + this.buttonAddReinforcedInShop = new System.Windows.Forms.Button(); this.MenuStrip.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).BeginInit(); this.SuspendLayout(); @@ -90,13 +94,18 @@ // this.магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem"; this.магазиныToolStripMenuItem.Size = new System.Drawing.Size(224, 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, + this.списокГруппЗаказовToolStripMenuItem}); this.отчетыToolStripMenuItem.Name = "отчетыToolStripMenuItem"; this.отчетыToolStripMenuItem.Size = new System.Drawing.Size(73, 24); this.отчетыToolStripMenuItem.Text = "Отчеты"; @@ -122,6 +131,27 @@ this.списокЗаказовToolStripMenuItem.Text = "Список заказов"; this.списокЗаказовToolStripMenuItem.Click += new System.EventHandler(this.списокЗаказовToolStripMenuItem_Click); // + // списокМагазиновToolStripMenuItem + // + this.списокМагазиновToolStripMenuItem.Name = "списокМагазиновToolStripMenuItem"; + this.списокМагазиновToolStripMenuItem.Size = new System.Drawing.Size(292, 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(292, 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(292, 26); + this.списокГруппЗаказовToolStripMenuItem.Text = "Список групп заказов"; + this.списокГруппЗаказовToolStripMenuItem.Click += new System.EventHandler(this.списокГруппЗаказовToolStripMenuItem_Click); + // // DataGridView // this.DataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; @@ -188,16 +218,6 @@ this.UpdateListButton.UseVisualStyleBackColor = true; this.UpdateListButton.Click += new System.EventHandler(this.UpdateListButton_Click); // - // ButtonAddReinforcedInShop - // - this.ButtonAddReinforcedInShop.Location = new System.Drawing.Point(905, 228); - this.ButtonAddReinforcedInShop.Name = "ButtonAddReinforcedInShop"; - this.ButtonAddReinforcedInShop.Size = new System.Drawing.Size(125, 42); - this.ButtonAddReinforcedInShop.TabIndex = 7; - this.ButtonAddReinforcedInShop.Text = "Пополнение магазина"; - this.ButtonAddReinforcedInShop.UseVisualStyleBackColor = true; - this.ButtonAddReinforcedInShop.Click += new System.EventHandler(this.ButtonAddReinforcedInShop_Click); - // // SellReinforcedButton // this.SellReinforcedButton.Location = new System.Drawing.Point(905, 276); @@ -208,11 +228,33 @@ this.SellReinforcedButton.UseVisualStyleBackColor = true; this.SellReinforcedButton.Click += new System.EventHandler(this.SellReinforcedButton_Click); // + // buttonSellReinforced + // + this.buttonSellReinforced.Location = new System.Drawing.Point(1034, 303); + this.buttonSellReinforced.Name = "buttonSellReinforced"; + this.buttonSellReinforced.Size = new System.Drawing.Size(143, 45); + this.buttonSellReinforced.TabIndex = 7; + this.buttonSellReinforced.Text = "Продать изделие"; + this.buttonSellReinforced.UseVisualStyleBackColor = true; + this.buttonSellReinforced.Click += new System.EventHandler(this.buttonSellReinforced_Click); + // + // buttonAddReinforcedInShop + // + this.buttonAddReinforcedInShop.Location = new System.Drawing.Point(1034, 354); + this.buttonAddReinforcedInShop.Name = "buttonAddReinforcedInShop"; + this.buttonAddReinforcedInShop.Size = new System.Drawing.Size(143, 55); + this.buttonAddReinforcedInShop.TabIndex = 8; + this.buttonAddReinforcedInShop.Text = "Пополнение магазина"; + this.buttonAddReinforcedInShop.UseVisualStyleBackColor = true; + this.buttonAddReinforcedInShop.Click += new System.EventHandler(this.buttonAddReinforcedInShop_Click); + // // FormMain // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(1209, 450); + this.Controls.Add(this.buttonAddReinforcedInShop); + this.Controls.Add(this.buttonSellReinforced); this.Controls.Add(this.UpdateListButton); this.Controls.Add(this.IssuedOrderButton); this.Controls.Add(this.OrderReadyButton); @@ -250,7 +292,11 @@ private Button OrderReadyButton; private Button IssuedOrderButton; private Button UpdateListButton; - public Button ButtonAddReinforcedInShop; public Button SellReinforcedButton; + private Button buttonSellReinforced; + private Button buttonAddReinforcedInShop; + private ToolStripMenuItem списокМагазиновToolStripMenuItem; + private ToolStripMenuItem магазиныСИзделиямиToolStripMenuItem; + private ToolStripMenuItem списокГруппЗаказовToolStripMenuItem; } } \ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormMain.cs b/PrecastConcretePlant/PrecastConcretePlant/FormMain.cs index f4e4232..53ba19f 100644 --- a/PrecastConcretePlant/PrecastConcretePlant/FormMain.cs +++ b/PrecastConcretePlant/PrecastConcretePlant/FormMain.cs @@ -1,5 +1,6 @@  using Microsoft.Extensions.Logging; +using PrecastConcretePlant; using PrecastConcretePlantBusinessLogic.BusinessLogic; using PrecastConcretePlantContracts.BindingModels; using PrecastConcretePlantContracts.BusinessLogicsContracts; @@ -201,23 +202,6 @@ namespace PrecastConcretePlantView LoadData(); } - private void ButtonAddReinforcedInShop_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormReinforcedShop)); - if (service is FormReinforcedShop form) - { - form.ShowDialog(); - } - } - - private void магазиныToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormShops)); - if (service is FormShops form) - { - form.ShowDialog(); - } - } private void SellReinforcedButton_Click(object sender, EventArgs e) { @@ -259,5 +243,60 @@ namespace PrecastConcretePlantView form.ShowDialog(); } } + + private void списокМагазиновToolStripMenuItem_Click(object sender, EventArgs e) + { + using var dialog = new SaveFileDialog { Filter = "docx|*.docx" }; + if (dialog.ShowDialog() == DialogResult.OK) + { + _reportLogic.SaveShopsTableToWordFile(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(FormReportShopReinforcedies)); + if (service is FormReportShopReinforcedies form) + { + form.ShowDialog(); + } + } + + private void списокГруппЗаказовToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormReportGroupOrders)); + if (service is FormReportGroupOrders form) + { + form.ShowDialog(); + } + } + + private void buttonSellReinforced_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormSellReinforced)); + if (service is FormSellReinforced form) + { + form.ShowDialog(); + } + } + + private void buttonAddReinforcedInShop_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormReinforcedShop)); + if (service is FormReinforcedShop form) + { + form.ShowDialog(); + } + } + + private void магазиныToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShops)); + if (service is FormShops form) + { + form.ShowDialog(); + } + } } } diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormReportGroupOrders.Designer.cs b/PrecastConcretePlant/PrecastConcretePlant/FormReportGroupOrders.Designer.cs new file mode 100644 index 0000000..e6e53d4 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlant/FormReportGroupOrders.Designer.cs @@ -0,0 +1,141 @@ +namespace PrecastConcretePlant +{ + partial class FormReportGroupOrders + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.panel = new System.Windows.Forms.Panel(); + this.buttonToPdf = new System.Windows.Forms.Button(); + this.buttonMake = new System.Windows.Forms.Button(); + this.dateTimePickerTo = new System.Windows.Forms.DateTimePicker(); + this.labelTo = new System.Windows.Forms.Label(); + this.dateTimePickerFrom = new System.Windows.Forms.DateTimePicker(); + this.labelFrom = new System.Windows.Forms.Label(); + this.panel.SuspendLayout(); + this.SuspendLayout(); + // + // panel + // + this.panel.Controls.Add(this.buttonToPdf); + this.panel.Controls.Add(this.buttonMake); + this.panel.Controls.Add(this.dateTimePickerTo); + this.panel.Controls.Add(this.labelTo); + this.panel.Controls.Add(this.dateTimePickerFrom); + this.panel.Controls.Add(this.labelFrom); + this.panel.Dock = System.Windows.Forms.DockStyle.Top; + this.panel.Location = new System.Drawing.Point(0, 0); + this.panel.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + this.panel.Name = "panel"; + this.panel.Size = new System.Drawing.Size(1031, 40); + this.panel.TabIndex = 0; + // + // buttonToPdf + // + this.buttonToPdf.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.buttonToPdf.Location = new System.Drawing.Point(878, 8); + this.buttonToPdf.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + this.buttonToPdf.Name = "buttonToPdf"; + this.buttonToPdf.Size = new System.Drawing.Size(139, 27); + this.buttonToPdf.TabIndex = 5; + this.buttonToPdf.Text = "В Pdf"; + this.buttonToPdf.UseVisualStyleBackColor = true; + this.buttonToPdf.Click += new System.EventHandler(this.ButtonToPdf_Click); + // + // buttonMake + // + this.buttonMake.Location = new System.Drawing.Point(476, 8); + this.buttonMake.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + this.buttonMake.Name = "buttonMake"; + this.buttonMake.Size = new System.Drawing.Size(139, 27); + this.buttonMake.TabIndex = 4; + this.buttonMake.Text = "Сформировать"; + this.buttonMake.UseVisualStyleBackColor = true; + this.buttonMake.Click += new System.EventHandler(this.ButtonMake_Click); + // + // dateTimePickerTo + // + this.dateTimePickerTo.Location = new System.Drawing.Point(237, 7); + this.dateTimePickerTo.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + this.dateTimePickerTo.Name = "dateTimePickerTo"; + this.dateTimePickerTo.Size = new System.Drawing.Size(163, 23); + this.dateTimePickerTo.TabIndex = 3; + // + // labelTo + // + this.labelTo.AutoSize = true; + this.labelTo.Location = new System.Drawing.Point(208, 10); + this.labelTo.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.labelTo.Name = "labelTo"; + this.labelTo.Size = new System.Drawing.Size(21, 15); + this.labelTo.TabIndex = 2; + this.labelTo.Text = "по"; + // + // dateTimePickerFrom + // + this.dateTimePickerFrom.Location = new System.Drawing.Point(37, 7); + this.dateTimePickerFrom.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + this.dateTimePickerFrom.Name = "dateTimePickerFrom"; + this.dateTimePickerFrom.Size = new System.Drawing.Size(163, 23); + this.dateTimePickerFrom.TabIndex = 1; + // + // labelFrom + // + this.labelFrom.AutoSize = true; + this.labelFrom.Location = new System.Drawing.Point(14, 10); + this.labelFrom.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.labelFrom.Name = "labelFrom"; + this.labelFrom.Size = new System.Drawing.Size(15, 15); + this.labelFrom.TabIndex = 0; + this.labelFrom.Text = "С"; + // + // FormReportOrders + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(1031, 647); + this.Controls.Add(this.panel); + this.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + this.Name = "FormReportOrders"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "Заказы"; + this.panel.ResumeLayout(false); + this.panel.PerformLayout(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.Panel panel; + private System.Windows.Forms.Button buttonToPdf; + private System.Windows.Forms.Button buttonMake; + private System.Windows.Forms.DateTimePicker dateTimePickerTo; + private System.Windows.Forms.Label labelTo; + private System.Windows.Forms.DateTimePicker dateTimePickerFrom; + private System.Windows.Forms.Label labelFrom; + } +} \ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormReportGroupOrders.cs b/PrecastConcretePlant/PrecastConcretePlant/FormReportGroupOrders.cs new file mode 100644 index 0000000..b79c648 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlant/FormReportGroupOrders.cs @@ -0,0 +1,91 @@ +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +using Microsoft.Reporting.WinForms; + +namespace PrecastConcretePlant +{ + public partial class FormReportGroupOrders : Form + { + private readonly ReportViewer reportViewer; + + private readonly ILogger _logger; + + private readonly IReportLogic _logic; + + public FormReportGroupOrders(ILogger logger, IReportLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + reportViewer = new ReportViewer + { + Dock = DockStyle.Fill + }; + reportViewer.LocalReport.LoadReportDefinition(new FileStream("ReportGroupOrders.rdlc", FileMode.Open)); + Controls.Clear(); + Controls.Add(reportViewer); + Controls.Add(panel); + } + + private void ButtonMake_Click(object sender, EventArgs e) + { + if (dateTimePickerFrom.Value.Date >= dateTimePickerTo.Value.Date) + { + MessageBox.Show("Дата начала должна быть меньше даты окончания", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + try + { + var dataSource = _logic.GetGroupOrders(new ReportBindingModel + { + DateFrom = dateTimePickerFrom.Value, + DateTo = dateTimePickerTo.Value + }); + var source = new ReportDataSource("DataSetOrders", dataSource); + reportViewer.LocalReport.DataSources.Clear(); + reportViewer.LocalReport.DataSources.Add(source); + var parameters = new[] { new ReportParameter("ReportParameterPeriod", + $"c {dateTimePickerFrom.Value.ToShortDateString()} по {dateTimePickerTo.Value.ToShortDateString()}") }; + reportViewer.LocalReport.SetParameters(parameters); + + reportViewer.RefreshReport(); + _logger.LogInformation("Загрузка списка заказов на период {From}-{To}", dateTimePickerFrom.Value.ToShortDateString(), dateTimePickerTo.Value.ToShortDateString()); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка заказов на период"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonToPdf_Click(object sender, EventArgs e) + { + if (dateTimePickerFrom.Value.Date >= dateTimePickerTo.Value.Date) + { + MessageBox.Show("Дата начала должна быть меньше даты окончания", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + using var dialog = new SaveFileDialog { Filter = "pdf|*.pdf" }; + if (dialog.ShowDialog() == DialogResult.OK) + { + try + { + _logic.SaveOrdersToPdfFile(new ReportBindingModel + { + FileName = dialog.FileName, + DateFrom = dateTimePickerFrom.Value, + DateTo = dateTimePickerTo.Value + }); + _logger.LogInformation("Сохранение списка заказов на период {From}-{To}", dateTimePickerFrom.Value.ToShortDateString(), dateTimePickerTo.Value.ToShortDateString()); + MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения списка заказов на период"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormReportGroupOrders.resx b/PrecastConcretePlant/PrecastConcretePlant/FormReportGroupOrders.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlant/FormReportGroupOrders.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormReportShopReinforcedies.Designer.cs b/PrecastConcretePlant/PrecastConcretePlant/FormReportShopReinforcedies.Designer.cs new file mode 100644 index 0000000..5d38bfe --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlant/FormReportShopReinforcedies.Designer.cs @@ -0,0 +1,113 @@ +namespace PrecastConcretePlant +{ + partial class FormReportShopReinforcedies + { + /// + /// 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(); + buttonSaveToExcel = new Button(); + ColumnShop = new DataGridViewTextBoxColumn(); + ColumnPastry = new DataGridViewTextBoxColumn(); + ColumnCount = new DataGridViewTextBoxColumn(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.AllowUserToOrderColumns = true; + dataGridView.AllowUserToResizeColumns = false; + dataGridView.AllowUserToResizeRows = false; + dataGridView.BackgroundColor = SystemColors.ControlLightLight; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Columns.AddRange(new DataGridViewColumn[] { ColumnShop, ColumnPastry, ColumnCount }); + dataGridView.Dock = DockStyle.Bottom; + dataGridView.Location = new Point(0, 47); + dataGridView.Margin = new Padding(4, 3, 4, 3); + dataGridView.MultiSelect = false; + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.RowHeadersVisible = false; + dataGridView.Size = new Size(616, 510); + dataGridView.TabIndex = 0; + // + // buttonSaveToExcel + // + buttonSaveToExcel.Location = new Point(14, 14); + buttonSaveToExcel.Margin = new Padding(4, 3, 4, 3); + buttonSaveToExcel.Name = "buttonSaveToExcel"; + buttonSaveToExcel.Size = new Size(186, 27); + buttonSaveToExcel.TabIndex = 1; + buttonSaveToExcel.Text = "Сохранить в Excel"; + buttonSaveToExcel.UseVisualStyleBackColor = true; + buttonSaveToExcel.Click += ButtonSaveToExcel_Click; + // + // ColumnShop + // + ColumnShop.HeaderText = "Магазин"; + ColumnShop.Name = "ColumnShop"; + ColumnShop.ReadOnly = true; + ColumnShop.Width = 200; + // + // ColumnPastry + // + ColumnPastry.HeaderText = "Изделие"; + ColumnPastry.Name = "ColumnPastry"; + ColumnPastry.ReadOnly = true; + ColumnPastry.Width = 200; + // + // ColumnCount + // + ColumnCount.HeaderText = "Количество"; + ColumnCount.Name = "ColumnCount"; + ColumnCount.ReadOnly = true; + // + // FormReportShopPastries + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(616, 557); + Controls.Add(buttonSaveToExcel); + Controls.Add(dataGridView); + Margin = new Padding(4, 3, 4, 3); + Name = "FormReportShopPastries"; + Text = "Изделия с компонентами"; + Load += FormReportShopReinforcedies_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private System.Windows.Forms.DataGridView dataGridView; + private System.Windows.Forms.Button buttonSaveToExcel; + private DataGridViewTextBoxColumn ColumnShop; + private DataGridViewTextBoxColumn ColumnPastry; + private DataGridViewTextBoxColumn ColumnCount; + } +} \ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormReportShopReinforcedies.cs b/PrecastConcretePlant/PrecastConcretePlant/FormReportShopReinforcedies.cs new file mode 100644 index 0000000..07645a0 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlant/FormReportShopReinforcedies.cs @@ -0,0 +1,80 @@ +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.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 PrecastConcretePlant +{ + public partial class FormReportShopReinforcedies : Form + { + private readonly ILogger _logger; + + private readonly IReportLogic _logic; + + public FormReportShopReinforcedies(ILogger logger, IReportLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormReportShopReinforcedies_Load(object sender, EventArgs e) + { + try + { + var dict = _logic.GetShopReinforcedies(); + if (dict != null) + { + dataGridView.Rows.Clear(); + foreach (var elem in dict) + { + dataGridView.Rows.Add(new object[] { elem.ShopName, "", "" }); + foreach (var listElem in elem.Reinforcedies) + { + dataGridView.Rows.Add(new object[] { "", listElem.Item1, listElem.Item2 }); + } + dataGridView.Rows.Add(new object[] { "Итого", "", elem.TotalCount }); + dataGridView.Rows.Add(new object[] { "Загруженность", "", Math.Round(elem.Workload * 100, 2).ToString() + "%" }); + 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.SaveShopReinforcedToExcelFile(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/PrecastConcretePlant/PrecastConcretePlant/FormReportShopReinforcedies.resx b/PrecastConcretePlant/PrecastConcretePlant/FormReportShopReinforcedies.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlant/FormReportShopReinforcedies.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/PrecastConcretePlant/PrecastConcretePlant/Program.cs b/PrecastConcretePlant/PrecastConcretePlant/Program.cs index 0f9f86e..7f1461d 100644 --- a/PrecastConcretePlant/PrecastConcretePlant/Program.cs +++ b/PrecastConcretePlant/PrecastConcretePlant/Program.cs @@ -8,6 +8,7 @@ using PrecastConcretePlantBusinessLogic.PrecastConcretePlantBusinessLogic.Busine using PrecastConcretePlantDatabaseImplement.Implements; using PrecastConcretePlantBusinessLogic.OfficePackage.Implements; using PrecastConcretePlantBusinessLogic.OfficePackage; +using PrecastConcretePlant; namespace PrecastConcretePlantView { @@ -41,10 +42,12 @@ namespace PrecastConcretePlantView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); - services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -52,6 +55,14 @@ namespace PrecastConcretePlantView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); } } } diff --git a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/ReportLogic.cs b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/ReportLogic.cs index 657a345..2b3d274 100644 --- a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/ReportLogic.cs +++ b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/ReportLogic.cs @@ -17,16 +17,18 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic { private readonly IComponentStorage _componentStorage; private readonly IReinforcedStorage _reinforcedStorage; + private readonly IShopStorage _shopStorage; private readonly IOrderStorage _orderStorage; private readonly AbstractSaveToExcel _saveToExcel; private readonly AbstractSaveToWord _saveToWord; private readonly AbstractSaveToPdf _saveToPdf; - public ReportLogic(IReinforcedStorage reinforcedStorage, IComponentStorage componentStorage, IOrderStorage orderStorage, AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf) + public ReportLogic(IReinforcedStorage reinforcedStorage, IComponentStorage componentStorage, IOrderStorage orderStorage, IShopStorage shopStorage, AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf) { _reinforcedStorage = reinforcedStorage; _componentStorage = componentStorage; _orderStorage = orderStorage; _saveToExcel = saveToExcel; + _shopStorage = shopStorage; _saveToWord = saveToWord; _saveToPdf = saveToPdf; } @@ -81,12 +83,12 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic { FileName = model.FileName, Title = "Список документов", - Reinforceds = _reinforcedStorage.GetFullList() + Reinforcedies = _reinforcedStorage.GetFullList() }); } public void SaveReinforcedComponentToExcelFile(ReportBindingModel model) { - _saveToExcel.CreateReport(new ExcelInfo + _saveToExcel.CreateReportReinforced(new ExcelInfoReinforced { FileName = model.FileName, Title = "Список документов", @@ -96,7 +98,7 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic public void SaveOrdersToPdfFile(ReportBindingModel model) { - _saveToPdf.CreateDoc(new PdfInfo + _saveToPdf.CreateDocOrders(new PdfInfoOrders { FileName = model.FileName, Title = "Список заказов", @@ -106,5 +108,79 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic }); } + public List GetShopReinforcedies() + { + var shops = _shopStorage.GetFullList(); + + var reinforcedies = _reinforcedStorage.GetFullList(); + + var list = new List(); + + foreach (var shop in shops) + { + var record = new ReportShopReinforcedViewModel + { + ShopName = shop.Name, + Reinforcedies = new List>(), + TotalCount = 0 + }; + foreach (var reinforced in reinforcedies) + { + if (shop.ShopReinforcedies.ContainsKey(reinforced.Id)) + { + record.Reinforcedies.Add(new(reinforced.ReinforcedName, shop.ShopReinforcedies[reinforced.Id].Item2)); + record.TotalCount += shop.ShopReinforcedies[reinforced.Id].Item2; + } + } + record.Workload = record.TotalCount / (double)shop.ReinforcedMaxCount; + list.Add(record); + } + + return list; + } + public List GetGroupOrders(ReportBindingModel model) + { + return _orderStorage.GetFullList() + .GroupBy(x => x.DateCreate.Date) + .Select(x => new ReportGroupOrdersViewModel + { + Date = x.Key, + Count = x.Count(), + Sum = x.Sum(y => y.Sum) + }).ToList(); + } + + + public void SaveShopsTableToWordFile(ReportBindingModel model) + { + _saveToWord.CreateDocTable(new WordInfoTable + { + FileName = model.FileName, + Title = "Список магазинов", + Shops = _shopStorage.GetFullList() + }); + } + + public void SaveGroupOrdersToPdfFile(ReportBindingModel model) + { + _saveToPdf.CreateDoc(new PdfInfo + { + FileName = model.FileName, + Title = "Список сгруппированных заказов по датам", + DateFrom = model.DateFrom!.Value, + DateTo = model.DateTo!.Value, + Orders = GetGroupOrders(model) + }); + } + + public void SaveShopReinforcedToExcelFile(ReportBindingModel model) + { + _saveToExcel.CreateReportShop(new ExcelInfo + { + FileName = model.FileName, + Title = "Список магазинов", + ShopReinforcedies = GetShopReinforcedies() + }); + } } } diff --git a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OfficePackage/AbstractSaveToExcel.cs b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OfficePackage/AbstractSaveToExcel.cs index c6bdec8..1ab43bb 100644 --- a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OfficePackage/AbstractSaveToExcel.cs +++ b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OfficePackage/AbstractSaveToExcel.cs @@ -10,9 +10,10 @@ namespace PrecastConcretePlantBusinessLogic.OfficePackage { public abstract class AbstractSaveToExcel { - public void CreateReport(ExcelInfo info) + public void CreateReportShop(ExcelInfo info) { CreateExcel(info); + InsertCellInWorksheet(new ExcelCellParameters { ColumnName = "A", @@ -20,11 +21,99 @@ namespace PrecastConcretePlantBusinessLogic.OfficePackage Text = info.Title, StyleInfo = ExcelStyleInfoType.Title }); + MergeCells(new ExcelMergeParameters { CellFromName = "A1", CellToName = "C1" }); + + uint rowIndex = 2; + foreach (var pc in info.ShopReinforcedies) + { + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "A", + RowIndex = rowIndex, + Text = pc.ShopName, + StyleInfo = ExcelStyleInfoType.Text + }); + rowIndex++; + + foreach (var (Shop, Count) in pc.Reinforcedies) + { + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "B", + RowIndex = rowIndex, + Text = Shop, + 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++; + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "A", + RowIndex = rowIndex, + Text = "Загруженность", + StyleInfo = ExcelStyleInfoType.Text + }); + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "C", + RowIndex = rowIndex, + Text = pc.Workload.ToString(), + StyleInfo = ExcelStyleInfoType.Text + }); + rowIndex++; + } + + SaveExcel(info); + } + + public void CreateReportReinforced(ExcelInfoReinforced info) + { + CreateExcel(new() { FileName = info.FileName }); + + 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.ReinforcedComponents) { @@ -36,15 +125,17 @@ namespace PrecastConcretePlantBusinessLogic.OfficePackage StyleInfo = ExcelStyleInfoType.Text }); rowIndex++; - foreach (var (Component, Count) in pc.Components) + + foreach (var (Reinforced, Count) in pc.Components) { InsertCellInWorksheet(new ExcelCellParameters { ColumnName = "B", RowIndex = rowIndex, - Text = Component, + Text = Reinforced, StyleInfo = ExcelStyleInfoType.TextWithBorder }); + InsertCellInWorksheet(new ExcelCellParameters { ColumnName = "C", @@ -52,8 +143,10 @@ namespace PrecastConcretePlantBusinessLogic.OfficePackage Text = Count.ToString(), StyleInfo = ExcelStyleInfoType.TextWithBorder }); + rowIndex++; } + InsertCellInWorksheet(new ExcelCellParameters { ColumnName = "A", @@ -70,12 +163,32 @@ namespace PrecastConcretePlantBusinessLogic.OfficePackage }); rowIndex++; } - SaveExcel(info); + + SaveExcel(new()); } + /// + /// Создание 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/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OfficePackage/AbstractSaveToPdf.cs b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OfficePackage/AbstractSaveToPdf.cs index 018b5f8..f94023c 100644 --- a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OfficePackage/AbstractSaveToPdf.cs +++ b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OfficePackage/AbstractSaveToPdf.cs @@ -13,47 +13,79 @@ namespace PrecastConcretePlantBusinessLogic.OfficePackage public void CreateDoc(PdfInfo info) { CreatePdf(info); + CreateParagraph(new PdfParagraph { Text = info.Title, Style = "NormalTitle", ParagraphAlignment = PdfParagraphAlignmentType.Center }); CreateParagraph(new PdfParagraph { - Text = info.Title, - Style = "NormalTitle", - ParagraphAlignment = PdfParagraphAlignmentType.Center - }); - CreateParagraph(new PdfParagraph - { - Text = $"с{info.DateFrom.ToShortDateString()} по {info.DateTo.ToShortDateString()}", + Text = $"с {info.DateFrom.ToShortDateString()} по {info.DateTo.ToShortDateString()}", Style = "Normal", ParagraphAlignment = PdfParagraphAlignmentType.Center }); - CreateTable(new List { "2cm", "3cm", "6cm", "3cm", "4cm" }); + + CreateTable(new List { "3cm", "4cm", "5cm" }); + CreateRow(new PdfRowParameters { - Texts = new List { "Номер", "Дата заказа", "Изделие", "Сумма", "Статус" }, + 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.ReinforcedName, order.Sum.ToString(), order.Status }, + Texts = new List { order.Date.ToShortDateString(), order.Count.ToString(), order.Sum.ToString() }, Style = "Normal", ParagraphAlignment = PdfParagraphAlignmentType.Left }); } + CreateParagraph(new PdfParagraph { Text = $"Итого: {info.Orders.Sum(x => x.Sum)}\t", Style = "Normal", ParagraphAlignment = PdfParagraphAlignmentType.Right }); + + SavePdf(info); + } + + public void CreateDocOrders(PdfInfoOrders info) + { + CreatePdf(info); + CreateParagraph(new PdfParagraph { Text = info.Title, Style = "NormalTitle", ParagraphAlignment = PdfParagraphAlignmentType.Center }); CreateParagraph(new PdfParagraph { - Text = $"Итого: {info.Orders.Sum(x => x.Sum)}\t", + Text = $"с {info.DateFrom.ToShortDateString()} по {info.DateTo.ToShortDateString()}", Style = "Normal", - ParagraphAlignment = PdfParagraphAlignmentType.Right + ParagraphAlignment = PdfParagraphAlignmentType.Center }); + + CreateTable(new List { "2cm", "3cm", "6cm", "4cm", "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.ReinforcedName, Convert.ToString(order.Status), order.Sum.ToString() }, + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Left + }); + } + CreateParagraph(new PdfParagraph { Text = $"Итого: {info.Orders.Sum(x => x.Sum)}\t", Style = "Normal", ParagraphAlignment = PdfParagraphAlignmentType.Right }); + SavePdf(info); } protected abstract void CreatePdf(PdfInfo info); + protected abstract void CreateParagraph(PdfParagraph paragraph); + protected abstract void CreateTable(List columns); + protected abstract void CreateRow(PdfRowParameters rowParameters); + protected abstract void SavePdf(PdfInfo info); } } diff --git a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OfficePackage/AbstractSaveToWord.cs b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OfficePackage/AbstractSaveToWord.cs index 033f1b0..6446c33 100644 --- a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OfficePackage/AbstractSaveToWord.cs +++ b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OfficePackage/AbstractSaveToWord.cs @@ -10,9 +10,10 @@ namespace PrecastConcretePlantBusinessLogic.OfficePackage { public abstract class AbstractSaveToWord { - public void CreateDoc(WordInfo info) + public void CreateDocTable(WordInfoTable info) { CreateWord(info); + CreateParagraph(new WordParagraph { Texts = new List<(string, WordTextProperties)> { (info.Title, new WordTextProperties { Bold = true, Size = "24", }) }, @@ -22,14 +23,48 @@ namespace PrecastConcretePlantBusinessLogic.OfficePackage JustificationType = WordJustificationType.Center } }); - foreach (var reinforced in info.Reinforceds) + + CreateTable(new() + { + ("Название", 3000), + ("Дата", null), + ("Адрес открытия", 4500), + }, + info.Shops + .Select(x => new List + { + x.Name, + Convert.ToString(x.DateOpening), + x.Address, + }) + .ToList()); + + SaveWord(info); + } + + public void CreateDoc(WordInfo info) + { + CreateWord(new() { FileName = info.FileName }); + + 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 reinforced in info.Reinforcedies) { CreateParagraph(new WordParagraph { Texts = new List<(string, WordTextProperties)> - {(reinforced.ReinforcedName + " - ", new WordTextProperties { Size = "24", Bold = true}), - (reinforced.Price.ToString(), new WordTextProperties { Size = "24", })}, - + { + (reinforced.ReinforcedName , new WordTextProperties { Size = "24", Bold = true}), + (" - цена: " + reinforced.Price.ToString(), new WordTextProperties { Size = "24" }) + }, TextProperties = new WordTextProperties { Size = "24", @@ -37,10 +72,15 @@ namespace PrecastConcretePlantBusinessLogic.OfficePackage } }); } - SaveWord(info); + + SaveWord(new()); } - protected abstract void CreateWord(WordInfo info); + + protected abstract void CreateWord(WordInfoTable info); + protected abstract void CreateParagraph(WordParagraph paragraph); - protected abstract void SaveWord(WordInfo info); + + protected abstract void CreateTable(List<(string, int?)> nameAndWidthColumns, List> rows); + protected abstract void SaveWord(WordInfoTable info); } } diff --git a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs index 47e064f..ae8bda4 100644 --- a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs +++ b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs @@ -11,6 +11,6 @@ namespace PrecastConcretePlantBusinessLogic.OfficePackage.HelperModels { public string FileName { get; set; } = string.Empty; public string Title { get; set; } = string.Empty; - public List ReinforcedComponents { get; set; } = new(); + public List ShopReinforcedies { get; set; } = new(); } } diff --git a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OfficePackage/HelperModels/ExcelInfoReinforced.cs b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OfficePackage/HelperModels/ExcelInfoReinforced.cs new file mode 100644 index 0000000..9d196e8 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OfficePackage/HelperModels/ExcelInfoReinforced.cs @@ -0,0 +1,20 @@ +using PrecastConcretePlantContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantBusinessLogic.OfficePackage.HelperModels +{ + public class ExcelInfoReinforced + { + public string FileName { get; set; } = string.Empty; + public string Title { get; set; } = string.Empty; + public List ReinforcedComponents + { + get; + set; + } = new(); + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs index a67ae02..a565372 100644 --- a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs +++ b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs @@ -13,6 +13,6 @@ namespace PrecastConcretePlantBusinessLogic.OfficePackage.HelperModels public string Title { get; set; } = string.Empty; public DateTime DateFrom { get; set; } public DateTime DateTo { get; set; } - public List Orders { get; set; } = new(); + public List Orders { get; set; } = new(); } } diff --git a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OfficePackage/HelperModels/PdfInfoOrders.cs b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OfficePackage/HelperModels/PdfInfoOrders.cs new file mode 100644 index 0000000..8bf0344 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OfficePackage/HelperModels/PdfInfoOrders.cs @@ -0,0 +1,29 @@ +using PrecastConcretePlantContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantBusinessLogic.OfficePackage.HelperModels +{ + public class PdfInfoOrders + { + 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(); + + public static implicit operator PdfInfo(PdfInfoOrders orders) + { + return new PdfInfo() + { + DateFrom = orders.DateFrom, + DateTo = orders.DateTo, + FileName = orders.FileName, + Title = orders.Title + }; + } + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OfficePackage/HelperModels/WordInfo.cs b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OfficePackage/HelperModels/WordInfo.cs index 48a059e..1fd6ab5 100644 --- a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OfficePackage/HelperModels/WordInfo.cs +++ b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OfficePackage/HelperModels/WordInfo.cs @@ -11,6 +11,7 @@ namespace PrecastConcretePlantBusinessLogic.OfficePackage.HelperModels { public string FileName { get; set; } = string.Empty; public string Title { get; set; } = string.Empty; - public List Reinforceds { get; set; } = new(); + public List Reinforcedies { get; set; } = new(); + public List Shops { get; set; } = new(); } } diff --git a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OfficePackage/HelperModels/WordInfoTable.cs b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OfficePackage/HelperModels/WordInfoTable.cs new file mode 100644 index 0000000..e5820b7 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OfficePackage/HelperModels/WordInfoTable.cs @@ -0,0 +1,16 @@ +using PrecastConcretePlantContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantBusinessLogic.OfficePackage.HelperModels +{ + public class WordInfoTable + { + public string FileName { get; set; } = string.Empty; + public string Title { get; set; } = string.Empty; + public List Shops { get; set; } = new(); + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OfficePackage/Implements/SaveToWord.cs b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OfficePackage/Implements/SaveToWord.cs index b6d7c6f..cfc86e3 100644 --- a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OfficePackage/Implements/SaveToWord.cs +++ b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OfficePackage/Implements/SaveToWord.cs @@ -3,26 +3,22 @@ using DocumentFormat.OpenXml.Packaging; using DocumentFormat.OpenXml.Wordprocessing; using PrecastConcretePlantBusinessLogic.OfficePackage.HelperEnums; using PrecastConcretePlantBusinessLogic.OfficePackage.HelperModels; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Reflection.Metadata; -using System.Text; -using System.Threading.Tasks; -using static System.Net.Mime.MediaTypeNames; -using Document = DocumentFormat.OpenXml.Wordprocessing.Document; -using Text = DocumentFormat.OpenXml.Wordprocessing.Text; + namespace PrecastConcretePlantBusinessLogic.OfficePackage.Implements { public class SaveToWord : AbstractSaveToWord { private WordprocessingDocument? _wordDocument; + private Body? _docBody; - - private static JustificationValues - GetJustificationValues(WordJustificationType type) + /// + /// Получение типа выравнивания + /// + /// + /// + private static JustificationValues GetJustificationValues(WordJustificationType type) { return type switch { @@ -32,54 +28,68 @@ namespace PrecastConcretePlantBusinessLogic.OfficePackage.Implements }; } + /// + /// Настройки страницы + /// + /// 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) + /// + /// Задание форматирования для абзаца + /// + /// + /// + 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) + protected override void CreateWord(WordInfoTable 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) @@ -89,9 +99,11 @@ namespace PrecastConcretePlantBusinessLogic.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) @@ -99,24 +111,66 @@ namespace PrecastConcretePlantBusinessLogic.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) + + protected override void SaveWord(WordInfoTable info) { if (_docBody == null || _wordDocument == null) { return; } _docBody.AppendChild(CreateSectionProperties()); + _wordDocument.MainDocumentPart!.Document.Save(); + _wordDocument.Close(); } + + private static TableCell GetTableCell(string text, int? widthCell = null) + { + + TableCell cell = new(new Paragraph(new Run(new Text(text)))); + if (widthCell != null) + { + cell.Append(new TableCellProperties() + { + TableCellWidth = new() { Width = widthCell.ToString() } + }); + } + return cell; + } + + protected override void CreateTable(List<(string, int?)> nameAndWidthColumns, List> rows) + { + if (_docBody == null) + { + return; + } + Table table = new(); + TableProperties tblProp = new TableProperties( + new TableBorders( + new TopBorder() { Val = new EnumValue(BorderValues.BasicBlackDashes), Size = 3 }, + new BottomBorder() { Val = new EnumValue(BorderValues.BasicBlackDashes), Size = 3 }, + new LeftBorder() { Val = new EnumValue(BorderValues.BasicBlackDashes), Size = 3 }, + new RightBorder() { Val = new EnumValue(BorderValues.BasicBlackDashes), Size = 3 }, + new InsideHorizontalBorder() { Val = new EnumValue(BorderValues.BasicBlackDashes), Size = 3 }, + new InsideVerticalBorder() { Val = new EnumValue(BorderValues.BasicBlackDashes), Size = 3 } + ) + ); + table.AppendChild(tblProp); + + table.Append(new TableRow(nameAndWidthColumns.Select(x => GetTableCell(x.Item1, x.Item2)))); + + table.Append(rows.Select(x => new TableRow(x.Select(y => GetTableCell(y))))); + + _docBody.Append(table); + } } } diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IReportLogic.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IReportLogic.cs index 176f587..9eed1b0 100644 --- a/PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IReportLogic.cs +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IReportLogic.cs @@ -10,10 +10,15 @@ namespace PrecastConcretePlantContracts.BusinessLogicsContracts { public interface IReportLogic { + List GetShopReinforcedies(); List GetReinforcedComponents(); List GetOrders(ReportBindingModel model); + List GetGroupOrders(ReportBindingModel model); void SaveReinforcedsToWordFile(ReportBindingModel model); void SaveReinforcedComponentToExcelFile(ReportBindingModel model); void SaveOrdersToPdfFile(ReportBindingModel model); + void SaveShopsTableToWordFile(ReportBindingModel model); + void SaveShopReinforcedToExcelFile(ReportBindingModel model); + void SaveGroupOrdersToPdfFile(ReportBindingModel model); } } diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ReportGroupOrdersViewModel.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ReportGroupOrdersViewModel.cs new file mode 100644 index 0000000..3389be6 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ReportGroupOrdersViewModel.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantContracts.ViewModels +{ + public class ReportGroupOrdersViewModel + { + public int Id { get; set; } + public DateTime Date { get; set; } + public int Count { get; set; } + public double Sum { get; set; } + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ReportComponentBlankViewModel.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ReportReinforcedComponentViewModel.cs similarity index 100% rename from PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ReportComponentBlankViewModel.cs rename to PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ReportReinforcedComponentViewModel.cs diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ReportShopReinforcedViewModel.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ReportShopReinforcedViewModel.cs new file mode 100644 index 0000000..e1e3e8e --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ReportShopReinforcedViewModel.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantContracts.ViewModels +{ + public class ReportShopReinforcedViewModel + { + public string ShopName { get; set; } = string.Empty; + public int TotalCount { get; set; } + public List> Reinforcedies { get; set; } = new(); + public double Workload { get; set; } + } +}