STDEditor.cs 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788
  1. using OTS.WinFormsUI.Docking;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Drawing;
  5. using System.Linq;
  6. using System.Windows.Forms;
  7. using System.Collections;
  8. using System.Text.RegularExpressions;
  9. namespace OTSPartA_STDEditor
  10. {
  11. public partial class STDEditor : DockContent
  12. {
  13. #region 全局变量
  14. public SubMidWindow m_SubMidWindow = null;
  15. public int STDId = -1;
  16. Hashtable table_STDEditor;
  17. //数据库操作对象
  18. public SqlLiteClass m_sc = null;
  19. // 连接状态
  20. bool m_bConnectionState = false;
  21. #endregion
  22. public enum Result
  23. {
  24. NoMatched=0,
  25. Success=1,
  26. Fail=2
  27. }
  28. public STDEditor(SubMidWindow SubMidWindow)
  29. {
  30. InitializeComponent();
  31. m_sc = new SqlLiteClass();
  32. m_SubMidWindow = SubMidWindow;
  33. X = this.Width;
  34. Y = this.Height;
  35. setTag(this);
  36. }
  37. public STDEditor(SubMidWindow SubMidWindow,string STDDBaddress)
  38. {
  39. InitializeComponent();
  40. m_sc = new SqlLiteClass(STDDBaddress);
  41. m_SubMidWindow = SubMidWindow;
  42. X = this.Width;
  43. Y = this.Height;
  44. setTag(this);
  45. }
  46. private void STDEditor_Load(object sender, EventArgs e)
  47. {
  48. m_SubMidWindow.m_MainForm.lan = new Language(this);
  49. table_STDEditor = m_SubMidWindow.m_MainForm.lan.GetNameTable("STDEditor");
  50. //初始化comboBox
  51. this.comboBox_Elem1.Items.Add("first_elem");
  52. this.comboBox_Elem1.Items.Add("second_elem");
  53. this.comboBox_Elem1.Items.Add("third_elem");
  54. this.comboBox_Elem1.Items.Add("forth_elem");
  55. this.comboBox_Elem1.Items.Add("fifth_elem");
  56. this.comboBox_Elem1.Items.Add("sixth_elem");
  57. this.comboBox_Elem1.Items.Add("seventh_elem");
  58. this.comboBox_Elem1.Items.Add("eighth_elem");
  59. this.comboBox_Elem1.Items.Add("ninth_elem");
  60. this.comboBox_Elem1.Items.Add("tenth_elem");
  61. comboBox_Elem1.SelectedIndex = comboBox_Elem1.Items.IndexOf("first_elem");
  62. this.comboBox_Elem.Items.Add("Element#1");
  63. this.comboBox_Elem.Items.Add("Element#2");
  64. this.comboBox_Elem.Items.Add("Element#3");
  65. this.comboBox_Elem.Items.Add("Element#4");
  66. this.comboBox_Elem.Items.Add("Element#5");
  67. this.comboBox_Elem.Items.Add("Element#6");
  68. this.comboBox_Elem.Items.Add("Element#7");
  69. this.comboBox_Elem.Items.Add("Element#8");
  70. this.comboBox_Elem.Items.Add("Element#9");
  71. this.comboBox_Elem.Items.Add("Element#10");
  72. comboBox_Elem.SelectedIndex = comboBox_Elem.Items.IndexOf("Element#1");
  73. this.comboBox_ImgProperty.Items.Add("Dmax"); //颗粒最大直径;
  74. this.comboBox_ImgProperty.Items.Add("Dmin"); //颗粒最小直径;
  75. this.comboBox_ImgProperty.Items.Add("Aspect"); //长宽比;
  76. this.comboBox_ImgProperty.Items.Add("Dperp"); //与Dmax垂直直径;
  77. this.comboBox_ImgProperty.Items.Add("Dmean"); //平均内接圆直径;
  78. this.comboBox_ImgProperty.Items.Add("Area"); //面积;
  79. this.comboBox_ImgProperty.Items.Add("Dferet"); //费雷特直径;
  80. this.comboBox_ImgProperty.Items.Add("Width"); //宽度(直上直下那种);
  81. this.comboBox_ImgProperty.Items.Add("Height"); //高度(直上直下那种)
  82. this.comboBox_ImgProperty.Items.Add("Perimeter"); //周长
  83. this.comboBox_ImgProperty.Items.Add("Dinscr"); //最大内接圆直径
  84. this.comboBox_ImgProperty.Items.Add("Orientation"); //朝向
  85. this.comboBox_ImgProperty.Items.Add("Delong"); //展开长度
  86. this.comboBox_ImgProperty.Items.Add("Aspectelong"); //展开后长宽比
  87. this.comboBox_ImgProperty.Items.Add("Dequalcircle"); //等效圆直径
  88. this.comboBox_ImgProperty.Items.Add("Vedio"); //BSE灰度平均值
  89. comboBox_ImgProperty.SelectedIndex = comboBox_ImgProperty.Items.IndexOf("Dmax");
  90. 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" };
  91. comboBox_PeriodicTable.Items.AddRange(PeriodicTable);
  92. AutoCompleteStringCollection sc = new AutoCompleteStringCollection();
  93. sc.AddRange(PeriodicTable);
  94. this.comboBox_PeriodicTable.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.SuggestAppend;
  95. this.comboBox_PeriodicTable.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.CustomSource;
  96. this.comboBox_PeriodicTable.AutoCompleteCustomSource = sc;
  97. dataGridView_KeyElements.RowHeadersVisible = false;
  98. dataGridView_KeyElements.ColumnHeadersVisible = false;
  99. dataGridView_KeyElements.AllowUserToAddRows = false;
  100. dataGridView_KeyElements.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
  101. dataGridView_SubElements.RowHeadersVisible = false;
  102. dataGridView_SubElements.ColumnHeadersVisible = false;
  103. dataGridView_SubElements.AllowUserToAddRows = false;
  104. dataGridView_SubElements.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
  105. }
  106. /// <summary>
  107. /// [颜色:16进制转成RGB]
  108. /// </summary>
  109. /// <param name="strColor">设置16进制颜色 [返回RGB]</param>
  110. /// <returns></returns>
  111. public static System.Drawing.Color colorHx16toRGB(string strHxColor)
  112. {
  113. try
  114. {
  115. if (strHxColor.Length == 0)
  116. {//如果为空
  117. return System.Drawing.Color.FromArgb(255, 255, 204);//设为白色
  118. }
  119. else
  120. {//转换颜色
  121. return System.Drawing.Color.FromArgb(System.Int32.Parse(strHxColor.Substring(1, 2), System.Globalization.NumberStyles.AllowHexSpecifier), System.Int32.Parse(strHxColor.Substring(3, 2), System.Globalization.NumberStyles.AllowHexSpecifier), System.Int32.Parse(strHxColor.Substring(5, 2), System.Globalization.NumberStyles.AllowHexSpecifier));
  122. }
  123. }
  124. catch
  125. {//设为白色
  126. return System.Drawing.Color.FromArgb(255, 255, 204);
  127. }
  128. }
  129. float AmplificationFactor = 1;
  130. //private void button_Extend_Click(object sender, EventArgs e)
  131. //{
  132. // if (button_Extend.BackColor == SystemColors.ControlDarkDark)
  133. // {
  134. // //groupBox_Data.Visible = true;
  135. // textbox_STDEditor.Height = (int)Math.Round(150 * AmplificationFactor);
  136. // button_Extend.BackColor = SystemColors.ControlDark;
  137. // }
  138. // else
  139. // {
  140. // button_Extend.BackColor = SystemColors.ControlDarkDark;
  141. // textbox_STDEditor.Height = (int)Math.Round(300* AmplificationFactor);
  142. // }
  143. //}
  144. private void comboBox_Elem1_SelectedIndexChanged(object sender, EventArgs e)
  145. {
  146. string newStr = comboBox_Elem1.SelectedItem.ToString();
  147. int index = textbox_STDEditor.SelectionStart;
  148. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, newStr);
  149. textbox_STDEditor.Focus();
  150. textbox_STDEditor.Select(index + newStr.Length, 0);
  151. textbox_STDEditor.ScrollToCaret();
  152. }
  153. private void comboBox_Elem2_SelectedIndexChanged(object sender, EventArgs e)
  154. {
  155. string newStr = comboBox_Elem.SelectedItem.ToString();
  156. int index = textbox_STDEditor.SelectionStart;
  157. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, newStr);
  158. textbox_STDEditor.Focus();
  159. textbox_STDEditor.Select(index + newStr.Length, 0);
  160. textbox_STDEditor.ScrollToCaret();
  161. }
  162. private void comboBox_ImgProperty_SelectedIndexChanged(object sender, EventArgs e)
  163. {
  164. string newStr = comboBox_ImgProperty.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 button_Plus_Click(object sender, EventArgs e)
  172. {
  173. //textbox_STDEditor 中的光标
  174. int index = textbox_STDEditor.SelectionStart;
  175. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "+");
  176. textbox_STDEditor.Focus();
  177. textbox_STDEditor.Select(index + 1, 0);
  178. textbox_STDEditor.ScrollToCaret();
  179. }
  180. private void button_Subtract_Click(object sender, EventArgs e)
  181. {
  182. //textbox_STDEditor 中的光标
  183. int index = textbox_STDEditor.SelectionStart;
  184. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "-");
  185. textbox_STDEditor.Focus();
  186. textbox_STDEditor.Select(index + 1, 0);
  187. textbox_STDEditor.ScrollToCaret();
  188. }
  189. private void button_Multiply_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_Divide_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_More_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_Less_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_LeftParenthesis_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_RightParenthesis_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_Equal_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. //元素下拉选择输入
  253. private void comboBox_PeriodicTable_SelectedIndexChanged(object sender, EventArgs e)
  254. {
  255. if (comboBox_PeriodicTable.Text != null && comboBox_PeriodicTable.SelectedItem != null)
  256. {
  257. string newStr = comboBox_PeriodicTable.SelectedItem.ToString();
  258. comboBox_PeriodicTable.Text = null;
  259. int index = textbox_STDEditor.SelectionStart;
  260. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, newStr);
  261. textbox_STDEditor.Focus();
  262. textbox_STDEditor.Select(index + newStr.Length, 0);
  263. textbox_STDEditor.ScrollToCaret();
  264. }
  265. }
  266. private void button_And_Click(object sender, EventArgs e)
  267. {
  268. //textbox_STDEditor 中的光标
  269. int index = textbox_STDEditor.SelectionStart;
  270. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "and");
  271. textbox_STDEditor.Focus();
  272. textbox_STDEditor.Select(index + 3, 0);
  273. textbox_STDEditor.ScrollToCaret();
  274. }
  275. private void button_Or_Click(object sender, EventArgs e)
  276. {
  277. //textbox_STDEditor 中的光标
  278. int index = textbox_STDEditor.SelectionStart;
  279. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "or");
  280. textbox_STDEditor.Focus();
  281. textbox_STDEditor.Select(index + 2, 0);
  282. textbox_STDEditor.ScrollToCaret();
  283. }
  284. private void comboBox_Constants_SelectedIndexChanged(object sender, EventArgs e)
  285. {
  286. if (comboBox_Constants.SelectedItem != null)
  287. {
  288. string newStr = comboBox_Constants.SelectedItem.ToString().Split('=')[0];
  289. int index = textbox_STDEditor.SelectionStart;
  290. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, newStr);
  291. textbox_STDEditor.Focus();
  292. textbox_STDEditor.Select(index + newStr.Length, 0);
  293. textbox_STDEditor.ScrollToCaret();
  294. }
  295. }
  296. private void button_1_Click(object sender, EventArgs e)
  297. {
  298. //textbox_STDEditor 中的光标
  299. int index = textbox_STDEditor.SelectionStart;
  300. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "1");
  301. textbox_STDEditor.Focus();
  302. textbox_STDEditor.Select(index + 1, 0);
  303. textbox_STDEditor.ScrollToCaret();
  304. }
  305. private void button_2_Click(object sender, EventArgs e)
  306. {
  307. //textbox_STDEditor 中的光标
  308. int index = textbox_STDEditor.SelectionStart;
  309. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "2");
  310. textbox_STDEditor.Focus();
  311. textbox_STDEditor.Select(index + 1, 0);
  312. textbox_STDEditor.ScrollToCaret();
  313. }
  314. private void button_3_Click(object sender, EventArgs e)
  315. {
  316. //textbox_STDEditor 中的光标
  317. int index = textbox_STDEditor.SelectionStart;
  318. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "3");
  319. textbox_STDEditor.Focus();
  320. textbox_STDEditor.Select(index + 1, 0);
  321. textbox_STDEditor.ScrollToCaret();
  322. }
  323. private void button_4_Click(object sender, EventArgs e)
  324. {
  325. //textbox_STDEditor 中的光标
  326. int index = textbox_STDEditor.SelectionStart;
  327. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "4");
  328. textbox_STDEditor.Focus();
  329. textbox_STDEditor.Select(index + 1, 0);
  330. textbox_STDEditor.ScrollToCaret();
  331. }
  332. private void button_5_Click(object sender, EventArgs e)
  333. {
  334. //textbox_STDEditor 中的光标
  335. int index = textbox_STDEditor.SelectionStart;
  336. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "5");
  337. textbox_STDEditor.Focus();
  338. textbox_STDEditor.Select(index + 1, 0);
  339. textbox_STDEditor.ScrollToCaret();
  340. }
  341. private void button_6_Click(object sender, EventArgs e)
  342. {
  343. //textbox_STDEditor 中的光标
  344. int index = textbox_STDEditor.SelectionStart;
  345. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "6");
  346. textbox_STDEditor.Focus();
  347. textbox_STDEditor.Select(index + 1, 0);
  348. textbox_STDEditor.ScrollToCaret();
  349. }
  350. private void button_7_Click(object sender, EventArgs e)
  351. {
  352. //textbox_STDEditor 中的光标
  353. int index = textbox_STDEditor.SelectionStart;
  354. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "7");
  355. textbox_STDEditor.Focus();
  356. textbox_STDEditor.Select(index + 1, 0);
  357. textbox_STDEditor.ScrollToCaret();
  358. }
  359. private void button_8_Click(object sender, EventArgs e)
  360. {
  361. //textbox_STDEditor 中的光标
  362. int index = textbox_STDEditor.SelectionStart;
  363. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "8");
  364. textbox_STDEditor.Focus();
  365. textbox_STDEditor.Select(index + 1, 0);
  366. textbox_STDEditor.ScrollToCaret();
  367. }
  368. private void button_9_Click(object sender, EventArgs e)
  369. {
  370. //textbox_STDEditor 中的光标
  371. int index = textbox_STDEditor.SelectionStart;
  372. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "9");
  373. textbox_STDEditor.Focus();
  374. textbox_STDEditor.Select(index + 1, 0);
  375. textbox_STDEditor.ScrollToCaret();
  376. }
  377. private void button_0_Click(object sender, EventArgs e)
  378. {
  379. int index = textbox_STDEditor.SelectionStart;
  380. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "0");
  381. textbox_STDEditor.Focus();
  382. textbox_STDEditor.Select(index + 1, 0);
  383. textbox_STDEditor.ScrollToCaret();
  384. }
  385. //元素自身text按回车键输入
  386. private void comboBox_PeriodicTable_KeyDown(object sender, KeyEventArgs e)
  387. {
  388. if (e.KeyValue == 13)
  389. {
  390. if (comboBox_PeriodicTable.Text != null && comboBox_PeriodicTable.Text != "")
  391. {
  392. this.textbox_STDEditor.Text += comboBox_PeriodicTable.Text.ToString();
  393. comboBox_PeriodicTable.Text = null;
  394. }
  395. }
  396. }
  397. /// <summary>
  398. /// 将颜色对象转换为uint
  399. /// </summary>
  400. /// <param name="color"></param>
  401. /// <returns></returns>
  402. public uint ParseRGB(Color color)
  403. {
  404. return (uint)(((uint)color.B << 16) | (ushort)(((ushort)color.G << 8) | color.R));
  405. }
  406. #region 常用数据验证的封装,数字字符的验证
  407. /// <summary>
  408. /// 常用数据验证的封装,数字字符的验证
  409. /// </summary>
  410. /// <param name="inputVal">需要验证的数值【字符串,或者数字】</param>
  411. /// <param name="type">类型为哪一个验证</param>
  412. /// <returns>如果验证成功则返回True,否则返回false</returns>
  413. public bool IsMatch(string inputVal, int type)
  414. {
  415. switch (type)
  416. {
  417. case 0:
  418. return Regex.IsMatch(inputVal, @"^[1-9]d*$"); //匹配正整数
  419. case 1:
  420. return Regex.IsMatch(inputVal, @"^-?\d+$"); //匹配整数
  421. case 2:
  422. return Regex.IsMatch(inputVal, @"^[A-Za-z0-9]+$"); //匹配由数字和26个英文字母组成的字符串
  423. case 3:
  424. return Regex.IsMatch(inputVal, @"^(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*))$"); //匹配正浮点数
  425. case 4:
  426. return Regex.IsMatch(inputVal, @"^[\u4e00-\u9fa5]{0,}$"); //匹配汉字
  427. case 5:
  428. return Regex.IsMatch(inputVal, @"^[0-9]+(.[0-9]{1,3})?$"); //匹配1~3位小数的正实数
  429. case 6:
  430. return Regex.IsMatch(inputVal, @"^[A-Za-z]+$"); //匹配英文字符
  431. default:
  432. return true;
  433. }
  434. }
  435. #endregion
  436. #region 弹出提示
  437. /// <summary>
  438. /// 弹出提示
  439. /// </summary>
  440. /// <param name="strContent"></param>
  441. protected void showMessage(string strContent)
  442. {
  443. MessageBox.Show(strContent, "Tip");
  444. }
  445. #endregion
  446. #region 控制BSE、化学式、元素本文框中不能输入下划线
  447. /// <summary>
  448. /// 控件不能输入下划线
  449. /// </summary>
  450. /// <param name="sender"></param>
  451. /// <param name="e"></param>
  452. private void textBox_KeyPress(object sender, KeyPressEventArgs e)
  453. {
  454. if ((e.KeyChar >= '0' && e.KeyChar <= '9') || (e.KeyChar >= 'A' && e.KeyChar <= 'Z') ||
  455. (e.KeyChar >= 'a' && e.KeyChar <= 'z') || (e.KeyChar == 8) || !(e.KeyChar == '_'))
  456. {
  457. e.Handled = false;
  458. }
  459. else
  460. {
  461. e.Handled = true;
  462. }
  463. }
  464. #endregion
  465. string ElementKeyOrSub = "";
  466. private void dataGridView_KeyElements_CellClick(object sender, DataGridViewCellEventArgs e)
  467. {
  468. ElementKeyOrSub = dataGridView_KeyElements.CurrentCell.Value.ToString();
  469. dataGridView_KeyElements.Columns.RemoveAt(e.ColumnIndex);
  470. DataGridViewButtonColumn dataGridViewButtonColumn = new DataGridViewButtonColumn();
  471. dataGridViewButtonColumn.Name = dataGridView_SubElements.Columns.Count.ToString();
  472. dataGridView_SubElements.Columns.Add(dataGridViewButtonColumn);
  473. if (dataGridView_SubElements.Rows.Count == 0)
  474. {
  475. DataGridViewRow row = new DataGridViewRow();
  476. dataGridView_SubElements.Rows.Add(row);
  477. }
  478. dataGridView_SubElements.Rows[0].Cells[dataGridView_SubElements.Columns.Count - 1].Value = ElementKeyOrSub;
  479. dataGridView_SubElements.ClearSelection();
  480. dataGridView_KeyElements.ClearSelection();
  481. }
  482. private void dataGridView_SubElements_CellClick(object sender, DataGridViewCellEventArgs e)
  483. {
  484. ElementKeyOrSub = dataGridView_SubElements.CurrentCell.Value.ToString();
  485. dataGridView_SubElements.Columns.RemoveAt(e.ColumnIndex);
  486. DataGridViewButtonColumn dataGridViewButtonColumn = new DataGridViewButtonColumn();
  487. dataGridViewButtonColumn.Name = dataGridView_SubElements.Columns.Count.ToString();
  488. dataGridView_KeyElements.Columns.Add(dataGridViewButtonColumn);
  489. if (dataGridView_KeyElements.Rows.Count == 0)
  490. {
  491. DataGridViewRow row = new DataGridViewRow();
  492. dataGridView_KeyElements.Rows.Add(row);
  493. }
  494. dataGridView_KeyElements.Rows[0].Cells[dataGridView_KeyElements.Columns.Count - 1].Value = ElementKeyOrSub;
  495. dataGridView_KeyElements.ClearSelection();
  496. dataGridView_SubElements.ClearSelection();
  497. }
  498. private float X=1;
  499. private float Y=1;
  500. private void STDEditor_Resize(object sender, EventArgs e)
  501. {
  502. float newx = (this.Width) / X;
  503. float newy = this.Height/ Y;
  504. AmplificationFactor = newy;
  505. setControls(newx, newy, this.tabSTDStandrad.TabPages[0]);
  506. //button_Extend.BackColor = SystemColors.ControlDarkDark;
  507. }
  508. private void setTag(Control cons)
  509. {
  510. foreach (Control con in cons.Controls)
  511. {
  512. con.Tag = con.Width + ":" + con.Height + ":" + con.Left + ":" + con.Top + ":" + con.Font.Size;
  513. if (con.Controls.Count > 0)
  514. setTag(con);
  515. }
  516. }
  517. private void setControls(float newx, float newy, Control cons)
  518. {
  519. foreach (Control con in cons.Controls)
  520. {
  521. if (false)
  522. {
  523. }
  524. else
  525. {
  526. string[] mytag = con.Tag.ToString().Split(':');
  527. float a = Convert.ToSingle(mytag[0]) * newx;
  528. con.Width = (int)a;
  529. a = Convert.ToSingle(mytag[1]) * newy;
  530. con.Height = (int)(a);
  531. a = Convert.ToSingle(mytag[2]) * newx;
  532. con.Left = (int)(a);
  533. a = Convert.ToSingle(mytag[3]) * newy;
  534. con.Top = (int)(a);
  535. Single currentSize ;
  536. if (con.Name == "button_Extend")
  537. {
  538. currentSize = 6f;
  539. }
  540. else
  541. {
  542. if (Math.Max(newx, newy) < 1)
  543. {
  544. currentSize = Convert.ToSingle(mytag[4]) * 1;
  545. }
  546. else
  547. {
  548. currentSize = Convert.ToSingle(mytag[4]) * Math.Max(newx, newy);
  549. }
  550. }
  551. con.Font = new Font(con.Font.Name, currentSize, con.Font.Style, con.Font.Unit);
  552. if (con.Controls.Count > 0)
  553. {
  554. setControls(newx, newy, con);
  555. }
  556. }
  557. }
  558. }
  559. Form_PeriodicTable form_PeriodicTable;
  560. private void button_PeriodicTableSwitch_Click(object sender, EventArgs e)
  561. {
  562. if (form_PeriodicTable == null) //如果子窗体为空则创造实例 并显示
  563. {
  564. form_PeriodicTable = new Form_PeriodicTable();
  565. if (table_STDEditor["language"].ToString() == "EN")
  566. {
  567. form_PeriodicTable.BackgroundImage = global::OTSPartA_STDEditor.Properties.Resources.PeriodicTable_EN;
  568. }
  569. else
  570. {
  571. form_PeriodicTable.BackgroundImage = global::OTSPartA_STDEditor.Properties.Resources.PeriodicTable_ZH;
  572. }
  573. form_PeriodicTable.Show();
  574. }
  575. else
  576. {
  577. if (form_PeriodicTable.IsDisposed) //若子窗体关闭 则打开新子窗体 并显示
  578. {
  579. form_PeriodicTable = new Form_PeriodicTable();
  580. if (table_STDEditor["language"].ToString() == "EN")
  581. {
  582. form_PeriodicTable.BackgroundImage = global::OTSPartA_STDEditor.Properties.Resources.PeriodicTable_EN;
  583. }
  584. else
  585. {
  586. form_PeriodicTable.BackgroundImage = global::OTSPartA_STDEditor.Properties.Resources.PeriodicTable_ZH;
  587. }
  588. form_PeriodicTable.Show();
  589. }
  590. else
  591. {
  592. form_PeriodicTable.Activate(); //使子窗体获得焦点
  593. }
  594. }
  595. }
  596. private void textbox_STDEditor_MouseLeave(object sender, EventArgs e)
  597. {
  598. dataGridView_KeyElements.Rows.Clear();
  599. dataGridView_KeyElements.Columns.Clear();
  600. string str_RemoveBlank = textbox_STDEditor.Text.ToString().Replace(" ", "");
  601. str_RemoveBlank = str_RemoveBlank.Replace("\r\n", "");
  602. str_RemoveBlank = str_RemoveBlank.Replace("forth_elem", "");
  603. string[] str_Removeand = System.Text.RegularExpressions.Regex.Split(str_RemoveBlank, "and", System.Text.RegularExpressions.RegexOptions.None);
  604. List<string> str_Removeandor = new List<string>();
  605. for (int i = 0; i < str_Removeand.Length; i++)
  606. {
  607. str_Removeandor.AddRange(System.Text.RegularExpressions.Regex.Split(str_Removeand[i], "or", System.Text.RegularExpressions.RegexOptions.None));
  608. }
  609. List<string> list_all = new List<string>();
  610. for (int i = 0; i < str_Removeandor.Count; i++)
  611. {
  612. list_all.AddRange(str_Removeandor[i].Split(new char[] { '+', '-', '*', '/', '=', '>', '<', '(', ')' }));
  613. }
  614. List<string> UsingElementL = new List<string>();
  615. for (int i = 0; i < list_all.Count; i++)
  616. {
  617. if (this.comboBox_PeriodicTable.Items.Contains(list_all[i]))
  618. {
  619. if (!UsingElementL.Contains(list_all[i]))
  620. {
  621. UsingElementL.Add(list_all[i]);
  622. }
  623. }
  624. }
  625. List<string> SubElements = new List<string>();
  626. for (int i = 0; i < dataGridView_SubElements.ColumnCount; i++)
  627. {
  628. if (UsingElementL.Contains(dataGridView_SubElements.Rows[0].Cells[i].Value))
  629. {
  630. SubElements.Add(dataGridView_SubElements.Rows[0].Cells[i].Value.ToString());
  631. }
  632. }
  633. dataGridView_SubElements.Rows.Clear();
  634. dataGridView_SubElements.Columns.Clear();
  635. for (int i = 0; i < SubElements.Count; i++)
  636. {
  637. DataGridViewButtonColumn dataGridViewButtonColumn = new DataGridViewButtonColumn();
  638. dataGridViewButtonColumn.Name = dataGridView_SubElements.Columns.Count.ToString();
  639. dataGridView_SubElements.Columns.Add(dataGridViewButtonColumn);
  640. if (dataGridView_SubElements.Rows.Count == 0)
  641. {
  642. DataGridViewRow row = new DataGridViewRow();
  643. dataGridView_SubElements.Rows.Add(row);
  644. }
  645. dataGridView_SubElements.Rows[0].Cells[dataGridView_SubElements.ColumnCount - 1].Value = SubElements[i];
  646. }
  647. if (SubElements.Count > 0)
  648. {
  649. for (int i = 0; i < UsingElementL.Count; i++)
  650. {
  651. if (!SubElements.Contains(UsingElementL[i]))
  652. {
  653. DataGridViewButtonColumn dataGridViewButtonColumn = new DataGridViewButtonColumn();
  654. dataGridViewButtonColumn.Name = dataGridView_KeyElements.Columns.Count.ToString();
  655. dataGridView_KeyElements.Columns.Add(dataGridViewButtonColumn);
  656. if (dataGridView_KeyElements.Rows.Count == 0)
  657. {
  658. DataGridViewRow row = new DataGridViewRow();
  659. dataGridView_KeyElements.Rows.Add(row);
  660. }
  661. dataGridView_KeyElements.Rows[0].Cells[dataGridView_KeyElements.ColumnCount - 1].Value = UsingElementL[i];
  662. }
  663. }
  664. }
  665. else
  666. {
  667. for (int i = 0; i < UsingElementL.Count; i++)
  668. {
  669. DataGridViewButtonColumn dataGridViewButtonColumn = new DataGridViewButtonColumn();
  670. dataGridViewButtonColumn.Name = dataGridView_KeyElements.Columns.Count.ToString();
  671. dataGridView_KeyElements.Columns.Add(dataGridViewButtonColumn);
  672. if (dataGridView_KeyElements.Rows.Count == 0)
  673. {
  674. DataGridViewRow row = new DataGridViewRow();
  675. dataGridView_KeyElements.Rows.Add(row);
  676. }
  677. dataGridView_KeyElements.Rows[0].Cells[i].Value = UsingElementL[i];
  678. }
  679. }
  680. dataGridView_KeyElements.ClearSelection();
  681. dataGridView_SubElements.ClearSelection();
  682. }
  683. public void ShowTabXray()
  684. {
  685. tabSTDStandrad.SelectedIndex = 1;
  686. }
  687. public void ShowSTD()
  688. {
  689. tabSTDStandrad.SelectedIndex = 0;
  690. }
  691. }
  692. }