Files
gwms/GWMS.UI/Components/OrderLoad.razor
T

192 lines
4.8 KiB
Plaintext

@using GWMS.Data.DatabaseModels
@using GWMS.Data.DTO
@using GWMS.UI.Data
@inject GWMSDataService DataService
@if (@currItem != null)
{
<ul class="list-group">
<li class="list-group-item active">
<h3 class="textCondensed mb-0">@OrderCode</h3>
</li>
<li class="list-group-item"><i>@currItem.OrderDesc</i></li>
@if (plantCorrect)
{
<li class="list-group-item h2">
<i class="fas fa-weight-hanging"></i>
<b>@currItem.OrderQty.ToString("N0")</b> kg
</li>
@if (showStart)
{
<li class="list-group-item">
<button class="btn btn-lg btn-block btn-success" @onclick="() => RefillStart()" title="Inizio Carico"><i class="fas fa-play"></i>&nbsp; Inizio Carico</button>
</li>
}
@if (showEnd)
{
@*<li class="list-group-item">
<InputNumber @bind-Value="@currItem.ExecutionQty" class="form-control"></InputNumber>
</li>*@
<li class="list-group-item">
<button class="btn btn-lg btn-block btn-warning" @onclick="() => RefillEnd()" title="Fine Carico"><i class="fas fa-stop"></i>&nbsp; Fine Carico</button>
</li>
}
}
</ul>
}
@code {
protected OrderModel _currItem = new OrderModel();
[Parameter]
public OrderModel currItem
{
get
{
return _currItem;
}
set
{
_currItem = value;
}
}
public string _orderCode { get; set; } = "";
[Parameter]
public string OrderCode
{
get
{
return _orderCode;
}
set
{
_orderCode = value;
var pUpd = Task.Run(async () => await ReloadData());
pUpd.Wait();
}
}
/// <summary>
/// verifica correttezza plant/ordine
/// </summary>
protected bool plantCorrect
{
get
{
bool answ = !string.IsNullOrEmpty(_orderCode);
try
{
if (answ)
{
answ = _orderCode.StartsWith($"O{currPlantData.PlantCode}");
}
}
catch
{
answ = false;
}
return answ;
}
}
public int _plantId { get; set; } = 0;
[Parameter]
public int PlantId
{
get
{
return _plantId;
}
set
{
_plantId = value;
var pUpd = Task.Run(async () => await ReloadData());
pUpd.Wait();
}
}
List<PlantDTO> plantsData = new List<PlantDTO>();
PlantDTO currPlantData = null;
private async Task ReloadData()
{
plantsData = await DataService.PlantsGetAll();
// recupero dato del plant corrente
currPlantData = plantsData.Where(x => x.PlantId == PlantId).FirstOrDefault();
// solo se ho valore QR selezionato
if (!string.IsNullOrEmpty(OrderCode))
{
currItem = await DataService.OrderGetByCode(OrderCode);
}
else
{
currItem = null;
}
}
protected void RefillStart()
{
if (currPlantData != null)
{
// aggiorno il record corrente con livello e dataora inizio carico...
_currItem.LevelStart = currPlantData.LevelAct;
_currItem.DtExecStart = DateTime.Now;
}
// salvo...
DataService.OrderUpdate(_currItem);
}
protected void RefillEnd()
{
if (currPlantData != null)
{
// aggiorno il record corrente con livello e dataora inizio carico...
_currItem.LevelEnd = currPlantData.LevelAct;
_currItem.DtExecEnd = DateTime.Now;
}
// salvo...
DataService.OrderUpdate(_currItem);
}
protected bool showStart
{
get
{
bool answ = (PlantId > 0);
if (answ)
{
if (_currItem != null)
{
answ = _currItem.DtExecStart.Year <= 1;
}
}
return answ;
}
}
protected bool showEnd
{
get
{
bool answ = (PlantId > 0);
if (answ)
{
if (_currItem != null)
{
DateTime oggi = DateTime.Today;
answ = _currItem.DtExecStart.Year > 1 && _currItem.DtExecEnd.Year <= 1;
#if false
if (answ)
{
// se visibile --> calcolo execution QTY
_currItem.ExecutionQty = _currItem.LevelEnd - _currItem.LevelStart;
}
#endif
}
}
return answ;
}
}
}