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