using AppData; using NKC_SDK; 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.WebUserControls { public partial class cmp_labelsPrint : BaseUserControl { /// /// ID univoco da IP /// protected string DeviceId { set { hfDeviceId.Value = value; } get { return hfDeviceId.Value; } } /// /// Postazione attuale (per ora cablata) /// protected string PlaceId { get { return "WRK001"; } } /// /// Sheet selezionato... /// protected int SheetID { set { hfSheetID.Value = value.ToString(); } get { int answ = 0; int.TryParse(hfSheetID.Value, out answ); return answ; } } /// /// Aggiorna dati correnti (IP, batch, sheet...) /// protected void updateCurrData() { // FORSE 5/5?!? var sheetList = DataLayer.man.taSHL.getByMLStatus(PackListID, 3, 5); if (sheetList.Count > 0) { SheetID = sheetList[0].SheetID; } DeviceId = ComLib.GetIPAddress().Replace(".", "0").Replace(":", "0"); } /// /// PackList corrente... /// public int PackListID { set { hfBatchID.Value = value.ToString(); } get { int answ = 0; int.TryParse(hfBatchID.Value, out answ); return answ; } } protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { lastObject = ""; resetShowData(); resetIcons(); updateCurrData(); } cmp_barcode.eh_doRefresh += Cmp_barcode_eh_doRefresh; cmp_barcode.eh_doReset += Cmp_barcode_eh_doReset; } private void cmp_KS_OtherItemsCart_eh_doRefresh(object sender, EventArgs e) { displInfo("Other PART added", true); } private void cmp_KS_BinCart_eh_doRefresh(object sender, EventArgs e) { displInfo("PAINT PART added", true); } private void resetShowData() { lbtPrintLabels.Visible = false; } /// /// Comando barcode letto /// protected string lastCmd { get { return hfLastBCode.Value; } set { hfLastBCode.Value = value; lastValidCmd = value; } } /// /// Ultimo object letto /// protected string lastObject { get { return hfLastObject.Value; } set { hfLastObject.Value = value; } } /// /// ULTIMO Comando barcode VALIDO (!="") letto /// protected string lastValidCmd { get { return hfLastValidBCode.Value; } set { // solo se è !="" if (!string.IsNullOrEmpty(value)) { hfLastValidBCode.Value = value; } } } private void Cmp_barcode_eh_doReset(object sender, EventArgs e) { resetIcons(); } private void Cmp_barcode_eh_doRefresh(object sender, EventArgs e) { bool doRaiseEv = false; // processo evento.. lastCmd = cmp_barcode.inputAcquired.ToUpper(); doRaiseEv = processLastCmd(doRaiseEv); // reset comando cmp_barcode.inputAcquired = ""; // aggiorno... doUpdate(); if (doRaiseEv) { raiseEvent(); } } private bool processLastCmd(bool doRaiseEv) { if (string.IsNullOrEmpty(lastCmd)) doRaiseEv = true; // processiamo barcode letto decodedData decoData = DataLayer.man.decodeBcode(lastCmd); switch (decoData.codeType) { case codeType.UNK: cmp_barcode.showOutput("text-danger", $"Unknown Data: {decoData.rawData} --> no action"); resetDisplay(true); doRaiseEv = true; break; case codeType.Item: cmp_barcode.showOutput("badge badge-success", $"Valid IT Code: {decoData.rawData}"); processItemSuggestion(decoData.codeType, decoData.rawData, decoData.codeInt); break; case codeType.ItemGeneric: cmp_barcode.showOutput("badge badge-success", $"IG Code - ignored: {decoData.rawData}"); resetDisplay(true); doRaiseEv = true; break; case codeType.OtherItem: cmp_barcode.showOutput("badge badge-success", $"Generic PART Code - ignored: {decoData.rawData}"); resetDisplay(true); doRaiseEv = true; break; case codeType.Material: cmp_barcode.showOutput("badge badge-warning", $"MATERIAL - ignored: {decoData.description}"); resetDisplay(true); doRaiseEv = true; break; case codeType.Sheet: cmp_barcode.showOutput("badge badge-warning", $"SHEET - ignored: {decoData.description}"); resetDisplay(true); doRaiseEv = true; break; case codeType.Stack: cmp_barcode.showOutput("badge badge-warning", $"BUNK - ignored: {decoData.description}"); resetDisplay(true); doRaiseEv = true; break; case codeType.Batch: cmp_barcode.showOutput("badge badge-warning", $"BATCH - ignored: {decoData.description}"); resetDisplay(true); doRaiseEv = true; break; case codeType.Cart: cmp_barcode.showOutput("badge badge-warning", $"CART - ignored: {decoData.description}"); resetDisplay(true); doRaiseEv = true; break; case codeType.Bin: cmp_barcode.showOutput("badge badge-warning", $"BIN NOT PAINTED - Ignored: {decoData.description}"); resetDisplay(true); doRaiseEv = true; break; case codeType.BinProcessed: cmp_barcode.showOutput("badge badge-warning", $"BIN PAINTED - ignored: {decoData.description}"); resetDisplay(true); doRaiseEv = true; break; default: cmp_barcode.showOutput("text-danger", $"Unknown Data: {decoData.rawData} --> no action"); resetDisplay(true); doRaiseEv = true; break; } return doRaiseEv; } /// /// Processo il DataMatrix letto /// /// /// /// private void processItemSuggestion(codeType tipoCod, string rawData, int codeInt) { DS_App.ItemListDataTable tabItem = null; divInfo.Visible = false; // processo suggerimenti x ITEM / cart / bin dato suo RawData (Dtmx) e Cod univoco (intero) switch (tipoCod) { case codeType.Item: tabItem = DataLayer.man.taIL.getBySearch(codeInt, rawData, 0, 999); if (tabItem.Count == 1) { showItemDetail(true, tabItem[0], false); } else if (tabItem.Count == 0) { showItemDetail(false, null, true); } // mostro print! lbtPrintLabels.Visible = true; break; default: lastObject = ""; // nascondo print! lbtPrintLabels.Visible = false; break; } } protected void lbtPrintLabels_Click(object sender, EventArgs e) { // chiamo procedura stampa report x etichette dei pezzi lavorati offline string printer = DataLayer.man.getPrinter("PC-MACHINE-PARTS"); // mando stampa.... bool fatto = DataLayer.man.stampaDoc(itemIdSelected.ToString(), printer, tipoDocumento.docPart, Request.UserHostName); if (fatto) { displInfo(traduci("PrintSendOk"), true); } else { displError(traduci("PrintSendKo"), true); } raiseEvent(); } /// /// Mostra errore ed effettua reset vari... /// /// /// protected void displInfo(string infoMessage, bool resetAll) { lblSuccessMsg.Text = infoMessage; divError.Visible = false; divInfo.Visible = true; resetDisplay(resetAll); } /// /// Mostra errore ed effettua reset vari... /// /// /// protected void displError(string errorMessage, bool resetAll) { lblErrorMsg.Text = errorMessage; divError.Visible = true; divInfo.Visible = false; resetDisplay(resetAll); } /// /// Reset visualizzazione /// /// nasconde TUTTO protected void resetDisplay(bool resetAll) { if (resetAll) { divError.Visible = false; divInfo.Visible = false; divItemDet.Visible = false; // elimino item sel... itemIdSelected = 0; } resetShowData(); } /// /// Mostra o nasconde dettaglio su ITEM letto /// /// /// /// private void showItemDetail(bool showItem, DS_App.ItemListRow itemRow, bool showError) { resetShowData(); divItemDet.Visible = showItem; divError.Visible = showError; if (showError) { displError("Item not found", true); } if (showItem) { lblItemCode.Text = itemRow.ItemExtCode; lblItemDesc.Text = itemRow.ItemDesc; lblItemDtmx.Text = itemRow.ItemDtmx; itemIdSelected = itemRow.ItemID; } } public int itemIdSelected { get { int answ = 0; int.TryParse(hfItemID.Value, out answ); return answ; } set { hfItemID.Value = value.ToString(); bool showBtn = value != 0; // fix visibilità lbtCancel.Visible = showBtn; } } private void resetIcons() { lblDestination.CssClass = "text-secondary"; lblMessage.Text = ""; lblDestination.Text = ""; lblLastBCode.Text = ""; lbtCancel.Visible = false; } protected DS_App.BinsDataTable currBinTab { get { return DataLayer.man.taBN.getByItemID(itemIdSelected); } } protected DS_App.CartsDataTable currCartTab { get { return DataLayer.man.taCR.getByItemID(itemIdSelected); } } private void doUpdate() { fixVisibility(); } private void fixVisibility() { } protected void lbtCancel_Click(object sender, EventArgs e) { // resetto item selezionato... DataLayer.man.taIL.updateStatus(itemIdSelected, 1, PlaceId); resetDisplay(true); showItemDetail(false, null, false); } } }