UControl_Init.cs 53 KB

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