Form_MaxEDSRules.cs 58 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406
  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("fourth_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 = "false";
  403. textbox_STDEditor.Text = "false";
  404. textBox_MaxEDSTime.Text = "200";
  405. }
  406. XmlTree.Nodes.Add(new_child);
  407. XmlTree.SelectedNode = null;
  408. XmlTree.SelectedNode = new_child;
  409. }
  410. catch (Exception ex)
  411. {
  412. MessageBox.Show(ex.ToString(), "Tip");
  413. }
  414. }
  415. void SaveXmlTreeDataToMaxEDSRules(string DBAddress)
  416. {
  417. System.Data.SQLite.SQLiteConnection m_dbConnection = new System.Data.SQLite.SQLiteConnection("data source='" + DBAddress + "'");
  418. m_dbConnection.Open();
  419. System.Data.SQLite.SQLiteCommand cmm = m_dbConnection.CreateCommand();
  420. cmm.CommandText = "delete from MaxEDSRules";
  421. try
  422. {
  423. cmm.ExecuteNonQuery();
  424. }
  425. catch (Exception ex)
  426. {
  427. MessageBox.Show(ex.ToString());
  428. }
  429. System.Data.SQLite.SQLiteDataAdapter m_dataAdapter = new System.Data.SQLite.SQLiteDataAdapter("select * from MaxEDSRules", m_dbConnection);
  430. System.Data.SQLite.SQLiteCommandBuilder qLiteCommandBuilder = new System.Data.SQLite.SQLiteCommandBuilder(m_dataAdapter);
  431. DataSet ds = new DataSet();
  432. m_dataAdapter.Fill(ds, "MaxEDSRules");
  433. DataTable dt = ds.Tables["MaxEDSRules"];
  434. dt.Clear();
  435. for (int num = 0; num < XmlTree_MaxEDSRules.Nodes.Count; num++)
  436. {
  437. string UsingElementList = "";
  438. string UsingImgPropertyList = "";
  439. string UsingOtherPropertyList = "";
  440. List<string> UsingElementL = new List<string>();
  441. List<string> UsingImgPropertyL = new List<string>();
  442. List<string> UsingOtherPropertyL = new List<string>();
  443. string str_RemoveBlank = "";
  444. //forth_elem干扰or分隔符,故先行去掉
  445. //if (XmlTree_MaxEDSRules.Nodes[num].Tag.ToString().Contains("fourth_elem"))
  446. //{
  447. // str_RemoveBlank = str_RemoveBlank.Replace("fourth_elem", "");
  448. // UsingOtherPropertyList = "fourth_elem,";
  449. //}
  450. str_RemoveBlank = XmlTree_MaxEDSRules.Nodes[num].Tag.ToString().Replace(" ", "");
  451. string[] str_Removeand = System.Text.RegularExpressions.Regex.Split(str_RemoveBlank, "and", System.Text.RegularExpressions.RegexOptions.None);
  452. List<string> str_Removeandor = new List<string>();
  453. for (int i = 0; i < str_Removeand.Length; i++)
  454. {
  455. str_Removeandor.AddRange(System.Text.RegularExpressions.Regex.Split(str_Removeand[i], "or", System.Text.RegularExpressions.RegexOptions.None));
  456. }
  457. List<string> list_all = new List<string>();
  458. for (int i = 0; i < str_Removeandor.Count; i++)
  459. {
  460. list_all.AddRange(str_Removeandor[i].Split(new char[] { '+', '-', '*', '/', '=', '>', '<', '(', ')' }));
  461. }
  462. for (int i = 0; i < list_all.Count; i++)
  463. {
  464. //周期元素?
  465. if (this.comboBox_PeriodicTable.Items.Contains(list_all[i]))
  466. {
  467. if (!UsingElementL.Contains(list_all[i]))
  468. {
  469. UsingElementL.Add(list_all[i]);
  470. }
  471. }
  472. //first_elem?
  473. if (this.comboBox_Elem1.Items.Contains(list_all[i]))
  474. {
  475. if (!UsingOtherPropertyL.Contains(list_all[i]))
  476. {
  477. UsingOtherPropertyL.Add(list_all[i]);
  478. }
  479. }
  480. //Element1?
  481. if (this.comboBox_Elem.Items.Contains(list_all[i]))
  482. {
  483. if (!UsingOtherPropertyL.Contains(list_all[i]))
  484. {
  485. UsingOtherPropertyL.Add(list_all[i]);
  486. }
  487. }
  488. //其它元素?
  489. if (this.comboBox_ImgProperty.Items.Contains(list_all[i]))
  490. {
  491. if (!UsingImgPropertyL.Contains(list_all[i]))
  492. {
  493. UsingImgPropertyL.Add(list_all[i]);
  494. }
  495. }
  496. }
  497. if (UsingElementL.Count > 0)
  498. {
  499. for (int i = 0; i < UsingElementL.Count - 1; i++)
  500. {
  501. UsingElementList += UsingElementL[i] + ",";
  502. }
  503. UsingElementList += UsingElementL[UsingElementL.Count - 1];
  504. }
  505. if (UsingImgPropertyL.Count > 0)
  506. {
  507. for (int i = 0; i < UsingImgPropertyL.Count - 1; i++)
  508. {
  509. UsingImgPropertyList += UsingImgPropertyL[i] + ",";
  510. }
  511. UsingImgPropertyList += UsingImgPropertyL[UsingImgPropertyL.Count - 1];
  512. }
  513. if (UsingOtherPropertyL.Count > 0)
  514. {
  515. for (int i = 0; i < UsingOtherPropertyL.Count - 1; i++)
  516. {
  517. UsingOtherPropertyList += UsingOtherPropertyL[i] + ",";
  518. }
  519. UsingOtherPropertyList += UsingOtherPropertyL[UsingOtherPropertyL.Count - 1];
  520. }
  521. DataRow newRow = dt.NewRow();
  522. newRow["MaxEDSTime"] = int.Parse(textBox_MaxEDSTime.Text);
  523. newRow["UsingElementList"] = UsingElementList;
  524. newRow["UsingImgPropertyList"] = UsingImgPropertyList;
  525. newRow["UsingOtherPropertyList"] = UsingOtherPropertyList;
  526. newRow["Expression"] = XmlTree_MaxEDSRules.Nodes[num].Tag;
  527. dt.Rows.Add(newRow);
  528. }
  529. m_dataAdapter.Update(ds, "MaxEDSRules");
  530. m_dbConnection.Close();
  531. MessageBox.Show("Save successful!", "Tip");
  532. }
  533. //元素周期表开关
  534. private void PeriodicTableSwitch_Click(object sender, EventArgs e)
  535. {
  536. //if (PeriodicTableSwitch.BackColor == SystemColors.Control)
  537. //{
  538. // //this.Resize -= new System.EventHandler(this.Form_MaxEDSRules_Resize);
  539. // panel_OTSPeriodicTable.Visible = false;
  540. // this.Width = this.Width - panel_OTSPeriodicTable.Width;
  541. // //this.Resize += new System.EventHandler(this.Form_MaxEDSRules_Resize);
  542. // PeriodicTableSwitch.BackColor = SystemColors.ControlDark;
  543. // //if (Language == "English")
  544. // //{
  545. // // PeriodicTableSwitch.Text = "Close PeriodicTable";
  546. // //}
  547. // //else if(Language == "Chinese")
  548. // //{
  549. // // PeriodicTableSwitch.Text = "关闭元素周期表";
  550. // //}
  551. //}
  552. //else if (PeriodicTableSwitch.BackColor == SystemColors.ControlDark)
  553. //{
  554. // //this.Resize -= new System.EventHandler(this.Form_MaxEDSRules_Resize);
  555. // //this.Width = this.Width + panel_OTSPeriodicTable.Width + 5;
  556. // panel_OTSPeriodicTable.Visible = true;
  557. // //this.Resize += new System.EventHandler(this.Form_MaxEDSRules_Resize);
  558. // PeriodicTableSwitch.BackColor = SystemColors.Control;
  559. // //if (Language == "English")
  560. // //{
  561. // // PeriodicTableSwitch.Text = "Open PeriodicTable";
  562. // //}
  563. // //else if (Language == "Chinese")
  564. // //{
  565. // // PeriodicTableSwitch.Text = "打开元素周期表";
  566. // //}
  567. // //textbox_STDEditor.Focus();
  568. // groupBox_CalculatingSymbols.Focus();
  569. //}
  570. if (form_PeriodicTable == null)
  571. {
  572. form_PeriodicTable = new Form_PeriodicTable();
  573. form_PeriodicTable.Show();
  574. form_PeriodicTable.Location = new Point(this.Location.X + this.Width - 14, this.Location.Y);
  575. }
  576. else
  577. {
  578. if (form_PeriodicTable.IsDisposed)
  579. {
  580. form_PeriodicTable = new Form_PeriodicTable();
  581. form_PeriodicTable.Show();
  582. form_PeriodicTable.Location = new Point(this.Location.X + this.Width - 14, this.Location.Y);
  583. }
  584. else
  585. {
  586. form_PeriodicTable.Activate();
  587. }
  588. }
  589. }
  590. private void button_Ok_Click(object sender, EventArgs e)
  591. {
  592. if (XmlTree_MaxEDSRules.SelectedNode != null)
  593. {
  594. //判断MaxEDSTime
  595. double dMaxEDSTime = 0;
  596. if (!double.TryParse(textBox_MaxEDSTime.Text, out dMaxEDSTime) || double.Parse(textBox_MaxEDSTime.Text) <= 0)
  597. {
  598. textBox_MaxEDSTime.Focus();
  599. textBox_MaxEDSTime.SelectAll();
  600. MessageBox.Show("The Item of MaxEDSTime input error, please enter the correct format!", "Tip", MessageBoxButtons.OK, MessageBoxIcon.Information);
  601. return;
  602. }
  603. //判断textbox_STDEditor
  604. if (!Checktextbox_STDEditor())
  605. {
  606. return;
  607. }
  608. XmlTree_MaxEDSRules.SelectedNode.Tag = this.textbox_STDEditor.Text;
  609. //XmlTree_MaxEDSRules.SelectedNode.Name = textBox_MaxEDSTime.Text;
  610. }
  611. SaveXmlTreeDataToMaxEDSRules(STDDBAddress);
  612. this.Close();
  613. }
  614. private void button_Cancel_Click(object sender, EventArgs e)
  615. {
  616. this.Close();
  617. }
  618. //元素下拉选择输入
  619. private void comboBox_PeriodicTable_SelectedIndexChanged(object sender, EventArgs e)
  620. {
  621. if (comboBox_PeriodicTable.Text != null && comboBox_PeriodicTable.SelectedItem != null)
  622. {
  623. string newStr = comboBox_PeriodicTable.SelectedItem.ToString();
  624. comboBox_PeriodicTable.Text = null;
  625. int index = textbox_STDEditor.SelectionStart;
  626. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, newStr);
  627. textbox_STDEditor.Focus();
  628. textbox_STDEditor.Select(index + newStr.Length, 0);
  629. textbox_STDEditor.ScrollToCaret();
  630. }
  631. }
  632. //元素自身text按回车键输入
  633. private void comboBox_PeriodicTable_KeyDown(object sender, KeyEventArgs e)
  634. {
  635. if (e.KeyValue == 13)
  636. {
  637. if (comboBox_PeriodicTable.Text != null && comboBox_PeriodicTable.Text != "")
  638. {
  639. this.textbox_STDEditor.Text += comboBox_PeriodicTable.Text.ToString();
  640. comboBox_PeriodicTable.Text = null;
  641. }
  642. }
  643. }
  644. //表达式规则检查
  645. private bool Checktextbox_STDEditor()
  646. {
  647. if (textbox_STDEditor.Text == "" || textbox_STDEditor.Text == null)
  648. {
  649. textBox_MaxEDSTime.Focus();
  650. MessageBox.Show("The content of Standard library cannot be empty!", "Tip", MessageBoxButtons.OK, MessageBoxIcon.Information);
  651. return false;
  652. }
  653. string str_RemoveBlank = textbox_STDEditor.Text.ToString().Replace(" ", "");
  654. str_RemoveBlank = str_RemoveBlank.Replace("\r\n", "");
  655. //分割符号检验
  656. string[] Symbol = { "and", "or", "+", "-", "*", "/", "=", ">", "<" };
  657. for (int i = 0; i < Symbol.Length; i++)
  658. {
  659. for (int j = 0; j < Symbol.Length; j++)
  660. {
  661. if ((Symbol[i] + Symbol[j]) != ">=" && (Symbol[i] + Symbol[j]) != "<=")
  662. {
  663. if (str_RemoveBlank.Contains(Symbol[i] + Symbol[j]))
  664. {
  665. MessageBox.Show("Invalid string exists:" + Symbol[i] + Symbol[j], "Tip", MessageBoxButtons.OK, MessageBoxIcon.Information);
  666. return false;
  667. }
  668. }
  669. }
  670. if (str_RemoveBlank.Contains(Symbol[i] + ")") || str_RemoveBlank.Contains("(" + Symbol[i]))
  671. {
  672. MessageBox.Show("Invalid string exists:" + Symbol[i] + ")", "Tip", MessageBoxButtons.OK, MessageBoxIcon.Information);
  673. return false;
  674. }
  675. if (str_RemoveBlank.Contains("(" + Symbol[i]))
  676. {
  677. MessageBox.Show("Invalid string exists:" + "(" + Symbol[i], "Tip", MessageBoxButtons.OK, MessageBoxIcon.Information);
  678. return false;
  679. }
  680. }
  681. if ((str_RemoveBlank != null) && (str_RemoveBlank != ""))
  682. {
  683. //左右括号匹配检验
  684. int BracketsNum = 0;
  685. for (int i = 0; i < str_RemoveBlank.Length; i++)
  686. {
  687. if (str_RemoveBlank[i] == '(') BracketsNum++;
  688. if (str_RemoveBlank[i] == ')') BracketsNum--;
  689. }
  690. if (BracketsNum != 0)
  691. {
  692. MessageBox.Show("Number of left and right parentheses does not match!", "Tip", MessageBoxButtons.OK,MessageBoxIcon.Information);
  693. return false;
  694. }
  695. //首字符检测
  696. 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] == '('))
  697. {
  698. MessageBox.Show("First character is error!", "Tip", MessageBoxButtons.OK, MessageBoxIcon.Information);
  699. return false;
  700. }
  701. if (str_RemoveBlank.Length >= 3)
  702. {
  703. if ((str_RemoveBlank.Substring(0, 3) == "and") || (str_RemoveBlank.Substring(0, 3) == "end"))
  704. {
  705. MessageBox.Show("First character is error!", "Tip", MessageBoxButtons.OK, MessageBoxIcon.Information);
  706. return false;
  707. }
  708. }
  709. }
  710. //forth_elem干扰or分隔符,故先行去掉
  711. //str_RemoveBlank = str_RemoveBlank.Replace("fourth_elem", "");
  712. string[] str_Removeand = System.Text.RegularExpressions.Regex.Split(str_RemoveBlank, "and", System.Text.RegularExpressions.RegexOptions.None);
  713. List<string> str_Removeandor = new List<string>();
  714. for (int i = 0; i < str_Removeand.Length; i++)
  715. {
  716. str_Removeandor.AddRange(System.Text.RegularExpressions.Regex.Split(str_Removeand[i], "or", System.Text.RegularExpressions.RegexOptions.None));
  717. }
  718. List<string> list_all = new List<string>();
  719. for (int i = 0; i < str_Removeandor.Count; i++)
  720. {
  721. list_all.AddRange(str_Removeandor[i].Split(new char[] { '+', '-', '*', '/', '=', '>', '<', '(', ')' }));
  722. }
  723. //常量
  724. List<string> Constantslist = new List<string>();
  725. for (int j = 0; j < comboBox_Constants.Items.Count; j++)
  726. {
  727. Constantslist.Add(comboBox_Constants.Items[j].ToString().Split('=')[0]);
  728. }
  729. for (int i = 0; i < list_all.Count; i++)
  730. {
  731. //周期元素?
  732. if (this.comboBox_PeriodicTable.Items.Contains(list_all[i]))
  733. {
  734. continue;
  735. }
  736. //first_elem?
  737. if (this.comboBox_Elem1.Items.Contains(list_all[i]))
  738. {
  739. continue;
  740. }
  741. //Element1?
  742. if (this.comboBox_Elem.Items.Contains(list_all[i]))
  743. {
  744. continue;
  745. }
  746. //其它元素?
  747. if (this.comboBox_ImgProperty.Items.Contains(list_all[i]))
  748. {
  749. continue;
  750. }
  751. //常量?
  752. if (Constantslist.Contains(list_all[i]))
  753. {
  754. continue;
  755. }
  756. //数字?
  757. double DNum = 0;
  758. if (double.TryParse(list_all[i], out DNum))
  759. {
  760. continue;
  761. }
  762. //>=? <=?等其它情况
  763. if (list_all[i] == "")
  764. {
  765. continue;
  766. }
  767. //true false?
  768. if ((list_all[i] == "true") || (list_all[i] == "false"))
  769. {
  770. continue;
  771. }
  772. MessageBox.Show("Please check whether the input rules are correct, error characters:" + list_all[i], "Tip", MessageBoxButtons.OK, MessageBoxIcon.Information);
  773. return false;
  774. }
  775. //检测是否有<>= true,false
  776. 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")
  777. {
  778. MessageBox.Show("Expressions have no effect!", "Tip", MessageBoxButtons.OK, MessageBoxIcon.Information);
  779. return false;
  780. }
  781. return true;
  782. }
  783. private void button_And_Click(object sender, EventArgs e)
  784. {
  785. //textbox_STDEditor 中的光标
  786. int index = textbox_STDEditor.SelectionStart;
  787. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "and");
  788. textbox_STDEditor.Focus();
  789. textbox_STDEditor.Select(index + 3, 0);
  790. textbox_STDEditor.ScrollToCaret();
  791. }
  792. private void button_Or_Click(object sender, EventArgs e)
  793. {
  794. //textbox_STDEditor 中的光标
  795. int index = textbox_STDEditor.SelectionStart;
  796. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "or");
  797. textbox_STDEditor.Focus();
  798. textbox_STDEditor.Select(index + 2, 0);
  799. textbox_STDEditor.ScrollToCaret();
  800. }
  801. private void comboBox_Constants_SelectedIndexChanged(object sender, EventArgs e)
  802. {
  803. if (comboBox_Constants.SelectedItem != null)
  804. {
  805. string newStr = comboBox_Constants.SelectedItem.ToString().Split('=')[0];
  806. int index = textbox_STDEditor.SelectionStart;
  807. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, newStr);
  808. textbox_STDEditor.Focus();
  809. textbox_STDEditor.Select(index + newStr.Length, 0);
  810. textbox_STDEditor.ScrollToCaret();
  811. }
  812. }
  813. private void button_Recover_Click(object sender, EventArgs e)
  814. {
  815. XmlDocument doc = new XmlDocument();
  816. try
  817. {
  818. //System.IO.File.Copy(Address_backup, Address, true);
  819. //doc.Load(Address_backup);
  820. //LoadXmlToTreeControl(doc, XmlTree_MaxEDSRules.Nodes);
  821. XmlTree_MaxEDSRules.Nodes.Clear();
  822. string STDDBAddress_backup = "";
  823. string[] files = System.IO.Directory.GetFiles(STDDBAddress_backupDirectory);//得到文件
  824. foreach (var file in files)
  825. {
  826. if (".db".IndexOf(file.Substring(file.LastIndexOf(".") + 1)) > -1)
  827. {
  828. STDDBAddress_backup = file;
  829. }
  830. }
  831. LoadMaxEDSRulesToTreeControl(STDDBAddress_backup, XmlTree_MaxEDSRules.Nodes);
  832. XmlTree_MaxEDSRules.Focus();
  833. if (XmlTree_MaxEDSRules.Nodes.Count > 0)
  834. {
  835. XmlTree_MaxEDSRules.SelectedNode = XmlTree_MaxEDSRules.Nodes[0];
  836. XmlTree_MaxEDSRules_AfterSelect(XmlTree_MaxEDSRules, new TreeViewEventArgs(XmlTree_MaxEDSRules.SelectedNode));
  837. }
  838. else
  839. {
  840. textbox_STDEditor.Text = "";
  841. textBox_MaxEDSTime.Text = "";
  842. }
  843. }
  844. catch(Exception ex)
  845. {
  846. MessageBox.Show("Recovery failed!" + "\n"+ex.Message.ToString(), "Tip", MessageBoxButtons.OK, MessageBoxIcon.Information);
  847. }
  848. }
  849. private bool CheckConstants(string ConstantName)
  850. {
  851. for (int num = 0; num < XmlTree_MaxEDSRules.Nodes.Count; num++)
  852. {
  853. if (XmlTree_MaxEDSRules.Nodes[num].Tag.ToString().Contains(ConstantName))
  854. {
  855. XmlTree_MaxEDSRules.SelectedNode = XmlTree_MaxEDSRules.Nodes[num];
  856. SetGrayExceptSelectedNode(XmlTree_MaxEDSRules, XmlTree_MaxEDSRules.SelectedNode);
  857. DialogResult result = MessageBox.Show("Closing failed," + XmlTree_MaxEDSRules.Nodes[num].Text + table["message28"].ToString(), "Tip", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  858. return false;
  859. }
  860. }
  861. return true;
  862. }
  863. private void XmlTree_MaxEDSRules_AfterSelect(object sender, TreeViewEventArgs e)
  864. {
  865. SetBlackAllNodes(XmlTree_MaxEDSRules);
  866. this.textbox_STDEditor.Text = XmlTree_MaxEDSRules.SelectedNode.Tag.ToString();
  867. }
  868. private void XmlTree_MaxEDSRules_BeforeSelect(object sender, TreeViewCancelEventArgs e)
  869. {
  870. if (XmlTree_MaxEDSRules.SelectedNode != null)
  871. {
  872. if (!Checktextbox_STDEditor())
  873. {
  874. SetGrayExceptSelectedNode(XmlTree_MaxEDSRules, XmlTree_MaxEDSRules.SelectedNode);
  875. e.Cancel = true;
  876. return;
  877. }
  878. XmlTree_MaxEDSRules.SelectedNode.Tag = this.textbox_STDEditor.Text;
  879. }
  880. }
  881. private void textbox_STDEditor_Leave(object sender, EventArgs e)
  882. {
  883. XmlTree_MaxEDSRules.Focus();
  884. }
  885. #region 为配合textbox_STDEditor_Leave时事件,点击其它groupbox组件时使焦点转移
  886. private void Form_ConstantsEditor_Click(object sender, EventArgs e)
  887. {
  888. groupBox_XmlTree_MaxEDSRules.Focus();
  889. }
  890. private void groupBox_Data_Click(object sender, EventArgs e)
  891. {
  892. groupBox_Data.Focus();
  893. }
  894. private void groupBox_ChemicalElement_Click(object sender, EventArgs e)
  895. {
  896. groupBox_ChemicalElement.Focus();
  897. }
  898. private void groupBox_OtherCommonlyUsedSymbols_Click(object sender, EventArgs e)
  899. {
  900. groupBox_OtherCommonlyUsedSymbols.Focus();
  901. }
  902. private void groupBox_CalculatingSymbols_Click(object sender, EventArgs e)
  903. {
  904. groupBox_CalculatingSymbols.Focus();
  905. }
  906. private void groupBox_XmlTree_MaxEDSRules_Click(object sender, EventArgs e)
  907. {
  908. groupBox_XmlTree_MaxEDSRules.Focus();
  909. }
  910. #endregion
  911. private void button_1_Click(object sender, EventArgs e)
  912. {
  913. //textbox_STDEditor 中的光标
  914. int index = textbox_STDEditor.SelectionStart;
  915. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "1");
  916. textbox_STDEditor.Focus();
  917. textbox_STDEditor.Select(index + 1, 0);
  918. textbox_STDEditor.ScrollToCaret();
  919. }
  920. private void button_2_Click(object sender, EventArgs e)
  921. {
  922. //textbox_STDEditor 中的光标
  923. int index = textbox_STDEditor.SelectionStart;
  924. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "2");
  925. textbox_STDEditor.Focus();
  926. textbox_STDEditor.Select(index + 1, 0);
  927. textbox_STDEditor.ScrollToCaret();
  928. }
  929. private void button_3_Click(object sender, EventArgs e)
  930. {
  931. //textbox_STDEditor 中的光标
  932. int index = textbox_STDEditor.SelectionStart;
  933. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "3");
  934. textbox_STDEditor.Focus();
  935. textbox_STDEditor.Select(index + 1, 0);
  936. textbox_STDEditor.ScrollToCaret();
  937. }
  938. private void button_4_Click(object sender, EventArgs e)
  939. {
  940. //textbox_STDEditor 中的光标
  941. int index = textbox_STDEditor.SelectionStart;
  942. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "4");
  943. textbox_STDEditor.Focus();
  944. textbox_STDEditor.Select(index + 1, 0);
  945. textbox_STDEditor.ScrollToCaret();
  946. }
  947. private void button_5_Click(object sender, EventArgs e)
  948. {
  949. //textbox_STDEditor 中的光标
  950. int index = textbox_STDEditor.SelectionStart;
  951. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "5");
  952. textbox_STDEditor.Focus();
  953. textbox_STDEditor.Select(index + 1, 0);
  954. textbox_STDEditor.ScrollToCaret();
  955. }
  956. private void button_6_Click(object sender, EventArgs e)
  957. {
  958. //textbox_STDEditor 中的光标
  959. int index = textbox_STDEditor.SelectionStart;
  960. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "6");
  961. textbox_STDEditor.Focus();
  962. textbox_STDEditor.Select(index + 1, 0);
  963. textbox_STDEditor.ScrollToCaret();
  964. }
  965. private void button_7_Click(object sender, EventArgs e)
  966. {
  967. //textbox_STDEditor 中的光标
  968. int index = textbox_STDEditor.SelectionStart;
  969. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "7");
  970. textbox_STDEditor.Focus();
  971. textbox_STDEditor.Select(index + 1, 0);
  972. textbox_STDEditor.ScrollToCaret();
  973. }
  974. private void button_8_Click(object sender, EventArgs e)
  975. {
  976. //textbox_STDEditor 中的光标
  977. int index = textbox_STDEditor.SelectionStart;
  978. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "8");
  979. textbox_STDEditor.Focus();
  980. textbox_STDEditor.Select(index + 1, 0);
  981. textbox_STDEditor.ScrollToCaret();
  982. }
  983. private void button_9_Click(object sender, EventArgs e)
  984. {
  985. //textbox_STDEditor 中的光标
  986. int index = textbox_STDEditor.SelectionStart;
  987. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "9");
  988. textbox_STDEditor.Focus();
  989. textbox_STDEditor.Select(index + 1, 0);
  990. textbox_STDEditor.ScrollToCaret();
  991. }
  992. private void button_0_Click(object sender, EventArgs e)
  993. {
  994. int index = textbox_STDEditor.SelectionStart;
  995. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "0");
  996. textbox_STDEditor.Focus();
  997. textbox_STDEditor.Select(index + 1, 0);
  998. textbox_STDEditor.ScrollToCaret();
  999. }
  1000. //private float X = 1;
  1001. //private float Y = 1;
  1002. //float AmplificationFactor = 1;
  1003. private void Form_MaxEDSRules_Resize(object sender, EventArgs e)
  1004. {
  1005. //float newx = this.Width / X;
  1006. //float newy = this.Height / Y;
  1007. //AmplificationFactor = newy;
  1008. //setControls(newx, newy, this);
  1009. //this.Resize -= new System.EventHandler(this.Form_MaxEDSRules_Resize);
  1010. //if (panel_OTSPeriodicTable.Visible == false)
  1011. //{
  1012. // int w = this.Width - panel_OTSPeriodicTable.Width;
  1013. // this.Width = w;
  1014. //}
  1015. //this.Resize += new System.EventHandler(this.Form_MaxEDSRules_Resize);
  1016. ////if (WindowState == FormWindowState.Maximized)
  1017. ////{
  1018. //// panel_OTSPeriodicTable.Visible = true;
  1019. //// PeriodicTableSwitch.Enabled = false;
  1020. ////}
  1021. }
  1022. private void setTag(Control cons)
  1023. {
  1024. foreach (Control con in cons.Controls)
  1025. {
  1026. con.Tag = con.Width + ":" + con.Height + ":" + con.Left + ":" + con.Top + ":" + con.Font.Size;
  1027. if (con.Controls.Count > 0)
  1028. setTag(con);
  1029. }
  1030. }
  1031. private void setControls(float newx, float newy, Control cons)
  1032. {
  1033. foreach (Control con in cons.Controls)
  1034. {
  1035. if (false)
  1036. {
  1037. }
  1038. else
  1039. {
  1040. string[] mytag = con.Tag.ToString().Split(':');
  1041. float a = Convert.ToSingle(mytag[0]) * newx;
  1042. con.Width = (int)a;
  1043. a = Convert.ToSingle(mytag[1]) * newy;
  1044. con.Height = (int)(a);
  1045. a = Convert.ToSingle(mytag[2]) * newx;
  1046. con.Left = (int)(a);
  1047. a = Convert.ToSingle(mytag[3]) * newy;
  1048. con.Top = (int)(a);
  1049. Single currentSize;
  1050. if (con.GetType().ToString() == "System.Windows.Forms.Label")
  1051. {
  1052. currentSize = Convert.ToSingle(mytag[4]) * ((newx + newy) / 2);
  1053. //currentSize = 6f;
  1054. }
  1055. else
  1056. {
  1057. if (Math.Max(newx, newy) < 1)
  1058. {
  1059. currentSize = Convert.ToSingle(mytag[4]) * 1;
  1060. }
  1061. else
  1062. {
  1063. currentSize = Convert.ToSingle(mytag[4]) * Math.Max(newx, newy);
  1064. }
  1065. }
  1066. con.Font = new Font(con.Font.Name, currentSize, con.Font.Style, con.Font.Unit);
  1067. if (con.Controls.Count > 0)
  1068. {
  1069. setControls(newx, newy, con);
  1070. }
  1071. }
  1072. }
  1073. }
  1074. #region
  1075. //XmlDocument doc = new XmlDocument();
  1076. //doc.Load(Address);
  1077. //LoadXmlToTreeControl(doc,XmlTree_MaxEDSRules.Nodes);
  1078. //public string Language = "English";
  1079. //string Address_backup = Application.StartupPath + "\\Config\\SysData\\OTSParticleSTD_backup.xml";
  1080. //string Address = Application.StartupPath + "\\Config\\SysData\\OTSParticleSTD.xml";
  1081. //保存xmltree内容到xml文件
  1082. //void SaveXmlTreeDataToXml(string Address)
  1083. //{
  1084. // XDocument xdoc = XDocument.Load(Address);
  1085. // IEnumerable<XElement> elements = from ele in xdoc.Descendants("XMLData") select ele;
  1086. // var item = (from ele1 in elements.Elements("Collection")
  1087. // where ele1.Attribute("RegName").Value.Equals("MaxEDSRules")
  1088. // select ele1).FirstOrDefault();
  1089. // if (item != null)
  1090. // {
  1091. // item.Remove();
  1092. // }
  1093. // XElement MaxEDS = new XElement("Collection");
  1094. // MaxEDS.SetAttributeValue("RegName", "MaxEDSRules");
  1095. // elements.ElementAt(0).Add(MaxEDS);
  1096. // for (int num = 0; num < XmlTree_MaxEDSRules.Nodes.Count; num++)
  1097. // {
  1098. // string UsingElementList = "";
  1099. // string UsingImgPropertyList = "";
  1100. // string UsingOtherPropertyList = "";
  1101. // List<string> UsingElementL = new List<string>();
  1102. // List<string> UsingImgPropertyL = new List<string>();
  1103. // List<string> UsingOtherPropertyL = new List<string>();
  1104. // string str_RemoveBlank = "";
  1105. // //forth_elem干扰or分隔符,故先行去掉
  1106. // if (XmlTree_MaxEDSRules.Nodes[num].Tag.ToString().Contains("forth_elem"))
  1107. // {
  1108. // str_RemoveBlank = str_RemoveBlank.Replace("forth_elem", "");
  1109. // UsingOtherPropertyList = "forth_elem,";
  1110. // }
  1111. // str_RemoveBlank = XmlTree_MaxEDSRules.Nodes[num].Tag.ToString().Replace(" ", "");
  1112. // string[] str_Removeand = System.Text.RegularExpressions.Regex.Split(str_RemoveBlank, "and", System.Text.RegularExpressions.RegexOptions.None);
  1113. // List<string> str_Removeandor = new List<string>();
  1114. // for (int i = 0; i < str_Removeand.Length; i++)
  1115. // {
  1116. // str_Removeandor.AddRange(System.Text.RegularExpressions.Regex.Split(str_Removeand[i], "or", System.Text.RegularExpressions.RegexOptions.None));
  1117. // }
  1118. // List<string> list_all = new List<string>();
  1119. // for (int i = 0; i < str_Removeandor.Count; i++)
  1120. // {
  1121. // list_all.AddRange(str_Removeandor[i].Split(new char[] { '+', '-', '*', '/', '=', '>', '<', '(', ')' }));
  1122. // }
  1123. // for (int i = 0; i < list_all.Count; i++)
  1124. // {
  1125. // //周期元素?
  1126. // if (this.comboBox_PeriodicTable.Items.Contains(list_all[i]))
  1127. // {
  1128. // if (!UsingElementL.Contains(list_all[i]))
  1129. // {
  1130. // UsingElementL.Add(list_all[i]);
  1131. // }
  1132. // }
  1133. // //first_elem?
  1134. // if (this.comboBox_Elem1.Items.Contains(list_all[i]))
  1135. // {
  1136. // if (!UsingOtherPropertyL.Contains(list_all[i]))
  1137. // {
  1138. // UsingOtherPropertyL.Add(list_all[i]);
  1139. // }
  1140. // }
  1141. // //Element1?
  1142. // if (this.comboBox_Elem.Items.Contains(list_all[i]))
  1143. // {
  1144. // if (!UsingOtherPropertyL.Contains(list_all[i]))
  1145. // {
  1146. // UsingOtherPropertyL.Add(list_all[i]);
  1147. // }
  1148. // }
  1149. // //其它元素?
  1150. // if (this.comboBox_ImgProperty.Items.Contains(list_all[i]))
  1151. // {
  1152. // if (!UsingImgPropertyL.Contains(list_all[i]))
  1153. // {
  1154. // UsingImgPropertyL.Add(list_all[i]);
  1155. // }
  1156. // }
  1157. // }
  1158. // if (UsingElementL.Count > 0)
  1159. // {
  1160. // for (int i = 0; i < UsingElementL.Count - 1; i++)
  1161. // {
  1162. // UsingElementList += UsingElementL[i] + ",";
  1163. // }
  1164. // UsingElementList += UsingElementL[UsingElementL.Count - 1];
  1165. // }
  1166. // if (UsingImgPropertyL.Count > 0)
  1167. // {
  1168. // for (int i = 0; i < UsingImgPropertyL.Count - 1; i++)
  1169. // {
  1170. // UsingImgPropertyList += UsingImgPropertyL[i] + ",";
  1171. // }
  1172. // UsingImgPropertyList += UsingImgPropertyL[UsingImgPropertyL.Count - 1];
  1173. // }
  1174. // if (UsingOtherPropertyL.Count > 0)
  1175. // {
  1176. // for (int i = 0; i < UsingOtherPropertyL.Count - 1; i++)
  1177. // {
  1178. // UsingOtherPropertyList += UsingOtherPropertyL[i] + ",";
  1179. // }
  1180. // UsingOtherPropertyList += UsingOtherPropertyL[UsingOtherPropertyL.Count - 1];
  1181. // }
  1182. // XElement EleName = new XElement("Member");
  1183. // //EleName.SetAttributeValue("MaxEDSTime", XmlTree_MaxEDSRules.Nodes[num].Name);
  1184. // EleName.SetAttributeValue("MaxEDSTime", textBox_MaxEDSTime.Text);
  1185. // EleName.SetAttributeValue("UsingElementList", UsingElementList);
  1186. // EleName.SetAttributeValue("UsingImgPropertyList", UsingImgPropertyList);
  1187. // EleName.SetAttributeValue("UsingOtherPropertyList", UsingOtherPropertyList);
  1188. // EleName.SetAttributeValue("Expression", XmlTree_MaxEDSRules.Nodes[num].Tag);
  1189. // MaxEDS.Add(EleName);
  1190. // }
  1191. // xdoc.Save(Address);
  1192. //}
  1193. //private void button_Backup_Click(object sender, EventArgs e)
  1194. //{
  1195. // if (XmlTree_MaxEDSRules.SelectedNode != null)
  1196. // {
  1197. // //判断MaxEDSTime
  1198. // double dMaxEDSTime = 0;
  1199. // if (!double.TryParse(textBox_MaxEDSTime.Text, out dMaxEDSTime) || double.Parse(textBox_MaxEDSTime.Text) <= 0)
  1200. // {
  1201. // textBox_MaxEDSTime.Focus();
  1202. // textBox_MaxEDSTime.SelectAll();
  1203. // MessageBox.Show(table["message16"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  1204. // return;
  1205. // }
  1206. // //判断textbox_STDEditor
  1207. // if (!Checktextbox_STDEditor())
  1208. // {
  1209. // return;
  1210. // }
  1211. // XmlTree_MaxEDSRules.SelectedNode.Tag = this.textbox_STDEditor.Text;
  1212. // //XmlTree_MaxEDSRules.SelectedNode.Name = textBox_MaxEDSTime.Text;
  1213. // }
  1214. // try
  1215. // {
  1216. // SaveFileDialog saveFile = new SaveFileDialog();
  1217. // saveFile.Title = table["message23"].ToString();
  1218. // saveFile.Filter = table["message24"].ToString();
  1219. // saveFile.OverwritePrompt = true; //是否覆盖当前文件
  1220. // saveFile.RestoreDirectory = true; //还原上次目录
  1221. // if (saveFile.ShowDialog() == DialogResult.OK)
  1222. // {
  1223. // System.IO.File.Copy(Address, saveFile.FileName, true);
  1224. // SaveXmlTreeDataToXml(saveFile.FileName);
  1225. // MessageBox.Show(table["message25"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  1226. // }
  1227. // else
  1228. // {
  1229. // return;
  1230. // }
  1231. // }
  1232. // catch (Exception ex)
  1233. // {
  1234. // MessageBox.Show(ex.Message);
  1235. // }
  1236. //}
  1237. #endregion
  1238. private void Form_MaxEDSRules_FormClosing(object sender, FormClosingEventArgs e)
  1239. {
  1240. if (form_PeriodicTable != null)
  1241. {
  1242. form_PeriodicTable.Close();
  1243. }
  1244. }
  1245. }
  1246. }