Form_ConstantsEditor.cs 162 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.Xml;
  11. using System.Xml.Linq;
  12. namespace OTSPartA_STDEditor
  13. {
  14. public partial class Form_ConstantsEditor : Form
  15. {
  16. //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"};
  17. //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" };
  18. public Form_ConstantsEditor()
  19. {
  20. InitializeComponent();
  21. //changeSize();
  22. }
  23. //国际化
  24. Language lan;
  25. System.Collections.Hashtable table;
  26. //public string Language = "English";
  27. string Address_backup = Application.StartupPath + "\\Config\\SysData\\OTSParticleSTD_backup.xml";
  28. string Address = Application.StartupPath + "\\Config\\SysData\\OTSParticleSTD.xml";
  29. private void Form_ConstantsEditor_Load(object sender, EventArgs e)
  30. {
  31. //初始化comboBox
  32. this.comboBox_Elem1.Items.Add("first_elem");
  33. this.comboBox_Elem1.Items.Add("second_elem");
  34. this.comboBox_Elem1.Items.Add("third_elem");
  35. this.comboBox_Elem1.Items.Add("forth_elem");
  36. this.comboBox_Elem1.Items.Add("fifth_elem");
  37. this.comboBox_Elem1.Items.Add("sixth_elem");
  38. this.comboBox_Elem1.Items.Add("seventh_elem");
  39. this.comboBox_Elem1.Items.Add("eighth_elem");
  40. this.comboBox_Elem1.Items.Add("ninth_elem");
  41. this.comboBox_Elem1.Items.Add("tenth_elem");
  42. comboBox_Elem1.SelectedIndex = comboBox_Elem1.Items.IndexOf("first_elem");
  43. this.comboBox_Elem.Items.Add("Element#1");
  44. this.comboBox_Elem.Items.Add("Element#2");
  45. this.comboBox_Elem.Items.Add("Element#3");
  46. this.comboBox_Elem.Items.Add("Element#4");
  47. this.comboBox_Elem.Items.Add("Element#5");
  48. this.comboBox_Elem.Items.Add("Element#6");
  49. this.comboBox_Elem.Items.Add("Element#7");
  50. this.comboBox_Elem.Items.Add("Element#8");
  51. this.comboBox_Elem.Items.Add("Element#9");
  52. this.comboBox_Elem.Items.Add("Element#10");
  53. comboBox_Elem.SelectedIndex = comboBox_Elem.Items.IndexOf("Element#1");
  54. this.comboBox_ImgProperty.Items.Add("Dmax");
  55. this.comboBox_ImgProperty.Items.Add("Dmin");
  56. this.comboBox_ImgProperty.Items.Add("Aspect");
  57. this.comboBox_ImgProperty.Items.Add("Dperp");
  58. this.comboBox_ImgProperty.Items.Add("Dmean");
  59. this.comboBox_ImgProperty.Items.Add("Area");
  60. this.comboBox_ImgProperty.Items.Add("Dferet");
  61. this.comboBox_ImgProperty.Items.Add("With");
  62. this.comboBox_ImgProperty.Items.Add("Height");
  63. this.comboBox_ImgProperty.Items.Add("Perimeter");
  64. this.comboBox_ImgProperty.Items.Add("Dinscr");
  65. this.comboBox_ImgProperty.Items.Add("Orientation");
  66. this.comboBox_ImgProperty.Items.Add("Delong");
  67. this.comboBox_ImgProperty.Items.Add("Aspectelong");
  68. this.comboBox_ImgProperty.Items.Add("Dequalcircle");
  69. this.comboBox_ImgProperty.Items.Add("Vedio");
  70. comboBox_ImgProperty.SelectedIndex = comboBox_ImgProperty.Items.IndexOf("Dmax");
  71. //this.comboBox_Constants.Items.Add("MAC#0");
  72. //this.comboBox_Constants.Items.Add("MAC#1");
  73. //this.comboBox_Constants.Items.Add("MAC#2");
  74. //this.comboBox_Constants.Items.Add("MAC#3");
  75. //this.comboBox_Constants.Items.Add("MAC#4");
  76. //this.comboBox_Constants.Items.Add("MAC#5");
  77. //this.comboBox_Constants.Items.Add("MAC#6");
  78. //this.comboBox_Constants.Items.Add("MAC#7");
  79. //this.comboBox_Constants.Items.Add("MAC#8");
  80. //this.comboBox_Constants.Items.Add("MAC#9");
  81. //comboBox_Constants.SelectedIndex = comboBox_Constants.Items.IndexOf("MAC#1");
  82. 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" };
  83. comboBox_PeriodicTable.Items.AddRange(PeriodicTable);
  84. AutoCompleteStringCollection sc = new AutoCompleteStringCollection();
  85. sc.AddRange(PeriodicTable);
  86. this.comboBox_PeriodicTable.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.Suggest;
  87. this.comboBox_PeriodicTable.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.CustomSource;
  88. this.comboBox_PeriodicTable.AutoCompleteCustomSource = sc;
  89. checkBox_0.Checked = false;
  90. checkBox_1.Checked = false;
  91. checkBox_2.Checked = false;
  92. checkBox_3.Checked = false;
  93. checkBox_4.Checked = false;
  94. checkBox_5.Checked = false;
  95. checkBox_6.Checked = false;
  96. checkBox_7.Checked = false;
  97. checkBox_8.Checked = false;
  98. checkBox_9.Checked = false;
  99. textBox_0.ReadOnly = true;
  100. textBox_1.ReadOnly = true;
  101. textBox_2.ReadOnly = true;
  102. textBox_3.ReadOnly = true;
  103. textBox_4.ReadOnly = true;
  104. textBox_5.ReadOnly = true;
  105. textBox_6.ReadOnly = true;
  106. textBox_7.ReadOnly = true;
  107. textBox_8.ReadOnly = true;
  108. textBox_9.ReadOnly = true;
  109. textBox_Density.ReadOnly = false;
  110. textBox_Electrical_conductivity.ReadOnly = false;
  111. textBox_Hardness.ReadOnly = false;
  112. btn_dbs.Enabled = true;
  113. dataGridView_KeyElements.RowHeadersVisible = false;
  114. dataGridView_KeyElements.ColumnHeadersVisible = false;
  115. dataGridView_KeyElements.AllowUserToAddRows = false;
  116. dataGridView_KeyElements.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
  117. dataGridView_SubElements.RowHeadersVisible = false;
  118. dataGridView_SubElements.ColumnHeadersVisible = false;
  119. dataGridView_SubElements.AllowUserToAddRows = false;
  120. dataGridView_SubElements.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
  121. XmlDocument doc = new XmlDocument();
  122. //string Address = Application.StartupPath.Substring(0, Application.StartupPath.Length-35) + "\\Opton\\OTSPartA\\OTS\\Bin\\Win32\\Debug\\Config\\SysData\\OTSParticleSTD.xml";
  123. //string Address = ".\\Config\\SysData\\OTSParticleSTD.xml";
  124. doc.Load(Address);
  125. LoadXmlToTreeControl(doc, XmlTree_STDlist.Nodes, XmlTree_MaxEDSRules.Nodes, XmlTree_ZeroElementRules.Nodes);
  126. button_UpOrder.Enabled = false;
  127. button_DownOrder.Enabled = false;
  128. textBox_MaxEDSTime.ReadOnly = true;
  129. this.textbox_STDEditor.Text = "";
  130. //this.XmlTree.TabStop = false;
  131. panel_OTSPeriodicTable.Visible = false;
  132. //修改窗体宽度
  133. //this.Width = this.Width - panel_OTSPeriodicTable.Width - 5;
  134. //if (XmlTree.GetNodeCount(true) != 0)
  135. //{
  136. // this.XmlTree.SelectedNode = XmlTree.Nodes[0];
  137. //}
  138. lan = new Language(this);
  139. table = lan.GetNameTable(this.Name);
  140. if (table["language"].ToString() == "EN")
  141. {
  142. panel_OTSPeriodicTable.BackgroundImage = global::OTSPartA_STDEditor.Properties.Resources.PeriodicTable_EN;
  143. PeriodicTableSwitch.BackgroundImage = global::OTSPartA_STDEditor.Properties.Resources.STDEditoName;
  144. PeriodicTableSwitch.Text = "";
  145. }
  146. else
  147. {
  148. panel_OTSPeriodicTable.BackgroundImage = global::OTSPartA_STDEditor.Properties.Resources.PeriodicTable_ZH;
  149. PeriodicTableSwitch.Text = "元素周期表";
  150. }
  151. panel_OTSPeriodicTable.Visible = false;
  152. this.Width = this.Width - panel_OTSPeriodicTable.Width - 5;
  153. Size size = Screen.PrimaryScreen.WorkingArea.Size; Left = (size.Width - Width) / 2;
  154. Top = (size.Height - Height) / 2;
  155. WindowState = FormWindowState.Normal;
  156. //groupBox_XmlTree_MaxEDSRules.Focus();
  157. this.XmlTree_STDlist.HideSelection = false;//失去焦点后不隐藏选中节点
  158. XmlTree_STDlist.Focus();
  159. if (XmlTree_STDlist.Nodes.Count > 0)
  160. {
  161. XmlTree_STDlist.SelectedNode = XmlTree_STDlist.Nodes[0];
  162. XmlTree_STDlist_AfterSelect(XmlTree_STDlist, new TreeViewEventArgs(XmlTree_STDlist.SelectedNode));
  163. }
  164. }
  165. /// <summary>
  166. /// [颜色:16进制转成RGB]
  167. /// </summary>
  168. /// <param name="strColor">设置16进制颜色 [返回RGB]</param>
  169. /// <returns></returns>
  170. public static System.Drawing.Color colorHx16toRGB(string strHxColor)
  171. {
  172. try
  173. {
  174. if (strHxColor.Length == 0)
  175. {//如果为空
  176. return System.Drawing.Color.FromArgb(255, 255, 204);//设为白色
  177. }
  178. else
  179. {//转换颜色
  180. 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));
  181. }
  182. }
  183. catch
  184. {//设为白色
  185. return System.Drawing.Color.FromArgb(255, 255, 204);
  186. }
  187. }
  188. /// <summary>
  189. /// [颜色:RGB转成16进制]
  190. /// </summary>
  191. /// <param name="R">红 int</param>
  192. /// <param name="G">绿 int</param>
  193. /// <param name="B">蓝 int</param>
  194. /// <returns></returns>
  195. public static string colorRGBtoHx16(int R, int G, int B)
  196. {
  197. return System.Drawing.ColorTranslator.ToHtml(System.Drawing.Color.FromArgb(R, G, B));
  198. }
  199. //XmlTree_STDlist、XmlTree_MaxEDSRules、XmlTree_ZeroElementRules和 ConstantsPage页
  200. void LoadXmlToTreeControl(XmlDocument xml, TreeNodeCollection XmlTree_STDlist, TreeNodeCollection XmlTree_MaxEDSRules, TreeNodeCollection XmlTree_ZeroElementRules)
  201. {
  202. XmlNode root = xml.SelectSingleNode("XMLData");
  203. XmlNodeList root2 = root.SelectNodes("Collection");
  204. for (int j = 0; j < root2.Count; j++)
  205. {
  206. if (root2[j].Attributes["RegName"].Value.ToString()== "STDList")
  207. {
  208. XmlNodeList childlist = root2[j].ChildNodes;
  209. for (int i = 0; i < childlist.Count; i++)
  210. {
  211. TreeNode new_child = new TreeNode();//定义一个TreeNode节点对象
  212. 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;
  213. new_child.Text = childlist[i].Attributes["StrName"].Value;
  214. new_child.Tag = childlist[i].Attributes["Expression"].Value;
  215. new_child.ToolTipText = childlist[i].Attributes["STDId"].Value;
  216. new_child.BackColor = colorHx16toRGB(childlist[i].Attributes["Color"].Value);
  217. XmlTree_STDlist.Add(new_child);
  218. }
  219. }
  220. if (root2[j].Attributes["RegName"].Value.ToString() == "ZeroElementRules")
  221. {
  222. XmlNodeList childlist = root2[j].ChildNodes;
  223. for (int i = 0; i < childlist.Count; i++)
  224. {
  225. TreeNode new_child = new TreeNode();//定义一个TreeNode节点对象
  226. new_child.Text = childlist[i].Attributes["ZeroElement"].Value+"=0";
  227. new_child.Tag = childlist[i].Attributes["Expression"].Value;
  228. XmlTree_ZeroElementRules.Add(new_child);
  229. }
  230. }
  231. if (root2[j].Attributes["RegName"].Value.ToString() == "MaxEDSRules")
  232. {
  233. XmlNodeList childlist = root2[j].ChildNodes;
  234. if (childlist.Count != 0)
  235. {
  236. for (int i = 0; i < childlist.Count; i++)
  237. {
  238. TreeNode new_child = new TreeNode();//定义一个TreeNode节点对象
  239. //new_child.Name = childlist[i].Attributes["MaxEDSTime"].Value;
  240. new_child.Tag = childlist[i].Attributes["Expression"].Value;
  241. new_child.Text = "Rule" + i.ToString();
  242. XmlTree_MaxEDSRules.Add(new_child);
  243. }
  244. if (childlist[0].Attributes["MaxEDSTime"] != null)
  245. {
  246. textBox_MaxEDSTime.Text = childlist[0].Attributes["MaxEDSTime"].Value;
  247. }
  248. }
  249. }
  250. }
  251. XmlNode root3 = root.SelectSingleNode("Member");
  252. string ConstantsStr = root3.Attributes["value"].Value;
  253. ConstantsStr = ConstantsStr.Replace(" ", "");
  254. string[] ConstantsStr2 = ConstantsStr.Split(',');
  255. this.comboBox_Constants.Items.Clear();
  256. this.comboBox_Constants.Items.AddRange(ConstantsStr2);
  257. List<string> Constantslist = new List<string>();
  258. for (int i = 0; i < ConstantsStr2.Length; i++)
  259. {
  260. Constantslist.AddRange(ConstantsStr2[i].Split('='));
  261. }
  262. for (int i = 0; i < Constantslist.Count; i += 2)
  263. {
  264. if (Constantslist[i].Contains("MAC#0"))
  265. {
  266. this.checkBox_0.Checked = true;
  267. this.textBox_0.ReadOnly = false;
  268. this.textBox_0.Text = Constantslist[i + 1];
  269. }
  270. else if (Constantslist[i].Contains("MAC#1"))
  271. {
  272. this.checkBox_1.Checked = true;
  273. this.textBox_1.ReadOnly = false;
  274. this.textBox_1.Text = Constantslist[i + 1];
  275. }
  276. else if (Constantslist[i].Contains("MAC#2"))
  277. {
  278. this.checkBox_2.Checked = true;
  279. this.textBox_2.ReadOnly = false;
  280. this.textBox_2.Text = Constantslist[i + 1];
  281. }
  282. else if (Constantslist[i].Contains("MAC#3"))
  283. {
  284. this.checkBox_3.Checked = true;
  285. this.textBox_3.ReadOnly = false;
  286. this.textBox_3.Text = Constantslist[i + 1];
  287. }
  288. else if (Constantslist[i].Contains("MAC#4"))
  289. {
  290. this.checkBox_4.Checked = true;
  291. this.textBox_4.ReadOnly = false;
  292. this.textBox_4.Text = Constantslist[i + 1];
  293. }
  294. else if (Constantslist[i].Contains("MAC#5"))
  295. {
  296. this.checkBox_5.Checked = true;
  297. this.textBox_5.ReadOnly = false;
  298. this.textBox_5.Text = Constantslist[i + 1];
  299. }
  300. else if (Constantslist[i].Contains("MAC#6"))
  301. {
  302. this.checkBox_6.Checked = true;
  303. this.textBox_6.ReadOnly = false;
  304. this.textBox_6.Text = Constantslist[i + 1];
  305. }
  306. else if (Constantslist[i].Contains("MAC#7"))
  307. {
  308. this.checkBox_7.Checked = true;
  309. this.textBox_7.ReadOnly = false;
  310. this.textBox_7.Text = Constantslist[i + 1];
  311. }
  312. else if (Constantslist[i].Contains("MAC#8"))
  313. {
  314. this.checkBox_8.Checked = true;
  315. this.textBox_8.ReadOnly = false;
  316. this.textBox_8.Text = Constantslist[i + 1];
  317. }
  318. else if (Constantslist[i].Contains("MAC#9"))
  319. {
  320. this.checkBox_9.Checked = true;
  321. this.textBox_9.ReadOnly = false;
  322. this.textBox_9.Text = Constantslist[i + 1];
  323. }
  324. }
  325. }
  326. private void comboBox_Elem1_SelectedIndexChanged(object sender, EventArgs e)
  327. {
  328. string newStr = comboBox_Elem1.SelectedItem.ToString();
  329. int index = textbox_STDEditor.SelectionStart;
  330. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, newStr);
  331. textbox_STDEditor.Focus();
  332. textbox_STDEditor.Select(index + newStr.Length, 0);
  333. textbox_STDEditor.ScrollToCaret();
  334. }
  335. private void comboBox_Elem2_SelectedIndexChanged(object sender, EventArgs e)
  336. {
  337. string newStr = comboBox_Elem.SelectedItem.ToString();
  338. int index = textbox_STDEditor.SelectionStart;
  339. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, newStr);
  340. textbox_STDEditor.Focus();
  341. textbox_STDEditor.Select(index + newStr.Length, 0);
  342. textbox_STDEditor.ScrollToCaret();
  343. }
  344. private void comboBox_ImgProperty_SelectedIndexChanged(object sender, EventArgs e)
  345. {
  346. string newStr = comboBox_ImgProperty.SelectedItem.ToString();
  347. int index = textbox_STDEditor.SelectionStart;
  348. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, newStr);
  349. textbox_STDEditor.Focus();
  350. textbox_STDEditor.Select(index + newStr.Length, 0);
  351. textbox_STDEditor.ScrollToCaret();
  352. }
  353. private void button_Plus_Click(object sender, EventArgs e)
  354. {
  355. //textbox_STDEditor 中的光标
  356. int index = textbox_STDEditor.SelectionStart;
  357. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "+");
  358. textbox_STDEditor.Focus();
  359. textbox_STDEditor.Select(index+1,0);
  360. textbox_STDEditor.ScrollToCaret();
  361. }
  362. private void button_Subtract_Click(object sender, EventArgs e)
  363. {
  364. //textbox_STDEditor 中的光标
  365. int index = textbox_STDEditor.SelectionStart;
  366. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "-");
  367. textbox_STDEditor.Focus();
  368. textbox_STDEditor.Select(index + 1, 0);
  369. textbox_STDEditor.ScrollToCaret();
  370. }
  371. private void button_Multiply_Click(object sender, EventArgs e)
  372. {
  373. //textbox_STDEditor 中的光标
  374. int index = textbox_STDEditor.SelectionStart;
  375. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "*");
  376. textbox_STDEditor.Focus();
  377. textbox_STDEditor.Select(index + 1, 0);
  378. textbox_STDEditor.ScrollToCaret();
  379. }
  380. private void button_Divide_Click(object sender, EventArgs e)
  381. {
  382. //textbox_STDEditor 中的光标
  383. int index = textbox_STDEditor.SelectionStart;
  384. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "/");
  385. textbox_STDEditor.Focus();
  386. textbox_STDEditor.Select(index + 1, 0);
  387. textbox_STDEditor.ScrollToCaret(); ;
  388. }
  389. private void button_More_Click(object sender, EventArgs e)
  390. {
  391. //textbox_STDEditor 中的光标
  392. int index = textbox_STDEditor.SelectionStart;
  393. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, ">");
  394. textbox_STDEditor.Focus();
  395. textbox_STDEditor.Select(index + 1, 0);
  396. textbox_STDEditor.ScrollToCaret();
  397. }
  398. private void button_Less_Click(object sender, EventArgs e)
  399. {
  400. //textbox_STDEditor 中的光标
  401. int index = textbox_STDEditor.SelectionStart;
  402. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "<");
  403. textbox_STDEditor.Focus();
  404. textbox_STDEditor.Select(index + 1, 0);
  405. textbox_STDEditor.ScrollToCaret();
  406. }
  407. private void button_LeftParenthesis_Click(object sender, EventArgs e)
  408. {
  409. //textbox_STDEditor 中的光标
  410. int index = textbox_STDEditor.SelectionStart;
  411. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "(");
  412. textbox_STDEditor.Focus();
  413. textbox_STDEditor.Select(index + 1, 0);
  414. textbox_STDEditor.ScrollToCaret();
  415. }
  416. private void button_RightParenthesis_Click(object sender, EventArgs e)
  417. {
  418. //textbox_STDEditor 中的光标
  419. int index = textbox_STDEditor.SelectionStart;
  420. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, ")");
  421. textbox_STDEditor.Focus();
  422. textbox_STDEditor.Select(index + 1, 0);
  423. textbox_STDEditor.ScrollToCaret();
  424. }
  425. private void button_Equal_Click(object sender, EventArgs e)
  426. {
  427. //textbox_STDEditor 中的光标
  428. int index = textbox_STDEditor.SelectionStart;
  429. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "=");
  430. textbox_STDEditor.Focus();
  431. textbox_STDEditor.Select(index + 1, 0);
  432. textbox_STDEditor.ScrollToCaret();
  433. }
  434. //除选中点以外其它节点前景色置灰
  435. private void SetGrayExceptSelectedNode(TreeView Tree, TreeNode SelectedNode)
  436. {
  437. foreach (TreeNode node in Tree.Nodes)
  438. {
  439. if (node != SelectedNode)
  440. {
  441. node.ForeColor = Color.Gray;
  442. }
  443. }
  444. }
  445. //恢复所有节点颜色为可用
  446. private void SetBlackAllNodes(TreeView Tree)
  447. {
  448. foreach (TreeNode node in Tree.Nodes)
  449. {
  450. node.ForeColor = Color.Black;
  451. }
  452. }
  453. //点击节点
  454. private void XmlTree_STDlist_MouseClick(object sender, MouseEventArgs e)
  455. {
  456. //if (e.Button == MouseButtons.Left)
  457. //{
  458. // Point ClickPoint = new Point(e.X, e.Y);
  459. // TreeNode CurrentNode = XmlTree_STDlist.GetNodeAt(ClickPoint);
  460. // if (CurrentNode != null)//判断你点的是不是一个节点
  461. // {
  462. // if (XmlTree_STDlist.SelectedNode != null&& XmlTree_STDlist.SelectedNode != CurrentNode)
  463. // {
  464. // //判断Hardness、Density、Electrical_conductivity
  465. // double dHardness = 0, dDensity = 0, dElectrical_conductivity = 0;
  466. // if (!double.TryParse(textBox_Hardness.Text, out dHardness))
  467. // {
  468. // MessageBox.Show("硬度输入错误,请输入数字!");
  469. // SetGrayExceptSelectedNode(XmlTree_STDlist, XmlTree_STDlist.SelectedNode);
  470. // return;
  471. // }
  472. // if (!double.TryParse(textBox_Density.Text, out dDensity))
  473. // {
  474. // MessageBox.Show("密度输入错误,请输入数字!");
  475. // SetGrayExceptSelectedNode(XmlTree_STDlist, XmlTree_STDlist.SelectedNode);
  476. // return;
  477. // }
  478. // if (!double.TryParse(textBox_Electrical_conductivity.Text, out dElectrical_conductivity))
  479. // {
  480. // MessageBox.Show("导电性输入错误,请输入数字!");
  481. // SetGrayExceptSelectedNode(XmlTree_STDlist, XmlTree_STDlist.SelectedNode);
  482. // return;
  483. // }
  484. // //判断textbox_STDEditor
  485. // if (!Checktextbox_STDEditor())
  486. // {
  487. // SetGrayExceptSelectedNode(XmlTree_STDlist, XmlTree_STDlist.SelectedNode);
  488. // return;
  489. // }
  490. // XmlTree_STDlist_SaveBeforeMouseClick(e);
  491. // }
  492. // SetBlackAllNodes(XmlTree_STDlist);
  493. // XmlTree_STDlist.SelectedNode = CurrentNode;
  494. // XmlTree_STDlist.LabelEdit = true;
  495. // this.textbox_STDEditor.Text = XmlTree_STDlist.SelectedNode.Tag.ToString();
  496. // btn_dbs.BackColor = XmlTree_STDlist.SelectedNode.BackColor;
  497. // string[] strOther = XmlTree_STDlist.SelectedNode.Name.Split('_');
  498. // textBox_Hardness.Text = strOther[0];
  499. // textBox_Density.Text = strOther[1];
  500. // textBox_Electrical_conductivity.Text = strOther[2];
  501. // if (UpOrder.Enabled == false)
  502. // {
  503. // UpOrder.Enabled = true;
  504. // }
  505. // if (DownOrder.Enabled == false)
  506. // {
  507. // DownOrder.Enabled = true;
  508. // }
  509. // if (XmlTree_STDlist.SelectedNode.PrevNode == null)
  510. // {
  511. // UpOrder.Enabled = false;
  512. // }
  513. // else if (XmlTree_STDlist.SelectedNode.NextNode == null)
  514. // {
  515. // DownOrder.Enabled = false;
  516. // }
  517. // }
  518. //}
  519. //if (e.Button == MouseButtons.Right)
  520. //{
  521. // Point ClickPoint = new Point(e.X, e.Y);
  522. // TreeNode CurrentNode = XmlTree.GetNodeAt(ClickPoint);
  523. // if (CurrentNode != null)//判断你点的是不是一个节点
  524. // {
  525. // XmlTree.SelectedNode = CurrentNode;//选中这个节点
  526. // XmlTree.LabelEdit = true;
  527. // this.textbox_STDEditor.Text = XmlTree.SelectedNode.Tag.ToString();
  528. // }
  529. //}
  530. }
  531. //XmlTree_STDlist点击节点前保存数据-Hardness、Density、Electrical_conductivity、textbox_STDEditor
  532. void XmlTree_STDlist_SaveBeforeMouseClick(MouseEventArgs e)
  533. {
  534. if ((this.textbox_STDEditor.Text != null) && (XmlTree_STDlist.SelectedNode != null))
  535. {
  536. XmlTree_STDlist.SelectedNode.Tag = this.textbox_STDEditor.Text;
  537. XmlTree_STDlist.SelectedNode.Name = textBox_Hardness.Text + "_" + textBox_Density.Text + "_" + textBox_Electrical_conductivity.Text;
  538. string sKeyElements = "";
  539. for (int i = 0; i < dataGridView_KeyElements.Columns.Count; i++)
  540. {
  541. sKeyElements += dataGridView_KeyElements.Rows[0].Cells[i].Value.ToString() + ",";
  542. }
  543. if (sKeyElements.Length > 0)
  544. {
  545. sKeyElements = sKeyElements.Substring(0, sKeyElements.Length - 1);
  546. }
  547. string sSubElements = "";
  548. for (int i = 0; i < dataGridView_SubElements.Columns.Count; i++)
  549. {
  550. sSubElements += dataGridView_SubElements.Rows[0].Cells[i].Value.ToString() + ",";
  551. }
  552. if (sSubElements.Length > 0)
  553. {
  554. sSubElements = sSubElements.Substring(0, sSubElements.Length - 1);
  555. }
  556. XmlTree_STDlist.SelectedNode.Name += "$" + sKeyElements + "$" + sSubElements;
  557. }
  558. }
  559. //删除
  560. private void DeleteTreeNode_Click(object sender, EventArgs e)
  561. {
  562. try
  563. {
  564. TreeView XmlTree = (TreeView)XmlTreeMenuStrip.SourceControl;
  565. if (XmlTree.SelectedNode != null)
  566. {
  567. if (XmlTree != null)
  568. {
  569. if (XmlTree.SelectedNode.NextNode != null)
  570. {
  571. TreeNode Temp = XmlTree.SelectedNode.NextNode;
  572. XmlTree.SelectedNode.Remove();
  573. XmlTree.SelectedNode = Temp;
  574. }
  575. else if (XmlTree.SelectedNode.PrevNode != null)
  576. {
  577. TreeNode Temp = XmlTree.SelectedNode.PrevNode;
  578. XmlTree.SelectedNode.Remove();
  579. XmlTree.SelectedNode = Temp;
  580. }
  581. else
  582. {
  583. XmlTree.SelectedNode.Remove();
  584. XmlTree.SelectedNode = null;
  585. if (XmlTree.Name == "XmlTree_STDlist")
  586. {
  587. textbox_STDEditor.Text = "";
  588. textBox_Density.Text = "";
  589. textBox_Electrical_conductivity.Text = "";
  590. textBox_Hardness.Text = "";
  591. btn_dbs.BackColor = Color.White;
  592. }
  593. if (XmlTree.Name == "XmlTree_MaxEDSRules")
  594. {
  595. textbox_STDEditor.Text = "";
  596. textBox_MaxEDSTime.Text = "";
  597. }
  598. if (XmlTree.Name == "XmlTree_ZeroElementRules")
  599. {
  600. textbox_STDEditor.Text = "";
  601. }
  602. }
  603. }
  604. }
  605. else
  606. {
  607. MessageBox.Show(table["message1"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  608. }
  609. }
  610. catch (Exception ex)
  611. {
  612. MessageBox.Show(ex.ToString(), table["message32"].ToString());
  613. }
  614. }
  615. //新建
  616. private void AddTreeNode_Click(object sender, EventArgs e)
  617. {
  618. try
  619. {
  620. if (tabControl_Rules.SelectedIndex == 0)
  621. {
  622. //保存节点当前数据
  623. if (XmlTree_STDlist.SelectedNode != null)
  624. {
  625. //判断Hardness、Density、Electrical_conductivity
  626. double dHardness = 0, dDensity = 0, dElectrical_conductivity = 0;
  627. if (!double.TryParse(textBox_Hardness.Text, out dHardness) || (double.Parse(textBox_Hardness.Text) <= 0))
  628. {
  629. textBox_Hardness.Focus();
  630. textBox_Hardness.SelectAll();
  631. MessageBox.Show(table["message2"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  632. return;
  633. }
  634. if (!double.TryParse(textBox_Density.Text, out dDensity)||double.Parse(textBox_Density.Text)<=0)
  635. {
  636. textBox_Density.Focus();
  637. textBox_Density.SelectAll();
  638. MessageBox.Show(table["message3"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  639. return;
  640. }
  641. if (!double.TryParse(textBox_Electrical_conductivity.Text, out dElectrical_conductivity)||double.Parse(textBox_Electrical_conductivity.Text)<=0)
  642. {
  643. textBox_Electrical_conductivity.Focus();
  644. textBox_Electrical_conductivity.SelectAll();
  645. MessageBox.Show(table["message4"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  646. return;
  647. }
  648. //判断textbox_STDEditor
  649. if (!Checktextbox_STDEditor())
  650. {
  651. return;
  652. }
  653. XmlTree_STDlist.SelectedNode.Tag = this.textbox_STDEditor.Text;
  654. XmlTree_STDlist.SelectedNode.Name = textBox_Hardness.Text + "_" + textBox_Density.Text + "_" + textBox_Electrical_conductivity.Text;
  655. string sKeyElements = "";
  656. for (int i = 0; i < dataGridView_KeyElements.Columns.Count; i++)
  657. {
  658. sKeyElements += dataGridView_KeyElements.Rows[0].Cells[i].Value.ToString() + ",";
  659. }
  660. if (sKeyElements.Length > 0)
  661. {
  662. sKeyElements = sKeyElements.Substring(0, sKeyElements.Length - 1);
  663. }
  664. string sSubElements = "";
  665. for (int i = 0; i < dataGridView_SubElements.Columns.Count; i++)
  666. {
  667. sSubElements += dataGridView_SubElements.Rows[0].Cells[i].Value.ToString() + ",";
  668. }
  669. if (sSubElements.Length > 0)
  670. {
  671. sSubElements = sSubElements.Substring(0, sSubElements.Length - 1);
  672. }
  673. XmlTree_STDlist.SelectedNode.Name += "$" + sKeyElements + "$" + sSubElements;
  674. }
  675. }
  676. else if (tabControl_Rules.SelectedIndex == 1)
  677. {
  678. if (XmlTree_MaxEDSRules.SelectedNode != null)
  679. {
  680. //判断MaxEDSTime
  681. double dMaxEDSTime = 0;
  682. if (!double.TryParse(textBox_MaxEDSTime.Text, out dMaxEDSTime) || double.Parse(textBox_MaxEDSTime.Text) <= 0)
  683. {
  684. MessageBox.Show(table["message8"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  685. return;
  686. }
  687. //判断textbox_STDEditor
  688. if (!Checktextbox_STDEditor())
  689. {
  690. return;
  691. }
  692. XmlTree_MaxEDSRules.SelectedNode.Tag = this.textbox_STDEditor.Text;
  693. //XmlTree_MaxEDSRules.SelectedNode.Name = textBox_MaxEDSTime.Text;
  694. }
  695. }
  696. else if (tabControl_Rules.SelectedIndex == 2)
  697. {
  698. if (XmlTree_ZeroElementRules.SelectedNode != null)
  699. {
  700. if (XmlTree_ZeroElementRules.SelectedNode.Text.Contains("="))
  701. {
  702. if (!comboBox_PeriodicTable.Items.Contains(XmlTree_ZeroElementRules.SelectedNode.Text.Split('=')[0]))
  703. {
  704. MessageBox.Show(XmlTree_ZeroElementRules.SelectedNode.Text + table["message9"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  705. return;
  706. }
  707. }
  708. else
  709. {
  710. MessageBox.Show(XmlTree_ZeroElementRules.SelectedNode.Text + table["message9"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  711. return;
  712. }
  713. //判断textbox_STDEditor
  714. if (!Checktextbox_STDEditor())
  715. {
  716. return;
  717. }
  718. XmlTree_ZeroElementRules.SelectedNode.Tag = this.textbox_STDEditor.Text;
  719. }
  720. }
  721. dataGridView_KeyElements.Rows.Clear();
  722. dataGridView_KeyElements.Columns.Clear();
  723. dataGridView_SubElements.Rows.Clear();
  724. dataGridView_SubElements.Columns.Clear();
  725. TreeNode new_child = new TreeNode();//定义一个TreeNode节点对象
  726. TreeView XmlTree = (TreeView)XmlTreeMenuStrip.SourceControl;
  727. if (XmlTreeMenuStrip.SourceControl.Name == "XmlTree_STDlist")
  728. {
  729. new_child.Name = "1_1_1$$";
  730. new_child.Text = "new strName";
  731. new_child.Tag = "NewRules";
  732. textbox_STDEditor.Text = "NewRules";
  733. textBox_Density.Text = "1";
  734. textBox_Electrical_conductivity.Text = "1";
  735. textBox_Hardness.Text = "1";
  736. new_child.BackColor = Color.White;
  737. int STDId = 1;
  738. for (int i = 0; i < XmlTree_STDlist.Nodes.Count; i++)
  739. {
  740. if (STDId < int.Parse(XmlTree_STDlist.Nodes[i].ToolTipText))
  741. {
  742. STDId = int.Parse(XmlTree_STDlist.Nodes[i].ToolTipText);
  743. }
  744. }
  745. new_child.ToolTipText = (STDId+1).ToString();
  746. }
  747. if (XmlTreeMenuStrip.SourceControl.Name == "XmlTree_MaxEDSRules")
  748. {
  749. int Number = XmlTree.Nodes.Count;
  750. for (int num = 0; num < XmlTree.Nodes.Count; num++)
  751. {
  752. string aa = XmlTree.Nodes[num].Text.ToString().Substring(XmlTree.Nodes[num].Text.Length - 1, 1);
  753. int tp = int.Parse(XmlTree.Nodes[num].Text.ToString().Substring(XmlTree.Nodes[num].Text.Length - 1, 1));
  754. if (Number < tp) Number = tp;
  755. }
  756. new_child.Text = "Rule" + Number.ToString();
  757. new_child.Tag = "NewRules";
  758. textbox_STDEditor.Text = "NewRules";
  759. }
  760. if (XmlTreeMenuStrip.SourceControl.Name == "XmlTree_ZeroElementRules")
  761. {
  762. new_child.Text = "NewElement=0";
  763. new_child.Tag = "NewRules";
  764. textbox_STDEditor.Text = "NewRules";
  765. }
  766. XmlTree.Nodes.Add(new_child);
  767. XmlTree.SelectedNode = null;
  768. XmlTree.SelectedNode = new_child;
  769. }
  770. catch (Exception ex)
  771. {
  772. MessageBox.Show(ex.ToString(), table["message32"].ToString());
  773. }
  774. }
  775. //双击节点
  776. private void XmlTree_STDlist_MouseDoubleClick(object sender, MouseEventArgs e)
  777. {
  778. if (e.Button == MouseButtons.Left)
  779. {
  780. Point ClickPoint = new Point(e.X, e.Y);
  781. TreeNode CurrentNode = XmlTree_STDlist.GetNodeAt(ClickPoint);
  782. if (CurrentNode != null)//判断你点的是不是一个节点
  783. {
  784. XmlTree_STDlist.SelectedNode = CurrentNode;//选中这个节点
  785. XmlTree_STDlist.LabelEdit = true;
  786. XmlTree_STDlist.SelectedNode.BeginEdit();
  787. }
  788. }
  789. }
  790. //保存xmltree内容到xml文件
  791. void SaveXmlTreeDataToXml(string Address)
  792. {
  793. XDocument xdoc = XDocument.Load(Address);
  794. IEnumerable<XElement> elements = from ele in xdoc.Descendants("XMLData") select ele;
  795. foreach (var ele in elements)
  796. {
  797. if (ele != null)
  798. {
  799. ele.RemoveAll();
  800. }
  801. }
  802. string value = "";
  803. foreach (var str in comboBox_Constants.Items)
  804. {
  805. value += str + ",";
  806. }
  807. if (value != "")
  808. {
  809. value = value.Substring(0, value.Length - 1);
  810. }
  811. XElement Constant = new XElement("Member");
  812. Constant.SetAttributeValue("RegName", "Constants");
  813. Constant.SetAttributeValue("value", value);
  814. elements.ElementAt(0).Add(Constant);
  815. XElement ZeroElement = new XElement("Collection");
  816. ZeroElement.SetAttributeValue("RegName", "ZeroElementRules");
  817. elements.ElementAt(0).Add(ZeroElement);
  818. for (int num = 0; num < XmlTree_ZeroElementRules.Nodes.Count; num++)
  819. {
  820. string UsingElementList = "";
  821. string UsingImgPropertyList = "";
  822. string UsingOtherPropertyList = "";
  823. List<string> UsingElementL = new List<string>();
  824. List<string> UsingImgPropertyL = new List<string>();
  825. List<string> UsingOtherPropertyL = new List<string>();
  826. string str_RemoveBlank = "";
  827. //forth_elem干扰or分隔符,故先行去掉
  828. if (XmlTree_ZeroElementRules.Nodes[num].Tag.ToString().Contains("forth_elem"))
  829. {
  830. str_RemoveBlank = str_RemoveBlank.Replace("forth_elem", "");
  831. UsingOtherPropertyL.Add("forth_elem");
  832. }
  833. str_RemoveBlank = XmlTree_ZeroElementRules.Nodes[num].Tag.ToString().Replace(" ", "");
  834. string[] str_Removeand = System.Text.RegularExpressions.Regex.Split(str_RemoveBlank, "and", System.Text.RegularExpressions.RegexOptions.None);
  835. List<string> str_Removeandor = new List<string>();
  836. for (int i = 0; i < str_Removeand.Length; i++)
  837. {
  838. str_Removeandor.AddRange(System.Text.RegularExpressions.Regex.Split(str_Removeand[i], "or", System.Text.RegularExpressions.RegexOptions.None));
  839. }
  840. List<string> list_all = new List<string>();
  841. for (int i = 0; i < str_Removeandor.Count; i++)
  842. {
  843. list_all.AddRange(str_Removeandor[i].Split(new char[] { '+', '-', '*', '/', '=', '>', '<', '(', ')' }));
  844. }
  845. for (int i = 0; i < list_all.Count; i++)
  846. {
  847. //周期元素?
  848. if (this.comboBox_PeriodicTable.Items.Contains(list_all[i]))
  849. {
  850. if (!UsingElementL.Contains(list_all[i]))
  851. {
  852. UsingElementL.Add(list_all[i]);
  853. }
  854. }
  855. //first_elem?
  856. if (this.comboBox_Elem1.Items.Contains(list_all[i]))
  857. {
  858. if (!UsingOtherPropertyL.Contains(list_all[i]))
  859. {
  860. UsingOtherPropertyL.Add(list_all[i]);
  861. }
  862. }
  863. //Element1?
  864. if (this.comboBox_Elem.Items.Contains(list_all[i]))
  865. {
  866. if (!UsingOtherPropertyL.Contains(list_all[i]))
  867. {
  868. UsingOtherPropertyL.Add(list_all[i]);
  869. }
  870. }
  871. //其它元素?
  872. if (this.comboBox_ImgProperty.Items.Contains(list_all[i]))
  873. {
  874. if (!UsingImgPropertyL.Contains(list_all[i]))
  875. {
  876. UsingImgPropertyL.Add(list_all[i]);
  877. }
  878. }
  879. }
  880. if (UsingElementL.Count > 0)
  881. {
  882. for (int i = 0; i < UsingElementL.Count - 1; i++)
  883. {
  884. UsingElementList += UsingElementL[i] + ",";
  885. }
  886. UsingElementList += UsingElementL[UsingElementL.Count - 1];
  887. }
  888. if (UsingImgPropertyL.Count > 0)
  889. {
  890. for (int i = 0; i < UsingImgPropertyL.Count - 1; i++)
  891. {
  892. UsingImgPropertyList += UsingImgPropertyL[i] + ",";
  893. }
  894. UsingImgPropertyList += UsingImgPropertyL[UsingImgPropertyL.Count - 1];
  895. }
  896. if (UsingOtherPropertyL.Count > 0)
  897. {
  898. for (int i = 0; i < UsingOtherPropertyL.Count - 1; i++)
  899. {
  900. UsingOtherPropertyList += UsingOtherPropertyL[i] + ",";
  901. }
  902. UsingOtherPropertyList += UsingOtherPropertyL[UsingOtherPropertyL.Count - 1];
  903. }
  904. XElement EleName = new XElement("Member");
  905. EleName.SetAttributeValue("ZeroElement", XmlTree_ZeroElementRules.Nodes[num].Text.Split('=')[0]);
  906. EleName.SetAttributeValue("UsingElementList", UsingElementList);
  907. EleName.SetAttributeValue("UsingImgPropertyList", UsingImgPropertyList);
  908. EleName.SetAttributeValue("UsingOtherPropertyList", UsingOtherPropertyList);
  909. EleName.SetAttributeValue("Expression", XmlTree_ZeroElementRules.Nodes[num].Tag);
  910. ZeroElement.Add(EleName);
  911. }
  912. XElement MaxEDS = new XElement("Collection");
  913. MaxEDS.SetAttributeValue("RegName", "MaxEDSRules");
  914. elements.ElementAt(0).Add(MaxEDS);
  915. for (int num = 0; num < XmlTree_MaxEDSRules.Nodes.Count; num++)
  916. {
  917. string UsingElementList = "";
  918. string UsingImgPropertyList = "";
  919. string UsingOtherPropertyList = "";
  920. List<string> UsingElementL = new List<string>();
  921. List<string> UsingImgPropertyL = new List<string>();
  922. List<string> UsingOtherPropertyL = new List<string>();
  923. string str_RemoveBlank = "";
  924. //forth_elem干扰or分隔符,故先行去掉
  925. if (XmlTree_MaxEDSRules.Nodes[num].Tag.ToString().Contains("forth_elem"))
  926. {
  927. str_RemoveBlank = str_RemoveBlank.Replace("forth_elem", "");
  928. UsingOtherPropertyList = "forth_elem,";
  929. }
  930. str_RemoveBlank = XmlTree_MaxEDSRules.Nodes[num].Tag.ToString().Replace(" ", "");
  931. string[] str_Removeand = System.Text.RegularExpressions.Regex.Split(str_RemoveBlank, "and", System.Text.RegularExpressions.RegexOptions.None);
  932. List<string> str_Removeandor = new List<string>();
  933. for (int i = 0; i < str_Removeand.Length; i++)
  934. {
  935. str_Removeandor.AddRange(System.Text.RegularExpressions.Regex.Split(str_Removeand[i], "or", System.Text.RegularExpressions.RegexOptions.None));
  936. }
  937. List<string> list_all = new List<string>();
  938. for (int i = 0; i < str_Removeandor.Count; i++)
  939. {
  940. list_all.AddRange(str_Removeandor[i].Split(new char[] { '+', '-', '*', '/', '=', '>', '<', '(', ')' }));
  941. }
  942. for (int i = 0; i < list_all.Count; i++)
  943. {
  944. //周期元素?
  945. if (this.comboBox_PeriodicTable.Items.Contains(list_all[i]))
  946. {
  947. if (!UsingElementL.Contains(list_all[i]))
  948. {
  949. UsingElementL.Add(list_all[i]);
  950. }
  951. }
  952. //first_elem?
  953. if (this.comboBox_Elem1.Items.Contains(list_all[i]))
  954. {
  955. if (!UsingOtherPropertyL.Contains(list_all[i]))
  956. {
  957. UsingOtherPropertyL.Add(list_all[i]);
  958. }
  959. }
  960. //Element1?
  961. if (this.comboBox_Elem.Items.Contains(list_all[i]))
  962. {
  963. if (!UsingOtherPropertyL.Contains(list_all[i]))
  964. {
  965. UsingOtherPropertyL.Add(list_all[i]);
  966. }
  967. }
  968. //其它元素?
  969. if (this.comboBox_ImgProperty.Items.Contains(list_all[i]))
  970. {
  971. if (!UsingImgPropertyL.Contains(list_all[i]))
  972. {
  973. UsingImgPropertyL.Add(list_all[i]);
  974. }
  975. }
  976. }
  977. if (UsingElementL.Count > 0)
  978. {
  979. for (int i = 0; i < UsingElementL.Count - 1; i++)
  980. {
  981. UsingElementList += UsingElementL[i] + ",";
  982. }
  983. UsingElementList += UsingElementL[UsingElementL.Count - 1];
  984. }
  985. if (UsingImgPropertyL.Count > 0)
  986. {
  987. for (int i = 0; i < UsingImgPropertyL.Count - 1; i++)
  988. {
  989. UsingImgPropertyList += UsingImgPropertyL[i] + ",";
  990. }
  991. UsingImgPropertyList += UsingImgPropertyL[UsingImgPropertyL.Count - 1];
  992. }
  993. if (UsingOtherPropertyL.Count > 0)
  994. {
  995. for (int i = 0; i < UsingOtherPropertyL.Count - 1; i++)
  996. {
  997. UsingOtherPropertyList += UsingOtherPropertyL[i] + ",";
  998. }
  999. UsingOtherPropertyList += UsingOtherPropertyL[UsingOtherPropertyL.Count - 1];
  1000. }
  1001. XElement EleName = new XElement("Member");
  1002. //EleName.SetAttributeValue("MaxEDSTime", XmlTree_MaxEDSRules.Nodes[num].Name);
  1003. EleName.SetAttributeValue("MaxEDSTime",textBox_MaxEDSTime.Text);
  1004. EleName.SetAttributeValue("UsingElementList", UsingElementList);
  1005. EleName.SetAttributeValue("UsingImgPropertyList", UsingImgPropertyList);
  1006. EleName.SetAttributeValue("UsingOtherPropertyList", UsingOtherPropertyList);
  1007. EleName.SetAttributeValue("Expression", XmlTree_MaxEDSRules.Nodes[num].Tag);
  1008. MaxEDS.Add(EleName);
  1009. }
  1010. XElement STD = new XElement("Collection");
  1011. STD.SetAttributeValue("RegName", "STDList");
  1012. elements.ElementAt(0).Add(STD);
  1013. for (int num = 0; num < XmlTree_STDlist.Nodes.Count; num++)
  1014. {
  1015. string UsingElementList = "";
  1016. string UsingImgPropertyList = "";
  1017. string UsingOtherPropertyList = "";
  1018. List<string> UsingElementL = new List<string>();
  1019. List<string> UsingImgPropertyL = new List<string>();
  1020. List<string> UsingOtherPropertyL = new List<string>();
  1021. string str_RemoveBlank = "";
  1022. //forth_elem干扰or分隔符,故先行去掉
  1023. if (XmlTree_STDlist.Nodes[num].Tag.ToString().Contains("forth_elem"))
  1024. {
  1025. str_RemoveBlank = str_RemoveBlank.Replace("forth_elem", "");
  1026. UsingOtherPropertyList = "forth_elem,";
  1027. }
  1028. str_RemoveBlank = XmlTree_STDlist.Nodes[num].Tag.ToString().Replace(" ", "");
  1029. string[] str_Removeand = System.Text.RegularExpressions.Regex.Split(str_RemoveBlank, "and", System.Text.RegularExpressions.RegexOptions.None);
  1030. List<string> str_Removeandor = new List<string>();
  1031. for (int i = 0; i < str_Removeand.Length; i++)
  1032. {
  1033. str_Removeandor.AddRange(System.Text.RegularExpressions.Regex.Split(str_Removeand[i], "or", System.Text.RegularExpressions.RegexOptions.None));
  1034. }
  1035. List<string> list_all = new List<string>();
  1036. for (int i = 0; i < str_Removeandor.Count; i++)
  1037. {
  1038. list_all.AddRange(str_Removeandor[i].Split(new char[] { '+', '-', '*', '/', '=', '>', '<', '(', ')' }));
  1039. }
  1040. for (int i = 0; i < list_all.Count; i++)
  1041. {
  1042. //周期元素?
  1043. if (this.comboBox_PeriodicTable.Items.Contains(list_all[i]))
  1044. {
  1045. if (!UsingElementL.Contains(list_all[i]))
  1046. {
  1047. UsingElementL.Add(list_all[i]);
  1048. }
  1049. }
  1050. //first_elem?
  1051. if (this.comboBox_Elem1.Items.Contains(list_all[i]))
  1052. {
  1053. if (!UsingOtherPropertyL.Contains(list_all[i]))
  1054. {
  1055. UsingOtherPropertyL.Add(list_all[i]);
  1056. }
  1057. }
  1058. //Element1?
  1059. if (this.comboBox_Elem.Items.Contains(list_all[i]))
  1060. {
  1061. if (!UsingOtherPropertyL.Contains(list_all[i]))
  1062. {
  1063. UsingOtherPropertyL.Add(list_all[i]);
  1064. }
  1065. }
  1066. //其它元素?
  1067. if (this.comboBox_ImgProperty.Items.Contains(list_all[i]))
  1068. {
  1069. if (!UsingImgPropertyL.Contains(list_all[i]))
  1070. {
  1071. UsingImgPropertyL.Add(list_all[i]);
  1072. }
  1073. }
  1074. }
  1075. if (UsingElementL.Count > 0)
  1076. {
  1077. for (int i = 0; i < UsingElementL.Count - 1; i++)
  1078. {
  1079. UsingElementList += UsingElementL[i] + ",";
  1080. }
  1081. UsingElementList += UsingElementL[UsingElementL.Count - 1];
  1082. }
  1083. if (UsingImgPropertyL.Count > 0)
  1084. {
  1085. for (int i = 0; i < UsingImgPropertyL.Count - 1; i++)
  1086. {
  1087. UsingImgPropertyList += UsingImgPropertyL[i] + ",";
  1088. }
  1089. UsingImgPropertyList += UsingImgPropertyL[UsingImgPropertyL.Count - 1];
  1090. }
  1091. if (UsingOtherPropertyL.Count > 0)
  1092. {
  1093. for (int i = 0; i < UsingOtherPropertyL.Count - 1; i++)
  1094. {
  1095. UsingOtherPropertyList += UsingOtherPropertyL[i] + ",";
  1096. }
  1097. UsingOtherPropertyList += UsingOtherPropertyL[UsingOtherPropertyL.Count - 1];
  1098. }
  1099. string[] str = XmlTree_STDlist.Nodes[num].Name.Split('$');
  1100. string[] strOther = str[0].Split('_');
  1101. XElement EleName = new XElement("Member");
  1102. EleName.SetAttributeValue("STDId", XmlTree_STDlist.Nodes[num].ToolTipText);
  1103. EleName.SetAttributeValue("StrName", XmlTree_STDlist.Nodes[num].Text);
  1104. EleName.SetAttributeValue("Color", colorRGBtoHx16(XmlTree_STDlist.Nodes[num].BackColor.R, XmlTree_STDlist.Nodes[num].BackColor.G, XmlTree_STDlist.Nodes[num].BackColor.B));
  1105. //EleName.SetAttributeValue("UsingElementList", UsingElementList);
  1106. EleName.SetAttributeValue("KeyElementList", str[1]);
  1107. EleName.SetAttributeValue("SubElementList", str[2]);
  1108. EleName.SetAttributeValue("UsingImgPropertyList", UsingImgPropertyList);
  1109. EleName.SetAttributeValue("UsingOtherPropertyList", UsingOtherPropertyList);
  1110. EleName.SetAttributeValue("Expression", XmlTree_STDlist.Nodes[num].Tag);
  1111. EleName.SetAttributeValue("Hardness", strOther[0]);
  1112. EleName.SetAttributeValue("Density", strOther[1]);
  1113. EleName.SetAttributeValue("Electrical_conductivity", strOther[2]);
  1114. STD.Add(EleName);
  1115. }
  1116. xdoc.Save(Address);
  1117. }
  1118. //元素周期表开关
  1119. private void PeriodicTableSwitch_Click(object sender, EventArgs e)
  1120. {
  1121. if (PeriodicTableSwitch.BackColor == SystemColors.Control)
  1122. {
  1123. panel_OTSPeriodicTable.Visible = true;
  1124. this.Width = this.Width + panel_OTSPeriodicTable.Width + 5;
  1125. PeriodicTableSwitch.BackColor = SystemColors.ControlDark;
  1126. //if (Language == "English")
  1127. //{
  1128. // PeriodicTableSwitch.Text = "Close PeriodicTable";
  1129. //}
  1130. //else if(Language == "Chinese")
  1131. //{
  1132. // PeriodicTableSwitch.Text = "关闭元素周期表";
  1133. //}
  1134. }
  1135. else if (PeriodicTableSwitch.BackColor == SystemColors.ControlDark)
  1136. {
  1137. panel_OTSPeriodicTable.Visible = false;
  1138. this.Width = this.Width - panel_OTSPeriodicTable.Width - 5;
  1139. PeriodicTableSwitch.BackColor = SystemColors.Control;
  1140. //if (Language == "English")
  1141. //{
  1142. // PeriodicTableSwitch.Text = "Open PeriodicTable";
  1143. //}
  1144. //else if (Language == "Chinese")
  1145. //{
  1146. // PeriodicTableSwitch.Text = "打开元素周期表";
  1147. //}
  1148. //textbox_STDEditor.Focus();
  1149. groupBox_XmlTree_MaxEDSRules.Focus();
  1150. }
  1151. }
  1152. private void button_Ok_Click(object sender, EventArgs e)
  1153. {
  1154. if (tabControl_Rules.SelectedIndex == 0)
  1155. {
  1156. //保存节点当前数据
  1157. if (XmlTree_STDlist.SelectedNode != null)
  1158. {
  1159. //判断Hardness、Density、Electrical_conductivity
  1160. double dHardness = 0, dDensity = 0, dElectrical_conductivity = 0;
  1161. if (!double.TryParse(textBox_Hardness.Text, out dHardness) || (double.Parse(textBox_Hardness.Text) <= 0))
  1162. {
  1163. textBox_Hardness.Focus();
  1164. textBox_Hardness.SelectAll();
  1165. MessageBox.Show(table["message10"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  1166. return;
  1167. }
  1168. if (!double.TryParse(textBox_Density.Text, out dDensity) || double.Parse(textBox_Density.Text) <= 0)
  1169. {
  1170. textBox_Density.Focus();
  1171. textBox_Density.SelectAll();
  1172. MessageBox.Show(table["message11"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  1173. return;
  1174. }
  1175. if (!double.TryParse(textBox_Electrical_conductivity.Text, out dElectrical_conductivity) || double.Parse(textBox_Electrical_conductivity.Text) <= 0)
  1176. {
  1177. textBox_Electrical_conductivity.Focus();
  1178. textBox_Electrical_conductivity.SelectAll();
  1179. MessageBox.Show(table["message12"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  1180. return;
  1181. }
  1182. //判断textbox_STDEditor
  1183. if (!Checktextbox_STDEditor())
  1184. {
  1185. return;
  1186. }
  1187. XmlTree_STDlist.SelectedNode.Tag = this.textbox_STDEditor.Text;
  1188. XmlTree_STDlist.SelectedNode.Name = textBox_Hardness.Text + "_" + textBox_Density.Text + "_" + textBox_Electrical_conductivity.Text;
  1189. string sKeyElements = "";
  1190. for (int i = 0; i < dataGridView_KeyElements.Columns.Count; i++)
  1191. {
  1192. sKeyElements += dataGridView_KeyElements.Rows[0].Cells[i].Value.ToString() + ",";
  1193. }
  1194. if (sKeyElements.Length > 0)
  1195. {
  1196. sKeyElements = sKeyElements.Substring(0, sKeyElements.Length - 1);
  1197. }
  1198. string sSubElements = "";
  1199. for (int i = 0; i < dataGridView_SubElements.Columns.Count; i++)
  1200. {
  1201. sSubElements += dataGridView_SubElements.Rows[0].Cells[i].Value.ToString() + ",";
  1202. }
  1203. if (sSubElements.Length > 0)
  1204. {
  1205. sSubElements = sSubElements.Substring(0, sSubElements.Length - 1);
  1206. }
  1207. XmlTree_STDlist.SelectedNode.Name += "$" + sKeyElements + "$" + sSubElements;
  1208. }
  1209. }
  1210. else if (tabControl_Rules.SelectedIndex == 1)
  1211. {
  1212. if (XmlTree_MaxEDSRules.SelectedNode != null)
  1213. {
  1214. //判断MaxEDSTime
  1215. double dMaxEDSTime = 0;
  1216. if (!double.TryParse(textBox_MaxEDSTime.Text, out dMaxEDSTime) || double.Parse(textBox_MaxEDSTime.Text) <= 0)
  1217. {
  1218. textBox_MaxEDSTime.Focus();
  1219. textBox_MaxEDSTime.SelectAll();
  1220. MessageBox.Show(table["message16"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  1221. return;
  1222. }
  1223. //判断textbox_STDEditor
  1224. if (!Checktextbox_STDEditor())
  1225. {
  1226. return;
  1227. }
  1228. XmlTree_MaxEDSRules.SelectedNode.Tag = this.textbox_STDEditor.Text;
  1229. //XmlTree_MaxEDSRules.SelectedNode.Name = textBox_MaxEDSTime.Text;
  1230. }
  1231. }
  1232. else if (tabControl_Rules.SelectedIndex == 2)
  1233. {
  1234. if (XmlTree_ZeroElementRules.SelectedNode != null)
  1235. {
  1236. if (XmlTree_ZeroElementRules.SelectedNode.Text.Contains("="))
  1237. {
  1238. if (!comboBox_PeriodicTable.Items.Contains(XmlTree_ZeroElementRules.SelectedNode.Text.Split('=')[0]))
  1239. {
  1240. MessageBox.Show(XmlTree_ZeroElementRules.SelectedNode.Text + table["message9"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  1241. return;
  1242. }
  1243. }
  1244. else
  1245. {
  1246. MessageBox.Show(XmlTree_ZeroElementRules.SelectedNode.Text + table["message9"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  1247. return;
  1248. }
  1249. //判断textbox_STDEditor
  1250. if (!Checktextbox_STDEditor())
  1251. {
  1252. return;
  1253. }
  1254. XmlTree_ZeroElementRules.SelectedNode.Tag = this.textbox_STDEditor.Text;
  1255. }
  1256. }
  1257. string value = "";
  1258. foreach (var str in comboBox_Constants.Items)
  1259. {
  1260. value += str + ",";
  1261. }
  1262. if (value != "")
  1263. {
  1264. value = value.Substring(0, value.Length - 1);
  1265. }
  1266. //string Address = Application.StartupPath + "\\Config\\SysData\\OTSParticleSTD.xml";
  1267. //string Address = ".\\Config\\SysData\\OTSParticleSTD.xml";
  1268. SaveXmlTreeDataToXml(Address);
  1269. this.Close();
  1270. }
  1271. private void button_Cancel_Click(object sender, EventArgs e)
  1272. {
  1273. this.Close();
  1274. }
  1275. //元素下拉选择输入
  1276. private void comboBox_PeriodicTable_SelectedIndexChanged(object sender, EventArgs e)
  1277. {
  1278. if (comboBox_PeriodicTable.Text != null && comboBox_PeriodicTable.SelectedItem != null)
  1279. {
  1280. //comboBox_PeriodicTable.Text = null;
  1281. //this.textbox_STDEditor.Text += comboBox_PeriodicTable.SelectedItem.ToString();
  1282. //textbox_STDEditor.Focus();
  1283. //textbox_STDEditor.SelectionStart = textbox_STDEditor.Text.Length;
  1284. //textbox_STDEditor.ScrollToCaret();
  1285. string newStr = comboBox_PeriodicTable.SelectedItem.ToString();
  1286. comboBox_PeriodicTable.Text = null;
  1287. int index = textbox_STDEditor.SelectionStart;
  1288. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, newStr);
  1289. textbox_STDEditor.Focus();
  1290. textbox_STDEditor.Select(index + newStr.Length, 0);
  1291. textbox_STDEditor.ScrollToCaret();
  1292. }
  1293. }
  1294. //元素自身text按回车键输入
  1295. private void comboBox_PeriodicTable_KeyDown(object sender, KeyEventArgs e)
  1296. {
  1297. if (e.KeyValue == 13)
  1298. {
  1299. if (comboBox_PeriodicTable.Text != null && comboBox_PeriodicTable.Text != "")
  1300. {
  1301. this.textbox_STDEditor.Text += comboBox_PeriodicTable.Text.ToString();
  1302. comboBox_PeriodicTable.Text = null;
  1303. }
  1304. }
  1305. }
  1306. //表达式规则检查
  1307. private bool Checktextbox_STDEditor()
  1308. {
  1309. if (textbox_STDEditor.Text == "" || textbox_STDEditor.Text == null)
  1310. {
  1311. textBox_MaxEDSTime.Focus();
  1312. MessageBox.Show(table["message17"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  1313. return false;
  1314. }
  1315. string str_RemoveBlank = textbox_STDEditor.Text.ToString().Replace(" ", "");
  1316. str_RemoveBlank = str_RemoveBlank.Replace("\r\n", "");
  1317. //分割符号检验
  1318. string[] Symbol = { "and", "or", "+", "-", "*", "/", "=", ">", "<" };
  1319. for (int i = 0; i < Symbol.Length; i++)
  1320. {
  1321. for (int j = 0; j < Symbol.Length; j++)
  1322. {
  1323. if ((Symbol[i] + Symbol[j]) != ">=" && (Symbol[i] + Symbol[j]) != "<=")
  1324. {
  1325. if (str_RemoveBlank.Contains(Symbol[i] + Symbol[j]))
  1326. {
  1327. MessageBox.Show(table["message18"].ToString() + Symbol[i] + Symbol[j], table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  1328. return false;
  1329. }
  1330. }
  1331. }
  1332. if (str_RemoveBlank.Contains(Symbol[i] + ")") || str_RemoveBlank.Contains("(" + Symbol[i]))
  1333. {
  1334. MessageBox.Show(table["message18"].ToString() + Symbol[i] + ")", table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  1335. return false;
  1336. }
  1337. if (str_RemoveBlank.Contains("(" + Symbol[i]))
  1338. {
  1339. MessageBox.Show(table["message18"].ToString() + "(" + Symbol[i], table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  1340. return false;
  1341. }
  1342. }
  1343. if ((str_RemoveBlank != null) && (str_RemoveBlank != ""))
  1344. {
  1345. //左右括号匹配检验
  1346. int BracketsNum = 0;
  1347. for (int i = 0; i < str_RemoveBlank.Length; i++)
  1348. {
  1349. if (str_RemoveBlank[i] == '(') BracketsNum++;
  1350. if (str_RemoveBlank[i] == ')') BracketsNum--;
  1351. }
  1352. if (BracketsNum != 0)
  1353. {
  1354. MessageBox.Show(table["message19"].ToString(),table["message32"].ToString(),MessageBoxButtons.OK,MessageBoxIcon.Information);
  1355. return false;
  1356. }
  1357. //首字符检测
  1358. 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] == '('))
  1359. {
  1360. MessageBox.Show(table["message20"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  1361. return false;
  1362. }
  1363. if (str_RemoveBlank.Length >= 3)
  1364. {
  1365. if ((str_RemoveBlank.Substring(0, 3) == "and") || (str_RemoveBlank.Substring(0, 3) == "end"))
  1366. {
  1367. MessageBox.Show(table["message20"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  1368. return false;
  1369. }
  1370. }
  1371. }
  1372. //forth_elem干扰or分隔符,故先行去掉
  1373. str_RemoveBlank = str_RemoveBlank.Replace("forth_elem", "");
  1374. string[] str_Removeand = System.Text.RegularExpressions.Regex.Split(str_RemoveBlank, "and", System.Text.RegularExpressions.RegexOptions.None);
  1375. List<string> str_Removeandor = new List<string>();
  1376. for (int i = 0; i < str_Removeand.Length; i++)
  1377. {
  1378. str_Removeandor.AddRange(System.Text.RegularExpressions.Regex.Split(str_Removeand[i], "or", System.Text.RegularExpressions.RegexOptions.None));
  1379. }
  1380. List<string> list_all = new List<string>();
  1381. for (int i = 0; i < str_Removeandor.Count; i++)
  1382. {
  1383. list_all.AddRange(str_Removeandor[i].Split(new char[] { '+', '-', '*', '/', '=', '>', '<', '(', ')' }));
  1384. }
  1385. //常量
  1386. List<string> Constantslist = new List<string>();
  1387. for (int j = 0; j < comboBox_Constants.Items.Count; j++)
  1388. {
  1389. Constantslist.Add(comboBox_Constants.Items[j].ToString().Split('=')[0]);
  1390. }
  1391. for (int i = 0; i < list_all.Count; i++)
  1392. {
  1393. //周期元素?
  1394. if (this.comboBox_PeriodicTable.Items.Contains(list_all[i]))
  1395. {
  1396. continue;
  1397. }
  1398. //first_elem?
  1399. if (this.comboBox_Elem1.Items.Contains(list_all[i]))
  1400. {
  1401. continue;
  1402. }
  1403. //Element1?
  1404. if (this.comboBox_Elem.Items.Contains(list_all[i]))
  1405. {
  1406. continue;
  1407. }
  1408. //其它元素?
  1409. if (this.comboBox_ImgProperty.Items.Contains(list_all[i]))
  1410. {
  1411. continue;
  1412. }
  1413. //常量?
  1414. if (Constantslist.Contains(list_all[i]))
  1415. {
  1416. continue;
  1417. }
  1418. //数字?
  1419. double DNum = 0;
  1420. if (double.TryParse(list_all[i], out DNum))
  1421. {
  1422. continue;
  1423. }
  1424. //>=? <=?等其它情况
  1425. if (list_all[i] == "")
  1426. {
  1427. continue;
  1428. }
  1429. //true false?
  1430. if ((list_all[i] == "true") || (list_all[i] == "false"))
  1431. {
  1432. continue;
  1433. }
  1434. MessageBox.Show(table["message21"].ToString() + list_all[i], table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  1435. return false;
  1436. }
  1437. //检测是否有<>= true,false
  1438. 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")
  1439. {
  1440. MessageBox.Show(table["message22"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  1441. return false;
  1442. }
  1443. return true;
  1444. }
  1445. private void btn_dbs_Click(object sender, EventArgs e)
  1446. {
  1447. ColorDialog cd = new ColorDialog();
  1448. cd.FullOpen = true;//自定义颜色界面打开
  1449. DialogResult result = cd.ShowDialog();
  1450. if (result == DialogResult.OK)
  1451. {
  1452. btn_dbs.BackColor = cd.Color;
  1453. if (XmlTree_STDlist.SelectedNode != null)
  1454. {
  1455. XmlTree_STDlist.SelectedNode.BackColor = cd.Color;
  1456. }
  1457. }
  1458. if (XmlTree_STDlist.SelectedNode != null)
  1459. {
  1460. //如果不是白色了,就把文字去掉吧,显得好看
  1461. if (btn_dbs.BackColor != Color.White)
  1462. {
  1463. btn_dbs.Text = "";
  1464. }
  1465. }
  1466. }
  1467. private void button_And_Click(object sender, EventArgs e)
  1468. {
  1469. //textbox_STDEditor 中的光标
  1470. int index = textbox_STDEditor.SelectionStart;
  1471. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "and");
  1472. textbox_STDEditor.Focus();
  1473. textbox_STDEditor.Select(index + 3, 0);
  1474. textbox_STDEditor.ScrollToCaret();
  1475. }
  1476. private void button_Or_Click(object sender, EventArgs e)
  1477. {
  1478. //textbox_STDEditor 中的光标
  1479. int index = textbox_STDEditor.SelectionStart;
  1480. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "or");
  1481. textbox_STDEditor.Focus();
  1482. textbox_STDEditor.Select(index + 2, 0);
  1483. textbox_STDEditor.ScrollToCaret();
  1484. }
  1485. private void comboBox_Constants_SelectedIndexChanged(object sender, EventArgs e)
  1486. {
  1487. //if (Flag_comboBox_Constants)
  1488. //{
  1489. if (comboBox_Constants.SelectedItem != null)
  1490. {
  1491. //this.textbox_STDEditor.Text += comboBox_Constants.SelectedItem.ToString().Split('=')[0];
  1492. ////comboBox_Constants.Text = null;
  1493. //textbox_STDEditor.Focus();
  1494. //textbox_STDEditor.SelectionStart = textbox_STDEditor.Text.Length;
  1495. //textbox_STDEditor.ScrollToCaret();
  1496. string newStr = comboBox_Constants.SelectedItem.ToString().Split('=')[0];
  1497. int index = textbox_STDEditor.SelectionStart;
  1498. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, newStr);
  1499. textbox_STDEditor.Focus();
  1500. textbox_STDEditor.Select(index + newStr.Length, 0);
  1501. textbox_STDEditor.ScrollToCaret();
  1502. }
  1503. //}
  1504. //Flag_comboBox_Constants = true;
  1505. }
  1506. bool Flag_SelStatus = true; //XML切换成功失败状态
  1507. private void button_UpOrder_Click(object sender, EventArgs e)
  1508. {
  1509. if (XmlTree_STDlist.SelectedNode.PrevNode != null)
  1510. {
  1511. //object tag = XmlTree_STDlist.SelectedNode.PrevNode.Tag;
  1512. //string name = XmlTree_STDlist.SelectedNode.PrevNode.Name;
  1513. //string text = XmlTree_STDlist.SelectedNode.PrevNode.Text;
  1514. //Color backcolor=XmlTree_STDlist.SelectedNode.PrevNode.BackColor;
  1515. //string STDId = XmlTree_STDlist.SelectedNode.PrevNode.ToolTipText;
  1516. //XmlTree_STDlist.SelectedNode.PrevNode.Tag = XmlTree_STDlist.SelectedNode.Tag;
  1517. //XmlTree_STDlist.SelectedNode.PrevNode.BackColor = XmlTree_STDlist.SelectedNode.BackColor;
  1518. //XmlTree_STDlist.SelectedNode.PrevNode.Name = XmlTree_STDlist.SelectedNode.Name;
  1519. //XmlTree_STDlist.SelectedNode.PrevNode.Text = XmlTree_STDlist.SelectedNode.Text;
  1520. //XmlTree_STDlist.SelectedNode.PrevNode.ToolTipText = XmlTree_STDlist.SelectedNode.ToolTipText;
  1521. //XmlTree_STDlist.SelectedNode.Tag = tag;
  1522. //XmlTree_STDlist.SelectedNode.BackColor = backcolor;
  1523. //XmlTree_STDlist.SelectedNode.Name = name;
  1524. //XmlTree_STDlist.SelectedNode.Text = text;
  1525. //XmlTree_STDlist.SelectedNode.ToolTipText = STDId;
  1526. //this.textbox_STDEditor.Text = XmlTree_STDlist.SelectedNode.Tag.ToString();
  1527. //btn_dbs.BackColor = XmlTree_STDlist.SelectedNode.BackColor;
  1528. //string[] strOther = XmlTree_STDlist.SelectedNode.Name.Split('$');
  1529. //string[] strOther2 = strOther[0].Split('_');
  1530. //textBox_Hardness.Text = strOther2[0];
  1531. //textBox_Density.Text = strOther2[1];
  1532. //textBox_Electrical_conductivity.Text = strOther2[2];
  1533. //dataGridView_KeyElements.Rows.Clear();
  1534. //dataGridView_KeyElements.Columns.Clear();
  1535. //string[] KeyElement = strOther[1].Split(',');
  1536. //for (int i = 0; i < KeyElement.Length; i++)
  1537. //{
  1538. // if (KeyElement[0] != "")
  1539. // {
  1540. // DataGridViewButtonColumn dataGridViewButtonColumn = new DataGridViewButtonColumn();
  1541. // dataGridViewButtonColumn.Name = dataGridView_SubElements.Columns.Count.ToString();
  1542. // dataGridView_KeyElements.Columns.Add(dataGridViewButtonColumn);
  1543. // if (dataGridView_KeyElements.Rows.Count == 0)
  1544. // {
  1545. // DataGridViewRow row = new DataGridViewRow();
  1546. // dataGridView_KeyElements.Rows.Add(row);
  1547. // }
  1548. // dataGridView_KeyElements.Rows[0].Cells[i].Value = KeyElement[i];
  1549. // }
  1550. //}
  1551. //dataGridView_SubElements.Rows.Clear();
  1552. //dataGridView_SubElements.Columns.Clear();
  1553. //string[] SubElement = strOther[2].Split(',');
  1554. //for (int i = 0; i < SubElement.Length; i++)
  1555. //{
  1556. // if (SubElement[i] != "")
  1557. // {
  1558. // DataGridViewButtonColumn dataGridViewButtonColumn = new DataGridViewButtonColumn();
  1559. // dataGridViewButtonColumn.Name = dataGridView_SubElements.Columns.Count.ToString();
  1560. // dataGridView_SubElements.Columns.Add(dataGridViewButtonColumn);
  1561. // if (dataGridView_SubElements.Rows.Count == 0)
  1562. // {
  1563. // DataGridViewRow row = new DataGridViewRow();
  1564. // dataGridView_SubElements.Rows.Add(row);
  1565. // }
  1566. // dataGridView_SubElements.Rows[0].Cells[i].Value = SubElement[i];
  1567. // }
  1568. //}
  1569. //this.XmlTree_STDlist.Focus();
  1570. //XmlTree_STDlist.SelectedNode = XmlTree_STDlist.SelectedNode.PrevNode;
  1571. //if (XmlTree_STDlist.SelectedNode.PrevNode == null)
  1572. //{
  1573. // UpOrder.Enabled = false;
  1574. //}
  1575. }
  1576. XmlTree_STDlist.SelectedNode = XmlTree_STDlist.SelectedNode.PrevNode;
  1577. if (Flag_SelStatus)
  1578. {
  1579. object tag = XmlTree_STDlist.SelectedNode.NextNode.Tag;
  1580. string name = XmlTree_STDlist.SelectedNode.NextNode.Name;
  1581. string text = XmlTree_STDlist.SelectedNode.NextNode.Text;
  1582. Color backcolor = XmlTree_STDlist.SelectedNode.NextNode.BackColor;
  1583. string STDId = XmlTree_STDlist.SelectedNode.NextNode.ToolTipText;
  1584. XmlTree_STDlist.SelectedNode.NextNode.Tag = XmlTree_STDlist.SelectedNode.Tag;
  1585. XmlTree_STDlist.SelectedNode.NextNode.BackColor = XmlTree_STDlist.SelectedNode.BackColor;
  1586. XmlTree_STDlist.SelectedNode.NextNode.Name = XmlTree_STDlist.SelectedNode.Name;
  1587. XmlTree_STDlist.SelectedNode.NextNode.Text = XmlTree_STDlist.SelectedNode.Text;
  1588. XmlTree_STDlist.SelectedNode.NextNode.ToolTipText = XmlTree_STDlist.SelectedNode.ToolTipText;
  1589. XmlTree_STDlist.SelectedNode.Tag = tag;
  1590. XmlTree_STDlist.SelectedNode.BackColor = backcolor;
  1591. XmlTree_STDlist.SelectedNode.Name = name;
  1592. XmlTree_STDlist.SelectedNode.Text = text;
  1593. XmlTree_STDlist.SelectedNode.ToolTipText = STDId;
  1594. this.textbox_STDEditor.Text = XmlTree_STDlist.SelectedNode.Tag.ToString();
  1595. btn_dbs.BackColor = XmlTree_STDlist.SelectedNode.BackColor;
  1596. string[] strOther = XmlTree_STDlist.SelectedNode.Name.Split('$');
  1597. string[] strOther2 = strOther[0].Split('_');
  1598. textBox_Hardness.Text = strOther2[0];
  1599. textBox_Density.Text = strOther2[1];
  1600. textBox_Electrical_conductivity.Text = strOther2[2];
  1601. dataGridView_KeyElements.Rows.Clear();
  1602. dataGridView_KeyElements.Columns.Clear();
  1603. string[] KeyElement = strOther[1].Split(',');
  1604. for (int i = 0; i < KeyElement.Length; i++)
  1605. {
  1606. if (KeyElement[0] != "")
  1607. {
  1608. DataGridViewButtonColumn dataGridViewButtonColumn = new DataGridViewButtonColumn();
  1609. dataGridViewButtonColumn.Name = dataGridView_SubElements.Columns.Count.ToString();
  1610. dataGridView_KeyElements.Columns.Add(dataGridViewButtonColumn);
  1611. if (dataGridView_KeyElements.Rows.Count == 0)
  1612. {
  1613. DataGridViewRow row = new DataGridViewRow();
  1614. dataGridView_KeyElements.Rows.Add(row);
  1615. }
  1616. dataGridView_KeyElements.Rows[0].Cells[i].Value = KeyElement[i];
  1617. }
  1618. }
  1619. dataGridView_SubElements.Rows.Clear();
  1620. dataGridView_SubElements.Columns.Clear();
  1621. string[] SubElement = strOther[2].Split(',');
  1622. for (int i = 0; i < SubElement.Length; i++)
  1623. {
  1624. if (SubElement[i] != "")
  1625. {
  1626. DataGridViewButtonColumn dataGridViewButtonColumn = new DataGridViewButtonColumn();
  1627. dataGridViewButtonColumn.Name = dataGridView_SubElements.Columns.Count.ToString();
  1628. dataGridView_SubElements.Columns.Add(dataGridViewButtonColumn);
  1629. if (dataGridView_SubElements.Rows.Count == 0)
  1630. {
  1631. DataGridViewRow row = new DataGridViewRow();
  1632. dataGridView_SubElements.Rows.Add(row);
  1633. }
  1634. dataGridView_SubElements.Rows[0].Cells[i].Value = SubElement[i];
  1635. }
  1636. }
  1637. this.XmlTree_STDlist.Focus();
  1638. if (XmlTree_STDlist.SelectedNode.PrevNode == null)
  1639. {
  1640. button_UpOrder.Enabled = false;
  1641. }
  1642. dataGridView_KeyElements.ClearSelection();
  1643. dataGridView_SubElements.ClearSelection();
  1644. }
  1645. this.XmlTree_STDlist.Focus();
  1646. Flag_SelStatus = true;
  1647. }
  1648. private void button_DownOrder_Click(object sender, EventArgs e)
  1649. {
  1650. if (XmlTree_STDlist.SelectedNode.NextNode != null)
  1651. {
  1652. //object tag = XmlTree_STDlist.SelectedNode.NextNode.Tag;
  1653. //string name = XmlTree_STDlist.SelectedNode.NextNode.Name;
  1654. //string text = XmlTree_STDlist.SelectedNode.NextNode.Text;
  1655. //Color backcolor = XmlTree_STDlist.SelectedNode.NextNode.BackColor;
  1656. //string STDId = XmlTree_STDlist.SelectedNode.NextNode.ToolTipText;
  1657. //XmlTree_STDlist.SelectedNode.NextNode.Tag = XmlTree_STDlist.SelectedNode.Tag;
  1658. //XmlTree_STDlist.SelectedNode.NextNode.BackColor = XmlTree_STDlist.SelectedNode.BackColor;
  1659. //XmlTree_STDlist.SelectedNode.NextNode.Name = XmlTree_STDlist.SelectedNode.Name;
  1660. //XmlTree_STDlist.SelectedNode.NextNode.Text = XmlTree_STDlist.SelectedNode.Text;
  1661. //XmlTree_STDlist.SelectedNode.NextNode.ToolTipText = XmlTree_STDlist.SelectedNode.ToolTipText;
  1662. //XmlTree_STDlist.SelectedNode.Tag = tag;
  1663. //XmlTree_STDlist.SelectedNode.BackColor = backcolor;
  1664. //XmlTree_STDlist.SelectedNode.Name = name;
  1665. //XmlTree_STDlist.SelectedNode.Text = text;
  1666. //XmlTree_STDlist.SelectedNode.ToolTipText = STDId;
  1667. //this.textbox_STDEditor.Text = XmlTree_STDlist.SelectedNode.Tag.ToString();
  1668. //btn_dbs.BackColor = XmlTree_STDlist.SelectedNode.BackColor;
  1669. //string[] strOther = XmlTree_STDlist.SelectedNode.Name.Split('$');
  1670. //string[] strOther2 = strOther[0].Split('_');
  1671. //textBox_Hardness.Text = strOther2[0];
  1672. //textBox_Density.Text = strOther2[1];
  1673. //textBox_Electrical_conductivity.Text = strOther2[2];
  1674. //dataGridView_KeyElements.Rows.Clear();
  1675. //dataGridView_KeyElements.Columns.Clear();
  1676. //string[] KeyElement = strOther[1].Split(',');
  1677. //for (int i = 0; i < KeyElement.Length; i++)
  1678. //{
  1679. // if (KeyElement[0] != "")
  1680. // {
  1681. // DataGridViewButtonColumn dataGridViewButtonColumn = new DataGridViewButtonColumn();
  1682. // dataGridViewButtonColumn.Name = dataGridView_SubElements.Columns.Count.ToString();
  1683. // dataGridView_KeyElements.Columns.Add(dataGridViewButtonColumn);
  1684. // if (dataGridView_KeyElements.Rows.Count == 0)
  1685. // {
  1686. // DataGridViewRow row = new DataGridViewRow();
  1687. // dataGridView_KeyElements.Rows.Add(row);
  1688. // }
  1689. // dataGridView_KeyElements.Rows[0].Cells[i].Value = KeyElement[i];
  1690. // }
  1691. //}
  1692. //dataGridView_SubElements.Rows.Clear();
  1693. //dataGridView_SubElements.Columns.Clear();
  1694. //string[] SubElement = strOther[2].Split(',');
  1695. //for (int i = 0; i < SubElement.Length; i++)
  1696. //{
  1697. // if (SubElement[i] != "")
  1698. // {
  1699. // DataGridViewButtonColumn dataGridViewButtonColumn = new DataGridViewButtonColumn();
  1700. // dataGridViewButtonColumn.Name = dataGridView_SubElements.Columns.Count.ToString();
  1701. // dataGridView_SubElements.Columns.Add(dataGridViewButtonColumn);
  1702. // if (dataGridView_SubElements.Rows.Count == 0)
  1703. // {
  1704. // DataGridViewRow row = new DataGridViewRow();
  1705. // dataGridView_SubElements.Rows.Add(row);
  1706. // }
  1707. // dataGridView_SubElements.Rows[0].Cells[i].Value = SubElement[i];
  1708. // }
  1709. //}
  1710. //this.XmlTree_STDlist.Focus();
  1711. //XmlTree_STDlist.SelectedNode = XmlTree_STDlist.SelectedNode.NextNode;
  1712. //if (XmlTree_STDlist.SelectedNode.NextNode == null)
  1713. //{
  1714. // DownOrder.Enabled = false;
  1715. //}
  1716. }
  1717. XmlTree_STDlist.SelectedNode = XmlTree_STDlist.SelectedNode.NextNode;
  1718. if (Flag_SelStatus)
  1719. {
  1720. object tag = XmlTree_STDlist.SelectedNode.PrevNode.Tag;
  1721. string name = XmlTree_STDlist.SelectedNode.PrevNode.Name;
  1722. string text = XmlTree_STDlist.SelectedNode.PrevNode.Text;
  1723. Color backcolor = XmlTree_STDlist.SelectedNode.PrevNode.BackColor;
  1724. string STDId = XmlTree_STDlist.SelectedNode.PrevNode.ToolTipText;
  1725. XmlTree_STDlist.SelectedNode.PrevNode.Tag = XmlTree_STDlist.SelectedNode.Tag;
  1726. XmlTree_STDlist.SelectedNode.PrevNode.BackColor = XmlTree_STDlist.SelectedNode.BackColor;
  1727. XmlTree_STDlist.SelectedNode.PrevNode.Name = XmlTree_STDlist.SelectedNode.Name;
  1728. XmlTree_STDlist.SelectedNode.PrevNode.Text = XmlTree_STDlist.SelectedNode.Text;
  1729. XmlTree_STDlist.SelectedNode.PrevNode.ToolTipText = XmlTree_STDlist.SelectedNode.ToolTipText;
  1730. XmlTree_STDlist.SelectedNode.Tag = tag;
  1731. XmlTree_STDlist.SelectedNode.BackColor = backcolor;
  1732. XmlTree_STDlist.SelectedNode.Name = name;
  1733. XmlTree_STDlist.SelectedNode.Text = text;
  1734. XmlTree_STDlist.SelectedNode.ToolTipText = STDId;
  1735. this.textbox_STDEditor.Text = XmlTree_STDlist.SelectedNode.Tag.ToString();
  1736. btn_dbs.BackColor = XmlTree_STDlist.SelectedNode.BackColor;
  1737. string[] strOther = XmlTree_STDlist.SelectedNode.Name.Split('$');
  1738. string[] strOther2 = strOther[0].Split('_');
  1739. textBox_Hardness.Text = strOther2[0];
  1740. textBox_Density.Text = strOther2[1];
  1741. textBox_Electrical_conductivity.Text = strOther2[2];
  1742. dataGridView_KeyElements.Rows.Clear();
  1743. dataGridView_KeyElements.Columns.Clear();
  1744. string[] KeyElement = strOther[1].Split(',');
  1745. for (int i = 0; i < KeyElement.Length; i++)
  1746. {
  1747. if (KeyElement[0] != "")
  1748. {
  1749. DataGridViewButtonColumn dataGridViewButtonColumn = new DataGridViewButtonColumn();
  1750. dataGridViewButtonColumn.Name = dataGridView_SubElements.Columns.Count.ToString();
  1751. dataGridView_KeyElements.Columns.Add(dataGridViewButtonColumn);
  1752. if (dataGridView_KeyElements.Rows.Count == 0)
  1753. {
  1754. DataGridViewRow row = new DataGridViewRow();
  1755. dataGridView_KeyElements.Rows.Add(row);
  1756. }
  1757. dataGridView_KeyElements.Rows[0].Cells[i].Value = KeyElement[i];
  1758. }
  1759. }
  1760. dataGridView_SubElements.Rows.Clear();
  1761. dataGridView_SubElements.Columns.Clear();
  1762. string[] SubElement = strOther[2].Split(',');
  1763. for (int i = 0; i < SubElement.Length; i++)
  1764. {
  1765. if (SubElement[i] != "")
  1766. {
  1767. DataGridViewButtonColumn dataGridViewButtonColumn = new DataGridViewButtonColumn();
  1768. dataGridViewButtonColumn.Name = dataGridView_SubElements.Columns.Count.ToString();
  1769. dataGridView_SubElements.Columns.Add(dataGridViewButtonColumn);
  1770. if (dataGridView_SubElements.Rows.Count == 0)
  1771. {
  1772. DataGridViewRow row = new DataGridViewRow();
  1773. dataGridView_SubElements.Rows.Add(row);
  1774. }
  1775. dataGridView_SubElements.Rows[0].Cells[i].Value = SubElement[i];
  1776. }
  1777. }
  1778. this.XmlTree_STDlist.Focus();
  1779. if (XmlTree_STDlist.SelectedNode.PrevNode == null)
  1780. {
  1781. button_DownOrder.Enabled = false;
  1782. }
  1783. dataGridView_KeyElements.ClearSelection();
  1784. dataGridView_SubElements.ClearSelection();
  1785. }
  1786. this.XmlTree_STDlist.Focus();
  1787. Flag_SelStatus = true;
  1788. }
  1789. private void button_Backup_Click(object sender, EventArgs e)
  1790. {
  1791. if (tabControl_Rules.SelectedIndex == 0)
  1792. {
  1793. //保存节点当前数据
  1794. if (XmlTree_STDlist.SelectedNode != null)
  1795. {
  1796. //判断Hardness、Density、Electrical_conductivity
  1797. double dHardness = 0, dDensity = 0, dElectrical_conductivity = 0;
  1798. if (!double.TryParse(textBox_Hardness.Text, out dHardness) || (double.Parse(textBox_Hardness.Text) <= 0))
  1799. {
  1800. textBox_Hardness.Focus();
  1801. textBox_Hardness.SelectAll();
  1802. MessageBox.Show(table["message10"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  1803. return;
  1804. }
  1805. if (!double.TryParse(textBox_Density.Text, out dDensity) || double.Parse(textBox_Density.Text) <= 0)
  1806. {
  1807. textBox_Density.Focus();
  1808. textBox_Density.SelectAll();
  1809. MessageBox.Show(table["message11"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  1810. return;
  1811. }
  1812. if (!double.TryParse(textBox_Electrical_conductivity.Text, out dElectrical_conductivity) || double.Parse(textBox_Electrical_conductivity.Text) <= 0)
  1813. {
  1814. textBox_Electrical_conductivity.Focus();
  1815. textBox_Electrical_conductivity.SelectAll();
  1816. MessageBox.Show(table["message12"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  1817. return;
  1818. }
  1819. //判断textbox_STDEditor
  1820. if (!Checktextbox_STDEditor())
  1821. {
  1822. return;
  1823. }
  1824. XmlTree_STDlist.SelectedNode.Tag = this.textbox_STDEditor.Text;
  1825. XmlTree_STDlist.SelectedNode.Name = textBox_Hardness.Text + "_" + textBox_Density.Text + "_" + textBox_Electrical_conductivity.Text;
  1826. string sKeyElements = "";
  1827. for (int i = 0; i < dataGridView_KeyElements.Columns.Count; i++)
  1828. {
  1829. sKeyElements += dataGridView_KeyElements.Rows[0].Cells[i].Value.ToString() + ",";
  1830. }
  1831. if (sKeyElements.Length > 0)
  1832. {
  1833. sKeyElements = sKeyElements.Substring(0, sKeyElements.Length - 1);
  1834. }
  1835. string sSubElements = "";
  1836. for (int i = 0; i < dataGridView_SubElements.Columns.Count; i++)
  1837. {
  1838. sSubElements += dataGridView_SubElements.Rows[0].Cells[i].Value.ToString() + ",";
  1839. }
  1840. if (sSubElements.Length > 0)
  1841. {
  1842. sSubElements = sSubElements.Substring(0, sSubElements.Length - 1);
  1843. }
  1844. XmlTree_STDlist.SelectedNode.Name += "$" + sKeyElements + "$" + sSubElements;
  1845. }
  1846. }
  1847. else if (tabControl_Rules.SelectedIndex == 1)
  1848. {
  1849. if (XmlTree_MaxEDSRules.SelectedNode != null)
  1850. {
  1851. //判断MaxEDSTime
  1852. double dMaxEDSTime = 0;
  1853. if (!double.TryParse(textBox_MaxEDSTime.Text, out dMaxEDSTime) || double.Parse(textBox_MaxEDSTime.Text) <= 0)
  1854. {
  1855. textBox_MaxEDSTime.Focus();
  1856. textBox_MaxEDSTime.SelectAll();
  1857. MessageBox.Show(table["message16"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  1858. return;
  1859. }
  1860. //判断textbox_STDEditor
  1861. if (!Checktextbox_STDEditor())
  1862. {
  1863. return;
  1864. }
  1865. XmlTree_MaxEDSRules.SelectedNode.Tag = this.textbox_STDEditor.Text;
  1866. //XmlTree_MaxEDSRules.SelectedNode.Name = textBox_MaxEDSTime.Text;
  1867. }
  1868. }
  1869. else if (tabControl_Rules.SelectedIndex == 2)
  1870. {
  1871. if (XmlTree_ZeroElementRules.SelectedNode != null)
  1872. {
  1873. if (XmlTree_ZeroElementRules.SelectedNode.Text.Contains("="))
  1874. {
  1875. if (!comboBox_PeriodicTable.Items.Contains(XmlTree_ZeroElementRules.SelectedNode.Text.Split('=')[0]))
  1876. {
  1877. MessageBox.Show(XmlTree_ZeroElementRules.SelectedNode.Text + table["message9"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  1878. return;
  1879. }
  1880. }
  1881. else
  1882. {
  1883. MessageBox.Show(XmlTree_ZeroElementRules.SelectedNode.Text + table["message9"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  1884. return;
  1885. }
  1886. //判断textbox_STDEditor
  1887. if (!Checktextbox_STDEditor())
  1888. {
  1889. return;
  1890. }
  1891. XmlTree_ZeroElementRules.SelectedNode.Tag = this.textbox_STDEditor.Text;
  1892. }
  1893. }
  1894. try
  1895. {
  1896. SaveFileDialog saveFile = new SaveFileDialog();
  1897. saveFile.Title = table["message23"].ToString();
  1898. saveFile.Filter = table["message24"].ToString();
  1899. saveFile.OverwritePrompt = true; //是否覆盖当前文件
  1900. saveFile.RestoreDirectory = true; //还原上次目录
  1901. if (saveFile.ShowDialog() == DialogResult.OK)
  1902. {
  1903. //string Address = Application.StartupPath.Substring(0, Application.StartupPath.Length - 35) + "\\Opton\\OTSPartA\\OTS\\Bin\\Win32\\Debug\\Config\\SysData\\OTSParticleSTD.xml";
  1904. //string Address = ".\\Config\\SysData\\OTSParticleSTD.xml";
  1905. System.IO.File.Copy(Address, saveFile.FileName, true);
  1906. SaveXmlTreeDataToXml(saveFile.FileName);
  1907. MessageBox.Show(table["message25"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  1908. }
  1909. else
  1910. {
  1911. return;
  1912. }
  1913. }
  1914. catch (Exception ex)
  1915. {
  1916. MessageBox.Show(ex.Message);
  1917. }
  1918. //string Address_backup = Application.StartupPath.Substring(0, Application.StartupPath.Length-35) + "\\Bin\\Win32\\Debug\\Config\\SysData\\OTSParticleSTD_backup.xml";
  1919. //string Address_backup = ".\\Config\\SysData\\OTSParticleSTD_backup.xml";
  1920. //SaveXmlTreeDataToXml(Address_backup);
  1921. //MessageBox.Show("备份成功!", "提示");
  1922. }
  1923. private void button_Recover_Click(object sender, EventArgs e)
  1924. {
  1925. XmlDocument doc = new XmlDocument();
  1926. //string Address_backup = ".\\Config\\SysData\\OTSParticleSTD_backup.xml";
  1927. //string Address = ".\\Config\\SysData\\OTSParticleSTD.xml";
  1928. //string Address_backup = Application.StartupPath + "\\Config\\SysData\\\\OTSParticleSTD_backup.xml";
  1929. //string Address = Application.StartupPath + "\\Config\\SysData\\OTSParticleSTD.xml";
  1930. try
  1931. {
  1932. System.IO.File.Copy(Address_backup, Address, true);
  1933. doc.Load(Address_backup);
  1934. XmlTree_STDlist.Nodes.Clear();
  1935. XmlTree_MaxEDSRules.Nodes.Clear();
  1936. XmlTree_ZeroElementRules.Nodes.Clear();
  1937. checkBox_0.Checked = false;
  1938. checkBox_1.Checked = false;
  1939. checkBox_2.Checked = false;
  1940. checkBox_3.Checked = false;
  1941. checkBox_4.Checked = false;
  1942. checkBox_5.Checked = false;
  1943. checkBox_6.Checked = false;
  1944. checkBox_7.Checked = false;
  1945. checkBox_8.Checked = false;
  1946. checkBox_9.Checked = false;
  1947. textBox_0.ReadOnly = true;
  1948. textBox_1.ReadOnly = true;
  1949. textBox_2.ReadOnly = true;
  1950. textBox_3.ReadOnly = true;
  1951. textBox_4.ReadOnly = true;
  1952. textBox_5.ReadOnly = true;
  1953. textBox_6.ReadOnly = true;
  1954. textBox_7.ReadOnly = true;
  1955. textBox_8.ReadOnly = true;
  1956. textBox_9.ReadOnly = true;
  1957. LoadXmlToTreeControl(doc, XmlTree_STDlist.Nodes, XmlTree_MaxEDSRules.Nodes, XmlTree_ZeroElementRules.Nodes);
  1958. XmlTree_STDlist.SelectedNode = null;
  1959. XmlTree_MaxEDSRules.SelectedNode = null;
  1960. XmlTree_ZeroElementRules.SelectedNode = null;
  1961. textbox_STDEditor.Text = "";
  1962. textBox_Density.Text = "";
  1963. textBox_Electrical_conductivity.Text = "";
  1964. textBox_Hardness.Text = "";
  1965. //textBox_MaxEDSTime.Text = "";
  1966. btn_dbs.BackColor = Color.White;
  1967. dataGridView_KeyElements.Rows.Clear();
  1968. dataGridView_KeyElements.Columns.Clear();
  1969. dataGridView_SubElements.Rows.Clear();
  1970. dataGridView_SubElements.Columns.Clear();
  1971. }
  1972. catch(Exception ex)
  1973. {
  1974. MessageBox.Show(table["message26"].ToString() + "\n"+ex.Message.ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  1975. }
  1976. }
  1977. private void tabControl_Rules_DrawItem(object sender, DrawItemEventArgs e)
  1978. {
  1979. //SolidBrush _Brush = new SolidBrush(Color.Black);//单色画刷
  1980. //RectangleF _TabTextArea = (RectangleF)tabControl_Rules.GetTabRect(e.Index);//绘制区域
  1981. //StringFormat _sf = new StringFormat();//封装文本布局格式信息
  1982. //_sf.LineAlignment = StringAlignment.Center;
  1983. //_sf.Alignment = StringAlignment.Center;
  1984. //e.Graphics.DrawString(tabControl_Rules.Controls[e.Index].Text, SystemInformation.MenuFont, _Brush, _TabTextArea, _sf);
  1985. //RectangleF tabArea = tabControl_Rules.GetTabRect(e.Index);
  1986. //RectangleF tabTextArea = tabArea;
  1987. //Graphics g = e.Graphics;
  1988. //StringFormat sf = new StringFormat();
  1989. //sf.LineAlignment = StringAlignment.Center;
  1990. //sf.Alignment = StringAlignment.Center;
  1991. //Font font = this.tabControl_Rules.Font;
  1992. //SolidBrush brush = new SolidBrush(Color.Black);
  1993. //g.DrawString(((TabControl)(sender)).TabPages[e.Index].Text, font, brush, tabTextArea, sf);
  1994. }
  1995. private void XmlTree_ZeroElementRules_MouseClick(object sender, MouseEventArgs e)
  1996. {
  1997. //if (e.Button == MouseButtons.Left)
  1998. //{
  1999. // Point ClickPoint = new Point(e.X, e.Y);
  2000. // TreeNode CurrentNode = XmlTree_ZeroElementRules.GetNodeAt(ClickPoint);
  2001. // if (CurrentNode != null)//判断你点的是不是一个节点
  2002. // {
  2003. // if (XmlTree_ZeroElementRules.SelectedNode != null&& XmlTree_ZeroElementRules.SelectedNode != CurrentNode)
  2004. // {
  2005. // if (XmlTree_ZeroElementRules.SelectedNode.Text.Contains("="))
  2006. // {
  2007. // if (!comboBox_PeriodicTable.Items.Contains(XmlTree_ZeroElementRules.SelectedNode.Text.Split('=')[0]))
  2008. // {
  2009. // MessageBox.Show(XmlTree_ZeroElementRules.SelectedNode.Text + "项,名称格式填写错误,正确格式为:元素名=0");
  2010. // SetGrayExceptSelectedNode(XmlTree_ZeroElementRules, XmlTree_ZeroElementRules.SelectedNode);
  2011. // return;
  2012. // }
  2013. // }
  2014. // else
  2015. // {
  2016. // MessageBox.Show(XmlTree_ZeroElementRules.SelectedNode.Text + "项,名称格式填写错误,正确格式为:元素名=0");
  2017. // SetGrayExceptSelectedNode(XmlTree_ZeroElementRules, XmlTree_ZeroElementRules.SelectedNode);
  2018. // return;
  2019. // }
  2020. // if (!Checktextbox_STDEditor())
  2021. // {
  2022. // SetGrayExceptSelectedNode(XmlTree_ZeroElementRules, XmlTree_ZeroElementRules.SelectedNode);
  2023. // return;
  2024. // }
  2025. // XmlTree_ZeroElementRules.SelectedNode.Tag = this.textbox_STDEditor.Text;
  2026. // }
  2027. // SetBlackAllNodes(XmlTree_ZeroElementRules);
  2028. // XmlTree_ZeroElementRules.SelectedNode = CurrentNode;
  2029. // this.textbox_STDEditor.Text = XmlTree_ZeroElementRules.SelectedNode.Tag.ToString();
  2030. // }
  2031. //}
  2032. }
  2033. private void XmlTree_ZeroElementRules_MouseDoubleClick(object sender, MouseEventArgs e)
  2034. {
  2035. if (e.Button == MouseButtons.Left)
  2036. {
  2037. Point ClickPoint = new Point(e.X, e.Y);
  2038. TreeNode CurrentNode = XmlTree_ZeroElementRules.GetNodeAt(ClickPoint);
  2039. if (CurrentNode != null)//判断你点的是不是一个节点
  2040. {
  2041. XmlTree_ZeroElementRules.SelectedNode = CurrentNode;//选中这个节点
  2042. //this.textbox_STDEditor.Text = XmlTree_ZeroElementRules.SelectedNode.Tag.ToString();
  2043. XmlTree_ZeroElementRules.LabelEdit = true;
  2044. XmlTree_ZeroElementRules.SelectedNode.BeginEdit();
  2045. }
  2046. }
  2047. }
  2048. private void XmlTree_MaxEDSRules_MouseClick(object sender, MouseEventArgs e)
  2049. {
  2050. //if (e.Button == MouseButtons.Left)
  2051. //{
  2052. // Point ClickPoint = new Point(e.X, e.Y);
  2053. // TreeNode CurrentNode = XmlTree_MaxEDSRules.GetNodeAt(ClickPoint);
  2054. // if (CurrentNode != null)//判断你点的是不是一个节点
  2055. // {
  2056. // if (XmlTree_MaxEDSRules.SelectedNode != null&& XmlTree_MaxEDSRules.SelectedNode!= CurrentNode)
  2057. // {
  2058. // if (!Checktextbox_STDEditor())
  2059. // {
  2060. // SetGrayExceptSelectedNode(XmlTree_MaxEDSRules, XmlTree_MaxEDSRules.SelectedNode);
  2061. // return;
  2062. // }
  2063. // //double dMaxEDSTime = 0;
  2064. // //if (!double.TryParse(textBox_MaxEDSTime.Text, out dMaxEDSTime)||double.Parse(textBox_MaxEDSTime.Text)<=0)
  2065. // //{
  2066. // // MessageBox.Show("MaxEDSTime请填写数字!", "提示");
  2067. // //}
  2068. // XmlTree_MaxEDSRules.SelectedNode.Tag = this.textbox_STDEditor.Text;
  2069. // //XmlTree_MaxEDSRules.SelectedNode.Name = this.textBox_MaxEDSTime.Text;
  2070. // }
  2071. // SetBlackAllNodes(XmlTree_MaxEDSRules);
  2072. // XmlTree_MaxEDSRules.SelectedNode = CurrentNode;
  2073. // this.textbox_STDEditor.Text = XmlTree_MaxEDSRules.SelectedNode.Tag.ToString();
  2074. // //textBox_MaxEDSTime.Text = XmlTree_MaxEDSRules.SelectedNode.Name;
  2075. // }
  2076. //}
  2077. }
  2078. private void checkBox_0_CheckedChanged(object sender, EventArgs e)
  2079. {
  2080. if (checkBox_0.Checked)
  2081. {
  2082. textBox_0.ReadOnly = false;
  2083. }
  2084. else
  2085. {
  2086. if (!CheckConstants(checkBox_0.Text))
  2087. {
  2088. checkBox_0.Checked = true;
  2089. }
  2090. else
  2091. {
  2092. textBox_0.ReadOnly = true;
  2093. }
  2094. }
  2095. }
  2096. private void checkBox_1_CheckedChanged(object sender, EventArgs e)
  2097. {
  2098. if (checkBox_1.Checked)
  2099. {
  2100. textBox_1.ReadOnly = false;
  2101. }
  2102. else
  2103. {
  2104. if (!CheckConstants(checkBox_1.Text))
  2105. {
  2106. checkBox_1.Checked = true;
  2107. }
  2108. else
  2109. {
  2110. textBox_1.ReadOnly = true;
  2111. }
  2112. }
  2113. }
  2114. private void checkBox_2_CheckedChanged(object sender, EventArgs e)
  2115. {
  2116. if (checkBox_2.Checked)
  2117. {
  2118. textBox_2.ReadOnly = false;
  2119. }
  2120. else
  2121. {
  2122. if (!CheckConstants(checkBox_2.Text))
  2123. {
  2124. checkBox_2.Checked = true;
  2125. }
  2126. else
  2127. {
  2128. textBox_2.ReadOnly = true;
  2129. }
  2130. }
  2131. }
  2132. private void checkBox_3_CheckedChanged(object sender, EventArgs e)
  2133. {
  2134. if (checkBox_3.Checked)
  2135. {
  2136. textBox_3.ReadOnly = false;
  2137. }
  2138. else
  2139. {
  2140. if (!CheckConstants(checkBox_3.Text))
  2141. {
  2142. checkBox_3.Checked = true;
  2143. }
  2144. else
  2145. {
  2146. textBox_3.ReadOnly = true;
  2147. }
  2148. }
  2149. }
  2150. private void checkBox_4_CheckedChanged(object sender, EventArgs e)
  2151. {
  2152. if (checkBox_4.Checked)
  2153. {
  2154. textBox_4.ReadOnly = false;
  2155. }
  2156. else
  2157. {
  2158. if (!CheckConstants(checkBox_4.Text))
  2159. {
  2160. checkBox_4.Checked = true;
  2161. }
  2162. else
  2163. {
  2164. textBox_4.ReadOnly = true;
  2165. }
  2166. }
  2167. }
  2168. private void checkBox_5_CheckedChanged(object sender, EventArgs e)
  2169. {
  2170. if (checkBox_5.Checked)
  2171. {
  2172. textBox_5.ReadOnly = false;
  2173. }
  2174. else
  2175. {
  2176. if (!CheckConstants(checkBox_5.Text))
  2177. {
  2178. checkBox_5.Checked = true;
  2179. }
  2180. else
  2181. {
  2182. textBox_5.ReadOnly = true;
  2183. }
  2184. }
  2185. }
  2186. private void checkBox_6_CheckedChanged(object sender, EventArgs e)
  2187. {
  2188. if (checkBox_6.Checked)
  2189. {
  2190. textBox_6.ReadOnly = false;
  2191. }
  2192. else
  2193. {
  2194. if (!CheckConstants(checkBox_6.Text))
  2195. {
  2196. checkBox_6.Checked = true;
  2197. }
  2198. else
  2199. {
  2200. textBox_6.ReadOnly = true;
  2201. }
  2202. }
  2203. }
  2204. private void checkBox_7_CheckedChanged(object sender, EventArgs e)
  2205. {
  2206. if (checkBox_7.Checked)
  2207. {
  2208. textBox_7.ReadOnly = false;
  2209. }
  2210. else
  2211. {
  2212. if (!CheckConstants(checkBox_7.Text))
  2213. {
  2214. checkBox_7.Checked = true;
  2215. }
  2216. else
  2217. {
  2218. textBox_7.ReadOnly = true;
  2219. }
  2220. }
  2221. }
  2222. private void checkBox_8_CheckedChanged(object sender, EventArgs e)
  2223. {
  2224. if (checkBox_8.Checked)
  2225. {
  2226. textBox_8.ReadOnly = false;
  2227. }
  2228. else
  2229. {
  2230. if (!CheckConstants(checkBox_8.Text))
  2231. {
  2232. checkBox_8.Checked = true;
  2233. }
  2234. else
  2235. {
  2236. textBox_8.ReadOnly = true;
  2237. }
  2238. }
  2239. }
  2240. private void checkBox_9_CheckedChanged(object sender, EventArgs e)
  2241. {
  2242. if (checkBox_9.Checked)
  2243. {
  2244. textBox_9.ReadOnly = false;
  2245. }
  2246. else
  2247. {
  2248. if (!CheckConstants(checkBox_9.Text))
  2249. {
  2250. checkBox_9.Checked = true;
  2251. }
  2252. else
  2253. {
  2254. textBox_9.ReadOnly = true;
  2255. }
  2256. }
  2257. }
  2258. private bool CheckConstants(string ConstantName)
  2259. {
  2260. for (int num = 0; num < XmlTree_STDlist.Nodes.Count; num++)
  2261. {
  2262. if (XmlTree_STDlist.Nodes[num].Tag.ToString().Contains(ConstantName))
  2263. {
  2264. tabControl_Rules.SelectedIndex = 0;
  2265. XmlTree_STDlist.SelectedNode = XmlTree_STDlist.Nodes[num];
  2266. SetGrayExceptSelectedNode(XmlTree_STDlist, XmlTree_STDlist.SelectedNode);
  2267. DialogResult result = MessageBox.Show(table["message27"].ToString() + XmlTree_STDlist.Nodes[num].Text + table["message28"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Warning);
  2268. return false;
  2269. }
  2270. }
  2271. for (int num = 0; num < XmlTree_MaxEDSRules.Nodes.Count; num++)
  2272. {
  2273. if (XmlTree_MaxEDSRules.Nodes[num].Tag.ToString().Contains(ConstantName))
  2274. {
  2275. tabControl_Rules.SelectedIndex = 1;
  2276. XmlTree_MaxEDSRules.SelectedNode = XmlTree_MaxEDSRules.Nodes[num];
  2277. SetGrayExceptSelectedNode(XmlTree_MaxEDSRules, XmlTree_MaxEDSRules.SelectedNode);
  2278. DialogResult result = MessageBox.Show(table["message27"].ToString() + XmlTree_MaxEDSRules.Nodes[num].Text + table["message28"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Warning);
  2279. return false;
  2280. }
  2281. }
  2282. for (int num = 0; num < XmlTree_ZeroElementRules.Nodes.Count; num++)
  2283. {
  2284. if (XmlTree_ZeroElementRules.Nodes[num].Tag.ToString().Contains(ConstantName))
  2285. {
  2286. tabControl_Rules.SelectedIndex = 2;
  2287. XmlTree_ZeroElementRules.SelectedNode = XmlTree_ZeroElementRules.Nodes[num];
  2288. SetGrayExceptSelectedNode(XmlTree_ZeroElementRules, XmlTree_ZeroElementRules.SelectedNode);
  2289. DialogResult result = MessageBox.Show(table["message27"].ToString() + XmlTree_ZeroElementRules.Nodes[num].Text + table["message28"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Warning);
  2290. return false;
  2291. }
  2292. }
  2293. return true;
  2294. }
  2295. private void button_UpdateConstants_Click(object sender, EventArgs e)
  2296. {
  2297. this.comboBox_Constants.Items.Clear();
  2298. for (int i=0;i<10;i++)
  2299. {
  2300. CheckBox checkBox= (CheckBox)this.tabControl_Rules.TabPages[3].Controls.Find("checkBox_" + i.ToString(), false)[0];
  2301. if (checkBox.Checked)
  2302. {
  2303. TextBox tBox = (TextBox)this.tabControl_Rules.TabPages[3].Controls.Find("textBox_" + i.ToString(), false)[0];
  2304. double DoubleTry = 0;
  2305. if (double.TryParse(tBox.Text, out DoubleTry))
  2306. {
  2307. this.comboBox_Constants.Items.Add(checkBox.Text + "=" + tBox.Text);
  2308. }
  2309. else
  2310. {
  2311. MessageBox.Show(table["message29"].ToString() + checkBox.Name + table["message30"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Warning);
  2312. return;
  2313. }
  2314. }
  2315. }
  2316. List<string> Constantslist = new List<string>();
  2317. Constantslist.Add("MAC#0");
  2318. Constantslist.Add("MAC#1");
  2319. Constantslist.Add("MAC#2");
  2320. Constantslist.Add("MAC#3");
  2321. Constantslist.Add("MAC#4");
  2322. Constantslist.Add("MAC#5");
  2323. Constantslist.Add("MAC#6");
  2324. Constantslist.Add("MAC#7");
  2325. Constantslist.Add("MAC#8");
  2326. Constantslist.Add("MAC#9");
  2327. foreach (var item in comboBox_Constants.Items)
  2328. {
  2329. Constantslist.Remove(item.ToString().Split('=')[0]);
  2330. }
  2331. MessageBox.Show(table["message31"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  2332. }
  2333. //tabpage切换开关
  2334. bool Flag_TabControlChange = true;
  2335. private void tabControl_Rules_Deselecting(object sender, TabControlCancelEventArgs e)
  2336. {
  2337. if (tabControl_Rules.SelectedIndex == 0)
  2338. {
  2339. //保存节点当前数据
  2340. if (XmlTree_STDlist.SelectedNode != null)
  2341. {
  2342. //判断Hardness、Density、Electrical_conductivity
  2343. double dHardness = 0, dDensity = 0, dElectrical_conductivity = 0;
  2344. if (!double.TryParse(textBox_Hardness.Text, out dHardness) || (double.Parse(textBox_Hardness.Text) <= 0))
  2345. {
  2346. textBox_Hardness.Focus();
  2347. textBox_Hardness.SelectAll();
  2348. MessageBox.Show(table["message10"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  2349. Flag_TabControlChange = false;
  2350. return;
  2351. }
  2352. if (!double.TryParse(textBox_Density.Text, out dDensity) || double.Parse(textBox_Density.Text) <= 0)
  2353. {
  2354. textBox_Density.Focus();
  2355. textBox_Density.SelectAll();
  2356. MessageBox.Show(table["message11"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  2357. Flag_TabControlChange = false;
  2358. return;
  2359. }
  2360. if (!double.TryParse(textBox_Electrical_conductivity.Text, out dElectrical_conductivity) || double.Parse(textBox_Electrical_conductivity.Text) <= 0)
  2361. {
  2362. textBox_Electrical_conductivity.Focus();
  2363. textBox_Electrical_conductivity.SelectAll();
  2364. MessageBox.Show(table["message12"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  2365. Flag_TabControlChange = false;
  2366. return;
  2367. }
  2368. //判断textbox_STDEditor
  2369. if (!Checktextbox_STDEditor())
  2370. {
  2371. Flag_TabControlChange = false;
  2372. return;
  2373. }
  2374. Flag_TabControlChange = true;
  2375. XmlTree_STDlist.SelectedNode.Tag = this.textbox_STDEditor.Text;
  2376. XmlTree_STDlist.SelectedNode.Name = textBox_Hardness.Text + "_" + textBox_Density.Text + "_" + textBox_Electrical_conductivity.Text;
  2377. string sKeyElements = "";
  2378. for (int i = 0; i < dataGridView_KeyElements.Columns.Count; i++)
  2379. {
  2380. sKeyElements += dataGridView_KeyElements.Rows[0].Cells[i].Value.ToString() + ",";
  2381. }
  2382. if (sKeyElements.Length > 0)
  2383. {
  2384. sKeyElements = sKeyElements.Substring(0, sKeyElements.Length - 1);
  2385. }
  2386. string sSubElements = "";
  2387. for (int i = 0; i < dataGridView_SubElements.Columns.Count; i++)
  2388. {
  2389. sSubElements += dataGridView_SubElements.Rows[0].Cells[i].Value.ToString() + ",";
  2390. }
  2391. if (sSubElements.Length > 0)
  2392. {
  2393. sSubElements = sSubElements.Substring(0, sSubElements.Length - 1);
  2394. }
  2395. XmlTree_STDlist.SelectedNode.Name += "$" + sKeyElements + "$" + sSubElements;
  2396. XmlTree_STDlist.SelectedNode.BackColor= btn_dbs.BackColor;
  2397. }
  2398. }
  2399. else if (tabControl_Rules.SelectedIndex == 1)
  2400. {
  2401. if (XmlTree_MaxEDSRules.SelectedNode != null)
  2402. {
  2403. //判断MaxEDSTime
  2404. double dMaxEDSTime = 0;
  2405. if (!double.TryParse(textBox_MaxEDSTime.Text, out dMaxEDSTime) || double.Parse(textBox_MaxEDSTime.Text) <= 0)
  2406. {
  2407. textBox_MaxEDSTime.Focus();
  2408. textBox_MaxEDSTime.SelectAll();
  2409. MessageBox.Show(table["message16"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  2410. Flag_TabControlChange = false;
  2411. return;
  2412. }
  2413. //判断textbox_STDEditor
  2414. if (!Checktextbox_STDEditor())
  2415. {
  2416. Flag_TabControlChange = false;
  2417. return;
  2418. }
  2419. Flag_TabControlChange = true;
  2420. XmlTree_MaxEDSRules.SelectedNode.Tag = this.textbox_STDEditor.Text;
  2421. //XmlTree_MaxEDSRules.SelectedNode.Name = textBox_MaxEDSTime.Text;
  2422. }
  2423. }
  2424. else if (tabControl_Rules.SelectedIndex == 2)
  2425. {
  2426. if (XmlTree_ZeroElementRules.SelectedNode != null)
  2427. {
  2428. if (XmlTree_ZeroElementRules.SelectedNode.Text.Contains("="))
  2429. {
  2430. if (!comboBox_PeriodicTable.Items.Contains(XmlTree_ZeroElementRules.SelectedNode.Text.Split('=')[0]))
  2431. {
  2432. MessageBox.Show(XmlTree_ZeroElementRules.SelectedNode.Text + table["message9"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  2433. Flag_TabControlChange = false;
  2434. return;
  2435. }
  2436. }
  2437. else
  2438. {
  2439. MessageBox.Show(XmlTree_ZeroElementRules.SelectedNode.Text + table["message9"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  2440. Flag_TabControlChange = false;
  2441. return;
  2442. }
  2443. //判断textbox_STDEditor
  2444. if (!Checktextbox_STDEditor())
  2445. {
  2446. Flag_TabControlChange = false;
  2447. return;
  2448. }
  2449. Flag_TabControlChange = true;
  2450. XmlTree_ZeroElementRules.SelectedNode.Tag = this.textbox_STDEditor.Text;
  2451. }
  2452. }
  2453. //XmlTree_STDlist.SelectedNode = null;
  2454. //XmlTree_MaxEDSRules.SelectedNode = null;
  2455. //XmlTree_ZeroElementRules.SelectedNode = null;
  2456. //textbox_STDEditor.Text = "";
  2457. //textBox_Density.Text = "";
  2458. //textBox_Electrical_conductivity.Text = "";
  2459. //textBox_Hardness.Text = "";
  2460. //textBox_MaxEDSTime.Text = "";
  2461. //btn_dbs.BackColor = Color.White;
  2462. }
  2463. private void tabControl_Rules_SelectedIndexChanged(object sender, EventArgs e)
  2464. {
  2465. if (tabControl_Rules.SelectedIndex == 0)
  2466. {
  2467. //XmlTree_STDlist.SelectedNode = null;
  2468. XmlTree_STDlist.Focus();
  2469. XmlTree_STDlist_AfterSelect(XmlTree_STDlist, new TreeViewEventArgs(XmlTree_STDlist.SelectedNode));
  2470. textBox_Density.ReadOnly = false;
  2471. textBox_Electrical_conductivity.ReadOnly = false;
  2472. textBox_Hardness.ReadOnly = false;
  2473. btn_dbs.Enabled = true;
  2474. textBox_MaxEDSTime.ReadOnly = true;
  2475. button_UpOrder.Enabled = false;
  2476. button_DownOrder.Enabled = false;
  2477. }
  2478. else if (tabControl_Rules.SelectedIndex == 1)
  2479. {
  2480. //XmlTree_MaxEDSRules.SelectedNode = null;
  2481. XmlTree_MaxEDSRules.Focus();
  2482. XmlTree_MaxEDSRules_AfterSelect(XmlTree_MaxEDSRules, new TreeViewEventArgs(XmlTree_MaxEDSRules.SelectedNode));
  2483. dataGridView_KeyElements.Rows.Clear();
  2484. dataGridView_KeyElements.Columns.Clear();
  2485. dataGridView_SubElements.Rows.Clear();
  2486. dataGridView_SubElements.Columns.Clear();
  2487. btn_dbs.BackColor = SystemColors.Control;
  2488. textBox_Density.Text = "";
  2489. textBox_Electrical_conductivity.Text = "";
  2490. textBox_Hardness.Text = "";
  2491. textBox_Density.ReadOnly = true;
  2492. textBox_Electrical_conductivity.ReadOnly = true;
  2493. textBox_Hardness.ReadOnly = true;
  2494. btn_dbs.Enabled = false;
  2495. textBox_MaxEDSTime.ReadOnly = false;
  2496. }
  2497. else if (tabControl_Rules.SelectedIndex == 2)
  2498. {
  2499. //XmlTree_ZeroElementRules.SelectedNode = null;
  2500. XmlTree_ZeroElementRules.Focus();
  2501. XmlTree_ZeroElementRules_AfterSelect(XmlTree_MaxEDSRules, new TreeViewEventArgs(XmlTree_ZeroElementRules.SelectedNode));
  2502. dataGridView_KeyElements.Rows.Clear();
  2503. dataGridView_KeyElements.Columns.Clear();
  2504. dataGridView_SubElements.Rows.Clear();
  2505. dataGridView_SubElements.Columns.Clear();
  2506. btn_dbs.BackColor = SystemColors.Control;
  2507. textBox_Density.Text = "";
  2508. textBox_Electrical_conductivity.Text = "";
  2509. textBox_Hardness.Text = "";
  2510. textBox_Density.ReadOnly = true;
  2511. textBox_Electrical_conductivity.ReadOnly = true;
  2512. textBox_Hardness.ReadOnly = true;
  2513. btn_dbs.Enabled = false;
  2514. textBox_MaxEDSTime.ReadOnly = true;
  2515. }
  2516. else
  2517. {
  2518. textbox_STDEditor.Text = "";
  2519. dataGridView_KeyElements.Rows.Clear();
  2520. dataGridView_KeyElements.Columns.Clear();
  2521. dataGridView_SubElements.Rows.Clear();
  2522. dataGridView_SubElements.Columns.Clear();
  2523. btn_dbs.BackColor = SystemColors.Control;
  2524. textBox_Density.Text = "";
  2525. textBox_Electrical_conductivity.Text = "";
  2526. textBox_Hardness.Text = "";
  2527. textBox_Density.ReadOnly = true;
  2528. textBox_Electrical_conductivity.ReadOnly = true;
  2529. textBox_Hardness.ReadOnly = true;
  2530. btn_dbs.Enabled = false;
  2531. textBox_MaxEDSTime.ReadOnly = true;
  2532. }
  2533. }
  2534. private void XmlTree_ZeroElementRules_BeforeSelect(object sender, TreeViewCancelEventArgs e)
  2535. {
  2536. //if (e.Node != null)
  2537. //{
  2538. // if (e.Node.ForeColor == Color.Gray)
  2539. // {
  2540. // e.Cancel = true; //不让选中禁用节点
  2541. // return;
  2542. // }
  2543. //}
  2544. if (XmlTree_ZeroElementRules.SelectedNode != null)
  2545. {
  2546. if (XmlTree_ZeroElementRules.SelectedNode.Text.Contains("="))
  2547. {
  2548. if (!comboBox_PeriodicTable.Items.Contains(XmlTree_ZeroElementRules.SelectedNode.Text.Split('=')[0]))
  2549. {
  2550. MessageBox.Show(XmlTree_ZeroElementRules.SelectedNode.Text + table["message9"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  2551. SetGrayExceptSelectedNode(XmlTree_ZeroElementRules, XmlTree_ZeroElementRules.SelectedNode);
  2552. e.Cancel = true;
  2553. return;
  2554. }
  2555. }
  2556. else
  2557. {
  2558. MessageBox.Show(XmlTree_ZeroElementRules.SelectedNode.Text + table["message9"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  2559. SetGrayExceptSelectedNode(XmlTree_ZeroElementRules, XmlTree_ZeroElementRules.SelectedNode);
  2560. e.Cancel = true;
  2561. return;
  2562. }
  2563. if (!Checktextbox_STDEditor())
  2564. {
  2565. SetGrayExceptSelectedNode(XmlTree_ZeroElementRules,XmlTree_ZeroElementRules.SelectedNode);
  2566. e.Cancel = true;
  2567. return;
  2568. }
  2569. XmlTree_ZeroElementRules.SelectedNode.Tag = this.textbox_STDEditor.Text;
  2570. }
  2571. }
  2572. private void tabControl_Rules_Selecting(object sender, TabControlCancelEventArgs e)
  2573. {
  2574. if (!Flag_TabControlChange)
  2575. {
  2576. e.Cancel = true;
  2577. }
  2578. else
  2579. {
  2580. }
  2581. }
  2582. private void XmlTree_ZeroElementRules_AfterSelect(object sender, TreeViewEventArgs e)
  2583. {
  2584. SetBlackAllNodes(XmlTree_ZeroElementRules);
  2585. this.textbox_STDEditor.Text = XmlTree_ZeroElementRules.SelectedNode.Tag.ToString();
  2586. }
  2587. private void XmlTree_STDlist_AfterSelect(object sender, TreeViewEventArgs e)
  2588. {
  2589. SetBlackAllNodes(XmlTree_STDlist);
  2590. this.textbox_STDEditor.Text = XmlTree_STDlist.SelectedNode.Tag.ToString();
  2591. btn_dbs.BackColor = XmlTree_STDlist.SelectedNode.BackColor;
  2592. string[] strOther = XmlTree_STDlist.SelectedNode.Name.Split('$');
  2593. string[] strOther2 = strOther[0].Split('_');
  2594. textBox_Hardness.Text = strOther2[0];
  2595. textBox_Density.Text = strOther2[1];
  2596. textBox_Electrical_conductivity.Text = strOther2[2];
  2597. dataGridView_KeyElements.Rows.Clear();
  2598. dataGridView_KeyElements.Columns.Clear();
  2599. string[] KeyElement = strOther[1].Split(',');
  2600. for (int i=0;i< KeyElement.Length;i++)
  2601. {
  2602. if(KeyElement[0]!="")
  2603. {
  2604. DataGridViewButtonColumn dataGridViewButtonColumn = new DataGridViewButtonColumn();
  2605. dataGridViewButtonColumn.Name = dataGridView_SubElements.Columns.Count.ToString();
  2606. dataGridView_KeyElements.Columns.Add(dataGridViewButtonColumn);
  2607. if (dataGridView_KeyElements.Rows.Count == 0)
  2608. {
  2609. DataGridViewRow row = new DataGridViewRow();
  2610. dataGridView_KeyElements.Rows.Add(row);
  2611. }
  2612. dataGridView_KeyElements.Rows[0].Cells[i].Value = KeyElement[i];
  2613. }
  2614. }
  2615. dataGridView_SubElements.Rows.Clear();
  2616. dataGridView_SubElements.Columns.Clear();
  2617. string[] SubElement = strOther[2].Split(',');
  2618. for (int i = 0; i < SubElement.Length; i++)
  2619. {
  2620. if(SubElement[i]!="")
  2621. {
  2622. DataGridViewButtonColumn dataGridViewButtonColumn = new DataGridViewButtonColumn();
  2623. dataGridViewButtonColumn.Name = dataGridView_SubElements.Columns.Count.ToString();
  2624. dataGridView_SubElements.Columns.Add(dataGridViewButtonColumn);
  2625. if (dataGridView_SubElements.Rows.Count == 0)
  2626. {
  2627. DataGridViewRow row = new DataGridViewRow();
  2628. dataGridView_SubElements.Rows.Add(row);
  2629. }
  2630. dataGridView_SubElements.Rows[0].Cells[i].Value = SubElement[i];
  2631. }
  2632. }
  2633. if (button_UpOrder.Enabled == false)
  2634. {
  2635. button_UpOrder.Enabled = true;
  2636. }
  2637. if (button_DownOrder.Enabled == false)
  2638. {
  2639. button_DownOrder.Enabled = true;
  2640. }
  2641. if (XmlTree_STDlist.SelectedNode.PrevNode == null)
  2642. {
  2643. button_UpOrder.Enabled = false;
  2644. }
  2645. else if (XmlTree_STDlist.SelectedNode.NextNode == null)
  2646. {
  2647. button_DownOrder.Enabled = false;
  2648. }
  2649. dataGridView_KeyElements.ClearSelection();
  2650. dataGridView_SubElements.ClearSelection();
  2651. }
  2652. private void XmlTree_STDlist_BeforeSelect(object sender, TreeViewCancelEventArgs e)
  2653. {
  2654. if (XmlTree_STDlist.SelectedNode != null)
  2655. {
  2656. //判断Hardness、Density、Electrical_conductivity
  2657. double dHardness = 0, dDensity = 0, dElectrical_conductivity = 0;
  2658. if (!double.TryParse(textBox_Hardness.Text, out dHardness) || (double.Parse(textBox_Hardness.Text) <= 0))
  2659. {
  2660. MessageBox.Show(table["message10"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  2661. SetGrayExceptSelectedNode(XmlTree_STDlist, XmlTree_STDlist.SelectedNode);
  2662. Flag_SelStatus = false;
  2663. e.Cancel = true;
  2664. return;
  2665. }
  2666. if (!double.TryParse(textBox_Density.Text, out dDensity) || double.Parse(textBox_Density.Text) <= 0)
  2667. {
  2668. MessageBox.Show(table["message11"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  2669. SetGrayExceptSelectedNode(XmlTree_STDlist, XmlTree_STDlist.SelectedNode);
  2670. Flag_SelStatus = false;
  2671. e.Cancel = true;
  2672. return;
  2673. }
  2674. if (!double.TryParse(textBox_Electrical_conductivity.Text, out dElectrical_conductivity) || double.Parse(textBox_Electrical_conductivity.Text) <= 0)
  2675. {
  2676. MessageBox.Show(table["message12"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  2677. SetGrayExceptSelectedNode(XmlTree_STDlist, XmlTree_STDlist.SelectedNode);
  2678. Flag_SelStatus = false;
  2679. e.Cancel = true;
  2680. return;
  2681. }
  2682. //判断textbox_STDEditor
  2683. if (!Checktextbox_STDEditor())
  2684. {
  2685. SetGrayExceptSelectedNode(XmlTree_STDlist, XmlTree_STDlist.SelectedNode);
  2686. Flag_SelStatus = false;
  2687. e.Cancel = true;
  2688. return;
  2689. }
  2690. XmlTree_STDlist.SelectedNode.Tag = this.textbox_STDEditor.Text;
  2691. if (dataGridView_KeyElements.Rows.Count == 0&& dataGridView_SubElements.Rows.Count==0)
  2692. {
  2693. string str_RemoveBlank = textbox_STDEditor.Text.ToString().Replace(" ", "");
  2694. str_RemoveBlank = str_RemoveBlank.Replace("\r\n", "");
  2695. str_RemoveBlank = str_RemoveBlank.Replace("forth_elem", "");
  2696. string[] str_Removeand = System.Text.RegularExpressions.Regex.Split(str_RemoveBlank, "and", System.Text.RegularExpressions.RegexOptions.None);
  2697. List<string> str_Removeandor = new List<string>();
  2698. for (int i = 0; i < str_Removeand.Length; i++)
  2699. {
  2700. str_Removeandor.AddRange(System.Text.RegularExpressions.Regex.Split(str_Removeand[i], "or", System.Text.RegularExpressions.RegexOptions.None));
  2701. }
  2702. List<string> list_all = new List<string>();
  2703. for (int i = 0; i < str_Removeandor.Count; i++)
  2704. {
  2705. list_all.AddRange(str_Removeandor[i].Split(new char[] { '+', '-', '*', '/', '=', '>', '<', '(', ')' }));
  2706. }
  2707. List<string> UsingElementL = new List<string>();
  2708. for (int i = 0; i < list_all.Count; i++)
  2709. {
  2710. if (this.comboBox_PeriodicTable.Items.Contains(list_all[i]))
  2711. {
  2712. if (!UsingElementL.Contains(list_all[i]))
  2713. {
  2714. UsingElementL.Add(list_all[i]);
  2715. }
  2716. }
  2717. }
  2718. for (int i = 0; i < UsingElementL.Count; i++)
  2719. {
  2720. DataGridViewButtonColumn dataGridViewButtonColumn = new DataGridViewButtonColumn();
  2721. dataGridViewButtonColumn.Name = dataGridView_KeyElements.Columns.Count.ToString();
  2722. dataGridView_KeyElements.Columns.Add(dataGridViewButtonColumn);
  2723. if (dataGridView_KeyElements.Rows.Count == 0)
  2724. {
  2725. DataGridViewRow row = new DataGridViewRow();
  2726. dataGridView_KeyElements.Rows.Add(row);
  2727. }
  2728. dataGridView_KeyElements.Rows[0].Cells[i].Value = UsingElementL[i];
  2729. }
  2730. }
  2731. XmlTree_STDlist.SelectedNode.Name = textBox_Hardness.Text + "_" + textBox_Density.Text + "_" + textBox_Electrical_conductivity.Text;
  2732. string sKeyElements = "";
  2733. for (int i = 0; i < dataGridView_KeyElements.Columns.Count; i++)
  2734. {
  2735. sKeyElements += dataGridView_KeyElements.Rows[0].Cells[i].Value.ToString()+",";
  2736. }
  2737. if (sKeyElements.Length > 0)
  2738. {
  2739. sKeyElements = sKeyElements.Substring(0,sKeyElements.Length-1);
  2740. }
  2741. string sSubElements = "";
  2742. for (int i = 0; i < dataGridView_SubElements.Columns.Count; i++)
  2743. {
  2744. sSubElements += dataGridView_SubElements.Rows[0].Cells[i].Value.ToString()+",";
  2745. }
  2746. if(sSubElements.Length>0)
  2747. {
  2748. sSubElements = sSubElements.Substring(0, sSubElements.Length-1);
  2749. }
  2750. XmlTree_STDlist.SelectedNode.Name += "$" + sKeyElements + "$" + sSubElements;
  2751. XmlTree_STDlist.SelectedNode.BackColor= btn_dbs.BackColor;
  2752. }
  2753. }
  2754. private void XmlTree_MaxEDSRules_AfterSelect(object sender, TreeViewEventArgs e)
  2755. {
  2756. SetBlackAllNodes(XmlTree_MaxEDSRules);
  2757. this.textbox_STDEditor.Text = XmlTree_MaxEDSRules.SelectedNode.Tag.ToString();
  2758. //textBox_MaxEDSTime.Text = XmlTree_MaxEDSRules.SelectedNode.Name;
  2759. }
  2760. private void XmlTree_MaxEDSRules_BeforeSelect(object sender, TreeViewCancelEventArgs e)
  2761. {
  2762. if (XmlTree_MaxEDSRules.SelectedNode != null)
  2763. {
  2764. if (!Checktextbox_STDEditor())
  2765. {
  2766. SetGrayExceptSelectedNode(XmlTree_MaxEDSRules, XmlTree_MaxEDSRules.SelectedNode);
  2767. e.Cancel = true;
  2768. return;
  2769. }
  2770. //double dMaxEDSTime = 0;
  2771. //if (!double.TryParse(textBox_MaxEDSTime.Text, out dMaxEDSTime)||double.Parse(textBox_MaxEDSTime.Text)<=0)
  2772. //{
  2773. // MessageBox.Show("MaxEDSTime请填写数字!", "提示");
  2774. // e.Cancel = true;
  2775. //}
  2776. XmlTree_MaxEDSRules.SelectedNode.Tag = this.textbox_STDEditor.Text;
  2777. //XmlTree_MaxEDSRules.SelectedNode.Name = this.textBox_MaxEDSTime.Text;
  2778. }
  2779. }
  2780. string ElementKeyOrSub = "";
  2781. private void dataGridView_KeyElements_CellClick(object sender, DataGridViewCellEventArgs e)
  2782. {
  2783. ElementKeyOrSub = dataGridView_KeyElements.CurrentCell.Value.ToString();
  2784. dataGridView_KeyElements.Columns.RemoveAt(e.ColumnIndex);
  2785. DataGridViewButtonColumn dataGridViewButtonColumn = new DataGridViewButtonColumn();
  2786. dataGridViewButtonColumn.Name = dataGridView_SubElements.Columns.Count.ToString();
  2787. dataGridView_SubElements.Columns.Add(dataGridViewButtonColumn);
  2788. if (dataGridView_SubElements.Rows.Count == 0)
  2789. {
  2790. DataGridViewRow row = new DataGridViewRow();
  2791. dataGridView_SubElements.Rows.Add(row);
  2792. }
  2793. dataGridView_SubElements.Rows[0].Cells[dataGridView_SubElements.Columns.Count-1].Value = ElementKeyOrSub;
  2794. dataGridView_SubElements.ClearSelection();
  2795. dataGridView_KeyElements.ClearSelection();
  2796. XmlTree_STDlist.Focus();
  2797. }
  2798. private void dataGridView_SubElements_CellClick(object sender, DataGridViewCellEventArgs e)
  2799. {
  2800. ElementKeyOrSub = dataGridView_SubElements.CurrentCell.Value.ToString();
  2801. dataGridView_SubElements.Columns.RemoveAt(e.ColumnIndex);
  2802. DataGridViewButtonColumn dataGridViewButtonColumn = new DataGridViewButtonColumn();
  2803. dataGridViewButtonColumn.Name = dataGridView_SubElements.Columns.Count.ToString();
  2804. dataGridView_KeyElements.Columns.Add(dataGridViewButtonColumn);
  2805. if (dataGridView_KeyElements.Rows.Count == 0)
  2806. {
  2807. DataGridViewRow row = new DataGridViewRow();
  2808. dataGridView_KeyElements.Rows.Add(row);
  2809. }
  2810. dataGridView_KeyElements.Rows[0].Cells[dataGridView_KeyElements.Columns.Count - 1].Value = ElementKeyOrSub;
  2811. dataGridView_KeyElements.ClearSelection();
  2812. dataGridView_SubElements.ClearSelection();
  2813. XmlTree_STDlist.Focus();
  2814. }
  2815. private void textbox_STDEditor_TextChanged(object sender, EventArgs e)
  2816. {
  2817. //string str_RemoveBlank = textbox_STDEditor.Text.ToString().Replace(" ", "");
  2818. //str_RemoveBlank = str_RemoveBlank.Replace("\r\n", "");
  2819. //str_RemoveBlank = str_RemoveBlank.Replace("forth_elem", "");
  2820. //string[] str_Removeand = System.Text.RegularExpressions.Regex.Split(str_RemoveBlank, "and", System.Text.RegularExpressions.RegexOptions.None);
  2821. //List<string> str_Removeandor = new List<string>();
  2822. //for (int i = 0; i < str_Removeand.Length; i++)
  2823. //{
  2824. // str_Removeandor.AddRange(System.Text.RegularExpressions.Regex.Split(str_Removeand[i], "or", System.Text.RegularExpressions.RegexOptions.None));
  2825. //}
  2826. //List<string> list_all = new List<string>();
  2827. //for (int i = 0; i < str_Removeandor.Count; i++)
  2828. //{
  2829. // list_all.AddRange(str_Removeandor[i].Split(new char[] { '+', '-', '*', '/', '=', '>', '<', '(', ')' }));
  2830. //}
  2831. //List<string> UsingElementL = new List<string>();
  2832. //for (int i = 0; i < list_all.Count; i++)
  2833. //{
  2834. // if (this.comboBox_PeriodicTable.Items.Contains(list_all[i]))
  2835. // {
  2836. // if (!UsingElementL.Contains(list_all[i]))
  2837. // {
  2838. // UsingElementL.Add(list_all[i]);
  2839. // }
  2840. // }
  2841. //}
  2842. //for (int i = 0; i < UsingElementL.Count; i++)
  2843. //{
  2844. // DataGridViewButtonColumn dataGridViewButtonColumn = new DataGridViewButtonColumn();
  2845. // dataGridViewButtonColumn.Name = dataGridView_KeyElements.Columns.Count.ToString();
  2846. // dataGridView_KeyElements.Columns.Add(dataGridViewButtonColumn);
  2847. // if (dataGridView_KeyElements.Rows.Count == 0)
  2848. // {
  2849. // DataGridViewRow row = new DataGridViewRow();
  2850. // dataGridView_KeyElements.Rows.Add(row);
  2851. // }
  2852. // dataGridView_KeyElements.Rows[0].Cells[i].Value = UsingElementL[i];
  2853. //}
  2854. }
  2855. private void textbox_STDEditor_KeyPress(object sender, KeyPressEventArgs e)
  2856. {
  2857. //if (e.KeyChar == '\r')
  2858. //{
  2859. // dataGridView_KeyElements.Rows.Clear();
  2860. // dataGridView_KeyElements.Columns.Clear();
  2861. // dataGridView_SubElements.Rows.Clear();
  2862. // dataGridView_SubElements.Columns.Clear();
  2863. // string str_RemoveBlank = textbox_STDEditor.Text.ToString().Replace(" ", "");
  2864. // str_RemoveBlank = str_RemoveBlank.Replace("\r\n", "");
  2865. // str_RemoveBlank = str_RemoveBlank.Replace("forth_elem", "");
  2866. // string[] str_Removeand = System.Text.RegularExpressions.Regex.Split(str_RemoveBlank, "and", System.Text.RegularExpressions.RegexOptions.None);
  2867. // List<string> str_Removeandor = new List<string>();
  2868. // for (int i = 0; i < str_Removeand.Length; i++)
  2869. // {
  2870. // str_Removeandor.AddRange(System.Text.RegularExpressions.Regex.Split(str_Removeand[i], "or", System.Text.RegularExpressions.RegexOptions.None));
  2871. // }
  2872. // List<string> list_all = new List<string>();
  2873. // for (int i = 0; i < str_Removeandor.Count; i++)
  2874. // {
  2875. // list_all.AddRange(str_Removeandor[i].Split(new char[] { '+', '-', '*', '/', '=', '>', '<', '(', ')' }));
  2876. // }
  2877. // List<string> UsingElementL = new List<string>();
  2878. // for (int i = 0; i < list_all.Count; i++)
  2879. // {
  2880. // if (this.comboBox_PeriodicTable.Items.Contains(list_all[i]))
  2881. // {
  2882. // if (!UsingElementL.Contains(list_all[i]))
  2883. // {
  2884. // UsingElementL.Add(list_all[i]);
  2885. // }
  2886. // }
  2887. // }
  2888. // for (int i = 0; i < UsingElementL.Count; i++)
  2889. // {
  2890. // DataGridViewButtonColumn dataGridViewButtonColumn = new DataGridViewButtonColumn();
  2891. // dataGridViewButtonColumn.Name = dataGridView_KeyElements.Columns.Count.ToString();
  2892. // dataGridView_KeyElements.Columns.Add(dataGridViewButtonColumn);
  2893. // if(dataGridView_KeyElements.Rows.Count==0)
  2894. // {
  2895. // DataGridViewRow row = new DataGridViewRow();
  2896. // dataGridView_KeyElements.Rows.Add(row);
  2897. // }
  2898. // dataGridView_KeyElements.Rows[0].Cells[i].Value = UsingElementL[i];
  2899. // }
  2900. //}
  2901. }
  2902. private void textbox_STDEditor_Leave(object sender, EventArgs e)
  2903. {
  2904. if (tabControl_Rules.SelectedIndex == 0)
  2905. {
  2906. dataGridView_KeyElements.Rows.Clear();
  2907. dataGridView_KeyElements.Columns.Clear();
  2908. string str_RemoveBlank = textbox_STDEditor.Text.ToString().Replace(" ", "");
  2909. str_RemoveBlank = str_RemoveBlank.Replace("\r\n", "");
  2910. str_RemoveBlank = str_RemoveBlank.Replace("forth_elem", "");
  2911. string[] str_Removeand = System.Text.RegularExpressions.Regex.Split(str_RemoveBlank, "and", System.Text.RegularExpressions.RegexOptions.None);
  2912. List<string> str_Removeandor = new List<string>();
  2913. for (int i = 0; i < str_Removeand.Length; i++)
  2914. {
  2915. str_Removeandor.AddRange(System.Text.RegularExpressions.Regex.Split(str_Removeand[i], "or", System.Text.RegularExpressions.RegexOptions.None));
  2916. }
  2917. List<string> list_all = new List<string>();
  2918. for (int i = 0; i < str_Removeandor.Count; i++)
  2919. {
  2920. list_all.AddRange(str_Removeandor[i].Split(new char[] { '+', '-', '*', '/', '=', '>', '<', '(', ')' }));
  2921. }
  2922. List<string> UsingElementL = new List<string>();
  2923. for (int i = 0; i < list_all.Count; i++)
  2924. {
  2925. if (this.comboBox_PeriodicTable.Items.Contains(list_all[i]))
  2926. {
  2927. if (!UsingElementL.Contains(list_all[i]))
  2928. {
  2929. UsingElementL.Add(list_all[i]);
  2930. }
  2931. }
  2932. }
  2933. List<string> SubElements = new List<string>();
  2934. for (int i = 0; i < dataGridView_SubElements.ColumnCount; i++)
  2935. {
  2936. if (UsingElementL.Contains(dataGridView_SubElements.Rows[0].Cells[i].Value))
  2937. {
  2938. SubElements.Add(dataGridView_SubElements.Rows[0].Cells[i].Value.ToString());
  2939. }
  2940. }
  2941. dataGridView_SubElements.Rows.Clear();
  2942. dataGridView_SubElements.Columns.Clear();
  2943. for (int i = 0; i < SubElements.Count; i++)
  2944. {
  2945. DataGridViewButtonColumn dataGridViewButtonColumn = new DataGridViewButtonColumn();
  2946. dataGridViewButtonColumn.Name = dataGridView_SubElements.Columns.Count.ToString();
  2947. dataGridView_SubElements.Columns.Add(dataGridViewButtonColumn);
  2948. if (dataGridView_SubElements.Rows.Count == 0)
  2949. {
  2950. DataGridViewRow row = new DataGridViewRow();
  2951. dataGridView_SubElements.Rows.Add(row);
  2952. }
  2953. dataGridView_SubElements.Rows[0].Cells[dataGridView_SubElements.ColumnCount - 1].Value = SubElements[i];
  2954. }
  2955. if (SubElements.Count > 0)
  2956. {
  2957. for (int i = 0; i < UsingElementL.Count; i++)
  2958. {
  2959. if (!SubElements.Contains(UsingElementL[i]))
  2960. {
  2961. DataGridViewButtonColumn dataGridViewButtonColumn = new DataGridViewButtonColumn();
  2962. dataGridViewButtonColumn.Name = dataGridView_KeyElements.Columns.Count.ToString();
  2963. dataGridView_KeyElements.Columns.Add(dataGridViewButtonColumn);
  2964. if (dataGridView_KeyElements.Rows.Count == 0)
  2965. {
  2966. DataGridViewRow row = new DataGridViewRow();
  2967. dataGridView_KeyElements.Rows.Add(row);
  2968. }
  2969. dataGridView_KeyElements.Rows[0].Cells[dataGridView_KeyElements.ColumnCount - 1].Value = UsingElementL[i];
  2970. }
  2971. }
  2972. }
  2973. else
  2974. {
  2975. for (int i = 0; i < UsingElementL.Count; i++)
  2976. {
  2977. DataGridViewButtonColumn dataGridViewButtonColumn = new DataGridViewButtonColumn();
  2978. dataGridViewButtonColumn.Name = dataGridView_KeyElements.Columns.Count.ToString();
  2979. dataGridView_KeyElements.Columns.Add(dataGridViewButtonColumn);
  2980. if (dataGridView_KeyElements.Rows.Count == 0)
  2981. {
  2982. DataGridViewRow row = new DataGridViewRow();
  2983. dataGridView_KeyElements.Rows.Add(row);
  2984. }
  2985. dataGridView_KeyElements.Rows[0].Cells[i].Value = UsingElementL[i];
  2986. }
  2987. }
  2988. dataGridView_KeyElements.ClearSelection();
  2989. dataGridView_SubElements.ClearSelection();
  2990. XmlTree_STDlist.Focus();
  2991. }
  2992. else if(tabControl_Rules.SelectedIndex == 1)
  2993. {
  2994. XmlTree_MaxEDSRules.Focus();
  2995. }
  2996. else if (tabControl_Rules.SelectedIndex == 2)
  2997. {
  2998. XmlTree_ZeroElementRules.Focus();
  2999. }
  3000. }
  3001. #region 为配合textbox_STDEditor_Leave时事件,点击其它groupbox组件时使焦点转移
  3002. private void Form_ConstantsEditor_Click(object sender, EventArgs e)
  3003. {
  3004. groupBox_XmlTree_MaxEDSRules.Focus();
  3005. }
  3006. private void groupBox_Data_Click(object sender, EventArgs e)
  3007. {
  3008. groupBox_Data.Focus();
  3009. }
  3010. private void groupBox_Color_Click(object sender, EventArgs e)
  3011. {
  3012. groupBox_Color.Focus();
  3013. }
  3014. private void groupBox_ChemicalElement_Click(object sender, EventArgs e)
  3015. {
  3016. groupBox_ChemicalElement.Focus();
  3017. }
  3018. private void groupBox_OtherCommonlyUsedSymbols_Click(object sender, EventArgs e)
  3019. {
  3020. groupBox_OtherCommonlyUsedSymbols.Focus();
  3021. }
  3022. private void groupBox_XmlTree_STDlist1_Click(object sender, EventArgs e)
  3023. {
  3024. groupBox_XmlTree_STDlist1.Focus();
  3025. }
  3026. private void groupBox_CalculatingSymbols_Click(object sender, EventArgs e)
  3027. {
  3028. groupBox_CalculatingSymbols.Focus();
  3029. }
  3030. private void groupBox_XmlTree_MaxEDSRules_Click(object sender, EventArgs e)
  3031. {
  3032. groupBox_XmlTree_MaxEDSRules.Focus();
  3033. }
  3034. #endregion
  3035. private void button_1_Click(object sender, EventArgs e)
  3036. {
  3037. //textbox_STDEditor 中的光标
  3038. int index = textbox_STDEditor.SelectionStart;
  3039. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "1");
  3040. textbox_STDEditor.Focus();
  3041. textbox_STDEditor.Select(index + 1, 0);
  3042. textbox_STDEditor.ScrollToCaret();
  3043. }
  3044. private void button_2_Click(object sender, EventArgs e)
  3045. {
  3046. //textbox_STDEditor 中的光标
  3047. int index = textbox_STDEditor.SelectionStart;
  3048. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "2");
  3049. textbox_STDEditor.Focus();
  3050. textbox_STDEditor.Select(index + 1, 0);
  3051. textbox_STDEditor.ScrollToCaret();
  3052. }
  3053. private void button_3_Click(object sender, EventArgs e)
  3054. {
  3055. //textbox_STDEditor 中的光标
  3056. int index = textbox_STDEditor.SelectionStart;
  3057. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "3");
  3058. textbox_STDEditor.Focus();
  3059. textbox_STDEditor.Select(index + 1, 0);
  3060. textbox_STDEditor.ScrollToCaret();
  3061. }
  3062. private void button_4_Click(object sender, EventArgs e)
  3063. {
  3064. //textbox_STDEditor 中的光标
  3065. int index = textbox_STDEditor.SelectionStart;
  3066. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "4");
  3067. textbox_STDEditor.Focus();
  3068. textbox_STDEditor.Select(index + 1, 0);
  3069. textbox_STDEditor.ScrollToCaret();
  3070. }
  3071. private void button_5_Click(object sender, EventArgs e)
  3072. {
  3073. //textbox_STDEditor 中的光标
  3074. int index = textbox_STDEditor.SelectionStart;
  3075. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "5");
  3076. textbox_STDEditor.Focus();
  3077. textbox_STDEditor.Select(index + 1, 0);
  3078. textbox_STDEditor.ScrollToCaret();
  3079. }
  3080. private void button_6_Click(object sender, EventArgs e)
  3081. {
  3082. //textbox_STDEditor 中的光标
  3083. int index = textbox_STDEditor.SelectionStart;
  3084. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "6");
  3085. textbox_STDEditor.Focus();
  3086. textbox_STDEditor.Select(index + 1, 0);
  3087. textbox_STDEditor.ScrollToCaret();
  3088. }
  3089. private void button_7_Click(object sender, EventArgs e)
  3090. {
  3091. //textbox_STDEditor 中的光标
  3092. int index = textbox_STDEditor.SelectionStart;
  3093. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "7");
  3094. textbox_STDEditor.Focus();
  3095. textbox_STDEditor.Select(index + 1, 0);
  3096. textbox_STDEditor.ScrollToCaret();
  3097. }
  3098. private void button_8_Click(object sender, EventArgs e)
  3099. {
  3100. //textbox_STDEditor 中的光标
  3101. int index = textbox_STDEditor.SelectionStart;
  3102. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "8");
  3103. textbox_STDEditor.Focus();
  3104. textbox_STDEditor.Select(index + 1, 0);
  3105. textbox_STDEditor.ScrollToCaret();
  3106. }
  3107. private void button_9_Click(object sender, EventArgs e)
  3108. {
  3109. //textbox_STDEditor 中的光标
  3110. int index = textbox_STDEditor.SelectionStart;
  3111. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "9");
  3112. textbox_STDEditor.Focus();
  3113. textbox_STDEditor.Select(index + 1, 0);
  3114. textbox_STDEditor.ScrollToCaret();
  3115. }
  3116. private void button_0_Click(object sender, EventArgs e)
  3117. {
  3118. int index = textbox_STDEditor.SelectionStart;
  3119. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "0");
  3120. textbox_STDEditor.Focus();
  3121. textbox_STDEditor.Select(index + 1, 0);
  3122. textbox_STDEditor.ScrollToCaret();
  3123. }
  3124. ////改变大小
  3125. //void changeSize()
  3126. //{
  3127. // //SetStyle(ControlStyles.UserPaint, true);
  3128. // //SetStyle(ControlStyles.AllPaintingInWmPaint, true); // 禁止擦除背景.
  3129. // //SetStyle(ControlStyles.OptimizedDoubleBuffer, true); // 双缓冲DoubleBuffer
  3130. // x = this.Width;
  3131. // y = this.Height;
  3132. // setTag(this);
  3133. // //if (this.WindowState == FormWindowState.Maximized)
  3134. // //{
  3135. // // this.WindowState = FormWindowState.Normal;
  3136. // //}
  3137. // //else
  3138. // //{
  3139. // // this.FormBorderStyle = FormBorderStyle.None;
  3140. // // this.WindowState = FormWindowState.Maximized;
  3141. // //}
  3142. //}
  3143. //#region 控件大小随窗体大小等比例缩放
  3144. //private float x;//定义当前窗体的宽度
  3145. //private float y;//定义当前窗体的高度
  3146. //private void setTag(Control cons)
  3147. //{
  3148. // foreach (Control con in cons.Controls)
  3149. // {
  3150. // con.Tag = con.Width + ";" + con.Height + ";" + con.Left + ";" + con.Top + ";" + con.Font.Size;
  3151. // if (con.Controls.Count > 0)
  3152. // {
  3153. // setTag(con);
  3154. // }
  3155. // }
  3156. //}
  3157. ////设置双缓冲区、解决闪屏问题
  3158. //public static void SetDouble(Control cc)
  3159. //{
  3160. // cc.GetType().GetProperty("DoubleBuffered", System.Reflection.BindingFlags.Instance |
  3161. // System.Reflection.BindingFlags.NonPublic).SetValue(cc, true, null);
  3162. //}
  3163. //private void setControls(float newx, float newy, Control cons)
  3164. //{
  3165. // //遍历窗体中的控件,重新设置控件的值
  3166. // foreach (Control con in cons.Controls)
  3167. // {
  3168. // ////获取控件的Tag属性值,并分割后存储字符串数组
  3169. // SetDouble(this);
  3170. // SetDouble(con);
  3171. // if (con.Tag != null)
  3172. // {
  3173. // string[] mytag = con.Tag.ToString().Split(new char[] { ';' });
  3174. // //根据窗体缩放的比例确定控件的值
  3175. // con.Width = Convert.ToInt32(System.Convert.ToSingle(mytag[0]) * newx);//宽度
  3176. // con.Height = Convert.ToInt32(System.Convert.ToSingle(mytag[1]) * newy);//高度
  3177. // con.Left = Convert.ToInt32(System.Convert.ToSingle(mytag[2]) * newx);//左边距
  3178. // con.Top = Convert.ToInt32(System.Convert.ToSingle(mytag[3]) * newy);//顶边距
  3179. // Single currentSize = System.Convert.ToSingle(mytag[4]) * newy;//字体大小
  3180. // con.Font = new Font(con.Font.Name, currentSize, con.Font.Style, con.Font.Unit);
  3181. // if (con.Controls.Count > 0)
  3182. // {
  3183. // setControls(newx, newy, con);
  3184. // }
  3185. // }
  3186. // }
  3187. //}
  3188. //private void setControls2(float newx, float newy, Control cons)
  3189. //{
  3190. // //遍历窗体中的控件,重新设置控件的值
  3191. // foreach (Control con in cons.Controls)
  3192. // {
  3193. // //根据窗体缩放的比例确定控件的值
  3194. // con.Width = Convert.ToInt32(con.Width * newx);
  3195. // con.Height = Convert.ToInt32(con.Height * newy);
  3196. // con.Left = Convert.ToInt32(con.Left * newx);
  3197. // con.Top = Convert.ToInt32(con.Top * newx);
  3198. // //Single currentSize = System.Convert.ToSingle(con.Font.Size) * newy;//字体大小
  3199. // //con.Font = new Font(con.Font.Name, currentSize, con.Font.Style, con.Font.Unit);
  3200. // if (con.Controls.Count > 0)
  3201. // {
  3202. // setControls2(newx, newy, con);
  3203. // }
  3204. // }
  3205. //}
  3206. ////在窗体的的时间中添加Resize事件
  3207. //private void Login_Resize(object sender, EventArgs e)
  3208. //{
  3209. // if (this.WindowState == FormWindowState.Maximized)
  3210. // {
  3211. // float newx = (this.Width) / x;
  3212. // float newy = (this.Height) / y;
  3213. // setControls2(newx, newy, this);
  3214. // PeriodicTableSwitch_Click(PeriodicTableSwitch, new EventArgs());
  3215. // }
  3216. // else
  3217. // {
  3218. // //setControls2(x, y, this);
  3219. // }
  3220. //}
  3221. //#endregion
  3222. }
  3223. }