Esempio n. 1
0
        /// <summary>
        /// 打印
        /// </summary>
        /// <param name="doc"></param>
        /// <param name="printName">打印机名称</param>
        /// <param name="templateType">模板类型</param>
        /// <param name="content">模板数据</param>
        /// <returns></returns>
        public string printLable(bpac.DocumentClass doc, String printName, string templateType, string content)
        {
            if (string.IsNullOrEmpty(content))
            {
                return("1");
            }

            //未找到打印机
            if (printName == null || "".Equals(printName))
            {
                return("2");
            }

            doc.SetPrinter(printName, true);
            //Console.WriteLine("将调用兄弟打印机:" + doc.Printer.Name + " 打印" + doc.Printer.IsPrinterSupported(printName));
            //打印的干活
            //打开一个模板文件
            //解析需打印的内容
            JObject obj = JObject.Parse(content);
            JArray  sns = (JArray)obj["sn"];

            JToken[] s = sns.ToArray();
            //是否ROS
            string isRos = (string)obj["ros"];

            if ("1".Equals(isRos))
            {
                if (s.Length < 11)
                {
                    //根据定制类型加载不同的模板
                    //加载10个的模板
                    return(printTemplate(doc, ROS_IMEI_10, obj, s));
                }
                else
                {
                    //加载20个的模板
                    return(printTemplate(doc, ROS_IMEI_20, obj, s));
                }
            }
            else
            {
                if (s.Length < 11)
                {
                    //加载10个的模板
                    return(printTemplate(doc, IMEI_10, obj, s));
                }
                else
                {
                    //加载20个的模板
                    return(printTemplate(doc, IMEI_20, obj, s));
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Imprime un collant avec les informations du participant
        /// </summary>
        /// <param name="id">ID du participant</param>
        /// <param name="nickname">Pseudonyme</param>
        /// <param name="adult">Si le participant est majeur</param>
        /// <param name="clan">Clan à afficher sur le tag</param>
        /// <param name="seat">Nom du siège</param>
        /// <param name="access">Type d'accès</param>
        /// <param name="url">Url du QR Code</param>
        public static void Print(string id, string nickname, string adult, string clan, string seat, string access, string url)
        {
            // Créer l'objet du label
            var label = new bpac.DocumentClass();

            // Ouvrir le template
            label.Open(System.IO.Path.GetFullPath("joueur.lbx")); // CRITIQUEMENT IMPORTANT QUE CE JOUEUR.LBX SE TROUVE AVEC LE SOFTWARE

            // Changer le texte
            label.SetText(1, adult);
            label.SetText(2, seat == string.Empty ? string.Empty : "Siège " + seat);
            label.SetText(3, clan);
            label.SetText(4, nickname);
            label.SetText(5, access.ToUpper());
            label.SetText(0, "# " + id);

            label.SetBarcodeData(0, url); // Code barre

            // Presto!
            label.SetPrinter(Properties.Settings.Default.printer, true);

            label.StartPrint("Label", PrintOptionConstants.bpoDefault);

            label.PrintOut(1, PrintOptionConstants.bpoDefault);

            label.EndPrint();

            label.Close();
        }
Esempio n. 3
0
        /// <summary>
        /// 打印模板
        /// </summary>
        /// <param name="doc"></param>
        /// <param name="template"></param>
        /// <param name="obj"></param>
        /// <param name="sns"></param>
        /// <returns></returns>
        private static string printTemplate(bpac.DocumentClass doc, string template, JObject obj, JToken[] sns)
        {
            if (doc.Open(template))
            {
                //订单号
                string pi = (string)obj["pi"];
                //型号
                string model = (string)obj["model"];
                //箱号
                string no = (string)obj["no"];
                //数量
                string qty = (string)obj["qty"];

                int offset = pi.Length - 2;
                //设置PI号后面带的箱号
                string piNo = no;
                if (piNo.Length == 1)
                {
                    piNo = "00" + piNo;
                }
                if (piNo.Length == 2)
                {
                    piNo = "0" + piNo;
                }
                //设置PI号后面带的数量
                string piQty = qty;
                if (piQty.Length == 1)
                {
                    piQty = "00" + piQty;
                }
                if (piQty.Length == 2)
                {
                    piQty = "0" + piQty;
                }
                //客户名称截取订单号最后两位
                string customer = null;
                if (pi.Contains("-"))
                {
                    int strIdx = pi.IndexOf("-");

                    customer = pi.Substring(strIdx - 2, 2);
                }
                else
                {
                    customer = pi.Substring(offset, 2);
                }

                /*
                 * 替换模板的value
                 */
                doc.GetObject("customer").Text = customer;
                doc.GetObject("model").Text    = model;
                doc.GetObject("pi").Text       = (pi + piNo + piQty);
                // doc.GetObject("no").Text = no;
                //最新需求箱号设置成空
                doc.GetObject("no").Text  = no;
                doc.GetObject("qty").Text = qty + "pcs";
                //二维码
                if (doc.GetObject("qr") != null)
                {
                    doc.GetObject("qr").Text = pi + ";" + customer + ";" + model + ";" + no + ";" + qty;
                }


                //设置PI单号条型码
                doc.SetBarcodeData(doc.GetBarcodeIndex("pIbarcode"), (pi + piNo + piQty));

                //设置barcode
                int idx;
                for (idx = 0; idx < sns.Length; idx++)
                {
                    doc.SetBarcodeData(doc.GetBarcodeIndex("barcode" + (idx + 1)), sns[idx] + "");
                }

                //将多余的SN框设置成空的
                if (idx < 10)
                {
                    Console.WriteLine("idx = " + idx);
                    for (; idx < 10; idx++)
                    {
                        doc.GetObject("sn" + (idx + 1)).Text = "";
                        doc.SetBarcodeData(doc.GetBarcodeIndex("barcode" + (idx + 1)), "");
                    }
                    Boolean st = doc.StartPrint("", bpac.PrintOptionConstants.bpoDefault);
                    Boolean po = doc.PrintOut(1, bpac.PrintOptionConstants.bpoDefault);
                    // Console.WriteLine(st + "--" + doc.ErrorCode + "---" + po);
                    doc.EndPrint();
                    doc.Close();
                    return(doc.ErrorCode == 0 ? "0" : "5");
                }
                else if (idx == 10)
                {
                    Boolean st = doc.StartPrint("", bpac.PrintOptionConstants.bpoDefault);
                    Boolean po = doc.PrintOut(1, bpac.PrintOptionConstants.bpoDefault);
                    //Console.WriteLine(st + "--" + doc.ErrorCode + "---" + po);
                    doc.EndPrint();
                    doc.Close();
                    return(doc.ErrorCode == 0 ? "0" : "5");
                }
                else if (idx > 10 && idx <= 20)
                {
                    for (; idx < 20; idx++)
                    {
                        doc.GetObject("sn" + (idx + 1)).Text = "";
                        doc.SetBarcodeData(doc.GetBarcodeIndex("barcode" + (idx + 1)), "");
                    }
                    Boolean st = doc.StartPrint("", bpac.PrintOptionConstants.bpoDefault);
                    Boolean po = doc.PrintOut(1, bpac.PrintOptionConstants.bpoDefault);
                    //Console.WriteLine(st + "--" + doc.ErrorCode + "---" + po);
                    doc.EndPrint();
                    doc.Close();
                    return(doc.ErrorCode == 0 ? "0" : "5");
                }
                else
                {
                    return("5");
                }
            }
            else
            {
                //Console.WriteLine("模板文件打开失败!!!!!!");
                //找不到模板
                return("4");
            }
        }