OTSPeriodicTableForm.cs 8.0 KB

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