Example #1
0
 void Scan1GetBarcodeCallback(string barcode)
 {
     AddMessage(barcode);
     if (barcode != "Error")
     {
         try
         {
             //载具码、盖片码、产品码
             string[] barcodes = barcode.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
             BP04 = barcodes[0];
             Inifile.INIWriteValue(iniParameterPath, "System", "BP04", BP04);
             BP11 = barcodes[1];
             Inifile.INIWriteValue(iniParameterPath, "System", "BP11", BP11);
             BPPNL = barcodes[2];
             Inifile.INIWriteValue(iniParameterPath, "System", "BPPNL", BPPNL);
             if (!Directory.Exists(Path.Combine(System.Environment.CurrentDirectory, GetBanci())))
             {
                 Directory.CreateDirectory(Path.Combine(System.Environment.CurrentDirectory, GetBanci()));
             }
             string path = Path.Combine(System.Environment.CurrentDirectory, GetBanci(), "Barcode.csv");
             Csvfile.savetocsv(path, new string[] { DateTime.Now.ToString(), BP04, BP11, BPPNL });
             SXJLibrary.Oracle oracle = new SXJLibrary.Oracle("qddb07.eavarytech.com", "mesdb07", "sfcabar", "sfcabar*168");
             if (oracle.isConnect())
             {
                 string stm = string.Format("INSERT INTO SFCDATA.BARAUTPNL (LOCATIONID,FACTORYID,BPDATE,BPTIME,BPEMPID,BPWORKNO,BPLINE,BPIP,BPPNL,BP01,BP04,BP11) VALUES ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}')"
                                            , LOCATIONID, FACTORYID, DateTime.Now.ToString("yyyyMMdd"), DateTime.Now.ToString("HHmmss"), BPEMPID, BPWORKNO, BPLINE, BPIP, BPPNL, BP01, BP04, BP11);
                 int rst = oracle.executeNonQuery(stm);
                 AddMessage("插入数据" + rst.ToString());
             }
             oracle.disconnect();
         }
         catch (Exception ex)
         {
             AddMessage(ex.Message);
         }
     }
     else
     {
         //扫码失败
     }
 }
Example #2
0
        private void SaveCSVfileRecord(string TestTime, string Barcode, string TestResult, string TestCycleTime, string Index)
        {
            string filepath = "D:\\生产记录\\生产记录" + GlobalVars.GetBanci() + ".csv";

            if (!Directory.Exists("D:\\生产记录"))
            {
                Directory.CreateDirectory("D:\\生产记录");
            }
            try
            {
                if (!File.Exists(filepath))
                {
                    string[] heads = { "Time", "Barcode", "Result", "Cycle", "Index" };
                    Csvfile.savetocsv(filepath, heads);
                }
                string[] conte = { TestTime, Barcode, TestResult, TestCycleTime, Index };
                Csvfile.savetocsv(filepath, conte);
            }
            catch (Exception ex)
            {
                ModelPrint(ex.Message);
            }
        }
Example #3
0
        private void SaveStartBarcodetoCSV(string bar, int index_ii)
        {
            if (!Directory.Exists(TestRecordSavePath + @"\Barcode\" + GetBanci()))
            {
                Directory.CreateDirectory(TestRecordSavePath + @"\Barcode\" + GetBanci());
            }
            string filepath = TestRecordSavePath + @"\Barcode\" + GetBanci() + @"\Tester" + index_ii.ToString() + GetBanciShort().Replace("/", "") + ".csv";

            try
            {
                if (!File.Exists(filepath))
                {
                    string[] heads = { "DateTime", "TesterBarcode" };
                    Csvfile.savetocsv(filepath, heads);
                }
                string[] conte = { System.DateTime.Now.ToString(), bar };
                Csvfile.savetocsv(filepath, conte);
            }
            catch (Exception ex)
            {
                //Msg = messagePrint.AddMessage("写入CSV文件失败");
                Log.Default.Error("写入CSV文件失败", ex.Message);
            }
        }
Example #4
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);
     }
 }
Example #5
0
        private async void UIRun()
        {
            int    oldMinute    = -1;
            string CurrentAlarm = "";

            if (!Directory.Exists("D:\\报警记录"))
            {
                Directory.CreateDirectory("D:\\报警记录");
            }
            while (true)
            {
                #region 报警记录
                await Task.Delay(100);

                try
                {
                    //读报警
                    bool[] M300 = await Task.Run <bool[]>(() => { return(h3u.ReadMultiM("M300", (ushort)AlarmList.Count)); });

                    if (M300 != null && StatusPLC)
                    {
                        for (int i = 0; i < AlarmList.Count; i++)
                        {
                            if (M300[i] != AlarmList[i].State && AlarmList[i].Content != "Null")
                            {
                                AlarmList[i].State = M300[i];
                                if (AlarmList[i].State)
                                {
                                    AlarmList[i].Start = DateTime.Now;
                                    AlarmList[i].End   = DateTime.Now;
                                    AddMessage(AlarmList[i].Code + AlarmList[i].Content + "发生");

                                    if (CurrentAlarm != AlarmList[i].Content)
                                    {
                                        var nowAlarm = AlarmReportForm.FirstOrDefault(s => s.Code == AlarmList[i].Code);
                                        if (nowAlarm == null)
                                        {
                                            AlarmReportFormViewModel newAlarm = new AlarmReportFormViewModel()
                                            {
                                                Code     = AlarmList[i].Code,
                                                Content  = AlarmList[i].Content,
                                                Count    = 1,
                                                TimeSpan = AlarmList[i].End - AlarmList[i].Start
                                            };
                                            AlarmReportForm.Add(newAlarm);
                                        }
                                        else
                                        {
                                            nowAlarm.Count++;
                                        }
                                        WriteToJson(AlarmReportForm, System.IO.Path.Combine(System.Environment.CurrentDirectory, "AlarmReportForm.json"));


                                        #region 写报警记录
                                        string banci = GetBanci();
                                        if (!File.Exists(Path.Combine("D:\\报警记录", "VPP报警记录" + banci + ".csv")))
                                        {
                                            string[] heads = new string[] { "时间", "内容" };
                                            Csvfile.savetocsv(Path.Combine("D:\\报警记录", "VPP报警记录" + banci + ".csv"), heads);
                                        }
                                        string[] conts = new string[] { AlarmList[i].Start.ToString(), AlarmList[i].Content };
                                        Csvfile.savetocsv(Path.Combine("D:\\报警记录", "VPP报警记录" + banci + ".csv"), conts);
                                        #endregion


                                        #region
                                        string Banci = (DateTime.Now.Hour >= 8 && DateTime.Now.Hour < 20) ? "D" : "N";
                                        SZRFUI.Models.Mysql mysql = new Mysql();
                                        if (mysql.Connect())
                                        {
                                            string stm = "insert into TED_WARN_DATA (WORKSTATION,PARTNUM,MACID,LOADID,PETID,TDATE,TTIME,CLASS,WARNID,DETAILID,WARNNUM,FL01,FL02,FL03,FL04,FL05,FL06,FL07,FL08,FL09,FL10,SUPPLIER,WARNVER) value('" + TestStation + "','" + ProgramName + "','" + MachineNumber + "','" + MachineNumber + "','','" + DateTime.Now.ToString("yyyyMMdd") + "','" + DateTime.Now.ToString("HHmmss") + "','" + Banci + "','" + AlarmList[i].Content + "','','1','','','','','','','','','','','" + Supplier + "','" + WARNVER + "')";
                                            mysql.executeQuery(stm);
                                        }
                                        mysql.DisConnect();
                                        #endregion


                                        CurrentAlarm = AlarmList[i].Content;
                                    }
                                }
                                else
                                {
                                    AlarmList[i].End = DateTime.Now;
                                    AddMessage(AlarmList[i].Code + AlarmList[i].Content + "解除");
                                    var nowAlarm = AlarmReportForm.FirstOrDefault(s => s.Code == AlarmList[i].Code);
                                    if (nowAlarm != null)
                                    {
                                        nowAlarm.TimeSpan += AlarmList[i].End - AlarmList[i].Start;
                                        WriteToJson(AlarmReportForm, System.IO.Path.Combine(System.Environment.CurrentDirectory, "AlarmReportForm.json"));
                                    }
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    AddMessage(ex.Message);
                }
                #endregion
                #region 心跳
                await Task.Run(() =>
                {
                    if (DateTime.Now.Minute != oldMinute)
                    {
                        oldMinute = DateTime.Now.Minute;

                        #region 心跳
                        try
                        {
                            int item      = h3u.ReadD("D300");
                            string Status = "";
                            switch (item)
                            {
                            case 1:
                                Status = "R";
                                break;

                            case 2:
                                Status = "H";
                                break;

                            case 3:
                                Status = "A";
                                break;

                            default:
                                break;
                            }
                            if (item > 0 && item < 4)
                            {
                                Mysql mysql = new Mysql();
                                if (mysql.Connect())
                                {
                                    string stm = "insert into TED_HEART_DATA (TestStation,MachineNumber,TestDate,TestTime,AlarmCode,Status,ProgramName,Barcode,SystemDate,SystemTime,SUPPLIER) value('" + TestStation + "','" + MachineNumber + "','" + DateTime.Now.ToString("yyyyMMdd") + "','" + DateTime.Now.ToString("HHmmss") + "','NA','" + Status + "','" + ProgramName + "','NA','" + DateTime.Now.ToString("yyyyMMdd") + "','" + DateTime.Now.ToString("HHmmss") + "','" + Supplier + "')";
                                    mysql.executeQuery(stm);
                                }
                                mysql.DisConnect();
                                AddMessage("上传心跳:" + Status);
                            }
                            else
                            {
                                AddMessage("读取心跳值异常" + item.ToString());
                            }
                        }
                        catch (Exception ex)
                        {
                            AddMessage(ex.Message);
                        }

                        #endregion
                    }
                });

                #endregion
                #region 换班
                if (LastBanci != GetBanci())
                {
                    try
                    {
                        WriteAlarmtoExcel(Path.Combine("D:\\报警记录", "RF报警统计" + LastBanci + ".xlsx"));
                        AlarmReportForm.Clear();
                        WriteToJson(AlarmReportForm, System.IO.Path.Combine(System.Environment.CurrentDirectory, "AlarmReportForm.json"));
                        LastBanci = GetBanci();
                        Inifile.INIWriteValue(iniParameterPath, "Summary", "LastBanci", LastBanci);
                        AddMessage(LastBanci + " 换班数据清零");
                    }
                    catch (Exception ex)
                    {
                        AddMessage(ex.Message);
                    }
                }
                #endregion
                await Task.Delay(200);
            }
        }
        private async void Run()
        {
            string alarmCode, _alarmCode = "-1";

            while (true)
            {
                try
                {
                    D300      = int.Parse(Inifile.INIGetStringValue(iniParameterPath, "Machine", "State", "-1"));
                    alarmCode = Inifile.INIGetStringValue(iniParameterPath, "AlarmCommand", "Code", "-1");
                    if (_alarmCode != alarmCode)
                    {
                        AlarmData alarmData = AlarmList.FirstOrDefault(s => s.Code == alarmCode);
                        if (alarmData != null)
                        {
                            AddMessage($"{alarmData.Code}:{alarmData.Content} 发生");

                            AlarmRecordViewModel newrow = new AlarmRecordViewModel
                            {
                                Time    = DateTime.Now,
                                Code    = alarmData.Code,
                                Content = alarmData.Content
                            };
                            AlarmRecord.Add(newrow);

                            string banci = GetBanci();
                            if (!File.Exists(System.IO.Path.Combine(@"D:\报警记录", "AlarmRecord" + banci + ".csv")))
                            {
                                string[] heads = new string[] { "时间", "报警代码", "报警内容" };
                                Csvfile.savetocsv(System.IO.Path.Combine(@"D:\报警记录", "AlarmRecord" + banci + ".csv"), heads);
                            }
                            string[] conts = new string[] { DateTime.Now.ToString(), alarmData.Code, alarmData.Content };
                            Csvfile.savetocsv(System.IO.Path.Combine(@"D:\报警记录", "AlarmRecord" + banci + ".csv"), conts);
                        }

                        _alarmCode = alarmCode;
                    }
                }
                catch (Exception ex) { AddMessage(ex.Message); }


                #region 换班
                if (LastBanci != GetBanci())
                {
                    try
                    {
                        WriteStatetoExcel(Path.Combine("D:\\报警记录", "时间统计" + LastBanci + ".xlsx"));
                        MachineStateA.Clean();
                        WriteToJson(MachineStateA, System.IO.Path.Combine(System.Environment.CurrentDirectory, "MachineStateA.json"));

                        LastBanci = GetBanci();
                        Inifile.INIWriteValue(iniParameterPath, "Summary", "LastBanci", LastBanci);
                        AddMessage(LastBanci + " 换班数据清零");
                    }
                    catch (Exception ex)
                    {
                        AddMessage(ex.Message);
                    }
                }
                #endregion
                await Task.Delay(100);
            }
        }