Triangulation_Edit.cs 8.4 KB

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