diff --git a/EgwCoreLib.BlazorTest/Pages/TestCompo.razor b/EgwCoreLib.BlazorTest/Pages/TestCompo.razor
new file mode 100644
index 0000000..43145cf
--- /dev/null
+++ b/EgwCoreLib.BlazorTest/Pages/TestCompo.razor
@@ -0,0 +1,30 @@
+@page "/TestCompo"
+@using EgwCoreLib.Utils;
+
+Test
+
+
TestCompo
+
+
+
+ @if (periodo != null)
+ {
+
+ Periodo Selezionato: @($"{periodo.Inizio:yyyy/MM/dd}") → @($"{periodo.Fine:yyyy/MM/dd}")
+
+ }
+
+
+
+
+@code {
+ protected DtUtils.Periodo? periodo { get; set; } = null;
+
+ protected async Task setPeriodo(DtUtils.Periodo newPeriodo)
+ {
+ await Task.Delay(1);
+ periodo = newPeriodo;
+ }
+}
diff --git a/EgwCoreLib.Razor/CalendarMonth.razor.cs b/EgwCoreLib.Razor/CalendarMonth.razor.cs
index a1d6a70..90ee805 100644
--- a/EgwCoreLib.Razor/CalendarMonth.razor.cs
+++ b/EgwCoreLib.Razor/CalendarMonth.razor.cs
@@ -171,18 +171,18 @@ namespace EgwCoreLib.Razor
private bool hasDot(DateTime dtCurr, string type)
{
bool answ = false;
- if(EventList != null)
+ if (EventList != null)
{
- foreach(var item in EventList)
+ foreach (var item in EventList)
{
- if(item.Inizio.Date == dtCurr.Date && item.Type == type)
+ if (item.Inizio.Date == dtCurr.Date && item.Type == type)
{
answ = true;
}
}
}
return answ;
- }
+ }
private async Task clickDay(DateTime dtClick)
{
@@ -213,13 +213,13 @@ namespace EgwCoreLib.Razor
private async Task addMonth()
{
-
+
await FixDate();
await MonthChanged.InvokeAsync(DtRif.AddMonths(1));
}
private async Task subtractMonth()
{
-
+
await FixDate();
await MonthChanged.InvokeAsync(DtRif.AddMonths(-1));
}
@@ -259,11 +259,11 @@ namespace EgwCoreLib.Razor
//await reloadData();
}
- ///
- /// Sistemazione date x disegnare controlli
- ///
- ///
- private async Task FixDate()
+ ///
+ /// Sistemazione date x disegnare controlli
+ ///
+ ///
+ private async Task FixDate()
{
await Task.Delay(1);
// disegno sempre 6 righe = 42 gg
diff --git a/EgwCoreLib.Razor/PeriodoSel.razor b/EgwCoreLib.Razor/PeriodoSel.razor
new file mode 100644
index 0000000..21d22bc
--- /dev/null
+++ b/EgwCoreLib.Razor/PeriodoSel.razor
@@ -0,0 +1,16 @@
+@using EgwCoreLib.Utils;
+
+
+ Periodo
+
+
+
+
+
+
+
diff --git a/EgwCoreLib.Razor/PeriodoSel.razor.cs b/EgwCoreLib.Razor/PeriodoSel.razor.cs
new file mode 100644
index 0000000..c39ee6c
--- /dev/null
+++ b/EgwCoreLib.Razor/PeriodoSel.razor.cs
@@ -0,0 +1,93 @@
+using EgwCoreLib.Utils;
+using Microsoft.AspNetCore.Components;
+
+namespace EgwCoreLib.Razor
+{
+ public partial class PeriodoSel
+ {
+ #region Public Properties
+
+ [Parameter]
+ public EventCallback E_PeriodoSel { get; set; }
+
+ #endregion Public Properties
+
+ #region Protected Properties
+
+ protected DtUtils.Periodo CurrPeriodo
+ {
+ get => currPeriodo;
+ set
+ {
+ if (currPeriodo != value)
+ {
+ currPeriodo = value;
+ E_PeriodoSel.InvokeAsync(CurrPeriodo);
+ }
+ }
+ }
+
+ protected DateTime Fine
+ {
+ get => CurrPeriodo.Fine;
+ set
+ {
+ if (CurrPeriodo.Fine != value)
+ {
+ CurrPeriodo.Fine = value;
+ perSelect = $"{DtUtils.PeriodSet.Select}";
+ E_PeriodoSel.InvokeAsync(CurrPeriodo);
+ }
+ }
+ }
+
+ protected DateTime Inizio
+ {
+ get => CurrPeriodo.Inizio;
+ set
+ {
+ if (CurrPeriodo.Inizio != value)
+ {
+ CurrPeriodo.Inizio = value;
+ perSelect = $"{DtUtils.PeriodSet.Select}";
+ E_PeriodoSel.InvokeAsync(CurrPeriodo);
+ }
+ }
+ }
+
+ protected List periodList { get => Enum.GetNames(typeof(DtUtils.PeriodSet)).ToList(); }
+
+ protected string PerSelect
+ {
+ get => perSelect;
+ set
+ {
+ if (perSelect != value)
+ {
+ perSelect = value;
+ // effettuo preselezione...
+ Enum.TryParse(value, out DtUtils.PeriodSet newPer);
+ CurrPeriodo = new DtUtils.Periodo(newPer);
+ }
+ }
+ }
+
+ #endregion Protected Properties
+
+ #region Protected Methods
+
+ protected override async Task OnInitializedAsync()
+ {
+ await E_PeriodoSel.InvokeAsync(CurrPeriodo);
+ }
+
+ #endregion Protected Methods
+
+ #region Private Properties
+
+ private DtUtils.Periodo currPeriodo { get; set; } = new DtUtils.Periodo();
+ private string perSelect { get; set; } = "Select";
+
+ #endregion Private Properties
+ }
+}
\ No newline at end of file
diff --git a/EgwCoreLib.Utils/DateTimeExtensions.cs b/EgwCoreLib.Utils/DateTimeExtensions.cs
new file mode 100644
index 0000000..6ad4288
--- /dev/null
+++ b/EgwCoreLib.Utils/DateTimeExtensions.cs
@@ -0,0 +1,17 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace EgwCoreLib.Utils
+{
+ public static class DateTimeExtensions
+ {
+ public static DateTime StartOfWeek(this DateTime dt, DayOfWeek startOfWeek)
+ {
+ int diff = (7 + (dt.DayOfWeek - startOfWeek)) % 7;
+ return dt.AddDays(-1 * diff).Date;
+ }
+ }
+}
diff --git a/EgwCoreLib.Utils/DtUtils.cs b/EgwCoreLib.Utils/DtUtils.cs
new file mode 100644
index 0000000..3b8f2c6
--- /dev/null
+++ b/EgwCoreLib.Utils/DtUtils.cs
@@ -0,0 +1,117 @@
+namespace EgwCoreLib.Utils
+{
+ public class DtUtils
+ {
+ #region Public Enums
+
+ public enum PeriodSet
+ {
+ Select = 0,
+ Today,
+ Yesterday,
+ LastMonth,
+ LastTrim,
+ LastWeek,
+ LastYear,
+ ThisMonth,
+ ThisTrim,
+ ThisWeek,
+ ThisYear
+ }
+
+ #endregion Public Enums
+
+ #region Public Classes
+
+ public class Periodo
+ {
+ #region Public Constructors
+
+ public Periodo()
+ { }
+
+ public Periodo(DateTime inizio, DateTime fine)
+ {
+ this.Inizio = inizio;
+ this.Fine = fine;
+ }
+
+ public Periodo(PeriodSet tipo)
+ {
+ int endMonth = 0;
+ DateTime oggi = DateTime.Today;
+ switch (tipo)
+ {
+ case DtUtils.PeriodSet.Today:
+ this.Inizio = oggi;
+ this.Fine = oggi.AddDays(1);
+ break;
+
+ case DtUtils.PeriodSet.Yesterday:
+ this.Inizio = oggi.AddDays(-1);
+ this.Fine = oggi;
+ break;
+
+ case DtUtils.PeriodSet.LastMonth:
+ this.Inizio = new DateTime(oggi.Year, oggi.Month, 1).AddMonths(-1);
+ this.Fine = new DateTime(oggi.Year, oggi.Month, 1);
+ break;
+
+ case DtUtils.PeriodSet.LastTrim:
+ // calcolo trimestre da mese...
+ endMonth = (int)Math.Ceiling((float)oggi.Month / 3) * 3;
+ this.Fine = new DateTime(oggi.Year, endMonth, 1).AddMonths(-2);
+ this.Inizio = this.Fine.AddMonths(-3);
+ break;
+
+ case DtUtils.PeriodSet.LastYear:
+ this.Inizio = new DateTime(oggi.Year-1, 1, 1);
+ this.Fine = new DateTime(oggi.Year , 1, 1);
+ break;
+
+ case DtUtils.PeriodSet.LastWeek:
+ this.Inizio = oggi.StartOfWeek(DayOfWeek.Monday).AddDays(-7);
+ this.Fine = this.Inizio.AddDays(7);
+ break;
+
+ case DtUtils.PeriodSet.ThisMonth:
+ this.Inizio = new DateTime(oggi.Year, oggi.Month, 1);
+ this.Fine = new DateTime(oggi.Year, oggi.Month + 1, 1);
+ break;
+
+ case DtUtils.PeriodSet.ThisTrim:
+ // calcolo trimestre da mese...
+ endMonth = (int)Math.Ceiling((float)oggi.Month / 3) * 3;
+ this.Fine = new DateTime(oggi.Year, endMonth, 1).AddMonths(1);
+ this.Inizio = this.Fine.AddMonths(-3);
+ break;
+
+ case DtUtils.PeriodSet.ThisWeek:
+ this.Inizio = oggi.StartOfWeek(DayOfWeek.Monday);
+ this.Fine = this.Inizio.AddDays(7);
+ break;
+
+ case DtUtils.PeriodSet.ThisYear:
+ this.Inizio = new DateTime(oggi.Year, 1, 1);
+ this.Fine = new DateTime(oggi.Year + 1, 1, 1);
+ break;
+
+ case DtUtils.PeriodSet.Select:
+ default:
+ break;
+ }
+ }
+
+ #endregion Public Constructors
+
+ #region Public Properties
+
+ public DateTime Fine { get; set; } = DateTime.Today.AddDays(+1);
+ public DateTime Inizio { get; set; } = DateTime.Today;
+
+ #endregion Public Properties
+ }
+
+ #endregion Public Classes
+ }
+}
\ No newline at end of file