UControl_Init.cs 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Drawing;
  5. using System.Data;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using MeasureData;
  11. using System.Configuration;
  12. using FileManager;
  13. using System.IO;
  14. namespace HOZProject
  15. {
  16. public partial class UControl_Init : UserControl
  17. {
  18. #region 成员变量
  19. String[] sT;
  20. String[] firms;
  21. String[] WPZD;
  22. String[] WPZF;
  23. String[] WQGD;
  24. String[] WQGF;
  25. String[] WLZ;
  26. Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
  27. private FormHOZMain formHOZMain;
  28. public FormHOZMain FormHOZMainObject { get => formHOZMain; set => formHOZMain = value; }
  29. //模板路径
  30. private string readConfigPath;
  31. public string ReadConfigPath { get => readConfigPath; set => readConfigPath = value; }
  32. //模板文件默认路径
  33. private string m_TemplateFilePath;
  34. #endregion
  35. #region 构造方法
  36. public UControl_Init(FormHOZMain formHOZ)
  37. {
  38. InitializeComponent();
  39. FormHOZMainObject = formHOZ;
  40. }
  41. #endregion
  42. #region 窗体加载
  43. private void UControl_Init_Load(object sender, EventArgs e)
  44. {
  45. }
  46. #endregion
  47. #region 关闭窗体
  48. private void btnClose_Click(object sender, EventArgs e)
  49. {
  50. Form fParent = this.ParentForm;
  51. fParent.Close();
  52. }
  53. #endregion
  54. #region 加载切孔文件,生成切孔列表
  55. private void pbCutHoleFile_Click(object sender, EventArgs e)
  56. {
  57. try
  58. {
  59. if (FormHOZMainObject.m_MeasureFile == null)
  60. {
  61. MessageBox.Show("请新建一个测量文件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  62. }
  63. else
  64. {
  65. if (!FormHOZMainObject.m_MeasureFile.GetCutHolesFromFile(""))
  66. {
  67. MessageBox.Show("导入切孔失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  68. }
  69. else
  70. {
  71. List<CutHole> ListCutHole = FormHOZMainObject.m_MeasureFile.ListCutHole;
  72. //文件路径
  73. string CutHoleFilePath = FormHOZMainObject.m_MeasureFile.CutHoleFilePath;
  74. FormHOZMainObject.CreateCutHoleList(ListCutHole);
  75. //显示导入的切孔数量
  76. lblCutHoleCount.Text = string.Format("成功导入{0}个切孔", ListCutHole.Count);
  77. tbCutHoleFilePath.Text = CutHoleFilePath;
  78. //保存测量文件
  79. if (FormHOZMainObject.IsSave)
  80. {
  81. FormHOZMainObject.m_MeasureFile.Save();
  82. }
  83. }
  84. }
  85. }
  86. catch (Exception ex)
  87. {
  88. LogManager.LogError(ex.Message);
  89. }
  90. }
  91. #endregion
  92. #region 根据一个切孔文件,自动计算其他切孔信息
  93. /// <summary>
  94. /// 根据一个切孔,自动计算其他切孔信息
  95. /// </summary>
  96. /// <param name="sender"></param>
  97. /// <param name="e"></param>
  98. private void pbCutHoleAuto_Click(object sender, EventArgs e)
  99. {
  100. try
  101. {
  102. if (FormHOZMainObject.m_MeasureFile == null)
  103. {
  104. MessageBox.Show("请新建一个测量文件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  105. }
  106. else
  107. {
  108. if (!FormHOZMainObject.m_MeasureFile.GetCutHolesFromFile(""))
  109. {
  110. MessageBox.Show("导入切孔失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  111. }
  112. else
  113. {
  114. List<CutHole> ListCutHole = FormHOZMainObject.m_MeasureFile.ListCutHole;
  115. if (ListCutHole != null)
  116. {
  117. if (ListCutHole.Count > 0)
  118. {
  119. //根据切孔文件的一个切孔,自动计算其他切孔位置
  120. float centerX = 65;
  121. float centerY = 65;
  122. float firstX = ListCutHole[0].Position.X;
  123. float firstY = ListCutHole[0].Position.Y;
  124. //距离
  125. float distance = Convert.ToSingle(config.AppSettings.Settings["distance"].Value.ToString());
  126. //矩阵 4*4
  127. int rag = Convert.ToInt32(config.AppSettings.Settings["rag"].Value.ToString());
  128. List<PointF> cutHolePoint = new List<PointF>();
  129. //根据一个切孔点计算其他切孔信息
  130. cutHolePoint = AnalysisPosition(centerX, centerY, firstX, firstY, distance, rag);
  131. if (!FormHOZMainObject.m_MeasureFile.GetCutHolesFromAnalysisPosition(cutHolePoint))
  132. {
  133. MessageBox.Show("生成切孔失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  134. }
  135. else
  136. {
  137. //文件路径
  138. string CutHoleFilePath = FormHOZMainObject.m_MeasureFile.CutHoleFilePath;
  139. //重新获取切孔列表信息
  140. ListCutHole = FormHOZMainObject.m_MeasureFile.ListCutHole;
  141. //创建切孔列表信息
  142. FormHOZMainObject.CreateCutHoleList(ListCutHole);
  143. //显示导入的切孔数量
  144. lblCutHoleCount.Text = string.Format("成功生成{0}个切孔", ListCutHole.Count);
  145. tbCutHoleFilePath.Text = CutHoleFilePath;
  146. }
  147. }
  148. }
  149. //保存测量文件
  150. if (FormHOZMainObject.IsSave)
  151. {
  152. FormHOZMainObject.m_MeasureFile.Save();
  153. }
  154. }
  155. }
  156. }
  157. catch (Exception ex)
  158. {
  159. LogManager.LogError(ex.Message);
  160. }
  161. }
  162. /// <summary>
  163. /// 分析点坐标
  164. /// </summary>
  165. /// <param name="centerX">中心点X轴坐标</param>
  166. /// <param name="centerY">中心点Y轴坐标</param>
  167. /// <param name="firstX">第一个点X轴坐标</param>
  168. /// <param name="firstY">第一个点Y轴坐标</param>
  169. /// <param name="distance">点与点的距离</param>
  170. /// <param name="rag">行、列数</param>
  171. /// <param name="ptsx">计算生成所有X轴坐标</param>
  172. /// <param name="ptsy">计算生成所有Y轴坐标</param>
  173. public List<PointF> AnalysisPosition(float centerX, float centerY, float firstX, float firstY, float distance, int rag)
  174. {
  175. //求样品1的水平角度
  176. double angle = 0;
  177. //清空所有点信息
  178. List<float> ptsx = new List<float>();
  179. List<float> ptsy = new List<float>();
  180. //将第一个点加入到点信息中
  181. ptsx.Add(firstX);
  182. ptsy.Add(firstY);
  183. //计算第一个点与X轴的交角度数
  184. angle = Math.Atan2(ptsy[0] - centerY, centerX - ptsx[0]) * 180 / Math.PI;
  185. //这里是求与第一个点横向排列的其他点的移动角度
  186. //就是按45度向左向右移动的度
  187. angle = 45 - angle;
  188. angle = angle * Math.PI / 180;
  189. float tx = 0;
  190. float ty = 0;
  191. for (int j = 0; j < rag; j++)
  192. {
  193. //计算每行第一个点的坐标
  194. if (j > 0)
  195. {
  196. tx = (float)(distance * j * Math.Sin(angle));
  197. ty = (float)(distance * j * Math.Cos(angle));
  198. ptsx.Add(tx + ptsx[0]);
  199. ptsy.Add(ptsy[0] - ty);
  200. }
  201. //计算每行其他点的坐标
  202. for (int i = 1; i < rag; i++)
  203. {
  204. tx = (float)(distance * i * Math.Cos(angle));
  205. ty = (float)(distance * i * Math.Sin(angle));
  206. ptsx.Add(tx + ptsx[j * rag]);
  207. ptsy.Add(ty + ptsy[j * rag]);
  208. }
  209. }
  210. List<PointF> pts = new List<PointF>();
  211. for (int i = 0; i < ptsx.Count; i++)
  212. {
  213. //增加的点
  214. PointF pf = new PointF();
  215. pf.X = ptsx[i];
  216. pf.Y = ptsy[i];
  217. pts.Add(pf);
  218. }
  219. return pts;
  220. }
  221. #endregion
  222. #region 加载PT模板文件
  223. private void pbTemplateFile_Click(object sender, EventArgs e)
  224. {
  225. string FilePathName;
  226. string fileNameWithoutExtension;
  227. //新建一个文件对话框
  228. OpenFileDialog pOpenFileDialog = new OpenFileDialog();
  229. //设置对话框标题
  230. pOpenFileDialog.Title = "选择模板文件";
  231. //设置打开文件类型
  232. pOpenFileDialog.Filter = "ely文件(*.ely)|*.ely";
  233. ////监测文件是否存在
  234. //pOpenFileDialog.CheckFileExists = true;
  235. //文件打开后执行以下程序
  236. if (pOpenFileDialog.ShowDialog() == DialogResult.OK)
  237. {
  238. FilePathName = System.IO.Path.GetFullPath(pOpenFileDialog.FileName); //绝对路径
  239. fileNameWithoutExtension = System.IO.Path.GetFileNameWithoutExtension(FilePathName);
  240. this.txtWPTF.Text = FilePathName;
  241. }
  242. }
  243. #endregion
  244. #region 加载FIB模板文件
  245. private void pbFIBTemplateFile_Click(object sender, EventArgs e)
  246. {
  247. string FilePathName;
  248. string fileNameWithoutExtension;
  249. //新建一个文件对话框
  250. OpenFileDialog pOpenFileDialog = new OpenFileDialog();
  251. //设置对话框标题
  252. pOpenFileDialog.Title = "选择模板文件";
  253. //设置打开文件类型
  254. pOpenFileDialog.Filter = "ely文件(*.ely)|*.ely";
  255. ////监测文件是否存在
  256. //pOpenFileDialog.CheckFileExists = true;
  257. //文件打开后执行以下程序
  258. if (pOpenFileDialog.ShowDialog() == DialogResult.OK)
  259. {
  260. FilePathName = System.IO.Path.GetFullPath(pOpenFileDialog.FileName); //绝对路径
  261. fileNameWithoutExtension = System.IO.Path.GetFileNameWithoutExtension(FilePathName);
  262. this.txtWFIBF.Text = FilePathName;
  263. }
  264. }
  265. #endregion
  266. #region 创建与读取样品参数、配置文件
  267. private void btnCreateConfig_Click(object sender, EventArgs e)
  268. {
  269. SaveTemplateFile();
  270. }
  271. /// <summary>
  272. /// 获取测量参数,初始化窗体中的控件信息
  273. /// </summary>
  274. /// <returns></returns>
  275. public MeasureParam GetMeasureParamInfo()
  276. {
  277. MeasureParam cfm = new MeasureParam();
  278. cfm.Is_Photograph = chkWIsP.Checked;
  279. cfm.PT = chkWPT.Checked;
  280. //自动对焦模式
  281. //cfm.FocusMode = chkManul.Checked;
  282. cfm.PTTemp = txtWPTF.Text;
  283. cfm.FIBTemp = txtWFIBF.Text;
  284. cfm.Stretch_Magnification = Convert.ToSingle(cbbWLZ.Text);
  285. cfm.Location_Magnification = Convert.ToSingle(cbbWQGF.Text);
  286. cfm.Location_Voltage = Convert.ToSingle(cbbWQGD.Text);
  287. cfm.Photograph_Magnification = Convert.ToSingle(cbbWPZF.Text);
  288. cfm.Photograph_Voltage = Convert.ToSingle(cbbWPZD.Text);
  289. if (cbbWXZ.SelectedIndex == 0)
  290. {
  291. cfm.Correction_Angle = 36;
  292. }
  293. else
  294. {
  295. cfm.Correction_Angle = 54;
  296. }
  297. cfm.SampleName = cbbWYP.Text;
  298. cfm.Firm = cbbWCS.Text;
  299. return cfm;
  300. }
  301. public void SaveTemplateFile()
  302. {
  303. MeasureParam cfm = new MeasureParam();
  304. cfm.Is_Photograph = chkWIsP.Checked;
  305. cfm.PT = chkWPT.Checked;
  306. //自动对焦模式
  307. //cfm.FocusMode = chkManul.Checked;
  308. cfm.PTTemp = txtWPTF.Text;
  309. cfm.FIBTemp = txtWFIBF.Text;
  310. cfm.Stretch_Magnification = Convert.ToSingle(cbbWLZ.Text);
  311. cfm.Location_Magnification = Convert.ToSingle(cbbWQGF.Text);
  312. cfm.Location_Voltage = Convert.ToSingle(cbbWQGD.Text);
  313. cfm.Photograph_Magnification = Convert.ToSingle(cbbWPZF.Text);
  314. cfm.Photograph_Voltage = Convert.ToSingle(cbbWPZD.Text);
  315. if (cbbWXZ.SelectedIndex == 0)
  316. {
  317. cfm.Correction_Angle = 36;
  318. }
  319. else
  320. {
  321. cfm.Correction_Angle = 54;
  322. }
  323. cfm.SampleName = cbbWYP.Text;
  324. cfm.Firm = cbbWCS.Text;
  325. ConfigFile cf = new ConfigFile(cfm);
  326. if (!m_TemplateFilePath.Equals(""))
  327. {
  328. if (!Directory.Exists(m_TemplateFilePath))
  329. {
  330. //创建路径
  331. Directory.CreateDirectory(m_TemplateFilePath);
  332. }
  333. }
  334. SaveFileDialog saveFileDialog = new SaveFileDialog();
  335. //设置默认打开路径(绝对路径)
  336. saveFileDialog.InitialDirectory = m_TemplateFilePath;
  337. saveFileDialog.Filter = "样品参数文件|*.cfg";
  338. if (saveFileDialog.ShowDialog() == DialogResult.OK)
  339. {
  340. cf.Save(saveFileDialog.FileName);
  341. }
  342. else
  343. {
  344. return;
  345. }
  346. //编辑Config文件
  347. EditConfig();
  348. }
  349. /// <summary>
  350. /// 编辑confing 文件信息
  351. /// </summary>
  352. public bool EditConfig()
  353. {
  354. try
  355. {
  356. //设置数据源信息
  357. //样品类型
  358. List<String> _sT = sT.ToList();
  359. if (_sT.IndexOf(cbbWYP.Text) < 0)
  360. {
  361. _sT.Add(cbbWYP.Text);
  362. string wsT = string.Join(",", _sT.ToArray());
  363. config.AppSettings.Settings["Sample_Type"].Value = wsT;
  364. }
  365. //厂商
  366. List<String> _firms = firms.ToList();
  367. if (_firms.IndexOf(cbbWCS.Text) < 0)
  368. {
  369. _firms.Add(cbbWCS.Text);
  370. string wFirms = string.Join(",", _firms.ToArray());
  371. config.AppSettings.Settings["Firm"].Value = wFirms;
  372. }
  373. //拍照电压
  374. List<String> _WPZD = WPZD.ToList();
  375. if (_WPZD.IndexOf(cbbWPZD.Text) < 0)
  376. {
  377. _WPZD.Add(cbbWPZD.Text);
  378. string wWPZD = string.Join(",", _WPZD.ToArray());
  379. config.AppSettings.Settings["WPZD"].Value = wWPZD;
  380. }
  381. //拍照放大位数
  382. List<String> _WPZF = WPZF.ToList();
  383. if (_WPZF.IndexOf(cbbWPZF.Text) < 0)
  384. {
  385. _WPZF.Add(cbbWPZF.Text);
  386. string wWPZF = string.Join(",", _WPZF.ToArray());
  387. config.AppSettings.Settings["WPZF"].Value = wWPZF;
  388. }
  389. //定位切割电压
  390. List<String> _WQGD = WQGD.ToList();
  391. if (_WQGD.IndexOf(cbbWQGD.Text) < 0)
  392. {
  393. _WQGD.Add(cbbWQGD.Text);
  394. string wWQGD = string.Join(",", _WQGD.ToArray());
  395. config.AppSettings.Settings["WQGD"].Value = wWQGD;
  396. }
  397. //定位切割放大位数
  398. List<String> _WQGF = WQGF.ToList();
  399. if (_WQGF.IndexOf(cbbWQGF.Text) < 0)
  400. {
  401. _WQGF.Add(cbbWQGF.Text);
  402. string wWQGF = string.Join(",", _WQGF.ToArray());
  403. config.AppSettings.Settings["WQGF"].Value = wWQGF;
  404. }
  405. //拉直操作放大位数
  406. List<String> _WLZ = WLZ.ToList();
  407. if (_WLZ.IndexOf(cbbWLZ.Text) < 0)
  408. {
  409. _WLZ.Add(cbbWLZ.Text);
  410. string wWLZ = string.Join(",", _WLZ.ToArray());
  411. config.AppSettings.Settings["WLZ"].Value = wWLZ;
  412. }
  413. MeasureParam cfm = new MeasureParam();
  414. cfm.Is_Photograph = chkWIsP.Checked;
  415. cfm.FocusMode = Convert.ToInt32(config.AppSettings.Settings["Focus_Mode"].Value);
  416. cfm.PT = chkWPT.Checked;
  417. //自动对焦模式
  418. //cfm.FocusMode = chkManul.Checked;
  419. cfm.PTTemp = txtWPTF.Text;
  420. cfm.FIBTemp = txtWFIBF.Text;
  421. cfm.Stretch_Magnification = Convert.ToSingle(cbbWLZ.Text);
  422. cfm.Location_Magnification = Convert.ToSingle(cbbWQGF.Text);
  423. cfm.Location_Voltage = Convert.ToSingle(cbbWQGD.Text);
  424. cfm.Photograph_Magnification = Convert.ToSingle(cbbWPZF.Text);
  425. cfm.Photograph_Voltage = Convert.ToSingle(cbbWPZD.Text);
  426. if (cbbWXZ.SelectedIndex == 0)
  427. {
  428. cfm.Correction_Angle = 36;
  429. }
  430. else
  431. {
  432. cfm.Correction_Angle = 54;
  433. }
  434. cfm.SampleName = cbbWYP.Text;
  435. cfm.Firm = cbbWCS.Text;
  436. //设置配置文件默认值
  437. config.AppSettings.Settings["Is_Photograph"].Value = cfm.Is_Photograph.ToString();
  438. config.AppSettings.Settings["PT_Depostion"].Value = cfm.PT.ToString();
  439. config.AppSettings.Settings["PT_ELYFile"].Value = cfm.PTTemp;
  440. config.AppSettings.Settings["FIB_ELYFile"].Value = cfm.FIBTemp;
  441. config.AppSettings.Settings["Stretch_Magnification"].Value = cfm.Stretch_Magnification.ToString();
  442. config.AppSettings.Settings["Location_Magnification"].Value = cfm.Location_Magnification.ToString();
  443. config.AppSettings.Settings["Location_Voltage"].Value = cfm.Location_Voltage.ToString();
  444. config.AppSettings.Settings["Photograph_Magnification"].Value = cfm.Photograph_Magnification.ToString();
  445. config.AppSettings.Settings["Photograph_Voltage"].Value = cfm.Photograph_Voltage.ToString();
  446. config.AppSettings.Settings["Correction_Angle"].Value = cfm.Correction_Angle.ToString();
  447. config.AppSettings.Settings["SampleName"].Value = cfm.SampleName;
  448. config.AppSettings.Settings["Firms"].Value = cfm.Firm;
  449. config.Save(ConfigurationSaveMode.Modified);
  450. ConfigurationManager.RefreshSection("appSettings");//重新加载新的配置文件
  451. return true;
  452. }
  453. catch (Exception ex)
  454. {
  455. LogManager.LogError(ex.Message);
  456. return false;
  457. }
  458. }
  459. /// <summary>
  460. /// 删除config文件节点中内容信息
  461. /// </summary>
  462. public bool DelConfigNodeContentInfo(string delControlName, string selName)
  463. {
  464. try
  465. {
  466. switch (delControlName)
  467. {
  468. case "WYP":
  469. //样品类型
  470. List<String> _sT = sT.ToList();
  471. _sT.Remove(selName);
  472. string wsT = string.Join(",", _sT.ToArray());
  473. config.AppSettings.Settings["Sample_Type"].Value = wsT;
  474. break;
  475. case "WCS":
  476. //厂商
  477. List<String> _firms = firms.ToList();
  478. _firms.Remove(selName);
  479. string wFirms = string.Join(",", _firms.ToArray());
  480. config.AppSettings.Settings["Firm"].Value = wFirms;
  481. break;
  482. case "WPZD":
  483. //拍照电压
  484. List<String> _WPZD = WPZD.ToList();
  485. _WPZD.Remove(selName);
  486. string wWPZD = string.Join(",", _WPZD.ToArray());
  487. config.AppSettings.Settings["WPZD"].Value = wWPZD;
  488. break;
  489. case "WPZF":
  490. //拍照放大位数
  491. List<String> _WPZF = WPZF.ToList();
  492. _WPZF.Remove(selName);
  493. string wWPZF = string.Join(",", _WPZF.ToArray());
  494. config.AppSettings.Settings["WPZF"].Value = wWPZF;
  495. break;
  496. case "WQGD"://定位切割电压
  497. List<String> _WQGD = WQGD.ToList();
  498. _WQGD.Remove(selName);
  499. string wWQGD = string.Join(",", _WQGD.ToArray());
  500. config.AppSettings.Settings["WQGD"].Value = wWQGD;
  501. break;
  502. case "WQGF": //定位切割放大位数
  503. List<String> _WQGF = WQGF.ToList();
  504. _WQGF.Remove(selName);
  505. string wWQGF = string.Join(",", _WQGF.ToArray());
  506. config.AppSettings.Settings["WQGF"].Value = wWQGF;
  507. break;
  508. case "WLZ":
  509. //拉直操作放大位数
  510. List<String> _WLZ = WLZ.ToList();
  511. _WLZ.Remove(selName);
  512. string wWLZ = string.Join(",", _WLZ.ToArray());
  513. config.AppSettings.Settings["WLZ"].Value = wWLZ;
  514. break;
  515. }
  516. config.Save(ConfigurationSaveMode.Modified);
  517. ConfigurationManager.RefreshSection("appSettings");//重新加载新的配置文件
  518. return true;
  519. }
  520. catch (Exception ex)
  521. {
  522. LogManager.LogError(ex.Message);
  523. return true;
  524. }
  525. }
  526. /// <summary>
  527. /// 绑定下拉菜单
  528. /// </summary>
  529. /// <param name="cb"></param>
  530. /// <param name="strGroup"></param>
  531. private void BindComboxData(ComboBox cb, string[] strGroup)
  532. {
  533. for (int i = 0; i < strGroup.Length; i++)
  534. {
  535. if (!strGroup[i].Equals(""))
  536. {
  537. cb.Items.Add(strGroup[i]);
  538. }
  539. }
  540. }
  541. /// <summary>
  542. /// 读取Config文件信息
  543. /// </summary>
  544. public void ReloadConfig()
  545. {
  546. cbbWYP.Items.Clear();
  547. cbbWCS.Items.Clear();
  548. cbbWPZD.Items.Clear();
  549. cbbWPZF.Items.Clear();
  550. cbbWQGD.Items.Clear();
  551. cbbWQGF.Items.Clear();
  552. cbbWLZ.Items.Clear();
  553. m_TemplateFilePath = config.AppSettings.Settings["TemplateFilePath"].Value.ToString();
  554. string sample_Type = config.AppSettings.Settings["Sample_Type"].Value.ToString();
  555. string firm = config.AppSettings.Settings["Firm"].Value.ToString();
  556. string WPZDTemp = config.AppSettings.Settings["WPZD"].Value.ToString();
  557. string WPZFTemp = config.AppSettings.Settings["WPZF"].Value.ToString();
  558. string WQGDTemp = config.AppSettings.Settings["WQGD"].Value.ToString();
  559. string WQGFTemp = config.AppSettings.Settings["WQGF"].Value.ToString();
  560. string WLZTemp = config.AppSettings.Settings["WLZ"].Value.ToString();
  561. //样品类型
  562. sT = sample_Type.Split(',');
  563. BindComboxData(cbbWYP, sT);
  564. //厂商
  565. firms = firm.Split(',');
  566. BindComboxData(cbbWCS, firms);
  567. //拍照电压
  568. WPZD = WPZDTemp.Split(',');
  569. BindComboxData(cbbWPZD, WPZD);
  570. //拍照放大位数
  571. WPZF = WPZFTemp.Split(',');
  572. BindComboxData(cbbWPZF, WPZF);
  573. //定位切割电压
  574. WQGD = WQGDTemp.Split(',');
  575. BindComboxData(cbbWQGD, WQGD);
  576. //定位切割放大位数
  577. WQGF = WQGFTemp.Split(',');
  578. BindComboxData(cbbWQGF, WQGF);
  579. //拉直操作放大位数
  580. WLZ = WLZTemp.Split(',');
  581. BindComboxData(cbbWLZ, WLZ);
  582. //设置配置文件默认值
  583. chkWIsP.Checked=Convert.ToBoolean(config.AppSettings.Settings["Is_Photograph"].Value);
  584. chkWPT.Checked = Convert.ToBoolean(config.AppSettings.Settings["PT_Depostion"].Value);
  585. //自动对焦模式
  586. //chkManul.Checked = Convert.ToBoolean(config.AppSettings.Settings["Focus_Mode"].Value);
  587. txtWPTF.Text = config.AppSettings.Settings["PT_ELYFile"].Value;
  588. txtWFIBF.Text = config.AppSettings.Settings["FIB_ELYFile"].Value;
  589. cbbWLZ.Text = config.AppSettings.Settings["Stretch_Magnification"].Value;
  590. cbbWQGF.Text = config.AppSettings.Settings["Location_Magnification"].Value;
  591. cbbWQGD.Text = config.AppSettings.Settings["Location_Voltage"].Value;
  592. cbbWPZF.Text = config.AppSettings.Settings["Photograph_Magnification"].Value;
  593. cbbWPZD.Text = config.AppSettings.Settings["Photograph_Voltage"].Value;
  594. string Correction_Angle = config.AppSettings.Settings["Correction_Angle"].Value;
  595. if (Correction_Angle == "36")
  596. {
  597. cbbWXZ.SelectedIndex = 0;
  598. }
  599. else
  600. {
  601. cbbWXZ.SelectedIndex = 1;
  602. }
  603. cbbWYP.Text = config.AppSettings.Settings["SampleName"].Value;
  604. cbbWCS.Text = config.AppSettings.Settings["Firms"].Value;
  605. }
  606. /// <summary>
  607. /// 根据所选路径,读取模板文件
  608. /// </summary>
  609. public void ReadConfigInfo()
  610. {
  611. if (!ReadConfigPath.Equals(""))
  612. {
  613. ReloadConfig();
  614. ConfigFile cfm = new ConfigFile(new MeasureParam());
  615. cfm.Read(ReadConfigPath);
  616. chkWIsP.Checked = cfm.m_Config.Is_Photograph;
  617. chkWPT.Checked = cfm.m_Config.PT;
  618. //自动对焦模式
  619. //cfm.FocusMode = chkManul.Checked;
  620. txtWPTF.Text = cfm.m_Config.PTTemp;
  621. txtWFIBF.Text = cfm.m_Config.FIBTemp;
  622. cbbWLZ.Text = cfm.m_Config.Stretch_Magnification.ToString();
  623. cbbWQGF.Text = cfm.m_Config.Location_Magnification.ToString();
  624. cbbWQGD.Text = cfm.m_Config.Location_Voltage.ToString();
  625. cbbWPZF.Text = cfm.m_Config.Photograph_Magnification.ToString();
  626. cbbWPZD.Text = cfm.m_Config.Photograph_Voltage.ToString();
  627. string Correction_Angle = cfm.m_Config.Correction_Angle.ToString();
  628. if (Correction_Angle == "36")
  629. {
  630. cbbWXZ.SelectedIndex = 0;
  631. }
  632. else
  633. {
  634. cbbWXZ.SelectedIndex = 1;
  635. }
  636. cbbWYP.Text = cfm.m_Config.SampleName;
  637. cbbWCS.Text = cfm.m_Config.Firm;
  638. }
  639. }
  640. /// <summary>
  641. /// 修改配置文件默认值
  642. /// </summary>
  643. /// <param name="sender"></param>
  644. /// <param name="e"></param>
  645. private void btnSaveDefalutPara_Click(object sender, EventArgs e)
  646. {
  647. if (EditConfig())
  648. {
  649. MessageBox.Show("保存成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  650. }
  651. }
  652. #endregion
  653. #region 删除下拉菜单选择项
  654. private void DelComboBoxItem_Click(object sender, EventArgs e)
  655. {
  656. if (MessageBox.Show("是否删除所选项信息?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
  657. {
  658. PictureBox pbDel = (PictureBox)sender;
  659. string ctrlName = pbDel.Name.Substring(5, pbDel.Name.Length - 5);
  660. if (DelComboBoxItem(ctrlName))
  661. {
  662. //重新加载
  663. ReloadConfig();
  664. }
  665. }
  666. }
  667. /// <summary>
  668. /// 删除下拉菜单选择项
  669. /// </summary>
  670. public bool DelComboBoxItem(string controlName)
  671. {
  672. string delName = controlName;
  673. foreach (Control item in this.Controls)
  674. {
  675. if (item is ComboBox)
  676. {
  677. if (item.Name.Contains(delName))
  678. {
  679. ComboBox cb = (ComboBox)item;
  680. return DelConfigNodeContentInfo(delName, cb.Text);
  681. }
  682. }
  683. }
  684. return false;
  685. }
  686. #endregion
  687. #region 根据是否仅拍照,进行逻辑判断
  688. private void chkWIsP_CheckedChanged(object sender, EventArgs e)
  689. {
  690. if (chkWIsP.Checked)
  691. {
  692. chkWPT.Checked = false;
  693. chkWPT.Visible = false;
  694. FormHOZMainObject.m_MeasureType = (int)MeasureMsgManage.measureType.Photo;
  695. }
  696. else
  697. {
  698. chkWPT.Visible = true;
  699. if (!chkWPT.Checked)
  700. {
  701. FormHOZMainObject.m_MeasureType = (int)MeasureMsgManage.measureType.FIB;
  702. }
  703. }
  704. CreateCutHoleList();
  705. }
  706. #endregion
  707. #region 创建切孔列表
  708. private void CreateCutHoleList()
  709. {
  710. List<CutHole> ListCutHole = FormHOZMainObject.m_MeasureFile.ListCutHole;
  711. FormHOZMainObject.CreateCutHoleList(ListCutHole);
  712. }
  713. #endregion
  714. #region 设置流程类型
  715. private void chkWPT_CheckedChanged(object sender, EventArgs e)
  716. {
  717. if (chkWPT.Checked)
  718. {
  719. FormHOZMainObject.m_MeasureType = (int)MeasureMsgManage.measureType.PT;
  720. }
  721. else
  722. {
  723. if (!chkWIsP.Checked)
  724. {
  725. FormHOZMainObject.m_MeasureType = (int)MeasureMsgManage.measureType.FIB;
  726. }
  727. }
  728. CreateCutHoleList();
  729. }
  730. #endregion
  731. #region 关闭按钮 鼠标操作事件
  732. private void pbClose_MouseEnter(object sender, EventArgs e)
  733. {
  734. pbClose.BackgroundImage = global::HOZProject.Properties.Resources.exit_Red;
  735. }
  736. private void pbClose_MouseLeave(object sender, EventArgs e)
  737. {
  738. pbClose.BackgroundImage = global::HOZProject.Properties.Resources.exit_Gray;
  739. }
  740. #endregion
  741. }
  742. }