UControl_Init.cs 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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. namespace HOZProject
  13. {
  14. public partial class UControl_Init : UserControl
  15. {
  16. #region 全局变量
  17. String[] sT;
  18. String[] firms;
  19. Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
  20. private FormHOZMain formHOZMain;
  21. public FormHOZMain FormHOZMainObject { get => formHOZMain; set => formHOZMain = value; }
  22. //模板路径
  23. private string readConfigPath;
  24. public string ReadConfigPath { get => readConfigPath; set => readConfigPath = value; }
  25. #endregion
  26. public UControl_Init(FormHOZMain formHOZ)
  27. {
  28. InitializeComponent();
  29. FormHOZMainObject = formHOZ;
  30. }
  31. private void UControl_Init_Load(object sender, EventArgs e)
  32. {
  33. }
  34. private void btnClose_Click(object sender, EventArgs e)
  35. {
  36. Form fParent = this.ParentForm;
  37. fParent.Close();
  38. }
  39. private void pbCutHoleFile_Click(object sender, EventArgs e)
  40. {
  41. if (FormHOZMainObject.m_MeasureFile == null)
  42. {
  43. MessageBox.Show("请新建一个测量文件");
  44. }
  45. else
  46. {
  47. if (!FormHOZMainObject.m_MeasureFile.GetCutHolesFromFile(""))
  48. {
  49. MessageBox.Show("导入切孔失败");
  50. }
  51. else
  52. {
  53. List<CutHole> ListCutHole = FormHOZMainObject.m_MeasureFile.ListCutHole;
  54. //文件路径
  55. string filePath = FormHOZMainObject.m_MeasureFile.FilePath;
  56. string fileName = FormHOZMainObject.m_MeasureFile.FileName;
  57. FormHOZMainObject.CreateCutHoleList(ListCutHole);
  58. //显示导入的切孔数量
  59. lblCutHoleCount.Text = string.Format("成功导入{0}个切孔",ListCutHole.Count);
  60. tbCutHoleFilePath.Text = filePath + fileName;
  61. }
  62. }
  63. }
  64. /// <summary>
  65. /// 根据一个切孔,自动计算其他切孔信息
  66. /// </summary>
  67. /// <param name="sender"></param>
  68. /// <param name="e"></param>
  69. private void pbCutHoleAuto_Click(object sender, EventArgs e)
  70. {
  71. }
  72. private void pbTemplateFile_Click(object sender, EventArgs e)
  73. {
  74. string FilePathName;
  75. string fileNameWithoutExtension;
  76. //新建一个文件对话框
  77. OpenFileDialog pOpenFileDialog = new OpenFileDialog();
  78. //设置对话框标题
  79. pOpenFileDialog.Title = "选择模板文件";
  80. //设置打开文件类型
  81. pOpenFileDialog.Filter = "ely文件(*.ely)|*.ely";
  82. //监测文件是否存在
  83. pOpenFileDialog.CheckFileExists = true;
  84. //文件打开后执行以下程序
  85. if (pOpenFileDialog.ShowDialog() == DialogResult.OK)
  86. {
  87. FilePathName = System.IO.Path.GetFullPath(pOpenFileDialog.FileName); //绝对路径
  88. fileNameWithoutExtension = System.IO.Path.GetFileNameWithoutExtension(FilePathName);
  89. this.txtWPTF.Text = fileNameWithoutExtension;
  90. }
  91. }
  92. private void pbFIBTemplateFile_Click(object sender, EventArgs e)
  93. {
  94. string FilePathName;
  95. string fileNameWithoutExtension;
  96. //新建一个文件对话框
  97. OpenFileDialog pOpenFileDialog = new OpenFileDialog();
  98. //设置对话框标题
  99. pOpenFileDialog.Title = "选择模板文件";
  100. //设置打开文件类型
  101. pOpenFileDialog.Filter = "ely文件(*.ely)|*.ely";
  102. //监测文件是否存在
  103. pOpenFileDialog.CheckFileExists = true;
  104. //文件打开后执行以下程序
  105. if (pOpenFileDialog.ShowDialog() == DialogResult.OK)
  106. {
  107. FilePathName = System.IO.Path.GetFullPath(pOpenFileDialog.FileName); //绝对路径
  108. fileNameWithoutExtension = System.IO.Path.GetFileNameWithoutExtension(FilePathName);
  109. this.txtWFIBF.Text = fileNameWithoutExtension;
  110. }
  111. }
  112. #region 创建与读取样品参数文件
  113. private void btnCreateConfig_Click(object sender, EventArgs e)
  114. {
  115. ConfigFile cfm = new ConfigFile();
  116. cfm.Is_Photograph = chkWIsP.Checked;
  117. cfm.PT_Depostion = chkWPT.Checked;
  118. cfm.PT_ELYFile = txtWPTF.Text;
  119. cfm.FIB_ELYFile = txtWFIBF.Text;
  120. cfm.Stretch_Magnification = Convert.ToDouble(cbbWLZ.Text);
  121. cfm.Location_Magnification = Convert.ToDouble(cbbWQGF.Text);
  122. cfm.Location_Voltage = Convert.ToDouble(cbbWQGD.Text);
  123. cfm.Photograph_Magnification = Convert.ToDouble(cbbWPZF.Text);
  124. cfm.Photograph_Voltage = Convert.ToDouble(cbbWPZD.Text);
  125. if (cbbWXZ.SelectedIndex == 0)
  126. {
  127. cfm.Correction_Angle = 36.0;
  128. }
  129. else
  130. {
  131. cfm.Correction_Angle = 54.0;
  132. }
  133. cfm.Sample_Type = cbbWYP.Text;
  134. cfm.Firm = cbbWCS.Text;
  135. SaveFileDialog saveFileDialog = new SaveFileDialog();
  136. saveFileDialog.Filter = "样品参数文件|*.cfg";
  137. if (saveFileDialog.ShowDialog() == DialogResult.OK)
  138. {
  139. cfm.Save(saveFileDialog.FileName);
  140. }
  141. else
  142. {
  143. return;
  144. }
  145. List<String> _sT = sT.ToList();
  146. if (_sT.IndexOf(cbbWYP.Text) < 0)
  147. {
  148. _sT.Add(cbbWYP.Text);
  149. sT = _sT.ToArray();
  150. string wsT = "";
  151. for (int i = 0; i < sT.Length; i++)
  152. {
  153. wsT += sT[i] + ",";
  154. }
  155. wsT = wsT.Substring(0, wsT.Length - 1);
  156. config.AppSettings.Settings["Sample_Type"].Value = wsT;
  157. }
  158. List<String> _firms = firms.ToList();
  159. if (_firms.IndexOf(cbbWCS.Text) < 0)
  160. {
  161. _firms.Add(cbbWCS.Text);
  162. firms = _firms.ToArray();
  163. string wFirms = "";
  164. for (int i = 0; i < firms.Length; i++)
  165. {
  166. wFirms += firms[i] + ",";
  167. }
  168. wFirms = wFirms.Substring(0, wFirms.Length - 1);
  169. config.AppSettings.Settings["Firm"].Value = wFirms;
  170. }
  171. config.Save(ConfigurationSaveMode.Modified);
  172. ConfigurationManager.RefreshSection("appSettings");//重新加载新的配置文件
  173. }
  174. public void Reloadconfig()
  175. {
  176. String sample_Type = ConfigurationManager.AppSettings["Sample_Type"];
  177. String firm = ConfigurationManager.AppSettings["Firm"];
  178. sT = sample_Type.Split(',');
  179. cbbWYP.Items.Clear();
  180. for (int i = 0; i < sT.Length; i++)
  181. {
  182. cbbWYP.Items.Add(sT[i]);
  183. }
  184. firms = firm.Split(',');
  185. cbbWCS.Items.Clear();
  186. for (int i = 0; i < firms.Length; i++)
  187. {
  188. cbbWCS.Items.Add(firms[i]);
  189. }
  190. cbbWYP.SelectedIndex = 0;
  191. cbbWCS.SelectedIndex = 0;
  192. cbbWXZ.SelectedIndex = 0;
  193. cbbWPZD.SelectedIndex = 0;
  194. cbbWPZF.SelectedIndex = 0;
  195. cbbWLZ.SelectedIndex = 0;
  196. cbbWQGD.SelectedIndex = 0;
  197. cbbWQGF.SelectedIndex = 0;
  198. }
  199. public void ReadConfigInfo()
  200. {
  201. if (!ReadConfigPath.Equals(""))
  202. {
  203. Reloadconfig();
  204. ConfigFile cfm = new ConfigFile();
  205. cfm.Read(ReadConfigPath);
  206. chkWIsP.Checked = cfm.Is_Photograph;
  207. chkWPT.Checked = cfm.PT_Depostion;
  208. txtWPTF.Text = cfm.PT_ELYFile;
  209. txtWFIBF.Text = cfm.FIB_ELYFile;
  210. cbbWLZ.Text = cfm.Stretch_Magnification.ToString();
  211. cbbWQGF.Text = cfm.Location_Magnification.ToString();
  212. cbbWQGD.Text = cfm.Location_Voltage.ToString();
  213. cbbWPZF.Text = cfm.Photograph_Magnification.ToString();
  214. cbbWPZD.Text = cfm.Photograph_Voltage.ToString();
  215. cbbWXZ.Text = cfm.Correction_Angle.ToString();
  216. cbbWYP.Text = cfm.Sample_Type;
  217. cbbWCS.Text = cfm.Firm;
  218. }
  219. }
  220. private void btnReadConfig_Click(object sender, EventArgs e)
  221. {
  222. //OpenFileDialog openFileDialog = new OpenFileDialog();
  223. //openFileDialog.Filter = "样品参数文件|*.cfg";
  224. //if (openFileDialog.ShowDialog() == DialogResult.OK)
  225. //{
  226. // ConfigFile cfm = new ConfigFile();
  227. // cfm.Read(openFileDialog.FileName);
  228. //}
  229. ReadConfigInfo();
  230. }
  231. #endregion
  232. }
  233. }