Browse Source

大箱采集修改

callm 2 months ago
parent
commit
a74055c6d3

+ 16 - 122
UAS_MES_HYSX/PublicMethod/HttpServer.cs

@@ -292,26 +292,29 @@ namespace UAS_MES_NEW.PublicMethod
             string prefix = "";
             string regcode = "";
             string makecode = "";
+            string prebigxbox = "";
             if (dt.Rows.Count > 0)
             {
                 prefix = dt.Rows[0]["pr_prefix"].ToString();
                 regcode = dt.Rows[0]["pr_regcode"].ToString();
                 makecode = dt.Rows[0]["ms_makecode"].ToString();
+                prebigxbox = dt.Rows[0]["pr_prebigxbox"].ToString();
             }
             dynamic obj = new ExpandoObject();
 
             obj.tool_name = "zte";
             obj.request = "Storage2";
             obj.User = "mes";
-            obj.password = "Mes@hy_231019";
-            obj.po_sn = makecode;
-            obj.wholeDeviceCode = "";
+            obj.password = "258456";
+            obj.po_sn = "250916001001";
+            obj.wholeDeviceCode = iSN;
             obj.reg_code = regcode;
             obj.prefix_en_no = prefix;
-            obj.prefix_big_box = "";
-            obj.packing_num = "";
+            obj.prefix_big_box = prebigxbox;
+            obj.packing_num = 6;
             obj.isn = iSN;
 
+
             string json = JsonConvert.SerializeObject(obj, Formatting.Indented);
             string returnstr = ToServerReq(json);
             JObject deviceObj = JObject.Parse(returnstr);
@@ -323,6 +326,7 @@ namespace UAS_MES_NEW.PublicMethod
             string mac_end = deviceObj["mac_end"].ToString();
             string reg_code = deviceObj["reg_code"].ToString();
             string reserve3 = deviceObj["reserve3"].ToString();
+            string status = deviceObj["status"].ToString();
             string device_type = deviceObj["device_type"].ToString();
             string en_no = deviceObj["en_no"].ToString();
             dh.ExecuteSql("insert into ZTEDATA(ZD_ID,ZD_D_SN,zd_WholeDeviceCode,ZD_DEV_EN_NO,ZD_SN, ZD_MAKECODE, ZD_TYPE, ZD_VALUE,zd_mac,ZD_MAC_START, ZD_MAC_END,ZD_RESERVE3,zd_enno,zd_devicetype,zd_regcode)" +
@@ -394,7 +398,7 @@ namespace UAS_MES_NEW.PublicMethod
                 }); ;
             }
             string json = JsonConvert.SerializeObject(root, Formatting.Indented);
-            string returnstr = SendData(json);
+            string returnstr = ToServerReq(json);
             Console.WriteLine(json);
         }
 
@@ -413,16 +417,15 @@ namespace UAS_MES_NEW.PublicMethod
                 makecode = dt.Rows[i]["pd_makecode"].ToString();
             }
             obj.request = "Q_wai_xiang";
-            obj.packing_num = 20;
+            obj.packing_num = dt.Rows.Count;
             obj.User = "mes";
-            obj.po_sn = makecode;
-            obj.password = "Mes@hy_231019";
+            obj.po_sn = "250916001001";
+            obj.password = "258456";
             obj.tool_name = "zte";
             obj.noType = 0;
 
-
             string json = JsonConvert.SerializeObject(obj, Formatting.Indented);
-            string returnstr = SendData(json);
+            string returnstr = ToServerReq(json);
 
             var settings = new JsonSerializerSettings
             {
@@ -470,121 +473,16 @@ namespace UAS_MES_NEW.PublicMethod
             obj.packing_num = dt.Rows.Count;
             obj.User = "mes";
             obj.po_sn = makecode;
-            obj.password = "Mes@hy_231019";
+            obj.password = "258456";
             obj.tool_name = "zte";
 
             string json = JsonConvert.SerializeObject(obj, Formatting.Indented);
-            string returnstr = SendData(json);
+            string returnstr = ToServerReq(json);
             Console.WriteLine(returnstr);
             Console.WriteLine(json);
         }
 
-        //发送数据
-        public static string SendData(string json)
-        {
-            string serverIP = "192.168.1.160";
-            int port = 21610;
-
-            try
-            {
-                TcpClient client = new TcpClient();
-                client.Connect(serverIP, port);
-                NetworkStream stream = client.GetStream();
-
-                // 发送数据
-                byte[] data = BuildPacket(json);
-                stream.Write(data, 0, data.Length);
-                Console.WriteLine($"已发送请求: {json}");
-
-                // 接收响应 - 使用安全的方式
-                return ReceiveDataSafely(stream);
-            }
-            catch (Exception ex)
-            {
-                Console.WriteLine($"错误: {ex.Message}");
-                return "";
-            }
-        }
-
-        private static string ReceiveDataSafely(NetworkStream stream)
-        {
-            MemoryStream ms = new MemoryStream();
-            byte[] buffer = new byte[8192];
-            int totalBytesRead = 0;
-            const int MAX_SIZE = 10 * 1024 * 1024;
-
-            try
-            {
-                stream.ReadTimeout = 5000;
-
-                while (true)
-                {
-                    int bytesRead = stream.Read(buffer, 0, buffer.Length);
-                    if (bytesRead == 0) break;
-
-                    ms.Write(buffer, 0, bytesRead);
-                    totalBytesRead += bytesRead;
-
-                    Console.WriteLine($"本次读取: {bytesRead} 字节, 累计: {totalBytesRead} 字节");
-
-                    if (totalBytesRead > MAX_SIZE)
-                    {
-                        throw new Exception($"接收数据超过大小限制: {MAX_SIZE} 字节");
-                    }
-
-                    if (!stream.DataAvailable)
-                    {
-                        Thread.Sleep(100);
-                        if (!stream.DataAvailable) break;
-                    }
-                }
-
-                byte[] receivedData = ms.ToArray();
-
-                // 直接使用GBK编码(最常用的中文编码)
-                Encoding chineseEncoding = Encoding.GetEncoding("GBK");
-                string response = chineseEncoding.GetString(receivedData);
-
-                Console.WriteLine($"使用GBK编码的响应: {response}");
-                return response;
-            }
-            catch (TimeoutException)
-            {
-                byte[] partialData = ms.ToArray();
-                Encoding chineseEncoding = Encoding.GetEncoding("GBK");
-                string partialResponse = chineseEncoding.GetString(partialData);
-                Console.WriteLine($"接收超时,已接收数据: {partialResponse}");
-                return partialResponse;
-            }
-        }
-
         public static readonly uint PROTOCOL_FLAG = 0x4C4F4F54;
-        public static byte[] BuildPacket(string jsonData)
-        {
-            if (string.IsNullOrEmpty(jsonData))
-            {
-                throw new ArgumentException("JSON数据不能为空");
-            }
-
-            using (MemoryStream ms = new MemoryStream())
-            {
-                // 1. 写入flag (小端序)
-                byte[] flagBytes = BitConverter.GetBytes(PROTOCOL_FLAG);
-                ms.Write(flagBytes, 0, 4);
-
-                // 2. 将JSON字符串转换为UTF8字节数组
-                byte[] jsonBytes = Encoding.UTF8.GetBytes(jsonData);
-
-                // 3. 写入data_len (小端序)
-                byte[] lengthBytes = BitConverter.GetBytes(jsonBytes.Length);
-                ms.Write(lengthBytes, 0, 4);
-
-                // 4. 写入data
-                ms.Write(jsonBytes, 0, jsonBytes.Length);
-
-                return ms.ToArray();
-            }
-        }
 
         public static string ToServerReq(string strJSON)
         {
@@ -625,10 +523,6 @@ namespace UAS_MES_NEW.PublicMethod
                 int nRecvSize = 0, nSize = 0;
                 nRecvSize = clientSocket.Receive(bytRecv, 0, FACT_DATA_HEAD.MY_LEN, SocketFlags.None);
 
-                //                 string strTmp;
-                //                 strTmp = string.Format("clientSocket.Receive={0}", nRecvSize);
-                //                 Trace.WriteLine(strTmp);
-
                 if (nRecvSize > 0)
                 {
                     FACT_DATA_HEAD stHead = new FACT_DATA_HEAD(bytRecv);

+ 7 - 8
UAS_MES_YD/FunctionCode/Packing/Packing_BigBoxCollection.cs

@@ -1,4 +1,5 @@
 using LabelManager2;
+using Seagull.BarTender.Print;
 using System;
 using System.Collections.Generic;
 using System.Data;
@@ -36,6 +37,8 @@ namespace UAS_MES_NEW.Packing
 
         string pa_nextstep = "";
 
+        Engine engine;
+
         public Packing_BigBoxCollection()
         {
             InitializeComponent();
@@ -46,8 +49,7 @@ namespace UAS_MES_NEW.Packing
         {
             try
             {
-                lbl = new ApplicationClass();
-                BaseUtil.WriteLbl();
+                engine = new Engine(true);
             }
             catch
             {
@@ -394,12 +396,9 @@ namespace UAS_MES_NEW.Packing
         {
             DataTable _dt = (DataTable)dh.ExecuteSql("select la_id,la_printnos,substr(la_url,instr(la_url,'\\',-1)+1)la_name,la_url,la_isdefault from label where la_prodcode='" + pa_prodcode.Text + "' and la_templatetype='大箱标' and la_statuscode='AUDITED' order by la_isdefault", "select");
             PrintLabel.DataSource = _dt;
-            PrintLabel.DisplayMember = "la_name";
+            PrintLabel.DisplayMember = "la_url";
             PrintLabel.ValueMember = "la_id";
-            for (int i = 0; i < _dt.Rows.Count; i++)
-            {
-                BaseUtil.GetPrintLabel(_dt.Rows[i]["la_name"].ToString(), _dt.Rows[i]["la_url"].ToString());
-            }
+
         }
 
         private void LoadCollectNum()
@@ -432,7 +431,7 @@ namespace UAS_MES_NEW.Packing
             {
                 if (dh.getFieldDataByCondition("package", "pa_status", "pa_outboxcode='" + pa_outboxcode.Text + "'").ToString() == "1")
                 {
-                    if (Print.CodeSoft(Tag.ToString(), ref lbl, PrintLabel.Text, PrintLabel.SelectedValue.ToString(), PrinterList.Text, pa_outboxcode.Text, int.Parse(PrintNum.Text), pa_makecode.Text, pa_prodcode.Text, "大箱标", "0", out ErrorMessage))
+                    if (Print.BarTender(Tag.ToString(), ref engine, PrintLabel.Text, PrintLabel.SelectedValue.ToString(), PrinterList.Text, pa_outboxcode.Text, int.Parse(PrintNum.Text), pa_makecode.Text, pa_prodcode.Text, "大箱标", "0", out ErrorMessage))
                     {
                         OperateResult.AppendText(">>打印箱号" + pa_outboxcode.Text + "\n", Color.Black);
                     }

+ 11 - 13
UAS_MES_YD/FunctionCode/Packing/Packing_BigBoxWeight.cs

@@ -1,5 +1,6 @@
 using DevExpress.Printing.Core.PdfExport.Metafile;
 using LabelManager2;
+using Seagull.BarTender.Print;
 using System;
 using System.Collections.Generic;
 using System.ComponentModel;
@@ -28,6 +29,8 @@ namespace UAS_MES_NEW.Packing
         //true的时候表示从串口读取数据
         bool GetData = true;
 
+        Engine engine;
+
         DataTable dt;
 
         LogStringBuilder sql = new LogStringBuilder();
@@ -87,8 +90,7 @@ namespace UAS_MES_NEW.Packing
         {
             try
             {
-                lbl = new ApplicationClass();
-                BaseUtil.WriteLbl();
+                engine = new Engine(true);
             }
             catch
             {
@@ -106,7 +108,7 @@ namespace UAS_MES_NEW.Packing
             if (e.KeyCode == Keys.Enter)
             {
                 sql.Clear();
-                sql.Append("select pr_bigboxmaxw,pr_bigboxminw,pa_id,pa_prodcode,pr_spec,pr_detail,pa_makecode,pa_salecode,pa_totalqty,");
+                sql.Append("select pr_bigboxmaxw,pr_bigboxminw,pr_colorboxgw,pa_id,pa_prodcode,pr_spec,pr_detail,pa_makecode,pa_salecode,pa_totalqty,");
                 sql.Append("pa_packageqty from package left join product on pr_code=pa_prodcode where ");
                 sql.Append("pa_outboxcode='" + pa_outboxcode.Text + "' and pa_type=2");
                 dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
@@ -134,9 +136,9 @@ namespace UAS_MES_NEW.Packing
                     MinWeight = double.Parse(_minweight == "" ? "0" : _minweight);
 
                     if (Weight - MinWeight == MaxWeight - Weight)
-                        pr_colorboxgw.Text = Weight + "±" + (MaxWeight - Weight) + dt.Rows[0]["pr_colorboxunit"].ToString();
+                        pr_colorboxgw.Text = Weight + "±" + (MaxWeight - Weight);
                     else
-                        pr_colorboxgw.Text = MinWeight + "-" + MaxWeight + dt.Rows[0]["pr_colorboxunit"].ToString();
+                        pr_colorboxgw.Text = MinWeight + "-" + MaxWeight;
 
                     if ((ActualWeight >= MinWeight) && (ActualWeight <= MaxWeight))
                     {
@@ -164,7 +166,8 @@ namespace UAS_MES_NEW.Packing
                         {
                             //doc = lbl.Documents.Open(ftpOperater.DownLoadTo + PrintLabel.Text);
                             string ErrorMessage = "";
-                            if (!Print.CodeSoft(Tag.ToString(), ref lbl, PrintLabel.Text, PrintLabel.SelectedValue.ToString(), Printer.Text, pa_outboxcode.Text, int.Parse(PrintNum.Text), pa_makecode.Text, pa_prodcode.Text, "大箱标", "0", out ErrorMessage))
+
+                            if (!Print.BarTender(Tag.ToString(), ref engine, PrintLabel.Text, PrintLabel.SelectedValue.ToString(), Printer.Text, pa_outboxcode.Text, int.Parse(PrintNum.Text), pa_makecode.Text, pa_prodcode.Text, "大箱标", "0", out ErrorMessage))
                             {
                                 OperateResult.AppendText(ErrorMessage + "\n", Color.Red);
                             }
@@ -207,15 +210,10 @@ namespace UAS_MES_NEW.Packing
 
         private void pa_prodcode_TextChanged(object sender, EventArgs e)
         {
-            DataTable _dt = (DataTable)dh.ExecuteSql("select la_id,substr(la_url,instr(la_url,'\\',-1)+1)la_name,la_url,la_isdefault from label where la_prodcode='" + pa_prodcode.Text + "' and la_templatetype='大箱标' and la_statuscode='AUDITED' order by la_isdefault", "select");
+            DataTable _dt = (DataTable)dh.ExecuteSql("select la_id,la_url,la_isdefault  from label where la_prodcode='" + pa_prodcode.Text + "' and la_templatetype='大箱标' and la_statuscode='AUDITED' order by la_isdefault", "select");
             PrintLabel.DataSource = _dt;
-            PrintLabel.DisplayMember = "la_name";
+            PrintLabel.DisplayMember = "la_url";
             PrintLabel.ValueMember = "la_id";
-            ftpOperater ftp = new ftpOperater();
-            for (int i = 0; i < _dt.Rows.Count; i++)
-            {
-                BaseUtil.GetPrintLabel(_dt.Rows[i]["la_name"].ToString(), _dt.Rows[i]["la_url"].ToString());
-            }
         }
 
         private void StartWeight_Click(object sender, EventArgs e)