OTSPeriodicTableForm.cs 7.9 KB

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