private void TextBox_Barcode_TextChanged(object sender, EventArgs e) { if (TextBox_Barcode.Text.Length == 10) { SN_Code = TextBox_Barcode.Text; if (Device_Address == null) { MessageBox.Show("找不到可连接的 Agilent 34401A!"); TextBox_Barcode.Clear(); TextBox_Barcode.Focus(); return; } TextBox_Barcode.Clear(); TextBox_Barcode.Focus(); Current.Text = "0.00"; Result.BackColor = Color.Yellow; Result.Text = "测试中,请等待......"; Result.Update(); Log.Clear(); try { if (measure != null && measure.IsAlive) { try { measure.Abort(); } catch (ThreadAbortException) { Print_Log("终止线程"); } finally { measure.Join(); } } measure = new Thread(Measure_Voltage); measure.Start(); //measure.Join(); } catch (Exception exp) { Log.AppendText(exp.Message); } } if (TextBox_Barcode.Text.Length > 10) { Print_Log("输入字符超出预定长度,已重置!"); TextBox_Barcode.Clear(); } }
private void Current_TextChanged(object sender, EventArgs e) { string Jugged = "Fail"; if (Current.Text.Equals("0.00")) { return; } try { if (float.Parse(Current.Text) <= 3.4 && float.Parse(Current.Text) >= 2.5) { Jugged = "Pass"; } else { Jugged = "Fail"; Current.BackColor = Color.OrangeRed; Result.Text = "Fail"; Result.BackColor = Color.OrangeRed; return; } } catch (Exception) { Current.BackColor = Color.OrangeRed; Result.Text = "Fail"; Result.BackColor = Color.OrangeRed; return; } TextBox_Barcode.Clear(); TextBox_Barcode.Focus(); if (IsConnection() == 0) { Print_Log("已连接数据库!"); } else { Print_Log("重新连接接数据库"); Statu_Init = InitIndexSuivi(); if (Statu_Init != 0) { MessageBox.Show("Dll 初始化失败!"); Current.BackColor = Color.OrangeRed; Result.Text = "Fail"; Result.BackColor = Color.OrangeRed; return; } Print_Log("Dll 初始化成功!"); Statu_Connect = InitConnectionSuivi(); if (Statu_Connect != 0) { Current.BackColor = Color.OrangeRed; Result.Text = "Fail"; Result.BackColor = Color.OrangeRed; MessageBox.Show("Suivi 连接数据库 初始化失败!"); return; } Print_Log("Suivi 连接数据库 初始化成功!"); } byte[] SN = Encoding.ASCII.GetBytes(String.Format("{0}\0", SN_Code)); byte[] Current_Value = Encoding.ASCII.GetBytes(String.Format("{0}\0", Current.Text)); byte[] Juged_Value = Encoding.ASCII.GetBytes(String.Format("{0}\0", Jugged)); try { string msg = String.Format("Barcode ={0},Voltage ={1},Result ={2}", SN_Code, Current.Text, Jugged); string filename = String.Format("log/RTC-Log-{0:yyyy-MM-dd}.txt", System.DateTime.Now); FileStream fs; if (File.Exists(filename)) { fs = new FileStream(filename, FileMode.Append, FileAccess.Write); } else { fs = new FileStream(filename, FileMode.OpenOrCreate, FileAccess.ReadWrite); } StreamWriter sw = new StreamWriter(fs); // 创建写入流 sw.WriteLine(msg); sw.Close(); //关闭文件 Print_Log(String.Format("本地保存数据成功:{0}", msg)); if (UpdateStatut(SN, Current_Value, Juged_Value) == 1) { Print_Log(String.Format("成功更新数据:{0}", msg)); Current.BackColor = Color.LightGreen; Result.Text = "Pass"; Result.BackColor = Color.LightGreen; CloseConnectionSuivi(); return; } else { Print_Log("上传数据库失败!"); } CloseConnectionSuivi(); } catch (Exception exp) { MessageBox.Show(exp.Message); } finally { CloseConnectionSuivi(); } Current.BackColor = Color.OrangeRed; Result.Text = "Fail"; Result.BackColor = Color.OrangeRed; }