Form_ZeroElementRules.cs 61 KB

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