123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace OTSPeriodicTable
- {
- public partial class OTSPeriodicTableForm_Small : Form
- {
- #region 变量
- /// <summary>
- /// 获取所有选择的元素
- /// </summary>
- public List<Periodic> m_List_Periodic;
- /// <summary>
- /// 常用元素列表
- /// </summary>
- private string[] m_common_elementliststr = { "Li","Sm","Mn","Be","Ac","Cr","Mg","B","Ni","Ca","C",
- "Co","Zr","Si","Cu","Sn","Se","W","Pb","Te","Mo",
- "Bi","As","V","Cs","S","Ti","Ba","P","Al","La",
- "N","Nb","Ce","O","Ta","Nd","H","Y","Cl","Ac","Hg","I","Br","F","Re","W"};
- #endregion
- #region 构造函数及窗体加载
- public OTSPeriodicTableForm_Small()
- {
- m_List_Periodic = new List<Periodic>();//加载窗体时,重新初始化元素lis
- InitializeComponent();
- //国际化
- OTSSysMgrTools.Language lan = new OTSSysMgrTools.Language(this);
- }
- /// <summary>
- /// 传入已经选择的元素购造函数
- /// </summary>
- /// <param name="in_list_periodic"></param>
- public OTSPeriodicTableForm_Small(List<Periodic> in_list_periodic)
- {
- m_List_Periodic = new List<Periodic>();//加载窗体时,重新初始化元素lis
- InitializeComponent();
- m_List_Periodic = in_list_periodic;
- }
- private void OTSPeriodicTableForm_Small_Load(object sender, EventArgs e)
- {
- this.DoubleBuffered = true;
- this.Refresh();
- //设置传入的元素列表被选择
- SetListToPeriodic();
- }
- #endregion
- #region 自定义方法封装
- /// <summary>
- /// 将所有的界面UI periodic设置成未选择状态
- /// </summary>
- private void SetAllUIPeriodicVisable()
- {
- foreach (Control uc in thePeriodicTable_Small1.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_Small ue = (User_Element_Small)uc3;
- ue.i_click = 0;
- ue.BackColor = Color.Gainsboro;
- }
- }
- }
- }
- }
- /// <summary>
- /// 将所有的界面UI periodic设置成选择状态
- /// </summary>
- private void SetAllUIPeriodicEnable()
- {
- foreach (Control uc in thePeriodicTable_Small1.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_Small ue = (User_Element_Small)uc3;
- ue.i_click = 2;
- ue.BackColor = Color.SpringGreen;
- }
- }
- }
- }
- }
- /// <summary>
- /// 将常用的界面UI periodic 设置成选择状态
- /// </summary>
- private void SetCommonPeriodicEnable()
- {
- foreach (Control uc in thePeriodicTable_Small1.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_Small ue = (User_Element_Small)uc3;
- //对常用元素进行判断
- if (m_common_elementliststr.Contains( ue.lb_fh.Text)== true)
- {
- //选择
- ue.i_click = 2;
- ue.BackColor = Color.SpringGreen;
- }
- else
- {
- //未选择
- ue.i_click = 0;
- ue.BackColor = Color.Gainsboro;
- }
-
- }
- }
- }
- }
- }
- /// <summary>
- /// 将元素表中的设置到元素界面上,让其显示为选择状态
- /// </summary>
- private void SetListToPeriodic()
- {
- //先首将所有的选择状态都去掉
- SetAllUIPeriodicVisable();
- //开始设置选择的元素
- for (int i = 0; i < m_List_Periodic.Count(); i++)
- {
- //先判断用户是否选择了元素,如果没有选择的话,直接退出,选择的话,先问
- foreach (Control uc in thePeriodicTable_Small1.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_Small ue = (User_Element_Small)uc3;
- //记录用户选择了的元素
- if (ue.lb_fh.Text == m_List_Periodic[i].FH)
- {
- //设置这个元素已经被选择
- ue.i_click = 2;
- ue.BackColor = Color.SpringGreen; ;
- }
- }
- }
- }
- }
- }
- }
- #endregion
- #region 保存选择的元素到List中
- /// <summary>
- /// 将选择的元素保存到列表中
- /// </summary>
- private void SelectPeriodicToList()
- {
- //先判断用户是否选择了元素,如果没有选择的话,直接退出,选择的话,先问
- foreach (Control uc in thePeriodicTable_Small1.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_Small ue = (User_Element_Small)uc3;
- //记录用户选择了的元素
- if (ue.i_click == 2)
- {
- 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";
- m_List_Periodic.Add(pc);
- }
- }
- }
- }
- }
- }
- #endregion
- #region 相关事件
- private void OTSPeriodicTableForm_Small_FormClosing(object sender, FormClosingEventArgs e)
- {
- m_List_Periodic.Clear();
- SelectPeriodicToList();
- }
- private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
- {
- //从UI向list更新
- m_List_Periodic.Clear();
- SelectPeriodicToList();
- OTSPeriodicTableForm otf = new OTSPeriodicTableForm(m_List_Periodic);
- otf.ShowDialog();
- //从list向UI更新
- this.m_List_Periodic = otf.m_List_Periodic; //该list未用clone,所以保持了一致该代码写不写都一样
- SetListToPeriodic();
- this.DoubleBuffered = true;
- this.Refresh();
- }
- #endregion
- private void linkLabel3_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
- {
- //选择常用元素
- SetCommonPeriodicEnable();
- }
- private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
- {
- //选择所有元素
- if (linkLabel2.Text == "All Element Enable")
- {
- linkLabel2.Text = "All Element Disable";
- SetAllUIPeriodicEnable();
- }
- else
- {
- linkLabel2.Text = "All Element Enable";
- SetAllUIPeriodicVisable();
- }
- }
- }
- }
|