Files
GPW/GPW_Admin/WebUserControls/mod_reviewTimbrature.ascx.cs
2024-04-15 12:18:41 +02:00

565 lines
18 KiB
C#

using GPW_data;
using SteamWare;
using System;
using System.Drawing;
using System.Globalization;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace GPW_Admin.WebUserControls
{
public partial class mod_reviewTimbrature : BaseUserControl
{
#region Protected Properties
/// <summary>
/// valore selezionato x dettaglio giornaliero utente
/// </summary>
protected DateTime dataRif
{
get
{
DateTime answ = DateTime.Now;
try
{
answ = Convert.ToDateTime(memLayer.ML.objSessionObj("dataRif"));
}
catch
{ }
return answ;
}
set
{
memLayer.ML.setSessionVal("dataRif", value);
}
}
/// <summary>
/// idx dipendente loggato
/// </summary>
protected int IdxDipendente
{
get
{
int idx = 0;
try
{
idx = memLayer.ML.IntSessionObj("IdxDipendente");
}
catch
{ }
return idx;
}
}
#endregion Protected Properties
#region Public Properties
/// <summary>
/// determina se si debba mostrare cognome nome (altrimenti IDX anonimo)
/// </summary>
public bool showCognomeNome
{
get
{
return memLayer.ML.confReadBool("reviewShowCN");
}
}
/// <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;
}
}
#endregion Public Properties
#region Private Methods
/// <summary>
/// imposto ODS
/// </summary>
private void checkFixOds()
{
memLayer.ML.setSessionVal("idxDip_sel", filtroDip.valoreInt);
grViewExpl.DataBind();
mod_elencoTimbr1.doUpdate();
}
/// <summary>
/// seleziono
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void filtroDip_eh_selValore(object sender, EventArgs e)
{
// imposto ods
grViewExpl.SelectedIndex = -1;
setDetailVisib(false);
checkFixOds();
}
private void mod_elencoTimbr1_eh_nuovoValore(object sender, EventArgs e)
{
checkFixOds();
}
/// <summary>
/// set visibilità grView dettagli
/// </summary>
/// <param name="value"></param>
private void setDetailVisib(bool value)
{
pnlDettagli.Visible = value;
//mod_elencoTimbr1.Visible = value;
grViewGiust.Visible = value;
}
/// <summary>
/// aggiorna i 3 datagrid
/// </summary>
private void updateVisual()
{
// aggiorno visualizzazioni
grViewExpl.DataBind();
mod_elencoTimbr1.doUpdate();
grViewGiust.DataBind();
}
#endregion Private Methods
#region Protected Methods
/// <summary>
/// inserisce un giust nuovo x dipendente/data
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btNewGiust_Click(object sender, EventArgs e)
{
int idxDip = memLayer.ML.IntSessionObj("idxDip_det");
// calcola ed inserisce giustificativi
DataProxy.DP.taGiust.giustInsByDate(idxDip, dataRif, "PERM");
updateVisual();
}
/// <summary>
/// gestione evento richiesta nuovo valore (mostra footer, ...)
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnNew_Click(object sender, EventArgs e)
{
// reset selezione...
resetSelezioneGiust();
int idxDip = memLayer.ML.IntSessionObj("idxDip_det");
// calcola ed inserisce giustificativi
DataProxy.DP.taGiust.giustInsByDate(idxDip, dataRif, "PERM");
updateVisual();
}
/// <summary>
/// reset della selezione
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnReset_Click(object sender, EventArgs e)
{
resetSelezione();
}
/// <summary>
/// reset della selezione
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnResetGiust_Click(object sender, EventArgs e)
{
resetSelezioneGiust();
}
/// <summary>
/// ricalcola giornate periodo visualizzato per i dipendenti selezionati
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnRicalcPeriodo_Click(object sender, EventArgs e)
{
// eseguo la stored di update dato condizione di filtro x periodo e dipendente...
DataProxy.DP.taTimbExpl.stp_ricalcolaTimbExpl_byPeriodoUser(memLayer.ML.IntSessionObj("idxDip_sel"), Convert.ToDateTime(memLayer.ML.objSessionObj("_inizio")), Convert.ToDateTime(memLayer.ML.objSessionObj("_fine")));
// verifico dip con giust da inserire...
var list2fix = DataProxy.DP.taTimbExpl.getByDipAnomalia(memLayer.ML.IntSessionObj("idxDip_sel"), Convert.ToDateTime(memLayer.ML.objSessionObj("_inizio")), Convert.ToDateTime(memLayer.ML.objSessionObj("_fine")), false, false, true);
if (list2fix != null && list2fix.Count > 0)
{
foreach (var item in list2fix)
{
// escludo date da oggi in poi...
if (item.dataLav < DateTime.Today)
{
// elimino eventuali vecchi permessi
DataProxy.DP.taGiust.DeleteQuery(item.dataLav, item.idxDipendente, "PERM");
// inserisco permessi...
DataProxy.DP.taGiust.giustInsByDate(item.idxDipendente, item.dataLav, "PERM");
}
}
// ricalcolo!
DataProxy.DP.taTimbExpl.stp_ricalcolaTimbExpl_byPeriodoUser(memLayer.ML.IntSessionObj("idxDip_sel"), Convert.ToDateTime(memLayer.ML.objSessionObj("_inizio")), Convert.ToDateTime(memLayer.ML.objSessionObj("_fine")));
}
DataProxy.DP.taRA.stp_ricalcolaRegAttivitaExpl_byPeriodoUser(memLayer.ML.IntSessionObj("idxDip_sel"), Convert.ToDateTime(memLayer.ML.objSessionObj("_inizio")), Convert.ToDateTime(memLayer.ML.objSessionObj("_fine")));
// aggiorno
checkFixOds();
}
protected void chkshowAll_CheckedChanged(object sender, EventArgs e)
{
filtroDip.ods = odsDip;
grViewExpl.DataBind();
}
/// <summary>
/// cambia stato visibilità week-end...
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void chkWE_CheckedChanged(object sender, EventArgs e)
{
// imposto ods
checkFixOds();
}
/// <summary>
/// evento cancellazione riga
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void grView_RowDeleted(object sender, GridViewDeletedEventArgs e)
{
grViewExpl.DataBind();
}
/// <summary>
/// evento update righe
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void grView_RowUpdated(object sender, GridViewUpdatedEventArgs e)
{
grViewExpl.DataBind();
}
/// <summary>
/// mostro visualizzazione dati di dettaglio!
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void grViewExpl_SelectedIndexChanged(object sender, EventArgs e)
{
dataRif = Convert.ToDateTime(grViewExpl.SelectedDataKey["dataLav"]).Date;
setDetailVisib(true);
// mostra timbrature
memLayer.ML.setSessionVal("inizioDet", dataRif);
memLayer.ML.setSessionVal("fineDet", dataRif.AddDays(1));
memLayer.ML.setSessionVal("idxDip_det", grViewExpl.SelectedDataKey["idxDipendente"]);
mod_elencoTimbr1.doUpdate();
// mostra commesse
memLayer.ML.setSessionVal("idxDipendente", grViewExpl.SelectedDataKey["idxDipendente"]);
CultureInfo ita = new CultureInfo("it-IT");
mod_commAttivitaDesk1.idxDipCurr = Convert.ToInt32(grViewExpl.SelectedDataKey["idxDipendente"]);
mod_commAttivitaDesk1.valoreDateTime = Convert.ToDateTime(dataRif, ita);
mod_commAttivitaDesk1.doUpdate();
grViewExpl.DataBind();
}
/// <summary>
/// annulla inserimento nuovo valore da footer
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void lblCanc_click(object sender, EventArgs e)
{
// annullo inserimento: nascondo footer, bind controlli...
grViewGiust.FooterRow.Visible = false;
}
/// <summary>
/// inserisce nuovo valore da footer
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void lblIns_click(object sender, EventArgs e)
{
// click su inserimento, chiamo il metodo insert dell'ObjectDataSource
odsGiust.Insert();
}
/// <summary>
/// aggiornamento x delete
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void odsGiust_Deleted(object sender, ObjectDataSourceStatusEventArgs e)
{
updateVisual();
}
protected void odsGiust_Inserting(object sender, ObjectDataSourceMethodEventArgs e)
{
}
/// <summary>
/// aggiornamento x update
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void odsGiust_Updated(object sender, ObjectDataSourceStatusEventArgs e)
{
updateVisual();
}
/// <summary>
/// caricamento pagina
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load(object sender, EventArgs e)
{
grViewExpl.PageSize = utils.pageSize;
if (!Page.IsPostBack)
{
// imposto intervallo date...1 mese...
intervalloDate date = new intervalloDate();
date.fine = DateTime.Now.Date.AddDays(1);
date.inizio = date.fine.AddMonths(-1);
cmp_periodoAnalisi.intervalloAnalisi = date;
// altri fix
filtroDip.ods = odsDip;
memLayer.ML.emptySessionVal("idxDip_sel");
memLayer.ML.setSessionVal("maxErrMin", memLayer.ML.confReadInt("maxErrMin"));
memLayer.ML.setSessionVal("maxErrPlus", memLayer.ML.confReadInt("maxErrPlus"));
filtroDip.reselFirst();
setDetailVisib(false);
// determino visibilità link export...
hlExport.Visible = memLayer.ML.cdvb("ExportORE_SPS");
hlExportComm.Visible = memLayer.ML.cdvb("ExportCommesse");
}
filtroDip.eh_selValore += new EventHandler(filtroDip_eh_selValore);
mod_elencoTimbr1.eh_nuovoValore += new EventHandler(mod_elencoTimbr1_eh_nuovoValore);
hlExport.Visible = chkLicOk;
hlExportComm.Visible = chkLicOk;
}
#endregion Protected Methods
#region Public Methods
/// <summary>
///
/// </summary>
/// <param name="minutiNonLav"></param>
/// <returns></returns>
public string classByNL(object minutiNonLav)
{
string answ = "";
try
{
if (Convert.ToDouble(minutiNonLav) > 0)
{
answ = "lblWarning";
}
}
catch
{ }
return answ;
}
/// <summary>
/// calcola cognome-nome da idx
/// </summary>
/// <param name="idxDip"></param>
/// <returns></returns>
public string cognomeNome(object idxDip)
{
string answ = "";
int IdxDipendente = 0;
if (int.TryParse($"{idxDip}", out IdxDipendente))
{
answ = DataProxy.DP.cognomeNomeByIdx(IdxDipendente);
}
return answ;
}
/// <summary>
/// restituisce il colore data valore ok commessa
/// </summary>
/// <param name="okLavCom"></param>
/// <returns></returns>
public Color coloreComm(object okLavCom)
{
Color answ = Color.Orange;
try
{
if (toBool(okLavCom))
{
answ = Color.Black;
}
}
catch
{ }
return answ;
}
/// <summary>
/// restituisce il colore dato minMpp (se > 0 è verde, altrimenti marrone)
/// </summary>
/// <param name="okLavCom"></param>
/// <returns></returns>
public Color coloreMPP(object minMpp)
{
Color answ = Color.FromName("#995511");
if (minMpp != null)
{
try
{
if (minMpp.ToString() != "0")
{
answ = Color.FromName("#66AA22");
}
}
catch
{ }
}
return answ;
}
public void doUpdate()
{
grViewExpl.PageSize = utils.pageSize;
grViewExpl.DataBind();
}
/// <summary>
/// formatta la durata in ore secondo web.config (centesimale/ore:min)
/// </summary>
/// <param name="oreCent"></param>
/// <returns></returns>
public string formatDurata(object oreCent)
{
decimal ore = 0;
try
{
ore = Convert.ToDecimal(oreCent);
}
catch
{ }
string answ = "";
if (memLayer.ML.confReadBool("reviewShowOreMin"))
{
//answ = string.Format("{0}:{1:00}", Math.Floor(ore), Math.Round((ore - Math.Floor(ore)) * 60));
answ = utils.formOreMin(ore);
}
else
{
answ = ore.ToString("0.00");
}
return answ;
}
/// <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;
}
/// <summary>
/// calcola se sia visibile con criterio GREATER THAN ZERO
/// </summary>
/// <param name="valore"></param>
/// <returns></returns>
public bool isGTZ(object valore)
{
bool answ = false;
try
{
if (Convert.ToDouble(valore) > 0)
{
answ = true;
}
}
catch
{ }
return answ;
}
/// <summary>
/// resetta la selezione dei valori in caso di modifiche su altri controlli
/// </summary>
public void resetSelezione()
{
grViewExpl.SelectedIndex = -1;
grViewExpl.DataBind();
setDetailVisib(false);
}
/// <summary>
/// resetta la selezione dei valori in caso di modifiche su altri controlli
/// </summary>
public void resetSelezioneGiust()
{
grViewGiust.SelectedIndex = -1;
grViewGiust.DataBind();
}
/// <summary>
/// prepara tooltip permessi/straordinarie
/// </summary>
/// <param name="minStra"></param>
/// <param name="minPerm"></param>
/// <param name="minPP"></param>
/// <returns></returns>
public string tooltipPermStra(object minStra, object minPerm, object minMpp)
{
string answ = "";
try
{
answ = string.Format("Straordinarie: {0:0.##} min, Permessi: {1:0.##} min", minStra, minPerm);
if (Convert.ToInt32(minMpp) > 0)
{
answ += string.Format(", Pranzo: {0:0.##} min", minMpp);
}
}
catch
{ }
return answ;
}
#endregion Public Methods
}
}