Form_ZeroElementRules.cs 60 KB

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