123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.IO;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using Tps_LQ_Transmitter.com;
- namespace Tps_LQ_Transmitter.models
- {
- /// <summary>
- /// 测试模板,对测试模板的基础类别
- /// </summary>
- public class BaseModel
- {
- /// <summary>
- /// 测试模板名称,测试指标配置表中的模板名称源自这个参数
- /// </summary>
- public string TemplateName { get; protected set; }
- public bool IsRuning { get; set; }
- public bool IsPassed { get; protected set; }
- public DateTime FinishedTime { get; protected set; }
- /// <summary>
- /// 这个测试项对应的显示界面,也可能是一个界面有多个测试项共用,取决于顶层的控制
- /// </summary>
- public UserControl UC { get; set; }
- /// <summary>
- /// 主程序
- /// </summary>
- public MainTps tps { get; set; }
- public virtual bool Run(TestNode parameters)
- {
- return false;
- }
- /// <summary>
- /// 开始测试
- /// </summary>
- /// <returns></returns>
- public virtual bool Start(TestNode parameters)
- {
- IsRuning = true;
- IsPassed = false;
- bool ok = Run(parameters);
- IsRuning = false;
- FinishedTime = DateTime.Now;
- return ok;
- // return true;
- }
- /// <summary>
- /// 停止测试
- /// </summary>
- /// <returns></returns>
- public virtual bool Stop()
- {
- IsRuning = false;
- return true;
- }
- public event DltShowMsg MessageEvent;
- protected void ShowMessage(MsgType msgType, string msg)
- {
- if (MessageEvent != null)
- {
- MessageEvent(msgType, msg);
- }
- }
- public void OpenExcel(string sheetname, out Spire.Xls.Workbook workbook, out Spire.Xls.Worksheet sheet)
- {
- Spire.Xls.Worksheet sheet1 = null;
- string TestFilePath = "F:";
- string ModelFile = "F:/发射机/发射机模板/"+ tps.TestProject + "模板.xlsx";
- string subPath = "F:/发射机/发射机测试数据/"+ tps.TestProject +"/";
- if (false == System.IO.Directory.Exists(subPath))
- {
- System.IO.Directory.CreateDirectory(subPath);
- }
- workbook = new Spire.Xls.Workbook();
- string FileName = subPath + tps.Serial + ".xlsx";
- if (File.Exists(FileName))
- {
- workbook.LoadFromFile(FileName);
- sheet1 = workbook.Worksheets[sheetname];
-
- }
- else if (File.Exists(ModelFile))
- {
- workbook.LoadFromFile(ModelFile);
- sheet1 = workbook.Worksheets["测试信息"];
- sheet1.Range["A2"].Value2 = tps.Serial;//序列号
- sheet1.Range["B2"].Value2 = tps.Tester;//检验员
- sheet1.Range["C2"].Value2 = DateTime.Now.Date.ToString();//日期
- sheet1.Range["D2"].Value2 = tps.Temperature;//温度
- sheet1.Range["E2"].Value2 = tps.Humidity;//湿度
- sheet1 = workbook.Worksheets[sheetname];
-
- }
-
- if (!File.Exists(ModelFile))
- {
- sheet1 = null;
- }
- sheet = sheet1;
- }
- public void WriteExcelData(Spire.Xls.Worksheet sheet, int row, int channel, string name, string lower, string upper, string val, string result)
- {
- int column = (channel - 1) * 6;
- sheet.Range[row + 2, 1 + column].Value2 = name;
- sheet.Range[row + 2, 2 + column].Value2 = lower;
- sheet.Range[row + 2, 3 + column].Value2 = upper;
- sheet.Range[row + 2, 4 + column].Value = val;
- sheet.Range[row + 2, 5 + column].Value2 = result;
- }
- public void SaveExcel(Spire.Xls.Workbook workbook)
- {
- string subPath = "F:/发射机/发射机测试数据/" + tps.TestProject + "/";
- string FileName = subPath + tps.Serial + ".xlsx";
- workbook.CalculateAllValue();
- workbook.SaveToFile(FileName);
- }
- public class DataType
- {
- /// <summary>
- /// 测试名称
- /// </summary>
- public string Test_name { set; get; }
- /// <summary>
- /// 指标下限
- /// </summary>
- public double Lower { set; get; }
- /// <summary>
- /// 指标上限
- /// </summary>
- public double Upper { set; get; }
- /// <summary>
- /// 测试值
- /// </summary>
- public double TestVal { set; get; }
- /// <summary>
- /// 判断结果
- /// </summary>
- public string Result { set; get; }
- }
- }
- }
|