Esempio n. 1
0
        /// <summary>
        /// 老式接口,迭代每个LabelContent并且在激活的当前文档下打印
        /// </summary>
        /// <param name="labelValue"></param>
        /// <param name="document"></param>
        private static void ItereatePerLabelContentPrintOld(string labelValue, Document document)
        {
            List <LabelData> list  = new List <LabelData>();
            List <LabelInfo> list2 = new List <LabelInfo>();


            list = Deserialization.JSONStringToList <LabelData>(labelValue);

            for (int i = 0; i < list.Count; i++)
            {
                list2 = Deserialization.JSONStringToList <LabelInfo>(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(list[i].LabelContent));



                AssignValueToFormVariables(document, list2);
                document.PrintDocument(Copys);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 新版接口迭代每个LabelContent并且打印
        /// </summary>
        /// <param name="labelValue"></param>
        /// <param name="copies"></param>
        /// <param name="errorCode"></param>
        /// <param name="errorMessage"></param>
        /// <param name="document"></param>
        private static void ItereatePerLabelContentAndPrint(string labelValue, int copies, ref int errorCode, ref String errorMessage, Document document)
        {
            List <LabelData> list  = new List <LabelData>();
            List <LabelInfo> list2 = new List <LabelInfo>();

            list = Deserialization.JSONStringToList <LabelData>(labelValue);

            for (int i = 0; i < list.Count; i++)
            {
                list2 = Deserialization.JSONStringToList <LabelInfo>(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(list[i].LabelContent));
                //清空脏数据
                //ClearOldFormVariables(document);
                AssignValueToFormVariables(document, list2);

                for (int m = 0; m < copies; m++)
                {
                    document.PrintDocument(1);
                }
            }

            //到这里可以确认打印成功了,默认是失败的
            errorCode    = 0;
            errorMessage = "打印成功";
        }
Esempio n. 3
0
        public void ProcessPrintJob(string e, ref int errorCode, ref String errorMessage)
        {
            Tool.Tools.PubMessage("收到打印请求");
            LabelPrintX.LabelPrint print = new LabelPrintX.LabelPrint();

            HashMap map = JsonConvert.DeserializeObject <HashMap>(e);

            if (!map.ContainsKey("labelJsonData"))
            {
                errorCode    = -1;
                errorMessage = "没有传递labelJsonData字段";
                Tool.Tools.PubMessage(errorMessage);
                return;
            }
            String LabelContent = map["labelJsonData"].ToString();
            String printer      = map.GetValue <String>("printName");

            if (!map.ContainsKey("tempatePath"))
            {
                errorCode    = -1;
                errorMessage = "没有传递tempatePath字段";
                Tool.Tools.PubMessage(errorMessage);

                return;
            }
            String tempatePath = map.GetValue <String>("tempatePath");
            int    copys       = map.GetValue <int>("copys");
            int    linkFlag    = map.GetValue <int>("linkFlag");

            Tools.PubMessage("是否连板--------" + linkFlag);
            if (linkFlag < 1)
            {
                //连扳标记
                linkFlag = 0;
            }

            PrintX.LeanMES.Plugin.LabelPrint.PrintHlper.linkFlag = linkFlag;
            if (copys < 1)
            {
                //打印份数
                PrintX.LeanMES.Plugin.LabelPrint.PrintHlper.Copys = 1;
                copys = 1;
            }

            Tools.PubMessage("打印份数--------" + copys);
            string           snString = "";
            List <LabelData> list     = new List <LabelData>();
            List <LabelInfo> list2    = new List <LabelInfo>();

            list = Deserialization.JSONStringToList <LabelData>(LabelContent);
            try
            {
                //加速赋值
                Parallel.For(0, list.Count, i =>
                {
                    list2 = Deserialization.JSONStringToList <LabelInfo>(JsonConvert.SerializeObject(list[i].LabelContent));
                    for (int j = 0; j < list2.Count; j++)
                    {
                        snString = list2[j].Value;
                    }
                });
            }
            catch (Exception err)
            {
                errorMessage = "解析打印内容的json失败,请校验格式是否正确,您传递的格式为:" + e + "触发的异常信息为:\n" + err.Message;
                errorCode    = -1;
            }

            try
            {
                Tools.PubMessage("准备打印--------");

                Tools.PubMessage("打印模板--------" + tempatePath);

                Tools.PubMessage("打印机--------" + printer);
                print.PrintLabelUseCodeSoft9(tempatePath, LabelContent, copys, "cn", printer, ref errorCode,

                                             ref errorMessage, linkFlag);
            }
            catch (Exception er)
            {
                errorMessage = er.Message;
                errorCode    = -1;
            }

            //组装返回结果
            HashMap responseBean = new HashMap();

            if (errorCode == 0)
            {
                errorMessage = "打印成功";
            }


            Tool.Tools.PubMessage(errorMessage);
        }
Esempio n. 4
0
        public static string ProcPrintJob(string e, ref int errorCode, ref String errorMessage)
        {
            LabelPrint print        = new LabelPrint();
            HashMap    map          = JsonConvert.DeserializeObject <HashMap>(e);
            String     LabelContent = map["labelJsonData"].ToString();
            String     printer      = map.GetValue <String>("printName");

            //如果设置了全局当前打印机,就用当前打印机打印
            //提供web修改接口
            if (Setting.globalPrinter != null && Setting.globalPrinter != "")
            {
                printer = Setting.globalPrinter;
            }
            String tempatePath = map.GetValue <String>("tempatePath");
            int    copys       = map.GetValue <int>("copys");

            try
            {
                PrintX.LeanMES.Plugin.LabelPrint.PrintHlper.Copys = copys;
            }
            catch (Exception err)
            {
                Console.WriteLine(err.Message);
                copys = 1;
            }

            int linkFlag = 0;

            try
            {
                map.GetValue <int>("linkFlag");
            }
            catch (Exception err)
            {
                Console.WriteLine(err.Message);
                linkFlag = 1;
            }

            Tools.PubMessage("是否连板--------" + linkFlag);
            if (linkFlag < 1)
            {
                //连扳标记
                linkFlag = 0;
            }
            if (copys < 1)
            {
                //打印份数
                PrintX.LeanMES.Plugin.LabelPrint.PrintHlper.Copys = 1;

                copys = 1;
            }


            Tools.PubMessage("打印份数--------" + copys);
            string           snString = "";
            List <LabelData> list     = new List <LabelData>();
            List <LabelInfo> list2    = new List <LabelInfo>();

            list = Deserialization.JSONStringToList <LabelData>(LabelContent);
            try
            {
                //加速赋值
                Parallel.For(0, list.Count, i =>
                {
                    list2 = Deserialization.JSONStringToList <LabelInfo>(JsonConvert.SerializeObject(list[i].LabelContent));
                    for (int j = 0; j < list2.Count; j++)
                    {
                        snString = list2[j].Value;
                    }
                });
            }
            catch (Exception err)
            {
                errorMessage = "解析打印内容的json失败,请校验格式是否正确,您传递的格式为:" + e + "触发的异常信息为:\n" + err.Message;
                errorCode    = -1;
            }

            try
            {
                Tools.PubMessage("准备打印--------");

                Tools.PubMessage("打印模板--------" + tempatePath);

                Tools.PubMessage("打印机--------" + printer);

                print.PrintLabelUseCodeSoft9(tempatePath, LabelContent, copys, "cn", printer, ref errorCode,

                                             ref errorMessage, linkFlag);
            }
            catch (Exception er)
            {
                Tools.PubMessage("发生异常咯--------" + er.Message);
                errorMessage = er.Message;
                errorCode    = -1;
            }


            //重置打印份数
            PrintX.LeanMES.Plugin.LabelPrint.PrintHlper.Copys = 1;



            //组装返回结果
            HashMap responseBean = new HashMap();

            if (errorCode == 0)
            {
                errorMessage = "打印成功";
            }
            responseBean.Add("errorMessage", errorMessage);
            responseBean.Add("errorCode", errorCode);
            responseBean.Add("key", "PrintJob");


            return(JsonConvert.SerializeObject(responseBean));
        }