using System; using System.Collections.Generic; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using SteamWare; namespace XPST.WebUserControls { public partial class mod_barcode : System.Web.UI.UserControl { #region area protected /// /// dictionary comandi ammessi /// protected Dictionary _comandi = new Dictionary(); /// /// dictionary dei valori ammessi /// protected Dictionary _tabValori = new Dictionary(); /// /// oggetto comando locale alla classe /// protected inputComando comando { get { inputComando answ; if (memLayer.ML.isInSessionObject("barcodeCmd")) { answ = (inputComando)memLayer.ML.objSessionObj("barcodeCmd"); } else { answ = new inputComando(); } return answ; } set { memLayer.ML.setSessionVal("barcodeCmd", value, false); } } /// /// al caricamento della pagina... /// /// /// protected void Page_Load(object sender, EventArgs e) { DetectAgent(); myInitialize(); } /// /// inizializzazione specifica barcode /// private void myInitialize() { lblInput.Text = traduci("PregoInserireBarcode"); if (!Page.IsPostBack) comando = new inputComando(); } public string BCodeVal { get { return txtInput.Text.Trim().ToUpper(); } set { txtInput.Text = value; } } /// /// barcode completato con invio... /// /// /// protected void txtInput_TextChanged(object sender, EventArgs e) { processInput(); } private void processInput() { // verifico se sia un comando o un valore valido... isInputEvent(); isValore(); // verifico se c'è stato input evento if (comando.isValid) { if (comando.currCmdIn != "") { txtInput2show = comando.descrComando; } else { txtInput2show = "---"; } if (comando.valore != "") { txtVal2show = comando.valoreTrad; } else { txtVal2show = "---"; } if (eh_comandoRegistrato != null) { eh_comandoRegistrato(this, new EventArgs()); } } else { lblInput.Text = traduci("ComandoSconosciuto"); lblValore.Text = BCodeVal; comando = new inputComando(); } BCodeVal = ""; } /// /// verifico se sia un valore compreso nell'elenco fornito /// private void isValore() { if (_tabValori.ContainsKey(BCodeVal)) // verifico se il comando digitato esista... { comando.isValid = true; comando.valore = BCodeVal; _tabValori.TryGetValue(BCodeVal, out comando.valoreTrad); } } /// /// verifica se il comando inserito sia valido /// private void isInputEvent() { if (_comandi.ContainsKey(BCodeVal)) // verifico se il comando digitato esista... { comando.isValid = true; // salvo comando precedente (se c'è...) comando.prevCmdIn = comando.currCmdIn; comando.descrComandoPrev = comando.descrComando; comando.currCmdIn = BCodeVal; _comandi.TryGetValue(BCodeVal, out comando.descrComando); } } /// /// verifica quale browser usato e applica css corretto al div attorno al box /// private void DetectAgent() { System.Web.HttpBrowserCapabilities browser = Request.Browser; if (browser.Browser == "IE") { pnlBarcodeBox.CssClass = "barcodeBoxIE"; } else { pnlBarcodeBox.CssClass = "barcodeBoxOther"; } } #endregion #region area public /// /// effettua al ettura da sessione del comando cliccato e lo inserisce come fosse barcode /// public void loadBtnClickComando() { BCodeVal = memLayer.ML.StringSessionObj("btnCmdPress"); memLayer.ML.emptySessionVal("btnCmdPress"); processInput(); } /// /// elenco dei comandi riconosciuti /// public Dictionary comandiAmmessi { get { return _comandi; } set { _comandi = value; } } /// /// tabella di valori ammissibili /// public Dictionary tabValori { get { return _tabValori; } set { _tabValori = value; } } /// /// evento comando registrato /// public event EventHandler eh_comandoRegistrato; /// /// comando registrato dal barcode /// public inputComando comandoRegistrato { get { return comando; } } /// /// scrive nella label input /// public string txtInput2show { set { lblInput.Text = value; } } /// /// scrive nella label valore /// public string txtVal2show { set { lblValore.Text = value; } } /// /// scrive nella label richiesta /// public string txtRich2show { set { lblRichiesta.Text = value; } } /// /// reset del controllo /// public void resetMe() { comando = new inputComando(); txtInput2show = "Prego inserire barcode"; txtVal2show = ""; txtRich2show = ""; } /// /// wrapper traduzione termini /// /// /// public string traduci(string lemma) { return user_std.UtSn.Traduci(lemma); } #endregion } }