using GPW_data; using System; using System.Collections.Generic; using System.Linq; using System.Web.UI.WebControls; namespace GPW_Admin.WebUserControls { public partial class cmp_calAnnuale : BaseUserControl { #region Public Properties public int anno { get => _anno; set { _anno = value; //odsMesi.DataBind(); repCal.DataBind(); } } /// /// Mostra anche richieste (permessi/ferie/104) confermate o solo da confermare /// public bool showAlsoConf { get; set; } = true; /// /// Mostrare/Colorare sul calendario le chiusure aziendali programmate /// public bool showCalAz { get => _showCalAz; set { _showCalAz = value; divCalAz.Visible = value; divFes.Visible = value; } } /// /// Mostrare/Colorare sul calendario le malattie ricevute /// public bool showMal { get => _showMal; set { _showMal = value; divMal.Visible = value; } } /// /// Mostrare/Colorare sul calendario le richieste dipendente /// public bool showRichDip { get => _showRichDip; set { _showRichDip = value; divRichDip.Visible = value; } } #endregion Public Properties #region Protected Properties protected DS_Applicazione.DipendentiDataTable listaDip { get; set; } protected List listCFF { get; set; } protected List listRM { get; set; } protected List listRR { get; set; } #endregion Protected Properties #region Protected Methods /// /// colorazione calendario da eventi registrati.... /// /// /// protected void calDisplay_DayRender(object sender, System.Web.UI.WebControls.DayRenderEventArgs e) { bool isColored = false; if (showCalAz) { // coloro se fa parte delle festività/ferie... if (listCFF != null && listCFF.Count > 0) { // cerco riga... var thisDate = listCFF.Where(x => x.data == e.Day.Date).FirstOrDefault(); if (thisDate != null && e.Cell.CssClass != "text-light") { isColored = true; e.Cell.CssClass = thisDate.codGiust == "FEST" ? "bg-danger text-warning" : "bg-warning"; e.Cell.ToolTip = $"{thisDate.descrizione}"; } } } if (showMal) { // coloro se fa parte delle festività/ferie... if (listRM != null && listRM.Count > 0) { // cerco riga... var listMal = listRM.Where(x => e.Day.Date >= x.DtInizio && e.Day.Date < x.DtInizio.AddDays(x.NumGG)).ToList(); var thisDate = listMal.FirstOrDefault(); if (thisDate != null && e.Cell.CssClass != "text-light") { isColored = true; e.Cell.CssClass = "bg-dark text-light"; // se ho 1 sola riga --> metto 1, altrimenti compilo multiplo... string toolTip = ""; if (listMal.Count == 1) { toolTip = $"{datiDip(thisDate.IdxDipendente)}"; } else { foreach (var item in listMal) { toolTip += $"{datiDip(item.IdxDipendente)} | "; } // elimino ultimo //
toolTip = toolTip.Substring(0, toolTip.Length - 3); } e.Cell.ToolTip = toolTip; } } } if (showRichDip) { // coloro se fa parte delle richieste dipendenti... if (listRR != null && listRR.Count > 0) { if (e.Day.Date.DayOfWeek != DayOfWeek.Saturday && e.Day.Date.DayOfWeek != DayOfWeek.Sunday) { // cerco righe... var listReq = listRR.Where(x => e.Day.Date >= x.DtStart.Date && e.Day.Date <= x.DtEnd.Date).ToList(); if (listReq != null && listReq.Count > 0) { var thisDate = listReq.FirstOrDefault(); if (thisDate != null && e.Cell.CssClass != "text-light") { isColored = true; switch (thisDate.CodGiust) { case "104": e.Cell.CssClass = thisDate.Conf ? "g104Conf" : "g104NC"; break; case "FER": e.Cell.CssClass = thisDate.Conf ? "gFerConf" : "gFerNC"; break; case "PERM": e.Cell.CssClass = thisDate.Conf ? "gPerConf" : "gPerNC"; break; default: e.Cell.CssClass = "bg-dark text-light"; break; } } // se ho 1 sola riga --> metto 1, altrimenti compilo multiplo... string toolTip = ""; if (listReq.Count == 1) { toolTip = $"{thisDate.CodGiust}, {datiDip(thisDate.IdxDipendente)}"; } else { foreach (var item in listReq) { toolTip += $"{item.CodGiust}, {datiDip(item.IdxDipendente)} | "; } // elimino ultimo //
toolTip = toolTip.Substring(0, toolTip.Length - 3); } e.Cell.ToolTip = toolTip; } } } } // se sab/dom --> grigio if (!isColored && e.Cell.CssClass != "text-light") { if (e.Day.Date.DayOfWeek == DayOfWeek.Saturday || e.Day.Date.DayOfWeek == DayOfWeek.Sunday) { e.Cell.CssClass = "bg-secondary text-light"; } } } 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() { if (showCalAz) { listCFF = CffListByAnno(anno); } if (showRichDip) { listRR = RRListByAnno(anno); } if (showMal) { listRM = RMListByAnno(anno); } } protected void Page_Load(object sender, EventArgs e) { repCal.Visible = chkLicOk; listaDip = licenzeGPW.getDipAttivi(); divRichDip.Visible = showRichDip; } protected void repCal_PreRender(object sender, EventArgs e) { doUpdateCal(); } #endregion Protected Methods #region Private Properties private int _anno { get { int answ = 0; int.TryParse(hfAnno.Value, out answ); return answ; } set { hfAnno.Value = $"{value}"; } } private bool _showCalAz { get; set; } = true; private bool _showMal { get; set; } = false; private bool _showRichDip { get; set; } = true; #endregion Private Properties #region Private Methods /// /// Elenco Festività / Ferie x anno /// /// private List CffListByAnno(int reqYear) { DateTime inizio = new DateTime(reqYear, 1, 1); DateTime fine = inizio.AddYears(1); List result = DataProxy.DP.taCFF.getPeriod(inizio, fine).ToList(); return result; } /// /// Elenco Richieste Dipendenti x anno /// /// private List RMListByAnno(int reqYear) { DateTime inizio = new DateTime(reqYear, 1, 1); DateTime fine = inizio.AddYears(1); List result = DataProxy.DP.taRM.getPeriod(0, inizio, fine).ToList(); return result; } /// /// Elenco Richieste Dipendenti x anno /// /// private List RRListByAnno(int reqYear) { DateTime inizio = new DateTime(reqYear, 1, 1); DateTime fine = inizio.AddYears(1); List result = DataProxy.DP.taRR.getPeriod(0, inizio, fine, showAlsoConf).ToList(); return result; } #endregion Private Methods } }