From 8d3a39c2565d19c13e4362f6ccdb855682ce84f9 Mon Sep 17 00:00:00 2001 From: DavidMakarov Date: Wed, 29 May 2024 14:37:56 +0400 Subject: [PATCH 1/2] implementation of storekeeper many-to-many relation --- .../BusinessLogics/ClientLogic.cs | 5 +- .../Controllers/HomeController.cs | 91 +++++++++++++++++-- Factory/FactoryStorekeeperApp/Program.cs | 2 + .../Views/Home/MachinePlanProductions.cshtml | 38 ++------ 4 files changed, 96 insertions(+), 40 deletions(-) diff --git a/Factory/FactoryBuisinessLogic/BusinessLogics/ClientLogic.cs b/Factory/FactoryBuisinessLogic/BusinessLogics/ClientLogic.cs index 7e4b263..ddc617e 100644 --- a/Factory/FactoryBuisinessLogic/BusinessLogics/ClientLogic.cs +++ b/Factory/FactoryBuisinessLogic/BusinessLogics/ClientLogic.cs @@ -4,6 +4,7 @@ using FactoryContracts.SearchModels; using FactoryContracts.StoragesContracts; using FactoryContracts.ViewModels; using Microsoft.Extensions.Logging; +using System.Text.RegularExpressions; namespace FactoryBusinessLogic.BusinessLogics { @@ -97,9 +98,9 @@ namespace FactoryBusinessLogic.BusinessLogics { throw new ArgumentNullException("Нет логина клиента", nameof(model.Login)); } - if (string.IsNullOrEmpty(model.Email)) + if (string.IsNullOrEmpty(model.Email) || !Regex.IsMatch(model.Email, @"^[a-z0-9._%+-]+\@([a-z0-9-]+\.)+[a-z]{2,4}$")) { - throw new ArgumentNullException("Нет почты клиента", nameof(model.Email)); + throw new ArgumentException("Почта не соответствует требованиям", nameof(model.Email)); } if (string.IsNullOrEmpty(model.Password)) { diff --git a/Factory/FactoryStorekeeperApp/Controllers/HomeController.cs b/Factory/FactoryStorekeeperApp/Controllers/HomeController.cs index d9a40c1..269206e 100644 --- a/Factory/FactoryStorekeeperApp/Controllers/HomeController.cs +++ b/Factory/FactoryStorekeeperApp/Controllers/HomeController.cs @@ -1,9 +1,7 @@ -using DocumentFormat.OpenXml.Office.CustomUI; -using FactoryContracts.BindingModels; +using FactoryContracts.BindingModels; using FactoryContracts.BusinessLogicsContracts; using FactoryContracts.SearchModels; using FactoryContracts.ViewModels; -using FactoryDatabaseImplement.Models; using FactoryDataModels.Enums; using FactoryDataModels.Models; using FactoryStorekepeerApp.Models; @@ -19,16 +17,18 @@ namespace FactoryStorekeeperApp.Controllers private readonly IMachineLogic machineLogic; private readonly IRequirementLogic requirementLogic; private readonly IProductLogic productLogic; + private readonly IPlanProductionLogic planProductionLogic; - private bool IsLoggedIn { get { return Client.client != null; } } + private static bool IsLoggedIn { get { return Client.client != null; } } - public HomeController(ILogger logger, IClientLogic clientLogic, IRequirementLogic requirementLogic, IProductLogic productLogic, IMachineLogic machineLogic) + public HomeController(ILogger logger, IClientLogic clientLogic, IRequirementLogic requirementLogic, IProductLogic productLogic, IMachineLogic machineLogic, IPlanProductionLogic planProductionLogic) { _logger = logger; this.clientLogic = clientLogic; this.requirementLogic = requirementLogic; this.productLogic = productLogic; this.machineLogic = machineLogic; + this.planProductionLogic = planProductionLogic; } public IActionResult Index() @@ -83,7 +83,7 @@ namespace FactoryStorekeeperApp.Controllers { if (!password.Equals(passwordConfirm)) { - return Error(); + throw new ArgumentException("Пароли не совпадают"); } clientLogic.Create(new ClientBindingModel { @@ -160,7 +160,10 @@ namespace FactoryStorekeeperApp.Controllers { return Unauthorized(); } - machineLogic.Delete(new MachineBindingModel { Id = id }); + if (id != 0) + { + machineLogic.Delete(new MachineBindingModel { Id = id }); + } return Redirect("~/Home/Machines"); } [HttpGet] @@ -234,7 +237,8 @@ namespace FactoryStorekeeperApp.Controllers { return Unauthorized(); } - productLogic.Delete(new ProductBindingModel { Id = id }); + if (id != 0) + productLogic.Delete(new ProductBindingModel { Id = id }); return Redirect("~/Home/Products"); } [HttpGet] @@ -306,11 +310,80 @@ namespace FactoryStorekeeperApp.Controllers { return Unauthorized(); } - requirementLogic.Delete(new RequirementBindingModel { Id = id }); + if (id != 0) + requirementLogic.Delete(new RequirementBindingModel { Id = id }); return Redirect("~/Home/Requirements"); } [HttpGet] + public IActionResult MachinePlanProductions() + { + if (!IsLoggedIn) + { + return Redirect("~/Home/Enter"); + } + var planProductions = planProductionLogic.ReadList(new PlanProductionSearchModel + { + ClientId = Client.client.Id, + }); + var machines = machineLogic.ReadList(new MachineSearchModel + { + ClientId = Client.client.Id, + }); + ViewBag.planProductions = planProductions; + ViewBag.machines = machines; + return View(); + } + + [HttpPost] + public IActionResult MachinePlanProductions(int machine, List planproductions, int count) + { + if (!IsLoggedIn) + { + return Unauthorized(); + } + var existMachine = machineLogic.ReadElement(new MachineSearchModel + { + Id = machine, + ClientId = Client.client.Id + }); + var planProductions = planProductionLogic.ReadList(new PlanProductionSearchModel + { + ClientId = Client.client.Id, + }).Where(x => planproductions.Contains(x.Id)) + .ToList(); + if (existMachine != null && planProductions.Count > 0) + { + foreach (var planId in planproductions) + { + var currPlan = planProductions.Where(x => x.Id == planId).FirstOrDefault(); + if (currPlan != null) + { + if (existMachine.MachinePlanProductions.ContainsKey(planId)) + { + var currTuple = existMachine.MachinePlanProductions[planId]; + existMachine.MachinePlanProductions[planId] = (currTuple.Item1, currTuple.Item2 + count); + } + else + { + existMachine.MachinePlanProductions.Add(planId, (currPlan, count)); + } + } + } + machineLogic.Update(new MachineBindingModel + { + Id = existMachine.Id, + MachineName = existMachine.MachineName, + ClientId = Client.client.Id, + ExploitationStartDate = existMachine.ExploitationStartDate, + Lifetime = existMachine.Lifetime, + MachinePlanProductions = existMachine.MachinePlanProductions, + }); + } + return Redirect("~/Home/Index"); + } + + [HttpGet] public IActionResult Reports() { if (!IsLoggedIn) diff --git a/Factory/FactoryStorekeeperApp/Program.cs b/Factory/FactoryStorekeeperApp/Program.cs index db59e66..77539bd 100644 --- a/Factory/FactoryStorekeeperApp/Program.cs +++ b/Factory/FactoryStorekeeperApp/Program.cs @@ -12,12 +12,14 @@ 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.AddTransient(); builder.Services.AddTransient(); +builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); diff --git a/Factory/FactoryStorekeeperApp/Views/Home/MachinePlanProductions.cshtml b/Factory/FactoryStorekeeperApp/Views/Home/MachinePlanProductions.cshtml index 49c6a2e..f88ce67 100644 --- a/Factory/FactoryStorekeeperApp/Views/Home/MachinePlanProductions.cshtml +++ b/Factory/FactoryStorekeeperApp/Views/Home/MachinePlanProductions.cshtml @@ -10,37 +10,17 @@
Станок:
- +
-

Список планов производства

-
-
Заготовки
-
- - - - - - - - - - @foreach (var planProduction in Model) - { - - - - - - } - -
Выбор Название Количество
- - @planProduction.ProductionName - -
-
+
+
Количество:
+ +
+
+
Список планов производств:
+
From 396f923de4748dfecb9103c615e353d554c64a6c Mon Sep 17 00:00:00 2001 From: DavidMakarov Date: Wed, 29 May 2024 15:32:47 +0400 Subject: [PATCH 2/2] MachineByPeriod implementation --- .../Implements/MachineStorage.cs | 5 ++- .../Controllers/HomeController.cs | 44 ++++++++++++------- .../Views/Home/GetByPeriod.cshtml | 24 ++++++++++ .../Views/Home/MachinePeriodReport.cshtml | 6 +-- .../Views/Home/Reports.cshtml | 4 +- 5 files changed, 60 insertions(+), 23 deletions(-) create mode 100644 Factory/FactoryStorekeeperApp/Views/Home/GetByPeriod.cshtml diff --git a/Factory/FactoryDatabaseImplement/Implements/MachineStorage.cs b/Factory/FactoryDatabaseImplement/Implements/MachineStorage.cs index aa573da..06875fd 100644 --- a/Factory/FactoryDatabaseImplement/Implements/MachineStorage.cs +++ b/Factory/FactoryDatabaseImplement/Implements/MachineStorage.cs @@ -129,7 +129,10 @@ namespace FactoryDatabaseImplement.Implements using var context = new FactoryDatabase(); return context.Machines .Include(x => x.Client) - // not sure if its true + .Include(x => x.PlanProductions) + .ThenInclude(x => x.PlanProduction) + .Include(x => x.Products) + .ThenInclude(x => x.Product) .Where(x => x.ClientId == client.Id && x.ExploitationStartDate >= model.DateFrom && x.ExploitationStartDate <= model.DateTo) .Select(x => new MachinePeriodReportViewModel() { diff --git a/Factory/FactoryStorekeeperApp/Controllers/HomeController.cs b/Factory/FactoryStorekeeperApp/Controllers/HomeController.cs index 269206e..04300c5 100644 --- a/Factory/FactoryStorekeeperApp/Controllers/HomeController.cs +++ b/Factory/FactoryStorekeeperApp/Controllers/HomeController.cs @@ -18,10 +18,14 @@ namespace FactoryStorekeeperApp.Controllers private readonly IRequirementLogic requirementLogic; private readonly IProductLogic productLogic; private readonly IPlanProductionLogic planProductionLogic; + private readonly IStorekeeperReportLogic storekeeperReportLogic; private static bool IsLoggedIn { get { return Client.client != null; } } - public HomeController(ILogger logger, IClientLogic clientLogic, IRequirementLogic requirementLogic, IProductLogic productLogic, IMachineLogic machineLogic, IPlanProductionLogic planProductionLogic) + public HomeController(ILogger logger, IClientLogic clientLogic, + IRequirementLogic requirementLogic, IProductLogic productLogic, + IMachineLogic machineLogic, IPlanProductionLogic planProductionLogic, + IStorekeeperReportLogic storekeeperReportLogic) { _logger = logger; this.clientLogic = clientLogic; @@ -29,6 +33,7 @@ namespace FactoryStorekeeperApp.Controllers this.productLogic = productLogic; this.machineLogic = machineLogic; this.planProductionLogic = planProductionLogic; + this.storekeeperReportLogic = storekeeperReportLogic; } public IActionResult Index() @@ -393,28 +398,33 @@ namespace FactoryStorekeeperApp.Controllers return View(); } + [HttpGet] + public IActionResult GetByPeriod() + { + if (!IsLoggedIn) + { + return Redirect("~/Home/Enter"); + } + return View(); + } + [HttpGet] - public IActionResult MachinePeriodReport() + public IActionResult MachinePeriodReport(DateTime datefrom, DateTime dateto) { if (!IsLoggedIn) { return Redirect("~/Home/Enter"); } - List reports = new List - { - new MachinePeriodReportViewModel - { - MachineName = "Станок А", - PlanProductions = new(), - Products = new() - }, - new MachinePeriodReportViewModel - { - MachineName = "Станок B", - PlanProductions = new(), - Products = new() - } - }; + var reports = storekeeperReportLogic.GetMachines( + new ClientSearchModel + { + Id = Client.client.Id + }, + new ReportBindingModel + { + DateFrom = datefrom, + DateTo = dateto, + }); return View(reports); } diff --git a/Factory/FactoryStorekeeperApp/Views/Home/GetByPeriod.cshtml b/Factory/FactoryStorekeeperApp/Views/Home/GetByPeriod.cshtml new file mode 100644 index 0000000..2e6bfb1 --- /dev/null +++ b/Factory/FactoryStorekeeperApp/Views/Home/GetByPeriod.cshtml @@ -0,0 +1,24 @@ +@using FactoryContracts.ViewModels + +@model List + +@{ + ViewData["Title"] = "Подготовка к созданию отчета за период"; +} + +
+

Список станков за период

+
+ +
+
Выберите период
+
+
Дата начала:
+
+
+
+
Дата конца:
+
+
+ +
diff --git a/Factory/FactoryStorekeeperApp/Views/Home/MachinePeriodReport.cshtml b/Factory/FactoryStorekeeperApp/Views/Home/MachinePeriodReport.cshtml index 96273e2..53bf257 100644 --- a/Factory/FactoryStorekeeperApp/Views/Home/MachinePeriodReport.cshtml +++ b/Factory/FactoryStorekeeperApp/Views/Home/MachinePeriodReport.cshtml @@ -3,7 +3,7 @@ @model List @{ - ViewData["Title"] = "Очет станков за период"; + ViewData["Title"] = "Отчет станков за период"; }
@@ -32,7 +32,7 @@
    @foreach (var product in machine.Products) { -
  • @product
  • +
  • @product.ProductName
  • }
@@ -40,7 +40,7 @@
    @foreach (var planProduction in machine.PlanProductions) { -
  • @planProduction
  • +
  • @planProduction.ProductionName
  • }
diff --git a/Factory/FactoryStorekeeperApp/Views/Home/Reports.cshtml b/Factory/FactoryStorekeeperApp/Views/Home/Reports.cshtml index 4732ef0..57a6bea 100644 --- a/Factory/FactoryStorekeeperApp/Views/Home/Reports.cshtml +++ b/Factory/FactoryStorekeeperApp/Views/Home/Reports.cshtml @@ -5,7 +5,7 @@ \ No newline at end of file