示例#1
0
        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);
        }