Triangulation_Edit.cs 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. using OTSPeriodicTable;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.Linq;
  6. using System.Windows.Forms;
  7. namespace OTSIncAReportApp.OTSMgrInfo
  8. {
  9. public partial class Triangulation_Edit : Form
  10. {
  11. #region 变量定义
  12. //三元相图模板信息
  13. private string TriName = "";
  14. //是否为修改
  15. private string Template = "";
  16. private string TemplateId = "";
  17. private frmReportApp m_frmReportApp = null;
  18. #endregion
  19. #region 构造函数和窗体加载
  20. public Triangulation_Edit()
  21. {
  22. InitializeComponent();
  23. }
  24. public Triangulation_Edit( frmReportApp in_frmReportApp, string name, string id)
  25. {
  26. m_frmReportApp = in_frmReportApp;
  27. TriName = name;
  28. TemplateId = id;
  29. InitializeComponent();
  30. }
  31. private void Triangulation_Edit_Load(object sender, EventArgs e)
  32. {
  33. if (TriName != "")
  34. {
  35. string[] vs = TriName.Split('.');
  36. BindComboBox(vs[0].Split('-')[1], vs[2].Split('-')[1]);
  37. txtType1.Text = vs[0].Split('-')[0];
  38. txtType2.Text = vs[1].Split('-')[0];
  39. txtElement2.Text = vs[1].Split('-')[1];
  40. txtType3.Text = vs[2].Split('-')[0];
  41. Template = txtType1.Text.Trim() + "." + txtType2.Text.Trim() + "." + txtType3.Text.Trim();
  42. }
  43. else
  44. {
  45. BindComboBox("", "");
  46. }
  47. }
  48. /// <summary>
  49. /// 绑定元素名称,及元素数量combobox
  50. /// </summary>
  51. private void BindComboBox(string v1, string v2)
  52. {
  53. cboElement1.Items.Clear();
  54. cboElement3.Items.Clear();
  55. List<OTSPeriodicTable.Periodic> list_periodic = OTSPeriodicTable.CListPeriodic.GetListPeriodic();
  56. //排序
  57. List<OTSPeriodicTable.Periodic> list_sortperiodic = list_periodic.OrderBy(s => s.FH).ToList();
  58. for (int i = 0; i < list_sortperiodic.Count; i++)
  59. {
  60. var va = list_sortperiodic[i].FH;
  61. cboElement1.Items.Add(va);
  62. cboElement3.Items.Add(va);
  63. if (va == v1)
  64. {
  65. cboElement1.SelectedIndex = i;
  66. }
  67. if (va == v2)
  68. {
  69. cboElement3.SelectedIndex = i;
  70. }
  71. }
  72. if ("" == v1)
  73. {
  74. cboElement1.SelectedIndex = 0;
  75. }
  76. if ("" == v2)
  77. {
  78. cboElement3.SelectedIndex = 0;
  79. }
  80. }
  81. #endregion
  82. #region 控件事件
  83. //保存,返回
  84. private void button1_Click(object sender, EventArgs e)
  85. {
  86. if (!Checking())
  87. {
  88. MessageBox.Show("Please enter full information!");
  89. return;
  90. }
  91. string TemplateName = txtType1.Text.Trim() + "." + txtType2.Text.Trim() + "." + txtType3.Text.Trim();
  92. string Element = cboElement1.Text + "." + txtElement2.Text.Trim() + "." + cboElement3.Text;
  93. string Group = txtType1.Text.Trim() + "-" + cboElement1.Text + "." +
  94. txtType2.Text.Trim() + "-" + txtElement2.Text.Trim() + "." +
  95. txtType3.Text.Trim() + "-" + cboElement3.Text;
  96. //获取三元相图模板配置文件
  97. string pathe = m_frmReportApp.m_RptConfigFile.FileFolderTrigTemp + "\\" + m_frmReportApp.m_RptConfigFile.TriTempFile;
  98. if (TemplateId != "")
  99. {
  100. string[] AttributeName = new string[] { "TemplateId", "TemplateName", "Element", "Group" };
  101. string[] Value = new string[] { TemplateId, TemplateName, Element, Group };
  102. bool ret = DataOperation.DataAccess.XMLoperate.UpdateByAttribute(pathe, AttributeName, Value);
  103. if (ret)
  104. {
  105. MessageBox.Show("保存成功!");
  106. }
  107. else
  108. {
  109. MessageBox.Show("保存失败!");
  110. }
  111. }
  112. else
  113. {
  114. string id = DateTime.Now.ToString("yyyyMMddHHmmss");
  115. string[] AttributeName = new string[] { "TemplateId", "TemplateName", "Element", "Group" };
  116. string[] Value = new string[] { id, TemplateName, Element, Group };
  117. int ret = DataOperation.DataAccess.XMLoperate.InsertAttribute(pathe, AttributeName, Value, "Member");
  118. if (ret == -1)
  119. {
  120. MessageBox.Show(TemplateName + "模板已经存在,不可重复添加!");
  121. }
  122. else if (ret == 0)
  123. {
  124. MessageBox.Show("保存失败!");
  125. }
  126. else
  127. {
  128. MessageBox.Show("保存成功!");
  129. }
  130. }
  131. this.DialogResult = DialogResult.OK;
  132. this.Close();
  133. }
  134. private void button2_Click(object sender, EventArgs e)
  135. {
  136. //取消
  137. this.Close();
  138. }
  139. private bool Checking()
  140. {
  141. if (txtType1.Text.Trim() == "")
  142. {
  143. txtType1.Focus();
  144. return false;
  145. }
  146. if (txtType2.Text.Trim() == "")
  147. {
  148. txtType2.Focus();
  149. return false;
  150. }
  151. if (txtType3.Text.Trim() == "")
  152. {
  153. txtType3.Focus();
  154. return false;
  155. }
  156. if (txtElement2.Text.Trim() == "")
  157. {
  158. txtElement2.Focus();
  159. return false;
  160. }
  161. return true;
  162. }
  163. #endregion
  164. private void btn_xsys_Click(object sender, EventArgs e)
  165. {
  166. //打开编辑元素列表窗体
  167. OTSPeriodicTableForm_Small opts = new OTSPeriodicTableForm_Small();
  168. //获取需要显示的元素列表,并转换成元素周期表窗体可接受的格式,传入----------------------
  169. string str_xsys = txtElement2.Text.Trim();
  170. List<string> list_str = new List<string>();
  171. string[] strs = str_xsys.Split(',');
  172. for (int i = 0; i < strs.Length; i++)
  173. {
  174. list_str.Add(strs[i]);
  175. }
  176. //清除元素周期表中所有的记录
  177. opts.m_List_Periodic.Clear();
  178. //将该分类下的元素添加到元素周期表窗体的List_periodic中
  179. for (int i = 0; i < strs.Length; i++)
  180. {
  181. string str_ysm = strs[i];
  182. OTSPeriodicTable.Periodic ls_periodic = new OTSPeriodicTable.Periodic();
  183. ls_periodic = OTSPeriodicTable.CListPeriodic.GetPeriodicByYsm(OTSPeriodicTable.CListPeriodic.GetListPeriodic(), str_ysm);
  184. opts.m_List_Periodic.Add(ls_periodic);
  185. }
  186. //----------------------------------------------------------------------------------------
  187. opts.ShowDialog();
  188. //先清空元素
  189. str_xsys = "";
  190. //然后再将选择的元素,组合起来,返回显示到该窗体上
  191. if (opts.m_List_Periodic.Count > 0)
  192. {
  193. for (int i = 0; i < opts.m_List_Periodic.Count; i++)
  194. {
  195. if (str_xsys == "")
  196. {
  197. str_xsys = opts.m_List_Periodic[i].FH;
  198. }
  199. else
  200. {
  201. str_xsys = str_xsys + "," + opts.m_List_Periodic[i].FH;
  202. }
  203. }
  204. }
  205. //再对选择的元素进行显示
  206. txtElement2.Text = str_xsys;
  207. }
  208. }
  209. }