Browse Source

功能修改

callm 2 months ago
parent
commit
672d18f3e5

+ 1 - 1
FileWatcher/AutoAnalysisXml.Designer.cs

@@ -285,7 +285,7 @@
             this.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
             this.MaximizeBox = false;
             this.Name = "AutoAnalysisXml";
-            this.Text = "UAS自动过站解析器 2024-12-08";
+            this.Text = "UAS自动过站解析器 2024-12-17";
             this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Form1_FormClosing);
             this.Load += new System.EventHandler(this.Form1_Load);
             ((System.ComponentModel.ISupportInitialize)(this.XmlWatcher)).EndInit();

+ 6 - 191
FileWatcher/AutoAnalysisXml.cs

@@ -262,6 +262,7 @@ namespace FileWatcher
                                 {
                                     OperateResult.AppendText(oErrMessage + "\n");
                                     tipform.startthread(oErrMessage, Result);
+                                    File.Delete(FileName);
                                 }
                                 tipform.startthread("序列号 " + SN + "通过检测", Result);
                                 OperateResult.AppendText("序列号 " + SN + "通过检测" + "\n");
@@ -273,6 +274,7 @@ namespace FileWatcher
                                 {
                                     OperateResult.AppendText(oErrMessage + "\n");
                                     tipform.startthread(oErrMessage, Result);
+                                    File.Delete(FileName);
                                 }
                                 tipform.startthread("序列号 " + SN + "未通过检测", Result);
                                 OperateResult.AppendText("序列号 " + SN + "未通过检测" + "\n");
@@ -280,14 +282,13 @@ namespace FileWatcher
                             default:
                                 break;
                         }
-                        File.Delete(FileName);
                     }
                 }
                 else
                 {
                     OperateResult.AppendText(oErrMessage + "\n");
                     tipform.startthread(oErrMessage, Result);
-                    File.Delete(FileName);
+                    // File.Delete(FileName);
                 }
             }
             else if (Device.Text == "测试设备")
@@ -351,7 +352,7 @@ namespace FileWatcher
                             }
                             else
                             {
-                                File.Delete(FileName);
+                                //File.Delete(FileName);
                                 OperateResult.AppendText(oErrMessage + "\n");
                                 tipform.startthread(oErrMessage, Result);
                             }
@@ -372,7 +373,7 @@ namespace FileWatcher
                                 istepcode = dt.Rows[0]["sc_stepcode"].ToString();
                                 ibadgroup = dt.Rows[0]["st_badgroupcode"].ToString();
                             }
-                            if (LogicHandler.CheckStepSNAndMacode(ma_code.Text, isource, ms_sncode, iusercode, out makecode, out oMSID, out oErrMessage))
+                            if (LogicHandler.CheckStepSNAndMacode("", isource, ms_sncode, iusercode, out makecode, out oMSID, out oErrMessage))
                             {
                                 ma_code.Text = makecode;
                                 if (LogicHandler.SetStepResult(makecode, isource, ms_sncode, "自动过站采集", "OK", iusercode, out oErrMessage))
@@ -409,7 +410,7 @@ namespace FileWatcher
                             }
                             else
                             {
-                                File.Delete(FileName);
+                                // File.Delete(FileName);
                                 OperateResult.AppendText(oErrMessage + "\n");
                                 tipform.startthread(oErrMessage, Result);
                             }
@@ -426,192 +427,6 @@ namespace FileWatcher
         /// <summary>
         /// 使用进程处理文件,避免界面假死
         /// </summary>
-        private void XmlHandleProcess(string FileName)
-        {
-            string test_date = "";
-            string test_result = "";
-            string test_sn = "";
-            string imageurl = "";
-            string oMSID = "";
-            string oErrMessage = "";
-            XmlReader myReader = XmlReader.Create(FolderPath.Text + @"\" + FileName);
-            OperateResult.AppendText("读取文件" + FileName + "\n");
-            //获取采集的项目名称
-            List<string> badcode = new List<string>();
-            //获取采集项目的结果
-            List<string> badlocation = new List<string>();
-            while (myReader.Read())
-            {
-                if (myReader.NodeType == XmlNodeType.Element && myReader.Name == "test" && myReader.IsStartElement())
-                {
-                    test_sn = myReader.GetAttribute("test_sn");
-                    test_result = myReader.GetAttribute("test_result");
-                    test_date = myReader.GetAttribute("test_date");
-                    imageurl = myReader.GetAttribute("imgurl");
-                }
-                //if (myReader.NodeType == XmlNodeType.Text)
-                //{
-                //    if (code_or_location % 2 == 0)
-                //    {
-                //        badcode.Add(myReader.Value);
-                //        code_or_location++;
-                //    }
-                //    else
-                //    {
-                //        badlocation.Add(myReader.Value);
-                //        code_or_location++;
-                //    }
-                //}
-                if (myReader.NodeType == XmlNodeType.Element && myReader.Name == "err_reason" && myReader.IsStartElement())
-                {
-                    badcode.Add(myReader.ReadInnerXml() + " ");
-                }
-                if (myReader.NodeType == XmlNodeType.Element && myReader.Name == "err_location" && myReader.IsStartElement())
-                {
-                    badlocation.Add(myReader.ReadInnerXml() + " ");
-                }
-            }
-            myReader.Close();
-            string sncode = FileName.Substring(0, 1) == "-" ? "" : FileName.Split('.')[0];
-            string makecode = "";
-            //获取序列号ID最大的工单号,所有序列号都测试为良品
-            if (sncode == "")
-            {
-                //获取资源,线别,工序相等,并且状态在线的序列号进行分配
-                sql.Clear();
-                sql.Append("select ms_sncode,ms_makecode from makeserial left join source on sc_code=ms_sccode where ");
-                sql.Append("sc_linecode='" + ilinecode + "' and ms_nextstepcode='" + istepcode + "' and ms_status=1 order by ms_id");
-                dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
-                if (dt.Rows.Count > 0)
-                {
-                    makecode = dt.Rows[0]["ms_makecode"].ToString();
-                    sncode = dt.Rows[0]["ms_sncode"].ToString();
-                }
-                else
-                {
-                    OperateResult.AppendText("当前线别在" + istepcode + "无可分配序列号");
-                    tipform.startthread("当前线别在" + istepcode + "无可分配序列号", "NG");
-                    return;
-                }
-                //-2-NG2017/10/2514:46:29.xml取第二位版号
-                string combinecode = FileName.Substring(1, 1);
-                if (LogicHandler.CheckStepSNAndMacode(ma_code.Text == "" ? makecode : ma_code.Text, isource, sncode, iusercode, out makecode, out oMSID, out oErrMessage))
-                {
-                    //插入日志
-                    LogicHandler.AutoPassLog(sncode, isource, makecode, test_date, istepcode, ilinecode, FileName, test_result == "NG" ? "-1" : "0", "-1", 0, "", "");
-                    //如果是不良品记录日志,用于测试采集判负
-                    if (test_result == "NG")
-                    {
-                        RecordBadInfo(sncode, makecode, FileName, combinecode, badcode.ToArray(), badlocation.ToArray(), null);
-                    }
-                    if (!LogicHandler.SetStepResult(makecode, isource, sncode, "自动过站采集", "OK", iusercode, out oErrMessage))
-                    {
-                        OperateResult.AppendText(oErrMessage + "\n");
-                        tipform.startthread(oErrMessage, "NG");
-                        return;
-                    }
-                    tipform.startthread("序列号 " + sncode + "通过检测", test_result);
-                }
-                else
-                {
-                    OperateResult.AppendText(oErrMessage + "\n");
-                    tipform.startthread(oErrMessage, "NG");
-                    return;
-                }
-            }
-            else
-            {
-                string status = "";
-                string errmessage = "";
-                bool NoteAlready = false;
-                LogicHandler.GetMakeInfo(sncode, out makecode, out status, out errmessage);
-                if (ma_code.Text != makecode && makecode != "" && ma_code.Text != "" && status != "2")
-                {
-                    string ChangeMakeCode = MessageBox.Show(this.ParentForm, "序列号" + sncode + "所属工单不同,是否切换?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
-                    //如果选择不切换赋值当前界面工单
-                    if (ChangeMakeCode != "Yes")
-                    {
-                        makecode = ma_code.Text;
-                    }
-                    else
-                    {
-                        NoteAlready = true;
-                    }
-                }
-                if (LogicHandler.CheckStepSNAndMacode(ma_code.Text == "" ? makecode : ma_code.Text, isource, sncode, iusercode, out makecode, out oMSID, out oErrMessage))
-                {
-                    if (!NoteAlready)
-                    {
-                        if (makecode != ma_code.Text && ma_code.Text != "")
-                        {
-                            string ChangeMakeCode = MessageBox.Show(this.ParentForm, "序列号所属工单不同,是否切换?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
-                            //如果选择不切换赋值当前界面工单
-                            if (ChangeMakeCode == "Yes")
-                            {
-                                ma_code.Text = makecode;
-                            }
-                            else
-                            {
-                                OperateResult.AppendText(">>请重新采集序列号\n");
-                                tipform.startthread("请重新采集序列号", test_result);
-                                return;
-                            }
-                        }
-                    }
-                    //获取序列号ID最大的工单
-                    dt = (DataTable)dh.ExecuteSql("select ms_makecode,ms_id from makeserial where ms_sncode='" + sncode + "' order by ms_id desc", "select");
-                    if (dt.Rows.Count > 0)
-                    {
-                        ma_code.Text = dt.Rows[0]["ms_makecode"].ToString();
-                        makecode = dt.Rows[0]["ms_makecode"].ToString();
-                        switch (test_result)
-                        {
-                            case "OK":
-                                if (!LogicHandler.SetStepResult(makecode, isource, sncode, "自动过站采集", test_result, iusercode, out oErrMessage))
-                                {
-                                    OperateResult.AppendText(oErrMessage + "\n");
-                                    tipform.startthread(oErrMessage, test_result);
-                                    return;
-                                }
-                                tipform.startthread("序列号 " + sncode + "通过检测", test_result);
-                                break;
-                            case "NG":
-                                RecordBadInfo(sncode, makecode, FileName, "", badcode.ToArray(), badlocation.ToArray(), null);
-                                //所有的序列号均采集为良品
-                                if (!LogicHandler.SetTestNGDetail(sncode, makecode, iusercode, isource, test_result, out oErrMessage))
-                                {
-                                    OperateResult.AppendText(oErrMessage + "\n");
-                                    tipform.startthread(oErrMessage, test_result);
-                                    return;
-                                }
-                                tipform.startthread("序列号 " + sncode + "未通过检测", test_result);
-                                break;
-                            default:
-                                break;
-                        }
-                        LogicHandler.AutoPassLog(sncode, isource, makecode, test_date, istepcode, ilinecode, FileName, test_result == "NG" ? "1" : "0", "0", 0, "", "");
-                    }
-                }
-                else
-                {
-                    OperateResult.AppendText(oErrMessage + "\n");
-                    tipform.startthread(oErrMessage, "NG");
-                    return;
-                }
-            }
-            FileInfo file = new FileInfo(FolderPath.Text + @"\" + FileName);
-            if (file.Exists)
-            {
-                try
-                {
-
-                }
-                catch (Exception ex)
-                {
-                    OperateResult.AppendText(FileName + ex.Message + "\n");
-                }
-            }
-        }
 
         private void RecordBadInfo(string sncode, string makecode, string filename, string combine, string[] badcode, string[] badlocation, string[] soncode)
         {

+ 1 - 1
FileWatcher/AutoAnalysisXmlByStep.Designer.cs

@@ -390,7 +390,7 @@
             this.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
             this.MaximizeBox = false;
             this.Name = "AutoAnalysisXmlByStep";
-            this.Text = "UAS自动过站解析器 2024-04-23 14:15";
+            this.Text = "UAS自动过站解析器 2024-12-16 14:15";
             this.Deactivate += new System.EventHandler(this.AutoAnalysisXmlByStep_Deactivate);
             this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Form1_FormClosing);
             this.Load += new System.EventHandler(this.Form1_Load);

+ 33 - 5
FileWatcher/AutoAnalysisXmlByStep.cs

@@ -65,9 +65,23 @@ namespace FileWatcher
         ftpOperater ftp;
         string imaster;
 
+        protected override CreateParams CreateParams
+        {
+            get
+            {
+                CreateParams cp = base.CreateParams;
+                const int WS_EX_APPWINDOW = 0x40000;
+                const int WS_EX_TOOLWINDOW = 0x80;
+                cp.ExStyle &= (~WS_EX_APPWINDOW);
+                cp.ExStyle |= WS_EX_TOOLWINDOW;
+                return cp;
+            }
+        }
+
         public AutoAnalysisXmlByStep()
         {
             tipform = new Tip();
+
             InitializeComponent();
             StartPosition = FormStartPosition.CenterScreen;
         }
@@ -129,7 +143,7 @@ namespace FileWatcher
             if (hide)
             {
                 this.WindowState = FormWindowState.Minimized;
-                this.ShowInTaskbar = false;
+                this.ShowInTaskbar = true;
             }
         }
 
@@ -398,12 +412,16 @@ namespace FileWatcher
 
         private void Form1_FormClosing(object sender, FormClosingEventArgs e)
         {
-            string ExitConfirm = MessageBox.Show(this, "确认退出?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
-            if (ExitConfirm != "Yes")
+            string ExitConfirm = MessageBox.Show(this, "最小化托盘?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
+            if (ExitConfirm == "Yes")
             {
                 WindowState = FormWindowState.Minimized;
                 e.Cancel = true;
             }
+            else
+            {
+                e.Cancel = true;
+            }
         }
 
         private void AutoStart_CheckedChanged(object sender, EventArgs e)
@@ -449,7 +467,15 @@ namespace FileWatcher
                 var AllXmls = Directory.GetFiles(FolderPath.Text, "*.*", SearchOption.AllDirectories).Where(s => s.EndsWith(".txt") || s.EndsWith(".ini"));
                 foreach (var Xml in AllXmls)
                 {
-                    File.Delete(Xml.ToString());
+                    try
+                    {
+                        TxtHandleProcess(Xml.ToString());
+                        File.Delete(Xml.ToString());
+                    }
+                    catch (Exception ex)
+                    {
+
+                    }
                 }
             }
         }
@@ -466,9 +492,11 @@ namespace FileWatcher
 
         private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
         {
-            if (WindowState == FormWindowState.Minimized)
+            //if (WindowState == FormWindowState.Minimized)
             {
+                Thread.Sleep(1000);
                 WindowState = FormWindowState.Normal;
+                Thread.Sleep(1000);
                 ShowInTaskbar = true;
             }
         }

+ 92 - 40
FileWatcher/AutoMakeQTYRZ.Designer.cs

@@ -46,11 +46,15 @@
             this.BaudRate = new System.Windows.Forms.TextBox();
             this.NowQTY = new System.Windows.Forms.TextBox();
             this.label4 = new System.Windows.Forms.Label();
-            this.ComPort = new FileWatcher.SerialPortCombox();
-            this.li_code = new FileWatcher.SearchTextBox();
             this.label5 = new System.Windows.Forms.Label();
-            this.ma_code = new FileWatcher.SearchTextBox();
             this.GetData = new System.Windows.Forms.Button();
+            this.FunctionNum = new System.Windows.Forms.TextBox();
+            this.label6 = new System.Windows.Forms.Label();
+            this.ma_code = new FileWatcher.SearchTextBox();
+            this.li_code = new FileWatcher.SearchTextBox();
+            this.ComPort = new FileWatcher.SerialPortCombox();
+            this.FunctionNum1 = new System.Windows.Forms.TextBox();
+            this.label7 = new System.Windows.Forms.Label();
             ((System.ComponentModel.ISupportInitialize)(this.XmlWatcher)).BeginInit();
             ((System.ComponentModel.ISupportInitialize)(this.ATEFile)).BeginInit();
             this.SuspendLayout();
@@ -120,7 +124,7 @@
             // 
             // Timer
             // 
-            this.Timer.Interval = 300;
+            this.Timer.Interval = 1000;
             this.Timer.Tick += new System.EventHandler(this.Timer_Tick);
             // 
             // ATEFile
@@ -215,32 +219,6 @@
             this.label4.TabIndex = 25;
             this.label4.Text = "当前计数";
             // 
-            // ComPort
-            // 
-            this.ComPort.Location = new System.Drawing.Point(204, 120);
-            this.ComPort.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
-            this.ComPort.Name = "ComPort";
-            this.ComPort.Size = new System.Drawing.Size(176, 40);
-            this.ComPort.TabIndex = 21;
-            // 
-            // li_code
-            // 
-            this.li_code.AllPower = null;
-            this.li_code.Caller = null;
-            this.li_code.Condition = null;
-            this.li_code.DBTitle = null;
-            this.li_code.FormName = null;
-            this.li_code.Location = new System.Drawing.Point(204, 291);
-            this.li_code.Name = "li_code";
-            this.li_code.Power = null;
-            this.li_code.ReturnData = null;
-            this.li_code.SelectField = null;
-            this.li_code.SetValueField = null;
-            this.li_code.Size = new System.Drawing.Size(436, 41);
-            this.li_code.TabIndex = 28;
-            this.li_code.TableName = null;
-            this.li_code.TextBoxEnable = false;
-            // 
             // label5
             // 
             this.label5.AutoSize = true;
@@ -251,6 +229,38 @@
             this.label5.TabIndex = 27;
             this.label5.Text = "线别";
             // 
+            // GetData
+            // 
+            this.GetData.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.GetData.Location = new System.Drawing.Point(492, 557);
+            this.GetData.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
+            this.GetData.Name = "GetData";
+            this.GetData.Size = new System.Drawing.Size(128, 56);
+            this.GetData.TabIndex = 30;
+            this.GetData.Text = "获取数据";
+            this.GetData.UseVisualStyleBackColor = true;
+            this.GetData.Click += new System.EventHandler(this.GetData_Click);
+            // 
+            // FunctionNum
+            // 
+            this.FunctionNum.AccessibleRole = System.Windows.Forms.AccessibleRole.SplitButton;
+            this.FunctionNum.Location = new System.Drawing.Point(567, 376);
+            this.FunctionNum.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
+            this.FunctionNum.Name = "FunctionNum";
+            this.FunctionNum.Size = new System.Drawing.Size(146, 35);
+            this.FunctionNum.TabIndex = 32;
+            // 
+            // label6
+            // 
+            this.label6.AutoSize = true;
+            this.label6.Font = new System.Drawing.Font("微软雅黑", 10.8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.label6.Location = new System.Drawing.Point(397, 373);
+            this.label6.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
+            this.label6.Name = "label6";
+            this.label6.Size = new System.Drawing.Size(133, 38);
+            this.label6.TabIndex = 31;
+            this.label6.Text = "功率下限";
+            // 
             // ma_code
             // 
             this.ma_code.AllPower = null;
@@ -269,23 +279,61 @@
             this.ma_code.TableName = null;
             this.ma_code.TextBoxEnable = false;
             // 
-            // GetData
+            // li_code
             // 
-            this.GetData.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.GetData.Location = new System.Drawing.Point(492, 557);
-            this.GetData.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
-            this.GetData.Name = "GetData";
-            this.GetData.Size = new System.Drawing.Size(128, 56);
-            this.GetData.TabIndex = 30;
-            this.GetData.Text = "获取数据";
-            this.GetData.UseVisualStyleBackColor = true;
-            this.GetData.Click += new System.EventHandler(this.GetData_Click);
+            this.li_code.AllPower = null;
+            this.li_code.Caller = null;
+            this.li_code.Condition = null;
+            this.li_code.DBTitle = null;
+            this.li_code.FormName = null;
+            this.li_code.Location = new System.Drawing.Point(204, 291);
+            this.li_code.Name = "li_code";
+            this.li_code.Power = null;
+            this.li_code.ReturnData = null;
+            this.li_code.SelectField = null;
+            this.li_code.SetValueField = null;
+            this.li_code.Size = new System.Drawing.Size(436, 41);
+            this.li_code.TabIndex = 28;
+            this.li_code.TableName = null;
+            this.li_code.TextBoxEnable = false;
+            // 
+            // ComPort
+            // 
+            this.ComPort.Location = new System.Drawing.Point(204, 120);
+            this.ComPort.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
+            this.ComPort.Name = "ComPort";
+            this.ComPort.Size = new System.Drawing.Size(176, 40);
+            this.ComPort.TabIndex = 21;
+            // 
+            // FunctionNum1
+            // 
+            this.FunctionNum1.AccessibleRole = System.Windows.Forms.AccessibleRole.SplitButton;
+            this.FunctionNum1.Location = new System.Drawing.Point(567, 431);
+            this.FunctionNum1.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
+            this.FunctionNum1.Name = "FunctionNum1";
+            this.FunctionNum1.Size = new System.Drawing.Size(146, 35);
+            this.FunctionNum1.TabIndex = 34;
+            // 
+            // label7
+            // 
+            this.label7.AutoSize = true;
+            this.label7.Font = new System.Drawing.Font("微软雅黑", 10.8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.label7.Location = new System.Drawing.Point(397, 428);
+            this.label7.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
+            this.label7.Name = "label7";
+            this.label7.Size = new System.Drawing.Size(133, 38);
+            this.label7.TabIndex = 33;
+            this.label7.Text = "功率上限";
             // 
             // AutoMakeQTYRZ
             // 
             this.AutoScaleDimensions = new System.Drawing.SizeF(12F, 24F);
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
             this.ClientSize = new System.Drawing.Size(1443, 640);
+            this.Controls.Add(this.FunctionNum1);
+            this.Controls.Add(this.label7);
+            this.Controls.Add(this.FunctionNum);
+            this.Controls.Add(this.label6);
             this.Controls.Add(this.GetData);
             this.Controls.Add(this.ma_code);
             this.Controls.Add(this.li_code);
@@ -341,6 +389,10 @@
         private System.Windows.Forms.Label label5;
         private SearchTextBox ma_code;
         private System.Windows.Forms.Button GetData;
+        private System.Windows.Forms.TextBox FunctionNum;
+        private System.Windows.Forms.Label label6;
+        private System.Windows.Forms.TextBox FunctionNum1;
+        private System.Windows.Forms.Label label7;
     }
 }
 

+ 49 - 7
FileWatcher/AutoMakeQTYRZ.cs

@@ -169,15 +169,21 @@ namespace FileWatcher
 
         double lastqty = 0;
         string data = "";
+        bool getSeconddata = false;
         bool realwritedata = false;
         private void SerialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)
         {
             try
             {
+
                 int len = serialPort1.BytesToRead;
                 Byte[] readBuffer = new Byte[len];
                 serialPort1.Read(readBuffer, 0, len); //将数据读入缓存
                 data = BitConverter.ToString(readBuffer, 0, readBuffer.Length).Replace("-", "");
+                if (data.Length > 48)
+                {
+                    data = data.Substring(0, 48);
+                }
                 if (data.Length == 48)
                 {
                     float 电压数据 = getdata(data.Substring(6, 8));
@@ -200,17 +206,50 @@ namespace FileWatcher
                         {
                             realwritedata = true;
                             writedata = false;
+                            Thread.Sleep(2000);
+                            OperateResult.AppendText("获取数据\n");
+                            byte[] data = HexStringToBytes("55 00 10 65");
+                            serialPort1.Write(data, 0, data.Length);
                         }
                     }
                     if (realwritedata)
                     {
-                        OperateResult.AppendText("数据上传成功\n");
-                        dh.ExecuteSql("insert into currenttest(CT_ID,ct_linecode, CT_MAKECODE, CT_VOLTAGE, CT_CURRENT, CT_POWER, CT_FREQUENCY, CT_POWER1)" +
-                         "VALUES(currenttest_SEQ.NEXTVAL,'" + li_code.Text + "','" + ma_code.Text + "','" + 电压数据 + "','" + 电流数据 + "','" + 功率数据 + "','" + 频率数据 + "','" + 功率因素 + "')", "insert");
-                        NowQTY.Text = dh.getRowCount("currenttest", "ct_makecode='" + ma_code.Text + "'").ToString();
-                        realwritedata = false;
+                        if (电流数据 > 0)
+                        {
+                            double num;
+                            double num1;
+                            if (double.TryParse(FunctionNum.Text, out num) && double.TryParse(FunctionNum1.Text, out num1))
+                            {
+                                if (功率数据 > num && 功率数据 < num1)
+                                {
+                                    OperateResult.AppendText("数据上传成功,功率[" + 功率数据 + "]\n");
+                                    dh.ExecuteSql("insert into currenttest(CT_ID,ct_linecode, CT_MAKECODE, CT_VOLTAGE, CT_CURRENT, CT_POWER, CT_FREQUENCY, CT_POWER1)" +
+                                     "VALUES(currenttest_SEQ.NEXTVAL,'" + li_code.Text + "','" + ma_code.Text + "','" + 电压数据 + "','" + 电流数据 + "','" + 功率数据 + "','" + 频率数据 + "','" + 功率因素 + "')", "insert");
+                                    NowQTY.Text = dh.getRowCount("currenttest", "ct_makecode='" + ma_code.Text + "'").ToString();
+                                    realwritedata = false;
+                                }
+                                else
+                                {
+                                    OperateResult.AppendText("功率数据异常\n");
+                                }
+                            }
+                            else
+                            {
+                                OperateResult.AppendText("请填写功率标准值\n");
+                            }
+                        }
                     }
                 }
+                else
+                {
+                    //realwritedata = true;
+                    //writedata = false;
+                    //Thread.Sleep(1000);
+                    //OperateResult.AppendText("获取数据1\n");
+                    //byte[] data = HexStringToBytes("55 00 10 65");
+                    //serialPort1.Write(data, 0, data.Length);
+                    //OperateResult.AppendText(data + "数据格式异常\n");
+                }
             }
             catch (Exception ex)
             {
@@ -328,8 +367,11 @@ namespace FileWatcher
         {
             if (serialPort1.IsOpen)
             {
-                byte[] data = HexStringToBytes("55 00 10 65");
-                serialPort1.Write(data, 0, data.Length);
+                if (!realwritedata)
+                {
+                    byte[] data = HexStringToBytes("55 00 10 65");
+                    serialPort1.Write(data, 0, data.Length);
+                }
             }
         }
 

+ 8 - 7
FileWatcher/DataHelper.cs

@@ -6,16 +6,16 @@ using System.Text;
 
 namespace FileWatcher
 {
-   public class DataHelper
+    public class DataHelper
     {
-       // 系统默认的的连接字符串
-        private string ConnectionStrings = "Connection Timeout=0;Pooling=false;Password=select!#%*(;User ID=N_MES;Pooling=false;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=10.10.6.28)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));";
+        // 系统默认的的连接字符串
+        private string ConnectionStrings = "Connection Timeout=0;Pooling=false;Password=select!#%*(;User ID=N_MES;Pooling=false;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=113.98.196.181)(PORT=1520)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));";
         //用户选择的数据库的连接字符串
-        public static string DBConnectionString = "Connection Timeout=0;Pooling=false;Password=select!#%*(;User ID=N_MES;Pooling=false;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=10.10.6.28)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));";
+        public static string DBConnectionString = "Connection Timeout=0;Pooling=false;Password=select!#%*(;User ID=N_MES;Pooling=false;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=113.98.196.181)(PORT=1520)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));";
 
-        //private string ConnectionStrings = "Connection Timeout=0;Pooling=false;Password=select!#%*(;User ID=YD_CYZZ;Pooling=false;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.0.85)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));";
+        //private string ConnectionStrings = "Connection Timeout=0;Pooling=false;Password=select!#%*(;User ID=YD_CYZZ;Pooling=false;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.0.85)(PORT=1520)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));";
         ////用户选择的数据库的连接字符串
-        //public static string DBConnectionString = "Connection Timeout=0;Pooling=false;Password=select!#%*(;User ID=YD_CYZZ;Pooling=false;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.0.85)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));";
+        //public static string DBConnectionString = "Connection Timeout=0;Pooling=false;Password=select!#%*(;User ID=YD_CYZZ;Pooling=false;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.0.85)(PORT=1520)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));";
 
         public static OracleConnection connection = null;
         OracleCommand command = null;
@@ -34,7 +34,8 @@ namespace FileWatcher
                     connection = new OracleConnection(DBConnectionString);
                 connection.Open();
             }
-            catch (Exception e) {
+            catch (Exception e)
+            {
 
             }
         }

+ 1 - 1
FileWatcher/Program.cs

@@ -45,7 +45,7 @@ namespace FileWatcher
                 Application.EnableVisualStyles();
                 Application.SetCompatibleTextRenderingDefault(false);
                 if (principal.IsInRole(WindowsBuiltInRole.Administrator))
-                    Application.Run(new AutoMakeQTYRZ());
+                    Application.Run(new AutoAnalysisXmlByStep());
                 else
                 {
                     //创建启动对象

+ 3 - 3
FileWatcher/ftpOperater.cs

@@ -21,9 +21,9 @@ namespace FileWatcher
 
         public ftpOperater()
         {
-            string[] FTPInf = "ftp://172.16.51.3|vsftpd|vsftpd3cd79014ef".Split('|');
-            //睿德FTP
-            //string[] FTPInf = "ftp://113.98.196.181|ftpuser2|Az789***".Split('|');
+            //string[] FTPInf = "ftp://172.16.51.3|vsftpd|vsftpd3cd79014ef".Split('|');
+            //次元FTP
+            string[] FTPInf = "ftp://113.98.196.181:8097|vsftpd|Az789***".Split('|');
             this.ftpServerIP = FTPInf[0];
             this.ftpUser = FTPInf[1];
             this.ftpPwd = FTPInf[2];