// 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); } }