FormHOZMain.cs 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967
  1. using FileManager;
  2. using MeasureData;
  3. using MeasureThread;
  4. using SenseShield;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.ComponentModel;
  8. using System.Configuration;
  9. using System.Data;
  10. using System.Diagnostics;
  11. using System.Drawing;
  12. using System.Drawing.Drawing2D;
  13. using System.IO;
  14. using System.Linq;
  15. using System.Runtime.InteropServices;
  16. using System.Text;
  17. //using SenseShield;
  18. using System.Threading.Tasks;
  19. using System.Windows.Forms;
  20. using static MeasureThread.ThreadStatusEventArgs;
  21. namespace HOZProject
  22. {
  23. public partial class FormHOZMain : Form
  24. {
  25. #region 控制窗体可以调整大小用
  26. const int HTLEFT = 10;
  27. const int HTRIGHT = 11;
  28. const int HTTOP = 12;
  29. const int HTTOPLEFT = 13;
  30. const int HTTOPRIGHT = 14;
  31. const int HTBOTTOM = 15;
  32. const int HTBOTTOMLEFT = 0x10;
  33. const int HTBOTTOMRIGHT = 17;
  34. protected override void WndProc(ref Message m)
  35. {
  36. switch (m.Msg)
  37. {
  38. case 0x0084:
  39. base.WndProc(ref m);
  40. Point vPoint = new Point((int)m.LParam & 0xFFFF,
  41. (int)m.LParam >> 16 & 0xFFFF);
  42. vPoint = PointToClient(vPoint);
  43. if (vPoint.X <= 5)
  44. if (vPoint.Y <= 5)
  45. m.Result = (IntPtr)HTTOPLEFT;
  46. else if (vPoint.Y >= ClientSize.Height - 5)
  47. m.Result = (IntPtr)HTBOTTOMLEFT;
  48. else m.Result = (IntPtr)HTLEFT;
  49. else if (vPoint.X >= ClientSize.Width - 5)
  50. if (vPoint.Y <= 5)
  51. m.Result = (IntPtr)HTTOPRIGHT;
  52. else if (vPoint.Y >= ClientSize.Height - 5)
  53. m.Result = (IntPtr)HTBOTTOMRIGHT;
  54. else m.Result = (IntPtr)HTRIGHT;
  55. else if (vPoint.Y <= 5)
  56. m.Result = (IntPtr)HTTOP;
  57. else if (vPoint.Y >= ClientSize.Height - 5)
  58. m.Result = (IntPtr)HTBOTTOM;
  59. break;
  60. case 0x0201://鼠标左键按下的消息
  61. m.Msg = 0x00A1;//更改消息为非客户区按下鼠标
  62. m.LParam = IntPtr.Zero;//默认值
  63. m.WParam = new IntPtr(2);//鼠标放在标题栏内
  64. base.WndProc(ref m);
  65. break;
  66. default:
  67. base.WndProc(ref m);
  68. break;
  69. }
  70. }
  71. #endregion
  72. #region 成员变量
  73. private NLog.Logger log;
  74. /// <summary>
  75. /// 控制闪烁
  76. /// </summary>
  77. public static bool ControlFlicker;//控制流程闪烁
  78. public BackgroundWorker m_BackgroundWorker;// 申明后台对象
  79. /// <summary>
  80. /// 测量文件
  81. /// </summary>
  82. public MeasureFile m_MeasureFile;
  83. /// 测量线程
  84. public Measure m_Ms;
  85. /// <summary>
  86. /// 显示日志窗体
  87. /// </summary>
  88. Form m_FormLog = null;
  89. /// <summary>
  90. /// 显示实例化窗体
  91. /// </summary>
  92. FormMove m_FormInit = null;
  93. /// <summary>
  94. /// 是否已保存
  95. /// </summary>
  96. public bool IsSave = false;
  97. /// <summary>
  98. /// 初始化用户控件
  99. /// </summary>
  100. UControl_Init uControl_Init = null;
  101. /// <summary>
  102. /// 日志用户控件
  103. /// </summary>
  104. UControl_Log ucLog = null;
  105. //流程控制
  106. public int m_MeasureType = (int)MeasureMsgManage.measureType.FIB;
  107. //是否关闭窗体标识
  108. public bool IsClose = false;
  109. OTSMeasureOutputNlog logwin;
  110. Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
  111. #endregion
  112. #region 构造函数
  113. public FormHOZMain()
  114. {
  115. InitializeComponent();
  116. //在线程操作过程中,可以设置控件属性
  117. Control.CheckForIllegalCrossThreadCalls = false;
  118. m_BackgroundWorker = new BackgroundWorker(); // 实例化后台对象
  119. m_BackgroundWorker.WorkerReportsProgress = true; // 设置可以通告进度
  120. m_BackgroundWorker.WorkerSupportsCancellation = true; // 设置可以取消
  121. m_BackgroundWorker.DoWork += new DoWorkEventHandler(DoWork);
  122. m_BackgroundWorker.ProgressChanged += new ProgressChangedEventHandler(UpdateProgress);
  123. m_BackgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(CompletedWork);
  124. uControl_Init = new UControl_Init(this);
  125. //LogManager.InitManulLog();
  126. }
  127. #endregion
  128. #region 测量线程
  129. void DoWork(object sender, DoWorkEventArgs e)
  130. {
  131. try
  132. {
  133. m_Ms = new Measure(ConfigurationManager.AppSettings["WebServerIP"].ToString(),
  134. ConfigurationManager.AppSettings["WebServerPort"].ToString(),
  135. ConfigurationManager.AppSettings["WebServerUrl"].ToString());
  136. //SmartSEM远程路径
  137. m_Ms.RemoteELYPath =m_MeasureFile.MParam.RemoteELYPath;
  138. m_Ms.RemoteMLFPath = m_MeasureFile.MParam.RemoteMLFPath;
  139. m_Ms.InitMeasure(m_MeasureFile);
  140. //注册事件
  141. m_Ms.SendThreadStatus += new ThreadStatusHandler(displayMessage);
  142. //注册事件
  143. m_Ms.SendCutHolesStatus += new CutHolesStatusHandler(displayCutHoleMessage);
  144. //自动测量的全过程
  145. m_Ms.DoMeasure();
  146. }
  147. catch (Exception ex)
  148. {
  149. log.Error(ex.ToString(),false);
  150. }
  151. }
  152. public void displayMessage(object sender, ThreadStatusEventArgs e)
  153. {
  154. //主界面显示内容
  155. this.BeginInvoke((Action)delegate
  156. {
  157. this.listmsg.Items.Add(e.HoleName +"_" + e.Time.ToString() + "_"+ e.Message + "_" + e.State );
  158. //显示流程中对应编号的内容
  159. MeasureMsgManage.ShowMsgContent(this, e);
  160. AddLogListInfo(e);
  161. });
  162. }
  163. public void displayCutHoleMessage(object sender, CutHolesStatusEventArgs e)
  164. {
  165. //主界面显示内容
  166. this.BeginInvoke((Action)delegate
  167. {
  168. //修改切孔状态
  169. ChangeCutHoleState(e.HoleName.ToString(), Convert.ToInt32(e.State));
  170. });
  171. }
  172. void UpdateProgress(object sender, ProgressChangedEventArgs e)
  173. {
  174. }
  175. void CompletedWork(object sender, RunWorkerCompletedEventArgs e)
  176. {
  177. ControlFlicker = false;
  178. //设置控件操作
  179. MessageBox.Show("测量已完成!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  180. SetWinControlMeasureState(true);
  181. pbStop.Visible = false;
  182. pbStart.Visible = true;
  183. //UControl_ParaInfo uControl_ParaInfo=new UControl_ParaInfo()
  184. UControl_ParaInfo uControl_ParaInfo = new UControl_ParaInfo(this);
  185. uControl_ParaInfo.pbMeasure.Value = 100;
  186. uControl_ParaInfo.lblCompletedAmount.Text = "100%";
  187. }
  188. #endregion
  189. #region 窗体加载
  190. private void FormHOZMain_Load(object sender, EventArgs e)
  191. {
  192. try
  193. {
  194. DogDecrypting.decrypting(100);//参数为许可号
  195. //加载控件的点击事件
  196. this.Click += new EventHandler(FormHOZMain_Click);
  197. plFill.Click += new EventHandler(FormHOZMain_Click);
  198. plTop.Click += new EventHandler(FormHOZMain_Click);
  199. plLeft.Click += new EventHandler(FormHOZMain_Click);
  200. plLeftContent.Click += new EventHandler(FormHOZMain_Click);
  201. pbImage.Click += new EventHandler(FormHOZMain_Click);
  202. //加载窗口移动事件
  203. this.MouseDown += new MouseEventHandler(FormHOZMain_MouseDown);
  204. this.plTop.MouseDown += new MouseEventHandler(FormHOZMain_MouseDown);
  205. //新建
  206. m_MeasureFile = new MeasureFile();
  207. m_MeasureFile.MParam.GetMeasureParamFromConfigration() ;//读到参数对象中
  208. uControl_Init.DisplayInitialParam();//显示到界面上
  209. logwin = new OTSMeasureOutputNlog();
  210. logwin.Show();
  211. logwin.Height = this.Height;
  212. logwin.Left = this.Left - logwin.Width;
  213. logwin.Top = this.Top;
  214. NLog.Config.LoggingRule lr = NLog.LogManager.Configuration.LoggingRules.FirstOrDefault(
  215. r => r.Targets.Any(
  216. t => "control" == t.Name
  217. )
  218. );
  219. log = NLog.LogManager.GetCurrentClassLogger();
  220. this.Left = this.Location.X + logwin.Width / 2;
  221. }
  222. catch (Exception ex)
  223. {
  224. MessageBox.Show(ex.Message, "错误:", MessageBoxButtons.OK, MessageBoxIcon.Error);
  225. this.Close();
  226. }
  227. }
  228. #endregion
  229. #region 创建切孔列表信息
  230. /// <summary>
  231. /// 创建切孔列表信息
  232. /// </summary>
  233. /// <param name="ListCutHole"></param>
  234. public void CreateCutHoleList(List<CutHole> ListCutHole)
  235. {
  236. //清空左侧Panel中的切孔控件
  237. ClearPanelControls();
  238. for (int i = ListCutHole.Count - 1; i >= 0; i--)
  239. {
  240. UControl_CutHole ucCutHole = new UControl_CutHole(this);
  241. ucCutHole.Dock = DockStyle.Top;
  242. ucCutHole.CutHoleName = ListCutHole[i].HoleName;
  243. //显示切孔参数信息
  244. if (ucCutHole.UControl_ParaInfo == null)
  245. {
  246. ucCutHole.UControl_ParaInfo = new UControl_ParaInfo(this);
  247. }
  248. plPrarInfo.Width = ucCutHole.UControl_ParaInfo.Width;
  249. plPrarInfo.Height = ucCutHole.UControl_ParaInfo.Height;
  250. //设置当前样品的参数信息
  251. string CutHoleName = ListCutHole[i].HoleName;
  252. ucCutHole.UControl_ParaInfo.Name = CutHoleName;
  253. ucCutHole.UControl_ParaInfo.CutHoleName = CutHoleName;
  254. ucCutHole.UControl_ParaInfo.Position = ListCutHole[i].Position;
  255. ucCutHole.UControl_ParaInfo.StartTime = ListCutHole[i].START.ToString();
  256. ucCutHole.UControl_ParaInfo.EndTime = ListCutHole[i].END.ToString();
  257. int state = (int)ListCutHole[i].STATE;
  258. ucCutHole.UControl_ParaInfo.State = state;
  259. ucCutHole.UControl_ParaInfo.IsSwitch = ListCutHole[i].SWITCH;
  260. ucCutHole.UControl_ParaInfo.ShowParaInfo();
  261. this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
  262. plPrarInfo.Controls.Add(ucCutHole.UControl_ParaInfo);
  263. plLeftContent.Controls.Add(ucCutHole);
  264. ChangeCutHoleState(CutHoleName, state);
  265. }
  266. plPrarInfo.Visible = false;
  267. }
  268. #endregion
  269. #region 隐藏处理层
  270. //隐藏处理层
  271. private void FormHOZMain_Click(object sender, EventArgs e)
  272. {
  273. if (plPrarInfo.Visible)
  274. {
  275. plPrarInfo.Visible = false;
  276. }
  277. }
  278. #endregion
  279. #region 设置控件在线程过程中的编辑状态
  280. /// <summary>
  281. /// 设置控件在线程过程中的编辑状态
  282. /// </summary>
  283. /// <param name="cState"></param>
  284. public void SetWinControlMeasureState(bool cState)
  285. {
  286. pbNew.Enabled = cState;
  287. pbOpen.Enabled = cState;
  288. pbSave.Enabled = cState;
  289. // pbInit.Enabled = cState;
  290. pbImportTemplateFile.Enabled = cState;
  291. //pbLog.Enabled = cState;
  292. pbStart.Enabled = cState;
  293. pbStop.Enabled = !cState;
  294. //设置切孔是否执行
  295. foreach (Control item in plPrarInfo.Controls)
  296. {
  297. if (item is UserControl)
  298. {
  299. UControl_ParaInfo ucParaInfo = (UControl_ParaInfo)item;
  300. ucParaInfo.CkIsSwitch.Enabled = cState;
  301. }
  302. }
  303. }
  304. #endregion
  305. #region 窗体中 线程开始 停止 最大化 最小化 关闭 按钮事件
  306. private void pbMin_MouseEnter(object sender, EventArgs e)
  307. {
  308. this.pbMin.BackgroundImage = global::HOZProject.Properties.Resources.Min_2_;
  309. }
  310. private void pbMin_MouseLeave(object sender, EventArgs e)
  311. {
  312. this.pbMin.BackgroundImage = global::HOZProject.Properties.Resources.Min_2_;
  313. }
  314. private void pbMax_MouseEnter(object sender, EventArgs e)
  315. {
  316. this.pbMax.BackgroundImage = global::HOZProject.Properties.Resources.Max_2_;
  317. }
  318. private void pbMax_MouseLeave(object sender, EventArgs e)
  319. {
  320. this.pbMax.BackgroundImage = global::HOZProject.Properties.Resources.Max_2_;
  321. }
  322. private void pbClose_MouseEnter(object sender, EventArgs e)
  323. {
  324. this.pbClose.BackgroundImage = global::HOZProject.Properties.Resources.exit_2_;
  325. }
  326. private void pbClose_MouseLeave(object sender, EventArgs e)
  327. {
  328. this.pbClose.BackgroundImage = global::HOZProject.Properties.Resources.exit_2_;
  329. }
  330. private void pbStart_MouseEnter(object sender, EventArgs e)
  331. {
  332. //this.pbStart.BackgroundImage = global::HOZProject.Properties.Resources.StartMove;
  333. }
  334. private void pbStart_MouseLeave(object sender, EventArgs e)
  335. {
  336. //this.pbStart.BackgroundImage = global::HOZProject.Properties.Resources.Start_3_;
  337. }
  338. private void pbStop_MouseEnter(object sender, EventArgs e)
  339. {
  340. //this.pbStop.BackgroundImage = global::HOZProject.Properties.Resources.StopMove;
  341. }
  342. private void pbStop_MouseLeave(object sender, EventArgs e)
  343. {
  344. //this.pbStop.BackgroundImage = global::HOZProject.Properties.Resources.Stop;
  345. }
  346. private void pbClose_Click(object sender, EventArgs e)
  347. {
  348. try
  349. {
  350. if (m_Ms != null)
  351. {
  352. if (m_BackgroundWorker.IsBusy)
  353. {
  354. if (MessageBox.Show("当前测量正在运行,是否关闭此窗体?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  355. {
  356. //线程停止变量
  357. m_Ms.key_stop = true;
  358. IsClose = true;
  359. lblStateMessage.Text = "正在关闭窗体...请等待";
  360. pbClose.Enabled = false;
  361. ControlFlicker = false;
  362. }
  363. return;
  364. }
  365. }
  366. if (MessageBox.Show("是否关闭此窗体?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  367. {
  368. //m_MeasureFile.Save();
  369. this.Close();
  370. }
  371. }
  372. catch (Exception ex)
  373. {
  374. log.Error(ex.Message);
  375. }
  376. }
  377. private void pbMin_Click(object sender, EventArgs e)
  378. {
  379. this.WindowState = FormWindowState.Minimized;
  380. }
  381. private void pbMax_Click(object sender, EventArgs e)
  382. {
  383. if (this.WindowState == FormWindowState.Maximized)
  384. {
  385. this.WindowState = FormWindowState.Normal;
  386. }
  387. else
  388. {
  389. this.WindowState = FormWindowState.Maximized;
  390. }
  391. //窗体据中
  392. this.StartPosition = FormStartPosition.CenterScreen;
  393. }
  394. #endregion
  395. #region 新建、保存、打开、初始化、导入配置、查看日志
  396. private void pbNew_Click(object sender, EventArgs e)
  397. {
  398. m_MeasureFile.MParam.GetMeasureParamFromConfigration();
  399. }
  400. private void pbSave_Click(object sender, EventArgs e)
  401. {
  402. Saveclick();
  403. }
  404. public void Saveclick()
  405. {
  406. }
  407. private void pbOpen_Click(object sender, EventArgs e)
  408. {
  409. try
  410. {
  411. //打开默认路径
  412. OpenFileDialog openFileDialog = new OpenFileDialog();
  413. //设置筛选文件格式
  414. openFileDialog.Filter = "测量文件(*.msf)|*.msf";
  415. if (openFileDialog.ShowDialog() == DialogResult.OK)
  416. {
  417. //读取文件
  418. string measureFileNamePath = openFileDialog.FileName;
  419. m_MeasureFile.FileName = measureFileNamePath;
  420. m_MeasureFile.Open();
  421. List<CutHole> ListCutHole = m_MeasureFile.ListCutHole;
  422. //文件路径
  423. string CutHoleFilePath = m_MeasureFile.CutHoleFilePath;
  424. CreateCutHoleList(ListCutHole);
  425. ////保存测量文件
  426. //m_MeasureFile.Save();
  427. //设置已保存状态
  428. IsSave = true;
  429. }
  430. }
  431. catch (Exception ex)
  432. {
  433. log.Error(ex.Message);
  434. }
  435. }
  436. private void pbInit_Click(object sender, EventArgs e)
  437. {
  438. if (uControl_Init == null)
  439. {
  440. uControl_Init = new UControl_Init(this);
  441. //uControl_Init.ReloadConfig();
  442. }
  443. if (m_FormInit == null)
  444. {
  445. m_FormInit = new FormMove();
  446. }
  447. m_FormInit.StartPosition = FormStartPosition.CenterScreen;
  448. m_FormInit.FormBorderStyle = FormBorderStyle.None;
  449. m_FormInit.Width = uControl_Init.Width + 8;
  450. m_FormInit.Height = uControl_Init.Height + 8;
  451. if (m_FormInit.Controls.Count == 0)
  452. {
  453. uControl_Init.Location = new Point(4,4);
  454. m_FormInit.Controls.Add(uControl_Init);
  455. }
  456. m_FormInit.ShowDialog();
  457. //ConfigurationParameter();
  458. m_FormInit.Left = this.Left;
  459. }
  460. private void pictureBox1_Click(object sender, EventArgs e)
  461. {
  462. }
  463. private void pbImportTemplateFile_Click(object sender, EventArgs e)
  464. {
  465. Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
  466. string m_TemplateFilePath = config.AppSettings.Settings["TemplateFilePath"].Value.ToString();
  467. //判断保存的路径是否存在
  468. if (!Directory.Exists(m_TemplateFilePath))
  469. {
  470. ////创建路径
  471. //Directory.CreateDirectory(m_TemplateFilePath);
  472. FolderBrowserDialog dialog = new FolderBrowserDialog();
  473. dialog.Description = "请选择文件路径";
  474. //dialog.RootFolder = Environment.SpecialFolder.Programs;
  475. if (dialog.ShowDialog() == DialogResult.OK)
  476. {
  477. m_TemplateFilePath = dialog.SelectedPath;
  478. config.AppSettings.Settings["TemplateFilePath"].Value = m_TemplateFilePath;
  479. config.Save(ConfigurationSaveMode.Modified);
  480. ConfigurationManager.RefreshSection("appSettings");//重新加载新的配置文件
  481. }
  482. }
  483. //打开默认路径
  484. OpenFileDialog openFileDialog = new OpenFileDialog();
  485. //设置默认打开路径(绝对路径)
  486. openFileDialog.InitialDirectory = m_TemplateFilePath;
  487. openFileDialog.Filter = "样品参数文件|*.cfg";
  488. if (openFileDialog.ShowDialog() == DialogResult.OK)
  489. {
  490. if (uControl_Init == null)
  491. {
  492. uControl_Init = new UControl_Init(this);
  493. }
  494. //设置选择的模板文件
  495. uControl_Init.ReadConfigPath = openFileDialog.FileName;
  496. //获取文件
  497. uControl_Init.ReadConfigInfo();
  498. }
  499. }
  500. private void pbLog_Click(object sender, EventArgs e)
  501. {
  502. }
  503. //显示日志
  504. private void AddLogListInfo(ThreadStatusEventArgs e)
  505. {
  506. if (m_FormLog != null)
  507. {
  508. foreach (Control item in m_FormLog.Controls)
  509. {
  510. if (item is UserControl)
  511. {
  512. if (item.Name == "UControl_Log")
  513. {
  514. ucLog = (UControl_Log)item;
  515. //获取日志信息
  516. if (listmsg.Items.Count > 0)
  517. {
  518. string[] strLog = new string[listmsg.Items.Count];
  519. for (int i = 0; i < listmsg.Items.Count; i++)
  520. {
  521. //赋值给数组
  522. strLog[i] = listmsg.Items[i].ToString();
  523. }
  524. ucLog.ShowProcessLogInfo(strLog);
  525. }
  526. }
  527. }
  528. }
  529. }
  530. }
  531. #endregion
  532. #region 修改切孔状态
  533. /// <summary>
  534. /// 修改切孔状态
  535. /// </summary>
  536. /// <param name="cutHoleCode"></param>
  537. /// <param name="States"></param>
  538. public void ChangeCutHoleState(string CutHoleName, int States)
  539. {
  540. foreach (Control item in plLeftContent.Controls)
  541. {
  542. if (item is UserControl)
  543. {
  544. UControl_CutHole cutHole = (UControl_CutHole)item;
  545. if (cutHole.CutHoleName == CutHoleName)
  546. {
  547. Button btnCutHole = (Button)cutHole.Controls.Find("btnCutHole", false)[0];
  548. switch (States)
  549. {
  550. //运行中
  551. case (int)MeasureThread.ThreadState.InProcess:
  552. //btnCutHole.BackColor = Color.Yellow;
  553. btnCutHole.BackgroundImage = Properties.Resources.CutHole_Yellow_2_;
  554. btnCutHole.BackgroundImageLayout = ImageLayout.Center;
  555. ChangeCutHoleMeasureState(CutHoleName, States);
  556. ControlFlicker = true;
  557. break;
  558. //等待
  559. case (int)MeasureThread.ThreadState.Waiting:
  560. //btnCutHole.BackColor = Color.Yellow;
  561. btnCutHole.BackgroundImage = Properties.Resources.CutHole_Yellow_2_;
  562. btnCutHole.BackgroundImageLayout = ImageLayout.Center;
  563. ChangeCutHoleMeasureState(CutHoleName, States);
  564. break;
  565. //准备
  566. case (int)MeasureThread.ThreadState.Ready:
  567. //btnCutHole.BackColor = Color.White;
  568. btnCutHole.BackgroundImage = Properties.Resources.CutHole_Gray_2_;
  569. btnCutHole.BackgroundImageLayout = ImageLayout.Center;
  570. ChangeCutHoleMeasureState(CutHoleName, States);
  571. break;
  572. //失败
  573. case (int)MeasureThread.ThreadState.Failed:
  574. //btnCutHole.BackColor = Color.Red;
  575. btnCutHole.BackgroundImage = Properties.Resources.CutHole_Red_2_;
  576. btnCutHole.BackgroundImageLayout = ImageLayout.Center;
  577. ChangeCutHoleMeasureState(CutHoleName, States);
  578. ControlFlicker = false;
  579. break;
  580. //完成
  581. case (int)MeasureThread.ThreadState.Success:
  582. //btnCutHole.BackColor = Color.GreenYellow;
  583. btnCutHole.BackgroundImage = Properties.Resources.CutHole_Green_2_;
  584. btnCutHole.BackgroundImageLayout = ImageLayout.Center;
  585. //修改切孔状态
  586. ChangeCutHoleMeasureState(CutHoleName, States);
  587. ControlFlicker = false;
  588. break;
  589. }
  590. break;
  591. }
  592. }
  593. }
  594. }
  595. #endregion
  596. #region 修改切孔状态
  597. public void ChangeCutHoleMeasureState(string CutHoleName, int States)
  598. {
  599. if (plPrarInfo.Controls.Count > 0)
  600. {
  601. foreach (Control item in plPrarInfo.Controls)
  602. {
  603. if (item is UserControl)
  604. {
  605. if (item.Name == CutHoleName)
  606. {
  607. UControl_ParaInfo uControl_ParaInfo = (UControl_ParaInfo)item;
  608. //获取切孔列表
  609. List<CutHole> aCutHole = m_MeasureFile.ListCutHole;
  610. foreach (CutHole cutHoleItem in aCutHole)
  611. {
  612. if (cutHoleItem.HoleName == CutHoleName)
  613. {
  614. //设置开始时间与结束时间
  615. uControl_ParaInfo.StartTime = cutHoleItem.START.ToString();
  616. uControl_ParaInfo.EndTime = cutHoleItem.END.ToString();
  617. uControl_ParaInfo.ShowTime();
  618. break;
  619. }
  620. }
  621. switch (States)
  622. {
  623. //准备
  624. case (int)MeasureThread.ThreadState.Ready:
  625. //修改切孔状态
  626. uControl_ParaInfo.lblShowState.Text = "准备";
  627. break;
  628. //等待
  629. case (int)MeasureThread.ThreadState.Waiting:
  630. //修改切孔状态
  631. uControl_ParaInfo.lblShowState.Text = "等待";
  632. break;
  633. //进行中
  634. case (int)MeasureThread.ThreadState.InProcess:
  635. //修改切孔状态
  636. uControl_ParaInfo.lblShowState.Text = "进行中";
  637. break;
  638. //完成
  639. case (int)MeasureThread.ThreadState.Success:
  640. //修改切孔状态
  641. uControl_ParaInfo.lblShowState.Text = "完成";
  642. break;
  643. //失败
  644. case (int)MeasureThread.ThreadState.Failed:
  645. uControl_ParaInfo.lblShowState.Text = "失败";
  646. uControl_ParaInfo.pbMeasure.Value = 100;
  647. uControl_ParaInfo.lblCompletedAmount.Text = "100%";
  648. break;
  649. }
  650. break;
  651. }
  652. }
  653. }
  654. }
  655. }
  656. #endregion
  657. #region 拖动无窗体的控件
  658. [DllImport("user32.dll")]//拖动无窗体的控件
  659. public static extern bool ReleaseCapture();
  660. [DllImport("user32.dll")]
  661. public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
  662. public const int WM_SYSCOMMAND = 0x0112;
  663. public const int SC_MOVE = 0xF010;
  664. public const int HTCAPTION = 0x0002;
  665. private void FormHOZMain_MouseDown(object sender, MouseEventArgs e)
  666. {
  667. if (this.WindowState == FormWindowState.Normal)
  668. {
  669. //拖动窗体
  670. ReleaseCapture();
  671. SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);
  672. }
  673. }
  674. #endregion
  675. #region 开始、结束线程事件
  676. private void pbStart_Click(object sender, EventArgs e)
  677. {
  678. if (plLeftContent.Controls.Count==0)
  679. {
  680. MessageBox.Show("请添加切孔信息!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  681. return;
  682. }
  683. if (IsSave)
  684. {
  685. if (m_BackgroundWorker.IsBusy)
  686. {
  687. MessageBox.Show("线程已经运行!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  688. return;
  689. }
  690. if (MessageBox.Show("是否开始测量!", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
  691. {
  692. log.Info("开始", true);
  693. m_BackgroundWorker.RunWorkerAsync(this);
  694. //设置控件操作
  695. SetWinControlMeasureState(false);
  696. pbStop.Visible = true;
  697. pbStart.Visible = false;
  698. }
  699. }
  700. else
  701. {
  702. MessageBox.Show("请保存当前测量文件", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  703. return;
  704. }
  705. }
  706. private void pbStop_Click(object sender, EventArgs e)
  707. {
  708. if (m_Ms != null)
  709. {
  710. if (MessageBox.Show("是否停止当前测量?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question)== DialogResult.Yes)
  711. {
  712. ControlFlicker = false;
  713. //线程停止变量
  714. m_Ms.key_stop = true;
  715. }
  716. }
  717. }
  718. #endregion
  719. #region 清空内容容器中的控件
  720. /// <summary>
  721. /// 清空内容容器中的控件
  722. /// </summary>
  723. private void ClearPanelControls()
  724. {
  725. //清空内容容器中的控件
  726. plLeftContent.Controls.Clear();
  727. plPrarInfo.Controls.Clear();
  728. }
  729. /// <summary>
  730. /// 清空日志控件内容
  731. /// </summary>
  732. private void ClearContrlsContent()
  733. {
  734. try
  735. {
  736. if (ucLog != null)
  737. {
  738. if (ucLog.dgvLog != null)
  739. {
  740. if (ucLog.dgvLog.Rows.Count > 0)
  741. {
  742. ucLog.dgvLog.Rows.Clear();
  743. }
  744. }
  745. }
  746. if (listmsg != null)
  747. {
  748. if (listmsg.Items.Count > 0)
  749. {
  750. listmsg.Items.Clear();
  751. }
  752. }
  753. }
  754. catch (Exception ex)
  755. {
  756. log.Error(ex.Message);
  757. }
  758. }
  759. #endregion
  760. #region 测试修改切孔中流程状态
  761. private void button1_Click(object sender, EventArgs e)
  762. {
  763. if (plPrarInfo.Controls.Count > 0)
  764. {
  765. string name = textBox1.Text;
  766. string code = textBox2.Text;
  767. bool state = Convert.ToBoolean(comboBox1.Text);
  768. foreach (Control item in plPrarInfo.Controls)
  769. {
  770. if (item is UserControl)
  771. {
  772. if (item.Name == name)
  773. {
  774. UControl_ParaInfo uControl_ParaInfo = (UControl_ParaInfo)item;
  775. TimeLineItem[] ParaItem = uControl_ParaInfo.TlItem;
  776. foreach (TimeLineItem tlItem in ParaItem)
  777. {
  778. if (tlItem.Code == code)
  779. {
  780. tlItem.State = Convert.ToInt32(state);
  781. break;
  782. }
  783. }
  784. uControl_ParaInfo.TimeLineInvalidate();
  785. break;
  786. }
  787. }
  788. }
  789. }
  790. }
  791. #endregion
  792. private void FormHOZMain_Resize(object sender, EventArgs e)
  793. {
  794. plMain.Left = 2;
  795. plMain.Top = 2;
  796. plMain.Width = this.Width - 4;
  797. plMain.Height = this.Height - 4;
  798. plFill.Width = plMain.Width - plLeft.Width - 4;
  799. plFill.Height = plMain.Height - plTop.Height - 4;
  800. plFill.Left = plLeft.Width + 4;
  801. plFill.Top = plTop.Height + 4;
  802. if(this.WindowState!= FormWindowState.Maximized)
  803. {
  804. plPrarInfo.Height = 505;
  805. foreach (Control item in plPrarInfo.Controls)
  806. {
  807. if (item is UserControl)
  808. {
  809. if(item.Height>505)
  810. {
  811. item.Height = 505;
  812. }
  813. }
  814. }
  815. }
  816. }
  817. private void FormHOZMain_Paint(object sender, PaintEventArgs e)
  818. {
  819. }
  820. private void FormHOZMain_FormClosing(object sender, FormClosingEventArgs e)
  821. {
  822. if (m_Ms != null)
  823. {
  824. if (m_Ms.iExtender != null)
  825. {
  826. m_Ms.iExtender.CloseExtender();
  827. }
  828. }
  829. }
  830. private void FormHOZMain_LocationChanged(object sender, EventArgs e)
  831. {
  832. if (logwin != null)
  833. {
  834. logwin.Left = this.Left-logwin.Width;
  835. logwin.Top = this.Top;
  836. }
  837. }
  838. private void pbPause_Click(object sender, EventArgs e)
  839. {
  840. if (File.Exists(m_MeasureFile.m_SavePath))
  841. {
  842. string position = System.Environment.CurrentDirectory;
  843. //Process pro = Process.Start(@"D:\DebugLine\Debug\ExportReport.exe", @"D:\6\s.msf");//打开程序B
  844. Process pro = Process.Start(position + "\\Report\\ExportReport.exe", m_MeasureFile.m_SavePath);//打开程序B
  845. pro.WaitForExit();
  846. int Result = pro.ExitCode;//程序B退出回传值
  847. if (Result == 1)//接收到程序B退出代码"1"
  848. {
  849. MessageBox.Show("退出程序B");
  850. }
  851. }
  852. else
  853. {
  854. MessageBox.Show("尚未保存文件");
  855. }
  856. }
  857. }
  858. }