using DayPilot.Web.Ui; using GPW_data; using SteamWare; using System; using System.Collections; using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Text.RegularExpressions; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace GPW_Admin.WebUserControls { public partial class cmp_calWeek : BaseUserControl { #region Public Properties public int anno { get => _anno; set { _anno = value; } } /// /// 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; } } public DateTime DataRif { get => dataRif; set { dataRif = value; WeekCalendar.StartDate = value; } } public int NumGG { get => numGG; set { numGG = value; WeekCalendar.Days = value; } } private DateTime dataRif { get; set; } private int numGG { get; set; } #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 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) { if (!IsPostBack) { listaDip = licenzeGPW.getDipAttivi(); doUpdateCal(); WeekCalendar.DataSource = getData(); DataBind(); } } #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 /// /// Elenco eventi da mostrare in calendario /// /// private ArrayList getData() { ArrayList al = new ArrayList(); // a seconda di cosa è richiesto popolo l'elenco... if (showCalAz) { // coloro se fa parte delle festività/ferie... if (listCFF != null && listCFF.Count > 0) { var elencoCFF = listCFF.Select(x => new CustomEvent() { Inizio = calcDuration(x.data, x.data).Item1, Fine = calcDuration(x.data, x.data).Item2, Name = $"{x.codGiust} - {x.descrizione}", Id = $"CFF{x.data:yyyyMMdd}", Tooltip = $"{x.codGiust} - {x.descrizione}" }).ToList(); al.AddRange(elencoCFF); } } if (showMal) { if (listRM != null && listRM.Count > 0) { var elencoRM = listRM.Select(x => new CustomEvent() { Inizio = x.DtInizio, Fine = x.DtInizio.AddDays(x.NumGG), Name = $"{datiDip(x.IdxDipendente)} | MAL", Id = $"CM{x.IdxRegMal}", Tooltip = $"{datiDip(x.IdxDipendente)} | MAL - {x.CodCert}" }).ToList(); al.AddRange(elencoRM); } } if (showRichDip) { if (listRR != null && listRR.Count > 0) { var elencoRR = listRR.Select(x => new CustomEvent() { Inizio = calcDuration(x.DtStart, x.DtEnd).Item1, Fine = calcDuration(x.DtStart, x.DtEnd).Item2, Name = $"{datiDip(x.IdxDipendente)} | {x.CodGiust}", Id = x.Conf ? $"RC{x.IdxRegRich}" : $"RNC{x.IdxRegRich}", Tooltip = $"{datiDip(x.IdxDipendente)} | {x.CodGiust} - {x.Note}" }).ToList(); al.AddRange(elencoRR); } } return al; } /// /// intercetto e cambio classe CSS... /// /// /// protected void WeekCalendar_BeforeEventRender(object sender, DayPilot.Web.Ui.Events.Calendar.BeforeEventRenderEventArgs e) { if (e.Text.Contains("FEST")) { e.CssClass = "bg-danger text-warning"; } else if (e.Text.Contains("FER")) { if (e.Id.StartsWith("RNC")) { e.CssClass = "gFerNC"; } else if (e.Id.StartsWith("RC")) { e.CssClass = "gFerConf"; } else { e.CssClass = "bg-warning"; } } else if (e.Text.Contains("MAL")) { e.CssClass = "bg-dark text-light"; } else if (e.Text.Contains("104")) { if (e.Id.StartsWith("RNC")) { e.CssClass = "g104NC"; } else if (e.Id.StartsWith("RC")) { e.CssClass = "g104Conf"; } } else if (e.Text.Contains("PERM")) { if (e.Id.StartsWith("RNC")) { e.CssClass = "gPerNC"; } else if (e.Id.StartsWith("RC")) { e.CssClass = "gPerConf"; } } } /// /// Calcolo durata evento dato tipo, inizio e fine salvati: /// - es ferie x 1 gg --> 8h /// /// /// /// protected Tuple calcDuration(DateTime dtInizio, DateTime dtFine) { var durata = Math.Abs(dtFine.Subtract(dtInizio).TotalHours); // giorno singolo if (durata < 24) { // se durata zero = 1gg --> 8h durata = durata == 0 ? 8 : durata; } else { // se è su più gg --> aggiungo 1 durata += 10; } // se inizio mezzanotte --> metto le 9:00... if (dtInizio.Hour == 0) { dtInizio = dtInizio.AddHours(9); } // calcolo! dtFine = dtInizio.AddHours(durata); Tuple answ = new Tuple(dtInizio, dtFine); return answ; } public class CustomEvent { private string name; private string tooltip; private DateTime start; private DateTime end; private string id; public string Name { get => name; set => name = value; } public string Tooltip { get => tooltip; set => tooltip = value; } public DateTime Inizio { get => start; set => start = value; } public DateTime Fine { get => end; set => end = value; } public string Id { get => id; set => id = value; } } protected void WeekCalendar_PreRender(object sender, EventArgs e) { doUpdateCal(); } } }