DavidMakarov 2024-05-28 23:35:11 +04:00
commit f9eae8c2da
7 changed files with 120 additions and 73 deletions

View File

@ -4,6 +4,7 @@ using FactoryContracts.SearchModels;
using FactoryContracts.StoragesContracts;
using FactoryContracts.ViewModels;
using FactoryDatabaseImplement.Models;
using System.Reflection.PortableExecutable;
namespace FactoryDatabaseImplement.Implements
{
@ -97,19 +98,30 @@ namespace FactoryDatabaseImplement.Implements
public PlanProductionViewModel? Update(PlanProductionBindingModel model)
{
using var context = new FactoryDatabase();
var order = context.PlanProductions
.Include(x => x.Client)
.Include(x => x.Workpieces)
.ThenInclude(x => x.Workpiece)
.FirstOrDefault(x => x.Id == model.Id);
if (order == null)
using var transaction = context.Database.BeginTransaction();
try
{
return null;
}
order.Update(model);
context.SaveChanges();
return order.GetViewModel;
}
var plan = context.PlanProductions
.Include(x => x.Client)
.Include(x => x.Workpieces)
.ThenInclude(x => x.Workpiece)
.FirstOrDefault(x => x.Id == model.Id);
if (plan == null)
{
return null;
}
plan.Update(model);
context.SaveChanges();
plan.UpdateWorkpieces(context, model);
transaction.Commit();
return plan.GetViewModel;
}
catch
{
transaction.Rollback();
throw;
}
}
}
}

View File

@ -84,11 +84,12 @@ namespace FactoryDatabaseImplement.Models
};
public void UpdateWorkpieces(FactoryDatabase context, PlanProductionBindingModel model)
{
var planProductionWorkpieces = context.PlanProductionWorkpieces.Where(rec => rec.PlanProductionId == model.Id).ToList();
if (planProductionWorkpieces != null && planProductionWorkpieces.Count > 0)
if (planProductionWorkpieces != null && planProductionWorkpieces.Count > 0 && model.PlanProductionWorkpieces.Count > 0)
{
context.PlanProductionWorkpieces.RemoveRange(planProductionWorkpieces.Where(rec => !model.PlanProductionWorkpieces.ContainsKey(rec.WorkpieceId)));
context.SaveChanges();
context.SaveChanges();
foreach (var updateWorkpiece in planProductionWorkpieces)
{
updateWorkpiece.Count = model.PlanProductionWorkpieces[updateWorkpiece.WorkpieceId].Item2;

View File

@ -15,8 +15,8 @@ namespace FactoryDatabaseImplement.Models
[Required]
public int Count { get; set; }
public virtual PlanProduction PlanProduction { get; set; } = new();
public virtual PlanProduction PlanProduction { get; set; }
public virtual Workpiece Workpiece { get; set; } = new();
public virtual Workpiece Workpiece { get; set; }
}
}

View File

@ -155,6 +155,8 @@ namespace FactoryWorkerApp.Controllers
[HttpGet]
public IActionResult PlanProduction(int id)
{
var workpieces = _logic.GetWorkpieces(Client.user!.Id);
ViewBag.AllWorkpieces = workpieces;
if (id != 0)
{
var value = _logic.GetPlanProduction(id);
@ -186,27 +188,39 @@ namespace FactoryWorkerApp.Controllers
{
if (!IsLoggedIn)
return RedirectToAction("Index");
var plan = _logic.GetPlanProduction(id);
ViewBag.PlanProduction = plan;
var workpieces = _logic.GetWorkpieces(id);
return View(workpieces);
ViewBag.PlanProductions = _logic.GetPlanProductions(Client.user!.Id);
ViewBag.Workpieces = _logic.GetWorkpieces(Client.user!.Id);
return View();
}
[HttpPost]
public IActionResult ConnectionPlanProductionWorkpiece(int planProductionId, int workpieceId)
public void ConnectionPlanProductionWorkpiece(int planId, int workpieceId, int count)
{
if (!IsLoggedIn)
return RedirectToAction("Index");
var plan = _logic.GetPlanProduction(planProductionId);
if (plan == null)
return RedirectToAction("Index");
PlanProductionBindingModel productBinding = new() { Id = planProductionId, Count = plan.Count, Deadline = plan.Deadline, ClientId= plan.ClientId, ProductionName= plan.ProductionName, PlanProductionWorkpieces = plan.PlanProductionWorkpieces};
//productBinding.PlanProductionWorkpieces.Add(_logic.GetWorkpiece(workpieceId));
_logic.UpdatePlanProduction(productBinding);
return RedirectToAction("Index");
Response.Redirect("Index");
PlanProductionViewModel planProduction = _logic.GetPlanProduction(planId)!;
WorkpieceViewModel workpiece = _logic.GetWorkpiece(workpieceId)!;
if(planProduction.PlanProductionWorkpieces.ContainsKey(workpieceId))
planProduction.PlanProductionWorkpieces[workpieceId] = (workpiece, planProduction.PlanProductionWorkpieces[workpieceId].Item2 + count);
else
planProduction.PlanProductionWorkpieces.Add(workpieceId, (workpiece, count));
_logic.UpdatePlanProduction(
new PlanProductionBindingModel
{
Id = planId,
ClientId = Client.user!.Id,
Count = planProduction.Count,
Deadline = planProduction.Deadline,
PlanProductionWorkpieces = planProduction.PlanProductionWorkpieces,
ProductionName = planProduction.ProductionName,
}
);
}
Response.Redirect("Index");
[HttpGet]
}
[HttpGet]
public IActionResult Reports()
{
return View();
@ -304,7 +318,6 @@ namespace FactoryWorkerApp.Controllers
return View(new ExecutionPhaseViewModel());
}
[HttpPost]
// доделать
public IActionResult ExecutionPhase(int id, string name, ExecutionPhaseStatus status, string impFIO, int planId)
{
ExecutionPhaseBindingModel model = new ExecutionPhaseBindingModel();

View File

@ -1,7 +1,6 @@
@using FactoryDataModels.Enums
@{
@{
ViewData["Title"] = "Connect plan and workpieces";
}
<div class="text-center">
<h3 class="display-4">Привязка заготовок к плану производства:</h3>
@ -9,41 +8,35 @@
<form method="post">
<div class="row">
<div class="col-4">План производства:</div>
<div class="col-8">
<select id="planproduction" name="planproduction" class="form-control"></select>
<div class="col-8" >
<select name="planId" id="PlanProductionSelect" class="form-control">
<option value="">Выберите план</option>
@foreach (var planProduction in ViewBag.PlanProductions)
{
<option name ="planId" value="@planProduction.Id">@planProduction.ProductionName</option>
}
</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 workpiece in Model)
{
<tr>
<td>
<input type="checkbox" name="workpieces" value="@workpiece.Id" />
</td>
<td>@workpiece.WorkpieceName</td>
<td>
<input type="number" name="count" value="0" min="0" class="form-control" />
</td>
</tr>
}
</tbody>
</table>
</div>
</div>
<div class="row">
<div class="col-8"></div>
<div class="col-4"><input type="submit" value="Сохранить" class="btn btn-primary" /></div>
</div>
<div class="row">
<div class="col-4">Заготовка:</div>
<div class="col-8" >
<select name ="workpieceId" id="WorkpieceSelect" class="form-control">
<option value="">Выберите заготовку</option>
@foreach (var workpiece in ViewBag.Workpieces)
{
<option name="workpieceId" value="@workpiece.Id">@workpiece.WorkpieceName</option>
}
</select>
</div>
</div>
<div class="row mb-5">
<div class="col-4">Количество заготовок:</div>
<div class="col-8">
<input type="number" name="count" id="count" />
</div>
</div>
<div class="col-4">
<input type="submit" value="Добавить" class="btn btn-success" />
</div>
</form>

View File

@ -2,12 +2,40 @@
@model PlanProductionViewModel;
@{
ViewData["Title"] = "Plan Production";
ViewData["Title"] = "Plan Production";
ViewBag.Workpieces = Model.PlanProductionWorkpieces;
}
<div class="text-center">
<h2 class="display-4">План производства</h2>
</div>
<form method="post">
<div class="container">
<h2>Заготовки</h2>
<div class="table-responsive-lg">
<table id="workpiecesTable" class="display">
<thead>
<tr>
<th>Название</th>
<th>Количество</th>
</tr>
</thead>
<tbody>
@foreach (var workpiece in ViewBag.Workpieces)
{
<tr data-workpiece-id="@workpiece.Value.Item1.Id">
<td>
<input type="hidden" name="WorkpieceIds" value="@workpiece.Key" />
@workpiece.Value.Item1.WorkpieceName
</td>
<td>
<input type="text" name="counts" value="@workpiece.Value.Item2" min="0" class="form-control product-count" readonly />
</td>
</tr>
}
</tbody>
</table>
</div>
</div>
<div class="row">
<div class="col-4">Название:</div>
<div class="col-8"><input type="text" name="productionname" id="productionname" value="@Model.ProductionName" /></div>
@ -24,4 +52,4 @@
<div class="col-8"></div>
<div class="col-4"><input type="submit" value="Создать" class="btn btn-primary" /></div>
</div>
</form>
</form>

View File

@ -46,7 +46,7 @@
<option value="@product.Id">@product.ProductName</option>
}
</select>
<button type="button" id="addProduct" class="btn btn-secondary">Добавить деталь</button>
<button type="button" id="addProduct" class="btn btn-secondary">Добавить изделие</button>
</div>
<div class="row">
<div class="col-4">Название:</div>