From 8ed579f6231156ee43f7851e1a674010d531d0c8 Mon Sep 17 00:00:00 2001 From: dasha Date: Wed, 17 May 2023 20:16:45 +0400 Subject: [PATCH] =?UTF-8?q?=D1=87=D0=B5=D1=82=D0=BE=20=D0=B5=D1=81=D1=82?= =?UTF-8?q?=D1=8C=20=D1=87=D0=B5=D1=82=D0=BE=20=D0=BD=D0=B5=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Storekeeper/ReportStorekeeperLogic.cs | 11 +- .../OfficePackage/AbstractSaveToExcel.cs | 34 +---- .../OfficePackage/AbstractSaveToWord.cs | 29 ++-- .../Controllers/StorekeeperController.cs | 45 ++++++- .../Views/Storekeeper/ListBuilds.cshtml | 126 ++++++++++++++++-- .../BindingModels/GoodBindingModel.cs | 9 ++ .../IReportStorekeeperLogic.cs | 4 +- HardwareShop/HardwareShopRestApi/$q.doc | Bin 0 -> 1501 bytes .../Controllers/ReportController.cs | 46 +++++++ HardwareShop/HardwareShopRestApi/Program.cs | 6 + .../Controllers/HomeController.cs | 12 +- 11 files changed, 262 insertions(+), 60 deletions(-) create mode 100644 HardwareShop/HardwareShopRestApi/$q.doc create mode 100644 HardwareShop/HardwareShopRestApi/Controllers/ReportController.cs 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 0000000000000000000000000000000000000000..d0726ba386d07651986c19072deca4cfa36ae15f GIT binary patch literal 1501 zcmWIWW@Zs#VBp|jm^E`_n1%b7{4CVPnDf%h-$)&lec_n%kxjApc zPG{XQ5cw;*uy*mu=AbhbPQo6$HI^<}8hd)vvBe7BZj+ABTyrb$v*=rKmB`i!K6Q@& z7RUWGG`TWUQ^ae*-5*}x6#<^b6sG}9t*)4+MKFgg_4fXDRxyil9 zUNSszRpiX#rveYA_O6mRKSx{1NoV%QIk$9U3s|?VG_x$-U@EzCizoMD$?amdo=$qx z<96QDul3Nv)J2zFJ6u0kq&rz8uIPFea%={pq`Abz3ENmxFEC{VY1GAd$t6cw-JRO% zb-Oil_l?c_PM?coR*daj({aYi;>@?tE48xL-SuHS()w`PY|G=5o$KGPf308lGGCy@ zd;c1HbLkWM6Zfw=|5r6d@6X)*&0lp_?RWZlD&FMeZHEU@v&y!#X-$lMu|oJ~n_kJw z1h?%P4fR@nmAB4vUS$rDycfUuvTOb11v{QdZ2P8j?C(~U`MbVyC~vyS=CNq*<)2kO z0bxu2e0|?ww~l#Y{JI$@{IylX#1!~ht5aR1rb!-g)@9_cyUY5$^vL1LPY>2)&)%s1 zFrawJ)XfDgQEDzd_8oJgzf22%5%D~P^=z8H6(q{eA6@kJtN8i#PpDU%TUC^UZJf%i_$h1&gKbIqCb>eO>0cnc3B%H-9@U>19Y< zFx%{0z{9FzavZ0>sY{Ffz2A6}KLDCu7#L;))64mul{>W<85lsA8<<|=i&Arn_4PpH z``!C(?13ppp)9qiI5R)bR>@G$KuIArFF8LYGcVm%sk9_b*FwqO&L$`|C$R*mqBtY7 zpjZK@C9l|4DWjyMz)D}gI5{IVH?deRzaTXaD3g|7l$%%ru&}6B9FIB?Wyu8+{ZX+o1;OeQBofC}41curM%4qn-2fN`Sd99^{MS zSWqS;K4`&u$PChCh`qWcAbWv9>XMq4SejF!;93E64kSi_Zc$Qzx(^b_i3J5YnaSX& z&@anNL5nwCNch1E6i}!Y6y+zU78e7PL~f2ATqZX$Gfx|AJTSbl*bGWxq*)D3E}*oD zNGWhD^uZwoj0#335eD4lAuv9W07j%Ev}4a62)zctLKZ2rpld`=1PG1I%vh5|fHx}} PND(s-?gY|&tRNl$lW95O literal 0 HcmV?d00001 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 {