UControl_Init.cs 31 KB

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