using AppData; using SteamWare; using System; using System.Linq; using System.Text.RegularExpressions; namespace C_TRACK.WebUserControls { public partial class mod_addTask : BaseUserControl { #region Public Events /// /// evento aggiunta record /// public event EventHandler eh_created; #endregion Public Events #region Public Properties /// /// Cod ARTICOLO corrente /// public string CodArticolo { get { return memLayer.ML.StringSessionObj("currCodArt"); } set { memLayer.ML.setSessionVal("currCodArt", value); } } /// /// Input da processare... /// public string newInput { set { processInput(value); } } /// /// Cod COMMESSA corrente /// public string NumTask { get { return memLayer.ML.StringSessionObj("currNumTask"); } set { memLayer.ML.setSessionVal("currNumTask", value); } } /// /// QTA da produrre /// public int Quantita { get { return memLayer.ML.IntSessionObj("currQta"); } set { memLayer.ML.setSessionVal("currQta", value); } } /// /// Tempo stimato x produzione /// public float TimeEst { get { float answ = -1; string rawVal = memLayer.ML.StringSessionObj("currTimeEst"); float.TryParse(rawVal, out answ); return answ; } set { memLayer.ML.setSessionVal("currTimeEst", value); } } #endregion Public Properties #region Private Methods private void checkValori() { // verifica quali valori siano disponibili e di conseguenza visualizza COLORE... divArticolo.Attributes.Remove("class"); divCommessa.Attributes.Remove("class"); divQta.Attributes.Remove("class"); divTime.Attributes.Remove("class"); divArticolo.Attributes.Add("class", CodArticolo != "" ? "col text-center table-success text-success" : "col text-center text-secondary"); divCommessa.Attributes.Add("class", NumTask != "" ? "col text-center table-success text-success" : "col text-center text-secondary"); divQta.Attributes.Add("class", Quantita > 0 ? "col text-center table-success text-success" : "col text-center text-secondary"); divTime.Attributes.Add("class", TimeEst > 0 ? "col text-center table-success text-success" : "col text-center text-secondary"); } /// /// Effettua riconoscimento input e determina valori commessa / articolo / qta /// /// private void processInput(string value) { // verifico se sia un articolo... Match testReset = Regex.Match(value, mUtils.reReset); Match testDelete = Regex.Match(value, mUtils.reDelete); Match testAddNew = Regex.Match(value, mUtils.reAddNew); Match testCodArt = Regex.Match(value, mUtils.reCodArt); Match testNumTask = Regex.Match(value, mUtils.reNumTask); Match testQta = Regex.Match(value, mUtils.reQta); Match testTempo = Regex.Match(value, mUtils.reTempoPrev); if (testReset.Success) { CodArticolo = ""; NumTask = ""; Quantita = 0; TimeEst = 0; } else if (testDelete.Success) { // creo... DLMan.taTL.deleteQuery(NumTask); // resetto! CodArticolo = ""; NumTask = ""; Quantita = 0; // invoco update... if (eh_created != null) { eh_created(this, new EventArgs()); } } else if (testAddNew.Success) { // controllo condizione richiesta tempo x setup Task bool confAddTaskReqTime = memLayer.ML.CRB("confAddTaskReqTime"); // se NON richiesto --> Time=0 if (!confAddTaskReqTime) { TimeEst = 0; } // se qta > 0 ed ho articolo e commessa... if (Quantita > 0 && !string.IsNullOrEmpty(CodArticolo) && !string.IsNullOrEmpty(NumTask) && (!confAddTaskReqTime || TimeEst > 0)) { // creo... DLMan.taTL.insertQuery(NumTask, CodArticolo, Quantita, TimeEst); // resetto! CodArticolo = ""; NumTask = ""; Quantita = 0; // invoco update... if (eh_created != null) { eh_created(this, new EventArgs()); } } } else if (testTempo.Success) { string newVal = value; // effettuo pulizia variabile da conf... foreach (var item in mUtils.lRepCleanTime) { string[] repVal = item.Split('|'); if (repVal.Length > 1) { newVal = newVal.Replace(repVal[0], repVal[1]); } } float tPrev = 0; float.TryParse(newVal, out tPrev); // se configurata conversione procedo if (mUtils.TimeEstFactor != 1) { tPrev = tPrev / mUtils.TimeEstFactor; } // assegno! TimeEst = tPrev; } else if (testCodArt.Success) { CodArticolo = value; } else if (testNumTask.Success) { NumTask = value; } else if (testQta.Success) { int qta = 0; int.TryParse(value, out qta); Quantita = qta; } // non match con RegExp --> ricerca ESPLICITA, se abilitato ricerca estesa if (memLayer.ML.CRB("OptEnableMapoIn") && !(testCodArt.Success || testNumTask.Success)) { var tabArt = DLMan.taAnArt.getByKey(value); if (tabArt.Rows.Count > 0) { CodArticolo = value; } else { var tabTask = DLMan.taTL.getByKey(value); if (tabTask.Rows.Count > 0) { NumTask = value; } } } checkValori(); } #endregion Private Methods #region Protected Methods protected void lbtReset_Click(object sender, EventArgs e) { processInput(memLayer.ML.CRS("regExp_KO")); } protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { CodArticolo = ""; NumTask = ""; Quantita = 0; } checkValori(); } #endregion Protected Methods } }