UControl_Init.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515
  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. namespace HOZProject
  14. {
  15. public partial class UControl_Init : UserControl
  16. {
  17. #region 全局变量
  18. String[] sT;
  19. String[] firms;
  20. String[] WPZD;
  21. String[] WPZF;
  22. String[] WQGD;
  23. String[] WQGF;
  24. String[] WLZ;
  25. Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
  26. private FormHOZMain formHOZMain;
  27. public FormHOZMain FormHOZMainObject { get => formHOZMain; set => formHOZMain = value; }
  28. //模板路径
  29. private string readConfigPath;
  30. public string ReadConfigPath { get => readConfigPath; set => readConfigPath = value; }
  31. #endregion
  32. #region 构造方法
  33. public UControl_Init(FormHOZMain formHOZ)
  34. {
  35. InitializeComponent();
  36. FormHOZMainObject = formHOZ;
  37. }
  38. #endregion
  39. private void UControl_Init_Load(object sender, EventArgs e)
  40. {
  41. }
  42. #region 关闭窗体
  43. private void btnClose_Click(object sender, EventArgs e)
  44. {
  45. Form fParent = this.ParentForm;
  46. fParent.Close();
  47. }
  48. #endregion
  49. #region 加载切孔文件,生成切孔列表
  50. private void pbCutHoleFile_Click(object sender, EventArgs e)
  51. {
  52. if (FormHOZMainObject.m_MeasureFile == null)
  53. {
  54. MessageBox.Show("请新建一个测量文件");
  55. }
  56. else
  57. {
  58. if (!FormHOZMainObject.m_MeasureFile.GetCutHolesFromFile(""))
  59. {
  60. MessageBox.Show("导入切孔失败");
  61. }
  62. else
  63. {
  64. List<CutHole> ListCutHole = FormHOZMainObject.m_MeasureFile.ListCutHole;
  65. //文件路径
  66. string filePath = FormHOZMainObject.m_MeasureFile.FilePath;
  67. string fileName = FormHOZMainObject.m_MeasureFile.FileName;
  68. FormHOZMainObject.CreateCutHoleList(ListCutHole);
  69. //显示导入的切孔数量
  70. lblCutHoleCount.Text = string.Format("成功导入{0}个切孔", ListCutHole.Count);
  71. tbCutHoleFilePath.Text = filePath + fileName;
  72. }
  73. }
  74. }
  75. #endregion
  76. #region 根据一个切孔文件,自动计算其他切孔信息
  77. /// <summary>
  78. /// 根据一个切孔,自动计算其他切孔信息
  79. /// </summary>
  80. /// <param name="sender"></param>
  81. /// <param name="e"></param>
  82. private void pbCutHoleAuto_Click(object sender, EventArgs e)
  83. {
  84. }
  85. #endregion
  86. #region 加载PT模板文件
  87. private void pbTemplateFile_Click(object sender, EventArgs e)
  88. {
  89. string FilePathName;
  90. string fileNameWithoutExtension;
  91. //新建一个文件对话框
  92. OpenFileDialog pOpenFileDialog = new OpenFileDialog();
  93. //设置对话框标题
  94. pOpenFileDialog.Title = "选择模板文件";
  95. //设置打开文件类型
  96. pOpenFileDialog.Filter = "ely文件(*.ely)|*.ely";
  97. //监测文件是否存在
  98. pOpenFileDialog.CheckFileExists = true;
  99. //文件打开后执行以下程序
  100. if (pOpenFileDialog.ShowDialog() == DialogResult.OK)
  101. {
  102. FilePathName = System.IO.Path.GetFullPath(pOpenFileDialog.FileName); //绝对路径
  103. fileNameWithoutExtension = System.IO.Path.GetFileNameWithoutExtension(FilePathName);
  104. this.txtWPTF.Text = FilePathName;
  105. }
  106. }
  107. #endregion
  108. #region 加载FIB模板文件
  109. private void pbFIBTemplateFile_Click(object sender, EventArgs e)
  110. {
  111. string FilePathName;
  112. string fileNameWithoutExtension;
  113. //新建一个文件对话框
  114. OpenFileDialog pOpenFileDialog = new OpenFileDialog();
  115. //设置对话框标题
  116. pOpenFileDialog.Title = "选择模板文件";
  117. //设置打开文件类型
  118. pOpenFileDialog.Filter = "ely文件(*.ely)|*.ely";
  119. //监测文件是否存在
  120. pOpenFileDialog.CheckFileExists = true;
  121. //文件打开后执行以下程序
  122. if (pOpenFileDialog.ShowDialog() == DialogResult.OK)
  123. {
  124. FilePathName = System.IO.Path.GetFullPath(pOpenFileDialog.FileName); //绝对路径
  125. fileNameWithoutExtension = System.IO.Path.GetFileNameWithoutExtension(FilePathName);
  126. this.txtWFIBF.Text = FilePathName;
  127. }
  128. }
  129. #endregion
  130. #region 创建与读取样品参数、配置文件
  131. private void btnCreateConfig_Click(object sender, EventArgs e)
  132. {
  133. SaveTemplateFile();
  134. }
  135. private void SaveTemplateFile()
  136. {
  137. MeasureParam cfm = new MeasureParam();
  138. cfm.Is_Photograph = chkWIsP.Checked;
  139. cfm.PT = chkWPT.Checked;
  140. cfm.PTTemp = txtWPTF.Text;
  141. cfm.FIBTemp = txtWFIBF.Text;
  142. cfm.Stretch_Magnification = Convert.ToDouble(cbbWLZ.Text);
  143. cfm.Location_Magnification = Convert.ToDouble(cbbWQGF.Text);
  144. cfm.Location_Voltage = Convert.ToDouble(cbbWQGD.Text);
  145. cfm.Photograph_Magnification = Convert.ToDouble(cbbWPZF.Text);
  146. cfm.Photograph_Voltage = Convert.ToDouble(cbbWPZD.Text);
  147. if (cbbWXZ.SelectedIndex == 0)
  148. {
  149. cfm.Correction_Angle = 36.0;
  150. }
  151. else
  152. {
  153. cfm.Correction_Angle = 54.0;
  154. }
  155. cfm.SampleName = cbbWYP.Text;
  156. cfm.Firm = cbbWCS.Text;
  157. ConfigFile cf = new ConfigFile(cfm);
  158. SaveFileDialog saveFileDialog = new SaveFileDialog();
  159. saveFileDialog.Filter = "样品参数文件|*.cfg";
  160. if (saveFileDialog.ShowDialog() == DialogResult.OK)
  161. {
  162. cf.Save(saveFileDialog.FileName);
  163. }
  164. else
  165. {
  166. return;
  167. }
  168. //编辑Config文件
  169. EditConfig();
  170. }
  171. /// <summary>
  172. /// 编辑confing 文件信息
  173. /// </summary>
  174. public void EditConfig()
  175. {
  176. //设置数据源信息
  177. //样品类型
  178. List<String> _sT = sT.ToList();
  179. if (_sT.IndexOf(cbbWYP.Text) < 0)
  180. {
  181. _sT.Add(cbbWYP.Text);
  182. string wsT = string.Join(",", _sT.ToArray());
  183. config.AppSettings.Settings["Sample_Type"].Value = wsT;
  184. }
  185. //厂商
  186. List<String> _firms = firms.ToList();
  187. if (_firms.IndexOf(cbbWCS.Text) < 0)
  188. {
  189. _firms.Add(cbbWCS.Text);
  190. string wFirms = string.Join(",", _firms.ToArray());
  191. config.AppSettings.Settings["Firm"].Value = wFirms;
  192. }
  193. //拍照电压
  194. List<String> _WPZD = WPZD.ToList();
  195. if (_WPZD.IndexOf(cbbWPZD.Text) < 0)
  196. {
  197. _WPZD.Add(cbbWPZD.Text);
  198. string wWPZD = string.Join(",", _WPZD.ToArray());
  199. config.AppSettings.Settings["WPZD"].Value = wWPZD;
  200. }
  201. //拍照放大位数
  202. List<String> _WPZF = WPZF.ToList();
  203. if (_WPZF.IndexOf(cbbWPZF.Text) < 0)
  204. {
  205. _WPZF.Add(cbbWPZF.Text);
  206. string wWPZF = string.Join(",", _WPZF.ToArray());
  207. config.AppSettings.Settings["WPZF"].Value = wWPZF;
  208. }
  209. //定位切割电压
  210. List<String> _WQGD = WQGD.ToList();
  211. if (_WQGD.IndexOf(cbbWQGD.Text) < 0)
  212. {
  213. _WQGD.Add(cbbWQGD.Text);
  214. string wWQGD = string.Join(",", _WQGD.ToArray());
  215. config.AppSettings.Settings["WQGD"].Value = wWQGD;
  216. }
  217. //定位切割放大位数
  218. List<String> _WQGF = WQGF.ToList();
  219. if (_WQGF.IndexOf(cbbWQGF.Text) < 0)
  220. {
  221. _WQGF.Add(cbbWQGF.Text);
  222. string wWQGF = string.Join(",", _WQGF.ToArray());
  223. config.AppSettings.Settings["WQGF"].Value = wWQGF;
  224. }
  225. //拉直操作放大位数
  226. List<String> _WLZ = WLZ.ToList();
  227. if (_WLZ.IndexOf(cbbWLZ.Text) < 0)
  228. {
  229. _WLZ.Add(cbbWLZ.Text);
  230. string wWLZ = string.Join(",", _WLZ.ToArray());
  231. config.AppSettings.Settings["WLZ"].Value = wWLZ;
  232. }
  233. MeasureParam cfm = new MeasureParam();
  234. cfm.Is_Photograph = chkWIsP.Checked;
  235. cfm.PT = chkWPT.Checked;
  236. cfm.PTTemp = txtWPTF.Text;
  237. cfm.FIBTemp = txtWFIBF.Text;
  238. cfm.Stretch_Magnification = Convert.ToDouble(cbbWLZ.Text);
  239. cfm.Location_Magnification = Convert.ToDouble(cbbWQGF.Text);
  240. cfm.Location_Voltage = Convert.ToDouble(cbbWQGD.Text);
  241. cfm.Photograph_Magnification = Convert.ToDouble(cbbWPZF.Text);
  242. cfm.Photograph_Voltage = Convert.ToDouble(cbbWPZD.Text);
  243. if (cbbWXZ.SelectedIndex == 0)
  244. {
  245. cfm.Correction_Angle = 36.0;
  246. }
  247. else
  248. {
  249. cfm.Correction_Angle = 54.0;
  250. }
  251. cfm.SampleName = cbbWYP.Text;
  252. cfm.Firm = cbbWCS.Text;
  253. //设置配置文件默认值
  254. config.AppSettings.Settings["Is_Photograph"].Value = cfm.Is_Photograph.ToString();
  255. config.AppSettings.Settings["PT_Depostion"].Value = cfm.PT.ToString();
  256. config.AppSettings.Settings["PT_ELYFile"].Value = cfm.PTTemp;
  257. config.AppSettings.Settings["FIB_ELYFile"].Value = cfm.FIBTemp;
  258. config.AppSettings.Settings["Stretch_Magnification"].Value = cfm.Stretch_Magnification.ToString();
  259. config.AppSettings.Settings["Location_Magnification"].Value = cfm.Location_Magnification.ToString();
  260. config.AppSettings.Settings["Location_Voltage"].Value = cfm.Location_Voltage.ToString();
  261. config.AppSettings.Settings["Photograph_Magnification"].Value = cfm.Photograph_Magnification.ToString();
  262. config.AppSettings.Settings["Photograph_Voltage"].Value = cfm.Photograph_Voltage.ToString();
  263. config.AppSettings.Settings["Correction_Angle"].Value = cfm.Correction_Angle.ToString();
  264. config.AppSettings.Settings["SampleName"].Value = cfm.SampleName;
  265. config.AppSettings.Settings["Firms"].Value = cfm.Firm;
  266. config.Save(ConfigurationSaveMode.Modified);
  267. ConfigurationManager.RefreshSection("appSettings");//重新加载新的配置文件
  268. }
  269. /// <summary>
  270. /// 删除config文件节点中内容信息
  271. /// </summary>
  272. public bool DelConfigNodeContentInfo(string delControlName, string selName)
  273. {
  274. try
  275. {
  276. switch (delControlName)
  277. {
  278. case "WYP":
  279. //样品类型
  280. List<String> _sT = sT.ToList();
  281. _sT.Remove(selName);
  282. string wsT = string.Join(",", _sT.ToArray());
  283. config.AppSettings.Settings["Sample_Type"].Value = wsT;
  284. break;
  285. case "WCS":
  286. //厂商
  287. List<String> _firms = firms.ToList();
  288. _firms.Remove(selName);
  289. string wFirms = string.Join(",", _firms.ToArray());
  290. config.AppSettings.Settings["Firm"].Value = wFirms;
  291. break;
  292. case "WPZD":
  293. //拍照电压
  294. List<String> _WPZD = WPZD.ToList();
  295. _WPZD.Remove(selName);
  296. string wWPZD = string.Join(",", _WPZD.ToArray());
  297. config.AppSettings.Settings["WPZD"].Value = wWPZD;
  298. break;
  299. case "WPZF":
  300. //拍照放大位数
  301. List<String> _WPZF = WPZF.ToList();
  302. _WPZF.Remove(selName);
  303. string wWPZF = string.Join(",", _WPZF.ToArray());
  304. config.AppSettings.Settings["WPZF"].Value = wWPZF;
  305. break;
  306. case "WQGD"://定位切割电压
  307. List<String> _WQGD = WQGD.ToList();
  308. _WQGD.Remove(selName);
  309. string wWQGD = string.Join(",", _WQGD.ToArray());
  310. config.AppSettings.Settings["WQGD"].Value = wWQGD;
  311. break;
  312. case "WQGF": //定位切割放大位数
  313. List<String> _WQGF = WQGF.ToList();
  314. _WQGF.Remove(selName);
  315. string wWQGF = string.Join(",", _WQGF.ToArray());
  316. config.AppSettings.Settings["WQGF"].Value = wWQGF;
  317. break;
  318. case "WLZ":
  319. //拉直操作放大位数
  320. List<String> _WLZ = WLZ.ToList();
  321. _WLZ.Remove(selName);
  322. string wWLZ = string.Join(",", _WLZ.ToArray());
  323. config.AppSettings.Settings["WLZ"].Value = wWLZ;
  324. break;
  325. }
  326. config.Save(ConfigurationSaveMode.Modified);
  327. ConfigurationManager.RefreshSection("appSettings");//重新加载新的配置文件
  328. return true;
  329. }
  330. catch (Exception ex)
  331. {
  332. LogManager.LogError(ex.Message);
  333. return true;
  334. }
  335. }
  336. /// <summary>
  337. /// 绑定下拉菜单
  338. /// </summary>
  339. /// <param name="cb"></param>
  340. /// <param name="strGroup"></param>
  341. private void BindComboxData(ComboBox cb, string[] strGroup)
  342. {
  343. for (int i = 0; i < strGroup.Length; i++)
  344. {
  345. if (!strGroup[i].Equals(""))
  346. {
  347. cb.Items.Add(strGroup[i]);
  348. }
  349. }
  350. }
  351. /// <summary>
  352. /// 读取Config文件信息
  353. /// </summary>
  354. public void ReloadConfig()
  355. {
  356. cbbWYP.Items.Clear();
  357. cbbWCS.Items.Clear();
  358. cbbWPZD.Items.Clear();
  359. cbbWPZF.Items.Clear();
  360. cbbWQGD.Items.Clear();
  361. cbbWQGF.Items.Clear();
  362. cbbWLZ.Items.Clear();
  363. string sample_Type = config.AppSettings.Settings["Sample_Type"].Value.ToString();
  364. string firm = config.AppSettings.Settings["Firm"].Value.ToString();
  365. string WPZDTemp = config.AppSettings.Settings["WPZD"].Value.ToString();
  366. string WPZFTemp = config.AppSettings.Settings["WPZF"].Value.ToString();
  367. string WQGDTemp = config.AppSettings.Settings["WQGD"].Value.ToString();
  368. string WQGFTemp = config.AppSettings.Settings["WQGF"].Value.ToString();
  369. string WLZTemp = config.AppSettings.Settings["WLZ"].Value.ToString();
  370. //样品类型
  371. sT = sample_Type.Split(',');
  372. BindComboxData(cbbWYP, sT);
  373. //厂商
  374. firms = firm.Split(',');
  375. BindComboxData(cbbWCS, firms);
  376. //拍照电压
  377. WPZD = WPZDTemp.Split(',');
  378. BindComboxData(cbbWPZD, WPZD);
  379. //拍照放大位数
  380. WPZF = WPZFTemp.Split(',');
  381. BindComboxData(cbbWPZF, WPZF);
  382. //定位切割电压
  383. WQGD = WQGDTemp.Split(',');
  384. BindComboxData(cbbWQGD, WQGD);
  385. //定位切割放大位数
  386. WQGF = WQGFTemp.Split(',');
  387. BindComboxData(cbbWQGF, WQGF);
  388. //拉直操作放大位数
  389. WLZ = WLZTemp.Split(',');
  390. BindComboxData(cbbWLZ, WLZ);
  391. //设置配置文件默认值
  392. chkWIsP.Checked=Convert.ToBoolean(config.AppSettings.Settings["Is_Photograph"].Value);
  393. chkWPT.Checked = Convert.ToBoolean(config.AppSettings.Settings["PT_Depostion"].Value);
  394. txtWPTF.Text = config.AppSettings.Settings["PT_ELYFile"].Value;
  395. txtWFIBF.Text = config.AppSettings.Settings["FIB_ELYFile"].Value;
  396. cbbWLZ.Text = config.AppSettings.Settings["Stretch_Magnification"].Value;
  397. cbbWQGF.Text = config.AppSettings.Settings["Location_Magnification"].Value;
  398. cbbWQGD.Text = config.AppSettings.Settings["Location_Voltage"].Value;
  399. cbbWPZF.Text = config.AppSettings.Settings["Photograph_Magnification"].Value;
  400. cbbWPZD.Text = config.AppSettings.Settings["Photograph_Voltage"].Value;
  401. cbbWXZ.Text = config.AppSettings.Settings["Correction_Angle"].Value;
  402. cbbWYP.Text = config.AppSettings.Settings["SampleName"].Value;
  403. cbbWCS.Text = config.AppSettings.Settings["Firms"].Value;
  404. }
  405. /// <summary>
  406. /// 根据所选路径,读取模板文件
  407. /// </summary>
  408. public void ReadConfigInfo()
  409. {
  410. if (!ReadConfigPath.Equals(""))
  411. {
  412. ReloadConfig();
  413. ConfigFile cfm = new ConfigFile(new MeasureParam());
  414. cfm.Read(ReadConfigPath);
  415. chkWIsP.Checked = cfm.m_Config.Is_Photograph;
  416. chkWPT.Checked = cfm.m_Config.PT;
  417. txtWPTF.Text = cfm.m_Config.PTTemp;
  418. txtWFIBF.Text = cfm.m_Config.FIBTemp;
  419. cbbWLZ.Text = cfm.m_Config.Stretch_Magnification.ToString();
  420. cbbWQGF.Text = cfm.m_Config.Location_Magnification.ToString();
  421. cbbWQGD.Text = cfm.m_Config.Location_Voltage.ToString();
  422. cbbWPZF.Text = cfm.m_Config.Photograph_Magnification.ToString();
  423. cbbWPZD.Text = cfm.m_Config.Photograph_Voltage.ToString();
  424. cbbWXZ.Text = cfm.m_Config.Correction_Angle.ToString();
  425. cbbWYP.Text = cfm.m_Config.SampleName;
  426. cbbWCS.Text = cfm.m_Config.Firm;
  427. }
  428. }
  429. /// <summary>
  430. /// 修改配置文件默认值
  431. /// </summary>
  432. /// <param name="sender"></param>
  433. /// <param name="e"></param>
  434. private void btnSaveDefalutPara_Click(object sender, EventArgs e)
  435. {
  436. EditConfig();
  437. }
  438. #endregion
  439. #region 删除下拉菜单选择项
  440. private void DelComboBoxItem_Click(object sender, EventArgs e)
  441. {
  442. if (MessageBox.Show("是否删除所选项信息?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
  443. {
  444. PictureBox pbDel = (PictureBox)sender;
  445. string ctrlName = pbDel.Name.Substring(5, pbDel.Name.Length - 5);
  446. if (DelComboBoxItem(ctrlName))
  447. {
  448. //重新加载
  449. ReloadConfig();
  450. }
  451. }
  452. }
  453. /// <summary>
  454. /// 删除下拉菜单选择项
  455. /// </summary>
  456. public bool DelComboBoxItem(string controlName)
  457. {
  458. string delName = controlName;
  459. foreach (Control item in this.Controls)
  460. {
  461. if (item is ComboBox)
  462. {
  463. if (item.Name.Contains(delName))
  464. {
  465. ComboBox cb = (ComboBox)item;
  466. return DelConfigNodeContentInfo(delName, cb.Text);
  467. }
  468. }
  469. }
  470. return false;
  471. }
  472. #endregion
  473. #region 根据是否仅拍照,进行逻辑判断
  474. private void chkWIsP_CheckedChanged(object sender, EventArgs e)
  475. {
  476. if (chkWIsP.Checked)
  477. {
  478. chkWPT.Checked = false;
  479. chkWPT.Visible = false;
  480. }
  481. else
  482. {
  483. chkWPT.Visible = true;
  484. }
  485. }
  486. #endregion
  487. }
  488. }