From 560194eb95eb6b63645b930a148163ed24baa5e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=98=D0=BB=D1=8C=D1=8F=20=D0=A4=D0=B5=D0=B4=D0=BE=D1=82?= =?UTF-8?q?=D0=BE=D0=B2?= Date: Tue, 2 Jul 2024 17:28:23 +0400 Subject: [PATCH] bug fix/xlsx file make --- .../BusinessLogic/ReportClientLogic.cs | 54 ++++++++++++-- .../AbstractSaveToExcelClient.cs | 73 +++++++++---------- .../HelperEnums/ExcelStyleInfoType.cs | 2 - .../HelperModels/ExcelInfoClient.cs | 4 +- .../Implements/SaveToExcelClient.cs | 6 +- .../IReportClientLogic.cs | 7 +- .../ReportPaymeantProductsViewModel.cs | 13 ++++ .../DataBase.cs | 6 +- .../Implements/ProductStorage.cs | 2 +- .../Controllers/MainController.cs | 2 - .../Controllers/HomeController.cs | 10 ++- .../Views/Home/AddProduct.cshtml | 4 +- .../Views/Home/Privacy.cshtml | 8 +- .../Views/Home/ReportSearch.cshtml | 7 ++ 14 files changed, 129 insertions(+), 69 deletions(-) create mode 100644 ElectronicsShop/ElectronicsShopContracts/ViewModels/ReportPaymeantProductsViewModel.cs diff --git a/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/ReportClientLogic.cs b/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/ReportClientLogic.cs index bf3eb46..4811c4a 100644 --- a/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/ReportClientLogic.cs +++ b/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/ReportClientLogic.cs @@ -12,15 +12,22 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic public class ReportClientLogic : IReportClientLogic { private readonly IPaymeantStorage _paymeantstorage; + private readonly IProductStorage _productstorage; + private readonly IOrderStorage _orderStorage; private readonly AbstractSaveToExcelClient _saveToExcel; private readonly AbstractSaveToWordClient _saveToWord; - public ReportClientLogic(AbstractSaveToExcelClient abstractSaveToExcelClient, AbstractSaveToWordClient abstractSaveToWordClient, IPaymeantStorage paymeantStorage) { + public ReportClientLogic(AbstractSaveToExcelClient abstractSaveToExcelClient, AbstractSaveToWordClient abstractSaveToWordClient, + IPaymeantStorage paymeantStorage, IProductStorage productStorage, IOrderStorage orderStorage) { _saveToExcel = abstractSaveToExcelClient; _saveToWord= abstractSaveToWordClient; _paymeantstorage = paymeantStorage; + _productstorage = productStorage; + _orderStorage = orderStorage; } - public List GetPaymeants(ReportBindingModel model) + + // получение списка оплат за период + public List GetPaymeants(ReportBindingModel model) { return _paymeantstorage.GetFillteredList(new PaymeantSearchModel { DateFrom = model.DateFrom, @@ -35,14 +42,45 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic }).ToList(); } - public void SavePaymeantToExcelFile(ReportBindingModel model) + // Получение списка товаров с указанием, в какие оплаты товар входит + public List GetPaymeantProducts(int _clientID) { + var products = _productstorage.GetFullList(); + var paymeants = _paymeantstorage.GetFillteredList(new PaymeantSearchModel { ClientID = _clientID }); + + var list = new List(); + + foreach (var paymeant in paymeants) { + var record = new ReportPaymeantProductsViewModel { + PaymeantID = paymeant.ID, + Products = new(), + TotalCount = 0 + }; + + var order = _orderStorage.GetElement(new OrderSearchModel { ID = paymeant.OrderID }); + if (order == null) { + continue; + } + + foreach (var product in products) { + if (order.ProductList.ContainsKey(product.ID)) { + record.Products.Add(new(product.ProductName, order.ProductList[product.ID].Item2)); + record.TotalCount += order.ProductList[product.ID].Item2; + } + } + list.Add(record); + } + + return list; + } + + public void SavePaymeantToExcelFile(ReportBindingModel model, int _clientID) { _saveToExcel.CreateReport(new ExcelInfoClient { - //FileName = model.ProductName, + FileName = model.FileName, Title = "Список оплат", - Paymeants = _paymeantstorage.GetFullList(), - }); + PaymeantProducts = GetPaymeantProducts(_clientID) + }); } public void SavePaymeantToWordFile(ReportBindingModel model) @@ -54,5 +92,7 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic ListPaymeant = _paymeantstorage.GetFullList(), }) ; } - } + + + } } diff --git a/ElectronicsShop/ElectronicsShopBusinessLogic/OfficePackage/AbstractSaveToExcelClient.cs b/ElectronicsShop/ElectronicsShopBusinessLogic/OfficePackage/AbstractSaveToExcelClient.cs index 8b32211..2ba3a11 100644 --- a/ElectronicsShop/ElectronicsShopBusinessLogic/OfficePackage/AbstractSaveToExcelClient.cs +++ b/ElectronicsShop/ElectronicsShopBusinessLogic/OfficePackage/AbstractSaveToExcelClient.cs @@ -6,79 +6,74 @@ namespace ElectronicsShopBusinessLogic.OfficePackage { public abstract class AbstractSaveToExcelClient { - public void CreateReport(ExcelInfoClient info) - { + public void CreateReport(ExcelInfoClient info) { CreateExcel(info); - InsertCellInWorksheet(new ExcelCellParameters - { + InsertCellInWorksheet(new ExcelCellParameters { ColumnName = "A", RowIndex = 1, Text = info.Title, StyleInfo = ExcelStyleInfoType.Title }); - MergeCells(new ExcelMergeParameters - { + MergeCells(new ExcelMergeParameters { CellFromName = "A1", CellToName = "C1" }); uint rowIndex = 2; - foreach (var pc in info.Paymeants) - { - InsertCellInWorksheet(new ExcelCellParameters - { + foreach (var pp in info.PaymeantProducts) { + InsertCellInWorksheet(new ExcelCellParameters { ColumnName = "A", RowIndex = rowIndex, - Text = pc.OrderID.ToString(), + Text = pp.PaymeantID.ToString(), StyleInfo = ExcelStyleInfoType.Text }); rowIndex++; + foreach (var (Product, Count) in pp.Products) { + InsertCellInWorksheet(new ExcelCellParameters { + ColumnName = "B", + RowIndex = rowIndex, + Text = Product, + StyleInfo = ExcelStyleInfoType.TextWithBroder + }); - InsertCellInWorksheet(new ExcelCellParameters - { - ColumnName = "B", + InsertCellInWorksheet(new ExcelCellParameters { + ColumnName = "C", + RowIndex = rowIndex, + Text = Count.ToString(), + StyleInfo = ExcelStyleInfoType.TextWithBroder + }); + rowIndex++; + } + InsertCellInWorksheet(new ExcelCellParameters { + ColumnName = "A", RowIndex = rowIndex, - Text = pc.PayOption.ToString(), - StyleInfo = ExcelStyleInfoType.Text + Text = "Итого", + StyleInfo = ExcelStyleInfoType.Title }); - InsertCellInWorksheet(new ExcelCellParameters - { + + InsertCellInWorksheet(new ExcelCellParameters { ColumnName = "C", RowIndex = rowIndex, - Text = pc.SumPayment.ToString(), - StyleInfo = ExcelStyleInfoType.TextWithBroder + Text = pp.TotalCount.ToString(), + StyleInfo = ExcelStyleInfoType.Title }); - rowIndex++; } - SaveExcel(info); - } + } - /// - /// Создание excel-файла - /// - /// + // Создание excel-файла protected abstract void CreateExcel(ExcelInfoClient info); - /// - /// Добавляем новую ячейку в лист - /// - /// + // Добавляем новую ячейку в лист protected abstract void InsertCellInWorksheet(ExcelCellParameters excelParams); - /// - /// Объединение ячеек - /// - /// + // Объединение ячеек protected abstract void MergeCells(ExcelMergeParameters excelParams); - /// - /// Сохранение файла - /// - /// + // Сохранение файла protected abstract void SaveExcel(ExcelInfoClient info); } } diff --git a/ElectronicsShop/ElectronicsShopBusinessLogic/OfficePackage/HelperEnums/ExcelStyleInfoType.cs b/ElectronicsShop/ElectronicsShopBusinessLogic/OfficePackage/HelperEnums/ExcelStyleInfoType.cs index dc4ebc5..0bc9bf8 100644 --- a/ElectronicsShop/ElectronicsShopBusinessLogic/OfficePackage/HelperEnums/ExcelStyleInfoType.cs +++ b/ElectronicsShop/ElectronicsShopBusinessLogic/OfficePackage/HelperEnums/ExcelStyleInfoType.cs @@ -9,9 +9,7 @@ namespace ElectronicsShopBusinessLogic.OfficePackage.HelperEnums public enum ExcelStyleInfoType { Title, - Text, - TextWithBroder } } diff --git a/ElectronicsShop/ElectronicsShopBusinessLogic/OfficePackage/HelperModels/ExcelInfoClient.cs b/ElectronicsShop/ElectronicsShopBusinessLogic/OfficePackage/HelperModels/ExcelInfoClient.cs index a2cedde..43dc843 100644 --- a/ElectronicsShop/ElectronicsShopBusinessLogic/OfficePackage/HelperModels/ExcelInfoClient.cs +++ b/ElectronicsShop/ElectronicsShopBusinessLogic/OfficePackage/HelperModels/ExcelInfoClient.cs @@ -5,9 +5,7 @@ namespace ElectronicsShopBusinessLogic.OfficePackage.HelperModels public class ExcelInfoClient { public string FileName { get; set; } = string.Empty; - public string Title { get; set; } = string.Empty; - - public List Paymeants { get; set; } = new(); + public List PaymeantProducts { get; set; } = new(); } } diff --git a/ElectronicsShop/ElectronicsShopBusinessLogic/OfficePackage/Implements/SaveToExcelClient.cs b/ElectronicsShop/ElectronicsShopBusinessLogic/OfficePackage/Implements/SaveToExcelClient.cs index eab254e..1f6fbfa 100644 --- a/ElectronicsShop/ElectronicsShopBusinessLogic/OfficePackage/Implements/SaveToExcelClient.cs +++ b/ElectronicsShop/ElectronicsShopBusinessLogic/OfficePackage/Implements/SaveToExcelClient.cs @@ -135,11 +135,7 @@ namespace ElectronicsShopBusinessLogic.OfficePackage.Implements sp.Stylesheet.Append(stylesheetExtensionList); } - /// - /// Получение номера стиля из типа - /// - /// - /// + // Получение номера стиля из типа private static uint GetStyleValue(ExcelStyleInfoType styleInfo) { return styleInfo switch diff --git a/ElectronicsShop/ElectronicsShopContracts/BusinessLogicContracts/IReportClientLogic.cs b/ElectronicsShop/ElectronicsShopContracts/BusinessLogicContracts/IReportClientLogic.cs index 8937855..ee7cae8 100644 --- a/ElectronicsShop/ElectronicsShopContracts/BusinessLogicContracts/IReportClientLogic.cs +++ b/ElectronicsShop/ElectronicsShopContracts/BusinessLogicContracts/IReportClientLogic.cs @@ -10,8 +10,13 @@ namespace ElectronicsShopContracts.BusinessLogicContracts { public interface IReportClientLogic { + // получение списка товаров с указанием, в какие оплаты товар входит + List GetPaymeantProducts(int _clientID); + // получения списка оплат List GetPaymeants(ReportBindingModel model); void SavePaymeantToWordFile(ReportBindingModel model); - void SavePaymeantToExcelFile(ReportBindingModel model); + + // Сохранение компонент с указанием отчета в .excel + void SavePaymeantToExcelFile(ReportBindingModel model, int _clientID); } } diff --git a/ElectronicsShop/ElectronicsShopContracts/ViewModels/ReportPaymeantProductsViewModel.cs b/ElectronicsShop/ElectronicsShopContracts/ViewModels/ReportPaymeantProductsViewModel.cs new file mode 100644 index 0000000..a49c6b5 --- /dev/null +++ b/ElectronicsShop/ElectronicsShopContracts/ViewModels/ReportPaymeantProductsViewModel.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ElectronicsShopContracts.ViewModels { + public class ReportPaymeantProductsViewModel { + public int PaymeantID { get; set; } + public int TotalCount { get; set; } + public List<(string Product, int count)> Products { get; set; } = new(); + } +} diff --git a/ElectronicsShop/ElectronicsShopDataBaseImplement/DataBase.cs b/ElectronicsShop/ElectronicsShopDataBaseImplement/DataBase.cs index 2830f99..b327360 100644 --- a/ElectronicsShop/ElectronicsShopDataBaseImplement/DataBase.cs +++ b/ElectronicsShop/ElectronicsShopDataBaseImplement/DataBase.cs @@ -7,12 +7,12 @@ namespace ElectronicsShopDataBaseImplement public class Database : DbContext { //DESKTOP-E2VPEN3 - //DESKTOP-O0N00SH + //WIN-4HUIDGH3G02 protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { if (optionsBuilder.IsConfigured == false) { - optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-O0N00SH\SQLEXPRESS;Initial Catalog=ElectronicsShopDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); + optionsBuilder.UseSqlServer(@"Data Source=WIN-4HUIDGH3G02\SQLEXPRESS;Initial Catalog=ElectronicsShopDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); } base.OnConfiguring(optionsBuilder); } @@ -25,4 +25,4 @@ namespace ElectronicsShopDataBaseImplement public virtual DbSet Paymeants { get; set; } public virtual DbSet Messages { set; get; } } -} +} \ No newline at end of file diff --git a/ElectronicsShop/ElectronicsShopDataBaseImplement/Implements/ProductStorage.cs b/ElectronicsShop/ElectronicsShopDataBaseImplement/Implements/ProductStorage.cs index 086307a..7cf4185 100644 --- a/ElectronicsShop/ElectronicsShopDataBaseImplement/Implements/ProductStorage.cs +++ b/ElectronicsShop/ElectronicsShopDataBaseImplement/Implements/ProductStorage.cs @@ -59,7 +59,7 @@ namespace ElectronicsShopDataBaseImplement.Implements { using var context = new Database(); - if (model.ID.HasValue && !string.IsNullOrEmpty(model.ProductName)) { + if (model.ID.HasValue && string.IsNullOrEmpty(model.ProductName)) { return context.Products .Include(x => x.CostItem) .FirstOrDefault(x => (!string.IsNullOrEmpty(model.ProductName) && x.ProductName == model.ProductName) || diff --git a/ElectronicsShop/ElectronicsShopRestAPI/Controllers/MainController.cs b/ElectronicsShop/ElectronicsShopRestAPI/Controllers/MainController.cs index f0ac137..66c75a0 100644 --- a/ElectronicsShop/ElectronicsShopRestAPI/Controllers/MainController.cs +++ b/ElectronicsShop/ElectronicsShopRestAPI/Controllers/MainController.cs @@ -135,8 +135,6 @@ namespace ElectronicsShopRestAPI.Controllers { } } - - [HttpPost] public void AddProduct(List jslist) { diff --git a/ElectronicsShop/ElectronicsShopShopClientApp/Controllers/HomeController.cs b/ElectronicsShop/ElectronicsShopShopClientApp/Controllers/HomeController.cs index f1d1894..48f2e18 100644 --- a/ElectronicsShop/ElectronicsShopShopClientApp/Controllers/HomeController.cs +++ b/ElectronicsShop/ElectronicsShopShopClientApp/Controllers/HomeController.cs @@ -307,5 +307,11 @@ namespace ElectronicsShopUserApp.Controllers { (DateTime, DateTime, List) tuple = (_datefrom, _dateto, reports); return View(tuple); } - } -} + + //todo / + [HttpPost] + public void CreateExcelReport() { + + } + } +} \ No newline at end of file diff --git a/ElectronicsShop/ElectronicsShopShopClientApp/Views/Home/AddProduct.cshtml b/ElectronicsShop/ElectronicsShopShopClientApp/Views/Home/AddProduct.cshtml index 9ec8b4d..32dfa0d 100644 --- a/ElectronicsShop/ElectronicsShopShopClientApp/Views/Home/AddProduct.cshtml +++ b/ElectronicsShop/ElectronicsShopShopClientApp/Views/Home/AddProduct.cshtml @@ -2,13 +2,13 @@ ViewData["Title"] = "AddProduct"; }
-

Создание заказа

+

Добавить товар

Продукты:
- +
diff --git a/ElectronicsShop/ElectronicsShopShopClientApp/Views/Home/Privacy.cshtml b/ElectronicsShop/ElectronicsShopShopClientApp/Views/Home/Privacy.cshtml index c71513b..c722309 100644 --- a/ElectronicsShop/ElectronicsShopShopClientApp/Views/Home/Privacy.cshtml +++ b/ElectronicsShop/ElectronicsShopShopClientApp/Views/Home/Privacy.cshtml @@ -10,13 +10,17 @@
-
Логин:
-
+
Почта:
+
Пароль:
+
+
ФИО:
+
+
diff --git a/ElectronicsShop/ElectronicsShopShopClientApp/Views/Home/ReportSearch.cshtml b/ElectronicsShop/ElectronicsShopShopClientApp/Views/Home/ReportSearch.cshtml index 8bb8c84..20fe908 100644 --- a/ElectronicsShop/ElectronicsShopShopClientApp/Views/Home/ReportSearch.cshtml +++ b/ElectronicsShop/ElectronicsShopShopClientApp/Views/Home/ReportSearch.cshtml @@ -23,7 +23,14 @@
+