bug fix/xlsx file make

This commit is contained in:
Илья Федотов 2024-07-02 17:28:23 +04:00
parent a8ccf282e3
commit 560194eb95
14 changed files with 129 additions and 69 deletions

View File

@ -12,14 +12,21 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic
public class ReportClientLogic : IReportClientLogic public class ReportClientLogic : IReportClientLogic
{ {
private readonly IPaymeantStorage _paymeantstorage; private readonly IPaymeantStorage _paymeantstorage;
private readonly IProductStorage _productstorage;
private readonly IOrderStorage _orderStorage;
private readonly AbstractSaveToExcelClient _saveToExcel; private readonly AbstractSaveToExcelClient _saveToExcel;
private readonly AbstractSaveToWordClient _saveToWord; 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; _saveToExcel = abstractSaveToExcelClient;
_saveToWord= abstractSaveToWordClient; _saveToWord= abstractSaveToWordClient;
_paymeantstorage = paymeantStorage; _paymeantstorage = paymeantStorage;
_productstorage = productStorage;
_orderStorage = orderStorage;
} }
// получение списка оплат за период
public List<ReportPaymeantsViewModel> GetPaymeants(ReportBindingModel model) public List<ReportPaymeantsViewModel> GetPaymeants(ReportBindingModel model)
{ {
return _paymeantstorage.GetFillteredList(new PaymeantSearchModel { return _paymeantstorage.GetFillteredList(new PaymeantSearchModel {
@ -35,13 +42,44 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic
}).ToList(); }).ToList();
} }
public void SavePaymeantToExcelFile(ReportBindingModel model) // Получение списка товаров с указанием, в какие оплаты товар входит
public List<ReportPaymeantProductsViewModel> GetPaymeantProducts(int _clientID) {
var products = _productstorage.GetFullList();
var paymeants = _paymeantstorage.GetFillteredList(new PaymeantSearchModel { ClientID = _clientID });
var list = new List<ReportPaymeantProductsViewModel>();
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 _saveToExcel.CreateReport(new ExcelInfoClient
{ {
//FileName = model.ProductName, FileName = model.FileName,
Title = "Список оплат", Title = "Список оплат",
Paymeants = _paymeantstorage.GetFullList(), PaymeantProducts = GetPaymeantProducts(_clientID)
}); });
} }
@ -54,5 +92,7 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic
ListPaymeant = _paymeantstorage.GetFullList(), ListPaymeant = _paymeantstorage.GetFullList(),
}) ; }) ;
} }
} }
} }

View File

@ -6,79 +6,74 @@ namespace ElectronicsShopBusinessLogic.OfficePackage
{ {
public abstract class AbstractSaveToExcelClient public abstract class AbstractSaveToExcelClient
{ {
public void CreateReport(ExcelInfoClient info) public void CreateReport(ExcelInfoClient info) {
{
CreateExcel(info); CreateExcel(info);
InsertCellInWorksheet(new ExcelCellParameters InsertCellInWorksheet(new ExcelCellParameters {
{
ColumnName = "A", ColumnName = "A",
RowIndex = 1, RowIndex = 1,
Text = info.Title, Text = info.Title,
StyleInfo = ExcelStyleInfoType.Title StyleInfo = ExcelStyleInfoType.Title
}); });
MergeCells(new ExcelMergeParameters MergeCells(new ExcelMergeParameters {
{
CellFromName = "A1", CellFromName = "A1",
CellToName = "C1" CellToName = "C1"
}); });
uint rowIndex = 2; uint rowIndex = 2;
foreach (var pc in info.Paymeants) foreach (var pp in info.PaymeantProducts) {
{ InsertCellInWorksheet(new ExcelCellParameters {
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "A", ColumnName = "A",
RowIndex = rowIndex, RowIndex = rowIndex,
Text = pc.OrderID.ToString(), Text = pp.PaymeantID.ToString(),
StyleInfo = ExcelStyleInfoType.Text StyleInfo = ExcelStyleInfoType.Text
}); });
rowIndex++; rowIndex++;
foreach (var (Product, Count) in pp.Products) {
InsertCellInWorksheet(new ExcelCellParameters InsertCellInWorksheet(new ExcelCellParameters {
{
ColumnName = "B", ColumnName = "B",
RowIndex = rowIndex, RowIndex = rowIndex,
Text = pc.PayOption.ToString(), Text = Product,
StyleInfo = ExcelStyleInfoType.Text
});
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "C",
RowIndex = rowIndex,
Text = pc.SumPayment.ToString(),
StyleInfo = ExcelStyleInfoType.TextWithBroder StyleInfo = ExcelStyleInfoType.TextWithBroder
}); });
InsertCellInWorksheet(new ExcelCellParameters {
ColumnName = "C",
RowIndex = rowIndex,
Text = Count.ToString(),
StyleInfo = ExcelStyleInfoType.TextWithBroder
});
rowIndex++; rowIndex++;
} }
InsertCellInWorksheet(new ExcelCellParameters {
ColumnName = "A",
RowIndex = rowIndex,
Text = "Итого",
StyleInfo = ExcelStyleInfoType.Title
});
InsertCellInWorksheet(new ExcelCellParameters {
ColumnName = "C",
RowIndex = rowIndex,
Text = pp.TotalCount.ToString(),
StyleInfo = ExcelStyleInfoType.Title
});
rowIndex++;
}
SaveExcel(info); SaveExcel(info);
} }
/// <summary> // Создание excel-файла
/// Создание excel-файла
/// </summary>
/// <param name="info"></param>
protected abstract void CreateExcel(ExcelInfoClient info); protected abstract void CreateExcel(ExcelInfoClient info);
/// <summary> // Добавляем новую ячейку в лист
/// Добавляем новую ячейку в лист
/// </summary>
/// <param name="cellParameters"></param>
protected abstract void InsertCellInWorksheet(ExcelCellParameters excelParams); protected abstract void InsertCellInWorksheet(ExcelCellParameters excelParams);
/// <summary> // Объединение ячеек
/// Объединение ячеек
/// </summary>
/// <param name="mergeParameters"></param>
protected abstract void MergeCells(ExcelMergeParameters excelParams); protected abstract void MergeCells(ExcelMergeParameters excelParams);
/// <summary> // Сохранение файла
/// Сохранение файла
/// </summary>
/// <param name="info"></param>
protected abstract void SaveExcel(ExcelInfoClient info); protected abstract void SaveExcel(ExcelInfoClient info);
} }
} }

View File

@ -9,9 +9,7 @@ namespace ElectronicsShopBusinessLogic.OfficePackage.HelperEnums
public enum ExcelStyleInfoType public enum ExcelStyleInfoType
{ {
Title, Title,
Text, Text,
TextWithBroder TextWithBroder
} }
} }

View File

@ -5,9 +5,7 @@ namespace ElectronicsShopBusinessLogic.OfficePackage.HelperModels
public class ExcelInfoClient public class ExcelInfoClient
{ {
public string FileName { get; set; } = string.Empty; public string FileName { get; set; } = string.Empty;
public string Title { get; set; } = string.Empty; public string Title { get; set; } = string.Empty;
public List<ReportPaymeantProductsViewModel> PaymeantProducts { get; set; } = new();
public List<PaymeantViewModel> Paymeants { get; set; } = new();
} }
} }

View File

@ -135,11 +135,7 @@ namespace ElectronicsShopBusinessLogic.OfficePackage.Implements
sp.Stylesheet.Append(stylesheetExtensionList); sp.Stylesheet.Append(stylesheetExtensionList);
} }
/// <summary> // Получение номера стиля из типа
/// Получение номера стиля из типа
/// </summary>
/// <param name="styleInfo"></param>
/// <returns></returns>
private static uint GetStyleValue(ExcelStyleInfoType styleInfo) private static uint GetStyleValue(ExcelStyleInfoType styleInfo)
{ {
return styleInfo switch return styleInfo switch

View File

@ -10,8 +10,13 @@ namespace ElectronicsShopContracts.BusinessLogicContracts
{ {
public interface IReportClientLogic public interface IReportClientLogic
{ {
// получение списка товаров с указанием, в какие оплаты товар входит
List<ReportPaymeantProductsViewModel> GetPaymeantProducts(int _clientID);
// получения списка оплат
List<ReportPaymeantsViewModel> GetPaymeants(ReportBindingModel model); List<ReportPaymeantsViewModel> GetPaymeants(ReportBindingModel model);
void SavePaymeantToWordFile(ReportBindingModel model); void SavePaymeantToWordFile(ReportBindingModel model);
void SavePaymeantToExcelFile(ReportBindingModel model);
// Сохранение компонент с указанием отчета в .excel
void SavePaymeantToExcelFile(ReportBindingModel model, int _clientID);
} }
} }

View File

@ -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();
}
}

View File

@ -7,12 +7,12 @@ namespace ElectronicsShopDataBaseImplement
public class Database : DbContext public class Database : DbContext
{ {
//DESKTOP-E2VPEN3 //DESKTOP-E2VPEN3
//DESKTOP-O0N00SH //WIN-4HUIDGH3G02
protected override void OnConfiguring(DbContextOptionsBuilder protected override void OnConfiguring(DbContextOptionsBuilder
optionsBuilder) optionsBuilder)
{ {
if (optionsBuilder.IsConfigured == false) { 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); base.OnConfiguring(optionsBuilder);
} }

View File

@ -59,7 +59,7 @@ namespace ElectronicsShopDataBaseImplement.Implements
{ {
using var context = new Database(); using var context = new Database();
if (model.ID.HasValue && !string.IsNullOrEmpty(model.ProductName)) { if (model.ID.HasValue && string.IsNullOrEmpty(model.ProductName)) {
return context.Products return context.Products
.Include(x => x.CostItem) .Include(x => x.CostItem)
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.ProductName) && x.ProductName == model.ProductName) || .FirstOrDefault(x => (!string.IsNullOrEmpty(model.ProductName) && x.ProductName == model.ProductName) ||

View File

@ -135,8 +135,6 @@ namespace ElectronicsShopRestAPI.Controllers {
} }
} }
[HttpPost] [HttpPost]
public void AddProduct(List<string> jslist) public void AddProduct(List<string> jslist)
{ {

View File

@ -307,5 +307,11 @@ namespace ElectronicsShopUserApp.Controllers {
(DateTime, DateTime, List<PaymeantViewModel>) tuple = (_datefrom, _dateto, reports); (DateTime, DateTime, List<PaymeantViewModel>) tuple = (_datefrom, _dateto, reports);
return View(tuple); return View(tuple);
} }
//todo запрос на создание файла/выгрузку
[HttpPost]
public void CreateExcelReport() {
}
} }
} }

View File

@ -2,7 +2,7 @@
ViewData["Title"] = "AddProduct"; ViewData["Title"] = "AddProduct";
} }
<div class="text-center"> <div class="text-center">
<h2 class="display-4">Создание заказа</h2> <h2 class="display-4">Добавить товар</h2>
</div> </div>
<form method="post"> <form method="post">
<div class="row"> <div class="row">

View File

@ -10,13 +10,17 @@
</div> </div>
<form method="post"> <form method="post">
<div class="row"> <div class="row">
<div class="col-4">Логин:</div> <div class="col-4">Почта:</div>
<div class="col-8"><input type="text" name="login" value="@Model.Email"/></div> <div class="col-8"><input type="text" name="email" value="@Model.Email"/></div>
</div> </div>
<div class="row"> <div class="row">
<div class="col-4">Пароль:</div> <div class="col-4">Пароль:</div>
<div class="col-8"><input type="password" name="password" value="@Model.Password"/></div> <div class="col-8"><input type="password" name="password" value="@Model.Password"/></div>
</div> </div>
<div class="row">
<div class="col-4">ФИО:</div>
<div class="col-8"><input type="text" name="fio" value="@Model.ClientFIO" /></div>
</div>
<div class="row"> <div class="row">
<div class="col-8"></div> <div class="col-8"></div>
<div class="col-4"><input type="submit" value="Сохранить" class="btn btn-primary" /></div> <div class="col-4"><input type="submit" value="Сохранить" class="btn btn-primary" /></div>

View File

@ -23,7 +23,14 @@
<div class="col-sm-auto"> <div class="col-sm-auto">
<input name="DateTo" id="dateto" type="text" value="@Model.Item2.Date.ToString("d")" readonly /> <input name="DateTo" id="dateto" type="text" value="@Model.Item2.Date.ToString("d")" readonly />
</div> </div>
<div class="row">
<div class="col-8">
<a class="btn btn-primary btn-sm" asp-action="CreateWordReport" style="background-color:#335a95;">Создать отчет в .xlsx</a>
<a class="btn btn-primary btn-sm" asp-action="CreateExcelReport" style="background-color:#04713A;">Создать отчет в .docx</a>
<a class="btn btn-primary btn-sm" asp-action="CreatePdfReport" style="background-color:#ad0d09;">Создать отчет в .pdf</a>
</div>
</h1> </h1>
</div> </div>