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_adminOrario : BaseUserControl { #region Protected Methods /// /// gestione evento richiesta nuovo valore (mostra footer, ...) /// /// /// protected void btnNew_Click(object sender, EventArgs e) { // reset selezione... resetSelezione(); // inserisco record DataProxy.DP.taAO.insertQuery("0000 (new)", "descrizione"); //update! grView.DataBind(); // sollevo evento nuovo valore... raiseAddNew(); } /// /// reset della selezione /// /// /// protected void btnReset_Click(object sender, EventArgs e) { resetSelezione(); } /// /// elenco colonne del datagrid /// /// protected DataColumnCollection colonneObj() { DataColumnCollection colonne = null; using (DS_Applicazione.AnagOrariDataTable tabella = new DS_Applicazione.AnagOrariDataTable()) { 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 = ""; } } /// /// 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(); } /// /// check licenze in fase di update... /// /// /// 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(); } } } /// /// caricamento /// /// /// protected void Page_Load(object sender, EventArgs e) { grView.PageSize = utils.pageSize; } /// /// 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 /// /// determina se sia eliminabile il record (=non usato) /// /// /// public bool delEnabled(object idxObj) { bool answ = true; // solo se ha diritti scrittura controllo if (idxObj != null) { int trovati = 0; // controllo se ci siano tipo celle associate trovati = DataProxy.DP.taDipendenti.getByCodOrario(idxObj.ToString()).Rows.Count; // controllo se ci sono record correlati... if (trovati > 0) { answ = false; } } return answ; } public void doUpdate() { grView.PageSize = utils.pageSize; grView.DataBind(); } /// /// resetta la selezione dei valori in caso di modifiche su altri controlli /// public void resetSelezione() { grView.SelectedIndex = -1; grView.DataBind(); raiseReset(); } #endregion Public Methods } }