private void btnPrint_Click(object sender, EventArgs e) { if (MessageBox.Show(string.Format("This will print {0} unit labels. Are you sure?", txtQty.Text), "SIMPLISTICA", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { int _labelInit = 0; txtPrinter.Text = Values.LabelPrinterAddress.ToString(); using (var _conn = new cAccesoDatosNet(Values.gDatos.Server, "REPAIRS", Values.gDatos.User, Values.gDatos.Password)) using (var _sp = new SP(_conn, "pGetContador")) { _sp.AddParameterValue("@Contador", ""); _sp.AddParameterValue("@Serv", ""); _sp.AddParameterValue("@Codigo", cboService.Value + "_UNIT_ETIQ"); _sp.AddParameterValue("@Incremento", Convert.ToInt32(txtQty.Value)); _sp.Execute(); _labelInit = Convert.ToInt32(_sp.ReturnValues()["@Contador"]); } if (txtCharacter.Text == "") { throw (new Exception("Wrong character for labels.")); } string _printerAddress = ""; int _printerResolution = 0; using (var _RS = new DynamicRS(string.Format("select descripcion,cmp_varchar,cmp_integer from ETIQUETAS..datosEmpresa where codigo='{0}'", Values.LabelPrinterAddress), Values.gDatos)) { _RS.Open(); _printerAddress = _RS["cmp_varchar"].ToString(); _printerResolution = Convert.ToInt32(_RS["cmp_integer"]); //_printerType = _RS["descripcion"].ToString().Split('|')[0]; } var _label = new ZPLLabel(70, 32, 3, _printerResolution); var _unitLabel = new SingleBarcode(_label); //_label.addLine(35, 3, 0, "C", "", "[BC][UNITNUMBER]", 0, 2.5F, 1,true); //var _param = new Dictionary<string, string>(); using (var _printer = new cRawPrinterHelper(_printerAddress)) { var _delimiterLabel = new ZPLLabel(_unitLabel.Label.width, _unitLabel.Label.height, 3, _unitLabel.Label.dpi); delimiterLabel.delim(_delimiterLabel, "START UNIT LABELS", "-"); _printer.SendUTF8StringToPrinter(_delimiterLabel.ToString(), 1); //for (var i = _labelInit; i < _labelInit + Convert.ToInt32(txtQty.Value); i++) for (var i = _labelInit + Convert.ToInt32(txtQty.Value) - 1; i >= _labelInit; i--) { _unitLabel.Parameters["VALUE"] = txtCharacter.Text + i.ToString().PadLeft(8, '0'); for (var j = 0; j < Convert.ToInt32(txtQtyLabel.Text); j++) { _printer.SendUTF8StringToPrinter(_unitLabel.ToString(), 1); } } delimiterLabel.delim(_delimiterLabel, "END UNIT LABLES", "-"); _printer.SendUTF8StringToPrinter(_delimiterLabel.ToString(), 1); } } }
private void btnPrint_Click(object sender, EventArgs e) { if (MessageBox.Show(string.Format("This will print {0} unit labels. Are you sure?", txtLOCATION.Text), "SIMPLISTICA", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { string _printerAddress = ""; int _printerResolution = 0; using (var _RS = new DynamicRS(string.Format("select descripcion,cmp_varchar,cmp_integer from ETIQUETAS..datosEmpresa where codigo='{0}'", Values.LabelPrinterAddress), Values.gDatos)) { _RS.Open(); _printerAddress = _RS["cmp_varchar"].ToString(); _printerResolution = Convert.ToInt32(_RS["cmp_integer"]); } var _label = new ZPLLabel(75, 150, 3, _printerResolution); var _racklabel = new RackLabelWOL(_label); using (var _printer = new cRawPrinterHelper(_printerAddress)) if (txtAISLE.Text == "") { using (var _rs = new DynamicRS(string.Format("select cod3,location,alias from sistemas..whmapaliases where cod3='{0}' and location='{1}'", Convert.ToString(txtCOD3.Text), Convert.ToString(txtLOCATION.Text)), Values.gDatos)) { _rs.Open(); //iterate labels _rs.ToList().ForEach(row => { _racklabel.Parameters["VALUE"] = row["location"].ToString(); _racklabel.Parameters["HASHVAL"] = row["alias"].ToString(); if (!_printer.SendUTF8StringToPrinter(_racklabel.ToString(), 1)) { CTWin.MsgError(string.Format("Error printing label {}.", row["VALUE"])); } }); } } else { using (var _rs = new DynamicRS(string.Format("select cod3,location,alias from sistemas..whmapaliasess where cod3='{0}' and location like('{1}'+'%')", Convert.ToString(txtCOD3.Text), Convert.ToString(txtAISLE.Text)), Values.gDatos)) { _rs.Open(); //iterate labels _rs.ToList().ForEach(row => { _racklabel.Parameters["VALUE"] = row["location"].ToString(); _racklabel.Parameters["HASHVAL"] = row["alias"].ToString(); if (!_printer.SendUTF8StringToPrinter(_racklabel.ToString(), 1)) { CTWin.MsgError(string.Format("Error printing label {}.", row["VALUE"])); } }); } } } }
// Print all "unprinted" labels of the selected group private void btnPrint_Click(object sender, EventArgs e) { SetFormEnabled(false); if (cboPrinters.Value.ToString() == "") { SetFormEnabled(true); CTWin.MsgError("Select a printer first."); return; } string _printerType = ""; string _printerAddress = ""; int _printerResolution = 0; using (var _RS = new DynamicRS(string.Format("select descripcion,cmp_varchar,cmp_integer from datosEmpresa where codigo='{0}'", cboPrinters.Value), Values.gDatos)) { _RS.Open(); _printerAddress = _RS["cmp_varchar"].ToString(); _printerType = _RS["descripcion"].ToString().Split('|')[0]; _printerResolution = Convert.ToInt32(_RS["cmp_integer"]); } cLabel _delimiterLabel; cLabel _label; if (_printerType == "ZPL") { _delimiterLabel = new ZPLLabel(labelHeight, labelWidth, 3, _printerResolution); if (!NoDelim) { delimiterLabel.delim(_delimiterLabel, "START", SQLParameterString.Replace(" WHERE ", "")); } _label = new ZPLLabel(labelHeight, labelWidth, 3, _printerResolution); } else { SetFormEnabled(true); throw new NotImplementedException(); } using (var _printer = new cRawPrinterHelper(_printerAddress)) { //print delimiter start if (!NoDelim) { _printer.SendUTF8StringToPrinter(_delimiterLabel.ToString(), 1); } using (var _RS = new DynamicRS(string.Format("Select * from Campos_CS where codigo='{0}'", txtCode.Text), Values.gDatos)) { _RS.Open(); _RS.ToList().ForEach(z => { float _bh = z["barcodeHeight"] is DBNull ? 0 : Convert.ToSingle(z["barcodeHeight"]); float _bm = z["barcodeWidthmult"] is DBNull ? 0 : Convert.ToSingle(z["barcodeWidthmult"]); float _cs = z["charSize"] is DBNull ? 0 : Convert.ToSingle(z["charSize"]); _label.addLine(Convert.ToInt32(z["Col"]), Convert.ToInt32(z["Fila"]), Convert.ToSingle(CT.Qnuln(z["TamTexto"])), z["Orientacion"].ToString(), z["Estilo"].ToString(), z["Texto"].ToString(), _cs, _bh, _bm); }); } Dictionary <string, string> _parameters = new Dictionary <string, string>(); SQLSelect.Split('|').ToList().ForEach(x => _parameters.Add(x, "")); string _group = ""; vsLabels.ToList().Where(line => line.Cells["PRINTED"].Value.ToString() == "N").ToList().ForEach(line => { _parameters.ToList().ForEach(p => _parameters[p.Key] = line.Cells[p.Key].Value.ToString()); if (SQLGroup != "" && _group != line.Cells[SQLGroup].Value.ToString()) { _group = line.Cells[SQLGroup].Value.ToString(); if (!NoDelim) { delimiterLabel.delim(_delimiterLabel, "GROUP", SQLGroup + "|" + _group); _printer.SendUTF8StringToPrinter(_delimiterLabel.ToString(), 1); } } _printer.SendUTF8StringToPrinter(_label.ToString(_parameters, Convert.ToInt32(line.Cells["QTY"].Value)), 1); //cRawPrinterHelper.SendUTF8StringToPrinter(_printerAddress, _label.ToString(_parameters), Convert.ToInt32("2")); ChangeLineStatus(line); }); if (!NoDelim) { delimiterLabel.delim(_delimiterLabel, "END", "***"); _printer.SendUTF8StringToPrinter(_delimiterLabel.ToString(), 1); } SetFormEnabled(true); } }
// Print HU labels public void ZPLPrintLabels(DynamicRS rs, string labelType) { string _printerAddress = Values.LabelPrinterAddress.ToString(); int _printerResolution; string _zplTemplate = "", _zplCode = ""; // Get settings for the printer using (var _RS = new StaticRS($"select ValueString,ValueInteger from MiscData where Code='{Values.LabelPrinterAddress}' and cod3='{Values.COD3}'", Values.gDatos)) { _RS.Open(); if (!_RS.EOF) { _printerAddress = _RS["ValueString"].ToString(); // "\\\\valsrv02\\VALLBLPRN003"; _printerResolution = Convert.ToInt32(_RS["ValueInteger"]); if (_printerResolution != 203 && _printerResolution != 300) { MessageBox.Show($"Printer DPI not set in database.", "Print", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } else { MessageBox.Show($"Printer {_printerAddress} not found.", "Print", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } // Get the ZPL template code using (var _RS = new StaticRS($"select ValueString from MiscData where Code='{labelType}_{_printerResolution}' and cod3='{Values.COD3}'", Values.gDatos)) { _RS.Open(); if (!_RS.EOF) { _zplTemplate = _RS["ValueString"].ToString(); } } if (_zplTemplate == "") { MessageBox.Show("ZLP template not found.", "Print HU", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } using (var _printer = new cRawPrinterHelper(_printerAddress)) { while (!rs.EOF) { // Get the Template code _zplCode = _zplTemplate; // Replace values for (int i = 0; i < rs.FieldCount; i++) { _zplCode = _zplCode.Replace("<" + rs.Fields[i] + ">", rs[rs.Fields[i]].ToString()); } // Print the label _printer.SendUTF8StringToPrinter(_zplCode, 1); rs.MoveNext(); } } }
private void btnLabelCMs_Click(object sender, EventArgs e) { if (MessageBox.Show("This will generate and print all CMs. Are you sure?", "SIMPLISTICA", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { //printer preparation string _printerAddress = ""; int _printerResolution = 0; if (Values.LabelPrinterAddress == "") { CTWin.MsgError("Select a label printer first in preferences."); return; } using (var _RS = new DynamicRS(string.Format("select descripcion,cmp_varchar,cmp_integer from ETIQUETAS..datosEmpresa where codigo='{0}'", Values.LabelPrinterAddress), Values.gDatos)) { _RS.Open(); _printerAddress = _RS["cmp_varchar"].ToString(); _printerResolution = Convert.ToInt32(_RS["cmp_integer"]); //_printerType = _RS["descripcion"].ToString().Split('|')[0]; } //label preparation var _label = new ZPLLabel(70, 31, 3, _printerResolution); var _CMLabel = new MicroCM(_label); //sp preparation using (var _printer = new cRawPrinterHelper(_printerAddress)) using (var _sp = new SP(Values.gDatos, "PGenerar_Paletags_linea")) { var _delimiterLabel = new ZPLLabel(_CMLabel.Label.width, _CMLabel.Label.height, 3, _CMLabel.Label.dpi); delimiterLabel.delim(_delimiterLabel, "START RECEIVAL", txtEntrada.Text); _printer.SendUTF8StringToPrinter(_delimiterLabel.ToString(), 1); //we will check line by line VS.ToList().Where(r => r.Cells[0].Value.ToString() != "").ToList().ForEach(r => { //first we generate the cms try { generateCM(Convert.ToInt32(txtEntrada.Value), Convert.ToInt32(r.Cells[1].Value)); } catch (Exception ex) { CTWin.MsgError(ex.Message); CTLM.StatusMsg(ex.Message); } //delimiter delimiterLabel.delim(_delimiterLabel, "LINE", r.Cells[1].Value.ToString()); _printer.SendUTF8StringToPrinter(_delimiterLabel.ToString(), 1); // then we print the labels using (var _rs = new DynamicRS(string.Format("Select cp.CM,cp.Entrada,cp.Linea,cp.Partnumber,cp.QTY,cp.xfec,c.Doc_Proveedor from CMS_PALETAGS cp inner join cab_Recepcion c on c.entrada=cp.entrada where cp.Entrada='{0}' and Linea='{1}'", Convert.ToInt32(txtEntrada.Value), Convert.ToInt32(r.Cells[1].Value)), Values.gDatos)) { _rs.Open(); _rs.ToList().ForEach(row => { _CMLabel.Parameters["CM"] = row["CM"].ToString(); _CMLabel.Parameters["RECEIVAL"] = row["Entrada"].ToString(); _CMLabel.Parameters["RECEIVAL_DATE"] = row["xfec"].ToString(); _CMLabel.Parameters["PARTNUMBER"] = row["Partnumber"].ToString(); _CMLabel.Parameters["QTY"] = row["QTY"].ToString(); if (!_printer.SendUTF8StringToPrinter(_CMLabel.ToString(), 1)) { CTWin.MsgError(string.Format("Error printing label {0}.", row["CM"])); } }); } delimiterLabel.delim(_delimiterLabel, "END RECEIVAL", txtEntrada.Text); _printer.SendUTF8StringToPrinter(_delimiterLabel.ToString(), 1); }); lstFlags["PALETAGS"] = true; CTLM.StatusMsg("CMs generated OK."); } } MessageBox.Show("Label printing task finished.", "SIMPLISTICA", MessageBoxButtons.OK, MessageBoxIcon.Information); }