4fda312aac
- altri metodi tracciati - modifica json x prod - aggiunta Async vari
171 lines
4.6 KiB
C#
171 lines
4.6 KiB
C#
using GWMS.Data.DatabaseModels;
|
|
using GWMS.UI.Data;
|
|
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.JSInterop;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace GWMS.UI.Components
|
|
{
|
|
public partial class OrderAdminEditor
|
|
{
|
|
#region Public Properties
|
|
|
|
[Parameter]
|
|
public OrderModel currItem
|
|
{
|
|
get
|
|
{
|
|
return _currItem = null;
|
|
}
|
|
set
|
|
{
|
|
_currItem = value;
|
|
}
|
|
}
|
|
|
|
[Parameter]
|
|
public EventCallback<int> DataReset { get; set; }
|
|
|
|
[Parameter]
|
|
public EventCallback<int> DataUpdated { get; set; }
|
|
|
|
[Parameter]
|
|
public int SupplierId
|
|
{
|
|
get
|
|
{
|
|
return _supplierId;
|
|
}
|
|
set
|
|
{
|
|
_supplierId = value;
|
|
// condiziono visualizzazione...
|
|
var pUpd = Task.Run(async () => await ReloadAllData());
|
|
pUpd.Wait();
|
|
}
|
|
}
|
|
|
|
#endregion Public Properties
|
|
|
|
#region Protected Fields
|
|
|
|
protected OrderModel _currItem = new OrderModel();
|
|
|
|
#endregion Protected Fields
|
|
|
|
#region Protected Properties
|
|
|
|
protected int _supplierId { get; set; } = 0;
|
|
|
|
[Inject]
|
|
protected MessageService MServ { get; set; } = null;
|
|
|
|
protected string rawCode
|
|
{
|
|
get
|
|
{
|
|
string answ = "";
|
|
if (_currItem != null)
|
|
{
|
|
answ = _currItem.OrderCode;
|
|
}
|
|
return answ;
|
|
}
|
|
}
|
|
|
|
#endregion Protected Properties
|
|
|
|
#region Protected Methods
|
|
|
|
// Blazor: get query parm from the URL
|
|
protected string GetQueryParm(string parmName)
|
|
{
|
|
var uriBuilder = new UriBuilder(NavManager.Uri);
|
|
var q = System.Web.HttpUtility.ParseQueryString(uriBuilder.Query);
|
|
return q[parmName] ?? "";
|
|
}
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
await ReloadAllData();
|
|
await JSRuntime.InvokeVoidAsync("displayQr", "qrCodeImg", rawCode);
|
|
}
|
|
|
|
protected async Task ReloadAllData()
|
|
{
|
|
suppList = await DataService.SuppliersGetAllAsync();
|
|
transpList = await DataService.TransportersGetAllAsync();
|
|
|
|
// vedere anche https://www.mikesdotnetting.com/article/340/working-with-query-strings-in-blazor
|
|
var uri = NavManager.ToAbsoluteUri(NavManager.Uri);
|
|
var currMode = GetQueryParm("currMode");
|
|
if (!string.IsNullOrEmpty(currMode))
|
|
{
|
|
editAll = currMode.Equals("debug");
|
|
}
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Private Fields
|
|
|
|
private List<SupplierModel> suppList;
|
|
private List<TransporterModel> transpList;
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Private Properties
|
|
|
|
private bool editAll { get; set; } = false;
|
|
|
|
#endregion Private Properties
|
|
|
|
#region Private Methods
|
|
|
|
private async Task cancelUpdate()
|
|
{
|
|
await DataReset.InvokeAsync(0);
|
|
}
|
|
|
|
private async Task deleteRecord()
|
|
{
|
|
if (!await JSRuntime.InvokeAsync<bool>("confirm", "Sicuro di voler eliminare l'ordine selezionato??"))
|
|
return;
|
|
|
|
if (_currItem != null)
|
|
{
|
|
using var activity = StartTracing("Delete");
|
|
await DataService.OrderDeleteAsync(_currItem);
|
|
activity?.SetTag("order.code", _currItem.OrderCode);
|
|
activity?.SetTag("order.operator", MServ.UserName);
|
|
activity?.SetTag("order.quantity_req", _currItem.OrderQty);
|
|
await DataUpdated.InvokeAsync(1);
|
|
}
|
|
else
|
|
{
|
|
Console.WriteLine("User null!");
|
|
}
|
|
}
|
|
|
|
private async Task saveUpdate()
|
|
{
|
|
if (_currItem != null)
|
|
{
|
|
using var activity = StartTracing("SaveUpdate");
|
|
await DataService.OrderUpdateAsync(_currItem);
|
|
activity?.SetTag("order.code", _currItem.OrderCode);
|
|
activity?.SetTag("order.operator", MServ.UserName);
|
|
activity?.SetTag("order.quantity_req", _currItem.OrderQty);
|
|
await DataUpdated.InvokeAsync(1);
|
|
}
|
|
else
|
|
{
|
|
Console.WriteLine("Order null!");
|
|
}
|
|
}
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |