using GPW_data; using MongoDB.Driver.Linq; using SteamWare; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Web.UI; using System.Web.UI.WebControls; namespace GPW_Admin.WebUserControls { public partial class cmp_gestRichDip : BaseUserControl { #region Public Methods public void doUpdate() { // aggiorno! grView.PageSize = utils.pageSize; grView.DataBind(); } #endregion Public Methods #region Protected Properties /// /// Anno corrente /// protected int anno { get { int answ = 0; if (txtAnno != null && !string.IsNullOrEmpty(txtAnno.Text)) { _ = int.TryParse(txtAnno.Text, out answ); } else { answ = DateTime.Today.Year; } return answ; } set { txtAnno.Text = value.ToString(); } } protected DateTime Fine { get { DateTime answ = new DateTime(anno + 1, 1, 1); if (!string.IsNullOrEmpty(hfFine.Value)) { DateTime.TryParse(hfFine.Value, out answ); } else { hfFine.Value = $"{answ}"; } return answ; } set { hfFine.Value = $"{value}"; } } protected DateTime Inizio { get { DateTime answ = new DateTime(anno, 1, 1); if (!string.IsNullOrEmpty(hfInizio.Value)) { DateTime.TryParse(hfInizio.Value, out answ); } else { hfInizio.Value = $"{answ}"; } return answ; } set { hfInizio.Value = $"{value}"; } } protected List listRR { get; set; } #endregion Protected Properties #region Protected Methods protected void chkShowAll_CheckedChanged(object sender, EventArgs e) { chkShowAll.Text = chkShowAll.Checked ? "Mostra Tutti" : "Da Confermare"; cmp_calAnnuale.showAlsoConf = chkShowAll.Checked; } protected void chkWeek_CheckedChanged(object sender, EventArgs e) { fixCalDisplay(); } protected string datiDip(object idxDip) { int idxDipendente = 0; int.TryParse($"{idxDip}", out idxDipendente); string answ = "NA"; var rigaDip = listaDip.FirstOrDefault(x => x.idxDipendente == idxDipendente); if (rigaDip != null) { answ = $"{rigaDip.Cognome} {rigaDip.Nome}"; } return answ; } protected void doUpdateCal() { listRR = RRListByAnno(anno); } protected void grView_SelectedIndexChanged(object sender, EventArgs e) { // recupero richiesta... string sIdx = $"{grView.SelectedDataKey["IdxRegRich"]}"; if (!string.IsNullOrEmpty(sIdx)) { int IdxRegRich = 0; int.TryParse(sIdx, out IdxRegRich); if (listRR == null || listRR.Count == 0) { doUpdateCal(); } // cerco richeista var richDip = listRR.Where(x => x.IdxRegRich == IdxRegRich).FirstOrDefault(); if (richDip != null) { // metto come data il lUNEDI' della data indicata... var dtRif = richDip.DtStart.Date; if (dtRif.DayOfWeek != DayOfWeek.Monday) { int offset = dtRif.DayOfWeek - DayOfWeek.Monday; dtRif = dtRif.AddDays(-offset); } cmp_calWeek.DataRif = dtRif; } } } protected void ods_Deleted(object sender, System.Web.UI.WebControls.ObjectDataSourceStatusEventArgs e) { doUpdateCal(); } /// /// check licenze in fase di eliminazione... /// /// /// protected void ods_Deleting(object sender, ObjectDataSourceMethodEventArgs e) { if (e != null) { if (!licenzeGPW.checkLicenze) { // annullo update se licenze sforate... e.Cancel = true; grView.EditIndex = -1; grView.DataBind(); } else { // cerco! if (e.InputParameters["Original_IdxRegRich"] != null) { string sIdxRegRich = $"{e.InputParameters["Original_IdxRegRich"]}"; int IdxRegRich = 0; int.TryParse(sIdxRegRich, out IdxRegRich); if (IdxRegRich > 0) { // recupero richiesta x i dati utente if (listRR == null || listRR.Count == 0) { listRR = RRListByAnno(anno); } var richDip = listRR.Where(x => x.IdxRegRich == IdxRegRich).FirstOrDefault(); if (richDip != null) { // recupero dipendente... var currUser = listaDip.Where(x => x.idxDipendente == richDip.IdxDipendente).FirstOrDefault(); string destEmail = currUser.email; string fromEmail = memLayer.ML.CRS("_fromEmail"); string adminEmail = memLayer.ML.CRS("adminRichDip"); // calcolo il responsabile if (currUser.idxResp > 0) { string mailResp = emailResp(currUser.idxResp); if (!string.IsNullOrEmpty(mailResp) && !adminEmail.Contains(mailResp)) { adminEmail += $",{mailResp}"; } } string subjMess = $"ELIMINAZIONE richiesta n.{IdxRegRich}"; DateTime adesso = DateTime.Now; StringBuilder sbMain = new StringBuilder(); sbMain.AppendLine($"Il giorno {adesso:yyyy.MM.dd} alle ore {adesso:HH:mm:ss} è stata ELIMINAZIONE la richiesta in oggetto."); sbMain.AppendLine(""); sbMain.Append("
"); sbMain.Append($"{currUser.Cognome} {currUser.Nome} ({currUser.matricola})"); sbMain.Append("
"); sbMain.AppendLine("
"); sbMain.AppendLine($"Richiesta: {richDip.CodGiust}"); string sConf = $"{e.InputParameters["Conf"]}"; bool isConf = false; bool.TryParse(sConf, out isConf); string stato = isConf ? "CONFERMATA" : "RIFIUTATA"; sbMain.AppendLine($"Stato: {stato}"); sbMain.AppendLine($"Inizio: {richDip.DtStart}"); sbMain.AppendLine($"Fine: {richDip.DtEnd}"); sbMain.AppendLine($"Note: {richDip.Note}"); sbMain.AppendLine("
"); string bodyMess = sbMain.ToString().Replace($"{Environment.NewLine}", "
"); // invio email! gestEmail.geAuth.mandaEmail(fromEmail, destEmail, subjMess, bodyMess); // ora sistemo x admin var adminList = adminEmail.Split(','); string urlRedir = memLayer.ML.CRS("urlRedirRich"); bodyMess += $"

Cliccare sul seguente link per accedere alla pagina di gestione"; foreach (var dest in adminList) { gestEmail.geAuth.mandaEmail(fromEmail, dest, subjMess, bodyMess); } } } } } } } protected void ods_Updated(object sender, System.Web.UI.WebControls.ObjectDataSourceStatusEventArgs e) { doUpdateCal(); } /// /// check licenze in fase di update... /// /// /// protected void ods_Updating(object sender, ObjectDataSourceMethodEventArgs e) { if (e != null) { if (!licenzeGPW.checkLicenze) { // annullo update se licenze sforate... e.Cancel = true; grView.EditIndex = -1; grView.DataBind(); } else { // sistemo note (eventualmente) se fossero vuote... var rawNote = e.InputParameters["Note"]; if (string.IsNullOrEmpty($"{rawNote}")) { e.InputParameters["Note"] = "-"; } // cerco! if (e.InputParameters["Original_IdxRegRich"] != null) { string sIdxRegRich = $"{e.InputParameters["Original_IdxRegRich"]}"; int IdxRegRich = 0; int.TryParse(sIdxRegRich, out IdxRegRich); if (IdxRegRich > 0) { // recupero richiesta x i dati utente anno corrente... if (listRR == null || listRR.Count == 0) { listRR = RRListByAnno(anno); } // se non trovato provo anno +1... if (listRR == null || listRR.Count == 0) { listRR = RRListByAnno(anno + 1); } var richDip = listRR.Where(x => x.IdxRegRich == IdxRegRich).FirstOrDefault(); if (richDip != null) { // recupero dipendente... var currUser = listaDip.Where(x => x.idxDipendente == richDip.IdxDipendente).FirstOrDefault(); string destEmail = currUser.email; string fromEmail = memLayer.ML.CRS("_fromEmail"); string adminEmail = memLayer.ML.CRS("adminRichDip"); // calcolo il responsabile if (currUser.idxResp > 0) { string mailResp = emailResp(currUser.idxResp); if (!string.IsNullOrEmpty(mailResp) && !adminEmail.Contains(mailResp)) { adminEmail += $",{mailResp}"; } } string subjMess = $"Aggiornamento richiesta n.{IdxRegRich}"; DateTime adesso = DateTime.Now; StringBuilder sbMain = new StringBuilder(); sbMain.AppendLine($"Il giorno {adesso:yyyy.MM.dd} alle ore {adesso:HH:mm:ss} è stata modificata la richiesta in oggetto."); sbMain.AppendLine(""); sbMain.Append("
"); sbMain.Append($"{currUser.Cognome} {currUser.Nome} ({currUser.matricola})"); sbMain.Append("
"); sbMain.AppendLine("
"); sbMain.AppendLine($"Richiesta: {richDip.CodGiust}"); string sConf = $"{e.InputParameters["Conf"]}"; bool isConf = false; bool.TryParse(sConf, out isConf); string stato = isConf ? "CONFERMATA" : "RIFIUTATA"; sbMain.AppendLine($"Stato: {stato}"); sbMain.AppendLine($"Inizio: {richDip.DtStart}"); sbMain.AppendLine($"Fine: {richDip.DtEnd}"); sbMain.AppendLine($"Note: {richDip.Note}"); sbMain.AppendLine("
"); string bodyMess = sbMain.ToString().Replace($"{Environment.NewLine}", "
"); // invio email! gestEmail.geAuth.mandaEmail(fromEmail, destEmail, subjMess, bodyMess); // ora sistemo x admin var adminList = adminEmail.Split(','); string urlRedir = memLayer.ML.CRS("urlRedirRich"); bodyMess += $"

Cliccare sul seguente link per accedere alla pagina di gestione"; foreach (var dest in adminList) { gestEmail.geAuth.mandaEmail(fromEmail, dest, subjMess, bodyMess); } } } } } } } protected void Page_Load(object sender, EventArgs e) { grView.PageSize = utils.pageSize; if (!Page.IsPostBack) { anno = DateTime.Now.Year; cmp_calAnnuale.anno = anno; cmp_calWeek.anno = anno; reportAnno(); doUpdateCal(); } listaDip = licenzeGPW.getDipAttivi(); grView.Visible = chkLicOk; cmp_selettoreMesi.eh_doRefresh += Cmp_selettoreMesi_eh_doRefresh; } protected void repCal_PreRender(object sender, EventArgs e) { doUpdateCal(); } protected void txtAnno_TextChanged(object sender, EventArgs e) { reportAnno(); doUpdateCal(); } protected void txtNumGG_TextChanged(object sender, EventArgs e) { int numGG = 10; int.TryParse(txtNumGG.Text, out numGG); cmp_calWeek.NumGG = numGG; } #endregion Protected Methods #region Private Methods private void Cmp_selettoreMesi_eh_doRefresh(object sender, EventArgs e) { Inizio = cmp_selettoreMesi.inizio; Fine = cmp_selettoreMesi.fine; doUpdate(); } private void fixCalDisplay() { // verifico cosa mostrare... cmp_calAnnuale.Visible = !chkWeek.Checked; cmp_calWeek.Visible = chkWeek.Checked; } private void reportAnno() { Inizio = new DateTime(anno, 1, 1); Fine = new DateTime(anno + 1, 1, 1); intervalloDate currAnno = new intervalloDate { inizio = Inizio, fine = Fine }; cmp_selettoreMesi.anno = anno; cmp_selettoreMesi.intervalloAnalisi = currAnno; cmp_calAnnuale.anno = anno; } /// /// Elenco Richieste Dipendenti x anno corrente + successivo /// /// private List RRListByAnno(int reqYear) { DateTime inizio = new DateTime(reqYear, 1, 1); // recupero x 2 anni x evitare problemi con cambio anno... DateTime fine = inizio.AddYears(2); List result = DataProxy.DP.taRR.getPeriod(0, inizio, fine, chkShowAll.Checked).ToList(); return result; } #endregion Private Methods } }