From 61b1751dd1c3ae99e42aedfc2296ee72fb32a79f Mon Sep 17 00:00:00 2001 From: antoc0der <1@DESKTOP-K1L8ND3> Date: Thu, 4 Apr 2024 12:07:16 +0400 Subject: [PATCH] =?UTF-8?q?=D1=87=D1=82=D0=BE=D0=B1=D1=8B=20=D0=BD=D0=B5?= =?UTF-8?q?=20=D1=83=D0=B4=D0=B0=D0=BB=D1=8F=D0=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FormReportDateOrders.Designer.cs | 80 ++++++++++++ ProjectFlowerShop/FormReportDateOrders.cs | 39 ++++++ ProjectFlowerShop/FormReportDateOrders.resx | 120 ++++++++++++++++++ .../FormReportShopsFlowers.Designer.cs | 34 ++++- ProjectFlowerShop/FormReportShopsFlowers.cs | 71 ++++++++++- 5 files changed, 340 insertions(+), 4 deletions(-) create mode 100644 ProjectFlowerShop/FormReportDateOrders.Designer.cs create mode 100644 ProjectFlowerShop/FormReportDateOrders.cs create mode 100644 ProjectFlowerShop/FormReportDateOrders.resx diff --git a/ProjectFlowerShop/FormReportDateOrders.Designer.cs b/ProjectFlowerShop/FormReportDateOrders.Designer.cs new file mode 100644 index 0000000..4880986 --- /dev/null +++ b/ProjectFlowerShop/FormReportDateOrders.Designer.cs @@ -0,0 +1,80 @@ +namespace ProjectFlowerShop +{ + partial class FormReportDateOrders + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + buttonCreate = new Button(); + buttonSaveToPdf = new Button(); + panel = new Panel(); + SuspendLayout(); + // + // buttonCreate + // + buttonCreate.Location = new Point(12, 12); + buttonCreate.Name = "buttonCreate"; + buttonCreate.Size = new Size(144, 33); + buttonCreate.TabIndex = 0; + buttonCreate.Text = "Сформировать"; + buttonCreate.UseVisualStyleBackColor = true; + // + // buttonSaveToPdf + // + buttonSaveToPdf.Location = new Point(680, 16); + buttonSaveToPdf.Name = "buttonSaveToPdf"; + buttonSaveToPdf.Size = new Size(108, 29); + buttonSaveToPdf.TabIndex = 1; + buttonSaveToPdf.Text = "В Pdf"; + buttonSaveToPdf.UseVisualStyleBackColor = true; + // + // panel + // + panel.Location = new Point(12, 51); + panel.Name = "panel"; + panel.Size = new Size(776, 387); + panel.TabIndex = 2; + // + // FormReportDateOrders + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(panel); + Controls.Add(buttonSaveToPdf); + Controls.Add(buttonCreate); + Name = "FormReportDateOrders"; + Text = "Заказы за полный период"; + ResumeLayout(false); + } + + #endregion + + private Button buttonCreate; + private Button buttonSaveToPdf; + private Panel panel; + } +} \ No newline at end of file diff --git a/ProjectFlowerShop/FormReportDateOrders.cs b/ProjectFlowerShop/FormReportDateOrders.cs new file mode 100644 index 0000000..fc01280 --- /dev/null +++ b/ProjectFlowerShop/FormReportDateOrders.cs @@ -0,0 +1,39 @@ +using FlowerShopContracts.BusinessLogicsContracts; +using Microsoft.Reporting.WinForms; +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 ProjectFlowerShop +{ + public partial class FormReportDateOrders : Form + { + private readonly ReportViewer reportViewer; + + private readonly ILogger _logger; + + private readonly IReportLogic _logic; + public FormReportDateOrders(ILogger logger, IReportLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + reportViewer = new ReportViewer + { + Dock = DockStyle.Fill + }; + reportViewer.LocalReport.LoadReportDefinition(new FileStream("ReportOrdersByDate.rdlc", FileMode.Open)); + panel.Controls.Add(reportViewer); + } + + + } +} diff --git a/ProjectFlowerShop/FormReportDateOrders.resx b/ProjectFlowerShop/FormReportDateOrders.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectFlowerShop/FormReportDateOrders.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/ProjectFlowerShop/FormReportShopsFlowers.Designer.cs b/ProjectFlowerShop/FormReportShopsFlowers.Designer.cs index 3662d1d..176581a 100644 --- a/ProjectFlowerShop/FormReportShopsFlowers.Designer.cs +++ b/ProjectFlowerShop/FormReportShopsFlowers.Designer.cs @@ -28,18 +28,48 @@ /// private void InitializeComponent() { + buttonSaveToExcel = new Button(); + dataGridView = new DataGridView(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); SuspendLayout(); // + // buttonSaveToExcel + // + buttonSaveToExcel.Location = new Point(12, 12); + buttonSaveToExcel.Name = "buttonSaveToExcel"; + buttonSaveToExcel.Size = new Size(168, 29); + buttonSaveToExcel.TabIndex = 0; + buttonSaveToExcel.Text = "Сохранить в Excel"; + buttonSaveToExcel.UseVisualStyleBackColor = true; + buttonSaveToExcel.Click += buttonSaveToExcel_Click; + // + // dataGridView + // + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(12, 67); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 29; + dataGridView.Size = new Size(742, 327); + dataGridView.TabIndex = 1; + // // FormReportShopsFlowers // AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(766, 278); + ClientSize = new Size(766, 406); + Controls.Add(dataGridView); + Controls.Add(buttonSaveToExcel); Name = "FormReportShopsFlowers"; - Text = "FormReportShopsFlowers"; + Text = "Загруженность магазинов"; + Load += FormReportShopsFlowers_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); ResumeLayout(false); } #endregion + + private Button buttonSaveToExcel; + private DataGridView dataGridView; } } \ No newline at end of file diff --git a/ProjectFlowerShop/FormReportShopsFlowers.cs b/ProjectFlowerShop/FormReportShopsFlowers.cs index 871e3eb..8817a73 100644 --- a/ProjectFlowerShop/FormReportShopsFlowers.cs +++ b/ProjectFlowerShop/FormReportShopsFlowers.cs @@ -1,4 +1,8 @@ -using System; +using FlowerShopContracts.BindingModels; +using FlowerShopContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; + +using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; @@ -12,9 +16,72 @@ namespace ProjectFlowerShop { public partial class FormReportShopsFlowers : Form { - public FormReportShopsFlowers() + private readonly ILogger _logger; + private readonly IReportLogic _logic; + public FormReportShopsFlowers(ILogger logger, IReportLogic logic) { InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormReportShopsFlowers_Load(object sender, EventArgs e) + { + try + { + var dict = _logic.GetShopsFlowers(); + if (dict != null) + { + dataGridView.Rows.Clear(); + foreach (var elem in dict) + { + dataGridView.Rows.Add(new object[] { elem.ShopName, "", "" }); + foreach (var listElem in elem.Flowers) + { + dataGridView.Rows.Add(new object[] { "", listElem.Item1, listElem.Item2 }); + } + dataGridView.Rows.Add(new object[] { "Итого", "", elem.TotalCount }); + dataGridView.Rows.Add(Array.Empty()); + } + } + _logger.LogInformation("Загрузка списка цветов по магазинам"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка цветов по магазинам"); + + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + + private void buttonSaveToExcel_Click(object sender, EventArgs e) + { + using var dialog = new SaveFileDialog + { + Filter = "xlsx|*.xlsx" + }; + if (dialog.ShowDialog() == DialogResult.OK) + { + try + { + _logic.SaveShopsFlowersToExcelFile(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); + } + } } } }