private void TimersTimer_Elapsed(object sender, ElapsedEventArgs e) { try { GetWindow g = new GetWindow("問診"); // vb.NET里面的vbCr & vbLf 在c# 是\r\n, chr(13) chr(10) // 第二個是身分證字號 //tempID = g.Key.Split('\n')[2]; tempID = g.Key; //string[] ss = tempID.Split('\n'); } catch { tempID = string.Empty; } if (StrID == string.Empty) { if (tempID == string.Empty) { // condition 1, strID = "" => "" do nothing return; } else { // 檢單查核, 如果分解後數目小於8, 應該就不是正確的 // 20190930似乎有效 if (tempID.Split(' ').Length < 8) { //'MessageBox.Show("抓到了") return; } // condition 2, strID = "" => something A record A, starttime // 要做很多事情, 分解 // 20190930 有些"問診畫面"的狀態,文字是不一樣的,這樣的話會有錯誤 StrID = tempID; Com_clDataContext dc = new Com_clDataContext(); string[] s = strID.Split(' '); //0 SDATE, 1 VIST, 2 RMNO, 4 Nr, 7 uid, 8 cname if (s[7].Substring(1, 10) == "A000000000") { strID = string.Empty; StrUID = string.Empty; return; } StrUID = s[7].Substring(1, 10); // Propertychanged dc.sp_insert_access(DateTime.Parse(s[0]), s[1], byte.Parse(s[2]), byte.Parse(s[4]), strUID, s[8], true); } } else { if (StrID == tempID) { // condition 3, strID = something A => something A do nothing return; } else if (tempID == string.Empty) { //' condition 4, strID = something A => "" record endtime, write into database //' 做的事情也不少 Com_clDataContext dc = new Com_clDataContext(); string[] s = strID.Split(' '); //'0 SDATE, 1 VIST, 2 RMNO, 4 Nr, 7 uid, 8 cname dc.sp_insert_access(DateTime.Parse(s[0]), s[1], byte.Parse(s[2]), byte.Parse(s[4]), strUID, s[8], false); StrID = tempID; StrUID = string.Empty; // Propertychanged } else { //' condition 5, strID = something A => something B I don't know if this is possible //' 有可能嗎? 我不知道 //' 20191001 答案揭曉了,有可能,因為THESIS在畫form時會有A000000000臨時的資料,然後再讀資料庫蓋上,就會出現something A => something B的情況 //' 我採用檢核若A000000000的情形就不要寫入的方式處理 //' 檢單查核, 如果分解後數目小於8, 應該就不是正確的 //' MessageBox.Show("抓到了! " + vbCrLf + strID + "=>" + tempID) if (tempID.Split(' ').Length < 8) { return; } } } }