using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using GMW_data; using SteamWare; namespace GMW_Term.WebUserControls { public partial class mod_barcode : System.Web.UI.UserControl { // variabile per verificare se è operatore bool _validUserInSession = false; string _homeBtnText = "Home"; string _homeBtnLink = "~/Home.aspx"; /// /// wrapper traduzione termini /// /// /// public string traduci(string lemma) { return user_std.UtSn.Traduci(lemma); } #region area eventi public event EventHandler eh_scannedUser; public event EventHandler eh_resetUser; public event EventHandler eh_scannedUdc; public event EventHandler eh_scannedListaPrelievo; public event EventHandler eh_scannedParticolare; public event EventHandler eh_scannedCella; #endregion /// /// testo del pulsante HOME /// public string homeBtnText { set { _homeBtnText = value; traduciObj(); } get { return _homeBtnText; } } /// /// link del pulsante HOME /// public string homeBtnLink { set { _homeBtnLink = value; traduciObj(); } get { return _homeBtnLink; } } /// /// traduce stringhe oggetti /// protected void traduciObj() { // scrive label e text bottoni btnLoginPage.Text = string.Format("{0}\n[Alt+{1}]", traduci("Login"), 7); btnLoginPage.AccessKey = "7"; btnButtonsHome.Text = string.Format("{0}\n[Alt+{1}]", traduci(_homeBtnText), 9); btnButtonsHome.AccessKey = "9"; } /// /// metodi al caricamento della pagina /// /// /// protected void Page_Load(object sender, EventArgs e) { traduciObj(); // se username è valorizzato... verificaOperatoreInSessione(); if (_validUserInSession) { btnLoginPage.Text = string.Format("{0}\n[Alt+{1}]", traduci("Logout"), 7); btnLoginPage.Visible = memLayer.ML.confReadBool("showLogout"); btnButtonsHome.Visible = true; // se ho un precedente valore barcode lo mostro... if (memLayer.ML.isInSessionObject("Barcode_sel")) { lblData.Text = memLayer.ML.StringSessionObj("Barcode_sel"); } else { lblData.Text = traduci("Insert Data") + "..."; } lblRev.Visible = false; } // se non è valorizzato chiede di effettuare login... else { if (memLayer.ML.confReadBool("SimpleLogin")) { // in questo caso fa login di default con l'operatore indicato... string codOperatore = memLayer.ML.confReadString("CodOperDefault"); effettuaLoginOperatore(codOperatore); } else { // sistema visualizzazione btnLoginPage.Visible = false; btnButtonsHome.Visible = false; lblData.Text = traduci("Please Login"); lblRev.Text = string.Format("{0} v.{1}.{2}", memLayer.ML.confReadString("appName"), memLayer.ML.confReadString("mainRev"), memLayer.ML.confReadString("minRev")); } } txtInput.Focus(); } /// /// inserito testo nella TextBox /// /// /// protected void txtInput_TextChanged(object sender, EventArgs e) { // salvo in sessione la scansione attuale... valoreScan = txtScansione; // verifica l'input immesso tipoCodiceBarcode answ = TermClass.Ter.riconosciBarcode(txtScansione); verificaOperatoreInSessione(); if (!_validUserInSession) //controllo: se non c'è operatore in sessione { if (answ == tipoCodiceBarcode.Operatore) { effettuaLoginOperatore(txtScansione); } else { lblData.Text = traduci("Invalid Code"); txtScansione = ""; } } else { switch (answ) { case tipoCodiceBarcode.ND: lblData.Text = traduci("Code Mismatch") + ": " + txtScansione; txtInput.Text = ""; break; case tipoCodiceBarcode.Operatore: effettuaLoginOperatore(txtScansione); break; case tipoCodiceBarcode.ListaPrelievo: chekListaPrelievo(); break; case tipoCodiceBarcode.UDC: verificaUdc(); break; case tipoCodiceBarcode.Particolare: verificaParticolare(); break; case tipoCodiceBarcode.Cella: verificaCella(); break; default: lblData.Text = traduci("CodeNotRecognized") + ": " + txtScansione; txtInput.Text = ""; break; } } lblData.Font.Italic = false; } /// /// verifica la lista di prelievo (se attivabile la attiva) /// private void chekListaPrelievo() { // verifica preliminare: se sia una chiamata di tipo "chiudi lista" e la lista sia quella dell'utente... bool isCloseCmd = false; try { isCloseCmd = txtScansione.EndsWith(memLayer.ML.confReadString("closeCodeLdp")); } catch { } if (isCloseCmd) { string codLista = txtScansione.Replace(memLayer.ML.confReadString("closeCodeLdp"), ""); // controllo se sia la lista di prelievo assegnata all'utente bool isUserList = (codLista == MagClass.magazzino.codListaAttivaUtente); if (isUserList) { // chiudo! esitoOperazione esitoCompleta = GMW_data.MagClass.magazzino.completaListaPrelievo(memLayer.ML.StringSessionObj("CodCS"), codLista, MagClass.magazzino.CodSoggCurrUser, Request.UserHostName); if (esitoCompleta == esitoOperazione.ok) { // indico che la lista indicata è stata chiusa lblData.Text = string.Format("{0}: {1}", traduci("ListClosed"), codLista); } else if (esitoCompleta == esitoOperazione.errore_noUdc) { GMW_data.MagClass.magazzino.attivaListaPrelievo(memLayer.ML.StringSessionObj("CodCS"), codLista, MagClass.magazzino.CodSoggCurrUser); httpLog(string.Format("Lista di prelievo {0} rilasciata poiché senza UDC prelevati da parte dell'opertore {1}", codLista, MagClass.magazzino.CodSoggCurrUser), tipoLog.INFO); // tolgo dalla session la lista prelievo attuale... memLayer.ML.emptySessionVal("CodLista_sel"); memLayer.ML.emptySessionVal("CodListaAttiva"); memLayer.ML.emptySessionVal("activeTask"); // indico che la lista indicata è stata rimessa in stato "attiva" lblData.Text = string.Format("{0}: {1}", traduci("ListReActivated"), codLista); } // svuoto cache! //memLayer.ML.emptySessionVal("UDC_sel"); GMW_data.TermClass.Ter.resetScanBarcode(true, false, false); } else { // indico che il codice di chiusura NON è valido xché non ha in carico la lista indicata lblData.Text = string.Format("!!! {0}: {1}", traduci("ListNotCloseable"), codLista); } } else { // verifico se al lista di prelievo sia valida ed attivabile if (MagClass.magazzino.listaPrelevabile(txtScansione)) { // verifico se l'utente ha delle lsite di prelievo attive e quindi NON PUO prenderne in carico altre if (!MagClass.magazzino.userHasActiveLP) { // indico la lista come attiva GMW_data.MagClass.magazzino.iniziaListaPrelievo(memLayer.ML.StringSessionObj("CodCS"), txtScansione, MagClass.magazzino.CodSoggCurrUser); // salvo in sessione che voglio mostrare il dettaglio della lista appena presa in carico memLayer.ML.setSessionVal("showDetListaPre", true, false); if (eh_scannedListaPrelievo != null) { eh_scannedListaPrelievo(this, new EventArgs()); } } else { // indico l'errore: operatore già con una lista attiva lblData.Text = string.Format("!!! {0}: {1}", traduci("ListStillOpen"), MagClass.magazzino.codListaAttivaUtente); } } else { // se la lista è quella in carico rimando a quella if (txtScansione == MagClass.magazzino.codListaAttivaUtente) { // salvo in sessione che voglio mostrare il dettaglio della lista appena presa in carico memLayer.ML.setSessionVal("showDetListaPre", true, false); if (eh_scannedListaPrelievo != null) { eh_scannedListaPrelievo(this, new EventArgs()); } } else { // indico l'errore: lista non valida o non attivabile lblData.Text = string.Format("!!! {0}: {1}", traduci("NotDownloadable"), txtScansione); } } } txtInput.Text = ""; } /// /// verifica validità UDC /// private void verificaUdc() { // controllo l'UDC se sia valido (==esistente) bool barcodeOk = MagClass.magazzino.checkUDC(valoreScan); if (barcodeOk) { // salvo in session UDC selezionato memLayer.ML.setSessionVal("UDC_sel", valoreScan, false); if (eh_scannedUdc != null) { eh_scannedUdc(this, new EventArgs()); } } else { lblData.Text = string.Format(traduci("UDCCodeInvalid") + ": " + "{0}", valoreScan); txtScansione = ""; } } /// /// verifica validità cella /// private void verificaCella() { // controllo cod cella se sia valido (==esistente) bool barcodeOk = MagClass.magazzino.checkCella(valoreScan); if (barcodeOk) { // calcolo idxCella int idxCella = MagClass.magazzino.IdxCellaByCodCella(memLayer.ML.StringSessionObj("CodCS"), valoreScan); // salvo in session idxCella selezionata memLayer.ML.setSessionVal("IdxCella_sel", idxCella); memLayer.ML.setSessionVal("codCella_sel", valoreScan); memLayer.ML.setSessionVal("activeTask", string.Format("Cella: {0}", valoreScan)); if (eh_scannedCella != null) { eh_scannedCella(this, new EventArgs()); } } else { lblData.Text = string.Format(traduci("CellaCodeInvalid") + ": " + "{0}", valoreScan); txtScansione = ""; } } /// /// verifica validità particolare /// private void verificaParticolare() { // controllo se sia valido il particolare (==esistente) bool barcodeOk = MagClass.magazzino.checkParticolare(memLayer.ML.StringSessionObj("CodCS"), valoreScan); if (barcodeOk) { // salvo in session particolare selezionato memLayer.ML.setSessionVal("Particolare_sel", txtScansione); memLayer.ML.setSessionVal("activeTask", string.Format("Particolare: {0}", valoreScan)); if (eh_scannedParticolare != null) { eh_scannedParticolare(this, new EventArgs()); } } else { lblData.Text = string.Format(traduci("PartCodeInvalid") + ": " + "{0}", valoreScan); txtScansione = ""; } } /// /// effettua le chiamate per la login /// /// private void effettuaLoginOperatore(string dataIn) { // salvo in sessione valore barcode memLayer.ML.setSessionVal("UserBarcode", dataIn); // verifico che il cod operatore passato sia valido per Rilpro.Anagoperatori e Soggetti2Utente httpLog(string.Format("Richiesta di login tramite barcode da {0}, IP {1}", Request.UserHostName, Request.UserHostAddress), tipoLog.STARTUP); esitoLoginTerm esito = TermClass.Ter.doUserLogin(dataIn); if (esito == esitoLoginTerm.ok) { // svuoto dati lista attiva e smartlist... memLayer.ML.emptySessionVal("CodListaAttiva"); memLayer.ML.emptySessionVal("activeTask"); // salvo i dati di CodCS memLayer.ML.setSessionVal("CodCS", memLayer.ML.confReadString("CodCS"), true); // in caso operatore abbia liste attive le carico... if (MagClass.magazzino.userHasActiveLP) { string codiceListaAttivo = ""; try { codiceListaAttivo = MagClass.magazzino.codListaAttivaUtente; // salvo la lista di prelievo come attiva memLayer.ML.setSessionVal("activeTask", string.Format("Lista Prelievo {0}", codiceListaAttivo)); memLayer.ML.setSessionVal("CodListaAttiva", codiceListaAttivo); } catch { // c'era una lista attiva, non l'ho recuperata, segno errore! httpLog(string.Format(traduci("ErrorListDataRetrieval"), user_std.UtSn.utente), tipoLog.ERROR); } } else { memLayer.ML.setSessionVal("activeTask", "Selezionato Operatore"); } // alza evento login! if (eh_scannedUser != null) { eh_scannedUser(this, new EventArgs()); } } else { // avvisa che il codice è errato lblData.Text = string.Format("{0} {1} {2}", traduci("Single User"), txtInput.Text, traduci("NotInDb")); txtInput.Text = ""; } } /// /// wrapper per log con salvataggio dell'IP del chiamante /// /// /// public bool httpLog(string _testoPre) { bool answ = false; string postazione_IP = ""; try { postazione_IP = string.Format(" | {0} | ", Request.UserHostName); } catch { } logger.lg.scriviLog(postazione_IP + _testoPre); return answ; } /// /// wrapper per log con salvataggio dell'IP del chiamante /// /// /// public bool httpLog(string testoLog, tipoLog tipo) { bool answ = false; string postazione_IP = ""; try { postazione_IP = string.Format(" | {0} | ", Request.UserHostName); } catch { } logger.lg.scriviLog(postazione_IP + testoLog, tipo); return answ; } /// /// effettua logout... /// /// /// protected void btnLoginPage_Click(object sender, EventArgs e) { TermUtils.TU.forceLogOut(); verificaOperatoreInSessione(); // evento reset if (eh_resetUser != null) { eh_resetUser(this, new EventArgs()); } } /// /// va alla pagina dei buttons principale /// /// /// protected void btnButtonsHome_Click(object sender, EventArgs e) { Response.Redirect(homeBtnLink); } /// /// Verifica se c'è un valore in sessione di tipo operatore /// protected void verificaOperatoreInSessione() { if (string.IsNullOrEmpty(user_std.UtSn.utente)) { _validUserInSession = false; httpLog(string.Format("Errore: perso user da sessione: IP {0}, user-barcode '{1}'", Request.UserHostAddress, memLayer.ML.StringSessionObj("UserBarcode")), tipoLog.ERROR); } else { _validUserInSession = true; } } ///// ///// metodo get set per impostare operatore ///// //public bool isOperatore //{ // set // { // _validUserInSession = value; // } // get // { // return _validUserInSession; // } //} /// /// testo contenuto nella textbox /// public string txtScansione { get { return txtInput.Text.Trim(); } set { txtInput.Text = value; } } /// /// valore della scansione barcode /// public string valoreScan { get { return memLayer.ML.StringSessionObj("scannedValue"); } set { memLayer.ML.setSessionVal("scannedValue", value, false); } } /// /// definisce se mostrare l'header text (Barcode input) /// public bool showHeaderText { get { return lblInput.Visible; } set { lblInput.Visible = value; } } /// /// definisce se mostrare testo di commento sotto barcode /// public bool showNoteText { get { return lblData.Visible; } set { lblData.Visible = value; } } } }