FrmMain.cs 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911
  1. using CommonDevHostApp.Devices;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Diagnostics;
  7. using System.Drawing;
  8. using System.IO;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading;
  12. using System.Threading.Tasks;
  13. using System.Windows.Forms;
  14. using Tps_LQ_Transmitter.com;
  15. using Tps_LQ_Transmitter.Common;
  16. using Tps_LQ_Transmitter.views;
  17. namespace Tps_LQ_Transmitter
  18. {
  19. public partial class FrmMain : Form
  20. {
  21. /// <summary>
  22. /// config目录下存在的测试配置文件信息
  23. /// </summary>
  24. IList<FileNode> FileNodes;
  25. bool comFlag = false;
  26. /// <summary>
  27. /// 当前选择的测试配置文件信息
  28. /// </summary>
  29. FileNode currFileNode;
  30. /// <summary>
  31. /// 停止测试标志
  32. /// </summary>
  33. public bool IsRuning = true;
  34. CommonVisaResource DCPower = null;
  35. RainwormPower rainwormPower = null;
  36. FrmMsg frmMsg;
  37. FrmDevice frmDevice;
  38. public FrmMain()
  39. {
  40. InitializeComponent();
  41. frmMsg = new FrmMsg();
  42. frmDevice = new FrmDevice();
  43. }
  44. private void FrmMain_Load(object sender, EventArgs e)
  45. {
  46. //this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
  47. FileNodes = new BindingList<FileNode>();
  48. cbbProduct.ValueMember = "TestProject";
  49. cbbProduct.DisplayMember = "DisplayName";
  50. cbbProduct.DataSource = FileNodes;
  51. //加载配置文件信息
  52. string folder = Path.Combine(Bundle.bundle.BundleDir, "config");
  53. if(Directory.Exists(folder))
  54. {
  55. //文件名示例:测试#常温测试#035变频模块.xlsx
  56. string[] files = Directory.GetFiles(folder, "测试#*.xlsx");
  57. foreach (string file in files)
  58. {
  59. FileNode node = new FileNode();
  60. node.FilePath = file;
  61. string fname = Path.GetFileNameWithoutExtension(file);
  62. fname = fname.Substring(fname.IndexOf('#') + 1);
  63. node.DisplayName = fname;
  64. node.TestProject = fname.Substring(0, fname.IndexOf('#'));
  65. node.ProductName = fname.Substring(fname.IndexOf('#') + 1);
  66. FileNodes.Add(node);
  67. }
  68. }
  69. cbbProduct.Refresh();
  70. comFlag = true;
  71. superTabControl1.SelectedTabIndex = 0;
  72. }
  73. private void BtnLoadTpsConfig_Click(object sender, EventArgs e)
  74. {
  75. if (cbbProduct.SelectedIndex >= 0 && cbbProduct.SelectedItem != null)
  76. {
  77. //把试验项目显示到界面
  78. FileNode fn = (FileNode)cbbProduct.SelectedItem;
  79. //加载内容
  80. if (fn.Tps == null)
  81. {
  82. MainTps tps = new MainTps();
  83. try
  84. {
  85. if (tps.LoadConfigFile(fn.FilePath))
  86. {
  87. fn.Tps = tps;
  88. }
  89. else
  90. {
  91. ShowMessage(MsgType.Error, string.Format("加载配置文件失败,文件路径:{0}", fn.FilePath));
  92. return;
  93. }
  94. }
  95. catch(Exception ee)
  96. {
  97. ShowMessage(MsgType.Error, string.Format("加载配置文件出现异常:{0},详细请查看日志文件。", ee.Message));
  98. Bundle.log.WriteLog(AppLibs.Host.LogLevel.Error, "类:FrmMain,方法:BtnLoadTpsConfig_Click", ee.Message + ee.StackTrace);
  99. }
  100. }
  101. //初始化界面相关
  102. ShowTps(fn);
  103. }
  104. }
  105. List<TestMessage> tMsgs = new List<TestMessage>();
  106. void ShowMessage(MsgType msgType , string msg)
  107. {
  108. if (msgType == MsgType.Error)
  109. {
  110. errorCount++;
  111. this.Invoke(new Action(() => {
  112. BtnMessage.Text = "消息/错误:" + errorCount.ToString();
  113. BtnMessage.ForeColor = Color.Red;
  114. }));
  115. }
  116. tMsgs.Add(new TestMessage() { type = msgType, message = msg });
  117. frmMsg.ShowMsg(tMsgs);
  118. }
  119. /// <summary>
  120. /// 清空消息
  121. /// </summary>
  122. void ClearMessage()
  123. {
  124. tMsgs.Clear();
  125. frmMsg.ClearMsg();
  126. }
  127. void ShowTps(FileNode fn)
  128. {
  129. if (currFileNode != null && currFileNode.Tps!= null )
  130. {
  131. currFileNode.Tps.MessageEvent -= Tps_MessageEvent;
  132. currFileNode.Tps.ManualTableCellChanged -= Tps_ManualTableCellChanged;
  133. currFileNode.Tps.TestTableCellChanged -= Tps_TestTableCellChanged;
  134. currFileNode.Tps.AddTestTableCell -= Tps_TestTableAddCell;
  135. currFileNode.Tps.CurrentSeries -= tps_UpdateCurrentSeries;
  136. }
  137. currFileNode = fn;
  138. if(currFileNode.Tps != null)
  139. {
  140. currFileNode.Tps.MessageEvent += Tps_MessageEvent;
  141. currFileNode.Tps.ManualTableCellChanged += Tps_ManualTableCellChanged;
  142. currFileNode.Tps.TestTableCellChanged += Tps_TestTableCellChanged;
  143. currFileNode.Tps.AddTestTableCell += Tps_TestTableAddCell;
  144. currFileNode.Tps.CurrentSeries += tps_UpdateCurrentSeries;
  145. }
  146. currFileNode.Tps.RemainTimeUpdate += RemainTime;
  147. tbTestProject.Text = fn.TestProject;
  148. displayTree(true);
  149. //显示主界面
  150. dgvTestData.DataSource = currFileNode.Tps.TestTable;
  151. //显示人工配置界面
  152. dgvManualData.DataSource = currFileNode.Tps.ManualTable;
  153. //显示仪器列表,把当前TPS使用的仪器和仪器检查界面绑定
  154. frmDevice.ShowDevices(currFileNode.Tps.Devices);
  155. }
  156. private void Tps_TestTableAddCell(string series,string name, string systemch,string lower, string upper, string testval, string result)
  157. {
  158. this.Invoke(new Action(() => {
  159. currFileNode.Tps.TestTable.Rows.Add(series, name, systemch,lower,upper,testval, result);
  160. if (result=="是")
  161. {
  162. dgvTestData.Rows[currFileNode.Tps.TestTable.Rows.Count-1].Cells[4].Style.BackColor = Color.Green;
  163. }
  164. else
  165. {
  166. dgvTestData.Rows[currFileNode.Tps.TestTable.Rows.Count-1].Cells[4].Style.BackColor = Color.Red;
  167. }
  168. }));
  169. }
  170. private void Tps_TestTableCellChanged(int row, int cell,bool ok, object value)
  171. {
  172. this.Invoke(new Action(() => {
  173. currFileNode.Tps.TestTable.Rows[row][cell] = value;
  174. if (ok)
  175. {
  176. dgvTestData.Rows[row].Cells[cell].Style.BackColor = Color.White;
  177. }
  178. else
  179. {
  180. dgvTestData.Rows[row].Cells[cell].Style.BackColor = Color.Red;
  181. }
  182. }));
  183. }
  184. private void Tps_ManualTableCellChanged(int row, int cell, bool ok, object value)
  185. {
  186. this.Invoke(new Action(() => {
  187. currFileNode.Tps.ManualTable.Rows[row][cell] = value;
  188. if (ok)
  189. {
  190. dgvTestData.Rows[row].Cells[cell].Style.BackColor = Color.White;
  191. }
  192. else
  193. {
  194. dgvTestData.Rows[row].Cells[cell].Style.BackColor = Color.Red;
  195. }
  196. }));
  197. }
  198. private void RemainTime(string channel, int point, int FrequencyNumber, double CenterFreq, double testMin)
  199. {
  200. this.BeginInvoke(new Action(() =>
  201. {
  202. labRemainTime.Text = $"{channel},第{point + 1}/{FrequencyNumber}个频点:{CenterFreq}MHz测试,耗时{Math.Round(testMin, 2)}Min。";
  203. }));
  204. }
  205. private void tps_UpdateCurrentSeries(string series)
  206. {
  207. this.BeginInvoke(new Action(() =>
  208. {
  209. tbSerials.Text = series;
  210. }));
  211. }
  212. int errorCount = 0;
  213. private void Tps_MessageEvent(MsgType msgType, string msg)
  214. {
  215. ShowMessage(msgType, msg);
  216. }
  217. bool isOrderByChannel = true;
  218. Task task;
  219. private void BtnStart_Click(object sender, EventArgs e)
  220. {
  221. if (currFileNode == null)
  222. return;
  223. if (tbSerials.Items.Count == 0)
  224. {
  225. MessageBox.Show("温馨提示:请输入产品编号后再进行测试!");
  226. return;
  227. }
  228. labRemainTime.Text = $"开始测试";
  229. IsRuning = true;
  230. BtnLoadTpsConfig.Enabled = false;
  231. BtnStart.Enabled = false;
  232. tbSerials.Enabled = false;
  233. currFileNode.Tps.Tester = tbTester.Text;
  234. currFileNode.Tps.Place = tbPlace.Text;
  235. currFileNode.Tps.Product = currFileNode.ProductName;
  236. currFileNode.Tps.Serial = tbSerial.Text;
  237. currFileNode.Tps.Temperature = tbTemp.Text;
  238. currFileNode.Tps.Humidity = tbRH.Text;
  239. currFileNode.Tps.TestProject = tbTestProject.Text;
  240. ClearMessage();
  241. //检查仪器,如果OK则开始测试
  242. if(currFileNode.Tps.CheckDevices())
  243. {
  244. if(BtnDevice.ForeColor == Color.Red)
  245. {
  246. BtnDevice.ForeColor = Color.Black;
  247. }
  248. StartTest();
  249. }
  250. else
  251. {
  252. //设备检查不通过,需要提醒用户确认
  253. //BtnDevice.ForeColor = Color.Red;
  254. //显示仪器设置界面
  255. //if(MessageBox.Show("设备参数异常,是否继续测试?","警告",MessageBoxButtons.YesNo) == DialogResult.Yes)
  256. //{
  257. StartTest();
  258. //}
  259. //else
  260. //{
  261. // BtnLoadTpsConfig.Enabled = true;
  262. // BtnStart.Enabled = true;
  263. //}
  264. }
  265. }
  266. Thread SerialHandleThread1;
  267. private void WorkThretdHandleFunction(object num)
  268. {
  269. }
  270. void StartTest()
  271. {
  272. Stopwatch TimesCounter = new Stopwatch();
  273. double testMin = 0;
  274. TimesCounter.Restart();
  275. //开始测试的时候重置测试表格
  276. currFileNode.Tps.ResetTestTable();
  277. SerialHandleThread1 = new Thread(new ParameterizedThreadStart(WorkThretdHandleFunction));
  278. SerialHandleThread1.Priority = ThreadPriority.Highest;
  279. MainTps tps = new MainTps();
  280. SerialConfig scfg = new SerialConfig();
  281. MatchComPara CfigComParas = scfg.LoadComWorkBook();
  282. if (CfigComParas == null)
  283. {
  284. return;
  285. }
  286. byte FourthByte = 0x00;
  287. string ComPort = CfigComParas.GetComPort("1");
  288. byte ThridByte = Convert.ToByte(CfigComParas.GetThirdByte("1"), 16);
  289. currFileNode.Tps.ThridByte = ThridByte;
  290. int FrequencyNumber;
  291. if (currFileNode.Tps.TestFreqSum >= CfigComParas.ComParameters.Count)//如果限定的测试频点数大于设置的频点数
  292. {
  293. FrequencyNumber = CfigComParas.ComParameters.Count;//取设置的频点数
  294. }
  295. else
  296. {
  297. FrequencyNumber = currFileNode.Tps.TestFreqSum;//取限定的测试频点数
  298. }
  299. dgvTestData.DataSource = null;
  300. dgvTestData.DataSource = currFileNode.Tps.TestTable;
  301. double volt = currFileNode.Tps.GloabConfigDict["电压"];
  302. double Current = currFileNode.Tps.GloabConfigDict["电流"];
  303. // ConfigParameter SetVoltPara = new ConfigParameter();
  304. if (tbSerials.Items.Count > 1) //如何测试产品大于1台,则使用外部TDK电源
  305. {
  306. DCPower = new CommonVisaResource();
  307. try
  308. {
  309. DCPower.Open(currFileNode.Tps.DCPowerAddress);
  310. }
  311. catch (Exception ex)
  312. {
  313. MessageBox.Show("打开TDK电源失败,请检查电源是否上电!");
  314. return;
  315. }
  316. DCPower.Write("INSTrument:NSELect 6\n"); DCPower.Query("*OPC?\n");
  317. DCPower.Write("VOLTage:PROTection:LEVel 34 V\n"); DCPower.Query("*OPC?\n");//设置过压保护
  318. DCPower.Write("VOLT:PROT:LOW 20 V\n"); DCPower.Query("*OPC?\n");//设置欠压保护
  319. DCPower.Write("VOLT:PROT:LOW:STAT UVP\n"); DCPower.Query("*OPC?\n");//启动欠压保护
  320. DCPower.Write($"VOLTage {volt} V\n"); DCPower.Query("*OPC?\n");//设置电压
  321. DCPower.Write($"CURRent {Current} A\n"); DCPower.Query("*OPC?\n");//设置电流
  322. DCPower.Write("GLOBal:OUTPut:STATe 1\n"); DCPower.Query("*OPC?\n");
  323. ShowMessage(MsgType.Info, string.Format("打开外部TDK电源."));
  324. }
  325. else //如何测试产品为1台,则使用内部蚯蚓电源
  326. {
  327. rainwormPower = new RainwormPower();
  328. rainwormPower.powerSetting(volt, Current);//设置输出电压和限制电流
  329. rainwormPower.powerOnoff(RainwormPower.State.ON);//设置蚯蚓电源输出
  330. rainwormPower.portClose();
  331. ShowMessage(MsgType.Info, string.Format("打开内部蚯蚓电源."));
  332. }
  333. TransmitterSerialPort SerialClient = new TransmitterSerialPort();
  334. int ControlDelay = currFileNode.Tps.TestNodes[0].Parameters.GetParameter<int>("控制延时");
  335. currFileNode.Tps.ControlDelay = ControlDelay;
  336. task = new Task(new Action(() => {
  337. //执行测试过程
  338. //currFileNode.Tps.Start(isOrderByChannel);
  339. SerialClient.SerialOpen(CfigComParas.GetComPort("1"));//获取config下的串口控制中的串口号,用于切频点的串口
  340. ShowMessage(MsgType.Info, string.Format("打开串口."));
  341. currFileNode.Tps.SerialClient = SerialClient;
  342. #region 根据频点来测指标
  343. //for (int point = 0; point < FrequencyNumber; point++)//频点总数
  344. //{
  345. //FourthByte = Convert.ToByte(CfigComParas.GetFourthByte((point + 1).ToString()), 16);
  346. //currFileNode.Tps.FourthByte = FourthByte;
  347. //double CenterFreq = double.Parse(CfigComParas.Getfreqpoint((point + 1).ToString()));
  348. //for (int i = 0; i < currFileNode.Tps.TestNodes.Count; i++)
  349. //{
  350. // currFileNode.Tps.TestNodes[i].PointIndex = point;
  351. // currFileNode.Tps.TestNodes[i].CenterFreq = CenterFreq;
  352. // //currFileNode.Tps.TestNodes[i].PointTotal = currFileNode.Tps.TestNodes.Count;
  353. // currFileNode.Tps.TestNodes[i].PointTotal = FrequencyNumber;
  354. //}
  355. //if (IsRuning == false)
  356. //{
  357. // //控制断电
  358. // if (currFileNode.Tps.Product.Contains("YZH16A"))//针对YZH16A的产品
  359. // {
  360. // SerialClient.DUT_Transmitter_Ctrol(0x00, 0x00, 0x55);
  361. // }
  362. // else
  363. // {
  364. // SerialClient.DUT_Transmitter_Ctrol1(0x00, 0x00);
  365. // }
  366. // SerialClient.SerialClose();
  367. // DCPower.Write("GLOBal:OUTPut:STATe 0\n"); DCPower.Query("*OPC?\n");
  368. // ShowMessage(MsgType.Info, string.Format("关闭6YYC信号源,关闭串口,关闭TDK电源."));
  369. // return;
  370. //}
  371. ////控制
  372. //if (currFileNode.Tps.Product.Contains("YZH16A"))//针对YZH16A的产品
  373. //{
  374. // SerialClient.DUT_Transmitter_Ctrol(ThridByte, FourthByte, 0x55);
  375. //}
  376. //else
  377. //{
  378. // SerialClient.DUT_Transmitter_Ctrol1(ThridByte, FourthByte);
  379. //}
  380. //ShowMessage(MsgType.Info, string.Format("发送串口指令EB 90 {0} {1}.", ThridByte, FourthByte));
  381. //testMin = TimesCounter.ElapsedMilliseconds/1000f / 60f;
  382. //Thread.Sleep(ControlDelay);//单位ms
  383. //ShowMessage(MsgType.Info, string.Format("延时{0}ms.", ControlDelay));
  384. //this.BeginInvoke(new Action(() =>
  385. //{
  386. // labRemainTime.Text = $"第{point + 1}个频点[{CenterFreq}]MHz测试,共{FrequencyNumber}个频点,耗时{Math.Round(testMin, 2)}Min。";
  387. //}));
  388. //}
  389. string[] ProductSeries = new string[tbSerials.Items.Count];
  390. tbSerials.Items.CopyTo(ProductSeries, 0);
  391. currFileNode.Tps.Start(isOrderByChannel, ProductSeries, DCPower, rainwormPower, SerialClient, CfigComParas);
  392. TimesCounter.Stop();
  393. testMin = TimesCounter.ElapsedMilliseconds / 1000f / 60f;
  394. this.BeginInvoke(new Action(() => {
  395. labRemainTime.Text = $"测试结束,共计耗时{Math.Round(testMin,2)}分钟";
  396. }));
  397. #endregion
  398. //控制断电
  399. if (currFileNode.Tps.Product.Contains("YZH16A"))//针对YZH16A的产品
  400. {
  401. SerialClient.DUT_Transmitter_Ctrol(0x00, 0x00, 0x55);//todo:掉电控制
  402. }
  403. else
  404. {
  405. SerialClient.DUT_Transmitter_Ctrol1(0x00, 0x00);//todo:掉电控制
  406. }
  407. SerialClient.SerialClose();//需要取消注释
  408. if (tbSerials.Items.Count > 1)//如果测试台数大于1,则使用外部TDK电源
  409. {
  410. DCPower.Write("GLOBal:OUTPut:STATe 0\n"); DCPower.Query("*OPC?\n");//需要取消注释
  411. ShowMessage(MsgType.Info, string.Format("关闭6YYC信号源,关闭串口,关闭外部TDK电源."));
  412. }
  413. else
  414. {
  415. rainwormPower.powerOnoff(RainwormPower.State.OFF);//设置蚯蚓电源输出
  416. ShowMessage(MsgType.Info, string.Format("关闭6YYC信号源,关闭串口,关闭内部蚯蚓电源."));
  417. }
  418. this.Invoke(new Action(() => {
  419. BtnLoadTpsConfig.Enabled = true;
  420. BtnStart.Enabled = true;
  421. tbSerials.Enabled = true;
  422. }));
  423. }));
  424. task.Start();
  425. }
  426. public void DataTableFlush(DataTable data)
  427. {
  428. this.Invoke(new Action(() => {
  429. dgvTestData.DataSource = null;
  430. dgvTestData.DataSource = data;
  431. }));
  432. }
  433. private void BtnStop_Click(object sender, EventArgs e)
  434. {
  435. MainTps tps = new MainTps();
  436. CommonVisaResource DCPower = new CommonVisaResource();
  437. //获取仪器
  438. //var DC = tps.GetDevice("程控电源");
  439. currFileNode.Tps.Stop();
  440. IsRuning = false;
  441. //if(task != null && task.IsCompleted == false)
  442. //{
  443. // //等待任务退出
  444. // task.Wait();
  445. //}
  446. BtnStart.Enabled = true;
  447. BtnLoadTpsConfig.Enabled = true;
  448. labRemainTime.Text = $"已停止测试。";
  449. //DC.Write("关闭电源");
  450. }
  451. private void BtnDevice_Click(object sender, EventArgs e)
  452. {
  453. if (currFileNode != null)
  454. {
  455. //点开按钮前检查仪器状态,并根据状态来显示不同背景颜色
  456. currFileNode.Tps.CheckDevices();
  457. }
  458. frmDevice.ShowDialog();
  459. }
  460. private void BtnMessage_Click(object sender, EventArgs e)
  461. {
  462. frmMsg.ShowDialog();
  463. errorCount = 0;
  464. BtnMessage.ForeColor = Color.Black;
  465. BtnMessage.Text = "消息";
  466. }
  467. private void advTree1_NodeDoubleClick(object sender, DevComponents.AdvTree.TreeNodeMouseEventArgs e)
  468. {
  469. //打开注释,则启用各测试指标的各自界面,否则只用公共界面
  470. //if(e.Node.Tag != null)
  471. //{
  472. // TestNode node = (TestNode)e.Node.Tag;
  473. // //没有界面的就只清除显示
  474. // if (node.TestModel.UC == null)
  475. // panel1.Controls.Clear();
  476. // //相同的界面不做处理
  477. // if (panel1.Controls.Count > 0 && panel1.Controls[0] == node.TestModel.UC)
  478. // return;
  479. // panel1.Controls.Clear();
  480. // panel1.Controls.Add(node.TestModel.UC);
  481. // node.TestModel.UC.Dock = DockStyle.Fill;
  482. // node.TestModel.UC.Visible = true;
  483. //}
  484. }
  485. //树形控件按通道分类
  486. private void tsmChannel_Click(object sender, EventArgs e)
  487. {
  488. displayTree(true);
  489. }
  490. //树形控件按指标分类
  491. private void tmsTestNode_Click(object sender, EventArgs e)
  492. {
  493. displayTree(false);
  494. }
  495. bool treeCanSelect = true;
  496. private void tsmSelectAll_Click(object sender, EventArgs e)
  497. {
  498. checkAllNode(true);
  499. }
  500. private void tsmUnSelecteAll_Click(object sender, EventArgs e)
  501. {
  502. checkAllNode(false);
  503. }
  504. //选或者反选所有节点
  505. void checkAllNode(bool isChecked)
  506. {
  507. treeCanSelect = false;
  508. foreach (DevComponents.AdvTree.Node node in advTree1.Nodes)
  509. {
  510. node.Checked = isChecked;
  511. if (node.Nodes.Count > 0)
  512. {
  513. foreach (DevComponents.AdvTree.Node child in node.Nodes)
  514. {
  515. child.Checked = isChecked;
  516. }
  517. }
  518. }
  519. treeCanSelect = true;
  520. }
  521. /// <summary>
  522. /// 显示测试指标的树结构
  523. /// </summary>
  524. /// <param name="isOrderByChannel">是否按通道来显示</param>
  525. void displayTree(bool isOrderByChannel)
  526. {
  527. this.isOrderByChannel = isOrderByChannel;
  528. advTree1.BeginUpdate();
  529. treeCanSelect = false;
  530. advTree1.Nodes.Clear();
  531. IEnumerable<string> parents = null;
  532. if(isOrderByChannel)
  533. {
  534. parents = (from x in currFileNode.Tps.TestNodes select x.Channel).ToList().Distinct();
  535. }
  536. else
  537. {
  538. parents = (from x in currFileNode.Tps.TestNodes select x.Name).ToList().Distinct();
  539. }
  540. if (parents == null)
  541. return;
  542. List<TestNode> childs = null;
  543. foreach (string chName in parents)
  544. {
  545. DevComponents.AdvTree.Node parent = new DevComponents.AdvTree.Node();
  546. parent.Text = chName;
  547. parent.CheckBoxVisible = true;
  548. parent.Tag = null;
  549. if (isOrderByChannel)
  550. {
  551. childs = currFileNode.Tps.TestNodes.Where(x => x.Channel == chName).ToList();
  552. }
  553. else
  554. {
  555. childs = currFileNode.Tps.TestNodes.Where(x => x.Name == chName).ToList();
  556. }
  557. foreach (TestNode node in childs)
  558. {
  559. DevComponents.AdvTree.Node treeNode = new DevComponents.AdvTree.Node();
  560. if (isOrderByChannel)
  561. {
  562. treeNode.Text = node.Name;
  563. }
  564. else
  565. {
  566. treeNode.Text = node.Channel;
  567. }
  568. treeNode.CheckBoxVisible = true;
  569. if (node.IsSelected)
  570. {
  571. treeNode.Checked = true;
  572. parent.Checked = true;
  573. }
  574. treeNode.Tag = node;
  575. parent.Nodes.Add(treeNode);
  576. }
  577. advTree1.Nodes.Add(parent);
  578. }
  579. //如果父节点只有一个,即只有一个通道,则不显示通道
  580. if(advTree1.Nodes.Count == 1)
  581. {
  582. DevComponents.AdvTree.Node root = advTree1.Nodes[0];
  583. advTree1.Nodes.Clear();
  584. if (root.Nodes.Count == 1)
  585. {
  586. advTree1.Nodes.Add(root.Nodes[0]);
  587. }
  588. else
  589. {
  590. foreach (DevComponents.AdvTree.Node item in root.Nodes)
  591. {
  592. advTree1.Nodes.Add(item);
  593. }
  594. }
  595. }
  596. treeCanSelect = true;
  597. advTree1.EndUpdate();
  598. advTree1.Refresh();
  599. advTree1.ExpandAll();
  600. }
  601. /// <summary>
  602. /// 父节点全选或者反选,子节点采用一致的动作
  603. /// </summary>
  604. /// <param name="sender"></param>
  605. /// <param name="e"></param>
  606. private void advTree1_AfterCheck(object sender, DevComponents.AdvTree.AdvTreeCellEventArgs e)
  607. {
  608. if(treeCanSelect && e.Cell.Parent.Tag == null)
  609. {
  610. //表明选到了顶层,把子节点的选中状态和当前一致
  611. foreach (DevComponents.AdvTree.Node node in e.Cell.Parent.Nodes)
  612. {
  613. node.Checked = e.Cell.Checked;
  614. }
  615. }
  616. else if(e.Cell.Parent.Tag != null)
  617. {
  618. TestNode node = (TestNode)e.Cell.Parent.Tag;
  619. node.IsSelected = e.Cell.Checked;
  620. }
  621. }
  622. public class ConfigParameter
  623. {
  624. /// <summary>
  625. /// 设置过压保护
  626. /// </summary>
  627. public string SetOverVoltProtect { set; get; }
  628. /// <summary>
  629. /// 设置电压
  630. /// </summary>
  631. public double SetVolt { set; get; }
  632. /// <summary>
  633. /// 设置电流
  634. /// </summary>
  635. public double SetCurrent { set; get; }
  636. }
  637. private void dgvTestData_CellContentClick(object sender, DataGridViewCellEventArgs e)
  638. {
  639. }
  640. private void tbTester_TextChanged(object sender, EventArgs e)
  641. {
  642. }
  643. /// <summary>
  644. /// 打开调试界面事件处理
  645. /// </summary>
  646. /// <param name="sender"></param>
  647. /// <param name="e"></param>
  648. private void btnDebugging_Click(object sender, EventArgs e)
  649. {
  650. DebuggingForm debuggingForm = new DebuggingForm();
  651. debuggingForm.Show();
  652. }
  653. /// <summary>
  654. /// 产品编号框添加、插入、删除事件处理
  655. /// </summary>
  656. /// <param name="sender"></param>
  657. /// <param name="e"></param>
  658. private void tbSerials_KeyDown(object sender, KeyEventArgs e)
  659. {
  660. if (e.KeyCode == Keys.Enter)
  661. {
  662. if (tbSerials.Text != "")
  663. {
  664. string newItem = tbSerials.Text.Trim();
  665. bool flag = false;
  666. for (int i = 0; i < tbSerials.Items.Count; i++)
  667. {
  668. if (string.Compare(newItem, tbSerials.Items[i].ToString()) == 0)
  669. {
  670. flag = true;
  671. this.BackColor = Color.Blue;
  672. MessageBox.Show("已经有相同项,添加无效");
  673. }
  674. }
  675. if (flag == false)
  676. {
  677. if (tbSerials.Items.Count < 8)
  678. {
  679. tbSerials.Items.Add(newItem);
  680. tbSerials.Text = "";
  681. }
  682. else
  683. {
  684. MessageBox.Show("已有8套产品的编号,添加无效");
  685. }
  686. }
  687. }
  688. else
  689. {
  690. MessageBox.Show("未输入产品编号,添加无效");
  691. }
  692. }
  693. if(e.KeyCode == Keys.Insert)
  694. {
  695. if (tbSerials.Items.Count != 0)
  696. {
  697. if (tbSerials.SelectedItem != null)
  698. {
  699. string strItem = tbSerials.SelectedItem.ToString();
  700. if (tbSerials.Text != "")
  701. {
  702. string newItem = tbSerials.Text.Trim();
  703. bool flag = false;
  704. for (int i = 0; i < tbSerials.Items.Count; i++)
  705. {
  706. if (string.Compare(newItem, tbSerials.Items[i].ToString()) == 0)
  707. {
  708. flag = true;
  709. this.BackColor = Color.Blue;
  710. MessageBox.Show("已经有相同项,插入无效");
  711. }
  712. }
  713. if (flag == false)
  714. {
  715. if (tbSerials.Items.Count < 8)
  716. {
  717. tbSerials.Items.Insert(tbSerials.Items.IndexOf(strItem), newItem); ;
  718. tbSerials.Text = "";
  719. }
  720. else
  721. {
  722. MessageBox.Show("已有8套产品的编号,插入无效");
  723. }
  724. }
  725. }
  726. else
  727. {
  728. MessageBox.Show("未输入产品编号,插入无效");
  729. }
  730. }
  731. else
  732. {
  733. MessageBox.Show("未选中需要插入的位置,插入无效");
  734. }
  735. }
  736. else
  737. {
  738. MessageBox.Show("产品编号为空,插入无效");
  739. }
  740. }
  741. if(e.KeyCode == Keys.Delete)
  742. {
  743. if (tbSerials.Items.Count != 0)
  744. {
  745. if (tbSerials.SelectedItem != null)
  746. {
  747. string strItem = tbSerials.SelectedItem.ToString();
  748. DialogResult selsecltresult;
  749. selsecltresult = MessageBox.Show("是否删除当前编号?", "提示", MessageBoxButtons.OKCancel);
  750. if (selsecltresult == DialogResult.OK)
  751. {
  752. tbSerials.Items.Remove(strItem);
  753. if (tbSerials.Items.Count != 0 )
  754. {
  755. tbSerials.SelectedItem = tbSerials.Items[0];
  756. }
  757. }
  758. }
  759. else
  760. {
  761. MessageBox.Show("未选中需要删除的产品编号,删除无效");
  762. }
  763. }
  764. else
  765. {
  766. MessageBox.Show("产品编号为空,删除无效");
  767. }
  768. }
  769. if(e.KeyCode == Keys.Escape)
  770. {
  771. if (tbSerials.Items.Count != 0)
  772. {
  773. DialogResult selsecltresult;
  774. selsecltresult = MessageBox.Show("是否删除全部编号?", "提示", MessageBoxButtons.OKCancel);
  775. if (selsecltresult == DialogResult.OK)
  776. {
  777. tbSerials.Items.Clear();
  778. }
  779. }
  780. else
  781. {
  782. MessageBox.Show("产品编号为空,删除无效");
  783. }
  784. }
  785. }
  786. }
  787. }