11
schangxiang@126.com
2024-12-06 85f23e46d99a120cbd268176d8f8959f87c32710
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
//using Admin.NET.Application;
//using iWareCommon.Utils;
//using iWareSql.WmsDBModel;
//using System;
//using System.Collections.Generic;
//using System.Data;
//using System.Linq;
//using System.Threading;
 
//namespace iWareCC
//{
//    /// <summary>
//    /// 打印处理的线程
//    /// </summary>
//    public class PrintHandler
//    {
//        public static void Handler()
//        {
//            var errMsg = "";
//            while (true)
//            {
//                try
//                {
//                    SystemWarningMsg._lbl_Alert_PrintHandler = "循环开始...";
//                    if (SystemValue.isAllowRuning_PrintHandler && SystemValue.isStartedModel)
//                    {
//                        errMsg = "";//重置
//                        try
//                        {
//                            Do(ref errMsg);
//                            if (!string.IsNullOrEmpty(errMsg))
//                            {
//                                SystemWarningMsg._lbl_Alert_PrintHandler = errMsg;
//                            }
//                        }
//                        catch (Exception ex)
//                        {
//                            Log4NetHelper.WriteErrorLog(LogType.PrintHandler, "打印处理的线程=>" + errMsg + ",异常:" + ex.Message, ex);
//                            SystemWarningMsg._lbl_Alert_PrintHandler = "打印处理的线程=>" + errMsg + ",异常:" + ex.Message;
//                        }
//                    }
//                }
//                catch (Exception ex)
//                {
//                    SystemWarningMsg._lbl_Alert_PrintHandler = "出现异常:" + ex.Message;
//                    Log4NetHelper.WriteErrorLog(LogType.PrintHandler, "PrintHandler 出现异常:" + ex.Message, ex);
//                }
//                Thread.Sleep(2 * 1000);//休眠2秒
//            }
//        }
 
 
//        /// <summary>
//        /// 打印
//        /// </summary>
//        /// <param name="model"></param>
//        /// <param name="Lane"></param>
//        /// <param name="flag"></param>
//        /// <param name="errMsg"></param>
//        private static void Do(ref string errMsg)
//        {
//            using (WmsDBModel mycontext = new WmsDBModel())
//            {
//                var query_PrintStatuEnum = (int)PrintStatuEnum.未打印;
//                var list = mycontext.wms_record_print.Where(x => (x.IsDelete == false) && x.PrintStatus == query_PrintStatuEnum)
//                    .OrderBy(x => x.Id).ToList();
 
 
//                wms_config_print printConfig = null;
//                string _PrinterName = "";
//                if (list.Count > 0)
//                {
 
//                }
//                else
//                {
//                    errMsg = $"没有可打印的内容!";
//                    return;
//                }
 
//                foreach (var item in list)
//                {
 
 
//                    PrintClassifyEnum printClassifyEnum = PrintClassifyEnum.包装条码;
 
 
//                    printConfig = mycontext.wms_config_print.Where(x => x.PrintClassify == (int)printClassifyEnum).FirstOrDefault();
//                    if (printConfig == null)
//                    {
//                        errMsg = $"没有找到{printClassifyEnum.ToString()}的打印配置!";
//                        return;
//                    }
//                    //设置打印机,注意:这里只获取第一个,以后可能要改!
//                    _PrinterName = printConfig.PrinterList.Split(',')[0];
//                    //根据配置名字查询 打印机名字
//                    //var printConfigData = mycontext.SysDictData.Where(x => x.Name == _PrinterName).FirstOrDefault();
//                    //if (printConfigData == null)
//                    //{
//                    //    errMsg = $"没有找到{_PrinterName.ToString()}的打印机名字!";
//                    //    return;
//                    //}
//                    //_PrinterName = printConfigData.Value;
 
//                    Dictionary<string, object> data = new Dictionary<string, object>();
//                    if (printClassifyEnum == PrintClassifyEnum.包装条码)
//                    {
//                        //data.Add("bar", item.SNCode);
//                        //data.Add("material", item.MaterialCode ?? "" + "/" + item.MaterialName ?? "");
//                        //data.Add("supplier", item.SupplierName ?? "");
//                        //data.Add("unit", item.MaterialUnit ?? "");
//                        //data.Add("qty", item.Quantity);
//                        //data.Add("date", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
//                    }
//                    else
//                    {
 
//                    }
 
 
//                    //调用打印接口
//                    bool isSuccess = false;
//                    using (PrintBaseService.PrintWcfServiceClient client = new PrintBaseService.PrintWcfServiceClient())
//                    {
//                        //isSuccess = client.Print3(data, 1, @"D:\打印程序\跟踪码打印模板\跟踪码打印模板_一维码.btw", "ZDesigner ZD888-203dpi ZPL", out errMsg);
//                        //isSuccess = client.Print3(data, 1, @"D:\打印程序\跟踪码打印模板\跟踪码打印模板_二维码.btw", "ZDesigner ZD888-203dpi ZPL", out errMsg);
//                        isSuccess = client.Print3(data, item.PrintSheetNum, printConfig.PrintTemplateAddr, _PrinterName, out errMsg);
//                    }
//                    if (isSuccess)
//                    {
//                        item.PrintStatus = 1;//打印状态(0:未打印 1:已打印)
//                        item.PrintNum = (item.PrintNum) + 1;
 
//                        mycontext.SaveChanges();
//                    }
//                    else
//                    {
//                        errMsg = $"打印错误 打印机名称{_PrinterName},错误信息:(打印服务返回)" + errMsg;
//                        Log4NetHelper.WriteErrorLog(LogType.PrintHandler, errMsg, null);
//                        return;
//                    }
 
//                    Thread.Sleep(2000);
//                }
 
//            }
//        }
 
 
 
//    }
//}