300 lines
7.7 KiB
C#
300 lines
7.7 KiB
C#
using GWMS.Data.DatabaseModels;
|
|
using GWMS.Data.DTO;
|
|
using GWMS.UI.Data;
|
|
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.JSInterop;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace GWMS.UI.Pages
|
|
{
|
|
public partial class Orders : ComponentBase, IDisposable
|
|
{
|
|
#region Private Fields
|
|
|
|
private OrderModel currRecord = null;
|
|
|
|
private List<OrderModel> ListRecords;
|
|
private List<PlantDTO> PlantsList;
|
|
private List<OrderModel> SearchRecords;
|
|
private List<SupplierModel> SuppliersList;
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Private Properties
|
|
|
|
private int _currPage { get; set; } = 1;
|
|
|
|
private int _numRecord { get; set; } = 10;
|
|
|
|
private int currPage
|
|
{
|
|
get => _currPage;
|
|
set
|
|
{
|
|
if (_currPage != value)
|
|
{
|
|
_currPage = value;
|
|
var pUpd = Task.Run(async () => await ReloadData());
|
|
pUpd.Wait();
|
|
}
|
|
}
|
|
}
|
|
|
|
private bool isLoading { get; set; } = false;
|
|
|
|
private int numRecord
|
|
{
|
|
get => _numRecord;
|
|
set
|
|
{
|
|
if (_numRecord != value)
|
|
{
|
|
_numRecord = value;
|
|
var pUpd = Task.Run(async () => await ReloadData());
|
|
pUpd.Wait();
|
|
}
|
|
}
|
|
}
|
|
|
|
private int SelPlantId
|
|
{
|
|
get
|
|
{
|
|
int answ = 0;
|
|
if (AppMService.Order_Filter != null)
|
|
{
|
|
answ = AppMService.Order_Filter.PlantId;
|
|
}
|
|
return answ;
|
|
}
|
|
set
|
|
{
|
|
if (!AppMService.Order_Filter.PlantId.Equals(value))
|
|
{
|
|
AppMService.Order_Filter.PlantId = value;
|
|
var pUpd = Task.Run(async () => await ReloadData());
|
|
pUpd.Wait();
|
|
}
|
|
}
|
|
}
|
|
|
|
private int SelSupplierId
|
|
{
|
|
get
|
|
{
|
|
int answ = 0;
|
|
if (AppMService.Order_Filter != null)
|
|
{
|
|
answ = AppMService.Order_Filter.SupplierId;
|
|
}
|
|
return answ;
|
|
}
|
|
set
|
|
{
|
|
if (!AppMService.Order_Filter.SupplierId.Equals(value))
|
|
{
|
|
AppMService.Order_Filter.SupplierId = value;
|
|
var pUpd = Task.Run(async () => await ReloadData());
|
|
pUpd.Wait();
|
|
}
|
|
}
|
|
}
|
|
|
|
private bool ShowCharts { get; set; } = false;
|
|
|
|
#endregion Private Properties
|
|
|
|
#region Protected Properties
|
|
|
|
[Inject]
|
|
protected MessageService AppMService { get; set; }
|
|
|
|
[Inject]
|
|
protected GWMSDataService DataService { get; set; }
|
|
|
|
protected DateTime DateEnd
|
|
{
|
|
get
|
|
{
|
|
DateTime answ = DateTime.Today.AddDays(1);
|
|
if (AppMService.Order_Filter != null)
|
|
{
|
|
answ = AppMService.Order_Filter.DateEnd;
|
|
}
|
|
return answ;
|
|
}
|
|
set
|
|
{
|
|
if (!AppMService.Order_Filter.DateEnd.Equals(value))
|
|
{
|
|
AppMService.Order_Filter.DateEnd = value;
|
|
var pUpd = Task.Run(async () => await ReloadData());
|
|
pUpd.Wait();
|
|
}
|
|
}
|
|
}
|
|
|
|
protected DateTime DateStart
|
|
{
|
|
get
|
|
{
|
|
DateTime answ = DateTime.Today.AddDays(-1);
|
|
if (AppMService.Order_Filter != null)
|
|
{
|
|
answ = AppMService.Order_Filter.DateStart;
|
|
}
|
|
return answ;
|
|
}
|
|
set
|
|
{
|
|
if (!AppMService.Order_Filter.DateStart.Equals(value))
|
|
{
|
|
AppMService.Order_Filter.DateStart = value;
|
|
var pUpd = Task.Run(async () => await ReloadData());
|
|
pUpd.Wait();
|
|
}
|
|
}
|
|
}
|
|
|
|
[Inject]
|
|
protected IJSRuntime JSRuntime { get; set; }
|
|
|
|
[Inject]
|
|
protected NavigationManager NavManager { get; set; }
|
|
|
|
protected int totalCount
|
|
{
|
|
get
|
|
{
|
|
int answ = 0;
|
|
if (SearchRecords != null)
|
|
{
|
|
answ = SearchRecords.Count;
|
|
}
|
|
return answ;
|
|
}
|
|
}
|
|
|
|
#endregion Protected Properties
|
|
|
|
#region Private Methods
|
|
|
|
private void OnDateEndChanged(DateTime? date)
|
|
{
|
|
DateEnd = (DateTime)date;
|
|
}
|
|
|
|
private void OnDateStartChanged(DateTime? date)
|
|
{
|
|
DateStart = (DateTime)date;
|
|
}
|
|
|
|
private async Task ReloadData()
|
|
{
|
|
isLoading = true;
|
|
SearchRecords = await DataService.OrdersGetFilt(AppMService.Order_Filter);
|
|
ListRecords = SearchRecords.Skip(numRecord * (currPage - 1)).Take(numRecord).ToList();
|
|
isLoading = false;
|
|
}
|
|
|
|
#endregion Private Methods
|
|
|
|
#region Protected Methods
|
|
|
|
protected void Edit(OrderModel selRecord)
|
|
{
|
|
currRecord = selRecord;
|
|
}
|
|
|
|
protected void ForceReload(int newNum)
|
|
{
|
|
numRecord = newNum;
|
|
}
|
|
|
|
protected void ForceReloadPage(int newNum)
|
|
{
|
|
currPage = newNum;
|
|
}
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
AppMService.ShowSearch = false;
|
|
AppMService.PageName = "Ordini";
|
|
AppMService.PageIcon = "fas fa-file-invoice pr-2";
|
|
AppMService.EA_SearchUpdated += OnSeachUpdated;
|
|
await ReloadAllData();
|
|
}
|
|
|
|
protected async Task ReloadAllData()
|
|
{
|
|
PlantsList = await DataService.PlantsGetAll();
|
|
SuppliersList = await DataService.SuppliersGetAll();
|
|
await ReloadData();
|
|
}
|
|
|
|
protected void ResetData()
|
|
{
|
|
DataService.rollBackEdit(currRecord);
|
|
currRecord = null;
|
|
}
|
|
|
|
protected async Task ResetFilter(SelectOrderData newFilter)
|
|
{
|
|
currRecord = null;
|
|
SearchRecords = null;
|
|
ListRecords = null;
|
|
AppMService.Order_Filter = SelectOrderData.Init(5, 7);
|
|
await ReloadAllData();
|
|
}
|
|
|
|
protected void Select(OrderModel selRecord)
|
|
{
|
|
// applico filtro da selezione
|
|
currRecord = selRecord;
|
|
}
|
|
|
|
protected async Task UpdateData()
|
|
{
|
|
currRecord = null;
|
|
await ReloadData();
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Public Methods
|
|
|
|
public string checkSelect(int OrderId)
|
|
{
|
|
string answ = "";
|
|
if (currRecord != null)
|
|
{
|
|
try
|
|
{
|
|
answ = (currRecord.OrderId == OrderId) ? "table-info" : "";
|
|
}
|
|
catch
|
|
{ }
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
AppMService.EA_SearchUpdated -= OnSeachUpdated;
|
|
}
|
|
|
|
public async void OnSeachUpdated()
|
|
{
|
|
await InvokeAsync(() =>
|
|
{
|
|
Task task = UpdateData();
|
|
StateHasChanged();
|
|
});
|
|
}
|
|
|
|
#endregion Public Methods
|
|
}
|
|
} |