Files
GPW/GPW.CORE.UI/Components/TimbrEditor.razor.cs
T

145 lines
4.1 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Components;
using System.Net.Http;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.AspNetCore.Components.Forms;
using Microsoft.AspNetCore.Components.Routing;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.Web.Virtualization;
using Microsoft.JSInterop;
using GPW.CORE.UI;
using GPW.CORE.UI.Shared;
using GPW.CORE.Data.DbModels;
using GPW.CORE.UI.Data;
using System.Net;
namespace GPW.CORE.UI.Components
{
public partial class TimbrEditor
{
protected bool vetoUpd = false;
[Inject]
private IJSRuntime JSRuntime { get; set; }
[Inject]
private MessageService AppMServ { get; set; }
[Parameter]
public List<TimbratureModel> ListTimb { get; set; } = new List<TimbratureModel>();
[Parameter]
public DateTime DataRif { get; set; }
[Parameter]
public EventCallback<bool> CloseReq { get; set; }
[Parameter]
public EventCallback<bool> ItemReset { get; set; }
[Parameter]
public EventCallback<bool> ItemUpdated { get; set; }
[Inject]
protected GpwDataService GDataServ { get; set; }
protected List<TimbratureModel> ListTimbAppr
{
get => ListTimb.Where(x => x.Approv == true).ToList();
}
protected List<TimbratureModel> ListTimbRich
{
get => ListTimb.Where(x => x.Approv == false).ToList();
}
protected bool IsUscita { get; set; } = false;
protected string txtMsgInOut
{
get => IsUscita ? "Uscita" : "Entrata";
}
protected override async Task OnInitializedAsync()
{
DateTime adesso = DateTime.Now;
// prendo primo record timbrature o oggi...
if (ListTimb != null && ListTimb.Count > 0)
{
DataRif = ListTimb.FirstOrDefault().DataOra.Date.AddHours(adesso.Hour).AddMinutes(Math.Ceiling((double)adesso.Minute / 5) * 5);
}
else
{
DataRif = DateTime.Today.AddHours(adesso.Hour).AddMinutes(Math.Ceiling((double)adesso.Minute / 5) * 5);
}
await Task.Delay(1);
}
/// <summary>
/// Indico item selezionato
/// </summary>
protected async void DoReset()
{
await ItemReset.InvokeAsync(true);
}
/// <summary>
/// Aggiorno e riporto update
/// </summary>
protected async void DoUpdate()
{
#if false
// aggiorno
await GDataServ.RegAttUpdate(currRecord);
// resetto clone e record corrente...
AppMServ.clonedRA = null;
#endif
// registro fatto
await ItemUpdated.InvokeAsync(true);
}
[Inject]
private IHttpContextAccessor httpContextAccessor { get; set; }
protected async void AddRequest()
{
//var remoteIp = httpContextAccessor.HttpContext.Connection?.RemoteIpAddress.ToString();
TimbratureModel currRecord = new TimbratureModel()
{
Entrata = !IsUscita,
Approv = false,
CodTipoTimb = "NoTim",
DataOra = DataRif,
IdxDipendente = AppMServ.IdxDipendente,
Ipv4 = ""//$"{remoteIp}"
};
// aggiorno
await GDataServ.TimbratureUpdate(currRecord);
// registro fatto
await ItemUpdated.InvokeAsync(true);
}
/// <summary>
/// Elimino record
/// </summary>
protected async void ReportUpdated()
{
// registro fatto
await ItemUpdated.InvokeAsync(true);
}
/// <summary>
/// Indico item selezionato
/// </summary>
protected async void DoClose()
{
await CloseReq.InvokeAsync(true);
}
}
}