FormHOZMain.cs 28 KB

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