Triangulation_Edit.cs 8.4 KB

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