STDEditor.cs 57 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424
  1. using OTS.WinFormsUI.Docking;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11. using OTSCLRINTERFACE;
  12. using System.Collections;
  13. using System.IO;
  14. using System.Runtime.InteropServices;
  15. using System.Text.RegularExpressions;
  16. namespace OTSPartA_STDEditor
  17. {
  18. public partial class STDEditor : DockContent
  19. {
  20. #region 全局变量
  21. public SubMidWindow m_SubMidWindow = null;
  22. public int STDId = -1;
  23. Hashtable table_STDEditor;
  24. //数据库操作对象
  25. public SqlLiteClass m_sc = null;
  26. // 电镜设置对象
  27. EDSController m_EDSHardwareMgr = null;
  28. //Xray图谱用户控件
  29. UXrayControl XrayControl = null;
  30. //全局Xray 用于存储当前选择行的Xray信息
  31. byte[] xrayByteData = null;
  32. // 连接状态
  33. bool m_bConnectionState = false;
  34. //标准Xray信息列表
  35. public List<STDXray> m_STDXrayList = null;
  36. #endregion
  37. public enum Result
  38. {
  39. NoMatched=0,
  40. Success=1,
  41. Fail=2
  42. }
  43. public STDEditor(SubMidWindow SubMidWindow)
  44. {
  45. InitializeComponent();
  46. m_sc = new SqlLiteClass();
  47. m_SubMidWindow = SubMidWindow;
  48. X = this.Width;
  49. Y = this.Height;
  50. setTag(this);
  51. }
  52. public STDEditor(SubMidWindow SubMidWindow,string STDDBaddress)
  53. {
  54. InitializeComponent();
  55. m_sc = new SqlLiteClass(STDDBaddress);
  56. m_SubMidWindow = SubMidWindow;
  57. X = this.Width;
  58. Y = this.Height;
  59. setTag(this);
  60. }
  61. private void STDEditor_Load(object sender, EventArgs e)
  62. {
  63. m_SubMidWindow.m_MainForm.lan = new Language(this);
  64. table_STDEditor = m_SubMidWindow.m_MainForm.lan.GetNameTable("STDEditor");
  65. //初始化comboBox
  66. this.comboBox_Elem1.Items.Add("first_elem");
  67. this.comboBox_Elem1.Items.Add("second_elem");
  68. this.comboBox_Elem1.Items.Add("third_elem");
  69. this.comboBox_Elem1.Items.Add("forth_elem");
  70. this.comboBox_Elem1.Items.Add("fifth_elem");
  71. this.comboBox_Elem1.Items.Add("sixth_elem");
  72. this.comboBox_Elem1.Items.Add("seventh_elem");
  73. this.comboBox_Elem1.Items.Add("eighth_elem");
  74. this.comboBox_Elem1.Items.Add("ninth_elem");
  75. this.comboBox_Elem1.Items.Add("tenth_elem");
  76. comboBox_Elem1.SelectedIndex = comboBox_Elem1.Items.IndexOf("first_elem");
  77. this.comboBox_Elem.Items.Add("Element#1");
  78. this.comboBox_Elem.Items.Add("Element#2");
  79. this.comboBox_Elem.Items.Add("Element#3");
  80. this.comboBox_Elem.Items.Add("Element#4");
  81. this.comboBox_Elem.Items.Add("Element#5");
  82. this.comboBox_Elem.Items.Add("Element#6");
  83. this.comboBox_Elem.Items.Add("Element#7");
  84. this.comboBox_Elem.Items.Add("Element#8");
  85. this.comboBox_Elem.Items.Add("Element#9");
  86. this.comboBox_Elem.Items.Add("Element#10");
  87. comboBox_Elem.SelectedIndex = comboBox_Elem.Items.IndexOf("Element#1");
  88. this.comboBox_ImgProperty.Items.Add("Dmax"); //颗粒最大直径;
  89. this.comboBox_ImgProperty.Items.Add("Dmin"); //颗粒最小直径;
  90. this.comboBox_ImgProperty.Items.Add("Aspect"); //长宽比;
  91. this.comboBox_ImgProperty.Items.Add("Dperp"); //与Dmax垂直直径;
  92. this.comboBox_ImgProperty.Items.Add("Dmean"); //平均内接圆直径;
  93. this.comboBox_ImgProperty.Items.Add("Area"); //面积;
  94. this.comboBox_ImgProperty.Items.Add("Dferet"); //费雷特直径;
  95. this.comboBox_ImgProperty.Items.Add("Width"); //宽度(直上直下那种);
  96. this.comboBox_ImgProperty.Items.Add("Height"); //高度(直上直下那种)
  97. this.comboBox_ImgProperty.Items.Add("Perimeter"); //周长
  98. this.comboBox_ImgProperty.Items.Add("Dinscr"); //最大内接圆直径
  99. this.comboBox_ImgProperty.Items.Add("Orientation"); //朝向
  100. this.comboBox_ImgProperty.Items.Add("Delong"); //展开长度
  101. this.comboBox_ImgProperty.Items.Add("Aspectelong"); //展开后长宽比
  102. this.comboBox_ImgProperty.Items.Add("Dequalcircle"); //等效圆直径
  103. this.comboBox_ImgProperty.Items.Add("Vedio"); //BSE灰度平均值
  104. comboBox_ImgProperty.SelectedIndex = comboBox_ImgProperty.Items.IndexOf("Dmax");
  105. 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" };
  106. comboBox_PeriodicTable.Items.AddRange(PeriodicTable);
  107. AutoCompleteStringCollection sc = new AutoCompleteStringCollection();
  108. sc.AddRange(PeriodicTable);
  109. this.comboBox_PeriodicTable.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.SuggestAppend;
  110. this.comboBox_PeriodicTable.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.CustomSource;
  111. this.comboBox_PeriodicTable.AutoCompleteCustomSource = sc;
  112. dataGridView_KeyElements.RowHeadersVisible = false;
  113. dataGridView_KeyElements.ColumnHeadersVisible = false;
  114. dataGridView_KeyElements.AllowUserToAddRows = false;
  115. dataGridView_KeyElements.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
  116. dataGridView_SubElements.RowHeadersVisible = false;
  117. dataGridView_SubElements.ColumnHeadersVisible = false;
  118. dataGridView_SubElements.AllowUserToAddRows = false;
  119. dataGridView_SubElements.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
  120. //添加Xray用户控件
  121. XrayControl = new UXrayControl();
  122. plXray.Controls.Add(XrayControl);
  123. XrayControl.Dock = DockStyle.Fill;
  124. //绑定数据库中的STDXray
  125. m_STDXrayList = new List<STDXray>();
  126. BindSTDXray();
  127. }
  128. /// <summary>
  129. /// [颜色:16进制转成RGB]
  130. /// </summary>
  131. /// <param name="strColor">设置16进制颜色 [返回RGB]</param>
  132. /// <returns></returns>
  133. public static System.Drawing.Color colorHx16toRGB(string strHxColor)
  134. {
  135. try
  136. {
  137. if (strHxColor.Length == 0)
  138. {//如果为空
  139. return System.Drawing.Color.FromArgb(255, 255, 204);//设为白色
  140. }
  141. else
  142. {//转换颜色
  143. 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));
  144. }
  145. }
  146. catch
  147. {//设为白色
  148. return System.Drawing.Color.FromArgb(255, 255, 204);
  149. }
  150. }
  151. float AmplificationFactor = 1;
  152. //private void button_Extend_Click(object sender, EventArgs e)
  153. //{
  154. // if (button_Extend.BackColor == SystemColors.ControlDarkDark)
  155. // {
  156. // //groupBox_Data.Visible = true;
  157. // textbox_STDEditor.Height = (int)Math.Round(150 * AmplificationFactor);
  158. // button_Extend.BackColor = SystemColors.ControlDark;
  159. // }
  160. // else
  161. // {
  162. // button_Extend.BackColor = SystemColors.ControlDarkDark;
  163. // textbox_STDEditor.Height = (int)Math.Round(300* AmplificationFactor);
  164. // }
  165. //}
  166. private void comboBox_Elem1_SelectedIndexChanged(object sender, EventArgs e)
  167. {
  168. string newStr = comboBox_Elem1.SelectedItem.ToString();
  169. int index = textbox_STDEditor.SelectionStart;
  170. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, newStr);
  171. textbox_STDEditor.Focus();
  172. textbox_STDEditor.Select(index + newStr.Length, 0);
  173. textbox_STDEditor.ScrollToCaret();
  174. }
  175. private void comboBox_Elem2_SelectedIndexChanged(object sender, EventArgs e)
  176. {
  177. string newStr = comboBox_Elem.SelectedItem.ToString();
  178. int index = textbox_STDEditor.SelectionStart;
  179. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, newStr);
  180. textbox_STDEditor.Focus();
  181. textbox_STDEditor.Select(index + newStr.Length, 0);
  182. textbox_STDEditor.ScrollToCaret();
  183. }
  184. private void comboBox_ImgProperty_SelectedIndexChanged(object sender, EventArgs e)
  185. {
  186. string newStr = comboBox_ImgProperty.SelectedItem.ToString();
  187. int index = textbox_STDEditor.SelectionStart;
  188. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, newStr);
  189. textbox_STDEditor.Focus();
  190. textbox_STDEditor.Select(index + newStr.Length, 0);
  191. textbox_STDEditor.ScrollToCaret();
  192. }
  193. private void button_Plus_Click(object sender, EventArgs e)
  194. {
  195. //textbox_STDEditor 中的光标
  196. int index = textbox_STDEditor.SelectionStart;
  197. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "+");
  198. textbox_STDEditor.Focus();
  199. textbox_STDEditor.Select(index + 1, 0);
  200. textbox_STDEditor.ScrollToCaret();
  201. }
  202. private void button_Subtract_Click(object sender, EventArgs e)
  203. {
  204. //textbox_STDEditor 中的光标
  205. int index = textbox_STDEditor.SelectionStart;
  206. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "-");
  207. textbox_STDEditor.Focus();
  208. textbox_STDEditor.Select(index + 1, 0);
  209. textbox_STDEditor.ScrollToCaret();
  210. }
  211. private void button_Multiply_Click(object sender, EventArgs e)
  212. {
  213. //textbox_STDEditor 中的光标
  214. int index = textbox_STDEditor.SelectionStart;
  215. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "*");
  216. textbox_STDEditor.Focus();
  217. textbox_STDEditor.Select(index + 1, 0);
  218. textbox_STDEditor.ScrollToCaret();
  219. }
  220. private void button_Divide_Click(object sender, EventArgs e)
  221. {
  222. //textbox_STDEditor 中的光标
  223. int index = textbox_STDEditor.SelectionStart;
  224. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "/");
  225. textbox_STDEditor.Focus();
  226. textbox_STDEditor.Select(index + 1, 0);
  227. textbox_STDEditor.ScrollToCaret(); ;
  228. }
  229. private void button_More_Click(object sender, EventArgs e)
  230. {
  231. //textbox_STDEditor 中的光标
  232. int index = textbox_STDEditor.SelectionStart;
  233. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, ">");
  234. textbox_STDEditor.Focus();
  235. textbox_STDEditor.Select(index + 1, 0);
  236. textbox_STDEditor.ScrollToCaret();
  237. }
  238. private void button_Less_Click(object sender, EventArgs e)
  239. {
  240. //textbox_STDEditor 中的光标
  241. int index = textbox_STDEditor.SelectionStart;
  242. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "<");
  243. textbox_STDEditor.Focus();
  244. textbox_STDEditor.Select(index + 1, 0);
  245. textbox_STDEditor.ScrollToCaret();
  246. }
  247. private void button_LeftParenthesis_Click(object sender, EventArgs e)
  248. {
  249. //textbox_STDEditor 中的光标
  250. int index = textbox_STDEditor.SelectionStart;
  251. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "(");
  252. textbox_STDEditor.Focus();
  253. textbox_STDEditor.Select(index + 1, 0);
  254. textbox_STDEditor.ScrollToCaret();
  255. }
  256. private void button_RightParenthesis_Click(object sender, EventArgs e)
  257. {
  258. //textbox_STDEditor 中的光标
  259. int index = textbox_STDEditor.SelectionStart;
  260. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, ")");
  261. textbox_STDEditor.Focus();
  262. textbox_STDEditor.Select(index + 1, 0);
  263. textbox_STDEditor.ScrollToCaret();
  264. }
  265. private void button_Equal_Click(object sender, EventArgs e)
  266. {
  267. //textbox_STDEditor 中的光标
  268. int index = textbox_STDEditor.SelectionStart;
  269. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "=");
  270. textbox_STDEditor.Focus();
  271. textbox_STDEditor.Select(index + 1, 0);
  272. textbox_STDEditor.ScrollToCaret();
  273. }
  274. //元素下拉选择输入
  275. private void comboBox_PeriodicTable_SelectedIndexChanged(object sender, EventArgs e)
  276. {
  277. if (comboBox_PeriodicTable.Text != null && comboBox_PeriodicTable.SelectedItem != null)
  278. {
  279. string newStr = comboBox_PeriodicTable.SelectedItem.ToString();
  280. comboBox_PeriodicTable.Text = null;
  281. int index = textbox_STDEditor.SelectionStart;
  282. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, newStr);
  283. textbox_STDEditor.Focus();
  284. textbox_STDEditor.Select(index + newStr.Length, 0);
  285. textbox_STDEditor.ScrollToCaret();
  286. }
  287. }
  288. private void button_And_Click(object sender, EventArgs e)
  289. {
  290. //textbox_STDEditor 中的光标
  291. int index = textbox_STDEditor.SelectionStart;
  292. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "and");
  293. textbox_STDEditor.Focus();
  294. textbox_STDEditor.Select(index + 3, 0);
  295. textbox_STDEditor.ScrollToCaret();
  296. }
  297. private void button_Or_Click(object sender, EventArgs e)
  298. {
  299. //textbox_STDEditor 中的光标
  300. int index = textbox_STDEditor.SelectionStart;
  301. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "or");
  302. textbox_STDEditor.Focus();
  303. textbox_STDEditor.Select(index + 2, 0);
  304. textbox_STDEditor.ScrollToCaret();
  305. }
  306. private void comboBox_Constants_SelectedIndexChanged(object sender, EventArgs e)
  307. {
  308. if (comboBox_Constants.SelectedItem != null)
  309. {
  310. string newStr = comboBox_Constants.SelectedItem.ToString().Split('=')[0];
  311. int index = textbox_STDEditor.SelectionStart;
  312. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, newStr);
  313. textbox_STDEditor.Focus();
  314. textbox_STDEditor.Select(index + newStr.Length, 0);
  315. textbox_STDEditor.ScrollToCaret();
  316. }
  317. }
  318. private void button_1_Click(object sender, EventArgs e)
  319. {
  320. //textbox_STDEditor 中的光标
  321. int index = textbox_STDEditor.SelectionStart;
  322. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "1");
  323. textbox_STDEditor.Focus();
  324. textbox_STDEditor.Select(index + 1, 0);
  325. textbox_STDEditor.ScrollToCaret();
  326. }
  327. private void button_2_Click(object sender, EventArgs e)
  328. {
  329. //textbox_STDEditor 中的光标
  330. int index = textbox_STDEditor.SelectionStart;
  331. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "2");
  332. textbox_STDEditor.Focus();
  333. textbox_STDEditor.Select(index + 1, 0);
  334. textbox_STDEditor.ScrollToCaret();
  335. }
  336. private void button_3_Click(object sender, EventArgs e)
  337. {
  338. //textbox_STDEditor 中的光标
  339. int index = textbox_STDEditor.SelectionStart;
  340. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "3");
  341. textbox_STDEditor.Focus();
  342. textbox_STDEditor.Select(index + 1, 0);
  343. textbox_STDEditor.ScrollToCaret();
  344. }
  345. private void button_4_Click(object sender, EventArgs e)
  346. {
  347. //textbox_STDEditor 中的光标
  348. int index = textbox_STDEditor.SelectionStart;
  349. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "4");
  350. textbox_STDEditor.Focus();
  351. textbox_STDEditor.Select(index + 1, 0);
  352. textbox_STDEditor.ScrollToCaret();
  353. }
  354. private void button_5_Click(object sender, EventArgs e)
  355. {
  356. //textbox_STDEditor 中的光标
  357. int index = textbox_STDEditor.SelectionStart;
  358. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "5");
  359. textbox_STDEditor.Focus();
  360. textbox_STDEditor.Select(index + 1, 0);
  361. textbox_STDEditor.ScrollToCaret();
  362. }
  363. private void button_6_Click(object sender, EventArgs e)
  364. {
  365. //textbox_STDEditor 中的光标
  366. int index = textbox_STDEditor.SelectionStart;
  367. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "6");
  368. textbox_STDEditor.Focus();
  369. textbox_STDEditor.Select(index + 1, 0);
  370. textbox_STDEditor.ScrollToCaret();
  371. }
  372. private void button_7_Click(object sender, EventArgs e)
  373. {
  374. //textbox_STDEditor 中的光标
  375. int index = textbox_STDEditor.SelectionStart;
  376. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "7");
  377. textbox_STDEditor.Focus();
  378. textbox_STDEditor.Select(index + 1, 0);
  379. textbox_STDEditor.ScrollToCaret();
  380. }
  381. private void button_8_Click(object sender, EventArgs e)
  382. {
  383. //textbox_STDEditor 中的光标
  384. int index = textbox_STDEditor.SelectionStart;
  385. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "8");
  386. textbox_STDEditor.Focus();
  387. textbox_STDEditor.Select(index + 1, 0);
  388. textbox_STDEditor.ScrollToCaret();
  389. }
  390. private void button_9_Click(object sender, EventArgs e)
  391. {
  392. //textbox_STDEditor 中的光标
  393. int index = textbox_STDEditor.SelectionStart;
  394. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "9");
  395. textbox_STDEditor.Focus();
  396. textbox_STDEditor.Select(index + 1, 0);
  397. textbox_STDEditor.ScrollToCaret();
  398. }
  399. private void button_0_Click(object sender, EventArgs e)
  400. {
  401. int index = textbox_STDEditor.SelectionStart;
  402. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "0");
  403. textbox_STDEditor.Focus();
  404. textbox_STDEditor.Select(index + 1, 0);
  405. textbox_STDEditor.ScrollToCaret();
  406. }
  407. //元素自身text按回车键输入
  408. private void comboBox_PeriodicTable_KeyDown(object sender, KeyEventArgs e)
  409. {
  410. if (e.KeyValue == 13)
  411. {
  412. if (comboBox_PeriodicTable.Text != null && comboBox_PeriodicTable.Text != "")
  413. {
  414. this.textbox_STDEditor.Text += comboBox_PeriodicTable.Text.ToString();
  415. comboBox_PeriodicTable.Text = null;
  416. }
  417. }
  418. }
  419. //采集Xray 按钮事件
  420. private void btnCollectXray_Click(object sender, EventArgs e)
  421. {
  422. m_SubMidWindow.m_MainForm.IsModified = true;
  423. string strTime = txtCollectTime.Text.Trim();
  424. if (txtCollectTime.Equals(""))
  425. {
  426. showMessage("Please fill in the collection time name!");
  427. txtCollectTime.Focus();
  428. return;
  429. }
  430. if (!IsMatch(strTime, 1))
  431. {
  432. showMessage("Error collecting time content, the format should be integer!");
  433. txtCollectTime.Focus();
  434. return;
  435. }
  436. if (Convert.ToInt32(strTime) < 50)
  437. {
  438. showMessage("CollectTime must not be less than 100 milliseconds!");
  439. txtCollectTime.Focus();
  440. return;
  441. }
  442. //显示Xray
  443. xrayByteData = IntArrToByteArr(GetCollectXray(strTime));
  444. m_EDSHardwareMgr.DisConnect();
  445. int color = Convert.ToInt32(ParseRGB(colorHx16toRGB(m_SubMidWindow.m_MainForm.STDDictionary[STDId].Color)).ToString());
  446. //根据树节点修改对应的Xray信息
  447. UpdateSTDXray(STDId, xrayByteData);
  448. ShowXrayAtlas(color, xrayByteData);
  449. }
  450. /// <summary>
  451. /// 获取采集当前的Xray信息
  452. /// </summary>
  453. /// <returns></returns>
  454. protected uint[] GetCollectXray(string strTime)
  455. {
  456. //控制类对象初始化
  457. if (null == m_EDSHardwareMgr)
  458. {
  459. m_EDSHardwareMgr = EDSController.GetEDSController();
  460. }
  461. //1.连接电镜
  462. if (m_EDSHardwareMgr.Connect())
  463. {
  464. int iSize = 2000;
  465. uint[] iXrayData = new uint[iSize];
  466. //采集XRay数据
  467. if (m_EDSHardwareMgr.CollectSpectrum(uint.Parse(strTime), ref iXrayData))
  468. {
  469. return iXrayData;
  470. }
  471. }
  472. return null;
  473. }
  474. private void btnReadXray_Click(object sender, EventArgs e)
  475. {
  476. OpenFileDialog fileSel = new OpenFileDialog();
  477. fileSel.Filter = "|*.txt";
  478. if (DialogResult.OK == fileSel.ShowDialog())
  479. {
  480. String str = "";
  481. //读取Xray文件
  482. using (StreamReader sr = new StreamReader(fileSel.FileName))
  483. {
  484. while (!sr.EndOfStream)
  485. {
  486. str += sr.ReadLine() + ",";
  487. }
  488. str = str.Substring(0, str.Length - 1);
  489. string[] xrayData = str.Split(',');
  490. if (xrayData.Length != 2000)
  491. {
  492. return;
  493. }
  494. uint[] data = new uint[xrayData.Length];
  495. for (int i = 0; i < xrayData.Length; i++)
  496. {
  497. data[i] = Convert.ToUInt32(xrayData[i]);
  498. }
  499. //Xray数据
  500. xrayByteData = IntArrToByteArr(data);
  501. int color = Convert.ToInt32(ParseRGB(colorHx16toRGB(m_SubMidWindow.m_MainForm.STDDictionary[STDId].Color)).ToString());
  502. //根据树节点修改对应的Xray信息
  503. UpdateSTDXray(STDId, xrayByteData);
  504. ShowXrayAtlas(color, xrayByteData);
  505. }
  506. }
  507. }
  508. /// <summary>
  509. /// 将int[] 转换为 byte[]
  510. /// </summary>
  511. /// <param name="intArr"></param>
  512. /// <returns></returns>
  513. public static byte[] IntArrToByteArr(uint[] intArr)
  514. {
  515. int intSize = sizeof(uint) * intArr.Length;
  516. byte[] bytArr = new byte[intSize];
  517. //申请一块非托管内存  
  518. //IntPtr ptr = Marshal.AllocHGlobal(intSize);
  519. ////复制int数组到该内存块  
  520. //Marshal.Copy(intArr, 0, ptr, intArr.Length);
  521. ////复制回byte数组  
  522. //Marshal.Copy(ptr, bytArr, 0, bytArr.Length);
  523. ////释放申请的非托管内存  
  524. //Marshal.FreeHGlobal(ptr);
  525. for (int i = 0; i < intArr.Length; i++)
  526. {
  527. byte[] c1 = BitConverter.GetBytes(intArr[i]);
  528. c1.CopyTo(bytArr, i * 4);
  529. }
  530. return bytArr;
  531. }
  532. /// <summary>
  533. /// 将颜色对象转换为uint
  534. /// </summary>
  535. /// <param name="color"></param>
  536. /// <returns></returns>
  537. public uint ParseRGB(Color color)
  538. {
  539. return (uint)(((uint)color.B << 16) | (ushort)(((ushort)color.G << 8) | color.R));
  540. }
  541. #region 显示Xray图谱
  542. /// <summary>
  543. /// 显示Xray图谱
  544. /// </summary>
  545. public void ShowXrayAtlas(int colorValue = 0, byte[] XrayData = null)
  546. {
  547. DataTable dt = new DataTable();
  548. dt.Columns.Add("Color", typeof(int));
  549. dt.Columns.Add("SPEC", typeof(byte[]));
  550. DataRow dRow = dt.NewRow();
  551. dRow["Color"] = colorValue;
  552. if (XrayData != null)
  553. {
  554. dRow["SPEC"] = XrayData;
  555. }
  556. else
  557. {
  558. dRow["SPEC"] = new byte[8000];
  559. }
  560. //将选择行的数据传递给Xray控件
  561. XrayControl.Dr = dRow;
  562. XrayControl.Refresh();
  563. XrayData = null;
  564. }
  565. #endregion
  566. #region 常用数据验证的封装,数字字符的验证
  567. /// <summary>
  568. /// 常用数据验证的封装,数字字符的验证
  569. /// </summary>
  570. /// <param name="inputVal">需要验证的数值【字符串,或者数字】</param>
  571. /// <param name="type">类型为哪一个验证</param>
  572. /// <returns>如果验证成功则返回True,否则返回false</returns>
  573. public bool IsMatch(string inputVal, int type)
  574. {
  575. switch (type)
  576. {
  577. case 0:
  578. return Regex.IsMatch(inputVal, @"^[1-9]d*$"); //匹配正整数
  579. case 1:
  580. return Regex.IsMatch(inputVal, @"^-?\d+$"); //匹配整数
  581. case 2:
  582. return Regex.IsMatch(inputVal, @"^[A-Za-z0-9]+$"); //匹配由数字和26个英文字母组成的字符串
  583. case 3:
  584. 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]*))$"); //匹配正浮点数
  585. case 4:
  586. return Regex.IsMatch(inputVal, @"^[\u4e00-\u9fa5]{0,}$"); //匹配汉字
  587. case 5:
  588. return Regex.IsMatch(inputVal, @"^[0-9]+(.[0-9]{1,3})?$"); //匹配1~3位小数的正实数
  589. case 6:
  590. return Regex.IsMatch(inputVal, @"^[A-Za-z]+$"); //匹配英文字符
  591. default:
  592. return true;
  593. }
  594. }
  595. #endregion
  596. #region 弹出提示
  597. /// <summary>
  598. /// 弹出提示
  599. /// </summary>
  600. /// <param name="strContent"></param>
  601. protected void showMessage(string strContent)
  602. {
  603. MessageBox.Show(strContent, "Tip");
  604. }
  605. #endregion
  606. #region Xray 与 STDDB数据操作
  607. /// <summary>
  608. /// 标准Xray状态
  609. /// </summary>
  610. public enum STDXrayInfoState
  611. {
  612. Add = 0,
  613. Modify = 1,
  614. Delete = 2
  615. }
  616. /// <summary>
  617. /// 记录修改后的标准中的Xray信息
  618. /// </summary>
  619. public class STDXray
  620. {
  621. /// <summary>
  622. /// 标准编号
  623. /// </summary>
  624. private string stdID;
  625. /// <summary>
  626. /// Xray数据
  627. /// </summary>
  628. private byte[] xrayData;
  629. /// <summary>
  630. /// 状态
  631. /// </summary>
  632. private int infoState = -1;
  633. public string StdID { get => stdID; set => stdID = value; }
  634. public byte[] XrayData { get => xrayData; set => xrayData = value; }
  635. public int InfoState { get => infoState; set => infoState = value; }
  636. }
  637. /// <summary>
  638. /// 绑定数据库中已存在的Xray信息
  639. /// </summary>
  640. public void BindSTDXray()
  641. {
  642. //清空STDXray列表中的集合
  643. m_STDXrayList.Clear();
  644. //查询
  645. DataTable dt = m_sc.GetDTFormSysSTDBySQLString("select Id,SPEC from STDMinerals");
  646. if (dt != null)
  647. {
  648. if (dt.Rows.Count > 0)
  649. {
  650. foreach (DataRow item in dt.Rows)
  651. {
  652. STDXray sXray = new STDXray();
  653. sXray.StdID = item["Id"].ToString();
  654. sXray.XrayData = (byte[])item["SPEC"];
  655. sXray.InfoState = 1;
  656. m_STDXrayList.Add(sXray);
  657. }
  658. }
  659. }
  660. }
  661. bool SaveOtherDataToXray(string STDDBAddress, int id)
  662. {
  663. #region 数据库存贮方式一
  664. System.Data.SQLite.SQLiteConnection m_dbConnection = new System.Data.SQLite.SQLiteConnection("data source='" + STDDBAddress + "'");
  665. System.Data.SQLite.SQLiteCommand cmm = m_dbConnection.CreateCommand();
  666. try
  667. {
  668. m_dbConnection.Open();
  669. //string insertstr = ("insert into STDMinerals(name,formula,density,Hardness,BSEValue,Electrical_conductivity,color,Element) values(" + m_SubMidWindow.m_MainForm.STDDictionary[id].StrName + "," + m_SubMidWindow.m_MainForm.STDDictionary[id].Formula + "," + m_SubMidWindow.m_MainForm.STDDictionary[id].Density + "," + m_SubMidWindow.m_MainForm.STDDictionary[id].Hardness + "," + m_SubMidWindow.m_MainForm.STDDictionary[id].BSE + "," + m_SubMidWindow.m_MainForm.STDDictionary[id].Electrical_conductivity + "," + m_SubMidWindow.m_MainForm.STDDictionary[id].Color + "," + m_SubMidWindow.m_MainForm.STDDictionary[id].Element + ");");
  670. string insertstr = ("insert into STDMinerals(name) values(" + m_SubMidWindow.m_MainForm.STDDictionary[id].StrName + ");");
  671. cmm.CommandText = insertstr;
  672. cmm.ExecuteNonQuery();
  673. }
  674. catch (Exception ex)
  675. {
  676. MessageBox.Show(ex.ToString());
  677. return false;
  678. }
  679. m_dbConnection.Close();
  680. #endregion
  681. return true;
  682. }
  683. /// <summary>
  684. /// 保存STDXray至数据库
  685. /// </summary>
  686. public void SaveSTDXray()
  687. {
  688. ArrayList delArrayList = new ArrayList();
  689. if (m_STDXrayList != null)
  690. {
  691. //if (m_STDXrayList.Count > 0)
  692. //{
  693. foreach (STDXray item in m_STDXrayList)
  694. {
  695. int infoState = item.InfoState;
  696. //添加状态 根据Xray信息当前只能按照一条操作
  697. if (infoState == (int)STDXrayInfoState.Add)
  698. {
  699. //if (item.XrayData == null)
  700. //{
  701. // item.XrayData = new byte[8000];
  702. //}
  703. //string strvaluename = "@data";
  704. ////编辑添加语句
  705. //StringBuilder strSqlAdd = new StringBuilder();
  706. //strSqlAdd.Append("insert into STDMinerals(Id,SPEC) values(" + item.StdID + "," + strvaluename + ");");
  707. //bool addResult = m_sc.ExecuteBlob(strSqlAdd.ToString(), strvaluename, (byte[])item.XrayData, ((byte[])item.XrayData).Length);
  708. bool addResult = false;
  709. //判断STDID在数据库中是否存在
  710. bool selResult = SelSTDDBBySTDId(item.StdID);
  711. if (selResult)
  712. {
  713. //addResult = UpdateSTDDB(item.StdID, xrayByteData);
  714. addResult = UpdateSTDDB(item.StdID, item.XrayData);
  715. }
  716. else
  717. {
  718. addResult = AddSTDDB(item.StdID, item.XrayData);
  719. }
  720. if (!addResult)
  721. {
  722. continue;
  723. }
  724. }
  725. //修改状态
  726. else if (infoState == (int)STDXrayInfoState.Modify)
  727. {
  728. //判断STDID在数据库中是否存在
  729. bool selResult = SelSTDDBBySTDId(item.StdID);
  730. if (selResult)
  731. {
  732. UpdateSTDDB(item.StdID, item.XrayData);
  733. }
  734. else
  735. {
  736. AddSTDDB(item.StdID, item.XrayData);
  737. }
  738. }
  739. //删除状态 编辑批量删除语句
  740. else if (infoState == (int)STDXrayInfoState.Delete)
  741. {
  742. //编辑删除语句
  743. delArrayList.Add("delete from STDMinerals where id=" + item.StdID + ";");
  744. }
  745. }
  746. //批量删除
  747. if (delArrayList.Count > 0)
  748. {
  749. bool delResult = m_sc.DelSTDInfo(delArrayList);
  750. }
  751. //}
  752. }
  753. }
  754. /// <summary>
  755. /// 添加STD信息至数据库
  756. /// </summary>
  757. protected bool AddSTDDB(string stdID, byte[] XrayData)
  758. {
  759. if (XrayData == null)
  760. {
  761. XrayData = new byte[8000];
  762. }
  763. string strvaluename = "@data";
  764. StringBuilder sqlStrAdd = new StringBuilder();
  765. sqlStrAdd.Append("insert into STDMinerals(Id,SPEC) values(" + stdID + "," + strvaluename + ");");
  766. bool addResult = m_sc.ExecuteBlob(sqlStrAdd.ToString(), strvaluename, (byte[])XrayData, ((byte[])XrayData).Length);
  767. return addResult;
  768. }
  769. /// <summary>
  770. /// 修改STD信息至数据库
  771. /// </summary>
  772. protected bool UpdateSTDDB(string stdID, byte[] XrayData)
  773. {
  774. if (XrayData == null)
  775. {
  776. XrayData = new byte[8000];
  777. }
  778. string strValueName = "@data";
  779. StringBuilder sqlStrUpdate = new StringBuilder();
  780. sqlStrUpdate.Append("update STDMinerals set SPEC=" + strValueName +" where id=" + stdID + ";");
  781. bool updateResult = m_sc.ExecuteBlob(sqlStrUpdate.ToString(), strValueName, (byte[])XrayData, ((byte[])XrayData).Length);
  782. return updateResult;
  783. }
  784. /// <summary>
  785. /// 查询是否存在标准编号
  786. /// </summary>
  787. /// <param name="stdID"></param>
  788. protected bool SelSTDDBBySTDId(string stdID)
  789. {
  790. bool selResult = false;
  791. //编辑查询语句
  792. StringBuilder sqlStr = new StringBuilder();
  793. sqlStr.Append("select * from STDMinerals where id=" + stdID + "");
  794. DataTable dt = m_sc.GetDTFormSysSTDBySQLString(sqlStr.ToString());
  795. if (dt != null)
  796. {
  797. if (dt.Rows.Count > 0)
  798. {
  799. //已存在状态
  800. selResult = true;
  801. }
  802. }
  803. return selResult;
  804. }
  805. /// <summary>
  806. /// 根据选择树节点显示对应的Xray信息
  807. /// </summary>
  808. public void SelSTDXray(int Key, STDdata sT)
  809. {
  810. if (sT == null)
  811. {
  812. return;
  813. }
  814. if (m_STDXrayList != null)
  815. {
  816. //if (m_STDXrayList.Count > 0)
  817. //{
  818. bool isExists = false;
  819. foreach (STDXray item in m_STDXrayList)
  820. {
  821. //修改XrayData信息
  822. if (item.StdID == Key.ToString())
  823. {
  824. string selColor = ParseRGB(colorHx16toRGB(sT.Color)).ToString();
  825. int colorValue = Convert.ToInt32(selColor);
  826. //显示Xray信息
  827. if (item.XrayData != null)
  828. {
  829. isExists = true;
  830. ShowXrayAtlas(colorValue, item.XrayData);
  831. }
  832. break;
  833. }
  834. }
  835. if (!isExists)
  836. {
  837. ShowXrayAtlas();
  838. }
  839. //}
  840. }
  841. }
  842. public void ShowEditContent(string stdID)
  843. {
  844. if (m_STDXrayList != null)
  845. {
  846. for (int i = 0; i < m_STDXrayList.Count; i++)
  847. {
  848. if (m_STDXrayList[i].StdID == stdID)
  849. {
  850. //获取修改行的信息
  851. xrayByteData = (byte[])m_STDXrayList[i].XrayData;
  852. }
  853. }
  854. }
  855. }
  856. /// <summary>
  857. /// 根据STDId修改对应的Xray信息
  858. /// </summary>
  859. /// <param name="STDId"></param>
  860. protected void UpdateSTDXray(int STDId, byte[] xrayData)
  861. {
  862. if (m_STDXrayList != null)
  863. {
  864. //if (m_STDXrayList.Count > 0)
  865. //{
  866. bool isExists = false;
  867. foreach (STDXray item in m_STDXrayList)
  868. {
  869. //修改XrayData信息
  870. if (item.StdID == STDId.ToString())
  871. {
  872. item.XrayData = xrayData;
  873. item.InfoState = (int)STDXrayInfoState.Modify;
  874. isExists = true;
  875. break;
  876. }
  877. }
  878. if (!isExists)
  879. {
  880. if (!STDId.ToString().Equals(""))
  881. {
  882. //添加STD XrayData信息
  883. STDXray stdXray = new STDXray();
  884. stdXray.StdID = STDId.ToString();
  885. stdXray.XrayData = xrayData;
  886. stdXray.InfoState = (int)STDXrayInfoState.Add;
  887. m_STDXrayList.Add(stdXray);
  888. }
  889. }
  890. //}
  891. }
  892. }
  893. /// <summary>
  894. /// 添加STDXray信息
  895. /// </summary>
  896. /// <param name="STDid">STDid</param>
  897. /// <param name="xrayData">Xray信息</param>
  898. /// <returns></returns>
  899. protected bool AddSTDXray(int STDId, byte[] xrayData)
  900. {
  901. bool addResult = false;
  902. if (m_STDXrayList != null)
  903. {
  904. //if (m_STDXrayList.Count > 0)
  905. //{
  906. if (!STDId.ToString().Equals(""))
  907. {
  908. //添加STD XrayData信息
  909. STDXray stdXray = new STDXray();
  910. stdXray.StdID = STDId.ToString();
  911. stdXray.XrayData = xrayData;
  912. stdXray.InfoState = (int)STDXrayInfoState.Add;
  913. m_STDXrayList.Add(stdXray);
  914. addResult = true;
  915. }
  916. //}
  917. }
  918. return addResult;
  919. }
  920. /// <summary>
  921. /// 删除STDXray信息
  922. /// </summary>
  923. /// <param name="STDId">所选要删除的STDId</param>
  924. /// <returns></returns>
  925. public bool DelSTDXray(int STDId)
  926. {
  927. bool delResult = false;
  928. if (m_STDXrayList != null)
  929. {
  930. //if (m_STDXrayList.Count > 0)
  931. //{
  932. if (!STDId.ToString().Equals(""))
  933. {
  934. foreach (STDXray item in m_STDXrayList)
  935. {
  936. //修改XrayData信息
  937. if (item.StdID == STDId.ToString())
  938. {
  939. item.InfoState = (int)STDXrayInfoState.Delete;
  940. delResult = true;
  941. break;
  942. }
  943. }
  944. }
  945. //}
  946. }
  947. return delResult;
  948. }
  949. #endregion
  950. #region 控制BSE、化学式、元素本文框中不能输入下划线
  951. /// <summary>
  952. /// 控件不能输入下划线
  953. /// </summary>
  954. /// <param name="sender"></param>
  955. /// <param name="e"></param>
  956. private void textBox_KeyPress(object sender, KeyPressEventArgs e)
  957. {
  958. if ((e.KeyChar >= '0' && e.KeyChar <= '9') || (e.KeyChar >= 'A' && e.KeyChar <= 'Z') ||
  959. (e.KeyChar >= 'a' && e.KeyChar <= 'z') || (e.KeyChar == 8) || !(e.KeyChar == '_'))
  960. {
  961. e.Handled = false;
  962. }
  963. else
  964. {
  965. e.Handled = true;
  966. }
  967. }
  968. #endregion
  969. private void btnTest_Click(object sender, EventArgs e)
  970. {
  971. XrayContrastForm xrayContrastForm = new XrayContrastForm();
  972. xrayContrastForm.STDDictionary = m_SubMidWindow.m_MainForm.STDDictionary;
  973. xrayContrastForm.ShowDialog();
  974. }
  975. string ElementKeyOrSub = "";
  976. private void dataGridView_KeyElements_CellClick(object sender, DataGridViewCellEventArgs e)
  977. {
  978. ElementKeyOrSub = dataGridView_KeyElements.CurrentCell.Value.ToString();
  979. dataGridView_KeyElements.Columns.RemoveAt(e.ColumnIndex);
  980. DataGridViewButtonColumn dataGridViewButtonColumn = new DataGridViewButtonColumn();
  981. dataGridViewButtonColumn.Name = dataGridView_SubElements.Columns.Count.ToString();
  982. dataGridView_SubElements.Columns.Add(dataGridViewButtonColumn);
  983. if (dataGridView_SubElements.Rows.Count == 0)
  984. {
  985. DataGridViewRow row = new DataGridViewRow();
  986. dataGridView_SubElements.Rows.Add(row);
  987. }
  988. dataGridView_SubElements.Rows[0].Cells[dataGridView_SubElements.Columns.Count - 1].Value = ElementKeyOrSub;
  989. dataGridView_SubElements.ClearSelection();
  990. dataGridView_KeyElements.ClearSelection();
  991. }
  992. private void dataGridView_SubElements_CellClick(object sender, DataGridViewCellEventArgs e)
  993. {
  994. ElementKeyOrSub = dataGridView_SubElements.CurrentCell.Value.ToString();
  995. dataGridView_SubElements.Columns.RemoveAt(e.ColumnIndex);
  996. DataGridViewButtonColumn dataGridViewButtonColumn = new DataGridViewButtonColumn();
  997. dataGridViewButtonColumn.Name = dataGridView_SubElements.Columns.Count.ToString();
  998. dataGridView_KeyElements.Columns.Add(dataGridViewButtonColumn);
  999. if (dataGridView_KeyElements.Rows.Count == 0)
  1000. {
  1001. DataGridViewRow row = new DataGridViewRow();
  1002. dataGridView_KeyElements.Rows.Add(row);
  1003. }
  1004. dataGridView_KeyElements.Rows[0].Cells[dataGridView_KeyElements.Columns.Count - 1].Value = ElementKeyOrSub;
  1005. dataGridView_KeyElements.ClearSelection();
  1006. dataGridView_SubElements.ClearSelection();
  1007. }
  1008. private float X=1;
  1009. private float Y=1;
  1010. private void STDEditor_Resize(object sender, EventArgs e)
  1011. {
  1012. float newx = (this.Width) / X;
  1013. float newy = this.Height/ Y;
  1014. AmplificationFactor = newy;
  1015. setControls(newx, newy, this.tabSTDStandrad.TabPages[0]);
  1016. //button_Extend.BackColor = SystemColors.ControlDarkDark;
  1017. }
  1018. private void setTag(Control cons)
  1019. {
  1020. foreach (Control con in cons.Controls)
  1021. {
  1022. con.Tag = con.Width + ":" + con.Height + ":" + con.Left + ":" + con.Top + ":" + con.Font.Size;
  1023. if (con.Controls.Count > 0)
  1024. setTag(con);
  1025. }
  1026. }
  1027. private void setControls(float newx, float newy, Control cons)
  1028. {
  1029. foreach (Control con in cons.Controls)
  1030. {
  1031. if (false)
  1032. {
  1033. }
  1034. else
  1035. {
  1036. string[] mytag = con.Tag.ToString().Split(':');
  1037. float a = Convert.ToSingle(mytag[0]) * newx;
  1038. con.Width = (int)a;
  1039. a = Convert.ToSingle(mytag[1]) * newy;
  1040. con.Height = (int)(a);
  1041. a = Convert.ToSingle(mytag[2]) * newx;
  1042. con.Left = (int)(a);
  1043. a = Convert.ToSingle(mytag[3]) * newy;
  1044. con.Top = (int)(a);
  1045. Single currentSize ;
  1046. if (con.Name == "button_Extend")
  1047. {
  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. Form_PeriodicTable form_PeriodicTable;
  1070. private void button_PeriodicTableSwitch_Click(object sender, EventArgs e)
  1071. {
  1072. if (form_PeriodicTable == null) //如果子窗体为空则创造实例 并显示
  1073. {
  1074. form_PeriodicTable = new Form_PeriodicTable();
  1075. if (table_STDEditor["language"].ToString() == "EN")
  1076. {
  1077. form_PeriodicTable.BackgroundImage = global::OTSPartA_STDEditor.Properties.Resources.PeriodicTable_EN;
  1078. }
  1079. else
  1080. {
  1081. form_PeriodicTable.BackgroundImage = global::OTSPartA_STDEditor.Properties.Resources.PeriodicTable_ZH;
  1082. }
  1083. form_PeriodicTable.Show();
  1084. }
  1085. else
  1086. {
  1087. if (form_PeriodicTable.IsDisposed) //若子窗体关闭 则打开新子窗体 并显示
  1088. {
  1089. form_PeriodicTable = new Form_PeriodicTable();
  1090. if (table_STDEditor["language"].ToString() == "EN")
  1091. {
  1092. form_PeriodicTable.BackgroundImage = global::OTSPartA_STDEditor.Properties.Resources.PeriodicTable_EN;
  1093. }
  1094. else
  1095. {
  1096. form_PeriodicTable.BackgroundImage = global::OTSPartA_STDEditor.Properties.Resources.PeriodicTable_ZH;
  1097. }
  1098. form_PeriodicTable.Show();
  1099. }
  1100. else
  1101. {
  1102. form_PeriodicTable.Activate(); //使子窗体获得焦点
  1103. }
  1104. }
  1105. }
  1106. private void button_ImportFromResult_Click(object sender, EventArgs e)
  1107. {
  1108. OpenFileDialog openFileDialog = new OpenFileDialog();
  1109. openFileDialog.Filter = "(*.db)|*.db";
  1110. openFileDialog.RestoreDirectory = true;
  1111. openFileDialog.FilterIndex = 1;
  1112. if (openFileDialog.ShowDialog() == DialogResult.OK)
  1113. {
  1114. try
  1115. {
  1116. System.Data.SQLite.SQLiteConnection m_dbConnection = new System.Data.SQLite.SQLiteConnection("data source='" + openFileDialog.FileName + "'");
  1117. m_dbConnection.Open();
  1118. string STDId = m_SubMidWindow.m_MainForm.m_STDRuleslist.Grid_Minerals[m_SubMidWindow.m_MainForm.m_STDRuleslist.Grid_Minerals.Selection.ActivePosition.Row, m_SubMidWindow.m_MainForm.m_STDRuleslist.Grid_Minerals.Selection.ActivePosition.Column].Tag.ToString();
  1119. Result ret=ImportFromResult(STDId, m_dbConnection);
  1120. if(ret== Result.NoMatched)
  1121. {
  1122. MessageBox.Show("No matching energy spectrum data was found", "Tip");
  1123. }
  1124. m_dbConnection.Close();
  1125. int color = Convert.ToInt32(ParseRGB(colorHx16toRGB(m_SubMidWindow.m_MainForm.STDDictionary[int.Parse(STDId)].Color)).ToString());
  1126. for(int i=0;i< m_STDXrayList.Count;i++)
  1127. {
  1128. if(m_STDXrayList[i].StdID== STDId)
  1129. {
  1130. ShowXrayAtlas(color, m_STDXrayList[i].XrayData);
  1131. break;
  1132. }
  1133. }
  1134. }
  1135. catch /*(Exception ex)*/
  1136. {
  1137. MessageBox.Show("Failed to load Xray data!", "Tip");
  1138. }
  1139. }
  1140. }
  1141. public Result ImportFromResult(string STDId, System.Data.SQLite.SQLiteConnection m_dbConnection)
  1142. {
  1143. try
  1144. {
  1145. System.Data.SQLite.SQLiteDataAdapter m_dataAdapter = new System.Data.SQLite.SQLiteDataAdapter("select FieldId ,XrayId from IncAData where TypeId ="+ STDId , m_dbConnection);
  1146. DataSet ds = new DataSet();
  1147. m_dataAdapter.Fill(ds);
  1148. DataTable dt = ds.Tables[0];
  1149. if (dt != null)
  1150. {
  1151. if (dt.Rows.Count > 0)
  1152. {
  1153. string sqlstr = "select XrayData from XRayData where FieldId = " + dt.Rows[0]["FieldId"] + " AND XrayIndex =" + dt.Rows[0]["XrayId"];
  1154. m_dataAdapter = new System.Data.SQLite.SQLiteDataAdapter(sqlstr, m_dbConnection);
  1155. ds = new DataSet();
  1156. m_dataAdapter.Fill(ds);
  1157. dt = ds.Tables[0];
  1158. if (dt != null)
  1159. {
  1160. if (dt.Rows.Count > 0)
  1161. {
  1162. DialogResult dr = MessageBox.Show("ID Num:" + STDId+ ", this rule has found the first match object, is it loaded?", "Tip", MessageBoxButtons.OKCancel);
  1163. if(dr == DialogResult.OK)
  1164. {
  1165. m_SubMidWindow.m_MainForm.IsModified = true;
  1166. if (SelSTDDBBySTDId(STDId))
  1167. {
  1168. if (MessageBox.Show("ID Num:" + STDId + ", the database already contains records of this rule XRay curve, is it overwritten?", "Tip", MessageBoxButtons.OKCancel) == DialogResult.OK)
  1169. {
  1170. UpdateSTDXray(int.Parse(STDId), (byte[])dt.Rows[0]["XrayData"]);
  1171. }
  1172. }
  1173. else
  1174. {
  1175. UpdateSTDXray(int.Parse(STDId), (byte[])dt.Rows[0]["XrayData"]);
  1176. }
  1177. }
  1178. return Result.Success;
  1179. }
  1180. else
  1181. {
  1182. return Result.NoMatched;
  1183. }
  1184. }
  1185. else
  1186. {
  1187. return Result.NoMatched;
  1188. }
  1189. }
  1190. else
  1191. {
  1192. return Result.NoMatched;
  1193. }
  1194. }
  1195. else
  1196. {
  1197. return Result.NoMatched;
  1198. }
  1199. }
  1200. catch /*(Exception ee)*/
  1201. {
  1202. MessageBox.Show("Failed to load Xray data!", "Tip");
  1203. return Result.Fail;
  1204. }
  1205. }
  1206. private void textbox_STDEditor_MouseLeave(object sender, EventArgs e)
  1207. {
  1208. dataGridView_KeyElements.Rows.Clear();
  1209. dataGridView_KeyElements.Columns.Clear();
  1210. string str_RemoveBlank = textbox_STDEditor.Text.ToString().Replace(" ", "");
  1211. str_RemoveBlank = str_RemoveBlank.Replace("\r\n", "");
  1212. str_RemoveBlank = str_RemoveBlank.Replace("forth_elem", "");
  1213. string[] str_Removeand = System.Text.RegularExpressions.Regex.Split(str_RemoveBlank, "and", System.Text.RegularExpressions.RegexOptions.None);
  1214. List<string> str_Removeandor = new List<string>();
  1215. for (int i = 0; i < str_Removeand.Length; i++)
  1216. {
  1217. str_Removeandor.AddRange(System.Text.RegularExpressions.Regex.Split(str_Removeand[i], "or", System.Text.RegularExpressions.RegexOptions.None));
  1218. }
  1219. List<string> list_all = new List<string>();
  1220. for (int i = 0; i < str_Removeandor.Count; i++)
  1221. {
  1222. list_all.AddRange(str_Removeandor[i].Split(new char[] { '+', '-', '*', '/', '=', '>', '<', '(', ')' }));
  1223. }
  1224. List<string> UsingElementL = new List<string>();
  1225. for (int i = 0; i < list_all.Count; i++)
  1226. {
  1227. if (this.comboBox_PeriodicTable.Items.Contains(list_all[i]))
  1228. {
  1229. if (!UsingElementL.Contains(list_all[i]))
  1230. {
  1231. UsingElementL.Add(list_all[i]);
  1232. }
  1233. }
  1234. }
  1235. List<string> SubElements = new List<string>();
  1236. for (int i = 0; i < dataGridView_SubElements.ColumnCount; i++)
  1237. {
  1238. if (UsingElementL.Contains(dataGridView_SubElements.Rows[0].Cells[i].Value))
  1239. {
  1240. SubElements.Add(dataGridView_SubElements.Rows[0].Cells[i].Value.ToString());
  1241. }
  1242. }
  1243. dataGridView_SubElements.Rows.Clear();
  1244. dataGridView_SubElements.Columns.Clear();
  1245. for (int i = 0; i < SubElements.Count; i++)
  1246. {
  1247. DataGridViewButtonColumn dataGridViewButtonColumn = new DataGridViewButtonColumn();
  1248. dataGridViewButtonColumn.Name = dataGridView_SubElements.Columns.Count.ToString();
  1249. dataGridView_SubElements.Columns.Add(dataGridViewButtonColumn);
  1250. if (dataGridView_SubElements.Rows.Count == 0)
  1251. {
  1252. DataGridViewRow row = new DataGridViewRow();
  1253. dataGridView_SubElements.Rows.Add(row);
  1254. }
  1255. dataGridView_SubElements.Rows[0].Cells[dataGridView_SubElements.ColumnCount - 1].Value = SubElements[i];
  1256. }
  1257. if (SubElements.Count > 0)
  1258. {
  1259. for (int i = 0; i < UsingElementL.Count; i++)
  1260. {
  1261. if (!SubElements.Contains(UsingElementL[i]))
  1262. {
  1263. DataGridViewButtonColumn dataGridViewButtonColumn = new DataGridViewButtonColumn();
  1264. dataGridViewButtonColumn.Name = dataGridView_KeyElements.Columns.Count.ToString();
  1265. dataGridView_KeyElements.Columns.Add(dataGridViewButtonColumn);
  1266. if (dataGridView_KeyElements.Rows.Count == 0)
  1267. {
  1268. DataGridViewRow row = new DataGridViewRow();
  1269. dataGridView_KeyElements.Rows.Add(row);
  1270. }
  1271. dataGridView_KeyElements.Rows[0].Cells[dataGridView_KeyElements.ColumnCount - 1].Value = UsingElementL[i];
  1272. }
  1273. }
  1274. }
  1275. else
  1276. {
  1277. for (int i = 0; i < UsingElementL.Count; i++)
  1278. {
  1279. DataGridViewButtonColumn dataGridViewButtonColumn = new DataGridViewButtonColumn();
  1280. dataGridViewButtonColumn.Name = dataGridView_KeyElements.Columns.Count.ToString();
  1281. dataGridView_KeyElements.Columns.Add(dataGridViewButtonColumn);
  1282. if (dataGridView_KeyElements.Rows.Count == 0)
  1283. {
  1284. DataGridViewRow row = new DataGridViewRow();
  1285. dataGridView_KeyElements.Rows.Add(row);
  1286. }
  1287. dataGridView_KeyElements.Rows[0].Cells[i].Value = UsingElementL[i];
  1288. }
  1289. }
  1290. dataGridView_KeyElements.ClearSelection();
  1291. dataGridView_SubElements.ClearSelection();
  1292. }
  1293. public void ShowTabXray()
  1294. {
  1295. tabSTDStandrad.SelectedIndex = 1;
  1296. }
  1297. public void ShowSTD()
  1298. {
  1299. tabSTDStandrad.SelectedIndex = 0;
  1300. }
  1301. }
  1302. }