Files
2023-01-12 09:08:28 +01:00

409 lines
12 KiB
C#

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;
}
}
/// <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;
divCalAz.Visible = value;
divFes.Visible = value;
}
}
/// <summary>
/// Mostrare/Colorare sul calendario le malattie ricevute
/// </summary>
public bool showMal
{
get => _showMal;
set
{
_showMal = value;
divMal.Visible = value;
}
}
/// <summary>
/// Mostrare/Colorare sul calendario le richieste dipendente
/// </summary>
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<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
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
/// <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
/// <summary>
/// Elenco eventi da mostrare in calendario
/// </summary>
/// <returns></returns>
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;
}
/// <summary>
/// intercetto e cambio classe CSS...
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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";
}
}
}
/// <summary>
/// Calcolo durata evento dato tipo, inizio e fine salvati:
/// - es ferie x 1 gg --> 8h
/// </summary>
/// <param name="dtInizio"></param>
/// <param name="dtFine"></param>
/// <returns></returns>
protected Tuple<DateTime, DateTime> 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<DateTime, DateTime> answ = new Tuple<DateTime, DateTime>(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();
}
}
}