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 { //扫码失败 } }
private async void Run() { string MODE = "1"; int CardStatus = 1, cardret = 1; while (true) { await Task.Delay(500); #region 刷卡 await Task.Run(() => { try { byte[] buf = new byte[256]; //用来存储卡信息的buff byte[] snr = 读写器530SDK.CPublic.CharToByte("FF FF FF FF FF FF"); //应该是一种读码格式,照抄即可。 if (IntPtr.Zero == reader.GetHComm()) { string COM = Inifile.INIGetStringValue(iniParameterPath, "读卡器", "COM", "COM19").Replace("COM", ""); reader.OpenComm(int.Parse(COM), 9600); MODE = Inifile.INIGetStringValue(iniParameterPath, "读卡器", "MODE", "3"); } //刷卡;若刷到卡返回0,没刷到回1。 CardStatus = reader.MF_Read(0, byte.Parse(MODE), 0, 1, ref snr[0], ref buf[0]); //采用上升沿信号,防止卡放在读卡机上,重复执行查询动作。寄卡放一次,才查询一次,要再查询,需要重新刷卡。 if (cardret != CardStatus) { cardret = CardStatus; if (CardStatus == 0)//刷到卡了 { string strTmp = ""; //测试发现,卡返回的是16个HEX(十六进制)数,放在byte[]数组内,需要用一下方法转成字符串格式。 for (int i = 0; i < 16; i++) { strTmp += string.Format("{0:X2} ", buf[i]); } //删除转换后,字符串内的空格。这些HEX字符并不是员工编号字符的编码,需要用读到的字符串在数据库里查找, //在记录里再匹配员工信息和权限 string barcode = strTmp.Replace(" ", ""); AddMessage("刷卡 " + barcode); BARCODE = barcode; SXJLibrary.Oracle oraDB = new SXJLibrary.Oracle("qddb04.eavarytech.com", "mesdb04", "ictdata", "ictdata*168"); if (oraDB.isConnect()) { string stm = string.Format("SELECT * FROM CAP_TABLE WHERE BARCODE = '{0}'", barcode); DataSet ds = oraDB.executeQuery(stm); DataTable dt = ds.Tables[0]; if (dt.Rows.Count > 0)//查询到数据条目大于0,即查到了 { //取查到的第一行记录,一般只有1行。如果有多行,也只取第一行。 DataRow dr = dt.Rows[0]; //筛选一下数据,如果我们需要的“工号”、“姓名”和“权限”对应的栏位为空,则数据不合格。 if (dr["OPERATORID"] != DBNull.Value && dr["DATA0"] != DBNull.Value && dr["RESULT"] != DBNull.Value && dr["DATA1"] != DBNull.Value) { //打印出匹配到的结果,并返回给下位机。 AddMessage("工号 " + (string)dr["OPERATORID"] + " 姓名 " + (string)dr["DATA0"] + " 权限 " + (string)dr["RESULT"] + " 料号 " + (string)dr["DATA1"]); stm = string.Format("UPDATE CFT_DATA SET BARCODE = '{0}',TRESULT = '{1}',OPERTOR = '{2}',TESTDATE = '{3}',TESTTIME = '{4}', CFT01 = '{6}' WHERE MNO = '{5}'", barcode, (string)dr["RESULT"], (string)dr["OPERATORID"], DateTime.Now.ToString("yyyyMMdd"), DateTime.Now.ToString("HHmmss"), MNO, (string)dr["DATA1"]); int updaterst = oraDB.executeNonQuery(stm); if (updaterst > 0) { AddMessage("更新刷卡机台" + (string)dr["PARTNUM"] + " " + updaterst.ToString()); oraDB.executeNonQuery("COMMIT"); } else { stm = string.Format("INSERT INTO CFT_DATA (BARCODE,TRESULT,OPERTOR,TESTDATE,TESTTIME,CFT01,MNO) VALUES ('{0}','{1}','{2}','{3}','{4}','{5}','{6}')", barcode, (string)dr["RESULT"], (string)dr["OPERATORID"], DateTime.Now.ToString("yyyyMMdd"), DateTime.Now.ToString("HHmmss"), (string)dr["DATA1"], MNO); int insertrst = oraDB.executeNonQuery(stm); AddMessage("插入刷卡机台" + (string)dr["PARTNUM"] + " " + insertrst.ToString()); oraDB.executeNonQuery("COMMIT"); } } else { AddMessage("数据库记录信息不完整"); } } else { AddMessage("未查询到卡信息"); } } oraDB.disconnect(); } } } catch (Exception ex) { reader.CloseComm(); AddMessage(ex.Message); } }); #endregion } }
private async void EntryInformationCommandExecute() { if (DATA0 != "") { if (OPERATORID != "") { if (PARTNUMItems.Count > 0) { if (BARCODE != "") { string Rst = RESULT ? "PASS" : "FAIL"; string data1 = ""; foreach (var item in PARTNUMItems) { data1 += item + ","; } data1 = data1.Substring(0, data1.Length - 1); await Task.Run(() => { try { SXJLibrary.Oracle oraDB = new SXJLibrary.Oracle("qddb04.eavarytech.com", "mesdb04", "ictdata", "ictdata*168"); if (oraDB.isConnect()) { string stm = string.Format("UPDATE CAP_TABLE SET RESULT = '{1}',OPERATORID = '{2}',SDATE = '{3}',STIME = '{4}',DATA0 = '{5}',DATA1 = '{6}' WHERE BARCODE = '{0}'" , BARCODE, Rst, OPERATORID, DateTime.Now.ToString("yyyyMMdd"), DateTime.Now.ToString("HHmmss"), DATA0, data1); int updaterst = oraDB.executeNonQuery(stm); if (updaterst > 0) { AddMessage("更新卡信息成功" + updaterst.ToString()); oraDB.executeNonQuery("COMMIT"); DATA0 = ""; OPERATORID = ""; BARCODE = ""; RESULT = true; } else { stm = string.Format("INSERT INTO CAP_TABLE (BARCODE,RESULT,OPERATORID,SDATE,STIME,DATA0,DATA1) VALUES ('{0}','{1}','{2}','{3}','{4}','{5}','{6}')" , BARCODE, Rst, OPERATORID, DateTime.Now.ToString("yyyyMMdd"), DateTime.Now.ToString("HHmmss"), DATA0, data1); int insertrst = oraDB.executeNonQuery(stm); if (insertrst > 0) { AddMessage("录入卡信息成功" + insertrst.ToString()); oraDB.executeNonQuery("COMMIT"); DATA0 = ""; OPERATORID = ""; BARCODE = ""; RESULT = true; } else { AddMessage("录入卡信息失败" + insertrst.ToString()); } } } else { AddMessage("数据库连接失败"); } oraDB.isConnect(); } catch (Exception ex) { AddMessage(ex.Message); } }); } else { AddMessage("条码为空"); } } else { AddMessage("料号为空"); } } else { AddMessage("工号为空"); } } else { AddMessage("姓名为空"); } }
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, "BigData", "MACID", "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}' ORDER BY CDATE DESC,CTIME DESC", (string)dt.Rows[0]["BARCODE"]); DataSet s1 = oraDB.executeQuery(stm); DataTable dt1 = s1.Tables[0]; if (dt1.Rows.Count > 0) { try { datestr = (string)dt1.Rows[0]["CDATE"]; timestr = (string)dt1.Rows[0]["CTIME"]; if (datestr.Length == 8 && (timestr.Length == 5 || timestr.Length == 6)) { if (timestr.Length == 5) { timestr = "0" + timestr; } 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)); updatetime = Convert.ToDateTime(datetimestr); if ((DateTime.Now - updatetime).TotalDays <= nGItemLimit) { //插入样本记录 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); await Task.Run(() => { oraDB.executeNonQuery(stm); }); string filepath = "D:\\样本记录\\样本记录" + 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); ModelPrint("插入样本记录 " + (string)dt.Rows[0]["BARCODE"] + " " + updatetime.ToString()); } else { ModelPrint((string)dt.Rows[0]["BARCODE"] + "样本时间" + updatetime.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"; } } } //回复样本结果 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) { ModelPrint(resultString); 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); } }