100 lines
2.9 KiB
C#
100 lines
2.9 KiB
C#
using GPW.CORE.Comp;
|
|
using Microsoft.AspNetCore.Components;
|
|
|
|
namespace GPW.CORE.Smart.Components
|
|
{
|
|
public partial class TestWeekCal
|
|
{
|
|
#region Public Properties
|
|
|
|
[Parameter]
|
|
public DateTime DtReq { get; set; } = DateTime.Today;
|
|
|
|
[Parameter]
|
|
public int NumDays { get; set; } = 1;
|
|
|
|
#endregion Public Properties
|
|
|
|
#region Protected Fields
|
|
|
|
protected List<DateTime> ListDate = new List<DateTime>();
|
|
|
|
public List<CalendarEvent> simEventList { get; set; } = new List<CalendarEvent>();
|
|
|
|
#endregion Protected Fields
|
|
|
|
#region Protected Methods
|
|
|
|
protected async Task ChangePeriod(int numStep)
|
|
{
|
|
ListDate = new List<DateTime>();
|
|
await Task.Delay(1);
|
|
DtReq = DtReq.AddDays(NumDays * numStep);
|
|
await reloadData();
|
|
await Task.Delay(1);
|
|
}
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
await reloadData();
|
|
}
|
|
|
|
protected override async Task OnParametersSetAsync()
|
|
{
|
|
await reloadData();
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Private Methods
|
|
|
|
protected Random rnd = new Random();
|
|
|
|
private async Task reloadData()
|
|
{
|
|
ListDate = new List<DateTime>();
|
|
int nWeek = DtReq.DayOfWeek - DayOfWeek.Monday;
|
|
if (NumDays < 5 || NumDays > 7)
|
|
{
|
|
nWeek = 0;
|
|
}
|
|
for (int i = 0; i < NumDays; i++)
|
|
{
|
|
ListDate.Add(DtReq.AddDays(i - nWeek));
|
|
}
|
|
|
|
// aggiongo eventi simulati x ogni giorno
|
|
int idxEv = 0;
|
|
simEventList = new List<CalendarEvent>();
|
|
int hStart = 0;
|
|
int minDur = 0;
|
|
DateTime dtInizio = DateTime.MinValue;
|
|
DateTime dtFine = DateTime.MinValue;
|
|
int numEv = 0;
|
|
foreach (var giorno in ListDate)
|
|
{
|
|
// per prima cosa devo decidere quanti eventi...
|
|
numEv = rnd.Next(0, 4);
|
|
for (int i = 0; i < numEv; i++)
|
|
{
|
|
hStart = rnd.Next(8, 14);
|
|
minDur = rnd.Next(6, 36) * 10;
|
|
dtInizio = giorno.AddHours(hStart);
|
|
dtFine = dtInizio.AddMinutes(minDur);
|
|
simEventList.Add(new CalendarEvent()
|
|
{
|
|
id = idxEv++,
|
|
Inizio = dtInizio,
|
|
Fine = dtFine,
|
|
CssClass = "text-light",
|
|
Title = $"Sim EV {idxEv}",
|
|
Description = $"Nuovo evento simulato, {dtInizio:HH:mm} --> {dtFine:HH:mm}"
|
|
});
|
|
}
|
|
}
|
|
await Task.Delay(1);
|
|
}
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |