Exemplo n.º 1
0
        private void run()
        {
            status = true;
            timed  = 1000;
            int ngnum = 0;

            while (true)
            {
                if (start)
                {
                    string newbar = Inifile.INIGetStringValue(iniFilepath, "A", "bar" + index.ToString(), "0");
                    try
                    {
                        Oracle oraDB = new Oracle("qddb04.eavarytech.com", "mesdb04", "ictdata", "ictdata*168");
                        if (oraDB.isConnect())
                        {
                            string    stm = String.Format("Select * from fluke_data WHERE BARCODE = '{0}'AND TRESULT = '{1}' ORDER BY ITSDATE DESC, ITSTIME DESC", newbar, result);
                            DataSet   s   = oraDB.executeQuery(stm);
                            DataTable dt  = s.Tables[0];
                            if (dt.Rows.Count > 0)
                            {
                                string datestr = (string)dt.Rows[0]["ITSDATE"];
                                string timestr = (string)dt.Rows[0]["ITSTIME"];
                                if (datestr.Length == 8 && (timestr.Length == 5 || timestr.Length == 6))
                                {
                                    if (timestr.Length == 5)
                                    {
                                        timestr = "0" + timestr;
                                    }
                                    string datetimestr = string.Empty;
                                    datetimestr = string.Format("{0}/{1}/{2} {3}:{4}:{5}", datestr.Substring(0, 4), datestr.Substring(4, 2), datestr.Substring(6, 2), timestr.Substring(0, 2), timestr.Substring(2, 2), timestr.Substring(4, 2));
                                    DateTime updatetime = Convert.ToDateTime(datetimestr);
                                    TimeSpan sp         = System.DateTime.Now - updatetime;
                                    if (sp.TotalSeconds < 30)
                                    {
                                        ngnum  = 0;
                                        status = true;
                                        timed  = 2000;
                                        start  = false;
                                        ModelPrint("测试机" + index.ToString() + ": " + newbar + " 数据上传成功 " + updatetime.ToString());
                                        stm = String.Format("Select * from fluke_data WHERE BARCODE = '{0}' ORDER BY ITSDATE DESC, ITSTIME DESC", newbar, result);
                                        s   = oraDB.executeQuery(stm);
                                        dt  = s.Tables[0];
                                        if (dt.Rows.Count > 3)
                                        {
                                            RecordPrint(index, newbar, result, testerCycle, false);
                                        }
                                        else
                                        {
                                            RecordPrint(index, newbar, result, testerCycle, true);
                                        }
                                    }
                                    else
                                    {
                                        timed = 1000;
                                        ModelPrint("测试机" + index.ToString() + ": " + newbar + " 数据上传逾时 " + updatetime.ToString());
                                    }
                                }
                                else
                                {
                                    timed = 1000;
                                    ModelPrint("测试机" + index.ToString() + ": " + newbar + " 时间格式错误 " + datestr + " " + timestr);
                                }
                            }
                            else
                            {
                                timed = 1000;
                                ModelPrint("测试机" + index.ToString() + ": " + newbar + " 未查询到数据");
                            }
                        }
                        else
                        {
                            timed = 1000;
                            ModelPrint("测试机" + index.ToString() + ": " + newbar + " 数据库未连接");
                        }
                        oraDB.disconnect();
                    }
                    catch (Exception ex)
                    {
                        ModelPrint("测试机" + index.ToString() + ": " + newbar + " 查询数据库出错" + ex.Message);

                        timed = 1000;
                    }

                    if (sw.Elapsed.TotalSeconds > 10 && start)
                    {
                        if (++ngnum > 1)
                        {
                            ngnum  = 0;
                            status = false;
                            ModelPrint("测试机" + index.ToString() + ": " + newbar + " 检测超时,2次,退出");
                        }
                        else
                        {
                            status = true;
                            ModelPrint("测试机" + index.ToString() + ": " + newbar + " 检测超时,1次,退出");
                        }

                        start = false;

                        timed = 2000;

                        RecordPrint(index, "****************************", result, testerCycle, true);
                    }
                }
                else
                {
                    timed = 2000;
                }
                System.Threading.Thread.Sleep(timed);
            }
        }
Exemplo n.º 2
0
 async void CheckSam()
 {
     try
     {
         int    ngItemCount = int.Parse(Inifile.INIGetStringValue(iniParameterPath, "Sample", "NGItemCount", "3"));
         int    nGItemLimit = int.Parse(Inifile.INIGetStringValue(iniParameterPath, "Sample", "NGItemLimit", "99"));
         string MNO         = Inifile.INIGetStringValue(iniParameterPath, "System", "MachineID", "X1621_1");
         Oracle oraDB       = new Oracle("qddb04.eavarytech.com", "mesdb04", "ictdata", "ictdata*168");
         if (oraDB.isConnect())
         {
             for (int i = 0; i < ngItemCount; i++)
             {
                 for (int j = 0; j < 4; j++)
                 {
                     string    flexid = Inifile.INIGetStringValue(iniFilepath, "A", "id" + (j + 1).ToString(), "99999");
                     string    ngitem = Inifile.INIGetStringValue(iniParameterPath, "Sample", "NGItem" + i.ToString(), "Null");
                     string    stm    = String.Format("Select * from fluke_data WHERE FL04 = '{0}' AND FL01 = '{1}' AND ITSDATE = '{2}' ORDER BY ITSDATE DESC, ITSTIME DESC", flexid, ngitem, DateTime.Now.ToString("yyyyMMdd"));
                     DataSet   s      = oraDB.executeQuery(stm);
                     DataTable dt     = s.Tables[0];
                     if (dt.Rows.Count > 0)
                     {
                         string datestr = (string)dt.Rows[0]["ITSDATE"];
                         string timestr = (string)dt.Rows[0]["ITSTIME"];
                         if (datestr.Length == 8 && (timestr.Length == 5 || timestr.Length == 6))
                         {
                             if (timestr.Length == 5)
                             {
                                 timestr = "0" + timestr;
                             }
                             string datetimestr = string.Empty;
                             datetimestr = string.Format("{0}/{1}/{2} {3}:{4}:{5}", datestr.Substring(0, 4), datestr.Substring(4, 2), datestr.Substring(6, 2), timestr.Substring(0, 2), timestr.Substring(2, 2), timestr.Substring(4, 2));
                             DateTime updatetime = Convert.ToDateTime(datetimestr);
                             TimeSpan sp         = updatetime - SamStart;
                             if (sp.TotalSeconds > 0)
                             {
                                 stm = String.Format("Select * from barsaminfo WHERE BARCODE = '{0}'", (string)dt.Rows[0]["BARCODE"]);
                                 DataSet   s1  = oraDB.executeQuery(stm);
                                 DataTable dt1 = s1.Tables[0];
                                 if (dt1.Rows.Count > 0)
                                 {
                                     try
                                     {
                                         //插入样本记录
                                         string parnum = Inifile.INIGetStringValue(iniFilepath, "Other", "pn", "FHAPHS9");
                                         string tres   = ngitem.Length > 20 ? ngitem.Substring(0, 20) : ngitem;
                                         stm = String.Format("INSERT INTO BARSAMREC (PARTNUM,SITEM,BARCODE,NGITEM,TRES,MNO,CDATE,CTIME,SR01) VALUES ('{0}','FLUKE','{1}','{2}','{3}','{4}','{5}','{6}','{7}')", parnum, (string)dt.Rows[0]["BARCODE"], (string)dt1.Rows[0]["NGITEM"], tres, MNO, DateTime.Now.ToString("yyyyMMdd"), DateTime.Now.ToString("HHmmss"), flexid);
                                         oraDB.executeNonQuery(stm);
                                         string filepath = "D:\\样本记录\\样本记录" + GlobalVars.GetBanci() + ".csv";
                                         if (!Directory.Exists("D:\\样本记录"))
                                         {
                                             Directory.CreateDirectory("D:\\样本记录");
                                         }
                                         if (!File.Exists(filepath))
                                         {
                                             string[] heads = { "DateTime", "PARTNUM", "SITEM", "BARCODE", "NGITEM", "TRES", "MNO", "CDATE", "CTIME", "SR01" };
                                             Csvfile.savetocsv(filepath, heads);
                                         }
                                         string[] conte = { System.DateTime.Now.ToString(), parnum, "FLUKE", (string)dt.Rows[0]["BARCODE"], (string)dt1.Rows[0]["NGITEM"], tres, MNO, DateTime.Now.ToString("yyyyMMdd"), DateTime.Now.ToString("HHmmss"), flexid };
                                         Csvfile.savetocsv(filepath, conte);
                                         stm = String.Format("Select * from BARSAMREC WHERE BARCODE = '{0}'", (string)dt.Rows[0]["BARCODE"]);
                                         DataSet samtimesds = oraDB.executeQuery(stm);
                                         ModelPrint("插入样本记录 " + (string)dt.Rows[0]["BARCODE"] + " " + samtimesds.Tables[0].Rows.Count.ToString());
                                         if (samtimesds.Tables[0].Rows.Count > nGItemLimit)
                                         {
                                             ModelPrint((string)dt.Rows[0]["BARCODE"] + "样本记录" + samtimesds.Tables[0].Rows.Count.ToString() + " > " + nGItemLimit.ToString());
                                             sampleContent[i][j] = "Limit";
                                         }
                                     }
                                     catch (Exception ex)
                                     {
                                         ModelPrint(ex.Message);
                                     }
                                     if (((string)dt1.Rows[0]["NGITEM"]).ToUpper() == ngitem.ToUpper())
                                     {
                                         sampleContent[i][j] = "OK";
                                     }
                                     else
                                     {
                                         sampleContent[i][j] = (string)dt1.Rows[0]["NGITEM"];
                                     }
                                 }
                                 else
                                 {
                                     sampleContent[i][j] = "NoSam";
                                 }
                             }
                             else
                             {
                                 sampleContent[i][j] = "NotNew";
                             }
                         }
                         else
                         {
                             ModelPrint("时间格式错误");
                             sampleContent[i][j] = "Error";
                         }
                     }
                     else
                     {
                         sampleContent[i][j] = "NoRecord";
                     }
                 }
             }
             //回复样本结果
             ModelPrint("UpdateCheckSam");
             bool resut = true;
             for (int i = 0; i < ngItemCount; i++)
             {
                 for (int j = 0; j < 4; j++)
                 {
                     if (sampleContent[i][j] != "OK")
                     {
                         string resultString = "RestartSample;" + j.ToString() + ";" + i.ToString();
                         if (TestSendStatus)
                         {
                             await TestSentNet.SendAsync(resultString);
                         }
                         resut = false;
                     }
                 }
             }
             if (resut)
             {
                 ModelPrint("EndSample");
                 await TestSentNet.SendAsync("EndSample");
             }
         }
         else
         {
             ModelPrint("样本查询Error:数据库连接失败");
         }
         oraDB.disconnect();
     }
     catch (Exception ex)
     {
         ModelPrint("样本查询Error:" + ex.Message);
     }
 }