STDEditor.cs 61 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526
  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. COTSControlFunExport m_cfun = 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. #region 采集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(table_STDEditor["message33"].ToString());
  427. txtCollectTime.Focus();
  428. return;
  429. }
  430. if (!IsMatch(strTime, 1))
  431. {
  432. showMessage(table_STDEditor["message34"].ToString());
  433. txtCollectTime.Focus();
  434. return;
  435. }
  436. if (Convert.ToInt32(strTime) < 50)
  437. {
  438. showMessage(table_STDEditor["message35"].ToString());
  439. txtCollectTime.Focus();
  440. return;
  441. }
  442. //显示Xray
  443. xrayByteData = IntArrToByteArr(GetCollectXray(strTime));
  444. int color = Convert.ToInt32(ParseRGB(colorHx16toRGB(m_SubMidWindow.m_MainForm.STDDictionary[STDId].Color)).ToString());
  445. //根据树节点修改对应的Xray信息
  446. UpdateSTDXray(STDId, xrayByteData);
  447. ShowXrayAtlas(color, xrayByteData);
  448. }
  449. /// <summary>
  450. /// 获取采集当前的Xray信息
  451. /// </summary>
  452. /// <returns></returns>
  453. protected uint[] GetCollectXray(string strTime)
  454. {
  455. try
  456. {
  457. if (null == m_cfun)
  458. {
  459. m_cfun = COTSControlFunExport.GetControllerInstance();
  460. }
  461. if (ConnectionSem(connectionEnumType.EDSOnlyPointXRay))
  462. {
  463. if (EDSInit())
  464. {
  465. int iSize = 2000;
  466. uint[] iXrayData = new uint[iSize];
  467. //采集XRay数据
  468. if (m_cfun.CollectSpectrum(uint.Parse(strTime), ref iXrayData))
  469. {
  470. return iXrayData;
  471. }
  472. }
  473. }
  474. return null;
  475. }
  476. catch /*(Exception ex)*/
  477. {
  478. return null;
  479. }
  480. finally
  481. {
  482. //EDS过程结束
  483. //m_cfun.EDSFinishedInstance();
  484. //关闭连接
  485. DisConnectSem(connectionEnumType.EDSOnlyPointXRay);
  486. }
  487. }
  488. private void btnReadXray_Click(object sender, EventArgs e)
  489. {
  490. OpenFileDialog fileSel = new OpenFileDialog();
  491. fileSel.Filter = "|*.txt";
  492. if (DialogResult.OK == fileSel.ShowDialog())
  493. {
  494. String str = "";
  495. //读取Xray文件
  496. using (StreamReader sr = new StreamReader(fileSel.FileName))
  497. {
  498. while (!sr.EndOfStream)
  499. {
  500. str += sr.ReadLine() + ",";
  501. }
  502. str = str.Substring(0, str.Length - 1);
  503. string[] xrayData = str.Split(',');
  504. if (xrayData.Length != 2000)
  505. {
  506. return;
  507. }
  508. uint[] data = new uint[xrayData.Length];
  509. for (int i = 0; i < xrayData.Length; i++)
  510. {
  511. data[i] = Convert.ToUInt32(xrayData[i]);
  512. }
  513. //Xray数据
  514. xrayByteData = IntArrToByteArr(data);
  515. int color = Convert.ToInt32(ParseRGB(colorHx16toRGB(m_SubMidWindow.m_MainForm.STDDictionary[STDId].Color)).ToString());
  516. //根据树节点修改对应的Xray信息
  517. UpdateSTDXray(STDId, xrayByteData);
  518. ShowXrayAtlas(color, xrayByteData);
  519. }
  520. }
  521. }
  522. /// <summary>
  523. /// 将int[] 转换为 byte[]
  524. /// </summary>
  525. /// <param name="intArr"></param>
  526. /// <returns></returns>
  527. public static byte[] IntArrToByteArr(uint[] intArr)
  528. {
  529. int intSize = sizeof(uint) * intArr.Length;
  530. byte[] bytArr = new byte[intSize];
  531. //申请一块非托管内存  
  532. //IntPtr ptr = Marshal.AllocHGlobal(intSize);
  533. ////复制int数组到该内存块  
  534. //Marshal.Copy(intArr, 0, ptr, intArr.Length);
  535. ////复制回byte数组  
  536. //Marshal.Copy(ptr, bytArr, 0, bytArr.Length);
  537. ////释放申请的非托管内存  
  538. //Marshal.FreeHGlobal(ptr);
  539. for (int i = 0; i < intArr.Length; i++)
  540. {
  541. byte[] c1 = BitConverter.GetBytes(intArr[i]);
  542. c1.CopyTo(bytArr, i * 4);
  543. }
  544. return bytArr;
  545. }
  546. /// <summary>
  547. /// 将颜色对象转换为uint
  548. /// </summary>
  549. /// <param name="color"></param>
  550. /// <returns></returns>
  551. public uint ParseRGB(Color color)
  552. {
  553. return (uint)(((uint)color.B << 16) | (ushort)(((ushort)color.G << 8) | color.R));
  554. }
  555. #region 显示Xray图谱
  556. /// <summary>
  557. /// 显示Xray图谱
  558. /// </summary>
  559. public void ShowXrayAtlas(int colorValue = 0, byte[] XrayData = null)
  560. {
  561. DataTable dt = new DataTable();
  562. dt.Columns.Add("Color", typeof(int));
  563. dt.Columns.Add("SPEC", typeof(byte[]));
  564. DataRow dRow = dt.NewRow();
  565. dRow["Color"] = colorValue;
  566. if (XrayData != null)
  567. {
  568. dRow["SPEC"] = XrayData;
  569. }
  570. else
  571. {
  572. dRow["SPEC"] = new byte[8000];
  573. }
  574. //将选择行的数据传递给Xray控件
  575. XrayControl.Dr = dRow;
  576. XrayControl.Refresh();
  577. XrayData = null;
  578. }
  579. #endregion
  580. #region 常用数据验证的封装,数字字符的验证
  581. /// <summary>
  582. /// 常用数据验证的封装,数字字符的验证
  583. /// </summary>
  584. /// <param name="inputVal">需要验证的数值【字符串,或者数字】</param>
  585. /// <param name="type">类型为哪一个验证</param>
  586. /// <returns>如果验证成功则返回True,否则返回false</returns>
  587. public bool IsMatch(string inputVal, int type)
  588. {
  589. switch (type)
  590. {
  591. case 0:
  592. return Regex.IsMatch(inputVal, @"^[1-9]d*$"); //匹配正整数
  593. case 1:
  594. return Regex.IsMatch(inputVal, @"^-?\d+$"); //匹配整数
  595. case 2:
  596. return Regex.IsMatch(inputVal, @"^[A-Za-z0-9]+$"); //匹配由数字和26个英文字母组成的字符串
  597. case 3:
  598. 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]*))$"); //匹配正浮点数
  599. case 4:
  600. return Regex.IsMatch(inputVal, @"^[\u4e00-\u9fa5]{0,}$"); //匹配汉字
  601. case 5:
  602. return Regex.IsMatch(inputVal, @"^[0-9]+(.[0-9]{1,3})?$"); //匹配1~3位小数的正实数
  603. case 6:
  604. return Regex.IsMatch(inputVal, @"^[A-Za-z]+$"); //匹配英文字符
  605. default:
  606. return true;
  607. }
  608. }
  609. #endregion
  610. #region 弹出提示
  611. /// <summary>
  612. /// 弹出提示
  613. /// </summary>
  614. /// <param name="strContent"></param>
  615. protected void showMessage(string strContent)
  616. {
  617. MessageBox.Show(strContent, table_STDEditor["message32"].ToString());
  618. }
  619. #endregion
  620. #region 连接与关闭设备
  621. public bool ConnectionSem(connectionEnumType connectionType)
  622. {
  623. //获取连接电镜类型
  624. string connTypeStr = GetConnectionType(connectionType);
  625. //连接电镜标识
  626. bool bDisConnResult = false;
  627. //判断连接状态
  628. if (!m_bConnectionState)
  629. {
  630. //连接电镜设置
  631. bDisConnResult = m_cfun.ConncetSem();
  632. }
  633. if (bDisConnResult)
  634. {
  635. m_bConnectionState = true;
  636. }
  637. else
  638. {
  639. m_bConnectionState = false;
  640. }
  641. return bDisConnResult;
  642. }
  643. public bool DisConnectSem(connectionEnumType disConnectType)
  644. {
  645. //获取关闭电镜类型
  646. string connTypeStr = GetConnectionType(disConnectType);
  647. bool bDisConnResult = false;
  648. if (m_bConnectionState)
  649. {
  650. bDisConnResult = m_cfun.DisconnectSem();
  651. }
  652. if (bDisConnResult)
  653. {
  654. m_bConnectionState = false;
  655. }
  656. else
  657. {
  658. m_bConnectionState = true;
  659. }
  660. return bDisConnResult;
  661. }
  662. private string GetConnectionType(connectionEnumType connectionType)
  663. {
  664. string connString = string.Empty;
  665. switch (connectionType)
  666. {
  667. //设置单点采集文字内容
  668. case connectionEnumType.EDSOnlyPointXRay:
  669. connString = "OnlyPointXRay";
  670. break;
  671. //设置多点采集文字内容
  672. case connectionEnumType.EDSMultiPointXRay:
  673. connString = "MultiPointXRay";
  674. break;
  675. //设置面采集文字内容
  676. case connectionEnumType.EDSAreaXRay:
  677. connString = "AreaXRay";
  678. break;
  679. //设置图片
  680. case connectionEnumType.ScanImage:
  681. connString = "Image";
  682. break;
  683. default: break;
  684. }
  685. return connString;
  686. }
  687. /// <summary>
  688. /// EDS初始化
  689. /// </summary>
  690. public bool EDSInit()
  691. {
  692. bool bResult = false;
  693. //线程调用 加载
  694. bResult = m_cfun.EDSInit();
  695. return bResult;
  696. }
  697. public enum connectionEnumType
  698. {
  699. EDSOnlyPointXRay = 0,
  700. EDSMultiPointXRay = 1,
  701. EDSAreaXRay = 2,
  702. ScanImage = 3
  703. }
  704. /// <summary>
  705. /// 标准Xray状态
  706. /// </summary>
  707. public enum STDXrayInfoState
  708. {
  709. Add = 0,
  710. Modify = 1,
  711. Delete = 2
  712. }
  713. #endregion
  714. /// <summary>
  715. /// 记录修改后的标准中的Xray信息
  716. /// </summary>
  717. public class STDXray
  718. {
  719. /// <summary>
  720. /// 标准编号
  721. /// </summary>
  722. private string stdID;
  723. /// <summary>
  724. /// Xray数据
  725. /// </summary>
  726. private byte[] xrayData;
  727. /// <summary>
  728. /// 状态
  729. /// </summary>
  730. private int infoState = -1;
  731. public string StdID { get => stdID; set => stdID = value; }
  732. public byte[] XrayData { get => xrayData; set => xrayData = value; }
  733. public int InfoState { get => infoState; set => infoState = value; }
  734. }
  735. #endregion
  736. #region Xray 与 STDDB数据操作
  737. /// <summary>
  738. /// 绑定数据库中已存在的Xray信息
  739. /// </summary>
  740. public void BindSTDXray()
  741. {
  742. //清空STDXray列表中的集合
  743. m_STDXrayList.Clear();
  744. //查询
  745. DataTable dt = m_sc.GetDTFormSysSTDBySQLString("select Id,SPEC from STDMinerals");
  746. if (dt != null)
  747. {
  748. if (dt.Rows.Count > 0)
  749. {
  750. foreach (DataRow item in dt.Rows)
  751. {
  752. STDXray sXray = new STDXray();
  753. sXray.StdID = item["Id"].ToString();
  754. sXray.XrayData = (byte[])item["SPEC"];
  755. sXray.InfoState = 1;
  756. m_STDXrayList.Add(sXray);
  757. }
  758. }
  759. }
  760. }
  761. bool SaveOtherDataToXray(string STDDBAddress, int id)
  762. {
  763. #region 数据库存贮方式一
  764. System.Data.SQLite.SQLiteConnection m_dbConnection = new System.Data.SQLite.SQLiteConnection("data source='" + STDDBAddress + "'");
  765. System.Data.SQLite.SQLiteCommand cmm = m_dbConnection.CreateCommand();
  766. try
  767. {
  768. m_dbConnection.Open();
  769. //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 + ");");
  770. string insertstr = ("insert into STDMinerals(name) values(" + m_SubMidWindow.m_MainForm.STDDictionary[id].StrName + ");");
  771. cmm.CommandText = insertstr;
  772. cmm.ExecuteNonQuery();
  773. }
  774. catch (Exception ex)
  775. {
  776. MessageBox.Show(ex.ToString());
  777. return false;
  778. }
  779. m_dbConnection.Close();
  780. #endregion
  781. return true;
  782. }
  783. /// <summary>
  784. /// 保存STDXray至数据库
  785. /// </summary>
  786. public void SaveSTDXray()
  787. {
  788. ArrayList delArrayList = new ArrayList();
  789. if (m_STDXrayList != null)
  790. {
  791. //if (m_STDXrayList.Count > 0)
  792. //{
  793. foreach (STDXray item in m_STDXrayList)
  794. {
  795. int infoState = item.InfoState;
  796. //添加状态 根据Xray信息当前只能按照一条操作
  797. if (infoState == (int)STDXrayInfoState.Add)
  798. {
  799. //if (item.XrayData == null)
  800. //{
  801. // item.XrayData = new byte[8000];
  802. //}
  803. //string strvaluename = "@data";
  804. ////编辑添加语句
  805. //StringBuilder strSqlAdd = new StringBuilder();
  806. //strSqlAdd.Append("insert into STDMinerals(Id,SPEC) values(" + item.StdID + "," + strvaluename + ");");
  807. //bool addResult = m_sc.ExecuteBlob(strSqlAdd.ToString(), strvaluename, (byte[])item.XrayData, ((byte[])item.XrayData).Length);
  808. bool addResult = false;
  809. //判断STDID在数据库中是否存在
  810. bool selResult = SelSTDDBBySTDId(item.StdID);
  811. if (selResult)
  812. {
  813. //addResult = UpdateSTDDB(item.StdID, xrayByteData);
  814. addResult = UpdateSTDDB(item.StdID, item.XrayData);
  815. }
  816. else
  817. {
  818. addResult = AddSTDDB(item.StdID, item.XrayData);
  819. }
  820. if (!addResult)
  821. {
  822. continue;
  823. }
  824. }
  825. //修改状态
  826. else if (infoState == (int)STDXrayInfoState.Modify)
  827. {
  828. //判断STDID在数据库中是否存在
  829. bool selResult = SelSTDDBBySTDId(item.StdID);
  830. if (selResult)
  831. {
  832. UpdateSTDDB(item.StdID, item.XrayData);
  833. }
  834. else
  835. {
  836. AddSTDDB(item.StdID, item.XrayData);
  837. }
  838. }
  839. //删除状态 编辑批量删除语句
  840. else if (infoState == (int)STDXrayInfoState.Delete)
  841. {
  842. //编辑删除语句
  843. delArrayList.Add("delete from STDMinerals where id=" + item.StdID + ";");
  844. }
  845. }
  846. //批量删除
  847. if (delArrayList.Count > 0)
  848. {
  849. bool delResult = m_sc.DelSTDInfo(delArrayList);
  850. }
  851. //}
  852. }
  853. }
  854. /// <summary>
  855. /// 添加STD信息至数据库
  856. /// </summary>
  857. protected bool AddSTDDB(string stdID, byte[] XrayData)
  858. {
  859. if (XrayData == null)
  860. {
  861. XrayData = new byte[8000];
  862. }
  863. string strvaluename = "@data";
  864. StringBuilder sqlStrAdd = new StringBuilder();
  865. sqlStrAdd.Append("insert into STDMinerals(Id,SPEC) values(" + stdID + "," + strvaluename + ");");
  866. bool addResult = m_sc.ExecuteBlob(sqlStrAdd.ToString(), strvaluename, (byte[])XrayData, ((byte[])XrayData).Length);
  867. return addResult;
  868. }
  869. /// <summary>
  870. /// 修改STD信息至数据库
  871. /// </summary>
  872. protected bool UpdateSTDDB(string stdID, byte[] XrayData)
  873. {
  874. if (XrayData == null)
  875. {
  876. XrayData = new byte[8000];
  877. }
  878. string strValueName = "@data";
  879. StringBuilder sqlStrUpdate = new StringBuilder();
  880. sqlStrUpdate.Append("update STDMinerals set SPEC=" + strValueName +" where id=" + stdID + ";");
  881. bool updateResult = m_sc.ExecuteBlob(sqlStrUpdate.ToString(), strValueName, (byte[])XrayData, ((byte[])XrayData).Length);
  882. return updateResult;
  883. }
  884. /// <summary>
  885. /// 查询是否存在标准编号
  886. /// </summary>
  887. /// <param name="stdID"></param>
  888. protected bool SelSTDDBBySTDId(string stdID)
  889. {
  890. bool selResult = false;
  891. //编辑查询语句
  892. StringBuilder sqlStr = new StringBuilder();
  893. sqlStr.Append("select * from STDMinerals where id=" + stdID + "");
  894. DataTable dt = m_sc.GetDTFormSysSTDBySQLString(sqlStr.ToString());
  895. if (dt != null)
  896. {
  897. if (dt.Rows.Count > 0)
  898. {
  899. //已存在状态
  900. selResult = true;
  901. }
  902. }
  903. return selResult;
  904. }
  905. /// <summary>
  906. /// 根据选择树节点显示对应的Xray信息
  907. /// </summary>
  908. public void SelSTDXray(int Key, STDdata sT)
  909. {
  910. if (sT == null)
  911. {
  912. return;
  913. }
  914. if (m_STDXrayList != null)
  915. {
  916. //if (m_STDXrayList.Count > 0)
  917. //{
  918. bool isExists = false;
  919. foreach (STDXray item in m_STDXrayList)
  920. {
  921. //修改XrayData信息
  922. if (item.StdID == Key.ToString())
  923. {
  924. string selColor = ParseRGB(colorHx16toRGB(sT.Color)).ToString();
  925. int colorValue = Convert.ToInt32(selColor);
  926. //显示Xray信息
  927. if (item.XrayData != null)
  928. {
  929. isExists = true;
  930. ShowXrayAtlas(colorValue, item.XrayData);
  931. }
  932. break;
  933. }
  934. }
  935. if (!isExists)
  936. {
  937. ShowXrayAtlas();
  938. }
  939. //}
  940. }
  941. }
  942. public void ShowEditContent(string stdID)
  943. {
  944. if (m_STDXrayList != null)
  945. {
  946. for (int i = 0; i < m_STDXrayList.Count; i++)
  947. {
  948. if (m_STDXrayList[i].StdID == stdID)
  949. {
  950. //获取修改行的信息
  951. xrayByteData = (byte[])m_STDXrayList[i].XrayData;
  952. }
  953. }
  954. }
  955. }
  956. /// <summary>
  957. /// 根据STDId修改对应的Xray信息
  958. /// </summary>
  959. /// <param name="STDId"></param>
  960. protected void UpdateSTDXray(int STDId, byte[] xrayData)
  961. {
  962. if (m_STDXrayList != null)
  963. {
  964. //if (m_STDXrayList.Count > 0)
  965. //{
  966. bool isExists = false;
  967. foreach (STDXray item in m_STDXrayList)
  968. {
  969. //修改XrayData信息
  970. if (item.StdID == STDId.ToString())
  971. {
  972. item.XrayData = xrayData;
  973. item.InfoState = (int)STDXrayInfoState.Modify;
  974. isExists = true;
  975. break;
  976. }
  977. }
  978. if (!isExists)
  979. {
  980. if (!STDId.ToString().Equals(""))
  981. {
  982. //添加STD XrayData信息
  983. STDXray stdXray = new STDXray();
  984. stdXray.StdID = STDId.ToString();
  985. stdXray.XrayData = xrayData;
  986. stdXray.InfoState = (int)STDXrayInfoState.Add;
  987. m_STDXrayList.Add(stdXray);
  988. }
  989. }
  990. //}
  991. }
  992. }
  993. /// <summary>
  994. /// 添加STDXray信息
  995. /// </summary>
  996. /// <param name="STDid">STDid</param>
  997. /// <param name="xrayData">Xray信息</param>
  998. /// <returns></returns>
  999. protected bool AddSTDXray(int STDId, byte[] xrayData)
  1000. {
  1001. bool addResult = false;
  1002. if (m_STDXrayList != null)
  1003. {
  1004. //if (m_STDXrayList.Count > 0)
  1005. //{
  1006. if (!STDId.ToString().Equals(""))
  1007. {
  1008. //添加STD XrayData信息
  1009. STDXray stdXray = new STDXray();
  1010. stdXray.StdID = STDId.ToString();
  1011. stdXray.XrayData = xrayData;
  1012. stdXray.InfoState = (int)STDXrayInfoState.Add;
  1013. m_STDXrayList.Add(stdXray);
  1014. addResult = true;
  1015. }
  1016. //}
  1017. }
  1018. return addResult;
  1019. }
  1020. /// <summary>
  1021. /// 删除STDXray信息
  1022. /// </summary>
  1023. /// <param name="STDId">所选要删除的STDId</param>
  1024. /// <returns></returns>
  1025. public bool DelSTDXray(int STDId)
  1026. {
  1027. bool delResult = false;
  1028. if (m_STDXrayList != null)
  1029. {
  1030. //if (m_STDXrayList.Count > 0)
  1031. //{
  1032. if (!STDId.ToString().Equals(""))
  1033. {
  1034. foreach (STDXray item in m_STDXrayList)
  1035. {
  1036. //修改XrayData信息
  1037. if (item.StdID == STDId.ToString())
  1038. {
  1039. item.InfoState = (int)STDXrayInfoState.Delete;
  1040. delResult = true;
  1041. break;
  1042. }
  1043. }
  1044. }
  1045. //}
  1046. }
  1047. return delResult;
  1048. }
  1049. #endregion
  1050. #region 控制BSE、化学式、元素本文框中不能输入下划线
  1051. /// <summary>
  1052. /// 控件不能输入下划线
  1053. /// </summary>
  1054. /// <param name="sender"></param>
  1055. /// <param name="e"></param>
  1056. private void textBox_KeyPress(object sender, KeyPressEventArgs e)
  1057. {
  1058. if ((e.KeyChar >= '0' && e.KeyChar <= '9') || (e.KeyChar >= 'A' && e.KeyChar <= 'Z') ||
  1059. (e.KeyChar >= 'a' && e.KeyChar <= 'z') || (e.KeyChar == 8) || !(e.KeyChar == '_'))
  1060. {
  1061. e.Handled = false;
  1062. }
  1063. else
  1064. {
  1065. e.Handled = true;
  1066. }
  1067. }
  1068. #endregion
  1069. private void btnTest_Click(object sender, EventArgs e)
  1070. {
  1071. XrayContrastForm xrayContrastForm = new XrayContrastForm();
  1072. xrayContrastForm.STDDictionary = m_SubMidWindow.m_MainForm.STDDictionary;
  1073. xrayContrastForm.ShowDialog();
  1074. }
  1075. string ElementKeyOrSub = "";
  1076. private void dataGridView_KeyElements_CellClick(object sender, DataGridViewCellEventArgs e)
  1077. {
  1078. ElementKeyOrSub = dataGridView_KeyElements.CurrentCell.Value.ToString();
  1079. dataGridView_KeyElements.Columns.RemoveAt(e.ColumnIndex);
  1080. DataGridViewButtonColumn dataGridViewButtonColumn = new DataGridViewButtonColumn();
  1081. dataGridViewButtonColumn.Name = dataGridView_SubElements.Columns.Count.ToString();
  1082. dataGridView_SubElements.Columns.Add(dataGridViewButtonColumn);
  1083. if (dataGridView_SubElements.Rows.Count == 0)
  1084. {
  1085. DataGridViewRow row = new DataGridViewRow();
  1086. dataGridView_SubElements.Rows.Add(row);
  1087. }
  1088. dataGridView_SubElements.Rows[0].Cells[dataGridView_SubElements.Columns.Count - 1].Value = ElementKeyOrSub;
  1089. dataGridView_SubElements.ClearSelection();
  1090. dataGridView_KeyElements.ClearSelection();
  1091. }
  1092. private void dataGridView_SubElements_CellClick(object sender, DataGridViewCellEventArgs e)
  1093. {
  1094. ElementKeyOrSub = dataGridView_SubElements.CurrentCell.Value.ToString();
  1095. dataGridView_SubElements.Columns.RemoveAt(e.ColumnIndex);
  1096. DataGridViewButtonColumn dataGridViewButtonColumn = new DataGridViewButtonColumn();
  1097. dataGridViewButtonColumn.Name = dataGridView_SubElements.Columns.Count.ToString();
  1098. dataGridView_KeyElements.Columns.Add(dataGridViewButtonColumn);
  1099. if (dataGridView_KeyElements.Rows.Count == 0)
  1100. {
  1101. DataGridViewRow row = new DataGridViewRow();
  1102. dataGridView_KeyElements.Rows.Add(row);
  1103. }
  1104. dataGridView_KeyElements.Rows[0].Cells[dataGridView_KeyElements.Columns.Count - 1].Value = ElementKeyOrSub;
  1105. dataGridView_KeyElements.ClearSelection();
  1106. dataGridView_SubElements.ClearSelection();
  1107. }
  1108. private float X=1;
  1109. private float Y=1;
  1110. private void STDEditor_Resize(object sender, EventArgs e)
  1111. {
  1112. float newx = (this.Width) / X;
  1113. float newy = this.Height/ Y;
  1114. AmplificationFactor = newy;
  1115. setControls(newx, newy, this.tabSTDStandrad.TabPages[0]);
  1116. //button_Extend.BackColor = SystemColors.ControlDarkDark;
  1117. }
  1118. private void setTag(Control cons)
  1119. {
  1120. foreach (Control con in cons.Controls)
  1121. {
  1122. con.Tag = con.Width + ":" + con.Height + ":" + con.Left + ":" + con.Top + ":" + con.Font.Size;
  1123. if (con.Controls.Count > 0)
  1124. setTag(con);
  1125. }
  1126. }
  1127. private void setControls(float newx, float newy, Control cons)
  1128. {
  1129. foreach (Control con in cons.Controls)
  1130. {
  1131. if (false)
  1132. {
  1133. }
  1134. else
  1135. {
  1136. string[] mytag = con.Tag.ToString().Split(':');
  1137. float a = Convert.ToSingle(mytag[0]) * newx;
  1138. con.Width = (int)a;
  1139. a = Convert.ToSingle(mytag[1]) * newy;
  1140. con.Height = (int)(a);
  1141. a = Convert.ToSingle(mytag[2]) * newx;
  1142. con.Left = (int)(a);
  1143. a = Convert.ToSingle(mytag[3]) * newy;
  1144. con.Top = (int)(a);
  1145. Single currentSize ;
  1146. if (con.Name == "button_Extend")
  1147. {
  1148. currentSize = 6f;
  1149. }
  1150. else
  1151. {
  1152. if (Math.Max(newx, newy) < 1)
  1153. {
  1154. currentSize = Convert.ToSingle(mytag[4]) * 1;
  1155. }
  1156. else
  1157. {
  1158. currentSize = Convert.ToSingle(mytag[4]) * Math.Max(newx, newy);
  1159. }
  1160. }
  1161. con.Font = new Font(con.Font.Name, currentSize, con.Font.Style, con.Font.Unit);
  1162. if (con.Controls.Count > 0)
  1163. {
  1164. setControls(newx, newy, con);
  1165. }
  1166. }
  1167. }
  1168. }
  1169. Form_PeriodicTable form_PeriodicTable;
  1170. private void button_PeriodicTableSwitch_Click(object sender, EventArgs e)
  1171. {
  1172. if (form_PeriodicTable == null) //如果子窗体为空则创造实例 并显示
  1173. {
  1174. form_PeriodicTable = new Form_PeriodicTable();
  1175. if (table_STDEditor["language"].ToString() == "EN")
  1176. {
  1177. form_PeriodicTable.BackgroundImage = global::OTSPartA_STDEditor.Properties.Resources.PeriodicTable_EN;
  1178. }
  1179. else
  1180. {
  1181. form_PeriodicTable.BackgroundImage = global::OTSPartA_STDEditor.Properties.Resources.PeriodicTable_ZH;
  1182. }
  1183. form_PeriodicTable.Show();
  1184. }
  1185. else
  1186. {
  1187. if (form_PeriodicTable.IsDisposed) //若子窗体关闭 则打开新子窗体 并显示
  1188. {
  1189. form_PeriodicTable = new Form_PeriodicTable();
  1190. if (table_STDEditor["language"].ToString() == "EN")
  1191. {
  1192. form_PeriodicTable.BackgroundImage = global::OTSPartA_STDEditor.Properties.Resources.PeriodicTable_EN;
  1193. }
  1194. else
  1195. {
  1196. form_PeriodicTable.BackgroundImage = global::OTSPartA_STDEditor.Properties.Resources.PeriodicTable_ZH;
  1197. }
  1198. form_PeriodicTable.Show();
  1199. }
  1200. else
  1201. {
  1202. form_PeriodicTable.Activate(); //使子窗体获得焦点
  1203. }
  1204. }
  1205. }
  1206. private void button_ImportFromResult_Click(object sender, EventArgs e)
  1207. {
  1208. OpenFileDialog openFileDialog = new OpenFileDialog();
  1209. openFileDialog.Filter = "(*.db)|*.db";
  1210. openFileDialog.RestoreDirectory = true;
  1211. openFileDialog.FilterIndex = 1;
  1212. if (openFileDialog.ShowDialog() == DialogResult.OK)
  1213. {
  1214. try
  1215. {
  1216. System.Data.SQLite.SQLiteConnection m_dbConnection = new System.Data.SQLite.SQLiteConnection("data source='" + openFileDialog.FileName + "'");
  1217. m_dbConnection.Open();
  1218. 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();
  1219. Result ret=ImportFromResult(STDId, m_dbConnection);
  1220. if(ret== Result.NoMatched)
  1221. {
  1222. MessageBox.Show(table_STDEditor["message3"].ToString(), table_STDEditor["message32"].ToString());
  1223. }
  1224. m_dbConnection.Close();
  1225. int color = Convert.ToInt32(ParseRGB(colorHx16toRGB(m_SubMidWindow.m_MainForm.STDDictionary[int.Parse(STDId)].Color)).ToString());
  1226. for(int i=0;i< m_STDXrayList.Count;i++)
  1227. {
  1228. if(m_STDXrayList[i].StdID== STDId)
  1229. {
  1230. ShowXrayAtlas(color, m_STDXrayList[i].XrayData);
  1231. break;
  1232. }
  1233. }
  1234. }
  1235. catch /*(Exception ex)*/
  1236. {
  1237. MessageBox.Show(table_STDEditor["message21"].ToString(), table_STDEditor["message32"].ToString());
  1238. }
  1239. }
  1240. }
  1241. public Result ImportFromResult(string STDId, System.Data.SQLite.SQLiteConnection m_dbConnection)
  1242. {
  1243. try
  1244. {
  1245. System.Data.SQLite.SQLiteDataAdapter m_dataAdapter = new System.Data.SQLite.SQLiteDataAdapter("select FieldId ,XrayId from IncAData where TypeId ="+ STDId , m_dbConnection);
  1246. DataSet ds = new DataSet();
  1247. m_dataAdapter.Fill(ds);
  1248. DataTable dt = ds.Tables[0];
  1249. if (dt != null)
  1250. {
  1251. if (dt.Rows.Count > 0)
  1252. {
  1253. string sqlstr = "select XrayData from XRayData where FieldId = " + dt.Rows[0]["FieldId"] + " AND XrayIndex =" + dt.Rows[0]["XrayId"];
  1254. m_dataAdapter = new System.Data.SQLite.SQLiteDataAdapter(sqlstr, m_dbConnection);
  1255. ds = new DataSet();
  1256. m_dataAdapter.Fill(ds);
  1257. dt = ds.Tables[0];
  1258. if (dt != null)
  1259. {
  1260. if (dt.Rows.Count > 0)
  1261. {
  1262. DialogResult dr = MessageBox.Show(table_STDEditor["message29"].ToString() + STDId+ table_STDEditor["message30"].ToString(), table_STDEditor["message32"].ToString(), MessageBoxButtons.OKCancel);
  1263. if(dr == DialogResult.OK)
  1264. {
  1265. m_SubMidWindow.m_MainForm.IsModified = true;
  1266. if (SelSTDDBBySTDId(STDId))
  1267. {
  1268. if (MessageBox.Show(table_STDEditor["message29"].ToString() + STDId + table_STDEditor["message36"].ToString(), table_STDEditor["message32"].ToString(), MessageBoxButtons.OKCancel) == DialogResult.OK)
  1269. {
  1270. UpdateSTDXray(int.Parse(STDId), (byte[])dt.Rows[0]["XrayData"]);
  1271. }
  1272. }
  1273. else
  1274. {
  1275. UpdateSTDXray(int.Parse(STDId), (byte[])dt.Rows[0]["XrayData"]);
  1276. }
  1277. }
  1278. return Result.Success;
  1279. }
  1280. else
  1281. {
  1282. return Result.NoMatched;
  1283. }
  1284. }
  1285. else
  1286. {
  1287. return Result.NoMatched;
  1288. }
  1289. }
  1290. else
  1291. {
  1292. return Result.NoMatched;
  1293. }
  1294. }
  1295. else
  1296. {
  1297. return Result.NoMatched;
  1298. }
  1299. }
  1300. catch /*(Exception ee)*/
  1301. {
  1302. MessageBox.Show(table_STDEditor["message21"].ToString(), table_STDEditor["message32"].ToString());
  1303. return Result.Fail;
  1304. }
  1305. }
  1306. private void textbox_STDEditor_MouseLeave(object sender, EventArgs e)
  1307. {
  1308. dataGridView_KeyElements.Rows.Clear();
  1309. dataGridView_KeyElements.Columns.Clear();
  1310. string str_RemoveBlank = textbox_STDEditor.Text.ToString().Replace(" ", "");
  1311. str_RemoveBlank = str_RemoveBlank.Replace("\r\n", "");
  1312. str_RemoveBlank = str_RemoveBlank.Replace("forth_elem", "");
  1313. string[] str_Removeand = System.Text.RegularExpressions.Regex.Split(str_RemoveBlank, "and", System.Text.RegularExpressions.RegexOptions.None);
  1314. List<string> str_Removeandor = new List<string>();
  1315. for (int i = 0; i < str_Removeand.Length; i++)
  1316. {
  1317. str_Removeandor.AddRange(System.Text.RegularExpressions.Regex.Split(str_Removeand[i], "or", System.Text.RegularExpressions.RegexOptions.None));
  1318. }
  1319. List<string> list_all = new List<string>();
  1320. for (int i = 0; i < str_Removeandor.Count; i++)
  1321. {
  1322. list_all.AddRange(str_Removeandor[i].Split(new char[] { '+', '-', '*', '/', '=', '>', '<', '(', ')' }));
  1323. }
  1324. List<string> UsingElementL = new List<string>();
  1325. for (int i = 0; i < list_all.Count; i++)
  1326. {
  1327. if (this.comboBox_PeriodicTable.Items.Contains(list_all[i]))
  1328. {
  1329. if (!UsingElementL.Contains(list_all[i]))
  1330. {
  1331. UsingElementL.Add(list_all[i]);
  1332. }
  1333. }
  1334. }
  1335. List<string> SubElements = new List<string>();
  1336. for (int i = 0; i < dataGridView_SubElements.ColumnCount; i++)
  1337. {
  1338. if (UsingElementL.Contains(dataGridView_SubElements.Rows[0].Cells[i].Value))
  1339. {
  1340. SubElements.Add(dataGridView_SubElements.Rows[0].Cells[i].Value.ToString());
  1341. }
  1342. }
  1343. dataGridView_SubElements.Rows.Clear();
  1344. dataGridView_SubElements.Columns.Clear();
  1345. for (int i = 0; i < SubElements.Count; i++)
  1346. {
  1347. DataGridViewButtonColumn dataGridViewButtonColumn = new DataGridViewButtonColumn();
  1348. dataGridViewButtonColumn.Name = dataGridView_SubElements.Columns.Count.ToString();
  1349. dataGridView_SubElements.Columns.Add(dataGridViewButtonColumn);
  1350. if (dataGridView_SubElements.Rows.Count == 0)
  1351. {
  1352. DataGridViewRow row = new DataGridViewRow();
  1353. dataGridView_SubElements.Rows.Add(row);
  1354. }
  1355. dataGridView_SubElements.Rows[0].Cells[dataGridView_SubElements.ColumnCount - 1].Value = SubElements[i];
  1356. }
  1357. if (SubElements.Count > 0)
  1358. {
  1359. for (int i = 0; i < UsingElementL.Count; i++)
  1360. {
  1361. if (!SubElements.Contains(UsingElementL[i]))
  1362. {
  1363. DataGridViewButtonColumn dataGridViewButtonColumn = new DataGridViewButtonColumn();
  1364. dataGridViewButtonColumn.Name = dataGridView_KeyElements.Columns.Count.ToString();
  1365. dataGridView_KeyElements.Columns.Add(dataGridViewButtonColumn);
  1366. if (dataGridView_KeyElements.Rows.Count == 0)
  1367. {
  1368. DataGridViewRow row = new DataGridViewRow();
  1369. dataGridView_KeyElements.Rows.Add(row);
  1370. }
  1371. dataGridView_KeyElements.Rows[0].Cells[dataGridView_KeyElements.ColumnCount - 1].Value = UsingElementL[i];
  1372. }
  1373. }
  1374. }
  1375. else
  1376. {
  1377. for (int i = 0; i < UsingElementL.Count; i++)
  1378. {
  1379. DataGridViewButtonColumn dataGridViewButtonColumn = new DataGridViewButtonColumn();
  1380. dataGridViewButtonColumn.Name = dataGridView_KeyElements.Columns.Count.ToString();
  1381. dataGridView_KeyElements.Columns.Add(dataGridViewButtonColumn);
  1382. if (dataGridView_KeyElements.Rows.Count == 0)
  1383. {
  1384. DataGridViewRow row = new DataGridViewRow();
  1385. dataGridView_KeyElements.Rows.Add(row);
  1386. }
  1387. dataGridView_KeyElements.Rows[0].Cells[i].Value = UsingElementL[i];
  1388. }
  1389. }
  1390. dataGridView_KeyElements.ClearSelection();
  1391. dataGridView_SubElements.ClearSelection();
  1392. }
  1393. public void ShowTabXray()
  1394. {
  1395. tabSTDStandrad.SelectedIndex = 1;
  1396. }
  1397. public void ShowSTD()
  1398. {
  1399. tabSTDStandrad.SelectedIndex = 0;
  1400. }
  1401. }
  1402. }