sardq 2024-05-29 16:14:03 +04:00
commit ba680292ef
8 changed files with 155 additions and 62 deletions

View File

@ -4,6 +4,7 @@ using FactoryContracts.SearchModels;
using FactoryContracts.StoragesContracts; using FactoryContracts.StoragesContracts;
using FactoryContracts.ViewModels; using FactoryContracts.ViewModels;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using System.Text.RegularExpressions;
namespace FactoryBusinessLogic.BusinessLogics namespace FactoryBusinessLogic.BusinessLogics
{ {
@ -97,9 +98,9 @@ namespace FactoryBusinessLogic.BusinessLogics
{ {
throw new ArgumentNullException("Нет логина клиента", nameof(model.Login)); 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)) if (string.IsNullOrEmpty(model.Password))
{ {

View File

@ -129,7 +129,10 @@ namespace FactoryDatabaseImplement.Implements
using var context = new FactoryDatabase(); using var context = new FactoryDatabase();
return context.Machines return context.Machines
.Include(x => x.Client) .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) .Where(x => x.ClientId == client.Id && x.ExploitationStartDate >= model.DateFrom && x.ExploitationStartDate <= model.DateTo)
.Select(x => new MachinePeriodReportViewModel() .Select(x => new MachinePeriodReportViewModel()
{ {

View File

@ -1,9 +1,7 @@
using DocumentFormat.OpenXml.Office.CustomUI; using FactoryContracts.BindingModels;
using FactoryContracts.BindingModels;
using FactoryContracts.BusinessLogicsContracts; using FactoryContracts.BusinessLogicsContracts;
using FactoryContracts.SearchModels; using FactoryContracts.SearchModels;
using FactoryContracts.ViewModels; using FactoryContracts.ViewModels;
using FactoryDatabaseImplement.Models;
using FactoryDataModels.Enums; using FactoryDataModels.Enums;
using FactoryDataModels.Models; using FactoryDataModels.Models;
using FactoryStorekepeerApp.Models; using FactoryStorekepeerApp.Models;
@ -19,16 +17,23 @@ namespace FactoryStorekeeperApp.Controllers
private readonly IMachineLogic machineLogic; private readonly IMachineLogic machineLogic;
private readonly IRequirementLogic requirementLogic; private readonly IRequirementLogic requirementLogic;
private readonly IProductLogic productLogic; private readonly IProductLogic productLogic;
private readonly IPlanProductionLogic planProductionLogic;
private readonly IStorekeeperReportLogic storekeeperReportLogic;
private bool IsLoggedIn { get { return Client.client != null; } } private static bool IsLoggedIn { get { return Client.client != null; } }
public HomeController(ILogger<HomeController> logger, IClientLogic clientLogic, IRequirementLogic requirementLogic, IProductLogic productLogic, IMachineLogic machineLogic) public HomeController(ILogger<HomeController> logger, IClientLogic clientLogic,
IRequirementLogic requirementLogic, IProductLogic productLogic,
IMachineLogic machineLogic, IPlanProductionLogic planProductionLogic,
IStorekeeperReportLogic storekeeperReportLogic)
{ {
_logger = logger; _logger = logger;
this.clientLogic = clientLogic; this.clientLogic = clientLogic;
this.requirementLogic = requirementLogic; this.requirementLogic = requirementLogic;
this.productLogic = productLogic; this.productLogic = productLogic;
this.machineLogic = machineLogic; this.machineLogic = machineLogic;
this.planProductionLogic = planProductionLogic;
this.storekeeperReportLogic = storekeeperReportLogic;
} }
public IActionResult Index() public IActionResult Index()
@ -83,7 +88,7 @@ namespace FactoryStorekeeperApp.Controllers
{ {
if (!password.Equals(passwordConfirm)) if (!password.Equals(passwordConfirm))
{ {
return Error(); throw new ArgumentException("Пароли не совпадают");
} }
clientLogic.Create(new ClientBindingModel clientLogic.Create(new ClientBindingModel
{ {
@ -160,7 +165,10 @@ namespace FactoryStorekeeperApp.Controllers
{ {
return Unauthorized(); return Unauthorized();
} }
machineLogic.Delete(new MachineBindingModel { Id = id }); if (id != 0)
{
machineLogic.Delete(new MachineBindingModel { Id = id });
}
return Redirect("~/Home/Machines"); return Redirect("~/Home/Machines");
} }
[HttpGet] [HttpGet]
@ -234,7 +242,8 @@ namespace FactoryStorekeeperApp.Controllers
{ {
return Unauthorized(); return Unauthorized();
} }
productLogic.Delete(new ProductBindingModel { Id = id }); if (id != 0)
productLogic.Delete(new ProductBindingModel { Id = id });
return Redirect("~/Home/Products"); return Redirect("~/Home/Products");
} }
[HttpGet] [HttpGet]
@ -306,11 +315,80 @@ namespace FactoryStorekeeperApp.Controllers
{ {
return Unauthorized(); return Unauthorized();
} }
requirementLogic.Delete(new RequirementBindingModel { Id = id }); if (id != 0)
requirementLogic.Delete(new RequirementBindingModel { Id = id });
return Redirect("~/Home/Requirements"); return Redirect("~/Home/Requirements");
} }
[HttpGet] [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<int> 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() public IActionResult Reports()
{ {
if (!IsLoggedIn) if (!IsLoggedIn)
@ -320,28 +398,33 @@ namespace FactoryStorekeeperApp.Controllers
return View(); return View();
} }
[HttpGet]
public IActionResult GetByPeriod()
{
if (!IsLoggedIn)
{
return Redirect("~/Home/Enter");
}
return View();
}
[HttpGet] [HttpGet]
public IActionResult MachinePeriodReport() public IActionResult MachinePeriodReport(DateTime datefrom, DateTime dateto)
{ {
if (!IsLoggedIn) if (!IsLoggedIn)
{ {
return Redirect("~/Home/Enter"); return Redirect("~/Home/Enter");
} }
List<MachinePeriodReportViewModel> reports = new List<MachinePeriodReportViewModel> var reports = storekeeperReportLogic.GetMachines(
{ new ClientSearchModel
new MachinePeriodReportViewModel {
{ Id = Client.client.Id
MachineName = "Станок А", },
PlanProductions = new(), new ReportBindingModel
Products = new() {
}, DateFrom = datefrom,
new MachinePeriodReportViewModel DateTo = dateto,
{ });
MachineName = "Станок B",
PlanProductions = new(),
Products = new()
}
};
return View(reports); return View(reports);
} }

View File

@ -12,12 +12,14 @@ builder.Services.AddTransient<IClientLogic, ClientLogic>();
builder.Services.AddTransient<IMachineLogic, MachineLogic>(); builder.Services.AddTransient<IMachineLogic, MachineLogic>();
builder.Services.AddTransient<IProductLogic, ProductLogic>(); builder.Services.AddTransient<IProductLogic, ProductLogic>();
builder.Services.AddTransient<IRequirementLogic, RequirementLogic>(); builder.Services.AddTransient<IRequirementLogic, RequirementLogic>();
builder.Services.AddTransient<IPlanProductionLogic, PlanProductionLogic>();
builder.Services.AddTransient<IStorekeeperReportLogic, StorekeeperReportLogic>(); builder.Services.AddTransient<IStorekeeperReportLogic, StorekeeperReportLogic>();
builder.Services.AddTransient<IClientStorage, ClientStorage>(); builder.Services.AddTransient<IClientStorage, ClientStorage>();
builder.Services.AddTransient<IMachineStorage, MachineStorage>(); builder.Services.AddTransient<IMachineStorage, MachineStorage>();
builder.Services.AddTransient<IProductStorage, ProductStorage>(); builder.Services.AddTransient<IProductStorage, ProductStorage>();
builder.Services.AddTransient<IRequirementStorage, RequirementStorage>(); builder.Services.AddTransient<IRequirementStorage, RequirementStorage>();
builder.Services.AddTransient<IPlanProductionStorage, PlanProductionStorage>();
builder.Services.AddTransient<AbstractSaveToExcel, SaveToExcel>(); builder.Services.AddTransient<AbstractSaveToExcel, SaveToExcel>();
builder.Services.AddTransient<AbstractSaveToPdf, SaveToPdf>(); builder.Services.AddTransient<AbstractSaveToPdf, SaveToPdf>();

View File

@ -0,0 +1,24 @@
@using FactoryContracts.ViewModels
@model List<MachinePeriodReportViewModel>
@{
ViewData["Title"] = "Подготовка к созданию отчета за период";
}
<div class="text-center">
<h1 class="display-4">Список станков за период</h1>
</div>
<form asp-controller="Home" asp-action="MachinePeriodReport" method="get">
<div class="row">Выберите период</div>
<div class="row">
<div class="col-4">Дата начала:</div>
<div class="col-8"><input type="date" name="datefrom" /></div>
</div>
<div class="row">
<div class="col-4">Дата конца:</div>
<div class="col-8"><input type="date" name="dateto" /></div>
</div>
<button type="submit" class="btn btn-primary">Создать отчёт</button>
</form>

View File

@ -3,7 +3,7 @@
@model List<MachinePeriodReportViewModel> @model List<MachinePeriodReportViewModel>
@{ @{
ViewData["Title"] = "Очет станков за период"; ViewData["Title"] = "Отчет станков за период";
} }
<div class="text-center"> <div class="text-center">
@ -32,7 +32,7 @@
<ul> <ul>
@foreach (var product in machine.Products) @foreach (var product in machine.Products)
{ {
<li>@product</li> <li>@product.ProductName</li>
} }
</ul> </ul>
</td> </td>
@ -40,7 +40,7 @@
<ul> <ul>
@foreach (var planProduction in machine.PlanProductions) @foreach (var planProduction in machine.PlanProductions)
{ {
<li>@planProduction</li> <li>@planProduction.ProductionName</li>
} }
</ul> </ul>
</td> </td>

View File

@ -10,37 +10,17 @@
<div class="row"> <div class="row">
<div class="col-4">Станок:</div> <div class="col-4">Станок:</div>
<div class="col-8"> <div class="col-8">
<select id="machine" name="machine" class="form-control"></select> <select id="machine" name="machine" class="form-control border border-dark rounded" asp-items="@(new SelectList(ViewBag.machines, "Id", "MachineName"))"></select>
</div> </div>
</div> </div>
<h3>Список планов производства</h3> <div class="row">
<div class="container"> <div class="col-4">Количество:</div>
<div>Заготовки</div> <input type="number" name="count"/>
<div class="table-responsive-lg"> </div>
<table id="detailsTable" class="display"> <div class="row">
<thead> <div class="col-4">Список планов производств:</div>
<tr> <select name="planproductions" id="planproductions" class="form-control border border-dark rounded" multiple size="5" asp-items="@(new SelectList(ViewBag.planProductions, "Id", "ProductionName"))">
<th>Выбор </th> </select>
<th>Название </th>
<th>Количество</th>
</tr>
</thead>
<tbody>
@foreach (var planProduction in Model)
{
<tr>
<td>
<input type="checkbox" name="planproductions" value="@planProduction.Id" />
</td>
<td>@planProduction.ProductionName</td>
<td>
<input type="number" name="count" value="0" min="0" class="form-control" />
</td>
</tr>
}
</tbody>
</table>
</div>
</div> </div>
<div class="row"> <div class="row">
<div class="col-8"></div> <div class="col-8"></div>

View File

@ -5,7 +5,7 @@
<div class="text-center"> <div class="text-center">
<h1 class="display-4">Выберите тип отчета</h1> <h1 class="display-4">Выберите тип отчета</h1>
<div class="list-group"> <div class="list-group">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="PlanProductionByProductReport">Отчет планов производства по изделиям</a> <a class="nav-link text-dark" asp-controller="Home" asp-action="PlanProductionByProductReport">Отчет планов производства по изделиям</a>
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="MachinePeriodReport">Отчет по станкам за период</a> <a class="nav-link text-dark" asp-controller="Home" asp-action="GetByPeriod">Отчет по станкам за период</a>
</div> </div>
</div> </div>