Солнце уже село, можно я отдохну

This commit is contained in:
Игорь Гордеев 2024-06-01 00:38:15 +04:00
parent 26bc87fda9
commit 85d1dcc8f2
13 changed files with 169 additions and 76 deletions

View File

@ -13,8 +13,8 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic
{
private readonly IPaymeantStorage _paymeantstorage;
private readonly AbstractSaveToExcelClient _saveToExcel;
private readonly AbstractSaveToWordClient _saveToWord;
public ReportClientLogic(AbstractSaveToExcelClient abstractSaveToExcelClient, AbstractSaveToWordClient abstractSaveToWordClient, IPaymeantStorage paymeantStorage) {
_saveToExcel = abstractSaveToExcelClient;
_saveToWord= abstractSaveToWordClient;
@ -28,9 +28,13 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic
{
var record = new ReportPaymeantsViewModel
{
PaymeantName = paymeant.ID.ToString(),
//PaymeantsList=
PaymeantID=paymeant.ID,
ProductID=paymeant.ProductID,
OrderID=paymeant.OrderID,
PayOption=paymeant.PayOption,
SumPayment=paymeant.SumPayment,
};
list.Add(record);
}
return list;
}

View File

@ -0,0 +1,50 @@
using ElectronicsShopBusinessLogic.OfficePackage;
using ElectronicsShopBusinessLogic.OfficePackage.HelperModels;
using ElectronicsShopContracts.BindingModels;
using ElectronicsShopContracts.BusinessLogicContracts;
using ElectronicsShopContracts.StorageContracts;
using ElectronicsShopContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ElectronicsShopBusinessLogic.BusinessLogic
{
public class ReportEmployeeLogic : IReportEmployeeLogic
{
private readonly IProductStorage _productStorage;
private readonly AbstractSaveToWordEmployee _saveToWord;
private readonly AbstractSaveToExcelEmployee _saveToExcel;
public ReportEmployeeLogic(AbstractSaveToExcelEmployee abstractSaveToExcelEmployee, AbstractSaveToWordEmployee abstractSaveToWordEmployee, IProductStorage productStorage) {
_productStorage = productStorage;
_saveToExcel = abstractSaveToExcelEmployee;
_saveToWord = abstractSaveToWordEmployee;
}
public List<ReportProductsViewModel> GetProduct(ReportProductBindingModel model)
{
throw new NotImplementedException();
}
public void SaveProductsToExcelFile(ReportProductBindingModel model)
{
_saveToExcel.CreateReport(new ExcelInfoEmployee
{
FileName = model.FileName,
Title = "Список продуктов",
Products = _productStorage.GetFullList(),
});
}
public void SaveProductsToWordFile(ReportProductBindingModel model)
{
_saveToWord.CreateDoc(new WordInfoEmployee
{
FileName = model.FileName,
Title = "Список продуктов",
ListProduct = _productStorage.GetFullList()
});
}
}
}

View File

@ -31,32 +31,16 @@ namespace ElectronicsShopBusinessLogic.OfficePackage
{
ColumnName = "A",
RowIndex = rowIndex,
Text = pc.PaymeantName.ToString(),
StyleInfo = ExcelStyleInfoType.Text
});
rowIndex++;
foreach (var payment in pc.PaymeantsList)
{
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "B",
RowIndex = rowIndex,
Text = payment.PayOption.ToString(),
Text = pc.PayOption.ToString(),
StyleInfo = ExcelStyleInfoType.Text
});
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "C",
ColumnName = "A",
RowIndex = rowIndex,
Text = payment.SumPayment.ToString(),
StyleInfo = ExcelStyleInfoType.TextWithBroder
});
//Не хорошо, что доступны ID а не название продукта, в идеале пофиксить надо
//Это AbstractSaveToExcelClient
rowIndex++;
}
Text = pc.ProductID.ToString(),
StyleInfo = ExcelStyleInfoType.Text
});//это не правильно но я заебався
rowIndex++;
}

View File

@ -35,31 +35,24 @@ namespace ElectronicsShopBusinessLogic.OfficePackage
StyleInfo = ExcelStyleInfoType.Text
});
rowIndex++;
foreach (var product in pc.Products)
{
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "B",
RowIndex = rowIndex,
Text = product.ProductName.ToString(),
Text = pc.ProductName.ToString(),
StyleInfo = ExcelStyleInfoType.TextWithBroder
});
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "C",
RowIndex = rowIndex,
Text = product.Price.ToString(),
Text = pc.Price.ToString(),
StyleInfo = ExcelStyleInfoType.TextWithBroder
});
rowIndex++;
}
rowIndex++;
}
SaveExcel(info);
}

View File

@ -36,22 +36,26 @@ namespace ElectronicsShopBusinessLogic.OfficePackage
JustificationType = WordJustificationType.Both
}
});
foreach (var pre in product.Products)
{
CreateParagraph(new WordParagraph
{
Texts = new List<(string, WordTextProperties)>
{ (pre.ProductName, new WordTextProperties { Size = "20", Bold=false})},
{ (product.Price.ToString(), new WordTextProperties { Size = "24", Bold=true})},
TextProperties = new WordTextProperties
{
Size = "24",
JustificationType = WordJustificationType.Both
}
});
//Добавить ещё поля кроме названия продукта
//Это AbstractSaveToWordEmployee
CreateParagraph(new WordParagraph
{
Texts = new List<(string, WordTextProperties)>
{ (product.CostItemName, new WordTextProperties { Size = "24", Bold=true})},
TextProperties = new WordTextProperties
{
Size = "24",
JustificationType = WordJustificationType.Both
}
});
}
SaveWord(info);

View File

@ -8,6 +8,6 @@ namespace ElectronicsShopBusinessLogic.OfficePackage.HelperModels
public string Title { get; set; } = string.Empty;
public List<ReportProductsViewModel> Products { get; set; } = new();
public List<ProductViewModel> Products { get; set; } = new();
}
}

View File

@ -9,6 +9,6 @@ namespace ElectronicsShopBusinessLogic.OfficePackage.HelperModels
public string Title { get; set; } = string.Empty;
public List<ReportProductsViewModel> ListProduct { get; set; } = new();
public List<ProductViewModel> ListProduct { get; set; } = new();
}
}

View File

@ -10,8 +10,8 @@ namespace ElectronicsShopContracts.BusinessLogicContracts
{
public interface IReportEmployeeLogic
{
List<ReportProductsViewModel> GetRoute(ReportProductBindingModel model);
void SaveRoutesToWordFile(ReportProductBindingModel model);
void SaveRoutesToExcelFile(ReportProductBindingModel model);
List<ReportProductsViewModel> GetProduct(ReportProductBindingModel model);
void SaveProductsToWordFile(ReportProductBindingModel model);
void SaveProductsToExcelFile(ReportProductBindingModel model);
}
}

View File

@ -1,4 +1,5 @@
using System;
using ElectronicsShopDataModels.Enums;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@ -8,7 +9,12 @@ namespace ElectronicsShopContracts.ViewModels
{
public class ReportPaymeantsViewModel
{
public string PaymeantName { get; set; } = string.Empty;
public List<PaymeantViewModel> PaymeantsList { get; set; } = new();
public int PaymeantID { get; set; }
public int ProductID { get; set; }
public int OrderID { get; set; }
public double SumPayment { get; set; }
public PaymeantOption PayOption { get; set; } = PaymeantOption.Неоплачено;
}
}

View File

@ -57,7 +57,7 @@ namespace ElectronicsShopRestAPI.Controllers {
}
}
[HttpPost]
public void CreateServiceListWordFile(ReportPaymeantBindingModel model)
public void CreateServiceListWordFile(ReportBindingModel model)
{
try
{
@ -69,7 +69,7 @@ namespace ElectronicsShopRestAPI.Controllers {
}
}
[HttpPost]
public void CreateServiceListExcelFile(ReportPaymeantBindingModel model)
public void CreateServiceListExcelFile(ReportBindingModel model)
{
try
{

View File

@ -155,7 +155,7 @@ namespace ElectronicsShopRestAPI.Controllers {
{
try
{
_report.SaveRoutesToWordFile(model);
_report.SaveProductsToWordFile(model);
}
catch (Exception ex)
{
@ -167,7 +167,7 @@ namespace ElectronicsShopRestAPI.Controllers {
{
try
{
_report.SaveRoutesToExcelFile(model);
_report.SaveProductsToExcelFile(model);
}
catch (Exception ex)
{

View File

@ -175,5 +175,53 @@ namespace ElectronicsShopUserApp.Controllers {
//ViewBag.Reports = APIClient.GetRequset<List<ProductViewModel>>($"api/main/getproducts"); Ïèñåì òàê æå ïîêà íåìà
return View();
}
[HttpGet]
public IActionResult GetWordFile()
{
return new PhysicalFileResult("C:\\gg\\wordfile.docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document");
}
public IActionResult GetExcelFile()
{
return new PhysicalFileResult("C:\\gg\\excelfile.xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
}
[HttpPost]
public void ListPreserves(List<int> preserve, string type)
{/*
if (APIEmployee.Employee == null)
{
throw new Exception("Âû êàê ñóäà ïîïàëè? Ñóäà âõîä òîëüêî àâòîðèçîâàííûì");
}
ß Õóé çíàåò êàê îíî ôóðû÷èò, ÁÎÑÑ ß ÓÑÒÀË
if (preserve.Count <= 0)
{
throw new Exception("Êîëè÷åñòâî äîëæíî áûòü áîëüøå 0");
}
if (string.IsNullOrEmpty(type))
{
throw new Exception("Íåâåðíûé òèï îò÷åòà");
}
if (type == "docx")
{
APIEmployee.PostRequest("api/report/createroductlistwordfile", new ReportProductBindingModel
{
Preserve = preserve,
FileName = "C:\\gg\\wordfile.docx"
});
Response.Redirect("GetWordFile");
}
else
{
APIEmployee.PostRequest("api/report/createproductlistexcelfile", new ReportProductBindingModel
{
Preserve = preserve,
FileName = "C:\\gg\\excelfile.xlsx"
});
Response.Redirect("GetExcelFile");
}*/
}
}
}

View File

@ -4,6 +4,10 @@
<div class="text-center">
<h2 class="display-4">Отчёты</h2>
<div class="list-group">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="ListPreserves">Списки оплат word</a>
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="AnimalVisitsAndDrugs">Заповедники и стоимость животных</a>
</div>
</div>
<form method="post">