diff --git a/ScanBox/Controller/ZebraController.cs b/ScanBox/Controller/ZebraController.cs index a961ceb..b1a387c 100644 --- a/ScanBox/Controller/ZebraController.cs +++ b/ScanBox/Controller/ZebraController.cs @@ -49,7 +49,7 @@ namespace ScaBox30.Controller #endregion #region ZEBRA -> buildPrn() - public void buildPrn(String v1, String v2, String v3, String barcode) + public void buildPrn(String v1, String v2, String v3, String v4, DateTime v5, String barcode) { try { @@ -85,6 +85,15 @@ namespace ScaBox30.Controller { etiqueta += line.Replace("$V3$", v3); } + else if (line.Contains("$V4$")) + { + etiqueta += line.Replace("$V4$", v4.ToString()); //consecutivo + } + else if (line.Contains("$V5$")) + { + // Insert formatted date/time for V5 + etiqueta += line.Replace("$V5$", v5.ToString("dd/MM/yyyy HH:mm:ss")); // fecha y hora + } else { etiqueta += line; @@ -94,7 +103,6 @@ namespace ScaBox30.Controller } - } #endregion diff --git a/ScanBox/Globals.cs b/ScanBox/Globals.cs index 65d51c3..e9bca46 100644 --- a/ScanBox/Globals.cs +++ b/ScanBox/Globals.cs @@ -22,6 +22,8 @@ namespace ScaBox30 public static Boolean debug = false; public static Boolean boxcapacity = false; public static Config cfg = new Config(); + public static int consec = 00000; + public static DateTime consecDate = DateTime.MinValue; //Fields @@ -139,7 +141,7 @@ namespace ScaBox30 codigo + ":028," + codigo + ":029," + codigo + ":030"; - //"0199170978" + ":030"; - //"ERROR"; + //"0199170978" + ":030"; + //"ERROR"; } } diff --git a/ScanBox/Principal.cs b/ScanBox/Principal.cs index c9a66fc..66a2ff8 100644 --- a/ScanBox/Principal.cs +++ b/ScanBox/Principal.cs @@ -188,6 +188,9 @@ namespace ScaBox30 // CARGA DE CONFIGURACIONES LoadConfigJson(Globals.config_json); + // Initialize daily consecutive date to today to avoid unexpected reset on first print + Globals.consecDate = DateTime.Today; + if (Globals.cfg.printerenabled) { btnPrinter.ForeColor = Color.White; @@ -371,8 +374,6 @@ namespace ScaBox30 string found_code = keyOfMaxCount; element = Globals.actual_data.Find(x => x.CCE.Equals(found_code)); //Busca el elemento que coincide con el codigo -> obtiene fila con la informacion de la etiqueta - Console.WriteLine($"Buscando código: '{found_code}'"); - Console.WriteLine($"Total registros en BD: {Globals.actual_data.Count}"); Globals.found_element = element; } @@ -409,8 +410,6 @@ namespace ScaBox30 System.Threading.Thread.Sleep(Globals.cfg.interval); } - Console.WriteLine("[DEBUG] BLOAD completado, esperando 300ms para estabilización..."); - System.Threading.Thread.Sleep(300); // El sensor necesita tiempo después de cambiar programa response = ""; @@ -744,9 +743,6 @@ namespace ScaBox30 //disable image clear timer timer1.Enabled = false; - - - //Disable button for re-clic and master barcode from being scanned TgrBtn.Enabled = false; UpdateTgrBtn(); @@ -815,10 +811,25 @@ namespace ScaBox30 } + private Form CreateDataUIInstance() + { + // Use reflection to instantiate the Form type named "DataUI" (avoids compiler ambiguity if a generated resource class shares the name) + var asm = typeof(Principal).Assembly; + var dataUiType = asm.GetTypes().FirstOrDefault(t => t.Name == "DataUI" && typeof(Form).IsAssignableFrom(t)); + if (dataUiType != null) + { + return Activator.CreateInstance(dataUiType) as Form; + } + return null; + } + private void btnBD_MouseClick(object sender, MouseEventArgs e) { - DataUI data = new DataUI(); - data.ShowDialog(); + var dataForm = CreateDataUIInstance(); + if (dataForm != null) + { + dataForm.ShowDialog(); + } } @@ -920,7 +931,6 @@ namespace ScaBox30 string sr2000w_ip; sr2000w_ip = Globals.cfg.ipscanner; - if (reader_found) { //Stop liveview. @@ -1165,16 +1175,26 @@ namespace ScaBox30 if (Globals.cfg.printerenabled) { + // Reset daily consecutive counter if day changed + if (Globals.consecDate.Date != DateTime.Today) + { + Globals.consec = 0; + Globals.consecDate = DateTime.Today; + } + string etiqueta = barcode_lbl.Text; if (Globals.found_element.CCE == etiqueta) { String v1 = Globals.found_element.nom_1; String v2 = Globals.found_element.@base + " / " + Globals.found_element.addition + " " + Globals.found_element.oeil; - String v3 = btnToogleMode.Text == operation_mode.manual ? "" : completa_parcial + " contiene: " + ok_count.ToString() + " de: " + Globals.found_element.Box_Capacity.Substring(0, 2); + //String v3 = btnToogleMode.Text == operation_mode.manual ? "" : completa_parcial + " contiene: " + ok_count.ToString() + " de: " + Globals.found_element.Box_Capacity.Substring(0,2); + String v3 = btnToogleMode.Text == operation_mode.manual ? "" : completa_parcial + ok_count.ToString() + " de " + Globals.found_element.Box_Capacity.Substring(0, 2); + String v4 = Globals.consec.ToString(); //Numero consecutivo + DateTime v5 = DateTime.Now; //Fecha y hora de impresión String barcode = Globals.found_element.CCE; - ZT231.buildPrn(v1, v2, v3, barcode); + ZT231.buildPrn(v1, v2, v3, v4, v5, barcode); switch (Globals.cfg.printertype) { @@ -1186,6 +1206,7 @@ namespace ScaBox30 break; } } + Globals.consec++; } } @@ -1258,4 +1279,4 @@ namespace ScaBox30 } -} \ No newline at end of file +}