вроде страницы сущностей работают исправно

This commit is contained in:
sardq 2024-05-28 20:50:32 +04:00
parent 37aa09c442
commit 6e34920bd3
8 changed files with 129 additions and 27 deletions

View File

@ -37,7 +37,7 @@ namespace FactoryDatabaseImplement.Implements
} }
using var context = new FactoryDatabase(); using var context = new FactoryDatabase();
return context.Clients return context.Clients
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.Login) && x.Login == model.Login) || .FirstOrDefault(x => ((!string.IsNullOrEmpty(model.Login) && x.Login == model.Login) && (!string.IsNullOrEmpty(model.Password) && x.Password == model.Password)) ||
(model.Id.HasValue && x.Id == model.Id)) (model.Id.HasValue && x.Id == model.Id))
?.GetViewModel; ?.GetViewModel;
} }

View File

@ -73,6 +73,7 @@ namespace FactoryDatabaseImplement.Models
{ {
Id = Id, Id = Id,
ExecutionPhaseName = ExecutionPhaseName, ExecutionPhaseName = ExecutionPhaseName,
PlanProductionName = PlanProduction == null ? null : PlanProduction.ProductionName,
ImplementerFIO = ImplementerFIO, ImplementerFIO = ImplementerFIO,
ClientId = ClientId, ClientId = ClientId,
PlanProductionId = PlanProductionId, PlanProductionId = PlanProductionId,

View File

@ -11,7 +11,7 @@ namespace FactoryDatabaseImplement.Models
public int Id { get; private set; } public int Id { get; private set; }
[Required] [Required]
public int ClientId { get; private set; } public int ClientId { get; private set; }
public virtual Client Client { get; private set; } = new(); public virtual Client Client { get; private set; }
[Required] [Required]
public string ProductionName { get; private set; } = string.Empty; public string ProductionName { get; private set; } = string.Empty;

View File

@ -1,4 +1,5 @@
using FactoryContracts.BindingModels; using DocumentFormat.OpenXml.Office2010.Excel;
using FactoryContracts.BindingModels;
using FactoryContracts.ViewModels; using FactoryContracts.ViewModels;
using FactoryDatabaseImplement.Models; using FactoryDatabaseImplement.Models;
using FactoryDataModels.Enums; using FactoryDataModels.Enums;
@ -49,8 +50,8 @@ namespace FactoryWorkerApp.Controllers
if (user != null) if (user != null)
{ {
Client.user = user; Client.user = user;
Response.Redirect("Index");
} }
Response.Redirect("Index");
} }
[HttpGet] [HttpGet]
public IActionResult Register() public IActionResult Register()
@ -104,21 +105,34 @@ namespace FactoryWorkerApp.Controllers
return View(new WorkpieceViewModel()); return View(new WorkpieceViewModel());
} }
[HttpPost] [HttpPost]
public IActionResult Workpiece(WorkpieceBindingModel model) public IActionResult Workpiece(int id, string workpiecename, string material, int cost, int[] productIds, int[] counts)
{ {
WorkpieceBindingModel model = new WorkpieceBindingModel();
model.Id = id;
model.WorkpieceName = workpiecename;
model.Material = material;
model.Cost = cost;
model.ClientId = Client.user!.Id;
var products = _logic.GetProducts();
for (int i = 0; i < productIds.Length; i++)
{
var product = products!.FirstOrDefault(x => x.Id == productIds[i])!;
if (counts[i] <= 0)
continue;
model.WorkpieceProducts[productIds[i]] = (product, counts[i]);
}
if (model.WorkpieceProducts.Count == 0)
return RedirectToAction("Workpieces");
if (model.Id == 0) if (model.Id == 0)
{ {
model.DateCreate = DateTime.Now; model.DateCreate = DateTime.Now;
model.ClientId = Client.user!.Id; _logic.CreateWorkpiece(model);
if (_logic.CreateWorkpiece(model))
return RedirectToAction("Workpieces");
} }
else else
{ {
if (_logic.UpdateWorkpiece(model)) _logic.UpdateWorkpiece(model);
return RedirectToAction("Workpieces");
} }
return View(); return RedirectToAction("Workpieces");
} }
[HttpGet] [HttpGet]

View File

@ -12,8 +12,8 @@
<form method="post"> <form method="post">
<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="planId" class="form-control"> <select name="planId" id="PlanProductionSelect" class="form-control">
<option value="">Выберите план</option> <option value="">Выберите план</option>
@foreach (var planProduction in ViewBag.AllPlans) @foreach (var planProduction in ViewBag.AllPlans)
{ {

View File

@ -14,7 +14,7 @@
</div> </div>
<div class="row"> <div class="row">
<div class="col-4">Количество:</div> <div class="col-4">Количество:</div>
<div class="col-8"><input type="text" id="count" name="count" value="@Model.Count" /></div> <div class="col-8"><input type="number" id="count" name="count" value="@Model.Count" /></div>
</div> </div>
<div class="row"> <div class="row">
<div class="col-4">Срок выполнения:</div> <div class="col-4">Срок выполнения:</div>

View File

@ -8,34 +8,45 @@
<div class="text-center"> <div class="text-center">
<h2 class="display-4">Заготовка</h2> <h2 class="display-4">Заготовка</h2>
</div> </div>
<form method="post"> <form id="workpieceForm" method="post">
<div class="container"> <div class="container">
<div>Изделия</div> <div>Изделия</div>
<div class="table-responsive-lg"> <div class="table-responsive-lg">
<table id="detailsTable" class="display"> <table id="productsTable" class="display">
<thead> <thead>
<tr> <tr>
<th>Выбор</th>
<th>Название</th> <th>Название</th>
<th>Количество</th> <th>Количество</th>
<th>Удалить</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@foreach (var product in ViewBag.AllProducts) @foreach (var product in ViewBag.Products)
{ {
<tr> <tr data-product-id="@product.Value.Item1.Id">
<td> <td>
<input type="checkbox" name="products" value="@product.Id" /> <input type="hidden" name="productIds" value="@product.Key" />
@product.Value.Item1.ProductName
</td> </td>
<td>@product.ProductName</td>
<td> <td>
<input type="number" name="count" value="0" min="0" class="form-control" /> <input type="number" name="counts" value="@product.Value.Item2" min="0" class="form-control product-count" />
</td>
<td>
<button type="button" class="deleteProduct" data-product-id="@product.Value.Item1.Id">Удалить</button>
</td> </td>
</tr> </tr>
} }
</tbody> </tbody>
</table> </table>
</div> </div>
<select id="productSelect" class="form-control">
<option value="">Выберите изделие</option>
@foreach (var product in ViewBag.AllProducts)
{
<option value="@product.Id">@product.ProductName</option>
}
</select>
<button type="button" id="addProduct" class="btn btn-secondary">Добавить деталь</button>
</div> </div>
<div class="row"> <div class="row">
<div class="col-4">Название:</div> <div class="col-4">Название:</div>
@ -54,3 +65,79 @@
<div class="col-4"><input type="submit" value="Создать" class="btn btn-primary" /></div> <div class="col-4"><input type="submit" value="Создать" class="btn btn-primary" /></div>
</div> </div>
</form> </form>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdn.datatables.net/1.11.3/js/jquery.dataTables.js"></script>
<script>
$(document).ready(function () {
$(document).on('click', '.deleteProduct', function () {
var row = $(this).closest('tr');
row.remove();
});
$('#addProduct').click(function () {
var selectedProduct = $('#productSelect option:selected');
if (selectedProduct.val()) {
var productId = selectedProduct.val();
var productName = selectedProduct.text();
var exists = false;
$('#productsTable tbody tr').each(function () {
if ($(this).data('product-id') == productId) {
exists = true;
return false;
}
});
if (exists) {
alert('Это изделие уже добавлено.');
return;
}
var newRow = `
<tr data-product-id="${productId}">
<td>
<input type="hidden" name="productIds" value="${productId}" />
${productName}
</td>
<td><input type="number" name="counts" value="0" min="1" class="form-control product-count" /></td>
<td><button type="button" class="deleteProduct" data-product-id="${productId}">Удалить</button></td>
</tr>
`;
$('#productsTable tbody').append(newRow);
updateSum();
$('#productSelect').val('');
} else {
alert('Выберите изделие для добавления');
}
});
$('#workpieceForm').submit(function (event) {
var title = $('#title').val();
var isValid = true;
var totalProducts = $('#productsTable tbody tr').length;
if (totalProducts == 0) {
alert('Пожалуйста, добавьте хотя бы одно изделие.');
isValid = false;
}
$('#productsTable tbody tr').each(function () {
var count = $(this).find('input[name="counts"]').val();
if (count < 1) {
alert('Количество каждого изделия должно быть не менее 1.');
isValid = false;
return false;
}
});
if (!isValid) {
event.preventDefault();
}
});
});
</script>

View File

@ -17,7 +17,7 @@
return; return;
} }
<p> <p>
<a asp-action="Workpiece">Создать заказ</a> <a asp-action="Workpiece">Создать заготовку</a>
</p> </p>