384 lines
20 KiB
C#
384 lines
20 KiB
C#
using Newtonsoft.Json;
|
|
using SteamWare;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
|
|
namespace GPW_data
|
|
{
|
|
public class utils
|
|
{
|
|
#region Public Fields
|
|
|
|
/// <summary>
|
|
/// singleton accesso metodo
|
|
/// </summary>
|
|
public static utils mng = new utils();
|
|
|
|
#endregion Public Fields
|
|
|
|
#region Protected Constructors
|
|
|
|
/// <summary>
|
|
/// avvio oggetti utils
|
|
/// </summary>
|
|
protected utils()
|
|
{
|
|
}
|
|
|
|
#endregion Protected Constructors
|
|
|
|
#region Public Properties
|
|
|
|
/// <summary>
|
|
/// dim pagina gridView in sessione
|
|
/// </summary>
|
|
public static int pageSize
|
|
{
|
|
get
|
|
{
|
|
int answ = 20;
|
|
try
|
|
{
|
|
answ = SteamWare.memLayer.ML.IntSessionObj("pageSize");
|
|
if (answ <= 0) answ = 20;
|
|
}
|
|
catch
|
|
{ }
|
|
return answ;
|
|
}
|
|
set
|
|
{
|
|
SteamWare.memLayer.ML.setSessionVal("pageSize", value);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// oggetto elenco clienti organizzato come dizionario con chiave idxCliente e valore la ragione sociale
|
|
/// </summary>
|
|
public Dictionary<string, string> elencoClienti
|
|
{
|
|
set
|
|
{
|
|
string redKey = memLayer.ML.redHash("elencoClienti");
|
|
string rawData = JsonConvert.SerializeObject(value);
|
|
memLayer.ML.setRSV(redKey, rawData, 60);
|
|
}
|
|
get
|
|
{
|
|
Dictionary<string, string> answ = new Dictionary<string, string>();
|
|
string redKey = memLayer.ML.redHash("elencoClienti");
|
|
string rawData = memLayer.ML.getRSV(redKey);
|
|
if (!string.IsNullOrEmpty(rawData))
|
|
{
|
|
try
|
|
{
|
|
answ = JsonConvert.DeserializeObject<Dictionary<string, string>>(rawData);
|
|
}
|
|
catch
|
|
{ }
|
|
}
|
|
if (answ.Count == 0)
|
|
{
|
|
answ = ricaricaElencoClienti();
|
|
elencoClienti = answ;
|
|
}
|
|
return answ;
|
|
}
|
|
}
|
|
|
|
#endregion Public Properties
|
|
|
|
#region Protected Methods
|
|
|
|
/// <summary>
|
|
/// restituisce elenco clienti trasformato in dictionary
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
protected Dictionary<string, string> ricaricaElencoClienti()
|
|
{
|
|
Dictionary<string, string> answ = new Dictionary<string, string>();
|
|
// recupero elenco clienti da dataproxy
|
|
foreach (DS_Applicazione.AnagClientiRow riga in DataProxy.DP.taAnCli.GetData())
|
|
{
|
|
answ.Add(riga.idxCliente.ToString(), riga.RagSociale);
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Public Methods
|
|
|
|
/// <summary>
|
|
/// formatta le ore in ore:minuti
|
|
/// </summary>
|
|
/// <param name="oreCent">ore centesimali (0,00)</param>
|
|
/// <returns></returns>
|
|
public static string formOreMin(decimal oreCent)
|
|
{
|
|
return string.Format("{0}:{1:00}", Math.Floor(oreCent), Math.Round((oreCent - Math.Floor(oreCent)) * 60));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Effettua un insieme di controlli sulle anomalie delel timbrature/orari e invia le relative eventuali email
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public bool checkAnomalie()
|
|
{
|
|
bool answ = false;
|
|
try
|
|
{
|
|
// log richiesta!
|
|
logger.lg.scriviLog("Richiesto controllo anomalie!", tipoLog.INFO);
|
|
/*******************************************************
|
|
* controllo le varie anomalie delle timbrature:
|
|
*
|
|
* (A) mancate approvazioni --> admin
|
|
* (B) entrate <> uscite --> admin, user
|
|
* (C) mancata copertura orario --> admin
|
|
*
|
|
* (D) mancata copertura commesse (2 be done)
|
|
*
|
|
* recupero elenco dip interessati x le varie anomalie con stp_DipendentiAndAnomalie
|
|
* e poi da timbrExpl recupero le singole istanze di record errori
|
|
*
|
|
*******************************************************/
|
|
|
|
// setup valori base
|
|
string fromEmail = memLayer.ML.confReadString("_fromEmail");
|
|
string adminEmail = memLayer.ML.confReadString("adminAnomalieEmail");
|
|
string adminContinuatoEmail = memLayer.ML.confReadString("adminContinuatoEmail");
|
|
string adminOreLavEmail = memLayer.ML.confReadString("adminOreLavEmail");
|
|
string oggettoEmail = "";
|
|
string corpoEmail = "";
|
|
DS_Applicazione.stp_DipendentiAndAnomalieDataTable tabDipAndAnom = new DS_Applicazione.stp_DipendentiAndAnomalieDataTable();
|
|
DS_Applicazione.TimbratureExplDataTable tabTimbExpl = new DS_Applicazione.TimbratureExplDataTable();
|
|
DS_Applicazione.TE_RA_ExplDataTable tabTimbRegAtt = new DS_Applicazione.TE_RA_ExplDataTable();
|
|
DateTime oggi = DateTime.Today;
|
|
int gg2Chk = memLayer.ML.confReadInt("gg2Chk");
|
|
int gg2ChkCont = memLayer.ML.confReadInt("gg2ChkCont");
|
|
int gg2ChkOreCaricate = memLayer.ML.confReadInt("gg2ChkOreCaricate");
|
|
|
|
// (A) recupero mancate approvazioni, mando solo ad admin
|
|
if (memLayer.ML.confReadBool("checkAnomAppr"))
|
|
{
|
|
tabTimbExpl = DataProxy.DP.taTimbExpl.getByDipAnomalia(0, oggi.AddDays(-gg2Chk), oggi, true, false, false);
|
|
// se ho trovato record...
|
|
if (tabTimbExpl.Rows.Count > 0)
|
|
{
|
|
logger.lg.scriviLog("Trovate anomalie mancate approvazioni, invio email ad admin", tipoLog.INFO);
|
|
oggettoEmail = "Anomalie GPW: Approvazione Timbrature";
|
|
if (memLayer.ML.confReadBool("includeDirectUrl"))
|
|
{
|
|
corpoEmail = string.Format("Risultano a sistema le seguenti anomalie:<br/><a href=\"{0}A1/approvTimbrature.aspx\">timbrature da approvare</a><br/><br/>", memLayer.ML.confReadString("baseUrl"));
|
|
}
|
|
else
|
|
{
|
|
corpoEmail = "Risultano a sistema le seguenti anomalie: timbrature da approvare<br/>";
|
|
}
|
|
corpoEmail += string.Format("{0}<br/>", SteamwareStrings.charLine('-', 80));
|
|
corpoEmail += "| -- DATA --\t| Dipendente<br/>";
|
|
corpoEmail += string.Format("{0}<br/>", SteamwareStrings.charLine('-', 80));
|
|
foreach (DS_Applicazione.TimbratureExplRow riga in tabTimbExpl)
|
|
{
|
|
corpoEmail += string.Format("| {0:yyyy.MM.dd ddd}\t| {1}<br/>", riga.dataLav, riga.CognomeNome);
|
|
}
|
|
corpoEmail += SteamwareStrings.charLine('-', 80);
|
|
gestEmail.geAuth.mandaEmail(fromEmail, adminEmail, oggettoEmail, corpoEmail);
|
|
}
|
|
}
|
|
|
|
// (B) recupero errori entrate/uscite, mando ad admin + utenti
|
|
if (memLayer.ML.confReadBool("checkAnomTimb"))
|
|
{
|
|
tabDipAndAnom = DataProxy.DP.taDipAnom.GetData(oggi.AddDays(-gg2Chk), oggi.AddHours(1), false, true, false);
|
|
tabTimbExpl = DataProxy.DP.taTimbExpl.getByDipAnomalia(0, oggi.AddDays(-gg2Chk), oggi.AddHours(1), false, true, false);
|
|
// se ho trovato record...
|
|
if (tabTimbExpl.Rows.Count > 0)
|
|
{
|
|
logger.lg.scriviLog("Trovate anomalie timbrature IN/OUT non corrispondenti, invio email!", tipoLog.INFO);
|
|
// mando email ad admin!
|
|
oggettoEmail = "Anomalie GPW: Timbrature mancanti";
|
|
if (memLayer.ML.confReadBool("includeDirectUrl"))
|
|
{
|
|
corpoEmail = string.Format("Risultano a sistema le seguenti anomalie:<br/><a href=\"{0}A1/reviewTimbrature.aspx\">timbrature mancanti / non corrispondenti</a><br/><br/>", memLayer.ML.confReadString("baseUrl"));
|
|
}
|
|
else
|
|
{
|
|
corpoEmail = "Risultano a sistema le seguenti anomalie: timbrature mancanti<br/>";
|
|
}
|
|
corpoEmail += string.Format("{0}<br/>", SteamwareStrings.charLine('-', 80));
|
|
corpoEmail += "| -- DATA --\t| Dipendente<br/>";
|
|
corpoEmail += string.Format("{0}<br/>", SteamwareStrings.charLine('-', 80));
|
|
foreach (DS_Applicazione.TimbratureExplRow riga in tabTimbExpl)
|
|
{
|
|
corpoEmail += string.Format("| {0:yyyy.MM.dd ddd}\t| {1}<br/>", riga.dataLav, riga.CognomeNome);
|
|
}
|
|
corpoEmail += SteamwareStrings.charLine('-', 80);
|
|
gestEmail.geAuth.mandaEmail(fromEmail, adminEmail, oggettoEmail, corpoEmail);
|
|
|
|
// re richiesto invio email utenti x warning entrate/uscrite
|
|
if (memLayer.ML.confReadBool("sendEmailToUser"))
|
|
{
|
|
// mando singole email ai dipendenti SE C'è EMAIL!!!!
|
|
foreach (DS_Applicazione.stp_DipendentiAndAnomalieRow rigaDip in tabDipAndAnom)
|
|
{
|
|
if (!string.IsNullOrEmpty(rigaDip.email))
|
|
{
|
|
tabTimbExpl = DataProxy.DP.taTimbExpl.getByDipAnomalia(rigaDip.idxDipendente, oggi.AddDays(-gg2Chk), oggi.AddHours(1), false, true, false);
|
|
// reimposto testo
|
|
if (memLayer.ML.confReadBool("includeDirectUrl"))
|
|
{
|
|
corpoEmail = string.Format("Risultano a sistema le seguenti anomalie:<br/><a href=\"{0}A4/commesseUtente.aspx\">timbrature mancanti / non corrispondenti</a><br/><br/>", memLayer.ML.confReadString("baseUrl"));
|
|
}
|
|
else
|
|
{
|
|
corpoEmail = "Risultano a sistema le seguenti anomalie: timbrature mancanti / non corrispondenti<br/>";
|
|
}
|
|
corpoEmail += string.Format("{0}<br/>", SteamwareStrings.charLine('-', 80));
|
|
corpoEmail += "| -- DATA --\t| -- Dipendente --<br/>";
|
|
corpoEmail += string.Format("{0}<br/>", SteamwareStrings.charLine('-', 80));
|
|
foreach (DS_Applicazione.TimbratureExplRow riga in tabTimbExpl)
|
|
{
|
|
corpoEmail += string.Format("| {0:yyyy.MM.dd ddd}\t| {1}<br/>", riga.dataLav, riga.CognomeNome);
|
|
}
|
|
corpoEmail += SteamwareStrings.charLine('-', 80);
|
|
gestEmail.geAuth.mandaEmail(fromEmail, rigaDip.email, oggettoEmail, corpoEmail);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// (C) recupero errori mancata copertura orario, mando ad admin
|
|
if (memLayer.ML.confReadBool("checkAnomOreLav"))
|
|
{
|
|
tabDipAndAnom = DataProxy.DP.taDipAnom.GetData(oggi.AddDays(-gg2Chk), oggi.AddHours(1), false, false, true);
|
|
tabTimbExpl = DataProxy.DP.taTimbExpl.getByDipAnomalia(0, oggi.AddDays(-gg2Chk), oggi.AddHours(1), false, false, true);
|
|
// se ho trovato record...
|
|
if (tabTimbExpl.Rows.Count > 0)
|
|
{
|
|
logger.lg.scriviLog("Trovate anomalie copertura orario, invio email!", tipoLog.INFO);
|
|
// mando email ad admin!
|
|
oggettoEmail = "Anomalie GPW: Ore timbrate";
|
|
if (memLayer.ML.confReadBool("includeDirectUrl"))
|
|
{
|
|
corpoEmail = string.Format("Risultano a sistema le seguenti anomalie:<br/><a href=\"{0}A1/reviewTimbrature.aspx\">Orario timbrato non suff a copertura standard</a><br/><br/>", memLayer.ML.confReadString("baseUrl"));
|
|
}
|
|
else
|
|
{
|
|
corpoEmail = "Risultano a sistema le seguenti anomalie: Orario timbrato non suff a copertura standard<br/>";
|
|
}
|
|
corpoEmail += string.Format("{0}<br/>", SteamwareStrings.charLine('-', 80));
|
|
corpoEmail += "| -- DATA --\t| -- Dipendente --<br/>";
|
|
corpoEmail += string.Format("{0}<br/>", SteamwareStrings.charLine('-', 80));
|
|
foreach (DS_Applicazione.TimbratureExplRow riga in tabTimbExpl)
|
|
{
|
|
corpoEmail += string.Format("| {0:yyyy.MM.dd ddd}\t| {1}<br/>", riga.dataLav, riga.CognomeNome);
|
|
}
|
|
corpoEmail += SteamwareStrings.charLine('-', 80);
|
|
gestEmail.geAuth.mandaEmail(fromEmail, adminEmail, oggettoEmail, corpoEmail);
|
|
}
|
|
}
|
|
|
|
// (D) recupero errori copertura ore lavorate / ore caricate a commessa...
|
|
if (memLayer.ML.confReadBool("checkAnomOreLavComm"))
|
|
{
|
|
tabTimbRegAtt = DataProxy.DP.taTimbRegAtt.GetData(0, oggi.AddDays(-gg2ChkOreCaricate), oggi.AddHours(1), false, true, memLayer.ML.confReadInt("maxErrMin"), memLayer.ML.confReadInt("maxErrPlus"));
|
|
// sulla tabella seleziono SE NON E' OK colonna okLavCom
|
|
if (((DS_Applicazione.TE_RA_ExplRow[])tabTimbRegAtt.Select(" okLavCom = 0 ")).Length > 0)
|
|
{
|
|
logger.lg.scriviLog("Trovate anomalie ore lavorate / commesse caricate, invio email!", tipoLog.INFO);
|
|
// mando email ad admin!
|
|
oggettoEmail = "Anomalie GPW: Ore Caricate a commessa";
|
|
if (memLayer.ML.confReadBool("includeDirectUrl"))
|
|
{
|
|
corpoEmail = string.Format("Risultano a sistema le seguenti anomalie:<br/><a href=\"{0}A1/reviewTimbrature.aspx\">ore caricate a commessa non corrispondenti ad ore lavorate secondo range {1} min / {2} min</a><br/><br/>", memLayer.ML.confReadString("baseUrl"), memLayer.ML.confReadInt("maxErrMin"), memLayer.ML.confReadInt("maxErrPlus"));
|
|
}
|
|
else
|
|
{
|
|
corpoEmail = "Risultano a sistema le seguenti anomalie: ore caricate a commessa non corrispondenti ad ore lavorate<br/>";
|
|
}
|
|
corpoEmail += string.Format("{0}<br/>", SteamwareStrings.charLine('-', 80));
|
|
corpoEmail += "| -- DATA --\t| -- Dipendente --\t\t| Progetti<br/>";
|
|
corpoEmail += string.Format("{0}<br/>", SteamwareStrings.charLine('-', 80));
|
|
foreach (DS_Applicazione.TE_RA_ExplRow riga in (DS_Applicazione.TE_RA_ExplRow[])tabTimbRegAtt.Select(" okLavCom = 0 "))
|
|
{
|
|
corpoEmail += string.Format("| {0:yyyy.MM.dd ddd}\t| {1}\t| {2}<br/>", riga.dataLav, riga.CognomeNome, riga.progetti);
|
|
}
|
|
corpoEmail += SteamwareStrings.charLine('-', 80);
|
|
gestEmail.geAuth.mandaEmail(fromEmail, adminOreLavEmail, oggettoEmail, corpoEmail);
|
|
}
|
|
}
|
|
|
|
// (E) cerco anomalie x orario continuato (no Pausa Pranzo, solo 1 IN, 1 OUT)
|
|
if (memLayer.ML.confReadBool("checkAnomContinuato"))
|
|
{
|
|
tabTimbExpl = DataProxy.DP.taTimbExpl.getContinuato(0, oggi.AddDays(-gg2ChkCont), oggi.AddHours(1));
|
|
// se ho trovato record...
|
|
if (tabTimbExpl.Rows.Count > 0)
|
|
{
|
|
logger.lg.scriviLog("Trovate anomalie orario continuato, invio email ad admin", tipoLog.INFO);
|
|
oggettoEmail = "Anomalie GPW: Orario Continuato";
|
|
if (memLayer.ML.confReadBool("includeDirectUrl"))
|
|
{
|
|
corpoEmail = string.Format("Risultano a sistema le seguenti anomalie:<br/><a href=\"{0}A1/approvTimbrature.aspx\">orari continuati da approvare</a><br/><br/>", memLayer.ML.confReadString("baseUrl"));
|
|
}
|
|
else
|
|
{
|
|
corpoEmail = "Risultano a sistema le seguenti anomalie: orari continuati da approvare<br/>";
|
|
}
|
|
corpoEmail += string.Format("{0}<br/>", SteamwareStrings.charLine('-', 80));
|
|
corpoEmail += "| -- DATA --\t| Dipendente<br/>";
|
|
corpoEmail += string.Format("{0}<br/>", SteamwareStrings.charLine('-', 80));
|
|
foreach (DS_Applicazione.TimbratureExplRow riga in tabTimbExpl)
|
|
{
|
|
corpoEmail += string.Format("| {0:yyyy.MM.dd ddd}\t| {1}<br/>", riga.dataLav, riga.CognomeNome);
|
|
}
|
|
corpoEmail += SteamwareStrings.charLine('-', 80);
|
|
gestEmail.geAuth.mandaEmail(fromEmail, adminContinuatoEmail, oggettoEmail, corpoEmail);
|
|
}
|
|
}
|
|
|
|
answ = true;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
logger.lg.scriviLog(string.Format("Errore in procedura check & invio email{0}{1}", Environment.NewLine, exc), tipoLog.EXCEPTION);
|
|
answ = false;
|
|
}
|
|
//registro evento
|
|
DataProxy.DP.taRE.Insert(DateTime.Now, "checkAnomalie", "-");
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Verifica ed eventualmente esegue gli script quotidiani tra cui il check anomalie
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public bool dailyDuties()
|
|
{
|
|
bool answ = false;
|
|
if (memLayer.ML.confReadBool("enableDailyCheck"))
|
|
{
|
|
int firstHour2Check = memLayer.ML.confReadInt("firstHour2Check");
|
|
// controllo sfasato di x ore come da web.config se ci sia già stato il check quotidiano anomalie (con relative email)
|
|
if (DataProxy.DP.taRE.getByDataEv("checkAnomalie", DateTime.Now.AddHours(-firstHour2Check).Date).Rows.Count == 0)
|
|
{
|
|
logger.lg.scriviLog("Richiesto Check Daily Duties", tipoLog.INFO);
|
|
// chiamo check anomalie
|
|
checkAnomalie();
|
|
//registro evento
|
|
DataProxy.DP.taRE.Insert(DateTime.Now.AddHours(-firstHour2Check), "dailyDuties", "-");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (memLayer.ML.confReadInt("_logLevel") > 5) logger.lg.scriviLog("DISABILITATO Check Daily Duties", tipoLog.INFO);
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
#endregion Public Methods
|
|
}
|
|
} |