1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342 |
- using OTSCLRINTERFACE;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Data;
- using System.Drawing;
- using System.IO;
- using System.Linq;
- using System.Runtime.InteropServices;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.Windows.Forms;
- using System.Xml;
- using System.Xml.Linq;
- namespace OTSPartA_STDEditor
- {
- public partial class Form_STDConstantsEditor : Form
- {
- //readonly string[] PeriodicTable = {"H","He","Li","Be","B","C","N","O","F","Ne","Na","Mg","Al","Si","P","S","Cl","Ar","K","Ca","Sc","Ti","V","Cr","Mn","Fe","Co","Ni","Cu","Zn","Ga","Ge","As","Se","Br","Kr","Rb","Sr","Y","Zr","Nb","Mo","Tc","Ru","Rh","Pd","Ag","Cd","In","Sn","Sb","Te","I","Xe","Cs","Ba","La","Ce","Pr","Nd","Pm","Sm","Eu","Gd","Tb","Dy","Ho","Er","Tm","Yb","Lu","Hf","Ta","W","Re","Os","Ir","Pt","Au","Hq","TI","Pb","Bi","Po","At","Rn","Fr","Ra","Ac","Th","Pa","U","Np","Pu","Am","Cm","Bk","Cf","Es","Fm","Mc","No","Lr","Rf","Db","Sg","Bh","Hs","Mt","Ds","Rg","Unb"};
- //readonly string[] OtherSymbol = { "first_elem" , "second_elem" , "third_elem" , "forth_elem", "fifth_elem", "sixth_elem", "seventh_elem","eighth_elem","ninth_elem", "tenth_elem", "Element1", "Element2" };
- public Form_STDConstantsEditor()
- {
- InitializeComponent();
- m_sc = new SqlLiteClass();
- }
- #region 全局变量
- //数据库操作对象
- private SqlLiteClass m_sc = null;
- // 电镜设置对象
- COTSControlFunExport m_cfun = null;
- //Xray图谱用户控件
- UXrayControl XrayControl = null;
- //全局Xray 用于存储当前选择行的Xray信息
- byte[] xrayByteData = null;
- // 连接状态
- bool m_bConnectionState = false;
- //标准Xray信息列表
- List<STDXray> m_STDXrayList = null;
- #endregion
- //国际化
- Language lan;
- Hashtable table;
- //public string Language = "English";
- string Address_backup = Application.StartupPath + "\\Config\\SysData\\OTSParticleSTD_backup.xml";
- string Address = Application.StartupPath + "\\Config\\SysData\\OTSParticleSTD.xml";
- private void Form_ConstantsEditor_Load(object sender, EventArgs e)
- {
- //初始化comboBox
- this.comboBox_Elem1.Items.Add("first_elem");
- this.comboBox_Elem1.Items.Add("second_elem");
- this.comboBox_Elem1.Items.Add("third_elem");
- this.comboBox_Elem1.Items.Add("forth_elem");
- this.comboBox_Elem1.Items.Add("fifth_elem");
- this.comboBox_Elem1.Items.Add("sixth_elem");
- this.comboBox_Elem1.Items.Add("seventh_elem");
- this.comboBox_Elem1.Items.Add("eighth_elem");
- this.comboBox_Elem1.Items.Add("ninth_elem");
- this.comboBox_Elem1.Items.Add("tenth_elem");
- comboBox_Elem1.SelectedIndex = comboBox_Elem1.Items.IndexOf("first_elem");
- this.comboBox_Elem.Items.Add("Element#1");
- this.comboBox_Elem.Items.Add("Element#2");
- this.comboBox_Elem.Items.Add("Element#3");
- this.comboBox_Elem.Items.Add("Element#4");
- this.comboBox_Elem.Items.Add("Element#5");
- this.comboBox_Elem.Items.Add("Element#6");
- this.comboBox_Elem.Items.Add("Element#7");
- this.comboBox_Elem.Items.Add("Element#8");
- this.comboBox_Elem.Items.Add("Element#9");
- this.comboBox_Elem.Items.Add("Element#10");
- comboBox_Elem.SelectedIndex = comboBox_Elem.Items.IndexOf("Element#1");
- this.comboBox_ImgProperty.Items.Add("Dmax");
- this.comboBox_ImgProperty.Items.Add("Dmin");
- this.comboBox_ImgProperty.Items.Add("Aspect");
- this.comboBox_ImgProperty.Items.Add("Dperp");
- this.comboBox_ImgProperty.Items.Add("Dmean");
- this.comboBox_ImgProperty.Items.Add("Area");
- this.comboBox_ImgProperty.Items.Add("Dferet");
- this.comboBox_ImgProperty.Items.Add("With");
- this.comboBox_ImgProperty.Items.Add("Height");
- this.comboBox_ImgProperty.Items.Add("Perimeter");
- this.comboBox_ImgProperty.Items.Add("Dinscr");
- this.comboBox_ImgProperty.Items.Add("Orientation");
- this.comboBox_ImgProperty.Items.Add("Delong");
- this.comboBox_ImgProperty.Items.Add("Aspectelong");
- this.comboBox_ImgProperty.Items.Add("Dequalcircle");
- this.comboBox_ImgProperty.Items.Add("Vedio");
- comboBox_ImgProperty.SelectedIndex = comboBox_ImgProperty.Items.IndexOf("Dmax");
- //this.comboBox_Constants.Items.Add("MAC#0");
- //this.comboBox_Constants.Items.Add("MAC#1");
- //this.comboBox_Constants.Items.Add("MAC#2");
- //this.comboBox_Constants.Items.Add("MAC#3");
- //this.comboBox_Constants.Items.Add("MAC#4");
- //this.comboBox_Constants.Items.Add("MAC#5");
- //this.comboBox_Constants.Items.Add("MAC#6");
- //this.comboBox_Constants.Items.Add("MAC#7");
- //this.comboBox_Constants.Items.Add("MAC#8");
- //this.comboBox_Constants.Items.Add("MAC#9");
- //comboBox_Constants.SelectedIndex = comboBox_Constants.Items.IndexOf("MAC#1");
- string[] PeriodicTable = { "H", "He", "Li", "Be", "B", "C", "N", "O", "F", "Ne", "Na", "Mg", "Al", "Si", "P", "S", "Cl", "Ar", "K", "Ca", "Sc", "Ti", "V", "Cr", "Mn", "Fe", "Co", "Ni", "Cu", "Zn", "Ga", "Ge", "As", "Se", "Br", "Kr", "Rb", "Sr", "Y", "Zr", "Nb", "Mo", "Tc", "Ru", "Rh", "Pd", "Ag", "Cd", "In", "Sn", "Sb", "Te", "I", "Xe", "Cs", "Ba", "La", "Ce", "Pr", "Nd", "Pm", "Sm", "Eu", "Gd", "Tb", "Dy", "Ho", "Er", "Tm", "Yb", "Lu", "Hf", "Ta", "W", "Re", "Os", "Ir", "Pt", "Au", "Hq", "TI", "Pb", "Bi", "Po", "At", "Rn", "Fr", "Ra", "Ac", "Th", "Pa", "U", "Np", "Pu", "Am", "Cm", "Bk", "Cf", "Es", "Fm", "Mc", "No", "Lr", "Rf", "Db", "Sg", "Bh", "Hs", "Mt", "Ds", "Rg", "Unb" };
- comboBox_PeriodicTable.Items.AddRange(PeriodicTable);
- AutoCompleteStringCollection sc = new AutoCompleteStringCollection();
- sc.AddRange(PeriodicTable);
- this.comboBox_PeriodicTable.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.Suggest;
- this.comboBox_PeriodicTable.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.CustomSource;
- this.comboBox_PeriodicTable.AutoCompleteCustomSource = sc;
- checkBox_0.Checked = false;
- checkBox_1.Checked = false;
- checkBox_2.Checked = false;
- checkBox_3.Checked = false;
- checkBox_4.Checked = false;
- checkBox_5.Checked = false;
- checkBox_6.Checked = false;
- checkBox_7.Checked = false;
- checkBox_8.Checked = false;
- checkBox_9.Checked = false;
- textBox_0.ReadOnly = true;
- textBox_1.ReadOnly = true;
- textBox_2.ReadOnly = true;
- textBox_3.ReadOnly = true;
- textBox_4.ReadOnly = true;
- textBox_5.ReadOnly = true;
- textBox_6.ReadOnly = true;
- textBox_7.ReadOnly = true;
- textBox_8.ReadOnly = true;
- textBox_9.ReadOnly = true;
- textBox_Density.ReadOnly = false;
- textBox_Electrical_conductivity.ReadOnly = false;
- textBox_BSEValue.ReadOnly = false;
- textBox_Formula.ReadOnly = false;
- textBox_Element.ReadOnly = false;
- textBox_Hardness.ReadOnly = false;
- btn_dbs.Enabled = true;
- dataGridView_KeyElements.RowHeadersVisible = false;
- dataGridView_KeyElements.ColumnHeadersVisible = false;
- dataGridView_KeyElements.AllowUserToAddRows = false;
- dataGridView_KeyElements.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
- dataGridView_SubElements.RowHeadersVisible = false;
- dataGridView_SubElements.ColumnHeadersVisible = false;
- dataGridView_SubElements.AllowUserToAddRows = false;
- dataGridView_SubElements.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
- XmlDocument doc = new XmlDocument();
- //string Address = Application.StartupPath.Substring(0, Application.StartupPath.Length-35) + "\\Opton\\OTSPartA\\OTS\\Bin\\Win32\\Debug\\Config\\SysData\\OTSParticleSTD.xml";
- //string Address = ".\\Config\\SysData\\OTSParticleSTD.xml";
- doc.Load(Address);
- LoadXmlToTreeControl(doc, XmlTree_STDlist.Nodes, XmlTree_MaxEDSRules.Nodes, XmlTree_ZeroElementRules.Nodes);
- button_UpOrder.Enabled = false;
- button_DownOrder.Enabled = false;
- textBox_MaxEDSTime.ReadOnly = true;
- this.textbox_STDEditor.Text = "";
- //this.XmlTree.TabStop = false;
- panel_OTSPeriodicTable.Visible = false;
- //修改窗体宽度
- //this.Width = this.Width - panel_OTSPeriodicTable.Width - 5;
- //if (XmlTree.GetNodeCount(true) != 0)
- //{
- // this.XmlTree.SelectedNode = XmlTree.Nodes[0];
- //}
- lan = new Language(this);
- table = lan.GetNameTable(this.Name);
- if (table["language"].ToString() == "EN")
- {
- panel_OTSPeriodicTable.BackgroundImage = global::OTSPartA_STDEditor.Properties.Resources.PeriodicTable_EN;
- PeriodicTableSwitch.BackgroundImage = global::OTSPartA_STDEditor.Properties.Resources.STDEditoName;
- PeriodicTableSwitch.Text = "";
- }
- else
- {
- panel_OTSPeriodicTable.BackgroundImage = global::OTSPartA_STDEditor.Properties.Resources.PeriodicTable_ZH;
- PeriodicTableSwitch.Text = "元素周期表";
- }
- panel_OTSPeriodicTable.Visible = false;
- this.Width = this.Width - panel_OTSPeriodicTable.Width - 5;
- Size size = Screen.PrimaryScreen.WorkingArea.Size; Left = (size.Width - Width) / 2;
- Top = (size.Height - Height) / 2;
- WindowState = FormWindowState.Normal;
- //groupBox_XmlTree_MaxEDSRules.Focus();
- this.XmlTree_STDlist.HideSelection = false;//失去焦点后不隐藏选中节点
- XmlTree_STDlist.Focus();
- if (XmlTree_STDlist.Nodes.Count > 0)
- {
- XmlTree_STDlist.SelectedNode = XmlTree_STDlist.Nodes[0];
- XmlTree_STDlist_AfterSelect(XmlTree_STDlist, new TreeViewEventArgs(XmlTree_STDlist.SelectedNode));
- }
- //添加Xray用户控件
- XrayControl = new UXrayControl();
- plXray.Controls.Add(XrayControl);
- XrayControl.Dock = DockStyle.Fill;
- //绑定数据库中的STDXray
- m_STDXrayList = new List<STDXray>();
- BindSTDXray();
- }
- /// <summary>
- /// [颜色:16进制转成RGB]
- /// </summary>
- /// <param name="strColor">设置16进制颜色 [返回RGB]</param>
- /// <returns></returns>
- public static System.Drawing.Color colorHx16toRGB(string strHxColor)
- {
- try
- {
- if (strHxColor.Length == 0)
- {//如果为空
- return System.Drawing.Color.FromArgb(255, 255, 204);//设为白色
- }
- else
- {//转换颜色
- return System.Drawing.Color.FromArgb(System.Int32.Parse(strHxColor.Substring(1, 2), System.Globalization.NumberStyles.AllowHexSpecifier), System.Int32.Parse(strHxColor.Substring(3, 2), System.Globalization.NumberStyles.AllowHexSpecifier), System.Int32.Parse(strHxColor.Substring(5, 2), System.Globalization.NumberStyles.AllowHexSpecifier));
- }
- }
- catch
- {//设为白色
- return System.Drawing.Color.FromArgb(255, 255, 204);
- }
- }
- /// <summary>
- /// [颜色:RGB转成16进制]
- /// </summary>
- /// <param name="R">红 int</param>
- /// <param name="G">绿 int</param>
- /// <param name="B">蓝 int</param>
- /// <returns></returns>
- public static string colorRGBtoHx16(int R, int G, int B)
- {
- return System.Drawing.ColorTranslator.ToHtml(System.Drawing.Color.FromArgb(R, G, B));
- }
- //XmlTree_STDlist、XmlTree_MaxEDSRules、XmlTree_ZeroElementRules和 ConstantsPage页
- void LoadXmlToTreeControl(XmlDocument xml, TreeNodeCollection XmlTree_STDlist, TreeNodeCollection XmlTree_MaxEDSRules, TreeNodeCollection XmlTree_ZeroElementRules)
- {
- XmlNode root = xml.SelectSingleNode("XMLData");
- XmlNodeList root2 = root.SelectNodes("Collection");
- for (int j = 0; j < root2.Count; j++)
- {
- if (root2[j].Attributes["RegName"].Value.ToString() == "STDList")
- {
- XmlNodeList childlist = root2[j].ChildNodes;
- for (int i = 0; i < childlist.Count; i++)
- {
- TreeNode new_child = new TreeNode();//定义一个TreeNode节点对象
- //BSE、化学式、元素
- string strBseValue = string.Empty;
- string strFormula = string.Empty;
- string strElement = string.Empty;
- if (childlist[i].Attributes["BSE"] != null)
- {
- strBseValue = childlist[i].Attributes["BSE"].Value;
- }
- if (childlist[i].Attributes["Formula"] != null)
- {
- strFormula = childlist[i].Attributes["Formula"].Value;
- }
- if (childlist[i].Attributes["Element"] != null)
- {
- strElement = childlist[i].Attributes["Element"].Value;
- }
- new_child.Name = childlist[i].Attributes["Hardness"].Value + "_" + childlist[i].Attributes["Density"].Value + "_" + childlist[i].Attributes["Electrical_conductivity"].Value + "_" + strBseValue + "_" + strFormula + "_" + strElement + "$" + childlist[i].Attributes["KeyElementList"].Value + "$" + childlist[i].Attributes["SubElementList"].Value;
- new_child.Text = childlist[i].Attributes["StrName"].Value;
- new_child.Tag = childlist[i].Attributes["Expression"].Value;
- new_child.ToolTipText = childlist[i].Attributes["STDId"].Value;
- new_child.BackColor = colorHx16toRGB(childlist[i].Attributes["Color"].Value);
- XmlTree_STDlist.Add(new_child);
- }
- }
- if (root2[j].Attributes["RegName"].Value.ToString() == "ZeroElementRules")
- {
- XmlNodeList childlist = root2[j].ChildNodes;
- for (int i = 0; i < childlist.Count; i++)
- {
- TreeNode new_child = new TreeNode();//定义一个TreeNode节点对象
- new_child.Text = childlist[i].Attributes["ZeroElement"].Value+"=0";
- new_child.Tag = childlist[i].Attributes["Expression"].Value;
- XmlTree_ZeroElementRules.Add(new_child);
- }
- }
- if (root2[j].Attributes["RegName"].Value.ToString() == "MaxEDSRules")
- {
- XmlNodeList childlist = root2[j].ChildNodes;
- if (childlist.Count != 0)
- {
- for (int i = 0; i < childlist.Count; i++)
- {
- TreeNode new_child = new TreeNode();//定义一个TreeNode节点对象
- //new_child.Name = childlist[i].Attributes["MaxEDSTime"].Value;
- new_child.Tag = childlist[i].Attributes["Expression"].Value;
- new_child.Text = "Rule" + i.ToString();
- XmlTree_MaxEDSRules.Add(new_child);
- }
- if (childlist[0].Attributes["MaxEDSTime"] != null)
- {
- textBox_MaxEDSTime.Text = childlist[0].Attributes["MaxEDSTime"].Value;
- }
- }
- }
- }
- XmlNode root3 = root.SelectSingleNode("Member");
- string ConstantsStr = root3.Attributes["value"].Value;
- ConstantsStr = ConstantsStr.Replace(" ", "");
- string[] ConstantsStr2 = ConstantsStr.Split(',');
- this.comboBox_Constants.Items.Clear();
- this.comboBox_Constants.Items.AddRange(ConstantsStr2);
- List<string> Constantslist = new List<string>();
- for (int i = 0; i < ConstantsStr2.Length; i++)
- {
- Constantslist.AddRange(ConstantsStr2[i].Split('='));
- }
- for (int i = 0; i < Constantslist.Count; i += 2)
- {
- if (Constantslist[i].Contains("MAC#0"))
- {
- this.checkBox_0.Checked = true;
- this.textBox_0.ReadOnly = false;
- this.textBox_0.Text = Constantslist[i + 1];
- }
- else if (Constantslist[i].Contains("MAC#1"))
- {
- this.checkBox_1.Checked = true;
- this.textBox_1.ReadOnly = false;
- this.textBox_1.Text = Constantslist[i + 1];
- }
- else if (Constantslist[i].Contains("MAC#2"))
- {
- this.checkBox_2.Checked = true;
- this.textBox_2.ReadOnly = false;
- this.textBox_2.Text = Constantslist[i + 1];
- }
- else if (Constantslist[i].Contains("MAC#3"))
- {
- this.checkBox_3.Checked = true;
- this.textBox_3.ReadOnly = false;
- this.textBox_3.Text = Constantslist[i + 1];
- }
- else if (Constantslist[i].Contains("MAC#4"))
- {
- this.checkBox_4.Checked = true;
- this.textBox_4.ReadOnly = false;
- this.textBox_4.Text = Constantslist[i + 1];
- }
- else if (Constantslist[i].Contains("MAC#5"))
- {
- this.checkBox_5.Checked = true;
- this.textBox_5.ReadOnly = false;
- this.textBox_5.Text = Constantslist[i + 1];
- }
- else if (Constantslist[i].Contains("MAC#6"))
- {
- this.checkBox_6.Checked = true;
- this.textBox_6.ReadOnly = false;
- this.textBox_6.Text = Constantslist[i + 1];
- }
- else if (Constantslist[i].Contains("MAC#7"))
- {
- this.checkBox_7.Checked = true;
- this.textBox_7.ReadOnly = false;
- this.textBox_7.Text = Constantslist[i + 1];
- }
- else if (Constantslist[i].Contains("MAC#8"))
- {
- this.checkBox_8.Checked = true;
- this.textBox_8.ReadOnly = false;
- this.textBox_8.Text = Constantslist[i + 1];
- }
- else if (Constantslist[i].Contains("MAC#9"))
- {
- this.checkBox_9.Checked = true;
- this.textBox_9.ReadOnly = false;
- this.textBox_9.Text = Constantslist[i + 1];
- }
- }
- }
- private void comboBox_Elem1_SelectedIndexChanged(object sender, EventArgs e)
- {
- string newStr = comboBox_Elem1.SelectedItem.ToString();
- int index = textbox_STDEditor.SelectionStart;
- textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, newStr);
- textbox_STDEditor.Focus();
- textbox_STDEditor.Select(index + newStr.Length, 0);
- textbox_STDEditor.ScrollToCaret();
- }
- private void comboBox_Elem2_SelectedIndexChanged(object sender, EventArgs e)
- {
- string newStr = comboBox_Elem.SelectedItem.ToString();
- int index = textbox_STDEditor.SelectionStart;
- textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, newStr);
- textbox_STDEditor.Focus();
- textbox_STDEditor.Select(index + newStr.Length, 0);
- textbox_STDEditor.ScrollToCaret();
- }
- private void comboBox_ImgProperty_SelectedIndexChanged(object sender, EventArgs e)
- {
- string newStr = comboBox_ImgProperty.SelectedItem.ToString();
- int index = textbox_STDEditor.SelectionStart;
- textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, newStr);
- textbox_STDEditor.Focus();
- textbox_STDEditor.Select(index + newStr.Length, 0);
- textbox_STDEditor.ScrollToCaret();
- }
- private void button_Plus_Click(object sender, EventArgs e)
- {
- //textbox_STDEditor 中的光标
- int index = textbox_STDEditor.SelectionStart;
- textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "+");
- textbox_STDEditor.Focus();
- textbox_STDEditor.Select(index+1,0);
- textbox_STDEditor.ScrollToCaret();
- }
- private void button_Subtract_Click(object sender, EventArgs e)
- {
- //textbox_STDEditor 中的光标
- int index = textbox_STDEditor.SelectionStart;
- textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "-");
- textbox_STDEditor.Focus();
- textbox_STDEditor.Select(index + 1, 0);
- textbox_STDEditor.ScrollToCaret();
- }
- private void button_Multiply_Click(object sender, EventArgs e)
- {
- //textbox_STDEditor 中的光标
- int index = textbox_STDEditor.SelectionStart;
- textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "*");
- textbox_STDEditor.Focus();
- textbox_STDEditor.Select(index + 1, 0);
- textbox_STDEditor.ScrollToCaret();
- }
- private void button_Divide_Click(object sender, EventArgs e)
- {
- //textbox_STDEditor 中的光标
- int index = textbox_STDEditor.SelectionStart;
- textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "/");
- textbox_STDEditor.Focus();
- textbox_STDEditor.Select(index + 1, 0);
- textbox_STDEditor.ScrollToCaret(); ;
- }
- private void button_More_Click(object sender, EventArgs e)
- {
- //textbox_STDEditor 中的光标
- int index = textbox_STDEditor.SelectionStart;
- textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, ">");
- textbox_STDEditor.Focus();
- textbox_STDEditor.Select(index + 1, 0);
- textbox_STDEditor.ScrollToCaret();
- }
- private void button_Less_Click(object sender, EventArgs e)
- {
- //textbox_STDEditor 中的光标
- int index = textbox_STDEditor.SelectionStart;
- textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "<");
- textbox_STDEditor.Focus();
- textbox_STDEditor.Select(index + 1, 0);
- textbox_STDEditor.ScrollToCaret();
- }
- private void button_LeftParenthesis_Click(object sender, EventArgs e)
- {
- //textbox_STDEditor 中的光标
- int index = textbox_STDEditor.SelectionStart;
- textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "(");
- textbox_STDEditor.Focus();
- textbox_STDEditor.Select(index + 1, 0);
- textbox_STDEditor.ScrollToCaret();
- }
- private void button_RightParenthesis_Click(object sender, EventArgs e)
- {
- //textbox_STDEditor 中的光标
- int index = textbox_STDEditor.SelectionStart;
- textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, ")");
- textbox_STDEditor.Focus();
- textbox_STDEditor.Select(index + 1, 0);
- textbox_STDEditor.ScrollToCaret();
- }
- private void button_Equal_Click(object sender, EventArgs e)
- {
- //textbox_STDEditor 中的光标
- int index = textbox_STDEditor.SelectionStart;
- textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "=");
- textbox_STDEditor.Focus();
- textbox_STDEditor.Select(index + 1, 0);
- textbox_STDEditor.ScrollToCaret();
- }
- //除选中点以外其它节点前景色置灰
- private void SetGrayExceptSelectedNode(TreeView Tree, TreeNode SelectedNode)
- {
- foreach (TreeNode node in Tree.Nodes)
- {
- if (node != SelectedNode)
- {
- node.ForeColor = Color.Gray;
- }
- }
- }
- //恢复所有节点颜色为可用
- private void SetBlackAllNodes(TreeView Tree)
- {
- foreach (TreeNode node in Tree.Nodes)
- {
- node.ForeColor = Color.Black;
- }
- }
- //点击节点
- private void XmlTree_STDlist_MouseClick(object sender, MouseEventArgs e)
- {
- //if (e.Button == MouseButtons.Left)
- //{
- // Point ClickPoint = new Point(e.X, e.Y);
- // TreeNode CurrentNode = XmlTree_STDlist.GetNodeAt(ClickPoint);
- // if (CurrentNode != null)//判断你点的是不是一个节点
- // {
- // if (XmlTree_STDlist.SelectedNode != null&& XmlTree_STDlist.SelectedNode != CurrentNode)
- // {
- // //判断Hardness、Density、Electrical_conductivity
- // double dHardness = 0, dDensity = 0, dElectrical_conductivity = 0;
- // if (!double.TryParse(textBox_Hardness.Text, out dHardness))
- // {
- // MessageBox.Show("硬度输入错误,请输入数字!");
- // SetGrayExceptSelectedNode(XmlTree_STDlist, XmlTree_STDlist.SelectedNode);
- // return;
- // }
- // if (!double.TryParse(textBox_Density.Text, out dDensity))
- // {
- // MessageBox.Show("密度输入错误,请输入数字!");
- // SetGrayExceptSelectedNode(XmlTree_STDlist, XmlTree_STDlist.SelectedNode);
- // return;
- // }
- // if (!double.TryParse(textBox_Electrical_conductivity.Text, out dElectrical_conductivity))
- // {
- // MessageBox.Show("导电性输入错误,请输入数字!");
- // SetGrayExceptSelectedNode(XmlTree_STDlist, XmlTree_STDlist.SelectedNode);
- // return;
- // }
- // //判断textbox_STDEditor
- // if (!Checktextbox_STDEditor())
- // {
- // SetGrayExceptSelectedNode(XmlTree_STDlist, XmlTree_STDlist.SelectedNode);
- // return;
- // }
- // XmlTree_STDlist_SaveBeforeMouseClick(e);
- // }
- // SetBlackAllNodes(XmlTree_STDlist);
- // XmlTree_STDlist.SelectedNode = CurrentNode;
- // XmlTree_STDlist.LabelEdit = true;
- // this.textbox_STDEditor.Text = XmlTree_STDlist.SelectedNode.Tag.ToString();
- // btn_dbs.BackColor = XmlTree_STDlist.SelectedNode.BackColor;
- // string[] strOther = XmlTree_STDlist.SelectedNode.Name.Split('_');
- // textBox_Hardness.Text = strOther[0];
- // textBox_Density.Text = strOther[1];
- // textBox_Electrical_conductivity.Text = strOther[2];
- // if (UpOrder.Enabled == false)
- // {
- // UpOrder.Enabled = true;
- // }
- // if (DownOrder.Enabled == false)
- // {
- // DownOrder.Enabled = true;
- // }
- // if (XmlTree_STDlist.SelectedNode.PrevNode == null)
- // {
- // UpOrder.Enabled = false;
- // }
- // else if (XmlTree_STDlist.SelectedNode.NextNode == null)
- // {
- // DownOrder.Enabled = false;
- // }
- // }
- //}
- //if (e.Button == MouseButtons.Right)
- //{
- // Point ClickPoint = new Point(e.X, e.Y);
- // TreeNode CurrentNode = XmlTree.GetNodeAt(ClickPoint);
- // if (CurrentNode != null)//判断你点的是不是一个节点
- // {
- // XmlTree.SelectedNode = CurrentNode;//选中这个节点
- // XmlTree.LabelEdit = true;
- // this.textbox_STDEditor.Text = XmlTree.SelectedNode.Tag.ToString();
- // }
- //}
- }
- //XmlTree_STDlist点击节点前保存数据-Hardness、Density、Electrical_conductivity、textbox_STDEditor
- void XmlTree_STDlist_BeforeMouseClick(MouseEventArgs e)
- {
- if ((this.textbox_STDEditor.Text != null) && (XmlTree_STDlist.SelectedNode != null))
- {
- XmlTree_STDlist.SelectedNode.Tag = this.textbox_STDEditor.Text;
- XmlTree_STDlist.SelectedNode.Name = textBox_Hardness.Text + "_" + textBox_Density.Text + "_" + textBox_Electrical_conductivity.Text + "_" + textBox_BSEValue.Text + "_" + textBox_Formula.Text + "_" + textBox_Element.Text; ;
- string sKeyElements = "";
- for (int i = 0; i < dataGridView_KeyElements.Columns.Count; i++)
- {
- sKeyElements += dataGridView_KeyElements.Rows[0].Cells[i].Value.ToString() + ",";
- }
- if (sKeyElements.Length > 0)
- {
- sKeyElements = sKeyElements.Substring(0, sKeyElements.Length - 1);
- }
- string sSubElements = "";
- for (int i = 0; i < dataGridView_SubElements.Columns.Count; i++)
- {
- sSubElements += dataGridView_SubElements.Rows[0].Cells[i].Value.ToString() + ",";
- }
- if (sSubElements.Length > 0)
- {
- sSubElements = sSubElements.Substring(0, sSubElements.Length - 1);
- }
- XmlTree_STDlist.SelectedNode.Name += "$" + sKeyElements + "$" + sSubElements;
- }
- }
- //删除
- private void DeleteTreeNode_Click(object sender, EventArgs e)
- {
- try
- {
- TreeView XmlTree = (TreeView)XmlTreeMenuStrip.SourceControl;
- if (XmlTree.SelectedNode != null)
- {
- if (XmlTree != null)
- {
- if (XmlTree.SelectedNode.NextNode != null)
- {
- TreeNode Temp = XmlTree.SelectedNode.NextNode;
- XmlTree.SelectedNode.Remove();
- XmlTree.SelectedNode = Temp;
- }
- else if (XmlTree.SelectedNode.PrevNode != null)
- {
- TreeNode Temp = XmlTree.SelectedNode.PrevNode;
- XmlTree.SelectedNode.Remove();
- XmlTree.SelectedNode = Temp;
- }
- else
- {
- XmlTree.SelectedNode.Remove();
- XmlTree.SelectedNode = null;
- if (XmlTree.Name == "XmlTree_STDlist")
- {
- textbox_STDEditor.Text = "";
- textBox_Density.Text = "";
- textBox_Electrical_conductivity.Text = "";
- textBox_BSEValue.Text = "";
- textBox_Formula.Text = "";
- textBox_Element.Text = "";
- textBox_Hardness.Text = "";
- btn_dbs.BackColor = Color.White;
- }
- if (XmlTree.Name == "XmlTree_MaxEDSRules")
- {
- textbox_STDEditor.Text = "";
- textBox_MaxEDSTime.Text = "";
- }
- if (XmlTree.Name == "XmlTree_ZeroElementRules")
- {
- textbox_STDEditor.Text = "";
- }
- }
- }
- }
- else
- {
- MessageBox.Show(table["message1"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.ToString(), table["message32"].ToString());
- }
- }
- //新建
- private void AddTreeNode_Click(object sender, EventArgs e)
- {
- try
- {
- if (tabControl_Rules.SelectedIndex == 0)
- {
- //保存节点当前数据
- if (XmlTree_STDlist.SelectedNode != null)
- {
- //判断Hardness、Density、Electrical_conductivity
- double dHardness = 0, dDensity = 0, dElectrical_conductivity = 0;
- if (!double.TryParse(textBox_Hardness.Text, out dHardness) || (double.Parse(textBox_Hardness.Text) <= 0))
- {
- textBox_Hardness.Focus();
- textBox_Hardness.SelectAll();
- MessageBox.Show(table["message2"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- if (!double.TryParse(textBox_Density.Text, out dDensity)||double.Parse(textBox_Density.Text)<=0)
- {
- textBox_Density.Focus();
- textBox_Density.SelectAll();
- MessageBox.Show(table["message3"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- if (!double.TryParse(textBox_Electrical_conductivity.Text, out dElectrical_conductivity)||double.Parse(textBox_Electrical_conductivity.Text)<=0)
- {
- textBox_Electrical_conductivity.Focus();
- textBox_Electrical_conductivity.SelectAll();
- MessageBox.Show(table["message4"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- if (textBox_BSEValue.Text.LastIndexOf("_") > 0)
- {
- MessageBox.Show(table["message5"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- textBox_BSEValue.Focus();
- return;
- }
- if (textBox_Formula.Text.LastIndexOf("_") > 0)
- {
- MessageBox.Show(table["message6"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- textBox_Formula.Focus();
- return;
- }
- if (textBox_Element.Text.LastIndexOf("_") > 0)
- {
- MessageBox.Show(table["message7"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- textBox_Element.Focus();
- return;
- }
- //判断textbox_STDEditor
- if (!Checktextbox_STDEditor())
- {
- return;
- }
- XmlTree_STDlist.SelectedNode.Tag = this.textbox_STDEditor.Text;
- XmlTree_STDlist.SelectedNode.Name = textBox_Hardness.Text + "_" + textBox_Density.Text + "_" + textBox_Electrical_conductivity.Text + "_" + textBox_BSEValue.Text + "_" + textBox_Formula.Text + "_" + textBox_Element.Text; ;
- string sKeyElements = "";
- for (int i = 0; i < dataGridView_KeyElements.Columns.Count; i++)
- {
- sKeyElements += dataGridView_KeyElements.Rows[0].Cells[i].Value.ToString() + ",";
- }
- if (sKeyElements.Length > 0)
- {
- sKeyElements = sKeyElements.Substring(0, sKeyElements.Length - 1);
- }
- string sSubElements = "";
- for (int i = 0; i < dataGridView_SubElements.Columns.Count; i++)
- {
- sSubElements += dataGridView_SubElements.Rows[0].Cells[i].Value.ToString() + ",";
- }
- if (sSubElements.Length > 0)
- {
- sSubElements = sSubElements.Substring(0, sSubElements.Length - 1);
- }
- XmlTree_STDlist.SelectedNode.Name += "$" + sKeyElements + "$" + sSubElements;
- }
- }
- else if (tabControl_Rules.SelectedIndex == 1)
- {
- if (XmlTree_MaxEDSRules.SelectedNode != null)
- {
- //判断MaxEDSTime
- double dMaxEDSTime = 0;
- if (!double.TryParse(textBox_MaxEDSTime.Text, out dMaxEDSTime) || double.Parse(textBox_MaxEDSTime.Text) <= 0)
- {
- MessageBox.Show(table["message8"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- //判断textbox_STDEditor
- if (!Checktextbox_STDEditor())
- {
- return;
- }
- XmlTree_MaxEDSRules.SelectedNode.Tag = this.textbox_STDEditor.Text;
- //XmlTree_MaxEDSRules.SelectedNode.Name = textBox_MaxEDSTime.Text;
- }
- }
- else if (tabControl_Rules.SelectedIndex == 2)
- {
- if (XmlTree_ZeroElementRules.SelectedNode != null)
- {
- if (XmlTree_ZeroElementRules.SelectedNode.Text.Contains("="))
- {
- if (!comboBox_PeriodicTable.Items.Contains(XmlTree_ZeroElementRules.SelectedNode.Text.Split('=')[0]))
- {
- MessageBox.Show(XmlTree_ZeroElementRules.SelectedNode.Text + table["message9"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- }
- else
- {
- MessageBox.Show(XmlTree_ZeroElementRules.SelectedNode.Text + table["message9"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- //判断textbox_STDEditor
- if (!Checktextbox_STDEditor())
- {
- return;
- }
- XmlTree_ZeroElementRules.SelectedNode.Tag = this.textbox_STDEditor.Text;
- }
- }
- dataGridView_KeyElements.Rows.Clear();
- dataGridView_KeyElements.Columns.Clear();
- dataGridView_SubElements.Rows.Clear();
- dataGridView_SubElements.Columns.Clear();
- TreeNode new_child = new TreeNode();//定义一个TreeNode节点对象
- TreeView XmlTree = (TreeView)XmlTreeMenuStrip.SourceControl;
- if (XmlTreeMenuStrip.SourceControl.Name == "XmlTree_STDlist")
- {
- new_child.Name = "1_1_1$$";
- new_child.Text = "new strName";
- new_child.Tag = "NewRules";
- textbox_STDEditor.Text = "NewRules";
- textBox_Density.Text = "1";
- textBox_Electrical_conductivity.Text = "1";
- textBox_Hardness.Text = "1";
- new_child.BackColor = Color.White;
- int STDId = 1;
- for (int i = 0; i < XmlTree_STDlist.Nodes.Count; i++)
- {
- if (STDId < int.Parse(XmlTree_STDlist.Nodes[i].ToolTipText))
- {
- STDId = int.Parse(XmlTree_STDlist.Nodes[i].ToolTipText);
- }
- }
- new_child.ToolTipText = (STDId+1).ToString();
- }
- if (XmlTreeMenuStrip.SourceControl.Name == "XmlTree_MaxEDSRules")
- {
- int Number = XmlTree.Nodes.Count;
- for (int num = 0; num < XmlTree.Nodes.Count; num++)
- {
- string aa = XmlTree.Nodes[num].Text.ToString().Substring(XmlTree.Nodes[num].Text.Length - 1, 1);
- int tp = int.Parse(XmlTree.Nodes[num].Text.ToString().Substring(XmlTree.Nodes[num].Text.Length - 1, 1));
- if (Number < tp) Number = tp;
- }
- new_child.Text = "Rule" + Number.ToString();
- new_child.Tag = "NewRules";
- textbox_STDEditor.Text = "NewRules";
- }
- if (XmlTreeMenuStrip.SourceControl.Name == "XmlTree_ZeroElementRules")
- {
- new_child.Text = "NewElement=0";
- new_child.Tag = "NewRules";
- textbox_STDEditor.Text = "NewRules";
- }
- XmlTree.Nodes.Add(new_child);
- XmlTree.SelectedNode = null;
- XmlTree.SelectedNode = new_child;
- //添加STDXray信息
- AddSTDXray(XmlTree.SelectedNode, xrayByteData);
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.ToString(), table["message32"].ToString());
- }
- }
- //双击节点
- private void XmlTree_STDlist_MouseDoubleClick(object sender, MouseEventArgs e)
- {
- if (e.Button == MouseButtons.Left)
- {
- Point ClickPoint = new Point(e.X, e.Y);
- TreeNode CurrentNode = XmlTree_STDlist.GetNodeAt(ClickPoint);
- if (CurrentNode != null)//判断你点的是不是一个节点
- {
- XmlTree_STDlist.SelectedNode = CurrentNode;//选中这个节点
- XmlTree_STDlist.LabelEdit = true;
- XmlTree_STDlist.SelectedNode.BeginEdit();
- }
- }
- }
- //保存xmltree内容到xml文件
- void SaveXmlTreeDataToXml(string Address)
- {
- XDocument xdoc = XDocument.Load(Address);
- IEnumerable<XElement> elements = from ele in xdoc.Descendants("XMLData") select ele;
- foreach (var ele in elements)
- {
- if (ele != null)
- {
- ele.RemoveAll();
- }
- }
- string value = "";
- foreach (var str in comboBox_Constants.Items)
- {
- value += str + ",";
- }
- if (value != "")
- {
- value = value.Substring(0, value.Length - 1);
- }
- XElement Constant = new XElement("Member");
- Constant.SetAttributeValue("RegName", "Constants");
- Constant.SetAttributeValue("value", value);
- elements.ElementAt(0).Add(Constant);
- XElement ZeroElement = new XElement("Collection");
- ZeroElement.SetAttributeValue("RegName", "ZeroElementRules");
- elements.ElementAt(0).Add(ZeroElement);
- for (int num = 0; num < XmlTree_ZeroElementRules.Nodes.Count; num++)
- {
- string UsingElementList = "";
- string UsingImgPropertyList = "";
- string UsingOtherPropertyList = "";
- List<string> UsingElementL = new List<string>();
- List<string> UsingImgPropertyL = new List<string>();
- List<string> UsingOtherPropertyL = new List<string>();
- string str_RemoveBlank = "";
- //forth_elem干扰or分隔符,故先行去掉
- if (XmlTree_ZeroElementRules.Nodes[num].Tag.ToString().Contains("forth_elem"))
- {
- str_RemoveBlank = str_RemoveBlank.Replace("forth_elem", "");
- UsingOtherPropertyL.Add("forth_elem");
- }
- str_RemoveBlank = XmlTree_ZeroElementRules.Nodes[num].Tag.ToString().Replace(" ", "");
- string[] str_Removeand = System.Text.RegularExpressions.Regex.Split(str_RemoveBlank, "and", System.Text.RegularExpressions.RegexOptions.None);
- List<string> str_Removeandor = new List<string>();
- for (int i = 0; i < str_Removeand.Length; i++)
- {
- str_Removeandor.AddRange(System.Text.RegularExpressions.Regex.Split(str_Removeand[i], "or", System.Text.RegularExpressions.RegexOptions.None));
- }
- List<string> list_all = new List<string>();
- for (int i = 0; i < str_Removeandor.Count; i++)
- {
- list_all.AddRange(str_Removeandor[i].Split(new char[] { '+', '-', '*', '/', '=', '>', '<', '(', ')' }));
- }
- for (int i = 0; i < list_all.Count; i++)
- {
- //周期元素?
- if (this.comboBox_PeriodicTable.Items.Contains(list_all[i]))
- {
- if (!UsingElementL.Contains(list_all[i]))
- {
- UsingElementL.Add(list_all[i]);
- }
- }
- //first_elem?
- if (this.comboBox_Elem1.Items.Contains(list_all[i]))
- {
- if (!UsingOtherPropertyL.Contains(list_all[i]))
- {
- UsingOtherPropertyL.Add(list_all[i]);
- }
- }
- //Element1?
- if (this.comboBox_Elem.Items.Contains(list_all[i]))
- {
- if (!UsingOtherPropertyL.Contains(list_all[i]))
- {
- UsingOtherPropertyL.Add(list_all[i]);
- }
- }
- //其它元素?
- if (this.comboBox_ImgProperty.Items.Contains(list_all[i]))
- {
- if (!UsingImgPropertyL.Contains(list_all[i]))
- {
- UsingImgPropertyL.Add(list_all[i]);
- }
- }
- }
- if (UsingElementL.Count > 0)
- {
- for (int i = 0; i < UsingElementL.Count - 1; i++)
- {
- UsingElementList += UsingElementL[i] + ",";
- }
- UsingElementList += UsingElementL[UsingElementL.Count - 1];
- }
- if (UsingImgPropertyL.Count > 0)
- {
- for (int i = 0; i < UsingImgPropertyL.Count - 1; i++)
- {
- UsingImgPropertyList += UsingImgPropertyL[i] + ",";
- }
- UsingImgPropertyList += UsingImgPropertyL[UsingImgPropertyL.Count - 1];
- }
- if (UsingOtherPropertyL.Count > 0)
- {
- for (int i = 0; i < UsingOtherPropertyL.Count - 1; i++)
- {
- UsingOtherPropertyList += UsingOtherPropertyL[i] + ",";
- }
- UsingOtherPropertyList += UsingOtherPropertyL[UsingOtherPropertyL.Count - 1];
- }
- XElement EleName = new XElement("Member");
- EleName.SetAttributeValue("ZeroElement", XmlTree_ZeroElementRules.Nodes[num].Text.Split('=')[0]);
- EleName.SetAttributeValue("UsingElementList", UsingElementList);
- EleName.SetAttributeValue("UsingImgPropertyList", UsingImgPropertyList);
- EleName.SetAttributeValue("UsingOtherPropertyList", UsingOtherPropertyList);
- EleName.SetAttributeValue("Expression", XmlTree_ZeroElementRules.Nodes[num].Tag);
- ZeroElement.Add(EleName);
- }
- XElement MaxEDS = new XElement("Collection");
- MaxEDS.SetAttributeValue("RegName", "MaxEDSRules");
- elements.ElementAt(0).Add(MaxEDS);
- for (int num = 0; num < XmlTree_MaxEDSRules.Nodes.Count; num++)
- {
- string UsingElementList = "";
- string UsingImgPropertyList = "";
- string UsingOtherPropertyList = "";
- List<string> UsingElementL = new List<string>();
- List<string> UsingImgPropertyL = new List<string>();
- List<string> UsingOtherPropertyL = new List<string>();
- string str_RemoveBlank = "";
- //forth_elem干扰or分隔符,故先行去掉
- if (XmlTree_MaxEDSRules.Nodes[num].Tag.ToString().Contains("forth_elem"))
- {
- str_RemoveBlank = str_RemoveBlank.Replace("forth_elem", "");
- UsingOtherPropertyList = "forth_elem,";
- }
- str_RemoveBlank = XmlTree_MaxEDSRules.Nodes[num].Tag.ToString().Replace(" ", "");
- string[] str_Removeand = System.Text.RegularExpressions.Regex.Split(str_RemoveBlank, "and", System.Text.RegularExpressions.RegexOptions.None);
- List<string> str_Removeandor = new List<string>();
- for (int i = 0; i < str_Removeand.Length; i++)
- {
- str_Removeandor.AddRange(System.Text.RegularExpressions.Regex.Split(str_Removeand[i], "or", System.Text.RegularExpressions.RegexOptions.None));
- }
- List<string> list_all = new List<string>();
- for (int i = 0; i < str_Removeandor.Count; i++)
- {
- list_all.AddRange(str_Removeandor[i].Split(new char[] { '+', '-', '*', '/', '=', '>', '<', '(', ')' }));
- }
- for (int i = 0; i < list_all.Count; i++)
- {
- //周期元素?
- if (this.comboBox_PeriodicTable.Items.Contains(list_all[i]))
- {
- if (!UsingElementL.Contains(list_all[i]))
- {
- UsingElementL.Add(list_all[i]);
- }
- }
- //first_elem?
- if (this.comboBox_Elem1.Items.Contains(list_all[i]))
- {
- if (!UsingOtherPropertyL.Contains(list_all[i]))
- {
- UsingOtherPropertyL.Add(list_all[i]);
- }
- }
- //Element1?
- if (this.comboBox_Elem.Items.Contains(list_all[i]))
- {
- if (!UsingOtherPropertyL.Contains(list_all[i]))
- {
- UsingOtherPropertyL.Add(list_all[i]);
- }
- }
- //其它元素?
- if (this.comboBox_ImgProperty.Items.Contains(list_all[i]))
- {
- if (!UsingImgPropertyL.Contains(list_all[i]))
- {
- UsingImgPropertyL.Add(list_all[i]);
- }
- }
- }
- if (UsingElementL.Count > 0)
- {
- for (int i = 0; i < UsingElementL.Count - 1; i++)
- {
- UsingElementList += UsingElementL[i] + ",";
- }
- UsingElementList += UsingElementL[UsingElementL.Count - 1];
- }
- if (UsingImgPropertyL.Count > 0)
- {
- for (int i = 0; i < UsingImgPropertyL.Count - 1; i++)
- {
- UsingImgPropertyList += UsingImgPropertyL[i] + ",";
- }
- UsingImgPropertyList += UsingImgPropertyL[UsingImgPropertyL.Count - 1];
- }
- if (UsingOtherPropertyL.Count > 0)
- {
- for (int i = 0; i < UsingOtherPropertyL.Count - 1; i++)
- {
- UsingOtherPropertyList += UsingOtherPropertyL[i] + ",";
- }
- UsingOtherPropertyList += UsingOtherPropertyL[UsingOtherPropertyL.Count - 1];
- }
- XElement EleName = new XElement("Member");
- //EleName.SetAttributeValue("MaxEDSTime", XmlTree_MaxEDSRules.Nodes[num].Name);
- EleName.SetAttributeValue("MaxEDSTime", textBox_MaxEDSTime.Text);
- EleName.SetAttributeValue("UsingElementList", UsingElementList);
- EleName.SetAttributeValue("UsingImgPropertyList", UsingImgPropertyList);
- EleName.SetAttributeValue("UsingOtherPropertyList", UsingOtherPropertyList);
- EleName.SetAttributeValue("Expression", XmlTree_MaxEDSRules.Nodes[num].Tag);
- MaxEDS.Add(EleName);
- }
- XElement STD = new XElement("Collection");
- STD.SetAttributeValue("RegName", "STDList");
- elements.ElementAt(0).Add(STD);
- for (int num = 0; num < XmlTree_STDlist.Nodes.Count; num++)
- {
- string UsingElementList = "";
- string UsingImgPropertyList = "";
- string UsingOtherPropertyList = "";
- List<string> UsingElementL = new List<string>();
- List<string> UsingImgPropertyL = new List<string>();
- List<string> UsingOtherPropertyL = new List<string>();
- string str_RemoveBlank = "";
- //forth_elem干扰or分隔符,故先行去掉
- if (XmlTree_STDlist.Nodes[num].Tag.ToString().Contains("forth_elem"))
- {
- str_RemoveBlank = str_RemoveBlank.Replace("forth_elem", "");
- UsingOtherPropertyList = "forth_elem,";
- }
- str_RemoveBlank = XmlTree_STDlist.Nodes[num].Tag.ToString().Replace(" ", "");
- string[] str_Removeand = System.Text.RegularExpressions.Regex.Split(str_RemoveBlank, "and", System.Text.RegularExpressions.RegexOptions.None);
- List<string> str_Removeandor = new List<string>();
- for (int i = 0; i < str_Removeand.Length; i++)
- {
- str_Removeandor.AddRange(System.Text.RegularExpressions.Regex.Split(str_Removeand[i], "or", System.Text.RegularExpressions.RegexOptions.None));
- }
- List<string> list_all = new List<string>();
- for (int i = 0; i < str_Removeandor.Count; i++)
- {
- list_all.AddRange(str_Removeandor[i].Split(new char[] { '+', '-', '*', '/', '=', '>', '<', '(', ')' }));
- }
- for (int i = 0; i < list_all.Count; i++)
- {
- //周期元素?
- if (this.comboBox_PeriodicTable.Items.Contains(list_all[i]))
- {
- if (!UsingElementL.Contains(list_all[i]))
- {
- UsingElementL.Add(list_all[i]);
- }
- }
- //first_elem?
- if (this.comboBox_Elem1.Items.Contains(list_all[i]))
- {
- if (!UsingOtherPropertyL.Contains(list_all[i]))
- {
- UsingOtherPropertyL.Add(list_all[i]);
- }
- }
- //Element1?
- if (this.comboBox_Elem.Items.Contains(list_all[i]))
- {
- if (!UsingOtherPropertyL.Contains(list_all[i]))
- {
- UsingOtherPropertyL.Add(list_all[i]);
- }
- }
- //其它元素?
- if (this.comboBox_ImgProperty.Items.Contains(list_all[i]))
- {
- if (!UsingImgPropertyL.Contains(list_all[i]))
- {
- UsingImgPropertyL.Add(list_all[i]);
- }
- }
- }
- if (UsingElementL.Count > 0)
- {
- for (int i = 0; i < UsingElementL.Count - 1; i++)
- {
- UsingElementList += UsingElementL[i] + ",";
- }
- UsingElementList += UsingElementL[UsingElementL.Count - 1];
- }
- if (UsingImgPropertyL.Count > 0)
- {
- for (int i = 0; i < UsingImgPropertyL.Count - 1; i++)
- {
- UsingImgPropertyList += UsingImgPropertyL[i] + ",";
- }
- UsingImgPropertyList += UsingImgPropertyL[UsingImgPropertyL.Count - 1];
- }
- if (UsingOtherPropertyL.Count > 0)
- {
- for (int i = 0; i < UsingOtherPropertyL.Count - 1; i++)
- {
- UsingOtherPropertyList += UsingOtherPropertyL[i] + ",";
- }
- UsingOtherPropertyList += UsingOtherPropertyL[UsingOtherPropertyL.Count - 1];
- }
- string[] str = XmlTree_STDlist.Nodes[num].Name.Split('$');
- string[] strOther = str[0].Split('_');
- XElement EleName = new XElement("Member");
- EleName.SetAttributeValue("STDId", XmlTree_STDlist.Nodes[num].ToolTipText);
- EleName.SetAttributeValue("StrName", XmlTree_STDlist.Nodes[num].Text);
- EleName.SetAttributeValue("Color", colorRGBtoHx16(XmlTree_STDlist.Nodes[num].BackColor.R, XmlTree_STDlist.Nodes[num].BackColor.G, XmlTree_STDlist.Nodes[num].BackColor.B));
- //EleName.SetAttributeValue("UsingElementList", UsingElementList);
- EleName.SetAttributeValue("KeyElementList", str[1]);
- EleName.SetAttributeValue("SubElementList", str[2]);
- EleName.SetAttributeValue("UsingImgPropertyList", UsingImgPropertyList);
- EleName.SetAttributeValue("UsingOtherPropertyList", UsingOtherPropertyList);
- EleName.SetAttributeValue("Expression", XmlTree_STDlist.Nodes[num].Tag);
- EleName.SetAttributeValue("Hardness", strOther[0]);
- EleName.SetAttributeValue("Density", strOther[1]);
- EleName.SetAttributeValue("Electrical_conductivity", strOther[2]);
- if (strOther.Length > 3)
- {
- EleName.SetAttributeValue("BSE", strOther[3]);
- EleName.SetAttributeValue("Formula", strOther[4]);
- EleName.SetAttributeValue("Element", strOther[5]);
- }
- else
- {
- EleName.SetAttributeValue("BSE", "");
- EleName.SetAttributeValue("Formula", "");
- EleName.SetAttributeValue("Element", "");
- }
- STD.Add(EleName);
- }
- xdoc.Save(Address);
- }
- //元素周期表开关
- private void PeriodicTableSwitch_Click(object sender, EventArgs e)
- {
- if (PeriodicTableSwitch.BackColor == SystemColors.Control)
- {
- panel_OTSPeriodicTable.Visible = true;
- this.Width = this.Width + panel_OTSPeriodicTable.Width + 5;
- PeriodicTableSwitch.BackColor = SystemColors.ControlDark;
- //if (Language == "English")
- //{
- // PeriodicTableSwitch.Text = "Close PeriodicTable";
- //}
- //else if(Language == "Chinese")
- //{
- // PeriodicTableSwitch.Text = "关闭元素周期表";
- //}
- }
- else if (PeriodicTableSwitch.BackColor == SystemColors.ControlDark)
- {
- panel_OTSPeriodicTable.Visible = false;
- this.Width = this.Width - panel_OTSPeriodicTable.Width - 5;
- PeriodicTableSwitch.BackColor = SystemColors.Control;
- //if (Language == "English")
- //{
- // PeriodicTableSwitch.Text = "Open PeriodicTable";
- //}
- //else if (Language == "Chinese")
- //{
- // PeriodicTableSwitch.Text = "打开元素周期表";
- //}
- //textbox_STDEditor.Focus();
- groupBox_XmlTree_MaxEDSRules.Focus();
- }
- }
- private void button_Ok_Click(object sender, EventArgs e)
- {
- if (tabControl_Rules.SelectedIndex == 0)
- {
- //保存节点当前数据
- if (XmlTree_STDlist.SelectedNode != null)
- {
- //判断Hardness、Density、Electrical_conductivity
- double dHardness = 0, dDensity = 0, dElectrical_conductivity = 0;
- if (!double.TryParse(textBox_Hardness.Text, out dHardness) || (double.Parse(textBox_Hardness.Text) <= 0))
- {
- textBox_Hardness.Focus();
- textBox_Hardness.SelectAll();
- MessageBox.Show(table["message10"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- if (!double.TryParse(textBox_Density.Text, out dDensity) || double.Parse(textBox_Density.Text) <= 0)
- {
- textBox_Density.Focus();
- textBox_Density.SelectAll();
- MessageBox.Show(table["message11"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- if (!double.TryParse(textBox_Electrical_conductivity.Text, out dElectrical_conductivity) || double.Parse(textBox_Electrical_conductivity.Text) <= 0)
- {
- textBox_Electrical_conductivity.Focus();
- textBox_Electrical_conductivity.SelectAll();
- MessageBox.Show(table["message12"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- if (textBox_BSEValue.Text.LastIndexOf("_") > 0)
- {
- textBox_BSEValue.Focus();
- textBox_BSEValue.SelectAll();
- MessageBox.Show(table["message13"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- textBox_BSEValue.Focus();
- return;
- }
- if (textBox_Formula.Text.LastIndexOf("_") > 0)
- {
- textBox_Formula.Focus();
- textBox_Formula.SelectAll();
- MessageBox.Show(table["message14"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- textBox_Formula.Focus();
- return;
- }
- if (textBox_Element.Text.LastIndexOf("_") > 0)
- {
- textBox_Element.Focus();
- textBox_Element.SelectAll();
- MessageBox.Show(table["message15"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- textBox_Element.Focus();
- return;
- }
- //判断textbox_STDEditor
- if (!Checktextbox_STDEditor())
- {
- return;
- }
- XmlTree_STDlist.SelectedNode.Tag = this.textbox_STDEditor.Text;
- XmlTree_STDlist.SelectedNode.Name = textBox_Hardness.Text + "_" + textBox_Density.Text + "_" + textBox_Electrical_conductivity.Text + "_" + textBox_BSEValue.Text + "_" + textBox_Formula.Text + "_" + textBox_Element.Text;
- string sKeyElements = "";
- for (int i = 0; i < dataGridView_KeyElements.Columns.Count; i++)
- {
- sKeyElements += dataGridView_KeyElements.Rows[0].Cells[i].Value.ToString() + ",";
- }
- if (sKeyElements.Length > 0)
- {
- sKeyElements = sKeyElements.Substring(0, sKeyElements.Length - 1);
- }
- string sSubElements = "";
- for (int i = 0; i < dataGridView_SubElements.Columns.Count; i++)
- {
- sSubElements += dataGridView_SubElements.Rows[0].Cells[i].Value.ToString() + ",";
- }
- if (sSubElements.Length > 0)
- {
- sSubElements = sSubElements.Substring(0, sSubElements.Length - 1);
- }
- XmlTree_STDlist.SelectedNode.Name += "$" + sKeyElements + "$" + sSubElements;
- }
- }
- else if (tabControl_Rules.SelectedIndex == 1)
- {
- if (XmlTree_MaxEDSRules.SelectedNode != null)
- {
- //判断MaxEDSTime
- double dMaxEDSTime = 0;
- if (!double.TryParse(textBox_MaxEDSTime.Text, out dMaxEDSTime) || double.Parse(textBox_MaxEDSTime.Text) <= 0)
- {
- textBox_MaxEDSTime.Focus();
- textBox_MaxEDSTime.SelectAll();
- MessageBox.Show(table["message16"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- //判断textbox_STDEditor
- if (!Checktextbox_STDEditor())
- {
- return;
- }
- XmlTree_MaxEDSRules.SelectedNode.Tag = this.textbox_STDEditor.Text;
- //XmlTree_MaxEDSRules.SelectedNode.Name = textBox_MaxEDSTime.Text;
- }
- }
- else if (tabControl_Rules.SelectedIndex == 2)
- {
- if (XmlTree_ZeroElementRules.SelectedNode != null)
- {
- if (XmlTree_ZeroElementRules.SelectedNode.Text.Contains("="))
- {
- if (!comboBox_PeriodicTable.Items.Contains(XmlTree_ZeroElementRules.SelectedNode.Text.Split('=')[0]))
- {
- MessageBox.Show(XmlTree_ZeroElementRules.SelectedNode.Text + table["message9"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- }
- else
- {
- MessageBox.Show(XmlTree_ZeroElementRules.SelectedNode.Text + table["message9"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- //判断textbox_STDEditor
- if (!Checktextbox_STDEditor())
- {
- return;
- }
- XmlTree_ZeroElementRules.SelectedNode.Tag = this.textbox_STDEditor.Text;
- }
- }
- string value = "";
- foreach (var str in comboBox_Constants.Items)
- {
- value += str + ",";
- }
- if (value != "")
- {
- value = value.Substring(0, value.Length - 1);
- }
- //string Address = Application.StartupPath + "\\Config\\SysData\\OTSParticleSTD.xml";
- //string Address = ".\\Config\\SysData\\OTSParticleSTD.xml";
- SaveXmlTreeDataToXml(Address);
- //保存STDXray信息至数据库
- SaveSTDXray();
- this.Close();
- }
- private void button_Cancel_Click(object sender, EventArgs e)
- {
- this.Close();
- }
- //元素下拉选择输入
- private void comboBox_PeriodicTable_SelectedIndexChanged(object sender, EventArgs e)
- {
- if (comboBox_PeriodicTable.Text != null && comboBox_PeriodicTable.SelectedItem != null)
- {
- string newStr = comboBox_PeriodicTable.SelectedItem.ToString();
- comboBox_PeriodicTable.Text = null;
- int index = textbox_STDEditor.SelectionStart;
- textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, newStr);
- textbox_STDEditor.Focus();
- textbox_STDEditor.Select(index + newStr.Length, 0);
- textbox_STDEditor.ScrollToCaret();
- }
- }
- //元素自身text按回车键输入
- private void comboBox_PeriodicTable_KeyDown(object sender, KeyEventArgs e)
- {
- if (e.KeyValue == 13)
- {
- if (comboBox_PeriodicTable.Text != null && comboBox_PeriodicTable.Text != "")
- {
- this.textbox_STDEditor.Text += comboBox_PeriodicTable.Text.ToString();
- comboBox_PeriodicTable.Text = null;
- }
- }
- }
- //表达式规则检查
- private bool Checktextbox_STDEditor()
- {
- if (textbox_STDEditor.Text == "" || textbox_STDEditor.Text == null)
- {
- textBox_MaxEDSTime.Focus();
- MessageBox.Show(table["message17"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- return false;
- }
- string str_RemoveBlank = textbox_STDEditor.Text.ToString().Replace(" ", "");
- str_RemoveBlank = str_RemoveBlank.Replace("\r\n", "");
- //分割符号检验
- string[] Symbol = { "and", "or", "+", "-", "*", "/", "=", ">", "<" };
- for (int i = 0; i < Symbol.Length; i++)
- {
- for (int j = 0; j < Symbol.Length; j++)
- {
- if ((Symbol[i] + Symbol[j]) != ">=" && (Symbol[i] + Symbol[j]) != "<=")
- {
- if (str_RemoveBlank.Contains(Symbol[i] + Symbol[j]))
- {
- MessageBox.Show(table["message18"].ToString() + Symbol[i] + Symbol[j], table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- return false;
- }
- }
- }
- if (str_RemoveBlank.Contains(Symbol[i] + ")") || str_RemoveBlank.Contains("(" + Symbol[i]))
- {
- MessageBox.Show(table["message18"].ToString() + Symbol[i] + ")", table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- return false;
- }
- if (str_RemoveBlank.Contains("(" + Symbol[i]))
- {
- MessageBox.Show(table["message18"].ToString() + "(" + Symbol[i], table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- return false;
- }
- }
- if ((str_RemoveBlank != null) && (str_RemoveBlank != ""))
- {
- //左右括号匹配检验
- int BracketsNum = 0;
- for (int i = 0; i < str_RemoveBlank.Length; i++)
- {
- if (str_RemoveBlank[i] == '(') BracketsNum++;
- if (str_RemoveBlank[i] == ')') BracketsNum--;
- }
- if (BracketsNum != 0)
- {
- MessageBox.Show(table["message19"].ToString(),table["message32"].ToString(),MessageBoxButtons.OK,MessageBoxIcon.Information);
- return false;
- }
- //首字符检测
- if ((str_RemoveBlank[0] == '+') || (str_RemoveBlank[0] == '-') || (str_RemoveBlank[0] == '*') || (str_RemoveBlank[0] == '/') || (str_RemoveBlank[0] == '>') || (str_RemoveBlank[0] == '<') || (str_RemoveBlank[0] == '=') || (str_RemoveBlank[0] == ')') || (str_RemoveBlank[str_RemoveBlank.Length - 1] == '('))
- {
- MessageBox.Show(table["message20"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- return false;
- }
- if (str_RemoveBlank.Length >= 3)
- {
- if ((str_RemoveBlank.Substring(0, 3) == "and") || (str_RemoveBlank.Substring(0, 3) == "end"))
- {
- MessageBox.Show(table["message20"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- return false;
- }
- }
- }
- //forth_elem干扰or分隔符,故先行去掉
- str_RemoveBlank = str_RemoveBlank.Replace("forth_elem", "");
- string[] str_Removeand = System.Text.RegularExpressions.Regex.Split(str_RemoveBlank, "and", System.Text.RegularExpressions.RegexOptions.None);
- List<string> str_Removeandor = new List<string>();
- for (int i = 0; i < str_Removeand.Length; i++)
- {
- str_Removeandor.AddRange(System.Text.RegularExpressions.Regex.Split(str_Removeand[i], "or", System.Text.RegularExpressions.RegexOptions.None));
- }
- List<string> list_all = new List<string>();
- for (int i = 0; i < str_Removeandor.Count; i++)
- {
- list_all.AddRange(str_Removeandor[i].Split(new char[] { '+', '-', '*', '/', '=', '>', '<', '(', ')' }));
- }
- //常量
- List<string> Constantslist = new List<string>();
- for (int j = 0; j < comboBox_Constants.Items.Count; j++)
- {
- Constantslist.Add(comboBox_Constants.Items[j].ToString().Split('=')[0]);
- }
- for (int i = 0; i < list_all.Count; i++)
- {
- //周期元素?
- if (this.comboBox_PeriodicTable.Items.Contains(list_all[i]))
- {
- continue;
- }
- //first_elem?
- if (this.comboBox_Elem1.Items.Contains(list_all[i]))
- {
- continue;
- }
- //Element1?
- if (this.comboBox_Elem.Items.Contains(list_all[i]))
- {
- continue;
- }
- //其它元素?
- if (this.comboBox_ImgProperty.Items.Contains(list_all[i]))
- {
- continue;
- }
- //常量?
- if (Constantslist.Contains(list_all[i]))
- {
- continue;
- }
- //数字?
- double DNum = 0;
- if (double.TryParse(list_all[i], out DNum))
- {
- continue;
- }
- //>=? <=?等其它情况
- if (list_all[i] == "")
- {
- continue;
- }
- //true false?
- if ((list_all[i] == "true") || (list_all[i] == "false"))
- {
- continue;
- }
- MessageBox.Show(table["message21"].ToString() + list_all[i], table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- return false;
- }
- //检测是否有<>= true,false
- if (!textbox_STDEditor.Text.ToString().Contains("<") && !textbox_STDEditor.Text.ToString().Contains(">") && !textbox_STDEditor.Text.ToString().Contains("=") && textbox_STDEditor.Text.ToString() != "true" && textbox_STDEditor.Text.ToString() != "false")
- {
- MessageBox.Show(table["message22"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- return false;
- }
- return true;
- }
- private void btn_dbs_Click(object sender, EventArgs e)
- {
- ColorDialog cd = new ColorDialog();
- cd.FullOpen = true;//自定义颜色界面打开
- DialogResult result = cd.ShowDialog();
- if (result == DialogResult.OK)
- {
- btn_dbs.BackColor = cd.Color;
- int color = Convert.ToInt32(ParseRGB(cd.Color));
- ShowXrayAtlas(color, xrayByteData);
- if (XmlTree_STDlist.SelectedNode != null)
- {
- XmlTree_STDlist.SelectedNode.BackColor = cd.Color;
- }
- }
- if (XmlTree_STDlist.SelectedNode != null)
- {
- //如果不是白色了,就把文字去掉吧,显得好看
- if (btn_dbs.BackColor != Color.White)
- {
- btn_dbs.Text = "";
- }
- }
- }
- private void button_And_Click(object sender, EventArgs e)
- {
- //textbox_STDEditor 中的光标
- int index = textbox_STDEditor.SelectionStart;
- textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "and");
- textbox_STDEditor.Focus();
- textbox_STDEditor.Select(index + 3, 0);
- textbox_STDEditor.ScrollToCaret();
- }
- private void button_Or_Click(object sender, EventArgs e)
- {
- //textbox_STDEditor 中的光标
- int index = textbox_STDEditor.SelectionStart;
- textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "or");
- textbox_STDEditor.Focus();
- textbox_STDEditor.Select(index + 2, 0);
- textbox_STDEditor.ScrollToCaret();
- }
- private void comboBox_Constants_SelectedIndexChanged(object sender, EventArgs e)
- {
- //if (Flag_comboBox_Constants)
- //{
- if (comboBox_Constants.SelectedItem != null)
- {
- //this.textbox_STDEditor.Text += comboBox_Constants.SelectedItem.ToString().Split('=')[0];
- ////comboBox_Constants.Text = null;
- //textbox_STDEditor.Focus();
- //textbox_STDEditor.SelectionStart = textbox_STDEditor.Text.Length;
- //textbox_STDEditor.ScrollToCaret();
- string newStr = comboBox_Constants.SelectedItem.ToString().Split('=')[0];
- int index = textbox_STDEditor.SelectionStart;
- textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, newStr);
- textbox_STDEditor.Focus();
- textbox_STDEditor.Select(index + newStr.Length, 0);
- textbox_STDEditor.ScrollToCaret();
- }
- //}
- //Flag_comboBox_Constants = true;
- }
- bool Flag_SelStatus = true; //XML切换成功失败状态
- private void button_UpOrder_Click(object sender, EventArgs e)
- {
- if (XmlTree_STDlist.SelectedNode.PrevNode != null)
- {
- //object tag = XmlTree_STDlist.SelectedNode.PrevNode.Tag;
- //string name = XmlTree_STDlist.SelectedNode.PrevNode.Name;
- //string text = XmlTree_STDlist.SelectedNode.PrevNode.Text;
- //Color backcolor=XmlTree_STDlist.SelectedNode.PrevNode.BackColor;
- //string STDId = XmlTree_STDlist.SelectedNode.PrevNode.ToolTipText;
- //XmlTree_STDlist.SelectedNode.PrevNode.Tag = XmlTree_STDlist.SelectedNode.Tag;
- //XmlTree_STDlist.SelectedNode.PrevNode.BackColor = XmlTree_STDlist.SelectedNode.BackColor;
- //XmlTree_STDlist.SelectedNode.PrevNode.Name = XmlTree_STDlist.SelectedNode.Name;
- //XmlTree_STDlist.SelectedNode.PrevNode.Text = XmlTree_STDlist.SelectedNode.Text;
- //XmlTree_STDlist.SelectedNode.PrevNode.ToolTipText = XmlTree_STDlist.SelectedNode.ToolTipText;
- //XmlTree_STDlist.SelectedNode.Tag = tag;
- //XmlTree_STDlist.SelectedNode.BackColor = backcolor;
- //XmlTree_STDlist.SelectedNode.Name = name;
- //XmlTree_STDlist.SelectedNode.Text = text;
- //XmlTree_STDlist.SelectedNode.ToolTipText = STDId;
- //this.textbox_STDEditor.Text = XmlTree_STDlist.SelectedNode.Tag.ToString();
- //btn_dbs.BackColor = XmlTree_STDlist.SelectedNode.BackColor;
- //string[] strOther = XmlTree_STDlist.SelectedNode.Name.Split('$');
- //string[] strOther2 = strOther[0].Split('_');
- //textBox_Hardness.Text = strOther2[0];
- //textBox_Density.Text = strOther2[1];
- //textBox_Electrical_conductivity.Text = strOther2[2];
- //dataGridView_KeyElements.Rows.Clear();
- //dataGridView_KeyElements.Columns.Clear();
- //string[] KeyElement = strOther[1].Split(',');
- //for (int i = 0; i < KeyElement.Length; i++)
- //{
- // if (KeyElement[0] != "")
- // {
- // DataGridViewButtonColumn dataGridViewButtonColumn = new DataGridViewButtonColumn();
- // dataGridViewButtonColumn.Name = dataGridView_SubElements.Columns.Count.ToString();
- // dataGridView_KeyElements.Columns.Add(dataGridViewButtonColumn);
- // if (dataGridView_KeyElements.Rows.Count == 0)
- // {
- // DataGridViewRow row = new DataGridViewRow();
- // dataGridView_KeyElements.Rows.Add(row);
- // }
- // dataGridView_KeyElements.Rows[0].Cells[i].Value = KeyElement[i];
- // }
- //}
- //dataGridView_SubElements.Rows.Clear();
- //dataGridView_SubElements.Columns.Clear();
- //string[] SubElement = strOther[2].Split(',');
- //for (int i = 0; i < SubElement.Length; i++)
- //{
- // if (SubElement[i] != "")
- // {
- // DataGridViewButtonColumn dataGridViewButtonColumn = new DataGridViewButtonColumn();
- // dataGridViewButtonColumn.Name = dataGridView_SubElements.Columns.Count.ToString();
- // dataGridView_SubElements.Columns.Add(dataGridViewButtonColumn);
- // if (dataGridView_SubElements.Rows.Count == 0)
- // {
- // DataGridViewRow row = new DataGridViewRow();
- // dataGridView_SubElements.Rows.Add(row);
- // }
- // dataGridView_SubElements.Rows[0].Cells[i].Value = SubElement[i];
- // }
- //}
- //this.XmlTree_STDlist.Focus();
- //XmlTree_STDlist.SelectedNode = XmlTree_STDlist.SelectedNode.PrevNode;
- //if (XmlTree_STDlist.SelectedNode.PrevNode == null)
- //{
- // UpOrder.Enabled = false;
- //}
- }
- XmlTree_STDlist.SelectedNode = XmlTree_STDlist.SelectedNode.PrevNode;
- if (Flag_SelStatus)
- {
- object tag = XmlTree_STDlist.SelectedNode.NextNode.Tag;
- string name = XmlTree_STDlist.SelectedNode.NextNode.Name;
- string text = XmlTree_STDlist.SelectedNode.NextNode.Text;
- Color backcolor = XmlTree_STDlist.SelectedNode.NextNode.BackColor;
- string STDId = XmlTree_STDlist.SelectedNode.NextNode.ToolTipText;
- XmlTree_STDlist.SelectedNode.NextNode.Tag = XmlTree_STDlist.SelectedNode.Tag;
- XmlTree_STDlist.SelectedNode.NextNode.BackColor = XmlTree_STDlist.SelectedNode.BackColor;
- XmlTree_STDlist.SelectedNode.NextNode.Name = XmlTree_STDlist.SelectedNode.Name;
- XmlTree_STDlist.SelectedNode.NextNode.Text = XmlTree_STDlist.SelectedNode.Text;
- XmlTree_STDlist.SelectedNode.NextNode.ToolTipText = XmlTree_STDlist.SelectedNode.ToolTipText;
- XmlTree_STDlist.SelectedNode.Tag = tag;
- XmlTree_STDlist.SelectedNode.BackColor = backcolor;
- XmlTree_STDlist.SelectedNode.Name = name;
- XmlTree_STDlist.SelectedNode.Text = text;
- XmlTree_STDlist.SelectedNode.ToolTipText = STDId;
- this.textbox_STDEditor.Text = XmlTree_STDlist.SelectedNode.Tag.ToString();
- btn_dbs.BackColor = XmlTree_STDlist.SelectedNode.BackColor;
- string[] strOther = XmlTree_STDlist.SelectedNode.Name.Split('$');
- string[] strOther2 = strOther[0].Split('_');
- textBox_Hardness.Text = strOther2[0];
- textBox_Density.Text = strOther2[1];
- textBox_Electrical_conductivity.Text = strOther2[2];
- if (strOther2.Length > 3)
- {
- textBox_BSEValue.Text = strOther2[3];
- textBox_Formula.Text = strOther2[4];
- textBox_Element.Text = strOther2[5];
- }
- else
- {
- textBox_BSEValue.Text = "";
- textBox_Formula.Text = "";
- textBox_Element.Text = "";
- }
- dataGridView_KeyElements.Rows.Clear();
- dataGridView_KeyElements.Columns.Clear();
- string[] KeyElement = strOther[1].Split(',');
- for (int i = 0; i < KeyElement.Length; i++)
- {
- if (KeyElement[0] != "")
- {
- DataGridViewButtonColumn dataGridViewButtonColumn = new DataGridViewButtonColumn();
- dataGridViewButtonColumn.Name = dataGridView_SubElements.Columns.Count.ToString();
- dataGridView_KeyElements.Columns.Add(dataGridViewButtonColumn);
- if (dataGridView_KeyElements.Rows.Count == 0)
- {
- DataGridViewRow row = new DataGridViewRow();
- dataGridView_KeyElements.Rows.Add(row);
- }
- dataGridView_KeyElements.Rows[0].Cells[i].Value = KeyElement[i];
- }
- }
- dataGridView_SubElements.Rows.Clear();
- dataGridView_SubElements.Columns.Clear();
- string[] SubElement = strOther[2].Split(',');
- for (int i = 0; i < SubElement.Length; i++)
- {
- if (SubElement[i] != "")
- {
- DataGridViewButtonColumn dataGridViewButtonColumn = new DataGridViewButtonColumn();
- dataGridViewButtonColumn.Name = dataGridView_SubElements.Columns.Count.ToString();
- dataGridView_SubElements.Columns.Add(dataGridViewButtonColumn);
- if (dataGridView_SubElements.Rows.Count == 0)
- {
- DataGridViewRow row = new DataGridViewRow();
- dataGridView_SubElements.Rows.Add(row);
- }
- dataGridView_SubElements.Rows[0].Cells[i].Value = SubElement[i];
- }
- }
- this.XmlTree_STDlist.Focus();
- if (XmlTree_STDlist.SelectedNode.PrevNode == null)
- {
- button_UpOrder.Enabled = false;
- }
- dataGridView_KeyElements.ClearSelection();
- dataGridView_SubElements.ClearSelection();
- }
- this.XmlTree_STDlist.Focus();
- Flag_SelStatus = true;
- }
- private void button_DownOrder_Click(object sender, EventArgs e)
- {
- if (XmlTree_STDlist.SelectedNode.NextNode != null)
- {
- //object tag = XmlTree_STDlist.SelectedNode.NextNode.Tag;
- //string name = XmlTree_STDlist.SelectedNode.NextNode.Name;
- //string text = XmlTree_STDlist.SelectedNode.NextNode.Text;
- //Color backcolor = XmlTree_STDlist.SelectedNode.NextNode.BackColor;
- //string STDId = XmlTree_STDlist.SelectedNode.NextNode.ToolTipText;
- //XmlTree_STDlist.SelectedNode.NextNode.Tag = XmlTree_STDlist.SelectedNode.Tag;
- //XmlTree_STDlist.SelectedNode.NextNode.BackColor = XmlTree_STDlist.SelectedNode.BackColor;
- //XmlTree_STDlist.SelectedNode.NextNode.Name = XmlTree_STDlist.SelectedNode.Name;
- //XmlTree_STDlist.SelectedNode.NextNode.Text = XmlTree_STDlist.SelectedNode.Text;
- //XmlTree_STDlist.SelectedNode.NextNode.ToolTipText = XmlTree_STDlist.SelectedNode.ToolTipText;
- //XmlTree_STDlist.SelectedNode.Tag = tag;
- //XmlTree_STDlist.SelectedNode.BackColor = backcolor;
- //XmlTree_STDlist.SelectedNode.Name = name;
- //XmlTree_STDlist.SelectedNode.Text = text;
- //XmlTree_STDlist.SelectedNode.ToolTipText = STDId;
- //this.textbox_STDEditor.Text = XmlTree_STDlist.SelectedNode.Tag.ToString();
- //btn_dbs.BackColor = XmlTree_STDlist.SelectedNode.BackColor;
- //string[] strOther = XmlTree_STDlist.SelectedNode.Name.Split('$');
- //string[] strOther2 = strOther[0].Split('_');
- //textBox_Hardness.Text = strOther2[0];
- //textBox_Density.Text = strOther2[1];
- //textBox_Electrical_conductivity.Text = strOther2[2];
- //dataGridView_KeyElements.Rows.Clear();
- //dataGridView_KeyElements.Columns.Clear();
- //string[] KeyElement = strOther[1].Split(',');
- //for (int i = 0; i < KeyElement.Length; i++)
- //{
- // if (KeyElement[0] != "")
- // {
- // DataGridViewButtonColumn dataGridViewButtonColumn = new DataGridViewButtonColumn();
- // dataGridViewButtonColumn.Name = dataGridView_SubElements.Columns.Count.ToString();
- // dataGridView_KeyElements.Columns.Add(dataGridViewButtonColumn);
- // if (dataGridView_KeyElements.Rows.Count == 0)
- // {
- // DataGridViewRow row = new DataGridViewRow();
- // dataGridView_KeyElements.Rows.Add(row);
- // }
- // dataGridView_KeyElements.Rows[0].Cells[i].Value = KeyElement[i];
- // }
- //}
- //dataGridView_SubElements.Rows.Clear();
- //dataGridView_SubElements.Columns.Clear();
- //string[] SubElement = strOther[2].Split(',');
- //for (int i = 0; i < SubElement.Length; i++)
- //{
- // if (SubElement[i] != "")
- // {
- // DataGridViewButtonColumn dataGridViewButtonColumn = new DataGridViewButtonColumn();
- // dataGridViewButtonColumn.Name = dataGridView_SubElements.Columns.Count.ToString();
- // dataGridView_SubElements.Columns.Add(dataGridViewButtonColumn);
- // if (dataGridView_SubElements.Rows.Count == 0)
- // {
- // DataGridViewRow row = new DataGridViewRow();
- // dataGridView_SubElements.Rows.Add(row);
- // }
- // dataGridView_SubElements.Rows[0].Cells[i].Value = SubElement[i];
- // }
- //}
- //this.XmlTree_STDlist.Focus();
- //XmlTree_STDlist.SelectedNode = XmlTree_STDlist.SelectedNode.NextNode;
- //if (XmlTree_STDlist.SelectedNode.NextNode == null)
- //{
- // DownOrder.Enabled = false;
- //}
- }
- XmlTree_STDlist.SelectedNode = XmlTree_STDlist.SelectedNode.NextNode;
- if (Flag_SelStatus)
- {
- object tag = XmlTree_STDlist.SelectedNode.PrevNode.Tag;
- string name = XmlTree_STDlist.SelectedNode.PrevNode.Name;
- string text = XmlTree_STDlist.SelectedNode.PrevNode.Text;
- Color backcolor = XmlTree_STDlist.SelectedNode.PrevNode.BackColor;
- string STDId = XmlTree_STDlist.SelectedNode.PrevNode.ToolTipText;
- XmlTree_STDlist.SelectedNode.PrevNode.Tag = XmlTree_STDlist.SelectedNode.Tag;
- XmlTree_STDlist.SelectedNode.PrevNode.BackColor = XmlTree_STDlist.SelectedNode.BackColor;
- XmlTree_STDlist.SelectedNode.PrevNode.Name = XmlTree_STDlist.SelectedNode.Name;
- XmlTree_STDlist.SelectedNode.PrevNode.Text = XmlTree_STDlist.SelectedNode.Text;
- XmlTree_STDlist.SelectedNode.PrevNode.ToolTipText = XmlTree_STDlist.SelectedNode.ToolTipText;
- XmlTree_STDlist.SelectedNode.Tag = tag;
- XmlTree_STDlist.SelectedNode.BackColor = backcolor;
- XmlTree_STDlist.SelectedNode.Name = name;
- XmlTree_STDlist.SelectedNode.Text = text;
- XmlTree_STDlist.SelectedNode.ToolTipText = STDId;
- this.textbox_STDEditor.Text = XmlTree_STDlist.SelectedNode.Tag.ToString();
- btn_dbs.BackColor = XmlTree_STDlist.SelectedNode.BackColor;
- string[] strOther = XmlTree_STDlist.SelectedNode.Name.Split('$');
- string[] strOther2 = strOther[0].Split('_');
- textBox_Hardness.Text = strOther2[0];
- textBox_Density.Text = strOther2[1];
- textBox_Electrical_conductivity.Text = strOther2[2];
- if (strOther2.Length > 3)
- {
- textBox_BSEValue.Text = strOther2[3];
- textBox_Formula.Text = strOther2[4];
- textBox_Element.Text = strOther2[5];
- }
- else
- {
- textBox_BSEValue.Text = "";
- textBox_Formula.Text = "";
- textBox_Element.Text = "";
- }
- dataGridView_KeyElements.Rows.Clear();
- dataGridView_KeyElements.Columns.Clear();
- string[] KeyElement = strOther[1].Split(',');
- for (int i = 0; i < KeyElement.Length; i++)
- {
- if (KeyElement[0] != "")
- {
- DataGridViewButtonColumn dataGridViewButtonColumn = new DataGridViewButtonColumn();
- dataGridViewButtonColumn.Name = dataGridView_SubElements.Columns.Count.ToString();
- dataGridView_KeyElements.Columns.Add(dataGridViewButtonColumn);
- if (dataGridView_KeyElements.Rows.Count == 0)
- {
- DataGridViewRow row = new DataGridViewRow();
- dataGridView_KeyElements.Rows.Add(row);
- }
- dataGridView_KeyElements.Rows[0].Cells[i].Value = KeyElement[i];
- }
- }
- dataGridView_SubElements.Rows.Clear();
- dataGridView_SubElements.Columns.Clear();
- string[] SubElement = strOther[2].Split(',');
- for (int i = 0; i < SubElement.Length; i++)
- {
- if (SubElement[i] != "")
- {
- DataGridViewButtonColumn dataGridViewButtonColumn = new DataGridViewButtonColumn();
- dataGridViewButtonColumn.Name = dataGridView_SubElements.Columns.Count.ToString();
- dataGridView_SubElements.Columns.Add(dataGridViewButtonColumn);
- if (dataGridView_SubElements.Rows.Count == 0)
- {
- DataGridViewRow row = new DataGridViewRow();
- dataGridView_SubElements.Rows.Add(row);
- }
- dataGridView_SubElements.Rows[0].Cells[i].Value = SubElement[i];
- }
- }
- this.XmlTree_STDlist.Focus();
- if (XmlTree_STDlist.SelectedNode.PrevNode == null)
- {
- button_DownOrder.Enabled = false;
- }
- dataGridView_KeyElements.ClearSelection();
- dataGridView_SubElements.ClearSelection();
- }
- this.XmlTree_STDlist.Focus();
- Flag_SelStatus = true;
- }
- private void button_Backup_Click(object sender, EventArgs e)
- {
- if (tabControl_Rules.SelectedIndex == 0)
- {
- //保存节点当前数据
- if (XmlTree_STDlist.SelectedNode != null)
- {
- //判断Hardness、Density、Electrical_conductivity
- double dHardness = 0, dDensity = 0, dElectrical_conductivity = 0;
- if (!double.TryParse(textBox_Hardness.Text, out dHardness) || (double.Parse(textBox_Hardness.Text) <= 0))
- {
- textBox_Hardness.Focus();
- textBox_Hardness.SelectAll();
- MessageBox.Show(table["message10"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- if (!double.TryParse(textBox_Density.Text, out dDensity) || double.Parse(textBox_Density.Text) <= 0)
- {
- textBox_Density.Focus();
- textBox_Density.SelectAll();
- MessageBox.Show(table["message11"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- if (!double.TryParse(textBox_Electrical_conductivity.Text, out dElectrical_conductivity) || double.Parse(textBox_Electrical_conductivity.Text) <= 0)
- {
- textBox_Electrical_conductivity.Focus();
- textBox_Electrical_conductivity.SelectAll();
- MessageBox.Show(table["message12"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- if (textBox_BSEValue.Text.LastIndexOf("_")>0)
- {
- textBox_BSEValue.Focus();
- textBox_BSEValue.SelectAll();
- MessageBox.Show(table["message13"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- textBox_BSEValue.Focus();
- return;
- }
- if (textBox_Formula.Text.LastIndexOf("_") > 0)
- {
- textBox_Formula.Focus();
- textBox_Formula.SelectAll();
- MessageBox.Show(table["message14"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- textBox_Formula.Focus();
- return;
- }
- if (textBox_Element.Text.LastIndexOf("_") > 0)
- {
- textBox_Element.Focus();
- textBox_Element.SelectAll();
- MessageBox.Show(table["message15"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- textBox_Element.Focus();
- return;
- }
- //判断textbox_STDEditor
- if (!Checktextbox_STDEditor())
- {
- return;
- }
- XmlTree_STDlist.SelectedNode.Tag = this.textbox_STDEditor.Text;
- XmlTree_STDlist.SelectedNode.Name = textBox_Hardness.Text + "_" + textBox_Density.Text + "_" + textBox_Electrical_conductivity.Text + "_" + textBox_BSEValue.Text + "_" + textBox_Formula.Text + "_" + textBox_Element.Text; ;
- string sKeyElements = "";
- for (int i = 0; i < dataGridView_KeyElements.Columns.Count; i++)
- {
- sKeyElements += dataGridView_KeyElements.Rows[0].Cells[i].Value.ToString() + ",";
- }
- if (sKeyElements.Length > 0)
- {
- sKeyElements = sKeyElements.Substring(0, sKeyElements.Length - 1);
- }
- string sSubElements = "";
- for (int i = 0; i < dataGridView_SubElements.Columns.Count; i++)
- {
- sSubElements += dataGridView_SubElements.Rows[0].Cells[i].Value.ToString() + ",";
- }
- if (sSubElements.Length > 0)
- {
- sSubElements = sSubElements.Substring(0, sSubElements.Length - 1);
- }
- XmlTree_STDlist.SelectedNode.Name += "$" + sKeyElements + "$" + sSubElements;
- }
- }
- else if (tabControl_Rules.SelectedIndex == 1)
- {
- if (XmlTree_MaxEDSRules.SelectedNode != null)
- {
- //判断MaxEDSTime
- double dMaxEDSTime = 0;
- if (!double.TryParse(textBox_MaxEDSTime.Text, out dMaxEDSTime) || double.Parse(textBox_MaxEDSTime.Text) <= 0)
- {
- textBox_MaxEDSTime.Focus();
- textBox_MaxEDSTime.SelectAll();
- MessageBox.Show(table["message16"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- //判断textbox_STDEditor
- if (!Checktextbox_STDEditor())
- {
- return;
- }
- XmlTree_MaxEDSRules.SelectedNode.Tag = this.textbox_STDEditor.Text;
- //XmlTree_MaxEDSRules.SelectedNode.Name = textBox_MaxEDSTime.Text;
- }
- }
- else if (tabControl_Rules.SelectedIndex == 2)
- {
- if (XmlTree_ZeroElementRules.SelectedNode != null)
- {
- if (XmlTree_ZeroElementRules.SelectedNode.Text.Contains("="))
- {
- if (!comboBox_PeriodicTable.Items.Contains(XmlTree_ZeroElementRules.SelectedNode.Text.Split('=')[0]))
- {
- MessageBox.Show(XmlTree_ZeroElementRules.SelectedNode.Text + table["message9"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- }
- else
- {
- MessageBox.Show(XmlTree_ZeroElementRules.SelectedNode.Text + table["message9"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- //判断textbox_STDEditor
- if (!Checktextbox_STDEditor())
- {
- return;
- }
- XmlTree_ZeroElementRules.SelectedNode.Tag = this.textbox_STDEditor.Text;
- }
- }
- try
- {
- SaveFileDialog saveFile = new SaveFileDialog();
- saveFile.Title = table["message23"].ToString();
- saveFile.Filter = table["message24"].ToString();
- saveFile.OverwritePrompt = true; //是否覆盖当前文件
- saveFile.RestoreDirectory = true; //还原上次目录
- if (saveFile.ShowDialog() == DialogResult.OK)
- {
- //string Address = Application.StartupPath.Substring(0, Application.StartupPath.Length - 35) + "\\Opton\\OTSPartA\\OTS\\Bin\\Win32\\Debug\\Config\\SysData\\OTSParticleSTD.xml";
- //string Address = ".\\Config\\SysData\\OTSParticleSTD.xml";
- System.IO.File.Copy(Address, saveFile.FileName, true);
- SaveXmlTreeDataToXml(saveFile.FileName);
- MessageBox.Show(table["message25"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- else
- {
- return;
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- //string Address_backup = Application.StartupPath.Substring(0, Application.StartupPath.Length-35) + "\\Bin\\Win32\\Debug\\Config\\SysData\\OTSParticleSTD_backup.xml";
- //string Address_backup = ".\\Config\\SysData\\OTSParticleSTD_backup.xml";
- //SaveXmlTreeDataToXml(Address_backup);
- //MessageBox.Show("备份成功!", "提示");
- }
- private void button_Recover_Click(object sender, EventArgs e)
- {
- XmlDocument doc = new XmlDocument();
- //string Address_backup = ".\\Config\\SysData\\OTSParticleSTD_backup.xml";
- //string Address = ".\\Config\\SysData\\OTSParticleSTD.xml";
- //string Address_backup = Application.StartupPath + "\\Config\\SysData\\\\OTSParticleSTD_backup.xml";
- //string Address = Application.StartupPath + "\\Config\\SysData\\OTSParticleSTD.xml";
- try
- {
- System.IO.File.Copy(Address_backup, Address, true);
- doc.Load(Address_backup);
- XmlTree_STDlist.Nodes.Clear();
- XmlTree_MaxEDSRules.Nodes.Clear();
- XmlTree_ZeroElementRules.Nodes.Clear();
- checkBox_0.Checked = false;
- checkBox_1.Checked = false;
- checkBox_2.Checked = false;
- checkBox_3.Checked = false;
- checkBox_4.Checked = false;
- checkBox_5.Checked = false;
- checkBox_6.Checked = false;
- checkBox_7.Checked = false;
- checkBox_8.Checked = false;
- checkBox_9.Checked = false;
- textBox_0.ReadOnly = true;
- textBox_1.ReadOnly = true;
- textBox_2.ReadOnly = true;
- textBox_3.ReadOnly = true;
- textBox_4.ReadOnly = true;
- textBox_5.ReadOnly = true;
- textBox_6.ReadOnly = true;
- textBox_7.ReadOnly = true;
- textBox_8.ReadOnly = true;
- textBox_9.ReadOnly = true;
- LoadXmlToTreeControl(doc, XmlTree_STDlist.Nodes, XmlTree_MaxEDSRules.Nodes, XmlTree_ZeroElementRules.Nodes);
- XmlTree_STDlist.SelectedNode = null;
- XmlTree_MaxEDSRules.SelectedNode = null;
- XmlTree_ZeroElementRules.SelectedNode = null;
- textbox_STDEditor.Text = "";
- textBox_Density.Text = "";
- textBox_Electrical_conductivity.Text = "";
- textBox_BSEValue.Text = "";
- textBox_Formula.Text = "";
- textBox_Element.Text = "";
- textBox_Hardness.Text = "";
- //textBox_MaxEDSTime.Text = "";
- btn_dbs.BackColor = Color.White;
- dataGridView_KeyElements.Rows.Clear();
- dataGridView_KeyElements.Columns.Clear();
- dataGridView_SubElements.Rows.Clear();
- dataGridView_SubElements.Columns.Clear();
- //重新绑定STDXray信息
- BindSTDXray();
- }
- catch(Exception ex)
- {
- MessageBox.Show(table["message26"].ToString() + "\n"+ex.Message.ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- }
- private void tabControl_Rules_DrawItem(object sender, DrawItemEventArgs e)
- {
- //SolidBrush _Brush = new SolidBrush(Color.Black);//单色画刷
- //RectangleF _TabTextArea = (RectangleF)tabControl_Rules.GetTabRect(e.Index);//绘制区域
- //StringFormat _sf = new StringFormat();//封装文本布局格式信息
- //_sf.LineAlignment = StringAlignment.Center;
- //_sf.Alignment = StringAlignment.Center;
- //e.Graphics.DrawString(tabControl_Rules.Controls[e.Index].Text, SystemInformation.MenuFont, _Brush, _TabTextArea, _sf);
- //RectangleF tabArea = tabControl_Rules.GetTabRect(e.Index);
- //RectangleF tabTextArea = tabArea;
- //Graphics g = e.Graphics;
- //StringFormat sf = new StringFormat();
- //sf.LineAlignment = StringAlignment.Center;
- //sf.Alignment = StringAlignment.Center;
- //Font font = this.tabControl_Rules.Font;
- //SolidBrush brush = new SolidBrush(Color.Black);
- //g.DrawString(((TabControl)(sender)).TabPages[e.Index].Text, font, brush, tabTextArea, sf);
- }
- private void XmlTree_ZeroElementRules_MouseClick(object sender, MouseEventArgs e)
- {
- //if (e.Button == MouseButtons.Left)
- //{
- // Point ClickPoint = new Point(e.X, e.Y);
- // TreeNode CurrentNode = XmlTree_ZeroElementRules.GetNodeAt(ClickPoint);
- // if (CurrentNode != null)//判断你点的是不是一个节点
- // {
- // if (XmlTree_ZeroElementRules.SelectedNode != null&& XmlTree_ZeroElementRules.SelectedNode != CurrentNode)
- // {
- // if (XmlTree_ZeroElementRules.SelectedNode.Text.Contains("="))
- // {
- // if (!comboBox_PeriodicTable.Items.Contains(XmlTree_ZeroElementRules.SelectedNode.Text.Split('=')[0]))
- // {
- // MessageBox.Show(XmlTree_ZeroElementRules.SelectedNode.Text + "项,名称格式填写错误,正确格式为:元素名=0");
- // SetGrayExceptSelectedNode(XmlTree_ZeroElementRules, XmlTree_ZeroElementRules.SelectedNode);
- // return;
- // }
- // }
- // else
- // {
- // MessageBox.Show(XmlTree_ZeroElementRules.SelectedNode.Text + "项,名称格式填写错误,正确格式为:元素名=0");
- // SetGrayExceptSelectedNode(XmlTree_ZeroElementRules, XmlTree_ZeroElementRules.SelectedNode);
- // return;
- // }
- // if (!Checktextbox_STDEditor())
- // {
- // SetGrayExceptSelectedNode(XmlTree_ZeroElementRules, XmlTree_ZeroElementRules.SelectedNode);
- // return;
- // }
- // XmlTree_ZeroElementRules.SelectedNode.Tag = this.textbox_STDEditor.Text;
- // }
- // SetBlackAllNodes(XmlTree_ZeroElementRules);
- // XmlTree_ZeroElementRules.SelectedNode = CurrentNode;
- // this.textbox_STDEditor.Text = XmlTree_ZeroElementRules.SelectedNode.Tag.ToString();
- // }
- //}
- }
- private void XmlTree_ZeroElementRules_MouseDoubleClick(object sender, MouseEventArgs e)
- {
- if (e.Button == MouseButtons.Left)
- {
- Point ClickPoint = new Point(e.X, e.Y);
- TreeNode CurrentNode = XmlTree_ZeroElementRules.GetNodeAt(ClickPoint);
- if (CurrentNode != null)//判断你点的是不是一个节点
- {
- XmlTree_ZeroElementRules.SelectedNode = CurrentNode;//选中这个节点
- //this.textbox_STDEditor.Text = XmlTree_ZeroElementRules.SelectedNode.Tag.ToString();
- XmlTree_ZeroElementRules.LabelEdit = true;
- XmlTree_ZeroElementRules.SelectedNode.BeginEdit();
- }
- }
- }
- private void XmlTree_MaxEDSRules_MouseClick(object sender, MouseEventArgs e)
- {
- //if (e.Button == MouseButtons.Left)
- //{
- // Point ClickPoint = new Point(e.X, e.Y);
- // TreeNode CurrentNode = XmlTree_MaxEDSRules.GetNodeAt(ClickPoint);
- // if (CurrentNode != null)//判断你点的是不是一个节点
- // {
- // if (XmlTree_MaxEDSRules.SelectedNode != null&& XmlTree_MaxEDSRules.SelectedNode!= CurrentNode)
- // {
- // if (!Checktextbox_STDEditor())
- // {
- // SetGrayExceptSelectedNode(XmlTree_MaxEDSRules, XmlTree_MaxEDSRules.SelectedNode);
- // return;
- // }
- // //double dMaxEDSTime = 0;
- // //if (!double.TryParse(textBox_MaxEDSTime.Text, out dMaxEDSTime)||double.Parse(textBox_MaxEDSTime.Text)<=0)
- // //{
- // // MessageBox.Show("MaxEDSTime请填写数字!", "提示");
- // //}
- // XmlTree_MaxEDSRules.SelectedNode.Tag = this.textbox_STDEditor.Text;
- // //XmlTree_MaxEDSRules.SelectedNode.Name = this.textBox_MaxEDSTime.Text;
- // }
- // SetBlackAllNodes(XmlTree_MaxEDSRules);
- // XmlTree_MaxEDSRules.SelectedNode = CurrentNode;
- // this.textbox_STDEditor.Text = XmlTree_MaxEDSRules.SelectedNode.Tag.ToString();
- // //textBox_MaxEDSTime.Text = XmlTree_MaxEDSRules.SelectedNode.Name;
- // }
- //}
- }
- private void checkBox_0_CheckedChanged(object sender, EventArgs e)
- {
- if (checkBox_0.Checked)
- {
- textBox_0.ReadOnly = false;
- }
- else
- {
- if (!CheckConstants(checkBox_0.Text))
- {
- checkBox_0.Checked = true;
- }
- else
- {
- textBox_0.ReadOnly = true;
- }
- }
- }
- private void checkBox_1_CheckedChanged(object sender, EventArgs e)
- {
- if (checkBox_1.Checked)
- {
- textBox_1.ReadOnly = false;
- }
- else
- {
- if (!CheckConstants(checkBox_1.Text))
- {
- checkBox_1.Checked = true;
- }
- else
- {
- textBox_1.ReadOnly = true;
- }
- }
- }
- private void checkBox_2_CheckedChanged(object sender, EventArgs e)
- {
- if (checkBox_2.Checked)
- {
- textBox_2.ReadOnly = false;
- }
- else
- {
- if (!CheckConstants(checkBox_2.Text))
- {
- checkBox_2.Checked = true;
- }
- else
- {
- textBox_2.ReadOnly = true;
- }
- }
- }
- private void checkBox_3_CheckedChanged(object sender, EventArgs e)
- {
- if (checkBox_3.Checked)
- {
- textBox_3.ReadOnly = false;
- }
- else
- {
- if (!CheckConstants(checkBox_3.Text))
- {
- checkBox_3.Checked = true;
- }
- else
- {
- textBox_3.ReadOnly = true;
- }
- }
- }
- private void checkBox_4_CheckedChanged(object sender, EventArgs e)
- {
- if (checkBox_4.Checked)
- {
- textBox_4.ReadOnly = false;
- }
- else
- {
- if (!CheckConstants(checkBox_4.Text))
- {
- checkBox_4.Checked = true;
- }
- else
- {
- textBox_4.ReadOnly = true;
- }
- }
- }
- private void checkBox_5_CheckedChanged(object sender, EventArgs e)
- {
- if (checkBox_5.Checked)
- {
- textBox_5.ReadOnly = false;
- }
- else
- {
- if (!CheckConstants(checkBox_5.Text))
- {
- checkBox_5.Checked = true;
- }
- else
- {
- textBox_5.ReadOnly = true;
- }
- }
- }
- private void checkBox_6_CheckedChanged(object sender, EventArgs e)
- {
- if (checkBox_6.Checked)
- {
- textBox_6.ReadOnly = false;
- }
- else
- {
- if (!CheckConstants(checkBox_6.Text))
- {
- checkBox_6.Checked = true;
- }
- else
- {
- textBox_6.ReadOnly = true;
- }
- }
- }
- private void checkBox_7_CheckedChanged(object sender, EventArgs e)
- {
- if (checkBox_7.Checked)
- {
- textBox_7.ReadOnly = false;
- }
- else
- {
- if (!CheckConstants(checkBox_7.Text))
- {
- checkBox_7.Checked = true;
- }
- else
- {
- textBox_7.ReadOnly = true;
- }
- }
- }
- private void checkBox_8_CheckedChanged(object sender, EventArgs e)
- {
- if (checkBox_8.Checked)
- {
- textBox_8.ReadOnly = false;
- }
- else
- {
- if (!CheckConstants(checkBox_8.Text))
- {
- checkBox_8.Checked = true;
- }
- else
- {
- textBox_8.ReadOnly = true;
- }
- }
- }
- private void checkBox_9_CheckedChanged(object sender, EventArgs e)
- {
- if (checkBox_9.Checked)
- {
- textBox_9.ReadOnly = false;
- }
- else
- {
- if (!CheckConstants(checkBox_9.Text))
- {
- checkBox_9.Checked = true;
- }
- else
- {
- textBox_9.ReadOnly = true;
- }
- }
- }
- private bool CheckConstants(string ConstantName)
- {
- for (int num = 0; num < XmlTree_STDlist.Nodes.Count; num++)
- {
- if (XmlTree_STDlist.Nodes[num].Tag.ToString().Contains(ConstantName))
- {
- tabControl_Rules.SelectedIndex = 0;
- XmlTree_STDlist.SelectedNode = XmlTree_STDlist.Nodes[num];
- SetGrayExceptSelectedNode(XmlTree_STDlist, XmlTree_STDlist.SelectedNode);
- DialogResult result = MessageBox.Show(table["message27"].ToString() + XmlTree_STDlist.Nodes[num].Text + table["message28"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return false;
- }
- }
- for (int num = 0; num < XmlTree_MaxEDSRules.Nodes.Count; num++)
- {
- if (XmlTree_MaxEDSRules.Nodes[num].Tag.ToString().Contains(ConstantName))
- {
- tabControl_Rules.SelectedIndex = 1;
- XmlTree_MaxEDSRules.SelectedNode = XmlTree_MaxEDSRules.Nodes[num];
- SetGrayExceptSelectedNode(XmlTree_MaxEDSRules, XmlTree_MaxEDSRules.SelectedNode);
- DialogResult result = MessageBox.Show(table["message27"].ToString() + XmlTree_MaxEDSRules.Nodes[num].Text + table["message28"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return false;
- }
- }
- for (int num = 0; num < XmlTree_ZeroElementRules.Nodes.Count; num++)
- {
- if (XmlTree_ZeroElementRules.Nodes[num].Tag.ToString().Contains(ConstantName))
- {
- tabControl_Rules.SelectedIndex = 2;
- XmlTree_ZeroElementRules.SelectedNode = XmlTree_ZeroElementRules.Nodes[num];
- SetGrayExceptSelectedNode(XmlTree_ZeroElementRules, XmlTree_ZeroElementRules.SelectedNode);
- DialogResult result = MessageBox.Show(table["message27"].ToString() + XmlTree_ZeroElementRules.Nodes[num].Text + table["message28"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return false;
- }
- }
- return true;
- }
- private void button_UpdateConstants_Click(object sender, EventArgs e)
- {
- this.comboBox_Constants.Items.Clear();
- for (int i = 0; i < 10; i++)
- {
- CheckBox checkBox = (CheckBox)this.tabControl_Rules.TabPages[3].Controls.Find("checkBox_" + i.ToString(), false)[0];
- if (checkBox.Checked)
- {
- TextBox tBox = (TextBox)this.tabControl_Rules.TabPages[3].Controls.Find("textBox_" + i.ToString(), false)[0];
- double DoubleTry = 0;
- if (double.TryParse(tBox.Text, out DoubleTry))
- {
- this.comboBox_Constants.Items.Add(checkBox.Text + "=" + tBox.Text);
- }
- else
- {
- MessageBox.Show(table["message29"].ToString() + checkBox.Name + table["message30"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return;
- }
- }
- }
- List<string> Constantslist = new List<string>();
- Constantslist.Add("MAC#0");
- Constantslist.Add("MAC#1");
- Constantslist.Add("MAC#2");
- Constantslist.Add("MAC#3");
- Constantslist.Add("MAC#4");
- Constantslist.Add("MAC#5");
- Constantslist.Add("MAC#6");
- Constantslist.Add("MAC#7");
- Constantslist.Add("MAC#8");
- Constantslist.Add("MAC#9");
- foreach (var item in comboBox_Constants.Items)
- {
- Constantslist.Remove(item.ToString().Split('=')[0]);
- }
- MessageBox.Show(table["message31"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- //tabpage切换开关
- bool Flag_TabControlChange = true;
- private void tabControl_Rules_Deselecting(object sender, TabControlCancelEventArgs e)
- {
- if (tabControl_Rules.SelectedIndex == 0)
- {
- //保存节点当前数据
- if (XmlTree_STDlist.SelectedNode != null)
- {
- //判断Hardness、Density、Electrical_conductivity
- double dHardness = 0, dDensity = 0, dElectrical_conductivity = 0;
- if (!double.TryParse(textBox_Hardness.Text, out dHardness) || (double.Parse(textBox_Hardness.Text) <= 0))
- {
- textBox_Hardness.Focus();
- textBox_Hardness.SelectAll();
- MessageBox.Show(table["message10"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- Flag_TabControlChange = false;
- return;
- }
- if (!double.TryParse(textBox_Density.Text, out dDensity) || double.Parse(textBox_Density.Text) <= 0)
- {
- textBox_Density.Focus();
- textBox_Density.SelectAll();
- MessageBox.Show(table["message11"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- Flag_TabControlChange = false;
- return;
- }
- if (!double.TryParse(textBox_Electrical_conductivity.Text, out dElectrical_conductivity) || double.Parse(textBox_Electrical_conductivity.Text) <= 0)
- {
- textBox_Electrical_conductivity.Focus();
- textBox_Electrical_conductivity.SelectAll();
- MessageBox.Show(table["message12"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- Flag_TabControlChange = false;
- return;
- }
- if (textBox_BSEValue.Text.LastIndexOf("_") > 0)
- {
- textBox_BSEValue.Focus();
- textBox_BSEValue.SelectAll();
- MessageBox.Show(table["message13"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- textBox_BSEValue.Focus();
- return;
- }
- if (textBox_Formula.Text.LastIndexOf("_") > 0)
- {
- textBox_Formula.Focus();
- textBox_Formula.SelectAll();
- MessageBox.Show(table["message14"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- textBox_Formula.Focus();
- return;
- }
- if (textBox_Element.Text.LastIndexOf("_") > 0)
- {
- textBox_Element.Focus();
- textBox_Element.SelectAll();
- MessageBox.Show(table["message15"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- textBox_Element.Focus();
- return;
- }
- //判断textbox_STDEditor
- if (!Checktextbox_STDEditor())
- {
- Flag_TabControlChange = false;
- return;
- }
- Flag_TabControlChange = true;
- XmlTree_STDlist.SelectedNode.Tag = this.textbox_STDEditor.Text;
- XmlTree_STDlist.SelectedNode.Name = textBox_Hardness.Text + "_" + textBox_Density.Text + "_" + textBox_Electrical_conductivity.Text + "_" + textBox_BSEValue.Text + "_" + textBox_Formula.Text + "_" + textBox_Element.Text; ;
- string sKeyElements = "";
- for (int i = 0; i < dataGridView_KeyElements.Columns.Count; i++)
- {
- sKeyElements += dataGridView_KeyElements.Rows[0].Cells[i].Value.ToString() + ",";
- }
- if (sKeyElements.Length > 0)
- {
- sKeyElements = sKeyElements.Substring(0, sKeyElements.Length - 1);
- }
- string sSubElements = "";
- for (int i = 0; i < dataGridView_SubElements.Columns.Count; i++)
- {
- sSubElements += dataGridView_SubElements.Rows[0].Cells[i].Value.ToString() + ",";
- }
- if (sSubElements.Length > 0)
- {
- sSubElements = sSubElements.Substring(0, sSubElements.Length - 1);
- }
- XmlTree_STDlist.SelectedNode.Name += "$" + sKeyElements + "$" + sSubElements;
- XmlTree_STDlist.SelectedNode.BackColor = btn_dbs.BackColor;
- }
- }
- else if (tabControl_Rules.SelectedIndex == 1)
- {
- if (XmlTree_MaxEDSRules.SelectedNode != null)
- {
- //判断MaxEDSTime
- double dMaxEDSTime = 0;
- if (!double.TryParse(textBox_MaxEDSTime.Text, out dMaxEDSTime) || double.Parse(textBox_MaxEDSTime.Text) <= 0)
- {
- textBox_MaxEDSTime.Focus();
- textBox_MaxEDSTime.SelectAll();
- MessageBox.Show(table["message16"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- Flag_TabControlChange = false;
- return;
- }
- //判断textbox_STDEditor
- if (!Checktextbox_STDEditor())
- {
- Flag_TabControlChange = false;
- return;
- }
- Flag_TabControlChange = true;
- XmlTree_MaxEDSRules.SelectedNode.Tag = this.textbox_STDEditor.Text;
- //XmlTree_MaxEDSRules.SelectedNode.Name = textBox_MaxEDSTime.Text;
- }
- }
- else if (tabControl_Rules.SelectedIndex == 2)
- {
- if (XmlTree_ZeroElementRules.SelectedNode != null)
- {
- if (XmlTree_ZeroElementRules.SelectedNode.Text.Contains("="))
- {
- if (!comboBox_PeriodicTable.Items.Contains(XmlTree_ZeroElementRules.SelectedNode.Text.Split('=')[0]))
- {
- MessageBox.Show(XmlTree_ZeroElementRules.SelectedNode.Text + table["message9"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- Flag_TabControlChange = false;
- return;
- }
- }
- else
- {
- MessageBox.Show(XmlTree_ZeroElementRules.SelectedNode.Text + table["message9"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- Flag_TabControlChange = false;
- return;
- }
- //判断textbox_STDEditor
- if (!Checktextbox_STDEditor())
- {
- Flag_TabControlChange = false;
- return;
- }
- Flag_TabControlChange = true;
- XmlTree_ZeroElementRules.SelectedNode.Tag = this.textbox_STDEditor.Text;
- }
- }
- //XmlTree_STDlist.SelectedNode = null;
- //XmlTree_MaxEDSRules.SelectedNode = null;
- //XmlTree_ZeroElementRules.SelectedNode = null;
- //textbox_STDEditor.Text = "";
- //textBox_Density.Text = "";
- //textBox_Electrical_conductivity.Text = "";
- //textBox_Hardness.Text = "";
- //textBox_MaxEDSTime.Text = "";
- //btn_dbs.BackColor = Color.White;
- }
- private void tabControl_Rules_SelectedIndexChanged(object sender, EventArgs e)
- {
- if (tabControl_Rules.SelectedIndex == 0)
- {
- //XmlTree_STDlist.SelectedNode = null;
- XmlTree_STDlist.Focus();
- XmlTree_STDlist_AfterSelect(XmlTree_STDlist, new TreeViewEventArgs(XmlTree_STDlist.SelectedNode));
- textBox_Density.ReadOnly = false;
- textBox_Electrical_conductivity.ReadOnly = false;
- textBox_Hardness.ReadOnly = false;
- textBox_BSEValue.ReadOnly = false;
- textBox_Formula.ReadOnly = false;
- textBox_Element.ReadOnly = false;
- btn_dbs.Enabled = true;
- textBox_MaxEDSTime.ReadOnly = true;
- button_UpOrder.Enabled = false;
- button_DownOrder.Enabled = false;
- }
- else if (tabControl_Rules.SelectedIndex == 1)
- {
- //XmlTree_MaxEDSRules.SelectedNode = null;
- XmlTree_MaxEDSRules.Focus();
- XmlTree_MaxEDSRules_AfterSelect(XmlTree_MaxEDSRules, new TreeViewEventArgs(XmlTree_MaxEDSRules.SelectedNode));
- dataGridView_KeyElements.Rows.Clear();
- dataGridView_KeyElements.Columns.Clear();
- dataGridView_SubElements.Rows.Clear();
- dataGridView_SubElements.Columns.Clear();
- btn_dbs.BackColor = SystemColors.Control;
- textBox_Density.Text = "";
- textBox_Electrical_conductivity.Text = "";
- textBox_Hardness.Text = "";
- textBox_Density.ReadOnly = true;
- textBox_Electrical_conductivity.ReadOnly = true;
- textBox_Hardness.ReadOnly = true;
- textBox_BSEValue.ReadOnly = true;
- textBox_Formula.ReadOnly = true;
- textBox_Element.ReadOnly = true;
- btn_dbs.Enabled = false;
- textBox_MaxEDSTime.ReadOnly = false;
- tabSTDStandrad.SelectedIndex = 0;
- }
- else if (tabControl_Rules.SelectedIndex == 2)
- {
- //XmlTree_ZeroElementRules.SelectedNode = null;
- XmlTree_ZeroElementRules.Focus();
- XmlTree_ZeroElementRules_AfterSelect(XmlTree_MaxEDSRules, new TreeViewEventArgs(XmlTree_ZeroElementRules.SelectedNode));
- dataGridView_KeyElements.Rows.Clear();
- dataGridView_KeyElements.Columns.Clear();
- dataGridView_SubElements.Rows.Clear();
- dataGridView_SubElements.Columns.Clear();
- btn_dbs.BackColor = SystemColors.Control;
- textBox_Density.Text = "";
- textBox_Electrical_conductivity.Text = "";
- textBox_Hardness.Text = "";
- textBox_Density.ReadOnly = true;
- textBox_Electrical_conductivity.ReadOnly = true;
- textBox_BSEValue.ReadOnly = true;
- textBox_Formula.ReadOnly = true;
- textBox_Element.ReadOnly = true;
- textBox_Hardness.ReadOnly = true;
- btn_dbs.Enabled = false;
- textBox_MaxEDSTime.ReadOnly = true;
- tabSTDStandrad.SelectedIndex = 0;
- }
- else
- {
- textbox_STDEditor.Text = "";
- dataGridView_KeyElements.Rows.Clear();
- dataGridView_KeyElements.Columns.Clear();
- dataGridView_SubElements.Rows.Clear();
- dataGridView_SubElements.Columns.Clear();
- btn_dbs.BackColor = SystemColors.Control;
- textBox_Density.Text = "";
- textBox_Electrical_conductivity.Text = "";
- textBox_Hardness.Text = "";
- textBox_Density.ReadOnly = true;
- textBox_Electrical_conductivity.ReadOnly = true;
- textBox_BSEValue.ReadOnly = true;
- textBox_Formula.ReadOnly = true;
- textBox_Element.ReadOnly = true;
- textBox_Hardness.ReadOnly = true;
- btn_dbs.Enabled = false;
- textBox_MaxEDSTime.ReadOnly = true;
- }
- //textbox_STDEditor.Text = "";
- //dataGridView_KeyElements.Rows.Clear();
- //dataGridView_KeyElements.Columns.Clear();
- //dataGridView_SubElements.Rows.Clear();
- //dataGridView_SubElements.Columns.Clear();
- }
- private void XmlTree_ZeroElementRules_BeforeSelect(object sender, TreeViewCancelEventArgs e)
- {
- //if (e.Node != null)
- //{
- // if (e.Node.ForeColor == Color.Gray)
- // {
- // e.Cancel = true; //不让选中禁用节点
- // return;
- // }
- //}
- if (XmlTree_ZeroElementRules.SelectedNode != null)
- {
- if (XmlTree_ZeroElementRules.SelectedNode.Text.Contains("="))
- {
- if (!comboBox_PeriodicTable.Items.Contains(XmlTree_ZeroElementRules.SelectedNode.Text.Split('=')[0]))
- {
- MessageBox.Show(XmlTree_ZeroElementRules.SelectedNode.Text + table["message9"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- SetGrayExceptSelectedNode(XmlTree_ZeroElementRules, XmlTree_ZeroElementRules.SelectedNode);
- e.Cancel = true;
- return;
- }
- }
- else
- {
- MessageBox.Show(XmlTree_ZeroElementRules.SelectedNode.Text + table["message9"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- SetGrayExceptSelectedNode(XmlTree_ZeroElementRules, XmlTree_ZeroElementRules.SelectedNode);
- e.Cancel = true;
- return;
- }
- if (!Checktextbox_STDEditor())
- {
- SetGrayExceptSelectedNode(XmlTree_ZeroElementRules, XmlTree_ZeroElementRules.SelectedNode);
- e.Cancel = true;
- return;
- }
- XmlTree_ZeroElementRules.SelectedNode.Tag = this.textbox_STDEditor.Text;
- }
- }
- private void tabControl_Rules_Selecting(object sender, TabControlCancelEventArgs e)
- {
- if (!Flag_TabControlChange)
- {
- e.Cancel = true;
- }
- else
- {
- }
- }
- private void XmlTree_ZeroElementRules_AfterSelect(object sender, TreeViewEventArgs e)
- {
- SetBlackAllNodes(XmlTree_ZeroElementRules);
- this.textbox_STDEditor.Text = XmlTree_ZeroElementRules.SelectedNode.Tag.ToString();
- }
- private void XmlTree_STDlist_BeforeSelect(object sender, TreeViewCancelEventArgs e)
- {
- if (XmlTree_STDlist.SelectedNode != null)
- {
- //判断Hardness、Density、Electrical_conductivity
- double dHardness = 0, dDensity = 0, dElectrical_conductivity = 0;
- if (!double.TryParse(textBox_Hardness.Text, out dHardness) || (double.Parse(textBox_Hardness.Text) <= 0))
- {
- MessageBox.Show(table["message10"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- SetGrayExceptSelectedNode(XmlTree_STDlist, XmlTree_STDlist.SelectedNode);
- Flag_SelStatus = false;
- e.Cancel = true;
- return;
- }
- if (!double.TryParse(textBox_Density.Text, out dDensity) || double.Parse(textBox_Density.Text) <= 0)
- {
- MessageBox.Show(table["message11"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- SetGrayExceptSelectedNode(XmlTree_STDlist, XmlTree_STDlist.SelectedNode);
- Flag_SelStatus = false;
- e.Cancel = true;
- return;
- }
- if (!double.TryParse(textBox_Electrical_conductivity.Text, out dElectrical_conductivity) || double.Parse(textBox_Electrical_conductivity.Text) <= 0)
- {
- MessageBox.Show(table["message12"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- SetGrayExceptSelectedNode(XmlTree_STDlist, XmlTree_STDlist.SelectedNode);
- Flag_SelStatus = false;
- e.Cancel = true;
- return;
- }
- if (textBox_BSEValue.Text.LastIndexOf("_") > 0)
- {
- MessageBox.Show(table["message13"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- textBox_BSEValue.Focus();
- return;
- }
- if (textBox_Formula.Text.LastIndexOf("_") > 0)
- {
- MessageBox.Show(table["message14"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- textBox_Formula.Focus();
- return;
- }
- if (textBox_Element.Text.LastIndexOf("_") > 0)
- {
- MessageBox.Show(table["message15"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- textBox_Element.Focus();
- return;
- }
- //判断textbox_STDEditor
- if (!Checktextbox_STDEditor())
- {
- SetGrayExceptSelectedNode(XmlTree_STDlist, XmlTree_STDlist.SelectedNode);
- Flag_SelStatus = false;
- e.Cancel = true;
- return;
- }
- XmlTree_STDlist.SelectedNode.Tag = this.textbox_STDEditor.Text;
- if (dataGridView_KeyElements.Rows.Count == 0 && dataGridView_SubElements.Rows.Count == 0)
- {
- string str_RemoveBlank = textbox_STDEditor.Text.ToString().Replace(" ", "");
- str_RemoveBlank = str_RemoveBlank.Replace("\r\n", "");
- str_RemoveBlank = str_RemoveBlank.Replace("forth_elem", "");
- string[] str_Removeand = System.Text.RegularExpressions.Regex.Split(str_RemoveBlank, "and", System.Text.RegularExpressions.RegexOptions.None);
- List<string> str_Removeandor = new List<string>();
- for (int i = 0; i < str_Removeand.Length; i++)
- {
- str_Removeandor.AddRange(System.Text.RegularExpressions.Regex.Split(str_Removeand[i], "or", System.Text.RegularExpressions.RegexOptions.None));
- }
- List<string> list_all = new List<string>();
- for (int i = 0; i < str_Removeandor.Count; i++)
- {
- list_all.AddRange(str_Removeandor[i].Split(new char[] { '+', '-', '*', '/', '=', '>', '<', '(', ')' }));
- }
- List<string> UsingElementL = new List<string>();
- for (int i = 0; i < list_all.Count; i++)
- {
- if (this.comboBox_PeriodicTable.Items.Contains(list_all[i]))
- {
- if (!UsingElementL.Contains(list_all[i]))
- {
- UsingElementL.Add(list_all[i]);
- }
- }
- }
- for (int i = 0; i < UsingElementL.Count; i++)
- {
- DataGridViewButtonColumn dataGridViewButtonColumn = new DataGridViewButtonColumn();
- dataGridViewButtonColumn.Name = dataGridView_KeyElements.Columns.Count.ToString();
- dataGridView_KeyElements.Columns.Add(dataGridViewButtonColumn);
- if (dataGridView_KeyElements.Rows.Count == 0)
- {
- DataGridViewRow row = new DataGridViewRow();
- dataGridView_KeyElements.Rows.Add(row);
- }
- dataGridView_KeyElements.Rows[0].Cells[i].Value = UsingElementL[i];
- }
- }
- XmlTree_STDlist.SelectedNode.Name = textBox_Hardness.Text + "_" + textBox_Density.Text + "_" + textBox_Electrical_conductivity.Text + "_" + textBox_BSEValue.Text + "_" + textBox_Formula.Text + "_" + textBox_Element.Text; ;
- string sKeyElements = "";
- for (int i = 0; i < dataGridView_KeyElements.Columns.Count; i++)
- {
- sKeyElements += dataGridView_KeyElements.Rows[0].Cells[i].Value.ToString() + ",";
- }
- if (sKeyElements.Length > 0)
- {
- sKeyElements = sKeyElements.Substring(0, sKeyElements.Length - 1);
- }
- string sSubElements = "";
- for (int i = 0; i < dataGridView_SubElements.Columns.Count; i++)
- {
- sSubElements += dataGridView_SubElements.Rows[0].Cells[i].Value.ToString() + ",";
- }
- if (sSubElements.Length > 0)
- {
- sSubElements = sSubElements.Substring(0, sSubElements.Length - 1);
- }
- XmlTree_STDlist.SelectedNode.Name += "$" + sKeyElements + "$" + sSubElements;
- XmlTree_STDlist.SelectedNode.BackColor = btn_dbs.BackColor;
- }
- }
- private void XmlTree_MaxEDSRules_AfterSelect(object sender, TreeViewEventArgs e)
- {
- SetBlackAllNodes(XmlTree_MaxEDSRules);
- this.textbox_STDEditor.Text = XmlTree_MaxEDSRules.SelectedNode.Tag.ToString();
- //textBox_MaxEDSTime.Text = XmlTree_MaxEDSRules.SelectedNode.Name;
- }
- private void XmlTree_MaxEDSRules_BeforeSelect(object sender, TreeViewCancelEventArgs e)
- {
- if (XmlTree_MaxEDSRules.SelectedNode != null)
- {
- if (!Checktextbox_STDEditor())
- {
- SetGrayExceptSelectedNode(XmlTree_MaxEDSRules, XmlTree_MaxEDSRules.SelectedNode);
- e.Cancel = true;
- return;
- }
- //double dMaxEDSTime = 0;
- //if (!double.TryParse(textBox_MaxEDSTime.Text, out dMaxEDSTime)||double.Parse(textBox_MaxEDSTime.Text)<=0)
- //{
- // MessageBox.Show("MaxEDSTime请填写数字!", "提示");
- // e.Cancel = true;
- //}
- XmlTree_MaxEDSRules.SelectedNode.Tag = this.textbox_STDEditor.Text;
- //XmlTree_MaxEDSRules.SelectedNode.Name = this.textBox_MaxEDSTime.Text;
- }
- }
- string ElementKeyOrSub = "";
- private void dataGridView_KeyElements_CellClick(object sender, DataGridViewCellEventArgs e)
- {
- ElementKeyOrSub = dataGridView_KeyElements.CurrentCell.Value.ToString();
- dataGridView_KeyElements.Columns.RemoveAt(e.ColumnIndex);
- DataGridViewButtonColumn dataGridViewButtonColumn = new DataGridViewButtonColumn();
- dataGridViewButtonColumn.Name = dataGridView_SubElements.Columns.Count.ToString();
- dataGridView_SubElements.Columns.Add(dataGridViewButtonColumn);
- if (dataGridView_SubElements.Rows.Count == 0)
- {
- DataGridViewRow row = new DataGridViewRow();
- dataGridView_SubElements.Rows.Add(row);
- }
- dataGridView_SubElements.Rows[0].Cells[dataGridView_SubElements.Columns.Count - 1].Value = ElementKeyOrSub;
- dataGridView_SubElements.ClearSelection();
- dataGridView_KeyElements.ClearSelection();
- XmlTree_STDlist.Focus();
- }
- private void dataGridView_SubElements_CellClick(object sender, DataGridViewCellEventArgs e)
- {
- ElementKeyOrSub = dataGridView_SubElements.CurrentCell.Value.ToString();
- dataGridView_SubElements.Columns.RemoveAt(e.ColumnIndex);
- DataGridViewButtonColumn dataGridViewButtonColumn = new DataGridViewButtonColumn();
- dataGridViewButtonColumn.Name = dataGridView_SubElements.Columns.Count.ToString();
- dataGridView_KeyElements.Columns.Add(dataGridViewButtonColumn);
- if (dataGridView_KeyElements.Rows.Count == 0)
- {
- DataGridViewRow row = new DataGridViewRow();
- dataGridView_KeyElements.Rows.Add(row);
- }
- dataGridView_KeyElements.Rows[0].Cells[dataGridView_KeyElements.Columns.Count - 1].Value = ElementKeyOrSub;
- dataGridView_KeyElements.ClearSelection();
- dataGridView_SubElements.ClearSelection();
- XmlTree_STDlist.Focus();
- }
- private void textbox_STDEditor_TextChanged(object sender, EventArgs e)
- {
- //string str_RemoveBlank = textbox_STDEditor.Text.ToString().Replace(" ", "");
- //str_RemoveBlank = str_RemoveBlank.Replace("forth_elem", "");
- //string[] str_Removeand = System.Text.RegularExpressions.Regex.Split(str_RemoveBlank, "and", System.Text.RegularExpressions.RegexOptions.None);
- //List<string> str_Removeandor = new List<string>();
- //for (int i = 0; i < str_Removeand.Length; i++)
- //{
- // str_Removeandor.AddRange(System.Text.RegularExpressions.Regex.Split(str_Removeand[i], "or", System.Text.RegularExpressions.RegexOptions.None));
- //}
- //List<string> list_all = new List<string>();
- //for (int i = 0; i < str_Removeandor.Count; i++)
- //{
- // list_all.AddRange(str_Removeandor[i].Split(new char[] { '+', '-', '*', '/', '=', '>', '<', '(', ')' }));
- //}
- //List<string> UsingElementL = new List<string>();
- //for (int i = 0; i < list_all.Count; i++)
- //{
- // if (this.comboBox_PeriodicTable.Items.Contains(list_all[i]))
- // {
- // if (!UsingElementL.Contains(list_all[i]))
- // {
- // UsingElementL.Add(list_all[i]);
- // }
- // }
- //}
- //for (int i = 0; i < UsingElementL.Count; i++)
- //{
- // DataGridViewButtonColumn dataGridViewButtonColumn = new DataGridViewButtonColumn();
- // dataGridViewButtonColumn.Name = dataGridView_KeyElements.Columns.Count.ToString();
- // dataGridView_KeyElements.Columns.Add(dataGridViewButtonColumn);
- // if (dataGridView_KeyElements.Rows.Count == 0)
- // {
- // DataGridViewRow row = new DataGridViewRow();
- // dataGridView_KeyElements.Rows.Add(row);
- // }
- // dataGridView_KeyElements.Rows[0].Cells[i].Value = UsingElementL[i];
- //}
- }
- private void textbox_STDEditor_KeyPress(object sender, KeyPressEventArgs e)
- {
- //if (e.KeyChar == '\r')
- //{
- // dataGridView_KeyElements.Rows.Clear();
- // dataGridView_KeyElements.Columns.Clear();
- // dataGridView_SubElements.Rows.Clear();
- // dataGridView_SubElements.Columns.Clear();
- // string str_RemoveBlank = textbox_STDEditor.Text.ToString().Replace(" ", "");
- // str_RemoveBlank = str_RemoveBlank.Replace("\r\n", "");
- // str_RemoveBlank = str_RemoveBlank.Replace("forth_elem", "");
- // string[] str_Removeand = System.Text.RegularExpressions.Regex.Split(str_RemoveBlank, "and", System.Text.RegularExpressions.RegexOptions.None);
- // List<string> str_Removeandor = new List<string>();
- // for (int i = 0; i < str_Removeand.Length; i++)
- // {
- // str_Removeandor.AddRange(System.Text.RegularExpressions.Regex.Split(str_Removeand[i], "or", System.Text.RegularExpressions.RegexOptions.None));
- // }
- // List<string> list_all = new List<string>();
- // for (int i = 0; i < str_Removeandor.Count; i++)
- // {
- // list_all.AddRange(str_Removeandor[i].Split(new char[] { '+', '-', '*', '/', '=', '>', '<', '(', ')' }));
- // }
- // List<string> UsingElementL = new List<string>();
- // for (int i = 0; i < list_all.Count; i++)
- // {
- // if (this.comboBox_PeriodicTable.Items.Contains(list_all[i]))
- // {
- // if (!UsingElementL.Contains(list_all[i]))
- // {
- // UsingElementL.Add(list_all[i]);
- // }
- // }
- // }
- // for (int i = 0; i < UsingElementL.Count; i++)
- // {
- // DataGridViewButtonColumn dataGridViewButtonColumn = new DataGridViewButtonColumn();
- // dataGridViewButtonColumn.Name = dataGridView_KeyElements.Columns.Count.ToString();
- // dataGridView_KeyElements.Columns.Add(dataGridViewButtonColumn);
- // if(dataGridView_KeyElements.Rows.Count==0)
- // {
- // DataGridViewRow row = new DataGridViewRow();
- // dataGridView_KeyElements.Rows.Add(row);
- // }
- // dataGridView_KeyElements.Rows[0].Cells[i].Value = UsingElementL[i];
- // }
- //}
- }
- private void textbox_STDEditor_Leave(object sender, EventArgs e)
- {
- if (tabControl_Rules.SelectedIndex == 0)
- {
- dataGridView_KeyElements.Rows.Clear();
- dataGridView_KeyElements.Columns.Clear();
- string str_RemoveBlank = textbox_STDEditor.Text.ToString().Replace(" ", "");
- str_RemoveBlank = str_RemoveBlank.Replace("\r\n", "");
- str_RemoveBlank = str_RemoveBlank.Replace("forth_elem", "");
- string[] str_Removeand = System.Text.RegularExpressions.Regex.Split(str_RemoveBlank, "and", System.Text.RegularExpressions.RegexOptions.None);
- List<string> str_Removeandor = new List<string>();
- for (int i = 0; i < str_Removeand.Length; i++)
- {
- str_Removeandor.AddRange(System.Text.RegularExpressions.Regex.Split(str_Removeand[i], "or", System.Text.RegularExpressions.RegexOptions.None));
- }
- List<string> list_all = new List<string>();
- for (int i = 0; i < str_Removeandor.Count; i++)
- {
- list_all.AddRange(str_Removeandor[i].Split(new char[] { '+', '-', '*', '/', '=', '>', '<', '(', ')' }));
- }
- List<string> UsingElementL = new List<string>();
- for (int i = 0; i < list_all.Count; i++)
- {
- if (this.comboBox_PeriodicTable.Items.Contains(list_all[i]))
- {
- if (!UsingElementL.Contains(list_all[i]))
- {
- UsingElementL.Add(list_all[i]);
- }
- }
- }
- List<string> SubElements = new List<string>();
- for (int i = 0; i < dataGridView_SubElements.ColumnCount; i++)
- {
- if (UsingElementL.Contains(dataGridView_SubElements.Rows[0].Cells[i].Value))
- {
- SubElements.Add(dataGridView_SubElements.Rows[0].Cells[i].Value.ToString());
- }
- }
- dataGridView_SubElements.Rows.Clear();
- dataGridView_SubElements.Columns.Clear();
- for (int i = 0; i < SubElements.Count; i++)
- {
- DataGridViewButtonColumn dataGridViewButtonColumn = new DataGridViewButtonColumn();
- dataGridViewButtonColumn.Name = dataGridView_SubElements.Columns.Count.ToString();
- dataGridView_SubElements.Columns.Add(dataGridViewButtonColumn);
- if (dataGridView_SubElements.Rows.Count == 0)
- {
- DataGridViewRow row = new DataGridViewRow();
- dataGridView_SubElements.Rows.Add(row);
- }
- dataGridView_SubElements.Rows[0].Cells[dataGridView_SubElements.ColumnCount - 1].Value = SubElements[i];
- }
- if (SubElements.Count > 0)
- {
- for (int i = 0; i < UsingElementL.Count; i++)
- {
- if (!SubElements.Contains(UsingElementL[i]))
- {
- DataGridViewButtonColumn dataGridViewButtonColumn = new DataGridViewButtonColumn();
- dataGridViewButtonColumn.Name = dataGridView_KeyElements.Columns.Count.ToString();
- dataGridView_KeyElements.Columns.Add(dataGridViewButtonColumn);
- if (dataGridView_KeyElements.Rows.Count == 0)
- {
- DataGridViewRow row = new DataGridViewRow();
- dataGridView_KeyElements.Rows.Add(row);
- }
- dataGridView_KeyElements.Rows[0].Cells[dataGridView_KeyElements.ColumnCount - 1].Value = UsingElementL[i];
- }
- }
- }
- else
- {
- for (int i = 0; i < UsingElementL.Count; i++)
- {
- DataGridViewButtonColumn dataGridViewButtonColumn = new DataGridViewButtonColumn();
- dataGridViewButtonColumn.Name = dataGridView_KeyElements.Columns.Count.ToString();
- dataGridView_KeyElements.Columns.Add(dataGridViewButtonColumn);
- if (dataGridView_KeyElements.Rows.Count == 0)
- {
- DataGridViewRow row = new DataGridViewRow();
- dataGridView_KeyElements.Rows.Add(row);
- }
- dataGridView_KeyElements.Rows[0].Cells[i].Value = UsingElementL[i];
- }
- }
- dataGridView_KeyElements.ClearSelection();
- dataGridView_SubElements.ClearSelection();
- XmlTree_STDlist.Focus();
- }
- else if(tabControl_Rules.SelectedIndex == 1)
- {
- XmlTree_MaxEDSRules.Focus();
- }
- else if (tabControl_Rules.SelectedIndex == 2)
- {
- XmlTree_ZeroElementRules.Focus();
- }
- }
-
- #region 为配合textbox_STDEditor_Leave时事件,点击其它groupbox组件时使焦点转移
- private void Form_ConstantsEditor_Click(object sender, EventArgs e)
- {
- groupBox_XmlTree_MaxEDSRules.Focus();
- }
- private void groupBox_Data_Click(object sender, EventArgs e)
- {
- groupBox_Data.Focus();
- }
-
- private void groupBox_ChemicalElement_Click(object sender, EventArgs e)
- {
- groupBox_ChemicalElement.Focus();
- }
- private void groupBox_OtherCommonlyUsedSymbols_Click(object sender, EventArgs e)
- {
- groupBox_OtherCommonlyUsedSymbols.Focus();
- }
- private void groupBox_XmlTree_STDlist1_Click(object sender, EventArgs e)
- {
- groupBox_XmlTree_STDlist1.Focus();
- }
- private void groupBox_CalculatingSymbols_Click(object sender, EventArgs e)
- {
- groupBox_CalculatingSymbols.Focus();
- }
- private void groupBox_XmlTree_MaxEDSRules_Click(object sender, EventArgs e)
- {
- groupBox_XmlTree_MaxEDSRules.Focus();
- }
- #endregion
-
- #region 采集Xray 按钮事件
- private void btnCollectXray_Click(object sender, EventArgs e)
- {
- string strTime = txtCollectTime.Text.Trim();
- if (txtCollectTime.Equals(""))
- {
- showMessage(table["message33"].ToString());
- txtCollectTime.Focus();
- return;
- }
- if (!IsMatch(strTime, 1))
- {
- showMessage(table["message34"].ToString());
- txtCollectTime.Focus();
- return;
- }
- if (Convert.ToInt32(strTime) < 100)
- {
- showMessage(table["message35"].ToString());
- txtCollectTime.Focus();
- return;
- }
- //显示Xray
- xrayByteData = IntArrToByteArr(GetCollectXray(strTime));
- int color = Convert.ToInt32(ParseRGB(btn_dbs.BackColor));
- //根据树节点修改对应的Xray信息
- UpdateSTDXray(XmlTree_STDlist.SelectedNode, xrayByteData);
- ShowXrayAtlas(color, xrayByteData);
- }
- /// <summary>
- /// 获取采集当前的Xray信息
- /// </summary>
- /// <returns></returns>
- protected uint[] GetCollectXray(string strTime)
- {
- try
- {
- if (null == m_cfun)
- {
- m_cfun = COTSControlFunExport.GetControllerInstance();
- }
- if (ConnectionSem(connectionEnumType.EDSOnlyPointXRay))
- {
- if (EDSInit())
- {
- int iSize = 2000;
- uint[] iXrayData = new uint[iSize];
- //采集XRay数据
- if (m_cfun.CollectSpectrum(uint.Parse(strTime), ref iXrayData))
- {
- return iXrayData;
- }
- }
- }
- return null;
- }
- catch /*(Exception ex)*/
- {
- return null;
- }
- finally
- {
- //EDS过程结束
- //m_cfun.EDSFinishedInstance();
- //关闭连接
- DisConnectSem(connectionEnumType.EDSOnlyPointXRay);
- }
- }
- private void btnReadXray_Click(object sender, EventArgs e)
- {
- OpenFileDialog fileSel = new OpenFileDialog();
- fileSel.Filter = "|*.txt";
- if (DialogResult.OK == fileSel.ShowDialog())
- {
- String str = "";
- //读取Xray文件
- using (StreamReader sr = new StreamReader(fileSel.FileName))
- {
- while (!sr.EndOfStream)
- {
- str += sr.ReadLine() + ",";
- }
- str = str.Substring(0, str.Length - 1);
- string[] xrayData = str.Split(',');
- if (xrayData.Length != 2000)
- {
- return;
- }
- uint[] data = new uint[xrayData.Length];
- for (int i = 0; i < xrayData.Length; i++)
- {
- data[i] = Convert.ToUInt32(xrayData[i]);
- }
- //Xray数据
- xrayByteData = IntArrToByteArr(data);
- int color = Convert.ToInt32(ParseRGB(btn_dbs.BackColor));
- //根据树节点修改对应的Xray信息
- UpdateSTDXray(XmlTree_STDlist.SelectedNode, xrayByteData);
- ShowXrayAtlas(color, xrayByteData);
- }
- }
- }
- /// <summary>
- /// 将int[] 转换为 byte[]
- /// </summary>
- /// <param name="intArr"></param>
- /// <returns></returns>
- public static byte[] IntArrToByteArr(uint[] intArr)
- {
- int intSize = sizeof(int) * intArr.Length;
- byte[] bytArr = new byte[intSize];
- //申请一块非托管内存
- //IntPtr ptr = Marshal.AllocHGlobal(intSize);
- //复制int数组到该内存块
- //Marshal.Copy(intArr, 0, ptr, intArr.Length);
- ////复制回byte数组
- //Marshal.Copy(ptr, bytArr, 0, bytArr.Length);
- ////释放申请的非托管内存
- //Marshal.FreeHGlobal(ptr);
- for (int i = 0; i < intSize; i++)
- {
- byte[] c1 = BitConverter.GetBytes(intArr[i]);
- c1.CopyTo(bytArr, i * intSize);
- }
-
- return bytArr;
- }
- /// <summary>
- /// 将颜色对象转换为uint
- /// </summary>
- /// <param name="color"></param>
- /// <returns></returns>
- public uint ParseRGB(Color color)
- {
- return (uint)(((uint)color.B << 16) | (ushort)(((ushort)color.G << 8) | color.R));
- }
- #region 显示Xray图谱
- /// <summary>
- /// 显示Xray图谱
- /// </summary>
- protected void ShowXrayAtlas(int colorValue = 0, byte[] XrayData = null)
- {
- DataTable dt = new DataTable();
- dt.Columns.Add("Color", typeof(int));
- dt.Columns.Add("SPEC", typeof(byte[]));
- DataRow dRow = dt.NewRow();
- dRow["Color"] = colorValue;
- if (XrayData != null)
- {
- dRow["SPEC"] = XrayData;
- }
- else
- {
- dRow["SPEC"] = new byte[8000];
- }
- //将选择行的数据传递给Xray控件
- XrayControl.Dr = dRow;
- XrayControl.Refresh();
- XrayData = null;
- }
- #endregion
- #region 常用数据验证的封装,数字字符的验证
- /// <summary>
- /// 常用数据验证的封装,数字字符的验证
- /// </summary>
- /// <param name="inputVal">需要验证的数值【字符串,或者数字】</param>
- /// <param name="type">类型为哪一个验证</param>
- /// <returns>如果验证成功则返回True,否则返回false</returns>
- public bool IsMatch(string inputVal, int type)
- {
- switch (type)
- {
- case 0:
- return Regex.IsMatch(inputVal, @"^[1-9]d*$"); //匹配正整数
- case 1:
- return Regex.IsMatch(inputVal, @"^-?\d+$"); //匹配整数
- case 2:
- return Regex.IsMatch(inputVal, @"^[A-Za-z0-9]+$"); //匹配由数字和26个英文字母组成的字符串
- case 3:
- return Regex.IsMatch(inputVal, @"^(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*))$"); //匹配正浮点数
- case 4:
- return Regex.IsMatch(inputVal, @"^[\u4e00-\u9fa5]{0,}$"); //匹配汉字
- case 5:
- return Regex.IsMatch(inputVal, @"^[0-9]+(.[0-9]{1,3})?$"); //匹配1~3位小数的正实数
- case 6:
- return Regex.IsMatch(inputVal, @"^[A-Za-z]+$"); //匹配英文字符
- default:
- return true;
- }
- }
- #endregion
- #region 弹出提示
- /// <summary>
- /// 弹出提示
- /// </summary>
- /// <param name="strContent"></param>
- protected void showMessage(string strContent)
- {
- MessageBox.Show(strContent, table["message32"].ToString());
- }
- #endregion
- #region 连接与关闭设备
- public bool ConnectionSem(connectionEnumType connectionType)
- {
- //获取连接电镜类型
- string connTypeStr = GetConnectionType(connectionType);
- //连接电镜标识
- bool bDisConnResult = false;
- //判断连接状态
- if (!m_bConnectionState)
- {
- //连接电镜设置
- bDisConnResult = m_cfun.ConncetSem();
- }
- if (bDisConnResult)
- {
- m_bConnectionState = true;
- }
- else
- {
- m_bConnectionState = false;
- }
- return bDisConnResult;
- }
- public bool DisConnectSem(connectionEnumType disConnectType)
- {
- //获取关闭电镜类型
- string connTypeStr = GetConnectionType(disConnectType);
- bool bDisConnResult = false;
- if (m_bConnectionState)
- {
- //bDisConnResult = m_cfun.DisConnectSem();
- }
- if (bDisConnResult)
- {
- m_bConnectionState = false;
- }
- else
- {
- m_bConnectionState = true;
- }
- return bDisConnResult;
- }
- private string GetConnectionType(connectionEnumType connectionType)
- {
- string connString = string.Empty;
- switch (connectionType)
- {
- //设置单点采集文字内容
- case connectionEnumType.EDSOnlyPointXRay:
- connString = "OnlyPointXRay";
- break;
- //设置多点采集文字内容
- case connectionEnumType.EDSMultiPointXRay:
- connString = "MultiPointXRay";
- break;
- //设置面采集文字内容
- case connectionEnumType.EDSAreaXRay:
- connString = "AreaXRay";
- break;
- //设置图片
- case connectionEnumType.ScanImage:
- connString = "Image";
- break;
- default: break;
- }
- return connString;
- }
- /// <summary>
- /// EDS初始化
- /// </summary>
- public bool EDSInit()
- {
- bool bResult = false;
- //线程调用 加载
- bResult = m_cfun.EDSInit();
- return bResult;
- }
- public enum connectionEnumType
- {
- EDSOnlyPointXRay = 0,
- EDSMultiPointXRay = 1,
- EDSAreaXRay = 2,
- ScanImage = 3
- }
- /// <summary>
- /// 标准Xray状态
- /// </summary>
- public enum STDXrayInfoState
- {
- Add = 0,
- Modify = 1,
- Delete = 2
- }
- #endregion
- /// <summary>
- /// 记录修改后的标准中的Xray信息
- /// </summary>
- public class STDXray
- {
- /// <summary>
- /// 标准编号
- /// </summary>
- private string stdID;
- /// <summary>
- /// Xray数据
- /// </summary>
- private byte[] xrayData;
- /// <summary>
- /// 状态
- /// </summary>
- private int infoState=-1;
- public string StdID { get => stdID; set => stdID = value; }
- public byte[] XrayData { get => xrayData; set => xrayData = value; }
- public int InfoState { get => infoState; set => infoState = value; }
- }
- #endregion
- #region Xray 与 STDDB数据操作
- /// <summary>
- /// 绑定数据库中已存在的Xray信息
- /// </summary>
- protected void BindSTDXray()
- {
- //清空STDXray列表中的集合
- m_STDXrayList.Clear();
- //查询
- DataTable dt = m_sc.GetDTFormSysSTDBySQLString("select Id,SPEC from STDMinerals");
- if (dt != null)
- {
- if (dt.Rows.Count > 0)
- {
- foreach (DataRow item in dt.Rows)
- {
- STDXray sXray = new STDXray();
- sXray.StdID = item["Id"].ToString();
- sXray.XrayData = (byte[])item["SPEC"];
- m_STDXrayList.Add(sXray);
- }
- }
- }
- }
- /// <summary>
- /// 保存STDXray至数据库
- /// </summary>
- protected void SaveSTDXray()
- {
- ArrayList delArrayList = new ArrayList();
- if (m_STDXrayList != null)
- {
- //if (m_STDXrayList.Count > 0)
- //{
- foreach (STDXray item in m_STDXrayList)
- {
- int infoState = item.InfoState;
- //添加状态 根据Xray信息当前只能按照一条操作
- if (infoState == (int)STDXrayInfoState.Add)
- {
- if (item.XrayData == null)
- {
- item.XrayData = new byte[8000];
- }
- string strvaluename = "@data";
- //编辑添加语句
- StringBuilder strSqlAdd = new StringBuilder();
- strSqlAdd.Append("insert into STDMinerals(Id,SPEC) values(" + item.StdID + "," + strvaluename + ");");
- bool addResult = m_sc.ExecuteBlob(strSqlAdd.ToString(), strvaluename, (byte[])item.XrayData, ((byte[])item.XrayData).Length);
- if (!addResult)
- {
- continue;
- }
- }
- //修改状态
- else if (infoState == (int)STDXrayInfoState.Modify)
- {
- //判断STDID在数据库中是否存在
- bool selResult = SelSTDDBBySTDId(item.StdID);
- if (selResult)
- {
- UpdateSTDDB(item.StdID, xrayByteData);
- }
- else
- {
- AddSTDDB(item.StdID, xrayByteData);
- }
- }
- //删除状态 编辑批量删除语句
- else if (infoState == (int)STDXrayInfoState.Delete)
- {
- //编辑删除语句
- delArrayList.Add("delete from STDMinerals where id=" + item.StdID + ";");
- }
- }
- //批量删除
- if (delArrayList.Count>0)
- {
- bool delResult = m_sc.DelSTDInfo(delArrayList);
- }
- //}
- }
- }
-
- /// <summary>
- /// 添加STD信息至数据库
- /// </summary>
- protected bool AddSTDDB(string stdID,byte[] XrayData)
- {
- if (XrayData == null)
- {
- XrayData = new byte[8000];
- }
- string strvaluename = "@data";
- StringBuilder sqlStrAdd = new StringBuilder();
- sqlStrAdd.Append("insert into STDMinerals(Id,SPEC) values(" + stdID + "," + strvaluename + ");");
- bool addResult = m_sc.ExecuteBlob(sqlStrAdd.ToString(), strvaluename, (byte[])XrayData, ((byte[])XrayData).Length);
- return addResult;
- }
- /// <summary>
- /// 修改STD信息至数据库
- /// </summary>
- protected bool UpdateSTDDB(string stdID, byte[] XrayData)
- {
- if (XrayData == null)
- {
- XrayData = new byte[8000];
- }
- string strValueName = "@data";
- StringBuilder sqlStrUpdate = new StringBuilder();
- sqlStrUpdate.Append("update STDMinerals set SPEC=" + strValueName + " where id=" + stdID + ";");
- bool updateResult = m_sc.ExecuteBlob(sqlStrUpdate.ToString(), strValueName, (byte[])XrayData, ((byte[])XrayData).Length);
- return updateResult;
- }
- /// <summary>
- /// 查询是否存在标准编号
- /// </summary>
- /// <param name="stdID"></param>
- protected bool SelSTDDBBySTDId(string stdID)
- {
- bool selResult = false;
- //编辑查询语句
- StringBuilder sqlStr = new StringBuilder();
- sqlStr.Append("select * from STDMinerals where id=" + stdID + "");
- DataTable dt = m_sc.GetDTFormSysSTDBySQLString(sqlStr.ToString());
- if (dt != null)
- {
- if (dt.Rows.Count > 0)
- {
- //已存在状态
- selResult = true;
- }
- }
- return selResult;
- }
- /// <summary>
- /// 根据选择树节点显示对应的Xray信息
- /// </summary>
- protected void SelSTDXray(TreeNode tn)
- {
- if (tn == null)
- {
- return;
- }
- if (m_STDXrayList != null)
- {
- if (m_STDXrayList.Count > 0)
- {
- bool isExists = false;
- foreach (STDXray item in m_STDXrayList)
- {
- //修改XrayData信息
- if (item.StdID == tn.ToolTipText.ToString())
- {
- string selColor = ParseRGB(tn.BackColor).ToString();
- int colorValue = Convert.ToInt32(selColor);
- //显示Xray信息
- if (item.XrayData != null)
- {
- isExists = true;
- ShowXrayAtlas(colorValue, item.XrayData);
- }
- break;
- }
- }
- if (!isExists)
- {
- ShowXrayAtlas();
- }
- }
- }
- }
- /// <summary>
- /// 根据树节点修改对应的Xray信息
- /// </summary>
- /// <param name="tn"></param>
- protected void UpdateSTDXray(TreeNode tn,byte[] xrayData)
- {
- if (tn == null)
- {
- return;
- }
- if (m_STDXrayList != null)
- {
- //if (m_STDXrayList.Count > 0)
- //{
- bool isExists = false;
- foreach (STDXray item in m_STDXrayList)
- {
- //修改XrayData信息
- if (item.StdID == tn.ToolTipText.ToString())
- {
- item.XrayData = xrayData;
- item.InfoState = (int)STDXrayInfoState.Modify;
- isExists = true;
- break;
- }
- }
- if (!isExists)
- {
- if (!tn.ToolTipText.ToString().Equals(""))
- {
- //添加STD XrayData信息
- STDXray stdXray = new STDXray();
- stdXray.StdID = tn.ToolTipText.ToString();
- stdXray.XrayData = xrayData;
- stdXray.InfoState = (int)STDXrayInfoState.Add;
- m_STDXrayList.Add(stdXray);
- }
- }
- //}
- }
- }
- /// <summary>
- /// 添加STDXray信息
- /// </summary>
- /// <param name="tn">所选树节点</param>
- /// <param name="xrayData">Xray信息</param>
- /// <returns></returns>
- protected bool AddSTDXray(TreeNode tn, byte[] xrayData)
- {
- bool addResult = false;
- if (tn == null)
- {
- return false;
- }
- if (m_STDXrayList != null)
- {
- if (m_STDXrayList.Count > 0)
- {
- if (!tn.ToolTipText.ToString().Equals(""))
- {
- //添加STD XrayData信息
- STDXray stdXray = new STDXray();
- stdXray.StdID = tn.ToolTipText.ToString();
- stdXray.XrayData = xrayData;
- stdXray.InfoState = (int)STDXrayInfoState.Add;
- m_STDXrayList.Add(stdXray);
- addResult = true;
- }
- }
- }
- return addResult;
- }
- /// <summary>
- /// 删除STDXray信息
- /// </summary>
- /// <param name="tn">所选要删除的树节点</param>
- /// <returns></returns>
- protected bool DelSTDXray(TreeNode tn)
- {
- bool delResult = false;
- if (tn == null)
- {
- return false;
- }
- if (m_STDXrayList != null)
- {
- if (m_STDXrayList.Count > 0)
- {
- if (!tn.ToolTipText.ToString().Equals(""))
- {
- foreach (STDXray item in m_STDXrayList)
- {
- //修改XrayData信息
- if (item.StdID == tn.ToolTipText.ToString())
- {
- item.InfoState = (int)STDXrayInfoState.Delete;
- delResult = true;
- break;
- }
- }
- }
- }
- }
- return delResult;
- }
- #endregion
- #region 控制BSE、化学式、元素本文框中不能输入下划线
- /// <summary>
- /// 控件不能输入下划线
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void textBox_KeyPress(object sender, KeyPressEventArgs e)
- {
- if ((e.KeyChar >= '0' && e.KeyChar <= '9') || (e.KeyChar >= 'A' && e.KeyChar <= 'Z') ||
- (e.KeyChar >= 'a' && e.KeyChar <= 'z') || (e.KeyChar == 8) || !(e.KeyChar == '_'))
- {
- e.Handled = false;
- }
- else
- {
- e.Handled = true;
- }
- }
- #endregion
- private void button_1_Click(object sender, EventArgs e)
- {
- //textbox_STDEditor 中的光标
- int index = textbox_STDEditor.SelectionStart;
- textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "1");
- textbox_STDEditor.Focus();
- textbox_STDEditor.Select(index + 1, 0);
- textbox_STDEditor.ScrollToCaret();
- }
- private void button_2_Click(object sender, EventArgs e)
- {
- //textbox_STDEditor 中的光标
- int index = textbox_STDEditor.SelectionStart;
- textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "2");
- textbox_STDEditor.Focus();
- textbox_STDEditor.Select(index + 1, 0);
- textbox_STDEditor.ScrollToCaret();
- }
- private void button_3_Click(object sender, EventArgs e)
- {
- //textbox_STDEditor 中的光标
- int index = textbox_STDEditor.SelectionStart;
- textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "3");
- textbox_STDEditor.Focus();
- textbox_STDEditor.Select(index + 1, 0);
- textbox_STDEditor.ScrollToCaret();
- }
- private void button_4_Click(object sender, EventArgs e)
- {
- //textbox_STDEditor 中的光标
- int index = textbox_STDEditor.SelectionStart;
- textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "4");
- textbox_STDEditor.Focus();
- textbox_STDEditor.Select(index + 1, 0);
- textbox_STDEditor.ScrollToCaret();
- }
- private void button_5_Click(object sender, EventArgs e)
- {
- //textbox_STDEditor 中的光标
- int index = textbox_STDEditor.SelectionStart;
- textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "5");
- textbox_STDEditor.Focus();
- textbox_STDEditor.Select(index + 1, 0);
- textbox_STDEditor.ScrollToCaret();
- }
- private void button_6_Click(object sender, EventArgs e)
- {
- //textbox_STDEditor 中的光标
- int index = textbox_STDEditor.SelectionStart;
- textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "6");
- textbox_STDEditor.Focus();
- textbox_STDEditor.Select(index + 1, 0);
- textbox_STDEditor.ScrollToCaret();
- }
- private void button_7_Click(object sender, EventArgs e)
- {
- //textbox_STDEditor 中的光标
- int index = textbox_STDEditor.SelectionStart;
- textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "7");
- textbox_STDEditor.Focus();
- textbox_STDEditor.Select(index + 1, 0);
- textbox_STDEditor.ScrollToCaret();
- }
- private void button_8_Click(object sender, EventArgs e)
- {
- //textbox_STDEditor 中的光标
- int index = textbox_STDEditor.SelectionStart;
- textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "8");
- textbox_STDEditor.Focus();
- textbox_STDEditor.Select(index + 1, 0);
- textbox_STDEditor.ScrollToCaret();
- }
- private void button_9_Click(object sender, EventArgs e)
- {
- //textbox_STDEditor 中的光标
- int index = textbox_STDEditor.SelectionStart;
- textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "9");
- textbox_STDEditor.Focus();
- textbox_STDEditor.Select(index + 1, 0);
- textbox_STDEditor.ScrollToCaret();
- }
- private void button_0_Click(object sender, EventArgs e)
- {
- int index = textbox_STDEditor.SelectionStart;
- textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "0");
- textbox_STDEditor.Focus();
- textbox_STDEditor.Select(index + 1, 0);
- textbox_STDEditor.ScrollToCaret();
- }
- private void tabSTDStandrad_SelectedIndexChanged(object sender, EventArgs e)
- {
- if (tabSTDStandrad.SelectedIndex == 1)
- {
- tabControl_Rules.SelectedIndex = 0;
- XmlTree_STDlist.Focus();
- }
- }
- private void btnTest_Click(object sender, EventArgs e)
- {
- XrayContrastForm xrayContrastForm = new XrayContrastForm();
- //xrayContrastForm.XmlTree_STDlist = XmlTree_STDlist.Nodes;
- xrayContrastForm.ShowDialog();
- }
- private void XmlTree_STDlist_AfterSelect(object sender, TreeViewEventArgs e)
- {
- SetBlackAllNodes(XmlTree_STDlist);
- this.textbox_STDEditor.Text = XmlTree_STDlist.SelectedNode.Tag.ToString();
- btn_dbs.BackColor = XmlTree_STDlist.SelectedNode.BackColor;
- string[] strOther = XmlTree_STDlist.SelectedNode.Name.Split('$');
- string[] strOther2 = strOther[0].Split('_');
- textBox_Hardness.Text = strOther2[0];
- textBox_Density.Text = strOther2[1];
- textBox_Electrical_conductivity.Text = strOther2[2];
- dataGridView_KeyElements.Rows.Clear();
- dataGridView_KeyElements.Columns.Clear();
- string[] KeyElement = strOther[1].Split(',');
- for (int i = 0; i < KeyElement.Length; i++)
- {
- if (KeyElement[0] != "")
- {
- DataGridViewButtonColumn dataGridViewButtonColumn = new DataGridViewButtonColumn();
- dataGridViewButtonColumn.Name = dataGridView_SubElements.Columns.Count.ToString();
- dataGridView_KeyElements.Columns.Add(dataGridViewButtonColumn);
- if (dataGridView_KeyElements.Rows.Count == 0)
- {
- DataGridViewRow row = new DataGridViewRow();
- dataGridView_KeyElements.Rows.Add(row);
- }
- dataGridView_KeyElements.Rows[0].Cells[i].Value = KeyElement[i];
- }
- }
- dataGridView_SubElements.Rows.Clear();
- dataGridView_SubElements.Columns.Clear();
- string[] SubElement = strOther[2].Split(',');
- for (int i = 0; i < SubElement.Length; i++)
- {
- if (SubElement[i] != "")
- {
- DataGridViewButtonColumn dataGridViewButtonColumn = new DataGridViewButtonColumn();
- dataGridViewButtonColumn.Name = dataGridView_SubElements.Columns.Count.ToString();
- dataGridView_SubElements.Columns.Add(dataGridViewButtonColumn);
- if (dataGridView_SubElements.Rows.Count == 0)
- {
- DataGridViewRow row = new DataGridViewRow();
- dataGridView_SubElements.Rows.Add(row);
- }
- dataGridView_SubElements.Rows[0].Cells[i].Value = SubElement[i];
- }
- }
- if (button_UpOrder.Enabled == false)
- {
- button_UpOrder.Enabled = true;
- }
- if (button_DownOrder.Enabled == false)
- {
- button_DownOrder.Enabled = true;
- }
- if (XmlTree_STDlist.SelectedNode.PrevNode == null)
- {
- button_UpOrder.Enabled = false;
- }
- else if (XmlTree_STDlist.SelectedNode.NextNode == null)
- {
- button_DownOrder.Enabled = false;
- }
- dataGridView_KeyElements.ClearSelection();
- dataGridView_SubElements.ClearSelection();
- ShowEditContent(XmlTree_STDlist.SelectedNode);
- SelSTDXray(XmlTree_STDlist.SelectedNode);
- }
- protected void ShowEditContent(TreeNode tn)
- {
- if (m_STDXrayList != null)
- {
- for (int i = 0; i < m_STDXrayList.Count; i++)
- {
- if (m_STDXrayList[i].StdID == tn.ToolTipText.ToString())
- {
- //获取修改行的信息
- xrayByteData = (byte[])m_STDXrayList[i].XrayData;
- }
- }
- }
- }
- }
- }
|