using MapoDb; using Newtonsoft.Json; using SteamWare; using System; using System.Collections.Generic; using System.Web.UI; namespace MP_ADM.WebUserControls { public partial class mod_barcode : BaseUserControl { #region Protected Fields /// /// dictionary comandi ammessi /// protected Dictionary _comandi = new Dictionary(); /// /// dictionary dei valori ammessi /// protected Dictionary _tabValori = new Dictionary(); /// /// RegExp x Find --> replace (se vettore è | delimited) /// protected string regExp_Find = memLayer.ML.cdv("regExp_Find"); /// /// RegExp x SAVE KIT /// protected string regExp_KitSave = memLayer.ML.cdv("regExp_KitSave"); /// /// RegExp x START KIT /// protected string regExp_KitStart = memLayer.ML.cdv("regExp_KitStart"); /// /// RegExp x RESET / CANCEL /// protected string regExp_KO = memLayer.ML.cdv("regExp_KO"); /// /// RegExp x CONFERMA /// protected string regExp_OK = memLayer.ML.cdv("regExp_OK"); /// /// RegExp x Replace da Find (se vettore è | delimited) /// protected string regExp_Replace = memLayer.ML.cdv("regExp_Replace"); #endregion Protected Fields #region Public Events /// /// evento comando registrato /// public event EventHandler eh_comandoRegistrato; /// /// evento lettura dati (grezza) effettuata /// public event EventHandler eh_dataRead; #endregion Public Events #region Protected Properties /// /// 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); } } #endregion Protected Properties #region Public Properties public string BCodeVal { get { return txtInput.Text.Trim().ToUpper(); } set { txtInput.Text = value; } } /// /// Verifica se il cod ordine è OK: /// coerenza tra ordine e iniziale ordine (OPR/KIT) /// public bool checkOrdOk { get { return codOrd.StartsWith(codOrdPre); } } public string codArt { get { return memLayer.ML.StringSessionObj(string.Format("codArt_{0}", uid)); } set { memLayer.ML.setSessionVal(string.Format("codArt_{0}", uid), value); } } public string codGruppo { get { return memLayer.ML.StringSessionObj(string.Format("codGruppo_{0}", uid)); } set { memLayer.ML.setSessionVal(string.Format("codGruppo_{0}", uid), value); } } public string codOrd { get { return memLayer.ML.StringSessionObj(string.Format("codOrd_{0}", uid)); } set { memLayer.ML.setSessionVal(string.Format("codOrd_{0}", uid), value); } } /// /// Valore validazione codici ORDINE come STARTING (es: OPR,KIT) /// public string codOrdPre { get { return memLayer.ML.StringSessionObj(string.Format("codOrdPre_{0}", uid)); } set { memLayer.ML.setSessionVal(string.Format("codOrdPre_{0}", uid), value); } } /// /// elenco dei comandi riconosciuti /// public Dictionary comandiAmmessi { get { return _comandi; } set { _comandi = value; } } /// /// comando registrato dal barcode /// public inputComando comandoRegistrato { get { return comando; } } public string descArt { get { return memLayer.ML.StringSessionObj(string.Format("descArt_{0}", uid)); } set { memLayer.ML.setSessionVal(string.Format("descArt_{0}", uid), value); } } public string idxMacc { get { return memLayer.ML.StringSessionObj(string.Format("idxMacc_{0}", uid)); } set { memLayer.ML.setSessionVal(string.Format("idxMacc_{0}", uid), value); } } public string kitCode { get { return memLayer.ML.StringSessionObj(string.Format("kitCode_{0}", uid)); } set { memLayer.ML.setSessionVal(string.Format("kitCode_{0}", uid), value); } } public string nomeMacc { get { return memLayer.ML.StringSessionObj(string.Format("nomeMacc_{0}", uid)); } set { memLayer.ML.setSessionVal(string.Format("nomeMacc_{0}", uid), value); } } public int qta { get { return memLayer.ML.IntSessionObj(string.Format("qta_{0}", uid)); } set { memLayer.ML.setSessionVal(string.Format("qta_{0}", uid), value); } } /// /// oggetto comando locale alla classe /// public string rawInput { get { string answ; if (memLayer.ML.isInSessionObject("barcodeRaw")) { answ = memLayer.ML.StringSessionObj("barcodeRaw"); } else { answ = ""; } return answ; } set { memLayer.ML.setSessionVal("barcodeRaw", value, false); } } /// /// tabella di valori ammissibili /// public Dictionary tabValori { get { return _tabValori; } set { _tabValori = value; } } /// /// scrive nella label input /// public string txtInput2show { set { lblInput.Text = value; } } /// /// scrive nella label richiesta /// public string txtRich2show { set { lblRichiesta.Text = value; } } /// /// scrive nella label valore /// public string txtVal2show { set { lblValore.Text = value; } } #endregion Public Properties #region Private Methods private bool checkComandi() { bool answ = false; // controllo eventuali comandi CUSTOM if (BCodeVal == regExp_KO) { comando.isValid = true; answ = true; resetData(); } else if (BCodeVal == regExp_KitStart) { comando.isValid = true; answ = true; resetData(); } else if (BCodeVal == regExp_KitSave) { comando.isValid = true; answ = true; resetData(); } else if (BCodeVal == regExp_OK) { // comando valido SE ho ordine coerente... if (checkOrdOk) { comando.isValid = true; // recupero il codGruppo da macchina... (primo) if (codGruppo == "") { var tabAG = DataLayerObj.taAG.getFaseByIdxMacc(idxMacc); if (tabAG.Rows.Count > 0) { codGruppo = tabAG[0].CodGruppo; } } // controllo se ho tutti i dati necessari... if (codOrd != "" && codArt != "" && codGruppo != "" && idxMacc != "" && qta > 0) { // setup parametri bool trovato = false; decimal TCiclo = 0; int pzPallet = 1; DS_ProdTempi.ODLDataTable tabODL = new DS_ProdTempi.ODLDataTable(); DS_ProdTempi.PromesseODLDataTable tabPODL = new DS_ProdTempi.PromesseODLDataTable(); if (memLayer.ML.cdvb("mpAdm_TcFromPODL")) { // controllo se richiesto ricerca preliminare x articolo + macchina if (memLayer.ML.cdvb("mpAdm_TcByMachine")) { // recupero TC promessa da ultimo per articolo/macchina tabPODL = DataLayerObj.taPODL.getByMaccArt(idxMacc, codArt, "", false); } // se non lo trovo (o non ho cercato...) prendo da SOLO ARTICOLO if (tabPODL.Rows.Count == 0) { tabPODL = DataLayerObj.taPODL.getByMaccArt("", codArt, "", false); } // recupero TCiclo if (tabPODL.Rows.Count > 0) { TCiclo = tabPODL[0].TCAssegnato; pzPallet = tabPODL[0].PzPallet; trovato = true; } } else { // controllos e richiesto ricerca preliminare x articolo + macchina if (memLayer.ML.cdvb("mpAdm_TcByMachine")) { // recupero TC promessa da ultimo per articolo/macchina tabODL = DataLayerObj.taODL.getByMacchinaArticolo(codArt, idxMacc); } // se non lo trovo (o non ho cercato...) prendo da SOLO ARTICOLO if (tabODL.Rows.Count == 0) { tabODL = DataLayerObj.taODL.getByMacchinaArticolo(codArt, ""); } // recupero TCiclo if (tabODL.Rows.Count > 0) { TCiclo = tabODL[0].TCAssegnato; pzPallet = tabODL[0].PzPallet; trovato = true; } } // se non lo trovo è valore default da config DB (oppure 59...) if (!trovato) { TCiclo = memLayer.ML.CRI("TCicloStd"); } if (TCiclo == 0) { TCiclo = 59; } // creo nuova PROMESSA ODL... DataLayerObj.taPODL.insertQuery(codOrd, codOrd, true, codArt, codGruppo, idxMacc, qta, TCiclo, DateTime.Now, 1, pzPallet, descArt); } } // resetto ricaricando Response.Redirect(titolo); } return answ; } private bool checkIntServ() { bool answ = false; // IN PRIMIS se c'è in config preprocesso BCode x Find-Replace string BCodeFilt = BCodeVal; if (regExp_Find != "") { // splitto i vettori var vettFind = regExp_Find.Split('|'); var vettRepl = regExp_Replace.Split('|'); // se ho tanti find quanti replace procedo... if (vettFind.Length == vettRepl.Length) { for (int i = 0; i < vettFind.Length; i++) { BCodeFilt = BCodeFilt.Replace(vettFind[i], vettRepl[i]); } } else { logger.lg.scriviLog(string.Format("Attenzione: problema in decodifica barcode find/replace, i parametri non corrispondono una volta esplosi i vettori:{0}find: {1}{0}replace: {2}", Environment.NewLine, regExp_Find, regExp_Replace)); } } // cerco esplicitamente sul DB IntegrationServices... var risultato = DataLayerObj.taIS_TrDati.getOrdini(BCodeFilt); if (risultato.Rows.Count > 0) { var rRes = risultato[0]; // verifico da config COME decodificare IS... string BCodeIS_DType = memLayer.ML.cdv("BCodeIS_DType"); // verifico corrispondano i formati... if (rRes.DataType == BCodeIS_DType) { // cerco i dati e decodifico... togliendo eventuale VETTORE "[..]" var jsonData = risultato[0].ValueOUT.Replace("[", "").Replace("]", ""); try { if (BCodeIS_DType == "Colcom_Order") { // a seconda del tipo decodifico... ISTD_OrderColcom currVal = JsonConvert.DeserializeObject(jsonData); comando.isValid = true; answ = true; // salvo ordine / articolo / qta codOrd = currVal.CodOrdine; codArt = currVal.CodArticolo; descArt = currVal.DescrArticolo; kitCode = currVal.KitCode; qta = (int)currVal.Qta; comando.valore = jsonData;// string.Format("{0}#{1}#{2:N0}", codOrd, codArt, qta); comando.currCmdIn = "OrdArtQta"; } } catch (Exception exc) { logger.lg.scriviLog(string.Format("Errore in decodifica obj JSON:{0}{1}", Environment.NewLine, exc), tipoLog.EXCEPTION); } } } return answ; } private bool checkMacc() { bool answ = false; // verifico se il barcode è di una macchina... var risultato = DataLayerObj.taMacchine.GetByIdx(BCodeVal); if (risultato.Rows.Count > 0) { idxMacc = BCodeVal; comando.valore = BCodeVal; comando.isValid = true; answ = true; // recupero altri dati var rRes = risultato[0]; nomeMacc = rRes.Descrizione; // imposto il gruppo cercandolo... var gruppi = DataLayerObj.taAG.getByIdxMacc(BCodeVal); if (gruppi.Rows.Count > 0) { // salvo primo... codGruppo = gruppi[0].CodGruppo; } } return answ; } /// /// verifica parametri in sessione x i valori eventualmente da mettere al comando... /// private void checkParam() { // ho macchina ed articolo? bool hasAllData = (idxMacc != "" && codArt != ""); string valOut = ""; if (codArt != "") { valOut += string.Format("{0}
Art: {1} | qta: {2:N0} | kit: {3}
{4}", codOrd, codArt, qta, kitCode, descArt); } if (idxMacc != "") { valOut += string.Format("
{0} | {1}", idxMacc, nomeMacc); } // imposto... comando.valoreTrad = valOut; // controllo se ho tutto... comando.descrComando = ""; if (idxMacc == "") { comando.descrComando += " - Manca Impianto - "; } if (codArt == "" || codOrd == "") { comando.descrComando += " - Manca Ordine Produzione - "; } if (!checkOrdOk) { comando.descrComando += " - Tipo Ordine errato - "; } if (hasAllData && checkOrdOk) { comando.descrComando = "Confermare caricamento"; } } /// /// 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"; } } /// /// 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); } } /// /// 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); } } /// /// inizializzazione specifica barcode /// private void myInitialize() { if (!Page.IsPostBack) { lblInput.Text = traduci("PregoInserireBarcode"); comando = new inputComando(); } } private void resetData() { // resetto idxMacc = ""; nomeMacc = ""; codArt = ""; descArt = ""; codGruppo = ""; codOrd = ""; qta = 0; } #endregion Private Methods #region Protected Methods /// /// al caricamento della pagina... /// /// /// protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { resetData(); } DetectAgent(); myInitialize(); } /// /// barcode completato con invio... /// /// /// protected void txtInput_TextChanged(object sender, EventArgs e) { processInput(); } #endregion Protected Methods #region Public Methods /// /// effettua la lettura da sessione del comando cliccato e lo inserisce come fosse barcode /// public void loadBtnClickComando() { BCodeVal = memLayer.ML.StringSessionObj("btnCmdPress"); memLayer.ML.emptySessionVal("btnCmdPress"); processInput(); } public void processInput() { comando.isValid = false; bool gotIt = false; gotIt = checkComandi(); if (!gotIt) { gotIt = checkMacc(); } if (!gotIt) { gotIt = checkIntServ(); } // ora check globale... checkParam(); // verifico se c'è stato input evento if (comando.isValid) { if (comando.currCmdIn != "" || comando.descrComando != "") { 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(); rawInput = BCodeVal; if (eh_dataRead != null) { eh_dataRead(this, new EventArgs()); } } BCodeVal = ""; } /// /// reset del controllo /// public void resetMe() { comando = new inputComando(); txtInput2show = "Prego inserire barcode"; txtVal2show = ""; txtRich2show = ""; } #endregion Public Methods } }