OTSPeriodicTableForm_Small.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. using OTSIncAReportApp.SysMgrTools;
  2. using OTSPeriodicTable;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Windows.Forms;
  8. namespace OTSRptPeriodicTable
  9. {
  10. public partial class OTSPeriodicTableForm_Small : Form
  11. {
  12. #region 变量
  13. /// <summary>
  14. /// 获取所有选择的元素
  15. /// </summary>
  16. public List<Periodic> m_List_Periodic;
  17. /// <summary>
  18. /// 常用元素列表
  19. /// </summary>
  20. private string[] m_common_elementliststr = { "Li","Sm","Mn","Be","Ac","Cr","Mg","B","Ni","Ca","C",
  21. "Co","Zr","Si","Cu","Sn","Se","W","Pb","Te","Mo",
  22. "Bi","As","V","Cs","S","Ti","Ba","P","Al","La",
  23. "N","Nb","Ce","O","Ta","Nd","H","Y","Cl","Ac","Hg","I","Br","F","Re","W"};
  24. #endregion
  25. #region 构造函数及窗体加载
  26. public OTSPeriodicTableForm_Small()
  27. {
  28. m_List_Periodic = new List<Periodic>();//加载窗体时,重新初始化元素lis
  29. InitializeComponent();
  30. //国际化
  31. Language lan = new Language(this);
  32. }
  33. /// <summary>
  34. /// 传入已经选择的元素购造函数
  35. /// </summary>
  36. /// <param name="in_list_periodic"></param>
  37. public OTSPeriodicTableForm_Small(List<Periodic> in_list_periodic)
  38. {
  39. m_List_Periodic = new List<Periodic>();//加载窗体时,重新初始化元素lis
  40. InitializeComponent();
  41. m_List_Periodic = in_list_periodic;
  42. }
  43. private void OTSPeriodicTableForm_Small_Load(object sender, EventArgs e)
  44. {
  45. this.DoubleBuffered = true;
  46. this.Refresh();
  47. //设置传入的元素列表被选择
  48. SetListToPeriodic();
  49. }
  50. #endregion
  51. #region 自定义方法封装
  52. /// <summary>
  53. /// 将所有的界面UI periodic设置成未选择状态
  54. /// </summary>
  55. private void SetAllUIPeriodicVisable()
  56. {
  57. foreach (Control uc in thePeriodicTable_Small1.Controls)
  58. {
  59. //第一步,先找到最外部大panel
  60. if (uc.Name == "panel1")
  61. foreach (Control uc2 in uc.Controls)
  62. {
  63. //第二步,再找到小panel
  64. if (uc2.Name.IndexOf("p_element") > -1)
  65. {
  66. //第三步,里面还有一层,这个才是user_element
  67. foreach (Control uc3 in uc2.Controls)
  68. {
  69. User_Element_Small ue = (User_Element_Small)uc3;
  70. ue.i_click = 0;
  71. ue.BackColor = Color.Gainsboro;
  72. }
  73. }
  74. }
  75. }
  76. }
  77. /// <summary>
  78. /// 将所有的界面UI periodic设置成选择状态
  79. /// </summary>
  80. private void SetAllUIPeriodicEnable()
  81. {
  82. foreach (Control uc in thePeriodicTable_Small1.Controls)
  83. {
  84. //第一步,先找到最外部大panel
  85. if (uc.Name == "panel1")
  86. foreach (Control uc2 in uc.Controls)
  87. {
  88. //第二步,再找到小panel
  89. if (uc2.Name.IndexOf("p_element") > -1)
  90. {
  91. //第三步,里面还有一层,这个才是user_element
  92. foreach (Control uc3 in uc2.Controls)
  93. {
  94. User_Element_Small ue = (User_Element_Small)uc3;
  95. ue.i_click = 2;
  96. ue.BackColor = Color.SpringGreen;
  97. }
  98. }
  99. }
  100. }
  101. }
  102. /// <summary>
  103. /// 将常用的界面UI periodic 设置成选择状态
  104. /// </summary>
  105. private void SetCommonPeriodicEnable()
  106. {
  107. foreach (Control uc in thePeriodicTable_Small1.Controls)
  108. {
  109. //第一步,先找到最外部大panel
  110. if (uc.Name == "panel1")
  111. foreach (Control uc2 in uc.Controls)
  112. {
  113. //第二步,再找到小panel
  114. if (uc2.Name.IndexOf("p_element") > -1)
  115. {
  116. //第三步,里面还有一层,这个才是user_element
  117. foreach (Control uc3 in uc2.Controls)
  118. {
  119. User_Element_Small ue = (User_Element_Small)uc3;
  120. //对常用元素进行判断
  121. if (m_common_elementliststr.Contains(ue.lb_fh.Text) == true)
  122. {
  123. //选择
  124. ue.i_click = 2;
  125. ue.BackColor = Color.SpringGreen;
  126. }
  127. else
  128. {
  129. //未选择
  130. ue.i_click = 0;
  131. ue.BackColor = Color.Gainsboro;
  132. }
  133. }
  134. }
  135. }
  136. }
  137. }
  138. /// <summary>
  139. /// 将元素表中的设置到元素界面上,让其显示为选择状态
  140. /// </summary>
  141. private void SetListToPeriodic()
  142. {
  143. //先首将所有的选择状态都去掉
  144. SetAllUIPeriodicVisable();
  145. //开始设置选择的元素
  146. for (int i = 0; i < m_List_Periodic.Count(); i++)
  147. {
  148. //先判断用户是否选择了元素,如果没有选择的话,直接退出,选择的话,先问
  149. foreach (Control uc in thePeriodicTable_Small1.Controls)
  150. {
  151. //第一步,先找到最外部大panel
  152. if (uc.Name == "panel1")
  153. foreach (Control uc2 in uc.Controls)
  154. {
  155. //第二步,再找到小panel
  156. if (uc2.Name.IndexOf("p_element") > -1)
  157. {
  158. //第三步,里面还有一层,这个才是user_element
  159. foreach (Control uc3 in uc2.Controls)
  160. {
  161. User_Element_Small ue = (User_Element_Small)uc3;
  162. //记录用户选择了的元素
  163. if (ue.lb_fh.Text == m_List_Periodic[i].Symbol)
  164. {
  165. //设置这个元素已经被选择
  166. ue.i_click = 2;
  167. ue.BackColor = Color.SpringGreen; ;
  168. }
  169. }
  170. }
  171. }
  172. }
  173. }
  174. }
  175. #endregion
  176. #region 保存选择的元素到List中
  177. /// <summary>
  178. /// 将选择的元素保存到列表中
  179. /// </summary>
  180. private void SelectPeriodicToList()
  181. {
  182. //先判断用户是否选择了元素,如果没有选择的话,直接退出,选择的话,先问
  183. foreach (Control uc in thePeriodicTable_Small1.Controls)
  184. {
  185. //第一步,先找到最外部大panel
  186. if (uc.Name == "panel1")
  187. foreach (Control uc2 in uc.Controls)
  188. {
  189. //第二步,再找到小panel
  190. if (uc2.Name.IndexOf("p_element") > -1)
  191. {
  192. //第三步,里面还有一层,这个才是user_element
  193. foreach (Control uc3 in uc2.Controls)
  194. {
  195. User_Element_Small ue = (User_Element_Small)uc3;
  196. //记录用户选择了的元素
  197. if (ue.i_click == 2)
  198. {
  199. Periodic pc = new Periodic();
  200. pc.Number = ue.lb_xh.Text.ToString().Trim(); //序号
  201. pc.EleWeight = ue.lb_yzzl.Text.ToString().Trim(); //元素重量
  202. pc.Symbol = ue.lb_fh.Text.ToString().Trim(); //符号
  203. pc.ChineseName = ue.zwysm.ToString().Trim(); //中文元素名
  204. if ("-" != ue.lb_sx1.Text.ToString().Trim() && "" != ue.lb_sx1.Text.ToString().Trim())
  205. pc.K_Peak = ue.lb_sx1.Text.ToString().Trim(); //属性1
  206. else
  207. pc.K_Peak = "0";
  208. if ("-" != ue.lb_sx2.Text.ToString().Trim() && "" != ue.lb_sx2.Text.ToString().Trim())
  209. pc.L_Peak = ue.lb_sx2.Text.ToString().Trim(); //属性2
  210. else
  211. pc.L_Peak = "0";
  212. if ("-" != ue.lb_sx3.Text.ToString().Trim() && "" != ue.lb_sx3.Text.ToString().Trim())
  213. pc.M_Peak = ue.lb_sx3.Text.ToString().Trim(); //属性3
  214. else
  215. pc.M_Peak = "0";
  216. m_List_Periodic.Add(pc);
  217. }
  218. }
  219. }
  220. }
  221. }
  222. }
  223. #endregion
  224. #region 相关事件
  225. private void OTSPeriodicTableForm_Small_FormClosing(object sender, FormClosingEventArgs e)
  226. {
  227. m_List_Periodic.Clear();
  228. SelectPeriodicToList();
  229. }
  230. private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  231. {
  232. //从UI向list更新
  233. m_List_Periodic.Clear();
  234. SelectPeriodicToList();
  235. OTSPeriodicTableForm otf = new OTSPeriodicTableForm(m_List_Periodic);
  236. otf.ShowDialog();
  237. //从list向UI更新
  238. this.m_List_Periodic = otf.m_List_Periodic; //该list未用clone,所以保持了一致该代码写不写都一样
  239. SetListToPeriodic();
  240. this.DoubleBuffered = true;
  241. this.Refresh();
  242. }
  243. #endregion
  244. private void linkLabel3_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  245. {
  246. //选择常用元素
  247. SetCommonPeriodicEnable();
  248. }
  249. private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  250. {
  251. //选择所有元素
  252. if (linkLabel2.Text == "All Element Enable")
  253. {
  254. linkLabel2.Text = "All Element Disable";
  255. SetAllUIPeriodicEnable();
  256. }
  257. else
  258. {
  259. linkLabel2.Text = "All Element Enable";
  260. SetAllUIPeriodicVisable();
  261. }
  262. }
  263. }
  264. }