12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578 |
- 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 System.Xml;
- using System.Xml.Linq;
- namespace OTSPartA_STDEditor
- {
- public partial class Form_ConstantsEditor : Form
- {
- //readonly 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"};
- //readonly string[] OtherSymbol = { "first_elem" , "second_elem" , "third_elem" , "forth_elem", "fifth_elem", "sixth_elem", "seventh_elem","eighth_elem","ninth_elem", "tenth_elem", "Element1", "Element2" };
- public Form_ConstantsEditor()
- {
- InitializeComponent();
- //changeSize();
- }
- //国际化
- Language lan;
- System.Collections.Hashtable table;
- //public string Language = "English";
- string Address_backup = Application.StartupPath + "\\Config\\SysData\\OTSParticleSTD_backup.xml";
- string Address = Application.StartupPath + "\\Config\\SysData\\OTSParticleSTD.xml";
- private void Form_ConstantsEditor_Load(object sender, EventArgs e)
- {
-
- //初始化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");
- this.comboBox_ImgProperty.Items.Add("Dmean");
- this.comboBox_ImgProperty.Items.Add("Area");
- this.comboBox_ImgProperty.Items.Add("Dferet");
- this.comboBox_ImgProperty.Items.Add("With");
- 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");
- comboBox_ImgProperty.SelectedIndex = comboBox_ImgProperty.Items.IndexOf("Dmax");
- //this.comboBox_Constants.Items.Add("MAC#0");
- //this.comboBox_Constants.Items.Add("MAC#1");
- //this.comboBox_Constants.Items.Add("MAC#2");
- //this.comboBox_Constants.Items.Add("MAC#3");
- //this.comboBox_Constants.Items.Add("MAC#4");
- //this.comboBox_Constants.Items.Add("MAC#5");
- //this.comboBox_Constants.Items.Add("MAC#6");
- //this.comboBox_Constants.Items.Add("MAC#7");
- //this.comboBox_Constants.Items.Add("MAC#8");
- //this.comboBox_Constants.Items.Add("MAC#9");
- //comboBox_Constants.SelectedIndex = comboBox_Constants.Items.IndexOf("MAC#1");
- 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.Suggest;
- this.comboBox_PeriodicTable.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.CustomSource;
- this.comboBox_PeriodicTable.AutoCompleteCustomSource = sc;
- checkBox_0.Checked = false;
- checkBox_1.Checked = false;
- checkBox_2.Checked = false;
- checkBox_3.Checked = false;
- checkBox_4.Checked = false;
- checkBox_5.Checked = false;
- checkBox_6.Checked = false;
- checkBox_7.Checked = false;
- checkBox_8.Checked = false;
- checkBox_9.Checked = false;
- textBox_0.ReadOnly = true;
- textBox_1.ReadOnly = true;
- textBox_2.ReadOnly = true;
- textBox_3.ReadOnly = true;
- textBox_4.ReadOnly = true;
- textBox_5.ReadOnly = true;
- textBox_6.ReadOnly = true;
- textBox_7.ReadOnly = true;
- textBox_8.ReadOnly = true;
- textBox_9.ReadOnly = true;
- textBox_Density.ReadOnly = false;
- textBox_Electrical_conductivity.ReadOnly = false;
- textBox_Hardness.ReadOnly = false;
- btn_dbs.Enabled = true;
-
- 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;
- XmlDocument doc = new XmlDocument();
- //string Address = Application.StartupPath.Substring(0, Application.StartupPath.Length-35) + "\\Opton\\OTSPartA\\OTS\\Bin\\Win32\\Debug\\Config\\SysData\\OTSParticleSTD.xml";
- //string Address = ".\\Config\\SysData\\OTSParticleSTD.xml";
- doc.Load(Address);
- LoadXmlToTreeControl(doc, XmlTree_STDlist.Nodes, XmlTree_MaxEDSRules.Nodes, XmlTree_ZeroElementRules.Nodes);
- button_UpOrder.Enabled = false;
- button_DownOrder.Enabled = false;
- textBox_MaxEDSTime.ReadOnly = true;
- this.textbox_STDEditor.Text = "";
- //this.XmlTree.TabStop = false;
- panel_OTSPeriodicTable.Visible = false;
- //修改窗体宽度
- //this.Width = this.Width - panel_OTSPeriodicTable.Width - 5;
- //if (XmlTree.GetNodeCount(true) != 0)
- //{
- // this.XmlTree.SelectedNode = XmlTree.Nodes[0];
- //}
- lan = new Language(this);
- table = lan.GetNameTable(this.Name);
- if (table["language"].ToString() == "EN")
- {
- panel_OTSPeriodicTable.BackgroundImage = global::OTSPartA_STDEditor.Properties.Resources.PeriodicTable_EN;
- PeriodicTableSwitch.BackgroundImage = global::OTSPartA_STDEditor.Properties.Resources.STDEditoName;
- PeriodicTableSwitch.Text = "";
- }
- else
- {
- panel_OTSPeriodicTable.BackgroundImage = global::OTSPartA_STDEditor.Properties.Resources.PeriodicTable_ZH;
- PeriodicTableSwitch.Text = "元素周期表";
- }
- panel_OTSPeriodicTable.Visible = false;
- this.Width = this.Width - panel_OTSPeriodicTable.Width - 5;
- Size size = Screen.PrimaryScreen.WorkingArea.Size; Left = (size.Width - Width) / 2;
- Top = (size.Height - Height) / 2;
- WindowState = FormWindowState.Normal;
- //groupBox_XmlTree_MaxEDSRules.Focus();
- this.XmlTree_STDlist.HideSelection = false;//失去焦点后不隐藏选中节点
- XmlTree_STDlist.Focus();
- if (XmlTree_STDlist.Nodes.Count > 0)
- {
- XmlTree_STDlist.SelectedNode = XmlTree_STDlist.Nodes[0];
- XmlTree_STDlist_AfterSelect(XmlTree_STDlist, new TreeViewEventArgs(XmlTree_STDlist.SelectedNode));
- }
- }
- /// <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);
- }
- }
- /// <summary>
- /// [颜色:RGB转成16进制]
- /// </summary>
- /// <param name="R">红 int</param>
- /// <param name="G">绿 int</param>
- /// <param name="B">蓝 int</param>
- /// <returns></returns>
- public static string colorRGBtoHx16(int R, int G, int B)
- {
- return System.Drawing.ColorTranslator.ToHtml(System.Drawing.Color.FromArgb(R, G, B));
- }
- //XmlTree_STDlist、XmlTree_MaxEDSRules、XmlTree_ZeroElementRules和 ConstantsPage页
- void LoadXmlToTreeControl(XmlDocument xml, TreeNodeCollection XmlTree_STDlist, TreeNodeCollection XmlTree_MaxEDSRules, TreeNodeCollection XmlTree_ZeroElementRules)
- {
- XmlNode root = xml.SelectSingleNode("XMLData");
- XmlNodeList root2 = root.SelectNodes("Collection");
- for (int j = 0; j < root2.Count; j++)
- {
- if (root2[j].Attributes["RegName"].Value.ToString()== "STDList")
- {
- XmlNodeList childlist = root2[j].ChildNodes;
- for (int i = 0; i < childlist.Count; i++)
- {
- TreeNode new_child = new TreeNode();//定义一个TreeNode节点对象
- new_child.Name = childlist[i].Attributes["Hardness"].Value + "_" + childlist[i].Attributes["Density"].Value + "_" + childlist[i].Attributes["Electrical_conductivity"].Value+"$"+ childlist[i].Attributes["KeyElementList"].Value + "$" + childlist[i].Attributes["SubElementList"].Value;
- new_child.Text = childlist[i].Attributes["StrName"].Value;
- new_child.Tag = childlist[i].Attributes["Expression"].Value;
- new_child.ToolTipText = childlist[i].Attributes["STDId"].Value;
- new_child.BackColor = colorHx16toRGB(childlist[i].Attributes["Color"].Value);
- XmlTree_STDlist.Add(new_child);
- }
- }
- if (root2[j].Attributes["RegName"].Value.ToString() == "ZeroElementRules")
- {
- XmlNodeList childlist = root2[j].ChildNodes;
- for (int i = 0; i < childlist.Count; i++)
- {
- TreeNode new_child = new TreeNode();//定义一个TreeNode节点对象
- new_child.Text = childlist[i].Attributes["ZeroElement"].Value+"=0";
- new_child.Tag = childlist[i].Attributes["Expression"].Value;
- XmlTree_ZeroElementRules.Add(new_child);
- }
- }
- if (root2[j].Attributes["RegName"].Value.ToString() == "MaxEDSRules")
- {
- XmlNodeList childlist = root2[j].ChildNodes;
- if (childlist.Count != 0)
- {
- for (int i = 0; i < childlist.Count; i++)
- {
- TreeNode new_child = new TreeNode();//定义一个TreeNode节点对象
- //new_child.Name = childlist[i].Attributes["MaxEDSTime"].Value;
- new_child.Tag = childlist[i].Attributes["Expression"].Value;
- new_child.Text = "Rule" + i.ToString();
- XmlTree_MaxEDSRules.Add(new_child);
- }
- if (childlist[0].Attributes["MaxEDSTime"] != null)
- {
- textBox_MaxEDSTime.Text = childlist[0].Attributes["MaxEDSTime"].Value;
- }
- }
- }
- }
- XmlNode root3 = root.SelectSingleNode("Member");
- string ConstantsStr = root3.Attributes["value"].Value;
- ConstantsStr = ConstantsStr.Replace(" ", "");
- string[] ConstantsStr2 = ConstantsStr.Split(',');
- this.comboBox_Constants.Items.Clear();
- this.comboBox_Constants.Items.AddRange(ConstantsStr2);
- List<string> Constantslist = new List<string>();
- for (int i = 0; i < ConstantsStr2.Length; i++)
- {
- Constantslist.AddRange(ConstantsStr2[i].Split('='));
- }
- for (int i = 0; i < Constantslist.Count; i += 2)
- {
- if (Constantslist[i].Contains("MAC#0"))
- {
- this.checkBox_0.Checked = true;
- this.textBox_0.ReadOnly = false;
- this.textBox_0.Text = Constantslist[i + 1];
- }
- else if (Constantslist[i].Contains("MAC#1"))
- {
- this.checkBox_1.Checked = true;
- this.textBox_1.ReadOnly = false;
- this.textBox_1.Text = Constantslist[i + 1];
- }
- else if (Constantslist[i].Contains("MAC#2"))
- {
- this.checkBox_2.Checked = true;
- this.textBox_2.ReadOnly = false;
- this.textBox_2.Text = Constantslist[i + 1];
- }
- else if (Constantslist[i].Contains("MAC#3"))
- {
- this.checkBox_3.Checked = true;
- this.textBox_3.ReadOnly = false;
- this.textBox_3.Text = Constantslist[i + 1];
- }
- else if (Constantslist[i].Contains("MAC#4"))
- {
- this.checkBox_4.Checked = true;
- this.textBox_4.ReadOnly = false;
- this.textBox_4.Text = Constantslist[i + 1];
- }
- else if (Constantslist[i].Contains("MAC#5"))
- {
- this.checkBox_5.Checked = true;
- this.textBox_5.ReadOnly = false;
- this.textBox_5.Text = Constantslist[i + 1];
- }
- else if (Constantslist[i].Contains("MAC#6"))
- {
- this.checkBox_6.Checked = true;
- this.textBox_6.ReadOnly = false;
- this.textBox_6.Text = Constantslist[i + 1];
- }
- else if (Constantslist[i].Contains("MAC#7"))
- {
- this.checkBox_7.Checked = true;
- this.textBox_7.ReadOnly = false;
- this.textBox_7.Text = Constantslist[i + 1];
- }
- else if (Constantslist[i].Contains("MAC#8"))
- {
- this.checkBox_8.Checked = true;
- this.textBox_8.ReadOnly = false;
- this.textBox_8.Text = Constantslist[i + 1];
- }
- else if (Constantslist[i].Contains("MAC#9"))
- {
- this.checkBox_9.Checked = true;
- this.textBox_9.ReadOnly = false;
- this.textBox_9.Text = Constantslist[i + 1];
- }
- }
- }
- 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 SetGrayExceptSelectedNode(TreeView Tree, TreeNode SelectedNode)
- {
- foreach (TreeNode node in Tree.Nodes)
- {
- if (node != SelectedNode)
- {
- node.ForeColor = Color.Gray;
- }
- }
- }
- //恢复所有节点颜色为可用
- private void SetBlackAllNodes(TreeView Tree)
- {
- foreach (TreeNode node in Tree.Nodes)
- {
- node.ForeColor = Color.Black;
- }
- }
- //点击节点
- private void XmlTree_STDlist_MouseClick(object sender, MouseEventArgs e)
- {
- //if (e.Button == MouseButtons.Left)
- //{
- // Point ClickPoint = new Point(e.X, e.Y);
- // TreeNode CurrentNode = XmlTree_STDlist.GetNodeAt(ClickPoint);
- // if (CurrentNode != null)//判断你点的是不是一个节点
- // {
- // if (XmlTree_STDlist.SelectedNode != null&& XmlTree_STDlist.SelectedNode != CurrentNode)
- // {
- // //判断Hardness、Density、Electrical_conductivity
- // double dHardness = 0, dDensity = 0, dElectrical_conductivity = 0;
- // if (!double.TryParse(textBox_Hardness.Text, out dHardness))
- // {
- // MessageBox.Show("硬度输入错误,请输入数字!");
- // SetGrayExceptSelectedNode(XmlTree_STDlist, XmlTree_STDlist.SelectedNode);
- // return;
- // }
- // if (!double.TryParse(textBox_Density.Text, out dDensity))
- // {
- // MessageBox.Show("密度输入错误,请输入数字!");
- // SetGrayExceptSelectedNode(XmlTree_STDlist, XmlTree_STDlist.SelectedNode);
- // return;
- // }
- // if (!double.TryParse(textBox_Electrical_conductivity.Text, out dElectrical_conductivity))
- // {
- // MessageBox.Show("导电性输入错误,请输入数字!");
- // SetGrayExceptSelectedNode(XmlTree_STDlist, XmlTree_STDlist.SelectedNode);
- // return;
- // }
- // //判断textbox_STDEditor
- // if (!Checktextbox_STDEditor())
- // {
- // SetGrayExceptSelectedNode(XmlTree_STDlist, XmlTree_STDlist.SelectedNode);
- // return;
- // }
- // XmlTree_STDlist_SaveBeforeMouseClick(e);
-
- // }
- // SetBlackAllNodes(XmlTree_STDlist);
- // XmlTree_STDlist.SelectedNode = CurrentNode;
- // XmlTree_STDlist.LabelEdit = true;
- // this.textbox_STDEditor.Text = XmlTree_STDlist.SelectedNode.Tag.ToString();
- // btn_dbs.BackColor = XmlTree_STDlist.SelectedNode.BackColor;
- // string[] strOther = XmlTree_STDlist.SelectedNode.Name.Split('_');
- // textBox_Hardness.Text = strOther[0];
- // textBox_Density.Text = strOther[1];
- // textBox_Electrical_conductivity.Text = strOther[2];
- // if (UpOrder.Enabled == false)
- // {
- // UpOrder.Enabled = true;
- // }
- // if (DownOrder.Enabled == false)
- // {
- // DownOrder.Enabled = true;
- // }
- // if (XmlTree_STDlist.SelectedNode.PrevNode == null)
- // {
- // UpOrder.Enabled = false;
- // }
- // else if (XmlTree_STDlist.SelectedNode.NextNode == null)
- // {
- // DownOrder.Enabled = false;
- // }
- // }
- //}
-
- //if (e.Button == MouseButtons.Right)
- //{
- // Point ClickPoint = new Point(e.X, e.Y);
- // TreeNode CurrentNode = XmlTree.GetNodeAt(ClickPoint);
- // if (CurrentNode != null)//判断你点的是不是一个节点
- // {
- // XmlTree.SelectedNode = CurrentNode;//选中这个节点
- // XmlTree.LabelEdit = true;
- // this.textbox_STDEditor.Text = XmlTree.SelectedNode.Tag.ToString();
- // }
- //}
- }
-
-
- //XmlTree_STDlist点击节点前保存数据-Hardness、Density、Electrical_conductivity、textbox_STDEditor
- void XmlTree_STDlist_SaveBeforeMouseClick(MouseEventArgs e)
- {
- if ((this.textbox_STDEditor.Text != null) && (XmlTree_STDlist.SelectedNode != null))
- {
- XmlTree_STDlist.SelectedNode.Tag = this.textbox_STDEditor.Text;
- XmlTree_STDlist.SelectedNode.Name = textBox_Hardness.Text + "_" + textBox_Density.Text + "_" + textBox_Electrical_conductivity.Text;
- string sKeyElements = "";
- for (int i = 0; i < dataGridView_KeyElements.Columns.Count; i++)
- {
- sKeyElements += dataGridView_KeyElements.Rows[0].Cells[i].Value.ToString() + ",";
- }
- if (sKeyElements.Length > 0)
- {
- sKeyElements = sKeyElements.Substring(0, sKeyElements.Length - 1);
- }
- string sSubElements = "";
- for (int i = 0; i < dataGridView_SubElements.Columns.Count; i++)
- {
- sSubElements += dataGridView_SubElements.Rows[0].Cells[i].Value.ToString() + ",";
- }
- if (sSubElements.Length > 0)
- {
- sSubElements = sSubElements.Substring(0, sSubElements.Length - 1);
- }
- XmlTree_STDlist.SelectedNode.Name += "$" + sKeyElements + "$" + sSubElements;
- }
- }
- //删除
- private void DeleteTreeNode_Click(object sender, EventArgs e)
- {
- try
- {
- TreeView XmlTree = (TreeView)XmlTreeMenuStrip.SourceControl;
- if (XmlTree.SelectedNode != null)
- {
- if (XmlTree != null)
- {
- if (XmlTree.SelectedNode.NextNode != null)
- {
- TreeNode Temp = XmlTree.SelectedNode.NextNode;
- XmlTree.SelectedNode.Remove();
- XmlTree.SelectedNode = Temp;
- }
- else if (XmlTree.SelectedNode.PrevNode != null)
- {
- TreeNode Temp = XmlTree.SelectedNode.PrevNode;
- XmlTree.SelectedNode.Remove();
- XmlTree.SelectedNode = Temp;
- }
- else
- {
- XmlTree.SelectedNode.Remove();
- XmlTree.SelectedNode = null;
- if (XmlTree.Name == "XmlTree_STDlist")
- {
- textbox_STDEditor.Text = "";
- textBox_Density.Text = "";
- textBox_Electrical_conductivity.Text = "";
- textBox_Hardness.Text = "";
- btn_dbs.BackColor = Color.White;
- }
- if (XmlTree.Name == "XmlTree_MaxEDSRules")
- {
- textbox_STDEditor.Text = "";
- textBox_MaxEDSTime.Text = "";
- }
- if (XmlTree.Name == "XmlTree_ZeroElementRules")
- {
- textbox_STDEditor.Text = "";
- }
- }
- }
- }
- else
- {
- MessageBox.Show(table["message1"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.ToString(), table["message32"].ToString());
- }
- }
- //新建
- private void AddTreeNode_Click(object sender, EventArgs e)
- {
- try
- {
- if (tabControl_Rules.SelectedIndex == 0)
- {
- //保存节点当前数据
- if (XmlTree_STDlist.SelectedNode != null)
- {
- //判断Hardness、Density、Electrical_conductivity
- double dHardness = 0, dDensity = 0, dElectrical_conductivity = 0;
- if (!double.TryParse(textBox_Hardness.Text, out dHardness) || (double.Parse(textBox_Hardness.Text) <= 0))
- {
- textBox_Hardness.Focus();
- textBox_Hardness.SelectAll();
- MessageBox.Show(table["message2"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- if (!double.TryParse(textBox_Density.Text, out dDensity)||double.Parse(textBox_Density.Text)<=0)
- {
- textBox_Density.Focus();
- textBox_Density.SelectAll();
- MessageBox.Show(table["message3"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- if (!double.TryParse(textBox_Electrical_conductivity.Text, out dElectrical_conductivity)||double.Parse(textBox_Electrical_conductivity.Text)<=0)
- {
- textBox_Electrical_conductivity.Focus();
- textBox_Electrical_conductivity.SelectAll();
- MessageBox.Show(table["message4"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- //判断textbox_STDEditor
- if (!Checktextbox_STDEditor())
- {
- return;
- }
- XmlTree_STDlist.SelectedNode.Tag = this.textbox_STDEditor.Text;
- XmlTree_STDlist.SelectedNode.Name = textBox_Hardness.Text + "_" + textBox_Density.Text + "_" + textBox_Electrical_conductivity.Text;
- string sKeyElements = "";
- for (int i = 0; i < dataGridView_KeyElements.Columns.Count; i++)
- {
- sKeyElements += dataGridView_KeyElements.Rows[0].Cells[i].Value.ToString() + ",";
- }
- if (sKeyElements.Length > 0)
- {
- sKeyElements = sKeyElements.Substring(0, sKeyElements.Length - 1);
- }
- string sSubElements = "";
- for (int i = 0; i < dataGridView_SubElements.Columns.Count; i++)
- {
- sSubElements += dataGridView_SubElements.Rows[0].Cells[i].Value.ToString() + ",";
- }
- if (sSubElements.Length > 0)
- {
- sSubElements = sSubElements.Substring(0, sSubElements.Length - 1);
- }
- XmlTree_STDlist.SelectedNode.Name += "$" + sKeyElements + "$" + sSubElements;
- }
- }
- else if (tabControl_Rules.SelectedIndex == 1)
- {
- if (XmlTree_MaxEDSRules.SelectedNode != null)
- {
- //判断MaxEDSTime
- double dMaxEDSTime = 0;
- if (!double.TryParse(textBox_MaxEDSTime.Text, out dMaxEDSTime) || double.Parse(textBox_MaxEDSTime.Text) <= 0)
- {
- MessageBox.Show(table["message8"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- //判断textbox_STDEditor
- if (!Checktextbox_STDEditor())
- {
- return;
- }
- XmlTree_MaxEDSRules.SelectedNode.Tag = this.textbox_STDEditor.Text;
- //XmlTree_MaxEDSRules.SelectedNode.Name = textBox_MaxEDSTime.Text;
- }
- }
- else if (tabControl_Rules.SelectedIndex == 2)
- {
- if (XmlTree_ZeroElementRules.SelectedNode != null)
- {
- if (XmlTree_ZeroElementRules.SelectedNode.Text.Contains("="))
- {
- if (!comboBox_PeriodicTable.Items.Contains(XmlTree_ZeroElementRules.SelectedNode.Text.Split('=')[0]))
- {
- MessageBox.Show(XmlTree_ZeroElementRules.SelectedNode.Text + table["message9"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- }
- else
- {
- MessageBox.Show(XmlTree_ZeroElementRules.SelectedNode.Text + table["message9"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- //判断textbox_STDEditor
- if (!Checktextbox_STDEditor())
- {
- return;
- }
- XmlTree_ZeroElementRules.SelectedNode.Tag = this.textbox_STDEditor.Text;
- }
- }
- dataGridView_KeyElements.Rows.Clear();
- dataGridView_KeyElements.Columns.Clear();
- dataGridView_SubElements.Rows.Clear();
- dataGridView_SubElements.Columns.Clear();
- TreeNode new_child = new TreeNode();//定义一个TreeNode节点对象
- TreeView XmlTree = (TreeView)XmlTreeMenuStrip.SourceControl;
- if (XmlTreeMenuStrip.SourceControl.Name == "XmlTree_STDlist")
- {
- new_child.Name = "1_1_1$$";
- new_child.Text = "new strName";
- new_child.Tag = "NewRules";
- textbox_STDEditor.Text = "NewRules";
- textBox_Density.Text = "1";
- textBox_Electrical_conductivity.Text = "1";
- textBox_Hardness.Text = "1";
- new_child.BackColor = Color.White;
- int STDId = 1;
- for (int i = 0; i < XmlTree_STDlist.Nodes.Count; i++)
- {
- if (STDId < int.Parse(XmlTree_STDlist.Nodes[i].ToolTipText))
- {
- STDId = int.Parse(XmlTree_STDlist.Nodes[i].ToolTipText);
- }
- }
- new_child.ToolTipText = (STDId+1).ToString();
- }
- if (XmlTreeMenuStrip.SourceControl.Name == "XmlTree_MaxEDSRules")
- {
- int Number = XmlTree.Nodes.Count;
- for (int num = 0; num < XmlTree.Nodes.Count; num++)
- {
- string aa = XmlTree.Nodes[num].Text.ToString().Substring(XmlTree.Nodes[num].Text.Length - 1, 1);
- int tp = int.Parse(XmlTree.Nodes[num].Text.ToString().Substring(XmlTree.Nodes[num].Text.Length - 1, 1));
- if (Number < tp) Number = tp;
- }
- new_child.Text = "Rule" + Number.ToString();
- new_child.Tag = "NewRules";
- textbox_STDEditor.Text = "NewRules";
- }
- if (XmlTreeMenuStrip.SourceControl.Name == "XmlTree_ZeroElementRules")
- {
- new_child.Text = "NewElement=0";
- new_child.Tag = "NewRules";
- textbox_STDEditor.Text = "NewRules";
- }
- XmlTree.Nodes.Add(new_child);
- XmlTree.SelectedNode = null;
- XmlTree.SelectedNode = new_child;
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.ToString(), table["message32"].ToString());
- }
- }
- //双击节点
- private void XmlTree_STDlist_MouseDoubleClick(object sender, MouseEventArgs e)
- {
- if (e.Button == MouseButtons.Left)
- {
- Point ClickPoint = new Point(e.X, e.Y);
- TreeNode CurrentNode = XmlTree_STDlist.GetNodeAt(ClickPoint);
- if (CurrentNode != null)//判断你点的是不是一个节点
- {
- XmlTree_STDlist.SelectedNode = CurrentNode;//选中这个节点
- XmlTree_STDlist.LabelEdit = true;
- XmlTree_STDlist.SelectedNode.BeginEdit();
- }
- }
- }
- //保存xmltree内容到xml文件
- void SaveXmlTreeDataToXml(string Address)
- {
- XDocument xdoc = XDocument.Load(Address);
- IEnumerable<XElement> elements = from ele in xdoc.Descendants("XMLData") select ele;
- foreach (var ele in elements)
- {
- if (ele != null)
- {
- ele.RemoveAll();
- }
- }
- string value = "";
- foreach (var str in comboBox_Constants.Items)
- {
- value += str + ",";
- }
- if (value != "")
- {
- value = value.Substring(0, value.Length - 1);
- }
- XElement Constant = new XElement("Member");
- Constant.SetAttributeValue("RegName", "Constants");
- Constant.SetAttributeValue("value", value);
- elements.ElementAt(0).Add(Constant);
- XElement ZeroElement = new XElement("Collection");
- ZeroElement.SetAttributeValue("RegName", "ZeroElementRules");
- elements.ElementAt(0).Add(ZeroElement);
- for (int num = 0; num < XmlTree_ZeroElementRules.Nodes.Count; num++)
- {
- string UsingElementList = "";
- string UsingImgPropertyList = "";
- string UsingOtherPropertyList = "";
- List<string> UsingElementL = new List<string>();
- List<string> UsingImgPropertyL = new List<string>();
- List<string> UsingOtherPropertyL = new List<string>();
- string str_RemoveBlank = "";
- //forth_elem干扰or分隔符,故先行去掉
- if (XmlTree_ZeroElementRules.Nodes[num].Tag.ToString().Contains("forth_elem"))
- {
- str_RemoveBlank = str_RemoveBlank.Replace("forth_elem", "");
- UsingOtherPropertyL.Add("forth_elem");
- }
- str_RemoveBlank = XmlTree_ZeroElementRules.Nodes[num].Tag.ToString().Replace(" ", "");
- 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[] { '+', '-', '*', '/', '=', '>', '<', '(', ')' }));
- }
- 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]);
- }
- }
- //first_elem?
- if (this.comboBox_Elem1.Items.Contains(list_all[i]))
- {
- if (!UsingOtherPropertyL.Contains(list_all[i]))
- {
- UsingOtherPropertyL.Add(list_all[i]);
- }
- }
- //Element1?
- if (this.comboBox_Elem.Items.Contains(list_all[i]))
- {
- if (!UsingOtherPropertyL.Contains(list_all[i]))
- {
- UsingOtherPropertyL.Add(list_all[i]);
- }
- }
- //其它元素?
- if (this.comboBox_ImgProperty.Items.Contains(list_all[i]))
- {
- if (!UsingImgPropertyL.Contains(list_all[i]))
- {
- UsingImgPropertyL.Add(list_all[i]);
- }
- }
- }
- if (UsingElementL.Count > 0)
- {
- for (int i = 0; i < UsingElementL.Count - 1; i++)
- {
- UsingElementList += UsingElementL[i] + ",";
- }
- UsingElementList += UsingElementL[UsingElementL.Count - 1];
- }
- if (UsingImgPropertyL.Count > 0)
- {
- for (int i = 0; i < UsingImgPropertyL.Count - 1; i++)
- {
- UsingImgPropertyList += UsingImgPropertyL[i] + ",";
- }
- UsingImgPropertyList += UsingImgPropertyL[UsingImgPropertyL.Count - 1];
- }
- if (UsingOtherPropertyL.Count > 0)
- {
- for (int i = 0; i < UsingOtherPropertyL.Count - 1; i++)
- {
- UsingOtherPropertyList += UsingOtherPropertyL[i] + ",";
- }
- UsingOtherPropertyList += UsingOtherPropertyL[UsingOtherPropertyL.Count - 1];
- }
- XElement EleName = new XElement("Member");
- EleName.SetAttributeValue("ZeroElement", XmlTree_ZeroElementRules.Nodes[num].Text.Split('=')[0]);
- EleName.SetAttributeValue("UsingElementList", UsingElementList);
- EleName.SetAttributeValue("UsingImgPropertyList", UsingImgPropertyList);
- EleName.SetAttributeValue("UsingOtherPropertyList", UsingOtherPropertyList);
- EleName.SetAttributeValue("Expression", XmlTree_ZeroElementRules.Nodes[num].Tag);
- ZeroElement.Add(EleName);
- }
- XElement MaxEDS = new XElement("Collection");
- MaxEDS.SetAttributeValue("RegName", "MaxEDSRules");
- elements.ElementAt(0).Add(MaxEDS);
- for (int num = 0; num < XmlTree_MaxEDSRules.Nodes.Count; num++)
- {
- string UsingElementList = "";
- string UsingImgPropertyList = "";
- string UsingOtherPropertyList = "";
- List<string> UsingElementL = new List<string>();
- List<string> UsingImgPropertyL = new List<string>();
- List<string> UsingOtherPropertyL = new List<string>();
- string str_RemoveBlank = "";
- //forth_elem干扰or分隔符,故先行去掉
- if (XmlTree_MaxEDSRules.Nodes[num].Tag.ToString().Contains("forth_elem"))
- {
- str_RemoveBlank = str_RemoveBlank.Replace("forth_elem", "");
- UsingOtherPropertyList = "forth_elem,";
- }
- str_RemoveBlank = XmlTree_MaxEDSRules.Nodes[num].Tag.ToString().Replace(" ", "");
- 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[] { '+', '-', '*', '/', '=', '>', '<', '(', ')' }));
- }
- 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]);
- }
- }
- //first_elem?
- if (this.comboBox_Elem1.Items.Contains(list_all[i]))
- {
- if (!UsingOtherPropertyL.Contains(list_all[i]))
- {
- UsingOtherPropertyL.Add(list_all[i]);
- }
- }
- //Element1?
- if (this.comboBox_Elem.Items.Contains(list_all[i]))
- {
- if (!UsingOtherPropertyL.Contains(list_all[i]))
- {
- UsingOtherPropertyL.Add(list_all[i]);
- }
- }
- //其它元素?
- if (this.comboBox_ImgProperty.Items.Contains(list_all[i]))
- {
- if (!UsingImgPropertyL.Contains(list_all[i]))
- {
- UsingImgPropertyL.Add(list_all[i]);
- }
- }
- }
- if (UsingElementL.Count > 0)
- {
- for (int i = 0; i < UsingElementL.Count - 1; i++)
- {
- UsingElementList += UsingElementL[i] + ",";
- }
- UsingElementList += UsingElementL[UsingElementL.Count - 1];
- }
- if (UsingImgPropertyL.Count > 0)
- {
- for (int i = 0; i < UsingImgPropertyL.Count - 1; i++)
- {
- UsingImgPropertyList += UsingImgPropertyL[i] + ",";
- }
- UsingImgPropertyList += UsingImgPropertyL[UsingImgPropertyL.Count - 1];
- }
- if (UsingOtherPropertyL.Count > 0)
- {
- for (int i = 0; i < UsingOtherPropertyL.Count - 1; i++)
- {
- UsingOtherPropertyList += UsingOtherPropertyL[i] + ",";
- }
- UsingOtherPropertyList += UsingOtherPropertyL[UsingOtherPropertyL.Count - 1];
- }
- XElement EleName = new XElement("Member");
- //EleName.SetAttributeValue("MaxEDSTime", XmlTree_MaxEDSRules.Nodes[num].Name);
- EleName.SetAttributeValue("MaxEDSTime",textBox_MaxEDSTime.Text);
- EleName.SetAttributeValue("UsingElementList", UsingElementList);
- EleName.SetAttributeValue("UsingImgPropertyList", UsingImgPropertyList);
- EleName.SetAttributeValue("UsingOtherPropertyList", UsingOtherPropertyList);
- EleName.SetAttributeValue("Expression", XmlTree_MaxEDSRules.Nodes[num].Tag);
- MaxEDS.Add(EleName);
- }
- XElement STD = new XElement("Collection");
- STD.SetAttributeValue("RegName", "STDList");
- elements.ElementAt(0).Add(STD);
- for (int num = 0; num < XmlTree_STDlist.Nodes.Count; num++)
- {
- string UsingElementList = "";
- string UsingImgPropertyList = "";
- string UsingOtherPropertyList = "";
- List<string> UsingElementL = new List<string>();
- List<string> UsingImgPropertyL = new List<string>();
- List<string> UsingOtherPropertyL = new List<string>();
- string str_RemoveBlank = "";
- //forth_elem干扰or分隔符,故先行去掉
- if (XmlTree_STDlist.Nodes[num].Tag.ToString().Contains("forth_elem"))
- {
- str_RemoveBlank = str_RemoveBlank.Replace("forth_elem", "");
- UsingOtherPropertyList = "forth_elem,";
- }
- str_RemoveBlank = XmlTree_STDlist.Nodes[num].Tag.ToString().Replace(" ", "");
- 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[] { '+', '-', '*', '/', '=', '>', '<', '(', ')' }));
- }
- 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]);
- }
- }
- //first_elem?
- if (this.comboBox_Elem1.Items.Contains(list_all[i]))
- {
- if (!UsingOtherPropertyL.Contains(list_all[i]))
- {
- UsingOtherPropertyL.Add(list_all[i]);
- }
- }
- //Element1?
- if (this.comboBox_Elem.Items.Contains(list_all[i]))
- {
- if (!UsingOtherPropertyL.Contains(list_all[i]))
- {
- UsingOtherPropertyL.Add(list_all[i]);
- }
- }
- //其它元素?
- if (this.comboBox_ImgProperty.Items.Contains(list_all[i]))
- {
- if (!UsingImgPropertyL.Contains(list_all[i]))
- {
- UsingImgPropertyL.Add(list_all[i]);
- }
- }
- }
- if (UsingElementL.Count > 0)
- {
- for (int i = 0; i < UsingElementL.Count - 1; i++)
- {
- UsingElementList += UsingElementL[i] + ",";
- }
- UsingElementList += UsingElementL[UsingElementL.Count - 1];
- }
- if (UsingImgPropertyL.Count > 0)
- {
- for (int i = 0; i < UsingImgPropertyL.Count - 1; i++)
- {
- UsingImgPropertyList += UsingImgPropertyL[i] + ",";
- }
- UsingImgPropertyList += UsingImgPropertyL[UsingImgPropertyL.Count - 1];
- }
- if (UsingOtherPropertyL.Count > 0)
- {
- for (int i = 0; i < UsingOtherPropertyL.Count - 1; i++)
- {
- UsingOtherPropertyList += UsingOtherPropertyL[i] + ",";
- }
- UsingOtherPropertyList += UsingOtherPropertyL[UsingOtherPropertyL.Count - 1];
- }
- string[] str = XmlTree_STDlist.Nodes[num].Name.Split('$');
- string[] strOther = str[0].Split('_');
-
- XElement EleName = new XElement("Member");
- EleName.SetAttributeValue("STDId", XmlTree_STDlist.Nodes[num].ToolTipText);
- EleName.SetAttributeValue("StrName", XmlTree_STDlist.Nodes[num].Text);
- EleName.SetAttributeValue("Color", colorRGBtoHx16(XmlTree_STDlist.Nodes[num].BackColor.R, XmlTree_STDlist.Nodes[num].BackColor.G, XmlTree_STDlist.Nodes[num].BackColor.B));
- //EleName.SetAttributeValue("UsingElementList", UsingElementList);
- EleName.SetAttributeValue("KeyElementList", str[1]);
- EleName.SetAttributeValue("SubElementList", str[2]);
- EleName.SetAttributeValue("UsingImgPropertyList", UsingImgPropertyList);
- EleName.SetAttributeValue("UsingOtherPropertyList", UsingOtherPropertyList);
- EleName.SetAttributeValue("Expression", XmlTree_STDlist.Nodes[num].Tag);
- EleName.SetAttributeValue("Hardness", strOther[0]);
- EleName.SetAttributeValue("Density", strOther[1]);
- EleName.SetAttributeValue("Electrical_conductivity", strOther[2]);
- STD.Add(EleName);
- }
- xdoc.Save(Address);
- }
- //元素周期表开关
- private void PeriodicTableSwitch_Click(object sender, EventArgs e)
- {
- if (PeriodicTableSwitch.BackColor == SystemColors.Control)
- {
- panel_OTSPeriodicTable.Visible = true;
- this.Width = this.Width + panel_OTSPeriodicTable.Width + 5;
- PeriodicTableSwitch.BackColor = SystemColors.ControlDark;
- //if (Language == "English")
- //{
- // PeriodicTableSwitch.Text = "Close PeriodicTable";
- //}
- //else if(Language == "Chinese")
- //{
- // PeriodicTableSwitch.Text = "关闭元素周期表";
- //}
- }
- else if (PeriodicTableSwitch.BackColor == SystemColors.ControlDark)
- {
- panel_OTSPeriodicTable.Visible = false;
- this.Width = this.Width - panel_OTSPeriodicTable.Width - 5;
- PeriodicTableSwitch.BackColor = SystemColors.Control;
- //if (Language == "English")
- //{
- // PeriodicTableSwitch.Text = "Open PeriodicTable";
- //}
- //else if (Language == "Chinese")
- //{
- // PeriodicTableSwitch.Text = "打开元素周期表";
- //}
- //textbox_STDEditor.Focus();
- groupBox_XmlTree_MaxEDSRules.Focus();
- }
- }
- private void button_Ok_Click(object sender, EventArgs e)
- {
- if (tabControl_Rules.SelectedIndex == 0)
- {
- //保存节点当前数据
- if (XmlTree_STDlist.SelectedNode != null)
- {
- //判断Hardness、Density、Electrical_conductivity
- double dHardness = 0, dDensity = 0, dElectrical_conductivity = 0;
- if (!double.TryParse(textBox_Hardness.Text, out dHardness) || (double.Parse(textBox_Hardness.Text) <= 0))
- {
- textBox_Hardness.Focus();
- textBox_Hardness.SelectAll();
- MessageBox.Show(table["message10"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- if (!double.TryParse(textBox_Density.Text, out dDensity) || double.Parse(textBox_Density.Text) <= 0)
- {
- textBox_Density.Focus();
- textBox_Density.SelectAll();
- MessageBox.Show(table["message11"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- if (!double.TryParse(textBox_Electrical_conductivity.Text, out dElectrical_conductivity) || double.Parse(textBox_Electrical_conductivity.Text) <= 0)
- {
- textBox_Electrical_conductivity.Focus();
- textBox_Electrical_conductivity.SelectAll();
- MessageBox.Show(table["message12"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- //判断textbox_STDEditor
- if (!Checktextbox_STDEditor())
- {
- return;
- }
- XmlTree_STDlist.SelectedNode.Tag = this.textbox_STDEditor.Text;
- XmlTree_STDlist.SelectedNode.Name = textBox_Hardness.Text + "_" + textBox_Density.Text + "_" + textBox_Electrical_conductivity.Text;
- string sKeyElements = "";
- for (int i = 0; i < dataGridView_KeyElements.Columns.Count; i++)
- {
- sKeyElements += dataGridView_KeyElements.Rows[0].Cells[i].Value.ToString() + ",";
- }
- if (sKeyElements.Length > 0)
- {
- sKeyElements = sKeyElements.Substring(0, sKeyElements.Length - 1);
- }
- string sSubElements = "";
- for (int i = 0; i < dataGridView_SubElements.Columns.Count; i++)
- {
- sSubElements += dataGridView_SubElements.Rows[0].Cells[i].Value.ToString() + ",";
- }
- if (sSubElements.Length > 0)
- {
- sSubElements = sSubElements.Substring(0, sSubElements.Length - 1);
- }
- XmlTree_STDlist.SelectedNode.Name += "$" + sKeyElements + "$" + sSubElements;
- }
- }
- else if (tabControl_Rules.SelectedIndex == 1)
- {
- if (XmlTree_MaxEDSRules.SelectedNode != null)
- {
- //判断MaxEDSTime
- double dMaxEDSTime = 0;
- if (!double.TryParse(textBox_MaxEDSTime.Text, out dMaxEDSTime) || double.Parse(textBox_MaxEDSTime.Text) <= 0)
- {
- textBox_MaxEDSTime.Focus();
- textBox_MaxEDSTime.SelectAll();
- MessageBox.Show(table["message16"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- //判断textbox_STDEditor
- if (!Checktextbox_STDEditor())
- {
- return;
- }
- XmlTree_MaxEDSRules.SelectedNode.Tag = this.textbox_STDEditor.Text;
- //XmlTree_MaxEDSRules.SelectedNode.Name = textBox_MaxEDSTime.Text;
- }
- }
- else if (tabControl_Rules.SelectedIndex == 2)
- {
- if (XmlTree_ZeroElementRules.SelectedNode != null)
- {
- if (XmlTree_ZeroElementRules.SelectedNode.Text.Contains("="))
- {
- if (!comboBox_PeriodicTable.Items.Contains(XmlTree_ZeroElementRules.SelectedNode.Text.Split('=')[0]))
- {
- MessageBox.Show(XmlTree_ZeroElementRules.SelectedNode.Text + table["message9"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- }
- else
- {
- MessageBox.Show(XmlTree_ZeroElementRules.SelectedNode.Text + table["message9"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- //判断textbox_STDEditor
- if (!Checktextbox_STDEditor())
- {
- return;
- }
- XmlTree_ZeroElementRules.SelectedNode.Tag = this.textbox_STDEditor.Text;
- }
- }
- string value = "";
- foreach (var str in comboBox_Constants.Items)
- {
- value += str + ",";
- }
- if (value != "")
- {
- value = value.Substring(0, value.Length - 1);
- }
- //string Address = Application.StartupPath + "\\Config\\SysData\\OTSParticleSTD.xml";
- //string Address = ".\\Config\\SysData\\OTSParticleSTD.xml";
- SaveXmlTreeDataToXml(Address);
- this.Close();
- }
- private void button_Cancel_Click(object sender, EventArgs e)
- {
- this.Close();
- }
- //元素下拉选择输入
- private void comboBox_PeriodicTable_SelectedIndexChanged(object sender, EventArgs e)
- {
- if (comboBox_PeriodicTable.Text != null && comboBox_PeriodicTable.SelectedItem != null)
- {
- //comboBox_PeriodicTable.Text = null;
- //this.textbox_STDEditor.Text += comboBox_PeriodicTable.SelectedItem.ToString();
- //textbox_STDEditor.Focus();
- //textbox_STDEditor.SelectionStart = textbox_STDEditor.Text.Length;
- //textbox_STDEditor.ScrollToCaret();
- 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();
- }
- }
- //元素自身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;
- }
- }
- }
- //表达式规则检查
- private bool Checktextbox_STDEditor()
- {
- if (textbox_STDEditor.Text == "" || textbox_STDEditor.Text == null)
- {
- textBox_MaxEDSTime.Focus();
- MessageBox.Show(table["message17"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- return false;
- }
- string str_RemoveBlank = textbox_STDEditor.Text.ToString().Replace(" ", "");
- str_RemoveBlank = str_RemoveBlank.Replace("\r\n", "");
- //分割符号检验
- string[] Symbol = { "and", "or", "+", "-", "*", "/", "=", ">", "<" };
- for (int i = 0; i < Symbol.Length; i++)
- {
- for (int j = 0; j < Symbol.Length; j++)
- {
- if ((Symbol[i] + Symbol[j]) != ">=" && (Symbol[i] + Symbol[j]) != "<=")
- {
- if (str_RemoveBlank.Contains(Symbol[i] + Symbol[j]))
- {
- MessageBox.Show(table["message18"].ToString() + Symbol[i] + Symbol[j], table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- return false;
- }
- }
- }
- if (str_RemoveBlank.Contains(Symbol[i] + ")") || str_RemoveBlank.Contains("(" + Symbol[i]))
- {
- MessageBox.Show(table["message18"].ToString() + Symbol[i] + ")", table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- return false;
- }
- if (str_RemoveBlank.Contains("(" + Symbol[i]))
- {
- MessageBox.Show(table["message18"].ToString() + "(" + Symbol[i], table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- return false;
- }
- }
- if ((str_RemoveBlank != null) && (str_RemoveBlank != ""))
- {
- //左右括号匹配检验
- int BracketsNum = 0;
- for (int i = 0; i < str_RemoveBlank.Length; i++)
- {
- if (str_RemoveBlank[i] == '(') BracketsNum++;
- if (str_RemoveBlank[i] == ')') BracketsNum--;
- }
- if (BracketsNum != 0)
- {
- MessageBox.Show(table["message19"].ToString(),table["message32"].ToString(),MessageBoxButtons.OK,MessageBoxIcon.Information);
- return false;
- }
- //首字符检测
- if ((str_RemoveBlank[0] == '+') || (str_RemoveBlank[0] == '-') || (str_RemoveBlank[0] == '*') || (str_RemoveBlank[0] == '/') || (str_RemoveBlank[0] == '>') || (str_RemoveBlank[0] == '<') || (str_RemoveBlank[0] == '=') || (str_RemoveBlank[0] == ')') || (str_RemoveBlank[str_RemoveBlank.Length - 1] == '('))
- {
- MessageBox.Show(table["message20"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- return false;
- }
- if (str_RemoveBlank.Length >= 3)
- {
- if ((str_RemoveBlank.Substring(0, 3) == "and") || (str_RemoveBlank.Substring(0, 3) == "end"))
- {
- MessageBox.Show(table["message20"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- return false;
- }
- }
- }
- //forth_elem干扰or分隔符,故先行去掉
- 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> Constantslist = new List<string>();
- for (int j = 0; j < comboBox_Constants.Items.Count; j++)
- {
- Constantslist.Add(comboBox_Constants.Items[j].ToString().Split('=')[0]);
- }
- for (int i = 0; i < list_all.Count; i++)
- {
- //周期元素?
- if (this.comboBox_PeriodicTable.Items.Contains(list_all[i]))
- {
- continue;
- }
- //first_elem?
- if (this.comboBox_Elem1.Items.Contains(list_all[i]))
- {
- continue;
- }
- //Element1?
- if (this.comboBox_Elem.Items.Contains(list_all[i]))
- {
- continue;
- }
- //其它元素?
- if (this.comboBox_ImgProperty.Items.Contains(list_all[i]))
- {
- continue;
- }
- //常量?
- if (Constantslist.Contains(list_all[i]))
- {
- continue;
- }
- //数字?
- double DNum = 0;
- if (double.TryParse(list_all[i], out DNum))
- {
- continue;
- }
- //>=? <=?等其它情况
- if (list_all[i] == "")
- {
- continue;
- }
- //true false?
- if ((list_all[i] == "true") || (list_all[i] == "false"))
- {
- continue;
- }
- MessageBox.Show(table["message21"].ToString() + list_all[i], table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- return false;
- }
- //检测是否有<>= true,false
- if (!textbox_STDEditor.Text.ToString().Contains("<") && !textbox_STDEditor.Text.ToString().Contains(">") && !textbox_STDEditor.Text.ToString().Contains("=")&& textbox_STDEditor.Text.ToString()!="true"&& textbox_STDEditor.Text.ToString() != "false")
- {
- MessageBox.Show(table["message22"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- return false;
- }
- return true;
- }
- private void btn_dbs_Click(object sender, EventArgs e)
- {
- ColorDialog cd = new ColorDialog();
- cd.FullOpen = true;//自定义颜色界面打开
- DialogResult result = cd.ShowDialog();
- if (result == DialogResult.OK)
- {
- btn_dbs.BackColor = cd.Color;
- if (XmlTree_STDlist.SelectedNode != null)
- {
- XmlTree_STDlist.SelectedNode.BackColor = cd.Color;
- }
- }
- if (XmlTree_STDlist.SelectedNode != null)
- {
- //如果不是白色了,就把文字去掉吧,显得好看
- if (btn_dbs.BackColor != Color.White)
- {
- btn_dbs.Text = "";
- }
- }
- }
- 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 (Flag_comboBox_Constants)
- //{
- if (comboBox_Constants.SelectedItem != null)
- {
- //this.textbox_STDEditor.Text += comboBox_Constants.SelectedItem.ToString().Split('=')[0];
- ////comboBox_Constants.Text = null;
- //textbox_STDEditor.Focus();
- //textbox_STDEditor.SelectionStart = textbox_STDEditor.Text.Length;
- //textbox_STDEditor.ScrollToCaret();
- 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();
- }
- //}
- //Flag_comboBox_Constants = true;
- }
- bool Flag_SelStatus = true; //XML切换成功失败状态
- private void button_UpOrder_Click(object sender, EventArgs e)
- {
- if (XmlTree_STDlist.SelectedNode.PrevNode != null)
- {
- //object tag = XmlTree_STDlist.SelectedNode.PrevNode.Tag;
- //string name = XmlTree_STDlist.SelectedNode.PrevNode.Name;
- //string text = XmlTree_STDlist.SelectedNode.PrevNode.Text;
- //Color backcolor=XmlTree_STDlist.SelectedNode.PrevNode.BackColor;
- //string STDId = XmlTree_STDlist.SelectedNode.PrevNode.ToolTipText;
- //XmlTree_STDlist.SelectedNode.PrevNode.Tag = XmlTree_STDlist.SelectedNode.Tag;
- //XmlTree_STDlist.SelectedNode.PrevNode.BackColor = XmlTree_STDlist.SelectedNode.BackColor;
- //XmlTree_STDlist.SelectedNode.PrevNode.Name = XmlTree_STDlist.SelectedNode.Name;
- //XmlTree_STDlist.SelectedNode.PrevNode.Text = XmlTree_STDlist.SelectedNode.Text;
- //XmlTree_STDlist.SelectedNode.PrevNode.ToolTipText = XmlTree_STDlist.SelectedNode.ToolTipText;
- //XmlTree_STDlist.SelectedNode.Tag = tag;
- //XmlTree_STDlist.SelectedNode.BackColor = backcolor;
- //XmlTree_STDlist.SelectedNode.Name = name;
- //XmlTree_STDlist.SelectedNode.Text = text;
- //XmlTree_STDlist.SelectedNode.ToolTipText = STDId;
- //this.textbox_STDEditor.Text = XmlTree_STDlist.SelectedNode.Tag.ToString();
- //btn_dbs.BackColor = XmlTree_STDlist.SelectedNode.BackColor;
- //string[] strOther = XmlTree_STDlist.SelectedNode.Name.Split('$');
- //string[] strOther2 = strOther[0].Split('_');
- //textBox_Hardness.Text = strOther2[0];
- //textBox_Density.Text = strOther2[1];
- //textBox_Electrical_conductivity.Text = strOther2[2];
- //dataGridView_KeyElements.Rows.Clear();
- //dataGridView_KeyElements.Columns.Clear();
- //string[] KeyElement = strOther[1].Split(',');
- //for (int i = 0; i < KeyElement.Length; i++)
- //{
- // if (KeyElement[0] != "")
- // {
- // 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[i].Value = KeyElement[i];
- // }
- //}
- //dataGridView_SubElements.Rows.Clear();
- //dataGridView_SubElements.Columns.Clear();
- //string[] SubElement = strOther[2].Split(',');
- //for (int i = 0; i < SubElement.Length; i++)
- //{
- // if (SubElement[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[i].Value = SubElement[i];
- // }
- //}
- //this.XmlTree_STDlist.Focus();
- //XmlTree_STDlist.SelectedNode = XmlTree_STDlist.SelectedNode.PrevNode;
- //if (XmlTree_STDlist.SelectedNode.PrevNode == null)
- //{
- // UpOrder.Enabled = false;
- //}
- }
- XmlTree_STDlist.SelectedNode = XmlTree_STDlist.SelectedNode.PrevNode;
- if (Flag_SelStatus)
- {
- object tag = XmlTree_STDlist.SelectedNode.NextNode.Tag;
- string name = XmlTree_STDlist.SelectedNode.NextNode.Name;
- string text = XmlTree_STDlist.SelectedNode.NextNode.Text;
- Color backcolor = XmlTree_STDlist.SelectedNode.NextNode.BackColor;
- string STDId = XmlTree_STDlist.SelectedNode.NextNode.ToolTipText;
- XmlTree_STDlist.SelectedNode.NextNode.Tag = XmlTree_STDlist.SelectedNode.Tag;
- XmlTree_STDlist.SelectedNode.NextNode.BackColor = XmlTree_STDlist.SelectedNode.BackColor;
- XmlTree_STDlist.SelectedNode.NextNode.Name = XmlTree_STDlist.SelectedNode.Name;
- XmlTree_STDlist.SelectedNode.NextNode.Text = XmlTree_STDlist.SelectedNode.Text;
- XmlTree_STDlist.SelectedNode.NextNode.ToolTipText = XmlTree_STDlist.SelectedNode.ToolTipText;
- XmlTree_STDlist.SelectedNode.Tag = tag;
- XmlTree_STDlist.SelectedNode.BackColor = backcolor;
- XmlTree_STDlist.SelectedNode.Name = name;
- XmlTree_STDlist.SelectedNode.Text = text;
- XmlTree_STDlist.SelectedNode.ToolTipText = STDId;
- this.textbox_STDEditor.Text = XmlTree_STDlist.SelectedNode.Tag.ToString();
- btn_dbs.BackColor = XmlTree_STDlist.SelectedNode.BackColor;
- string[] strOther = XmlTree_STDlist.SelectedNode.Name.Split('$');
- string[] strOther2 = strOther[0].Split('_');
- textBox_Hardness.Text = strOther2[0];
- textBox_Density.Text = strOther2[1];
- textBox_Electrical_conductivity.Text = strOther2[2];
- dataGridView_KeyElements.Rows.Clear();
- dataGridView_KeyElements.Columns.Clear();
- string[] KeyElement = strOther[1].Split(',');
- for (int i = 0; i < KeyElement.Length; i++)
- {
- if (KeyElement[0] != "")
- {
- 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[i].Value = KeyElement[i];
- }
- }
- dataGridView_SubElements.Rows.Clear();
- dataGridView_SubElements.Columns.Clear();
- string[] SubElement = strOther[2].Split(',');
- for (int i = 0; i < SubElement.Length; i++)
- {
- if (SubElement[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[i].Value = SubElement[i];
- }
- }
- this.XmlTree_STDlist.Focus();
- if (XmlTree_STDlist.SelectedNode.PrevNode == null)
- {
- button_UpOrder.Enabled = false;
- }
- dataGridView_KeyElements.ClearSelection();
- dataGridView_SubElements.ClearSelection();
- }
- this.XmlTree_STDlist.Focus();
- Flag_SelStatus = true;
- }
- private void button_DownOrder_Click(object sender, EventArgs e)
- {
- if (XmlTree_STDlist.SelectedNode.NextNode != null)
- {
- //object tag = XmlTree_STDlist.SelectedNode.NextNode.Tag;
- //string name = XmlTree_STDlist.SelectedNode.NextNode.Name;
- //string text = XmlTree_STDlist.SelectedNode.NextNode.Text;
- //Color backcolor = XmlTree_STDlist.SelectedNode.NextNode.BackColor;
- //string STDId = XmlTree_STDlist.SelectedNode.NextNode.ToolTipText;
- //XmlTree_STDlist.SelectedNode.NextNode.Tag = XmlTree_STDlist.SelectedNode.Tag;
- //XmlTree_STDlist.SelectedNode.NextNode.BackColor = XmlTree_STDlist.SelectedNode.BackColor;
- //XmlTree_STDlist.SelectedNode.NextNode.Name = XmlTree_STDlist.SelectedNode.Name;
- //XmlTree_STDlist.SelectedNode.NextNode.Text = XmlTree_STDlist.SelectedNode.Text;
- //XmlTree_STDlist.SelectedNode.NextNode.ToolTipText = XmlTree_STDlist.SelectedNode.ToolTipText;
- //XmlTree_STDlist.SelectedNode.Tag = tag;
- //XmlTree_STDlist.SelectedNode.BackColor = backcolor;
- //XmlTree_STDlist.SelectedNode.Name = name;
- //XmlTree_STDlist.SelectedNode.Text = text;
- //XmlTree_STDlist.SelectedNode.ToolTipText = STDId;
- //this.textbox_STDEditor.Text = XmlTree_STDlist.SelectedNode.Tag.ToString();
- //btn_dbs.BackColor = XmlTree_STDlist.SelectedNode.BackColor;
- //string[] strOther = XmlTree_STDlist.SelectedNode.Name.Split('$');
- //string[] strOther2 = strOther[0].Split('_');
- //textBox_Hardness.Text = strOther2[0];
- //textBox_Density.Text = strOther2[1];
- //textBox_Electrical_conductivity.Text = strOther2[2];
- //dataGridView_KeyElements.Rows.Clear();
- //dataGridView_KeyElements.Columns.Clear();
- //string[] KeyElement = strOther[1].Split(',');
- //for (int i = 0; i < KeyElement.Length; i++)
- //{
- // if (KeyElement[0] != "")
- // {
- // 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[i].Value = KeyElement[i];
- // }
- //}
- //dataGridView_SubElements.Rows.Clear();
- //dataGridView_SubElements.Columns.Clear();
- //string[] SubElement = strOther[2].Split(',');
- //for (int i = 0; i < SubElement.Length; i++)
- //{
- // if (SubElement[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[i].Value = SubElement[i];
- // }
- //}
- //this.XmlTree_STDlist.Focus();
- //XmlTree_STDlist.SelectedNode = XmlTree_STDlist.SelectedNode.NextNode;
- //if (XmlTree_STDlist.SelectedNode.NextNode == null)
- //{
- // DownOrder.Enabled = false;
- //}
- }
- XmlTree_STDlist.SelectedNode = XmlTree_STDlist.SelectedNode.NextNode;
- if (Flag_SelStatus)
- {
- object tag = XmlTree_STDlist.SelectedNode.PrevNode.Tag;
- string name = XmlTree_STDlist.SelectedNode.PrevNode.Name;
- string text = XmlTree_STDlist.SelectedNode.PrevNode.Text;
- Color backcolor = XmlTree_STDlist.SelectedNode.PrevNode.BackColor;
- string STDId = XmlTree_STDlist.SelectedNode.PrevNode.ToolTipText;
- XmlTree_STDlist.SelectedNode.PrevNode.Tag = XmlTree_STDlist.SelectedNode.Tag;
- XmlTree_STDlist.SelectedNode.PrevNode.BackColor = XmlTree_STDlist.SelectedNode.BackColor;
- XmlTree_STDlist.SelectedNode.PrevNode.Name = XmlTree_STDlist.SelectedNode.Name;
- XmlTree_STDlist.SelectedNode.PrevNode.Text = XmlTree_STDlist.SelectedNode.Text;
- XmlTree_STDlist.SelectedNode.PrevNode.ToolTipText = XmlTree_STDlist.SelectedNode.ToolTipText;
- XmlTree_STDlist.SelectedNode.Tag = tag;
- XmlTree_STDlist.SelectedNode.BackColor = backcolor;
- XmlTree_STDlist.SelectedNode.Name = name;
- XmlTree_STDlist.SelectedNode.Text = text;
- XmlTree_STDlist.SelectedNode.ToolTipText = STDId;
- this.textbox_STDEditor.Text = XmlTree_STDlist.SelectedNode.Tag.ToString();
- btn_dbs.BackColor = XmlTree_STDlist.SelectedNode.BackColor;
- string[] strOther = XmlTree_STDlist.SelectedNode.Name.Split('$');
- string[] strOther2 = strOther[0].Split('_');
- textBox_Hardness.Text = strOther2[0];
- textBox_Density.Text = strOther2[1];
- textBox_Electrical_conductivity.Text = strOther2[2];
- dataGridView_KeyElements.Rows.Clear();
- dataGridView_KeyElements.Columns.Clear();
- string[] KeyElement = strOther[1].Split(',');
- for (int i = 0; i < KeyElement.Length; i++)
- {
- if (KeyElement[0] != "")
- {
- 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[i].Value = KeyElement[i];
- }
- }
- dataGridView_SubElements.Rows.Clear();
- dataGridView_SubElements.Columns.Clear();
- string[] SubElement = strOther[2].Split(',');
- for (int i = 0; i < SubElement.Length; i++)
- {
- if (SubElement[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[i].Value = SubElement[i];
- }
- }
- this.XmlTree_STDlist.Focus();
- if (XmlTree_STDlist.SelectedNode.PrevNode == null)
- {
- button_DownOrder.Enabled = false;
- }
- dataGridView_KeyElements.ClearSelection();
- dataGridView_SubElements.ClearSelection();
- }
- this.XmlTree_STDlist.Focus();
- Flag_SelStatus = true;
- }
- private void button_Backup_Click(object sender, EventArgs e)
- {
- if (tabControl_Rules.SelectedIndex == 0)
- {
- //保存节点当前数据
- if (XmlTree_STDlist.SelectedNode != null)
- {
- //判断Hardness、Density、Electrical_conductivity
- double dHardness = 0, dDensity = 0, dElectrical_conductivity = 0;
- if (!double.TryParse(textBox_Hardness.Text, out dHardness) || (double.Parse(textBox_Hardness.Text) <= 0))
- {
- textBox_Hardness.Focus();
- textBox_Hardness.SelectAll();
- MessageBox.Show(table["message10"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- if (!double.TryParse(textBox_Density.Text, out dDensity) || double.Parse(textBox_Density.Text) <= 0)
- {
- textBox_Density.Focus();
- textBox_Density.SelectAll();
- MessageBox.Show(table["message11"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- if (!double.TryParse(textBox_Electrical_conductivity.Text, out dElectrical_conductivity) || double.Parse(textBox_Electrical_conductivity.Text) <= 0)
- {
- textBox_Electrical_conductivity.Focus();
- textBox_Electrical_conductivity.SelectAll();
- MessageBox.Show(table["message12"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- //判断textbox_STDEditor
- if (!Checktextbox_STDEditor())
- {
- return;
- }
- XmlTree_STDlist.SelectedNode.Tag = this.textbox_STDEditor.Text;
- XmlTree_STDlist.SelectedNode.Name = textBox_Hardness.Text + "_" + textBox_Density.Text + "_" + textBox_Electrical_conductivity.Text;
- string sKeyElements = "";
- for (int i = 0; i < dataGridView_KeyElements.Columns.Count; i++)
- {
- sKeyElements += dataGridView_KeyElements.Rows[0].Cells[i].Value.ToString() + ",";
- }
- if (sKeyElements.Length > 0)
- {
- sKeyElements = sKeyElements.Substring(0, sKeyElements.Length - 1);
- }
- string sSubElements = "";
- for (int i = 0; i < dataGridView_SubElements.Columns.Count; i++)
- {
- sSubElements += dataGridView_SubElements.Rows[0].Cells[i].Value.ToString() + ",";
- }
- if (sSubElements.Length > 0)
- {
- sSubElements = sSubElements.Substring(0, sSubElements.Length - 1);
- }
- XmlTree_STDlist.SelectedNode.Name += "$" + sKeyElements + "$" + sSubElements;
- }
- }
- else if (tabControl_Rules.SelectedIndex == 1)
- {
- if (XmlTree_MaxEDSRules.SelectedNode != null)
- {
- //判断MaxEDSTime
- double dMaxEDSTime = 0;
- if (!double.TryParse(textBox_MaxEDSTime.Text, out dMaxEDSTime) || double.Parse(textBox_MaxEDSTime.Text) <= 0)
- {
- textBox_MaxEDSTime.Focus();
- textBox_MaxEDSTime.SelectAll();
- MessageBox.Show(table["message16"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- //判断textbox_STDEditor
- if (!Checktextbox_STDEditor())
- {
- return;
- }
- XmlTree_MaxEDSRules.SelectedNode.Tag = this.textbox_STDEditor.Text;
- //XmlTree_MaxEDSRules.SelectedNode.Name = textBox_MaxEDSTime.Text;
- }
- }
- else if (tabControl_Rules.SelectedIndex == 2)
- {
- if (XmlTree_ZeroElementRules.SelectedNode != null)
- {
- if (XmlTree_ZeroElementRules.SelectedNode.Text.Contains("="))
- {
- if (!comboBox_PeriodicTable.Items.Contains(XmlTree_ZeroElementRules.SelectedNode.Text.Split('=')[0]))
- {
- MessageBox.Show(XmlTree_ZeroElementRules.SelectedNode.Text + table["message9"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- }
- else
- {
- MessageBox.Show(XmlTree_ZeroElementRules.SelectedNode.Text + table["message9"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- //判断textbox_STDEditor
- if (!Checktextbox_STDEditor())
- {
- return;
- }
- XmlTree_ZeroElementRules.SelectedNode.Tag = this.textbox_STDEditor.Text;
- }
- }
- try
- {
- SaveFileDialog saveFile = new SaveFileDialog();
- saveFile.Title = table["message23"].ToString();
- saveFile.Filter = table["message24"].ToString();
- saveFile.OverwritePrompt = true; //是否覆盖当前文件
- saveFile.RestoreDirectory = true; //还原上次目录
- if (saveFile.ShowDialog() == DialogResult.OK)
- {
- //string Address = Application.StartupPath.Substring(0, Application.StartupPath.Length - 35) + "\\Opton\\OTSPartA\\OTS\\Bin\\Win32\\Debug\\Config\\SysData\\OTSParticleSTD.xml";
- //string Address = ".\\Config\\SysData\\OTSParticleSTD.xml";
- System.IO.File.Copy(Address, saveFile.FileName, true);
- SaveXmlTreeDataToXml(saveFile.FileName);
- MessageBox.Show(table["message25"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- else
- {
- return;
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- //string Address_backup = Application.StartupPath.Substring(0, Application.StartupPath.Length-35) + "\\Bin\\Win32\\Debug\\Config\\SysData\\OTSParticleSTD_backup.xml";
- //string Address_backup = ".\\Config\\SysData\\OTSParticleSTD_backup.xml";
- //SaveXmlTreeDataToXml(Address_backup);
- //MessageBox.Show("备份成功!", "提示");
- }
- private void button_Recover_Click(object sender, EventArgs e)
- {
- XmlDocument doc = new XmlDocument();
- //string Address_backup = ".\\Config\\SysData\\OTSParticleSTD_backup.xml";
- //string Address = ".\\Config\\SysData\\OTSParticleSTD.xml";
- //string Address_backup = Application.StartupPath + "\\Config\\SysData\\\\OTSParticleSTD_backup.xml";
- //string Address = Application.StartupPath + "\\Config\\SysData\\OTSParticleSTD.xml";
- try
- {
- System.IO.File.Copy(Address_backup, Address, true);
- doc.Load(Address_backup);
-
- XmlTree_STDlist.Nodes.Clear();
- XmlTree_MaxEDSRules.Nodes.Clear();
- XmlTree_ZeroElementRules.Nodes.Clear();
- checkBox_0.Checked = false;
- checkBox_1.Checked = false;
- checkBox_2.Checked = false;
- checkBox_3.Checked = false;
- checkBox_4.Checked = false;
- checkBox_5.Checked = false;
- checkBox_6.Checked = false;
- checkBox_7.Checked = false;
- checkBox_8.Checked = false;
- checkBox_9.Checked = false;
- textBox_0.ReadOnly = true;
- textBox_1.ReadOnly = true;
- textBox_2.ReadOnly = true;
- textBox_3.ReadOnly = true;
- textBox_4.ReadOnly = true;
- textBox_5.ReadOnly = true;
- textBox_6.ReadOnly = true;
- textBox_7.ReadOnly = true;
- textBox_8.ReadOnly = true;
- textBox_9.ReadOnly = true;
- LoadXmlToTreeControl(doc, XmlTree_STDlist.Nodes, XmlTree_MaxEDSRules.Nodes, XmlTree_ZeroElementRules.Nodes);
- XmlTree_STDlist.SelectedNode = null;
- XmlTree_MaxEDSRules.SelectedNode = null;
- XmlTree_ZeroElementRules.SelectedNode = null;
- textbox_STDEditor.Text = "";
- textBox_Density.Text = "";
- textBox_Electrical_conductivity.Text = "";
- textBox_Hardness.Text = "";
- //textBox_MaxEDSTime.Text = "";
- btn_dbs.BackColor = Color.White;
- dataGridView_KeyElements.Rows.Clear();
- dataGridView_KeyElements.Columns.Clear();
- dataGridView_SubElements.Rows.Clear();
- dataGridView_SubElements.Columns.Clear();
- }
- catch(Exception ex)
- {
- MessageBox.Show(table["message26"].ToString() + "\n"+ex.Message.ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- }
- private void tabControl_Rules_DrawItem(object sender, DrawItemEventArgs e)
- {
- //SolidBrush _Brush = new SolidBrush(Color.Black);//单色画刷
- //RectangleF _TabTextArea = (RectangleF)tabControl_Rules.GetTabRect(e.Index);//绘制区域
- //StringFormat _sf = new StringFormat();//封装文本布局格式信息
- //_sf.LineAlignment = StringAlignment.Center;
- //_sf.Alignment = StringAlignment.Center;
- //e.Graphics.DrawString(tabControl_Rules.Controls[e.Index].Text, SystemInformation.MenuFont, _Brush, _TabTextArea, _sf);
- //RectangleF tabArea = tabControl_Rules.GetTabRect(e.Index);
- //RectangleF tabTextArea = tabArea;
- //Graphics g = e.Graphics;
- //StringFormat sf = new StringFormat();
- //sf.LineAlignment = StringAlignment.Center;
- //sf.Alignment = StringAlignment.Center;
- //Font font = this.tabControl_Rules.Font;
- //SolidBrush brush = new SolidBrush(Color.Black);
- //g.DrawString(((TabControl)(sender)).TabPages[e.Index].Text, font, brush, tabTextArea, sf);
- }
- private void XmlTree_ZeroElementRules_MouseClick(object sender, MouseEventArgs e)
- {
- //if (e.Button == MouseButtons.Left)
- //{
- // Point ClickPoint = new Point(e.X, e.Y);
- // TreeNode CurrentNode = XmlTree_ZeroElementRules.GetNodeAt(ClickPoint);
- // if (CurrentNode != null)//判断你点的是不是一个节点
- // {
- // if (XmlTree_ZeroElementRules.SelectedNode != null&& XmlTree_ZeroElementRules.SelectedNode != CurrentNode)
- // {
- // if (XmlTree_ZeroElementRules.SelectedNode.Text.Contains("="))
- // {
- // if (!comboBox_PeriodicTable.Items.Contains(XmlTree_ZeroElementRules.SelectedNode.Text.Split('=')[0]))
- // {
- // MessageBox.Show(XmlTree_ZeroElementRules.SelectedNode.Text + "项,名称格式填写错误,正确格式为:元素名=0");
- // SetGrayExceptSelectedNode(XmlTree_ZeroElementRules, XmlTree_ZeroElementRules.SelectedNode);
- // return;
- // }
- // }
- // else
- // {
- // MessageBox.Show(XmlTree_ZeroElementRules.SelectedNode.Text + "项,名称格式填写错误,正确格式为:元素名=0");
- // SetGrayExceptSelectedNode(XmlTree_ZeroElementRules, XmlTree_ZeroElementRules.SelectedNode);
- // return;
- // }
- // if (!Checktextbox_STDEditor())
- // {
- // SetGrayExceptSelectedNode(XmlTree_ZeroElementRules, XmlTree_ZeroElementRules.SelectedNode);
- // return;
- // }
- // XmlTree_ZeroElementRules.SelectedNode.Tag = this.textbox_STDEditor.Text;
-
- // }
- // SetBlackAllNodes(XmlTree_ZeroElementRules);
- // XmlTree_ZeroElementRules.SelectedNode = CurrentNode;
- // this.textbox_STDEditor.Text = XmlTree_ZeroElementRules.SelectedNode.Tag.ToString();
-
- // }
- //}
- }
- private void XmlTree_ZeroElementRules_MouseDoubleClick(object sender, MouseEventArgs e)
- {
- if (e.Button == MouseButtons.Left)
- {
- Point ClickPoint = new Point(e.X, e.Y);
- TreeNode CurrentNode = XmlTree_ZeroElementRules.GetNodeAt(ClickPoint);
- if (CurrentNode != null)//判断你点的是不是一个节点
- {
- XmlTree_ZeroElementRules.SelectedNode = CurrentNode;//选中这个节点
- //this.textbox_STDEditor.Text = XmlTree_ZeroElementRules.SelectedNode.Tag.ToString();
- XmlTree_ZeroElementRules.LabelEdit = true;
- XmlTree_ZeroElementRules.SelectedNode.BeginEdit();
- }
- }
- }
- private void XmlTree_MaxEDSRules_MouseClick(object sender, MouseEventArgs e)
- {
- //if (e.Button == MouseButtons.Left)
- //{
- // Point ClickPoint = new Point(e.X, e.Y);
- // TreeNode CurrentNode = XmlTree_MaxEDSRules.GetNodeAt(ClickPoint);
- // if (CurrentNode != null)//判断你点的是不是一个节点
- // {
- // if (XmlTree_MaxEDSRules.SelectedNode != null&& XmlTree_MaxEDSRules.SelectedNode!= CurrentNode)
- // {
- // if (!Checktextbox_STDEditor())
- // {
- // SetGrayExceptSelectedNode(XmlTree_MaxEDSRules, XmlTree_MaxEDSRules.SelectedNode);
- // return;
- // }
- // //double dMaxEDSTime = 0;
- // //if (!double.TryParse(textBox_MaxEDSTime.Text, out dMaxEDSTime)||double.Parse(textBox_MaxEDSTime.Text)<=0)
- // //{
- // // MessageBox.Show("MaxEDSTime请填写数字!", "提示");
- // //}
- // XmlTree_MaxEDSRules.SelectedNode.Tag = this.textbox_STDEditor.Text;
- // //XmlTree_MaxEDSRules.SelectedNode.Name = this.textBox_MaxEDSTime.Text;
-
- // }
- // SetBlackAllNodes(XmlTree_MaxEDSRules);
- // XmlTree_MaxEDSRules.SelectedNode = CurrentNode;
- // this.textbox_STDEditor.Text = XmlTree_MaxEDSRules.SelectedNode.Tag.ToString();
- // //textBox_MaxEDSTime.Text = XmlTree_MaxEDSRules.SelectedNode.Name;
- // }
- //}
- }
- private void checkBox_0_CheckedChanged(object sender, EventArgs e)
- {
- if (checkBox_0.Checked)
- {
- textBox_0.ReadOnly = false;
- }
- else
- {
- if (!CheckConstants(checkBox_0.Text))
- {
- checkBox_0.Checked = true;
- }
- else
- {
- textBox_0.ReadOnly = true;
- }
- }
- }
- private void checkBox_1_CheckedChanged(object sender, EventArgs e)
- {
- if (checkBox_1.Checked)
- {
- textBox_1.ReadOnly = false;
- }
- else
- {
- if (!CheckConstants(checkBox_1.Text))
- {
- checkBox_1.Checked = true;
- }
- else
- {
- textBox_1.ReadOnly = true;
- }
- }
- }
- private void checkBox_2_CheckedChanged(object sender, EventArgs e)
- {
- if (checkBox_2.Checked)
- {
- textBox_2.ReadOnly = false;
- }
- else
- {
- if (!CheckConstants(checkBox_2.Text))
- {
- checkBox_2.Checked = true;
- }
- else
- {
- textBox_2.ReadOnly = true;
- }
- }
- }
- private void checkBox_3_CheckedChanged(object sender, EventArgs e)
- {
- if (checkBox_3.Checked)
- {
- textBox_3.ReadOnly = false;
- }
- else
- {
- if (!CheckConstants(checkBox_3.Text))
- {
- checkBox_3.Checked = true;
- }
- else
- {
- textBox_3.ReadOnly = true;
- }
- }
- }
- private void checkBox_4_CheckedChanged(object sender, EventArgs e)
- {
- if (checkBox_4.Checked)
- {
- textBox_4.ReadOnly = false;
- }
- else
- {
- if (!CheckConstants(checkBox_4.Text))
- {
- checkBox_4.Checked = true;
- }
- else
- {
- textBox_4.ReadOnly = true;
- }
- }
- }
- private void checkBox_5_CheckedChanged(object sender, EventArgs e)
- {
- if (checkBox_5.Checked)
- {
- textBox_5.ReadOnly = false;
- }
- else
- {
- if (!CheckConstants(checkBox_5.Text))
- {
- checkBox_5.Checked = true;
- }
- else
- {
- textBox_5.ReadOnly = true;
- }
- }
- }
- private void checkBox_6_CheckedChanged(object sender, EventArgs e)
- {
- if (checkBox_6.Checked)
- {
- textBox_6.ReadOnly = false;
- }
- else
- {
- if (!CheckConstants(checkBox_6.Text))
- {
- checkBox_6.Checked = true;
- }
- else
- {
- textBox_6.ReadOnly = true;
- }
- }
- }
- private void checkBox_7_CheckedChanged(object sender, EventArgs e)
- {
- if (checkBox_7.Checked)
- {
- textBox_7.ReadOnly = false;
- }
- else
- {
- if (!CheckConstants(checkBox_7.Text))
- {
- checkBox_7.Checked = true;
- }
- else
- {
- textBox_7.ReadOnly = true;
- }
- }
- }
- private void checkBox_8_CheckedChanged(object sender, EventArgs e)
- {
- if (checkBox_8.Checked)
- {
- textBox_8.ReadOnly = false;
- }
- else
- {
- if (!CheckConstants(checkBox_8.Text))
- {
- checkBox_8.Checked = true;
- }
- else
- {
- textBox_8.ReadOnly = true;
- }
- }
- }
- private void checkBox_9_CheckedChanged(object sender, EventArgs e)
- {
- if (checkBox_9.Checked)
- {
- textBox_9.ReadOnly = false;
- }
- else
- {
- if (!CheckConstants(checkBox_9.Text))
- {
- checkBox_9.Checked = true;
- }
- else
- {
- textBox_9.ReadOnly = true;
- }
- }
- }
- private bool CheckConstants(string ConstantName)
- {
- for (int num = 0; num < XmlTree_STDlist.Nodes.Count; num++)
- {
- if (XmlTree_STDlist.Nodes[num].Tag.ToString().Contains(ConstantName))
- {
- tabControl_Rules.SelectedIndex = 0;
- XmlTree_STDlist.SelectedNode = XmlTree_STDlist.Nodes[num];
- SetGrayExceptSelectedNode(XmlTree_STDlist, XmlTree_STDlist.SelectedNode);
- DialogResult result = MessageBox.Show(table["message27"].ToString() + XmlTree_STDlist.Nodes[num].Text + table["message28"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return false;
- }
- }
- for (int num = 0; num < XmlTree_MaxEDSRules.Nodes.Count; num++)
- {
- if (XmlTree_MaxEDSRules.Nodes[num].Tag.ToString().Contains(ConstantName))
- {
- tabControl_Rules.SelectedIndex = 1;
- XmlTree_MaxEDSRules.SelectedNode = XmlTree_MaxEDSRules.Nodes[num];
- SetGrayExceptSelectedNode(XmlTree_MaxEDSRules, XmlTree_MaxEDSRules.SelectedNode);
- DialogResult result = MessageBox.Show(table["message27"].ToString() + XmlTree_MaxEDSRules.Nodes[num].Text + table["message28"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return false;
- }
- }
- for (int num = 0; num < XmlTree_ZeroElementRules.Nodes.Count; num++)
- {
- if (XmlTree_ZeroElementRules.Nodes[num].Tag.ToString().Contains(ConstantName))
- {
- tabControl_Rules.SelectedIndex = 2;
- XmlTree_ZeroElementRules.SelectedNode = XmlTree_ZeroElementRules.Nodes[num];
- SetGrayExceptSelectedNode(XmlTree_ZeroElementRules, XmlTree_ZeroElementRules.SelectedNode);
- DialogResult result = MessageBox.Show(table["message27"].ToString() + XmlTree_ZeroElementRules.Nodes[num].Text + table["message28"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return false;
- }
- }
- return true;
- }
- private void button_UpdateConstants_Click(object sender, EventArgs e)
- {
- this.comboBox_Constants.Items.Clear();
- for (int i=0;i<10;i++)
- {
- CheckBox checkBox= (CheckBox)this.tabControl_Rules.TabPages[3].Controls.Find("checkBox_" + i.ToString(), false)[0];
- if (checkBox.Checked)
- {
- TextBox tBox = (TextBox)this.tabControl_Rules.TabPages[3].Controls.Find("textBox_" + i.ToString(), false)[0];
- double DoubleTry = 0;
- if (double.TryParse(tBox.Text, out DoubleTry))
- {
- this.comboBox_Constants.Items.Add(checkBox.Text + "=" + tBox.Text);
- }
- else
- {
- MessageBox.Show(table["message29"].ToString() + checkBox.Name + table["message30"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return;
- }
- }
- }
- List<string> Constantslist = new List<string>();
- Constantslist.Add("MAC#0");
- Constantslist.Add("MAC#1");
- Constantslist.Add("MAC#2");
- Constantslist.Add("MAC#3");
- Constantslist.Add("MAC#4");
- Constantslist.Add("MAC#5");
- Constantslist.Add("MAC#6");
- Constantslist.Add("MAC#7");
- Constantslist.Add("MAC#8");
- Constantslist.Add("MAC#9");
- foreach (var item in comboBox_Constants.Items)
- {
- Constantslist.Remove(item.ToString().Split('=')[0]);
- }
- MessageBox.Show(table["message31"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- //tabpage切换开关
- bool Flag_TabControlChange = true;
- private void tabControl_Rules_Deselecting(object sender, TabControlCancelEventArgs e)
- {
- if (tabControl_Rules.SelectedIndex == 0)
- {
- //保存节点当前数据
- if (XmlTree_STDlist.SelectedNode != null)
- {
- //判断Hardness、Density、Electrical_conductivity
- double dHardness = 0, dDensity = 0, dElectrical_conductivity = 0;
- if (!double.TryParse(textBox_Hardness.Text, out dHardness) || (double.Parse(textBox_Hardness.Text) <= 0))
- {
- textBox_Hardness.Focus();
- textBox_Hardness.SelectAll();
- MessageBox.Show(table["message10"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- Flag_TabControlChange = false;
- return;
- }
- if (!double.TryParse(textBox_Density.Text, out dDensity) || double.Parse(textBox_Density.Text) <= 0)
- {
- textBox_Density.Focus();
- textBox_Density.SelectAll();
- MessageBox.Show(table["message11"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- Flag_TabControlChange = false;
- return;
- }
- if (!double.TryParse(textBox_Electrical_conductivity.Text, out dElectrical_conductivity) || double.Parse(textBox_Electrical_conductivity.Text) <= 0)
- {
- textBox_Electrical_conductivity.Focus();
- textBox_Electrical_conductivity.SelectAll();
- MessageBox.Show(table["message12"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- Flag_TabControlChange = false;
- return;
- }
- //判断textbox_STDEditor
- if (!Checktextbox_STDEditor())
- {
- Flag_TabControlChange = false;
- return;
- }
- Flag_TabControlChange = true;
- XmlTree_STDlist.SelectedNode.Tag = this.textbox_STDEditor.Text;
- XmlTree_STDlist.SelectedNode.Name = textBox_Hardness.Text + "_" + textBox_Density.Text + "_" + textBox_Electrical_conductivity.Text;
- string sKeyElements = "";
- for (int i = 0; i < dataGridView_KeyElements.Columns.Count; i++)
- {
- sKeyElements += dataGridView_KeyElements.Rows[0].Cells[i].Value.ToString() + ",";
- }
- if (sKeyElements.Length > 0)
- {
- sKeyElements = sKeyElements.Substring(0, sKeyElements.Length - 1);
- }
- string sSubElements = "";
- for (int i = 0; i < dataGridView_SubElements.Columns.Count; i++)
- {
- sSubElements += dataGridView_SubElements.Rows[0].Cells[i].Value.ToString() + ",";
- }
- if (sSubElements.Length > 0)
- {
- sSubElements = sSubElements.Substring(0, sSubElements.Length - 1);
- }
- XmlTree_STDlist.SelectedNode.Name += "$" + sKeyElements + "$" + sSubElements;
- XmlTree_STDlist.SelectedNode.BackColor= btn_dbs.BackColor;
- }
- }
- else if (tabControl_Rules.SelectedIndex == 1)
- {
- if (XmlTree_MaxEDSRules.SelectedNode != null)
- {
- //判断MaxEDSTime
- double dMaxEDSTime = 0;
- if (!double.TryParse(textBox_MaxEDSTime.Text, out dMaxEDSTime) || double.Parse(textBox_MaxEDSTime.Text) <= 0)
- {
- textBox_MaxEDSTime.Focus();
- textBox_MaxEDSTime.SelectAll();
- MessageBox.Show(table["message16"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- Flag_TabControlChange = false;
- return;
- }
- //判断textbox_STDEditor
- if (!Checktextbox_STDEditor())
- {
- Flag_TabControlChange = false;
- return;
- }
- Flag_TabControlChange = true;
- XmlTree_MaxEDSRules.SelectedNode.Tag = this.textbox_STDEditor.Text;
- //XmlTree_MaxEDSRules.SelectedNode.Name = textBox_MaxEDSTime.Text;
- }
- }
- else if (tabControl_Rules.SelectedIndex == 2)
- {
- if (XmlTree_ZeroElementRules.SelectedNode != null)
- {
- if (XmlTree_ZeroElementRules.SelectedNode.Text.Contains("="))
- {
- if (!comboBox_PeriodicTable.Items.Contains(XmlTree_ZeroElementRules.SelectedNode.Text.Split('=')[0]))
- {
- MessageBox.Show(XmlTree_ZeroElementRules.SelectedNode.Text + table["message9"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- Flag_TabControlChange = false;
- return;
- }
- }
- else
- {
- MessageBox.Show(XmlTree_ZeroElementRules.SelectedNode.Text + table["message9"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- Flag_TabControlChange = false;
- return;
- }
- //判断textbox_STDEditor
- if (!Checktextbox_STDEditor())
- {
- Flag_TabControlChange = false;
- return;
- }
- Flag_TabControlChange = true;
- XmlTree_ZeroElementRules.SelectedNode.Tag = this.textbox_STDEditor.Text;
- }
- }
- //XmlTree_STDlist.SelectedNode = null;
- //XmlTree_MaxEDSRules.SelectedNode = null;
- //XmlTree_ZeroElementRules.SelectedNode = null;
- //textbox_STDEditor.Text = "";
- //textBox_Density.Text = "";
- //textBox_Electrical_conductivity.Text = "";
- //textBox_Hardness.Text = "";
- //textBox_MaxEDSTime.Text = "";
- //btn_dbs.BackColor = Color.White;
- }
- private void tabControl_Rules_SelectedIndexChanged(object sender, EventArgs e)
- {
- if (tabControl_Rules.SelectedIndex == 0)
- {
- //XmlTree_STDlist.SelectedNode = null;
- XmlTree_STDlist.Focus();
- XmlTree_STDlist_AfterSelect(XmlTree_STDlist, new TreeViewEventArgs(XmlTree_STDlist.SelectedNode));
- textBox_Density.ReadOnly = false;
- textBox_Electrical_conductivity.ReadOnly = false;
- textBox_Hardness.ReadOnly = false;
- btn_dbs.Enabled = true;
- textBox_MaxEDSTime.ReadOnly = true;
- button_UpOrder.Enabled = false;
- button_DownOrder.Enabled = false;
- }
- else if (tabControl_Rules.SelectedIndex == 1)
- {
- //XmlTree_MaxEDSRules.SelectedNode = null;
- XmlTree_MaxEDSRules.Focus();
- XmlTree_MaxEDSRules_AfterSelect(XmlTree_MaxEDSRules, new TreeViewEventArgs(XmlTree_MaxEDSRules.SelectedNode));
- dataGridView_KeyElements.Rows.Clear();
- dataGridView_KeyElements.Columns.Clear();
- dataGridView_SubElements.Rows.Clear();
- dataGridView_SubElements.Columns.Clear();
- btn_dbs.BackColor = SystemColors.Control;
- textBox_Density.Text = "";
- textBox_Electrical_conductivity.Text = "";
- textBox_Hardness.Text = "";
- textBox_Density.ReadOnly = true;
- textBox_Electrical_conductivity.ReadOnly = true;
- textBox_Hardness.ReadOnly = true;
- btn_dbs.Enabled = false;
- textBox_MaxEDSTime.ReadOnly = false;
- }
- else if (tabControl_Rules.SelectedIndex == 2)
- {
- //XmlTree_ZeroElementRules.SelectedNode = null;
- XmlTree_ZeroElementRules.Focus();
- XmlTree_ZeroElementRules_AfterSelect(XmlTree_MaxEDSRules, new TreeViewEventArgs(XmlTree_ZeroElementRules.SelectedNode));
- dataGridView_KeyElements.Rows.Clear();
- dataGridView_KeyElements.Columns.Clear();
- dataGridView_SubElements.Rows.Clear();
- dataGridView_SubElements.Columns.Clear();
- btn_dbs.BackColor = SystemColors.Control;
- textBox_Density.Text = "";
- textBox_Electrical_conductivity.Text = "";
- textBox_Hardness.Text = "";
- textBox_Density.ReadOnly = true;
- textBox_Electrical_conductivity.ReadOnly = true;
- textBox_Hardness.ReadOnly = true;
- btn_dbs.Enabled = false;
- textBox_MaxEDSTime.ReadOnly = true;
- }
- else
- {
- textbox_STDEditor.Text = "";
- dataGridView_KeyElements.Rows.Clear();
- dataGridView_KeyElements.Columns.Clear();
- dataGridView_SubElements.Rows.Clear();
- dataGridView_SubElements.Columns.Clear();
- btn_dbs.BackColor = SystemColors.Control;
- textBox_Density.Text = "";
- textBox_Electrical_conductivity.Text = "";
- textBox_Hardness.Text = "";
- textBox_Density.ReadOnly = true;
- textBox_Electrical_conductivity.ReadOnly = true;
- textBox_Hardness.ReadOnly = true;
- btn_dbs.Enabled = false;
- textBox_MaxEDSTime.ReadOnly = true;
- }
- }
- private void XmlTree_ZeroElementRules_BeforeSelect(object sender, TreeViewCancelEventArgs e)
- {
- //if (e.Node != null)
- //{
- // if (e.Node.ForeColor == Color.Gray)
- // {
- // e.Cancel = true; //不让选中禁用节点
- // return;
- // }
- //}
- if (XmlTree_ZeroElementRules.SelectedNode != null)
- {
- if (XmlTree_ZeroElementRules.SelectedNode.Text.Contains("="))
- {
- if (!comboBox_PeriodicTable.Items.Contains(XmlTree_ZeroElementRules.SelectedNode.Text.Split('=')[0]))
- {
- MessageBox.Show(XmlTree_ZeroElementRules.SelectedNode.Text + table["message9"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- SetGrayExceptSelectedNode(XmlTree_ZeroElementRules, XmlTree_ZeroElementRules.SelectedNode);
- e.Cancel = true;
- return;
- }
- }
- else
- {
- MessageBox.Show(XmlTree_ZeroElementRules.SelectedNode.Text + table["message9"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- SetGrayExceptSelectedNode(XmlTree_ZeroElementRules, XmlTree_ZeroElementRules.SelectedNode);
- e.Cancel = true;
- return;
- }
- if (!Checktextbox_STDEditor())
- {
- SetGrayExceptSelectedNode(XmlTree_ZeroElementRules,XmlTree_ZeroElementRules.SelectedNode);
- e.Cancel = true;
- return;
- }
- XmlTree_ZeroElementRules.SelectedNode.Tag = this.textbox_STDEditor.Text;
- }
- }
- private void tabControl_Rules_Selecting(object sender, TabControlCancelEventArgs e)
- {
- if (!Flag_TabControlChange)
- {
- e.Cancel = true;
- }
- else
- {
- }
- }
- private void XmlTree_ZeroElementRules_AfterSelect(object sender, TreeViewEventArgs e)
- {
- SetBlackAllNodes(XmlTree_ZeroElementRules);
- this.textbox_STDEditor.Text = XmlTree_ZeroElementRules.SelectedNode.Tag.ToString();
- }
- private void XmlTree_STDlist_AfterSelect(object sender, TreeViewEventArgs e)
- {
- SetBlackAllNodes(XmlTree_STDlist);
- this.textbox_STDEditor.Text = XmlTree_STDlist.SelectedNode.Tag.ToString();
- btn_dbs.BackColor = XmlTree_STDlist.SelectedNode.BackColor;
- string[] strOther = XmlTree_STDlist.SelectedNode.Name.Split('$');
- string[] strOther2 = strOther[0].Split('_');
- textBox_Hardness.Text = strOther2[0];
- textBox_Density.Text = strOther2[1];
- textBox_Electrical_conductivity.Text = strOther2[2];
- dataGridView_KeyElements.Rows.Clear();
- dataGridView_KeyElements.Columns.Clear();
- string[] KeyElement = strOther[1].Split(',');
- for (int i=0;i< KeyElement.Length;i++)
- {
- if(KeyElement[0]!="")
- {
- 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[i].Value = KeyElement[i];
- }
- }
- dataGridView_SubElements.Rows.Clear();
- dataGridView_SubElements.Columns.Clear();
- string[] SubElement = strOther[2].Split(',');
- for (int i = 0; i < SubElement.Length; i++)
- {
- if(SubElement[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[i].Value = SubElement[i];
- }
- }
- if (button_UpOrder.Enabled == false)
- {
- button_UpOrder.Enabled = true;
- }
- if (button_DownOrder.Enabled == false)
- {
- button_DownOrder.Enabled = true;
- }
- if (XmlTree_STDlist.SelectedNode.PrevNode == null)
- {
- button_UpOrder.Enabled = false;
- }
- else if (XmlTree_STDlist.SelectedNode.NextNode == null)
- {
- button_DownOrder.Enabled = false;
- }
- dataGridView_KeyElements.ClearSelection();
- dataGridView_SubElements.ClearSelection();
- }
- private void XmlTree_STDlist_BeforeSelect(object sender, TreeViewCancelEventArgs e)
- {
- if (XmlTree_STDlist.SelectedNode != null)
- {
- //判断Hardness、Density、Electrical_conductivity
- double dHardness = 0, dDensity = 0, dElectrical_conductivity = 0;
- if (!double.TryParse(textBox_Hardness.Text, out dHardness) || (double.Parse(textBox_Hardness.Text) <= 0))
- {
- MessageBox.Show(table["message10"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- SetGrayExceptSelectedNode(XmlTree_STDlist, XmlTree_STDlist.SelectedNode);
- Flag_SelStatus = false;
- e.Cancel = true;
- return;
- }
- if (!double.TryParse(textBox_Density.Text, out dDensity) || double.Parse(textBox_Density.Text) <= 0)
- {
- MessageBox.Show(table["message11"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- SetGrayExceptSelectedNode(XmlTree_STDlist, XmlTree_STDlist.SelectedNode);
- Flag_SelStatus = false;
- e.Cancel = true;
- return;
- }
- if (!double.TryParse(textBox_Electrical_conductivity.Text, out dElectrical_conductivity) || double.Parse(textBox_Electrical_conductivity.Text) <= 0)
- {
- MessageBox.Show(table["message12"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- SetGrayExceptSelectedNode(XmlTree_STDlist, XmlTree_STDlist.SelectedNode);
- Flag_SelStatus = false;
- e.Cancel = true;
- return;
- }
- //判断textbox_STDEditor
- if (!Checktextbox_STDEditor())
- {
- SetGrayExceptSelectedNode(XmlTree_STDlist, XmlTree_STDlist.SelectedNode);
- Flag_SelStatus = false;
- e.Cancel = true;
- return;
- }
- XmlTree_STDlist.SelectedNode.Tag = this.textbox_STDEditor.Text;
- if (dataGridView_KeyElements.Rows.Count == 0&& dataGridView_SubElements.Rows.Count==0)
- {
- 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]);
- }
- }
- }
- 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];
- }
- }
- XmlTree_STDlist.SelectedNode.Name = textBox_Hardness.Text + "_" + textBox_Density.Text + "_" + textBox_Electrical_conductivity.Text;
- string sKeyElements = "";
- for (int i = 0; i < dataGridView_KeyElements.Columns.Count; i++)
- {
- sKeyElements += dataGridView_KeyElements.Rows[0].Cells[i].Value.ToString()+",";
- }
- if (sKeyElements.Length > 0)
- {
- sKeyElements = sKeyElements.Substring(0,sKeyElements.Length-1);
- }
- string sSubElements = "";
- for (int i = 0; i < dataGridView_SubElements.Columns.Count; i++)
- {
- sSubElements += dataGridView_SubElements.Rows[0].Cells[i].Value.ToString()+",";
- }
- if(sSubElements.Length>0)
- {
- sSubElements = sSubElements.Substring(0, sSubElements.Length-1);
- }
- XmlTree_STDlist.SelectedNode.Name += "$" + sKeyElements + "$" + sSubElements;
- XmlTree_STDlist.SelectedNode.BackColor= btn_dbs.BackColor;
- }
- }
- private void XmlTree_MaxEDSRules_AfterSelect(object sender, TreeViewEventArgs e)
- {
- SetBlackAllNodes(XmlTree_MaxEDSRules);
- this.textbox_STDEditor.Text = XmlTree_MaxEDSRules.SelectedNode.Tag.ToString();
- //textBox_MaxEDSTime.Text = XmlTree_MaxEDSRules.SelectedNode.Name;
- }
- private void XmlTree_MaxEDSRules_BeforeSelect(object sender, TreeViewCancelEventArgs e)
- {
- if (XmlTree_MaxEDSRules.SelectedNode != null)
- {
- if (!Checktextbox_STDEditor())
- {
- SetGrayExceptSelectedNode(XmlTree_MaxEDSRules, XmlTree_MaxEDSRules.SelectedNode);
- e.Cancel = true;
- return;
- }
- //double dMaxEDSTime = 0;
- //if (!double.TryParse(textBox_MaxEDSTime.Text, out dMaxEDSTime)||double.Parse(textBox_MaxEDSTime.Text)<=0)
- //{
- // MessageBox.Show("MaxEDSTime请填写数字!", "提示");
- // e.Cancel = true;
- //}
- XmlTree_MaxEDSRules.SelectedNode.Tag = this.textbox_STDEditor.Text;
- //XmlTree_MaxEDSRules.SelectedNode.Name = this.textBox_MaxEDSTime.Text;
- }
- }
- 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();
- XmlTree_STDlist.Focus();
- }
- 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();
- XmlTree_STDlist.Focus();
- }
- private void textbox_STDEditor_TextChanged(object sender, EventArgs e)
- {
- //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]);
- // }
- // }
- //}
- //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];
- //}
- }
- private void textbox_STDEditor_KeyPress(object sender, KeyPressEventArgs e)
- {
- //if (e.KeyChar == '\r')
- //{
- // dataGridView_KeyElements.Rows.Clear();
- // dataGridView_KeyElements.Columns.Clear();
- // dataGridView_SubElements.Rows.Clear();
- // dataGridView_SubElements.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]);
- // }
- // }
- // }
- // 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];
- // }
- //}
- }
- private void textbox_STDEditor_Leave(object sender, EventArgs e)
- {
- if (tabControl_Rules.SelectedIndex == 0)
- {
- 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();
- XmlTree_STDlist.Focus();
- }
- else if(tabControl_Rules.SelectedIndex == 1)
- {
- XmlTree_MaxEDSRules.Focus();
- }
- else if (tabControl_Rules.SelectedIndex == 2)
- {
- XmlTree_ZeroElementRules.Focus();
- }
- }
-
- #region 为配合textbox_STDEditor_Leave时事件,点击其它groupbox组件时使焦点转移
- private void Form_ConstantsEditor_Click(object sender, EventArgs e)
- {
- groupBox_XmlTree_MaxEDSRules.Focus();
- }
- private void groupBox_Data_Click(object sender, EventArgs e)
- {
- groupBox_Data.Focus();
- }
- private void groupBox_Color_Click(object sender, EventArgs e)
- {
- groupBox_Color.Focus();
- }
- private void groupBox_ChemicalElement_Click(object sender, EventArgs e)
- {
- groupBox_ChemicalElement.Focus();
- }
- private void groupBox_OtherCommonlyUsedSymbols_Click(object sender, EventArgs e)
- {
- groupBox_OtherCommonlyUsedSymbols.Focus();
- }
- private void groupBox_XmlTree_STDlist1_Click(object sender, EventArgs e)
- {
- groupBox_XmlTree_STDlist1.Focus();
- }
- private void groupBox_CalculatingSymbols_Click(object sender, EventArgs e)
- {
- groupBox_CalculatingSymbols.Focus();
- }
- private void groupBox_XmlTree_MaxEDSRules_Click(object sender, EventArgs e)
- {
- groupBox_XmlTree_MaxEDSRules.Focus();
- }
- #endregion
- 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();
- }
- ////改变大小
- //void changeSize()
- //{
- // //SetStyle(ControlStyles.UserPaint, true);
- // //SetStyle(ControlStyles.AllPaintingInWmPaint, true); // 禁止擦除背景.
- // //SetStyle(ControlStyles.OptimizedDoubleBuffer, true); // 双缓冲DoubleBuffer
- // x = this.Width;
- // y = this.Height;
- // setTag(this);
- // //if (this.WindowState == FormWindowState.Maximized)
- // //{
- // // this.WindowState = FormWindowState.Normal;
- // //}
- // //else
- // //{
- // // this.FormBorderStyle = FormBorderStyle.None;
- // // this.WindowState = FormWindowState.Maximized;
- // //}
- //}
- //#region 控件大小随窗体大小等比例缩放
- //private float x;//定义当前窗体的宽度
- //private float y;//定义当前窗体的高度
- //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);
- // }
- // }
- //}
- ////设置双缓冲区、解决闪屏问题
- //public static void SetDouble(Control cc)
- //{
- // cc.GetType().GetProperty("DoubleBuffered", System.Reflection.BindingFlags.Instance |
- // System.Reflection.BindingFlags.NonPublic).SetValue(cc, true, null);
- //}
- //private void setControls(float newx, float newy, Control cons)
- //{
- // //遍历窗体中的控件,重新设置控件的值
- // foreach (Control con in cons.Controls)
- // {
- // ////获取控件的Tag属性值,并分割后存储字符串数组
- // SetDouble(this);
- // SetDouble(con);
- // if (con.Tag != null)
- // {
- // string[] mytag = con.Tag.ToString().Split(new char[] { ';' });
- // //根据窗体缩放的比例确定控件的值
- // con.Width = Convert.ToInt32(System.Convert.ToSingle(mytag[0]) * newx);//宽度
- // con.Height = Convert.ToInt32(System.Convert.ToSingle(mytag[1]) * newy);//高度
- // con.Left = Convert.ToInt32(System.Convert.ToSingle(mytag[2]) * newx);//左边距
- // con.Top = Convert.ToInt32(System.Convert.ToSingle(mytag[3]) * newy);//顶边距
- // Single currentSize = System.Convert.ToSingle(mytag[4]) * newy;//字体大小
- // con.Font = new Font(con.Font.Name, currentSize, con.Font.Style, con.Font.Unit);
- // if (con.Controls.Count > 0)
- // {
- // setControls(newx, newy, con);
- // }
- // }
- // }
- //}
- //private void setControls2(float newx, float newy, Control cons)
- //{
- // //遍历窗体中的控件,重新设置控件的值
- // foreach (Control con in cons.Controls)
- // {
- // //根据窗体缩放的比例确定控件的值
- // con.Width = Convert.ToInt32(con.Width * newx);
- // con.Height = Convert.ToInt32(con.Height * newy);
- // con.Left = Convert.ToInt32(con.Left * newx);
- // con.Top = Convert.ToInt32(con.Top * newx);
- // //Single currentSize = System.Convert.ToSingle(con.Font.Size) * newy;//字体大小
- // //con.Font = new Font(con.Font.Name, currentSize, con.Font.Style, con.Font.Unit);
- // if (con.Controls.Count > 0)
- // {
- // setControls2(newx, newy, con);
- // }
- // }
- //}
- ////在窗体的的时间中添加Resize事件
- //private void Login_Resize(object sender, EventArgs e)
- //{
- // if (this.WindowState == FormWindowState.Maximized)
- // {
- // float newx = (this.Width) / x;
- // float newy = (this.Height) / y;
- // setControls2(newx, newy, this);
- // PeriodicTableSwitch_Click(PeriodicTableSwitch, new EventArgs());
- // }
- // else
- // {
- // //setControls2(x, y, this);
- // }
- //}
- //#endregion
- }
- }
|