FormHOZMain.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686
  1. using FileManager;
  2. using MeasureData;
  3. using MeasureThread;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.ComponentModel;
  7. using System.Configuration;
  8. using System.Data;
  9. using System.Drawing;
  10. using System.IO;
  11. using System.Linq;
  12. using System.Runtime.InteropServices;
  13. using System.Text;
  14. using System.Threading.Tasks;
  15. using System.Windows.Forms;
  16. using static MeasureThread.ThreadStatusEventArgs;
  17. namespace HOZProject
  18. {
  19. public partial class FormHOZMain : Form
  20. {
  21. #region 成员变量
  22. public BackgroundWorker m_BackgroundWorker;// 申明后台对象
  23. /// <summary>
  24. /// 测量文件
  25. /// </summary>
  26. public MeasureFile m_MeasureFile;
  27. /// 测量线程
  28. public Measure m_Ms;
  29. /// <summary>
  30. /// 显示日志窗体
  31. /// </summary>
  32. Form m_FormLog = null;
  33. /// <summary>
  34. /// 显示实例化窗体
  35. /// </summary>
  36. Form m_FormInit = null;
  37. /// <summary>
  38. /// 是否已保存
  39. /// </summary>
  40. public bool IsSave = false;
  41. /// <summary>
  42. /// 初始化用户控件
  43. /// </summary>
  44. UControl_Init uControl_Init = null;
  45. /// <summary>
  46. /// 日志用户控件
  47. /// </summary>
  48. UControl_Log ucLog = null;
  49. //流程控制
  50. public int m_MeasureType = (int)MeasureMsgManage.measureType.FIB;
  51. //是否关闭窗体标识
  52. public bool IsClose = false;
  53. Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
  54. #endregion
  55. #region 构造函数
  56. public FormHOZMain()
  57. {
  58. InitializeComponent();
  59. //在线程操作过程中,可以设置控件属性
  60. Control.CheckForIllegalCrossThreadCalls = false;
  61. m_BackgroundWorker = new BackgroundWorker(); // 实例化后台对象
  62. m_BackgroundWorker.WorkerReportsProgress = true; // 设置可以通告进度
  63. m_BackgroundWorker.WorkerSupportsCancellation = true; // 设置可以取消
  64. m_BackgroundWorker.DoWork += new DoWorkEventHandler(DoWork);
  65. m_BackgroundWorker.ProgressChanged += new ProgressChangedEventHandler(UpdateProgress);
  66. m_BackgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(CompletedWork);
  67. LogManager.InitManulLog();
  68. }
  69. #endregion
  70. #region 测量线程
  71. void DoWork(object sender, DoWorkEventArgs e)
  72. {
  73. m_Ms = new Measure(ConfigurationManager.AppSettings["WebServerIP"].ToString(),
  74. ConfigurationManager.AppSettings["WebServerPort"].ToString(),
  75. ConfigurationManager.AppSettings["WebServerUrl"].ToString());
  76. m_MeasureFile.MParam.AutoFocus.UP = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_UP"].ToString());
  77. m_MeasureFile.MParam.AutoFocus.Down = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_Down"].ToString());
  78. m_MeasureFile.MParam.AutoFocus.Step = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_Step"].ToString());
  79. m_MeasureFile.MParam.AutoFocus.Range = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_Range"].ToString());
  80. m_MeasureFile.MParam.AutoFocus.fStep = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_FStep"].ToString());
  81. m_Ms.InitMeas(m_MeasureFile);
  82. m_Ms.SendThreadStatus += new ThreadStatusHandler(displayMessage); //注册事件
  83. m_Ms.SendCutHolesStatus += new CutHolesStatusHandler(displayCutHoleMessage); //注册事件
  84. //设置控件操作
  85. SetWinControlMeasureState(false);
  86. //自动测量的全过程
  87. m_Ms.DoMeasure();
  88. //定位
  89. //切割
  90. //分析位置
  91. //截面
  92. }
  93. public void displayMessage(object sender, ThreadStatusEventArgs e)
  94. {
  95. //主界面显示内容
  96. this.BeginInvoke((Action)delegate
  97. {
  98. this.listmsg.Items.Add(e.HoleName +"_" + e.Time.ToString() + "_"+ e.Message + "_" + e.State );
  99. //显示流程中对应编号的内容
  100. MeasureMsgManage.ShowMsgContent(this, e);
  101. AddLogListInfo(e);
  102. });
  103. }
  104. public void displayCutHoleMessage(object sender, CutHolesStatusEventArgs e)
  105. {
  106. //主界面显示内容
  107. this.BeginInvoke((Action)delegate
  108. {
  109. //this.listmsg.Items.Add(e.HoleName.ToString() + e.State);
  110. ChangeCutHoleState(e.HoleName.ToString(), Convert.ToInt32(e.State));
  111. });
  112. }
  113. void UpdateProgress(object sender, ProgressChangedEventArgs e)
  114. {
  115. }
  116. void CompletedWork(object sender, RunWorkerCompletedEventArgs e)
  117. {
  118. //设置控件操作
  119. MessageBox.Show("线程已完成!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  120. SetWinControlMeasureState(true);
  121. }
  122. #endregion
  123. private void FormHOZMain_Load(object sender, EventArgs e)
  124. {
  125. //加载控件的点击事件
  126. this.Click += new EventHandler(FormHOZMain_Click);
  127. plFill.Click += new EventHandler(FormHOZMain_Click);
  128. plTop.Click += new EventHandler(FormHOZMain_Click);
  129. plLeft.Click += new EventHandler(FormHOZMain_Click);
  130. plLeftContent.Click += new EventHandler(FormHOZMain_Click);
  131. pbImage.Click += new EventHandler(FormHOZMain_Click);
  132. //加载窗口移动事件
  133. this.MouseDown += new MouseEventHandler(FormHOZMain_MouseDown);
  134. //新建
  135. NewCreate();
  136. //实例初始化窗体对象
  137. if (uControl_Init == null)
  138. {
  139. uControl_Init = new UControl_Init(this);
  140. uControl_Init.ReloadConfig();
  141. }
  142. }
  143. #region 创建切孔列表信息
  144. /// <summary>
  145. /// 创建切孔列表信息
  146. /// </summary>
  147. /// <param name="ListCutHole"></param>
  148. public void CreateCutHoleList(List<CutHole> ListCutHole)
  149. {
  150. //清空左侧Panel中的切孔控件
  151. ClearPanelControls();
  152. for (int i = ListCutHole.Count - 1; i >= 0; i--)
  153. {
  154. UControl_CutHole ucCutHole = new UControl_CutHole(this);
  155. ucCutHole.Dock = DockStyle.Top;
  156. ucCutHole.CutHoleName = ListCutHole[i].HoleName;
  157. //显示切孔参数信息
  158. if (ucCutHole.UControl_ParaInfo == null)
  159. {
  160. ucCutHole.UControl_ParaInfo = new UControl_ParaInfo(this);
  161. }
  162. plPrarInfo.Width = ucCutHole.UControl_ParaInfo.Width;
  163. plPrarInfo.Height = ucCutHole.UControl_ParaInfo.Height;
  164. //设置当前样品的参数信息
  165. ucCutHole.UControl_ParaInfo.Name = ListCutHole[i].HoleName;
  166. ucCutHole.UControl_ParaInfo.CutHoleName = ListCutHole[i].HoleName;
  167. ucCutHole.UControl_ParaInfo.Position = ListCutHole[i].Position;
  168. ucCutHole.UControl_ParaInfo.StartTime = ListCutHole[i].START.ToString();
  169. ucCutHole.UControl_ParaInfo.EndTime = ListCutHole[i].END.ToString();
  170. ucCutHole.UControl_ParaInfo.State = ListCutHole[i].STATE.ToString();
  171. ucCutHole.UControl_ParaInfo.IsSwitch = ListCutHole[i].SWITCH;
  172. ucCutHole.UControl_ParaInfo.Dock = DockStyle.Fill;
  173. ucCutHole.UControl_ParaInfo.ShowParaInfo();
  174. plPrarInfo.Controls.Add(ucCutHole.UControl_ParaInfo);
  175. plLeftContent.Controls.Add(ucCutHole);
  176. }
  177. plPrarInfo.Visible = false;
  178. }
  179. #endregion
  180. //隐藏处理层
  181. private void FormHOZMain_Click(object sender, EventArgs e)
  182. {
  183. if (plPrarInfo.Visible)
  184. {
  185. plPrarInfo.Visible = false;
  186. }
  187. }
  188. #region 设置控件在线程过程中的编辑状态
  189. /// <summary>
  190. /// 设置控件在线程过程中的编辑状态
  191. /// </summary>
  192. /// <param name="cState"></param>
  193. public void SetWinControlMeasureState(bool cState)
  194. {
  195. pbNew.Enabled = cState;
  196. pbOpen.Enabled = cState;
  197. pbSave.Enabled = cState;
  198. pbInit.Enabled = cState;
  199. pbImportTemplateFile.Enabled = cState;
  200. pbLog.Enabled = cState;
  201. pbStop.Enabled = !cState;
  202. }
  203. #endregion
  204. #region 窗体中 线程开始 停止 最大化 最小化 关闭 按钮事件
  205. private void pbMin_MouseEnter(object sender, EventArgs e)
  206. {
  207. this.pbMin.BackgroundImage = global::HOZProject.Properties.Resources.Min_Blue;
  208. }
  209. private void pbMin_MouseLeave(object sender, EventArgs e)
  210. {
  211. this.pbMin.BackgroundImage = global::HOZProject.Properties.Resources.Min_Gray;
  212. }
  213. private void pbMax_MouseEnter(object sender, EventArgs e)
  214. {
  215. this.pbMax.BackgroundImage = global::HOZProject.Properties.Resources.Max_Blue;
  216. }
  217. private void pbMax_MouseLeave(object sender, EventArgs e)
  218. {
  219. this.pbMax.BackgroundImage = global::HOZProject.Properties.Resources.Max_Gray;
  220. }
  221. private void pbClose_MouseEnter(object sender, EventArgs e)
  222. {
  223. this.pbClose.BackgroundImage = global::HOZProject.Properties.Resources.exit_Red;
  224. }
  225. private void pbClose_MouseLeave(object sender, EventArgs e)
  226. {
  227. this.pbClose.BackgroundImage = global::HOZProject.Properties.Resources.exit_Gray;
  228. }
  229. private void pbStart_MouseEnter(object sender, EventArgs e)
  230. {
  231. this.pbStart.BackgroundImage = global::HOZProject.Properties.Resources.Start_Green;
  232. }
  233. private void pbStart_MouseLeave(object sender, EventArgs e)
  234. {
  235. this.pbStart.BackgroundImage = global::HOZProject.Properties.Resources.Start;
  236. }
  237. private void pbStop_MouseEnter(object sender, EventArgs e)
  238. {
  239. this.pbStop.BackgroundImage = global::HOZProject.Properties.Resources.Stop_Red;
  240. }
  241. private void pbStop_MouseLeave(object sender, EventArgs e)
  242. {
  243. this.pbStop.BackgroundImage = global::HOZProject.Properties.Resources.Stop;
  244. }
  245. private void pbClose_Click(object sender, EventArgs e)
  246. {
  247. if (m_Ms != null)
  248. {
  249. if (!m_Ms.key_stop)
  250. {
  251. if (MessageBox.Show("当前测量正在运行,是否关闭此窗体?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  252. {
  253. //线程停止变量
  254. m_Ms.key_stop = true;
  255. IsClose = true;
  256. lblStateMessage.Text = "正在关闭窗体...请等待";
  257. }
  258. return;
  259. }
  260. }
  261. if (MessageBox.Show("是否关闭此窗体?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  262. {
  263. this.Close();
  264. }
  265. }
  266. private void pbMin_Click(object sender, EventArgs e)
  267. {
  268. this.WindowState = FormWindowState.Minimized;
  269. }
  270. private void pbMax_Click(object sender, EventArgs e)
  271. {
  272. if (this.WindowState == FormWindowState.Maximized)
  273. {
  274. this.WindowState = FormWindowState.Normal;
  275. }
  276. else
  277. {
  278. this.WindowState = FormWindowState.Maximized;
  279. }
  280. //窗体据中
  281. this.StartPosition = FormStartPosition.CenterScreen;
  282. }
  283. #endregion
  284. #region 新建、保存、打开、初始化、导入配置、查看日志
  285. private void pbNew_Click(object sender, EventArgs e)
  286. {
  287. NewCreate();
  288. }
  289. private void NewCreate()
  290. {
  291. m_MeasureFile = new MeasureFile();
  292. if (!m_MeasureFile.New())
  293. {
  294. return;
  295. }
  296. else
  297. {
  298. //清空内容容器中的控件
  299. ClearPanelControls();
  300. }
  301. }
  302. private void pbSave_Click(object sender, EventArgs e)
  303. {
  304. if (m_MeasureFile == null)
  305. {
  306. MessageBox.Show("请新建一个测量文件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  307. }
  308. else
  309. {
  310. //保存测量文件
  311. if (m_MeasureFile.Save())
  312. {
  313. //获取测量文件所在路径
  314. string savePath = m_MeasureFile.FilePath;
  315. //数据库名称
  316. string dbFileName = "MeasureFile.db";
  317. //要复制的文件路径
  318. string pLocalFilePath = Application.StartupPath +"\\"+dbFileName;
  319. string pSaveFilePath = savePath + "\\" + dbFileName;//指定存储的路径
  320. if (File.Exists(pLocalFilePath))//必须判断要复制的文件是否存在
  321. {
  322. //三个参数分别是源文件路径,存储路径,若存储路径有相同文件是否替换
  323. File.Copy(pLocalFilePath, pSaveFilePath, true);
  324. }
  325. //将初始化中的参数,配置到测量参数中
  326. m_MeasureFile.MParam = uControl_Init.GetMeasureParamInfo();
  327. //设置已保存状态
  328. IsSave = true;
  329. }
  330. }
  331. }
  332. private void pbOpen_Click(object sender, EventArgs e)
  333. {
  334. }
  335. private void pbInit_Click(object sender, EventArgs e)
  336. {
  337. if (uControl_Init == null)
  338. {
  339. uControl_Init = new UControl_Init(this);
  340. uControl_Init.ReloadConfig();
  341. }
  342. if (m_FormInit == null)
  343. {
  344. m_FormInit = new Form();
  345. }
  346. m_FormInit.StartPosition = FormStartPosition.CenterScreen;
  347. m_FormInit.FormBorderStyle = FormBorderStyle.None;
  348. m_FormInit.Width = uControl_Init.Width;
  349. m_FormInit.Height = uControl_Init.Height;
  350. if (m_FormInit.Controls.Count == 0)
  351. {
  352. m_FormInit.Controls.Add(uControl_Init);
  353. }
  354. m_FormInit.ShowDialog();
  355. }
  356. private void pbImportTemplateFile_Click(object sender, EventArgs e)
  357. {
  358. Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
  359. string m_TemplateFilePath = config.AppSettings.Settings["TemplateFilePath"].Value.ToString();
  360. //判断保存的路径是否存在
  361. if (!Directory.Exists(m_TemplateFilePath))
  362. {
  363. //创建路径
  364. Directory.CreateDirectory(m_TemplateFilePath);
  365. }
  366. //打开默认路径
  367. OpenFileDialog openFileDialog = new OpenFileDialog();
  368. //设置默认打开路径(绝对路径)
  369. openFileDialog.InitialDirectory = m_TemplateFilePath;
  370. openFileDialog.Filter = "样品参数文件|*.cfg";
  371. if (openFileDialog.ShowDialog() == DialogResult.OK)
  372. {
  373. if (uControl_Init == null)
  374. {
  375. uControl_Init = new UControl_Init(this);
  376. }
  377. //设置选择的模板文件
  378. uControl_Init.ReadConfigPath = openFileDialog.FileName;
  379. //获取文件
  380. uControl_Init.ReadConfigInfo();
  381. }
  382. }
  383. private void pbLog_Click(object sender, EventArgs e)
  384. {
  385. m_FormLog = new Form();
  386. m_FormLog.StartPosition = FormStartPosition.CenterScreen;
  387. if (ucLog == null)
  388. {
  389. ucLog = new UControl_Log();
  390. }
  391. m_FormLog.FormBorderStyle = FormBorderStyle.None;
  392. m_FormLog.Width = ucLog.Width;
  393. m_FormLog.Height = ucLog.Height;
  394. ucLog.Name = "UControl_Log";
  395. //获取日志信息
  396. if (listmsg.Items.Count>0)
  397. {
  398. string[] strLog = new string[listmsg.Items.Count];
  399. for (int i = 0; i < listmsg.Items.Count; i++)
  400. {
  401. //赋值给数组
  402. strLog[i] = listmsg.Items[i].ToString();
  403. }
  404. ucLog.ShowProcessLogInfo(strLog);
  405. }
  406. m_FormLog.Controls.Add(ucLog);
  407. m_FormLog.ShowDialog();
  408. }
  409. //显示日志
  410. private void AddLogListInfo(ThreadStatusEventArgs e)
  411. {
  412. if (m_FormLog != null)
  413. {
  414. foreach (Control item in m_FormLog.Controls)
  415. {
  416. if (item is UserControl)
  417. {
  418. if (item.Name == "UControl_Log")
  419. {
  420. ucLog = (UControl_Log)item;
  421. //获取日志信息
  422. if (listmsg.Items.Count > 0)
  423. {
  424. string[] strLog = new string[listmsg.Items.Count];
  425. for (int i = 0; i < listmsg.Items.Count; i++)
  426. {
  427. //赋值给数组
  428. strLog[i] = listmsg.Items[i].ToString();
  429. }
  430. ucLog.ShowProcessLogInfo(strLog);
  431. }
  432. }
  433. }
  434. }
  435. }
  436. }
  437. #endregion
  438. #region 修改切孔状态
  439. /// <summary>
  440. /// 修改切孔状态
  441. /// </summary>
  442. /// <param name="cutHoleCode"></param>
  443. /// <param name="States"></param>
  444. private void ChangeCutHoleState(string CutHoleName, int States)
  445. {
  446. foreach (Control item in plLeftContent.Controls)
  447. {
  448. if (item is UserControl)
  449. {
  450. UControl_CutHole cutHole = (UControl_CutHole)item;
  451. if (cutHole.CutHoleName == CutHoleName)
  452. {
  453. Button btnCutHole = (Button)cutHole.Controls.Find("btnCutHole", false)[0];
  454. switch (States)
  455. {
  456. //运行中
  457. case (int)ThreadState.InProcess:
  458. btnCutHole.BackColor = Color.Yellow;
  459. ChangeCutHoleMeasureState(CutHoleName, States);
  460. break;
  461. //等待
  462. case (int)ThreadState.Waiting:
  463. btnCutHole.BackColor = Color.Yellow;
  464. ChangeCutHoleMeasureState(CutHoleName, States);
  465. break;
  466. //准备
  467. case (int)ThreadState.Ready:
  468. btnCutHole.BackColor = Color.Yellow;
  469. ChangeCutHoleMeasureState(CutHoleName, States);
  470. break;
  471. //失败
  472. case (int)ThreadState.Failed:
  473. btnCutHole.BackColor = Color.Red;
  474. ChangeCutHoleMeasureState(CutHoleName, States);
  475. break;
  476. //完成
  477. case (int)ThreadState.Success:
  478. btnCutHole.BackColor = Color.GreenYellow;
  479. //修改切孔状态
  480. ChangeCutHoleMeasureState(CutHoleName, States);
  481. break;
  482. }
  483. break;
  484. }
  485. }
  486. }
  487. }
  488. #endregion
  489. #region 修改切孔状态
  490. protected void ChangeCutHoleMeasureState(string CutHoleName, int States)
  491. {
  492. if (plPrarInfo.Controls.Count > 0)
  493. {
  494. foreach (Control item in plPrarInfo.Controls)
  495. {
  496. if (item is UserControl)
  497. {
  498. if (item.Name == CutHoleName)
  499. {
  500. UControl_ParaInfo uControl_ParaInfo = (UControl_ParaInfo)item;
  501. switch (States)
  502. {
  503. //准备
  504. case (int)ThreadState.Ready:
  505. //修改切孔状态
  506. uControl_ParaInfo.lblShowState.Text = "准备";
  507. break;
  508. //等待
  509. case (int)ThreadState.Waiting:
  510. //修改切孔状态
  511. uControl_ParaInfo.lblShowState.Text = "等待";
  512. break;
  513. //进行中
  514. case (int)ThreadState.InProcess:
  515. //修改切孔状态
  516. uControl_ParaInfo.lblShowState.Text = "进行中";
  517. break;
  518. //完成
  519. case (int)ThreadState.Success:
  520. //修改切孔状态
  521. uControl_ParaInfo.lblShowState.Text = "完成";
  522. break;
  523. //失败
  524. case (int)ThreadState.Failed:
  525. uControl_ParaInfo.lblShowState.Text = "失败";
  526. break;
  527. }
  528. break;
  529. }
  530. }
  531. }
  532. }
  533. }
  534. #endregion
  535. #region 拖动无窗体的控件
  536. [DllImport("user32.dll")]//拖动无窗体的控件
  537. public static extern bool ReleaseCapture();
  538. [DllImport("user32.dll")]
  539. public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
  540. public const int WM_SYSCOMMAND = 0x0112;
  541. public const int SC_MOVE = 0xF010;
  542. public const int HTCAPTION = 0x0002;
  543. private void FormHOZMain_MouseDown(object sender, MouseEventArgs e)
  544. {
  545. if (this.WindowState == FormWindowState.Normal)
  546. {
  547. //拖动窗体
  548. ReleaseCapture();
  549. SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);
  550. }
  551. }
  552. #endregion
  553. #region 开始、结束线程事件
  554. private void pbStart_Click(object sender, EventArgs e)
  555. {
  556. if (m_MeasureFile == null)
  557. {
  558. MessageBox.Show("请新建一个测量文件", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  559. //listmsg.Items.Clear();
  560. }
  561. else
  562. {
  563. if (IsSave)
  564. {
  565. if (m_BackgroundWorker.IsBusy)
  566. {
  567. MessageBox.Show("线程已经运行!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
  568. return;
  569. }
  570. m_BackgroundWorker.RunWorkerAsync(this);
  571. }
  572. else
  573. {
  574. MessageBox.Show("请保存当前测量文件", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  575. }
  576. }
  577. }
  578. private void pbStop_Click(object sender, EventArgs e)
  579. {
  580. if (m_Ms != null)
  581. {
  582. if (MessageBox.Show("是否停止当前测量?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question)== DialogResult.Yes)
  583. {
  584. //线程停止变量
  585. m_Ms.key_stop = true;
  586. }
  587. }
  588. }
  589. #endregion
  590. #region 清空内容容器中的控件
  591. /// <summary>
  592. /// 清空内容容器中的控件
  593. /// </summary>
  594. private void ClearPanelControls()
  595. {
  596. //清空内容容器中的控件
  597. plLeftContent.Controls.Clear();
  598. plPrarInfo.Controls.Clear();
  599. }
  600. #endregion
  601. #region 测试修改切孔中流程状态
  602. private void button1_Click(object sender, EventArgs e)
  603. {
  604. if (plPrarInfo.Controls.Count > 0)
  605. {
  606. string name = textBox1.Text;
  607. string code = textBox2.Text;
  608. bool state = Convert.ToBoolean(comboBox1.Text);
  609. foreach (Control item in plPrarInfo.Controls)
  610. {
  611. if (item is UserControl)
  612. {
  613. if (item.Name == name)
  614. {
  615. UControl_ParaInfo uControl_ParaInfo = (UControl_ParaInfo)item;
  616. TimeLineItem[] ParaItem = uControl_ParaInfo.TlItem;
  617. foreach (TimeLineItem tlItem in ParaItem)
  618. {
  619. if (tlItem.Code == code)
  620. {
  621. tlItem.State = Convert.ToInt32(state);
  622. break;
  623. }
  624. }
  625. uControl_ParaInfo.TimeLineInvalidate();
  626. break;
  627. }
  628. }
  629. }
  630. }
  631. }
  632. #endregion
  633. }
  634. }