Merge branch 'release/AddPeriodSelector01'

This commit is contained in:
Samuele Locatelli
2023-06-28 14:53:10 +02:00
6 changed files with 284 additions and 11 deletions
@@ -0,0 +1,30 @@
@page "/TestCompo"
@using EgwCoreLib.Utils;
<PageTitle>Test</PageTitle>
<h3>TestCompo</h3>
<div class="row">
<div class="col-6">
@if (periodo != null)
{
<div>
Periodo Selezionato: <b>@($"{periodo.Inizio:yyyy/MM/dd}") &rarr; @($"{periodo.Fine:yyyy/MM/dd}")</b>
</div>
}
</div>
<div class="col-6">
<PeriodoSel E_PeriodoSel="setPeriodo"></PeriodoSel>
</div>
</div>
@code {
protected DtUtils.Periodo? periodo { get; set; } = null;
protected async Task setPeriodo(DtUtils.Periodo newPeriodo)
{
await Task.Delay(1);
periodo = newPeriodo;
}
}
+11 -11
View File
@@ -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();
}
/// <summary>
/// Sistemazione date x disegnare controlli
/// </summary>
/// <returns></returns>
private async Task FixDate()
/// <summary>
/// Sistemazione date x disegnare controlli
/// </summary>
/// <returns></returns>
private async Task FixDate()
{
await Task.Delay(1);
// disegno sempre 6 righe = 42 gg
+16
View File
@@ -0,0 +1,16 @@
@using EgwCoreLib.Utils;
<div class="input-group">
<span class="input-group-text">Periodo</span>
<input type="date" class="form-control" @bind-value="@Inizio">
<input type="date" class="form-control" @bind-value="@Fine">
<select @bind="@PerSelect" class="form-select form-select-sm">
@foreach (var item in periodList)
{
<option value="@item">@item</option>
}
</select>
<span class="input-group-text"><i class="far fa-calendar-alt"></i></span>
</div>
+93
View File
@@ -0,0 +1,93 @@
using EgwCoreLib.Utils;
using Microsoft.AspNetCore.Components;
namespace EgwCoreLib.Razor
{
public partial class PeriodoSel
{
#region Public Properties
[Parameter]
public EventCallback<DtUtils.Periodo> 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<string> 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
}
}
+17
View File
@@ -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;
}
}
}
+117
View File
@@ -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
}
}