123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238 |
- using OTSPeriodicTable;
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Linq;
- using System.Windows.Forms;
- namespace OTSIncAReportApp.OTSMgrInfo
- {
- public partial class Triangulation_Edit : Form
- {
- #region 变量定义
- //三元相图模板信息
- private string TriName = "";
- //是否为修改
- private string Template = "";
- private string TemplateId = "";
- private frmReportApp m_frmReportApp = null;
- #endregion
- #region 构造函数和窗体加载
- public Triangulation_Edit()
- {
- InitializeComponent();
- }
- public Triangulation_Edit( frmReportApp in_frmReportApp, string name, string id)
- {
- m_frmReportApp = in_frmReportApp;
- TriName = name;
- TemplateId = id;
- InitializeComponent();
- }
- private void Triangulation_Edit_Load(object sender, EventArgs e)
- {
- if (TriName != "")
- {
- string[] vs = TriName.Split('.');
- BindComboBox(vs[0].Split('-')[1], vs[2].Split('-')[1]);
- txtType1.Text = vs[0].Split('-')[0];
- txtType2.Text = vs[1].Split('-')[0];
- txtElement2.Text = vs[1].Split('-')[1];
- txtType3.Text = vs[2].Split('-')[0];
- Template = txtType1.Text.Trim() + "." + txtType2.Text.Trim() + "." + txtType3.Text.Trim();
- }
- else
- {
- BindComboBox("", "");
- }
- }
- /// <summary>
- /// 绑定元素名称,及元素数量combobox
- /// </summary>
- private void BindComboBox(string v1, string v2)
- {
- cboElement1.Items.Clear();
- cboElement3.Items.Clear();
- List<OTSPeriodicTable.Periodic> list_periodic = OTSPeriodicTable.CListPeriodic.GetListPeriodic();
- //排序
- List<OTSPeriodicTable.Periodic> list_sortperiodic = list_periodic.OrderBy(s => s.FH).ToList();
- for (int i = 0; i < list_sortperiodic.Count; i++)
- {
- var va = list_sortperiodic[i].FH;
- cboElement1.Items.Add(va);
- cboElement3.Items.Add(va);
- if (va == v1)
- {
- cboElement1.SelectedIndex = i;
- }
- if (va == v2)
- {
- cboElement3.SelectedIndex = i;
- }
- }
- if ("" == v1)
- {
- cboElement1.SelectedIndex = 0;
- }
- if ("" == v2)
- {
- cboElement3.SelectedIndex = 0;
- }
- }
- #endregion
- #region 控件事件
- //保存,返回
- private void button1_Click(object sender, EventArgs e)
- {
- if (!Checking())
- {
- MessageBox.Show("Please enter full information!");
- return;
- }
- string TemplateName = txtType1.Text.Trim() + "." + txtType2.Text.Trim() + "." + txtType3.Text.Trim();
- string Element = cboElement1.Text + "." + txtElement2.Text.Trim() + "." + cboElement3.Text;
- string Group = txtType1.Text.Trim() + "-" + cboElement1.Text + "." +
- txtType2.Text.Trim() + "-" + txtElement2.Text.Trim() + "." +
- txtType3.Text.Trim() + "-" + cboElement3.Text;
- //获取三元相图模板配置文件
- string pathe = m_frmReportApp.m_RptConfigFile.FileFolderTrigTemp + "\\" + m_frmReportApp.m_RptConfigFile.TriTempFile;
- if (TemplateId != "")
- {
- string[] AttributeName = new string[] { "TemplateId", "TemplateName", "Element", "Group" };
- string[] Value = new string[] { TemplateId, TemplateName, Element, Group };
- bool ret = DataOperation.DataAccess.XMLoperate.UpdateByAttribute(pathe, AttributeName, Value);
- if (ret)
- {
- MessageBox.Show("保存成功!");
- }
- else
- {
- MessageBox.Show("保存失败!");
- }
- }
- else
- {
- string id = DateTime.Now.ToString("yyyyMMddHHmmss");
- string[] AttributeName = new string[] { "TemplateId", "TemplateName", "Element", "Group" };
- string[] Value = new string[] { id, TemplateName, Element, Group };
- int ret = DataOperation.DataAccess.XMLoperate.InsertAttribute(pathe, AttributeName, Value, "Member");
- if (ret == -1)
- {
- MessageBox.Show(TemplateName + "模板已经存在,不可重复添加!");
- }
- else if (ret == 0)
- {
- MessageBox.Show("保存失败!");
- }
- else
- {
- MessageBox.Show("保存成功!");
- }
- }
- this.DialogResult = DialogResult.OK;
- this.Close();
- }
- private void button2_Click(object sender, EventArgs e)
- {
- //取消
- this.Close();
- }
- private bool Checking()
- {
- if (txtType1.Text.Trim() == "")
- {
- txtType1.Focus();
- return false;
- }
- if (txtType2.Text.Trim() == "")
- {
- txtType2.Focus();
- return false;
- }
- if (txtType3.Text.Trim() == "")
- {
- txtType3.Focus();
- return false;
- }
- if (txtElement2.Text.Trim() == "")
- {
- txtElement2.Focus();
- return false;
- }
- return true;
- }
- #endregion
- private void btn_xsys_Click(object sender, EventArgs e)
- {
- //打开编辑元素列表窗体
- OTSPeriodicTableForm_Small opts = new OTSPeriodicTableForm_Small();
- //获取需要显示的元素列表,并转换成元素周期表窗体可接受的格式,传入----------------------
- string str_xsys = txtElement2.Text.Trim();
- List<string> list_str = new List<string>();
- string[] strs = str_xsys.Split(',');
- for (int i = 0; i < strs.Length; i++)
- {
- list_str.Add(strs[i]);
- }
- //清除元素周期表中所有的记录
- opts.m_List_Periodic.Clear();
- //将该分类下的元素添加到元素周期表窗体的List_periodic中
- for (int i = 0; i < strs.Length; i++)
- {
- string str_ysm = strs[i];
- OTSPeriodicTable.Periodic ls_periodic = new OTSPeriodicTable.Periodic();
- ls_periodic = OTSPeriodicTable.CListPeriodic.GetPeriodicByYsm(OTSPeriodicTable.CListPeriodic.GetListPeriodic(), str_ysm);
- opts.m_List_Periodic.Add(ls_periodic);
- }
- //----------------------------------------------------------------------------------------
- opts.ShowDialog();
- //先清空元素
- str_xsys = "";
- //然后再将选择的元素,组合起来,返回显示到该窗体上
- if (opts.m_List_Periodic.Count > 0)
- {
- for (int i = 0; i < opts.m_List_Periodic.Count; i++)
- {
- if (str_xsys == "")
- {
- str_xsys = opts.m_List_Periodic[i].FH;
- }
- else
- {
- str_xsys = str_xsys + "," + opts.m_List_Periodic[i].FH;
- }
- }
- }
- //再对选择的元素进行显示
- txtElement2.Text = str_xsys;
- }
- }
- }
|