Files
GPW/GPW_Admin/WebUserControls/cmp_calWeek.ascx.cs
T

434 lines
14 KiB
C#

using DayPilot.Web.Ui;
using GPW_data;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
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;
#if false
repCal.DataBind();
#endif
}
}
/// <summary>
/// Mostra anche richieste (permessi/ferie/104) confermate o solo da confermare
/// </summary>
public bool showAlsoConf { get; set; } = true;
/// <summary>
/// Mostrare/Colorare sul calendario le chiusure aziendali programmate
/// </summary>
public bool showCalAz
{
get => _showCalAz;
set
{
_showCalAz = value;
#if false
divCalAz.Visible = value;
divFes.Visible = value;
#endif
}
}
/// <summary>
/// Mostrare/Colorare sul calendario le malattie ricevute
/// </summary>
public bool showMal
{
get => _showMal;
set
{
_showMal = value;
#if false
divMal.Visible = value;
#endif
}
}
/// <summary>
/// Mostrare/Colorare sul calendario le richieste dipendente
/// </summary>
public bool showRichDip
{
get => _showRichDip;
set
{
_showRichDip = value;
#if false
divRichDip.Visible = value;
#endif
}
}
#endregion Public Properties
#region Protected Properties
protected DS_Applicazione.DipendentiDataTable listaDip { get; set; }
protected List<DS_Applicazione.CalendFesteFerieRow> listCFF { get; set; }
protected List<DS_Applicazione.RegistroMalattieRow> listRM { get; set; }
protected List<DS_Applicazione.RegistroRichiesteRow> listRR { get; set; }
#endregion Protected Properties
#region Protected Methods
/// <summary>
/// colorazione calendario da eventi registrati....
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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
// <br />
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
// <br />
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)
{
if (!IsPostBack)
{
listaDip = licenzeGPW.getDipAttivi();
doUpdateCal();
WeekCalendar.DataSource = getData();
DataBind();
}
#if false
repCal.Visible = chkLicOk;
listaDip = licenzeGPW.getDipAttivi();
divRichDip.Visible = showRichDip;
#endif
}
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
/// <summary>
/// Elenco Festività / Ferie x anno
/// </summary>
/// <param name="reqYear"></param>
private List<DS_Applicazione.CalendFesteFerieRow> CffListByAnno(int reqYear)
{
DateTime inizio = new DateTime(reqYear, 1, 1);
DateTime fine = inizio.AddYears(1);
List<DS_Applicazione.CalendFesteFerieRow> result = DataProxy.DP.taCFF.getPeriod(inizio, fine).ToList();
return result;
}
/// <summary>
/// Elenco Richieste Dipendenti x anno
/// </summary>
/// <param name="reqYear"></param>
private List<DS_Applicazione.RegistroMalattieRow> RMListByAnno(int reqYear)
{
DateTime inizio = new DateTime(reqYear, 1, 1);
DateTime fine = inizio.AddYears(1);
List<DS_Applicazione.RegistroMalattieRow> result = DataProxy.DP.taRM.getPeriod(0, inizio, fine).ToList();
return result;
}
/// <summary>
/// Elenco Richieste Dipendenti x anno
/// </summary>
/// <param name="reqYear"></param>
private List<DS_Applicazione.RegistroRichiesteRow> RRListByAnno(int reqYear)
{
DateTime inizio = new DateTime(reqYear, 1, 1);
DateTime fine = inizio.AddYears(1);
List<DS_Applicazione.RegistroRichiesteRow> result = DataProxy.DP.taRR.getPeriod(0, inizio, fine, showAlsoConf).ToList();
return result;
}
#endregion Private Methods
private ArrayList getData()
{
ArrayList al = new ArrayList();
//CustomEvent ce = new CustomEvent();
//ce.Inizio = Convert.ToDateTime("15:30");
//ce.Fine = Convert.ToDateTime("16:30");
//ce.Name = "My event";
//ce.Id = "1";
//ce.Tooltip = "prova tooltip";
//al.Add(ce);
// 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=x.data,
Fine=x.data,
Name= x.codGiust,
Id=$"F{x.data:yyyyMMdd}",
Tooltip = $"{x.codGiust} - {x.descrizione}"
}).ToList();
al.AddRange(elencoCFF);
}
}
if (showMal)
{
// coloro se fa parte delle festività/ferie...
if (listRM != null && listRM.Count > 0)
{
var elencoRM = listRM.Select(x => new CustomEvent()
{
Inizio = x.DtInizio,
Fine = x.DtInizio.AddDays(x.NumGG),
Name = "MAL",
Id = $"M{x.IdxRegMal}",
Tooltip = $"{datiDip(x.IdxDipendente)} | MAL - {x.CodCert}"
}).ToList();
al.AddRange(elencoRM);
}
}
if (showRichDip)
{
// coloro se fa parte delle richieste dipendenti...
if (listRR != null && listRR.Count > 0)
{
var elencoRR = listRR.Select(x => new CustomEvent()
{
Inizio = x.DtStart,
Fine = x.DtEnd,
Name = $"{x.CodGiust}",
Id = $"R{x.IdxRegRich}",
Tooltip = $"{datiDip(x.IdxDipendente)} | {x.CodGiust} - {x.Note}"
}).ToList();
al.AddRange(elencoRR);
}
}
return al;
}
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;
}
}
}
}