diff --git a/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/ReportClientLogic.cs b/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/ReportClientLogic.cs index 29b2582..e6bb4c3 100644 --- a/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/ReportClientLogic.cs +++ b/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/ReportClientLogic.cs @@ -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; } diff --git a/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/ReportEmployeeLogic.cs b/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/ReportEmployeeLogic.cs new file mode 100644 index 0000000..e07b8bd --- /dev/null +++ b/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/ReportEmployeeLogic.cs @@ -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 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() + }); + } + } +} diff --git a/ElectronicsShop/ElectronicsShopBusinessLogic/OfficePackage/AbstractSaveToExcelClient.cs b/ElectronicsShop/ElectronicsShopBusinessLogic/OfficePackage/AbstractSaveToExcelClient.cs index 9ffdf9d..32c66e8 100644 --- a/ElectronicsShop/ElectronicsShopBusinessLogic/OfficePackage/AbstractSaveToExcelClient.cs +++ b/ElectronicsShop/ElectronicsShopBusinessLogic/OfficePackage/AbstractSaveToExcelClient.cs @@ -31,32 +31,16 @@ namespace ElectronicsShopBusinessLogic.OfficePackage { ColumnName = "A", RowIndex = rowIndex, - Text = pc.PaymeantName.ToString(), + Text = pc.PayOption.ToString(), StyleInfo = ExcelStyleInfoType.Text }); - rowIndex++; - - foreach (var payment in pc.PaymeantsList) + InsertCellInWorksheet(new ExcelCellParameters { - InsertCellInWorksheet(new ExcelCellParameters - { - ColumnName = "B", - RowIndex = rowIndex, - Text = payment.PayOption.ToString(), - StyleInfo = ExcelStyleInfoType.Text - }); - InsertCellInWorksheet(new ExcelCellParameters - { - ColumnName = "C", - RowIndex = rowIndex, - Text = payment.SumPayment.ToString(), - StyleInfo = ExcelStyleInfoType.TextWithBroder - }); - //Не хорошо, что доступны ID а не название продукта, в идеале пофиксить надо - //Это AbstractSaveToExcelClient - rowIndex++; - } - + ColumnName = "A", + RowIndex = rowIndex, + Text = pc.ProductID.ToString(), + StyleInfo = ExcelStyleInfoType.Text + });//это не правильно но я заебався rowIndex++; } diff --git a/ElectronicsShop/ElectronicsShopBusinessLogic/OfficePackage/AbstractSaveToExcelEmployee.cs b/ElectronicsShop/ElectronicsShopBusinessLogic/OfficePackage/AbstractSaveToExcelEmployee.cs index b0c3432..07c8f66 100644 --- a/ElectronicsShop/ElectronicsShopBusinessLogic/OfficePackage/AbstractSaveToExcelEmployee.cs +++ b/ElectronicsShop/ElectronicsShopBusinessLogic/OfficePackage/AbstractSaveToExcelEmployee.cs @@ -35,27 +35,20 @@ namespace ElectronicsShopBusinessLogic.OfficePackage StyleInfo = ExcelStyleInfoType.Text }); rowIndex++; - - foreach (var product in pc.Products) + InsertCellInWorksheet(new ExcelCellParameters { - InsertCellInWorksheet(new ExcelCellParameters - { - ColumnName = "B", - RowIndex = rowIndex, - Text = product.ProductName.ToString(), - StyleInfo = ExcelStyleInfoType.TextWithBroder - }); - - InsertCellInWorksheet(new ExcelCellParameters - { - ColumnName = "C", - RowIndex = rowIndex, - Text = product.Price.ToString(), - StyleInfo = ExcelStyleInfoType.TextWithBroder - }); - - rowIndex++; - } + ColumnName = "B", + RowIndex = rowIndex, + Text = pc.ProductName.ToString(), + StyleInfo = ExcelStyleInfoType.TextWithBroder + }); + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "C", + RowIndex = rowIndex, + Text = pc.Price.ToString(), + StyleInfo = ExcelStyleInfoType.TextWithBroder + }); rowIndex++; } diff --git a/ElectronicsShop/ElectronicsShopBusinessLogic/OfficePackage/AbstractSaveToWordEmployee.cs b/ElectronicsShop/ElectronicsShopBusinessLogic/OfficePackage/AbstractSaveToWordEmployee.cs index 93914e1..a313b07 100644 --- a/ElectronicsShop/ElectronicsShopBusinessLogic/OfficePackage/AbstractSaveToWordEmployee.cs +++ b/ElectronicsShop/ElectronicsShopBusinessLogic/OfficePackage/AbstractSaveToWordEmployee.cs @@ -36,23 +36,27 @@ 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})}, - TextProperties = new WordTextProperties - { - Size = "24", - JustificationType = WordJustificationType.Both - } - }); - //Добавить ещё поля кроме названия продукта - //Это AbstractSaveToWordEmployee - } - } + CreateParagraph(new WordParagraph + { + Texts = new List<(string, WordTextProperties)> + { (product.Price.ToString(), new WordTextProperties { Size = "24", Bold=true})}, + TextProperties = new WordTextProperties + { + Size = "24", + JustificationType = WordJustificationType.Both + } + }); + 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); } diff --git a/ElectronicsShop/ElectronicsShopBusinessLogic/OfficePackage/HelperModels/ExcelInfoEmployee.cs b/ElectronicsShop/ElectronicsShopBusinessLogic/OfficePackage/HelperModels/ExcelInfoEmployee.cs index 9e5b755..8cca808 100644 --- a/ElectronicsShop/ElectronicsShopBusinessLogic/OfficePackage/HelperModels/ExcelInfoEmployee.cs +++ b/ElectronicsShop/ElectronicsShopBusinessLogic/OfficePackage/HelperModels/ExcelInfoEmployee.cs @@ -8,6 +8,6 @@ namespace ElectronicsShopBusinessLogic.OfficePackage.HelperModels public string Title { get; set; } = string.Empty; - public List Products { get; set; } = new(); + public List Products { get; set; } = new(); } } diff --git a/ElectronicsShop/ElectronicsShopBusinessLogic/OfficePackage/HelperModels/WordInfoEmployee.cs b/ElectronicsShop/ElectronicsShopBusinessLogic/OfficePackage/HelperModels/WordInfoEmployee.cs index ff98c64..5956264 100644 --- a/ElectronicsShop/ElectronicsShopBusinessLogic/OfficePackage/HelperModels/WordInfoEmployee.cs +++ b/ElectronicsShop/ElectronicsShopBusinessLogic/OfficePackage/HelperModels/WordInfoEmployee.cs @@ -9,6 +9,6 @@ namespace ElectronicsShopBusinessLogic.OfficePackage.HelperModels public string Title { get; set; } = string.Empty; - public List ListProduct { get; set; } = new(); + public List ListProduct { get; set; } = new(); } } diff --git a/ElectronicsShop/ElectronicsShopContracts/BusinessLogicContracts/IReportEmployeeLogic.cs b/ElectronicsShop/ElectronicsShopContracts/BusinessLogicContracts/IReportEmployeeLogic.cs index 4f58760..c584ce6 100644 --- a/ElectronicsShop/ElectronicsShopContracts/BusinessLogicContracts/IReportEmployeeLogic.cs +++ b/ElectronicsShop/ElectronicsShopContracts/BusinessLogicContracts/IReportEmployeeLogic.cs @@ -10,8 +10,8 @@ namespace ElectronicsShopContracts.BusinessLogicContracts { public interface IReportEmployeeLogic { - List GetRoute(ReportProductBindingModel model); - void SaveRoutesToWordFile(ReportProductBindingModel model); - void SaveRoutesToExcelFile(ReportProductBindingModel model); + List GetProduct(ReportProductBindingModel model); + void SaveProductsToWordFile(ReportProductBindingModel model); + void SaveProductsToExcelFile(ReportProductBindingModel model); } } diff --git a/ElectronicsShop/ElectronicsShopContracts/ViewModels/ReportPaymeantsViewModel.cs b/ElectronicsShop/ElectronicsShopContracts/ViewModels/ReportPaymeantsViewModel.cs index dca6f74..3f579bc 100644 --- a/ElectronicsShop/ElectronicsShopContracts/ViewModels/ReportPaymeantsViewModel.cs +++ b/ElectronicsShop/ElectronicsShopContracts/ViewModels/ReportPaymeantsViewModel.cs @@ -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 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.Неоплачено; + } } diff --git a/ElectronicsShop/ElectronicsShopRestAPI/Controllers/ClientController.cs b/ElectronicsShop/ElectronicsShopRestAPI/Controllers/ClientController.cs index 10cf5b4..a092aa6 100644 --- a/ElectronicsShop/ElectronicsShopRestAPI/Controllers/ClientController.cs +++ b/ElectronicsShop/ElectronicsShopRestAPI/Controllers/ClientController.cs @@ -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 { diff --git a/ElectronicsShop/ElectronicsShopRestAPI/Controllers/EmployeeController.cs b/ElectronicsShop/ElectronicsShopRestAPI/Controllers/EmployeeController.cs index 5098225..96785ac 100644 --- a/ElectronicsShop/ElectronicsShopRestAPI/Controllers/EmployeeController.cs +++ b/ElectronicsShop/ElectronicsShopRestAPI/Controllers/EmployeeController.cs @@ -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) { diff --git a/ElectronicsShop/ElectronicsShopShopClientApp/Controllers/HomeController.cs b/ElectronicsShop/ElectronicsShopShopClientApp/Controllers/HomeController.cs index 51077df..c7d4d88 100644 --- a/ElectronicsShop/ElectronicsShopShopClientApp/Controllers/HomeController.cs +++ b/ElectronicsShop/ElectronicsShopShopClientApp/Controllers/HomeController.cs @@ -175,5 +175,53 @@ namespace ElectronicsShopUserApp.Controllers { //ViewBag.Reports = APIClient.GetRequset>($"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 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"); + }*/ + } + } } diff --git a/ElectronicsShop/ElectronicsShopShopClientApp/Views/Home/Report.cshtml b/ElectronicsShop/ElectronicsShopShopClientApp/Views/Home/Report.cshtml index f3248f5..596e149 100644 --- a/ElectronicsShop/ElectronicsShopShopClientApp/Views/Home/Report.cshtml +++ b/ElectronicsShop/ElectronicsShopShopClientApp/Views/Home/Report.cshtml @@ -4,6 +4,10 @@