OTSPeriodicTableForm.cs 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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 : Form
  9. {
  10. #region 变量定义
  11. /// <summary>
  12. /// 获取所有选择的元素
  13. /// </summary>
  14. public List<Periodic> m_List_Periodic;
  15. //是否点击了确定按钮
  16. //private bool m_isOK = false;
  17. #endregion
  18. #region 构造函数和窗体加载
  19. public OTSPeriodicTableForm()
  20. {
  21. m_List_Periodic = new List<Periodic>();
  22. InitializeComponent();
  23. //国际化
  24. OTSCommon.Language lan = new OTSCommon.Language(this);
  25. }
  26. /// <summary>
  27. /// 传入已经选择的元素购造函数
  28. /// </summary>
  29. /// <param name="in_list_periodic"></param>
  30. public OTSPeriodicTableForm(List<Periodic> in_list_periodic)
  31. {
  32. m_List_Periodic = new List<Periodic>();
  33. InitializeComponent();
  34. m_List_Periodic = in_list_periodic;
  35. }
  36. private void OTSPeriodicTableForm_Load(object sender, EventArgs e)
  37. {
  38. //设置传入的元素列表被选择
  39. SetListToPeriodic(); //问题从这里开始
  40. this.DoubleBuffered = true;
  41. this.Refresh();
  42. }
  43. #endregion
  44. #region 保存选择的元素到List中
  45. /// <summary>
  46. /// 将所有的界面UI periodic设置成未选择状态
  47. /// </summary>
  48. private void SetAllUIPeriodicVisable()
  49. {
  50. foreach (Control uc in thePeriodicTable1.Controls)
  51. {
  52. //第一步,先找到最外部大panel
  53. if (uc.Name == "panel1")
  54. foreach (Control uc2 in uc.Controls)
  55. {
  56. //第二步,再找到小panel
  57. if (uc2.Name.IndexOf("p_element") > -1)
  58. {
  59. //第三步,里面还有一层,这个才是user_element
  60. foreach (Control uc3 in uc2.Controls)
  61. {
  62. User_Element ue = (User_Element)uc3;
  63. ue.i_click = 0;
  64. ue.BackColor = ue.OldColor;
  65. }
  66. }
  67. }
  68. }
  69. }
  70. /// <summary>
  71. /// 将元素表中的设置到元素界面上,让其显示为选择状态
  72. /// </summary>
  73. private void SetListToPeriodic()
  74. {
  75. //先首将所有的选择状态都去掉
  76. SetAllUIPeriodicVisable();
  77. //开始设置选择的元素
  78. for (int i = 0; i < m_List_Periodic.Count(); i++)
  79. {
  80. //先判断用户是否选择了元素,如果没有选择的话,直接退出,选择的话,先问
  81. foreach (Control uc in thePeriodicTable1.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 ue = (User_Element)uc3;
  94. //记录用户选择了的元素
  95. if (ue.lb_fh.Text == m_List_Periodic[i].FH)
  96. {
  97. //设置这个元素已经被选择
  98. ue.i_click = 2;
  99. ue.BackColor = Color.SpringGreen; ;
  100. }
  101. }
  102. }
  103. }
  104. }
  105. }
  106. }
  107. /// <summary>
  108. /// 将选择的元素保存到列表中
  109. /// </summary>
  110. private void SelectPeriodicToList()
  111. {
  112. m_List_Periodic.Clear();
  113. //先判断用户是否选择了元素,如果没有选择的话,直接退出,选择的话,先问
  114. foreach (Control uc in thePeriodicTable1.Controls)
  115. {
  116. //第一步,先找到最外部大panel
  117. if (uc.Name == "panel1")
  118. foreach (Control uc2 in uc.Controls)
  119. {
  120. //第二步,再找到小panel
  121. if (uc2.Name.IndexOf("p_element") > -1)
  122. {
  123. //第三步,里面还有一层,这个才是user_element
  124. foreach (Control uc3 in uc2.Controls)
  125. {
  126. User_Element ue = (User_Element)uc3;
  127. //记录用户选择了的元素
  128. if (ue.i_click == 2)
  129. {
  130. //aa++;
  131. Periodic pc = new Periodic();
  132. pc.XH =ue.lb_xh.Text.ToString().Trim(); //序号
  133. pc.YZZL = ue.lb_yzzl.Text.ToString().Trim(); //元素重量
  134. pc.FH = ue.lb_fh.Text.ToString().Trim(); //符号
  135. pc.ZWYSM = ue.zwysm.ToString().Trim(); //中文元素名
  136. pc.YWM = ue.lb_xh.Text.ToString().Trim(); //英文名
  137. if ("-" != ue.lb_sx1.Text.ToString().Trim() && "" != ue.lb_sx1.Text.ToString().Trim())
  138. pc.SX1 = ue.lb_sx1.Text.ToString().Trim(); //属性1
  139. else
  140. pc.SX1 = "0";
  141. if ("-" != ue.lb_sx2.Text.ToString().Trim() && "" != ue.lb_sx2.Text.ToString().Trim())
  142. pc.SX2 = ue.lb_sx2.Text.ToString().Trim(); //属性2
  143. else
  144. pc.SX2 = "0";
  145. if ("-" != ue.lb_sx3.Text.ToString().Trim() && "" != ue.lb_sx3.Text.ToString().Trim())
  146. pc.SX3 = ue.lb_sx3.Text.ToString().Trim(); //属性3
  147. else
  148. pc.SX3 = "0";
  149. if (null != ue.pictureBox1.Image.Tag)
  150. pc.FL = ue.pictureBox1.Image.Tag.ToString(); //分类
  151. m_List_Periodic.Add(pc);
  152. }
  153. }
  154. }
  155. }
  156. }
  157. }
  158. #endregion
  159. #region 窗体退出事件
  160. private void OTSPeriodicTableForm_FormClosing(object sender, FormClosingEventArgs e)
  161. {
  162. SelectPeriodicToList();
  163. }
  164. #endregion
  165. #region 确定和取消事件
  166. //点击确定
  167. private void button1_Click(object sender, EventArgs e)
  168. {
  169. SelectPeriodicToList();
  170. //m_isOK = true;
  171. this.DialogResult = DialogResult.OK;
  172. this.Close();
  173. }
  174. //点击取消
  175. private void button2_Click(object sender, EventArgs e)
  176. {
  177. this.Close();
  178. }
  179. #endregion
  180. }
  181. }