135 lines
3.4 KiB
C#
135 lines
3.4 KiB
C#
using GPW.CORE.Smart8.Data;
|
|
using Microsoft.AspNetCore.Components;
|
|
|
|
namespace GPW.CORE.Smart8.Components.Compo
|
|
{
|
|
public partial class DtCard : IDisposable
|
|
{
|
|
#region Public Properties
|
|
|
|
[Parameter]
|
|
public bool IsLoading { get; set; } = true;
|
|
|
|
[Parameter]
|
|
public bool IsRicTimb { get; set; } = true;
|
|
|
|
[Parameter]
|
|
public bool NextIsExtrata { get; set; } = true;
|
|
[Parameter]
|
|
public bool isCompactMode { get; set; } = false;
|
|
|
|
#endregion Public Properties
|
|
|
|
#region Public Methods
|
|
|
|
public void Dispose()
|
|
{
|
|
try
|
|
{
|
|
if (uiTimer != null)
|
|
{
|
|
uiTimer.Elapsed -= ElapsedTimerUi;
|
|
uiTimer.Stop();
|
|
uiTimer.Dispose();
|
|
}
|
|
}
|
|
catch
|
|
{ }
|
|
}
|
|
|
|
public void ElapsedTimerUi(object? source, System.Timers.ElapsedEventArgs e)
|
|
{
|
|
var pUpd = Task.Run(async () =>
|
|
{
|
|
if (!IsRicTimb)
|
|
{
|
|
dtCurr = DateTime.Now;
|
|
cssSec = (dtCurr.Second % 2 == 0) ? "text-light" : "text-light opacity-50";
|
|
await Task.Delay(1);
|
|
|
|
await InvokeAsync(() => StateHasChanged());
|
|
}
|
|
});
|
|
pUpd.Wait();
|
|
}
|
|
|
|
public void StartTimerUI()
|
|
{
|
|
// timer che scatta dopo 3sec
|
|
uiTimer = new System.Timers.Timer(1000);
|
|
uiTimer.Elapsed += ElapsedTimerUi;
|
|
uiTimer.Enabled = true;
|
|
uiTimer.AutoReset = true;
|
|
uiTimer.Start();
|
|
}
|
|
|
|
#endregion Public Methods
|
|
|
|
#region Protected Properties
|
|
|
|
protected string cssSec { get; set; } = "text-light";
|
|
|
|
[Inject]
|
|
protected MessageService MService { get; set; } = null!;
|
|
|
|
#endregion Protected Properties
|
|
|
|
#region Protected Methods
|
|
|
|
protected override void OnInitialized()
|
|
{
|
|
base.OnInitialized();
|
|
MService.EA_DateChanged += MService_EA_DateChanged;
|
|
if (!IsRicTimb)
|
|
{
|
|
StartTimerUI();
|
|
}
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Private Fields
|
|
|
|
private DateTime dtCurr = DateTime.Now;
|
|
|
|
private System.Timers.Timer uiTimer = null!;
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Private Properties
|
|
|
|
/// <summary>
|
|
/// Card da collegare al tipo di stato/colore
|
|
/// </summary>
|
|
private string cardCss
|
|
{
|
|
get
|
|
{
|
|
string answ = "defaultCard";
|
|
if (!IsLoading)
|
|
{
|
|
answ = NextIsExtrata ? "cardEntrata" : "cardUscita";
|
|
}
|
|
return answ;
|
|
}
|
|
}
|
|
|
|
private DateTime oraRichiesta
|
|
{
|
|
get => MService.targetDateMancTimb;
|
|
set => MService.targetDateMancTimb = new DateTime(MService.targetDateMancTimb.Year, MService.targetDateMancTimb.Month, MService.targetDateMancTimb.Day, value.Hour, value.Minute, 0);
|
|
}
|
|
|
|
#endregion Private Properties
|
|
|
|
#region Private Methods
|
|
|
|
private async void MService_EA_DateChanged()
|
|
{
|
|
await Task.Delay(1);
|
|
await InvokeAsync(StateHasChanged);
|
|
}
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |