Files
WebGIM/GIM_site/WebUserControls/mod_elencoMtzProg.ascx.cs

538 lines
15 KiB
C#

using GIM_dataLayer;
using SteamWare;
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class mod_elencoMtzProg : ApplicationUserControl
{
#region gestione eventi
public event EventHandler eh_newReq;
public event EventHandler eh_resetSelezione;
public event EventHandler eh_selValore;
public event EventHandler eh_updateDone;
#endregion
protected string _idxGridView;
/// <summary>
/// traduzioni
/// </summary>
protected override void traduciObj()
{
base.traduciObj();
btnShowNew.Text = traduci("btnShowNew");
btnMassEdit.Text = traduci("btnMassEditShow");
btnEditCancel.Text = traduci("btnEditCancel");
btnEditConfirm.Text = traduci("btnEditConfirm");
chkInizioMtzPro.Text = traduci("chkInizioMtzPro");
chkPrior.Text = traduci("chkPrior");
chkSetFermo.Text = traduci("chkSetFermo");
chkImpFermo.Text = traduci("chkImpFermo");
chkTipoGuasto.Text = traduci("chkTipoGuasto");
chkFreq.Text = traduci("lblFreq");
chkCadenza.Text = traduci("lblCadenza");
chkCausale.Text = traduci("lblCausale");
chkDescrMtzPro.Text = traduci("chkDescrMtzPro");
lblIstrMtzPrg.Text = traduci("lblIstrMtzPrg");
}
/// <summary>
/// cambio visibilità pannello new data
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnShowNew_Click(object sender, EventArgs e)
{
modoInsertMtzPrg = !modoInsertMtzPrg;
doUpdate();
// chiamo evento
if (eh_newReq != null)
{
eh_newReq(this, new EventArgs());
}
}
/// <summary>
/// aggiorno il controllo
/// </summary>
public void doUpdate()
{
if (modoInsertMtzPrg)
{
btnShowNew.Text = traduci("btnHideNew");
}
else
{
btnShowNew.Text = traduci("btnShowNew");
}
setBtnEdit();
checkFixOds();
grView.DataBind();
}
/// <summary>
/// reset della selezione
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnReset_Click(object sender, EventArgs e)
{
resetSelezione();
}
/// <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());
}
}
/// <summary>
/// restituisce un testo trimamto a maxChar caratteri
/// </summary>
/// <param name="testo"></param>
/// <param name="maxChar"></param>
/// <returns></returns>
public string trimmaTesto(object _testo, object _maxChar)
{
string answ = "";
string testo = _testo.ToString();
int maxChar = Convert.ToInt32(_maxChar);
if (testo.Length <= maxChar)
{
answ = testo;
}
else
{
answ = string.Format("{0}...", testo.Substring(0, maxChar));
}
return answ;
}
/// <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>
/// 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_mtzProgExpRow riga = (GIM_dataLayer.DS_applicazione.v_mtzProgExpRow)_drv.Row;
if (SteamWare.memLayer.ML.StringSessionObj(_idxGridView) == riga.idxIntPro.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>
/// 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["numIntMtz"]);
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":
// blocco update!
e.Cancel = true;
break;
default:
// faccio update!
break;
}
}
/// <summary>
/// inizializzazione valori di default
/// </summary>
/// <param name="e"></param>
protected override void OnInit(EventArgs e)
{
if (!Page.IsPostBack)
{
checkDate();
hlExportExcel.Text = traduci("hlExportExcel");
hlExportExcel.NavigateUrl = "~/ExcelExportMtzPrev";
modoInsertMtzPrg = false;
doUpdate();
}
base.OnInit(e);
_idxGridView = "idxIntPro";
txtDataInizio.Text = DateTime.Now.ToString("yyyy-MM-dd");
//txtDataInizio.Text = DateTime.Now.ToShortDateString();
txtCadenza.Text = "1";
// determina visibilità edit/insert nuovi interventi
btnShowNew.Visible = isWritable();
btnMassEdit.Visible = isWritable();
}
private void checkDate()
{
// cerco periodo, se non c'è imposto a 1 mese...
intervalloDate _intervallo;
try
{
_intervallo = (intervalloDate)Session["_intervallo"];
}
catch
{
_intervallo = new intervalloDate();
// in base al tipo intervallo (futuro/all) decido cosa mostrare...
_intervallo.fine = DateTime.Now.Subtract(DateTime.Now.TimeOfDay).AddDays(1);
_intervallo.inizio = _intervallo.fine.AddMonths(-1);
Session["_intervallo"] = _intervallo;
Session["_inizio"] = _intervallo.inizio;
Session["_fine"] = _intervallo.fine;
}
}
/// <summary>
/// modalità insert mtz prog
/// </summary>
public bool modoInsertMtzPrg
{
get
{
return memLayer.ML.BoolSessionObj("modoInserMtzPrg");
}
set
{
memLayer.ML.setSessionVal("modoInserMtzPrg", value);
}
}
void mod_filtroMacchina_eh_selValore(object sender, EventArgs e)
{
// chiamo procedura ricostruzione ods con filtri...
checkFixOds();
}
void mod_filtroTipo_eh_selValore(object sender, EventArgs e)
{
// chiamo procedura ricostruzione ods con filtri...
checkFixOds();
}
/// <summary>
/// sistemo filtraggio con valori selezionati
/// </summary>
private void checkFixOds()
{
ods.FilterExpression = "( codMacchina LIKE '%{0}%' OR nomeMacchina LIKE '%{0}%' OR descrizione LIKE '%{0}%' )";
if (memLayer.ML.isInSessionObject("idxTipo_filt"))
{
ods.FilterExpression += " AND (idxTipo = {1})";
}
if (memLayer.ML.isInSessionObject("idxImpianto_filt"))
{
ods.FilterExpression += " AND (idxImpianto = {2})";
}
if (memLayer.ML.isInSessionObject("idxMacchina_filt"))
{
ods.FilterExpression += " AND (idxMacchina = {3})";
}
ods.DataBind();
}
/// <summary>
/// controllo visibilità pannello edit in massa
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnMassEdit_Click(object sender, EventArgs e)
{
pnlMassEdit.Visible = !pnlMassEdit.Visible;
if (pnlMassEdit.Visible)
{
btnMassEdit.Text = traduci("btnMassEditHide");
}
else
{
btnMassEdit.Text = traduci("btnMassEditShow");
}
checkFixOds();
}
/// <summary>
/// seleziona/deseleziona le righe indicate...
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnSelAll_Click(object sender, EventArgs e)
{
// seleziono tutti i valori visibili nel datagrid
CheckBox chkbox = ((CheckBox)sender);
bool isChecked = chkbox.Checked;
if (!isChecked)
{
chkbox.ToolTip = traduci("btnSelAll");
}
else
{
chkbox.ToolTip = traduci("btnDeselAll");
}
foreach (GridViewRow riga in grView.Rows)
{
((CheckBox)riga.FindControl("chkSelect")).Checked = isChecked;
}
}
/// <summary>
/// aggiorna selezione di default
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void ddlPrior_DataBound(object sender, EventArgs e)
{
ddlPrior.SelectedIndex = memLayer.ML.CRI("defPriorMtzPred");
}
/// <summary>
/// aggiorna selezione di default
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void ddlCausale_DataBound(object sender, EventArgs e)
{
ddlCausale.SelectedValue = memLayer.ML.CRS("defCauMtzPred");
}
#region gestione checkBox edit campi
protected void chkInizioMtzPro_CheckedChanged(object sender, EventArgs e)
{
pnlInizio.Visible = chkInizioMtzPro.Checked;
setBtnEdit();
}
protected void chkPrior_CheckedChanged(object sender, EventArgs e)
{
pnlPrior.Visible = chkPrior.Checked;
setBtnEdit();
}
protected void chkSetFermo_CheckedChanged(object sender, EventArgs e)
{
pnlSetFermo.Visible = chkSetFermo.Checked;
setBtnEdit();
}
protected void chkTipoGuasto_CheckedChanged(object sender, EventArgs e)
{
pnlTipoGuasto.Visible = chkTipoGuasto.Checked;
setBtnEdit();
}
protected void chkFreq_CheckedChanged(object sender, EventArgs e)
{
pnlFreq.Visible = chkFreq.Checked;
setBtnEdit();
}
protected void chkCadenza_CheckedChanged(object sender, EventArgs e)
{
pnlCadenza.Visible = chkCadenza.Checked;
setBtnEdit();
}
protected void chkCausale_CheckedChanged(object sender, EventArgs e)
{
pnlCausale.Visible = chkCausale.Checked;
setBtnEdit();
}
protected void chkDescrMtzPro_CheckedChanged(object sender, EventArgs e)
{
pnlDescrMtzPro.Visible = chkDescrMtzPro.Checked;
setBtnEdit();
}
/// <summary>
/// sistema btn edit (attivi se almeno 1 valore checked)
/// </summary>
protected void setBtnEdit()
{
bool saveEnabled = false;
if (chkCadenza.Checked || chkDescrMtzPro.Checked || chkFreq.Checked || chkTipoGuasto.Checked || chkInizioMtzPro.Checked || chkPrior.Checked || chkSetFermo.Checked)
{
saveEnabled = true;
}
btnEditConfirm.Enabled = saveEnabled;
btnEditCancel.Enabled = saveEnabled;
}
#endregion
/// <summary>
/// applica edit a tutte le righe selezionate
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnEditConfirm_Click(object sender, EventArgs e)
{
// controllo quali righe siano checked
DS_applicazione.MtzProgrammataRow rigaMtzPro;
int idxIntPro;
foreach (GridViewRow riga in grView.Rows)
{
if (((CheckBox)riga.FindControl("chkSelect")).Checked)
{
try
{
// leggo il record della riga
idxIntPro = Convert.ToInt32(((Label)riga.FindControl("lblidxIntPro")).Text);
rigaMtzPro = (DS_applicazione.MtzProgrammataRow)mtzProgr.obj.taMtzProg.getByKey(idxIntPro)[0];
// controllo 1:1 i valori che si vogliono sovrascrivere
if (chkInizioMtzPro.Checked)
{
rigaMtzPro.inizio = Convert.ToDateTime(txtDataInizio.Text);
}
if (chkPrior.Checked)
{
rigaMtzPro.idxPriorita = Convert.ToInt32(ddlPrior.SelectedValue);
}
if (chkSetFermo.Checked)
{
rigaMtzPro.isFermo = chkSetFermo.Checked;
}
if (chkTipoGuasto.Checked)
{
rigaMtzPro.idxTipo = Convert.ToInt32(ddlTipo.Text);
}
if (chkFreq.Checked)
{
rigaMtzPro.codFrequenza = ddlFreq.SelectedValue;
}
if (chkCadenza.Checked)
{
rigaMtzPro.cadenza = Convert.ToInt32(txtCadenza.Text);
}
if (chkDescrMtzPro.Checked)
{
rigaMtzPro.descrizione = txtDescrizione.Text;
}
if (chkCausale.Checked)
{
rigaMtzPro.idxCausale = Convert.ToInt32(ddlCausale.SelectedValue);
}
// aggiorno i valori!
mtzProgr.obj.taMtzProg.updateQuery(rigaMtzPro.idxIntPro, rigaMtzPro.inizio, rigaMtzPro.codFrequenza, rigaMtzPro.cadenza, rigaMtzPro.descrizione, rigaMtzPro.idxPriorita, rigaMtzPro.isFermo, rigaMtzPro.idxTipo, rigaMtzPro.idxCausale);
}
catch
{ }
}
}
// a questo punto aggiorno e ricalcolo pending!
mtzProgr.obj.processaCodaMtzPro();
ods.DataBind();
grView.DataBind();
UpdatePanel2.Update();
// aggiorno
doUpdate();
// chiamo evento
if (eh_updateDone != null)
{
eh_updateDone(this, new EventArgs());
}
}
/// <summary>
/// annulla edit (deseleziona checkbox...)
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnEditCancel_Click(object sender, EventArgs e)
{
chkCadenza.Checked = false;
chkDescrMtzPro.Checked = false;
chkFreq.Checked = false;
chkInizioMtzPro.Checked = false;
chkPrior.Checked = false;
chkSetFermo.Checked = false;
chkTipoGuasto.Checked = false;
pnlCadenza.Visible = false;
pnlDescrMtzPro.Visible = false;
pnlFreq.Visible = false;
pnlInizio.Visible = false;
pnlPrior.Visible = false;
pnlSetFermo.Visible = false;
pnlTipoGuasto.Visible = false;
}
/// <summary>
/// update post cambio pagina
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void grView_PageIndexChanged(object sender, EventArgs e)
{
doUpdate();
}
/// <summary>
/// update post delete
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void grView_RowDeleted(object sender, GridViewDeletedEventArgs e)
{
doUpdate();
}
protected void grView_Sorted(object sender, EventArgs e)
{
doUpdate();
}
}