UControl_Init.cs 29 KB

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