OTSPeriodicTableForm.cs 8.0 KB

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