Form_MaxEDSRules.cs 58 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.Xml;
  11. using System.Xml.Linq;
  12. namespace OTSPartA_STDEditor
  13. {
  14. public partial class Form_MaxEDSRules : Form
  15. {
  16. //国际化
  17. Language lan;
  18. System.Collections.Hashtable table;
  19. string STDDBAddress = Application.StartupPath + "\\Config\\SysData\\" + "OTSCleanlinesSTD.db";
  20. //string STDDBAddress_backup = Application.StartupPath + "\\Config\\SysData\\LibBackup\\" + "OTSCleanlinesSTD_backup.db";
  21. string STDDBAddress_backupDirectory = Application.StartupPath + "\\Config\\SysData\\LibBackup\\";
  22. //元素周期表
  23. Form_PeriodicTable form_PeriodicTable=null;
  24. public Form_MaxEDSRules(string DBAddress)
  25. {
  26. InitializeComponent();
  27. STDDBAddress = DBAddress;
  28. //X = this.Width;
  29. //Y = this.Height;
  30. //setTag(this);
  31. }
  32. private void Form_MaxEDSRules_Load(object sender, EventArgs e)
  33. {
  34. //初始化comboBox
  35. this.comboBox_Elem1.Items.Add("first_elem");
  36. this.comboBox_Elem1.Items.Add("second_elem");
  37. this.comboBox_Elem1.Items.Add("third_elem");
  38. this.comboBox_Elem1.Items.Add("forth_elem");
  39. this.comboBox_Elem1.Items.Add("fifth_elem");
  40. this.comboBox_Elem1.Items.Add("sixth_elem");
  41. this.comboBox_Elem1.Items.Add("seventh_elem");
  42. this.comboBox_Elem1.Items.Add("eighth_elem");
  43. this.comboBox_Elem1.Items.Add("ninth_elem");
  44. this.comboBox_Elem1.Items.Add("tenth_elem");
  45. comboBox_Elem1.SelectedIndex = comboBox_Elem1.Items.IndexOf("first_elem");
  46. this.comboBox_Elem.Items.Add("Element#1");
  47. this.comboBox_Elem.Items.Add("Element#2");
  48. this.comboBox_Elem.Items.Add("Element#3");
  49. this.comboBox_Elem.Items.Add("Element#4");
  50. this.comboBox_Elem.Items.Add("Element#5");
  51. this.comboBox_Elem.Items.Add("Element#6");
  52. this.comboBox_Elem.Items.Add("Element#7");
  53. this.comboBox_Elem.Items.Add("Element#8");
  54. this.comboBox_Elem.Items.Add("Element#9");
  55. this.comboBox_Elem.Items.Add("Element#10");
  56. comboBox_Elem.SelectedIndex = comboBox_Elem.Items.IndexOf("Element#1");
  57. this.comboBox_ImgProperty.Items.Add("Dmax");
  58. this.comboBox_ImgProperty.Items.Add("Dmin");
  59. this.comboBox_ImgProperty.Items.Add("Aspect");
  60. this.comboBox_ImgProperty.Items.Add("Dperp");
  61. this.comboBox_ImgProperty.Items.Add("Dmean");
  62. this.comboBox_ImgProperty.Items.Add("Area");
  63. this.comboBox_ImgProperty.Items.Add("Dferet");
  64. this.comboBox_ImgProperty.Items.Add("With");
  65. this.comboBox_ImgProperty.Items.Add("Height");
  66. this.comboBox_ImgProperty.Items.Add("Perimeter");
  67. this.comboBox_ImgProperty.Items.Add("Dinscr");
  68. this.comboBox_ImgProperty.Items.Add("Orientation");
  69. this.comboBox_ImgProperty.Items.Add("Delong");
  70. this.comboBox_ImgProperty.Items.Add("Aspectelong");
  71. this.comboBox_ImgProperty.Items.Add("Dequalcircle");
  72. this.comboBox_ImgProperty.Items.Add("Vedio");
  73. comboBox_ImgProperty.SelectedIndex = comboBox_ImgProperty.Items.IndexOf("Dmax");
  74. string[] PeriodicTable = { "H", "He", "Li", "Be", "B", "C", "N", "O", "F", "Ne", "Na", "Mg", "Al", "Si", "P", "S", "Cl", "Ar", "K", "Ca", "Sc", "Ti", "V", "Cr", "Mn", "Fe", "Co", "Ni", "Cu", "Zn", "Ga", "Ge", "As", "Se", "Br", "Kr", "Rb", "Sr", "Y", "Zr", "Nb", "Mo", "Tc", "Ru", "Rh", "Pd", "Ag", "Cd", "In", "Sn", "Sb", "Te", "I", "Xe", "Cs", "Ba", "La", "Ce", "Pr", "Nd", "Pm", "Sm", "Eu", "Gd", "Tb", "Dy", "Ho", "Er", "Tm", "Yb", "Lu", "Hf", "Ta", "W", "Re", "Os", "Ir", "Pt", "Au", "Hq", "TI", "Pb", "Bi", "Po", "At", "Rn", "Fr", "Ra", "Ac", "Th", "Pa", "U", "Np", "Pu", "Am", "Cm", "Bk", "Cf", "Es", "Fm", "Mc", "No", "Lr", "Rf", "Db", "Sg", "Bh", "Hs", "Mt", "Ds", "Rg", "Unb" };
  75. comboBox_PeriodicTable.Items.AddRange(PeriodicTable);
  76. AutoCompleteStringCollection sc = new AutoCompleteStringCollection();
  77. sc.AddRange(PeriodicTable);
  78. this.comboBox_PeriodicTable.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.Suggest;
  79. this.comboBox_PeriodicTable.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.CustomSource;
  80. this.comboBox_PeriodicTable.AutoCompleteCustomSource = sc;
  81. LoadMaxEDSRulesToTreeControl(STDDBAddress, XmlTree_MaxEDSRules.Nodes);
  82. LoadConstants(STDDBAddress);
  83. this.textbox_STDEditor.Text = "";
  84. lan = new Language(this);
  85. table = lan.GetNameTable("Form_MaxEDSRules");
  86. if (table["language"].ToString() == "EN")
  87. {
  88. //panel_OTSPeriodicTable.BackgroundImage = global::OTSPartA_STDEditor.Properties.Resources.PeriodicTable_EN;
  89. PeriodicTableSwitch.BackgroundImage = global::OTSPartA_STDEditor.Properties.Resources.STDEditoName;
  90. PeriodicTableSwitch.Text = "";
  91. }
  92. else
  93. {
  94. //panel_OTSPeriodicTable.BackgroundImage = global::OTSPartA_STDEditor.Properties.Resources.PeriodicTable_ZH;
  95. PeriodicTableSwitch.Text = "元素周期表";
  96. }
  97. //panel_OTSPeriodicTable.Visible = true;
  98. //this.Width = this.Width - panel_OTSPeriodicTable.Width - 5;
  99. Size size = Screen.PrimaryScreen.WorkingArea.Size;
  100. Left = (size.Width - Width) / 2;
  101. Top = (size.Height - Height) / 2;
  102. WindowState = FormWindowState.Normal;
  103. //groupBox_XmlTree_MaxEDSRules.Focus();
  104. this.XmlTree_MaxEDSRules.HideSelection = false;//失去焦点后不隐藏选中节点
  105. XmlTree_MaxEDSRules.Focus();
  106. if (XmlTree_MaxEDSRules.Nodes.Count > 0)
  107. {
  108. XmlTree_MaxEDSRules.SelectedNode = XmlTree_MaxEDSRules.Nodes[0];
  109. XmlTree_MaxEDSRules_AfterSelect(XmlTree_MaxEDSRules, new TreeViewEventArgs(XmlTree_MaxEDSRules.SelectedNode));
  110. }
  111. }
  112. //XmlTree_MaxEDSRules
  113. void LoadXmlToTreeControl(XmlDocument xml,TreeNodeCollection XmlTree_MaxEDSRules)
  114. {
  115. XmlNode root = xml.SelectSingleNode("XMLData");
  116. XmlNodeList root2 = root.SelectNodes("Collection");
  117. for (int j = 0; j < root2.Count; j++)
  118. {
  119. if (root2[j].Attributes["RegName"].Value.ToString() == "MaxEDSRules")
  120. {
  121. XmlNodeList childlist = root2[j].ChildNodes;
  122. if (childlist.Count != 0)
  123. {
  124. for (int i = 0; i < childlist.Count; i++)
  125. {
  126. TreeNode new_child = new TreeNode();//定义一个TreeNode节点对象
  127. //new_child.Name = childlist[i].Attributes["MaxEDSTime"].Value;
  128. new_child.Tag = childlist[i].Attributes["Expression"].Value;
  129. new_child.Text = "Rule" + i.ToString();
  130. XmlTree_MaxEDSRules.Add(new_child);
  131. }
  132. if (childlist[0].Attributes["MaxEDSTime"] != null)
  133. {
  134. textBox_MaxEDSTime.Text = childlist[0].Attributes["MaxEDSTime"].Value;
  135. }
  136. }
  137. }
  138. }
  139. XmlNode root3 = root.SelectSingleNode("Member");
  140. string ConstantsStr = root3.Attributes["value"].Value;
  141. ConstantsStr = ConstantsStr.Replace(" ", "");
  142. string[] ConstantsStr2 = ConstantsStr.Split(',');
  143. this.comboBox_Constants.Items.Clear();
  144. this.comboBox_Constants.Items.AddRange(ConstantsStr2);
  145. }
  146. void LoadMaxEDSRulesToTreeControl(string DBAddress, TreeNodeCollection XmlTree_MaxEDSRules)
  147. {
  148. try
  149. {
  150. System.Data.SQLite.SQLiteConnection m_dbConnection = new System.Data.SQLite.SQLiteConnection("data source='" + DBAddress + "'");
  151. m_dbConnection.Open();
  152. System.Data.SQLite.SQLiteDataAdapter m_dataAdapter = new System.Data.SQLite.SQLiteDataAdapter("select * from MaxEDSRules", m_dbConnection);
  153. DataSet ds = new DataSet();
  154. m_dataAdapter.Fill(ds);
  155. DataTable dt = ds.Tables[0];
  156. if (dt != null)
  157. {
  158. if (dt.Rows.Count > 0)
  159. {
  160. int i = 1;
  161. foreach (DataRow item in dt.Rows)
  162. {
  163. TreeNode new_child = new TreeNode();//定义一个TreeNode节点对象
  164. new_child.Tag = item["Expression"].ToString();
  165. new_child.Text = "Rule" + i.ToString();
  166. XmlTree_MaxEDSRules.Add(new_child);
  167. i++;
  168. }
  169. if (dt.Rows[0]["MaxEDSTime"] != null)
  170. {
  171. textBox_MaxEDSTime.Text = dt.Rows[0]["MaxEDSTime"].ToString();
  172. }
  173. }
  174. }
  175. }
  176. catch (Exception ee)
  177. {
  178. MessageBox.Show(ee.ToString());
  179. }
  180. }
  181. void LoadConstants(string STDDBAddress)
  182. {
  183. try
  184. {
  185. System.Data.SQLite.SQLiteConnection m_dbConnection = new System.Data.SQLite.SQLiteConnection("data source='" + STDDBAddress + "'");
  186. m_dbConnection.Open();
  187. System.Data.SQLite.SQLiteDataAdapter m_dataAdapter = new System.Data.SQLite.SQLiteDataAdapter("select * from Constants", m_dbConnection);
  188. DataSet ds = new DataSet();
  189. m_dataAdapter.Fill(ds);
  190. DataTable dt = ds.Tables[0];
  191. string ConstantsStr = "";
  192. if (dt.Rows.Count > 0)
  193. {
  194. ConstantsStr = dt.Rows[0][0].ToString();
  195. }
  196. ConstantsStr = ConstantsStr.Replace(" ", "");
  197. string[] ConstantsStr2 = ConstantsStr.Split(',');
  198. comboBox_Constants.Items.Clear();
  199. comboBox_Constants.Items.AddRange(ConstantsStr2);
  200. m_dbConnection.Close();
  201. }
  202. catch (Exception ee)
  203. {
  204. MessageBox.Show(ee.ToString());
  205. }
  206. }
  207. private void comboBox_Elem1_SelectedIndexChanged(object sender, EventArgs e)
  208. {
  209. string newStr = comboBox_Elem1.SelectedItem.ToString();
  210. int index = textbox_STDEditor.SelectionStart;
  211. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, newStr);
  212. textbox_STDEditor.Focus();
  213. textbox_STDEditor.Select(index + newStr.Length, 0);
  214. textbox_STDEditor.ScrollToCaret();
  215. }
  216. private void comboBox_Elem2_SelectedIndexChanged(object sender, EventArgs e)
  217. {
  218. string newStr = comboBox_Elem.SelectedItem.ToString();
  219. int index = textbox_STDEditor.SelectionStart;
  220. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, newStr);
  221. textbox_STDEditor.Focus();
  222. textbox_STDEditor.Select(index + newStr.Length, 0);
  223. textbox_STDEditor.ScrollToCaret();
  224. }
  225. private void comboBox_ImgProperty_SelectedIndexChanged(object sender, EventArgs e)
  226. {
  227. string newStr = comboBox_ImgProperty.SelectedItem.ToString();
  228. int index = textbox_STDEditor.SelectionStart;
  229. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, newStr);
  230. textbox_STDEditor.Focus();
  231. textbox_STDEditor.Select(index + newStr.Length, 0);
  232. textbox_STDEditor.ScrollToCaret();
  233. }
  234. private void button_Plus_Click(object sender, EventArgs e)
  235. {
  236. int index = textbox_STDEditor.SelectionStart;
  237. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "+");
  238. textbox_STDEditor.Focus();
  239. textbox_STDEditor.Select(index+1,0);
  240. textbox_STDEditor.ScrollToCaret();
  241. }
  242. private void button_Subtract_Click(object sender, EventArgs e)
  243. {
  244. int index = textbox_STDEditor.SelectionStart;
  245. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "-");
  246. textbox_STDEditor.Focus();
  247. textbox_STDEditor.Select(index + 1, 0);
  248. textbox_STDEditor.ScrollToCaret();
  249. }
  250. private void button_Multiply_Click(object sender, EventArgs e)
  251. {
  252. int index = textbox_STDEditor.SelectionStart;
  253. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "*");
  254. textbox_STDEditor.Focus();
  255. textbox_STDEditor.Select(index + 1, 0);
  256. textbox_STDEditor.ScrollToCaret();
  257. }
  258. private void button_Divide_Click(object sender, EventArgs e)
  259. {
  260. int index = textbox_STDEditor.SelectionStart;
  261. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "/");
  262. textbox_STDEditor.Focus();
  263. textbox_STDEditor.Select(index + 1, 0);
  264. textbox_STDEditor.ScrollToCaret(); ;
  265. }
  266. private void button_More_Click(object sender, EventArgs e)
  267. {
  268. int index = textbox_STDEditor.SelectionStart;
  269. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, ">");
  270. textbox_STDEditor.Focus();
  271. textbox_STDEditor.Select(index + 1, 0);
  272. textbox_STDEditor.ScrollToCaret();
  273. }
  274. private void button_Less_Click(object sender, EventArgs e)
  275. {
  276. int index = textbox_STDEditor.SelectionStart;
  277. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "<");
  278. textbox_STDEditor.Focus();
  279. textbox_STDEditor.Select(index + 1, 0);
  280. textbox_STDEditor.ScrollToCaret();
  281. }
  282. private void button_LeftParenthesis_Click(object sender, EventArgs e)
  283. {
  284. int index = textbox_STDEditor.SelectionStart;
  285. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "(");
  286. textbox_STDEditor.Focus();
  287. textbox_STDEditor.Select(index + 1, 0);
  288. textbox_STDEditor.ScrollToCaret();
  289. }
  290. private void button_RightParenthesis_Click(object sender, EventArgs e)
  291. {
  292. int index = textbox_STDEditor.SelectionStart;
  293. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, ")");
  294. textbox_STDEditor.Focus();
  295. textbox_STDEditor.Select(index + 1, 0);
  296. textbox_STDEditor.ScrollToCaret();
  297. }
  298. private void button_Equal_Click(object sender, EventArgs e)
  299. {
  300. int index = textbox_STDEditor.SelectionStart;
  301. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "=");
  302. textbox_STDEditor.Focus();
  303. textbox_STDEditor.Select(index + 1, 0);
  304. textbox_STDEditor.ScrollToCaret();
  305. }
  306. //除选中点以外其它节点前景色置灰
  307. private void SetGrayExceptSelectedNode(TreeView Tree, TreeNode SelectedNode)
  308. {
  309. foreach (TreeNode node in Tree.Nodes)
  310. {
  311. if (node != SelectedNode)
  312. {
  313. node.ForeColor = Color.Gray;
  314. }
  315. }
  316. }
  317. //恢复所有节点颜色为可用
  318. private void SetBlackAllNodes(TreeView Tree)
  319. {
  320. foreach (TreeNode node in Tree.Nodes)
  321. {
  322. node.ForeColor = Color.Black;
  323. }
  324. }
  325. //删除
  326. private void DeleteTreeNode_Click(object sender, EventArgs e)
  327. {
  328. try
  329. {
  330. TreeView XmlTree = (TreeView)XmlTreeMenuStrip.SourceControl;
  331. if (XmlTree.SelectedNode != null)
  332. {
  333. if (XmlTree != null)
  334. {
  335. if (XmlTree.SelectedNode.NextNode != null)
  336. {
  337. TreeNode Temp = XmlTree.SelectedNode.NextNode;
  338. XmlTree.SelectedNode.Remove();
  339. XmlTree.SelectedNode = Temp;
  340. }
  341. else if (XmlTree.SelectedNode.PrevNode != null)
  342. {
  343. TreeNode Temp = XmlTree.SelectedNode.PrevNode;
  344. XmlTree.SelectedNode.Remove();
  345. XmlTree.SelectedNode = Temp;
  346. }
  347. else
  348. {
  349. XmlTree.SelectedNode.Remove();
  350. XmlTree.SelectedNode = null;
  351. if (XmlTree.Name == "XmlTree_MaxEDSRules")
  352. {
  353. textbox_STDEditor.Text = "";
  354. textBox_MaxEDSTime.Text = "";
  355. }
  356. }
  357. }
  358. }
  359. else
  360. {
  361. MessageBox.Show("No nodes are selected!", "Tip", MessageBoxButtons.OK, MessageBoxIcon.Information);
  362. }
  363. }
  364. catch (Exception ex)
  365. {
  366. MessageBox.Show(ex.ToString(), "Tip");
  367. }
  368. }
  369. //新建
  370. private void AddTreeNode_Click(object sender, EventArgs e)
  371. {
  372. try
  373. {
  374. if (XmlTree_MaxEDSRules.SelectedNode != null)
  375. {
  376. //判断MaxEDSTime
  377. double dMaxEDSTime = 0;
  378. if (!double.TryParse(textBox_MaxEDSTime.Text, out dMaxEDSTime) || double.Parse(textBox_MaxEDSTime.Text) <= 0)
  379. {
  380. MessageBox.Show("The MaxEDSTime of current selected node input error, please enter the correct format!", "Tip", MessageBoxButtons.OK, MessageBoxIcon.Information);
  381. return;
  382. }
  383. //判断textbox_STDEditor
  384. if (!Checktextbox_STDEditor())
  385. {
  386. return;
  387. }
  388. XmlTree_MaxEDSRules.SelectedNode.Tag = this.textbox_STDEditor.Text;
  389. }
  390. TreeNode new_child = new TreeNode();//定义一个TreeNode节点对象
  391. TreeView XmlTree = (TreeView)XmlTreeMenuStrip.SourceControl;
  392. if (XmlTreeMenuStrip.SourceControl.Name == "XmlTree_MaxEDSRules")
  393. {
  394. int Number = XmlTree.Nodes.Count;
  395. for (int num = 0; num < XmlTree.Nodes.Count; num++)
  396. {
  397. string aa = XmlTree.Nodes[num].Text.ToString().Substring(XmlTree.Nodes[num].Text.Length - 1, 1);
  398. int tp = int.Parse(XmlTree.Nodes[num].Text.ToString().Substring(XmlTree.Nodes[num].Text.Length - 1, 1));
  399. if (Number < tp) Number = tp;
  400. }
  401. new_child.Text = "Rule" + Number.ToString();
  402. new_child.Tag = "NewRules";
  403. textbox_STDEditor.Text = "NewRules";
  404. }
  405. XmlTree.Nodes.Add(new_child);
  406. XmlTree.SelectedNode = null;
  407. XmlTree.SelectedNode = new_child;
  408. }
  409. catch (Exception ex)
  410. {
  411. MessageBox.Show(ex.ToString(), "Tip");
  412. }
  413. }
  414. void SaveXmlTreeDataToMaxEDSRules(string DBAddress)
  415. {
  416. System.Data.SQLite.SQLiteConnection m_dbConnection = new System.Data.SQLite.SQLiteConnection("data source='" + DBAddress + "'");
  417. m_dbConnection.Open();
  418. System.Data.SQLite.SQLiteCommand cmm = m_dbConnection.CreateCommand();
  419. cmm.CommandText = "delete from MaxEDSRules";
  420. try
  421. {
  422. cmm.ExecuteNonQuery();
  423. }
  424. catch (Exception ex)
  425. {
  426. MessageBox.Show(ex.ToString());
  427. }
  428. System.Data.SQLite.SQLiteDataAdapter m_dataAdapter = new System.Data.SQLite.SQLiteDataAdapter("select * from MaxEDSRules", m_dbConnection);
  429. System.Data.SQLite.SQLiteCommandBuilder qLiteCommandBuilder = new System.Data.SQLite.SQLiteCommandBuilder(m_dataAdapter);
  430. DataSet ds = new DataSet();
  431. m_dataAdapter.Fill(ds, "MaxEDSRules");
  432. DataTable dt = ds.Tables["MaxEDSRules"];
  433. dt.Clear();
  434. for (int num = 0; num < XmlTree_MaxEDSRules.Nodes.Count; num++)
  435. {
  436. string UsingElementList = "";
  437. string UsingImgPropertyList = "";
  438. string UsingOtherPropertyList = "";
  439. List<string> UsingElementL = new List<string>();
  440. List<string> UsingImgPropertyL = new List<string>();
  441. List<string> UsingOtherPropertyL = new List<string>();
  442. string str_RemoveBlank = "";
  443. //forth_elem干扰or分隔符,故先行去掉
  444. if (XmlTree_MaxEDSRules.Nodes[num].Tag.ToString().Contains("forth_elem"))
  445. {
  446. str_RemoveBlank = str_RemoveBlank.Replace("forth_elem", "");
  447. UsingOtherPropertyList = "forth_elem,";
  448. }
  449. str_RemoveBlank = XmlTree_MaxEDSRules.Nodes[num].Tag.ToString().Replace(" ", "");
  450. string[] str_Removeand = System.Text.RegularExpressions.Regex.Split(str_RemoveBlank, "and", System.Text.RegularExpressions.RegexOptions.None);
  451. List<string> str_Removeandor = new List<string>();
  452. for (int i = 0; i < str_Removeand.Length; i++)
  453. {
  454. str_Removeandor.AddRange(System.Text.RegularExpressions.Regex.Split(str_Removeand[i], "or", System.Text.RegularExpressions.RegexOptions.None));
  455. }
  456. List<string> list_all = new List<string>();
  457. for (int i = 0; i < str_Removeandor.Count; i++)
  458. {
  459. list_all.AddRange(str_Removeandor[i].Split(new char[] { '+', '-', '*', '/', '=', '>', '<', '(', ')' }));
  460. }
  461. for (int i = 0; i < list_all.Count; i++)
  462. {
  463. //周期元素?
  464. if (this.comboBox_PeriodicTable.Items.Contains(list_all[i]))
  465. {
  466. if (!UsingElementL.Contains(list_all[i]))
  467. {
  468. UsingElementL.Add(list_all[i]);
  469. }
  470. }
  471. //first_elem?
  472. if (this.comboBox_Elem1.Items.Contains(list_all[i]))
  473. {
  474. if (!UsingOtherPropertyL.Contains(list_all[i]))
  475. {
  476. UsingOtherPropertyL.Add(list_all[i]);
  477. }
  478. }
  479. //Element1?
  480. if (this.comboBox_Elem.Items.Contains(list_all[i]))
  481. {
  482. if (!UsingOtherPropertyL.Contains(list_all[i]))
  483. {
  484. UsingOtherPropertyL.Add(list_all[i]);
  485. }
  486. }
  487. //其它元素?
  488. if (this.comboBox_ImgProperty.Items.Contains(list_all[i]))
  489. {
  490. if (!UsingImgPropertyL.Contains(list_all[i]))
  491. {
  492. UsingImgPropertyL.Add(list_all[i]);
  493. }
  494. }
  495. }
  496. if (UsingElementL.Count > 0)
  497. {
  498. for (int i = 0; i < UsingElementL.Count - 1; i++)
  499. {
  500. UsingElementList += UsingElementL[i] + ",";
  501. }
  502. UsingElementList += UsingElementL[UsingElementL.Count - 1];
  503. }
  504. if (UsingImgPropertyL.Count > 0)
  505. {
  506. for (int i = 0; i < UsingImgPropertyL.Count - 1; i++)
  507. {
  508. UsingImgPropertyList += UsingImgPropertyL[i] + ",";
  509. }
  510. UsingImgPropertyList += UsingImgPropertyL[UsingImgPropertyL.Count - 1];
  511. }
  512. if (UsingOtherPropertyL.Count > 0)
  513. {
  514. for (int i = 0; i < UsingOtherPropertyL.Count - 1; i++)
  515. {
  516. UsingOtherPropertyList += UsingOtherPropertyL[i] + ",";
  517. }
  518. UsingOtherPropertyList += UsingOtherPropertyL[UsingOtherPropertyL.Count - 1];
  519. }
  520. DataRow newRow = dt.NewRow();
  521. newRow["MaxEDSTime"] = int.Parse(textBox_MaxEDSTime.Text);
  522. newRow["UsingElementList"] = UsingElementList;
  523. newRow["UsingImgPropertyList"] = UsingImgPropertyList;
  524. newRow["UsingOtherPropertyList"] = UsingOtherPropertyList;
  525. newRow["Expression"] = XmlTree_MaxEDSRules.Nodes[num].Tag;
  526. dt.Rows.Add(newRow);
  527. }
  528. m_dataAdapter.Update(ds, "MaxEDSRules");
  529. m_dbConnection.Close();
  530. MessageBox.Show("Save successful!", "Tip");
  531. }
  532. //元素周期表开关
  533. private void PeriodicTableSwitch_Click(object sender, EventArgs e)
  534. {
  535. //if (PeriodicTableSwitch.BackColor == SystemColors.Control)
  536. //{
  537. // //this.Resize -= new System.EventHandler(this.Form_MaxEDSRules_Resize);
  538. // panel_OTSPeriodicTable.Visible = false;
  539. // this.Width = this.Width - panel_OTSPeriodicTable.Width;
  540. // //this.Resize += new System.EventHandler(this.Form_MaxEDSRules_Resize);
  541. // PeriodicTableSwitch.BackColor = SystemColors.ControlDark;
  542. // //if (Language == "English")
  543. // //{
  544. // // PeriodicTableSwitch.Text = "Close PeriodicTable";
  545. // //}
  546. // //else if(Language == "Chinese")
  547. // //{
  548. // // PeriodicTableSwitch.Text = "关闭元素周期表";
  549. // //}
  550. //}
  551. //else if (PeriodicTableSwitch.BackColor == SystemColors.ControlDark)
  552. //{
  553. // //this.Resize -= new System.EventHandler(this.Form_MaxEDSRules_Resize);
  554. // //this.Width = this.Width + panel_OTSPeriodicTable.Width + 5;
  555. // panel_OTSPeriodicTable.Visible = true;
  556. // //this.Resize += new System.EventHandler(this.Form_MaxEDSRules_Resize);
  557. // PeriodicTableSwitch.BackColor = SystemColors.Control;
  558. // //if (Language == "English")
  559. // //{
  560. // // PeriodicTableSwitch.Text = "Open PeriodicTable";
  561. // //}
  562. // //else if (Language == "Chinese")
  563. // //{
  564. // // PeriodicTableSwitch.Text = "打开元素周期表";
  565. // //}
  566. // //textbox_STDEditor.Focus();
  567. // groupBox_CalculatingSymbols.Focus();
  568. //}
  569. if (form_PeriodicTable == null)
  570. {
  571. form_PeriodicTable = new Form_PeriodicTable();
  572. form_PeriodicTable.Show();
  573. form_PeriodicTable.Location = new Point(this.Location.X + this.Width - 14, this.Location.Y);
  574. }
  575. else
  576. {
  577. if (form_PeriodicTable.IsDisposed)
  578. {
  579. form_PeriodicTable = new Form_PeriodicTable();
  580. form_PeriodicTable.Show();
  581. form_PeriodicTable.Location = new Point(this.Location.X + this.Width - 14, this.Location.Y);
  582. }
  583. else
  584. {
  585. form_PeriodicTable.Activate();
  586. }
  587. }
  588. }
  589. private void button_Ok_Click(object sender, EventArgs e)
  590. {
  591. if (XmlTree_MaxEDSRules.SelectedNode != null)
  592. {
  593. //判断MaxEDSTime
  594. double dMaxEDSTime = 0;
  595. if (!double.TryParse(textBox_MaxEDSTime.Text, out dMaxEDSTime) || double.Parse(textBox_MaxEDSTime.Text) <= 0)
  596. {
  597. textBox_MaxEDSTime.Focus();
  598. textBox_MaxEDSTime.SelectAll();
  599. MessageBox.Show("The Item of MaxEDSTime input error, please enter the correct format!", "Tip", MessageBoxButtons.OK, MessageBoxIcon.Information);
  600. return;
  601. }
  602. //判断textbox_STDEditor
  603. if (!Checktextbox_STDEditor())
  604. {
  605. return;
  606. }
  607. XmlTree_MaxEDSRules.SelectedNode.Tag = this.textbox_STDEditor.Text;
  608. //XmlTree_MaxEDSRules.SelectedNode.Name = textBox_MaxEDSTime.Text;
  609. }
  610. SaveXmlTreeDataToMaxEDSRules(STDDBAddress);
  611. this.Close();
  612. }
  613. private void button_Cancel_Click(object sender, EventArgs e)
  614. {
  615. this.Close();
  616. }
  617. //元素下拉选择输入
  618. private void comboBox_PeriodicTable_SelectedIndexChanged(object sender, EventArgs e)
  619. {
  620. if (comboBox_PeriodicTable.Text != null && comboBox_PeriodicTable.SelectedItem != null)
  621. {
  622. string newStr = comboBox_PeriodicTable.SelectedItem.ToString();
  623. comboBox_PeriodicTable.Text = null;
  624. int index = textbox_STDEditor.SelectionStart;
  625. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, newStr);
  626. textbox_STDEditor.Focus();
  627. textbox_STDEditor.Select(index + newStr.Length, 0);
  628. textbox_STDEditor.ScrollToCaret();
  629. }
  630. }
  631. //元素自身text按回车键输入
  632. private void comboBox_PeriodicTable_KeyDown(object sender, KeyEventArgs e)
  633. {
  634. if (e.KeyValue == 13)
  635. {
  636. if (comboBox_PeriodicTable.Text != null && comboBox_PeriodicTable.Text != "")
  637. {
  638. this.textbox_STDEditor.Text += comboBox_PeriodicTable.Text.ToString();
  639. comboBox_PeriodicTable.Text = null;
  640. }
  641. }
  642. }
  643. //表达式规则检查
  644. private bool Checktextbox_STDEditor()
  645. {
  646. if (textbox_STDEditor.Text == "" || textbox_STDEditor.Text == null)
  647. {
  648. textBox_MaxEDSTime.Focus();
  649. MessageBox.Show("The content of Standard library cannot be empty!", "Tip", MessageBoxButtons.OK, MessageBoxIcon.Information);
  650. return false;
  651. }
  652. string str_RemoveBlank = textbox_STDEditor.Text.ToString().Replace(" ", "");
  653. str_RemoveBlank = str_RemoveBlank.Replace("\r\n", "");
  654. //分割符号检验
  655. string[] Symbol = { "and", "or", "+", "-", "*", "/", "=", ">", "<" };
  656. for (int i = 0; i < Symbol.Length; i++)
  657. {
  658. for (int j = 0; j < Symbol.Length; j++)
  659. {
  660. if ((Symbol[i] + Symbol[j]) != ">=" && (Symbol[i] + Symbol[j]) != "<=")
  661. {
  662. if (str_RemoveBlank.Contains(Symbol[i] + Symbol[j]))
  663. {
  664. MessageBox.Show("Invalid string exists:" + Symbol[i] + Symbol[j], "Tip", MessageBoxButtons.OK, MessageBoxIcon.Information);
  665. return false;
  666. }
  667. }
  668. }
  669. if (str_RemoveBlank.Contains(Symbol[i] + ")") || str_RemoveBlank.Contains("(" + Symbol[i]))
  670. {
  671. MessageBox.Show("Invalid string exists:" + Symbol[i] + ")", "Tip", MessageBoxButtons.OK, MessageBoxIcon.Information);
  672. return false;
  673. }
  674. if (str_RemoveBlank.Contains("(" + Symbol[i]))
  675. {
  676. MessageBox.Show("Invalid string exists:" + "(" + Symbol[i], "Tip", MessageBoxButtons.OK, MessageBoxIcon.Information);
  677. return false;
  678. }
  679. }
  680. if ((str_RemoveBlank != null) && (str_RemoveBlank != ""))
  681. {
  682. //左右括号匹配检验
  683. int BracketsNum = 0;
  684. for (int i = 0; i < str_RemoveBlank.Length; i++)
  685. {
  686. if (str_RemoveBlank[i] == '(') BracketsNum++;
  687. if (str_RemoveBlank[i] == ')') BracketsNum--;
  688. }
  689. if (BracketsNum != 0)
  690. {
  691. MessageBox.Show("Number of left and right parentheses does not match!", "Tip", MessageBoxButtons.OK,MessageBoxIcon.Information);
  692. return false;
  693. }
  694. //首字符检测
  695. if ((str_RemoveBlank[0] == '+') || (str_RemoveBlank[0] == '-') || (str_RemoveBlank[0] == '*') || (str_RemoveBlank[0] == '/') || (str_RemoveBlank[0] == '>') || (str_RemoveBlank[0] == '<') || (str_RemoveBlank[0] == '=') || (str_RemoveBlank[0] == ')') || (str_RemoveBlank[str_RemoveBlank.Length - 1] == '('))
  696. {
  697. MessageBox.Show("First character is error!", "Tip", MessageBoxButtons.OK, MessageBoxIcon.Information);
  698. return false;
  699. }
  700. if (str_RemoveBlank.Length >= 3)
  701. {
  702. if ((str_RemoveBlank.Substring(0, 3) == "and") || (str_RemoveBlank.Substring(0, 3) == "end"))
  703. {
  704. MessageBox.Show("First character is error!", "Tip", MessageBoxButtons.OK, MessageBoxIcon.Information);
  705. return false;
  706. }
  707. }
  708. }
  709. //forth_elem干扰or分隔符,故先行去掉
  710. str_RemoveBlank = str_RemoveBlank.Replace("forth_elem", "");
  711. string[] str_Removeand = System.Text.RegularExpressions.Regex.Split(str_RemoveBlank, "and", System.Text.RegularExpressions.RegexOptions.None);
  712. List<string> str_Removeandor = new List<string>();
  713. for (int i = 0; i < str_Removeand.Length; i++)
  714. {
  715. str_Removeandor.AddRange(System.Text.RegularExpressions.Regex.Split(str_Removeand[i], "or", System.Text.RegularExpressions.RegexOptions.None));
  716. }
  717. List<string> list_all = new List<string>();
  718. for (int i = 0; i < str_Removeandor.Count; i++)
  719. {
  720. list_all.AddRange(str_Removeandor[i].Split(new char[] { '+', '-', '*', '/', '=', '>', '<', '(', ')' }));
  721. }
  722. //常量
  723. List<string> Constantslist = new List<string>();
  724. for (int j = 0; j < comboBox_Constants.Items.Count; j++)
  725. {
  726. Constantslist.Add(comboBox_Constants.Items[j].ToString().Split('=')[0]);
  727. }
  728. for (int i = 0; i < list_all.Count; i++)
  729. {
  730. //周期元素?
  731. if (this.comboBox_PeriodicTable.Items.Contains(list_all[i]))
  732. {
  733. continue;
  734. }
  735. //first_elem?
  736. if (this.comboBox_Elem1.Items.Contains(list_all[i]))
  737. {
  738. continue;
  739. }
  740. //Element1?
  741. if (this.comboBox_Elem.Items.Contains(list_all[i]))
  742. {
  743. continue;
  744. }
  745. //其它元素?
  746. if (this.comboBox_ImgProperty.Items.Contains(list_all[i]))
  747. {
  748. continue;
  749. }
  750. //常量?
  751. if (Constantslist.Contains(list_all[i]))
  752. {
  753. continue;
  754. }
  755. //数字?
  756. double DNum = 0;
  757. if (double.TryParse(list_all[i], out DNum))
  758. {
  759. continue;
  760. }
  761. //>=? <=?等其它情况
  762. if (list_all[i] == "")
  763. {
  764. continue;
  765. }
  766. //true false?
  767. if ((list_all[i] == "true") || (list_all[i] == "false"))
  768. {
  769. continue;
  770. }
  771. MessageBox.Show("Please check whether the input rules are correct, error characters:" + list_all[i], "Tip", MessageBoxButtons.OK, MessageBoxIcon.Information);
  772. return false;
  773. }
  774. //检测是否有<>= true,false
  775. if (!textbox_STDEditor.Text.ToString().Contains("<") && !textbox_STDEditor.Text.ToString().Contains(">") && !textbox_STDEditor.Text.ToString().Contains("=")&& textbox_STDEditor.Text.ToString()!="true"&& textbox_STDEditor.Text.ToString() != "false")
  776. {
  777. MessageBox.Show("Expressions have no effect!", "Tip", MessageBoxButtons.OK, MessageBoxIcon.Information);
  778. return false;
  779. }
  780. return true;
  781. }
  782. private void button_And_Click(object sender, EventArgs e)
  783. {
  784. //textbox_STDEditor 中的光标
  785. int index = textbox_STDEditor.SelectionStart;
  786. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "and");
  787. textbox_STDEditor.Focus();
  788. textbox_STDEditor.Select(index + 3, 0);
  789. textbox_STDEditor.ScrollToCaret();
  790. }
  791. private void button_Or_Click(object sender, EventArgs e)
  792. {
  793. //textbox_STDEditor 中的光标
  794. int index = textbox_STDEditor.SelectionStart;
  795. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "or");
  796. textbox_STDEditor.Focus();
  797. textbox_STDEditor.Select(index + 2, 0);
  798. textbox_STDEditor.ScrollToCaret();
  799. }
  800. private void comboBox_Constants_SelectedIndexChanged(object sender, EventArgs e)
  801. {
  802. if (comboBox_Constants.SelectedItem != null)
  803. {
  804. string newStr = comboBox_Constants.SelectedItem.ToString().Split('=')[0];
  805. int index = textbox_STDEditor.SelectionStart;
  806. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, newStr);
  807. textbox_STDEditor.Focus();
  808. textbox_STDEditor.Select(index + newStr.Length, 0);
  809. textbox_STDEditor.ScrollToCaret();
  810. }
  811. }
  812. private void button_Recover_Click(object sender, EventArgs e)
  813. {
  814. XmlDocument doc = new XmlDocument();
  815. try
  816. {
  817. //System.IO.File.Copy(Address_backup, Address, true);
  818. //doc.Load(Address_backup);
  819. //LoadXmlToTreeControl(doc, XmlTree_MaxEDSRules.Nodes);
  820. XmlTree_MaxEDSRules.Nodes.Clear();
  821. string STDDBAddress_backup = "";
  822. string[] files = System.IO.Directory.GetFiles(STDDBAddress_backupDirectory);//得到文件
  823. foreach (var file in files)
  824. {
  825. if (".db".IndexOf(file.Substring(file.LastIndexOf(".") + 1)) > -1)
  826. {
  827. STDDBAddress_backup = file;
  828. }
  829. }
  830. LoadMaxEDSRulesToTreeControl(STDDBAddress_backup, XmlTree_MaxEDSRules.Nodes);
  831. XmlTree_MaxEDSRules.Focus();
  832. if (XmlTree_MaxEDSRules.Nodes.Count > 0)
  833. {
  834. XmlTree_MaxEDSRules.SelectedNode = XmlTree_MaxEDSRules.Nodes[0];
  835. XmlTree_MaxEDSRules_AfterSelect(XmlTree_MaxEDSRules, new TreeViewEventArgs(XmlTree_MaxEDSRules.SelectedNode));
  836. }
  837. else
  838. {
  839. textbox_STDEditor.Text = "";
  840. textBox_MaxEDSTime.Text = "";
  841. }
  842. }
  843. catch(Exception ex)
  844. {
  845. MessageBox.Show("Recovery failed!" + "\n"+ex.Message.ToString(), "Tip", MessageBoxButtons.OK, MessageBoxIcon.Information);
  846. }
  847. }
  848. private bool CheckConstants(string ConstantName)
  849. {
  850. for (int num = 0; num < XmlTree_MaxEDSRules.Nodes.Count; num++)
  851. {
  852. if (XmlTree_MaxEDSRules.Nodes[num].Tag.ToString().Contains(ConstantName))
  853. {
  854. XmlTree_MaxEDSRules.SelectedNode = XmlTree_MaxEDSRules.Nodes[num];
  855. SetGrayExceptSelectedNode(XmlTree_MaxEDSRules, XmlTree_MaxEDSRules.SelectedNode);
  856. DialogResult result = MessageBox.Show("Closing failed," + XmlTree_MaxEDSRules.Nodes[num].Text + table["message28"].ToString(), "Tip", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  857. return false;
  858. }
  859. }
  860. return true;
  861. }
  862. private void XmlTree_MaxEDSRules_AfterSelect(object sender, TreeViewEventArgs e)
  863. {
  864. SetBlackAllNodes(XmlTree_MaxEDSRules);
  865. this.textbox_STDEditor.Text = XmlTree_MaxEDSRules.SelectedNode.Tag.ToString();
  866. }
  867. private void XmlTree_MaxEDSRules_BeforeSelect(object sender, TreeViewCancelEventArgs e)
  868. {
  869. if (XmlTree_MaxEDSRules.SelectedNode != null)
  870. {
  871. if (!Checktextbox_STDEditor())
  872. {
  873. SetGrayExceptSelectedNode(XmlTree_MaxEDSRules, XmlTree_MaxEDSRules.SelectedNode);
  874. e.Cancel = true;
  875. return;
  876. }
  877. XmlTree_MaxEDSRules.SelectedNode.Tag = this.textbox_STDEditor.Text;
  878. }
  879. }
  880. private void textbox_STDEditor_Leave(object sender, EventArgs e)
  881. {
  882. XmlTree_MaxEDSRules.Focus();
  883. }
  884. #region 为配合textbox_STDEditor_Leave时事件,点击其它groupbox组件时使焦点转移
  885. private void Form_ConstantsEditor_Click(object sender, EventArgs e)
  886. {
  887. groupBox_XmlTree_MaxEDSRules.Focus();
  888. }
  889. private void groupBox_Data_Click(object sender, EventArgs e)
  890. {
  891. groupBox_Data.Focus();
  892. }
  893. private void groupBox_ChemicalElement_Click(object sender, EventArgs e)
  894. {
  895. groupBox_ChemicalElement.Focus();
  896. }
  897. private void groupBox_OtherCommonlyUsedSymbols_Click(object sender, EventArgs e)
  898. {
  899. groupBox_OtherCommonlyUsedSymbols.Focus();
  900. }
  901. private void groupBox_CalculatingSymbols_Click(object sender, EventArgs e)
  902. {
  903. groupBox_CalculatingSymbols.Focus();
  904. }
  905. private void groupBox_XmlTree_MaxEDSRules_Click(object sender, EventArgs e)
  906. {
  907. groupBox_XmlTree_MaxEDSRules.Focus();
  908. }
  909. #endregion
  910. private void button_1_Click(object sender, EventArgs e)
  911. {
  912. //textbox_STDEditor 中的光标
  913. int index = textbox_STDEditor.SelectionStart;
  914. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "1");
  915. textbox_STDEditor.Focus();
  916. textbox_STDEditor.Select(index + 1, 0);
  917. textbox_STDEditor.ScrollToCaret();
  918. }
  919. private void button_2_Click(object sender, EventArgs e)
  920. {
  921. //textbox_STDEditor 中的光标
  922. int index = textbox_STDEditor.SelectionStart;
  923. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "2");
  924. textbox_STDEditor.Focus();
  925. textbox_STDEditor.Select(index + 1, 0);
  926. textbox_STDEditor.ScrollToCaret();
  927. }
  928. private void button_3_Click(object sender, EventArgs e)
  929. {
  930. //textbox_STDEditor 中的光标
  931. int index = textbox_STDEditor.SelectionStart;
  932. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "3");
  933. textbox_STDEditor.Focus();
  934. textbox_STDEditor.Select(index + 1, 0);
  935. textbox_STDEditor.ScrollToCaret();
  936. }
  937. private void button_4_Click(object sender, EventArgs e)
  938. {
  939. //textbox_STDEditor 中的光标
  940. int index = textbox_STDEditor.SelectionStart;
  941. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "4");
  942. textbox_STDEditor.Focus();
  943. textbox_STDEditor.Select(index + 1, 0);
  944. textbox_STDEditor.ScrollToCaret();
  945. }
  946. private void button_5_Click(object sender, EventArgs e)
  947. {
  948. //textbox_STDEditor 中的光标
  949. int index = textbox_STDEditor.SelectionStart;
  950. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "5");
  951. textbox_STDEditor.Focus();
  952. textbox_STDEditor.Select(index + 1, 0);
  953. textbox_STDEditor.ScrollToCaret();
  954. }
  955. private void button_6_Click(object sender, EventArgs e)
  956. {
  957. //textbox_STDEditor 中的光标
  958. int index = textbox_STDEditor.SelectionStart;
  959. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "6");
  960. textbox_STDEditor.Focus();
  961. textbox_STDEditor.Select(index + 1, 0);
  962. textbox_STDEditor.ScrollToCaret();
  963. }
  964. private void button_7_Click(object sender, EventArgs e)
  965. {
  966. //textbox_STDEditor 中的光标
  967. int index = textbox_STDEditor.SelectionStart;
  968. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "7");
  969. textbox_STDEditor.Focus();
  970. textbox_STDEditor.Select(index + 1, 0);
  971. textbox_STDEditor.ScrollToCaret();
  972. }
  973. private void button_8_Click(object sender, EventArgs e)
  974. {
  975. //textbox_STDEditor 中的光标
  976. int index = textbox_STDEditor.SelectionStart;
  977. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "8");
  978. textbox_STDEditor.Focus();
  979. textbox_STDEditor.Select(index + 1, 0);
  980. textbox_STDEditor.ScrollToCaret();
  981. }
  982. private void button_9_Click(object sender, EventArgs e)
  983. {
  984. //textbox_STDEditor 中的光标
  985. int index = textbox_STDEditor.SelectionStart;
  986. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "9");
  987. textbox_STDEditor.Focus();
  988. textbox_STDEditor.Select(index + 1, 0);
  989. textbox_STDEditor.ScrollToCaret();
  990. }
  991. private void button_0_Click(object sender, EventArgs e)
  992. {
  993. int index = textbox_STDEditor.SelectionStart;
  994. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "0");
  995. textbox_STDEditor.Focus();
  996. textbox_STDEditor.Select(index + 1, 0);
  997. textbox_STDEditor.ScrollToCaret();
  998. }
  999. //private float X = 1;
  1000. //private float Y = 1;
  1001. //float AmplificationFactor = 1;
  1002. private void Form_MaxEDSRules_Resize(object sender, EventArgs e)
  1003. {
  1004. //float newx = this.Width / X;
  1005. //float newy = this.Height / Y;
  1006. //AmplificationFactor = newy;
  1007. //setControls(newx, newy, this);
  1008. //this.Resize -= new System.EventHandler(this.Form_MaxEDSRules_Resize);
  1009. //if (panel_OTSPeriodicTable.Visible == false)
  1010. //{
  1011. // int w = this.Width - panel_OTSPeriodicTable.Width;
  1012. // this.Width = w;
  1013. //}
  1014. //this.Resize += new System.EventHandler(this.Form_MaxEDSRules_Resize);
  1015. ////if (WindowState == FormWindowState.Maximized)
  1016. ////{
  1017. //// panel_OTSPeriodicTable.Visible = true;
  1018. //// PeriodicTableSwitch.Enabled = false;
  1019. ////}
  1020. }
  1021. private void setTag(Control cons)
  1022. {
  1023. foreach (Control con in cons.Controls)
  1024. {
  1025. con.Tag = con.Width + ":" + con.Height + ":" + con.Left + ":" + con.Top + ":" + con.Font.Size;
  1026. if (con.Controls.Count > 0)
  1027. setTag(con);
  1028. }
  1029. }
  1030. private void setControls(float newx, float newy, Control cons)
  1031. {
  1032. foreach (Control con in cons.Controls)
  1033. {
  1034. if (false)
  1035. {
  1036. }
  1037. else
  1038. {
  1039. string[] mytag = con.Tag.ToString().Split(':');
  1040. float a = Convert.ToSingle(mytag[0]) * newx;
  1041. con.Width = (int)a;
  1042. a = Convert.ToSingle(mytag[1]) * newy;
  1043. con.Height = (int)(a);
  1044. a = Convert.ToSingle(mytag[2]) * newx;
  1045. con.Left = (int)(a);
  1046. a = Convert.ToSingle(mytag[3]) * newy;
  1047. con.Top = (int)(a);
  1048. Single currentSize;
  1049. if (con.GetType().ToString() == "System.Windows.Forms.Label")
  1050. {
  1051. currentSize = Convert.ToSingle(mytag[4]) * ((newx + newy) / 2);
  1052. //currentSize = 6f;
  1053. }
  1054. else
  1055. {
  1056. if (Math.Max(newx, newy) < 1)
  1057. {
  1058. currentSize = Convert.ToSingle(mytag[4]) * 1;
  1059. }
  1060. else
  1061. {
  1062. currentSize = Convert.ToSingle(mytag[4]) * Math.Max(newx, newy);
  1063. }
  1064. }
  1065. con.Font = new Font(con.Font.Name, currentSize, con.Font.Style, con.Font.Unit);
  1066. if (con.Controls.Count > 0)
  1067. {
  1068. setControls(newx, newy, con);
  1069. }
  1070. }
  1071. }
  1072. }
  1073. #region
  1074. //XmlDocument doc = new XmlDocument();
  1075. //doc.Load(Address);
  1076. //LoadXmlToTreeControl(doc,XmlTree_MaxEDSRules.Nodes);
  1077. //public string Language = "English";
  1078. //string Address_backup = Application.StartupPath + "\\Config\\SysData\\OTSParticleSTD_backup.xml";
  1079. //string Address = Application.StartupPath + "\\Config\\SysData\\OTSParticleSTD.xml";
  1080. //保存xmltree内容到xml文件
  1081. //void SaveXmlTreeDataToXml(string Address)
  1082. //{
  1083. // XDocument xdoc = XDocument.Load(Address);
  1084. // IEnumerable<XElement> elements = from ele in xdoc.Descendants("XMLData") select ele;
  1085. // var item = (from ele1 in elements.Elements("Collection")
  1086. // where ele1.Attribute("RegName").Value.Equals("MaxEDSRules")
  1087. // select ele1).FirstOrDefault();
  1088. // if (item != null)
  1089. // {
  1090. // item.Remove();
  1091. // }
  1092. // XElement MaxEDS = new XElement("Collection");
  1093. // MaxEDS.SetAttributeValue("RegName", "MaxEDSRules");
  1094. // elements.ElementAt(0).Add(MaxEDS);
  1095. // for (int num = 0; num < XmlTree_MaxEDSRules.Nodes.Count; num++)
  1096. // {
  1097. // string UsingElementList = "";
  1098. // string UsingImgPropertyList = "";
  1099. // string UsingOtherPropertyList = "";
  1100. // List<string> UsingElementL = new List<string>();
  1101. // List<string> UsingImgPropertyL = new List<string>();
  1102. // List<string> UsingOtherPropertyL = new List<string>();
  1103. // string str_RemoveBlank = "";
  1104. // //forth_elem干扰or分隔符,故先行去掉
  1105. // if (XmlTree_MaxEDSRules.Nodes[num].Tag.ToString().Contains("forth_elem"))
  1106. // {
  1107. // str_RemoveBlank = str_RemoveBlank.Replace("forth_elem", "");
  1108. // UsingOtherPropertyList = "forth_elem,";
  1109. // }
  1110. // str_RemoveBlank = XmlTree_MaxEDSRules.Nodes[num].Tag.ToString().Replace(" ", "");
  1111. // string[] str_Removeand = System.Text.RegularExpressions.Regex.Split(str_RemoveBlank, "and", System.Text.RegularExpressions.RegexOptions.None);
  1112. // List<string> str_Removeandor = new List<string>();
  1113. // for (int i = 0; i < str_Removeand.Length; i++)
  1114. // {
  1115. // str_Removeandor.AddRange(System.Text.RegularExpressions.Regex.Split(str_Removeand[i], "or", System.Text.RegularExpressions.RegexOptions.None));
  1116. // }
  1117. // List<string> list_all = new List<string>();
  1118. // for (int i = 0; i < str_Removeandor.Count; i++)
  1119. // {
  1120. // list_all.AddRange(str_Removeandor[i].Split(new char[] { '+', '-', '*', '/', '=', '>', '<', '(', ')' }));
  1121. // }
  1122. // for (int i = 0; i < list_all.Count; i++)
  1123. // {
  1124. // //周期元素?
  1125. // if (this.comboBox_PeriodicTable.Items.Contains(list_all[i]))
  1126. // {
  1127. // if (!UsingElementL.Contains(list_all[i]))
  1128. // {
  1129. // UsingElementL.Add(list_all[i]);
  1130. // }
  1131. // }
  1132. // //first_elem?
  1133. // if (this.comboBox_Elem1.Items.Contains(list_all[i]))
  1134. // {
  1135. // if (!UsingOtherPropertyL.Contains(list_all[i]))
  1136. // {
  1137. // UsingOtherPropertyL.Add(list_all[i]);
  1138. // }
  1139. // }
  1140. // //Element1?
  1141. // if (this.comboBox_Elem.Items.Contains(list_all[i]))
  1142. // {
  1143. // if (!UsingOtherPropertyL.Contains(list_all[i]))
  1144. // {
  1145. // UsingOtherPropertyL.Add(list_all[i]);
  1146. // }
  1147. // }
  1148. // //其它元素?
  1149. // if (this.comboBox_ImgProperty.Items.Contains(list_all[i]))
  1150. // {
  1151. // if (!UsingImgPropertyL.Contains(list_all[i]))
  1152. // {
  1153. // UsingImgPropertyL.Add(list_all[i]);
  1154. // }
  1155. // }
  1156. // }
  1157. // if (UsingElementL.Count > 0)
  1158. // {
  1159. // for (int i = 0; i < UsingElementL.Count - 1; i++)
  1160. // {
  1161. // UsingElementList += UsingElementL[i] + ",";
  1162. // }
  1163. // UsingElementList += UsingElementL[UsingElementL.Count - 1];
  1164. // }
  1165. // if (UsingImgPropertyL.Count > 0)
  1166. // {
  1167. // for (int i = 0; i < UsingImgPropertyL.Count - 1; i++)
  1168. // {
  1169. // UsingImgPropertyList += UsingImgPropertyL[i] + ",";
  1170. // }
  1171. // UsingImgPropertyList += UsingImgPropertyL[UsingImgPropertyL.Count - 1];
  1172. // }
  1173. // if (UsingOtherPropertyL.Count > 0)
  1174. // {
  1175. // for (int i = 0; i < UsingOtherPropertyL.Count - 1; i++)
  1176. // {
  1177. // UsingOtherPropertyList += UsingOtherPropertyL[i] + ",";
  1178. // }
  1179. // UsingOtherPropertyList += UsingOtherPropertyL[UsingOtherPropertyL.Count - 1];
  1180. // }
  1181. // XElement EleName = new XElement("Member");
  1182. // //EleName.SetAttributeValue("MaxEDSTime", XmlTree_MaxEDSRules.Nodes[num].Name);
  1183. // EleName.SetAttributeValue("MaxEDSTime", textBox_MaxEDSTime.Text);
  1184. // EleName.SetAttributeValue("UsingElementList", UsingElementList);
  1185. // EleName.SetAttributeValue("UsingImgPropertyList", UsingImgPropertyList);
  1186. // EleName.SetAttributeValue("UsingOtherPropertyList", UsingOtherPropertyList);
  1187. // EleName.SetAttributeValue("Expression", XmlTree_MaxEDSRules.Nodes[num].Tag);
  1188. // MaxEDS.Add(EleName);
  1189. // }
  1190. // xdoc.Save(Address);
  1191. //}
  1192. //private void button_Backup_Click(object sender, EventArgs e)
  1193. //{
  1194. // if (XmlTree_MaxEDSRules.SelectedNode != null)
  1195. // {
  1196. // //判断MaxEDSTime
  1197. // double dMaxEDSTime = 0;
  1198. // if (!double.TryParse(textBox_MaxEDSTime.Text, out dMaxEDSTime) || double.Parse(textBox_MaxEDSTime.Text) <= 0)
  1199. // {
  1200. // textBox_MaxEDSTime.Focus();
  1201. // textBox_MaxEDSTime.SelectAll();
  1202. // MessageBox.Show(table["message16"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  1203. // return;
  1204. // }
  1205. // //判断textbox_STDEditor
  1206. // if (!Checktextbox_STDEditor())
  1207. // {
  1208. // return;
  1209. // }
  1210. // XmlTree_MaxEDSRules.SelectedNode.Tag = this.textbox_STDEditor.Text;
  1211. // //XmlTree_MaxEDSRules.SelectedNode.Name = textBox_MaxEDSTime.Text;
  1212. // }
  1213. // try
  1214. // {
  1215. // SaveFileDialog saveFile = new SaveFileDialog();
  1216. // saveFile.Title = table["message23"].ToString();
  1217. // saveFile.Filter = table["message24"].ToString();
  1218. // saveFile.OverwritePrompt = true; //是否覆盖当前文件
  1219. // saveFile.RestoreDirectory = true; //还原上次目录
  1220. // if (saveFile.ShowDialog() == DialogResult.OK)
  1221. // {
  1222. // System.IO.File.Copy(Address, saveFile.FileName, true);
  1223. // SaveXmlTreeDataToXml(saveFile.FileName);
  1224. // MessageBox.Show(table["message25"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  1225. // }
  1226. // else
  1227. // {
  1228. // return;
  1229. // }
  1230. // }
  1231. // catch (Exception ex)
  1232. // {
  1233. // MessageBox.Show(ex.Message);
  1234. // }
  1235. //}
  1236. #endregion
  1237. private void Form_MaxEDSRules_FormClosing(object sender, FormClosingEventArgs e)
  1238. {
  1239. if (form_PeriodicTable != null)
  1240. {
  1241. form_PeriodicTable.Close();
  1242. }
  1243. }
  1244. }
  1245. }