Form_ZeroElementRules.cs 60 KB

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