7d289a3b64
pulizia codice...
631 lines
19 KiB
C#
631 lines
19 KiB
C#
using SteamWare;
|
|
using System;
|
|
using System.Data;
|
|
using System.Web.UI;
|
|
using System.Web.UI.WebControls;
|
|
|
|
public partial class mod_macchine : ApplicationUserControl
|
|
{
|
|
#region area da NON modificare
|
|
|
|
#region area protected
|
|
|
|
protected string _idxGridView;
|
|
protected string _idxGridViewExt;
|
|
protected bool _showNewBtn = false;
|
|
|
|
/// <summary>
|
|
/// imposta errore non cancellabilità per record correlati
|
|
/// </summary>
|
|
protected void setNoDeletableErrorMessage()
|
|
{
|
|
// mostro avviso di non cancellabilità...
|
|
lblWarning.Text = traduci("notDeletable_hasChild");
|
|
lblWarning.Visible = true;
|
|
grView.DataBind();
|
|
}
|
|
/// <summary>
|
|
/// esegue cancellazione record
|
|
/// </summary>
|
|
protected void doDelete()
|
|
{
|
|
// posso cancellare...
|
|
lblWarning.Visible = false;
|
|
ods.Delete();
|
|
}
|
|
/// <summary>
|
|
/// Valida la cancellazione per i dati mostrati dal gridView
|
|
/// richiede sia preventivamentedichiarato _idxGridView
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected virtual void validaDelete(object sender, ObjectDataSourceMethodEventArgs e)
|
|
{
|
|
int idx = Convert.ToInt32(e.InputParameters[string.Format("Original_{0}", _idxGridView)]);
|
|
if (objIsNotRelated(idx))
|
|
{
|
|
// annullo cancellazione...
|
|
e.Cancel = true;
|
|
// seleziono record... metto in session valore idx e poi ridisegno...
|
|
SteamWare.memLayer.ML.setSessionVal(_idxGridView, idx);
|
|
setNoDeletableErrorMessage();
|
|
}
|
|
else
|
|
{
|
|
doDelete();
|
|
}
|
|
}
|
|
|
|
/// <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>
|
|
/// aggiorna controlli datagrid e numero righe in pagina
|
|
/// </summary>
|
|
protected override void aggiornaControlliDataGL()
|
|
{
|
|
base.aggiornaControlliDataGL();
|
|
//grViewShort.PageSize = _righeDataGridAnagr;
|
|
//grView.PageSize = _righeDataGridMed;
|
|
}
|
|
/// <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>
|
|
/// traduce gli header delle colonne
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void grViewShort_DataBound(object sender, EventArgs e)
|
|
{
|
|
if (grViewShort.Rows.Count > 0)
|
|
{
|
|
LinkButton lb;
|
|
// aggiorno gli headers
|
|
foreach (TableCell cella in grViewShort.HeaderRow.Cells)
|
|
{
|
|
try
|
|
{
|
|
lb = (LinkButton)cella.Controls[0];
|
|
lb.Text = traduci(lb.Text);
|
|
}
|
|
catch
|
|
{ }
|
|
}
|
|
int totRecord = grViewShort.Rows.Count + grViewShort.PageSize * (grViewShort.PageCount - 1);
|
|
lblNumRec.Text = string.Format("{0} records of ~ {1}", grViewShort.Rows.Count, totRecord);
|
|
}
|
|
else
|
|
{
|
|
lblNumRec.Text = "";
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// gestione evento richeista 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>
|
|
/// reset della selezione
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void btnReset_Click(object sender, EventArgs e)
|
|
{
|
|
resetSelezione();
|
|
}
|
|
/// <summary>
|
|
/// reset della selezione
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void btnResetShort_Click(object sender, EventArgs e)
|
|
{
|
|
grViewShort.SelectedIndex = -1;
|
|
grViewShort.DataBind();
|
|
lblWarning.Visible = false;
|
|
}
|
|
/// <summary>
|
|
/// gestione cambio selezione valore
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void grView_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
// salvo in session il valore selezionato...
|
|
SteamWare.memLayer.ML.setSessionVal(string.Format("{0}_sel", _idxGridView), grView.SelectedValue);
|
|
// sollevo evento nuovo valore...
|
|
if (eh_selValore != null)
|
|
{
|
|
eh_selValore(this, new EventArgs());
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// resetta la selezione dei valori in caso di modifiche su altri controlli
|
|
/// </summary>
|
|
public void resetSelezione()
|
|
{
|
|
SteamWare.memLayer.ML.emptySessionVal(string.Format("{0}_sel", _idxGridView));
|
|
grView.SelectedIndex = -1;
|
|
grView.DataBind();
|
|
lblWarning.Visible = false;
|
|
if (eh_resetSelezione != null)
|
|
{
|
|
eh_resetSelezione(this, new EventArgs());
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region gestione eventi
|
|
|
|
public event EventHandler eh_resetSelezione;
|
|
public event EventHandler eh_nuovoValore;
|
|
public event EventHandler eh_selValore;
|
|
|
|
#endregion
|
|
|
|
#region public
|
|
|
|
/// <summary>
|
|
/// definisce visibilità btnNew
|
|
/// </summary>
|
|
public bool showNewBtn
|
|
{
|
|
get
|
|
{
|
|
return _showNewBtn;
|
|
}
|
|
set
|
|
{
|
|
_showNewBtn = value;
|
|
}
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
#region area codice variabile
|
|
|
|
/// <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)
|
|
{
|
|
//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("cal_{0}", nomeCol)) != null)
|
|
{
|
|
tipoColonna = "calTextBox";
|
|
}
|
|
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";
|
|
}
|
|
else if (grView.FooterRow.FindControl(string.Format("selAjax_{0}", nomeCol)) != null)
|
|
{
|
|
tipoColonna = "selAjax";
|
|
}
|
|
// 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 "calTextBox":
|
|
e.InputParameters[nomeCol] = Convert.ToDateTime(((TextBox)grView.FooterRow.FindControl(string.Format("cal_{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("dl{0}", nomeCol))).Checked;
|
|
break;
|
|
case "selAjax":
|
|
e.InputParameters[nomeCol] = ((mod_selettore_ajax)grView.FooterRow.FindControl(string.Format("selAjax_{0}", nomeCol))).valore;
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
tipoColonna = "";
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// devo mostrare meno colonne
|
|
/// </summary>
|
|
protected bool _dispLessCol = false;
|
|
/// <summary>
|
|
/// effettua update del modulo
|
|
/// </summary>
|
|
public void doUpdate()
|
|
{
|
|
resetSelezione();
|
|
updateOdsDaFiltro();
|
|
grView.SelectedIndex = -1;
|
|
grView.DataBind();
|
|
grViewShort.SelectedIndex = -1;
|
|
grViewShort.DataBind();
|
|
}
|
|
|
|
/// <summary>
|
|
/// verifica complessiva non esistenza record child
|
|
/// </summary>
|
|
/// <param name="idxObj"></param>
|
|
/// <returns></returns>
|
|
protected bool objIsNotRelated(object idxObj)
|
|
{
|
|
bool answ = false;
|
|
try
|
|
{
|
|
answ = (TA_app.obj.taInterventiMtz.getByIdxMacchina(Convert.ToInt32(idxObj)).Rows.Count == 0);
|
|
}
|
|
catch
|
|
{ }
|
|
return answ;
|
|
}
|
|
/// <summary>
|
|
/// elenco colonne del datagrid
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
protected DataColumnCollection colonneObj()
|
|
{
|
|
GIM_dataLayer.DS_applicazione.v_macchineDataTable tabella = new GIM_dataLayer.DS_applicazione.v_macchineDataTable();
|
|
DataColumnCollection colonne = tabella.Columns;
|
|
return colonne;
|
|
}
|
|
/// <summary>
|
|
/// inizializzazione valori di default
|
|
/// </summary>
|
|
/// <param name="e"></param>
|
|
protected override void OnInit(EventArgs e)
|
|
{
|
|
base.OnInit(e);
|
|
mod_filtroImpianti.eh_selValore += new EventHandler(mod_filtroImpianti_eh_selValore);
|
|
if (!Page.IsPostBack)
|
|
{
|
|
mod_filtroImpianti.ods = odsImpianti;
|
|
}
|
|
_idxGridView = "idxmacchina";
|
|
// determino quale grView a seconda del tipo visibilità colonne...
|
|
if (_dispLessCol)
|
|
{
|
|
grView.Visible = false;
|
|
grViewShort.Visible = true;
|
|
}
|
|
else
|
|
{
|
|
grView.Visible = true;
|
|
grViewShort.Visible = false;
|
|
}
|
|
updateOdsDaFiltro();
|
|
}
|
|
|
|
/// <summary>
|
|
/// aggiorna visualizzazioni varie
|
|
/// </summary>
|
|
private void aggiornaAll()
|
|
{
|
|
// imposto visibilità filtro in base a tipo controllo
|
|
if (vistaModulo == tipoVistaMod.selezione)
|
|
{
|
|
mod_filtroImpianti.Visible = false;
|
|
}
|
|
else
|
|
{
|
|
mod_filtroImpianti.Visible = true;
|
|
}
|
|
}
|
|
|
|
void mod_filtroImpianti_eh_selValore(object sender, EventArgs e)
|
|
{
|
|
if (mod_filtroImpianti.valoreInt != 0)
|
|
{
|
|
// salvo il valore selezionato...
|
|
idxImpiantoSel = mod_filtroImpianti.valoreInt;
|
|
}
|
|
doUpdate();
|
|
}
|
|
/// <summary>
|
|
/// verifica e sistema il filtro dell'ods...
|
|
/// </summary>
|
|
private void updateOdsDaFiltro()
|
|
{
|
|
string filterExpr = " (codMacchina LIKE '%{0}%' OR nomeMacchina LIKE '%{0}%' OR modello LIKE '%{0}%' OR matricola LIKE '%{0}%' OR descrImpianto LIKE '%{0}%') ";
|
|
if (vistaModulo == tipoVistaMod.selezione || (mod_filtroImpianti.Visible && mod_filtroImpianti.valore != "*"))
|
|
{
|
|
filterExpr += " AND idxImpianto = {1} ";
|
|
}
|
|
ods.FilterExpression = filterExpr;
|
|
}
|
|
/// <summary>
|
|
/// setta selected alla riga il cui valore key è in session
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void grView_RowDataBound(object sender, GridViewRowEventArgs e)
|
|
{
|
|
// se riga di dati...
|
|
if (e.Row.RowType == DataControlRowType.DataRow)
|
|
{
|
|
// ottengo la riga tipizzata...
|
|
System.Data.DataRowView _drv = (System.Data.DataRowView)e.Row.DataItem;
|
|
GIM_dataLayer.DS_applicazione.v_macchineRow riga = (GIM_dataLayer.DS_applicazione.v_macchineRow)_drv.Row;
|
|
if (SteamWare.memLayer.ML.StringSessionObj(_idxGridView) == riga.idxImpianto.ToString())
|
|
{
|
|
grView.SelectedIndex = e.Row.RowIndex;
|
|
// salvo in session il valore selezionato...
|
|
SteamWare.memLayer.ML.setSessionVal(string.Format("{0}_sel", _idxGridView), SteamWare.memLayer.ML.StringSessionObj(_idxGridView));
|
|
// sollevo evento nuovo valore...
|
|
if (eh_selValore != null)
|
|
{
|
|
eh_selValore(this, new EventArgs());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// svuoto da cache post update
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void ods_Updated(object sender, ObjectDataSourceStatusEventArgs e)
|
|
{
|
|
// svuoto da cache...
|
|
doUpdate();
|
|
}
|
|
/// <summary>
|
|
/// gestione evento inserimento nuovo record standard (se ZERO presenti)
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void btnNewFromEmpty_Click(object sender, EventArgs e)
|
|
{
|
|
// reset selezione...
|
|
resetSelezione();
|
|
// i primi valori ("0") di default sono "ND"... li inserisco come standard...
|
|
string codMacc = memLayer.ML.confReadString("defaultCodMacc");
|
|
TA_app.obj.taMacchine.Insert(idxImpiantoSel, codMacc, memLayer.ML.confReadString("newMacchina"), memLayer.ML.confReadString("newModello"), "", DateTime.Now.Year, 0, 0, DateTime.Today, DateTime.Today.AddYears(10));
|
|
//doUpdate();
|
|
// sollevo evento nuovo valore...
|
|
if (eh_nuovoValore != null)
|
|
{
|
|
eh_nuovoValore(this, new EventArgs());
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// salvo in session che il prox comando è clonare...
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void imgClona_Click(object sender, ImageClickEventArgs e)
|
|
{
|
|
SteamWare.memLayer.ML.setSessionVal("nextObjCommand", "clonaObj");
|
|
}
|
|
/// <summary>
|
|
/// in caso di aggiornamento verifico se sia salvato un comando clona...
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void grView_RowUpdating(object sender, GridViewUpdateEventArgs e)
|
|
{
|
|
// carico l'idx dell'oggetto
|
|
int _idx = Convert.ToInt32(e.Keys["idxMacchina"]);
|
|
string _comando = "";
|
|
if (SteamWare.memLayer.ML.isInSessionObject("nextObjCommand"))
|
|
{
|
|
_comando = SteamWare.memLayer.ML.StringSessionObj("nextObjCommand");
|
|
SteamWare.memLayer.ML.emptySessionVal("nextObjCommand");
|
|
}
|
|
// verifico il tipo di richiesta (up/down level, clona o update normale
|
|
switch (_comando)
|
|
{
|
|
case "clonaObj":
|
|
TA_app.obj.taMacchine.sp_clonaMacchina(_idx);
|
|
grView.EditIndex = -1;
|
|
grView.DataBind();
|
|
// blocco update!
|
|
e.Cancel = true;
|
|
break;
|
|
default:
|
|
// faccio update!
|
|
break;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// determina se sia abilitata la cancellazione della macchina
|
|
/// </summary>
|
|
public bool isDelEnabled(object cosa, object idx)
|
|
{
|
|
bool answ = isWritable();
|
|
if (answ)
|
|
{
|
|
answ = false;
|
|
// controllo se ci siano record correlati...
|
|
if (objIsNotRelated(idx))
|
|
{
|
|
answ = isVisible(cosa);
|
|
}
|
|
else
|
|
{
|
|
answ = false;
|
|
}
|
|
}
|
|
return answ;
|
|
}
|
|
/// <summary>
|
|
/// indica il valore dell'impianto filtrato in visualizzazione
|
|
/// </summary>
|
|
public int idxImpiantoSel
|
|
{
|
|
get
|
|
{
|
|
int answ = 1;
|
|
try
|
|
{
|
|
answ = Convert.ToInt32(lblImpianto.Text);
|
|
}
|
|
catch
|
|
{
|
|
answ = 1;
|
|
}
|
|
return answ;
|
|
}
|
|
set
|
|
{
|
|
lblImpianto.Text = value.ToString();
|
|
aggiornaAll();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// definisce se mostrare meno colonne (per funzione MOVE delle macchine tra diversi impianti)
|
|
/// </summary>
|
|
public bool dispLessCol
|
|
{
|
|
get
|
|
{
|
|
return _dispLessCol;
|
|
}
|
|
set
|
|
{
|
|
_dispLessCol = value;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// definisce se mostrare o meno una colonna...
|
|
/// </summary>
|
|
public bool mostraColonna
|
|
{
|
|
get
|
|
{
|
|
return !_dispLessCol;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// restituisce idx della macchina selezionata nel grVIew versione "short"
|
|
/// </summary>
|
|
public int idxMacchinaSel
|
|
{
|
|
get
|
|
{
|
|
int answ = -1;
|
|
try
|
|
{
|
|
answ = Convert.ToInt32(grViewShort.SelectedValue);
|
|
}
|
|
catch
|
|
{ }
|
|
return answ;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// cambio pagina...
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void grView_PageIndexChanged(object sender, EventArgs e)
|
|
{
|
|
doUpdate();
|
|
}
|
|
/// <summary>
|
|
/// sort!
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void grView_Sorted(object sender, EventArgs e)
|
|
{
|
|
doUpdate();
|
|
}
|
|
|
|
#endregion
|
|
|
|
protected void grView_RowEditing(object sender, GridViewEditEventArgs e)
|
|
{
|
|
doUpdate();
|
|
}
|
|
|
|
protected void grView_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
|
|
{
|
|
doUpdate();
|
|
}
|
|
|
|
} |