Form_ZeroElementRules.cs 60 KB

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