Files
GMW/GMW/WebUserControls/mod_labConsUdc.ascx.cs
T
2017-05-10 16:08:24 +02:00

412 lines
14 KiB
C#

using GMW_data;
using SteamWare;
using System;
using System.Data;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace GMW.WebUserControls
{
public partial class mod_labConsUdc : SteamWare.ApplicationUserControl
{
#region area da NON modificare
#region area protected
protected string _idxGridView;
protected string _idxGridViewExt;
protected string _tabCache;
/// <summary>
/// aggiorna controlli datagrid e numero righe in pagina
/// </summary>
protected override void aggiornaControlliDataGL()
{
base.aggiornaControlliDataGL();
}
/// <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>
/// reset della selezione
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnReset_Click(object sender, EventArgs e)
{
resetSelezione();
}
/// <summary>
/// collega i controlli
/// </summary>
protected override void bindControlli()
{
base.bindControlli();
caricaTabelle();
}
#endregion
#region gestione eventi
public event EventHandler eh_resetSelezione;
//public event EventHandler eh_nuovoValore;
//public event EventHandler eh_selValore;
#endregion
#region public
/// <summary>
/// effettua update del modulo
/// </summary>
public void doUpdate()
{
resetSelezione();
}
#endregion
#endregion
#region area codice variabile
/// <summary>
/// carico le tabelle
/// </summary>
private void caricaTabelle()
{
}
/// <summary>
/// elenco colonne del datagrid
/// </summary>
/// <returns></returns>
protected DataColumnCollection colonneObj()
{
DS_magazzino.RapQualDataTable tabella = new DS_magazzino.RapQualDataTable();
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);
_idxGridView = "UDC_MP";
if (!Page.IsPostBack)
{
checkRblExt();
lblBarcodeConsumoUdcMP.Text = traduci("BarcodeInput");
btnConsumaMP.Text = traduci("btnConsumaMP");
btnConsumaMP.OnClientClick = SteamWare.jsUtils.getCBE("ConfermaConsumoMP");
btnReloadDataRQL.Text = traduci("btnReloadDataRQL");
// calcolo ultimo update AS400...
DateTime lastUpdate = DateTime.Now.AddYears(-2);
try
{
lastUpdate = utils.obj.taAs400.getByStored("stp_consumaMP")[0].DataEsecuzione;
}
catch
{ }
lblLastUpdateAs400.Text = string.Format("{0} {1:dd/MM/yy HH:mm}", traduci("lblLastUpdateAs400"), lastUpdate);
btnSendAs400.Text = traduci("btnSendAs400");
//checkFixOds();
mod_righePag1.numRowPag = 15;
grView.PageSize = mod_righePag1.numRowPag;
}
lblWarning.Visible = true;
lblWarning.Text = memLayer.ML.StringSessionObj("errConsUdc");
memLayer.ML.emptySessionVal("errConsUdc");
mod_righePag1.eh_newNum += mod_righePag1_eh_newNum;
}
/// <summary>
/// aggiornato numero righe datagrid... aggiorno visualizzazione
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void mod_righePag1_eh_newNum(object sender, EventArgs e)
{
grView.PageSize = mod_righePag1.numRowPag;
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
txtBarcode.Focus();
}
/// <summary>
/// segnalo nuovo valore filtro attivo...
/// </summary>
private void checkFixOds()
{
}
/// <summary>
/// aggiorno visualizzazione
/// </summary>
private void updateOdsDaFiltro()
{
grView.DataBind();
}
/// <summary>
/// chiamata post page change gridview
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void grView_PageIndexChanged(object sender, EventArgs e)
{
// sistemazione dell'ods post evento cambio pagina
checkFixOds();
}
/// <summary>
/// chiamata post sort gridview
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void grView_Sorted(object sender, EventArgs e)
{
// sistemazione dell'ods post evento sort
checkFixOds();
}
/// <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, true);
}
/// <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>
/// 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>
/// effettua consumo MP per gli UDC selezionati
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnConsumaMP_Click(object sender, EventArgs e)
{
string UDC = "";
foreach (GridViewRow riga in grView.Rows)
{
if (((CheckBox)riga.FindControl("chkSelect")).Checked && ((CheckBox)riga.FindControl("chkSelect")).Visible)
{
UDC = ((Label)riga.FindControl("lblUDC")).Text;
consumaUdc(UDC);
}
}
grView.DataBind();
}
/// <summary>
/// effettua le procedure di registrazione consumo degli UDC
/// </summary>
/// <param name="UDC"></param>
private void consumaUdc(string UDC)
{
// controllo se l'UDC sia scaricabile (BeneQual !="N")
if (MagClass.magazzino.udcMpHasBenesQual(UDC))
{
// turno: per ora è semplicemente sempre calcolato coi 3 turni 1-2-3
int turnoInt = Convert.ToInt32(1 + Math.Floor(Convert.ToDouble((DateTime.Now.AddHours(-6).TimeOfDay.Hours) / 8)));
string turno = "";
switch (turnoInt)
{
case 1:
turno = "P";
break;
case 2:
turno = "S";
break;
case 3:
turno = "N";
break;
default:
turno = "P";
break;
}
string codTerz = "";
try
{
if (rbl.SelectedValue == "T01")
{
codTerz = ddlExt.SelectedValue;
}
}
catch
{ }
// controllo che UDC non risulti già consumato
if (MagClass.magazzino.udcMpIsConsumabile(UDC))
{
// consumo!
try
{
// registro nuova posizione + X --> - X (scambio da positivo a negativo)
bool fatto = MagClass.magazzino.scaricaUdcMpWip(UDC, Request.UserHostName);
if (fatto)
{
// registro consumo in AS400
utils.obj.taSTP.stp_accodaConsumoUdcMP(UDC, DateTime.Now, turno, rbl.SelectedValue, codTerz);
}
lblWarning.Text = "";
lblWarning.Visible = false;
}
catch (Exception e)
{
httpLog(string.Format("Errore tentando di consumare UDC di MP cod {0}: {1}{2}", UDC, Environment.NewLine, e), tipoLog.EXCEPTION);
}
}
else
{
// mostro errore che è già stato consumato!
lblWarning.Text = traduci("erroreUdcConsumato");
lblWarning.Visible = true;
// log dell'errore
httpLog(string.Format("Errore tentando di consumare UDC di MP cod {0}: risulta già consumato!", UDC), tipoLog.INFO);
}
}
else
{
// mostro errore che non c'è benestare!
lblWarning.Text = traduci("erroreUdcSenzaBenestare");
lblWarning.Visible = true;
// log dell'errore
httpLog(string.Format("Errore tentando di consumare UDC di MP cod {0}: non c'è benestare qualità!", UDC), tipoLog.INFO);
}
}
/// <summary>
/// cambio valore selezionato in tipo consumo
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void rbl_SelectedIndexChanged(object sender, EventArgs e)
{
checkRblExt();
}
private void checkRblExt()
{
// constrollo se è ext mostro testo ext...
if (rbl.SelectedValue == "T01")
{
ddlExt.Visible = true;
}
else
{
ddlExt.Visible = false;
}
}
/// <summary>
/// verifica e scarica UDC scannato da barcode...
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void txtBarcode_TextChanged(object sender, EventArgs e)
{
// verifico se è UDC valido...
if (MagClass.magazzino.checkUDC(txtBarcode.Text.Trim()))
{
// se è valido chiamo consumo...
consumaUdc(txtBarcode.Text.Trim());
}
memLayer.ML.setSessionVal("errConsUdc", lblWarning.Text);
// x velocizzare ricarico pagina...
Response.Redirect(_paginaCorrente);
}
/// <summary>
/// effettua chiamata stored x aggiornare ssu AS400
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnSendAs400_Click(object sender, EventArgs e)
{
utils.obj.taSTP.stp_processaCodaConsumoMP(true);
}
/// <summary>
/// forza il ricaricamento da AS400 i dati per il numero di giorni richiesto
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnReloadDataRQL_Click(object sender, EventArgs e)
{
int numGgPassati = memLayer.ML.confReadInt("numGgToReloadRQ");
// stored 1 : ricarico da AS400
utils.obj.taSTP.stp_batch_RapQual_S01(DateTime.Now.AddDays(-numGgPassati));
// stored 2 aggiorno tabella
string codMagMp = memLayer.ML.confReadString("CodMagMP");
string codMagMpNa = memLayer.ML.confReadString("CodMagMP_NA");
string CodStatoMp = memLayer.ML.confReadString("CodStatoMP");
string CodStatoMpNa = memLayer.ML.confReadString("CodStatoMP-NA");
utils.obj.taSTP.stp_batch_RapQual_S02(codMagMpNa, codMagMp, CodStatoMpNa, CodStatoMp);
// update
resetSelezione();
}
#endregion
}
}