123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace OTSPeriodicTable
- {
- public partial class OTSPeriodicTableForm : Form
- {
- #region 变量定义
- /// <summary>
- /// 获取所有选择的元素
- /// </summary>
- public List<Periodic> m_List_Periodic;
- //是否点击了确定按钮
- private bool m_isOK = false;
- #endregion
- #region 构造函数和窗体加载
- public OTSPeriodicTableForm()
- {
- m_List_Periodic = new List<Periodic>();
- InitializeComponent();
- //国际化
- OTSSysMgrTools.Language lan = new OTSSysMgrTools.Language(this);
- }
- /// <summary>
- /// 传入已经选择的元素购造函数
- /// </summary>
- /// <param name="in_list_periodic"></param>
- public OTSPeriodicTableForm(List<Periodic> in_list_periodic)
- {
- m_List_Periodic = new List<Periodic>();
- InitializeComponent();
- m_List_Periodic = in_list_periodic;
- }
- private void OTSPeriodicTableForm_Load(object sender, EventArgs e)
- {
- //设置传入的元素列表被选择
- SetListToPeriodic(); //问题从这里开始
- this.DoubleBuffered = true;
- this.Refresh();
- }
- #endregion
- #region 保存选择的元素到List中
- /// <summary>
- /// 将所有的界面UI periodic设置成未选择状态
- /// </summary>
- private void SetAllUIPeriodicVisable()
- {
- foreach (Control uc in thePeriodicTable1.Controls)
- {
- //第一步,先找到最外部大panel
- if (uc.Name == "panel1")
- foreach (Control uc2 in uc.Controls)
- {
- //第二步,再找到小panel
- if (uc2.Name.IndexOf("p_element") > -1)
- {
- //第三步,里面还有一层,这个才是user_element
- foreach (Control uc3 in uc2.Controls)
- {
- User_Element ue = (User_Element)uc3;
- ue.i_click = 0;
- ue.BackColor = ue.OldColor;
- }
- }
- }
- }
- }
- /// <summary>
- /// 将元素表中的设置到元素界面上,让其显示为选择状态
- /// </summary>
- private void SetListToPeriodic()
- {
- //先首将所有的选择状态都去掉
- SetAllUIPeriodicVisable();
- //开始设置选择的元素
- for (int i = 0; i < m_List_Periodic.Count(); i++)
- {
- //先判断用户是否选择了元素,如果没有选择的话,直接退出,选择的话,先问
- foreach (Control uc in thePeriodicTable1.Controls)
- {
- //第一步,先找到最外部大panel
- if (uc.Name == "panel1")
- foreach (Control uc2 in uc.Controls)
- {
- //第二步,再找到小panel
- if (uc2.Name.IndexOf("p_element") > -1)
- {
- //第三步,里面还有一层,这个才是user_element
- foreach (Control uc3 in uc2.Controls)
- {
- User_Element ue = (User_Element)uc3;
- //记录用户选择了的元素
- if (ue.lb_fh.Text == m_List_Periodic[i].FH)
- {
- //设置这个元素已经被选择
- ue.i_click = 2;
- ue.BackColor = Color.SpringGreen; ;
- }
- }
- }
- }
- }
- }
- }
- /// <summary>
- /// 将选择的元素保存到列表中
- /// </summary>
- private void SelectPeriodicToList()
- {
- m_List_Periodic.Clear();
- //先判断用户是否选择了元素,如果没有选择的话,直接退出,选择的话,先问
- foreach (Control uc in thePeriodicTable1.Controls)
- {
- //第一步,先找到最外部大panel
- if (uc.Name == "panel1")
- foreach (Control uc2 in uc.Controls)
- {
- //第二步,再找到小panel
- if (uc2.Name.IndexOf("p_element") > -1)
- {
- //第三步,里面还有一层,这个才是user_element
- foreach (Control uc3 in uc2.Controls)
- {
- User_Element ue = (User_Element)uc3;
- //记录用户选择了的元素
- if (ue.i_click == 2)
- {
- //aa++;
- Periodic pc = new Periodic();
- pc.XH =ue.lb_xh.Text.ToString().Trim(); //序号
- pc.YZZL = ue.lb_yzzl.Text.ToString().Trim(); //元素重量
- pc.FH = ue.lb_fh.Text.ToString().Trim(); //符号
- pc.ZWYSM = ue.zwysm.ToString().Trim(); //中文元素名
- pc.YWM = ue.lb_xh.Text.ToString().Trim(); //英文名
- if ("-" != ue.lb_sx1.Text.ToString().Trim() && "" != ue.lb_sx1.Text.ToString().Trim())
- pc.SX1 = ue.lb_sx1.Text.ToString().Trim(); //属性1
- else
- pc.SX1 = "0";
- if ("-" != ue.lb_sx2.Text.ToString().Trim() && "" != ue.lb_sx2.Text.ToString().Trim())
- pc.SX2 = ue.lb_sx2.Text.ToString().Trim(); //属性2
- else
- pc.SX2 = "0";
- if ("-" != ue.lb_sx3.Text.ToString().Trim() && "" != ue.lb_sx3.Text.ToString().Trim())
- pc.SX3 = ue.lb_sx3.Text.ToString().Trim(); //属性3
- else
- pc.SX3 = "0";
- if (null != ue.pictureBox1.Image.Tag)
- pc.FL = ue.pictureBox1.Image.Tag.ToString(); //分类
- m_List_Periodic.Add(pc);
- }
- }
- }
- }
- }
- }
- #endregion
- #region 窗体退出事件
- private void OTSPeriodicTableForm_FormClosing(object sender, FormClosingEventArgs e)
- {
- SelectPeriodicToList();
- }
- #endregion
- #region 确定和取消事件
- //点击确定
- private void button1_Click(object sender, EventArgs e)
- {
- SelectPeriodicToList();
- m_isOK = true;
- this.DialogResult = DialogResult.OK;
- this.Close();
- }
- //点击取消
- private void button2_Click(object sender, EventArgs e)
- {
- this.Close();
- }
- #endregion
- }
- }
|