UControl_Init.cs 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079
  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. //倾斜观测
  457. cfm.Title = chkWqxkc.Checked;
  458. //移动Z轴大小
  459. cfm.ZDistance = Convert.ToSingle(cbbYDZZDX.Text);
  460. if (cbbWXZ.SelectedIndex == 0)
  461. {
  462. cfm.Correction_Angle = 36;
  463. }
  464. else
  465. {
  466. cfm.Correction_Angle = 54;
  467. }
  468. cfm.SampleName = cbbWYP.Text;
  469. cfm.Firm = cbbWCS.Text;
  470. //设置配置文件默认值
  471. config.AppSettings.Settings["Is_Photograph"].Value = cfm.Is_Photograph.ToString();
  472. config.AppSettings.Settings["PT_Depostion"].Value = cfm.PT.ToString();
  473. config.AppSettings.Settings["PT_ELYFile"].Value = cfm.PTTemp;
  474. config.AppSettings.Settings["FIB_ELYFile"].Value = cfm.FIBTemp;
  475. config.AppSettings.Settings["Stretch_Magnification"].Value = cfm.Stretch_Magnification.ToString();
  476. config.AppSettings.Settings["Location_Magnification"].Value = cfm.Location_Magnification.ToString();
  477. config.AppSettings.Settings["Location_Voltage"].Value = cfm.Location_Voltage.ToString();
  478. config.AppSettings.Settings["Photograph_Magnification"].Value = cfm.Photograph_Magnification.ToString();
  479. config.AppSettings.Settings["Photograph_Voltage"].Value = cfm.Photograph_Voltage.ToString();
  480. config.AppSettings.Settings["Correction_Angle"].Value = cfm.Correction_Angle.ToString();
  481. config.AppSettings.Settings["SampleName"].Value = cfm.SampleName;
  482. config.AppSettings.Settings["Firms"].Value = cfm.Firm;
  483. config.AppSettings.Settings["Is_Title"].Value = cfm.Title.ToString();
  484. config.AppSettings.Settings["ZDistance"].Value = cfm.ZDistance.ToString();
  485. config.Save(ConfigurationSaveMode.Modified);
  486. ConfigurationManager.RefreshSection("appSettings");//重新加载新的配置文件
  487. return true;
  488. }
  489. catch (Exception ex)
  490. {
  491. LogManager.LogError(ex.Message);
  492. return false;
  493. }
  494. }
  495. /// <summary>
  496. /// 删除config文件节点中内容信息
  497. /// </summary>
  498. public bool DelConfigNodeContentInfo(string delControlName, string selName)
  499. {
  500. try
  501. {
  502. switch (delControlName)
  503. {
  504. case "WYP":
  505. //样品类型
  506. List<String> _sT = sT.ToList();
  507. _sT.Remove(selName);
  508. string wsT = string.Join(",", _sT.ToArray());
  509. config.AppSettings.Settings["Sample_Type"].Value = wsT;
  510. break;
  511. case "WCS":
  512. //厂商
  513. List<String> _firms = firms.ToList();
  514. _firms.Remove(selName);
  515. string wFirms = string.Join(",", _firms.ToArray());
  516. config.AppSettings.Settings["Firm"].Value = wFirms;
  517. break;
  518. case "WPZD":
  519. //拍照电压
  520. List<String> _WPZD = WPZD.ToList();
  521. _WPZD.Remove(selName);
  522. string wWPZD = string.Join(",", _WPZD.ToArray());
  523. config.AppSettings.Settings["WPZD"].Value = wWPZD;
  524. break;
  525. case "WPZF":
  526. //拍照放大位数
  527. List<String> _WPZF = WPZF.ToList();
  528. _WPZF.Remove(selName);
  529. string wWPZF = string.Join(",", _WPZF.ToArray());
  530. config.AppSettings.Settings["WPZF"].Value = wWPZF;
  531. break;
  532. case "WQGD"://定位切割电压
  533. List<String> _WQGD = WQGD.ToList();
  534. _WQGD.Remove(selName);
  535. string wWQGD = string.Join(",", _WQGD.ToArray());
  536. config.AppSettings.Settings["WQGD"].Value = wWQGD;
  537. break;
  538. case "WQGF": //定位切割放大位数
  539. List<String> _WQGF = WQGF.ToList();
  540. _WQGF.Remove(selName);
  541. string wWQGF = string.Join(",", _WQGF.ToArray());
  542. config.AppSettings.Settings["WQGF"].Value = wWQGF;
  543. break;
  544. case "WLZ":
  545. //拉直操作放大位数
  546. List<String> _WLZ = WLZ.ToList();
  547. _WLZ.Remove(selName);
  548. string wWLZ = string.Join(",", _WLZ.ToArray());
  549. config.AppSettings.Settings["WLZ"].Value = wWLZ;
  550. break;
  551. }
  552. config.Save(ConfigurationSaveMode.Modified);
  553. ConfigurationManager.RefreshSection("appSettings");//重新加载新的配置文件
  554. return true;
  555. }
  556. catch (Exception ex)
  557. {
  558. LogManager.LogError(ex.Message);
  559. return true;
  560. }
  561. }
  562. /// <summary>
  563. /// 绑定下拉菜单
  564. /// </summary>
  565. /// <param name="cb"></param>
  566. /// <param name="strGroup"></param>
  567. private void BindComboxData(ComboBox cb, string[] strGroup)
  568. {
  569. for (int i = 0; i < strGroup.Length; i++)
  570. {
  571. if (!strGroup[i].Equals(""))
  572. {
  573. cb.Items.Add(strGroup[i]);
  574. }
  575. }
  576. }
  577. /// <summary>
  578. /// 读取Config文件信息
  579. /// </summary>
  580. public void ReloadConfig()
  581. {
  582. cbbWYP.Items.Clear();
  583. cbbWCS.Items.Clear();
  584. cbbWPZD.Items.Clear();
  585. cbbWPZF.Items.Clear();
  586. cbbWQGD.Items.Clear();
  587. cbbWQGF.Items.Clear();
  588. cbbWLZ.Items.Clear();
  589. cbbWFIB.Items.Clear();
  590. cbbYDZZDX.Text = "0";
  591. m_TemplateFilePath = config.AppSettings.Settings["TemplateFilePath"].Value.ToString();
  592. string sample_Type = config.AppSettings.Settings["Sample_Type"].Value.ToString();
  593. string firm = config.AppSettings.Settings["Firm"].Value.ToString();
  594. string WPZDTemp = config.AppSettings.Settings["WPZD"].Value.ToString();
  595. string WPZFTemp = config.AppSettings.Settings["WPZF"].Value.ToString();
  596. string WQGDTemp = config.AppSettings.Settings["WQGD"].Value.ToString();
  597. string WQGFTemp = config.AppSettings.Settings["WQGF"].Value.ToString();
  598. string WLZTemp = config.AppSettings.Settings["WLZ"].Value.ToString();
  599. string WFIBTemp = config.AppSettings.Settings["WFIB"].Value.ToString();
  600. //string ZZDistance = config.AppSettings.Settings["ZDistance"].Value.ToString();
  601. //样品类型
  602. sT = sample_Type.Split(',');
  603. BindComboxData(cbbWYP, sT);
  604. //厂商
  605. firms = firm.Split(',');
  606. BindComboxData(cbbWCS, firms);
  607. //拍照电压
  608. WPZD = WPZDTemp.Split(',');
  609. BindComboxData(cbbWPZD, WPZD);
  610. //拍照放大位数
  611. WPZF = WPZFTemp.Split(',');
  612. BindComboxData(cbbWPZF, WPZF);
  613. //定位切割电压
  614. WQGD = WQGDTemp.Split(',');
  615. BindComboxData(cbbWQGD, WQGD);
  616. //定位切割放大位数
  617. WQGF = WQGFTemp.Split(',');
  618. BindComboxData(cbbWQGF, WQGF);
  619. //拉直操作放大位数
  620. WLZ = WLZTemp.Split(',');
  621. BindComboxData(cbbWLZ, WLZ);
  622. //FIB放大倍数
  623. WFIB = WFIBTemp.Split(',');
  624. BindComboxData(cbbWFIB, WFIB);
  625. //设置配置文件默认值
  626. chkWIsP.Checked=Convert.ToBoolean(config.AppSettings.Settings["Is_Photograph"].Value);
  627. chkWPT.Checked = Convert.ToBoolean(config.AppSettings.Settings["PT_Depostion"].Value);
  628. //倾斜观测
  629. chkWqxkc.Checked = Convert.ToBoolean(config.AppSettings.Settings["Is_Title"].Value);
  630. //移动Z轴大小
  631. cbbYDZZDX.Text = config.AppSettings.Settings["ZDistance"].Value;
  632. //自动对焦模式
  633. //chkManul.Checked = Convert.ToBoolean(config.AppSettings.Settings["Focus_Mode"].Value);
  634. txtWPTF.Text = config.AppSettings.Settings["PT_ELYFile"].Value;
  635. txtWFIBF.Text = config.AppSettings.Settings["FIB_ELYFile"].Value;
  636. cbbWLZ.Text = config.AppSettings.Settings["Stretch_Magnification"].Value;
  637. cbbWQGF.Text = config.AppSettings.Settings["Location_Magnification"].Value;
  638. cbbWQGD.Text = config.AppSettings.Settings["Location_Voltage"].Value;
  639. cbbWPZF.Text = config.AppSettings.Settings["Photograph_Magnification"].Value;
  640. cbbWPZD.Text = config.AppSettings.Settings["Photograph_Voltage"].Value;
  641. cbbWFIB.Text = config.AppSettings.Settings["FIB_Magnification"].Value;
  642. string Correction_Angle = config.AppSettings.Settings["Correction_Angle"].Value;
  643. if (Convert.ToBoolean(config.AppSettings.Settings["Is_Title"].Value))
  644. {
  645. cbbYDZZDX.Visible = true;
  646. label3.Visible = true;
  647. }
  648. else
  649. {
  650. cbbYDZZDX.Visible = false;
  651. label3.Visible = false;
  652. }
  653. if (Correction_Angle == "36")
  654. {
  655. cbbWXZ.SelectedIndex = 0;
  656. }
  657. else
  658. {
  659. cbbWXZ.SelectedIndex = 1;
  660. }
  661. cbbWYP.Text = config.AppSettings.Settings["SampleName"].Value;
  662. cbbWCS.Text = config.AppSettings.Settings["Firms"].Value;
  663. }
  664. /// <summary>
  665. /// 根据所选路径,读取模板文件
  666. /// </summary>
  667. public void ReadConfigInfo()
  668. {
  669. if (!ReadConfigPath.Equals(""))
  670. {
  671. ReloadConfig();
  672. ConfigFile cfm = new ConfigFile(new MeasureParam());
  673. cfm.Read(ReadConfigPath);
  674. chkWIsP.Checked = cfm.m_Config.Is_Photograph;
  675. chkWPT.Checked = cfm.m_Config.PT;
  676. //自动对焦模式
  677. //cfm.FocusMode = chkManul.Checked;
  678. txtWPTF.Text = cfm.m_Config.PTTemp;
  679. txtWFIBF.Text = cfm.m_Config.FIBTemp;
  680. cbbWLZ.Text = cfm.m_Config.Stretch_Magnification.ToString();
  681. cbbWQGF.Text = cfm.m_Config.Location_Magnification.ToString();
  682. cbbWQGD.Text = cfm.m_Config.Location_Voltage.ToString();
  683. cbbWPZF.Text = cfm.m_Config.Photograph_Magnification.ToString();
  684. cbbWPZD.Text = cfm.m_Config.Photograph_Voltage.ToString();
  685. cbbWFIB.Text = cfm.m_Config.FIB_Magnification.ToString();
  686. string Correction_Angle = cfm.m_Config.Correction_Angle.ToString();
  687. if (Correction_Angle == "36")
  688. {
  689. cbbWXZ.SelectedIndex = 0;
  690. }
  691. else
  692. {
  693. cbbWXZ.SelectedIndex = 1;
  694. }
  695. cbbWYP.Text = cfm.m_Config.SampleName;
  696. cbbWCS.Text = cfm.m_Config.Firm;
  697. }
  698. }
  699. /// <summary>
  700. /// 修改配置文件默认值
  701. /// </summary>
  702. /// <param name="sender"></param>
  703. /// <param name="e"></param>
  704. private void btnSaveDefalutPara_Click(object sender, EventArgs e)
  705. {
  706. if (Convert.ToInt32(cbbWFIB.Text) < 200)
  707. {
  708. MessageBox.Show("FIB最小放大倍数为200倍");
  709. }
  710. else
  711. {
  712. if (EditConfig())
  713. {
  714. MessageBox.Show("保存成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  715. }
  716. }
  717. }
  718. #endregion
  719. #region 删除下拉菜单选择项
  720. private void DelComboBoxItem_Click(object sender, EventArgs e)
  721. {
  722. if (MessageBox.Show("是否删除所选项信息?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
  723. {
  724. PictureBox pbDel = (PictureBox)sender;
  725. string ctrlName = pbDel.Name.Substring(5, pbDel.Name.Length - 5);
  726. if (DelComboBoxItem(ctrlName))
  727. {
  728. //重新加载
  729. ReloadConfig();
  730. }
  731. }
  732. }
  733. /// <summary>
  734. /// 删除下拉菜单选择项
  735. /// </summary>
  736. public bool DelComboBoxItem(string controlName)
  737. {
  738. string delName = controlName;
  739. foreach (Control item in this.Controls)
  740. {
  741. if (item is ComboBox)
  742. {
  743. if (item.Name.Contains(delName))
  744. {
  745. ComboBox cb = (ComboBox)item;
  746. return DelConfigNodeContentInfo(delName, cb.Text);
  747. }
  748. }
  749. }
  750. return false;
  751. }
  752. #endregion
  753. #region 根据是否仅拍照,进行逻辑判断
  754. private void chkWIsP_CheckedChanged(object sender, EventArgs e)
  755. {
  756. if (chkWIsP.Checked)
  757. {
  758. chkWPT.Checked = false;
  759. chkWPT.Visible = false;
  760. label61.Visible = false;
  761. label59.Visible = false;
  762. txtWFIBF.Visible = false;
  763. txtWPTF.Visible = false;
  764. pbPTTemplateFile.Visible = false;
  765. pbFIBTemplateFile.Visible = false;
  766. label58.Visible = false;
  767. cbbWXZ.Visible = false;
  768. label2.Visible = false;
  769. cbbWFIB.Visible = false;
  770. FormHOZMainObject.m_MeasureType = (int)MeasureMsgManage.measureType.Photo;
  771. }
  772. else
  773. {
  774. chkWPT.Visible = true;
  775. label61.Visible = true;
  776. label59.Visible = true;
  777. txtWFIBF.Visible = true;
  778. txtWPTF.Visible = true;
  779. pbPTTemplateFile.Visible = true;
  780. pbFIBTemplateFile.Visible = true;
  781. label58.Visible = true;
  782. cbbWXZ.Visible = true;
  783. label2.Visible = true;
  784. cbbWFIB.Visible = true;
  785. if (!chkWPT.Checked)
  786. {
  787. FormHOZMainObject.m_MeasureType = (int)MeasureMsgManage.measureType.FIB;
  788. }
  789. }
  790. CreateCutHoleList();
  791. }
  792. #endregion
  793. public MeasureParam GetMeasureParam()
  794. {
  795. MeasureParam cfm = new MeasureParam();
  796. //设置配置文件默认值
  797. bool bResult = false;
  798. bool.TryParse(config.AppSettings.Settings["Is_Photograph"].Value, out bResult);
  799. cfm.Is_Photograph = bResult;
  800. bool.TryParse(config.AppSettings.Settings["PT_Depostion"].Value, out bResult);
  801. cfm.PT = bResult;
  802. cfm.PTTemp = config.AppSettings.Settings["PT_ELYFile"].Value;
  803. cfm.FIBTemp = config.AppSettings.Settings["FIB_ELYFile"].Value;
  804. float fResult = (float)0.0;
  805. float.TryParse(config.AppSettings.Settings["Stretch_Magnification"].Value, out fResult);
  806. cfm.Stretch_Magnification = fResult;
  807. float.TryParse(config.AppSettings.Settings["Location_Magnification"].Value, out fResult);
  808. cfm.Location_Magnification = fResult;
  809. float.TryParse(config.AppSettings.Settings["Location_Voltage"].Value, out fResult);
  810. cfm.Location_Voltage = fResult;
  811. float.TryParse(config.AppSettings.Settings["Photograph_Magnification"].Value, out fResult);
  812. cfm.Photograph_Magnification = fResult;
  813. float.TryParse(config.AppSettings.Settings["Photograph_Voltage"].Value, out fResult);
  814. cfm.Photograph_Voltage = fResult;
  815. float.TryParse(config.AppSettings.Settings["Correction_Angle"].Value, out fResult);
  816. cfm.Correction_Angle = fResult;
  817. cfm.SampleName = config.AppSettings.Settings["SampleName"].Value;
  818. cfm.Firm = config.AppSettings.Settings["Firms"].Value;
  819. cfm.AutoFocus.UP = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_UP"].ToString());
  820. cfm.AutoFocus.Down = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_Down"].ToString());
  821. cfm.AutoFocus.Step = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_Step"].ToString());
  822. cfm.AutoFocus.Range = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_Range"].ToString());
  823. cfm.AutoFocus.fStep = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_FStep"].ToString());
  824. cfm.FIBFocus.UP = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_UP"].ToString());
  825. cfm.FIBFocus.Down = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_Down"].ToString());
  826. cfm.FIBFocus.Step = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_Step"].ToString());
  827. cfm.FIBFocus.Range = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_Range"].ToString());
  828. cfm.FIBFocus.fStep = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_FStep"].ToString());
  829. cfm.AutoStigX.UP = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_UP"].ToString());
  830. cfm.AutoStigX.Down = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_Down"].ToString());
  831. cfm.AutoStigX.Step = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_Step"].ToString());
  832. cfm.AutoStigX.Range = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_Range"].ToString());
  833. cfm.AutoStigX.fStep = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_FStep"].ToString());
  834. cfm.AutoStigY.UP = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_UP"].ToString());
  835. cfm.AutoStigY.Down = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_Down"].ToString());
  836. cfm.AutoStigY.Step = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_Step"].ToString());
  837. cfm.AutoStigY.Range = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_Range"].ToString());
  838. cfm.AutoStigY.fStep = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_FStep"].ToString());
  839. bool.TryParse(config.AppSettings.Settings["Is_Title"].Value, out bResult);
  840. cfm.Title = bResult;
  841. float.TryParse(config.AppSettings.Settings["ZDistance"].Value, out fResult);
  842. cfm.ZDistance = fResult;
  843. return cfm;
  844. }
  845. #region 创建切孔列表
  846. private void CreateCutHoleList()
  847. {
  848. List<CutHole> ListCutHole = FormHOZMainObject.m_MeasureFile.ListCutHole;
  849. FormHOZMainObject.CreateCutHoleList(ListCutHole);
  850. }
  851. #endregion
  852. #region 设置流程类型
  853. private void chkWPT_CheckedChanged(object sender, EventArgs e)
  854. {
  855. if (chkWPT.Checked)
  856. {
  857. FormHOZMainObject.m_MeasureType = (int)MeasureMsgManage.measureType.PT;
  858. }
  859. else
  860. {
  861. if (!chkWIsP.Checked)
  862. {
  863. FormHOZMainObject.m_MeasureType = (int)MeasureMsgManage.measureType.FIB;
  864. }
  865. }
  866. CreateCutHoleList();
  867. }
  868. #endregion
  869. #region 关闭按钮 鼠标操作事件
  870. private void pbClose_MouseEnter(object sender, EventArgs e)
  871. {
  872. pbClose.BackgroundImage = global::HOZProject.Properties.Resources.exit_Red;
  873. }
  874. private void pbClose_MouseLeave(object sender, EventArgs e)
  875. {
  876. pbClose.BackgroundImage = global::HOZProject.Properties.Resources.exit_Gray;
  877. }
  878. #endregion
  879. #region 输入限制只能是数字
  880. private void ComboBox_KeyPress(string text, object sender, KeyPressEventArgs e)
  881. {
  882. //允许输入数字、小数点、删除键和负号
  883. if ((e.KeyChar < 48 || e.KeyChar > 57) && e.KeyChar != 8 && e.KeyChar != (char)('.') && e.KeyChar != (char)('-'))
  884. {
  885. MessageBox.Show("请输入正确的数字");
  886. text = "";
  887. e.Handled = true;
  888. }
  889. if (e.KeyChar == (char)('-'))
  890. {
  891. if (text != "")
  892. {
  893. MessageBox.Show("请输入正确的数字");
  894. text = "";
  895. e.Handled = true;
  896. }
  897. }
  898. //小数点只能输入一次
  899. if (e.KeyChar == (char)('.') && ((ComboBox)sender).Text.IndexOf('.') != -1)
  900. {
  901. MessageBox.Show("请输入正确的数字");
  902. text = "";
  903. e.Handled = true;
  904. }
  905. //第一位不能为小数点
  906. if (e.KeyChar == (char)('.') && ((ComboBox)sender).Text == "")
  907. {
  908. MessageBox.Show("请输入正确的数字");
  909. text = "";
  910. e.Handled = true;
  911. }
  912. //第一位是0,第二位必须为小数点
  913. if (e.KeyChar != (char)('.') && ((ComboBox)sender).Text == "0")
  914. {
  915. MessageBox.Show("请输入正确的数字");
  916. text = "";
  917. e.Handled = true;
  918. }
  919. //第一位是负号,第二位不能为小数点
  920. if (((ComboBox)sender).Text == "-" && e.KeyChar == (char)('.'))
  921. {
  922. MessageBox.Show("请输入正确的数字");
  923. text = "";
  924. e.Handled = true;
  925. }
  926. }
  927. private void cbbWPZD_KeyPress(object sender, KeyPressEventArgs e)
  928. {
  929. ComboBox_KeyPress(cbbWPZD.Text, sender, e);
  930. }
  931. private void cbbWPZF_KeyPress(object sender, KeyPressEventArgs e)
  932. {
  933. ComboBox_KeyPress(cbbWPZF.Text, sender, e);
  934. }
  935. private void cbbWQGD_KeyPress(object sender, KeyPressEventArgs e)
  936. {
  937. ComboBox_KeyPress(cbbWQGD.Text, sender, e);
  938. }
  939. private void cbbWQGF_KeyPress(object sender, KeyPressEventArgs e)
  940. {
  941. ComboBox_KeyPress(cbbWQGF.Text, sender, e);
  942. }
  943. private void cbbWLZ_KeyPress(object sender, KeyPressEventArgs e)
  944. {
  945. ComboBox_KeyPress(cbbWLZ.Text, sender, e);
  946. }
  947. private void cbbWFIB_KeyPress(object sender, KeyPressEventArgs e)
  948. {
  949. ComboBox_KeyPress(cbbWFIB.Text, sender, e);
  950. }
  951. #endregion
  952. private void chkWqxkc_CheckedChanged(object sender, EventArgs e)
  953. {
  954. if (chkWqxkc.Checked)
  955. {
  956. label3.Visible = true;
  957. cbbYDZZDX.Visible = true;
  958. }
  959. else
  960. {
  961. label3.Visible = false;
  962. cbbYDZZDX.Visible = false;
  963. }
  964. }
  965. #region 拖动控件
  966. [DllImportAttribute("user32.dll")]
  967. private extern static bool ReleaseCapture();
  968. [DllImportAttribute("user32.dll")]
  969. private extern static int SendMessage(IntPtr handle, int m, int p, int h);
  970. private void panelEx4_MouseDown(object sender, MouseEventArgs e)
  971. {
  972. //DevComponents.DotNetBar.PanelEx p = (DevComponents.DotNetBar.PanelEx)sender;
  973. //if (e.Button == MouseButtons.Left)
  974. //{
  975. // this.Cursor = Cursors.SizeAll;
  976. // ReleaseCapture();
  977. // SendMessage(p.Handle, 0xA1, 0x2, 0); this.Cursor = Cursors.Default;
  978. //}
  979. }
  980. #endregion
  981. private void cbbYDZZDX_TextChanged(object sender, EventArgs e)
  982. {
  983. if (cbbYDZZDX.Text!="")
  984. {
  985. if (Convert.ToSingle(cbbYDZZDX.Text)>40)
  986. {
  987. MessageBox.Show("数值最大为40");
  988. cbbYDZZDX.Text = "40";
  989. }
  990. }
  991. else
  992. {
  993. cbbYDZZDX.Text = "0";
  994. }
  995. }
  996. private void cbbYDZZDX_KeyPress(object sender, KeyPressEventArgs e)
  997. {
  998. if (((int)e.KeyChar < 48 || (int)e.KeyChar > 57) && (int)e.KeyChar != 8 && (int)e.KeyChar != 46)
  999. {
  1000. e.Handled = true;
  1001. }
  1002. }
  1003. }
  1004. }