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; using System.ServiceModel; using Newtonsoft.Json; namespace GPW_Admin.WebUserControls { public class filtroProj { #region Public Constructors /// /// Init con valori specifici /// /// /// /// /// /// /// public filtroProj(bool fGrp, bool fCli, intervalloDate interv, bool onlStar, bool showA, bool showE) { this.filtGrp = fGrp; this.filtCli = fCli; this.intAnalys = interv; this.onlyStarred = onlStar; this.showArch = showA; this.showEmpty = showE; } /// /// Init con valori default /// public filtroProj() { filtGrp = false; filtCli = false; // imposto intervallo dal 2000.01.01... intervalloDate date = new intervalloDate(); date.fine = DateTime.Now.Date.AddDays(1); date.inizio = new DateTime(2000, 1, 1); onlyStarred = false; intAnalys = date; showArch = false; showEmpty = true; } #endregion Public Constructors #region Public Properties public bool filtCli { get; set; } public bool filtGrp { get; set; } public intervalloDate intAnalys { get; set; } public bool onlyStarred { get; set; } public bool showArch { get; set; } public bool showEmpty { get; set; } #endregion Public Properties } public partial class mod_adminProgetti : BaseUserControl { #region Protected Properties /// /// Filtro attivo (formato OBJ) salvato in redis x utente /// protected filtroProj currFiltProj { get { string redKey = memLayer.ML.redHash($"currFiltProj:{user_std.UtSn.userNameAD.Replace("\\", ":")}"); filtroProj answ = new filtroProj(); string rawData = memLayer.ML.getRSV(redKey); if (!string.IsNullOrEmpty(rawData)) { try { answ = JsonConvert.DeserializeObject(rawData); } catch { } } else { } return answ; } set { string redKey = memLayer.ML.redHash($"currFiltProj:{user_std.UtSn.userNameAD.Replace("\\", ":")}"); string rawData = JsonConvert.SerializeObject(value); memLayer.ML.setRSV(redKey, rawData); } } #endregion Protected Properties #region Public Properties /// /// determina se siano da visualizzare i progetti già chiusi /// public bool showArchiviati { get { return memLayer.ML.BoolSessionObj("showPrjArch"); } set { memLayer.ML.setSessionVal("showPrjArch", value); chkShowChiusi.Checked = value; } } /// /// determina se siano visibili SOLO progetti "Starred" /// public bool showOnlyStarred { get { return memLayer.ML.BoolSessionObj("showPrjStar"); } set { memLayer.ML.setSessionVal("showPrjStar", value); chkShowOnlyStarred.Checked = value; } } /// /// determina se siano visibili progetti "vuoti" con zero ore caricate quindi /// public bool showVuoti { get { return memLayer.ML.BoolSessionObj("showPrjZeroH"); } set { memLayer.ML.setSessionVal("showPrjZeroH", value); chkShowVuoti.Checked = value; } } #endregion Public Properties #region Private Methods /// /// verifica vetodi ricalcolo in REDIS, se non ci fosse --> ricalcola! /// private void checkRefresh() { string vetoHash = memLayer.ML.redHash($"VetoProjRefresh"); string vetoRefresh = memLayer.ML.getRSV(vetoHash); if (string.IsNullOrEmpty(vetoRefresh)) { // effettua refresh SOLO ATTIVI DataProxy.DP.taAP.doSummary_Update(0, "", 0, false); // imposto veto 120 min int vetoRicalcProj = memLayer.ML.CRI("vetoRicalcProj") > 0 ? memLayer.ML.CRI("vetoRicalcProj") : 60; memLayer.ML.setRSV(vetoHash, $"Last Update {DateTime.Now:yyyy.MM.dd HH:mm:ss}", vetoRicalcProj * 60); } } /// /// selezionato valore, filtro! /// /// /// private 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); } // salvo! var tempFilt = currFiltProj; tempFilt.filtCli = filtroCli.isChecked; currFiltProj = tempFilt; grView.DataBind(); } /// /// selezionato valore, filtro! /// /// /// private void filtroGrp_eh_selValore(object sender, EventArgs e) { if (filtroGrp.isChecked) { memLayer.ML.setSessionVal("gruppo_sel", filtroGrp.valore); } else { memLayer.ML.setSessionVal("gruppo_sel", ""); } // salvo! var tempFilt = currFiltProj; tempFilt.filtGrp = filtroGrp.isChecked; currFiltProj = tempFilt; grView.DataBind(); } /// /// cambiati dati dettaglio (attivo/inattivo) /// /// /// private void mod_dettaglioProgetto1_eh_nuovoValore(object sender, EventArgs e) { doUpdate(); } /// /// resetta filtraggio /// private void resetFilter() { // svuoto variabili sessione memLayer.ML.emptySessionVal("idxProgetto_sel"); memLayer.ML.emptySessionVal("idxCli_sel"); // genero un nuovo oggetto di default currFiltProj = new filtroProj(); setupFilter(currFiltProj); } private void setupFilter(filtroProj currFilt) { // imposto showArchiviati = currFilt.showArch; showVuoti = currFilt.showEmpty; showOnlyStarred = currFilt.onlyStarred; filtroCli.isChecked = currFilt.filtCli; filtroGrp.isChecked = currFilt.filtGrp; // se deselezionato --> svuoto if (!currFilt.filtGrp) { filtroGrp.valore = ""; } if (!currFilt.filtCli) { filtroCli.valore = ""; } // salvo ulteriori valori filtroGrp.ods = odsGruppi; filtroCli.ods = odsClienti; currFiltProj = currFilt; grView.DataBind(); } #endregion Private Methods #region Protected Methods /// /// gestione evento richiesta nuovo valore (mostra footer, ...) /// /// /// 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... raiseAddNew(); } /// /// reset della selezione /// /// /// protected void btnReset_Click(object sender, EventArgs e) { resetSelezione(); } /// /// determina se mostrare i progetti archiviati /// /// /// protected void chkShowChiusi_CheckedChanged(object sender, EventArgs e) { showArchiviati = chkShowChiusi.Checked; var tempFilt = currFiltProj; tempFilt.showArch = chkShowChiusi.Checked; currFiltProj = tempFilt; grView.DataBind(); filtroCli.ods = odsClienti; } protected void chkShowOnlyStarred_CheckedChanged(object sender, EventArgs e) { showOnlyStarred = chkShowOnlyStarred.Checked; var tempFilt = currFiltProj; tempFilt.onlyStarred = chkShowOnlyStarred.Checked; currFiltProj = tempFilt; grView.DataBind(); } /// /// cambia impsotazione show/hide progetti con ore a zero... /// /// /// protected void chkShowVuoti_CheckedChanged(object sender, EventArgs e) { showVuoti = chkShowVuoti.Checked; var tempFilt = currFiltProj; tempFilt.showEmpty = chkShowVuoti.Checked; currFiltProj = tempFilt; grView.DataBind(); } /// /// elenco colonne del datagrid /// /// protected DataColumnCollection colonneObj() { DataColumnCollection colonne = null; using (DS_Applicazione.AnagProgettiDataTable tabella = new DS_Applicazione.AnagProgettiDataTable()) { colonne = tabella.Columns; } return colonne; } /// /// traduce gli header delle colonne /// /// /// 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 = ""; } } /// /// intercetto eventuale update fittizio x rimandare a pagina dett fasi /// /// /// protected void grView_RowUpdating(object sender, GridViewUpdateEventArgs e) { if (e != null) { // 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); // preseleziono filtro cliente... var tempFilt = currFiltProj; tempFilt.filtCli = true; currFiltProj = tempFilt; filtroCli.valore = $"{idxCli}"; Response.Redirect("fasi"); // blocco update! e.Cancel = true; break; default: // faccio update! break; } } } /// /// evento selezione! /// /// /// protected void grView_SelectedIndexChanged(object sender, EventArgs e) { memLayer.ML.setSessionVal("idxProgetto_sel", grView.SelectedDataKey["idxProgetto"]); mod_dettaglioProgetto1.Visible = true; raiseEvent(); } /// /// annulla inserimento nuovo valore da footer /// /// /// protected void lblCanc_click(object sender, EventArgs e) { // annullo inserimento: nascondo footer, bind controlli... grView.FooterRow.Visible = false; } /// /// inserisce nuovo valore da footer /// /// /// protected void lblIns_click(object sender, EventArgs e) { // click su inserimento, chiamo il metodo insert dell'ObjectDataSource ods.Insert(); } /// /// salvo in session che il prox comando è andare a dettaglio... /// /// /// protected void lbtDettFasi_Click(object sender, EventArgs e) { memLayer.ML.setSessionVal("nextObjCommand", "dettFasi"); } protected void lbtForceUpdate_Click(object sender, EventArgs e) { // effettua refresh DI TUTTI (anche archiviati) DataProxy.DP.taAP.doSummary_Update(0, "", 0, true); } protected void lbtResetFilt_Click(object sender, EventArgs e) { resetFilter(); } /// /// check licenze in fase di update... /// /// /// protected void ods_Updating(object sender, ObjectDataSourceMethodEventArgs e) { if (e != null) { if (!licenzeGPW.checkLicenze) { // annullo insert se licenze sforate... e.Cancel = true; grView.EditIndex = -1; grView.DataBind(); } } } /// /// caricamento /// /// /// protected void Page_Load(object sender, EventArgs e) { grView.PageSize = utils.pageSize; if (!Page.IsPostBack) { // imposto filtro (precedente o da zero) setupFilter(currFiltProj); mod_dettaglioProgetto1.Visible = false; } filtroGrp.eh_selValore += new EventHandler(filtroGrp_eh_selValore); filtroCli.eh_selValore += new EventHandler(filtroCli_eh_selValore); mod_dettaglioProgetto1.eh_nuovoValore += new EventHandler(mod_dettaglioProgetto1_eh_nuovoValore); checkRefresh(); } /// /// recupera i dati di un nuovo record contenuti nel footer di un gridView; /// questi devono esses opportunamente nominati (es: txt{0}, dl{0}, ...) /// /// /// 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 = ""; } } else { // annullo insert se licenze sforate... e.Cancel = true; grView.DataBind(); } } } #endregion Protected Methods #region Public Methods /// /// restituisce una classe css a seconda dei valori passati: /// green: bdgt > real /// orange: real > bdgt*warning /// red: real > bdgt /// std: errore... /// /// /// /// 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 table-{specClass} border border-{specClass} rounded"; } /// /// Determina se sia eliminabile il record (=non ha ore caricate ne fasi) /// /// /// public bool delEnabled(object totOre, object idxProj) { bool answ = isWritable(); // solo se ha diritti scrittura controllo if (answ && totOre != null && idxProj !=null) { double numOre = 0; _ = Double.TryParse($"{totOre}", out numOre); answ = (numOre == 0); // se fosse true --> procedo con controllo fasi if (answ) { int idxProgetto = 0; _ = int.TryParse($"{idxProj}", out idxProgetto); answ = !hasChildObj(idxProgetto); } } return answ; } /// /// Determina se abbia child obj --> NON eliminabile /// /// /// public bool hasChildObj(int idxProj) { bool answ = false; string redKey = memLayer.ML.redHash($"projHasChildObj:{idxProj}"); // cerco inc ache redis... string rawData = memLayer.ML.getRSV(redKey); if (rawData == null) { int trovati = DataProxy.DP.taAF.getByIdxProgetto(idxProj).Count; answ = (trovati > 0); memLayer.ML.setRSV(redKey, $"{answ}", 60 * 5); } else { bool.TryParse(rawData, out answ); } return answ; } /// /// effettua update controllo /// public void doUpdate() { grView.PageSize = utils.pageSize; resetSelezione(); } /// /// inverte valore booleano /// /// /// public bool invBool(object valore) { bool answ = true; try { answ = !Convert.ToBoolean(valore); } catch { } return answ; } /// /// resetta la selezione dei valori in caso di modifiche su altri controlli /// public void resetSelezione() { grView.SelectedIndex = -1; grView.DataBind(); mod_dettaglioProgetto1.Visible = false; raiseReset(); } #endregion Public Methods } }