Merge branch 'main' of https://git.is.ulstu.ru/DavidMakarov/PIbd-21_Makarov_Razubaev_CourseWork
This commit is contained in:
commit
ba680292ef
@ -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))
|
||||
{
|
||||
|
@ -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()
|
||||
{
|
||||
|
@ -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,23 @@ namespace FactoryStorekeeperApp.Controllers
|
||||
private readonly IMachineLogic machineLogic;
|
||||
private readonly IRequirementLogic requirementLogic;
|
||||
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;
|
||||
this.clientLogic = clientLogic;
|
||||
this.requirementLogic = requirementLogic;
|
||||
this.productLogic = productLogic;
|
||||
this.machineLogic = machineLogic;
|
||||
this.planProductionLogic = planProductionLogic;
|
||||
this.storekeeperReportLogic = storekeeperReportLogic;
|
||||
}
|
||||
|
||||
public IActionResult Index()
|
||||
@ -83,7 +88,7 @@ namespace FactoryStorekeeperApp.Controllers
|
||||
{
|
||||
if (!password.Equals(passwordConfirm))
|
||||
{
|
||||
return Error();
|
||||
throw new ArgumentException("Пароли не совпадают");
|
||||
}
|
||||
clientLogic.Create(new ClientBindingModel
|
||||
{
|
||||
@ -160,7 +165,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 +242,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 +315,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<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()
|
||||
{
|
||||
if (!IsLoggedIn)
|
||||
@ -320,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<MachinePeriodReportViewModel> reports = new List<MachinePeriodReportViewModel>
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -12,12 +12,14 @@ builder.Services.AddTransient<IClientLogic, ClientLogic>();
|
||||
builder.Services.AddTransient<IMachineLogic, MachineLogic>();
|
||||
builder.Services.AddTransient<IProductLogic, ProductLogic>();
|
||||
builder.Services.AddTransient<IRequirementLogic, RequirementLogic>();
|
||||
builder.Services.AddTransient<IPlanProductionLogic, PlanProductionLogic>();
|
||||
builder.Services.AddTransient<IStorekeeperReportLogic, StorekeeperReportLogic>();
|
||||
|
||||
builder.Services.AddTransient<IClientStorage, ClientStorage>();
|
||||
builder.Services.AddTransient<IMachineStorage, MachineStorage>();
|
||||
builder.Services.AddTransient<IProductStorage, ProductStorage>();
|
||||
builder.Services.AddTransient<IRequirementStorage, RequirementStorage>();
|
||||
builder.Services.AddTransient<IPlanProductionStorage, PlanProductionStorage>();
|
||||
|
||||
builder.Services.AddTransient<AbstractSaveToExcel, SaveToExcel>();
|
||||
builder.Services.AddTransient<AbstractSaveToPdf, SaveToPdf>();
|
||||
|
24
Factory/FactoryStorekeeperApp/Views/Home/GetByPeriod.cshtml
Normal file
24
Factory/FactoryStorekeeperApp/Views/Home/GetByPeriod.cshtml
Normal 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>
|
@ -3,7 +3,7 @@
|
||||
@model List<MachinePeriodReportViewModel>
|
||||
|
||||
@{
|
||||
ViewData["Title"] = "Очет станков за период";
|
||||
ViewData["Title"] = "Отчет станков за период";
|
||||
}
|
||||
|
||||
<div class="text-center">
|
||||
@ -32,7 +32,7 @@
|
||||
<ul>
|
||||
@foreach (var product in machine.Products)
|
||||
{
|
||||
<li>@product</li>
|
||||
<li>@product.ProductName</li>
|
||||
}
|
||||
</ul>
|
||||
</td>
|
||||
@ -40,7 +40,7 @@
|
||||
<ul>
|
||||
@foreach (var planProduction in machine.PlanProductions)
|
||||
{
|
||||
<li>@planProduction</li>
|
||||
<li>@planProduction.ProductionName</li>
|
||||
}
|
||||
</ul>
|
||||
</td>
|
||||
|
@ -10,37 +10,17 @@
|
||||
<div class="row">
|
||||
<div class="col-4">Станок:</div>
|
||||
<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>
|
||||
<h3>Список планов производства</h3>
|
||||
<div class="container">
|
||||
<div>Заготовки</div>
|
||||
<div class="table-responsive-lg">
|
||||
<table id="detailsTable" class="display">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Выбор </th>
|
||||
<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 class="row">
|
||||
<div class="col-4">Количество:</div>
|
||||
<input type="number" name="count"/>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4">Список планов производств:</div>
|
||||
<select name="planproductions" id="planproductions" class="form-control border border-dark rounded" multiple size="5" asp-items="@(new SelectList(ViewBag.planProductions, "Id", "ProductionName"))">
|
||||
</select>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-8"></div>
|
||||
|
@ -5,7 +5,7 @@
|
||||
<div class="text-center">
|
||||
<h1 class="display-4">Выберите тип отчета</h1>
|
||||
<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-area="" asp-controller="Home" asp-action="MachinePeriodReport">Отчет по станкам за период</a>
|
||||
<a class="nav-link text-dark" asp-controller="Home" asp-action="PlanProductionByProductReport">Отчет планов производства по изделиям</a>
|
||||
<a class="nav-link text-dark" asp-controller="Home" asp-action="GetByPeriod">Отчет по станкам за период</a>
|
||||
</div>
|
||||
</div>
|
Loading…
Reference in New Issue
Block a user