ReadTestInfo.cs 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Text.RegularExpressions;
  10. using System.Windows.Forms;
  11. namespace MaterialPrint
  12. {
  13. public partial class ReadTestInfo : Form
  14. {
  15. DataHelper dh = new DataHelper();
  16. public ReadTestInfo()
  17. {
  18. InitializeComponent();
  19. }
  20. Dictionary<string, string> TestItem = new Dictionary<string, string>();
  21. private void ReadTestInfo_Load(object sender, EventArgs e)
  22. {
  23. TestItem.Add("SystemInfo", "系统测试");
  24. TestItem.Add("Keypad", "按键测试");
  25. TestItem.Add("Battery", "电池测试");
  26. TestItem.Add("FrontCameraRec", "前摄像头摄像");
  27. TestItem.Add("FrontCamera", "前摄像头拍照");
  28. TestItem.Add("Brightness", "背光测试");
  29. TestItem.Add("Display", "显示屏测试");
  30. TestItem.Add("ExtDisplay", "外接显示器");
  31. TestItem.Add("RemovableDevice", "存储设备");
  32. TestItem.Add("WiFi", "WIFI测试");
  33. TestItem.Add("Bluetooth", "BT测试");
  34. TestItem.Add("Speaker", "扬声器和麦克风测试");
  35. TestItem.Add("Headset", "耳机和麦克风测试");
  36. TestItem.Add("Touchpad", "触摸板");
  37. TestItem.Add("Keyboard", "键盘测试");
  38. TestItem.Add("SerialPort", "COM接口");
  39. TestItem.Add("RearCamera", "后摄像头拍照");
  40. TestItem.Add("RearCameraRec", "后摄像头摄像");
  41. TestItem.Add("Touch", "触摸屏测试");
  42. TestItem.Add("Pen", "触控笔测试");
  43. TestItem.Add("LAN", "RJ45接口");
  44. TestItem.Add("SIM", "3G/4G测试");
  45. TestItem.Add("Accelerometer", "G Sensor 重力感应测试");
  46. TestItem.Add("GPS", "GPS测试");
  47. TestItem.Add("Gyrometer", "陀螺仪测试");
  48. TestItem.Add("Light", "光感测试");
  49. TestItem.Add("Compass", "指南针");
  50. }
  51. public void GetWriteInfo(string FilePath)
  52. {
  53. Dictionary<string, string> Dic = new Dictionary<string, string>();
  54. StreamReader sr = new StreamReader(FilePath);
  55. DataTable dt = new DataTable();
  56. dt.Columns.Add("itemname");
  57. dt.Columns.Add("testresult");
  58. while (!sr.EndOfStream)
  59. {
  60. string str = sr.ReadLine();
  61. 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;
  62. if (Value != "")
  63. {
  64. if (Dic.ContainsKey(Value.Split('\t')[2]))
  65. Dic.Remove(Value.Split('\t')[2]);
  66. Dic.Add(Value.Split('\t')[2], Value);
  67. }
  68. }
  69. ResultView.DataSource = dt;
  70. foreach (var item in Dic)
  71. {
  72. string time = item.Value.Split('\t')[0];
  73. string result = item.Value.Split('\t')[1].Contains("PASS") ? "PASS" : "FAIL";
  74. string itemname = TestItem.ContainsKey(item.Key) ? TestItem[item.Key] : item.Key;
  75. DataRow dr = dt.NewRow();
  76. dr["itemname"] = itemname;
  77. dr["testresult"] = item.Value;
  78. dt.Rows.Add(dr);
  79. string sql = "insert into steptestdetail (std_id,std_sn,std_date,std_class,std_testresult,std_itemname)values";
  80. sql += "(steptestdetail_seq.nextval,'" + SN.Text + "',to_timestamp('" + item.Value.Split('\t')[0] + "',";
  81. sql += "'yyyy-mm-dd hh24:mi:ss.ff6'),'" + item.Key + "','" + result + "','" + itemname + "')";
  82. dh.ExecuteSql(sql, "insert");
  83. }
  84. MessageBox.Show("测试记录保存成功");
  85. }
  86. private void SN_KeyDown(object sender, KeyEventArgs e)
  87. {
  88. if (e.KeyData == Keys.Enter)
  89. {
  90. if (dh.CheckExist("makeserial", "ms_sncode='" + SN.Text + "' or ms_firstsn='" + SN.Text + "'"))
  91. {
  92. GetWriteInfo(@"C:\TEST_TOOL\SFTClassicLog.txt");
  93. }
  94. else
  95. {
  96. MessageBox.Show("序列号" + SN.Text + "不存在");
  97. }
  98. }
  99. }
  100. private void ResultView_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
  101. {
  102. if (e.ColumnIndex >= 0)
  103. {
  104. if (ResultView.Columns[e.ColumnIndex].Name == "testresult")
  105. {
  106. if (e.RowIndex >= 0)
  107. {
  108. if (ResultView.Rows[e.RowIndex].Cells["testresult"].Value != null && (ResultView.Rows[e.RowIndex].Cells["testresult"].Value.ToString().Contains("PASS")))
  109. {
  110. e.Graphics.FillRectangle(Brushes.ForestGreen, e.CellBounds);
  111. Rectangle border = e.CellBounds;
  112. border.Width -= 1;
  113. e.Graphics.DrawRectangle(Pens.Black, border);
  114. e.PaintContent(e.CellBounds);
  115. e.Handled = true;
  116. }
  117. else
  118. {
  119. e.Graphics.FillRectangle(Brushes.OrangeRed, e.CellBounds);
  120. Rectangle border = e.CellBounds;
  121. border.Width -= 1;
  122. e.Graphics.DrawRectangle(Pens.Black, border);
  123. e.PaintContent(e.CellBounds);
  124. e.Handled = true;
  125. }
  126. }
  127. }
  128. }
  129. }
  130. }
  131. }