From f34c6a21dc58bc0d40a011d6d7366c5eb3f15f15 Mon Sep 17 00:00:00 2001
From: yxj <yxj@hz-kingdee.com>
Date: 星期五, 20 九月 2024 13:59:34 +0800
Subject: [PATCH] Merge branch 'master' of http://101.37.171.70:10101/r/MES-WEB-API

---
 WarM/条码打印/Kf_WeighToBarCode.cs |  359 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 351 insertions(+), 8 deletions(-)

diff --git "a/WarM/\346\235\241\347\240\201\346\211\223\345\215\260/Kf_WeighToBarCode.cs" "b/WarM/\346\235\241\347\240\201\346\211\223\345\215\260/Kf_WeighToBarCode.cs"
index 9be67cd..4dc1ac2 100644
--- "a/WarM/\346\235\241\347\240\201\346\211\223\345\215\260/Kf_WeighToBarCode.cs"
+++ "b/WarM/\346\235\241\347\240\201\346\211\223\345\215\260/Kf_WeighToBarCode.cs"
@@ -11,6 +11,8 @@
 using System.Threading;
 using System.IO;
 using Pub_Class;
+using System.IO.Ports;
+using System.Linq;
 
 namespace WarM
 {
@@ -35,7 +37,7 @@
         public Int64 HSourceEntryID = 0;
         public string HSourceBillNo = "";
         public string HSourceBillType = "";
-        public Int64 ProcessExchangeInterID = 0;
+        public Int64 HProcessExchangeInterID = 0;
         public Int64 HSupID = 0;
         public double HSourceQty = 0;
         public double HMaterWeight = 0;         //鐗╂枡鍏嬮噸
@@ -62,6 +64,9 @@
             grdMain.DataSource = null;
             grdSub.DataSource = null;
             chkHDYFlag.Checked = true;
+
+            //璇诲彇 鎵撳紑涓插彛鐨勯厤缃俊鎭�
+            readParams();
         }
 
         //绐椾綋鍔犺浇
@@ -383,7 +388,13 @@
 
         private void tc_Click(object sender, EventArgs e)
         {
-            this.Close();
+            //閫�鍑烘椂鍏抽棴涓插彛
+            if (ComDevice != null)
+            {
+                CloseCom();
+            }
+
+            this.Close();   
         }
 
         #endregion
@@ -578,6 +589,38 @@
             {
                 if (MessageBox.Show("鐗╂枡缁存姢鍏嬮噸涓猴細"+HMaterWeight.ToString()+ "锛屽疄闄呭厠閲嶄负锛�" + sQty.ToString() + "锛屾墍杈撳叆瀹為檯鍏嬮噸瓒呭嚭鐗╂枡缁存姢鍏嬮噸鐨勭櫨鍒嗕箣浜屽崄鎴栦笉瓒崇墿鏂欑淮鎶ゅ厠閲嶇殑鐧惧垎涔嬪叓鍗侊紝璇锋鏌ヨ緭鍏ョ殑鏁版嵁鏄惁姝g‘锛�", "鎻愮ず", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                 {
+                    //return true;
+                }
+                else
+                {
+                    return false;
+                }
+            }
+
+            //鏉$爜鐢熸垚鍓嶆帶鍒跺垽鏂�
+            double HNowQty = 0;     //绫虫暟
+            double HWeightQyt = 0;  //閲嶉噺
+            double HKDQty = 0;      //鎵g偣鏁�
+            HNowQty = DBUtility.ClsPub.isDoule(txtHQty.Text);
+            HWeightQyt = DBUtility.ClsPub.isDoule(txtHWeightQyt.Text);
+            HKDQty = DBUtility.ClsPub.isDoule(txtHKDQty.Text);
+
+            DataSet oDsCheck = oCn.RunProcReturn("exec h_p_Kf_WeighToBarCode_AddBarCodeCheck " + HInterID.ToString() + "," + HSourceInterID.ToString() + "," + HSourceEntryID.ToString() + "," + HProcessExchangeInterID.ToString() + "," + HSourceQty.ToString() + "," + HNowQty.ToString() + "," + HWeightQyt.ToString() + "," + HKDQty.ToString(), "h_p_Kf_WeighToBarCode_AddBarCodeCheck");
+            //
+            if (oDsCheck == null && oDsCheck.Tables[0].Rows.Count == 0)
+            {
+                MessageBox.Show("鏉$爜鐢熸垚鍓嶅垽鏂敊璇紒");
+                return false;
+            }
+            else if (DBUtility.ClsPub.isStrNull(oDsCheck.Tables[0].Rows[0][0]) == "1")
+            {
+                MessageBox.Show(DBUtility.ClsPub.isStrNull(oDsCheck.Tables[0].Rows[0]["HRemark"]), "鎻愮ず");
+                return false;
+            }
+            else if (DBUtility.ClsPub.isStrNull(oDsCheck.Tables[0].Rows[0][0]) == "2")
+            {
+                if (MessageBox.Show(DBUtility.ClsPub.isStrNull(oDsCheck.Tables[0].Rows[0]["HRemark"]), "鎻愮ず", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
+                {
                     return true;
                 }
                 else
@@ -585,7 +628,10 @@
                     return false;
                 }
             }
-            return true;
+            else
+            {
+                return true;
+            }
         }
 
         //鐢熸垚鏉$爜
@@ -652,7 +698,7 @@
             string HRemark = "";
             string HMaterName = "";
             string HMaterModel = "";
-            string ProcessExchangeBillNo = "";
+            string HProcessExchangeBillNo = "";
             Int64 HBarcodeNo = 0;       //鍖呮暟
             Int64 HBadReasonID = 0;     //涓嶈壇鍘熷洜ID
             string HCusMaterName = "";  //瀹㈡埛鐗╂枡鍚嶇О
@@ -668,7 +714,7 @@
             HRemark = DBUtility.ClsPub.isStrNull(txtHRemark.Text);
             HMaterName = DBUtility.ClsPub.isStrNull(txtHMaterName.Text);
             HMaterModel = DBUtility.ClsPub.isStrNull(txtHMaterModel.Text);
-            ProcessExchangeBillNo = DBUtility.ClsPub.isStrNull(txtHBillNo.Text);
+            HProcessExchangeBillNo = DBUtility.ClsPub.isStrNull(txtHBillNo.Text);
             HBarcodeNo = DBUtility.ClsPub.isLong(txtHBarcodeNo.Text);
             HBadReasonID = DBUtility.ClsPub.isLong(txtHRemark.Tag);
             HCusMaterName = DBUtility.ClsPub.isStrNull(txtHCusMaterName.Text);
@@ -694,14 +740,14 @@
                 + ", 1," + HBarcodeNo.ToString() + "," + HDeptID.ToString() + "," + HWhID.ToString() + "," + HSPID.ToString() + ",'" + HRemark + "'"
                 + ", 0,'',getdate(),'','" + sDate + "'," + HMaterialJQty.ToString() + "," + HMaterialMQty.ToString() + "," + HNowQty.ToString()
                 + ", " + HStockOrgID.ToString() + "," + HStockOrgID.ToString() + ",''," + HInterID.ToString() + ",0"
-                + ", " + ProcessExchangeInterID.ToString() + ",0,'" + ProcessExchangeBillNo + "'," + HBadReasonID.ToString() + ",'" + HCusMaterName + "','" + HCusModel + "'"
+                + ", " + HProcessExchangeInterID.ToString() + ",0,'" + HProcessExchangeBillNo + "'," + HBadReasonID.ToString() + ",'" + HCusMaterName + "','" + HCusModel + "'"
                 + ",'" + HMaterName + "','" + HMaterModel + "',''," + HAuxPropID.ToString() + ",'','','1')");
 
                 //鍥炲~鏈�澶ф祦姘村彿
                 oCn.RunProc("exec h_p_WMS_SetMaxNo_QTY '" + sTMNumber + "',1 ");
 
                 //鍥炲~婧愬崟涓存椂琛℉InterID
-                oCn.RunProc("update a set a.HInterID=" + HInterID.ToString() + ",a.HBillNo='" + HBillNo +"',a.HRelationInterID= 0 from KF_WeighSource_Temp a where a.HInterID<>" + HInterID.ToString() + " and a.HMaker='" + HMaker + "' and a.HSourceBillNo='" + ProcessExchangeBillNo + "'");
+                oCn.RunProc("update a set a.HInterID=" + HInterID.ToString() + ",a.HBillNo='" + HBillNo +"',a.HRelationInterID= 0 from KF_WeighSource_Temp a where a.HInterID<>" + HInterID.ToString() + " and a.HMaker='" + HMaker + "' and a.HSourceBillNo='" + HProcessExchangeBillNo + "'");
 
                 //鍐欏叆鏉$爜鍑哄叆搴撲复鏃惰〃
                 oCn.RunProc("Insert into KF_PonderationBillMain_Temp " +
@@ -757,9 +803,10 @@
             HSourceBillNo = DBUtility.ClsPub.isStrNull(grdSub.SelectedRows[0].Cells[Fun_GetSubCol("鐢熶骇璁㈠崟")].Value);
             HSourceBillType = DBUtility.ClsPub.isStrNull(grdSub.SelectedRows[0].Cells[Fun_GetSubCol("HSourceBillType")].Value);
             HSourceQty = DBUtility.ClsPub.isDoule(grdSub.SelectedRows[0].Cells[Fun_GetSubCol("鏁伴噺")].Value);
-            ProcessExchangeInterID = DBUtility.ClsPub.isLong(grdSub.SelectedRows[0].Cells[Fun_GetSubCol("ProcessExchangeInterID")].Value);
+            HProcessExchangeInterID = DBUtility.ClsPub.isLong(grdSub.SelectedRows[0].Cells[Fun_GetSubCol("ProcessExchangeInterID")].Value);
             HSupID = DBUtility.ClsPub.isLong(grdSub.SelectedRows[0].Cells[Fun_GetSubCol("HSupID")].Value);
             HMaterWeight = DBUtility.ClsPub.isDoule(grdSub.SelectedRows[0].Cells[Fun_GetSubCol("HMaterWeight")].Value);
+            txtHOrderPickRemark.Text = DBUtility.ClsPub.isStrNull(grdSub.SelectedRows[0].Cells[Fun_GetSubCol("璁㈠崟鍖呰澶囨敞")].Value);
         }
 
         //杩斿洖婧愬崟鍒楄〃淇℃伅
@@ -999,8 +1046,304 @@
 
 
 
+        #region 璇诲彇璁惧绉伴噸淇℃伅
 
 
 
+        private static string repeatData = string.Empty;
+        private SerialPort ComDevice = null;
+
+        private int HGetWeight = 0;
+        private string Message = "";
+
+        private int timeIndex = 0;
+
+        private string value_COM = "";              //COM
+        private string value_BaudRate = "9600";     //姣旂壒鐜�
+        private string value_StopBits = "1";        //鍋滄浣�
+        private string value_Parity = "0";          //鏍¢獙浣�
+        private string value_DataBits = "8";        //鏁版嵁浣�
+
+        #region 鎵撳紑涓插彛鎸夐挳瑙﹀彂浜嬩欢
+        private void button_OpenCom_Click(object sender, EventArgs e)
+        {
+            value_COM = textBox_COM.Text;
+            OpenCom();
+        }
+        #endregion
+
+        #region 鎵撳紑涓插彛
+        public void OpenCom()
+        {
+            //鍒濆鍖栦覆鍙�
+            ComDevice = new SerialPort();
+            ComDevice.DataReceived += new SerialDataReceivedEventHandler(Com_DataReceived);//缁戝畾浜嬩欢
+            string[] PortNames = SerialPort.GetPortNames();
+
+            if (!ComDevice.IsOpen)
+            {
+                try
+                {
+                    ComDevice.PortName = value_COM;
+                    ComDevice.BaudRate = int.Parse(value_BaudRate);
+                    switch (value_Parity)
+                    {
+                        case "0":
+                            ComDevice.Parity = Parity.None;
+                            break;
+                        case "1":
+                            ComDevice.Parity = Parity.Odd;
+                            break;
+                        case "2":
+                            ComDevice.Parity = Parity.Even;
+                            break;
+                        case "3":
+                            ComDevice.Parity = Parity.Mark;
+                            break;
+                        case "4":
+                            ComDevice.Parity = Parity.Space;
+                            break;
+                        default:
+                            break;
+                    }
+
+                    ComDevice.DataBits = int.Parse(value_DataBits);
+                    switch (value_StopBits)
+                    {
+                        case "0":
+                            ComDevice.StopBits = StopBits.None;
+                            break;
+                        case "1":
+                            ComDevice.StopBits = StopBits.One;
+                            break;
+                        case "2":
+                            ComDevice.StopBits = StopBits.Two;
+                            break;
+                        case "1.5":
+                            ComDevice.StopBits = StopBits.OnePointFive;
+                            break;
+                        default:
+                            break;
+                    }
+
+                    ComDevice.Open();
+
+                    MessageBox.Show("涓插彛鎵撳紑鎴愬姛锛�");
+
+                    //淇濆瓨涓插彛鐨勯厤缃俊鎭�
+                    saveParams();
+                }
+                catch (Exception ex)
+                {
+                    MessageBox.Show("鎵撳紑涓插彛澶辫触锛�" + ex.Message, "閿欒", MessageBoxButtons.OK, MessageBoxIcon.Error);
+                    return;
+                }
+            }
+            else
+            {
+
+            }
+        }
+        #endregion
+
+        #region 鍏抽棴涓插彛
+        public void CloseCom()
+        {
+            if (!ComDevice.IsOpen)
+            {
+                MessageBox.Show("涓插彛鍏抽棴澶辫触锛佸綋鍓嶄覆鍙f湭鎵撳紑锛�");
+            }
+            else
+            {
+                try
+                {
+                    Thread.Sleep(100);
+                    ComDevice.Close();
+
+                    MessageBox.Show("涓插彛鍏抽棴鎴愬姛锛�");
+                }
+                catch (Exception ex)
+                {
+                    MessageBox.Show(ex.Message, "閿欒", MessageBoxButtons.OK, MessageBoxIcon.Error);
+                    return;
+                }
+            }
+        }
+        #endregion
+
+        #region 鎺ユ敹鏁版嵁
+        private void Com_DataReceived(object sender, SerialDataReceivedEventArgs e)
+        {
+            if (HGetWeight == 1)
+            {
+                byte[] ReDatas = new byte[ComDevice.BytesToRead];
+                ComDevice.Read(ReDatas, 0, ReDatas.Length);//璇诲彇鏁版嵁
+                this.AddData(ReDatas);//杈撳嚭鏁版嵁
+            }
+        }
+        #endregion
+
+        #region 澶勭悊鎺ユ敹鍒扮殑鏁版嵁
+        public void AddData(byte[] data)
+        {
+            StringBuilder sb = new StringBuilder();
+            sb.Append(Encoding.ASCII.GetString(data));
+
+            var str = sb.ToString();
+            str = str.Replace("w", "").Replace("n", "").Replace("kg\r\n", ";");
+
+
+            if (str != repeatData)
+            {
+                repeatData = str;
+                string[] strArray = str.Split(';');
+
+                for (int i = 0; i < strArray.Length; i++)
+                {
+                    if (double.TryParse(strArray[i], out double ret))//鍒ゆ柇鏄惁鏄暟瀛�
+                    {
+                        //淇濈暀涓�浣嶅皬鏁�
+                        double temp = double.Parse(strArray[i]);
+                        temp = Math.Round(temp,1);
+
+                        Message += double.Parse(strArray[i]) + ";";
+                    }
+                }
+            }
+        }
+        #endregion
+
+        #region 鑾峰彇鏁扮粍涓嚭鐜伴鐜囨渶楂樼殑鏁版嵁
+        private string getMostStr(string message)
+        {
+            string[] strArray = message.Split(';');
+            // 浣跨敤LINQ鏌ヨ鍑虹幇娆℃暟鏈�澶氱殑鍏冪礌
+            var maxElement = strArray.GroupBy(x => x)
+                                  .OrderByDescending(g => g.Count())
+                                  .First()
+                                  .Key;
+
+
+            return maxElement;
+        }
+        #endregion
+
+        #region 璁℃椂鍣ㄨЕ鍙戜簨浠讹紝鐢ㄤ簬鑾峰彇鏃堕棿闂撮殧鍐呮帴鏀跺埌鐨勬暟鎹�
+        private void timer2_Tick(object sender, EventArgs e)
+        {
+            if (timeIndex == 0)
+            {
+                timeIndex = 1;
+            }
+            else
+            {
+                timer2.Enabled = false;
+
+                string str = getMostStr(Message);
+
+                txtHWeightQyt.Text = str;
+
+
+                Message = "";
+                timeIndex = 0;
+                HGetWeight = 0;
+            }
+        }
+        #endregion
+
+        #region 绉伴噸鎸夐挳瑙﹀彂浜嬩欢
+        private void button_getHWeight_Click(object sender, EventArgs e)
+        {
+            HGetWeight = 1;
+            timer2.Enabled = true;
+        }
+        #endregion
+
+
+        #region 淇濆瓨閰嶇疆淇℃伅
+        //鍐欏叆閰嶇疆鍙傛暟
+        private void saveParams()
+        {
+            //鍒ゆ柇鏂囦欢鏄惁瀛樺湪   
+            if (!File.Exists(Application.StartupPath + "//Kf_WeightToBarCodeParams.txt"))
+            {
+                FileStream fs1 = new FileStream(Application.StartupPath + "//Kf_WeightToBarCodeParams.txt", FileMode.Create, FileAccess.Write);//鍒涘缓鍐欏叆鏂囦欢    
+                StreamWriter sw = new StreamWriter(fs1);
+                sw.WriteLine(value_COM);//寮�濮嬪啓鍏ュ��   
+                sw.WriteLine(value_BaudRate);
+
+                sw.WriteLine(value_StopBits);
+
+                sw.WriteLine(value_Parity);
+                sw.WriteLine(value_DataBits);
+                sw.Close();
+                fs1.Close();
+            }
+            else
+            {
+                FileStream fs1 = new FileStream(Application.StartupPath + "//Kf_WeightToBarCodeParams.txt", FileMode.Create, FileAccess.Write);//鍒涘缓鍐欏叆鏂囦欢    
+                StreamWriter sw = new StreamWriter(fs1);
+                sw.WriteLine(value_COM);//寮�濮嬪啓鍏ュ��   
+                sw.WriteLine(value_BaudRate);
+
+                sw.WriteLine(value_StopBits);
+
+                sw.WriteLine(value_Parity);
+                sw.WriteLine(value_DataBits);
+                sw.Close();
+                fs1.Close();
+            }
+        }
+        #endregion
+
+        #region 璇诲彇閰嶇疆淇℃伅
+        //璇诲彇閰嶇疆鏂囦欢
+        private void readParams()
+        {
+            //鍏抽棴涓插彛
+            //CloseCom();
+
+            if (File.Exists(Application.StartupPath + "//Kf_WeightToBarCodeParams.txt"))
+            {
+                //璇诲彇鏂囦欢鍊煎苟鏄剧ず鍒扮獥浣�    
+                FileStream fs = new FileStream(Application.StartupPath + "//Kf_WeightToBarCodeParams.txt", FileMode.Open, FileAccess.ReadWrite);
+                StreamReader sr = new StreamReader(fs);
+                string line = sr.ReadLine();
+                int curLine = 0;
+                while (line != null)
+                {
+                    if (++curLine == 1)
+                    {
+                        value_COM = line;
+                        textBox_COM.Text = value_COM;
+                    }
+                    else if (curLine == 2)
+                    {
+                        value_BaudRate = line;
+                    }
+                    else if (curLine == 3)
+                    {
+                        value_StopBits = line;
+                    }
+                    else if (curLine == 4)
+                    {
+                        value_Parity = line;
+                    }
+                    else if (curLine == 5)
+                    {
+                        value_DataBits = line;
+                    }
+                    else
+                    {
+
+                    }
+                    line = sr.ReadLine();
+                }
+                sr.Close();
+                fs.Close();
+            }
+        }
+        #endregion
+        #endregion
     }
 }
\ No newline at end of file

--
Gitblit v1.9.1