Form_MaxEDSRules.cs 58 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401
  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 = dt.Rows[0][0].ToString();
  192. ConstantsStr = ConstantsStr.Replace(" ", "");
  193. string[] ConstantsStr2 = ConstantsStr.Split(',');
  194. comboBox_Constants.Items.Clear();
  195. comboBox_Constants.Items.AddRange(ConstantsStr2);
  196. m_dbConnection.Close();
  197. }
  198. catch (Exception ee)
  199. {
  200. MessageBox.Show(ee.ToString());
  201. }
  202. }
  203. private void comboBox_Elem1_SelectedIndexChanged(object sender, EventArgs e)
  204. {
  205. string newStr = comboBox_Elem1.SelectedItem.ToString();
  206. int index = textbox_STDEditor.SelectionStart;
  207. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, newStr);
  208. textbox_STDEditor.Focus();
  209. textbox_STDEditor.Select(index + newStr.Length, 0);
  210. textbox_STDEditor.ScrollToCaret();
  211. }
  212. private void comboBox_Elem2_SelectedIndexChanged(object sender, EventArgs e)
  213. {
  214. string newStr = comboBox_Elem.SelectedItem.ToString();
  215. int index = textbox_STDEditor.SelectionStart;
  216. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, newStr);
  217. textbox_STDEditor.Focus();
  218. textbox_STDEditor.Select(index + newStr.Length, 0);
  219. textbox_STDEditor.ScrollToCaret();
  220. }
  221. private void comboBox_ImgProperty_SelectedIndexChanged(object sender, EventArgs e)
  222. {
  223. string newStr = comboBox_ImgProperty.SelectedItem.ToString();
  224. int index = textbox_STDEditor.SelectionStart;
  225. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, newStr);
  226. textbox_STDEditor.Focus();
  227. textbox_STDEditor.Select(index + newStr.Length, 0);
  228. textbox_STDEditor.ScrollToCaret();
  229. }
  230. private void button_Plus_Click(object sender, EventArgs e)
  231. {
  232. int index = textbox_STDEditor.SelectionStart;
  233. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "+");
  234. textbox_STDEditor.Focus();
  235. textbox_STDEditor.Select(index+1,0);
  236. textbox_STDEditor.ScrollToCaret();
  237. }
  238. private void button_Subtract_Click(object sender, EventArgs e)
  239. {
  240. int index = textbox_STDEditor.SelectionStart;
  241. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "-");
  242. textbox_STDEditor.Focus();
  243. textbox_STDEditor.Select(index + 1, 0);
  244. textbox_STDEditor.ScrollToCaret();
  245. }
  246. private void button_Multiply_Click(object sender, EventArgs e)
  247. {
  248. int index = textbox_STDEditor.SelectionStart;
  249. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "*");
  250. textbox_STDEditor.Focus();
  251. textbox_STDEditor.Select(index + 1, 0);
  252. textbox_STDEditor.ScrollToCaret();
  253. }
  254. private void button_Divide_Click(object sender, EventArgs e)
  255. {
  256. int index = textbox_STDEditor.SelectionStart;
  257. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "/");
  258. textbox_STDEditor.Focus();
  259. textbox_STDEditor.Select(index + 1, 0);
  260. textbox_STDEditor.ScrollToCaret(); ;
  261. }
  262. private void button_More_Click(object sender, EventArgs e)
  263. {
  264. int index = textbox_STDEditor.SelectionStart;
  265. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, ">");
  266. textbox_STDEditor.Focus();
  267. textbox_STDEditor.Select(index + 1, 0);
  268. textbox_STDEditor.ScrollToCaret();
  269. }
  270. private void button_Less_Click(object sender, EventArgs e)
  271. {
  272. int index = textbox_STDEditor.SelectionStart;
  273. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "<");
  274. textbox_STDEditor.Focus();
  275. textbox_STDEditor.Select(index + 1, 0);
  276. textbox_STDEditor.ScrollToCaret();
  277. }
  278. private void button_LeftParenthesis_Click(object sender, EventArgs e)
  279. {
  280. int index = textbox_STDEditor.SelectionStart;
  281. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "(");
  282. textbox_STDEditor.Focus();
  283. textbox_STDEditor.Select(index + 1, 0);
  284. textbox_STDEditor.ScrollToCaret();
  285. }
  286. private void button_RightParenthesis_Click(object sender, EventArgs e)
  287. {
  288. int index = textbox_STDEditor.SelectionStart;
  289. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, ")");
  290. textbox_STDEditor.Focus();
  291. textbox_STDEditor.Select(index + 1, 0);
  292. textbox_STDEditor.ScrollToCaret();
  293. }
  294. private void button_Equal_Click(object sender, EventArgs e)
  295. {
  296. int index = textbox_STDEditor.SelectionStart;
  297. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "=");
  298. textbox_STDEditor.Focus();
  299. textbox_STDEditor.Select(index + 1, 0);
  300. textbox_STDEditor.ScrollToCaret();
  301. }
  302. //除选中点以外其它节点前景色置灰
  303. private void SetGrayExceptSelectedNode(TreeView Tree, TreeNode SelectedNode)
  304. {
  305. foreach (TreeNode node in Tree.Nodes)
  306. {
  307. if (node != SelectedNode)
  308. {
  309. node.ForeColor = Color.Gray;
  310. }
  311. }
  312. }
  313. //恢复所有节点颜色为可用
  314. private void SetBlackAllNodes(TreeView Tree)
  315. {
  316. foreach (TreeNode node in Tree.Nodes)
  317. {
  318. node.ForeColor = Color.Black;
  319. }
  320. }
  321. //删除
  322. private void DeleteTreeNode_Click(object sender, EventArgs e)
  323. {
  324. try
  325. {
  326. TreeView XmlTree = (TreeView)XmlTreeMenuStrip.SourceControl;
  327. if (XmlTree.SelectedNode != null)
  328. {
  329. if (XmlTree != null)
  330. {
  331. if (XmlTree.SelectedNode.NextNode != null)
  332. {
  333. TreeNode Temp = XmlTree.SelectedNode.NextNode;
  334. XmlTree.SelectedNode.Remove();
  335. XmlTree.SelectedNode = Temp;
  336. }
  337. else if (XmlTree.SelectedNode.PrevNode != null)
  338. {
  339. TreeNode Temp = XmlTree.SelectedNode.PrevNode;
  340. XmlTree.SelectedNode.Remove();
  341. XmlTree.SelectedNode = Temp;
  342. }
  343. else
  344. {
  345. XmlTree.SelectedNode.Remove();
  346. XmlTree.SelectedNode = null;
  347. if (XmlTree.Name == "XmlTree_MaxEDSRules")
  348. {
  349. textbox_STDEditor.Text = "";
  350. textBox_MaxEDSTime.Text = "";
  351. }
  352. }
  353. }
  354. }
  355. else
  356. {
  357. MessageBox.Show(table["message1"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  358. }
  359. }
  360. catch (Exception ex)
  361. {
  362. MessageBox.Show(ex.ToString(), table["message32"].ToString());
  363. }
  364. }
  365. //新建
  366. private void AddTreeNode_Click(object sender, EventArgs e)
  367. {
  368. try
  369. {
  370. if (XmlTree_MaxEDSRules.SelectedNode != null)
  371. {
  372. //判断MaxEDSTime
  373. double dMaxEDSTime = 0;
  374. if (!double.TryParse(textBox_MaxEDSTime.Text, out dMaxEDSTime) || double.Parse(textBox_MaxEDSTime.Text) <= 0)
  375. {
  376. MessageBox.Show(table["message8"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  377. return;
  378. }
  379. //判断textbox_STDEditor
  380. if (!Checktextbox_STDEditor())
  381. {
  382. return;
  383. }
  384. XmlTree_MaxEDSRules.SelectedNode.Tag = this.textbox_STDEditor.Text;
  385. }
  386. TreeNode new_child = new TreeNode();//定义一个TreeNode节点对象
  387. TreeView XmlTree = (TreeView)XmlTreeMenuStrip.SourceControl;
  388. if (XmlTreeMenuStrip.SourceControl.Name == "XmlTree_MaxEDSRules")
  389. {
  390. int Number = XmlTree.Nodes.Count;
  391. for (int num = 0; num < XmlTree.Nodes.Count; num++)
  392. {
  393. string aa = XmlTree.Nodes[num].Text.ToString().Substring(XmlTree.Nodes[num].Text.Length - 1, 1);
  394. int tp = int.Parse(XmlTree.Nodes[num].Text.ToString().Substring(XmlTree.Nodes[num].Text.Length - 1, 1));
  395. if (Number < tp) Number = tp;
  396. }
  397. new_child.Text = "Rule" + Number.ToString();
  398. new_child.Tag = "NewRules";
  399. textbox_STDEditor.Text = "NewRules";
  400. }
  401. XmlTree.Nodes.Add(new_child);
  402. XmlTree.SelectedNode = null;
  403. XmlTree.SelectedNode = new_child;
  404. }
  405. catch (Exception ex)
  406. {
  407. MessageBox.Show(ex.ToString(), table["message32"].ToString());
  408. }
  409. }
  410. void SaveXmlTreeDataToMaxEDSRules(string DBAddress)
  411. {
  412. System.Data.SQLite.SQLiteConnection m_dbConnection = new System.Data.SQLite.SQLiteConnection("data source='" + DBAddress + "'");
  413. m_dbConnection.Open();
  414. System.Data.SQLite.SQLiteCommand cmm = m_dbConnection.CreateCommand();
  415. cmm.CommandText = "delete from MaxEDSRules";
  416. try
  417. {
  418. cmm.ExecuteNonQuery();
  419. }
  420. catch (Exception ex)
  421. {
  422. MessageBox.Show(ex.ToString());
  423. }
  424. System.Data.SQLite.SQLiteDataAdapter m_dataAdapter = new System.Data.SQLite.SQLiteDataAdapter("select * from MaxEDSRules", m_dbConnection);
  425. System.Data.SQLite.SQLiteCommandBuilder qLiteCommandBuilder = new System.Data.SQLite.SQLiteCommandBuilder(m_dataAdapter);
  426. DataSet ds = new DataSet();
  427. m_dataAdapter.Fill(ds, "MaxEDSRules");
  428. DataTable dt = ds.Tables["MaxEDSRules"];
  429. dt.Clear();
  430. for (int num = 0; num < XmlTree_MaxEDSRules.Nodes.Count; num++)
  431. {
  432. string UsingElementList = "";
  433. string UsingImgPropertyList = "";
  434. string UsingOtherPropertyList = "";
  435. List<string> UsingElementL = new List<string>();
  436. List<string> UsingImgPropertyL = new List<string>();
  437. List<string> UsingOtherPropertyL = new List<string>();
  438. string str_RemoveBlank = "";
  439. //forth_elem干扰or分隔符,故先行去掉
  440. if (XmlTree_MaxEDSRules.Nodes[num].Tag.ToString().Contains("forth_elem"))
  441. {
  442. str_RemoveBlank = str_RemoveBlank.Replace("forth_elem", "");
  443. UsingOtherPropertyList = "forth_elem,";
  444. }
  445. str_RemoveBlank = XmlTree_MaxEDSRules.Nodes[num].Tag.ToString().Replace(" ", "");
  446. string[] str_Removeand = System.Text.RegularExpressions.Regex.Split(str_RemoveBlank, "and", System.Text.RegularExpressions.RegexOptions.None);
  447. List<string> str_Removeandor = new List<string>();
  448. for (int i = 0; i < str_Removeand.Length; i++)
  449. {
  450. str_Removeandor.AddRange(System.Text.RegularExpressions.Regex.Split(str_Removeand[i], "or", System.Text.RegularExpressions.RegexOptions.None));
  451. }
  452. List<string> list_all = new List<string>();
  453. for (int i = 0; i < str_Removeandor.Count; i++)
  454. {
  455. list_all.AddRange(str_Removeandor[i].Split(new char[] { '+', '-', '*', '/', '=', '>', '<', '(', ')' }));
  456. }
  457. for (int i = 0; i < list_all.Count; i++)
  458. {
  459. //周期元素?
  460. if (this.comboBox_PeriodicTable.Items.Contains(list_all[i]))
  461. {
  462. if (!UsingElementL.Contains(list_all[i]))
  463. {
  464. UsingElementL.Add(list_all[i]);
  465. }
  466. }
  467. //first_elem?
  468. if (this.comboBox_Elem1.Items.Contains(list_all[i]))
  469. {
  470. if (!UsingOtherPropertyL.Contains(list_all[i]))
  471. {
  472. UsingOtherPropertyL.Add(list_all[i]);
  473. }
  474. }
  475. //Element1?
  476. if (this.comboBox_Elem.Items.Contains(list_all[i]))
  477. {
  478. if (!UsingOtherPropertyL.Contains(list_all[i]))
  479. {
  480. UsingOtherPropertyL.Add(list_all[i]);
  481. }
  482. }
  483. //其它元素?
  484. if (this.comboBox_ImgProperty.Items.Contains(list_all[i]))
  485. {
  486. if (!UsingImgPropertyL.Contains(list_all[i]))
  487. {
  488. UsingImgPropertyL.Add(list_all[i]);
  489. }
  490. }
  491. }
  492. if (UsingElementL.Count > 0)
  493. {
  494. for (int i = 0; i < UsingElementL.Count - 1; i++)
  495. {
  496. UsingElementList += UsingElementL[i] + ",";
  497. }
  498. UsingElementList += UsingElementL[UsingElementL.Count - 1];
  499. }
  500. if (UsingImgPropertyL.Count > 0)
  501. {
  502. for (int i = 0; i < UsingImgPropertyL.Count - 1; i++)
  503. {
  504. UsingImgPropertyList += UsingImgPropertyL[i] + ",";
  505. }
  506. UsingImgPropertyList += UsingImgPropertyL[UsingImgPropertyL.Count - 1];
  507. }
  508. if (UsingOtherPropertyL.Count > 0)
  509. {
  510. for (int i = 0; i < UsingOtherPropertyL.Count - 1; i++)
  511. {
  512. UsingOtherPropertyList += UsingOtherPropertyL[i] + ",";
  513. }
  514. UsingOtherPropertyList += UsingOtherPropertyL[UsingOtherPropertyL.Count - 1];
  515. }
  516. DataRow newRow = dt.NewRow();
  517. newRow["MaxEDSTime"] = int.Parse(textBox_MaxEDSTime.Text);
  518. newRow["UsingElementList"] = UsingElementList;
  519. newRow["UsingImgPropertyList"] = UsingImgPropertyList;
  520. newRow["UsingOtherPropertyList"] = UsingOtherPropertyList;
  521. newRow["Expression"] = XmlTree_MaxEDSRules.Nodes[num].Tag;
  522. dt.Rows.Add(newRow);
  523. }
  524. m_dataAdapter.Update(ds, "MaxEDSRules");
  525. m_dbConnection.Close();
  526. MessageBox.Show(table["message2"].ToString(), table["message32"].ToString());
  527. }
  528. //元素周期表开关
  529. private void PeriodicTableSwitch_Click(object sender, EventArgs e)
  530. {
  531. //if (PeriodicTableSwitch.BackColor == SystemColors.Control)
  532. //{
  533. // //this.Resize -= new System.EventHandler(this.Form_MaxEDSRules_Resize);
  534. // panel_OTSPeriodicTable.Visible = false;
  535. // this.Width = this.Width - panel_OTSPeriodicTable.Width;
  536. // //this.Resize += new System.EventHandler(this.Form_MaxEDSRules_Resize);
  537. // PeriodicTableSwitch.BackColor = SystemColors.ControlDark;
  538. // //if (Language == "English")
  539. // //{
  540. // // PeriodicTableSwitch.Text = "Close PeriodicTable";
  541. // //}
  542. // //else if(Language == "Chinese")
  543. // //{
  544. // // PeriodicTableSwitch.Text = "关闭元素周期表";
  545. // //}
  546. //}
  547. //else if (PeriodicTableSwitch.BackColor == SystemColors.ControlDark)
  548. //{
  549. // //this.Resize -= new System.EventHandler(this.Form_MaxEDSRules_Resize);
  550. // //this.Width = this.Width + panel_OTSPeriodicTable.Width + 5;
  551. // panel_OTSPeriodicTable.Visible = true;
  552. // //this.Resize += new System.EventHandler(this.Form_MaxEDSRules_Resize);
  553. // PeriodicTableSwitch.BackColor = SystemColors.Control;
  554. // //if (Language == "English")
  555. // //{
  556. // // PeriodicTableSwitch.Text = "Open PeriodicTable";
  557. // //}
  558. // //else if (Language == "Chinese")
  559. // //{
  560. // // PeriodicTableSwitch.Text = "打开元素周期表";
  561. // //}
  562. // //textbox_STDEditor.Focus();
  563. // groupBox_CalculatingSymbols.Focus();
  564. //}
  565. if (form_PeriodicTable == null)
  566. {
  567. form_PeriodicTable = new Form_PeriodicTable();
  568. form_PeriodicTable.Show();
  569. form_PeriodicTable.Location = new Point(this.Location.X + this.Width - 14, this.Location.Y);
  570. }
  571. else
  572. {
  573. if (form_PeriodicTable.IsDisposed)
  574. {
  575. form_PeriodicTable = new Form_PeriodicTable();
  576. form_PeriodicTable.Show();
  577. form_PeriodicTable.Location = new Point(this.Location.X + this.Width - 14, this.Location.Y);
  578. }
  579. else
  580. {
  581. form_PeriodicTable.Activate();
  582. }
  583. }
  584. }
  585. private void button_Ok_Click(object sender, EventArgs e)
  586. {
  587. if (XmlTree_MaxEDSRules.SelectedNode != null)
  588. {
  589. //判断MaxEDSTime
  590. double dMaxEDSTime = 0;
  591. if (!double.TryParse(textBox_MaxEDSTime.Text, out dMaxEDSTime) || double.Parse(textBox_MaxEDSTime.Text) <= 0)
  592. {
  593. textBox_MaxEDSTime.Focus();
  594. textBox_MaxEDSTime.SelectAll();
  595. MessageBox.Show(table["message16"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  596. return;
  597. }
  598. //判断textbox_STDEditor
  599. if (!Checktextbox_STDEditor())
  600. {
  601. return;
  602. }
  603. XmlTree_MaxEDSRules.SelectedNode.Tag = this.textbox_STDEditor.Text;
  604. //XmlTree_MaxEDSRules.SelectedNode.Name = textBox_MaxEDSTime.Text;
  605. }
  606. SaveXmlTreeDataToMaxEDSRules(STDDBAddress);
  607. this.Close();
  608. }
  609. private void button_Cancel_Click(object sender, EventArgs e)
  610. {
  611. this.Close();
  612. }
  613. //元素下拉选择输入
  614. private void comboBox_PeriodicTable_SelectedIndexChanged(object sender, EventArgs e)
  615. {
  616. if (comboBox_PeriodicTable.Text != null && comboBox_PeriodicTable.SelectedItem != null)
  617. {
  618. string newStr = comboBox_PeriodicTable.SelectedItem.ToString();
  619. comboBox_PeriodicTable.Text = null;
  620. int index = textbox_STDEditor.SelectionStart;
  621. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, newStr);
  622. textbox_STDEditor.Focus();
  623. textbox_STDEditor.Select(index + newStr.Length, 0);
  624. textbox_STDEditor.ScrollToCaret();
  625. }
  626. }
  627. //元素自身text按回车键输入
  628. private void comboBox_PeriodicTable_KeyDown(object sender, KeyEventArgs e)
  629. {
  630. if (e.KeyValue == 13)
  631. {
  632. if (comboBox_PeriodicTable.Text != null && comboBox_PeriodicTable.Text != "")
  633. {
  634. this.textbox_STDEditor.Text += comboBox_PeriodicTable.Text.ToString();
  635. comboBox_PeriodicTable.Text = null;
  636. }
  637. }
  638. }
  639. //表达式规则检查
  640. private bool Checktextbox_STDEditor()
  641. {
  642. if (textbox_STDEditor.Text == "" || textbox_STDEditor.Text == null)
  643. {
  644. textBox_MaxEDSTime.Focus();
  645. MessageBox.Show(table["message17"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  646. return false;
  647. }
  648. string str_RemoveBlank = textbox_STDEditor.Text.ToString().Replace(" ", "");
  649. str_RemoveBlank = str_RemoveBlank.Replace("\r\n", "");
  650. //分割符号检验
  651. string[] Symbol = { "and", "or", "+", "-", "*", "/", "=", ">", "<" };
  652. for (int i = 0; i < Symbol.Length; i++)
  653. {
  654. for (int j = 0; j < Symbol.Length; j++)
  655. {
  656. if ((Symbol[i] + Symbol[j]) != ">=" && (Symbol[i] + Symbol[j]) != "<=")
  657. {
  658. if (str_RemoveBlank.Contains(Symbol[i] + Symbol[j]))
  659. {
  660. MessageBox.Show(table["message18"].ToString() + Symbol[i] + Symbol[j], table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  661. return false;
  662. }
  663. }
  664. }
  665. if (str_RemoveBlank.Contains(Symbol[i] + ")") || str_RemoveBlank.Contains("(" + Symbol[i]))
  666. {
  667. MessageBox.Show(table["message18"].ToString() + Symbol[i] + ")", table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  668. return false;
  669. }
  670. if (str_RemoveBlank.Contains("(" + Symbol[i]))
  671. {
  672. MessageBox.Show(table["message18"].ToString() + "(" + Symbol[i], table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  673. return false;
  674. }
  675. }
  676. if ((str_RemoveBlank != null) && (str_RemoveBlank != ""))
  677. {
  678. //左右括号匹配检验
  679. int BracketsNum = 0;
  680. for (int i = 0; i < str_RemoveBlank.Length; i++)
  681. {
  682. if (str_RemoveBlank[i] == '(') BracketsNum++;
  683. if (str_RemoveBlank[i] == ')') BracketsNum--;
  684. }
  685. if (BracketsNum != 0)
  686. {
  687. MessageBox.Show(table["message19"].ToString(),table["message32"].ToString(),MessageBoxButtons.OK,MessageBoxIcon.Information);
  688. return false;
  689. }
  690. //首字符检测
  691. 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] == '('))
  692. {
  693. MessageBox.Show(table["message20"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  694. return false;
  695. }
  696. if (str_RemoveBlank.Length >= 3)
  697. {
  698. if ((str_RemoveBlank.Substring(0, 3) == "and") || (str_RemoveBlank.Substring(0, 3) == "end"))
  699. {
  700. MessageBox.Show(table["message20"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  701. return false;
  702. }
  703. }
  704. }
  705. //forth_elem干扰or分隔符,故先行去掉
  706. str_RemoveBlank = str_RemoveBlank.Replace("forth_elem", "");
  707. string[] str_Removeand = System.Text.RegularExpressions.Regex.Split(str_RemoveBlank, "and", System.Text.RegularExpressions.RegexOptions.None);
  708. List<string> str_Removeandor = new List<string>();
  709. for (int i = 0; i < str_Removeand.Length; i++)
  710. {
  711. str_Removeandor.AddRange(System.Text.RegularExpressions.Regex.Split(str_Removeand[i], "or", System.Text.RegularExpressions.RegexOptions.None));
  712. }
  713. List<string> list_all = new List<string>();
  714. for (int i = 0; i < str_Removeandor.Count; i++)
  715. {
  716. list_all.AddRange(str_Removeandor[i].Split(new char[] { '+', '-', '*', '/', '=', '>', '<', '(', ')' }));
  717. }
  718. //常量
  719. List<string> Constantslist = new List<string>();
  720. for (int j = 0; j < comboBox_Constants.Items.Count; j++)
  721. {
  722. Constantslist.Add(comboBox_Constants.Items[j].ToString().Split('=')[0]);
  723. }
  724. for (int i = 0; i < list_all.Count; i++)
  725. {
  726. //周期元素?
  727. if (this.comboBox_PeriodicTable.Items.Contains(list_all[i]))
  728. {
  729. continue;
  730. }
  731. //first_elem?
  732. if (this.comboBox_Elem1.Items.Contains(list_all[i]))
  733. {
  734. continue;
  735. }
  736. //Element1?
  737. if (this.comboBox_Elem.Items.Contains(list_all[i]))
  738. {
  739. continue;
  740. }
  741. //其它元素?
  742. if (this.comboBox_ImgProperty.Items.Contains(list_all[i]))
  743. {
  744. continue;
  745. }
  746. //常量?
  747. if (Constantslist.Contains(list_all[i]))
  748. {
  749. continue;
  750. }
  751. //数字?
  752. double DNum = 0;
  753. if (double.TryParse(list_all[i], out DNum))
  754. {
  755. continue;
  756. }
  757. //>=? <=?等其它情况
  758. if (list_all[i] == "")
  759. {
  760. continue;
  761. }
  762. //true false?
  763. if ((list_all[i] == "true") || (list_all[i] == "false"))
  764. {
  765. continue;
  766. }
  767. MessageBox.Show(table["message21"].ToString() + list_all[i], table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  768. return false;
  769. }
  770. //检测是否有<>= true,false
  771. 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")
  772. {
  773. MessageBox.Show(table["message22"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  774. return false;
  775. }
  776. return true;
  777. }
  778. private void button_And_Click(object sender, EventArgs e)
  779. {
  780. //textbox_STDEditor 中的光标
  781. int index = textbox_STDEditor.SelectionStart;
  782. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "and");
  783. textbox_STDEditor.Focus();
  784. textbox_STDEditor.Select(index + 3, 0);
  785. textbox_STDEditor.ScrollToCaret();
  786. }
  787. private void button_Or_Click(object sender, EventArgs e)
  788. {
  789. //textbox_STDEditor 中的光标
  790. int index = textbox_STDEditor.SelectionStart;
  791. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "or");
  792. textbox_STDEditor.Focus();
  793. textbox_STDEditor.Select(index + 2, 0);
  794. textbox_STDEditor.ScrollToCaret();
  795. }
  796. private void comboBox_Constants_SelectedIndexChanged(object sender, EventArgs e)
  797. {
  798. if (comboBox_Constants.SelectedItem != null)
  799. {
  800. string newStr = comboBox_Constants.SelectedItem.ToString().Split('=')[0];
  801. int index = textbox_STDEditor.SelectionStart;
  802. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, newStr);
  803. textbox_STDEditor.Focus();
  804. textbox_STDEditor.Select(index + newStr.Length, 0);
  805. textbox_STDEditor.ScrollToCaret();
  806. }
  807. }
  808. private void button_Recover_Click(object sender, EventArgs e)
  809. {
  810. XmlDocument doc = new XmlDocument();
  811. try
  812. {
  813. //System.IO.File.Copy(Address_backup, Address, true);
  814. //doc.Load(Address_backup);
  815. //LoadXmlToTreeControl(doc, XmlTree_MaxEDSRules.Nodes);
  816. XmlTree_MaxEDSRules.Nodes.Clear();
  817. string STDDBAddress_backup = "";
  818. string[] files = System.IO.Directory.GetFiles(STDDBAddress_backupDirectory);//得到文件
  819. foreach (var file in files)
  820. {
  821. if (".db".IndexOf(file.Substring(file.LastIndexOf(".") + 1)) > -1)
  822. {
  823. STDDBAddress_backup = file;
  824. }
  825. }
  826. LoadMaxEDSRulesToTreeControl(STDDBAddress_backup, XmlTree_MaxEDSRules.Nodes);
  827. XmlTree_MaxEDSRules.Focus();
  828. if (XmlTree_MaxEDSRules.Nodes.Count > 0)
  829. {
  830. XmlTree_MaxEDSRules.SelectedNode = XmlTree_MaxEDSRules.Nodes[0];
  831. XmlTree_MaxEDSRules_AfterSelect(XmlTree_MaxEDSRules, new TreeViewEventArgs(XmlTree_MaxEDSRules.SelectedNode));
  832. }
  833. else
  834. {
  835. textbox_STDEditor.Text = "";
  836. textBox_MaxEDSTime.Text = "";
  837. }
  838. }
  839. catch(Exception ex)
  840. {
  841. MessageBox.Show(table["message26"].ToString() + "\n"+ex.Message.ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  842. }
  843. }
  844. private bool CheckConstants(string ConstantName)
  845. {
  846. for (int num = 0; num < XmlTree_MaxEDSRules.Nodes.Count; num++)
  847. {
  848. if (XmlTree_MaxEDSRules.Nodes[num].Tag.ToString().Contains(ConstantName))
  849. {
  850. XmlTree_MaxEDSRules.SelectedNode = XmlTree_MaxEDSRules.Nodes[num];
  851. SetGrayExceptSelectedNode(XmlTree_MaxEDSRules, XmlTree_MaxEDSRules.SelectedNode);
  852. DialogResult result = MessageBox.Show(table["message27"].ToString() + XmlTree_MaxEDSRules.Nodes[num].Text + table["message28"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Warning);
  853. return false;
  854. }
  855. }
  856. return true;
  857. }
  858. private void XmlTree_MaxEDSRules_AfterSelect(object sender, TreeViewEventArgs e)
  859. {
  860. SetBlackAllNodes(XmlTree_MaxEDSRules);
  861. this.textbox_STDEditor.Text = XmlTree_MaxEDSRules.SelectedNode.Tag.ToString();
  862. }
  863. private void XmlTree_MaxEDSRules_BeforeSelect(object sender, TreeViewCancelEventArgs e)
  864. {
  865. if (XmlTree_MaxEDSRules.SelectedNode != null)
  866. {
  867. if (!Checktextbox_STDEditor())
  868. {
  869. SetGrayExceptSelectedNode(XmlTree_MaxEDSRules, XmlTree_MaxEDSRules.SelectedNode);
  870. e.Cancel = true;
  871. return;
  872. }
  873. XmlTree_MaxEDSRules.SelectedNode.Tag = this.textbox_STDEditor.Text;
  874. }
  875. }
  876. private void textbox_STDEditor_Leave(object sender, EventArgs e)
  877. {
  878. XmlTree_MaxEDSRules.Focus();
  879. }
  880. #region 为配合textbox_STDEditor_Leave时事件,点击其它groupbox组件时使焦点转移
  881. private void Form_ConstantsEditor_Click(object sender, EventArgs e)
  882. {
  883. groupBox_XmlTree_MaxEDSRules.Focus();
  884. }
  885. private void groupBox_Data_Click(object sender, EventArgs e)
  886. {
  887. groupBox_Data.Focus();
  888. }
  889. private void groupBox_ChemicalElement_Click(object sender, EventArgs e)
  890. {
  891. groupBox_ChemicalElement.Focus();
  892. }
  893. private void groupBox_OtherCommonlyUsedSymbols_Click(object sender, EventArgs e)
  894. {
  895. groupBox_OtherCommonlyUsedSymbols.Focus();
  896. }
  897. private void groupBox_CalculatingSymbols_Click(object sender, EventArgs e)
  898. {
  899. groupBox_CalculatingSymbols.Focus();
  900. }
  901. private void groupBox_XmlTree_MaxEDSRules_Click(object sender, EventArgs e)
  902. {
  903. groupBox_XmlTree_MaxEDSRules.Focus();
  904. }
  905. #endregion
  906. private void button_1_Click(object sender, EventArgs e)
  907. {
  908. //textbox_STDEditor 中的光标
  909. int index = textbox_STDEditor.SelectionStart;
  910. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "1");
  911. textbox_STDEditor.Focus();
  912. textbox_STDEditor.Select(index + 1, 0);
  913. textbox_STDEditor.ScrollToCaret();
  914. }
  915. private void button_2_Click(object sender, EventArgs e)
  916. {
  917. //textbox_STDEditor 中的光标
  918. int index = textbox_STDEditor.SelectionStart;
  919. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "2");
  920. textbox_STDEditor.Focus();
  921. textbox_STDEditor.Select(index + 1, 0);
  922. textbox_STDEditor.ScrollToCaret();
  923. }
  924. private void button_3_Click(object sender, EventArgs e)
  925. {
  926. //textbox_STDEditor 中的光标
  927. int index = textbox_STDEditor.SelectionStart;
  928. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "3");
  929. textbox_STDEditor.Focus();
  930. textbox_STDEditor.Select(index + 1, 0);
  931. textbox_STDEditor.ScrollToCaret();
  932. }
  933. private void button_4_Click(object sender, EventArgs e)
  934. {
  935. //textbox_STDEditor 中的光标
  936. int index = textbox_STDEditor.SelectionStart;
  937. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "4");
  938. textbox_STDEditor.Focus();
  939. textbox_STDEditor.Select(index + 1, 0);
  940. textbox_STDEditor.ScrollToCaret();
  941. }
  942. private void button_5_Click(object sender, EventArgs e)
  943. {
  944. //textbox_STDEditor 中的光标
  945. int index = textbox_STDEditor.SelectionStart;
  946. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "5");
  947. textbox_STDEditor.Focus();
  948. textbox_STDEditor.Select(index + 1, 0);
  949. textbox_STDEditor.ScrollToCaret();
  950. }
  951. private void button_6_Click(object sender, EventArgs e)
  952. {
  953. //textbox_STDEditor 中的光标
  954. int index = textbox_STDEditor.SelectionStart;
  955. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "6");
  956. textbox_STDEditor.Focus();
  957. textbox_STDEditor.Select(index + 1, 0);
  958. textbox_STDEditor.ScrollToCaret();
  959. }
  960. private void button_7_Click(object sender, EventArgs e)
  961. {
  962. //textbox_STDEditor 中的光标
  963. int index = textbox_STDEditor.SelectionStart;
  964. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "7");
  965. textbox_STDEditor.Focus();
  966. textbox_STDEditor.Select(index + 1, 0);
  967. textbox_STDEditor.ScrollToCaret();
  968. }
  969. private void button_8_Click(object sender, EventArgs e)
  970. {
  971. //textbox_STDEditor 中的光标
  972. int index = textbox_STDEditor.SelectionStart;
  973. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "8");
  974. textbox_STDEditor.Focus();
  975. textbox_STDEditor.Select(index + 1, 0);
  976. textbox_STDEditor.ScrollToCaret();
  977. }
  978. private void button_9_Click(object sender, EventArgs e)
  979. {
  980. //textbox_STDEditor 中的光标
  981. int index = textbox_STDEditor.SelectionStart;
  982. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "9");
  983. textbox_STDEditor.Focus();
  984. textbox_STDEditor.Select(index + 1, 0);
  985. textbox_STDEditor.ScrollToCaret();
  986. }
  987. private void button_0_Click(object sender, EventArgs e)
  988. {
  989. int index = textbox_STDEditor.SelectionStart;
  990. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "0");
  991. textbox_STDEditor.Focus();
  992. textbox_STDEditor.Select(index + 1, 0);
  993. textbox_STDEditor.ScrollToCaret();
  994. }
  995. private float X = 1;
  996. private float Y = 1;
  997. float AmplificationFactor = 1;
  998. private void Form_MaxEDSRules_Resize(object sender, EventArgs e)
  999. {
  1000. //float newx = this.Width / X;
  1001. //float newy = this.Height / Y;
  1002. //AmplificationFactor = newy;
  1003. //setControls(newx, newy, this);
  1004. //this.Resize -= new System.EventHandler(this.Form_MaxEDSRules_Resize);
  1005. //if (panel_OTSPeriodicTable.Visible == false)
  1006. //{
  1007. // int w = this.Width - panel_OTSPeriodicTable.Width;
  1008. // this.Width = w;
  1009. //}
  1010. //this.Resize += new System.EventHandler(this.Form_MaxEDSRules_Resize);
  1011. ////if (WindowState == FormWindowState.Maximized)
  1012. ////{
  1013. //// panel_OTSPeriodicTable.Visible = true;
  1014. //// PeriodicTableSwitch.Enabled = false;
  1015. ////}
  1016. }
  1017. private void setTag(Control cons)
  1018. {
  1019. foreach (Control con in cons.Controls)
  1020. {
  1021. con.Tag = con.Width + ":" + con.Height + ":" + con.Left + ":" + con.Top + ":" + con.Font.Size;
  1022. if (con.Controls.Count > 0)
  1023. setTag(con);
  1024. }
  1025. }
  1026. private void setControls(float newx, float newy, Control cons)
  1027. {
  1028. foreach (Control con in cons.Controls)
  1029. {
  1030. if (false)
  1031. {
  1032. }
  1033. else
  1034. {
  1035. string[] mytag = con.Tag.ToString().Split(':');
  1036. float a = Convert.ToSingle(mytag[0]) * newx;
  1037. con.Width = (int)a;
  1038. a = Convert.ToSingle(mytag[1]) * newy;
  1039. con.Height = (int)(a);
  1040. a = Convert.ToSingle(mytag[2]) * newx;
  1041. con.Left = (int)(a);
  1042. a = Convert.ToSingle(mytag[3]) * newy;
  1043. con.Top = (int)(a);
  1044. Single currentSize;
  1045. if (con.GetType().ToString() == "System.Windows.Forms.Label")
  1046. {
  1047. currentSize = Convert.ToSingle(mytag[4]) * ((newx + newy) / 2);
  1048. //currentSize = 6f;
  1049. }
  1050. else
  1051. {
  1052. if (Math.Max(newx, newy) < 1)
  1053. {
  1054. currentSize = Convert.ToSingle(mytag[4]) * 1;
  1055. }
  1056. else
  1057. {
  1058. currentSize = Convert.ToSingle(mytag[4]) * Math.Max(newx, newy);
  1059. }
  1060. }
  1061. con.Font = new Font(con.Font.Name, currentSize, con.Font.Style, con.Font.Unit);
  1062. if (con.Controls.Count > 0)
  1063. {
  1064. setControls(newx, newy, con);
  1065. }
  1066. }
  1067. }
  1068. }
  1069. #region
  1070. //XmlDocument doc = new XmlDocument();
  1071. //doc.Load(Address);
  1072. //LoadXmlToTreeControl(doc,XmlTree_MaxEDSRules.Nodes);
  1073. //public string Language = "English";
  1074. //string Address_backup = Application.StartupPath + "\\Config\\SysData\\OTSParticleSTD_backup.xml";
  1075. //string Address = Application.StartupPath + "\\Config\\SysData\\OTSParticleSTD.xml";
  1076. //保存xmltree内容到xml文件
  1077. //void SaveXmlTreeDataToXml(string Address)
  1078. //{
  1079. // XDocument xdoc = XDocument.Load(Address);
  1080. // IEnumerable<XElement> elements = from ele in xdoc.Descendants("XMLData") select ele;
  1081. // var item = (from ele1 in elements.Elements("Collection")
  1082. // where ele1.Attribute("RegName").Value.Equals("MaxEDSRules")
  1083. // select ele1).FirstOrDefault();
  1084. // if (item != null)
  1085. // {
  1086. // item.Remove();
  1087. // }
  1088. // XElement MaxEDS = new XElement("Collection");
  1089. // MaxEDS.SetAttributeValue("RegName", "MaxEDSRules");
  1090. // elements.ElementAt(0).Add(MaxEDS);
  1091. // for (int num = 0; num < XmlTree_MaxEDSRules.Nodes.Count; num++)
  1092. // {
  1093. // string UsingElementList = "";
  1094. // string UsingImgPropertyList = "";
  1095. // string UsingOtherPropertyList = "";
  1096. // List<string> UsingElementL = new List<string>();
  1097. // List<string> UsingImgPropertyL = new List<string>();
  1098. // List<string> UsingOtherPropertyL = new List<string>();
  1099. // string str_RemoveBlank = "";
  1100. // //forth_elem干扰or分隔符,故先行去掉
  1101. // if (XmlTree_MaxEDSRules.Nodes[num].Tag.ToString().Contains("forth_elem"))
  1102. // {
  1103. // str_RemoveBlank = str_RemoveBlank.Replace("forth_elem", "");
  1104. // UsingOtherPropertyList = "forth_elem,";
  1105. // }
  1106. // str_RemoveBlank = XmlTree_MaxEDSRules.Nodes[num].Tag.ToString().Replace(" ", "");
  1107. // string[] str_Removeand = System.Text.RegularExpressions.Regex.Split(str_RemoveBlank, "and", System.Text.RegularExpressions.RegexOptions.None);
  1108. // List<string> str_Removeandor = new List<string>();
  1109. // for (int i = 0; i < str_Removeand.Length; i++)
  1110. // {
  1111. // str_Removeandor.AddRange(System.Text.RegularExpressions.Regex.Split(str_Removeand[i], "or", System.Text.RegularExpressions.RegexOptions.None));
  1112. // }
  1113. // List<string> list_all = new List<string>();
  1114. // for (int i = 0; i < str_Removeandor.Count; i++)
  1115. // {
  1116. // list_all.AddRange(str_Removeandor[i].Split(new char[] { '+', '-', '*', '/', '=', '>', '<', '(', ')' }));
  1117. // }
  1118. // for (int i = 0; i < list_all.Count; i++)
  1119. // {
  1120. // //周期元素?
  1121. // if (this.comboBox_PeriodicTable.Items.Contains(list_all[i]))
  1122. // {
  1123. // if (!UsingElementL.Contains(list_all[i]))
  1124. // {
  1125. // UsingElementL.Add(list_all[i]);
  1126. // }
  1127. // }
  1128. // //first_elem?
  1129. // if (this.comboBox_Elem1.Items.Contains(list_all[i]))
  1130. // {
  1131. // if (!UsingOtherPropertyL.Contains(list_all[i]))
  1132. // {
  1133. // UsingOtherPropertyL.Add(list_all[i]);
  1134. // }
  1135. // }
  1136. // //Element1?
  1137. // if (this.comboBox_Elem.Items.Contains(list_all[i]))
  1138. // {
  1139. // if (!UsingOtherPropertyL.Contains(list_all[i]))
  1140. // {
  1141. // UsingOtherPropertyL.Add(list_all[i]);
  1142. // }
  1143. // }
  1144. // //其它元素?
  1145. // if (this.comboBox_ImgProperty.Items.Contains(list_all[i]))
  1146. // {
  1147. // if (!UsingImgPropertyL.Contains(list_all[i]))
  1148. // {
  1149. // UsingImgPropertyL.Add(list_all[i]);
  1150. // }
  1151. // }
  1152. // }
  1153. // if (UsingElementL.Count > 0)
  1154. // {
  1155. // for (int i = 0; i < UsingElementL.Count - 1; i++)
  1156. // {
  1157. // UsingElementList += UsingElementL[i] + ",";
  1158. // }
  1159. // UsingElementList += UsingElementL[UsingElementL.Count - 1];
  1160. // }
  1161. // if (UsingImgPropertyL.Count > 0)
  1162. // {
  1163. // for (int i = 0; i < UsingImgPropertyL.Count - 1; i++)
  1164. // {
  1165. // UsingImgPropertyList += UsingImgPropertyL[i] + ",";
  1166. // }
  1167. // UsingImgPropertyList += UsingImgPropertyL[UsingImgPropertyL.Count - 1];
  1168. // }
  1169. // if (UsingOtherPropertyL.Count > 0)
  1170. // {
  1171. // for (int i = 0; i < UsingOtherPropertyL.Count - 1; i++)
  1172. // {
  1173. // UsingOtherPropertyList += UsingOtherPropertyL[i] + ",";
  1174. // }
  1175. // UsingOtherPropertyList += UsingOtherPropertyL[UsingOtherPropertyL.Count - 1];
  1176. // }
  1177. // XElement EleName = new XElement("Member");
  1178. // //EleName.SetAttributeValue("MaxEDSTime", XmlTree_MaxEDSRules.Nodes[num].Name);
  1179. // EleName.SetAttributeValue("MaxEDSTime", textBox_MaxEDSTime.Text);
  1180. // EleName.SetAttributeValue("UsingElementList", UsingElementList);
  1181. // EleName.SetAttributeValue("UsingImgPropertyList", UsingImgPropertyList);
  1182. // EleName.SetAttributeValue("UsingOtherPropertyList", UsingOtherPropertyList);
  1183. // EleName.SetAttributeValue("Expression", XmlTree_MaxEDSRules.Nodes[num].Tag);
  1184. // MaxEDS.Add(EleName);
  1185. // }
  1186. // xdoc.Save(Address);
  1187. //}
  1188. //private void button_Backup_Click(object sender, EventArgs e)
  1189. //{
  1190. // if (XmlTree_MaxEDSRules.SelectedNode != null)
  1191. // {
  1192. // //判断MaxEDSTime
  1193. // double dMaxEDSTime = 0;
  1194. // if (!double.TryParse(textBox_MaxEDSTime.Text, out dMaxEDSTime) || double.Parse(textBox_MaxEDSTime.Text) <= 0)
  1195. // {
  1196. // textBox_MaxEDSTime.Focus();
  1197. // textBox_MaxEDSTime.SelectAll();
  1198. // MessageBox.Show(table["message16"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  1199. // return;
  1200. // }
  1201. // //判断textbox_STDEditor
  1202. // if (!Checktextbox_STDEditor())
  1203. // {
  1204. // return;
  1205. // }
  1206. // XmlTree_MaxEDSRules.SelectedNode.Tag = this.textbox_STDEditor.Text;
  1207. // //XmlTree_MaxEDSRules.SelectedNode.Name = textBox_MaxEDSTime.Text;
  1208. // }
  1209. // try
  1210. // {
  1211. // SaveFileDialog saveFile = new SaveFileDialog();
  1212. // saveFile.Title = table["message23"].ToString();
  1213. // saveFile.Filter = table["message24"].ToString();
  1214. // saveFile.OverwritePrompt = true; //是否覆盖当前文件
  1215. // saveFile.RestoreDirectory = true; //还原上次目录
  1216. // if (saveFile.ShowDialog() == DialogResult.OK)
  1217. // {
  1218. // System.IO.File.Copy(Address, saveFile.FileName, true);
  1219. // SaveXmlTreeDataToXml(saveFile.FileName);
  1220. // MessageBox.Show(table["message25"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  1221. // }
  1222. // else
  1223. // {
  1224. // return;
  1225. // }
  1226. // }
  1227. // catch (Exception ex)
  1228. // {
  1229. // MessageBox.Show(ex.Message);
  1230. // }
  1231. //}
  1232. #endregion
  1233. private void Form_MaxEDSRules_FormClosing(object sender, FormClosingEventArgs e)
  1234. {
  1235. if (form_PeriodicTable != null)
  1236. {
  1237. form_PeriodicTable.Close();
  1238. }
  1239. }
  1240. }
  1241. }