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 ListDate = new List(); public List simEventList { get; set; } = new List(); #endregion Protected Fields #region Protected Methods protected async Task ChangePeriod(int numStep) { ListDate = new List(); 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(); 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(); 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++, CssClass = "text-light", Inizio = dtInizio, Fine = dtFine, Title = $"Sim EV {idxEv}", Description = $"Nuovo evento simulato, {dtInizio:HH:mm} --> {dtFine:HH:mm}" }); } } await Task.Delay(1); } #endregion Private Methods } }