From e911493961e2210b3f1fee645ca34cbbe6ddfabf Mon Sep 17 00:00:00 2001
From: antoc0der <1@DESKTOP-K1L8ND3>
Date: Tue, 26 Mar 2024 18:10:51 +0400
Subject: [PATCH] =?UTF-8?q?=D1=87=D1=82=D0=BE=20=D1=82=D1=83=D1=82=20?=
=?UTF-8?q?=D1=81=D0=BA=D0=B0=D0=B6=D0=B5=D1=88=D1=8C=3F?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
FlowerShopBusinessLogic/ReportLogic.cs | 129 ++++++++++++++++
.../BusinessLogicsContracts/IReportLogic.cs | 2 +-
.../SearchModels/OrderSearchModel.cs | 2 +
.../FormReportFlowerComponent.Designer.cs | 103 +++++++++++++
.../FormReportFlowerComponent.cs | 88 +++++++++++
.../FormReportFlowerComponent.resx | 138 ++++++++++++++++++
ProjectFlowerShop/MainForm.Designer.cs | 39 ++++-
7 files changed, 497 insertions(+), 4 deletions(-)
create mode 100644 FlowerShopBusinessLogic/ReportLogic.cs
create mode 100644 ProjectFlowerShop/FormReportFlowerComponent.Designer.cs
create mode 100644 ProjectFlowerShop/FormReportFlowerComponent.cs
create mode 100644 ProjectFlowerShop/FormReportFlowerComponent.resx
diff --git a/FlowerShopBusinessLogic/ReportLogic.cs b/FlowerShopBusinessLogic/ReportLogic.cs
new file mode 100644
index 0000000..6362773
--- /dev/null
+++ b/FlowerShopBusinessLogic/ReportLogic.cs
@@ -0,0 +1,129 @@
+using FlowerShopBusinessLogic.OfficePackage.HelperModels;
+using FlowerShopBusinessLogic.OfficePackage;
+using FlowerShopContracts.BindingModels;
+using FlowerShopContracts.BusinessLogicsContracts;
+using FlowerShopContracts.SearchModels;
+using FlowerShopContracts.StoragesContracts;
+using FlowerShopContracts.ViewModels;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace FlowerShopBusinessLogic
+{
+ public class ReportLogic : IReportLogic
+ {
+ private readonly IComponentStorage _componentStorage;
+ private readonly IFlowerStorage _flowerStorage;
+ private readonly IOrderStorage _orderStorage;
+ private readonly AbstractSaveToExcel _saveToExcel;
+ private readonly AbstractSaveToWord _saveToWord;
+ private readonly AbstractSaveToPdf _saveToPdf;
+ public ReportLogic(IFlowerStorage flowerStorage, IComponentStorage
+ componentStorage, IOrderStorage orderStorage,
+ AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord,
+ AbstractSaveToPdf saveToPdf)
+ {
+ _flowerStorage = flowerStorage;
+ _componentStorage = componentStorage;
+ _orderStorage = orderStorage;
+ _saveToExcel = saveToExcel;
+ _saveToWord = saveToWord;
+ _saveToPdf = saveToPdf;
+ }
+ ///
+ /// Получение списка компонент с указанием, в каких изделиях используются
+ ///
+ ///
+ public List GetFlowerComponent()
+ {
+ var components = _componentStorage.GetFullList();
+ var flowers = _flowerStorage.GetFullList();
+ var list = new List();
+ foreach (var component in components)
+ {
+ var record = new ReportFlowerComponentViewModel
+ {
+ ComponentName = component.ComponentName,
+ Flowers = new List>(),
+ TotalCount = 0
+ };
+ foreach (var flower in flowers)
+ {
+ if (flower.FlowerComponents.ContainsKey(component.Id))
+ {
+ record.Flowers.Add(new Tuple(flower.FlowerName, flower.FlowerComponents[component.Id].Item2));
+ record.TotalCount +=flower.FlowerComponents[component.Id].Item2;
+ }
+ }
+ list.Add(record);
+ }
+ return list;
+ }
+ ///
+ /// Получение списка заказов за определенный период
+ ///
+ ///
+ ///
+ public List GetOrders(ReportBindingModel model)
+ {
+ return _orderStorage.GetFilteredList(new OrderSearchModel
+ {
+ DateFrom
+ = model.DateFrom,
+ DateTo = model.DateTo
+ })
+ .Select(x => new ReportOrdersViewModel
+ {
+ Id = x.Id,
+ DateCreate = x.DateCreate,
+ FlowerName = x.FlowerName,
+ Sum = x.Sum
+ })
+ .ToList();
+ }
+ ///
+ /// Сохранение компонент в файл-Word
+ ///
+ ///
+ public void SaveComponentsToWordFile(ReportBindingModel model)
+ {
+ _saveToWord.CreateDoc(new WordInfo
+ {
+ FileName = model.FileName,
+ Title = "Список компонент",
+ Components = _componentStorage.GetFullList()
+ });
+ }
+ ///
+ /// Сохранение компонент с указаеним продуктов в файл-Excel
+ ///
+ ///
+ public void SaveFlowerComponentToExcelFile(ReportBindingModel model)
+ {
+ _saveToExcel.CreateReport(new ExcelInfo
+ {
+ FileName = model.FileName,
+ Title = "Список компонент",
+ FlowerComponents = GetFlowerComponent()
+ });
+ }
+ ///
+ /// Сохранение заказов в файл-Pdf
+ ///
+ ///
+ public void SaveOrdersToPdfFile(ReportBindingModel model)
+ {
+ _saveToPdf.CreateDoc(new PdfInfo
+ {
+ FileName = model.FileName,
+ Title = "Список заказов",
+ DateFrom = model.DateFrom!.Value,
+ DateTo = model.DateTo!.Value,
+ Orders = GetOrders(model)
+ });
+ }
+ }
+}
diff --git a/FlowerShopContracts/BusinessLogicsContracts/IReportLogic.cs b/FlowerShopContracts/BusinessLogicsContracts/IReportLogic.cs
index 154de41..0b68630 100644
--- a/FlowerShopContracts/BusinessLogicsContracts/IReportLogic.cs
+++ b/FlowerShopContracts/BusinessLogicsContracts/IReportLogic.cs
@@ -30,7 +30,7 @@ namespace FlowerShopContracts.BusinessLogicsContracts
/// Сохранение компонент с указаеним продуктов в файл-Excel
///
///
- void SaveProductComponentToExcelFile(ReportBindingModel model);
+ void SaveFlowerComponentToExcelFile(ReportBindingModel model);
///
/// Сохранение заказов в файл-Pdf
///
diff --git a/FlowerShopContracts/SearchModels/OrderSearchModel.cs b/FlowerShopContracts/SearchModels/OrderSearchModel.cs
index 5b569de..c8cd5d3 100644
--- a/FlowerShopContracts/SearchModels/OrderSearchModel.cs
+++ b/FlowerShopContracts/SearchModels/OrderSearchModel.cs
@@ -9,5 +9,7 @@ namespace FlowerShopContracts.SearchModels
public class OrderSearchModel
{
public int? Id { get; set; }
+ public DateTime? DateFrom { get; set; }
+ public DateTime? DateTo { get; set; }
}
}
diff --git a/ProjectFlowerShop/FormReportFlowerComponent.Designer.cs b/ProjectFlowerShop/FormReportFlowerComponent.Designer.cs
new file mode 100644
index 0000000..112e00a
--- /dev/null
+++ b/ProjectFlowerShop/FormReportFlowerComponent.Designer.cs
@@ -0,0 +1,103 @@
+namespace ProjectFlowerShop
+{
+ partial class FormReportFlowerComponent
+ {
+ ///
+ /// 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()
+ {
+ buttonSaveToExcel = new Button();
+ dataGridView = new DataGridView();
+ Component = new DataGridViewTextBoxColumn();
+ Flower = new DataGridViewTextBoxColumn();
+ Count = new DataGridViewTextBoxColumn();
+ ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
+ SuspendLayout();
+ //
+ // buttonSaveToExcel
+ //
+ buttonSaveToExcel.Location = new Point(12, 21);
+ buttonSaveToExcel.Name = "buttonSaveToExcel";
+ buttonSaveToExcel.Size = new Size(207, 29);
+ buttonSaveToExcel.TabIndex = 0;
+ buttonSaveToExcel.Text = "Сохранить в Excel";
+ buttonSaveToExcel.UseVisualStyleBackColor = true;
+ buttonSaveToExcel.Click += buttonSaveToExcel_Click;
+ //
+ // dataGridView
+ //
+ dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+ dataGridView.Columns.AddRange(new DataGridViewColumn[] { Component, Flower, Count });
+ dataGridView.Location = new Point(12, 65);
+ dataGridView.Name = "dataGridView";
+ dataGridView.RowHeadersWidth = 51;
+ dataGridView.RowTemplate.Height = 29;
+ dataGridView.Size = new Size(812, 359);
+ dataGridView.TabIndex = 1;
+ //
+ // Component
+ //
+ Component.HeaderText = "Компонент";
+ Component.MinimumWidth = 6;
+ Component.Name = "Component";
+ Component.Width = 250;
+ //
+ // Flower
+ //
+ Flower.HeaderText = "Изделие";
+ Flower.MinimumWidth = 6;
+ Flower.Name = "Flower";
+ Flower.Width = 250;
+ //
+ // Count
+ //
+ Count.HeaderText = "Количество";
+ Count.MinimumWidth = 6;
+ Count.Name = "Count";
+ Count.Width = 250;
+ //
+ // FormReportFlowerComponent
+ //
+ AutoScaleDimensions = new SizeF(8F, 20F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(836, 450);
+ Controls.Add(dataGridView);
+ Controls.Add(buttonSaveToExcel);
+ Name = "FormReportFlowerComponent";
+ Text = "FormReportFlowerComponent";
+ Load += FormReportFlowerComponent_Load;
+ ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
+ ResumeLayout(false);
+ }
+
+ #endregion
+
+ private Button buttonSaveToExcel;
+ private DataGridView dataGridView;
+ private DataGridViewTextBoxColumn Component;
+ private DataGridViewTextBoxColumn Flower;
+ private DataGridViewTextBoxColumn Count;
+ }
+}
\ No newline at end of file
diff --git a/ProjectFlowerShop/FormReportFlowerComponent.cs b/ProjectFlowerShop/FormReportFlowerComponent.cs
new file mode 100644
index 0000000..ceb3959
--- /dev/null
+++ b/ProjectFlowerShop/FormReportFlowerComponent.cs
@@ -0,0 +1,88 @@
+using FlowerShopContracts.BusinessLogicsContracts;
+using FlowerShopContracts.BindingModels;
+
+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;
+using Microsoft.Extensions.Logging;
+
+
+namespace ProjectFlowerShop
+{
+ public partial class FormReportFlowerComponent : Form
+ {
+ private readonly ILogger _logger;
+ private readonly IReportLogic _logic;
+
+ public FormReportFlowerComponent(ILogger logger, IReportLogic logic)
+ {
+ InitializeComponent();
+ _logger = logger;
+ _logic = logic;
+ }
+
+ private void buttonSaveToExcel_Click(object sender, EventArgs e)
+ {
+ using var dialog = new SaveFileDialog
+ {
+ Filter = "xlsx|*.xlsx"
+ };
+ if (dialog.ShowDialog() == DialogResult.OK)
+ {
+ try
+ {
+ _logic.SaveFlowerComponentToExcelFile(new ReportBindingModel
+ {
+ FileName = dialog.FileName
+ });
+ _logger.LogInformation("Сохранение списка изделий покомпонентам");
+
+ MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK,
+ MessageBoxIcon.Information);
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка сохранения списка изделий покомпонентам");
+
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
+ MessageBoxIcon.Error);
+ }
+ }
+ }
+
+ private void FormReportFlowerComponent_Load(object sender, EventArgs e)
+ {
+ try
+ {
+ var dict = _logic.GetFlowerComponent();
+ if (dict != null)
+ {
+ dataGridView.Rows.Clear();
+ foreach (var elem in dict)
+ {
+ dataGridView.Rows.Add(new object[] { elem.ComponentName, "", "" });
+ 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