550 lines
15 KiB
C#
550 lines
15 KiB
C#
using AppData;
|
|
using SteamWare;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using System.Web.UI;
|
|
|
|
namespace C_TRACK
|
|
{
|
|
public partial class barcode : System.Web.UI.Page
|
|
{
|
|
/// <summary>
|
|
/// Codice Operatore
|
|
/// </summary>
|
|
public string CodOpr
|
|
{
|
|
get
|
|
{
|
|
return memLayer.ML.StringSessionObj("CodOpr");
|
|
}
|
|
set
|
|
{
|
|
memLayer.ML.setSessionVal("CodOpr", value);
|
|
memLayer.ML.emptySessionVal("NomeOpr");
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Codice postazione di lavoro
|
|
/// </summary>
|
|
public string CodPost
|
|
{
|
|
get
|
|
{
|
|
return memLayer.ML.StringSessionObj("CodPost");
|
|
}
|
|
set
|
|
{
|
|
memLayer.ML.setSessionVal("CodPost", value);
|
|
memLayer.ML.emptySessionVal("DescPost");
|
|
}
|
|
}
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
{
|
|
|
|
if (!Page.IsPostBack)
|
|
{
|
|
// Crea stopwatch.
|
|
Stopwatch stopwatch = new Stopwatch();
|
|
// Avvio...
|
|
stopwatch.Start();
|
|
traduciObj();
|
|
// registro che i valori in cache sono scaduti...
|
|
lastDataRefresh = DateTime.Now.AddDays(-1);
|
|
numDD = memLayer.ML.CRI("numDD");
|
|
cacheValSec = memLayer.ML.CRI("cacheValSec");
|
|
// registro
|
|
stopwatch.Stop();
|
|
lastUpdDuration = stopwatch.Elapsed;
|
|
}
|
|
checkRequisiti();
|
|
// effettuo load valori...
|
|
setupComandiBarcode();
|
|
setupValoriBarcode();
|
|
// registro eventi
|
|
mod_barcode1.eh_comandoRegistrato += new EventHandler(mod_barcode1_eh_comandoRegistrato);
|
|
mod_btnComandi1.eh_clickComando += new EventHandler(mod_btnComandi1_eh_clickComando);
|
|
}
|
|
/// <summary>
|
|
/// Verifica i requisiti (operatore e postazione) per operare
|
|
/// </summary>
|
|
private void checkRequisiti()
|
|
{
|
|
mod_btnComandi1.Visible = (CodOpr != "" && CodPost != "");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Numero comandi ammessi caricati
|
|
/// </summary>
|
|
public int nComandi
|
|
{
|
|
get
|
|
{
|
|
return comandiAmmessiBCode.Count;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Numero record BCode caricati
|
|
/// </summary>
|
|
public int nBCodeRec
|
|
{
|
|
get
|
|
{
|
|
return valoriAmmessiBCode.Count;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Memorizzo durata ultimo update (lettura record...) come timespan
|
|
/// </summary>
|
|
public TimeSpan lastUpdDuration
|
|
{
|
|
get
|
|
{
|
|
return (TimeSpan)memLayer.ML.objSessionObj("lastUpdDuration");
|
|
}
|
|
set
|
|
{
|
|
memLayer.ML.setSessionVal("lastUpdDuration", value);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// inviato un comando dai link buttons
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
void mod_btnComandi1_eh_clickComando(object sender, EventArgs e)
|
|
{
|
|
// chiamo metodo caricamento comandi in modulo barcode...
|
|
mod_barcode1.loadBtnClickComando();
|
|
}
|
|
|
|
private void traduciObj()
|
|
{
|
|
}
|
|
/// <summary>
|
|
/// imposta/recupera valore num gg da rileggere...
|
|
/// </summary>
|
|
public int numDD
|
|
{
|
|
get
|
|
{
|
|
int answ = 85;
|
|
try
|
|
{
|
|
answ = Convert.ToInt32(txtNumDD.Text.Trim());
|
|
}
|
|
catch
|
|
{ }
|
|
return answ;
|
|
}
|
|
set
|
|
{
|
|
txtNumDD.Text = value.ToString();
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// logLevel impostato...
|
|
/// </summary>
|
|
public int logLevel
|
|
{
|
|
get
|
|
{
|
|
int answ = 1;
|
|
try
|
|
{
|
|
answ = memLayer.ML.CRI("_logLevel");
|
|
}
|
|
catch
|
|
{ }
|
|
return answ;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// imposta/recupera valore num sec validità cache...
|
|
/// </summary>
|
|
public int cacheValSec
|
|
{
|
|
get
|
|
{
|
|
int answ = 55;
|
|
try
|
|
{
|
|
answ = Convert.ToInt32(txtCacheSec.Text.Trim());
|
|
}
|
|
catch
|
|
{ }
|
|
|
|
return answ;
|
|
}
|
|
set
|
|
{
|
|
txtCacheSec.Text = value.ToString();
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Variabile x controllo scadenza valori in cache
|
|
/// </summary>
|
|
protected DateTime lastDataRefresh
|
|
{
|
|
get
|
|
{
|
|
DateTime answ = DateTime.Now.AddDays(-1);
|
|
try
|
|
{
|
|
answ = Convert.ToDateTime(memLayer.ML.objCacheObj("lastBCodeDataRead"));
|
|
}
|
|
catch
|
|
{ }
|
|
return answ;
|
|
}
|
|
set
|
|
{
|
|
// registro che i valori in cache sono scaduti...
|
|
memLayer.ML.setCacheVal("lastBCodeDataRead", value);
|
|
if (logLevel > 5)
|
|
{
|
|
logger.lg.scriviLog("impostata validità cache");
|
|
}
|
|
}
|
|
}
|
|
protected bool cacheValida
|
|
{
|
|
get
|
|
{
|
|
bool answ = false;
|
|
try
|
|
{
|
|
if (DateTime.Now.Subtract(lastDataRefresh).TotalSeconds < cacheValSec)
|
|
{
|
|
answ = true;
|
|
}
|
|
}
|
|
catch
|
|
{ }
|
|
return answ;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Elenco (da cache) dei valori ammessi x BCode
|
|
/// </summary>
|
|
protected Dictionary<string, string> valoriAmmessiBCode
|
|
{
|
|
get
|
|
{
|
|
Dictionary<string, string> answ = new Dictionary<string, string>();
|
|
if (memLayer.ML.isInCacheObject("valoriAmmessiBCode") && cacheValida)
|
|
{
|
|
answ = (Dictionary<string, string>)memLayer.ML.objCacheObj("valoriAmmessiBCode");
|
|
}
|
|
return answ;
|
|
}
|
|
set
|
|
{
|
|
memLayer.ML.setCacheVal("valoriAmmessiBCode", value);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Elenco (da cache) dei comandi ammessi x BCode
|
|
/// </summary>
|
|
protected Dictionary<string, string> comandiAmmessiBCode
|
|
{
|
|
get
|
|
{
|
|
Dictionary<string, string> answ = new Dictionary<string, string>();
|
|
if (memLayer.ML.isInCacheObject("comandiAmmessiBCode"))
|
|
{
|
|
answ = (Dictionary<string, string>)memLayer.ML.objCacheObj("comandiAmmessiBCode");
|
|
}
|
|
return answ;
|
|
}
|
|
set
|
|
{
|
|
memLayer.ML.setCacheVal("comandiAmmessiBCode", value);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// effettuo il setup dei valori ammessi x il barcode...
|
|
/// </summary>
|
|
private void setupValoriBarcode()
|
|
{
|
|
if (valoriAmmessiBCode.Count > 0)
|
|
{
|
|
// assegno valori al barcode...
|
|
mod_barcode1.tabValori = valoriAmmessiBCode;
|
|
if (logLevel > 5)
|
|
{
|
|
logger.lg.scriviLog("Letti da cache VALORI Barcode", tipoLog.INFO);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// Crea stopwatch.
|
|
Stopwatch stopwatch = new Stopwatch();
|
|
// Avvio...
|
|
stopwatch.Start();
|
|
// carico dati!
|
|
if (logLevel > 5)
|
|
{
|
|
logger.lg.scriviLog("Inizio setup valori Barcode", tipoLog.INFO);
|
|
}
|
|
|
|
Dictionary<string, string> valori = new Dictionary<string, string>();
|
|
|
|
// aggiungo i COD OPERATORE
|
|
var tabOpr = dataLayer.man.taAO.GetData();
|
|
foreach (var rigaOpr in tabOpr)
|
|
{
|
|
valori.Add(rigaOpr.CodOpr, string.Format("{0} {1}", rigaOpr.Cognome, rigaOpr.Nome));
|
|
}
|
|
if (logLevel > 5)
|
|
{
|
|
logger.lg.scriviLog("Caricato OPERATORI per Barcode", tipoLog.INFO);
|
|
}
|
|
|
|
// aggiungo le POSTAZIONI
|
|
var tabPost = dataLayer.man.taAP.GetData();
|
|
foreach (var rigaPost in tabPost)
|
|
{
|
|
valori.Add(rigaPost.CodPost, rigaPost.Descrizione);
|
|
}
|
|
if (logLevel > 5)
|
|
{
|
|
logger.lg.scriviLog("Caricato POSTAZIONI per Barcode", tipoLog.INFO);
|
|
}
|
|
// aggiungo le commesse...
|
|
var tabTask = dataLayer.man.taTL.getLastNumDD(numDD);
|
|
foreach (var rigaTask in tabTask)
|
|
{
|
|
valori.Add(rigaTask.NumTask, string.Format("Comm. {0} | Art. {1} | Qta {2}", rigaTask.NumTask, rigaTask.CodArt, rigaTask.QtaRic));
|
|
}
|
|
if (logLevel > 5)
|
|
{
|
|
logger.lg.scriviLog("Caricato TaskList per Barcode", tipoLog.INFO);
|
|
}
|
|
// assegno valori al barcode...
|
|
mod_barcode1.tabValori = valori;
|
|
valoriAmmessiBCode = valori;
|
|
lastDataRefresh = DateTime.Now;
|
|
logger.lg.scriviLog("Letti da DB VALORI Barcode", tipoLog.INFO);
|
|
stopwatch.Start();
|
|
lastUpdDuration = stopwatch.Elapsed;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// carico da tab i comandi ammessi per il barcode...
|
|
/// </summary>
|
|
private void setupComandiBarcode()
|
|
{
|
|
if (comandiAmmessiBCode.Count > 0)
|
|
{
|
|
// assegno valori al barcode...
|
|
mod_barcode1.comandiAmmessi = comandiAmmessiBCode;
|
|
if (logLevel > 5)
|
|
{
|
|
logger.lg.scriviLog("Letti da cache COMANDI Barcode", tipoLog.INFO);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Dictionary<string, string> comandi = new Dictionary<string, string>();
|
|
|
|
// !!!FARE!!! togleire...
|
|
var tabCmd = dataLayer.man.taTE2S.getByMappa("E_BC");
|
|
foreach (var rigaCmd in tabCmd)
|
|
{
|
|
comandi.Add(rigaCmd.CodEvento.ToUpper(), devicesAuthProxy.stObj.traduci(rigaCmd.text2show));
|
|
}
|
|
|
|
|
|
var tabFasi = dataLayer.man.taAF.GetData();
|
|
foreach (var rigaFase in tabFasi)
|
|
{
|
|
comandi.Add(rigaFase.CodFase, rigaFase.DescrFase);
|
|
}
|
|
|
|
#if false
|
|
XPS_data.DS_applicazioneTableAdapters.TraEv2StatiTableAdapter taTrEv2St = new XPS_data.DS_applicazioneTableAdapters.TraEv2StatiTableAdapter();
|
|
DS_applicazione.TraEv2StatiDataTable _tabTran = taTrEv2St.getByCodMappa("E_BC");
|
|
foreach (DS_applicazione.TraEv2StatiRow riga in _tabTran)
|
|
{
|
|
comandi.Add(riga.CodEvento, user_std.UtSn.Traduci(riga.text2show));
|
|
}
|
|
#endif
|
|
// impongo i comandi al barcode...
|
|
mod_barcode1.comandiAmmessi = comandi;
|
|
comandiAmmessiBCode = comandi;
|
|
logger.lg.scriviLog("Letti da DB COMANDI Barcode", tipoLog.INFO);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// il barcode ha registrato un evento...
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
void mod_barcode1_eh_comandoRegistrato(object sender, EventArgs e)
|
|
{
|
|
switch (stateMachine.st.azioneComando(mod_barcode1.comandoRegistrato))
|
|
{
|
|
case tipoAzione.annulla:
|
|
mod_barcode1.resetMe();
|
|
break;
|
|
case tipoAzione.conferma:
|
|
// se input completo eseguo...
|
|
if (mod_barcode1.comandoRegistrato.currCmdIn != "" && mod_barcode1.comandoRegistrato.valore != "")
|
|
{
|
|
eseguiComando();
|
|
}
|
|
else // altrimenti warning... e rimetto valori precedenti
|
|
{
|
|
mod_barcode1.txtRich2show = user_std.UtSn.Traduci("codObjUnknown");
|
|
mod_barcode1.comandoRegistrato.currCmdIn = mod_barcode1.comandoRegistrato.prevCmdIn;
|
|
mod_barcode1.comandoRegistrato.descrComando = mod_barcode1.comandoRegistrato.descrComandoPrev;
|
|
mod_barcode1.txtInput2show = mod_barcode1.comandoRegistrato.descrComandoPrev;
|
|
}
|
|
break;
|
|
case tipoAzione.esegui:
|
|
// se ho auto conferma eseguo!
|
|
if (memLayer.ML.confReadBool("autoConfCmd"))
|
|
{
|
|
mod_barcode1.comandoRegistrato.prevCmdIn = mod_barcode1.comandoRegistrato.currCmdIn;
|
|
mod_barcode1.comandoRegistrato.currCmdIn = "ok";
|
|
eseguiComando();
|
|
}
|
|
else
|
|
{
|
|
if (mod_barcode1.comandoRegistrato.valore != "")
|
|
{
|
|
mod_barcode1.txtRich2show = user_std.UtSn.Traduci("pleaseConfirm");
|
|
}
|
|
else
|
|
{
|
|
mod_barcode1.txtRich2show = user_std.UtSn.Traduci("codObjUnknown");
|
|
}
|
|
}
|
|
break;
|
|
case tipoAzione.noAct:
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
mod_btnComandi1.updateBtn();
|
|
}
|
|
/// <summary>
|
|
/// eseguo il comando
|
|
/// </summary>
|
|
private void eseguiComando()
|
|
{
|
|
// in primis: sono in esecuzione, x cui il comando è valido...
|
|
string msg2show = "";
|
|
string currState = "";
|
|
// verifico se cmd setup utente...
|
|
if (mod_barcode1.comandoRegistrato.prevCmdIn == "RESOP")
|
|
{
|
|
// rimuovo OPR da POST corrente
|
|
dataLayer.man.taAP.resetOpr(CodOpr);
|
|
// rimuovo OPR da sessione
|
|
CodOpr = "";
|
|
// rimuovo post corrente...
|
|
CodPost = "";
|
|
// torno a pagina base...
|
|
Response.Redirect("~/barcode");
|
|
}
|
|
else if (mod_barcode1.comandoRegistrato.valore.Contains("OPR."))
|
|
{
|
|
CodOpr = mod_barcode1.comandoRegistrato.valore;
|
|
// SE HO postsazione ...
|
|
if (CodPost != "")
|
|
{
|
|
// ...e SE la postazione è libera o c'è lui associo e registro
|
|
var tabPost = dataLayer.man.taAP.getByKey(CodPost);
|
|
if (tabPost.Rows.Count == 1)
|
|
{
|
|
var rigaPost = tabPost[0];
|
|
if (rigaPost.CodOpr == CodOpr || rigaPost.CodOpr == "")
|
|
{
|
|
dataLayer.man.taAP.setOpr(CodPost, CodOpr);
|
|
}
|
|
}
|
|
}
|
|
Response.Redirect("~/barcode");
|
|
}
|
|
else if (mod_barcode1.comandoRegistrato.valore.Contains("POST."))
|
|
{
|
|
// SE HO operatore ...
|
|
if (CodOpr != "")
|
|
{
|
|
// ...e SE la postazione è libera o c'è lui associo e registro
|
|
var tabPost = dataLayer.man.taAP.getByKey(mod_barcode1.comandoRegistrato.valore);
|
|
if (tabPost.Rows.Count == 1)
|
|
{
|
|
var rigaPost = tabPost[0];
|
|
if (rigaPost.CodOpr == CodOpr || rigaPost.CodOpr == "")
|
|
{
|
|
CodPost = mod_barcode1.comandoRegistrato.valore;
|
|
dataLayer.man.taAP.setOpr(CodPost, CodOpr);
|
|
// svuoto vallori
|
|
}
|
|
}
|
|
}
|
|
Response.Redirect("~/barcode");
|
|
}
|
|
|
|
#if false
|
|
DS_applicazione.IstObjRow rigaIstObj;
|
|
// calcolo lo stato dell'oggetto...
|
|
try
|
|
{
|
|
rigaIstObj = XPS_data.XPS.obj.taObj.getByIdxObj(mod_barcode1.comandoRegistrato.valore)[0];
|
|
currState = rigaIstObj.CodStato;
|
|
}
|
|
catch
|
|
{
|
|
}
|
|
tipoEsito esito = stateMachine.st.doAction("E_Stati", mod_barcode1.comandoRegistrato.valore, currState, mod_barcode1.comandoRegistrato.prevCmdIn);
|
|
if (esito == tipoEsito.ok)
|
|
{
|
|
msg2show = string.Format("{0}: {1}", mod_barcode1.comandoRegistrato.valore, user_std.UtSn.Traduci("chgStateDone"));
|
|
}
|
|
else if (esito == tipoEsito.error)
|
|
{
|
|
msg2show = user_std.UtSn.Traduci("cannotStateChange");
|
|
}
|
|
else
|
|
{
|
|
msg2show = user_std.UtSn.Traduci("unknownCmd");
|
|
}
|
|
#endif
|
|
// reset e mostro output...
|
|
mod_barcode1.resetMe();
|
|
if (msg2show != "")
|
|
{
|
|
mod_barcode1.txtInput2show = msg2show;
|
|
}
|
|
}
|
|
|
|
protected void btnReload_Click(object sender, EventArgs e)
|
|
{
|
|
resetCache();
|
|
}
|
|
|
|
private void resetCache()
|
|
{
|
|
// resetto tutto!
|
|
comandiAmmessiBCode = new Dictionary<string, string>();
|
|
valoriAmmessiBCode = new Dictionary<string, string>();
|
|
lastDataRefresh = DateTime.Now.AddDays(-1);
|
|
}
|
|
|
|
protected void txtCacheSec_TextChanged(object sender, EventArgs e)
|
|
{
|
|
resetCache();
|
|
}
|
|
|
|
protected void txtNumDD_TextChanged(object sender, EventArgs e)
|
|
{
|
|
resetCache();
|
|
}
|
|
}
|
|
}
|
|
|