OTSPeriodicTableForm_Small.cs 11 KB

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