UControl_Init.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460
  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 = fileNameWithoutExtension;
  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 = fileNameWithoutExtension;
  127. }
  128. }
  129. #endregion
  130. #region 创建与读取样品参数文件
  131. private void btnCreateConfig_Click(object sender, EventArgs e)
  132. {
  133. ConfigFile cfm = new ConfigFile();
  134. cfm.Is_Photograph = chkWIsP.Checked;
  135. cfm.PT_Depostion = chkWPT.Checked;
  136. cfm.PT_ELYFile = txtWPTF.Text;
  137. cfm.FIB_ELYFile = txtWFIBF.Text;
  138. cfm.Stretch_Magnification = Convert.ToDouble(cbbWLZ.Text);
  139. cfm.Location_Magnification = Convert.ToDouble(cbbWQGF.Text);
  140. cfm.Location_Voltage = Convert.ToDouble(cbbWQGD.Text);
  141. cfm.Photograph_Magnification = Convert.ToDouble(cbbWPZF.Text);
  142. cfm.Photograph_Voltage = Convert.ToDouble(cbbWPZD.Text);
  143. if (cbbWXZ.SelectedIndex == 0)
  144. {
  145. cfm.Correction_Angle = 36.0;
  146. }
  147. else
  148. {
  149. cfm.Correction_Angle = 54.0;
  150. }
  151. cfm.Sample_Type = cbbWYP.Text;
  152. cfm.Firm = cbbWCS.Text;
  153. SaveFileDialog saveFileDialog = new SaveFileDialog();
  154. saveFileDialog.Filter = "样品参数文件|*.cfg";
  155. if (saveFileDialog.ShowDialog() == DialogResult.OK)
  156. {
  157. cfm.Save(saveFileDialog.FileName);
  158. }
  159. else
  160. {
  161. return;
  162. }
  163. //编辑Config文件
  164. EditConfig();
  165. }
  166. /// <summary>
  167. /// 编辑confing 文件信息
  168. /// </summary>
  169. public void EditConfig()
  170. {
  171. //样品类型
  172. List<String> _sT = sT.ToList();
  173. if (_sT.IndexOf(cbbWYP.Text) < 0)
  174. {
  175. _sT.Add(cbbWYP.Text);
  176. string wsT = string.Join(",", _sT.ToArray());
  177. config.AppSettings.Settings["Sample_Type"].Value = wsT;
  178. }
  179. //厂商
  180. List<String> _firms = firms.ToList();
  181. if (_firms.IndexOf(cbbWCS.Text) < 0)
  182. {
  183. _firms.Add(cbbWCS.Text);
  184. string wFirms = string.Join(",", _firms.ToArray());
  185. config.AppSettings.Settings["Firm"].Value = wFirms;
  186. }
  187. //拍照电压
  188. List<String> _WPZD = WPZD.ToList();
  189. if (_WPZD.IndexOf(cbbWPZD.Text) < 0)
  190. {
  191. _WPZD.Add(cbbWPZD.Text);
  192. string wWPZD = string.Join(",", _WPZD.ToArray());
  193. config.AppSettings.Settings["WPZD"].Value = wWPZD;
  194. }
  195. //拍照放大位数
  196. List<String> _WPZF = WPZF.ToList();
  197. if (_WPZF.IndexOf(cbbWPZF.Text) < 0)
  198. {
  199. _WPZF.Add(cbbWPZF.Text);
  200. string wWPZF = string.Join(",", _WPZF.ToArray());
  201. config.AppSettings.Settings["WPZF"].Value = wWPZF;
  202. }
  203. //定位切割电压
  204. List<String> _WQGD = WQGD.ToList();
  205. if (_WQGD.IndexOf(cbbWQGD.Text) < 0)
  206. {
  207. _WQGD.Add(cbbWQGD.Text);
  208. string wWQGD = string.Join(",", _WQGD.ToArray());
  209. config.AppSettings.Settings["WQGD"].Value = wWQGD;
  210. }
  211. //定位切割放大位数
  212. List<String> _WQGF = WQGF.ToList();
  213. if (_WQGF.IndexOf(cbbWQGF.Text) < 0)
  214. {
  215. _WQGF.Add(cbbWQGF.Text);
  216. string wWQGF = string.Join(",", _WQGF.ToArray());
  217. config.AppSettings.Settings["WQGF"].Value = wWQGF;
  218. }
  219. //拉直操作放大位数
  220. List<String> _WLZ = WLZ.ToList();
  221. if (_WLZ.IndexOf(cbbWLZ.Text) < 0)
  222. {
  223. _WLZ.Add(cbbWLZ.Text);
  224. string wWLZ = string.Join(",", _WLZ.ToArray());
  225. config.AppSettings.Settings["WLZ"].Value = wWLZ;
  226. }
  227. config.Save(ConfigurationSaveMode.Modified);
  228. ConfigurationManager.RefreshSection("appSettings");//重新加载新的配置文件
  229. ReloadConfig();
  230. }
  231. /// <summary>
  232. /// 删除config文件节点中内容信息
  233. /// </summary>
  234. public bool DelConfigNodeContentInfo(string delControlName, string selName)
  235. {
  236. try
  237. {
  238. switch (delControlName)
  239. {
  240. case "WYP":
  241. //样品类型
  242. List<String> _sT = sT.ToList();
  243. _sT.Remove(selName);
  244. string wsT = string.Join(",", _sT.ToArray());
  245. config.AppSettings.Settings["Sample_Type"].Value = wsT;
  246. break;
  247. case "WCS":
  248. //厂商
  249. List<String> _firms = firms.ToList();
  250. _firms.Remove(selName);
  251. string wFirms = string.Join(",", _firms.ToArray());
  252. config.AppSettings.Settings["Firm"].Value = wFirms;
  253. break;
  254. case "WPZD":
  255. //拍照电压
  256. List<String> _WPZD = WPZD.ToList();
  257. _WPZD.Remove(selName);
  258. string wWPZD = string.Join(",", _WPZD.ToArray());
  259. config.AppSettings.Settings["WPZD"].Value = wWPZD;
  260. break;
  261. case "WPZF":
  262. //拍照放大位数
  263. List<String> _WPZF = WPZF.ToList();
  264. _WPZF.Remove(selName);
  265. string wWPZF = string.Join(",", _WPZF.ToArray());
  266. config.AppSettings.Settings["WPZF"].Value = wWPZF;
  267. break;
  268. case "WQGD"://定位切割电压
  269. List<String> _WQGD = WQGD.ToList();
  270. _WQGD.Remove(selName);
  271. string wWQGD = string.Join(",", _WQGD.ToArray());
  272. config.AppSettings.Settings["WQGD"].Value = wWQGD;
  273. break;
  274. case "WQGF": //定位切割放大位数
  275. List<String> _WQGF = WQGF.ToList();
  276. _WQGF.Remove(selName);
  277. string wWQGF = string.Join(",", _WQGF.ToArray());
  278. config.AppSettings.Settings["WQGF"].Value = wWQGF;
  279. break;
  280. case "WLZ":
  281. //拉直操作放大位数
  282. List<String> _WLZ = WLZ.ToList();
  283. _WLZ.Remove(selName);
  284. string wWLZ = string.Join(",", _WLZ.ToArray());
  285. config.AppSettings.Settings["WLZ"].Value = wWLZ;
  286. break;
  287. }
  288. config.Save(ConfigurationSaveMode.Modified);
  289. ConfigurationManager.RefreshSection("appSettings");//重新加载新的配置文件
  290. return true;
  291. }
  292. catch (Exception ex)
  293. {
  294. LogManager.LogError(ex.Message);
  295. return true;
  296. }
  297. }
  298. /// <summary>
  299. /// 绑定下拉菜单
  300. /// </summary>
  301. /// <param name="cb"></param>
  302. /// <param name="strGroup"></param>
  303. private void BindComboxData(ComboBox cb, string[] strGroup)
  304. {
  305. for (int i = 0; i < strGroup.Length; i++)
  306. {
  307. if (!strGroup[i].Equals(""))
  308. {
  309. cb.Items.Add(strGroup[i]);
  310. }
  311. }
  312. }
  313. /// <summary>
  314. /// 读取Config文件信息
  315. /// </summary>
  316. public void ReloadConfig()
  317. {
  318. cbbWYP.Items.Clear();
  319. cbbWCS.Items.Clear();
  320. cbbWPZD.Items.Clear();
  321. cbbWPZF.Items.Clear();
  322. cbbWQGD.Items.Clear();
  323. cbbWQGF.Items.Clear();
  324. cbbWLZ.Items.Clear();
  325. string sample_Type = ConfigurationManager.AppSettings["Sample_Type"];
  326. string firm = ConfigurationManager.AppSettings["Firm"];
  327. string WPZDTemp = ConfigurationManager.AppSettings["WPZD"];
  328. string WPZFTemp = ConfigurationManager.AppSettings["WPZF"];
  329. string WQGDTemp = ConfigurationManager.AppSettings["WQGD"];
  330. string WQGFTemp = ConfigurationManager.AppSettings["WQGF"];
  331. string WLZTemp = ConfigurationManager.AppSettings["WLZ"];
  332. //样品类型
  333. sT = sample_Type.Split(',');
  334. BindComboxData(cbbWYP, sT);
  335. //厂商
  336. firms = firm.Split(',');
  337. BindComboxData(cbbWCS, firms);
  338. //拍照电压
  339. WPZD = WPZDTemp.Split(',');
  340. BindComboxData(cbbWPZD, WPZD);
  341. //拍照放大位数
  342. WPZF = WPZFTemp.Split(',');
  343. BindComboxData(cbbWPZF, WPZF);
  344. //定位切割电压
  345. WQGD = WQGDTemp.Split(',');
  346. BindComboxData(cbbWQGD, WQGD);
  347. //定位切割放大位数
  348. WQGF = WQGFTemp.Split(',');
  349. BindComboxData(cbbWQGF, WQGF);
  350. //拉直操作放大位数
  351. WLZ = WLZTemp.Split(',');
  352. BindComboxData(cbbWLZ, WLZ);
  353. cbbWYP.SelectedIndex = 0;
  354. cbbWCS.SelectedIndex = 0;
  355. cbbWXZ.SelectedIndex = 0;
  356. cbbWPZD.SelectedIndex = 0;
  357. cbbWPZF.SelectedIndex = 0;
  358. cbbWLZ.SelectedIndex = 0;
  359. cbbWQGD.SelectedIndex = 0;
  360. cbbWQGF.SelectedIndex = 0;
  361. }
  362. /// <summary>
  363. /// 根据所选路径,读取模板文件
  364. /// </summary>
  365. public void ReadConfigInfo()
  366. {
  367. if (!ReadConfigPath.Equals(""))
  368. {
  369. ReloadConfig();
  370. ConfigFile cfm = new ConfigFile();
  371. cfm.Read(ReadConfigPath);
  372. chkWIsP.Checked = cfm.Is_Photograph;
  373. chkWPT.Checked = cfm.PT_Depostion;
  374. txtWPTF.Text = cfm.PT_ELYFile;
  375. txtWFIBF.Text = cfm.FIB_ELYFile;
  376. cbbWLZ.Text = cfm.Stretch_Magnification.ToString();
  377. cbbWQGF.Text = cfm.Location_Magnification.ToString();
  378. cbbWQGD.Text = cfm.Location_Voltage.ToString();
  379. cbbWPZF.Text = cfm.Photograph_Magnification.ToString();
  380. cbbWPZD.Text = cfm.Photograph_Voltage.ToString();
  381. cbbWXZ.Text = cfm.Correction_Angle.ToString();
  382. cbbWYP.Text = cfm.Sample_Type;
  383. cbbWCS.Text = cfm.Firm;
  384. }
  385. }
  386. #endregion
  387. #region 删除下拉菜单选择项
  388. private void DelComboBoxItem_Click(object sender, EventArgs e)
  389. {
  390. if (MessageBox.Show("是否删除所选项信息?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
  391. {
  392. PictureBox pbDel = (PictureBox)sender;
  393. string ctrlName = pbDel.Name.Substring(5, pbDel.Name.Length - 5);
  394. if (DelComboBoxItem(ctrlName))
  395. {
  396. //重新加载
  397. ReloadConfig();
  398. }
  399. }
  400. }
  401. /// <summary>
  402. /// 删除下拉菜单选择项
  403. /// </summary>
  404. public bool DelComboBoxItem(string controlName)
  405. {
  406. string delName = controlName;
  407. foreach (Control item in this.Controls)
  408. {
  409. if (item is ComboBox)
  410. {
  411. if (item.Name.Contains(delName))
  412. {
  413. ComboBox cb = (ComboBox)item;
  414. return DelConfigNodeContentInfo(delName, cb.Text);
  415. }
  416. }
  417. }
  418. return false;
  419. }
  420. #endregion
  421. #region 根据是否仅拍照,进行逻辑判断
  422. private void chkWIsP_CheckedChanged(object sender, EventArgs e)
  423. {
  424. if (chkWIsP.Checked)
  425. {
  426. chkWPT.Checked = false;
  427. chkWPT.Visible = false;
  428. }
  429. else
  430. {
  431. chkWPT.Visible = true;
  432. }
  433. }
  434. #endregion
  435. }
  436. }