OTSPeriodicTableForm_Small.cs 11 KB

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