OTSPeriodicTableForm_Small.cs 12 KB

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