Files
GPW/GPW_Smart/WebUserControls/mod_timbrature.ascx.cs
2024-02-29 15:03:16 +01:00

260 lines
7.8 KiB
C#

using GPW_data;
using GPW_Smart;
using SteamWare;
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace GPW.WebUserControls
{
public partial class mod_timbrature : BaseUserControl
{
#region Protected Properties
protected bool forceButtons
{
get
{
return !abilitaAll;
}
set
{
abilitaAll = !(value);
}
}
protected bool userEnabled
{
get => (DataProxy.currDipIsActive && DataProxy.currDipHasPayloadActive);
}
#endregion Protected Properties
#region Private Methods
private void fixBtnInOut(bool showIn, bool showOut)
{
lbtEntrata.Enabled = showIn;
lbtUscita.Enabled = showOut;
lbtEntrata.CssClass = showIn ? "btn btn-primary w-100" : "btn btn-outline-primary disabled w-100";
lbtUscita.CssClass = showOut ? "btn btn-success w-100" : "btn btn-outline-success disabled w-100";
}
private void fixFont()
{
divTable.Style.Clear();
divTable.Style.Add("font-size", textSize);
}
/// <summary>
/// registro timbratura
/// </summary>
/// <param name="isEntrata"></param>
/// <returns></returns>
private int registraTimbratura(bool isEntrata)
{
// salvo evento entrata...
string IPv4 = "";
bool approvata = false;
if (IdxDipendente > 0)
{
// recupero IP
IPv4 = Request.UserHostName;
// controllo se IP locale = approvata...
if (IPv4.Contains(memLayer.ML.confReadString("localNet")))
{
approvata = true;
}
timbratrice.registraTimbratura(IdxDipendente, DateTime.Now, isEntrata, IPv4, "Web", approvata);
lblWarning.Visible = false;
abilitaAll = false;
// se manca temperatura x il giorno --> rimando a pagina!
DateTime dataRif = DateTime.Today;
var tabRT = DataProxy.DP.taRT.getByKey(IdxDipendente, dataRif);
if (tabRT.Rows.Count == 0)
{
// salvo in sessione...
memLayer.ML.setSessionVal("dataRif", dataRif);
// reinvio
Response.Redirect($"TempRil?dataRif={dataRif:yyyy-MM-dd}");
}
//aggiorno timbrature visualizzate
setButtons();
updateTimbrature();
grView.DataBind();
}
else
{
lblWarning.Text = "IdxDipendente non trovato! timbratura impossibile";
lblWarning.Visible = true;
}
return IdxDipendente;
}
/// <summary>
/// fix buttons button
/// </summary>
private void setButtons()
{
// se utente ok...
if (userEnabled)
{
// controllo SE voglio inibire i buttons...
if (forceButtons)
{
// controllo se il prox comando DOVREBBE essere entrata o uscita
bool nextIsEntrata = true;
// controllo dipendente
if (IdxDipendente > 0)
{
// ricavo ultima timbratura..
nextIsEntrata = timbratrice.nextIsEntrata(IdxDipendente);
// di conseguenza cambio abilitazione ad un buttons
if (nextIsEntrata)
{
fixBtnInOut(true, false);
}
else
{
fixBtnInOut(false, true);
}
}
else
{
fixBtnInOut(false, false);
}
}
else
{
fixBtnInOut(true, true);
}
}
else
{
fixBtnInOut(false, false);
}
}
/// <summary>
/// update elenco ultime timbrature
/// </summary>
private void updateTimbrature()
{
// aggiorno datagrid
}
#endregion Private Methods
#region Protected Methods
protected void grView_RowCreated(object sender, GridViewRowEventArgs e)
{
int maxNum = e.Row.Cells.Count - 2;
for (int i = numColEU * 2 + 1; i < maxNum; i++)
{
e.Row.Cells[i].Visible = false;
}
}
protected void grView_SelectedIndexChanged(object sender, EventArgs e)
{
// rimando ai progetti sulla data indicata...
DateTime dataRif = DateTime.Today;
try
{
dataRif = Convert.ToDateTime(grView.SelectedDataKey["dataLav"]);
}
catch
{ }
// salvo in sessione...
memLayer.ML.setSessionVal("dataRif", dataRif);
// reinvio
Response.Redirect($"Progetti?dataRif={dataRif:yyyy-MM-dd}");
}
protected void lbShowTemp_Click(object sender, EventArgs e)
{
// recupero data di riferimento
try
{
LinkButton lbt = (LinkButton)sender;
string cmdArg = lbt.CommandArgument;
DateTime dataRif = DateTime.Today;
DateTime.TryParse(cmdArg, out dataRif);
// salvo in sessione...
memLayer.ML.setSessionVal("dataRif", dataRif);
// reinvio
Response.Redirect($"TempRil?dataRif={dataRif:yyyy-MM-dd}");
}
catch
{ }
}
/// <summary>
/// timbro entrata...
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void lbtEntrata_Click(object sender, EventArgs e)
{
bool isEntrata = true;
registraTimbratura(isEntrata);
}
/// <summary>
/// uscita...
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void lbtUscita_Click(object sender, EventArgs e)
{
bool isEntrata = false;
registraTimbratura(isEntrata);
}
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
// verifico se ci sia un numero di righe selezionate altrimenti lo imposto...
if (!memLayer.ML.isInSessionObject("numColEU")) numColEU = 2;
if (!memLayer.ML.isInSessionObject("numRowTimb")) numRowTimb = 10;
memLayer.ML.setSessionVal("dataRif", DateTime.Today);
}
setButtons();
fixFont();
}
#endregion Protected Methods
#region Public Methods
/// <summary>
/// Aggiorno visualizzazione
/// </summary>
public void doUpdate()
{
setButtons();
grView.DataBind();
}
/// <summary>
/// inverte valore booleano
/// </summary>
/// <param name="valore"></param>
/// <returns></returns>
public bool invBool(object valore)
{
bool answ = true;
try
{
answ = !Convert.ToBoolean(valore);
}
catch
{ }
return answ;
}
#endregion Public Methods
}
}