Files
gpw_testci/GPW/WebUserControls/mod_adminProgetti.ascx.cs
2021-03-26 17:17:28 +01:00

523 lines
18 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.WebUserControls
{
public partial class mod_adminProgetti : System.Web.UI.UserControl
{
#region area standard (non modificare)
#region gestione eventi
public event EventHandler eh_resetSelezione;
public event EventHandler eh_nuovoValore;
public event EventHandler eh_selValore;
#endregion
/// <summary>
/// effettua traduzione del lemma
/// </summary>
/// <param name="lemma"></param>
/// <returns></returns>
public string traduci(string lemma)
{
return user_std.UtSn.Traduci(lemma);
}
/// <summary>
/// resetta la selezione dei valori in caso di modifiche su altri controlli
/// </summary>
public void resetSelezione()
{
grView.SelectedIndex = -1;
grView.DataBind();
mod_dettaglioProgetto1.Visible = false;
if (eh_resetSelezione != null)
{
eh_resetSelezione(this, new EventArgs());
}
}
/// <summary>
/// reset della selezione
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnReset_Click(object sender, EventArgs e)
{
resetSelezione();
}
/// <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)
{
// 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...
if (eh_nuovoValore != null)
{
eh_nuovoValore(this, new EventArgs());
}
}
/// <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>
/// 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>
/// 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 = "";
}
}
#endregion
#region area CUSTOM (da modificare)
/// <summary>
/// pagina corrente (URL finale)
/// </summary>
public string _paginaCorrente { get; set; }
/// <summary>
/// determina se siano da visualizzare i progetti già chiusi
/// </summary>
public bool showChiusi
{
get
{
return memLayer.ML.BoolSessionObj("showPrjArch");
}
set
{
memLayer.ML.setSessionVal("showPrjArch", value);
}
}
/// <summary>
/// determina se siano visibili progetti "vuoti" con zero ore caricate quindi
/// </summary>
public bool showVuoti
{
get
{
return memLayer.ML.BoolSessionObj("showPrjZeroH");
}
set
{
memLayer.ML.setSessionVal("showPrjZeroH", value);
}
}
/// <summary>
/// determina se siano visibili SOLO progetti "Starred"
/// </summary>
public bool showOnlyStarred
{
get
{
return memLayer.ML.BoolSessionObj("showPrjStar");
}
set
{
memLayer.ML.setSessionVal("showPrjStar", value);
}
}
/// <summary>
/// caricamento
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load(object sender, EventArgs e)
{
grView.PageSize = utils.pageSize;
if (!Page.IsPostBack)
{
// imposto intervallo date...10 anni...
intervalloDate date = new intervalloDate();
date.fine = DateTime.Now.Date.AddDays(1);
date.inizio = date.fine.AddYears(-10);
mod_periodoAnalisi1.intervalloAnalisi = date;
// svuoto variabili sessione
memLayer.ML.emptySessionVal("idxProgetto_sel");
memLayer.ML.emptySessionVal("idxCli_sel");
filtroCli.ods = odsClienti;
filtroCli.reselFirst();
filtroCli.isChecked = false;
showChiusi = false;
showVuoti = true;
mod_dettaglioProgetto1.Visible = false;
}
filtroCli.eh_selValore += new EventHandler(filtroCli_eh_selValore);
mod_dettaglioProgetto1.eh_nuovoValore += new EventHandler(mod_dettaglioProgetto1_eh_nuovoValore);
}
/// <summary>
/// salva in variabile pagina il nome della pagina corrente
/// </summary>
protected void PagCorrente()
{
Uri MyUrl = Request.Url;
string delimStr = "/";
char[] delimiter = delimStr.ToCharArray();
string[] finalUrl = MyUrl.LocalPath.ToString().Split(delimiter);
int n = finalUrl.Length;
_paginaCorrente = finalUrl[n - 1].ToString();
}
/// <summary>
/// cambiati dati dettaglio (attivo/inattivo)
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void mod_dettaglioProgetto1_eh_nuovoValore(object sender, EventArgs e)
{
doUpdate();
}
/// <summary>
/// selezionato valore, filtro!
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void filtroCli_eh_selValore(object sender, EventArgs e)
{
if (filtroCli.isChecked)
{
memLayer.ML.setSessionVal("idxCli_sel", filtroCli.valoreInt);
}
else
{
memLayer.ML.setSessionVal("idxCli_sel", 0);
}
grView.DataBind();
}
/// <summary>
/// elenco colonne del datagrid
/// </summary>
/// <returns></returns>
protected DataColumnCollection colonneObj()
{
DS_Applicazione.AnagProgettiDataTable tabella = new DS_Applicazione.AnagProgettiDataTable();
DataColumnCollection colonne = tabella.Columns;
return colonne;
}
/// <summary>
/// determina se sia eliminabile il record (=non usato)
/// </summary>
/// <param name="idxMaker"></param>
/// <returns></returns>
public bool delEnabled(object idxObj)
{
bool answ = isWritable();
// solo se ha diritti scrittura controllo
if (answ)
{
int trovati = 0;
// !!!FARE!!!
#if false
// controllo se ci siano tipo celle associate
trovati = MagClass.magazzino.taTipoCella.getByCodMag(memLayer.ML.StringSessionObj("CodCS"), idxObj.ToString()).Rows.Count;
// controllo se ci siano blocchi associati
trovati = trovati + MagClass.magazzino.taBlocchi.getByCodMag(memLayer.ML.StringSessionObj("CodCS"), idxObj.ToString()).Rows.Count;
#endif
// controllo se ci sono record correlati...
if (trovati > 0)
{
answ = false;
}
}
return answ;
}
/// <summary>
/// evento selezione!
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void grView_SelectedIndexChanged(object sender, EventArgs e)
{
memLayer.ML.setSessionVal("idxProgetto_sel", grView.SelectedDataKey["idxProgetto"]);
mod_dettaglioProgetto1.Visible = true;
if (eh_selValore != null)
{
eh_selValore(this, new EventArgs());
}
}
/// <summary>
/// determina se mostrare i progetti archiviati
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void chkShowChiusi_CheckedChanged(object sender, EventArgs e)
{
showChiusi = chkShowChiusi.Checked;
grView.DataBind();
}
/// <summary>
/// salvo in session che il prox comando è clonare...
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void imgDettFasi_Click(object sender, ImageClickEventArgs e)
{
SteamWare.memLayer.ML.setSessionVal("nextObjCommand", "dettFasi");
}
/// <summary>
/// intercetto eventuale update fittizio x rimandare a pagina dett fasi
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void grView_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
// salvo progetto sel
memLayer.ML.setSessionVal("idxProgetto_sel", e.Keys["idxProgetto"]);
// quale comando?
string _comando = "";
if (SteamWare.memLayer.ML.isInSessionObject("nextObjCommand"))
{
_comando = SteamWare.memLayer.ML.StringSessionObj("nextObjCommand");
SteamWare.memLayer.ML.emptySessionVal("nextObjCommand");
}
// verifico il tipo di richiesta (clona o update normale)
switch (_comando)
{
case "dettFasi":
// salvo idxCli...
int idxCli = 0;
try
{
idxCli = DataProxy.DP.taAP.getByIdxPrj(memLayer.ML.IntSessionObj("idxProgetto_sel"))[0].idxCliente;
}
catch
{ }
memLayer.ML.setSessionVal("idxCli_sel", idxCli);
Response.Redirect("fasi.aspx");
// blocco update!
e.Cancel = true;
break;
default:
// faccio update!
break;
}
}
/// <summary>
/// effettua update controllo
/// </summary>
public void doUpdate()
{
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>
/// 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 answ = "badgeStd";
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)
{
answ = "badgeRosso";
}
else if (valoreReal >= valoreWarn)
{
answ = "badgeArancio";
}
else
{
answ = "badgeVerde";
}
}
catch
{
}
return "ui-corner-all " + answ;
}
/// <summary>
/// cambia impsotazione show/hide progetti con ore a zero...
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void chkShowVuoti_CheckedChanged(object sender, EventArgs e)
{
showVuoti = chkShowVuoti.Checked;
grView.DataBind();
}
protected void chkShowOnlyStarred_CheckedChanged(object sender, EventArgs e)
{
showOnlyStarred = chkShowOnlyStarred.Checked;
grView.DataBind();
}
/// <summary>
/// risponde alla domanda se l'utente abbia permesso tipo writable (S) nel permessi2funzione
/// </summary>
/// <returns></returns>
public bool isWritable()
{
bool answ = false;
if (_paginaCorrente == null)
{
PagCorrente();
}
answ = user_std.UtSn.isPageWriteEnabled(_paginaCorrente) && chkLicOk;
return answ;
}
/// <summary>
/// controllo stato licenze!
/// </summary>
public bool chkLicOk
{
get
{
return (licenzeGPW.utentiAttivi < licenzeGPW.licenzeAttive);
}
}
/// <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 (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 = "";
}
}
else
{
// annullo insert se licenze sforate...
e.Cancel = true;
grView.DataBind();
}
}
/// <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)
{
// annullo insert se licenze sforate...
e.Cancel = true;
grView.EditIndex = -1;
grView.DataBind();
}
}
#endregion
}
}