OTSPeriodicTableForm_Small.cs 12 KB

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