STDEditor.cs 35 KB

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