FormHOZMain.cs 42 KB

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