Files
egwcorelib/EgwCoreLib.BlazorTest/Pages/TestCalendario.razor.cs
T
2024-08-26 10:19:35 +02:00

146 lines
4.5 KiB
C#

using EgwCoreLib.Razor.Data;
namespace EgwCoreLib.BlazorTest.Pages
{
public partial class TestCalendario
{
#region Protected Methods
protected override async Task OnInitializedAsync()
{
dtCurr = DateTime.Today;
await Task.Delay(1);
setupMonthSim();
// preparo calendario settimanale...
setupWeekSim();
}
private void setupMonthSim()
{
DateCheck = new Dictionary<DateTime, string>();
// random colorate...
for (int i = 0; i < 10; i++)
{
DateTime newDate = dtCurr.AddDays(rnd.Next(-5, 10)).Date;
if (!DateCheck.ContainsKey(newDate))
{
DateCheck.Add(newDate, "bg-success text-light rounded-circle p-2");
}
else
{
DateCheck[newDate] = "bg-warning text-light rounded-circle p-2";
}
}
}
/// <summary>
/// Forza ricaricamento week
/// </summary>
protected void ForceReloadWeek()
{
// preparo calendario settimanale...
setupWeekSim();
}
protected void SetDayDetail(DateTime selDate)
{
var tmpDays = new List<DateTime>();
var tmpEv = new List<CalendarEvent>();
tmpDays.Add(selDate);
// genero qualche evento da 0 a 6...
int numEv = rnd.Next(0, 8);
if (numEv > 0)
{
for (int e = 0; e < numEv; e++)
{
double duration = 9 + 8 * rnd.NextDouble();
CalendarEvent newEv = new CalendarEvent()
{
CssClass = "bg-success opacity-25",
Description = $"Permesso #{e}",
Type = "PERM",
Inizio = selDate.AddHours(8),
Fine = selDate.AddHours(duration),
Title = "O.S.",
ToolTip = $"O.S. {selDate.AddHours(8)} - {selDate.AddHours(duration)}"
};
tmpEv.Add(newEv);
}
}
// salvo valori simulati
ListDate = tmpDays;
EventListWeek = tmpEv;
}
protected Random rnd = new Random();
private void setupWeekSim()
{
DateTime oggi = DateTime.Today;
var tmpDays = new List<DateTime>();
var tmpEv = new List<CalendarEvent>();
for (int i = 0; i < 5; i++)
{
tmpDays.Add(oggi.AddDays(i));
// genero qualche evento da 0 a 6...
int numEv = rnd.Next(0, 8);
if (numEv > 0)
{
for (int e = 0; e < numEv; e++)
{
CalendarEvent newEv = new CalendarEvent()
{
CssClass = "bg-success opacity-25",
Description = $"Permesso #{e}",
Type = "PERM",
Inizio = oggi.AddDays(i).AddHours(8),
Fine = oggi.AddDays(i).AddHours(9 + 8 * rnd.NextDouble()),
Title = "O.S.",
ToolTip = $"O.S. {oggi.AddDays(i).AddHours(8)} - {oggi.AddDays(i).AddHours(17)}"
};
tmpEv.Add(newEv);
}
}
}
// salvo valori simulati
ListDate = tmpDays;
EventListWeek = tmpEv;
}
#endregion Protected Methods
#region Private Fields
private Dictionary<DateTime, string> DateCheck = new Dictionary<DateTime, string>();
#endregion Private Fields
#region Private Properties
private DateTime dtCurr { get; set; } = DateTime.Today;
private List<DateTime> ListDate { get; set; } = new List<DateTime>();
private List<CalendarEvent> EventListWeek { get; set; } = new List<CalendarEvent>();
private bool singleWeek = false;
#endregion Private Properties
#region Private Methods
private void DisplayDate(DateTime dtSel)
{
dtCurr = dtSel;
singleWeek = true;
}
private async Task resetCal()
{
singleWeek = false;
await Task.Delay(1);
}
#endregion Private Methods
}
}