ReadTestInfo.cs 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Diagnostics;
  6. using System.Drawing;
  7. using System.IO;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Text.RegularExpressions;
  11. using System.Windows.Forms;
  12. namespace MaterialPrint
  13. {
  14. public partial class ReadTestInfo : Form
  15. {
  16. DataHelper dh = new DataHelper();
  17. string ms_id = "";
  18. public ReadTestInfo()
  19. {
  20. InitializeComponent();
  21. }
  22. Dictionary<string, string> TestItem = new Dictionary<string, string>();
  23. private void ReadTestInfo_Load(object sender, EventArgs e)
  24. {
  25. TestItem.Add("SystemInfo", "系统测试");
  26. TestItem.Add("Keypad", "按键测试");
  27. TestItem.Add("Battery", "电池测试");
  28. TestItem.Add("FrontCameraRec", "前摄像头摄像");
  29. TestItem.Add("FrontCamera", "前摄像头拍照");
  30. TestItem.Add("Brightness", "背光测试");
  31. TestItem.Add("Display", "显示屏测试");
  32. TestItem.Add("ExtDisplay", "外接显示器");
  33. TestItem.Add("RemovableDevice", "存储设备");
  34. TestItem.Add("WiFi", "WIFI测试");
  35. TestItem.Add("Bluetooth", "BT测试");
  36. TestItem.Add("Speaker", "扬声器和麦克风测试");
  37. TestItem.Add("Headset", "耳机和麦克风测试");
  38. TestItem.Add("Touchpad", "触摸板");
  39. TestItem.Add("Keyboard", "键盘测试");
  40. TestItem.Add("SerialPort", "COM接口");
  41. TestItem.Add("RearCamera", "后摄像头拍照");
  42. TestItem.Add("RearCameraRec", "后摄像头摄像");
  43. TestItem.Add("Touch", "触摸屏测试");
  44. TestItem.Add("Pen", "触控笔测试");
  45. TestItem.Add("LAN", "RJ45接口");
  46. TestItem.Add("SIM", "3G/4G测试");
  47. TestItem.Add("Accelerometer", "G Sensor 重力感应测试");
  48. TestItem.Add("GPS", "GPS测试");
  49. TestItem.Add("Gyrometer", "陀螺仪测试");
  50. TestItem.Add("Light", "光感测试");
  51. TestItem.Add("Compass", "指南针");
  52. }
  53. public string exec(string exePath, string parameters)
  54. {
  55. Process process = new Process();
  56. process.StartInfo.FileName = exePath;
  57. process.StartInfo.UseShellExecute = false;
  58. process.StartInfo.RedirectStandardInput = true;
  59. process.StartInfo.RedirectStandardOutput = true;
  60. process.StartInfo.CreateNoWindow = true;
  61. process.StartInfo.RedirectStandardError = true;//重定向标准错误输出
  62. process.Start();
  63. process.StandardInput.WriteLine(parameters);
  64. process.StandardInput.Close(); //运行完毕关闭控制台输入
  65. string add = process.StandardOutput.ReadToEnd(); //读取输出的信息
  66. Console.WriteLine(add);
  67. process.Close();
  68. return add;
  69. }
  70. public void GetWriteInfo(string FilePath)
  71. {
  72. Dictionary<string, string> Dic = new Dictionary<string, string>();
  73. StreamReader sr = new StreamReader(FilePath);
  74. DataTable dt = new DataTable();
  75. dt.Columns.Add("itemname");
  76. dt.Columns.Add("testresult");
  77. dt.Columns.Add("SN");
  78. dt.Columns.Add("BIOS");
  79. dt.Columns.Add("PK");
  80. while (!sr.EndOfStream)
  81. {
  82. string str = sr.ReadLine();
  83. string Value = Regex.Match(str, @"\d{4}/\d{2}/\d{2} \d{2}:\d{2}:\d{2}.\d{3}\t\[Info] - (PASS|FAIL)\t\S+").Value;
  84. if (Value != "")
  85. {
  86. if (Dic.ContainsKey(Value.Split('\t')[2]))
  87. Dic.Remove(Value.Split('\t')[2]);
  88. Dic.Add(Value.Split('\t')[2], Value);
  89. }
  90. }
  91. string SerialNumber = Regex.Match(exec("cmd.exe", " wmic os get SerialNumber /value"), @"SerialNumber=\S+").Value.Replace("SerialNumber=", "");
  92. string BIOS = Regex.Match(exec("cmd.exe", " wmic bios get SMBIOSBIOSVersion / value"), @"SMBIOSBIOSVersion=\S+").Value.Replace("SMBIOSBIOSVersion=", "");
  93. string PK = Regex.Match(exec("CheckupKey.exe", ""), @"The PKID is: \S+").Value.Replace("The PKID is: ", "");
  94. //判断KEY是否被使用过
  95. string keysn = dh.getFieldDataByCondition("makeserial", "ms_sncode", "ms_id<>" + ms_id + " and ms_key='" + PK + "'").ToString();
  96. if (SerialNumber != SN.Text)
  97. {
  98. MessageBox.Show("扫描序列号:" + SN.Text + "和本机读取序列号:" + SerialNumber + "不一致");
  99. return;
  100. }
  101. if (keysn != "")
  102. {
  103. MessageBox.Show("KEY:" + PK + "已被序列号:" + keysn + "使用");
  104. return;
  105. }
  106. ResultView.DataSource = dt;
  107. foreach (var item in Dic)
  108. {
  109. string time = item.Value.Split('\t')[0];
  110. string result = item.Value.Split('\t')[1].Contains("PASS") ? "PASS" : "FAIL";
  111. string itemname = TestItem.ContainsKey(item.Key) ? TestItem[item.Key] : item.Key;
  112. DataRow dr = dt.NewRow();
  113. dr["itemname"] = itemname;
  114. dr["testresult"] = item.Value;
  115. dr["SN"] = SerialNumber;
  116. dr["BIOS"] = BIOS;
  117. dr["PK"] = PK;
  118. dt.Rows.Add(dr);
  119. string sql = "insert into steptestdetail (std_id,std_sn,std_date,std_class,std_testresult,std_itemname)values";
  120. sql += "(steptestdetail_seq.nextval,'" + SN.Text + "',to_timestamp('" + item.Value.Split('\t')[0] + "',";
  121. sql += "'yyyy-mm-dd hh24:mi:ss.ff6'),'" + item.Key + "','" + result + "','" + itemname + "')";
  122. dh.ExecuteSql(sql, "insert");
  123. }
  124. dh.ExecuteSql("update makeserial set ms_key='" + PK + "' where ms_id=" + ms_id, "update");
  125. MessageBox.Show("测试记录保存成功");
  126. }
  127. private void SN_KeyDown(object sender, KeyEventArgs e)
  128. {
  129. if (e.KeyData == Keys.Enter)
  130. {
  131. ms_id = dh.getFieldDataByCondition("makeserial", "max(ms_id)", "ms_sncode='" + SN.Text + "' or ms_firstsn='" + SN.Text + "'").ToString();
  132. if (ms_id != "")
  133. {
  134. GetWriteInfo(@"C:\TEST_TOOL\SFTClassicLog.txt");
  135. }
  136. else
  137. {
  138. MessageBox.Show("序列号" + SN.Text + "不存在");
  139. }
  140. }
  141. }
  142. private void ResultView_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
  143. {
  144. if (e.ColumnIndex >= 0)
  145. {
  146. if (ResultView.Columns[e.ColumnIndex].Name == "testresult")
  147. {
  148. if (e.RowIndex >= 0)
  149. {
  150. if (ResultView.Rows[e.RowIndex].Cells["testresult"].Value != null && (ResultView.Rows[e.RowIndex].Cells["testresult"].Value.ToString().Contains("PASS")))
  151. {
  152. e.Graphics.FillRectangle(Brushes.ForestGreen, e.CellBounds);
  153. Rectangle border = e.CellBounds;
  154. border.Width -= 1;
  155. e.Graphics.DrawRectangle(Pens.Black, border);
  156. e.PaintContent(e.CellBounds);
  157. e.Handled = true;
  158. }
  159. else
  160. {
  161. e.Graphics.FillRectangle(Brushes.OrangeRed, e.CellBounds);
  162. Rectangle border = e.CellBounds;
  163. border.Width -= 1;
  164. e.Graphics.DrawRectangle(Pens.Black, border);
  165. e.PaintContent(e.CellBounds);
  166. e.Handled = true;
  167. }
  168. }
  169. }
  170. }
  171. }
  172. }
  173. }