UControl_Init.cs 42 KB

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