BaseModel.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.IO;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Windows.Forms;
  8. using Tps_LQ_Transmitter.com;
  9. namespace Tps_LQ_Transmitter.models
  10. {
  11. /// <summary>
  12. /// 测试模板,对测试模板的基础类别
  13. /// </summary>
  14. public class BaseModel
  15. {
  16. /// <summary>
  17. /// 测试模板名称,测试指标配置表中的模板名称源自这个参数
  18. /// </summary>
  19. public string TemplateName { get; protected set; }
  20. public bool IsRuning { get; set; }
  21. public bool IsPassed { get; protected set; }
  22. public DateTime FinishedTime { get; protected set; }
  23. /// <summary>
  24. /// 这个测试项对应的显示界面,也可能是一个界面有多个测试项共用,取决于顶层的控制
  25. /// </summary>
  26. public UserControl UC { get; set; }
  27. /// <summary>
  28. /// 主程序
  29. /// </summary>
  30. public MainTps tps { get; set; }
  31. public virtual bool Run(TestNode parameters)
  32. {
  33. return false;
  34. }
  35. /// <summary>
  36. /// 开始测试
  37. /// </summary>
  38. /// <returns></returns>
  39. public virtual bool Start(TestNode parameters)
  40. {
  41. IsRuning = true;
  42. IsPassed = false;
  43. bool ok = Run(parameters);
  44. IsRuning = false;
  45. FinishedTime = DateTime.Now;
  46. return ok;
  47. // return true;
  48. }
  49. /// <summary>
  50. /// 停止测试
  51. /// </summary>
  52. /// <returns></returns>
  53. public virtual bool Stop()
  54. {
  55. IsRuning = false;
  56. return true;
  57. }
  58. public event DltShowMsg MessageEvent;
  59. protected void ShowMessage(MsgType msgType, string msg)
  60. {
  61. if (MessageEvent != null)
  62. {
  63. MessageEvent(msgType, msg);
  64. }
  65. }
  66. public void OpenExcel(string sheetname, out Spire.Xls.Workbook workbook, out Spire.Xls.Worksheet sheet)
  67. {
  68. Spire.Xls.Worksheet sheet1 = null;
  69. string TestFilePath = "F:";
  70. string ModelFile = "F:/发射机/发射机模板/"+ tps.TestProject + "模板.xlsx";
  71. string subPath = "F:/发射机/发射机测试数据/"+ tps.TestProject +"/";
  72. if (false == System.IO.Directory.Exists(subPath))
  73. {
  74. System.IO.Directory.CreateDirectory(subPath);
  75. }
  76. workbook = new Spire.Xls.Workbook();
  77. string FileName = subPath + tps.Serial + ".xlsx";
  78. if (File.Exists(FileName))
  79. {
  80. workbook.LoadFromFile(FileName);
  81. sheet1 = workbook.Worksheets[sheetname];
  82. }
  83. else if (File.Exists(ModelFile))
  84. {
  85. workbook.LoadFromFile(ModelFile);
  86. sheet1 = workbook.Worksheets["测试信息"];
  87. sheet1.Range["A2"].Value2 = tps.Serial;//序列号
  88. sheet1.Range["B2"].Value2 = tps.Tester;//检验员
  89. sheet1.Range["C2"].Value2 = DateTime.Now.Date.ToString();//日期
  90. sheet1.Range["D2"].Value2 = tps.Temperature;//温度
  91. sheet1.Range["E2"].Value2 = tps.Humidity;//湿度
  92. sheet1 = workbook.Worksheets[sheetname];
  93. }
  94. if (!File.Exists(ModelFile))
  95. {
  96. sheet1 = null;
  97. }
  98. sheet = sheet1;
  99. }
  100. public void WriteExcelData(Spire.Xls.Worksheet sheet, int row, int channel, string name, string lower, string upper, string val, string result)
  101. {
  102. int column = (channel - 1) * 6;
  103. sheet.Range[row + 2, 1 + column].Value2 = name;
  104. sheet.Range[row + 2, 2 + column].Value2 = lower;
  105. sheet.Range[row + 2, 3 + column].Value2 = upper;
  106. sheet.Range[row + 2, 4 + column].Value = val;
  107. sheet.Range[row + 2, 5 + column].Value2 = result;
  108. }
  109. public void SaveExcel(Spire.Xls.Workbook workbook)
  110. {
  111. string subPath = "F:/发射机/发射机测试数据/" + tps.TestProject + "/";
  112. string FileName = subPath + tps.Serial + ".xlsx";
  113. workbook.CalculateAllValue();
  114. workbook.SaveToFile(FileName);
  115. }
  116. public class DataType
  117. {
  118. /// <summary>
  119. /// 测试名称
  120. /// </summary>
  121. public string Test_name { set; get; }
  122. /// <summary>
  123. /// 指标下限
  124. /// </summary>
  125. public double Lower { set; get; }
  126. /// <summary>
  127. /// 指标上限
  128. /// </summary>
  129. public double Upper { set; get; }
  130. /// <summary>
  131. /// 测试值
  132. /// </summary>
  133. public double TestVal { set; get; }
  134. /// <summary>
  135. /// 判断结果
  136. /// </summary>
  137. public string Result { set; get; }
  138. }
  139. }
  140. }