123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.ComponentModel;
- using Tps_LQ_Transmitter.com;
- using System.IO;
- using Tps_LQ_Transmitter.models;
- using System.Data;
- using AppLibs.Devices;
- namespace Tps_LQ_Transmitter
- {
- public delegate void DltShowMsg(MsgType msgType, string msg);
- public delegate void DltCellValueChanged(int row, int cell, bool ok, object value);
- /// <summary>
- /// 一个测试文件对应的测试项目
- /// </summary>
- public class MainTps
- {
- /// <summary>
- /// 测试人员
- /// </summary>
- public string Tester { get; set; }
- //测试地点
- public string Place { get; set; }
- //环境温度
- public string Temperature { get; set; }
- //当前测试的产品序列号
- public string Serial { get; set; }
- //环境湿度
- public string Humidity { get; set; }
- //待测产品
- public string Product { get; set; }
- //测试项目
- public string TestProject { get; set; }
- //配置文件路径
- string FilePath;
- /// <summary>
- /// 设备节点,表示当前测试程序包含的试验设备,绑定到界面的设备列表中
- /// </summary>
- public IList<DeviceNode> Devices;
- /// <summary>
- /// 测试节点,表示当前测试程序含有的测试指标,绑定到界面的指标列表中
- /// </summary>
- public IList<TestNode> TestNodes;
- /// <summary>
- /// 手工输入表
- /// </summary>
- public DataTable ManualTable;
- /// <summary>
- /// 自动测试表
- /// </summary>
- public DataTable TestTable;
- /// <summary>
- /// 测试值字典
- /// </summary>
- public Dictionary<string,double> TestValueDict;
- public event DltCellValueChanged ManualTableCellChanged;
- public event DltCellValueChanged TestTableCellChanged;
- DataTable InitTestTable,InitManualTable; //原始数据的界面,用于初始化或者重置
- /// <summary>
- /// 测试指标的结构
- /// </summary>
- List<BaseModelStruct> baseModelStructs;
- public MainTps()
- {
- Devices = new BindingList<DeviceNode>();
- TestNodes = new BindingList<TestNode>();
- baseModelStructs = new List<BaseModelStruct>();
- LoadBaseModelStructs();
- }
- #region 模板基础方法
- /// <summary>
- /// 加载配置文件
- /// </summary>
- /// <param name="filePath"></param>
- /// <returns></returns>
- public bool LoadConfigFile(string filePath)
- {
- bool ok = true;
- if (File.Exists(filePath) == false)
- {
- ShowMessage(MsgType.Error, string.Format("找不到配置文件:{0}", filePath));
- return false;
- }
- this.FilePath = filePath;
- using (Spire.Xls.Workbook workbook = new Spire.Xls.Workbook())
- {
- workbook.LoadFromFile(filePath);
- //处理Excel数据,更多请参考官方Demo
- Spire.Xls.Worksheet sheet = workbook.Worksheets["自动测试项总表"];
- if(sheet == null)
- {
- ShowMessage(MsgType.Error, "文件中找不到‘自动测试项总表’");
- return false;
- }
- int blankRows = 0; //避免出错
- int num = 0;
- //默认最多两百行
- while (num++ < 200)
- {
- //索引从1开始
- string col1 = sheet.Range[num, 1].Value2 != null ? sheet.Range[num, 1].Value2.ToString():"";
- col1 = col1.Trim();
- if (string.IsNullOrEmpty(col1))
- {
- blankRows++;
- if(blankRows > 5)
- {
- //连续5个空行以上则退出
- break;
- }
- }
- else
- {
- blankRows = 0;
- }
- if (col1.Equals("设备配置表"))
- {
- ok &= readDevices(sheet,num);
- //解析行数跳过,实际上还得再加上
- num = num + this.Devices.Count+2;
- }
- else if (col1.Equals("测试指标配置表"))
- {
- ok &= readTestNodes(workbook,sheet,num);
- var items = (from p in TestNodes select p.Name).Distinct().ToArray();
- //解析行数跳过,实际上还得再加上
- num = num + items.Count() + 3;
- }
- }
- //加载人工测试项总表
- sheet = workbook.Worksheets["人工测试项总表"];
- if (sheet != null)
- {
- blankRows = 0; //避免出错
- num = 0;
- //默认最多两百行
- while (num++ < 200)
- {
- //索引从1开始
- string col1 = sheet.Range[num, 1].Value2 != null ? sheet.Range[num, 1].Value2.ToString() : "";
- col1 = col1.Trim();
- if (string.IsNullOrEmpty(col1))
- {
- blankRows++;
- if (blankRows > 5)
- {
- //连续5个空行以上则退出
- break;
- }
- }
- else
- {
- blankRows = 0;
- }
- if (col1.Equals("人工测试项总表"))
- {
- this.ManualTable = readTable(sheet, num);
- if (this.ManualTable != null)
- {
- this.InitManualTable = this.ManualTable.Copy();
- }
- }
- }
- }
- //加载人工测试项总表
- sheet = workbook.Worksheets["自动测试记录表"];
- if (sheet != null)
- {
- blankRows = 0; //避免出错
- num = 0;
- //默认最多两百行
- while (num++ < 200)
- {
- //索引从1开始
- string col1 = sheet.Range[num, 1].Value2 != null ? sheet.Range[num, 1].Value2.ToString() : "";
- col1 = col1.Trim();
- if (string.IsNullOrEmpty(col1))
- {
- blankRows++;
- if (blankRows > 5)
- {
- //连续5个空行以上则退出
- break;
- }
- }
- else
- {
- blankRows = 0;
- }
- if (col1.Equals("自动测试记录表"))
- {
- this.TestTable = readTable(sheet, num);
- if(this.TestTable != null)
- {
- this.InitTestTable = this.TestTable.Copy();
- }
- }
- }
- }
- }
- return ok;
- }
- /// <summary>
- /// 读设备配置表
- /// </summary>
- /// <param name="rowIndex">设备配置表的起始位置</param>
- bool readDevices(Spire.Xls.Worksheet sheet, int rowIndex)
- {
- //检查表的格式正确
- string col1 = sheet.Range[rowIndex + 1, 1].Value2 != null ? sheet.Range[rowIndex + 1, 1].Value2.ToString() : "";
- string col2 = sheet.Range[rowIndex + 1, 2].Value2 != null ? sheet.Range[rowIndex + 1, 2].Value2.ToString() : "";
- string col3 = sheet.Range[rowIndex + 1, 3].Value2 != null ? sheet.Range[rowIndex + 1, 3].Value2.ToString() : "";
- string col4 = sheet.Range[rowIndex + 1, 4].Value2 != null ? sheet.Range[rowIndex + 1, 4].Value2.ToString() : "";
- if (!(col1 == "设备名称" && col2 == "设备类型" && col3 == "设备型号" && col4 == "控制句柄"))
- {
- ShowMessage(MsgType.Error, "'设备配置表'行首标题位置和格式不正确");
- return false;
- }
- int num = rowIndex + 1;
- //默认最多30行
- while (num++ < rowIndex + 30)
- {
- col1 = sheet.Range[num, 1].Value2 != null ? sheet.Range[num, 1].Value2.ToString() : "";
- col2 = sheet.Range[num, 2].Value2 != null ? sheet.Range[num, 2].Value2.ToString() : "";
- col3 = sheet.Range[num, 3].Value2 != null ? sheet.Range[num, 3].Value2.ToString() : "";
- col4 = sheet.Range[num, 4].Value2 != null ? sheet.Range[num, 4].Value2.ToString() : "";
- if (string.IsNullOrEmpty(col1) || string.IsNullOrEmpty(col2) || string.IsNullOrEmpty(col3))
- {
- break;
- }
- DeviceNode dn = new DeviceNode();
- dn.DeviceName = col1;
- dn.DeviceType = col2;
- dn.DeviceModel = col3;
- dn.DeviceHandle = col4;
- this.Devices.Add(dn);
- }
- return true;
- }
- /// <summary>
- /// 读测试指标配置表
- /// </summary>
- /// <param name="rowIndex">测试指标配置表的起始位置</param>
- bool readTestNodes(Spire.Xls.Workbook workbook,Spire.Xls.Worksheet sheet, int rowIndex)
- {
- List<TestNode> models = new List<TestNode>();
- //检查表的格式正确
- string col1 = sheet.Range[rowIndex + 2, 1].Value2 != null ? sheet.Range[rowIndex + 2, 1].Value2.ToString() : "";
- string col2 = sheet.Range[rowIndex + 2, 2].Value2 != null ? sheet.Range[rowIndex + 2, 2].Value2.ToString() : "";
- string col3 = sheet.Range[rowIndex + 2, 3].Value2 != null ? sheet.Range[rowIndex + 2, 3].Value2.ToString() : "";
- string col4 = sheet.Range[rowIndex + 2, 4].Value2 != null ? sheet.Range[rowIndex + 2, 4].Value2.ToString() : "";
- if (!(col1 == "测试指标" && col2 == "默认勾选" && col3 == "测试模板" && col4 == "测试顺序"))
- {
- ShowMessage(MsgType.Error, "'测试指标配置表'行首标题位置和格式不正确");
- return false;
- }
- int num = rowIndex + 2;
- //默认最多100行,先解析测试指标个数
- while (num++ < rowIndex + 100)
- {
- col1 = sheet.Range[num, 1].Value2 != null ? sheet.Range[num, 1].Value2.ToString() : "";
- col2 = sheet.Range[num, 2].Value2 != null ? sheet.Range[num, 2].Value2.ToString() : "";
- col3 = sheet.Range[num, 3].Value2 != null ? sheet.Range[num, 3].Value2.ToString() : "";
- col4 = sheet.Range[num, 4].Value2 != null ? sheet.Range[num, 4].Value2.ToString() : "";
- if (string.IsNullOrEmpty(col1) || string.IsNullOrEmpty(col3))
- {
- break;
- }
- TestNode tn = new TestNode();
- tn.Name = col1;
- if(col2 == "是")
- {
- tn.IsSelected = true;
- }
- else
- {
- tn.IsSelected = false;
- }
- tn.Template = col3;
- int order = Int32.MaxValue;
- if (Int32.TryParse(col4, out order))
- tn.Order = order;
- models.Add(tn);
- }
- //再解析各通道的配置数据
- int colIndex = 5; //通道数据从第5列开始
- while(true)
- {
- col1 = sheet.Range[rowIndex + 3, colIndex].Value2 != null ? sheet.Range[rowIndex + 3, colIndex].Value2.ToString() : "";
- col2 = sheet.Range[rowIndex + 3, colIndex + 1].Value2 != null ? sheet.Range[rowIndex + 3, colIndex + 1].Value2.ToString() : "";
- //有新通道数据则继续,否则退出
- if(string.IsNullOrEmpty(col1) || string.IsNullOrEmpty(col2) || col2 != "启用")
- {
- break;
- }
- string channel = sheet.Range[rowIndex + 1, colIndex].Value2 != null ? sheet.Range[rowIndex + 1, colIndex].Value2.ToString() : "";
- //按指标个数来解析通道数据
- for (int i = 0; i < models.Count; i++)
- {
- col1 = sheet.Range[rowIndex + 3 + i, colIndex].Value2 != null ? sheet.Range[rowIndex + 3 + i, colIndex].Value2.ToString() : "";
- col2 = sheet.Range[rowIndex + 3 + i, colIndex + 1].Value2 != null ? sheet.Range[rowIndex + 3 + i, colIndex + 1].Value2.ToString() : "";
- if (col2 != "启用")
- continue;
- TestNode newNode = models[i].Copy();
- newNode.Channel = channel; //通道名
- newNode.ParaConfigTable = col1; //测试配置表
- //复制已有参数表,或者从文件解析参数表
- TestNode preNode = TestNodes.FirstOrDefault(x => x.ParaConfigTable == col1);
- if(preNode != null)
- {
- //存在则复制,避免读文件费时间
- newNode.Parameters = preNode.Parameters.Copy();
- }
- else
- {
- //否则找到文件中对应的配置表
- Spire.Xls.Worksheet paraSheet = workbook.Worksheets[col1];
- if (paraSheet == null)
- {
- ShowMessage(MsgType.Error, "文件中找不到参数配置表:"+ col1);
- continue;
- }
- //解析参数配置表
- newNode.Parameters = readTestParameter(paraSheet);
- }
- //如果已经创建了同名的处理对象,则直接使用,否则则新建,采用单例模式
- //如果注释了下面的if,就是多例模式,即同名处理模块是不同的软件对象
- TestNode tn = this.TestNodes.FirstOrDefault(x => x.Template == newNode.Template);
- if(tn != null && tn.TestModel != null)
- {
- newNode.TestModel = tn.TestModel;
- }
- else
- {
- //根据测试指标的名称,创建BaseModel指标处理对象
- newNode.TestModel = CreateModel(newNode.Template);
- }
-
- this.TestNodes.Add(newNode);
- }
- colIndex += 2; //跳过2列
- }
- return true;
- }
- BaseModel CreateModel(string template)
- {
- //如果没有这个名字的软件模块,则返回null
- BaseModelStruct bms = baseModelStructs.FirstOrDefault(x => x.ModelName == template);
- if (bms == null)
- {
- ShowMessage(MsgType.Error, "找不到名称为:" + template +" 的测试指标模块。");
- return null;
- }
-
- BaseModel model = (BaseModel)Activator.CreateInstance(bms.type);
- model.tps = this;
- model.MessageEvent += ShowMessage;
- return model;
- }
- void LoadBaseModelStructs()
- {
- try
- {
- Type[] types = this.GetType().Assembly.GetTypes();
- foreach (var item in types)
- {
- //排除接口本身
- if (item.Name != "BaseModel")
- {
- if (typeof(BaseModel).IsAssignableFrom(item))
- {
- BaseModel model = (BaseModel)Activator.CreateInstance(item);
- BaseModelStruct bms = new BaseModelStruct();
- bms.ModelName = model.TemplateName;
- bms.type = item;
- this.baseModelStructs.Add(bms);
- model = null;
- }
- }
- }
- }
- catch(Exception e)
- {
- ShowMessage(MsgType.Error, "实例化BaseModel测试指标模块时出现错误,某个测试指标模块创建时发生错误,请检查代码!详细错误见程序日志文件!");
- Bundle.log.WriteLog(AppLibs.Host.LogLevel.Error, "类:MainTps,方法:LoadBaseModelStructs", e.Message + e.StackTrace);
- }
-
- }
- /// <summary>
- /// 读参数配置表
- /// </summary>
- /// <returns></returns>
- TestParameters readTestParameter(Spire.Xls.Worksheet sheet)
- {
- TestParameters pars = new TestParameters();
- int blankRows = 0; //避免出错
- int num = 0;
- //默认最多两百行
- while (num++ < 200)
- {
- //索引从1开始
- string col1 = sheet.Range[num, 1].Value2 != null ? sheet.Range[num, 1].Value2.ToString() : "";
- col1 = col1.Trim();
- if (string.IsNullOrEmpty(col1))
- {
- blankRows++;
- if (blankRows > 5)
- {
- //连续5个空行以上则退出
- break;
- }
- }
- else
- {
- blankRows = 0;
- }
- if (col1.Equals("参数表"))
- {
- ///获取表中的参数
- List<ParameterNode> nodes = readParameters(sheet,num);
- foreach (var item in nodes)
- {
- if(pars.Parameters.ContainsKey(item.Name))
- {
- ShowMessage(MsgType.Error, string.Format("参数配置表:{0} 存在同名参数:{1},无法重复添加参数", sheet.Name, item.Name));
- continue;
- }
- pars.Parameters.Add(item.Name, item);
- }
- //解析行数跳过,实际上还得再加上
- num = num + nodes.Count +1;
- }
- else if (col1.Equals("测试显示表"))
- {
- //获取表中的原始显示界面
- pars.InitialTable = readTable( sheet, num);
- //解析行数跳过,实际上还得再加上
- num = num + pars.InitialTable.Rows.Count + 1;
- }
- }
- return pars;
- }
- /// <summary>
- /// 读参数表
- /// </summary>
- /// <param name="sheet"></param>
- /// <returns></returns>
- List<ParameterNode> readParameters(Spire.Xls.Worksheet sheet,int rowIndex)
- {
- List<ParameterNode> nodes = new List<ParameterNode>();
- string col1 = sheet.Range[rowIndex + 1, 1].Value2 != null ? sheet.Range[rowIndex + 1, 1].Value2.ToString() : "";
- string col2 = sheet.Range[rowIndex + 1, 2].Value2 != null ? sheet.Range[rowIndex + 1, 2].Value2.ToString() : "";
- string col3 = sheet.Range[rowIndex + 1, 3].Value2 != null ? sheet.Range[rowIndex + 1, 3].Value2.ToString() : "";
- string col4 = sheet.Range[rowIndex + 1, 4].Value2 != null ? sheet.Range[rowIndex + 1, 4].Value2.ToString() : "";
- if (!(col1 == "名称" && col2 == "类型" && col3 == "值"))
- {
- ShowMessage(MsgType.Error, "'参数表'行首标题位置和格式不正确");
- return nodes;
- }
- int num = rowIndex + 1;
- //默认最多30行
- while (num++ < rowIndex + 200)
- {
- col1 = sheet.Range[num, 1].Value2 != null ? sheet.Range[num, 1].Value2.ToString() : "";
- col2 = sheet.Range[num, 2].Value2 != null ? sheet.Range[num, 2].Value2.ToString() : "";
- col3 = sheet.Range[num, 3].Value2 != null ? sheet.Range[num, 3].Value2.ToString() : "";
- col4 = sheet.Range[num, 4].Value2 != null ? sheet.Range[num, 4].Value2.ToString() : "";
- if (string.IsNullOrEmpty(col1) || string.IsNullOrEmpty(col2) || string.IsNullOrEmpty(col3))
- {
- break;
- }
- ParameterNode pn = new ParameterNode();
- pn.Name = col1;
- pn.Type = col2;
- pn.StrValue = col3;
- pn.Mark = col4;
- nodes.Add(pn);
- }
- return nodes;
- }
- /// <summary>
- /// 读表格,人工测试表和测试显示表
- /// </summary>
- /// <param name="sheet"></param>
- /// <returns></returns>
- DataTable readTable(Spire.Xls.Worksheet sheet, int rowIndex)
- {
- //先创建列,再创建行
- DataTable dt = new DataTable();
- int num = 0;
- while (num++ < 50)
- {
- string col = sheet.Range[rowIndex + 1, num].Value2 != null ? sheet.Range[rowIndex + 1, num].Value2.ToString() : "";
- if (string.IsNullOrEmpty(col))
- break;
- dt.Columns.Add(col);
- }
- //再创建行
- num = rowIndex + 1;
- //默认最多200行
- while (num++ < rowIndex + 200)
- {
- //首列无值就认为表格结束
- string val = sheet.Range[num, 1].Value2 != null ? sheet.Range[num, 1].Value2.ToString() : "";
- if (string.IsNullOrEmpty(val.Trim()))
- break;
- DataRow dr = dt.NewRow();
- dt.Rows.Add(dr);
- for (int i = 0; i < dt.Columns.Count; i++)
- {
- val = sheet.Range[num, i+1].Value2 != null ? sheet.Range[num, i+1].Value2.ToString() : "";
- dr[i] = val;
- }
-
- }
- return dt;
- }
- /// <summary>
- /// 检查仪器是否正常配置
- /// </summary>
- /// <returns></returns>
- public bool CheckDevices()
- {
- bool ok = true;
- AppLibs.Devices.IDeviceHost devHost = Bundle.host.GetFirstOrDefaultService<AppLibs.Devices.IDeviceHost>();
- foreach (DeviceNode device in this.Devices)
- {
- DeviceParameter dev = devHost.GetFirstOrDefaultDeviceID(device.DeviceHandle);
- if (dev == null || !(device.DeviceType == dev.DeviceType && device.DeviceModel == dev.DeviceModel))
- {
- device.State = false;
- ok = false;
- }
- else
- {
- device.State = true;
- continue;
- }
- }
- return ok;
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="isOrderByChannel">按照指标分组还是按照通道分组</param>
- public void Start(bool isOrderByChannel)
- {
- ShowMessage(MsgType.Info, string.Format("序列号:{0} 测试开始",Serial));
- isStop = false;
- //清空测试数据
- // BaseModel.TestResults.Clear();
- //选择勾选项
- List<TestNode> nodes = this.TestNodes.Where(x => x.IsSelected == true).ToList();
- if(isOrderByChannel)
- {
- //按照通道分组
- foreach (IGrouping<string, TestNode> group in nodes.GroupBy(x => x.Channel))
- {
- //排序后执行
- foreach (TestNode testnode in group.OrderBy(a => a.Order))
- {
- if(isStop == false)
- {
- ShowMessage(MsgType.Info, string.Format("开始执行测试指标:{0}/{1}", testnode.Channel, testnode.Name));
- if(testnode.TestModel != null)
- {
- //测试中途取消了勾选项
- if(testnode.IsSelected)
- {
- currModel = testnode.TestModel;
- testnode.TestModel.Start(testnode);
- }
- }
- else
- {
- ShowMessage(MsgType.Error, string.Format("测试指标:{0}/{1} 没有实例化执行模块", testnode.Channel, testnode.Name));
- }
- }
- else
- {
- break;
- }
- }
- }
- }
- else
- {
- //按照指标名称进行
- foreach (IGrouping<string, TestNode> group in nodes.GroupBy(x => x.Name))
- {
- //排序后执行
- foreach (TestNode testnode in group.OrderBy(a => a.Order))
- {
- if (isStop == false)
- {
- ShowMessage(MsgType.Info, string.Format("开始执行测试指标:{0}/{1}", testnode.Channel, testnode.Name));
- if (testnode.TestModel != null)
- {
- currModel = testnode.TestModel;
- testnode.TestModel.Start(testnode);
- }
- else
- {
- ShowMessage(MsgType.Error, string.Format("测试指标:{0}/{1} 没有实例化执行模块", testnode.Channel, testnode.Name));
- }
- }
- else
- {
- break;
- }
- }
- }
- }
- //保存自动测试记录表
- SaveTestTable();
- ShowMessage(MsgType.Info, string.Format("序列号:{0} 测试完成", Serial));
- }
- bool isStop = false;
- BaseModel currModel = null;
- public void Stop()
- {
- isStop = true;
- if(currModel!= null)
- {
- currModel.Stop();
- }
- ShowMessage(MsgType.Info, string.Format("序列号:{0} 测试中止", Serial));
- }
- public event DltShowMsg MessageEvent;
- /// <summary>
- /// 本对象显示消息,以及测试指标显示消息都经过这个方法
- /// </summary>
- /// <param name="msgType"></param>
- /// <param name="msg"></param>
- void ShowMessage(MsgType msgType, string msg)
- {
- if(MessageEvent != null)
- {
- MessageEvent(msgType, msg);
- }
- }
- public void ResetTestTable()
- {
- if(this.InitTestTable != null)
- {
- TestTable = this.InitTestTable.Copy();
- }
- }
- public void ResetManualTable()
- {
- if (this.InitManualTable != null)
- {
- ManualTable = this.InitManualTable.Copy();
- }
- }
- public AppLibs.Devices.IVISA GetDevice(string name)
- {
- DeviceNode node = this.Devices.FirstOrDefault(x => x.DeviceName == name);
- //不存在或者状态不对,都返回空
- if(node == null || node.State == false)
- {
- return null;
- }
- else
- {
- AppLibs.Devices.IDeviceHost devHost = Bundle.host.GetFirstOrDefaultService<AppLibs.Devices.IDeviceHost>();
- if (devHost == null)
- return null;
- DeviceParameter dev = devHost.GetFirstOrDefaultDeviceID(node.DeviceHandle);
- //要地址,名称,型号一致
- if (dev == null || !(node.DeviceType == dev.DeviceType && node.DeviceModel == dev.DeviceModel))
- {
- return null;
- }
- else
- {
- return (IVISA)dev;
- }
- }
- }
- public void SetManualTableCellValue(int row, int col, bool ok, object value)
- {
- if (ManualTableCellChanged != null)
- ManualTableCellChanged(row, col,ok, value);
- }
- public void SetTestTableCellValue(int row, int col, bool ok, object value)
- {
- if (TestTableCellChanged != null)
- TestTableCellChanged(row, col, ok, value);
- }
- void SaveTestTable()
- {
- if(string.IsNullOrEmpty(Serial))
- {
- ShowMessage(MsgType.Info, "序列号为空,数据不保存");
- return;
- }
- AppLibs.Function.IReportHost report = Bundle.host.GetFirstOrDefaultService<AppLibs.Function.IReportHost>();
- if(report != null)
- {
- AppLibs.Models.TableInfo tableInfo = new AppLibs.Models.TableInfo();
- tableInfo.data = TestTable;
- tableInfo.table = new AppLibs.Models.Table();
- tableInfo.table.Result = "合格";
- tableInfo.table.Temperature = Temperature;
- tableInfo.table.Tester = Tester;
- tableInfo.table.Time = DateTime.Now;
- tableInfo.table.Place = Place;
- tableInfo.table.Serial = Serial;
- tableInfo.table.Humidity = Humidity;
- tableInfo.table.Type = TestProject;
- tableInfo.table.ProductCode = Product;
- tableInfo.table.ProductName = Product;
- tableInfo.table.Name = TestProject + "#" + Product;
- if (report.WriteAndReplaceTable(tableInfo))
- {
- ShowMessage(MsgType.Info, "自动测试记录表保存成功");
- }
- else
- {
- ShowMessage(MsgType.Info, "自动测试记录表保存失败");
- }
- }
- else
- {
- ShowMessage(MsgType.Info, "软件未包含数据存储模块");
- }
-
- }
- //判断某个测试项是否勾选
- public bool IsTestItemSelected(string channel , string name)
- {
- var node = this.TestNodes.FirstOrDefault(x => x.Channel == channel && x.Name == name);
- if (node == null)
- return false;
- return node.IsSelected;
- }
- #endregion
- #region 二次修改的方法
- #endregion
- }
- }
|