Files
GPW/GPW.CORE.UI/Pages/Planner.razor.cs
T

376 lines
9.6 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Components;
using System.Net.Http;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.AspNetCore.Components.Forms;
using Microsoft.AspNetCore.Components.Routing;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.Web.Virtualization;
using Microsoft.JSInterop;
using GPW.CORE.UI;
using GPW.CORE.UI.Shared;
using GPW.CORE.UI.Data;
using GPW.CORE.Data;
using GPW.CORE.Data.DbModels;
using GPW.CORE.Data.DTO;
namespace GPW.CORE.UI.Pages
{
//[Authorize(Roles = "SuperAdmin, Admin")]
public partial class Planner
{
private int _endHour = 21;
private int _startHour = 7;
private RegAttivitaModel currRecord;
private List<WeekStatDTO> weekStatList = new List<WeekStatDTO>();
private List<DailyDataDTO> ListRecords=new List<DailyDataDTO>();
private List<AnagFasiModel> ListFasi = new List<AnagFasiModel>();
#if false
private WeekPlanModel currRecord = null;
private List<PlantDTO> PlantsList;
private List<SupplierModel> SuppliersList;
private List<TransporterModel> TransportersList;
#endif
private int _currPage { get; set; } = 1;
private int _numRecord { get; set; } = 10;
#if false
private UserLevel _selLevel { get; set; } = UserLevel.ND;
#endif
private int _selPlantId { get; set; } = 0;
private int _selSuppId { get; set; } = 0;
private int _selTraspId { get; set; } = 0;
private int currPage
{
get => _currPage;
set
{
if (_currPage != value)
{
_currPage = value;
var pUpd = Task.Run(async () => await ReloadData());
pUpd.Wait();
}
}
}
private int endHour
{
get => _endHour;
set
{
// fix --> max 24...
_endHour = _endHour > 24 ? 24 : _endHour;
if (_endHour != value)
{
_endHour = 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();
}
}
}
#if false
private UserLevel SelLevel
{
get => _selLevel;
set
{
if (_selLevel != value)
{
_selLevel = value;
var pUpd = Task.Run(async () => await ReloadData());
pUpd.Wait();
}
}
}
#endif
private int SelPlantId
{
get => _selPlantId;
set
{
if (_selPlantId != value)
{
_selPlantId = value;
var pUpd = Task.Run(async () => await ReloadData());
pUpd.Wait();
}
}
}
private int SelSupplierId
{
get => _selSuppId;
set
{
if (_selSuppId != value)
{
_selSuppId = value;
checkHourRange();
}
}
}
private int SelTransporterId
{
get => _selTraspId;
set
{
if (_selTraspId != value)
{
_selTraspId = value;
checkHourRange();
}
}
}
private int startHour
{
get => _startHour;
set
{
// fix --> MIN 0...
_startHour = _startHour < 0 ? 0 : _startHour;
if (_startHour != value)
{
_startHour = value;
var pUpd = Task.Run(async () => await ReloadData());
pUpd.Wait();
}
}
}
#if false
[Inject]
protected MessageService AppMService { get; set; }
#endif
[Inject]
protected GpwDataService DataService { get; set; }
[Inject]
protected IJSRuntime JSRuntime { get; set; }
[Inject]
protected NavigationManager NavManager { get; set; }
protected int totalCount
{
get
{
int answ = 0;
if (ListRecords != null)
{
answ = ListRecords.Count;
}
return answ;
}
}
protected WeekData currWeekSel
{
get
{
int anno = DateTime.Today.Year;
return new WeekData(anno, currWeekNum);
}
}
protected int currWeekNum { get; set; } = 0;
protected async Task setWeekNumber(int newNum)
{
currWeekNum = newNum;
await ReloadData();
}
private void checkHourRange()
{
int minHour = 7;
int maxHour = 21;
#if false
if (ListRecords != null)
{
var minRecord = ListRecords.OrderBy(x => x.DeliveryHour).FirstOrDefault();
if (minRecord != null)
{
minHour = ListRecords.OrderBy(x => x.DeliveryHour).FirstOrDefault().DeliveryHour;
_startHour = _startHour < minHour ? _startHour : minHour;
}
var maxRecord = ListRecords.OrderByDescending(x => x.DeliveryHour).FirstOrDefault();
if (maxRecord != null)
{
maxHour = ListRecords.OrderByDescending(x => x.DeliveryHour).FirstOrDefault().DeliveryHour;
_endHour = _endHour > maxHour ? _endHour : maxHour;
}
}
#endif
}
/// <summary>
/// Dipendente corrente
/// !!! FARE FixMe ToDo da gestire correttamente!!!
/// </summary>
protected int IdxDipendente { get; set; } = 1;
private async Task InitData()
{
isLoading = true;
weekStatList = await DataService.LastWeeks(IdxDipendente, DateTime.Today, 4);
currWeekNum = weekStatList.Last().WeekNumber;
isLoading = false;
}
private async Task ReloadData()
{
isLoading = true;
ListRecords = await DataService.DailyDetails(1, currWeekSel.inizio, currWeekSel.fine);
//ListFasi = await DataService.AnagFasiAll();
#if false
ListRecords = await DataService.WeekPlanGet();
#endif
// calcolo min/max...
checkHourRange();
isLoading = false;
}
protected void CreateNew()
{
#if false
// creo nuovo record
WeekPlanModel newRecord = new WeekPlanModel()
{
DayNum = DayOfWeek.Sunday,
DeliveryHour = 14,
Note = "18K"
};
currRecord = newRecord;
#endif
}
#if false
protected void Edit(WeekPlanModel selRecord)
{
currRecord = selRecord;
}
protected void EditRecord(int WeekPlanId)
{
currRecord = null;
var findRecord = ListRecords
.Where(x => x.WeekPlanId == WeekPlanId)
.FirstOrDefault();
currRecord = findRecord;
}
#endif
protected override async Task OnInitializedAsync()
{
#if false
AppMService.ShowSearch = false;
AppMService.PageName = "Planner Consegne";
AppMService.PageIcon = "fas fa-calendar pr-2";
#endif
await InitData();
await ReloadAllData();
}
protected async Task ReloadAllData()
{
#if false
PlantsList = await DataService.PlantsGetAll();
SuppliersList = await DataService.SuppliersGetAll();
TransportersList = await DataService.TransportersGetAll();
#endif
await ReloadData();
}
protected async Task ResetData()
{
currRecord = null;
#if false
DataService.rollBackEdit(currRecord);
currRecord = null;
#endif
await InitData();
await ReloadData();
}
#if false
protected void Select(WeekPlanModel selRecord)
{
// applico filtro da selezione
currRecord = selRecord;
}
#endif
#if false
protected List<WeekPlanModel> SlotList(DayOfWeek Giorno, int Ora)
{
List<WeekPlanModel> result = new List<WeekPlanModel>();
if (ListRecords != null && ListRecords.Count > 0)
{
result = ListRecords
.Where(x => x.DayNum == Giorno && x.DeliveryHour == Ora)
.ToList();
}
return result;
}
#endif
protected async Task UpdateData()
{
#if false
currRecord = null;
#endif
await ReloadData();
}
/// <summary>
/// Indico item selezionato
/// </summary>
protected async void ReportSelect(RegAttivitaModel selRecord)
{
// recupero attività selezionata in curr record
currRecord = selRecord;
}
}
}