ReadTestInfo.cs 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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 GetAgingInfo(string FilePath)
  71. {
  72. //C:\Users\callm\Desktop\iNet
  73. FilePath = @"C:\Users\callm\Desktop\iNet\RunIn.Log";
  74. StreamReader sr = new StreamReader(FilePath);
  75. string StartTime = "";
  76. string EndTime = "";
  77. while (!sr.EndOfStream)
  78. {
  79. string str = sr.ReadLine();
  80. if (str.Contains("Video Start"))
  81. {
  82. StartTime = Regex.Match(str, @"\d{2}/\d{2}/\d{4} \d{2}:\d{2}:\d{2}").Value;
  83. }
  84. if (str.Contains("Video PASS"))
  85. {
  86. EndTime = Regex.Match(str, @"\d{2}/\d{2}/\d{4} \d{2}:\d{2}:\d{2}").Value;
  87. }
  88. }
  89. dh.ExecuteSql("update makeserial set ms_starttime=to_date('" + StartTime + "','dd/mm/yyyy hh24:mi:ss'),ms_endtime=to_date('" + EndTime + "','dd/mm/yyyy hh24:mi:ss') where ms_id='" + ms_id + "'", "select");
  90. }
  91. public void GetWriteInfo(string FilePath)
  92. {
  93. Dictionary<string, string> Dic = new Dictionary<string, string>();
  94. StreamReader sr = new StreamReader(FilePath);
  95. DataTable dt = new DataTable();
  96. dt.Columns.Add("itemname");
  97. dt.Columns.Add("testresult");
  98. dt.Columns.Add("SN");
  99. dt.Columns.Add("BIOS");
  100. dt.Columns.Add("PK");
  101. while (!sr.EndOfStream)
  102. {
  103. string str = sr.ReadLine();
  104. 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;
  105. if (Value != "")
  106. {
  107. if (Dic.ContainsKey(Value.Split('\t')[2]))
  108. Dic.Remove(Value.Split('\t')[2]);
  109. Dic.Add(Value.Split('\t')[2], Value);
  110. }
  111. }
  112. string SerialNumber = Regex.Match(exec("cmd.exe", " wmic os get SerialNumber /value"), @"SerialNumber=\S+").Value.Replace("SerialNumber=", "");
  113. string BIOS = Regex.Match(exec("cmd.exe", " wmic bios get SMBIOSBIOSVersion / value"), @"SMBIOSBIOSVersion=\S+").Value.Replace("SMBIOSBIOSVersion=", "");
  114. string PK = Regex.Match(exec("CheckupKey.exe", ""), @"The PKID is: \S+").Value.Replace("The PKID is: ", "");
  115. //判断KEY是否被使用过
  116. string keysn = dh.getFieldDataByCondition("makeserial", "ms_sncode", "ms_id<>" + ms_id + " and ms_key='" + PK + "'").ToString();
  117. bool TestOK = true;
  118. //if (SerialNumber != SN.Text)
  119. //{
  120. // MessageBox.Show("扫描序列号:" + SN.Text + "和本机读取序列号:" + SerialNumber + "不一致");
  121. // TestOK = false;
  122. //}
  123. if (keysn != "")
  124. {
  125. MessageBox.Show("KEY:" + PK + "已被序列号:" + keysn + "使用");
  126. TestOK = false;
  127. }
  128. ResultView.DataSource = dt;
  129. foreach (var item in Dic)
  130. {
  131. string time = item.Value.Split('\t')[0];
  132. string result = item.Value.Split('\t')[1].Contains("PASS") ? "PASS" : "FAIL";
  133. string itemname = TestItem.ContainsKey(item.Key) ? TestItem[item.Key] : item.Key;
  134. DataRow dr = dt.NewRow();
  135. dr["itemname"] = itemname;
  136. dr["testresult"] = item.Value;
  137. dr["SN"] = SerialNumber;
  138. dr["BIOS"] = BIOS;
  139. dr["PK"] = PK;
  140. dt.Rows.Add(dr);
  141. string sql = "insert into steptestdetail (std_id,std_sn,std_date,std_class,std_testresult,std_itemname)values";
  142. sql += "(steptestdetail_seq.nextval,'" + SN.Text + "',to_timestamp('" + item.Value.Split('\t')[0] + "',";
  143. sql += "'yyyy-mm-dd hh24:mi:ss.ff6'),'" + item.Key + "','" + result + "','" + itemname + "')";
  144. //测试OK才上传数据
  145. if (TestOK)
  146. dh.ExecuteSql(sql, "insert");
  147. }
  148. if (TestOK)
  149. {
  150. dh.ExecuteSql("update makeserial set ms_key='" + PK + "' where ms_id=" + ms_id, "update");
  151. MessageBox.Show("测试记录保存成功");
  152. }
  153. }
  154. private void SN_KeyDown(object sender, KeyEventArgs e)
  155. {
  156. if (e.KeyData == Keys.Enter)
  157. {
  158. ms_id = dh.getFieldDataByCondition("makeserial", "max(ms_id)", "ms_sncode='" + SN.Text + "' or ms_firstsn='" + SN.Text + "'").ToString();
  159. if (ms_id != "")
  160. {
  161. GetAgingInfo("");
  162. //GetWriteInfo(@"C:\TEST_TOOL\SFTClassicLog.txt");
  163. }
  164. else
  165. {
  166. MessageBox.Show("序列号" + SN.Text + "不存在");
  167. }
  168. }
  169. }
  170. private void ResultView_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
  171. {
  172. if (e.ColumnIndex >= 0)
  173. {
  174. if (ResultView.Columns[e.ColumnIndex].Name == "testresult")
  175. {
  176. if (e.RowIndex >= 0)
  177. {
  178. if (ResultView.Rows[e.RowIndex].Cells["testresult"].Value != null && (ResultView.Rows[e.RowIndex].Cells["testresult"].Value.ToString().Contains("PASS")))
  179. {
  180. e.Graphics.FillRectangle(Brushes.ForestGreen, e.CellBounds);
  181. Rectangle border = e.CellBounds;
  182. border.Width -= 1;
  183. e.Graphics.DrawRectangle(Pens.Black, border);
  184. e.PaintContent(e.CellBounds);
  185. e.Handled = true;
  186. }
  187. else
  188. {
  189. e.Graphics.FillRectangle(Brushes.OrangeRed, e.CellBounds);
  190. Rectangle border = e.CellBounds;
  191. border.Width -= 1;
  192. e.Graphics.DrawRectangle(Pens.Black, border);
  193. e.PaintContent(e.CellBounds);
  194. e.Handled = true;
  195. }
  196. }
  197. }
  198. }
  199. }
  200. }
  201. }