Files
XPS/XPST/WebUserControls/mod_barcode.ascx.cs

275 lines
6.2 KiB
C#

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
/// <summary>
/// dictionary comandi ammessi
/// </summary>
protected Dictionary<string, string> _comandi = new Dictionary<string, string>();
/// <summary>
/// dictionary dei valori ammessi
/// </summary>
protected Dictionary<string, string> _tabValori = new Dictionary<string, string>();
/// <summary>
/// oggetto comando locale alla classe
/// </summary>
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);
}
}
/// <summary>
/// al caricamento della pagina...
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load(object sender, EventArgs e)
{
DetectAgent();
myInitialize();
}
/// <summary>
/// inizializzazione specifica barcode
/// </summary>
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;
}
}
/// <summary>
/// barcode completato con invio...
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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 = "";
}
/// <summary>
/// verifico se sia un valore compreso nell'elenco fornito
/// </summary>
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);
}
}
/// <summary>
/// verifica se il comando inserito sia valido
/// </summary>
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);
}
}
/// <summary>
/// verifica quale browser usato e applica css corretto al div attorno al box
/// </summary>
private void DetectAgent()
{
System.Web.HttpBrowserCapabilities browser = Request.Browser;
if (browser.Browser == "IE")
{
pnlBarcodeBox.CssClass = "barcodeBoxIE";
}
else
{
pnlBarcodeBox.CssClass = "barcodeBoxOther";
}
}
#endregion
#region area public
/// <summary>
/// effettua al ettura da sessione del comando cliccato e lo inserisce come fosse barcode
/// </summary>
public void loadBtnClickComando()
{
BCodeVal = memLayer.ML.StringSessionObj("btnCmdPress");
memLayer.ML.emptySessionVal("btnCmdPress");
processInput();
}
/// <summary>
/// elenco dei comandi riconosciuti
/// </summary>
public Dictionary<string, string> comandiAmmessi
{
get
{
return _comandi;
}
set
{
_comandi = value;
}
}
/// <summary>
/// tabella di valori ammissibili
/// </summary>
public Dictionary<string, string> tabValori
{
get
{
return _tabValori;
}
set
{
_tabValori = value;
}
}
/// <summary>
/// evento comando registrato
/// </summary>
public event EventHandler eh_comandoRegistrato;
/// <summary>
/// comando registrato dal barcode
/// </summary>
public inputComando comandoRegistrato
{
get
{
return comando;
}
}
/// <summary>
/// scrive nella label input
/// </summary>
public string txtInput2show
{
set
{
lblInput.Text = value;
}
}
/// <summary>
/// scrive nella label valore
/// </summary>
public string txtVal2show
{
set
{
lblValore.Text = value;
}
}
/// <summary>
/// scrive nella label richiesta
/// </summary>
public string txtRich2show
{
set
{
lblRichiesta.Text = value;
}
}
/// <summary>
/// reset del controllo
/// </summary>
public void resetMe()
{
comando = new inputComando();
txtInput2show = "Prego inserire barcode";
txtVal2show = "";
txtRich2show = "";
}
/// <summary>
/// wrapper traduzione termini
/// </summary>
/// <param name="lemma"></param>
/// <returns></returns>
public string traduci(string lemma)
{
return user_std.UtSn.Traduci(lemma);
}
#endregion
}
}