using AppData; using SteamWare; using System; namespace NKC_WF.WebUserControls { public partial class cmp_kitImpCheck : BaseUserControl { /// /// Folder x SQL import /// protected string _SqlImportDir = memLayer.ML.CRS("_SqlImportDir"); protected void Page_Load(object sender, EventArgs e) { } /// /// Nome file caricato /// public string fileName { get { return hfFileName.Value; } set { hfFileName.Value = value; } } /// /// Nome file caricato /// public string batchName { get { return hfBatchName.Value; } set { hfBatchName.Value = value; } } /// /// NUM TASK eseguito /// public int numTask { get { int answ = 0; int.TryParse(hfNumTask.Value, out answ); return answ; } set { hfNumTask.Value = value.ToString(); } } /// /// Esito OK a check import /// public bool checkOk { get { bool answ = false; bool.TryParse(hfCheckOk.Value, out answ); return answ; } set { hfCheckOk.Value = value.ToString(); } } /// /// File effettivamente caricato /// public bool imported { get { bool answ = false; bool.TryParse(hfImported.Value, out answ); return answ; } set { hfImported.Value = value.ToString(); } } /// /// Verifico il file e aggiorno visualizazione di conseguenza /// private void processValidation() { // controllo ed aggiorno... bool fileOk = !string.IsNullOrEmpty(fileName); string newClass1 = fileOk ? "alert alert-success" : "alert alert-secondary"; string newClass2 = checkOk ? "alert alert-success" : "alert alert-secondary"; string newClass3 = imported ? "alert alert-success" : "alert alert-secondary"; updateClass(divStep1, newClass1); updateClass(divStep2, newClass2); updateClass(divStep3, newClass3); } private static void updateClass(System.Web.UI.HtmlControls.HtmlGenericControl currControl, string newClass) { currControl.Attributes.Remove("class"); currControl.Attributes.Add("class", newClass); currControl.DataBind(); } /// /// Effettua un test di importazione o l'importazione effettiva /// /// true= solo test, false= vero import (SE non ci sono errori) public void tryImport(bool testOnly) { DateTime adesso = DateTime.Now; string dirImport = $"{_SqlImportDir}{adesso.ToString("yyyy-MM")}\\"; try { // chiamo procedura SQL x import BATCH... come test o reale secondo del parametro var tabCount = DataLayer.man.taCount.getNextNum("NumTicket"); if (tabCount.Count == 1) { numTask = tabCount[0].LastNum; } var risultati = DataLayer.man.taImpLog.importCsvKit($"{dirImport}", fileName, batchName, ";", "\n", "2", numTask, 0, 0, testOnly); // se ho delle righe di log processo... bool allCheck = true; foreach (var item in risultati) { if (!item.IsOk) { allCheck = false; } } checkOk = allCheck; // ho importato SOLO SE era stato richiesto e se NON HO avuto errori imported = checkOk && !testOnly; // ora effettua validazione e mostra eventuale esito... processValidation(); lblOutTask.Text = $"Data Import: executed tray, checkOk: {checkOk} | imported: {imported}"; } catch (Exception exc) { string fullMessage = $"KitCsvMan: Eccezione in IMPORT file:{Environment.NewLine}{exc}"; logger.lg.scriviLog(fullMessage); lblOutTask.Text = fullMessage; } } protected void lbtDoAction_Click(object sender, EventArgs e) { // in base a cosa ho in memoria procedo con successivo step, qui FAKE... //if (!imported) if (checkOk && !imported) { tryImport(false); } processValidation(); } } }