diff --git a/HardwareShop/HardwareShopBusinessLogic/BusinessLogics/Storekeeper/ReportStorekeeperLogic.cs b/HardwareShop/HardwareShopBusinessLogic/BusinessLogics/Storekeeper/ReportStorekeeperLogic.cs index a59018c..3d95e07 100644 --- a/HardwareShop/HardwareShopBusinessLogic/BusinessLogics/Storekeeper/ReportStorekeeperLogic.cs +++ b/HardwareShop/HardwareShopBusinessLogic/BusinessLogics/Storekeeper/ReportStorekeeperLogic.cs @@ -88,7 +88,7 @@ namespace HardwareShopBusinessLogic.BusinessLogics.Storekeeper }); } - public void SaveBuildGoodToWordFile(ReportBindingModel model, List goods) + public byte[] SaveBuildGoodToWordFile(ReportBindingModel model, List goods) { _saveToWord.CreateBuildGoodReport(new WordInfo { @@ -96,6 +96,15 @@ namespace HardwareShopBusinessLogic.BusinessLogics.Storekeeper Title = "Cписок сборок по выбранным товарам", BuildGood = GetBuildGood(goods) }); + + byte[] file = File.ReadAllBytes(model.FileName); + File.Delete(model.FileName); + return file; + } + + byte[] IReportStorekeeperLogic.SaveBuildGoodToExcelFile(ReportBindingModel model, List goods) + { + throw new NotImplementedException(); } } } diff --git a/HardwareShop/HardwareShopBusinessLogic/OfficePackage/AbstractSaveToExcel.cs b/HardwareShop/HardwareShopBusinessLogic/OfficePackage/AbstractSaveToExcel.cs index 2b8ff15..038a23d 100644 --- a/HardwareShop/HardwareShopBusinessLogic/OfficePackage/AbstractSaveToExcel.cs +++ b/HardwareShop/HardwareShopBusinessLogic/OfficePackage/AbstractSaveToExcel.cs @@ -27,55 +27,33 @@ namespace HardwareShopBusinessLogic.OfficePackage CellToName = "C1" }); - /*uint rowIndex = 2; - foreach (var ss in info.BuildGood) + uint rowIndex = 2; + foreach (var bg in info.BuildGood) { InsertCellInWorksheet(new ExcelCellParameters { ColumnName = "A", RowIndex = rowIndex, - Text = ss.ShopName, + Text = bg.GoodName, StyleInfo = ExcelStyleInfoType.Text }); rowIndex++; - foreach (var (Sushi, Count) in ss.ListSushi) + foreach (var build in bg.Builds) { InsertCellInWorksheet(new ExcelCellParameters { ColumnName = "B", RowIndex = rowIndex, - Text = Sushi, - StyleInfo = ExcelStyleInfoType.TextWithBroder - }); - - InsertCellInWorksheet(new ExcelCellParameters - { - ColumnName = "C", - RowIndex = rowIndex, - Text = Count.ToString(), + Text = build, StyleInfo = ExcelStyleInfoType.TextWithBroder }); rowIndex++; } - InsertCellInWorksheet(new ExcelCellParameters - { - ColumnName = "A", - RowIndex = rowIndex, - Text = "Итого", - StyleInfo = ExcelStyleInfoType.Text - }); - InsertCellInWorksheet(new ExcelCellParameters - { - ColumnName = "C", - RowIndex = rowIndex, - Text = ss.TotalCount.ToString(), - StyleInfo = ExcelStyleInfoType.Text - }); rowIndex++; - }*/ + } SaveExcel(info); } diff --git a/HardwareShop/HardwareShopBusinessLogic/OfficePackage/AbstractSaveToWord.cs b/HardwareShop/HardwareShopBusinessLogic/OfficePackage/AbstractSaveToWord.cs index 054d527..b7b704a 100644 --- a/HardwareShop/HardwareShopBusinessLogic/OfficePackage/AbstractSaveToWord.cs +++ b/HardwareShop/HardwareShopBusinessLogic/OfficePackage/AbstractSaveToWord.cs @@ -23,23 +23,34 @@ namespace HardwareShopBusinessLogic.OfficePackage rows.Add(new WordRow { Rows = new List<(string, WordTextProperties)> { - ("Название", new WordTextProperties { Size = "24", Bold = true }), - ("Адрес", new WordTextProperties { Size = "24", Bold = true }), - ("Дата открытия", new WordTextProperties { Size = "24", Bold = true }) + ("Товары", new WordTextProperties { Size = "24", Bold = true }), + ("Сборки", new WordTextProperties { Size = "24", Bold = true }) } }); - /*foreach (var shop in info.BuildGood) + var reportRecords = info.BuildGood; + foreach (var reportRecord in reportRecords) { rows.Add(new WordRow { - Rows = new List<(string, WordTextProperties)> { - (shop.ShopName, new WordTextProperties { Size = "24" }), - (shop.Address, new WordTextProperties { Size = "24" }), - (shop.DateOpening.ToShortDateString(), new WordTextProperties { Size = "24" }) + Rows = new List<(string, WordTextProperties)> + { + (reportRecord.GoodName, new WordTextProperties { Size = "24" }), + ("", new WordTextProperties { }) } }); - }*/ + for (int i = 0; i < reportRecord.Builds.Count; i++) + { + rows.Add(new WordRow + { + Rows = new List<(string, WordTextProperties)> + { + ("", new WordTextProperties { }), + (reportRecord.Builds[i], new WordTextProperties { Size = "24" }) + } + }); + } + } CreateTable(rows); diff --git a/HardwareShop/HardwareShopClientApp/Controllers/StorekeeperController.cs b/HardwareShop/HardwareShopClientApp/Controllers/StorekeeperController.cs index dbc2a6f..39ef02f 100644 --- a/HardwareShop/HardwareShopClientApp/Controllers/StorekeeperController.cs +++ b/HardwareShop/HardwareShopClientApp/Controllers/StorekeeperController.cs @@ -4,6 +4,7 @@ using HardwareShopDatabaseImplement.Models; using HardwareShopDatabaseImplement.Models.Storekeeper; using HardwareShopDataModels.Enums; using Microsoft.AspNetCore.Mvc; +using System.ComponentModel; namespace HardwareShopStorekeeperApp.Controllers { @@ -115,7 +116,7 @@ namespace HardwareShopStorekeeperApp.Controllers } [HttpPost] - public void CreateGood([FromBody]GoodBindingModel goodModel) + public void CreateGood([FromBody] GoodBindingModel goodModel) { if (APIClient.User == null) { @@ -162,6 +163,21 @@ namespace HardwareShopStorekeeperApp.Controllers APIClient.PostRequest("api/good/updatedata", goodModel); } + [HttpGet] + public GoodViewModel? GetGood(int Id) + { + if (APIClient.User == null) + { + throw new Exception("Вы как сюда попали? Сюда вход только авторизованным"); + } + if (Id <= 0) + { + throw new Exception($"Идентификатор товара не может быть меньше или равен 0"); + } + var result = APIClient.GetRequest($"api/good/getgood?id={Id}"); + return result; + } + [HttpGet] public Tuple>>? GetGoodUpdate(int goodid) { @@ -183,7 +199,7 @@ namespace HardwareShopStorekeeperApp.Controllers } if (good <= 0) { - throw new Exception($"Идентификтаор товара не может быть меньше или равен 0"); + throw new Exception($"Идентификатор товара не может быть меньше или равен 0"); } APIClient.PostRequest("api/good/deletegood", new GoodBindingModel { @@ -221,7 +237,7 @@ namespace HardwareShopStorekeeperApp.Controllers } if (buildId <= 0) { - throw new Exception($"Идентификтаор сборки не может быть меньше или равен 0"); + throw new Exception($"Идентификатор сборки не может быть меньше или равен 0"); } var result = APIClient.GetRequest($"api/build/getbuild?buildId={buildId}"); return result; @@ -296,7 +312,7 @@ namespace HardwareShopStorekeeperApp.Controllers } if (component <= 0) { - throw new Exception($"Идентификтаор комплектующего не может быть меньше или равен 0"); + throw new Exception($"Идентификатор комплектующего не может быть меньше или равен 0"); } if (string.IsNullOrEmpty(name)) { @@ -325,7 +341,7 @@ namespace HardwareShopStorekeeperApp.Controllers } if (component <= 0) { - throw new Exception($"Идентификтаор комплектующего не может быть меньше или равен 0"); + throw new Exception($"Идентификатор комплектующего не может быть меньше или равен 0"); } APIClient.PostRequest("api/component/deletecomponent", new ComponentBindingModel { @@ -375,9 +391,28 @@ namespace HardwareShopStorekeeperApp.Controllers { return Redirect("~/Home/Enter"); } + ViewBag.Goods = APIClient.GetRequest>($"api/good/getgoods?userId={APIClient.User.Id}"); return View(); } + [HttpPost] + public void ListBuilds([FromBody] GoodBindingModel goodModel, [FromQuery] string format, [FromQuery] string filename) + { + if (APIClient.User == null) + { + throw new Exception("Вы как сюда попали? Сюда вход только авторизованным"); + } + if (string.IsNullOrEmpty(format)) + { + throw new FormatException($"Неправильный формат файла: {format}"); + } + if (string.IsNullOrEmpty(filename)) + { + throw new FormatException($"Неправильное название файла: {filename}"); + } + APIClient.PostRequest($"api/report/buildgoodreport?format={format}&filename=${filename}", goodModel); + } + public IActionResult Report() { if (APIClient.User == null) diff --git a/HardwareShop/HardwareShopClientApp/Views/Storekeeper/ListBuilds.cshtml b/HardwareShop/HardwareShopClientApp/Views/Storekeeper/ListBuilds.cshtml index 9b0e452..c9fac2e 100644 --- a/HardwareShop/HardwareShopClientApp/Views/Storekeeper/ListBuilds.cshtml +++ b/HardwareShop/HardwareShopClientApp/Views/Storekeeper/ListBuilds.cshtml @@ -8,21 +8,129 @@

Получение списка сборок

-
+

Выбранные товары

+
+ +
- + + - +
- Товар - ТоварДействия
-
- - +
+ +
- \ No newline at end of file +
+ + +
+
+ + +@section Scripts +{ + +} \ No newline at end of file diff --git a/HardwareShop/HardwareShopContracts/BindingModels/GoodBindingModel.cs b/HardwareShop/HardwareShopContracts/BindingModels/GoodBindingModel.cs index a80ef36..a8c3fd0 100644 --- a/HardwareShop/HardwareShopContracts/BindingModels/GoodBindingModel.cs +++ b/HardwareShop/HardwareShopContracts/BindingModels/GoodBindingModel.cs @@ -19,16 +19,25 @@ namespace HardwareShopContracts.BindingModels set; } = new(); + // for dictionary item1 public List GoodComponentsComponents { get; set; } = new(); + // for dictionary item2 public List GoodComponentsCounts { get; set; } = new(); + + // for report list + public List Goods + { + get; + set; + } = new(); } } diff --git a/HardwareShop/HardwareShopContracts/BusinessLogicsContracts/IReportStorekeeperLogic.cs b/HardwareShop/HardwareShopContracts/BusinessLogicsContracts/IReportStorekeeperLogic.cs index 148398b..7a35f24 100644 --- a/HardwareShop/HardwareShopContracts/BusinessLogicsContracts/IReportStorekeeperLogic.cs +++ b/HardwareShop/HardwareShopContracts/BusinessLogicsContracts/IReportStorekeeperLogic.cs @@ -24,12 +24,12 @@ namespace HardwareShopContracts.BusinessLogicsContracts /// Сохранение списка сборок по выбранным товарам в файл-Word /// /// - void SaveBuildGoodToWordFile(ReportBindingModel model, List goods); + byte[] SaveBuildGoodToWordFile(ReportBindingModel model, List goods); /// /// Сохранение списка сборок по выбранным товарам в файл-Excel /// /// - void SaveBuildGoodToExcelFile(ReportBindingModel model, List goods); + byte[] SaveBuildGoodToExcelFile(ReportBindingModel model, List goods); } } diff --git a/HardwareShop/HardwareShopRestApi/$q.doc b/HardwareShop/HardwareShopRestApi/$q.doc new file mode 100644 index 0000000..d0726ba Binary files /dev/null and b/HardwareShop/HardwareShopRestApi/$q.doc differ diff --git a/HardwareShop/HardwareShopRestApi/Controllers/ReportController.cs b/HardwareShop/HardwareShopRestApi/Controllers/ReportController.cs new file mode 100644 index 0000000..d00a628 --- /dev/null +++ b/HardwareShop/HardwareShopRestApi/Controllers/ReportController.cs @@ -0,0 +1,46 @@ +using HardwareShopContracts.BindingModels; +using HardwareShopContracts.BusinessLogicsContracts; +using Microsoft.AspNetCore.Mvc; + +namespace HardwareShopRestApi.Controllers +{ + [Route("api/[controller]/[action]")] + [ApiController] + public class ReportController : Controller + { + private readonly ILogger _logger; + private readonly IReportStorekeeperLogic _reportStorekeeperLogic; + private readonly IWorkerReportLogic _reportWorkerLogic; + + public ReportController(ILogger logger, IReportStorekeeperLogic reportStorekeeperLogic, IWorkerReportLogic workerReportLogic) + { + _logger = logger; + _reportStorekeeperLogic = reportStorekeeperLogic; + _reportWorkerLogic = workerReportLogic; + } + + [HttpPost] + public void BuildGoodReport(GoodBindingModel model, string format, string filename) + { + try + { + switch (format) + { + case "doc": + _reportStorekeeperLogic.SaveBuildGoodToWordFile(new ReportBindingModel { FileName = filename }, model.Goods); + break; + case "excel": + _reportStorekeeperLogic.SaveBuildGoodToExcelFile(new ReportBindingModel { FileName = filename }, model.Goods); + break; + default: + throw new FormatException("Неправильный формат файла"); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения списка сборок по выбранным товарам"); + throw; + } + } + } +} diff --git a/HardwareShop/HardwareShopRestApi/Program.cs b/HardwareShop/HardwareShopRestApi/Program.cs index 6053db8..1d68e4b 100644 --- a/HardwareShop/HardwareShopRestApi/Program.cs +++ b/HardwareShop/HardwareShopRestApi/Program.cs @@ -1,5 +1,7 @@ using HardwareShopBusinessLogic.BusinessLogics; using HardwareShopBusinessLogic.BusinessLogics.Storekeeper; +using HardwareShopBusinessLogic.OfficePackage; +using HardwareShopBusinessLogic.OfficePackage.Implements; using HardwareShopContracts.BuisnessLogicsContracts; using HardwareShopContracts.BusinessLogicsContracts; using HardwareShopContracts.StoragesContracts; @@ -29,6 +31,10 @@ builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); builder.Services.AddControllers(); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle diff --git a/HardwareShop/HardwareShopWorkerApp/Controllers/HomeController.cs b/HardwareShop/HardwareShopWorkerApp/Controllers/HomeController.cs index 343bd27..205dda3 100644 --- a/HardwareShop/HardwareShopWorkerApp/Controllers/HomeController.cs +++ b/HardwareShop/HardwareShopWorkerApp/Controllers/HomeController.cs @@ -110,7 +110,7 @@ namespace HardwareShopWorkerApp.Controllers } if (buildId <= 0) { - throw new Exception($"Идентификтаор сборки не может быть ниже или равен 0"); + throw new Exception($"Идентификатор сборки не может быть ниже или равен 0"); } var result = APIClient.GetRequest($"api/build/getBuild?buildId={buildId}"); if (result == null) @@ -133,7 +133,7 @@ namespace HardwareShopWorkerApp.Controllers } if (buildId <= 0) { - throw new Exception($"Идентификтаор сборки не может быть ниже или равен 0"); + throw new Exception($"Идентификатор сборки не может быть ниже или равен 0"); } APIClient.PostRequest("api/build/update", new BuildBindingModel { @@ -153,7 +153,7 @@ namespace HardwareShopWorkerApp.Controllers } if (deleteBuildId <= 0) { - throw new Exception($"Идентификтаор сборки не может быть ниже или равен 0"); + throw new Exception($"Идентификатор сборки не может быть ниже или равен 0"); } APIClient.PostRequest("api/build/DeleteBuild", new BuildBindingModel { @@ -210,7 +210,7 @@ namespace HardwareShopWorkerApp.Controllers } if (commentId <= 0) { - throw new Exception($"Идентификтаор комментария не может быть ниже или равен 0"); + throw new Exception($"Идентификатор комментария не может быть ниже или равен 0"); } var result = APIClient.GetRequest($"api/comment/getcomment?commentId={commentId}"); if (result == null) @@ -233,7 +233,7 @@ namespace HardwareShopWorkerApp.Controllers } if (commentId <= 0) { - throw new Exception($"Идентификтаор комментария не может быть ниже или равен 0"); + throw new Exception($"Идентификатор комментария не может быть ниже или равен 0"); } APIClient.PostRequest("api/comment/update", new CommentBindingModel { @@ -253,7 +253,7 @@ namespace HardwareShopWorkerApp.Controllers } if (deleteCommentId <= 0) { - throw new Exception($"Идентификтаор комментария не может быть ниже или равен 0"); + throw new Exception($"Идентификатор комментария не может быть ниже или равен 0"); } APIClient.PostRequest("api/comment/delete", new CommentBindingModel {