UControl_Init.cs 37 KB

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