FormHOZMain.cs 32 KB

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