Files
NKC/NKC_WF/WebUserControls/cmp_paintingSmart.ascx.cs
T
2020-08-18 13:21:22 +02:00

194 lines
7.5 KiB
C#

using AppData;
using NKC_SDK;
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_paintingSmart : BaseUserControl
{
/// <summary>
/// Comando barcode letto
/// </summary>
protected string lastCmd
{
get
{
return hfLastBCode.Value;
}
set
{
hfLastBCode.Value = value;
}
}
/// <summary>
/// ULTIMO Comando barcode VALIDO (!="") letto
/// </summary>
protected string lastValidCmd
{
get
{
return hfLastValidBCode.Value;
}
set
{
// solo se è !=""
if (!string.IsNullOrEmpty(value))
{
hfLastValidBCode.Value = value;
}
}
}
/// <summary>
/// caricamento pagina
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
// pulisco dir temp dai file dei cartellini stampati
reportPrinter.obj.pulisciDir();
}
fixButtons();
cmp_barcode.eh_doRefresh += Cmp_barcode_eh_doRefresh;
}
private void fixButtons()
{
lbtConfirmPaint.Visible = false;
}
private void doUpdate()
{
}
private void Cmp_barcode_eh_doRefresh(object sender, EventArgs e)
{
bool doRaiseEv = false;
lastCmd = cmp_barcode.inputAcquired.ToUpper();
doRaiseEv = processLastCmd(doRaiseEv);
doUpdate();
}
private bool processLastCmd(bool doRaiseEv)
{
// verifico il datamatrix dei BIN da pitturare
if (string.IsNullOrEmpty(lastCmd)) doRaiseEv = true;
// processiamo barcode letto
decodedData decoData = DataLayer.man.decodeBcode(lastCmd);
switch (decoData.codeType)
{
case codeType.Item:
cmp_barcode.showOutput("badge badge-warning", $"{traduci("Item")} - {traduci("Ignored")}: {decoData.description}");
doRaiseEv = true;
break;
case codeType.ItemGeneric:
cmp_barcode.showOutput("badge badge-warning", $"{traduci("ItemGeneric")} - {traduci("Ignored")}: {decoData.description}");
doRaiseEv = true;
break;
case codeType.Material:
cmp_barcode.showOutput("badge badge-warning", $"{traduci("Material")} - {traduci("Ignored")}: {decoData.description}");
doRaiseEv = true;
break;
case codeType.Sheet:
cmp_barcode.showOutput("badge badge-warning", $"{traduci("Sheet")} - {traduci("Ignored")}: {decoData.description}");
doRaiseEv = true;
break;
case codeType.Stack:
cmp_barcode.showOutput("badge badge-warning", $"{traduci("Bunk")} - {traduci("Ignored")}: {decoData.description}");
doRaiseEv = true;
break;
case codeType.Batch:
cmp_barcode.showOutput("badge badge-warning", $"{traduci("Batch")} - {traduci("Ignored")}: {decoData.description}");
doRaiseEv = true;
break;
case codeType.Cart:
cmp_barcode.showOutput("badge badge-warning", $"{traduci("Cart")} - {traduci("Ignored")}: {decoData.description}");
doRaiseEv = true;
break;
case codeType.Bin:
var tabBin = DataLayer.man.taBN.getByKey(decoData.codeInt);
bool allOk = false;
// se ne trovo 1 --> OK verde
if (tabBin.Count == 1)
{
// se NON E' PAINTED ma è COMPLETE
var riga = tabBin[0];
allOk = (riga.Complete == 1 && riga.Painted == 0);
}
if (allOk)
{
// ora confronto cmd con ultimo valido
if (lastValidCmd != lastCmd)
{
cmp_barcode.showOutput("badge badge-success", $"{traduci("ValiBnCode")}: {decoData.description}");
// salvo
lastValidCmd = lastCmd;
}
else
{
// se uguale e valido --> stampo!
executePaintConfirm();
allOk = false;
doRaiseEv = false;
}
}
else
{
cmp_barcode.showOutput("badge badge-danger", $"{decoData.description} --> {traduci("NoValiAction")}");
}
lbtConfirmPaint.Visible = allOk;
break;
case codeType.BinProcessed:
cmp_barcode.showOutput("text-danger", $"{traduci("BinProcessed")} - {traduci("Ignored")}: {decoData.rawData} --> no action");
doRaiseEv = true;
break;
case codeType.SecScreen:
cmp_barcode.showOutput("badge badge-warning", $"{traduci("SecScreen")} - {traduci("Ignored")}: {decoData.description}");
doRaiseEv = true;
break;
case codeType.UNK:
default:
cmp_barcode.showOutput("text-danger", $"{traduci("UnknownData")}: {decoData.rawData} --> {traduci("NoValiAction")}");
doRaiseEv = true;
break;
}
return doRaiseEv;
}
protected void lbtConfirmPaint_Click(object sender, EventArgs e)
{
executePaintConfirm();
}
/// <summary>
/// Effettua stampa nuova label BP
/// </summary>
private void printNewLabel(decodedData decoData)
{
// chiamo procedura stampa report x BIN pitturati
string printer = DataLayer.man.getPrinter("PC-MACHINE-PAINT-STATION");
DataLayer.man.stampaDoc(decoData.codeInt.ToString(), printer, tipoDocumento.docBinPost, Request.UserHostName);
lgInfo($"PRINT req for BIN | codeInt : {decoData.codeInt} | currQueue: {printer} | tipoDoc: {tipoDocumento.docBinPost} | user: {Request.UserHostName} | IP: {currIpAddress}");
}
private void executePaintConfirm()
{
// processiamo barcode letto
decodedData decoData = DataLayer.man.decodeBcode(lastValidCmd);
// lo indico come painted (update dtPainted)
DataLayer.man.taBN.updatePainted(decoData.codeInt, DateTime.Now);
lgInfo($"cmp_paintingSmart | executePaintConfirm | codeInt: {decoData.codeInt} | raw: {decoData.rawData}");
printNewLabel(decoData);
// update tabelle!
doUpdate();
cmp_barcode.showOutput("badge badge-success", $"{traduci("PaintConfirmed")}: {decoData.description}");
}
}
}