Form_ZeroElementRules.cs 61 KB

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