12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526 |
- using OTS.WinFormsUI.Docking;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using OTSCLRINTERFACE;
- using System.Collections;
- using System.IO;
- using System.Runtime.InteropServices;
- using System.Text.RegularExpressions;
- namespace OTSPartA_STDEditor
- {
- public partial class STDEditor : DockContent
- {
- #region 全局变量
- public SubMidWindow m_SubMidWindow = null;
- public int STDId = -1;
- Hashtable table_STDEditor;
- //数据库操作对象
- public SqlLiteClass m_sc = null;
- // 电镜设置对象
- COTSControlFunExport m_cfun = null;
- //Xray图谱用户控件
- UXrayControl XrayControl = null;
- //全局Xray 用于存储当前选择行的Xray信息
- byte[] xrayByteData = null;
- // 连接状态
- bool m_bConnectionState = false;
- //标准Xray信息列表
- public List<STDXray> m_STDXrayList = null;
- #endregion
- public enum Result
- {
- NoMatched=0,
- Success=1,
- Fail=2
- }
- public STDEditor(SubMidWindow SubMidWindow)
- {
- InitializeComponent();
- m_sc = new SqlLiteClass();
- m_SubMidWindow = SubMidWindow;
- X = this.Width;
- Y = this.Height;
- setTag(this);
- }
- public STDEditor(SubMidWindow SubMidWindow,string STDDBaddress)
- {
- InitializeComponent();
- m_sc = new SqlLiteClass(STDDBaddress);
- m_SubMidWindow = SubMidWindow;
- X = this.Width;
- Y = this.Height;
- setTag(this);
- }
- private void STDEditor_Load(object sender, EventArgs e)
- {
- m_SubMidWindow.m_MainForm.lan = new Language(this);
- table_STDEditor = m_SubMidWindow.m_MainForm.lan.GetNameTable("STDEditor");
- //初始化comboBox
- this.comboBox_Elem1.Items.Add("first_elem");
- this.comboBox_Elem1.Items.Add("second_elem");
- this.comboBox_Elem1.Items.Add("third_elem");
- this.comboBox_Elem1.Items.Add("forth_elem");
- this.comboBox_Elem1.Items.Add("fifth_elem");
- this.comboBox_Elem1.Items.Add("sixth_elem");
- this.comboBox_Elem1.Items.Add("seventh_elem");
- this.comboBox_Elem1.Items.Add("eighth_elem");
- this.comboBox_Elem1.Items.Add("ninth_elem");
- this.comboBox_Elem1.Items.Add("tenth_elem");
- comboBox_Elem1.SelectedIndex = comboBox_Elem1.Items.IndexOf("first_elem");
- this.comboBox_Elem.Items.Add("Element#1");
- this.comboBox_Elem.Items.Add("Element#2");
- this.comboBox_Elem.Items.Add("Element#3");
- this.comboBox_Elem.Items.Add("Element#4");
- this.comboBox_Elem.Items.Add("Element#5");
- this.comboBox_Elem.Items.Add("Element#6");
- this.comboBox_Elem.Items.Add("Element#7");
- this.comboBox_Elem.Items.Add("Element#8");
- this.comboBox_Elem.Items.Add("Element#9");
- this.comboBox_Elem.Items.Add("Element#10");
- comboBox_Elem.SelectedIndex = comboBox_Elem.Items.IndexOf("Element#1");
- this.comboBox_ImgProperty.Items.Add("Dmax"); //颗粒最大直径;
- this.comboBox_ImgProperty.Items.Add("Dmin"); //颗粒最小直径;
- this.comboBox_ImgProperty.Items.Add("Aspect"); //长宽比;
- this.comboBox_ImgProperty.Items.Add("Dperp"); //与Dmax垂直直径;
- this.comboBox_ImgProperty.Items.Add("Dmean"); //平均内接圆直径;
- this.comboBox_ImgProperty.Items.Add("Area"); //面积;
- this.comboBox_ImgProperty.Items.Add("Dferet"); //费雷特直径;
- this.comboBox_ImgProperty.Items.Add("Width"); //宽度(直上直下那种);
- this.comboBox_ImgProperty.Items.Add("Height"); //高度(直上直下那种)
- this.comboBox_ImgProperty.Items.Add("Perimeter"); //周长
- this.comboBox_ImgProperty.Items.Add("Dinscr"); //最大内接圆直径
- this.comboBox_ImgProperty.Items.Add("Orientation"); //朝向
- this.comboBox_ImgProperty.Items.Add("Delong"); //展开长度
- this.comboBox_ImgProperty.Items.Add("Aspectelong"); //展开后长宽比
- this.comboBox_ImgProperty.Items.Add("Dequalcircle"); //等效圆直径
- this.comboBox_ImgProperty.Items.Add("Vedio"); //BSE灰度平均值
- comboBox_ImgProperty.SelectedIndex = comboBox_ImgProperty.Items.IndexOf("Dmax");
- 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" };
- comboBox_PeriodicTable.Items.AddRange(PeriodicTable);
- AutoCompleteStringCollection sc = new AutoCompleteStringCollection();
- sc.AddRange(PeriodicTable);
- this.comboBox_PeriodicTable.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.SuggestAppend;
- this.comboBox_PeriodicTable.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.CustomSource;
- this.comboBox_PeriodicTable.AutoCompleteCustomSource = sc;
- dataGridView_KeyElements.RowHeadersVisible = false;
- dataGridView_KeyElements.ColumnHeadersVisible = false;
- dataGridView_KeyElements.AllowUserToAddRows = false;
- dataGridView_KeyElements.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
- dataGridView_SubElements.RowHeadersVisible = false;
- dataGridView_SubElements.ColumnHeadersVisible = false;
- dataGridView_SubElements.AllowUserToAddRows = false;
- dataGridView_SubElements.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
- //添加Xray用户控件
- XrayControl = new UXrayControl();
- plXray.Controls.Add(XrayControl);
- XrayControl.Dock = DockStyle.Fill;
- //绑定数据库中的STDXray
- m_STDXrayList = new List<STDXray>();
- BindSTDXray();
- }
- /// <summary>
- /// [颜色:16进制转成RGB]
- /// </summary>
- /// <param name="strColor">设置16进制颜色 [返回RGB]</param>
- /// <returns></returns>
- public static System.Drawing.Color colorHx16toRGB(string strHxColor)
- {
- try
- {
- if (strHxColor.Length == 0)
- {//如果为空
- return System.Drawing.Color.FromArgb(255, 255, 204);//设为白色
- }
- else
- {//转换颜色
- 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));
- }
- }
- catch
- {//设为白色
- return System.Drawing.Color.FromArgb(255, 255, 204);
- }
- }
- float AmplificationFactor = 1;
- //private void button_Extend_Click(object sender, EventArgs e)
- //{
- // if (button_Extend.BackColor == SystemColors.ControlDarkDark)
- // {
- // //groupBox_Data.Visible = true;
- // textbox_STDEditor.Height = (int)Math.Round(150 * AmplificationFactor);
- // button_Extend.BackColor = SystemColors.ControlDark;
- // }
- // else
- // {
- // button_Extend.BackColor = SystemColors.ControlDarkDark;
- // textbox_STDEditor.Height = (int)Math.Round(300* AmplificationFactor);
- // }
- //}
- private void comboBox_Elem1_SelectedIndexChanged(object sender, EventArgs e)
- {
- string newStr = comboBox_Elem1.SelectedItem.ToString();
- int index = textbox_STDEditor.SelectionStart;
- textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, newStr);
- textbox_STDEditor.Focus();
- textbox_STDEditor.Select(index + newStr.Length, 0);
- textbox_STDEditor.ScrollToCaret();
- }
- private void comboBox_Elem2_SelectedIndexChanged(object sender, EventArgs e)
- {
- string newStr = comboBox_Elem.SelectedItem.ToString();
- int index = textbox_STDEditor.SelectionStart;
- textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, newStr);
- textbox_STDEditor.Focus();
- textbox_STDEditor.Select(index + newStr.Length, 0);
- textbox_STDEditor.ScrollToCaret();
- }
- private void comboBox_ImgProperty_SelectedIndexChanged(object sender, EventArgs e)
- {
- string newStr = comboBox_ImgProperty.SelectedItem.ToString();
- int index = textbox_STDEditor.SelectionStart;
- textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, newStr);
- textbox_STDEditor.Focus();
- textbox_STDEditor.Select(index + newStr.Length, 0);
- textbox_STDEditor.ScrollToCaret();
- }
- private void button_Plus_Click(object sender, EventArgs e)
- {
- //textbox_STDEditor 中的光标
- int index = textbox_STDEditor.SelectionStart;
- textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "+");
- textbox_STDEditor.Focus();
- textbox_STDEditor.Select(index + 1, 0);
- textbox_STDEditor.ScrollToCaret();
- }
- private void button_Subtract_Click(object sender, EventArgs e)
- {
- //textbox_STDEditor 中的光标
- int index = textbox_STDEditor.SelectionStart;
- textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "-");
- textbox_STDEditor.Focus();
- textbox_STDEditor.Select(index + 1, 0);
- textbox_STDEditor.ScrollToCaret();
- }
- private void button_Multiply_Click(object sender, EventArgs e)
- {
- //textbox_STDEditor 中的光标
- int index = textbox_STDEditor.SelectionStart;
- textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "*");
- textbox_STDEditor.Focus();
- textbox_STDEditor.Select(index + 1, 0);
- textbox_STDEditor.ScrollToCaret();
- }
- private void button_Divide_Click(object sender, EventArgs e)
- {
- //textbox_STDEditor 中的光标
- int index = textbox_STDEditor.SelectionStart;
- textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "/");
- textbox_STDEditor.Focus();
- textbox_STDEditor.Select(index + 1, 0);
- textbox_STDEditor.ScrollToCaret(); ;
- }
- private void button_More_Click(object sender, EventArgs e)
- {
- //textbox_STDEditor 中的光标
- int index = textbox_STDEditor.SelectionStart;
- textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, ">");
- textbox_STDEditor.Focus();
- textbox_STDEditor.Select(index + 1, 0);
- textbox_STDEditor.ScrollToCaret();
- }
- private void button_Less_Click(object sender, EventArgs e)
- {
- //textbox_STDEditor 中的光标
- int index = textbox_STDEditor.SelectionStart;
- textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "<");
- textbox_STDEditor.Focus();
- textbox_STDEditor.Select(index + 1, 0);
- textbox_STDEditor.ScrollToCaret();
- }
- private void button_LeftParenthesis_Click(object sender, EventArgs e)
- {
- //textbox_STDEditor 中的光标
- int index = textbox_STDEditor.SelectionStart;
- textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "(");
- textbox_STDEditor.Focus();
- textbox_STDEditor.Select(index + 1, 0);
- textbox_STDEditor.ScrollToCaret();
- }
- private void button_RightParenthesis_Click(object sender, EventArgs e)
- {
- //textbox_STDEditor 中的光标
- int index = textbox_STDEditor.SelectionStart;
- textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, ")");
- textbox_STDEditor.Focus();
- textbox_STDEditor.Select(index + 1, 0);
- textbox_STDEditor.ScrollToCaret();
- }
- private void button_Equal_Click(object sender, EventArgs e)
- {
- //textbox_STDEditor 中的光标
- int index = textbox_STDEditor.SelectionStart;
- textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "=");
- textbox_STDEditor.Focus();
- textbox_STDEditor.Select(index + 1, 0);
- textbox_STDEditor.ScrollToCaret();
- }
- //元素下拉选择输入
- private void comboBox_PeriodicTable_SelectedIndexChanged(object sender, EventArgs e)
- {
- if (comboBox_PeriodicTable.Text != null && comboBox_PeriodicTable.SelectedItem != null)
- {
- string newStr = comboBox_PeriodicTable.SelectedItem.ToString();
- comboBox_PeriodicTable.Text = null;
- int index = textbox_STDEditor.SelectionStart;
- textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, newStr);
- textbox_STDEditor.Focus();
- textbox_STDEditor.Select(index + newStr.Length, 0);
- textbox_STDEditor.ScrollToCaret();
- }
- }
- private void button_And_Click(object sender, EventArgs e)
- {
- //textbox_STDEditor 中的光标
- int index = textbox_STDEditor.SelectionStart;
- textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "and");
- textbox_STDEditor.Focus();
- textbox_STDEditor.Select(index + 3, 0);
- textbox_STDEditor.ScrollToCaret();
- }
- private void button_Or_Click(object sender, EventArgs e)
- {
- //textbox_STDEditor 中的光标
- int index = textbox_STDEditor.SelectionStart;
- textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "or");
- textbox_STDEditor.Focus();
- textbox_STDEditor.Select(index + 2, 0);
- textbox_STDEditor.ScrollToCaret();
- }
- private void comboBox_Constants_SelectedIndexChanged(object sender, EventArgs e)
- {
- if (comboBox_Constants.SelectedItem != null)
- {
- string newStr = comboBox_Constants.SelectedItem.ToString().Split('=')[0];
- int index = textbox_STDEditor.SelectionStart;
- textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, newStr);
- textbox_STDEditor.Focus();
- textbox_STDEditor.Select(index + newStr.Length, 0);
- textbox_STDEditor.ScrollToCaret();
- }
- }
- private void button_1_Click(object sender, EventArgs e)
- {
- //textbox_STDEditor 中的光标
- int index = textbox_STDEditor.SelectionStart;
- textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "1");
- textbox_STDEditor.Focus();
- textbox_STDEditor.Select(index + 1, 0);
- textbox_STDEditor.ScrollToCaret();
- }
- private void button_2_Click(object sender, EventArgs e)
- {
- //textbox_STDEditor 中的光标
- int index = textbox_STDEditor.SelectionStart;
- textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "2");
- textbox_STDEditor.Focus();
- textbox_STDEditor.Select(index + 1, 0);
- textbox_STDEditor.ScrollToCaret();
- }
- private void button_3_Click(object sender, EventArgs e)
- {
- //textbox_STDEditor 中的光标
- int index = textbox_STDEditor.SelectionStart;
- textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "3");
- textbox_STDEditor.Focus();
- textbox_STDEditor.Select(index + 1, 0);
- textbox_STDEditor.ScrollToCaret();
- }
- private void button_4_Click(object sender, EventArgs e)
- {
- //textbox_STDEditor 中的光标
- int index = textbox_STDEditor.SelectionStart;
- textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "4");
- textbox_STDEditor.Focus();
- textbox_STDEditor.Select(index + 1, 0);
- textbox_STDEditor.ScrollToCaret();
- }
- private void button_5_Click(object sender, EventArgs e)
- {
- //textbox_STDEditor 中的光标
- int index = textbox_STDEditor.SelectionStart;
- textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "5");
- textbox_STDEditor.Focus();
- textbox_STDEditor.Select(index + 1, 0);
- textbox_STDEditor.ScrollToCaret();
- }
- private void button_6_Click(object sender, EventArgs e)
- {
- //textbox_STDEditor 中的光标
- int index = textbox_STDEditor.SelectionStart;
- textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "6");
- textbox_STDEditor.Focus();
- textbox_STDEditor.Select(index + 1, 0);
- textbox_STDEditor.ScrollToCaret();
- }
- private void button_7_Click(object sender, EventArgs e)
- {
- //textbox_STDEditor 中的光标
- int index = textbox_STDEditor.SelectionStart;
- textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "7");
- textbox_STDEditor.Focus();
- textbox_STDEditor.Select(index + 1, 0);
- textbox_STDEditor.ScrollToCaret();
- }
- private void button_8_Click(object sender, EventArgs e)
- {
- //textbox_STDEditor 中的光标
- int index = textbox_STDEditor.SelectionStart;
- textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "8");
- textbox_STDEditor.Focus();
- textbox_STDEditor.Select(index + 1, 0);
- textbox_STDEditor.ScrollToCaret();
- }
- private void button_9_Click(object sender, EventArgs e)
- {
- //textbox_STDEditor 中的光标
- int index = textbox_STDEditor.SelectionStart;
- textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "9");
- textbox_STDEditor.Focus();
- textbox_STDEditor.Select(index + 1, 0);
- textbox_STDEditor.ScrollToCaret();
- }
- private void button_0_Click(object sender, EventArgs e)
- {
- int index = textbox_STDEditor.SelectionStart;
- textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "0");
- textbox_STDEditor.Focus();
- textbox_STDEditor.Select(index + 1, 0);
- textbox_STDEditor.ScrollToCaret();
- }
- //元素自身text按回车键输入
- private void comboBox_PeriodicTable_KeyDown(object sender, KeyEventArgs e)
- {
- if (e.KeyValue == 13)
- {
- if (comboBox_PeriodicTable.Text != null && comboBox_PeriodicTable.Text != "")
- {
- this.textbox_STDEditor.Text += comboBox_PeriodicTable.Text.ToString();
- comboBox_PeriodicTable.Text = null;
- }
- }
- }
- #region 采集Xray 按钮事件
- private void btnCollectXray_Click(object sender, EventArgs e)
- {
- m_SubMidWindow.m_MainForm.IsModified = true;
- string strTime = txtCollectTime.Text.Trim();
- if (txtCollectTime.Equals(""))
- {
- showMessage("Please fill in the collection time name!");
- txtCollectTime.Focus();
- return;
- }
- if (!IsMatch(strTime, 1))
- {
- showMessage("Error collecting time content, the format should be integer!");
- txtCollectTime.Focus();
- return;
- }
- if (Convert.ToInt32(strTime) < 50)
- {
- showMessage("CollectTime must not be less than 100 milliseconds!");
- txtCollectTime.Focus();
- return;
- }
- //显示Xray
- xrayByteData = IntArrToByteArr(GetCollectXray(strTime));
- int color = Convert.ToInt32(ParseRGB(colorHx16toRGB(m_SubMidWindow.m_MainForm.STDDictionary[STDId].Color)).ToString());
- //根据树节点修改对应的Xray信息
- UpdateSTDXray(STDId, xrayByteData);
- ShowXrayAtlas(color, xrayByteData);
- }
- /// <summary>
- /// 获取采集当前的Xray信息
- /// </summary>
- /// <returns></returns>
- protected uint[] GetCollectXray(string strTime)
- {
- try
- {
- if (null == m_cfun)
- {
- m_cfun = COTSControlFunExport.GetControllerInstance();
- }
- if (ConnectionSem(connectionEnumType.EDSOnlyPointXRay))
- {
- if (EDSInit())
- {
- int iSize = 2000;
- uint[] iXrayData = new uint[iSize];
- //采集XRay数据
- if (m_cfun.CollectSpectrum(uint.Parse(strTime), ref iXrayData))
- {
- return iXrayData;
- }
- }
- }
- return null;
- }
- catch /*(Exception ex)*/
- {
- return null;
- }
- finally
- {
- //EDS过程结束
- //m_cfun.EDSFinishedInstance();
- //关闭连接
- DisConnectSem(connectionEnumType.EDSOnlyPointXRay);
- }
- }
- private void btnReadXray_Click(object sender, EventArgs e)
- {
- OpenFileDialog fileSel = new OpenFileDialog();
- fileSel.Filter = "|*.txt";
- if (DialogResult.OK == fileSel.ShowDialog())
- {
- String str = "";
- //读取Xray文件
- using (StreamReader sr = new StreamReader(fileSel.FileName))
- {
- while (!sr.EndOfStream)
- {
- str += sr.ReadLine() + ",";
- }
- str = str.Substring(0, str.Length - 1);
- string[] xrayData = str.Split(',');
- if (xrayData.Length != 2000)
- {
- return;
- }
- uint[] data = new uint[xrayData.Length];
- for (int i = 0; i < xrayData.Length; i++)
- {
- data[i] = Convert.ToUInt32(xrayData[i]);
- }
- //Xray数据
- xrayByteData = IntArrToByteArr(data);
- int color = Convert.ToInt32(ParseRGB(colorHx16toRGB(m_SubMidWindow.m_MainForm.STDDictionary[STDId].Color)).ToString());
- //根据树节点修改对应的Xray信息
- UpdateSTDXray(STDId, xrayByteData);
- ShowXrayAtlas(color, xrayByteData);
- }
- }
- }
- /// <summary>
- /// 将int[] 转换为 byte[]
- /// </summary>
- /// <param name="intArr"></param>
- /// <returns></returns>
- public static byte[] IntArrToByteArr(uint[] intArr)
- {
- int intSize = sizeof(uint) * intArr.Length;
- byte[] bytArr = new byte[intSize];
- //申请一块非托管内存
- //IntPtr ptr = Marshal.AllocHGlobal(intSize);
- ////复制int数组到该内存块
- //Marshal.Copy(intArr, 0, ptr, intArr.Length);
- ////复制回byte数组
- //Marshal.Copy(ptr, bytArr, 0, bytArr.Length);
- ////释放申请的非托管内存
- //Marshal.FreeHGlobal(ptr);
- for (int i = 0; i < intArr.Length; i++)
- {
- byte[] c1 = BitConverter.GetBytes(intArr[i]);
- c1.CopyTo(bytArr, i * 4);
-
- }
- return bytArr;
- }
- /// <summary>
- /// 将颜色对象转换为uint
- /// </summary>
- /// <param name="color"></param>
- /// <returns></returns>
- public uint ParseRGB(Color color)
- {
- return (uint)(((uint)color.B << 16) | (ushort)(((ushort)color.G << 8) | color.R));
- }
- #region 显示Xray图谱
- /// <summary>
- /// 显示Xray图谱
- /// </summary>
- public void ShowXrayAtlas(int colorValue = 0, byte[] XrayData = null)
- {
- DataTable dt = new DataTable();
- dt.Columns.Add("Color", typeof(int));
- dt.Columns.Add("SPEC", typeof(byte[]));
- DataRow dRow = dt.NewRow();
- dRow["Color"] = colorValue;
- if (XrayData != null)
- {
- dRow["SPEC"] = XrayData;
- }
- else
- {
- dRow["SPEC"] = new byte[8000];
- }
- //将选择行的数据传递给Xray控件
- XrayControl.Dr = dRow;
- XrayControl.Refresh();
- XrayData = null;
- }
- #endregion
- #region 常用数据验证的封装,数字字符的验证
- /// <summary>
- /// 常用数据验证的封装,数字字符的验证
- /// </summary>
- /// <param name="inputVal">需要验证的数值【字符串,或者数字】</param>
- /// <param name="type">类型为哪一个验证</param>
- /// <returns>如果验证成功则返回True,否则返回false</returns>
- public bool IsMatch(string inputVal, int type)
- {
- switch (type)
- {
- case 0:
- return Regex.IsMatch(inputVal, @"^[1-9]d*$"); //匹配正整数
- case 1:
- return Regex.IsMatch(inputVal, @"^-?\d+$"); //匹配整数
- case 2:
- return Regex.IsMatch(inputVal, @"^[A-Za-z0-9]+$"); //匹配由数字和26个英文字母组成的字符串
- case 3:
- 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]*))$"); //匹配正浮点数
- case 4:
- return Regex.IsMatch(inputVal, @"^[\u4e00-\u9fa5]{0,}$"); //匹配汉字
- case 5:
- return Regex.IsMatch(inputVal, @"^[0-9]+(.[0-9]{1,3})?$"); //匹配1~3位小数的正实数
- case 6:
- return Regex.IsMatch(inputVal, @"^[A-Za-z]+$"); //匹配英文字符
- default:
- return true;
- }
- }
- #endregion
- #region 弹出提示
- /// <summary>
- /// 弹出提示
- /// </summary>
- /// <param name="strContent"></param>
- protected void showMessage(string strContent)
- {
- MessageBox.Show(strContent, "Tip");
- }
- #endregion
- #region 连接与关闭设备
- public bool ConnectionSem(connectionEnumType connectionType)
- {
- //获取连接电镜类型
- string connTypeStr = GetConnectionType(connectionType);
- //连接电镜标识
- bool bDisConnResult = false;
- //判断连接状态
- if (!m_bConnectionState)
- {
- //连接电镜设置
- bDisConnResult = m_cfun.ConncetSem();
- }
- if (bDisConnResult)
- {
- m_bConnectionState = true;
- }
- else
- {
- m_bConnectionState = false;
- }
- return bDisConnResult;
- }
- public bool DisConnectSem(connectionEnumType disConnectType)
- {
- //获取关闭电镜类型
- string connTypeStr = GetConnectionType(disConnectType);
- bool bDisConnResult = false;
- if (m_bConnectionState)
- {
- bDisConnResult = m_cfun.DisconnectSem();
- }
- if (bDisConnResult)
- {
- m_bConnectionState = false;
- }
- else
- {
- m_bConnectionState = true;
- }
- return bDisConnResult;
- }
- private string GetConnectionType(connectionEnumType connectionType)
- {
- string connString = string.Empty;
- switch (connectionType)
- {
- //设置单点采集文字内容
- case connectionEnumType.EDSOnlyPointXRay:
- connString = "OnlyPointXRay";
- break;
- //设置多点采集文字内容
- case connectionEnumType.EDSMultiPointXRay:
- connString = "MultiPointXRay";
- break;
- //设置面采集文字内容
- case connectionEnumType.EDSAreaXRay:
- connString = "AreaXRay";
- break;
- //设置图片
- case connectionEnumType.ScanImage:
- connString = "Image";
- break;
- default: break;
- }
- return connString;
- }
- /// <summary>
- /// EDS初始化
- /// </summary>
- public bool EDSInit()
- {
- bool bResult = false;
- //线程调用 加载
- bResult = m_cfun.EDSInit();
- return bResult;
- }
- public enum connectionEnumType
- {
- EDSOnlyPointXRay = 0,
- EDSMultiPointXRay = 1,
- EDSAreaXRay = 2,
- ScanImage = 3
- }
- /// <summary>
- /// 标准Xray状态
- /// </summary>
- public enum STDXrayInfoState
- {
- Add = 0,
- Modify = 1,
- Delete = 2
- }
- #endregion
- /// <summary>
- /// 记录修改后的标准中的Xray信息
- /// </summary>
- public class STDXray
- {
- /// <summary>
- /// 标准编号
- /// </summary>
- private string stdID;
- /// <summary>
- /// Xray数据
- /// </summary>
- private byte[] xrayData;
- /// <summary>
- /// 状态
- /// </summary>
- private int infoState = -1;
- public string StdID { get => stdID; set => stdID = value; }
- public byte[] XrayData { get => xrayData; set => xrayData = value; }
- public int InfoState { get => infoState; set => infoState = value; }
- }
- #endregion
- #region Xray 与 STDDB数据操作
- /// <summary>
- /// 绑定数据库中已存在的Xray信息
- /// </summary>
- public void BindSTDXray()
- {
- //清空STDXray列表中的集合
- m_STDXrayList.Clear();
- //查询
- DataTable dt = m_sc.GetDTFormSysSTDBySQLString("select Id,SPEC from STDMinerals");
- if (dt != null)
- {
- if (dt.Rows.Count > 0)
- {
- foreach (DataRow item in dt.Rows)
- {
- STDXray sXray = new STDXray();
- sXray.StdID = item["Id"].ToString();
- sXray.XrayData = (byte[])item["SPEC"];
- sXray.InfoState = 1;
- m_STDXrayList.Add(sXray);
- }
- }
- }
- }
- bool SaveOtherDataToXray(string STDDBAddress, int id)
- {
- #region 数据库存贮方式一
- System.Data.SQLite.SQLiteConnection m_dbConnection = new System.Data.SQLite.SQLiteConnection("data source='" + STDDBAddress + "'");
- System.Data.SQLite.SQLiteCommand cmm = m_dbConnection.CreateCommand();
- try
- {
- m_dbConnection.Open();
- //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 + ");");
- string insertstr = ("insert into STDMinerals(name) values(" + m_SubMidWindow.m_MainForm.STDDictionary[id].StrName + ");");
- cmm.CommandText = insertstr;
- cmm.ExecuteNonQuery();
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.ToString());
- return false;
- }
- m_dbConnection.Close();
- #endregion
- return true;
- }
- /// <summary>
- /// 保存STDXray至数据库
- /// </summary>
- public void SaveSTDXray()
- {
- ArrayList delArrayList = new ArrayList();
- if (m_STDXrayList != null)
- {
- //if (m_STDXrayList.Count > 0)
- //{
- foreach (STDXray item in m_STDXrayList)
- {
- int infoState = item.InfoState;
- //添加状态 根据Xray信息当前只能按照一条操作
- if (infoState == (int)STDXrayInfoState.Add)
- {
- //if (item.XrayData == null)
- //{
- // item.XrayData = new byte[8000];
- //}
- //string strvaluename = "@data";
- ////编辑添加语句
- //StringBuilder strSqlAdd = new StringBuilder();
- //strSqlAdd.Append("insert into STDMinerals(Id,SPEC) values(" + item.StdID + "," + strvaluename + ");");
- //bool addResult = m_sc.ExecuteBlob(strSqlAdd.ToString(), strvaluename, (byte[])item.XrayData, ((byte[])item.XrayData).Length);
- bool addResult = false;
- //判断STDID在数据库中是否存在
- bool selResult = SelSTDDBBySTDId(item.StdID);
- if (selResult)
- {
- //addResult = UpdateSTDDB(item.StdID, xrayByteData);
- addResult = UpdateSTDDB(item.StdID, item.XrayData);
- }
- else
- {
- addResult = AddSTDDB(item.StdID, item.XrayData);
- }
- if (!addResult)
- {
- continue;
- }
- }
- //修改状态
- else if (infoState == (int)STDXrayInfoState.Modify)
- {
- //判断STDID在数据库中是否存在
- bool selResult = SelSTDDBBySTDId(item.StdID);
- if (selResult)
- {
- UpdateSTDDB(item.StdID, item.XrayData);
- }
- else
- {
- AddSTDDB(item.StdID, item.XrayData);
- }
- }
- //删除状态 编辑批量删除语句
- else if (infoState == (int)STDXrayInfoState.Delete)
- {
- //编辑删除语句
- delArrayList.Add("delete from STDMinerals where id=" + item.StdID + ";");
- }
- }
- //批量删除
- if (delArrayList.Count > 0)
- {
- bool delResult = m_sc.DelSTDInfo(delArrayList);
- }
- //}
- }
- }
- /// <summary>
- /// 添加STD信息至数据库
- /// </summary>
- protected bool AddSTDDB(string stdID, byte[] XrayData)
- {
- if (XrayData == null)
- {
- XrayData = new byte[8000];
- }
- string strvaluename = "@data";
- StringBuilder sqlStrAdd = new StringBuilder();
- sqlStrAdd.Append("insert into STDMinerals(Id,SPEC) values(" + stdID + "," + strvaluename + ");");
- bool addResult = m_sc.ExecuteBlob(sqlStrAdd.ToString(), strvaluename, (byte[])XrayData, ((byte[])XrayData).Length);
- return addResult;
- }
- /// <summary>
- /// 修改STD信息至数据库
- /// </summary>
- protected bool UpdateSTDDB(string stdID, byte[] XrayData)
- {
- if (XrayData == null)
- {
- XrayData = new byte[8000];
- }
- string strValueName = "@data";
- StringBuilder sqlStrUpdate = new StringBuilder();
- sqlStrUpdate.Append("update STDMinerals set SPEC=" + strValueName +" where id=" + stdID + ";");
- bool updateResult = m_sc.ExecuteBlob(sqlStrUpdate.ToString(), strValueName, (byte[])XrayData, ((byte[])XrayData).Length);
- return updateResult;
- }
- /// <summary>
- /// 查询是否存在标准编号
- /// </summary>
- /// <param name="stdID"></param>
- protected bool SelSTDDBBySTDId(string stdID)
- {
- bool selResult = false;
- //编辑查询语句
- StringBuilder sqlStr = new StringBuilder();
- sqlStr.Append("select * from STDMinerals where id=" + stdID + "");
- DataTable dt = m_sc.GetDTFormSysSTDBySQLString(sqlStr.ToString());
- if (dt != null)
- {
- if (dt.Rows.Count > 0)
- {
- //已存在状态
- selResult = true;
- }
- }
- return selResult;
- }
- /// <summary>
- /// 根据选择树节点显示对应的Xray信息
- /// </summary>
- public void SelSTDXray(int Key, STDdata sT)
- {
- if (sT == null)
- {
- return;
- }
- if (m_STDXrayList != null)
- {
- //if (m_STDXrayList.Count > 0)
- //{
- bool isExists = false;
- foreach (STDXray item in m_STDXrayList)
- {
- //修改XrayData信息
- if (item.StdID == Key.ToString())
- {
- string selColor = ParseRGB(colorHx16toRGB(sT.Color)).ToString();
- int colorValue = Convert.ToInt32(selColor);
- //显示Xray信息
- if (item.XrayData != null)
- {
- isExists = true;
- ShowXrayAtlas(colorValue, item.XrayData);
- }
- break;
- }
- }
- if (!isExists)
- {
- ShowXrayAtlas();
- }
- //}
- }
- }
- public void ShowEditContent(string stdID)
- {
- if (m_STDXrayList != null)
- {
- for (int i = 0; i < m_STDXrayList.Count; i++)
- {
- if (m_STDXrayList[i].StdID == stdID)
- {
- //获取修改行的信息
- xrayByteData = (byte[])m_STDXrayList[i].XrayData;
-
- }
- }
- }
- }
- /// <summary>
- /// 根据STDId修改对应的Xray信息
- /// </summary>
- /// <param name="STDId"></param>
- protected void UpdateSTDXray(int STDId, byte[] xrayData)
- {
- if (m_STDXrayList != null)
- {
- //if (m_STDXrayList.Count > 0)
- //{
- bool isExists = false;
- foreach (STDXray item in m_STDXrayList)
- {
- //修改XrayData信息
- if (item.StdID == STDId.ToString())
- {
- item.XrayData = xrayData;
- item.InfoState = (int)STDXrayInfoState.Modify;
- isExists = true;
- break;
- }
- }
- if (!isExists)
- {
- if (!STDId.ToString().Equals(""))
- {
- //添加STD XrayData信息
- STDXray stdXray = new STDXray();
- stdXray.StdID = STDId.ToString();
- stdXray.XrayData = xrayData;
- stdXray.InfoState = (int)STDXrayInfoState.Add;
- m_STDXrayList.Add(stdXray);
- }
- }
- //}
- }
- }
- /// <summary>
- /// 添加STDXray信息
- /// </summary>
- /// <param name="STDid">STDid</param>
- /// <param name="xrayData">Xray信息</param>
- /// <returns></returns>
- protected bool AddSTDXray(int STDId, byte[] xrayData)
- {
- bool addResult = false;
- if (m_STDXrayList != null)
- {
- //if (m_STDXrayList.Count > 0)
- //{
- if (!STDId.ToString().Equals(""))
- {
- //添加STD XrayData信息
- STDXray stdXray = new STDXray();
- stdXray.StdID = STDId.ToString();
- stdXray.XrayData = xrayData;
- stdXray.InfoState = (int)STDXrayInfoState.Add;
- m_STDXrayList.Add(stdXray);
- addResult = true;
- }
- //}
- }
- return addResult;
- }
- /// <summary>
- /// 删除STDXray信息
- /// </summary>
- /// <param name="STDId">所选要删除的STDId</param>
- /// <returns></returns>
- public bool DelSTDXray(int STDId)
- {
- bool delResult = false;
- if (m_STDXrayList != null)
- {
- //if (m_STDXrayList.Count > 0)
- //{
- if (!STDId.ToString().Equals(""))
- {
- foreach (STDXray item in m_STDXrayList)
- {
- //修改XrayData信息
- if (item.StdID == STDId.ToString())
- {
- item.InfoState = (int)STDXrayInfoState.Delete;
- delResult = true;
- break;
- }
- }
- }
- //}
- }
- return delResult;
- }
- #endregion
- #region 控制BSE、化学式、元素本文框中不能输入下划线
- /// <summary>
- /// 控件不能输入下划线
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void textBox_KeyPress(object sender, KeyPressEventArgs e)
- {
- if ((e.KeyChar >= '0' && e.KeyChar <= '9') || (e.KeyChar >= 'A' && e.KeyChar <= 'Z') ||
- (e.KeyChar >= 'a' && e.KeyChar <= 'z') || (e.KeyChar == 8) || !(e.KeyChar == '_'))
- {
- e.Handled = false;
- }
- else
- {
- e.Handled = true;
- }
- }
- #endregion
- private void btnTest_Click(object sender, EventArgs e)
- {
- XrayContrastForm xrayContrastForm = new XrayContrastForm();
- xrayContrastForm.STDDictionary = m_SubMidWindow.m_MainForm.STDDictionary;
- xrayContrastForm.ShowDialog();
- }
- string ElementKeyOrSub = "";
- private void dataGridView_KeyElements_CellClick(object sender, DataGridViewCellEventArgs e)
- {
- ElementKeyOrSub = dataGridView_KeyElements.CurrentCell.Value.ToString();
- dataGridView_KeyElements.Columns.RemoveAt(e.ColumnIndex);
- DataGridViewButtonColumn dataGridViewButtonColumn = new DataGridViewButtonColumn();
- dataGridViewButtonColumn.Name = dataGridView_SubElements.Columns.Count.ToString();
- dataGridView_SubElements.Columns.Add(dataGridViewButtonColumn);
- if (dataGridView_SubElements.Rows.Count == 0)
- {
- DataGridViewRow row = new DataGridViewRow();
- dataGridView_SubElements.Rows.Add(row);
- }
- dataGridView_SubElements.Rows[0].Cells[dataGridView_SubElements.Columns.Count - 1].Value = ElementKeyOrSub;
- dataGridView_SubElements.ClearSelection();
- dataGridView_KeyElements.ClearSelection();
- }
- private void dataGridView_SubElements_CellClick(object sender, DataGridViewCellEventArgs e)
- {
- ElementKeyOrSub = dataGridView_SubElements.CurrentCell.Value.ToString();
- dataGridView_SubElements.Columns.RemoveAt(e.ColumnIndex);
- DataGridViewButtonColumn dataGridViewButtonColumn = new DataGridViewButtonColumn();
- dataGridViewButtonColumn.Name = dataGridView_SubElements.Columns.Count.ToString();
- dataGridView_KeyElements.Columns.Add(dataGridViewButtonColumn);
- if (dataGridView_KeyElements.Rows.Count == 0)
- {
- DataGridViewRow row = new DataGridViewRow();
- dataGridView_KeyElements.Rows.Add(row);
- }
- dataGridView_KeyElements.Rows[0].Cells[dataGridView_KeyElements.Columns.Count - 1].Value = ElementKeyOrSub;
- dataGridView_KeyElements.ClearSelection();
- dataGridView_SubElements.ClearSelection();
- }
- private float X=1;
- private float Y=1;
- private void STDEditor_Resize(object sender, EventArgs e)
- {
- float newx = (this.Width) / X;
- float newy = this.Height/ Y;
- AmplificationFactor = newy;
- setControls(newx, newy, this.tabSTDStandrad.TabPages[0]);
- //button_Extend.BackColor = SystemColors.ControlDarkDark;
- }
- private void setTag(Control cons)
- {
- foreach (Control con in cons.Controls)
- {
- con.Tag = con.Width + ":" + con.Height + ":" + con.Left + ":" + con.Top + ":" + con.Font.Size;
- if (con.Controls.Count > 0)
- setTag(con);
- }
- }
- private void setControls(float newx, float newy, Control cons)
- {
- foreach (Control con in cons.Controls)
- {
- if (false)
- {
-
- }
- else
- {
- string[] mytag = con.Tag.ToString().Split(':');
- float a = Convert.ToSingle(mytag[0]) * newx;
- con.Width = (int)a;
- a = Convert.ToSingle(mytag[1]) * newy;
- con.Height = (int)(a);
- a = Convert.ToSingle(mytag[2]) * newx;
- con.Left = (int)(a);
- a = Convert.ToSingle(mytag[3]) * newy;
- con.Top = (int)(a);
- Single currentSize ;
- if (con.Name == "button_Extend")
- {
- currentSize = 6f;
- }
- else
- {
- if (Math.Max(newx, newy) < 1)
- {
- currentSize = Convert.ToSingle(mytag[4]) * 1;
- }
- else
- {
- currentSize = Convert.ToSingle(mytag[4]) * Math.Max(newx, newy);
- }
- }
- con.Font = new Font(con.Font.Name, currentSize, con.Font.Style, con.Font.Unit);
- if (con.Controls.Count > 0)
- {
- setControls(newx, newy, con);
- }
- }
- }
- }
- Form_PeriodicTable form_PeriodicTable;
- private void button_PeriodicTableSwitch_Click(object sender, EventArgs e)
- {
- if (form_PeriodicTable == null) //如果子窗体为空则创造实例 并显示
- {
- form_PeriodicTable = new Form_PeriodicTable();
- if (table_STDEditor["language"].ToString() == "EN")
- {
- form_PeriodicTable.BackgroundImage = global::OTSPartA_STDEditor.Properties.Resources.PeriodicTable_EN;
- }
- else
- {
- form_PeriodicTable.BackgroundImage = global::OTSPartA_STDEditor.Properties.Resources.PeriodicTable_ZH;
- }
- form_PeriodicTable.Show();
- }
- else
- {
- if (form_PeriodicTable.IsDisposed) //若子窗体关闭 则打开新子窗体 并显示
- {
- form_PeriodicTable = new Form_PeriodicTable();
- if (table_STDEditor["language"].ToString() == "EN")
- {
- form_PeriodicTable.BackgroundImage = global::OTSPartA_STDEditor.Properties.Resources.PeriodicTable_EN;
- }
- else
- {
- form_PeriodicTable.BackgroundImage = global::OTSPartA_STDEditor.Properties.Resources.PeriodicTable_ZH;
- }
- form_PeriodicTable.Show();
- }
- else
- {
- form_PeriodicTable.Activate(); //使子窗体获得焦点
- }
- }
- }
- private void button_ImportFromResult_Click(object sender, EventArgs e)
- {
- OpenFileDialog openFileDialog = new OpenFileDialog();
- openFileDialog.Filter = "(*.db)|*.db";
- openFileDialog.RestoreDirectory = true;
- openFileDialog.FilterIndex = 1;
- if (openFileDialog.ShowDialog() == DialogResult.OK)
- {
- try
- {
- System.Data.SQLite.SQLiteConnection m_dbConnection = new System.Data.SQLite.SQLiteConnection("data source='" + openFileDialog.FileName + "'");
- m_dbConnection.Open();
- 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();
- Result ret=ImportFromResult(STDId, m_dbConnection);
- if(ret== Result.NoMatched)
- {
- MessageBox.Show("No matching energy spectrum data was found", "Tip");
- }
- m_dbConnection.Close();
- int color = Convert.ToInt32(ParseRGB(colorHx16toRGB(m_SubMidWindow.m_MainForm.STDDictionary[int.Parse(STDId)].Color)).ToString());
- for(int i=0;i< m_STDXrayList.Count;i++)
- {
- if(m_STDXrayList[i].StdID== STDId)
- {
- ShowXrayAtlas(color, m_STDXrayList[i].XrayData);
- break;
- }
- }
- }
- catch /*(Exception ex)*/
- {
- MessageBox.Show("Failed to load Xray data!", "Tip");
- }
- }
- }
- public Result ImportFromResult(string STDId, System.Data.SQLite.SQLiteConnection m_dbConnection)
- {
- try
- {
- System.Data.SQLite.SQLiteDataAdapter m_dataAdapter = new System.Data.SQLite.SQLiteDataAdapter("select FieldId ,XrayId from IncAData where TypeId ="+ STDId , m_dbConnection);
- DataSet ds = new DataSet();
- m_dataAdapter.Fill(ds);
- DataTable dt = ds.Tables[0];
- if (dt != null)
- {
- if (dt.Rows.Count > 0)
- {
- string sqlstr = "select XrayData from XRayData where FieldId = " + dt.Rows[0]["FieldId"] + " AND XrayIndex =" + dt.Rows[0]["XrayId"];
- m_dataAdapter = new System.Data.SQLite.SQLiteDataAdapter(sqlstr, m_dbConnection);
- ds = new DataSet();
- m_dataAdapter.Fill(ds);
- dt = ds.Tables[0];
- if (dt != null)
- {
- if (dt.Rows.Count > 0)
- {
- DialogResult dr = MessageBox.Show("ID Num:" + STDId+ ", this rule has found the first match object, is it loaded?", "Tip", MessageBoxButtons.OKCancel);
- if(dr == DialogResult.OK)
- {
- m_SubMidWindow.m_MainForm.IsModified = true;
- if (SelSTDDBBySTDId(STDId))
- {
- if (MessageBox.Show("ID Num:" + STDId + ", the database already contains records of this rule XRay curve, is it overwritten?", "Tip", MessageBoxButtons.OKCancel) == DialogResult.OK)
- {
- UpdateSTDXray(int.Parse(STDId), (byte[])dt.Rows[0]["XrayData"]);
- }
- }
- else
- {
- UpdateSTDXray(int.Parse(STDId), (byte[])dt.Rows[0]["XrayData"]);
- }
- }
- return Result.Success;
- }
- else
- {
- return Result.NoMatched;
- }
- }
- else
- {
- return Result.NoMatched;
- }
- }
- else
- {
- return Result.NoMatched;
- }
- }
- else
- {
- return Result.NoMatched;
- }
-
- }
- catch /*(Exception ee)*/
- {
- MessageBox.Show("Failed to load Xray data!", "Tip");
- return Result.Fail;
- }
- }
- private void textbox_STDEditor_MouseLeave(object sender, EventArgs e)
- {
- dataGridView_KeyElements.Rows.Clear();
- dataGridView_KeyElements.Columns.Clear();
- string str_RemoveBlank = textbox_STDEditor.Text.ToString().Replace(" ", "");
- str_RemoveBlank = str_RemoveBlank.Replace("\r\n", "");
- str_RemoveBlank = str_RemoveBlank.Replace("forth_elem", "");
- string[] str_Removeand = System.Text.RegularExpressions.Regex.Split(str_RemoveBlank, "and", System.Text.RegularExpressions.RegexOptions.None);
- List<string> str_Removeandor = new List<string>();
- for (int i = 0; i < str_Removeand.Length; i++)
- {
- str_Removeandor.AddRange(System.Text.RegularExpressions.Regex.Split(str_Removeand[i], "or", System.Text.RegularExpressions.RegexOptions.None));
- }
- List<string> list_all = new List<string>();
- for (int i = 0; i < str_Removeandor.Count; i++)
- {
- list_all.AddRange(str_Removeandor[i].Split(new char[] { '+', '-', '*', '/', '=', '>', '<', '(', ')' }));
- }
- List<string> UsingElementL = new List<string>();
- for (int i = 0; i < list_all.Count; i++)
- {
- if (this.comboBox_PeriodicTable.Items.Contains(list_all[i]))
- {
- if (!UsingElementL.Contains(list_all[i]))
- {
- UsingElementL.Add(list_all[i]);
- }
- }
- }
- List<string> SubElements = new List<string>();
- for (int i = 0; i < dataGridView_SubElements.ColumnCount; i++)
- {
- if (UsingElementL.Contains(dataGridView_SubElements.Rows[0].Cells[i].Value))
- {
- SubElements.Add(dataGridView_SubElements.Rows[0].Cells[i].Value.ToString());
- }
- }
- dataGridView_SubElements.Rows.Clear();
- dataGridView_SubElements.Columns.Clear();
- for (int i = 0; i < SubElements.Count; i++)
- {
- DataGridViewButtonColumn dataGridViewButtonColumn = new DataGridViewButtonColumn();
- dataGridViewButtonColumn.Name = dataGridView_SubElements.Columns.Count.ToString();
- dataGridView_SubElements.Columns.Add(dataGridViewButtonColumn);
- if (dataGridView_SubElements.Rows.Count == 0)
- {
- DataGridViewRow row = new DataGridViewRow();
- dataGridView_SubElements.Rows.Add(row);
- }
- dataGridView_SubElements.Rows[0].Cells[dataGridView_SubElements.ColumnCount - 1].Value = SubElements[i];
- }
- if (SubElements.Count > 0)
- {
- for (int i = 0; i < UsingElementL.Count; i++)
- {
- if (!SubElements.Contains(UsingElementL[i]))
- {
- DataGridViewButtonColumn dataGridViewButtonColumn = new DataGridViewButtonColumn();
- dataGridViewButtonColumn.Name = dataGridView_KeyElements.Columns.Count.ToString();
- dataGridView_KeyElements.Columns.Add(dataGridViewButtonColumn);
- if (dataGridView_KeyElements.Rows.Count == 0)
- {
- DataGridViewRow row = new DataGridViewRow();
- dataGridView_KeyElements.Rows.Add(row);
- }
- dataGridView_KeyElements.Rows[0].Cells[dataGridView_KeyElements.ColumnCount - 1].Value = UsingElementL[i];
- }
- }
- }
- else
- {
- for (int i = 0; i < UsingElementL.Count; i++)
- {
- DataGridViewButtonColumn dataGridViewButtonColumn = new DataGridViewButtonColumn();
- dataGridViewButtonColumn.Name = dataGridView_KeyElements.Columns.Count.ToString();
- dataGridView_KeyElements.Columns.Add(dataGridViewButtonColumn);
- if (dataGridView_KeyElements.Rows.Count == 0)
- {
- DataGridViewRow row = new DataGridViewRow();
- dataGridView_KeyElements.Rows.Add(row);
- }
- dataGridView_KeyElements.Rows[0].Cells[i].Value = UsingElementL[i];
- }
- }
- dataGridView_KeyElements.ClearSelection();
- dataGridView_SubElements.ClearSelection();
- }
- public void ShowTabXray()
- {
- tabSTDStandrad.SelectedIndex = 1;
- }
- public void ShowSTD()
- {
- tabSTDStandrad.SelectedIndex = 0;
- }
- }
- }
|