UControl_Init.cs 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005
  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. if (Convert.ToInt32(cbbWFIB.Text) < 200)
  271. {
  272. MessageBox.Show("FIB最小放大倍数为200倍");
  273. }
  274. else
  275. {
  276. SaveTemplateFile();
  277. }
  278. }
  279. /// <summary>
  280. /// 获取测量参数,初始化窗体中的控件信息
  281. /// </summary>
  282. /// <returns></returns>
  283. public MeasureParam GetMeasureParamInfo()
  284. {
  285. MeasureParam cfm = new MeasureParam();
  286. cfm.Is_Photograph = chkWIsP.Checked;
  287. cfm.PT = chkWPT.Checked;
  288. //自动对焦模式
  289. //cfm.FocusMode = chkManul.Checked;
  290. cfm.PTTemp = txtWPTF.Text;
  291. cfm.FIBTemp = txtWFIBF.Text;
  292. cfm.Stretch_Magnification = Convert.ToSingle(cbbWLZ.Text);
  293. cfm.Location_Magnification = Convert.ToSingle(cbbWQGF.Text);
  294. cfm.Location_Voltage = Convert.ToSingle(cbbWQGD.Text);
  295. cfm.Photograph_Magnification = Convert.ToSingle(cbbWPZF.Text);
  296. cfm.Photograph_Voltage = Convert.ToSingle(cbbWPZD.Text);
  297. cfm.FIB_Magnification = Convert.ToSingle(cbbWFIB.Text);
  298. if (cbbWXZ.SelectedIndex == 0)
  299. {
  300. cfm.Correction_Angle = 36;
  301. }
  302. else
  303. {
  304. cfm.Correction_Angle = 54;
  305. }
  306. cfm.SampleName = cbbWYP.Text;
  307. cfm.Firm = cbbWCS.Text;
  308. return cfm;
  309. }
  310. public void SaveTemplateFile()
  311. {
  312. MeasureParam cfm = new MeasureParam();
  313. cfm.Is_Photograph = chkWIsP.Checked;
  314. cfm.PT = chkWPT.Checked;
  315. //自动对焦模式
  316. //cfm.FocusMode = chkManul.Checked;
  317. cfm.PTTemp = txtWPTF.Text;
  318. cfm.FIBTemp = txtWFIBF.Text;
  319. cfm.Stretch_Magnification = Convert.ToSingle(cbbWLZ.Text);
  320. cfm.Location_Magnification = Convert.ToSingle(cbbWQGF.Text);
  321. cfm.Location_Voltage = Convert.ToSingle(cbbWQGD.Text);
  322. cfm.Photograph_Magnification = Convert.ToSingle(cbbWPZF.Text);
  323. cfm.Photograph_Voltage = Convert.ToSingle(cbbWPZD.Text);
  324. cfm.FIB_Magnification = Convert.ToSingle(cbbWFIB.Text);
  325. if (cbbWXZ.SelectedIndex == 0)
  326. {
  327. cfm.Correction_Angle = 36;
  328. }
  329. else
  330. {
  331. cfm.Correction_Angle = 54;
  332. }
  333. cfm.SampleName = cbbWYP.Text;
  334. cfm.Firm = cbbWCS.Text;
  335. ConfigFile cf = new ConfigFile(cfm);
  336. if (!m_TemplateFilePath.Equals(""))
  337. {
  338. if (!Directory.Exists(m_TemplateFilePath))
  339. {
  340. //创建路径
  341. //Directory.CreateDirectory(m_TemplateFilePath);
  342. FolderBrowserDialog dialog = new FolderBrowserDialog();
  343. dialog.Description = "请选择文件路径";
  344. //dialog.RootFolder = Environment.SpecialFolder.Programs;
  345. if (dialog.ShowDialog() == DialogResult.OK)
  346. {
  347. m_TemplateFilePath = dialog.SelectedPath;
  348. config.AppSettings.Settings["TemplateFilePath"].Value = m_TemplateFilePath;
  349. config.Save(ConfigurationSaveMode.Modified);
  350. ConfigurationManager.RefreshSection("appSettings");//重新加载新的配置文件
  351. }
  352. }
  353. }
  354. SaveFileDialog saveFileDialog = new SaveFileDialog();
  355. //设置默认打开路径(绝对路径)
  356. saveFileDialog.InitialDirectory = m_TemplateFilePath;
  357. saveFileDialog.Filter = "样品参数文件|*.cfg";
  358. if (saveFileDialog.ShowDialog() == DialogResult.OK)
  359. {
  360. cf.Save(saveFileDialog.FileName);
  361. }
  362. else
  363. {
  364. return;
  365. }
  366. //编辑Config文件
  367. EditConfig();
  368. }
  369. /// <summary>
  370. /// 编辑confing 文件信息
  371. /// </summary>
  372. public bool EditConfig()
  373. {
  374. try
  375. {
  376. //设置数据源信息
  377. //样品类型
  378. List<String> _sT = sT.ToList();
  379. if (_sT.IndexOf(cbbWYP.Text) < 0)
  380. {
  381. _sT.Add(cbbWYP.Text);
  382. string wsT = string.Join(",", _sT.ToArray());
  383. config.AppSettings.Settings["Sample_Type"].Value = wsT;
  384. }
  385. //厂商
  386. List<String> _firms = firms.ToList();
  387. if (_firms.IndexOf(cbbWCS.Text) < 0)
  388. {
  389. _firms.Add(cbbWCS.Text);
  390. string wFirms = string.Join(",", _firms.ToArray());
  391. config.AppSettings.Settings["Firm"].Value = wFirms;
  392. }
  393. //拍照电压
  394. List<String> _WPZD = WPZD.ToList();
  395. if (_WPZD.IndexOf(cbbWPZD.Text) < 0)
  396. {
  397. _WPZD.Add(cbbWPZD.Text);
  398. string wWPZD = string.Join(",", _WPZD.ToArray());
  399. config.AppSettings.Settings["WPZD"].Value = wWPZD;
  400. }
  401. //拍照放大位数
  402. List<String> _WPZF = WPZF.ToList();
  403. if (_WPZF.IndexOf(cbbWPZF.Text) < 0)
  404. {
  405. _WPZF.Add(cbbWPZF.Text);
  406. string wWPZF = string.Join(",", _WPZF.ToArray());
  407. config.AppSettings.Settings["WPZF"].Value = wWPZF;
  408. }
  409. //定位切割电压
  410. List<String> _WQGD = WQGD.ToList();
  411. if (_WQGD.IndexOf(cbbWQGD.Text) < 0)
  412. {
  413. _WQGD.Add(cbbWQGD.Text);
  414. string wWQGD = string.Join(",", _WQGD.ToArray());
  415. config.AppSettings.Settings["WQGD"].Value = wWQGD;
  416. }
  417. //定位切割放大位数
  418. List<String> _WQGF = WQGF.ToList();
  419. if (_WQGF.IndexOf(cbbWQGF.Text) < 0)
  420. {
  421. _WQGF.Add(cbbWQGF.Text);
  422. string wWQGF = string.Join(",", _WQGF.ToArray());
  423. config.AppSettings.Settings["WQGF"].Value = wWQGF;
  424. }
  425. //拉直操作放大位数
  426. List<String> _WLZ = WLZ.ToList();
  427. if (_WLZ.IndexOf(cbbWLZ.Text) < 0)
  428. {
  429. _WLZ.Add(cbbWLZ.Text);
  430. string wWLZ = string.Join(",", _WLZ.ToArray());
  431. config.AppSettings.Settings["WLZ"].Value = wWLZ;
  432. }
  433. //FIB放大位数
  434. List<String> _WFIB = WFIB.ToList();
  435. if (_WFIB.IndexOf(cbbWFIB.Text) < 0)
  436. {
  437. _WFIB.Add(cbbWFIB.Text);
  438. string wWFIB = string.Join(",", _WFIB.ToArray());
  439. config.AppSettings.Settings["WFIB"].Value = wWFIB;
  440. }
  441. MeasureParam cfm = new MeasureParam();
  442. cfm.Is_Photograph = chkWIsP.Checked;
  443. cfm.FocusMode = Convert.ToInt32(config.AppSettings.Settings["Focus_Mode"].Value);
  444. cfm.PT = chkWPT.Checked;
  445. //自动对焦模式
  446. //cfm.FocusMode = chkManul.Checked;
  447. cfm.PTTemp = txtWPTF.Text;
  448. cfm.FIBTemp = txtWFIBF.Text;
  449. cfm.Stretch_Magnification = Convert.ToSingle(cbbWLZ.Text);
  450. cfm.Location_Magnification = Convert.ToSingle(cbbWQGF.Text);
  451. cfm.Location_Voltage = Convert.ToSingle(cbbWQGD.Text);
  452. cfm.Photograph_Magnification = Convert.ToSingle(cbbWPZF.Text);
  453. cfm.Photograph_Voltage = Convert.ToSingle(cbbWPZD.Text);
  454. cfm.FIB_Magnification = Convert.ToSingle(cbbWFIB.Text);
  455. if (cbbWXZ.SelectedIndex == 0)
  456. {
  457. cfm.Correction_Angle = 36;
  458. }
  459. else
  460. {
  461. cfm.Correction_Angle = 54;
  462. }
  463. cfm.SampleName = cbbWYP.Text;
  464. cfm.Firm = cbbWCS.Text;
  465. //设置配置文件默认值
  466. config.AppSettings.Settings["Is_Photograph"].Value = cfm.Is_Photograph.ToString();
  467. config.AppSettings.Settings["PT_Depostion"].Value = cfm.PT.ToString();
  468. config.AppSettings.Settings["PT_ELYFile"].Value = cfm.PTTemp;
  469. config.AppSettings.Settings["FIB_ELYFile"].Value = cfm.FIBTemp;
  470. config.AppSettings.Settings["Stretch_Magnification"].Value = cfm.Stretch_Magnification.ToString();
  471. config.AppSettings.Settings["Location_Magnification"].Value = cfm.Location_Magnification.ToString();
  472. config.AppSettings.Settings["Location_Voltage"].Value = cfm.Location_Voltage.ToString();
  473. config.AppSettings.Settings["Photograph_Magnification"].Value = cfm.Photograph_Magnification.ToString();
  474. config.AppSettings.Settings["Photograph_Voltage"].Value = cfm.Photograph_Voltage.ToString();
  475. config.AppSettings.Settings["Correction_Angle"].Value = cfm.Correction_Angle.ToString();
  476. config.AppSettings.Settings["SampleName"].Value = cfm.SampleName;
  477. config.AppSettings.Settings["Firms"].Value = cfm.Firm;
  478. config.Save(ConfigurationSaveMode.Modified);
  479. ConfigurationManager.RefreshSection("appSettings");//重新加载新的配置文件
  480. return true;
  481. }
  482. catch (Exception ex)
  483. {
  484. LogManager.LogError(ex.Message);
  485. return false;
  486. }
  487. }
  488. /// <summary>
  489. /// 删除config文件节点中内容信息
  490. /// </summary>
  491. public bool DelConfigNodeContentInfo(string delControlName, string selName)
  492. {
  493. try
  494. {
  495. switch (delControlName)
  496. {
  497. case "WYP":
  498. //样品类型
  499. List<String> _sT = sT.ToList();
  500. _sT.Remove(selName);
  501. string wsT = string.Join(",", _sT.ToArray());
  502. config.AppSettings.Settings["Sample_Type"].Value = wsT;
  503. break;
  504. case "WCS":
  505. //厂商
  506. List<String> _firms = firms.ToList();
  507. _firms.Remove(selName);
  508. string wFirms = string.Join(",", _firms.ToArray());
  509. config.AppSettings.Settings["Firm"].Value = wFirms;
  510. break;
  511. case "WPZD":
  512. //拍照电压
  513. List<String> _WPZD = WPZD.ToList();
  514. _WPZD.Remove(selName);
  515. string wWPZD = string.Join(",", _WPZD.ToArray());
  516. config.AppSettings.Settings["WPZD"].Value = wWPZD;
  517. break;
  518. case "WPZF":
  519. //拍照放大位数
  520. List<String> _WPZF = WPZF.ToList();
  521. _WPZF.Remove(selName);
  522. string wWPZF = string.Join(",", _WPZF.ToArray());
  523. config.AppSettings.Settings["WPZF"].Value = wWPZF;
  524. break;
  525. case "WQGD"://定位切割电压
  526. List<String> _WQGD = WQGD.ToList();
  527. _WQGD.Remove(selName);
  528. string wWQGD = string.Join(",", _WQGD.ToArray());
  529. config.AppSettings.Settings["WQGD"].Value = wWQGD;
  530. break;
  531. case "WQGF": //定位切割放大位数
  532. List<String> _WQGF = WQGF.ToList();
  533. _WQGF.Remove(selName);
  534. string wWQGF = string.Join(",", _WQGF.ToArray());
  535. config.AppSettings.Settings["WQGF"].Value = wWQGF;
  536. break;
  537. case "WLZ":
  538. //拉直操作放大位数
  539. List<String> _WLZ = WLZ.ToList();
  540. _WLZ.Remove(selName);
  541. string wWLZ = string.Join(",", _WLZ.ToArray());
  542. config.AppSettings.Settings["WLZ"].Value = wWLZ;
  543. break;
  544. }
  545. config.Save(ConfigurationSaveMode.Modified);
  546. ConfigurationManager.RefreshSection("appSettings");//重新加载新的配置文件
  547. return true;
  548. }
  549. catch (Exception ex)
  550. {
  551. LogManager.LogError(ex.Message);
  552. return true;
  553. }
  554. }
  555. /// <summary>
  556. /// 绑定下拉菜单
  557. /// </summary>
  558. /// <param name="cb"></param>
  559. /// <param name="strGroup"></param>
  560. private void BindComboxData(ComboBox cb, string[] strGroup)
  561. {
  562. for (int i = 0; i < strGroup.Length; i++)
  563. {
  564. if (!strGroup[i].Equals(""))
  565. {
  566. cb.Items.Add(strGroup[i]);
  567. }
  568. }
  569. }
  570. /// <summary>
  571. /// 读取Config文件信息
  572. /// </summary>
  573. public void ReloadConfig()
  574. {
  575. cbbWYP.Items.Clear();
  576. cbbWCS.Items.Clear();
  577. cbbWPZD.Items.Clear();
  578. cbbWPZF.Items.Clear();
  579. cbbWQGD.Items.Clear();
  580. cbbWQGF.Items.Clear();
  581. cbbWLZ.Items.Clear();
  582. cbbWFIB.Items.Clear();
  583. m_TemplateFilePath = config.AppSettings.Settings["TemplateFilePath"].Value.ToString();
  584. string sample_Type = config.AppSettings.Settings["Sample_Type"].Value.ToString();
  585. string firm = config.AppSettings.Settings["Firm"].Value.ToString();
  586. string WPZDTemp = config.AppSettings.Settings["WPZD"].Value.ToString();
  587. string WPZFTemp = config.AppSettings.Settings["WPZF"].Value.ToString();
  588. string WQGDTemp = config.AppSettings.Settings["WQGD"].Value.ToString();
  589. string WQGFTemp = config.AppSettings.Settings["WQGF"].Value.ToString();
  590. string WLZTemp = config.AppSettings.Settings["WLZ"].Value.ToString();
  591. string WFIBTemp = config.AppSettings.Settings["WFIB"].Value.ToString();
  592. //样品类型
  593. sT = sample_Type.Split(',');
  594. BindComboxData(cbbWYP, sT);
  595. //厂商
  596. firms = firm.Split(',');
  597. BindComboxData(cbbWCS, firms);
  598. //拍照电压
  599. WPZD = WPZDTemp.Split(',');
  600. BindComboxData(cbbWPZD, WPZD);
  601. //拍照放大位数
  602. WPZF = WPZFTemp.Split(',');
  603. BindComboxData(cbbWPZF, WPZF);
  604. //定位切割电压
  605. WQGD = WQGDTemp.Split(',');
  606. BindComboxData(cbbWQGD, WQGD);
  607. //定位切割放大位数
  608. WQGF = WQGFTemp.Split(',');
  609. BindComboxData(cbbWQGF, WQGF);
  610. //拉直操作放大位数
  611. WLZ = WLZTemp.Split(',');
  612. BindComboxData(cbbWLZ, WLZ);
  613. //FIB放大倍数
  614. WFIB = WFIBTemp.Split(',');
  615. BindComboxData(cbbWFIB, WFIB);
  616. //设置配置文件默认值
  617. chkWIsP.Checked=Convert.ToBoolean(config.AppSettings.Settings["Is_Photograph"].Value);
  618. chkWPT.Checked = Convert.ToBoolean(config.AppSettings.Settings["PT_Depostion"].Value);
  619. //自动对焦模式
  620. //chkManul.Checked = Convert.ToBoolean(config.AppSettings.Settings["Focus_Mode"].Value);
  621. txtWPTF.Text = config.AppSettings.Settings["PT_ELYFile"].Value;
  622. txtWFIBF.Text = config.AppSettings.Settings["FIB_ELYFile"].Value;
  623. cbbWLZ.Text = config.AppSettings.Settings["Stretch_Magnification"].Value;
  624. cbbWQGF.Text = config.AppSettings.Settings["Location_Magnification"].Value;
  625. cbbWQGD.Text = config.AppSettings.Settings["Location_Voltage"].Value;
  626. cbbWPZF.Text = config.AppSettings.Settings["Photograph_Magnification"].Value;
  627. cbbWPZD.Text = config.AppSettings.Settings["Photograph_Voltage"].Value;
  628. cbbWFIB.Text = config.AppSettings.Settings["FIB_Magnification"].Value;
  629. string Correction_Angle = config.AppSettings.Settings["Correction_Angle"].Value;
  630. if (Correction_Angle == "36")
  631. {
  632. cbbWXZ.SelectedIndex = 0;
  633. }
  634. else
  635. {
  636. cbbWXZ.SelectedIndex = 1;
  637. }
  638. cbbWYP.Text = config.AppSettings.Settings["SampleName"].Value;
  639. cbbWCS.Text = config.AppSettings.Settings["Firms"].Value;
  640. }
  641. /// <summary>
  642. /// 根据所选路径,读取模板文件
  643. /// </summary>
  644. public void ReadConfigInfo()
  645. {
  646. if (!ReadConfigPath.Equals(""))
  647. {
  648. ReloadConfig();
  649. ConfigFile cfm = new ConfigFile(new MeasureParam());
  650. cfm.Read(ReadConfigPath);
  651. chkWIsP.Checked = cfm.m_Config.Is_Photograph;
  652. chkWPT.Checked = cfm.m_Config.PT;
  653. //自动对焦模式
  654. //cfm.FocusMode = chkManul.Checked;
  655. txtWPTF.Text = cfm.m_Config.PTTemp;
  656. txtWFIBF.Text = cfm.m_Config.FIBTemp;
  657. cbbWLZ.Text = cfm.m_Config.Stretch_Magnification.ToString();
  658. cbbWQGF.Text = cfm.m_Config.Location_Magnification.ToString();
  659. cbbWQGD.Text = cfm.m_Config.Location_Voltage.ToString();
  660. cbbWPZF.Text = cfm.m_Config.Photograph_Magnification.ToString();
  661. cbbWPZD.Text = cfm.m_Config.Photograph_Voltage.ToString();
  662. cbbWFIB.Text = cfm.m_Config.FIB_Magnification.ToString();
  663. string Correction_Angle = cfm.m_Config.Correction_Angle.ToString();
  664. if (Correction_Angle == "36")
  665. {
  666. cbbWXZ.SelectedIndex = 0;
  667. }
  668. else
  669. {
  670. cbbWXZ.SelectedIndex = 1;
  671. }
  672. cbbWYP.Text = cfm.m_Config.SampleName;
  673. cbbWCS.Text = cfm.m_Config.Firm;
  674. }
  675. }
  676. /// <summary>
  677. /// 修改配置文件默认值
  678. /// </summary>
  679. /// <param name="sender"></param>
  680. /// <param name="e"></param>
  681. private void btnSaveDefalutPara_Click(object sender, EventArgs e)
  682. {
  683. if (Convert.ToInt32(cbbWFIB.Text) < 200)
  684. {
  685. MessageBox.Show("FIB最小放大倍数为200倍");
  686. }
  687. else
  688. {
  689. if (EditConfig())
  690. {
  691. MessageBox.Show("保存成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  692. }
  693. }
  694. }
  695. #endregion
  696. #region 删除下拉菜单选择项
  697. private void DelComboBoxItem_Click(object sender, EventArgs e)
  698. {
  699. if (MessageBox.Show("是否删除所选项信息?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
  700. {
  701. PictureBox pbDel = (PictureBox)sender;
  702. string ctrlName = pbDel.Name.Substring(5, pbDel.Name.Length - 5);
  703. if (DelComboBoxItem(ctrlName))
  704. {
  705. //重新加载
  706. ReloadConfig();
  707. }
  708. }
  709. }
  710. /// <summary>
  711. /// 删除下拉菜单选择项
  712. /// </summary>
  713. public bool DelComboBoxItem(string controlName)
  714. {
  715. string delName = controlName;
  716. foreach (Control item in this.Controls)
  717. {
  718. if (item is ComboBox)
  719. {
  720. if (item.Name.Contains(delName))
  721. {
  722. ComboBox cb = (ComboBox)item;
  723. return DelConfigNodeContentInfo(delName, cb.Text);
  724. }
  725. }
  726. }
  727. return false;
  728. }
  729. #endregion
  730. #region 根据是否仅拍照,进行逻辑判断
  731. private void chkWIsP_CheckedChanged(object sender, EventArgs e)
  732. {
  733. if (chkWIsP.Checked)
  734. {
  735. chkWPT.Checked = false;
  736. chkWPT.Visible = false;
  737. label61.Visible = false;
  738. label59.Visible = false;
  739. txtWFIBF.Visible = false;
  740. txtWPTF.Visible = false;
  741. pbPTTemplateFile.Visible = false;
  742. pbFIBTemplateFile.Visible = false;
  743. label58.Visible = false;
  744. cbbWXZ.Visible = false;
  745. label2.Visible = false;
  746. cbbWFIB.Visible = false;
  747. FormHOZMainObject.m_MeasureType = (int)MeasureMsgManage.measureType.Photo;
  748. }
  749. else
  750. {
  751. chkWPT.Visible = true;
  752. label61.Visible = true;
  753. label59.Visible = true;
  754. txtWFIBF.Visible = true;
  755. txtWPTF.Visible = true;
  756. pbPTTemplateFile.Visible = true;
  757. pbFIBTemplateFile.Visible = true;
  758. label58.Visible = true;
  759. cbbWXZ.Visible = true;
  760. label2.Visible = true;
  761. cbbWFIB.Visible = true;
  762. if (!chkWPT.Checked)
  763. {
  764. FormHOZMainObject.m_MeasureType = (int)MeasureMsgManage.measureType.FIB;
  765. }
  766. }
  767. CreateCutHoleList();
  768. }
  769. #endregion
  770. public MeasureParam GetMeasureParam()
  771. {
  772. MeasureParam cfm = new MeasureParam();
  773. //设置配置文件默认值
  774. bool bResult = false;
  775. bool.TryParse(config.AppSettings.Settings["Is_Photograph"].Value, out bResult);
  776. cfm.Is_Photograph = bResult;
  777. bool.TryParse(config.AppSettings.Settings["PT_Depostion"].Value, out bResult);
  778. cfm.PT = bResult;
  779. cfm.PTTemp = config.AppSettings.Settings["PT_ELYFile"].Value;
  780. cfm.FIBTemp = config.AppSettings.Settings["FIB_ELYFile"].Value;
  781. float fResult = (float)0.0;
  782. float.TryParse(config.AppSettings.Settings["Stretch_Magnification"].Value, out fResult);
  783. cfm.Stretch_Magnification = fResult;
  784. float.TryParse(config.AppSettings.Settings["Location_Magnification"].Value, out fResult);
  785. cfm.Location_Magnification = fResult;
  786. float.TryParse(config.AppSettings.Settings["Location_Voltage"].Value, out fResult);
  787. cfm.Location_Voltage = fResult;
  788. float.TryParse(config.AppSettings.Settings["Photograph_Magnification"].Value, out fResult);
  789. cfm.Photograph_Magnification = fResult;
  790. float.TryParse(config.AppSettings.Settings["Photograph_Voltage"].Value, out fResult);
  791. cfm.Photograph_Voltage = fResult;
  792. float.TryParse(config.AppSettings.Settings["Correction_Angle"].Value, out fResult);
  793. cfm.Correction_Angle = fResult;
  794. cfm.SampleName = config.AppSettings.Settings["SampleName"].Value;
  795. cfm.Firm = config.AppSettings.Settings["Firms"].Value;
  796. cfm.AutoFocus.UP = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_UP"].ToString());
  797. cfm.AutoFocus.Down = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_Down"].ToString());
  798. cfm.AutoFocus.Step = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_Step"].ToString());
  799. cfm.AutoFocus.Range = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_Range"].ToString());
  800. cfm.AutoFocus.fStep = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_FStep"].ToString());
  801. cfm.FIBFocus.UP = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_UP"].ToString());
  802. cfm.FIBFocus.Down = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_Down"].ToString());
  803. cfm.FIBFocus.Step = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_Step"].ToString());
  804. cfm.FIBFocus.Range = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_Range"].ToString());
  805. cfm.FIBFocus.fStep = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_FStep"].ToString());
  806. cfm.AutoStigX.UP = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_UP"].ToString());
  807. cfm.AutoStigX.Down = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_Down"].ToString());
  808. cfm.AutoStigX.Step = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_Step"].ToString());
  809. cfm.AutoStigX.Range = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_Range"].ToString());
  810. cfm.AutoStigX.fStep = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_FStep"].ToString());
  811. cfm.AutoStigY.UP = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_UP"].ToString());
  812. cfm.AutoStigY.Down = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_Down"].ToString());
  813. cfm.AutoStigY.Step = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_Step"].ToString());
  814. cfm.AutoStigY.Range = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_Range"].ToString());
  815. cfm.AutoStigY.fStep = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_FStep"].ToString());
  816. return cfm;
  817. }
  818. #region 创建切孔列表
  819. private void CreateCutHoleList()
  820. {
  821. List<CutHole> ListCutHole = FormHOZMainObject.m_MeasureFile.ListCutHole;
  822. FormHOZMainObject.CreateCutHoleList(ListCutHole);
  823. }
  824. #endregion
  825. #region 设置流程类型
  826. private void chkWPT_CheckedChanged(object sender, EventArgs e)
  827. {
  828. if (chkWPT.Checked)
  829. {
  830. FormHOZMainObject.m_MeasureType = (int)MeasureMsgManage.measureType.PT;
  831. }
  832. else
  833. {
  834. if (!chkWIsP.Checked)
  835. {
  836. FormHOZMainObject.m_MeasureType = (int)MeasureMsgManage.measureType.FIB;
  837. }
  838. }
  839. CreateCutHoleList();
  840. }
  841. #endregion
  842. #region 关闭按钮 鼠标操作事件
  843. private void pbClose_MouseEnter(object sender, EventArgs e)
  844. {
  845. pbClose.BackgroundImage = global::HOZProject.Properties.Resources.exit_Red;
  846. }
  847. private void pbClose_MouseLeave(object sender, EventArgs e)
  848. {
  849. pbClose.BackgroundImage = global::HOZProject.Properties.Resources.exit_Gray;
  850. }
  851. #endregion
  852. #region 输入限制只能是数字
  853. private void ComboBox_KeyPress(string text, object sender, KeyPressEventArgs e)
  854. {
  855. //允许输入数字、小数点、删除键和负号
  856. if ((e.KeyChar < 48 || e.KeyChar > 57) && e.KeyChar != 8 && e.KeyChar != (char)('.') && e.KeyChar != (char)('-'))
  857. {
  858. MessageBox.Show("请输入正确的数字");
  859. text = "";
  860. e.Handled = true;
  861. }
  862. if (e.KeyChar == (char)('-'))
  863. {
  864. if (text != "")
  865. {
  866. MessageBox.Show("请输入正确的数字");
  867. text = "";
  868. e.Handled = true;
  869. }
  870. }
  871. //小数点只能输入一次
  872. if (e.KeyChar == (char)('.') && ((ComboBox)sender).Text.IndexOf('.') != -1)
  873. {
  874. MessageBox.Show("请输入正确的数字");
  875. text = "";
  876. e.Handled = true;
  877. }
  878. //第一位不能为小数点
  879. if (e.KeyChar == (char)('.') && ((ComboBox)sender).Text == "")
  880. {
  881. MessageBox.Show("请输入正确的数字");
  882. text = "";
  883. e.Handled = true;
  884. }
  885. //第一位是0,第二位必须为小数点
  886. if (e.KeyChar != (char)('.') && ((ComboBox)sender).Text == "0")
  887. {
  888. MessageBox.Show("请输入正确的数字");
  889. text = "";
  890. e.Handled = true;
  891. }
  892. //第一位是负号,第二位不能为小数点
  893. if (((ComboBox)sender).Text == "-" && e.KeyChar == (char)('.'))
  894. {
  895. MessageBox.Show("请输入正确的数字");
  896. text = "";
  897. e.Handled = true;
  898. }
  899. }
  900. private void cbbWPZD_KeyPress(object sender, KeyPressEventArgs e)
  901. {
  902. ComboBox_KeyPress(cbbWPZD.Text, sender, e);
  903. }
  904. private void cbbWPZF_KeyPress(object sender, KeyPressEventArgs e)
  905. {
  906. ComboBox_KeyPress(cbbWPZF.Text, sender, e);
  907. }
  908. private void cbbWQGD_KeyPress(object sender, KeyPressEventArgs e)
  909. {
  910. ComboBox_KeyPress(cbbWQGD.Text, sender, e);
  911. }
  912. private void cbbWQGF_KeyPress(object sender, KeyPressEventArgs e)
  913. {
  914. ComboBox_KeyPress(cbbWQGF.Text, sender, e);
  915. }
  916. private void cbbWLZ_KeyPress(object sender, KeyPressEventArgs e)
  917. {
  918. ComboBox_KeyPress(cbbWLZ.Text, sender, e);
  919. }
  920. private void cbbWFIB_KeyPress(object sender, KeyPressEventArgs e)
  921. {
  922. ComboBox_KeyPress(cbbWFIB.Text, sender, e);
  923. }
  924. #endregion
  925. private void chkWqxkc_CheckedChanged(object sender, EventArgs e)
  926. {
  927. if (chkWqxkc.Checked)
  928. {
  929. label3.Visible = true;
  930. cbbYDZZDX.Visible = true;
  931. }
  932. else
  933. {
  934. label3.Visible = false;
  935. cbbYDZZDX.Visible = false;
  936. }
  937. }
  938. }
  939. }