private void GenerateNewLabels(List <DataRow> r) { var l = r.GroupBy(p => p[SQLGroup].ToString()); r.ForEach(x => { int _qty = SQLQty != "" ? Convert.ToInt32(x[SQLQty]):1; var _SP = new SP(Values.gDatos, "pAddEtiquetasDetalle"); _SP.AddParameterValue("codigo", txtCode.Text.ToUpper()); var _split = SQLSelect.Split('|'); string _dataString = ""; _split.ToList().ForEach(s => _dataString += x[s] + "|"); _dataString = _dataString.Substring(0, _dataString.Length - 1); _SP.AddParameterValue("parametros", SQLParameterString.Replace("'", "#")); _SP.AddParameterValue("datos", _dataString); _SP.AddParameterValue("qty", _qty); _SP.AddParameterValue("Grupo", SQLGroup != "" ? x[SQLGroup] : ""); _SP.Execute(); if (_SP.LastMsg.Substring(0, 2) != "OK") { CTWin.MsgError("Error: " + _SP.LastMsg); return; } Application.DoEvents(); }); }
private void ShowDetails() { vsLabels.ClearEspackControl(); vsLabels.ColumnCount = 0; vsLabels.Conn = Values.gDatos; string _group = ""; if (vsGroups.CurrentCell != null) { _group = (vsGroups.CurrentCell.Value.ToString() != "" ? " and grupo='" + vsGroups.CurrentCell.Value + "'" : ""); } List <string> _SelectFields = new List <string>(); _SelectFields.Add("IDREG"); _SelectFields.AddRange(SQLSelect.Split('|')); _SelectFields.Add("QTY"); _SelectFields.Add("PRINTED"); for (int i = 0; i < _SelectFields.Count; i++) { vsLabels.AddColumn(_SelectFields[i].ToUpper()); } SQLPrintable.Split('|').ToList().ForEach(x => ((CtlVSColumn)vsLabels.Columns[x.ToString()]).Print = true); ((CtlVSColumn)vsLabels.Columns[0]).Aggregate = AggregateOperations.COUNT; ((CtlVSColumn)vsLabels.Columns["QTY"]).Aggregate = AggregateOperations.SUM; var _Sql = string.Format("SELECT IDREG,DATA=datos,QTY,PRINTED=impreso FROM etiquetas_detalle WHERE codigo='{0}' and parametros='{1}'{2} order by datos,idreg", txtCode.Text, SQLParameterString.Replace("'", "#"), _group); using (var _RS = new DynamicRS(_Sql, Values.gDatos)) { _RS.Open(); _RS.ToList().ForEach(x => { List <string> row = new List <string>(); row.Add(x["IDREG"].ToString()); row.AddRange(x["DATA"].ToString().Split('|')); row.Add(x["QTY"].ToString()); row.Add(x["PRINTED"].ToString()); vsLabels.Rows.Add(row.ToArray()); //Application.DoEvents(); //vsLabels.Rows.Add(x["IDREG"].ToString(), x["DATA"].ToString(), x["QTY"].ToString(), x["PRINTED"]); }); }; //vsLabels.UpdateEspackControl(); }
// 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); } }