Files
GPW/GPW_Admin/WebUserControls/mod_approvaTimbr.ascx.cs
2024-03-25 18:51:00 +01:00

364 lines
12 KiB
C#

using GPW_data;
using SteamWare;
using System;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace GPW_Admin.WebUserControls
{
public partial class mod_approvaTimbr : BaseUserControl
{
#region Public Properties
/// <summary>
/// verifica se l'utente possa approvare la modifica oraria
/// </summary>
public bool userCanApprove
{
get
{
bool answ = false;
try
{
answ = user_std.UtSn.userHasRight("GPW_admin") && chkLicOk;
}
catch
{ }
return answ;
}
}
/// <summary>
/// restituisce info se utente sia admin (vedi web.config x ruolo...)
/// </summary>
public bool userIsAdmin
{
get
{
bool answ = false;
try
{
string adminRole = memLayer.ML.confReadString("adminRole");
answ = user_std.UtSn.userHasRight(adminRole);
}
catch
{ }
return answ;
}
}
#endregion Public Properties
#region Public Methods
/// <summary>
/// calcola cognome-nome da idx
/// </summary>
/// <param name="idxDip"></param>
/// <returns></returns>
public string cognomeNome(object idxDip)
{
string answ = "";
try
{
int IdxDipendente = 0;
if (int.TryParse($"{idxDip}", out IdxDipendente))
{
answ = DataProxy.DP.cognomeNomeByIdx(IdxDipendente);
}
}
catch
{ }
return answ;
}
public void doUpdate()
{
grView.PageSize = utils.pageSize;
grView.DataBind();
}
/// <summary>
/// inverte valore booleano
/// </summary>
/// <param name="isEnt"></param>
/// <returns></returns>
public bool invBool(object valore)
{
bool answ = true;
try
{
answ = !Convert.ToBoolean(valore);
}
catch
{ }
return answ;
}
#endregion Public Methods
#region Protected Properties
/// <summary>
/// idx dipendente loggato
/// </summary>
protected int IdxDipSel
{
get
{
int idx = -1;
try
{
idx = memLayer.ML.IntSessionObj("idxDip_sel");
}
catch
{ }
return idx;
}
set
{
memLayer.ML.setSessionVal("idxDip_sel", value);
}
}
#endregion Protected Properties
#region Protected Methods
/// <summary>
/// Approva + deseleziona le righe selezionate...
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnApproveSelected_Click(object sender, EventArgs e)
{
if (sender != null)
{
// salvo approvazione
DateTime dataOra = DateTime.Today;
int idxDip = 0;
foreach (GridViewRow riga in grView.Rows)
{
if (((CheckBox)riga.FindControl("chkSelect")).Checked)
{
idxDip = 0;
try
{
dataOra = Convert.ToDateTime(((Label)riga.FindControl("lblDataOra")).Text);
idxDip = Convert.ToInt32(((Label)riga.FindControl("lblIdxDip")).Text);
logger.lg.scriviLog(string.Format("Approvazione per dip {0} in data/ora {1}", idxDip, dataOra), tipoLog.INFO);
}
catch (Exception exc)
{
logger.lg.scriviLog($"Eccezione durante recupero dati dip/data-ora in approva timbr{Environment.NewLine}{exc}");
}
if (idxDip > 0)
{
// recupero tab timbr non approvate x dip
DS_Applicazione.TimbratureRow rigaTimb = DataProxy.DP.taTimb.getByDipDataOra(idxDip, dataOra)[0];
// effettua arrotondamento (aggiunge/toglie)
int minOrig = dataOra.Minute;
int secOrig = dataOra.Second;
int minArr = 0;
int step = Convert.ToInt32(txtArrot.Text);
if (rigaTimb.entrata)
{
minArr = Convert.ToInt32(Math.Ceiling(Convert.ToDouble(minOrig / step))) * step;
}
else
{
minArr = Convert.ToInt32(Math.Floor(Convert.ToDouble(minOrig / step))) * step;
}
try
{
// modifico data del record
DataProxy.DP.taTimb.stp_Timbr_modifica(idxDip, dataOra, dataOra.AddMinutes(minArr - minOrig).AddSeconds(-secOrig));
}
catch (Exception exc)
{
logger.lg.scriviLog($"Eccezione durante approva timbr{Environment.NewLine}{exc}");
}
try
{
// approvo con data modificata
DataProxy.DP.taTimb.stp_Timbr_Approva(idxDip, dataOra.AddMinutes(minArr - minOrig).AddSeconds(-secOrig));
((CheckBox)riga.FindControl("chkSelect")).Checked = false;
}
catch (Exception exc)
{
logger.lg.scriviLog($"Eccezione durante approva timbr{Environment.NewLine}{exc}");
}
}
}
}
// update!
grView.SelectedIndex = -1;
checkFixOds();
}
}
/// <summary>
/// seleziona/deseleziona le righe indicate...
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnSelAll_Click(object sender, EventArgs e)
{
if (sender != null)
{
// seleziono tutti i valori visibili nel datagrid
CheckBox chkbox = ((CheckBox)sender);
bool isChecked = chkbox.Checked;
if (!isChecked)
{
chkbox.ToolTip = "Seleziona tutti";
}
else
{
chkbox.ToolTip = "Deseleziona tutti";
}
foreach (GridViewRow riga in grView.Rows)
{
((CheckBox)riga.FindControl("chkSelect")).Checked = isChecked;
}
}
}
protected void chkshowAll_CheckedChanged(object sender, EventArgs e)
{
filtroDip.ods = odsDip;
}
protected void grView_PageIndexChanged(object sender, EventArgs e)
{
// imposto ods
checkFixOds();
}
/// <summary>
/// wrapper x salvare approvazioni
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void grView_SelectedIndexChanged(object sender, EventArgs e)
{
// salvo approvazione
DateTime dataOra = DateTime.Now;
int idxDip = 0;
try
{
dataOra = Convert.ToDateTime(grView.SelectedDataKey["dataOra"].ToString());
idxDip = Convert.ToInt32(grView.SelectedDataKey["idxDipendente"].ToString());
logger.lg.scriviLog(string.Format("Approvazione per dip {0} in data/ora {1}", idxDip, dataOra), tipoLog.INFO);
// recupero tab timbr non approvate x dip
DS_Applicazione.TimbratureRow rigaTimb = DataProxy.DP.taTimb.getByDipDataOra(idxDip, dataOra)[0];
// effettua arrotondamento (aggiunge/toglie)
int minOrig = dataOra.Minute;
int secOrig = dataOra.Second;
int minArr = 0;
int step = Convert.ToInt32(txtArrot.Text);
if (rigaTimb.entrata)
{
minArr = Convert.ToInt32(Math.Ceiling(Convert.ToDouble(minOrig / step))) * step;
}
else
{
minArr = Convert.ToInt32(Math.Floor(Convert.ToDouble(minOrig / step))) * step;
}
try
{
// modifico data del record
DataProxy.DP.taTimb.stp_Timbr_modifica(idxDip, dataOra, dataOra.AddMinutes(minArr - minOrig).AddSeconds(-secOrig));
}
catch (Exception exc)
{
logger.lg.scriviLog($"Eccezione durante stp_Timbr_modifica{Environment.NewLine}{exc}");
}
try
{
// approvo con data modificata
DataProxy.DP.taTimb.stp_Timbr_Approva(idxDip, dataOra.AddMinutes(minArr - minOrig).AddSeconds(-secOrig));
}
catch (Exception exc)
{
logger.lg.scriviLog($"Eccezione durante stp_Timbr_Approva{Environment.NewLine}{exc}");
}
}
catch
{ }
// update!
grView.SelectedIndex = -1;
checkFixOds();
}
/// <summary>
/// post delete resetto filtro...
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void ods_Deleted(object sender, ObjectDataSourceStatusEventArgs e)
{
checkFixOds();
}
/// <summary>
/// post update resetto filtro...
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void ods_Updated(object sender, ObjectDataSourceStatusEventArgs e)
{
checkFixOds();
}
protected void Page_Load(object sender, EventArgs e)
{
grView.PageSize = utils.pageSize;
if (!Page.IsPostBack)
{
filtroDip.ods = odsDip;
filtroDip.reset();
}
filtroDip.eh_selValore += new EventHandler(filtroDip_eh_selValore);
}
#endregion Protected Methods
#region Private Methods
/// <summary>
/// imposto ODS
/// </summary>
private void checkFixOds()
{
if (filtroDip.valoreInt != -1)
{
IdxDipSel = filtroDip.valoreInt;
ods.SelectMethod = "getNonApprByDip";
}
else
{
//memLayer.ML.emptySessionVal("idxDip_sel");
IdxDipSel = -1;
ods.SelectMethod = "getNonAppr";
}
grView.DataBind();
}
/// <summary>
/// seleziono
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void filtroDip_eh_selValore(object sender, EventArgs e)
{
// imposto ods
checkFixOds();
}
#endregion Private Methods
}
}