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,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<ReportPaymeantsViewModel> GetPaymeants(ReportBindingModel model)
// получение списка оплат за период
public List<ReportPaymeantsViewModel> 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<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
{
//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(),
}) ;
}
}
}
}

View File

@ -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);
}
}
/// <summary>
/// Создание excel-файла
/// </summary>
/// <param name="info"></param>
// Создание excel-файла
protected abstract void CreateExcel(ExcelInfoClient info);
/// <summary>
/// Добавляем новую ячейку в лист
/// </summary>
/// <param name="cellParameters"></param>
// Добавляем новую ячейку в лист
protected abstract void InsertCellInWorksheet(ExcelCellParameters excelParams);
/// <summary>
/// Объединение ячеек
/// </summary>
/// <param name="mergeParameters"></param>
// Объединение ячеек
protected abstract void MergeCells(ExcelMergeParameters excelParams);
/// <summary>
/// Сохранение файла
/// </summary>
/// <param name="info"></param>
// Сохранение файла
protected abstract void SaveExcel(ExcelInfoClient info);
}
}

View File

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

View File

@ -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<PaymeantViewModel> Paymeants { get; set; } = new();
public List<ReportPaymeantProductsViewModel> PaymeantProducts { get; set; } = new();
}
}

View File

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

View File

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

View File

@ -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) ||

View File

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

View File

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

View File

@ -2,13 +2,13 @@
ViewData["Title"] = "AddProduct";
}
<div class="text-center">
<h2 class="display-4">Создание заказа</h2>
<h2 class="display-4">Добавить товар</h2>
</div>
<form method="post">
<div class="row">
<div class="col-4">Продукты:</div>
<div class="col-8">
<select id="product" name="product" class="form-control" asp-items="@(new SelectList(ViewBag.Products, "ID", "ProductName"))"> </select>
<select id="product" name="product" class="form-control" asp-items="@(new SelectList(ViewBag.Products, "ID", "ProductName"))"></select>
</div>
</div>
<div class="row">

View File

@ -10,13 +10,17 @@
</div>
<form method="post">
<div class="row">
<div class="col-4">Логин:</div>
<div class="col-8"><input type="text" name="login" value="@Model.Email"/></div>
<div class="col-4">Почта:</div>
<div class="col-8"><input type="text" name="email" value="@Model.Email"/></div>
</div>
<div class="row">
<div class="col-4">Пароль:</div>
<div class="col-8"><input type="password" name="password" value="@Model.Password"/></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="col-8"></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">
<input name="DateTo" id="dateto" type="text" value="@Model.Item2.Date.ToString("d")" readonly />
</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>
</div>