using AppData; using Newtonsoft.Json; using SteamWare; using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace NKC_WF.site { public partial class BatchPreview : System.Web.UI.Page { /// /// Batch corrente... /// public int BatchId { get { int answ = memLayer.ML.QSI("BatchId"); return answ; } } /// /// Indice bunk selezionato (0..n-1) /// protected int bunkIndex { get { return cmp_BP_bunkList.selIndex; } set { cmp_BP_bunkList.selIndex = value; } } /// /// BunkId selezionato /// protected int BunkId { get { return cmp_BP_bunkList.BunkIdSel; } } /// /// Indice sheet selezionato (0..n-1) /// protected int sheetIndex { get { return cmp_BP_sheetList.selIndex; } set { cmp_BP_sheetList.selIndex = value; } } /// /// BunkId selezionato /// protected int SheetId { get { return cmp_BP_sheetList.SheetIdSel; } } /// /// valore selezionato nello slider /// protected int valSlider { get { return cmp_slider.selValue; } set { cmp_slider.selValue = value; } } /// /// Chaive URL base x gestione sheet del batch corrente /// protected string tabSheetKey; /// /// Elenco fogli della gestione corrente /// protected DS_App.SheetListDataTable tabSheets { get { DS_App.SheetListDataTable answ = null; string rawData = memLayer.ML.getRSV(tabSheetKey); if (string.IsNullOrEmpty(rawData)) { answ = DataLayer.man.taSHL.getByBatch(BatchId); tabSheets = answ; } else { answ = JsonConvert.DeserializeObject(rawData); } return answ; } set { string rawData = JsonConvert.SerializeObject(value); memLayer.ML.setRSV(tabSheetKey, rawData, 60); } } /// /// Restituisce la riga dall'indice inserito ( /// /// valore 1..maxSheets /// protected DS_App.SheetListRow rigaSel(int indice) { DS_App.SheetListRow answ = null; // init var int maxNum = tabSheets.Count; // base 0 --> riduco di 1... indice--; // controllo valore sia accettabile... indice = indice < 0 ? 0 : indice; indice = indice >= maxNum ? maxNum - 1 : indice; try { answ = tabSheets[indice]; } catch { } // restituisco! return answ; } /// /// Restituisce la PRIMA riga dal codice BUNK inserito /// /// valore 1..numBunk /// protected DS_App.SheetListRow rigaByBunk(int BunkId) { DS_App.SheetListRow answ = null; try { answ = tabSheets.First(x => x.StackID == BunkId); } catch { } // restituisco! return answ; } /// /// Restituisce la riga dal codice Sheet inserito /// /// valore 1..numBunk /// protected DS_App.SheetListRow rigaBySheet(int SheetId) { DS_App.SheetListRow answ = null; try { answ = tabSheets.First(x => x.StackID == SheetId); } catch { } // restituisco! return answ; } /// /// caicamento pagina /// /// /// protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { tabSheetKey = $"{memLayer.ML.redHash($"TabSheets")}:{BatchId}"; // imposto bunk! cmp_BP_bunkList.BatchId = BatchId; setupSlider(); doUpdate(); } cmp_BP_bunkList.eh_doRefresh += Cmp_BP_bunkList_eh_doRefresh; cmp_BP_sheetList.eh_doRefresh += Cmp_BP_sheetList_eh_doRefresh; cmp_slider.eh_doRefresh += Cmp_slider_eh_doRefresh; } /// /// Setup slider da num fogli /// private void setupSlider() { cmp_slider.minVal = 1; cmp_slider.maxVal = tabSheets.Count; cmp_slider.selValue = 1; } private void doUpdate() { updateBySlider(); } private void Cmp_slider_eh_doRefresh(object sender, EventArgs e) { updateBySlider(); } /// /// Effettua update da Slider --> valore selezionato /// private void updateBySlider() { // il valore assoluto dello slider è già corretto... cerco nella tab! DS_App.SheetListRow currRow = rigaSel(valSlider); if (currRow != null) { // recupero indice bunk e sheets e seleziono bunkIndex = currRow.StackIndex - 1; cmp_BP_sheetList.BunkId = cmp_BP_bunkList.BunkIdSel; sheetIndex = currRow.SheetIndex - 1; // update svg... cmp_MU_svgViewer.SheetId = currRow.SheetID; } } private void Cmp_BP_sheetList_eh_doRefresh(object sender, EventArgs e) { // calcolo indice slider da chiave sheet... int num = 1; foreach (var item in tabSheets) { if (item.SheetID == cmp_BP_sheetList.SheetIdSel) { break; } else { num++; } } cmp_slider.selValue = num; // update svg... cmp_MU_svgViewer.SheetId = cmp_BP_sheetList.SheetIdSel; } private void Cmp_BP_bunkList_eh_doRefresh(object sender, EventArgs e) { DS_App.SheetListRow currRow = rigaByBunk(cmp_BP_bunkList.BunkIdSel); if (currRow != null) { // calcolo indice slider da chiave sheet... int num = 1; foreach (var item in tabSheets) { if (item.SheetID == currRow.SheetID) { break; } else { num++; } } cmp_slider.selValue = num; // recupero bunk e sheets e seleziono cmp_BP_sheetList.BunkId = cmp_BP_bunkList.BunkIdSel; sheetIndex = currRow.SheetIndex - 1; // update svg... cmp_MU_svgViewer.SheetId = currRow.SheetID; } } } }