using System; using System.Collections.Generic; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using SteamWare; public partial class mod_barcode : ApplicationUserControl { #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 override void Page_Load(object sender, EventArgs e) { base.Page_Load(sender, e); DetectAgent(); myInitialize(); } /// /// inizializzazione specifica barcode /// private void myInitialize() { lblInput.Text = traduci("PregoInserireBarcode"); if (!Page.IsPostBack) comando = new inputComando(); txtComando.Focus(); } /// /// barcode completato con invio... /// /// /// protected void txtComando_TextChanged(object sender, EventArgs e) { // 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 = txtComando.Text; comando = new inputComando(); } txtComando.Text = ""; } /// /// verifico se sia un valore compreso nell'elenco fornito /// private void isValore() { if (_tabValori.ContainsKey(txtComando.Text)) // verifico se il comando digitato esista... { comando.isValid = true; comando.valore = txtComando.Text; _tabValori.TryGetValue(txtComando.Text, out comando.valoreTrad); } } /// /// verifica se il comando inserito sia valido /// private void isInputEvent() { if (_comandi.ContainsKey(txtComando.Text)) // verifico se il comando digitato esista... { comando.isValid = true; // salvo comando precedente (se c'è...) comando.prevCmdIn = comando.currCmdIn; comando.descrComandoPrev = comando.descrComando; comando.currCmdIn = txtComando.Text; _comandi.TryGetValue(txtComando.Text, 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 /// /// 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 = ""; } #endregion }