Files
GPW/GPW_Admin/WebUserControls/mod_adminFasi.ascx.cs
2024-03-21 09:52:12 +01:00

714 lines
22 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using SteamWare;
using GPW_data;
namespace GPW_Admin.WebUserControls
{
public partial class mod_adminFasi : BaseUserControl
{
#region Public Events
public event EventHandler eh_faseSel;
#endregion Public Events
#region Protected Properties
/// <summary>
/// uid base
/// </summary>
protected string sessionUid
{
get
{
return this.UniqueID.Replace("$", "-");
}
}
#endregion Protected Properties
#region Public Properties
public string CardStyle
{
get
{
return hfCardStyle.Value;
}
set
{
hfCardStyle.Value = value;
divCardMain.Attributes.Remove("class");
divCardHeader.Attributes.Remove("class");
divCardMain.Attributes.Add("class", $"card border-{value}");
divCardHeader.Attributes.Add("class", $"card-header bg-{value}");
}
}
/// <summary>
/// abilitazione/disabilitazione gestione cambio cliente
/// </summary>
public bool changeSelCliEnabled
{
get
{
return filtroCli.changeSelEnabled;
}
set
{
filtroCli.changeSelEnabled = value;
}
}
/// <summary>
/// determina se sia visibile pnl dettaglio RA della fase selezionata
/// </summary>
public bool enableShowRA
{
get
{
return pnlDetRA.Visible;
}
set
{
pnlDetRA.Visible = value;
}
}
/// <summary>
/// determina se sia visibile pnl dettaglio RA della fase selezionata
/// </summary>
public bool enableAddFasi
{
get
{
bool answ = false;
bool.TryParse(hfEnableAdd.Value, out answ);
return answ;
}
set
{
hfEnableAdd.Value= $"{value}";
}
}
/// <summary>
/// idx del cliente selezionato
/// </summary>
public int idxCliente
{
get
{
return memLayer.ML.IntSessionObj(string.Format("idxCli_{0}", sessionUid));
}
set
{
memLayer.ML.setSessionVal(string.Format("idxCli_{0}", sessionUid), value);
}
}
/// <summary>
/// valore della fase selezionata
/// </summary>
public int idxFase
{
get
{
int answ = 0;
if (grView.SelectedIndex >= 0)
{
try
{
answ = Convert.ToInt32(grView.SelectedValue);
}
catch
{ }
}
return answ;
}
}
/// <summary>
/// idx del progetto selezionato
/// </summary>
public int idxProgetto
{
get
{
return memLayer.ML.IntSessionObj(string.Format("idxProj_{0}", sessionUid));
}
set
{
memLayer.ML.setSessionVal(string.Format("idxProj_{0}", sessionUid), value);
filtroPrj.valore = $"{value}";
}
}
public bool showReturnProj
{
get
{
return divReturn.Visible;
}
set
{
divReturn.Visible = value;
}
}
#endregion Public Properties
#region Private Methods
/// <summary>
/// cambio sel cliente --> aggiorno progetti
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void filtroCli_eh_selValore(object sender, EventArgs e)
{
saveFilterCli();
salveFilterPrj();
}
/// <summary>
/// aggiorno visualizzazione fasi!
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void filtroPrj_eh_selValore(object sender, EventArgs e)
{
salveFilterPrj();
}
/// <summary>
/// salva filtro prj
/// </summary>
private void salveFilterPrj()
{
//memLayer.ML.setSessionVal("idxProgetto_sel", filtroPrj.valore);
idxProgetto = filtroPrj.valoreInt;
grView.DataBind();
}
/// <summary>
/// salva filtro cliente
/// </summary>
private void saveFilterCli()
{
// salvo filtro cliente
//memLayer.ML.setSessionVal("idxCli_sel", filtroCli.valore);
idxCliente = filtroCli.valoreInt;
filtroPrj.ods = odsProj;
filtroPrj.reselFirst();
}
/// <summary>
/// sistema visibilità area dettaglio RA
/// </summary>
private void setDetVisibility()
{
pnlDetRA.Visible = enableShowRA;
lblDet.Visible = (grView.SelectedIndex >= 0);
}
#endregion Private Methods
#region Protected Methods
/// <summary>
/// gestione evento richiesta nuovo valore (mostra footer, ...)
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnNew_Click(object sender, EventArgs e)
{
if (e != null && sender != null)
{
// controllo se c'è un argument x la fase...
string idxFaseAncest = "0";
try
{
var cmdArg = ((LinkButton)sender).CommandArgument;
if (!string.IsNullOrEmpty(cmdArg))
{
idxFaseAncest = cmdArg;
}
}
catch
{ }
memLayer.ML.setSessionVal("idxFaseAncest", idxFaseAncest);
if (idxFaseAncest == "0")
{
// reset selezione...
resetSelezione();
}
// mostro il footer oppure la riga dei dettagli x nuovo...
if (grView.FooterRow != null)
{
grView.FooterRow.Visible = true;
}
// sollevo evento nuovo valore...
raiseAddNew();
}
}
/// <summary>
/// gestione evento richiesta nuovo valore QUANDO NON CI SIANO RECORDS!
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnNewEmpty_Click(object sender, EventArgs e)
{
memLayer.ML.setSessionVal("idxFaseAncest", "0");
DataProxy.DP.taAF.insertQuery(idxProgetto, 0, "NuovaFase", "DescrizioneFase", false, false, 0, 0, 1, true);
grView.DataBind();
// sollevo evento nuovo valore...
raiseAddNew();
}
/// <summary>
/// reset della selezione
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnReset_Click(object sender, EventArgs e)
{
resetSelezione();
}
/// <summary>
/// Effettua mass update del CodTagFase x tutte le fasi di progetto
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void lbtForceSet_Click(object sender, EventArgs e)
{
string codTagFase = ddlTagFaseSet.SelectedValue;
DataProxy.DP.taAF.updCodFaseByProj(idxProgetto, codTagFase);
resetSelezione();
}
/// <summary>
/// elenco colonne del datagrid
/// </summary>
/// <returns></returns>
protected DataColumnCollection colonneObj()
{
DataColumnCollection colonne = null;
using (DS_Applicazione.AnagFasiDataTable tabella = new DS_Applicazione.AnagFasiDataTable())
{
colonne = tabella.Columns;
}
return colonne;
}
/// <summary>
/// traduce gli header delle colonne
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void grView_DataBound(object sender, EventArgs e)
{
if (grView.Rows.Count > 0)
{
LinkButton lb;
// aggiorno gli headers
foreach (TableCell cella in grView.HeaderRow.Cells)
{
try
{
lb = (LinkButton)cella.Controls[0];
lb.Text = traduci(lb.Text);
}
catch
{ }
}
int totRecord = grView.Rows.Count + grView.PageSize * (grView.PageCount - 1);
lblNumRec.Text = string.Format("{0} records of ~ {1}", grView.Rows.Count, totRecord);
}
else
{
lblNumRec.Text = "";
}
}
/// <summary>
/// indico cambio selezione valore...
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void grView_SelectedIndexChanged(object sender, EventArgs e)
{
setDetVisibility();
if (eh_faseSel != null)
{
eh_faseSel(this, new EventArgs());
}
}
/// <summary>
/// annulla inserimento nuovo valore da footer
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void lblCanc_click(object sender, EventArgs e)
{
// annullo inserimento: nascondo footer, bind controlli...
grView.FooterRow.Visible = false;
}
/// <summary>
/// inserisce nuovo valore da footer
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void lblIns_click(object sender, EventArgs e)
{
// click su inserimento, chiamo il metodo insert dell'ObjectDataSource
ods.Insert();
}
/// <summary>
/// check licenze in fase di update...
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void ods_Updating(object sender, ObjectDataSourceMethodEventArgs e)
{
if (!licenzeGPW.checkLicenze)
{
if (e != null)
{
// annullo insert se licenze sforate...
e.Cancel = true;
grView.EditIndex = -1;
grView.DataBind();
}
}
}
/// <summary>
/// caricamento
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
filtroCli.ods = odsClienti;
filtroCli.valore = idxCliente.ToString();// memLayer.ML.StringSessionObj("idxCli_sel");
filtroPrj.ods = odsProj;
filtroPrj.valore = idxProgetto.ToString();// memLayer.ML.StringSessionObj("idxProgetto_sel");
PagCorrente();
}
filtroCli.eh_selValore += new EventHandler(filtroCli_eh_selValore);
filtroPrj.eh_selValore += new EventHandler(filtroPrj_eh_selValore);
grView.PageSize = utils.pageSize;
setDetVisibility();
}
/// <summary>
/// recupera i dati di un nuovo record contenuti nel footer di un gridView;
/// questi devono esses opportunamente nominati (es: txt{0}, dl{0}, ...)
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void recuperaFooter(object sender, ObjectDataSourceMethodEventArgs e)
{
if (e != null)
{
if (chkLicOk)
{
//recupero la riga footer...
DataColumnCollection colonne = colonneObj();
string nomeCol;
string tipoColonna = "";
foreach (DataColumn colonna in colonne)
{
nomeCol = colonna.ColumnName;
// cerco un textbox o quello che sia...
if (grView.FooterRow.FindControl(string.Format("txt{0}", nomeCol)) != null)
{
tipoColonna = "textBox";
}
else if (grView.FooterRow.FindControl(string.Format("dl{0}", nomeCol)) != null)
{
tipoColonna = "dropDownList";
}
else if (grView.FooterRow.FindControl(string.Format("chk{0}", nomeCol)) != null)
{
tipoColonna = "checkBox";
}
// in base al tipo salvo negli inputparameters dell'ODS
switch (tipoColonna)
{
case "textBox":
e.InputParameters[nomeCol] = ((TextBox)grView.FooterRow.FindControl(string.Format("txt{0}", nomeCol))).Text;
break;
case "dropDownList":
e.InputParameters[nomeCol] = ((DropDownList)grView.FooterRow.FindControl(string.Format("dl{0}", nomeCol))).SelectedValue;
break;
case "checkBox":
e.InputParameters[nomeCol] = ((CheckBox)grView.FooterRow.FindControl(string.Format("chk{0}", nomeCol))).Checked;
break;
default:
break;
}
tipoColonna = "";
}
//// aggiungo fase ancestor!
//e.InputParameters["idxFaseAncest"] = memLayer.ML.IntSessionObj("idxFaseAncest");
// aggiungo progetto!
e.InputParameters["idxProgetto"] = idxProgetto;
}
else
{
// annullo insert se licenze sforate...
e.Cancel = true;
grView.DataBind();
}
}
}
#endregion Protected Methods
#region Public Methods
/// <summary>
/// calcola classe css dato codice fase
/// </summary>
/// <param name="codFase"></param>
/// <returns></returns>
public string classByCod(object codFase)
{
string answ = "";
if (codFase != null)
{
int livello = 0;
// calcolo livello come num punti "." -1...
try
{
string[] array = codFase.ToString().Split('.');
livello = array.Length;
}
catch
{ }
if (livello < 4)
{
answ = "text-dark";
}
else
{
answ = "small text-primary";
}
}
return answ;
}
/// <summary>
/// restituisce una classe css a seconda dei valori passati:
/// green: bdgt > real
/// orange: real > bdgt*warning
/// red: real > bdgt
/// std: errore...
/// </summary>
/// <param name="real"></param>
/// <param name="bdgt"></param>
/// <returns></returns>
public string colorByVal(object real, object bdgt)
{
string specClass = "default";
try
{
double valoreReal = Convert.ToDouble(real);
double valoreBdget = Convert.ToDouble(bdgt);
double valoreWarn = Convert.ToDouble(bdgt) * Convert.ToDouble(memLayer.ML.confReadString("warningRatioPerc")) / 100;
if (valoreReal >= valoreBdget)
{
specClass = "danger";
}
else if (valoreReal >= valoreWarn)
{
specClass = "warning";
}
else
{
specClass = "success";
}
}
catch
{ }
return $"textNormal bg-{specClass} bg-opacity-50 bg-gradient border border-{specClass} rounded";
}
/// <summary>
/// Determina se sia eliminabile il record (=non ha ore caricate ne fasi)
/// </summary>
/// <param name="_totOre"></param>
/// <param name="_idxFase"></param>
/// <param name="_idxFaseAncest"></param>
/// <returns></returns>
public bool delEnabled(object _totOre, object _idxFase, object _idxFaseAncest)
{
bool answ = isWritable();
int idxFase = 0;
int idxFaseAnc = 0;
// solo se ha diritti scrittura controllo
if (answ && _totOre != null && _idxFase != null && _idxFaseAncest != null)
{
// se è una fase master (ancestor == 0 ) e ha child --> false...
_ = int.TryParse($"{_idxFaseAncest}", out idxFaseAnc);
_ = int.TryParse($"{_idxFase}", out idxFase);
if (idxFaseAnc == 0)
{
// verifico: se ha child --> NON eliminabile
int numFasiChild = DataProxy.DP.taAF.getByAncest(idxFase).Count;
answ = numFasiChild == 0;
}
else
{
double numOre = 0;
_ = Double.TryParse($"{_totOre}", out numOre);
answ = (numOre == 0);
// se fosse true --> procedo con controllo fasi
if (answ)
{
answ = !hasChildObj(idxFase);
}
}
}
return answ;
}
/// <summary>
/// Determina se abbia child obj --> NON eliminabile
/// </summary>
/// <param name="idxFase"></param>
/// <returns></returns>
public bool hasChildObj(int idxFase)
{
bool answ = false;
if (idxFase > 0)
{
string redKey = memLayer.ML.redHash($"faseHasChildObj:{idxFase}");
// cerco in cache redis...
string rawData = memLayer.ML.getRSV(redKey);
if (rawData == null)
{
int trovati = DataProxy.DP.taRA.getByFase(this.idxFase).Count;
answ = (trovati > 0);
memLayer.ML.setRSV(redKey, $"{answ}", 60 * 5);
}
else
{
bool.TryParse(rawData, out answ);
}
}
else
{
answ = true;
}
return answ;
}
/// <summary>
/// effettua update controllo
/// </summary>
public void doUpdate()
{
grView.PageSize = utils.pageSize;
resetSelezione();
}
/// <summary>
/// inverte valore booleano
/// </summary>
/// <param name="isEnt"></param>
/// <returns></returns>
public bool invBool(object valore)
{
bool answ = true;
try
{
answ = !Convert.ToBoolean(valore);
}
catch
{ }
return answ;
}
/// <summary>
/// calcola se sia ancestor la fase
/// </summary>
/// <param name="idxFaseAncest"></param>
/// <returns></returns>
public bool isAncestor(object idxFaseAncest)
{
bool answ = isWritable();
if (answ)
{
int idxFase = -1;
try
{
idxFase = Convert.ToInt32(idxFaseAncest);
}
catch
{ }
answ = (idxFase == 0);
}
return answ;
}
/// <summary>
/// resetta la selezione dei valori in caso di modifiche su altri controlli
/// </summary>
public void resetSelezione()
{
grView.SelectedIndex = -1;
grView.DataBind();
setDetVisibility();
raiseReset();
}
/// <summary>
/// determina dimensioni dell'oggetto spaziatore data la fase
/// </summary>
/// <param name="codFase"></param>
/// <returns></returns>
public Unit widthByCod(object codFase)
{
Unit answ = new Unit(0, UnitType.Pixel);
int livello = 0;
if (codFase != null)
{
// calcolo livello come num punti "." -1...
try
{
string[] array = codFase.ToString().Split('.');
livello = array.Length;
}
catch
{ }
if (livello >= 4)
{
answ = new Unit((livello - 3) * 10, UnitType.Pixel);
}
}
return answ;
}
#endregion Public Methods
}
}