Form_STDConstantsEditor.cs 191 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342
  1. using OTSCLRINTERFACE;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.IO;
  8. using System.Linq;
  9. using System.Runtime.InteropServices;
  10. using System.Text;
  11. using System.Text.RegularExpressions;
  12. using System.Windows.Forms;
  13. using System.Xml;
  14. using System.Xml.Linq;
  15. namespace OTSPartA_STDEditor
  16. {
  17. public partial class Form_STDConstantsEditor : Form
  18. {
  19. //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"};
  20. //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" };
  21. public Form_STDConstantsEditor()
  22. {
  23. InitializeComponent();
  24. m_sc = new SqlLiteClass();
  25. }
  26. #region 全局变量
  27. //数据库操作对象
  28. private SqlLiteClass m_sc = null;
  29. // 电镜设置对象
  30. COTSControlFunExport m_cfun = null;
  31. //Xray图谱用户控件
  32. UXrayControl XrayControl = null;
  33. //全局Xray 用于存储当前选择行的Xray信息
  34. byte[] xrayByteData = null;
  35. // 连接状态
  36. bool m_bConnectionState = false;
  37. //标准Xray信息列表
  38. List<STDXray> m_STDXrayList = null;
  39. #endregion
  40. //国际化
  41. Language lan;
  42. Hashtable table;
  43. //public string Language = "English";
  44. string Address_backup = Application.StartupPath + "\\Config\\SysData\\OTSParticleSTD_backup.xml";
  45. string Address = Application.StartupPath + "\\Config\\SysData\\OTSParticleSTD.xml";
  46. private void Form_ConstantsEditor_Load(object sender, EventArgs e)
  47. {
  48. //初始化comboBox
  49. this.comboBox_Elem1.Items.Add("first_elem");
  50. this.comboBox_Elem1.Items.Add("second_elem");
  51. this.comboBox_Elem1.Items.Add("third_elem");
  52. this.comboBox_Elem1.Items.Add("forth_elem");
  53. this.comboBox_Elem1.Items.Add("fifth_elem");
  54. this.comboBox_Elem1.Items.Add("sixth_elem");
  55. this.comboBox_Elem1.Items.Add("seventh_elem");
  56. this.comboBox_Elem1.Items.Add("eighth_elem");
  57. this.comboBox_Elem1.Items.Add("ninth_elem");
  58. this.comboBox_Elem1.Items.Add("tenth_elem");
  59. comboBox_Elem1.SelectedIndex = comboBox_Elem1.Items.IndexOf("first_elem");
  60. this.comboBox_Elem.Items.Add("Element#1");
  61. this.comboBox_Elem.Items.Add("Element#2");
  62. this.comboBox_Elem.Items.Add("Element#3");
  63. this.comboBox_Elem.Items.Add("Element#4");
  64. this.comboBox_Elem.Items.Add("Element#5");
  65. this.comboBox_Elem.Items.Add("Element#6");
  66. this.comboBox_Elem.Items.Add("Element#7");
  67. this.comboBox_Elem.Items.Add("Element#8");
  68. this.comboBox_Elem.Items.Add("Element#9");
  69. this.comboBox_Elem.Items.Add("Element#10");
  70. comboBox_Elem.SelectedIndex = comboBox_Elem.Items.IndexOf("Element#1");
  71. this.comboBox_ImgProperty.Items.Add("Dmax");
  72. this.comboBox_ImgProperty.Items.Add("Dmin");
  73. this.comboBox_ImgProperty.Items.Add("Aspect");
  74. this.comboBox_ImgProperty.Items.Add("Dperp");
  75. this.comboBox_ImgProperty.Items.Add("Dmean");
  76. this.comboBox_ImgProperty.Items.Add("Area");
  77. this.comboBox_ImgProperty.Items.Add("Dferet");
  78. this.comboBox_ImgProperty.Items.Add("With");
  79. this.comboBox_ImgProperty.Items.Add("Height");
  80. this.comboBox_ImgProperty.Items.Add("Perimeter");
  81. this.comboBox_ImgProperty.Items.Add("Dinscr");
  82. this.comboBox_ImgProperty.Items.Add("Orientation");
  83. this.comboBox_ImgProperty.Items.Add("Delong");
  84. this.comboBox_ImgProperty.Items.Add("Aspectelong");
  85. this.comboBox_ImgProperty.Items.Add("Dequalcircle");
  86. this.comboBox_ImgProperty.Items.Add("Vedio");
  87. comboBox_ImgProperty.SelectedIndex = comboBox_ImgProperty.Items.IndexOf("Dmax");
  88. //this.comboBox_Constants.Items.Add("MAC#0");
  89. //this.comboBox_Constants.Items.Add("MAC#1");
  90. //this.comboBox_Constants.Items.Add("MAC#2");
  91. //this.comboBox_Constants.Items.Add("MAC#3");
  92. //this.comboBox_Constants.Items.Add("MAC#4");
  93. //this.comboBox_Constants.Items.Add("MAC#5");
  94. //this.comboBox_Constants.Items.Add("MAC#6");
  95. //this.comboBox_Constants.Items.Add("MAC#7");
  96. //this.comboBox_Constants.Items.Add("MAC#8");
  97. //this.comboBox_Constants.Items.Add("MAC#9");
  98. //comboBox_Constants.SelectedIndex = comboBox_Constants.Items.IndexOf("MAC#1");
  99. 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" };
  100. comboBox_PeriodicTable.Items.AddRange(PeriodicTable);
  101. AutoCompleteStringCollection sc = new AutoCompleteStringCollection();
  102. sc.AddRange(PeriodicTable);
  103. this.comboBox_PeriodicTable.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.Suggest;
  104. this.comboBox_PeriodicTable.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.CustomSource;
  105. this.comboBox_PeriodicTable.AutoCompleteCustomSource = sc;
  106. checkBox_0.Checked = false;
  107. checkBox_1.Checked = false;
  108. checkBox_2.Checked = false;
  109. checkBox_3.Checked = false;
  110. checkBox_4.Checked = false;
  111. checkBox_5.Checked = false;
  112. checkBox_6.Checked = false;
  113. checkBox_7.Checked = false;
  114. checkBox_8.Checked = false;
  115. checkBox_9.Checked = false;
  116. textBox_0.ReadOnly = true;
  117. textBox_1.ReadOnly = true;
  118. textBox_2.ReadOnly = true;
  119. textBox_3.ReadOnly = true;
  120. textBox_4.ReadOnly = true;
  121. textBox_5.ReadOnly = true;
  122. textBox_6.ReadOnly = true;
  123. textBox_7.ReadOnly = true;
  124. textBox_8.ReadOnly = true;
  125. textBox_9.ReadOnly = true;
  126. textBox_Density.ReadOnly = false;
  127. textBox_Electrical_conductivity.ReadOnly = false;
  128. textBox_BSEValue.ReadOnly = false;
  129. textBox_Formula.ReadOnly = false;
  130. textBox_Element.ReadOnly = false;
  131. textBox_Hardness.ReadOnly = false;
  132. btn_dbs.Enabled = true;
  133. dataGridView_KeyElements.RowHeadersVisible = false;
  134. dataGridView_KeyElements.ColumnHeadersVisible = false;
  135. dataGridView_KeyElements.AllowUserToAddRows = false;
  136. dataGridView_KeyElements.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
  137. dataGridView_SubElements.RowHeadersVisible = false;
  138. dataGridView_SubElements.ColumnHeadersVisible = false;
  139. dataGridView_SubElements.AllowUserToAddRows = false;
  140. dataGridView_SubElements.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
  141. XmlDocument doc = new XmlDocument();
  142. //string Address = Application.StartupPath.Substring(0, Application.StartupPath.Length-35) + "\\Opton\\OTSPartA\\OTS\\Bin\\Win32\\Debug\\Config\\SysData\\OTSParticleSTD.xml";
  143. //string Address = ".\\Config\\SysData\\OTSParticleSTD.xml";
  144. doc.Load(Address);
  145. LoadXmlToTreeControl(doc, XmlTree_STDlist.Nodes, XmlTree_MaxEDSRules.Nodes, XmlTree_ZeroElementRules.Nodes);
  146. button_UpOrder.Enabled = false;
  147. button_DownOrder.Enabled = false;
  148. textBox_MaxEDSTime.ReadOnly = true;
  149. this.textbox_STDEditor.Text = "";
  150. //this.XmlTree.TabStop = false;
  151. panel_OTSPeriodicTable.Visible = false;
  152. //修改窗体宽度
  153. //this.Width = this.Width - panel_OTSPeriodicTable.Width - 5;
  154. //if (XmlTree.GetNodeCount(true) != 0)
  155. //{
  156. // this.XmlTree.SelectedNode = XmlTree.Nodes[0];
  157. //}
  158. lan = new Language(this);
  159. table = lan.GetNameTable(this.Name);
  160. if (table["language"].ToString() == "EN")
  161. {
  162. panel_OTSPeriodicTable.BackgroundImage = global::OTSPartA_STDEditor.Properties.Resources.PeriodicTable_EN;
  163. PeriodicTableSwitch.BackgroundImage = global::OTSPartA_STDEditor.Properties.Resources.STDEditoName;
  164. PeriodicTableSwitch.Text = "";
  165. }
  166. else
  167. {
  168. panel_OTSPeriodicTable.BackgroundImage = global::OTSPartA_STDEditor.Properties.Resources.PeriodicTable_ZH;
  169. PeriodicTableSwitch.Text = "元素周期表";
  170. }
  171. panel_OTSPeriodicTable.Visible = false;
  172. this.Width = this.Width - panel_OTSPeriodicTable.Width - 5;
  173. Size size = Screen.PrimaryScreen.WorkingArea.Size; Left = (size.Width - Width) / 2;
  174. Top = (size.Height - Height) / 2;
  175. WindowState = FormWindowState.Normal;
  176. //groupBox_XmlTree_MaxEDSRules.Focus();
  177. this.XmlTree_STDlist.HideSelection = false;//失去焦点后不隐藏选中节点
  178. XmlTree_STDlist.Focus();
  179. if (XmlTree_STDlist.Nodes.Count > 0)
  180. {
  181. XmlTree_STDlist.SelectedNode = XmlTree_STDlist.Nodes[0];
  182. XmlTree_STDlist_AfterSelect(XmlTree_STDlist, new TreeViewEventArgs(XmlTree_STDlist.SelectedNode));
  183. }
  184. //添加Xray用户控件
  185. XrayControl = new UXrayControl();
  186. plXray.Controls.Add(XrayControl);
  187. XrayControl.Dock = DockStyle.Fill;
  188. //绑定数据库中的STDXray
  189. m_STDXrayList = new List<STDXray>();
  190. BindSTDXray();
  191. }
  192. /// <summary>
  193. /// [颜色:16进制转成RGB]
  194. /// </summary>
  195. /// <param name="strColor">设置16进制颜色 [返回RGB]</param>
  196. /// <returns></returns>
  197. public static System.Drawing.Color colorHx16toRGB(string strHxColor)
  198. {
  199. try
  200. {
  201. if (strHxColor.Length == 0)
  202. {//如果为空
  203. return System.Drawing.Color.FromArgb(255, 255, 204);//设为白色
  204. }
  205. else
  206. {//转换颜色
  207. 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));
  208. }
  209. }
  210. catch
  211. {//设为白色
  212. return System.Drawing.Color.FromArgb(255, 255, 204);
  213. }
  214. }
  215. /// <summary>
  216. /// [颜色:RGB转成16进制]
  217. /// </summary>
  218. /// <param name="R">红 int</param>
  219. /// <param name="G">绿 int</param>
  220. /// <param name="B">蓝 int</param>
  221. /// <returns></returns>
  222. public static string colorRGBtoHx16(int R, int G, int B)
  223. {
  224. return System.Drawing.ColorTranslator.ToHtml(System.Drawing.Color.FromArgb(R, G, B));
  225. }
  226. //XmlTree_STDlist、XmlTree_MaxEDSRules、XmlTree_ZeroElementRules和 ConstantsPage页
  227. void LoadXmlToTreeControl(XmlDocument xml, TreeNodeCollection XmlTree_STDlist, TreeNodeCollection XmlTree_MaxEDSRules, TreeNodeCollection XmlTree_ZeroElementRules)
  228. {
  229. XmlNode root = xml.SelectSingleNode("XMLData");
  230. XmlNodeList root2 = root.SelectNodes("Collection");
  231. for (int j = 0; j < root2.Count; j++)
  232. {
  233. if (root2[j].Attributes["RegName"].Value.ToString() == "STDList")
  234. {
  235. XmlNodeList childlist = root2[j].ChildNodes;
  236. for (int i = 0; i < childlist.Count; i++)
  237. {
  238. TreeNode new_child = new TreeNode();//定义一个TreeNode节点对象
  239. //BSE、化学式、元素
  240. string strBseValue = string.Empty;
  241. string strFormula = string.Empty;
  242. string strElement = string.Empty;
  243. if (childlist[i].Attributes["BSE"] != null)
  244. {
  245. strBseValue = childlist[i].Attributes["BSE"].Value;
  246. }
  247. if (childlist[i].Attributes["Formula"] != null)
  248. {
  249. strFormula = childlist[i].Attributes["Formula"].Value;
  250. }
  251. if (childlist[i].Attributes["Element"] != null)
  252. {
  253. strElement = childlist[i].Attributes["Element"].Value;
  254. }
  255. 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;
  256. new_child.Text = childlist[i].Attributes["StrName"].Value;
  257. new_child.Tag = childlist[i].Attributes["Expression"].Value;
  258. new_child.ToolTipText = childlist[i].Attributes["STDId"].Value;
  259. new_child.BackColor = colorHx16toRGB(childlist[i].Attributes["Color"].Value);
  260. XmlTree_STDlist.Add(new_child);
  261. }
  262. }
  263. if (root2[j].Attributes["RegName"].Value.ToString() == "ZeroElementRules")
  264. {
  265. XmlNodeList childlist = root2[j].ChildNodes;
  266. for (int i = 0; i < childlist.Count; i++)
  267. {
  268. TreeNode new_child = new TreeNode();//定义一个TreeNode节点对象
  269. new_child.Text = childlist[i].Attributes["ZeroElement"].Value+"=0";
  270. new_child.Tag = childlist[i].Attributes["Expression"].Value;
  271. XmlTree_ZeroElementRules.Add(new_child);
  272. }
  273. }
  274. if (root2[j].Attributes["RegName"].Value.ToString() == "MaxEDSRules")
  275. {
  276. XmlNodeList childlist = root2[j].ChildNodes;
  277. if (childlist.Count != 0)
  278. {
  279. for (int i = 0; i < childlist.Count; i++)
  280. {
  281. TreeNode new_child = new TreeNode();//定义一个TreeNode节点对象
  282. //new_child.Name = childlist[i].Attributes["MaxEDSTime"].Value;
  283. new_child.Tag = childlist[i].Attributes["Expression"].Value;
  284. new_child.Text = "Rule" + i.ToString();
  285. XmlTree_MaxEDSRules.Add(new_child);
  286. }
  287. if (childlist[0].Attributes["MaxEDSTime"] != null)
  288. {
  289. textBox_MaxEDSTime.Text = childlist[0].Attributes["MaxEDSTime"].Value;
  290. }
  291. }
  292. }
  293. }
  294. XmlNode root3 = root.SelectSingleNode("Member");
  295. string ConstantsStr = root3.Attributes["value"].Value;
  296. ConstantsStr = ConstantsStr.Replace(" ", "");
  297. string[] ConstantsStr2 = ConstantsStr.Split(',');
  298. this.comboBox_Constants.Items.Clear();
  299. this.comboBox_Constants.Items.AddRange(ConstantsStr2);
  300. List<string> Constantslist = new List<string>();
  301. for (int i = 0; i < ConstantsStr2.Length; i++)
  302. {
  303. Constantslist.AddRange(ConstantsStr2[i].Split('='));
  304. }
  305. for (int i = 0; i < Constantslist.Count; i += 2)
  306. {
  307. if (Constantslist[i].Contains("MAC#0"))
  308. {
  309. this.checkBox_0.Checked = true;
  310. this.textBox_0.ReadOnly = false;
  311. this.textBox_0.Text = Constantslist[i + 1];
  312. }
  313. else if (Constantslist[i].Contains("MAC#1"))
  314. {
  315. this.checkBox_1.Checked = true;
  316. this.textBox_1.ReadOnly = false;
  317. this.textBox_1.Text = Constantslist[i + 1];
  318. }
  319. else if (Constantslist[i].Contains("MAC#2"))
  320. {
  321. this.checkBox_2.Checked = true;
  322. this.textBox_2.ReadOnly = false;
  323. this.textBox_2.Text = Constantslist[i + 1];
  324. }
  325. else if (Constantslist[i].Contains("MAC#3"))
  326. {
  327. this.checkBox_3.Checked = true;
  328. this.textBox_3.ReadOnly = false;
  329. this.textBox_3.Text = Constantslist[i + 1];
  330. }
  331. else if (Constantslist[i].Contains("MAC#4"))
  332. {
  333. this.checkBox_4.Checked = true;
  334. this.textBox_4.ReadOnly = false;
  335. this.textBox_4.Text = Constantslist[i + 1];
  336. }
  337. else if (Constantslist[i].Contains("MAC#5"))
  338. {
  339. this.checkBox_5.Checked = true;
  340. this.textBox_5.ReadOnly = false;
  341. this.textBox_5.Text = Constantslist[i + 1];
  342. }
  343. else if (Constantslist[i].Contains("MAC#6"))
  344. {
  345. this.checkBox_6.Checked = true;
  346. this.textBox_6.ReadOnly = false;
  347. this.textBox_6.Text = Constantslist[i + 1];
  348. }
  349. else if (Constantslist[i].Contains("MAC#7"))
  350. {
  351. this.checkBox_7.Checked = true;
  352. this.textBox_7.ReadOnly = false;
  353. this.textBox_7.Text = Constantslist[i + 1];
  354. }
  355. else if (Constantslist[i].Contains("MAC#8"))
  356. {
  357. this.checkBox_8.Checked = true;
  358. this.textBox_8.ReadOnly = false;
  359. this.textBox_8.Text = Constantslist[i + 1];
  360. }
  361. else if (Constantslist[i].Contains("MAC#9"))
  362. {
  363. this.checkBox_9.Checked = true;
  364. this.textBox_9.ReadOnly = false;
  365. this.textBox_9.Text = Constantslist[i + 1];
  366. }
  367. }
  368. }
  369. private void comboBox_Elem1_SelectedIndexChanged(object sender, EventArgs e)
  370. {
  371. string newStr = comboBox_Elem1.SelectedItem.ToString();
  372. int index = textbox_STDEditor.SelectionStart;
  373. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, newStr);
  374. textbox_STDEditor.Focus();
  375. textbox_STDEditor.Select(index + newStr.Length, 0);
  376. textbox_STDEditor.ScrollToCaret();
  377. }
  378. private void comboBox_Elem2_SelectedIndexChanged(object sender, EventArgs e)
  379. {
  380. string newStr = comboBox_Elem.SelectedItem.ToString();
  381. int index = textbox_STDEditor.SelectionStart;
  382. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, newStr);
  383. textbox_STDEditor.Focus();
  384. textbox_STDEditor.Select(index + newStr.Length, 0);
  385. textbox_STDEditor.ScrollToCaret();
  386. }
  387. private void comboBox_ImgProperty_SelectedIndexChanged(object sender, EventArgs e)
  388. {
  389. string newStr = comboBox_ImgProperty.SelectedItem.ToString();
  390. int index = textbox_STDEditor.SelectionStart;
  391. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, newStr);
  392. textbox_STDEditor.Focus();
  393. textbox_STDEditor.Select(index + newStr.Length, 0);
  394. textbox_STDEditor.ScrollToCaret();
  395. }
  396. private void button_Plus_Click(object sender, EventArgs e)
  397. {
  398. //textbox_STDEditor 中的光标
  399. int index = textbox_STDEditor.SelectionStart;
  400. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "+");
  401. textbox_STDEditor.Focus();
  402. textbox_STDEditor.Select(index+1,0);
  403. textbox_STDEditor.ScrollToCaret();
  404. }
  405. private void button_Subtract_Click(object sender, EventArgs e)
  406. {
  407. //textbox_STDEditor 中的光标
  408. int index = textbox_STDEditor.SelectionStart;
  409. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "-");
  410. textbox_STDEditor.Focus();
  411. textbox_STDEditor.Select(index + 1, 0);
  412. textbox_STDEditor.ScrollToCaret();
  413. }
  414. private void button_Multiply_Click(object sender, EventArgs e)
  415. {
  416. //textbox_STDEditor 中的光标
  417. int index = textbox_STDEditor.SelectionStart;
  418. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "*");
  419. textbox_STDEditor.Focus();
  420. textbox_STDEditor.Select(index + 1, 0);
  421. textbox_STDEditor.ScrollToCaret();
  422. }
  423. private void button_Divide_Click(object sender, EventArgs e)
  424. {
  425. //textbox_STDEditor 中的光标
  426. int index = textbox_STDEditor.SelectionStart;
  427. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "/");
  428. textbox_STDEditor.Focus();
  429. textbox_STDEditor.Select(index + 1, 0);
  430. textbox_STDEditor.ScrollToCaret(); ;
  431. }
  432. private void button_More_Click(object sender, EventArgs e)
  433. {
  434. //textbox_STDEditor 中的光标
  435. int index = textbox_STDEditor.SelectionStart;
  436. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, ">");
  437. textbox_STDEditor.Focus();
  438. textbox_STDEditor.Select(index + 1, 0);
  439. textbox_STDEditor.ScrollToCaret();
  440. }
  441. private void button_Less_Click(object sender, EventArgs e)
  442. {
  443. //textbox_STDEditor 中的光标
  444. int index = textbox_STDEditor.SelectionStart;
  445. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "<");
  446. textbox_STDEditor.Focus();
  447. textbox_STDEditor.Select(index + 1, 0);
  448. textbox_STDEditor.ScrollToCaret();
  449. }
  450. private void button_LeftParenthesis_Click(object sender, EventArgs e)
  451. {
  452. //textbox_STDEditor 中的光标
  453. int index = textbox_STDEditor.SelectionStart;
  454. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "(");
  455. textbox_STDEditor.Focus();
  456. textbox_STDEditor.Select(index + 1, 0);
  457. textbox_STDEditor.ScrollToCaret();
  458. }
  459. private void button_RightParenthesis_Click(object sender, EventArgs e)
  460. {
  461. //textbox_STDEditor 中的光标
  462. int index = textbox_STDEditor.SelectionStart;
  463. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, ")");
  464. textbox_STDEditor.Focus();
  465. textbox_STDEditor.Select(index + 1, 0);
  466. textbox_STDEditor.ScrollToCaret();
  467. }
  468. private void button_Equal_Click(object sender, EventArgs e)
  469. {
  470. //textbox_STDEditor 中的光标
  471. int index = textbox_STDEditor.SelectionStart;
  472. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "=");
  473. textbox_STDEditor.Focus();
  474. textbox_STDEditor.Select(index + 1, 0);
  475. textbox_STDEditor.ScrollToCaret();
  476. }
  477. //除选中点以外其它节点前景色置灰
  478. private void SetGrayExceptSelectedNode(TreeView Tree, TreeNode SelectedNode)
  479. {
  480. foreach (TreeNode node in Tree.Nodes)
  481. {
  482. if (node != SelectedNode)
  483. {
  484. node.ForeColor = Color.Gray;
  485. }
  486. }
  487. }
  488. //恢复所有节点颜色为可用
  489. private void SetBlackAllNodes(TreeView Tree)
  490. {
  491. foreach (TreeNode node in Tree.Nodes)
  492. {
  493. node.ForeColor = Color.Black;
  494. }
  495. }
  496. //点击节点
  497. private void XmlTree_STDlist_MouseClick(object sender, MouseEventArgs e)
  498. {
  499. //if (e.Button == MouseButtons.Left)
  500. //{
  501. // Point ClickPoint = new Point(e.X, e.Y);
  502. // TreeNode CurrentNode = XmlTree_STDlist.GetNodeAt(ClickPoint);
  503. // if (CurrentNode != null)//判断你点的是不是一个节点
  504. // {
  505. // if (XmlTree_STDlist.SelectedNode != null&& XmlTree_STDlist.SelectedNode != CurrentNode)
  506. // {
  507. // //判断Hardness、Density、Electrical_conductivity
  508. // double dHardness = 0, dDensity = 0, dElectrical_conductivity = 0;
  509. // if (!double.TryParse(textBox_Hardness.Text, out dHardness))
  510. // {
  511. // MessageBox.Show("硬度输入错误,请输入数字!");
  512. // SetGrayExceptSelectedNode(XmlTree_STDlist, XmlTree_STDlist.SelectedNode);
  513. // return;
  514. // }
  515. // if (!double.TryParse(textBox_Density.Text, out dDensity))
  516. // {
  517. // MessageBox.Show("密度输入错误,请输入数字!");
  518. // SetGrayExceptSelectedNode(XmlTree_STDlist, XmlTree_STDlist.SelectedNode);
  519. // return;
  520. // }
  521. // if (!double.TryParse(textBox_Electrical_conductivity.Text, out dElectrical_conductivity))
  522. // {
  523. // MessageBox.Show("导电性输入错误,请输入数字!");
  524. // SetGrayExceptSelectedNode(XmlTree_STDlist, XmlTree_STDlist.SelectedNode);
  525. // return;
  526. // }
  527. // //判断textbox_STDEditor
  528. // if (!Checktextbox_STDEditor())
  529. // {
  530. // SetGrayExceptSelectedNode(XmlTree_STDlist, XmlTree_STDlist.SelectedNode);
  531. // return;
  532. // }
  533. // XmlTree_STDlist_SaveBeforeMouseClick(e);
  534. // }
  535. // SetBlackAllNodes(XmlTree_STDlist);
  536. // XmlTree_STDlist.SelectedNode = CurrentNode;
  537. // XmlTree_STDlist.LabelEdit = true;
  538. // this.textbox_STDEditor.Text = XmlTree_STDlist.SelectedNode.Tag.ToString();
  539. // btn_dbs.BackColor = XmlTree_STDlist.SelectedNode.BackColor;
  540. // string[] strOther = XmlTree_STDlist.SelectedNode.Name.Split('_');
  541. // textBox_Hardness.Text = strOther[0];
  542. // textBox_Density.Text = strOther[1];
  543. // textBox_Electrical_conductivity.Text = strOther[2];
  544. // if (UpOrder.Enabled == false)
  545. // {
  546. // UpOrder.Enabled = true;
  547. // }
  548. // if (DownOrder.Enabled == false)
  549. // {
  550. // DownOrder.Enabled = true;
  551. // }
  552. // if (XmlTree_STDlist.SelectedNode.PrevNode == null)
  553. // {
  554. // UpOrder.Enabled = false;
  555. // }
  556. // else if (XmlTree_STDlist.SelectedNode.NextNode == null)
  557. // {
  558. // DownOrder.Enabled = false;
  559. // }
  560. // }
  561. //}
  562. //if (e.Button == MouseButtons.Right)
  563. //{
  564. // Point ClickPoint = new Point(e.X, e.Y);
  565. // TreeNode CurrentNode = XmlTree.GetNodeAt(ClickPoint);
  566. // if (CurrentNode != null)//判断你点的是不是一个节点
  567. // {
  568. // XmlTree.SelectedNode = CurrentNode;//选中这个节点
  569. // XmlTree.LabelEdit = true;
  570. // this.textbox_STDEditor.Text = XmlTree.SelectedNode.Tag.ToString();
  571. // }
  572. //}
  573. }
  574. //XmlTree_STDlist点击节点前保存数据-Hardness、Density、Electrical_conductivity、textbox_STDEditor
  575. void XmlTree_STDlist_BeforeMouseClick(MouseEventArgs e)
  576. {
  577. if ((this.textbox_STDEditor.Text != null) && (XmlTree_STDlist.SelectedNode != null))
  578. {
  579. XmlTree_STDlist.SelectedNode.Tag = this.textbox_STDEditor.Text;
  580. XmlTree_STDlist.SelectedNode.Name = textBox_Hardness.Text + "_" + textBox_Density.Text + "_" + textBox_Electrical_conductivity.Text + "_" + textBox_BSEValue.Text + "_" + textBox_Formula.Text + "_" + textBox_Element.Text; ;
  581. string sKeyElements = "";
  582. for (int i = 0; i < dataGridView_KeyElements.Columns.Count; i++)
  583. {
  584. sKeyElements += dataGridView_KeyElements.Rows[0].Cells[i].Value.ToString() + ",";
  585. }
  586. if (sKeyElements.Length > 0)
  587. {
  588. sKeyElements = sKeyElements.Substring(0, sKeyElements.Length - 1);
  589. }
  590. string sSubElements = "";
  591. for (int i = 0; i < dataGridView_SubElements.Columns.Count; i++)
  592. {
  593. sSubElements += dataGridView_SubElements.Rows[0].Cells[i].Value.ToString() + ",";
  594. }
  595. if (sSubElements.Length > 0)
  596. {
  597. sSubElements = sSubElements.Substring(0, sSubElements.Length - 1);
  598. }
  599. XmlTree_STDlist.SelectedNode.Name += "$" + sKeyElements + "$" + sSubElements;
  600. }
  601. }
  602. //删除
  603. private void DeleteTreeNode_Click(object sender, EventArgs e)
  604. {
  605. try
  606. {
  607. TreeView XmlTree = (TreeView)XmlTreeMenuStrip.SourceControl;
  608. if (XmlTree.SelectedNode != null)
  609. {
  610. if (XmlTree != null)
  611. {
  612. if (XmlTree.SelectedNode.NextNode != null)
  613. {
  614. TreeNode Temp = XmlTree.SelectedNode.NextNode;
  615. XmlTree.SelectedNode.Remove();
  616. XmlTree.SelectedNode = Temp;
  617. }
  618. else if (XmlTree.SelectedNode.PrevNode != null)
  619. {
  620. TreeNode Temp = XmlTree.SelectedNode.PrevNode;
  621. XmlTree.SelectedNode.Remove();
  622. XmlTree.SelectedNode = Temp;
  623. }
  624. else
  625. {
  626. XmlTree.SelectedNode.Remove();
  627. XmlTree.SelectedNode = null;
  628. if (XmlTree.Name == "XmlTree_STDlist")
  629. {
  630. textbox_STDEditor.Text = "";
  631. textBox_Density.Text = "";
  632. textBox_Electrical_conductivity.Text = "";
  633. textBox_BSEValue.Text = "";
  634. textBox_Formula.Text = "";
  635. textBox_Element.Text = "";
  636. textBox_Hardness.Text = "";
  637. btn_dbs.BackColor = Color.White;
  638. }
  639. if (XmlTree.Name == "XmlTree_MaxEDSRules")
  640. {
  641. textbox_STDEditor.Text = "";
  642. textBox_MaxEDSTime.Text = "";
  643. }
  644. if (XmlTree.Name == "XmlTree_ZeroElementRules")
  645. {
  646. textbox_STDEditor.Text = "";
  647. }
  648. }
  649. }
  650. }
  651. else
  652. {
  653. MessageBox.Show(table["message1"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  654. }
  655. }
  656. catch (Exception ex)
  657. {
  658. MessageBox.Show(ex.ToString(), table["message32"].ToString());
  659. }
  660. }
  661. //新建
  662. private void AddTreeNode_Click(object sender, EventArgs e)
  663. {
  664. try
  665. {
  666. if (tabControl_Rules.SelectedIndex == 0)
  667. {
  668. //保存节点当前数据
  669. if (XmlTree_STDlist.SelectedNode != null)
  670. {
  671. //判断Hardness、Density、Electrical_conductivity
  672. double dHardness = 0, dDensity = 0, dElectrical_conductivity = 0;
  673. if (!double.TryParse(textBox_Hardness.Text, out dHardness) || (double.Parse(textBox_Hardness.Text) <= 0))
  674. {
  675. textBox_Hardness.Focus();
  676. textBox_Hardness.SelectAll();
  677. MessageBox.Show(table["message2"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  678. return;
  679. }
  680. if (!double.TryParse(textBox_Density.Text, out dDensity)||double.Parse(textBox_Density.Text)<=0)
  681. {
  682. textBox_Density.Focus();
  683. textBox_Density.SelectAll();
  684. MessageBox.Show(table["message3"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  685. return;
  686. }
  687. if (!double.TryParse(textBox_Electrical_conductivity.Text, out dElectrical_conductivity)||double.Parse(textBox_Electrical_conductivity.Text)<=0)
  688. {
  689. textBox_Electrical_conductivity.Focus();
  690. textBox_Electrical_conductivity.SelectAll();
  691. MessageBox.Show(table["message4"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  692. return;
  693. }
  694. if (textBox_BSEValue.Text.LastIndexOf("_") > 0)
  695. {
  696. MessageBox.Show(table["message5"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  697. textBox_BSEValue.Focus();
  698. return;
  699. }
  700. if (textBox_Formula.Text.LastIndexOf("_") > 0)
  701. {
  702. MessageBox.Show(table["message6"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  703. textBox_Formula.Focus();
  704. return;
  705. }
  706. if (textBox_Element.Text.LastIndexOf("_") > 0)
  707. {
  708. MessageBox.Show(table["message7"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  709. textBox_Element.Focus();
  710. return;
  711. }
  712. //判断textbox_STDEditor
  713. if (!Checktextbox_STDEditor())
  714. {
  715. return;
  716. }
  717. XmlTree_STDlist.SelectedNode.Tag = this.textbox_STDEditor.Text;
  718. XmlTree_STDlist.SelectedNode.Name = textBox_Hardness.Text + "_" + textBox_Density.Text + "_" + textBox_Electrical_conductivity.Text + "_" + textBox_BSEValue.Text + "_" + textBox_Formula.Text + "_" + textBox_Element.Text; ;
  719. string sKeyElements = "";
  720. for (int i = 0; i < dataGridView_KeyElements.Columns.Count; i++)
  721. {
  722. sKeyElements += dataGridView_KeyElements.Rows[0].Cells[i].Value.ToString() + ",";
  723. }
  724. if (sKeyElements.Length > 0)
  725. {
  726. sKeyElements = sKeyElements.Substring(0, sKeyElements.Length - 1);
  727. }
  728. string sSubElements = "";
  729. for (int i = 0; i < dataGridView_SubElements.Columns.Count; i++)
  730. {
  731. sSubElements += dataGridView_SubElements.Rows[0].Cells[i].Value.ToString() + ",";
  732. }
  733. if (sSubElements.Length > 0)
  734. {
  735. sSubElements = sSubElements.Substring(0, sSubElements.Length - 1);
  736. }
  737. XmlTree_STDlist.SelectedNode.Name += "$" + sKeyElements + "$" + sSubElements;
  738. }
  739. }
  740. else if (tabControl_Rules.SelectedIndex == 1)
  741. {
  742. if (XmlTree_MaxEDSRules.SelectedNode != null)
  743. {
  744. //判断MaxEDSTime
  745. double dMaxEDSTime = 0;
  746. if (!double.TryParse(textBox_MaxEDSTime.Text, out dMaxEDSTime) || double.Parse(textBox_MaxEDSTime.Text) <= 0)
  747. {
  748. MessageBox.Show(table["message8"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  749. return;
  750. }
  751. //判断textbox_STDEditor
  752. if (!Checktextbox_STDEditor())
  753. {
  754. return;
  755. }
  756. XmlTree_MaxEDSRules.SelectedNode.Tag = this.textbox_STDEditor.Text;
  757. //XmlTree_MaxEDSRules.SelectedNode.Name = textBox_MaxEDSTime.Text;
  758. }
  759. }
  760. else if (tabControl_Rules.SelectedIndex == 2)
  761. {
  762. if (XmlTree_ZeroElementRules.SelectedNode != null)
  763. {
  764. if (XmlTree_ZeroElementRules.SelectedNode.Text.Contains("="))
  765. {
  766. if (!comboBox_PeriodicTable.Items.Contains(XmlTree_ZeroElementRules.SelectedNode.Text.Split('=')[0]))
  767. {
  768. MessageBox.Show(XmlTree_ZeroElementRules.SelectedNode.Text + table["message9"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  769. return;
  770. }
  771. }
  772. else
  773. {
  774. MessageBox.Show(XmlTree_ZeroElementRules.SelectedNode.Text + table["message9"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  775. return;
  776. }
  777. //判断textbox_STDEditor
  778. if (!Checktextbox_STDEditor())
  779. {
  780. return;
  781. }
  782. XmlTree_ZeroElementRules.SelectedNode.Tag = this.textbox_STDEditor.Text;
  783. }
  784. }
  785. dataGridView_KeyElements.Rows.Clear();
  786. dataGridView_KeyElements.Columns.Clear();
  787. dataGridView_SubElements.Rows.Clear();
  788. dataGridView_SubElements.Columns.Clear();
  789. TreeNode new_child = new TreeNode();//定义一个TreeNode节点对象
  790. TreeView XmlTree = (TreeView)XmlTreeMenuStrip.SourceControl;
  791. if (XmlTreeMenuStrip.SourceControl.Name == "XmlTree_STDlist")
  792. {
  793. new_child.Name = "1_1_1$$";
  794. new_child.Text = "new strName";
  795. new_child.Tag = "NewRules";
  796. textbox_STDEditor.Text = "NewRules";
  797. textBox_Density.Text = "1";
  798. textBox_Electrical_conductivity.Text = "1";
  799. textBox_Hardness.Text = "1";
  800. new_child.BackColor = Color.White;
  801. int STDId = 1;
  802. for (int i = 0; i < XmlTree_STDlist.Nodes.Count; i++)
  803. {
  804. if (STDId < int.Parse(XmlTree_STDlist.Nodes[i].ToolTipText))
  805. {
  806. STDId = int.Parse(XmlTree_STDlist.Nodes[i].ToolTipText);
  807. }
  808. }
  809. new_child.ToolTipText = (STDId+1).ToString();
  810. }
  811. if (XmlTreeMenuStrip.SourceControl.Name == "XmlTree_MaxEDSRules")
  812. {
  813. int Number = XmlTree.Nodes.Count;
  814. for (int num = 0; num < XmlTree.Nodes.Count; num++)
  815. {
  816. string aa = XmlTree.Nodes[num].Text.ToString().Substring(XmlTree.Nodes[num].Text.Length - 1, 1);
  817. int tp = int.Parse(XmlTree.Nodes[num].Text.ToString().Substring(XmlTree.Nodes[num].Text.Length - 1, 1));
  818. if (Number < tp) Number = tp;
  819. }
  820. new_child.Text = "Rule" + Number.ToString();
  821. new_child.Tag = "NewRules";
  822. textbox_STDEditor.Text = "NewRules";
  823. }
  824. if (XmlTreeMenuStrip.SourceControl.Name == "XmlTree_ZeroElementRules")
  825. {
  826. new_child.Text = "NewElement=0";
  827. new_child.Tag = "NewRules";
  828. textbox_STDEditor.Text = "NewRules";
  829. }
  830. XmlTree.Nodes.Add(new_child);
  831. XmlTree.SelectedNode = null;
  832. XmlTree.SelectedNode = new_child;
  833. //添加STDXray信息
  834. AddSTDXray(XmlTree.SelectedNode, xrayByteData);
  835. }
  836. catch (Exception ex)
  837. {
  838. MessageBox.Show(ex.ToString(), table["message32"].ToString());
  839. }
  840. }
  841. //双击节点
  842. private void XmlTree_STDlist_MouseDoubleClick(object sender, MouseEventArgs e)
  843. {
  844. if (e.Button == MouseButtons.Left)
  845. {
  846. Point ClickPoint = new Point(e.X, e.Y);
  847. TreeNode CurrentNode = XmlTree_STDlist.GetNodeAt(ClickPoint);
  848. if (CurrentNode != null)//判断你点的是不是一个节点
  849. {
  850. XmlTree_STDlist.SelectedNode = CurrentNode;//选中这个节点
  851. XmlTree_STDlist.LabelEdit = true;
  852. XmlTree_STDlist.SelectedNode.BeginEdit();
  853. }
  854. }
  855. }
  856. //保存xmltree内容到xml文件
  857. void SaveXmlTreeDataToXml(string Address)
  858. {
  859. XDocument xdoc = XDocument.Load(Address);
  860. IEnumerable<XElement> elements = from ele in xdoc.Descendants("XMLData") select ele;
  861. foreach (var ele in elements)
  862. {
  863. if (ele != null)
  864. {
  865. ele.RemoveAll();
  866. }
  867. }
  868. string value = "";
  869. foreach (var str in comboBox_Constants.Items)
  870. {
  871. value += str + ",";
  872. }
  873. if (value != "")
  874. {
  875. value = value.Substring(0, value.Length - 1);
  876. }
  877. XElement Constant = new XElement("Member");
  878. Constant.SetAttributeValue("RegName", "Constants");
  879. Constant.SetAttributeValue("value", value);
  880. elements.ElementAt(0).Add(Constant);
  881. XElement ZeroElement = new XElement("Collection");
  882. ZeroElement.SetAttributeValue("RegName", "ZeroElementRules");
  883. elements.ElementAt(0).Add(ZeroElement);
  884. for (int num = 0; num < XmlTree_ZeroElementRules.Nodes.Count; num++)
  885. {
  886. string UsingElementList = "";
  887. string UsingImgPropertyList = "";
  888. string UsingOtherPropertyList = "";
  889. List<string> UsingElementL = new List<string>();
  890. List<string> UsingImgPropertyL = new List<string>();
  891. List<string> UsingOtherPropertyL = new List<string>();
  892. string str_RemoveBlank = "";
  893. //forth_elem干扰or分隔符,故先行去掉
  894. if (XmlTree_ZeroElementRules.Nodes[num].Tag.ToString().Contains("forth_elem"))
  895. {
  896. str_RemoveBlank = str_RemoveBlank.Replace("forth_elem", "");
  897. UsingOtherPropertyL.Add("forth_elem");
  898. }
  899. str_RemoveBlank = XmlTree_ZeroElementRules.Nodes[num].Tag.ToString().Replace(" ", "");
  900. string[] str_Removeand = System.Text.RegularExpressions.Regex.Split(str_RemoveBlank, "and", System.Text.RegularExpressions.RegexOptions.None);
  901. List<string> str_Removeandor = new List<string>();
  902. for (int i = 0; i < str_Removeand.Length; i++)
  903. {
  904. str_Removeandor.AddRange(System.Text.RegularExpressions.Regex.Split(str_Removeand[i], "or", System.Text.RegularExpressions.RegexOptions.None));
  905. }
  906. List<string> list_all = new List<string>();
  907. for (int i = 0; i < str_Removeandor.Count; i++)
  908. {
  909. list_all.AddRange(str_Removeandor[i].Split(new char[] { '+', '-', '*', '/', '=', '>', '<', '(', ')' }));
  910. }
  911. for (int i = 0; i < list_all.Count; i++)
  912. {
  913. //周期元素?
  914. if (this.comboBox_PeriodicTable.Items.Contains(list_all[i]))
  915. {
  916. if (!UsingElementL.Contains(list_all[i]))
  917. {
  918. UsingElementL.Add(list_all[i]);
  919. }
  920. }
  921. //first_elem?
  922. if (this.comboBox_Elem1.Items.Contains(list_all[i]))
  923. {
  924. if (!UsingOtherPropertyL.Contains(list_all[i]))
  925. {
  926. UsingOtherPropertyL.Add(list_all[i]);
  927. }
  928. }
  929. //Element1?
  930. if (this.comboBox_Elem.Items.Contains(list_all[i]))
  931. {
  932. if (!UsingOtherPropertyL.Contains(list_all[i]))
  933. {
  934. UsingOtherPropertyL.Add(list_all[i]);
  935. }
  936. }
  937. //其它元素?
  938. if (this.comboBox_ImgProperty.Items.Contains(list_all[i]))
  939. {
  940. if (!UsingImgPropertyL.Contains(list_all[i]))
  941. {
  942. UsingImgPropertyL.Add(list_all[i]);
  943. }
  944. }
  945. }
  946. if (UsingElementL.Count > 0)
  947. {
  948. for (int i = 0; i < UsingElementL.Count - 1; i++)
  949. {
  950. UsingElementList += UsingElementL[i] + ",";
  951. }
  952. UsingElementList += UsingElementL[UsingElementL.Count - 1];
  953. }
  954. if (UsingImgPropertyL.Count > 0)
  955. {
  956. for (int i = 0; i < UsingImgPropertyL.Count - 1; i++)
  957. {
  958. UsingImgPropertyList += UsingImgPropertyL[i] + ",";
  959. }
  960. UsingImgPropertyList += UsingImgPropertyL[UsingImgPropertyL.Count - 1];
  961. }
  962. if (UsingOtherPropertyL.Count > 0)
  963. {
  964. for (int i = 0; i < UsingOtherPropertyL.Count - 1; i++)
  965. {
  966. UsingOtherPropertyList += UsingOtherPropertyL[i] + ",";
  967. }
  968. UsingOtherPropertyList += UsingOtherPropertyL[UsingOtherPropertyL.Count - 1];
  969. }
  970. XElement EleName = new XElement("Member");
  971. EleName.SetAttributeValue("ZeroElement", XmlTree_ZeroElementRules.Nodes[num].Text.Split('=')[0]);
  972. EleName.SetAttributeValue("UsingElementList", UsingElementList);
  973. EleName.SetAttributeValue("UsingImgPropertyList", UsingImgPropertyList);
  974. EleName.SetAttributeValue("UsingOtherPropertyList", UsingOtherPropertyList);
  975. EleName.SetAttributeValue("Expression", XmlTree_ZeroElementRules.Nodes[num].Tag);
  976. ZeroElement.Add(EleName);
  977. }
  978. XElement MaxEDS = new XElement("Collection");
  979. MaxEDS.SetAttributeValue("RegName", "MaxEDSRules");
  980. elements.ElementAt(0).Add(MaxEDS);
  981. for (int num = 0; num < XmlTree_MaxEDSRules.Nodes.Count; num++)
  982. {
  983. string UsingElementList = "";
  984. string UsingImgPropertyList = "";
  985. string UsingOtherPropertyList = "";
  986. List<string> UsingElementL = new List<string>();
  987. List<string> UsingImgPropertyL = new List<string>();
  988. List<string> UsingOtherPropertyL = new List<string>();
  989. string str_RemoveBlank = "";
  990. //forth_elem干扰or分隔符,故先行去掉
  991. if (XmlTree_MaxEDSRules.Nodes[num].Tag.ToString().Contains("forth_elem"))
  992. {
  993. str_RemoveBlank = str_RemoveBlank.Replace("forth_elem", "");
  994. UsingOtherPropertyList = "forth_elem,";
  995. }
  996. str_RemoveBlank = XmlTree_MaxEDSRules.Nodes[num].Tag.ToString().Replace(" ", "");
  997. string[] str_Removeand = System.Text.RegularExpressions.Regex.Split(str_RemoveBlank, "and", System.Text.RegularExpressions.RegexOptions.None);
  998. List<string> str_Removeandor = new List<string>();
  999. for (int i = 0; i < str_Removeand.Length; i++)
  1000. {
  1001. str_Removeandor.AddRange(System.Text.RegularExpressions.Regex.Split(str_Removeand[i], "or", System.Text.RegularExpressions.RegexOptions.None));
  1002. }
  1003. List<string> list_all = new List<string>();
  1004. for (int i = 0; i < str_Removeandor.Count; i++)
  1005. {
  1006. list_all.AddRange(str_Removeandor[i].Split(new char[] { '+', '-', '*', '/', '=', '>', '<', '(', ')' }));
  1007. }
  1008. for (int i = 0; i < list_all.Count; i++)
  1009. {
  1010. //周期元素?
  1011. if (this.comboBox_PeriodicTable.Items.Contains(list_all[i]))
  1012. {
  1013. if (!UsingElementL.Contains(list_all[i]))
  1014. {
  1015. UsingElementL.Add(list_all[i]);
  1016. }
  1017. }
  1018. //first_elem?
  1019. if (this.comboBox_Elem1.Items.Contains(list_all[i]))
  1020. {
  1021. if (!UsingOtherPropertyL.Contains(list_all[i]))
  1022. {
  1023. UsingOtherPropertyL.Add(list_all[i]);
  1024. }
  1025. }
  1026. //Element1?
  1027. if (this.comboBox_Elem.Items.Contains(list_all[i]))
  1028. {
  1029. if (!UsingOtherPropertyL.Contains(list_all[i]))
  1030. {
  1031. UsingOtherPropertyL.Add(list_all[i]);
  1032. }
  1033. }
  1034. //其它元素?
  1035. if (this.comboBox_ImgProperty.Items.Contains(list_all[i]))
  1036. {
  1037. if (!UsingImgPropertyL.Contains(list_all[i]))
  1038. {
  1039. UsingImgPropertyL.Add(list_all[i]);
  1040. }
  1041. }
  1042. }
  1043. if (UsingElementL.Count > 0)
  1044. {
  1045. for (int i = 0; i < UsingElementL.Count - 1; i++)
  1046. {
  1047. UsingElementList += UsingElementL[i] + ",";
  1048. }
  1049. UsingElementList += UsingElementL[UsingElementL.Count - 1];
  1050. }
  1051. if (UsingImgPropertyL.Count > 0)
  1052. {
  1053. for (int i = 0; i < UsingImgPropertyL.Count - 1; i++)
  1054. {
  1055. UsingImgPropertyList += UsingImgPropertyL[i] + ",";
  1056. }
  1057. UsingImgPropertyList += UsingImgPropertyL[UsingImgPropertyL.Count - 1];
  1058. }
  1059. if (UsingOtherPropertyL.Count > 0)
  1060. {
  1061. for (int i = 0; i < UsingOtherPropertyL.Count - 1; i++)
  1062. {
  1063. UsingOtherPropertyList += UsingOtherPropertyL[i] + ",";
  1064. }
  1065. UsingOtherPropertyList += UsingOtherPropertyL[UsingOtherPropertyL.Count - 1];
  1066. }
  1067. XElement EleName = new XElement("Member");
  1068. //EleName.SetAttributeValue("MaxEDSTime", XmlTree_MaxEDSRules.Nodes[num].Name);
  1069. EleName.SetAttributeValue("MaxEDSTime", textBox_MaxEDSTime.Text);
  1070. EleName.SetAttributeValue("UsingElementList", UsingElementList);
  1071. EleName.SetAttributeValue("UsingImgPropertyList", UsingImgPropertyList);
  1072. EleName.SetAttributeValue("UsingOtherPropertyList", UsingOtherPropertyList);
  1073. EleName.SetAttributeValue("Expression", XmlTree_MaxEDSRules.Nodes[num].Tag);
  1074. MaxEDS.Add(EleName);
  1075. }
  1076. XElement STD = new XElement("Collection");
  1077. STD.SetAttributeValue("RegName", "STDList");
  1078. elements.ElementAt(0).Add(STD);
  1079. for (int num = 0; num < XmlTree_STDlist.Nodes.Count; num++)
  1080. {
  1081. string UsingElementList = "";
  1082. string UsingImgPropertyList = "";
  1083. string UsingOtherPropertyList = "";
  1084. List<string> UsingElementL = new List<string>();
  1085. List<string> UsingImgPropertyL = new List<string>();
  1086. List<string> UsingOtherPropertyL = new List<string>();
  1087. string str_RemoveBlank = "";
  1088. //forth_elem干扰or分隔符,故先行去掉
  1089. if (XmlTree_STDlist.Nodes[num].Tag.ToString().Contains("forth_elem"))
  1090. {
  1091. str_RemoveBlank = str_RemoveBlank.Replace("forth_elem", "");
  1092. UsingOtherPropertyList = "forth_elem,";
  1093. }
  1094. str_RemoveBlank = XmlTree_STDlist.Nodes[num].Tag.ToString().Replace(" ", "");
  1095. string[] str_Removeand = System.Text.RegularExpressions.Regex.Split(str_RemoveBlank, "and", System.Text.RegularExpressions.RegexOptions.None);
  1096. List<string> str_Removeandor = new List<string>();
  1097. for (int i = 0; i < str_Removeand.Length; i++)
  1098. {
  1099. str_Removeandor.AddRange(System.Text.RegularExpressions.Regex.Split(str_Removeand[i], "or", System.Text.RegularExpressions.RegexOptions.None));
  1100. }
  1101. List<string> list_all = new List<string>();
  1102. for (int i = 0; i < str_Removeandor.Count; i++)
  1103. {
  1104. list_all.AddRange(str_Removeandor[i].Split(new char[] { '+', '-', '*', '/', '=', '>', '<', '(', ')' }));
  1105. }
  1106. for (int i = 0; i < list_all.Count; i++)
  1107. {
  1108. //周期元素?
  1109. if (this.comboBox_PeriodicTable.Items.Contains(list_all[i]))
  1110. {
  1111. if (!UsingElementL.Contains(list_all[i]))
  1112. {
  1113. UsingElementL.Add(list_all[i]);
  1114. }
  1115. }
  1116. //first_elem?
  1117. if (this.comboBox_Elem1.Items.Contains(list_all[i]))
  1118. {
  1119. if (!UsingOtherPropertyL.Contains(list_all[i]))
  1120. {
  1121. UsingOtherPropertyL.Add(list_all[i]);
  1122. }
  1123. }
  1124. //Element1?
  1125. if (this.comboBox_Elem.Items.Contains(list_all[i]))
  1126. {
  1127. if (!UsingOtherPropertyL.Contains(list_all[i]))
  1128. {
  1129. UsingOtherPropertyL.Add(list_all[i]);
  1130. }
  1131. }
  1132. //其它元素?
  1133. if (this.comboBox_ImgProperty.Items.Contains(list_all[i]))
  1134. {
  1135. if (!UsingImgPropertyL.Contains(list_all[i]))
  1136. {
  1137. UsingImgPropertyL.Add(list_all[i]);
  1138. }
  1139. }
  1140. }
  1141. if (UsingElementL.Count > 0)
  1142. {
  1143. for (int i = 0; i < UsingElementL.Count - 1; i++)
  1144. {
  1145. UsingElementList += UsingElementL[i] + ",";
  1146. }
  1147. UsingElementList += UsingElementL[UsingElementL.Count - 1];
  1148. }
  1149. if (UsingImgPropertyL.Count > 0)
  1150. {
  1151. for (int i = 0; i < UsingImgPropertyL.Count - 1; i++)
  1152. {
  1153. UsingImgPropertyList += UsingImgPropertyL[i] + ",";
  1154. }
  1155. UsingImgPropertyList += UsingImgPropertyL[UsingImgPropertyL.Count - 1];
  1156. }
  1157. if (UsingOtherPropertyL.Count > 0)
  1158. {
  1159. for (int i = 0; i < UsingOtherPropertyL.Count - 1; i++)
  1160. {
  1161. UsingOtherPropertyList += UsingOtherPropertyL[i] + ",";
  1162. }
  1163. UsingOtherPropertyList += UsingOtherPropertyL[UsingOtherPropertyL.Count - 1];
  1164. }
  1165. string[] str = XmlTree_STDlist.Nodes[num].Name.Split('$');
  1166. string[] strOther = str[0].Split('_');
  1167. XElement EleName = new XElement("Member");
  1168. EleName.SetAttributeValue("STDId", XmlTree_STDlist.Nodes[num].ToolTipText);
  1169. EleName.SetAttributeValue("StrName", XmlTree_STDlist.Nodes[num].Text);
  1170. EleName.SetAttributeValue("Color", colorRGBtoHx16(XmlTree_STDlist.Nodes[num].BackColor.R, XmlTree_STDlist.Nodes[num].BackColor.G, XmlTree_STDlist.Nodes[num].BackColor.B));
  1171. //EleName.SetAttributeValue("UsingElementList", UsingElementList);
  1172. EleName.SetAttributeValue("KeyElementList", str[1]);
  1173. EleName.SetAttributeValue("SubElementList", str[2]);
  1174. EleName.SetAttributeValue("UsingImgPropertyList", UsingImgPropertyList);
  1175. EleName.SetAttributeValue("UsingOtherPropertyList", UsingOtherPropertyList);
  1176. EleName.SetAttributeValue("Expression", XmlTree_STDlist.Nodes[num].Tag);
  1177. EleName.SetAttributeValue("Hardness", strOther[0]);
  1178. EleName.SetAttributeValue("Density", strOther[1]);
  1179. EleName.SetAttributeValue("Electrical_conductivity", strOther[2]);
  1180. if (strOther.Length > 3)
  1181. {
  1182. EleName.SetAttributeValue("BSE", strOther[3]);
  1183. EleName.SetAttributeValue("Formula", strOther[4]);
  1184. EleName.SetAttributeValue("Element", strOther[5]);
  1185. }
  1186. else
  1187. {
  1188. EleName.SetAttributeValue("BSE", "");
  1189. EleName.SetAttributeValue("Formula", "");
  1190. EleName.SetAttributeValue("Element", "");
  1191. }
  1192. STD.Add(EleName);
  1193. }
  1194. xdoc.Save(Address);
  1195. }
  1196. //元素周期表开关
  1197. private void PeriodicTableSwitch_Click(object sender, EventArgs e)
  1198. {
  1199. if (PeriodicTableSwitch.BackColor == SystemColors.Control)
  1200. {
  1201. panel_OTSPeriodicTable.Visible = true;
  1202. this.Width = this.Width + panel_OTSPeriodicTable.Width + 5;
  1203. PeriodicTableSwitch.BackColor = SystemColors.ControlDark;
  1204. //if (Language == "English")
  1205. //{
  1206. // PeriodicTableSwitch.Text = "Close PeriodicTable";
  1207. //}
  1208. //else if(Language == "Chinese")
  1209. //{
  1210. // PeriodicTableSwitch.Text = "关闭元素周期表";
  1211. //}
  1212. }
  1213. else if (PeriodicTableSwitch.BackColor == SystemColors.ControlDark)
  1214. {
  1215. panel_OTSPeriodicTable.Visible = false;
  1216. this.Width = this.Width - panel_OTSPeriodicTable.Width - 5;
  1217. PeriodicTableSwitch.BackColor = SystemColors.Control;
  1218. //if (Language == "English")
  1219. //{
  1220. // PeriodicTableSwitch.Text = "Open PeriodicTable";
  1221. //}
  1222. //else if (Language == "Chinese")
  1223. //{
  1224. // PeriodicTableSwitch.Text = "打开元素周期表";
  1225. //}
  1226. //textbox_STDEditor.Focus();
  1227. groupBox_XmlTree_MaxEDSRules.Focus();
  1228. }
  1229. }
  1230. private void button_Ok_Click(object sender, EventArgs e)
  1231. {
  1232. if (tabControl_Rules.SelectedIndex == 0)
  1233. {
  1234. //保存节点当前数据
  1235. if (XmlTree_STDlist.SelectedNode != null)
  1236. {
  1237. //判断Hardness、Density、Electrical_conductivity
  1238. double dHardness = 0, dDensity = 0, dElectrical_conductivity = 0;
  1239. if (!double.TryParse(textBox_Hardness.Text, out dHardness) || (double.Parse(textBox_Hardness.Text) <= 0))
  1240. {
  1241. textBox_Hardness.Focus();
  1242. textBox_Hardness.SelectAll();
  1243. MessageBox.Show(table["message10"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  1244. return;
  1245. }
  1246. if (!double.TryParse(textBox_Density.Text, out dDensity) || double.Parse(textBox_Density.Text) <= 0)
  1247. {
  1248. textBox_Density.Focus();
  1249. textBox_Density.SelectAll();
  1250. MessageBox.Show(table["message11"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  1251. return;
  1252. }
  1253. if (!double.TryParse(textBox_Electrical_conductivity.Text, out dElectrical_conductivity) || double.Parse(textBox_Electrical_conductivity.Text) <= 0)
  1254. {
  1255. textBox_Electrical_conductivity.Focus();
  1256. textBox_Electrical_conductivity.SelectAll();
  1257. MessageBox.Show(table["message12"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  1258. return;
  1259. }
  1260. if (textBox_BSEValue.Text.LastIndexOf("_") > 0)
  1261. {
  1262. textBox_BSEValue.Focus();
  1263. textBox_BSEValue.SelectAll();
  1264. MessageBox.Show(table["message13"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  1265. textBox_BSEValue.Focus();
  1266. return;
  1267. }
  1268. if (textBox_Formula.Text.LastIndexOf("_") > 0)
  1269. {
  1270. textBox_Formula.Focus();
  1271. textBox_Formula.SelectAll();
  1272. MessageBox.Show(table["message14"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  1273. textBox_Formula.Focus();
  1274. return;
  1275. }
  1276. if (textBox_Element.Text.LastIndexOf("_") > 0)
  1277. {
  1278. textBox_Element.Focus();
  1279. textBox_Element.SelectAll();
  1280. MessageBox.Show(table["message15"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  1281. textBox_Element.Focus();
  1282. return;
  1283. }
  1284. //判断textbox_STDEditor
  1285. if (!Checktextbox_STDEditor())
  1286. {
  1287. return;
  1288. }
  1289. XmlTree_STDlist.SelectedNode.Tag = this.textbox_STDEditor.Text;
  1290. XmlTree_STDlist.SelectedNode.Name = textBox_Hardness.Text + "_" + textBox_Density.Text + "_" + textBox_Electrical_conductivity.Text + "_" + textBox_BSEValue.Text + "_" + textBox_Formula.Text + "_" + textBox_Element.Text;
  1291. string sKeyElements = "";
  1292. for (int i = 0; i < dataGridView_KeyElements.Columns.Count; i++)
  1293. {
  1294. sKeyElements += dataGridView_KeyElements.Rows[0].Cells[i].Value.ToString() + ",";
  1295. }
  1296. if (sKeyElements.Length > 0)
  1297. {
  1298. sKeyElements = sKeyElements.Substring(0, sKeyElements.Length - 1);
  1299. }
  1300. string sSubElements = "";
  1301. for (int i = 0; i < dataGridView_SubElements.Columns.Count; i++)
  1302. {
  1303. sSubElements += dataGridView_SubElements.Rows[0].Cells[i].Value.ToString() + ",";
  1304. }
  1305. if (sSubElements.Length > 0)
  1306. {
  1307. sSubElements = sSubElements.Substring(0, sSubElements.Length - 1);
  1308. }
  1309. XmlTree_STDlist.SelectedNode.Name += "$" + sKeyElements + "$" + sSubElements;
  1310. }
  1311. }
  1312. else if (tabControl_Rules.SelectedIndex == 1)
  1313. {
  1314. if (XmlTree_MaxEDSRules.SelectedNode != null)
  1315. {
  1316. //判断MaxEDSTime
  1317. double dMaxEDSTime = 0;
  1318. if (!double.TryParse(textBox_MaxEDSTime.Text, out dMaxEDSTime) || double.Parse(textBox_MaxEDSTime.Text) <= 0)
  1319. {
  1320. textBox_MaxEDSTime.Focus();
  1321. textBox_MaxEDSTime.SelectAll();
  1322. MessageBox.Show(table["message16"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  1323. return;
  1324. }
  1325. //判断textbox_STDEditor
  1326. if (!Checktextbox_STDEditor())
  1327. {
  1328. return;
  1329. }
  1330. XmlTree_MaxEDSRules.SelectedNode.Tag = this.textbox_STDEditor.Text;
  1331. //XmlTree_MaxEDSRules.SelectedNode.Name = textBox_MaxEDSTime.Text;
  1332. }
  1333. }
  1334. else if (tabControl_Rules.SelectedIndex == 2)
  1335. {
  1336. if (XmlTree_ZeroElementRules.SelectedNode != null)
  1337. {
  1338. if (XmlTree_ZeroElementRules.SelectedNode.Text.Contains("="))
  1339. {
  1340. if (!comboBox_PeriodicTable.Items.Contains(XmlTree_ZeroElementRules.SelectedNode.Text.Split('=')[0]))
  1341. {
  1342. MessageBox.Show(XmlTree_ZeroElementRules.SelectedNode.Text + table["message9"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  1343. return;
  1344. }
  1345. }
  1346. else
  1347. {
  1348. MessageBox.Show(XmlTree_ZeroElementRules.SelectedNode.Text + table["message9"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  1349. return;
  1350. }
  1351. //判断textbox_STDEditor
  1352. if (!Checktextbox_STDEditor())
  1353. {
  1354. return;
  1355. }
  1356. XmlTree_ZeroElementRules.SelectedNode.Tag = this.textbox_STDEditor.Text;
  1357. }
  1358. }
  1359. string value = "";
  1360. foreach (var str in comboBox_Constants.Items)
  1361. {
  1362. value += str + ",";
  1363. }
  1364. if (value != "")
  1365. {
  1366. value = value.Substring(0, value.Length - 1);
  1367. }
  1368. //string Address = Application.StartupPath + "\\Config\\SysData\\OTSParticleSTD.xml";
  1369. //string Address = ".\\Config\\SysData\\OTSParticleSTD.xml";
  1370. SaveXmlTreeDataToXml(Address);
  1371. //保存STDXray信息至数据库
  1372. SaveSTDXray();
  1373. this.Close();
  1374. }
  1375. private void button_Cancel_Click(object sender, EventArgs e)
  1376. {
  1377. this.Close();
  1378. }
  1379. //元素下拉选择输入
  1380. private void comboBox_PeriodicTable_SelectedIndexChanged(object sender, EventArgs e)
  1381. {
  1382. if (comboBox_PeriodicTable.Text != null && comboBox_PeriodicTable.SelectedItem != null)
  1383. {
  1384. string newStr = comboBox_PeriodicTable.SelectedItem.ToString();
  1385. comboBox_PeriodicTable.Text = null;
  1386. int index = textbox_STDEditor.SelectionStart;
  1387. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, newStr);
  1388. textbox_STDEditor.Focus();
  1389. textbox_STDEditor.Select(index + newStr.Length, 0);
  1390. textbox_STDEditor.ScrollToCaret();
  1391. }
  1392. }
  1393. //元素自身text按回车键输入
  1394. private void comboBox_PeriodicTable_KeyDown(object sender, KeyEventArgs e)
  1395. {
  1396. if (e.KeyValue == 13)
  1397. {
  1398. if (comboBox_PeriodicTable.Text != null && comboBox_PeriodicTable.Text != "")
  1399. {
  1400. this.textbox_STDEditor.Text += comboBox_PeriodicTable.Text.ToString();
  1401. comboBox_PeriodicTable.Text = null;
  1402. }
  1403. }
  1404. }
  1405. //表达式规则检查
  1406. private bool Checktextbox_STDEditor()
  1407. {
  1408. if (textbox_STDEditor.Text == "" || textbox_STDEditor.Text == null)
  1409. {
  1410. textBox_MaxEDSTime.Focus();
  1411. MessageBox.Show(table["message17"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  1412. return false;
  1413. }
  1414. string str_RemoveBlank = textbox_STDEditor.Text.ToString().Replace(" ", "");
  1415. str_RemoveBlank = str_RemoveBlank.Replace("\r\n", "");
  1416. //分割符号检验
  1417. string[] Symbol = { "and", "or", "+", "-", "*", "/", "=", ">", "<" };
  1418. for (int i = 0; i < Symbol.Length; i++)
  1419. {
  1420. for (int j = 0; j < Symbol.Length; j++)
  1421. {
  1422. if ((Symbol[i] + Symbol[j]) != ">=" && (Symbol[i] + Symbol[j]) != "<=")
  1423. {
  1424. if (str_RemoveBlank.Contains(Symbol[i] + Symbol[j]))
  1425. {
  1426. MessageBox.Show(table["message18"].ToString() + Symbol[i] + Symbol[j], table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  1427. return false;
  1428. }
  1429. }
  1430. }
  1431. if (str_RemoveBlank.Contains(Symbol[i] + ")") || str_RemoveBlank.Contains("(" + Symbol[i]))
  1432. {
  1433. MessageBox.Show(table["message18"].ToString() + Symbol[i] + ")", table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  1434. return false;
  1435. }
  1436. if (str_RemoveBlank.Contains("(" + Symbol[i]))
  1437. {
  1438. MessageBox.Show(table["message18"].ToString() + "(" + Symbol[i], table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  1439. return false;
  1440. }
  1441. }
  1442. if ((str_RemoveBlank != null) && (str_RemoveBlank != ""))
  1443. {
  1444. //左右括号匹配检验
  1445. int BracketsNum = 0;
  1446. for (int i = 0; i < str_RemoveBlank.Length; i++)
  1447. {
  1448. if (str_RemoveBlank[i] == '(') BracketsNum++;
  1449. if (str_RemoveBlank[i] == ')') BracketsNum--;
  1450. }
  1451. if (BracketsNum != 0)
  1452. {
  1453. MessageBox.Show(table["message19"].ToString(),table["message32"].ToString(),MessageBoxButtons.OK,MessageBoxIcon.Information);
  1454. return false;
  1455. }
  1456. //首字符检测
  1457. 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] == '('))
  1458. {
  1459. MessageBox.Show(table["message20"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  1460. return false;
  1461. }
  1462. if (str_RemoveBlank.Length >= 3)
  1463. {
  1464. if ((str_RemoveBlank.Substring(0, 3) == "and") || (str_RemoveBlank.Substring(0, 3) == "end"))
  1465. {
  1466. MessageBox.Show(table["message20"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  1467. return false;
  1468. }
  1469. }
  1470. }
  1471. //forth_elem干扰or分隔符,故先行去掉
  1472. str_RemoveBlank = str_RemoveBlank.Replace("forth_elem", "");
  1473. string[] str_Removeand = System.Text.RegularExpressions.Regex.Split(str_RemoveBlank, "and", System.Text.RegularExpressions.RegexOptions.None);
  1474. List<string> str_Removeandor = new List<string>();
  1475. for (int i = 0; i < str_Removeand.Length; i++)
  1476. {
  1477. str_Removeandor.AddRange(System.Text.RegularExpressions.Regex.Split(str_Removeand[i], "or", System.Text.RegularExpressions.RegexOptions.None));
  1478. }
  1479. List<string> list_all = new List<string>();
  1480. for (int i = 0; i < str_Removeandor.Count; i++)
  1481. {
  1482. list_all.AddRange(str_Removeandor[i].Split(new char[] { '+', '-', '*', '/', '=', '>', '<', '(', ')' }));
  1483. }
  1484. //常量
  1485. List<string> Constantslist = new List<string>();
  1486. for (int j = 0; j < comboBox_Constants.Items.Count; j++)
  1487. {
  1488. Constantslist.Add(comboBox_Constants.Items[j].ToString().Split('=')[0]);
  1489. }
  1490. for (int i = 0; i < list_all.Count; i++)
  1491. {
  1492. //周期元素?
  1493. if (this.comboBox_PeriodicTable.Items.Contains(list_all[i]))
  1494. {
  1495. continue;
  1496. }
  1497. //first_elem?
  1498. if (this.comboBox_Elem1.Items.Contains(list_all[i]))
  1499. {
  1500. continue;
  1501. }
  1502. //Element1?
  1503. if (this.comboBox_Elem.Items.Contains(list_all[i]))
  1504. {
  1505. continue;
  1506. }
  1507. //其它元素?
  1508. if (this.comboBox_ImgProperty.Items.Contains(list_all[i]))
  1509. {
  1510. continue;
  1511. }
  1512. //常量?
  1513. if (Constantslist.Contains(list_all[i]))
  1514. {
  1515. continue;
  1516. }
  1517. //数字?
  1518. double DNum = 0;
  1519. if (double.TryParse(list_all[i], out DNum))
  1520. {
  1521. continue;
  1522. }
  1523. //>=? <=?等其它情况
  1524. if (list_all[i] == "")
  1525. {
  1526. continue;
  1527. }
  1528. //true false?
  1529. if ((list_all[i] == "true") || (list_all[i] == "false"))
  1530. {
  1531. continue;
  1532. }
  1533. MessageBox.Show(table["message21"].ToString() + list_all[i], table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  1534. return false;
  1535. }
  1536. //检测是否有<>= true,false
  1537. 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")
  1538. {
  1539. MessageBox.Show(table["message22"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  1540. return false;
  1541. }
  1542. return true;
  1543. }
  1544. private void btn_dbs_Click(object sender, EventArgs e)
  1545. {
  1546. ColorDialog cd = new ColorDialog();
  1547. cd.FullOpen = true;//自定义颜色界面打开
  1548. DialogResult result = cd.ShowDialog();
  1549. if (result == DialogResult.OK)
  1550. {
  1551. btn_dbs.BackColor = cd.Color;
  1552. int color = Convert.ToInt32(ParseRGB(cd.Color));
  1553. ShowXrayAtlas(color, xrayByteData);
  1554. if (XmlTree_STDlist.SelectedNode != null)
  1555. {
  1556. XmlTree_STDlist.SelectedNode.BackColor = cd.Color;
  1557. }
  1558. }
  1559. if (XmlTree_STDlist.SelectedNode != null)
  1560. {
  1561. //如果不是白色了,就把文字去掉吧,显得好看
  1562. if (btn_dbs.BackColor != Color.White)
  1563. {
  1564. btn_dbs.Text = "";
  1565. }
  1566. }
  1567. }
  1568. private void button_And_Click(object sender, EventArgs e)
  1569. {
  1570. //textbox_STDEditor 中的光标
  1571. int index = textbox_STDEditor.SelectionStart;
  1572. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "and");
  1573. textbox_STDEditor.Focus();
  1574. textbox_STDEditor.Select(index + 3, 0);
  1575. textbox_STDEditor.ScrollToCaret();
  1576. }
  1577. private void button_Or_Click(object sender, EventArgs e)
  1578. {
  1579. //textbox_STDEditor 中的光标
  1580. int index = textbox_STDEditor.SelectionStart;
  1581. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "or");
  1582. textbox_STDEditor.Focus();
  1583. textbox_STDEditor.Select(index + 2, 0);
  1584. textbox_STDEditor.ScrollToCaret();
  1585. }
  1586. private void comboBox_Constants_SelectedIndexChanged(object sender, EventArgs e)
  1587. {
  1588. //if (Flag_comboBox_Constants)
  1589. //{
  1590. if (comboBox_Constants.SelectedItem != null)
  1591. {
  1592. //this.textbox_STDEditor.Text += comboBox_Constants.SelectedItem.ToString().Split('=')[0];
  1593. ////comboBox_Constants.Text = null;
  1594. //textbox_STDEditor.Focus();
  1595. //textbox_STDEditor.SelectionStart = textbox_STDEditor.Text.Length;
  1596. //textbox_STDEditor.ScrollToCaret();
  1597. string newStr = comboBox_Constants.SelectedItem.ToString().Split('=')[0];
  1598. int index = textbox_STDEditor.SelectionStart;
  1599. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, newStr);
  1600. textbox_STDEditor.Focus();
  1601. textbox_STDEditor.Select(index + newStr.Length, 0);
  1602. textbox_STDEditor.ScrollToCaret();
  1603. }
  1604. //}
  1605. //Flag_comboBox_Constants = true;
  1606. }
  1607. bool Flag_SelStatus = true; //XML切换成功失败状态
  1608. private void button_UpOrder_Click(object sender, EventArgs e)
  1609. {
  1610. if (XmlTree_STDlist.SelectedNode.PrevNode != null)
  1611. {
  1612. //object tag = XmlTree_STDlist.SelectedNode.PrevNode.Tag;
  1613. //string name = XmlTree_STDlist.SelectedNode.PrevNode.Name;
  1614. //string text = XmlTree_STDlist.SelectedNode.PrevNode.Text;
  1615. //Color backcolor=XmlTree_STDlist.SelectedNode.PrevNode.BackColor;
  1616. //string STDId = XmlTree_STDlist.SelectedNode.PrevNode.ToolTipText;
  1617. //XmlTree_STDlist.SelectedNode.PrevNode.Tag = XmlTree_STDlist.SelectedNode.Tag;
  1618. //XmlTree_STDlist.SelectedNode.PrevNode.BackColor = XmlTree_STDlist.SelectedNode.BackColor;
  1619. //XmlTree_STDlist.SelectedNode.PrevNode.Name = XmlTree_STDlist.SelectedNode.Name;
  1620. //XmlTree_STDlist.SelectedNode.PrevNode.Text = XmlTree_STDlist.SelectedNode.Text;
  1621. //XmlTree_STDlist.SelectedNode.PrevNode.ToolTipText = XmlTree_STDlist.SelectedNode.ToolTipText;
  1622. //XmlTree_STDlist.SelectedNode.Tag = tag;
  1623. //XmlTree_STDlist.SelectedNode.BackColor = backcolor;
  1624. //XmlTree_STDlist.SelectedNode.Name = name;
  1625. //XmlTree_STDlist.SelectedNode.Text = text;
  1626. //XmlTree_STDlist.SelectedNode.ToolTipText = STDId;
  1627. //this.textbox_STDEditor.Text = XmlTree_STDlist.SelectedNode.Tag.ToString();
  1628. //btn_dbs.BackColor = XmlTree_STDlist.SelectedNode.BackColor;
  1629. //string[] strOther = XmlTree_STDlist.SelectedNode.Name.Split('$');
  1630. //string[] strOther2 = strOther[0].Split('_');
  1631. //textBox_Hardness.Text = strOther2[0];
  1632. //textBox_Density.Text = strOther2[1];
  1633. //textBox_Electrical_conductivity.Text = strOther2[2];
  1634. //dataGridView_KeyElements.Rows.Clear();
  1635. //dataGridView_KeyElements.Columns.Clear();
  1636. //string[] KeyElement = strOther[1].Split(',');
  1637. //for (int i = 0; i < KeyElement.Length; i++)
  1638. //{
  1639. // if (KeyElement[0] != "")
  1640. // {
  1641. // DataGridViewButtonColumn dataGridViewButtonColumn = new DataGridViewButtonColumn();
  1642. // dataGridViewButtonColumn.Name = dataGridView_SubElements.Columns.Count.ToString();
  1643. // dataGridView_KeyElements.Columns.Add(dataGridViewButtonColumn);
  1644. // if (dataGridView_KeyElements.Rows.Count == 0)
  1645. // {
  1646. // DataGridViewRow row = new DataGridViewRow();
  1647. // dataGridView_KeyElements.Rows.Add(row);
  1648. // }
  1649. // dataGridView_KeyElements.Rows[0].Cells[i].Value = KeyElement[i];
  1650. // }
  1651. //}
  1652. //dataGridView_SubElements.Rows.Clear();
  1653. //dataGridView_SubElements.Columns.Clear();
  1654. //string[] SubElement = strOther[2].Split(',');
  1655. //for (int i = 0; i < SubElement.Length; i++)
  1656. //{
  1657. // if (SubElement[i] != "")
  1658. // {
  1659. // DataGridViewButtonColumn dataGridViewButtonColumn = new DataGridViewButtonColumn();
  1660. // dataGridViewButtonColumn.Name = dataGridView_SubElements.Columns.Count.ToString();
  1661. // dataGridView_SubElements.Columns.Add(dataGridViewButtonColumn);
  1662. // if (dataGridView_SubElements.Rows.Count == 0)
  1663. // {
  1664. // DataGridViewRow row = new DataGridViewRow();
  1665. // dataGridView_SubElements.Rows.Add(row);
  1666. // }
  1667. // dataGridView_SubElements.Rows[0].Cells[i].Value = SubElement[i];
  1668. // }
  1669. //}
  1670. //this.XmlTree_STDlist.Focus();
  1671. //XmlTree_STDlist.SelectedNode = XmlTree_STDlist.SelectedNode.PrevNode;
  1672. //if (XmlTree_STDlist.SelectedNode.PrevNode == null)
  1673. //{
  1674. // UpOrder.Enabled = false;
  1675. //}
  1676. }
  1677. XmlTree_STDlist.SelectedNode = XmlTree_STDlist.SelectedNode.PrevNode;
  1678. if (Flag_SelStatus)
  1679. {
  1680. object tag = XmlTree_STDlist.SelectedNode.NextNode.Tag;
  1681. string name = XmlTree_STDlist.SelectedNode.NextNode.Name;
  1682. string text = XmlTree_STDlist.SelectedNode.NextNode.Text;
  1683. Color backcolor = XmlTree_STDlist.SelectedNode.NextNode.BackColor;
  1684. string STDId = XmlTree_STDlist.SelectedNode.NextNode.ToolTipText;
  1685. XmlTree_STDlist.SelectedNode.NextNode.Tag = XmlTree_STDlist.SelectedNode.Tag;
  1686. XmlTree_STDlist.SelectedNode.NextNode.BackColor = XmlTree_STDlist.SelectedNode.BackColor;
  1687. XmlTree_STDlist.SelectedNode.NextNode.Name = XmlTree_STDlist.SelectedNode.Name;
  1688. XmlTree_STDlist.SelectedNode.NextNode.Text = XmlTree_STDlist.SelectedNode.Text;
  1689. XmlTree_STDlist.SelectedNode.NextNode.ToolTipText = XmlTree_STDlist.SelectedNode.ToolTipText;
  1690. XmlTree_STDlist.SelectedNode.Tag = tag;
  1691. XmlTree_STDlist.SelectedNode.BackColor = backcolor;
  1692. XmlTree_STDlist.SelectedNode.Name = name;
  1693. XmlTree_STDlist.SelectedNode.Text = text;
  1694. XmlTree_STDlist.SelectedNode.ToolTipText = STDId;
  1695. this.textbox_STDEditor.Text = XmlTree_STDlist.SelectedNode.Tag.ToString();
  1696. btn_dbs.BackColor = XmlTree_STDlist.SelectedNode.BackColor;
  1697. string[] strOther = XmlTree_STDlist.SelectedNode.Name.Split('$');
  1698. string[] strOther2 = strOther[0].Split('_');
  1699. textBox_Hardness.Text = strOther2[0];
  1700. textBox_Density.Text = strOther2[1];
  1701. textBox_Electrical_conductivity.Text = strOther2[2];
  1702. if (strOther2.Length > 3)
  1703. {
  1704. textBox_BSEValue.Text = strOther2[3];
  1705. textBox_Formula.Text = strOther2[4];
  1706. textBox_Element.Text = strOther2[5];
  1707. }
  1708. else
  1709. {
  1710. textBox_BSEValue.Text = "";
  1711. textBox_Formula.Text = "";
  1712. textBox_Element.Text = "";
  1713. }
  1714. dataGridView_KeyElements.Rows.Clear();
  1715. dataGridView_KeyElements.Columns.Clear();
  1716. string[] KeyElement = strOther[1].Split(',');
  1717. for (int i = 0; i < KeyElement.Length; i++)
  1718. {
  1719. if (KeyElement[0] != "")
  1720. {
  1721. DataGridViewButtonColumn dataGridViewButtonColumn = new DataGridViewButtonColumn();
  1722. dataGridViewButtonColumn.Name = dataGridView_SubElements.Columns.Count.ToString();
  1723. dataGridView_KeyElements.Columns.Add(dataGridViewButtonColumn);
  1724. if (dataGridView_KeyElements.Rows.Count == 0)
  1725. {
  1726. DataGridViewRow row = new DataGridViewRow();
  1727. dataGridView_KeyElements.Rows.Add(row);
  1728. }
  1729. dataGridView_KeyElements.Rows[0].Cells[i].Value = KeyElement[i];
  1730. }
  1731. }
  1732. dataGridView_SubElements.Rows.Clear();
  1733. dataGridView_SubElements.Columns.Clear();
  1734. string[] SubElement = strOther[2].Split(',');
  1735. for (int i = 0; i < SubElement.Length; i++)
  1736. {
  1737. if (SubElement[i] != "")
  1738. {
  1739. DataGridViewButtonColumn dataGridViewButtonColumn = new DataGridViewButtonColumn();
  1740. dataGridViewButtonColumn.Name = dataGridView_SubElements.Columns.Count.ToString();
  1741. dataGridView_SubElements.Columns.Add(dataGridViewButtonColumn);
  1742. if (dataGridView_SubElements.Rows.Count == 0)
  1743. {
  1744. DataGridViewRow row = new DataGridViewRow();
  1745. dataGridView_SubElements.Rows.Add(row);
  1746. }
  1747. dataGridView_SubElements.Rows[0].Cells[i].Value = SubElement[i];
  1748. }
  1749. }
  1750. this.XmlTree_STDlist.Focus();
  1751. if (XmlTree_STDlist.SelectedNode.PrevNode == null)
  1752. {
  1753. button_UpOrder.Enabled = false;
  1754. }
  1755. dataGridView_KeyElements.ClearSelection();
  1756. dataGridView_SubElements.ClearSelection();
  1757. }
  1758. this.XmlTree_STDlist.Focus();
  1759. Flag_SelStatus = true;
  1760. }
  1761. private void button_DownOrder_Click(object sender, EventArgs e)
  1762. {
  1763. if (XmlTree_STDlist.SelectedNode.NextNode != null)
  1764. {
  1765. //object tag = XmlTree_STDlist.SelectedNode.NextNode.Tag;
  1766. //string name = XmlTree_STDlist.SelectedNode.NextNode.Name;
  1767. //string text = XmlTree_STDlist.SelectedNode.NextNode.Text;
  1768. //Color backcolor = XmlTree_STDlist.SelectedNode.NextNode.BackColor;
  1769. //string STDId = XmlTree_STDlist.SelectedNode.NextNode.ToolTipText;
  1770. //XmlTree_STDlist.SelectedNode.NextNode.Tag = XmlTree_STDlist.SelectedNode.Tag;
  1771. //XmlTree_STDlist.SelectedNode.NextNode.BackColor = XmlTree_STDlist.SelectedNode.BackColor;
  1772. //XmlTree_STDlist.SelectedNode.NextNode.Name = XmlTree_STDlist.SelectedNode.Name;
  1773. //XmlTree_STDlist.SelectedNode.NextNode.Text = XmlTree_STDlist.SelectedNode.Text;
  1774. //XmlTree_STDlist.SelectedNode.NextNode.ToolTipText = XmlTree_STDlist.SelectedNode.ToolTipText;
  1775. //XmlTree_STDlist.SelectedNode.Tag = tag;
  1776. //XmlTree_STDlist.SelectedNode.BackColor = backcolor;
  1777. //XmlTree_STDlist.SelectedNode.Name = name;
  1778. //XmlTree_STDlist.SelectedNode.Text = text;
  1779. //XmlTree_STDlist.SelectedNode.ToolTipText = STDId;
  1780. //this.textbox_STDEditor.Text = XmlTree_STDlist.SelectedNode.Tag.ToString();
  1781. //btn_dbs.BackColor = XmlTree_STDlist.SelectedNode.BackColor;
  1782. //string[] strOther = XmlTree_STDlist.SelectedNode.Name.Split('$');
  1783. //string[] strOther2 = strOther[0].Split('_');
  1784. //textBox_Hardness.Text = strOther2[0];
  1785. //textBox_Density.Text = strOther2[1];
  1786. //textBox_Electrical_conductivity.Text = strOther2[2];
  1787. //dataGridView_KeyElements.Rows.Clear();
  1788. //dataGridView_KeyElements.Columns.Clear();
  1789. //string[] KeyElement = strOther[1].Split(',');
  1790. //for (int i = 0; i < KeyElement.Length; i++)
  1791. //{
  1792. // if (KeyElement[0] != "")
  1793. // {
  1794. // DataGridViewButtonColumn dataGridViewButtonColumn = new DataGridViewButtonColumn();
  1795. // dataGridViewButtonColumn.Name = dataGridView_SubElements.Columns.Count.ToString();
  1796. // dataGridView_KeyElements.Columns.Add(dataGridViewButtonColumn);
  1797. // if (dataGridView_KeyElements.Rows.Count == 0)
  1798. // {
  1799. // DataGridViewRow row = new DataGridViewRow();
  1800. // dataGridView_KeyElements.Rows.Add(row);
  1801. // }
  1802. // dataGridView_KeyElements.Rows[0].Cells[i].Value = KeyElement[i];
  1803. // }
  1804. //}
  1805. //dataGridView_SubElements.Rows.Clear();
  1806. //dataGridView_SubElements.Columns.Clear();
  1807. //string[] SubElement = strOther[2].Split(',');
  1808. //for (int i = 0; i < SubElement.Length; i++)
  1809. //{
  1810. // if (SubElement[i] != "")
  1811. // {
  1812. // DataGridViewButtonColumn dataGridViewButtonColumn = new DataGridViewButtonColumn();
  1813. // dataGridViewButtonColumn.Name = dataGridView_SubElements.Columns.Count.ToString();
  1814. // dataGridView_SubElements.Columns.Add(dataGridViewButtonColumn);
  1815. // if (dataGridView_SubElements.Rows.Count == 0)
  1816. // {
  1817. // DataGridViewRow row = new DataGridViewRow();
  1818. // dataGridView_SubElements.Rows.Add(row);
  1819. // }
  1820. // dataGridView_SubElements.Rows[0].Cells[i].Value = SubElement[i];
  1821. // }
  1822. //}
  1823. //this.XmlTree_STDlist.Focus();
  1824. //XmlTree_STDlist.SelectedNode = XmlTree_STDlist.SelectedNode.NextNode;
  1825. //if (XmlTree_STDlist.SelectedNode.NextNode == null)
  1826. //{
  1827. // DownOrder.Enabled = false;
  1828. //}
  1829. }
  1830. XmlTree_STDlist.SelectedNode = XmlTree_STDlist.SelectedNode.NextNode;
  1831. if (Flag_SelStatus)
  1832. {
  1833. object tag = XmlTree_STDlist.SelectedNode.PrevNode.Tag;
  1834. string name = XmlTree_STDlist.SelectedNode.PrevNode.Name;
  1835. string text = XmlTree_STDlist.SelectedNode.PrevNode.Text;
  1836. Color backcolor = XmlTree_STDlist.SelectedNode.PrevNode.BackColor;
  1837. string STDId = XmlTree_STDlist.SelectedNode.PrevNode.ToolTipText;
  1838. XmlTree_STDlist.SelectedNode.PrevNode.Tag = XmlTree_STDlist.SelectedNode.Tag;
  1839. XmlTree_STDlist.SelectedNode.PrevNode.BackColor = XmlTree_STDlist.SelectedNode.BackColor;
  1840. XmlTree_STDlist.SelectedNode.PrevNode.Name = XmlTree_STDlist.SelectedNode.Name;
  1841. XmlTree_STDlist.SelectedNode.PrevNode.Text = XmlTree_STDlist.SelectedNode.Text;
  1842. XmlTree_STDlist.SelectedNode.PrevNode.ToolTipText = XmlTree_STDlist.SelectedNode.ToolTipText;
  1843. XmlTree_STDlist.SelectedNode.Tag = tag;
  1844. XmlTree_STDlist.SelectedNode.BackColor = backcolor;
  1845. XmlTree_STDlist.SelectedNode.Name = name;
  1846. XmlTree_STDlist.SelectedNode.Text = text;
  1847. XmlTree_STDlist.SelectedNode.ToolTipText = STDId;
  1848. this.textbox_STDEditor.Text = XmlTree_STDlist.SelectedNode.Tag.ToString();
  1849. btn_dbs.BackColor = XmlTree_STDlist.SelectedNode.BackColor;
  1850. string[] strOther = XmlTree_STDlist.SelectedNode.Name.Split('$');
  1851. string[] strOther2 = strOther[0].Split('_');
  1852. textBox_Hardness.Text = strOther2[0];
  1853. textBox_Density.Text = strOther2[1];
  1854. textBox_Electrical_conductivity.Text = strOther2[2];
  1855. if (strOther2.Length > 3)
  1856. {
  1857. textBox_BSEValue.Text = strOther2[3];
  1858. textBox_Formula.Text = strOther2[4];
  1859. textBox_Element.Text = strOther2[5];
  1860. }
  1861. else
  1862. {
  1863. textBox_BSEValue.Text = "";
  1864. textBox_Formula.Text = "";
  1865. textBox_Element.Text = "";
  1866. }
  1867. dataGridView_KeyElements.Rows.Clear();
  1868. dataGridView_KeyElements.Columns.Clear();
  1869. string[] KeyElement = strOther[1].Split(',');
  1870. for (int i = 0; i < KeyElement.Length; i++)
  1871. {
  1872. if (KeyElement[0] != "")
  1873. {
  1874. DataGridViewButtonColumn dataGridViewButtonColumn = new DataGridViewButtonColumn();
  1875. dataGridViewButtonColumn.Name = dataGridView_SubElements.Columns.Count.ToString();
  1876. dataGridView_KeyElements.Columns.Add(dataGridViewButtonColumn);
  1877. if (dataGridView_KeyElements.Rows.Count == 0)
  1878. {
  1879. DataGridViewRow row = new DataGridViewRow();
  1880. dataGridView_KeyElements.Rows.Add(row);
  1881. }
  1882. dataGridView_KeyElements.Rows[0].Cells[i].Value = KeyElement[i];
  1883. }
  1884. }
  1885. dataGridView_SubElements.Rows.Clear();
  1886. dataGridView_SubElements.Columns.Clear();
  1887. string[] SubElement = strOther[2].Split(',');
  1888. for (int i = 0; i < SubElement.Length; i++)
  1889. {
  1890. if (SubElement[i] != "")
  1891. {
  1892. DataGridViewButtonColumn dataGridViewButtonColumn = new DataGridViewButtonColumn();
  1893. dataGridViewButtonColumn.Name = dataGridView_SubElements.Columns.Count.ToString();
  1894. dataGridView_SubElements.Columns.Add(dataGridViewButtonColumn);
  1895. if (dataGridView_SubElements.Rows.Count == 0)
  1896. {
  1897. DataGridViewRow row = new DataGridViewRow();
  1898. dataGridView_SubElements.Rows.Add(row);
  1899. }
  1900. dataGridView_SubElements.Rows[0].Cells[i].Value = SubElement[i];
  1901. }
  1902. }
  1903. this.XmlTree_STDlist.Focus();
  1904. if (XmlTree_STDlist.SelectedNode.PrevNode == null)
  1905. {
  1906. button_DownOrder.Enabled = false;
  1907. }
  1908. dataGridView_KeyElements.ClearSelection();
  1909. dataGridView_SubElements.ClearSelection();
  1910. }
  1911. this.XmlTree_STDlist.Focus();
  1912. Flag_SelStatus = true;
  1913. }
  1914. private void button_Backup_Click(object sender, EventArgs e)
  1915. {
  1916. if (tabControl_Rules.SelectedIndex == 0)
  1917. {
  1918. //保存节点当前数据
  1919. if (XmlTree_STDlist.SelectedNode != null)
  1920. {
  1921. //判断Hardness、Density、Electrical_conductivity
  1922. double dHardness = 0, dDensity = 0, dElectrical_conductivity = 0;
  1923. if (!double.TryParse(textBox_Hardness.Text, out dHardness) || (double.Parse(textBox_Hardness.Text) <= 0))
  1924. {
  1925. textBox_Hardness.Focus();
  1926. textBox_Hardness.SelectAll();
  1927. MessageBox.Show(table["message10"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  1928. return;
  1929. }
  1930. if (!double.TryParse(textBox_Density.Text, out dDensity) || double.Parse(textBox_Density.Text) <= 0)
  1931. {
  1932. textBox_Density.Focus();
  1933. textBox_Density.SelectAll();
  1934. MessageBox.Show(table["message11"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  1935. return;
  1936. }
  1937. if (!double.TryParse(textBox_Electrical_conductivity.Text, out dElectrical_conductivity) || double.Parse(textBox_Electrical_conductivity.Text) <= 0)
  1938. {
  1939. textBox_Electrical_conductivity.Focus();
  1940. textBox_Electrical_conductivity.SelectAll();
  1941. MessageBox.Show(table["message12"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  1942. return;
  1943. }
  1944. if (textBox_BSEValue.Text.LastIndexOf("_")>0)
  1945. {
  1946. textBox_BSEValue.Focus();
  1947. textBox_BSEValue.SelectAll();
  1948. MessageBox.Show(table["message13"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  1949. textBox_BSEValue.Focus();
  1950. return;
  1951. }
  1952. if (textBox_Formula.Text.LastIndexOf("_") > 0)
  1953. {
  1954. textBox_Formula.Focus();
  1955. textBox_Formula.SelectAll();
  1956. MessageBox.Show(table["message14"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  1957. textBox_Formula.Focus();
  1958. return;
  1959. }
  1960. if (textBox_Element.Text.LastIndexOf("_") > 0)
  1961. {
  1962. textBox_Element.Focus();
  1963. textBox_Element.SelectAll();
  1964. MessageBox.Show(table["message15"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  1965. textBox_Element.Focus();
  1966. return;
  1967. }
  1968. //判断textbox_STDEditor
  1969. if (!Checktextbox_STDEditor())
  1970. {
  1971. return;
  1972. }
  1973. XmlTree_STDlist.SelectedNode.Tag = this.textbox_STDEditor.Text;
  1974. XmlTree_STDlist.SelectedNode.Name = textBox_Hardness.Text + "_" + textBox_Density.Text + "_" + textBox_Electrical_conductivity.Text + "_" + textBox_BSEValue.Text + "_" + textBox_Formula.Text + "_" + textBox_Element.Text; ;
  1975. string sKeyElements = "";
  1976. for (int i = 0; i < dataGridView_KeyElements.Columns.Count; i++)
  1977. {
  1978. sKeyElements += dataGridView_KeyElements.Rows[0].Cells[i].Value.ToString() + ",";
  1979. }
  1980. if (sKeyElements.Length > 0)
  1981. {
  1982. sKeyElements = sKeyElements.Substring(0, sKeyElements.Length - 1);
  1983. }
  1984. string sSubElements = "";
  1985. for (int i = 0; i < dataGridView_SubElements.Columns.Count; i++)
  1986. {
  1987. sSubElements += dataGridView_SubElements.Rows[0].Cells[i].Value.ToString() + ",";
  1988. }
  1989. if (sSubElements.Length > 0)
  1990. {
  1991. sSubElements = sSubElements.Substring(0, sSubElements.Length - 1);
  1992. }
  1993. XmlTree_STDlist.SelectedNode.Name += "$" + sKeyElements + "$" + sSubElements;
  1994. }
  1995. }
  1996. else if (tabControl_Rules.SelectedIndex == 1)
  1997. {
  1998. if (XmlTree_MaxEDSRules.SelectedNode != null)
  1999. {
  2000. //判断MaxEDSTime
  2001. double dMaxEDSTime = 0;
  2002. if (!double.TryParse(textBox_MaxEDSTime.Text, out dMaxEDSTime) || double.Parse(textBox_MaxEDSTime.Text) <= 0)
  2003. {
  2004. textBox_MaxEDSTime.Focus();
  2005. textBox_MaxEDSTime.SelectAll();
  2006. MessageBox.Show(table["message16"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  2007. return;
  2008. }
  2009. //判断textbox_STDEditor
  2010. if (!Checktextbox_STDEditor())
  2011. {
  2012. return;
  2013. }
  2014. XmlTree_MaxEDSRules.SelectedNode.Tag = this.textbox_STDEditor.Text;
  2015. //XmlTree_MaxEDSRules.SelectedNode.Name = textBox_MaxEDSTime.Text;
  2016. }
  2017. }
  2018. else if (tabControl_Rules.SelectedIndex == 2)
  2019. {
  2020. if (XmlTree_ZeroElementRules.SelectedNode != null)
  2021. {
  2022. if (XmlTree_ZeroElementRules.SelectedNode.Text.Contains("="))
  2023. {
  2024. if (!comboBox_PeriodicTable.Items.Contains(XmlTree_ZeroElementRules.SelectedNode.Text.Split('=')[0]))
  2025. {
  2026. MessageBox.Show(XmlTree_ZeroElementRules.SelectedNode.Text + table["message9"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  2027. return;
  2028. }
  2029. }
  2030. else
  2031. {
  2032. MessageBox.Show(XmlTree_ZeroElementRules.SelectedNode.Text + table["message9"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  2033. return;
  2034. }
  2035. //判断textbox_STDEditor
  2036. if (!Checktextbox_STDEditor())
  2037. {
  2038. return;
  2039. }
  2040. XmlTree_ZeroElementRules.SelectedNode.Tag = this.textbox_STDEditor.Text;
  2041. }
  2042. }
  2043. try
  2044. {
  2045. SaveFileDialog saveFile = new SaveFileDialog();
  2046. saveFile.Title = table["message23"].ToString();
  2047. saveFile.Filter = table["message24"].ToString();
  2048. saveFile.OverwritePrompt = true; //是否覆盖当前文件
  2049. saveFile.RestoreDirectory = true; //还原上次目录
  2050. if (saveFile.ShowDialog() == DialogResult.OK)
  2051. {
  2052. //string Address = Application.StartupPath.Substring(0, Application.StartupPath.Length - 35) + "\\Opton\\OTSPartA\\OTS\\Bin\\Win32\\Debug\\Config\\SysData\\OTSParticleSTD.xml";
  2053. //string Address = ".\\Config\\SysData\\OTSParticleSTD.xml";
  2054. System.IO.File.Copy(Address, saveFile.FileName, true);
  2055. SaveXmlTreeDataToXml(saveFile.FileName);
  2056. MessageBox.Show(table["message25"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  2057. }
  2058. else
  2059. {
  2060. return;
  2061. }
  2062. }
  2063. catch (Exception ex)
  2064. {
  2065. MessageBox.Show(ex.Message);
  2066. }
  2067. //string Address_backup = Application.StartupPath.Substring(0, Application.StartupPath.Length-35) + "\\Bin\\Win32\\Debug\\Config\\SysData\\OTSParticleSTD_backup.xml";
  2068. //string Address_backup = ".\\Config\\SysData\\OTSParticleSTD_backup.xml";
  2069. //SaveXmlTreeDataToXml(Address_backup);
  2070. //MessageBox.Show("备份成功!", "提示");
  2071. }
  2072. private void button_Recover_Click(object sender, EventArgs e)
  2073. {
  2074. XmlDocument doc = new XmlDocument();
  2075. //string Address_backup = ".\\Config\\SysData\\OTSParticleSTD_backup.xml";
  2076. //string Address = ".\\Config\\SysData\\OTSParticleSTD.xml";
  2077. //string Address_backup = Application.StartupPath + "\\Config\\SysData\\\\OTSParticleSTD_backup.xml";
  2078. //string Address = Application.StartupPath + "\\Config\\SysData\\OTSParticleSTD.xml";
  2079. try
  2080. {
  2081. System.IO.File.Copy(Address_backup, Address, true);
  2082. doc.Load(Address_backup);
  2083. XmlTree_STDlist.Nodes.Clear();
  2084. XmlTree_MaxEDSRules.Nodes.Clear();
  2085. XmlTree_ZeroElementRules.Nodes.Clear();
  2086. checkBox_0.Checked = false;
  2087. checkBox_1.Checked = false;
  2088. checkBox_2.Checked = false;
  2089. checkBox_3.Checked = false;
  2090. checkBox_4.Checked = false;
  2091. checkBox_5.Checked = false;
  2092. checkBox_6.Checked = false;
  2093. checkBox_7.Checked = false;
  2094. checkBox_8.Checked = false;
  2095. checkBox_9.Checked = false;
  2096. textBox_0.ReadOnly = true;
  2097. textBox_1.ReadOnly = true;
  2098. textBox_2.ReadOnly = true;
  2099. textBox_3.ReadOnly = true;
  2100. textBox_4.ReadOnly = true;
  2101. textBox_5.ReadOnly = true;
  2102. textBox_6.ReadOnly = true;
  2103. textBox_7.ReadOnly = true;
  2104. textBox_8.ReadOnly = true;
  2105. textBox_9.ReadOnly = true;
  2106. LoadXmlToTreeControl(doc, XmlTree_STDlist.Nodes, XmlTree_MaxEDSRules.Nodes, XmlTree_ZeroElementRules.Nodes);
  2107. XmlTree_STDlist.SelectedNode = null;
  2108. XmlTree_MaxEDSRules.SelectedNode = null;
  2109. XmlTree_ZeroElementRules.SelectedNode = null;
  2110. textbox_STDEditor.Text = "";
  2111. textBox_Density.Text = "";
  2112. textBox_Electrical_conductivity.Text = "";
  2113. textBox_BSEValue.Text = "";
  2114. textBox_Formula.Text = "";
  2115. textBox_Element.Text = "";
  2116. textBox_Hardness.Text = "";
  2117. //textBox_MaxEDSTime.Text = "";
  2118. btn_dbs.BackColor = Color.White;
  2119. dataGridView_KeyElements.Rows.Clear();
  2120. dataGridView_KeyElements.Columns.Clear();
  2121. dataGridView_SubElements.Rows.Clear();
  2122. dataGridView_SubElements.Columns.Clear();
  2123. //重新绑定STDXray信息
  2124. BindSTDXray();
  2125. }
  2126. catch(Exception ex)
  2127. {
  2128. MessageBox.Show(table["message26"].ToString() + "\n"+ex.Message.ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  2129. }
  2130. }
  2131. private void tabControl_Rules_DrawItem(object sender, DrawItemEventArgs e)
  2132. {
  2133. //SolidBrush _Brush = new SolidBrush(Color.Black);//单色画刷
  2134. //RectangleF _TabTextArea = (RectangleF)tabControl_Rules.GetTabRect(e.Index);//绘制区域
  2135. //StringFormat _sf = new StringFormat();//封装文本布局格式信息
  2136. //_sf.LineAlignment = StringAlignment.Center;
  2137. //_sf.Alignment = StringAlignment.Center;
  2138. //e.Graphics.DrawString(tabControl_Rules.Controls[e.Index].Text, SystemInformation.MenuFont, _Brush, _TabTextArea, _sf);
  2139. //RectangleF tabArea = tabControl_Rules.GetTabRect(e.Index);
  2140. //RectangleF tabTextArea = tabArea;
  2141. //Graphics g = e.Graphics;
  2142. //StringFormat sf = new StringFormat();
  2143. //sf.LineAlignment = StringAlignment.Center;
  2144. //sf.Alignment = StringAlignment.Center;
  2145. //Font font = this.tabControl_Rules.Font;
  2146. //SolidBrush brush = new SolidBrush(Color.Black);
  2147. //g.DrawString(((TabControl)(sender)).TabPages[e.Index].Text, font, brush, tabTextArea, sf);
  2148. }
  2149. private void XmlTree_ZeroElementRules_MouseClick(object sender, MouseEventArgs e)
  2150. {
  2151. //if (e.Button == MouseButtons.Left)
  2152. //{
  2153. // Point ClickPoint = new Point(e.X, e.Y);
  2154. // TreeNode CurrentNode = XmlTree_ZeroElementRules.GetNodeAt(ClickPoint);
  2155. // if (CurrentNode != null)//判断你点的是不是一个节点
  2156. // {
  2157. // if (XmlTree_ZeroElementRules.SelectedNode != null&& XmlTree_ZeroElementRules.SelectedNode != CurrentNode)
  2158. // {
  2159. // if (XmlTree_ZeroElementRules.SelectedNode.Text.Contains("="))
  2160. // {
  2161. // if (!comboBox_PeriodicTable.Items.Contains(XmlTree_ZeroElementRules.SelectedNode.Text.Split('=')[0]))
  2162. // {
  2163. // MessageBox.Show(XmlTree_ZeroElementRules.SelectedNode.Text + "项,名称格式填写错误,正确格式为:元素名=0");
  2164. // SetGrayExceptSelectedNode(XmlTree_ZeroElementRules, XmlTree_ZeroElementRules.SelectedNode);
  2165. // return;
  2166. // }
  2167. // }
  2168. // else
  2169. // {
  2170. // MessageBox.Show(XmlTree_ZeroElementRules.SelectedNode.Text + "项,名称格式填写错误,正确格式为:元素名=0");
  2171. // SetGrayExceptSelectedNode(XmlTree_ZeroElementRules, XmlTree_ZeroElementRules.SelectedNode);
  2172. // return;
  2173. // }
  2174. // if (!Checktextbox_STDEditor())
  2175. // {
  2176. // SetGrayExceptSelectedNode(XmlTree_ZeroElementRules, XmlTree_ZeroElementRules.SelectedNode);
  2177. // return;
  2178. // }
  2179. // XmlTree_ZeroElementRules.SelectedNode.Tag = this.textbox_STDEditor.Text;
  2180. // }
  2181. // SetBlackAllNodes(XmlTree_ZeroElementRules);
  2182. // XmlTree_ZeroElementRules.SelectedNode = CurrentNode;
  2183. // this.textbox_STDEditor.Text = XmlTree_ZeroElementRules.SelectedNode.Tag.ToString();
  2184. // }
  2185. //}
  2186. }
  2187. private void XmlTree_ZeroElementRules_MouseDoubleClick(object sender, MouseEventArgs e)
  2188. {
  2189. if (e.Button == MouseButtons.Left)
  2190. {
  2191. Point ClickPoint = new Point(e.X, e.Y);
  2192. TreeNode CurrentNode = XmlTree_ZeroElementRules.GetNodeAt(ClickPoint);
  2193. if (CurrentNode != null)//判断你点的是不是一个节点
  2194. {
  2195. XmlTree_ZeroElementRules.SelectedNode = CurrentNode;//选中这个节点
  2196. //this.textbox_STDEditor.Text = XmlTree_ZeroElementRules.SelectedNode.Tag.ToString();
  2197. XmlTree_ZeroElementRules.LabelEdit = true;
  2198. XmlTree_ZeroElementRules.SelectedNode.BeginEdit();
  2199. }
  2200. }
  2201. }
  2202. private void XmlTree_MaxEDSRules_MouseClick(object sender, MouseEventArgs e)
  2203. {
  2204. //if (e.Button == MouseButtons.Left)
  2205. //{
  2206. // Point ClickPoint = new Point(e.X, e.Y);
  2207. // TreeNode CurrentNode = XmlTree_MaxEDSRules.GetNodeAt(ClickPoint);
  2208. // if (CurrentNode != null)//判断你点的是不是一个节点
  2209. // {
  2210. // if (XmlTree_MaxEDSRules.SelectedNode != null&& XmlTree_MaxEDSRules.SelectedNode!= CurrentNode)
  2211. // {
  2212. // if (!Checktextbox_STDEditor())
  2213. // {
  2214. // SetGrayExceptSelectedNode(XmlTree_MaxEDSRules, XmlTree_MaxEDSRules.SelectedNode);
  2215. // return;
  2216. // }
  2217. // //double dMaxEDSTime = 0;
  2218. // //if (!double.TryParse(textBox_MaxEDSTime.Text, out dMaxEDSTime)||double.Parse(textBox_MaxEDSTime.Text)<=0)
  2219. // //{
  2220. // // MessageBox.Show("MaxEDSTime请填写数字!", "提示");
  2221. // //}
  2222. // XmlTree_MaxEDSRules.SelectedNode.Tag = this.textbox_STDEditor.Text;
  2223. // //XmlTree_MaxEDSRules.SelectedNode.Name = this.textBox_MaxEDSTime.Text;
  2224. // }
  2225. // SetBlackAllNodes(XmlTree_MaxEDSRules);
  2226. // XmlTree_MaxEDSRules.SelectedNode = CurrentNode;
  2227. // this.textbox_STDEditor.Text = XmlTree_MaxEDSRules.SelectedNode.Tag.ToString();
  2228. // //textBox_MaxEDSTime.Text = XmlTree_MaxEDSRules.SelectedNode.Name;
  2229. // }
  2230. //}
  2231. }
  2232. private void checkBox_0_CheckedChanged(object sender, EventArgs e)
  2233. {
  2234. if (checkBox_0.Checked)
  2235. {
  2236. textBox_0.ReadOnly = false;
  2237. }
  2238. else
  2239. {
  2240. if (!CheckConstants(checkBox_0.Text))
  2241. {
  2242. checkBox_0.Checked = true;
  2243. }
  2244. else
  2245. {
  2246. textBox_0.ReadOnly = true;
  2247. }
  2248. }
  2249. }
  2250. private void checkBox_1_CheckedChanged(object sender, EventArgs e)
  2251. {
  2252. if (checkBox_1.Checked)
  2253. {
  2254. textBox_1.ReadOnly = false;
  2255. }
  2256. else
  2257. {
  2258. if (!CheckConstants(checkBox_1.Text))
  2259. {
  2260. checkBox_1.Checked = true;
  2261. }
  2262. else
  2263. {
  2264. textBox_1.ReadOnly = true;
  2265. }
  2266. }
  2267. }
  2268. private void checkBox_2_CheckedChanged(object sender, EventArgs e)
  2269. {
  2270. if (checkBox_2.Checked)
  2271. {
  2272. textBox_2.ReadOnly = false;
  2273. }
  2274. else
  2275. {
  2276. if (!CheckConstants(checkBox_2.Text))
  2277. {
  2278. checkBox_2.Checked = true;
  2279. }
  2280. else
  2281. {
  2282. textBox_2.ReadOnly = true;
  2283. }
  2284. }
  2285. }
  2286. private void checkBox_3_CheckedChanged(object sender, EventArgs e)
  2287. {
  2288. if (checkBox_3.Checked)
  2289. {
  2290. textBox_3.ReadOnly = false;
  2291. }
  2292. else
  2293. {
  2294. if (!CheckConstants(checkBox_3.Text))
  2295. {
  2296. checkBox_3.Checked = true;
  2297. }
  2298. else
  2299. {
  2300. textBox_3.ReadOnly = true;
  2301. }
  2302. }
  2303. }
  2304. private void checkBox_4_CheckedChanged(object sender, EventArgs e)
  2305. {
  2306. if (checkBox_4.Checked)
  2307. {
  2308. textBox_4.ReadOnly = false;
  2309. }
  2310. else
  2311. {
  2312. if (!CheckConstants(checkBox_4.Text))
  2313. {
  2314. checkBox_4.Checked = true;
  2315. }
  2316. else
  2317. {
  2318. textBox_4.ReadOnly = true;
  2319. }
  2320. }
  2321. }
  2322. private void checkBox_5_CheckedChanged(object sender, EventArgs e)
  2323. {
  2324. if (checkBox_5.Checked)
  2325. {
  2326. textBox_5.ReadOnly = false;
  2327. }
  2328. else
  2329. {
  2330. if (!CheckConstants(checkBox_5.Text))
  2331. {
  2332. checkBox_5.Checked = true;
  2333. }
  2334. else
  2335. {
  2336. textBox_5.ReadOnly = true;
  2337. }
  2338. }
  2339. }
  2340. private void checkBox_6_CheckedChanged(object sender, EventArgs e)
  2341. {
  2342. if (checkBox_6.Checked)
  2343. {
  2344. textBox_6.ReadOnly = false;
  2345. }
  2346. else
  2347. {
  2348. if (!CheckConstants(checkBox_6.Text))
  2349. {
  2350. checkBox_6.Checked = true;
  2351. }
  2352. else
  2353. {
  2354. textBox_6.ReadOnly = true;
  2355. }
  2356. }
  2357. }
  2358. private void checkBox_7_CheckedChanged(object sender, EventArgs e)
  2359. {
  2360. if (checkBox_7.Checked)
  2361. {
  2362. textBox_7.ReadOnly = false;
  2363. }
  2364. else
  2365. {
  2366. if (!CheckConstants(checkBox_7.Text))
  2367. {
  2368. checkBox_7.Checked = true;
  2369. }
  2370. else
  2371. {
  2372. textBox_7.ReadOnly = true;
  2373. }
  2374. }
  2375. }
  2376. private void checkBox_8_CheckedChanged(object sender, EventArgs e)
  2377. {
  2378. if (checkBox_8.Checked)
  2379. {
  2380. textBox_8.ReadOnly = false;
  2381. }
  2382. else
  2383. {
  2384. if (!CheckConstants(checkBox_8.Text))
  2385. {
  2386. checkBox_8.Checked = true;
  2387. }
  2388. else
  2389. {
  2390. textBox_8.ReadOnly = true;
  2391. }
  2392. }
  2393. }
  2394. private void checkBox_9_CheckedChanged(object sender, EventArgs e)
  2395. {
  2396. if (checkBox_9.Checked)
  2397. {
  2398. textBox_9.ReadOnly = false;
  2399. }
  2400. else
  2401. {
  2402. if (!CheckConstants(checkBox_9.Text))
  2403. {
  2404. checkBox_9.Checked = true;
  2405. }
  2406. else
  2407. {
  2408. textBox_9.ReadOnly = true;
  2409. }
  2410. }
  2411. }
  2412. private bool CheckConstants(string ConstantName)
  2413. {
  2414. for (int num = 0; num < XmlTree_STDlist.Nodes.Count; num++)
  2415. {
  2416. if (XmlTree_STDlist.Nodes[num].Tag.ToString().Contains(ConstantName))
  2417. {
  2418. tabControl_Rules.SelectedIndex = 0;
  2419. XmlTree_STDlist.SelectedNode = XmlTree_STDlist.Nodes[num];
  2420. SetGrayExceptSelectedNode(XmlTree_STDlist, XmlTree_STDlist.SelectedNode);
  2421. DialogResult result = MessageBox.Show(table["message27"].ToString() + XmlTree_STDlist.Nodes[num].Text + table["message28"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Warning);
  2422. return false;
  2423. }
  2424. }
  2425. for (int num = 0; num < XmlTree_MaxEDSRules.Nodes.Count; num++)
  2426. {
  2427. if (XmlTree_MaxEDSRules.Nodes[num].Tag.ToString().Contains(ConstantName))
  2428. {
  2429. tabControl_Rules.SelectedIndex = 1;
  2430. XmlTree_MaxEDSRules.SelectedNode = XmlTree_MaxEDSRules.Nodes[num];
  2431. SetGrayExceptSelectedNode(XmlTree_MaxEDSRules, XmlTree_MaxEDSRules.SelectedNode);
  2432. DialogResult result = MessageBox.Show(table["message27"].ToString() + XmlTree_MaxEDSRules.Nodes[num].Text + table["message28"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Warning);
  2433. return false;
  2434. }
  2435. }
  2436. for (int num = 0; num < XmlTree_ZeroElementRules.Nodes.Count; num++)
  2437. {
  2438. if (XmlTree_ZeroElementRules.Nodes[num].Tag.ToString().Contains(ConstantName))
  2439. {
  2440. tabControl_Rules.SelectedIndex = 2;
  2441. XmlTree_ZeroElementRules.SelectedNode = XmlTree_ZeroElementRules.Nodes[num];
  2442. SetGrayExceptSelectedNode(XmlTree_ZeroElementRules, XmlTree_ZeroElementRules.SelectedNode);
  2443. DialogResult result = MessageBox.Show(table["message27"].ToString() + XmlTree_ZeroElementRules.Nodes[num].Text + table["message28"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Warning);
  2444. return false;
  2445. }
  2446. }
  2447. return true;
  2448. }
  2449. private void button_UpdateConstants_Click(object sender, EventArgs e)
  2450. {
  2451. this.comboBox_Constants.Items.Clear();
  2452. for (int i = 0; i < 10; i++)
  2453. {
  2454. CheckBox checkBox = (CheckBox)this.tabControl_Rules.TabPages[3].Controls.Find("checkBox_" + i.ToString(), false)[0];
  2455. if (checkBox.Checked)
  2456. {
  2457. TextBox tBox = (TextBox)this.tabControl_Rules.TabPages[3].Controls.Find("textBox_" + i.ToString(), false)[0];
  2458. double DoubleTry = 0;
  2459. if (double.TryParse(tBox.Text, out DoubleTry))
  2460. {
  2461. this.comboBox_Constants.Items.Add(checkBox.Text + "=" + tBox.Text);
  2462. }
  2463. else
  2464. {
  2465. MessageBox.Show(table["message29"].ToString() + checkBox.Name + table["message30"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Warning);
  2466. return;
  2467. }
  2468. }
  2469. }
  2470. List<string> Constantslist = new List<string>();
  2471. Constantslist.Add("MAC#0");
  2472. Constantslist.Add("MAC#1");
  2473. Constantslist.Add("MAC#2");
  2474. Constantslist.Add("MAC#3");
  2475. Constantslist.Add("MAC#4");
  2476. Constantslist.Add("MAC#5");
  2477. Constantslist.Add("MAC#6");
  2478. Constantslist.Add("MAC#7");
  2479. Constantslist.Add("MAC#8");
  2480. Constantslist.Add("MAC#9");
  2481. foreach (var item in comboBox_Constants.Items)
  2482. {
  2483. Constantslist.Remove(item.ToString().Split('=')[0]);
  2484. }
  2485. MessageBox.Show(table["message31"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  2486. }
  2487. //tabpage切换开关
  2488. bool Flag_TabControlChange = true;
  2489. private void tabControl_Rules_Deselecting(object sender, TabControlCancelEventArgs e)
  2490. {
  2491. if (tabControl_Rules.SelectedIndex == 0)
  2492. {
  2493. //保存节点当前数据
  2494. if (XmlTree_STDlist.SelectedNode != null)
  2495. {
  2496. //判断Hardness、Density、Electrical_conductivity
  2497. double dHardness = 0, dDensity = 0, dElectrical_conductivity = 0;
  2498. if (!double.TryParse(textBox_Hardness.Text, out dHardness) || (double.Parse(textBox_Hardness.Text) <= 0))
  2499. {
  2500. textBox_Hardness.Focus();
  2501. textBox_Hardness.SelectAll();
  2502. MessageBox.Show(table["message10"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  2503. Flag_TabControlChange = false;
  2504. return;
  2505. }
  2506. if (!double.TryParse(textBox_Density.Text, out dDensity) || double.Parse(textBox_Density.Text) <= 0)
  2507. {
  2508. textBox_Density.Focus();
  2509. textBox_Density.SelectAll();
  2510. MessageBox.Show(table["message11"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  2511. Flag_TabControlChange = false;
  2512. return;
  2513. }
  2514. if (!double.TryParse(textBox_Electrical_conductivity.Text, out dElectrical_conductivity) || double.Parse(textBox_Electrical_conductivity.Text) <= 0)
  2515. {
  2516. textBox_Electrical_conductivity.Focus();
  2517. textBox_Electrical_conductivity.SelectAll();
  2518. MessageBox.Show(table["message12"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  2519. Flag_TabControlChange = false;
  2520. return;
  2521. }
  2522. if (textBox_BSEValue.Text.LastIndexOf("_") > 0)
  2523. {
  2524. textBox_BSEValue.Focus();
  2525. textBox_BSEValue.SelectAll();
  2526. MessageBox.Show(table["message13"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  2527. textBox_BSEValue.Focus();
  2528. return;
  2529. }
  2530. if (textBox_Formula.Text.LastIndexOf("_") > 0)
  2531. {
  2532. textBox_Formula.Focus();
  2533. textBox_Formula.SelectAll();
  2534. MessageBox.Show(table["message14"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  2535. textBox_Formula.Focus();
  2536. return;
  2537. }
  2538. if (textBox_Element.Text.LastIndexOf("_") > 0)
  2539. {
  2540. textBox_Element.Focus();
  2541. textBox_Element.SelectAll();
  2542. MessageBox.Show(table["message15"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  2543. textBox_Element.Focus();
  2544. return;
  2545. }
  2546. //判断textbox_STDEditor
  2547. if (!Checktextbox_STDEditor())
  2548. {
  2549. Flag_TabControlChange = false;
  2550. return;
  2551. }
  2552. Flag_TabControlChange = true;
  2553. XmlTree_STDlist.SelectedNode.Tag = this.textbox_STDEditor.Text;
  2554. XmlTree_STDlist.SelectedNode.Name = textBox_Hardness.Text + "_" + textBox_Density.Text + "_" + textBox_Electrical_conductivity.Text + "_" + textBox_BSEValue.Text + "_" + textBox_Formula.Text + "_" + textBox_Element.Text; ;
  2555. string sKeyElements = "";
  2556. for (int i = 0; i < dataGridView_KeyElements.Columns.Count; i++)
  2557. {
  2558. sKeyElements += dataGridView_KeyElements.Rows[0].Cells[i].Value.ToString() + ",";
  2559. }
  2560. if (sKeyElements.Length > 0)
  2561. {
  2562. sKeyElements = sKeyElements.Substring(0, sKeyElements.Length - 1);
  2563. }
  2564. string sSubElements = "";
  2565. for (int i = 0; i < dataGridView_SubElements.Columns.Count; i++)
  2566. {
  2567. sSubElements += dataGridView_SubElements.Rows[0].Cells[i].Value.ToString() + ",";
  2568. }
  2569. if (sSubElements.Length > 0)
  2570. {
  2571. sSubElements = sSubElements.Substring(0, sSubElements.Length - 1);
  2572. }
  2573. XmlTree_STDlist.SelectedNode.Name += "$" + sKeyElements + "$" + sSubElements;
  2574. XmlTree_STDlist.SelectedNode.BackColor = btn_dbs.BackColor;
  2575. }
  2576. }
  2577. else if (tabControl_Rules.SelectedIndex == 1)
  2578. {
  2579. if (XmlTree_MaxEDSRules.SelectedNode != null)
  2580. {
  2581. //判断MaxEDSTime
  2582. double dMaxEDSTime = 0;
  2583. if (!double.TryParse(textBox_MaxEDSTime.Text, out dMaxEDSTime) || double.Parse(textBox_MaxEDSTime.Text) <= 0)
  2584. {
  2585. textBox_MaxEDSTime.Focus();
  2586. textBox_MaxEDSTime.SelectAll();
  2587. MessageBox.Show(table["message16"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  2588. Flag_TabControlChange = false;
  2589. return;
  2590. }
  2591. //判断textbox_STDEditor
  2592. if (!Checktextbox_STDEditor())
  2593. {
  2594. Flag_TabControlChange = false;
  2595. return;
  2596. }
  2597. Flag_TabControlChange = true;
  2598. XmlTree_MaxEDSRules.SelectedNode.Tag = this.textbox_STDEditor.Text;
  2599. //XmlTree_MaxEDSRules.SelectedNode.Name = textBox_MaxEDSTime.Text;
  2600. }
  2601. }
  2602. else if (tabControl_Rules.SelectedIndex == 2)
  2603. {
  2604. if (XmlTree_ZeroElementRules.SelectedNode != null)
  2605. {
  2606. if (XmlTree_ZeroElementRules.SelectedNode.Text.Contains("="))
  2607. {
  2608. if (!comboBox_PeriodicTable.Items.Contains(XmlTree_ZeroElementRules.SelectedNode.Text.Split('=')[0]))
  2609. {
  2610. MessageBox.Show(XmlTree_ZeroElementRules.SelectedNode.Text + table["message9"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  2611. Flag_TabControlChange = false;
  2612. return;
  2613. }
  2614. }
  2615. else
  2616. {
  2617. MessageBox.Show(XmlTree_ZeroElementRules.SelectedNode.Text + table["message9"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  2618. Flag_TabControlChange = false;
  2619. return;
  2620. }
  2621. //判断textbox_STDEditor
  2622. if (!Checktextbox_STDEditor())
  2623. {
  2624. Flag_TabControlChange = false;
  2625. return;
  2626. }
  2627. Flag_TabControlChange = true;
  2628. XmlTree_ZeroElementRules.SelectedNode.Tag = this.textbox_STDEditor.Text;
  2629. }
  2630. }
  2631. //XmlTree_STDlist.SelectedNode = null;
  2632. //XmlTree_MaxEDSRules.SelectedNode = null;
  2633. //XmlTree_ZeroElementRules.SelectedNode = null;
  2634. //textbox_STDEditor.Text = "";
  2635. //textBox_Density.Text = "";
  2636. //textBox_Electrical_conductivity.Text = "";
  2637. //textBox_Hardness.Text = "";
  2638. //textBox_MaxEDSTime.Text = "";
  2639. //btn_dbs.BackColor = Color.White;
  2640. }
  2641. private void tabControl_Rules_SelectedIndexChanged(object sender, EventArgs e)
  2642. {
  2643. if (tabControl_Rules.SelectedIndex == 0)
  2644. {
  2645. //XmlTree_STDlist.SelectedNode = null;
  2646. XmlTree_STDlist.Focus();
  2647. XmlTree_STDlist_AfterSelect(XmlTree_STDlist, new TreeViewEventArgs(XmlTree_STDlist.SelectedNode));
  2648. textBox_Density.ReadOnly = false;
  2649. textBox_Electrical_conductivity.ReadOnly = false;
  2650. textBox_Hardness.ReadOnly = false;
  2651. textBox_BSEValue.ReadOnly = false;
  2652. textBox_Formula.ReadOnly = false;
  2653. textBox_Element.ReadOnly = false;
  2654. btn_dbs.Enabled = true;
  2655. textBox_MaxEDSTime.ReadOnly = true;
  2656. button_UpOrder.Enabled = false;
  2657. button_DownOrder.Enabled = false;
  2658. }
  2659. else if (tabControl_Rules.SelectedIndex == 1)
  2660. {
  2661. //XmlTree_MaxEDSRules.SelectedNode = null;
  2662. XmlTree_MaxEDSRules.Focus();
  2663. XmlTree_MaxEDSRules_AfterSelect(XmlTree_MaxEDSRules, new TreeViewEventArgs(XmlTree_MaxEDSRules.SelectedNode));
  2664. dataGridView_KeyElements.Rows.Clear();
  2665. dataGridView_KeyElements.Columns.Clear();
  2666. dataGridView_SubElements.Rows.Clear();
  2667. dataGridView_SubElements.Columns.Clear();
  2668. btn_dbs.BackColor = SystemColors.Control;
  2669. textBox_Density.Text = "";
  2670. textBox_Electrical_conductivity.Text = "";
  2671. textBox_Hardness.Text = "";
  2672. textBox_Density.ReadOnly = true;
  2673. textBox_Electrical_conductivity.ReadOnly = true;
  2674. textBox_Hardness.ReadOnly = true;
  2675. textBox_BSEValue.ReadOnly = true;
  2676. textBox_Formula.ReadOnly = true;
  2677. textBox_Element.ReadOnly = true;
  2678. btn_dbs.Enabled = false;
  2679. textBox_MaxEDSTime.ReadOnly = false;
  2680. tabSTDStandrad.SelectedIndex = 0;
  2681. }
  2682. else if (tabControl_Rules.SelectedIndex == 2)
  2683. {
  2684. //XmlTree_ZeroElementRules.SelectedNode = null;
  2685. XmlTree_ZeroElementRules.Focus();
  2686. XmlTree_ZeroElementRules_AfterSelect(XmlTree_MaxEDSRules, new TreeViewEventArgs(XmlTree_ZeroElementRules.SelectedNode));
  2687. dataGridView_KeyElements.Rows.Clear();
  2688. dataGridView_KeyElements.Columns.Clear();
  2689. dataGridView_SubElements.Rows.Clear();
  2690. dataGridView_SubElements.Columns.Clear();
  2691. btn_dbs.BackColor = SystemColors.Control;
  2692. textBox_Density.Text = "";
  2693. textBox_Electrical_conductivity.Text = "";
  2694. textBox_Hardness.Text = "";
  2695. textBox_Density.ReadOnly = true;
  2696. textBox_Electrical_conductivity.ReadOnly = true;
  2697. textBox_BSEValue.ReadOnly = true;
  2698. textBox_Formula.ReadOnly = true;
  2699. textBox_Element.ReadOnly = true;
  2700. textBox_Hardness.ReadOnly = true;
  2701. btn_dbs.Enabled = false;
  2702. textBox_MaxEDSTime.ReadOnly = true;
  2703. tabSTDStandrad.SelectedIndex = 0;
  2704. }
  2705. else
  2706. {
  2707. textbox_STDEditor.Text = "";
  2708. dataGridView_KeyElements.Rows.Clear();
  2709. dataGridView_KeyElements.Columns.Clear();
  2710. dataGridView_SubElements.Rows.Clear();
  2711. dataGridView_SubElements.Columns.Clear();
  2712. btn_dbs.BackColor = SystemColors.Control;
  2713. textBox_Density.Text = "";
  2714. textBox_Electrical_conductivity.Text = "";
  2715. textBox_Hardness.Text = "";
  2716. textBox_Density.ReadOnly = true;
  2717. textBox_Electrical_conductivity.ReadOnly = true;
  2718. textBox_BSEValue.ReadOnly = true;
  2719. textBox_Formula.ReadOnly = true;
  2720. textBox_Element.ReadOnly = true;
  2721. textBox_Hardness.ReadOnly = true;
  2722. btn_dbs.Enabled = false;
  2723. textBox_MaxEDSTime.ReadOnly = true;
  2724. }
  2725. //textbox_STDEditor.Text = "";
  2726. //dataGridView_KeyElements.Rows.Clear();
  2727. //dataGridView_KeyElements.Columns.Clear();
  2728. //dataGridView_SubElements.Rows.Clear();
  2729. //dataGridView_SubElements.Columns.Clear();
  2730. }
  2731. private void XmlTree_ZeroElementRules_BeforeSelect(object sender, TreeViewCancelEventArgs e)
  2732. {
  2733. //if (e.Node != null)
  2734. //{
  2735. // if (e.Node.ForeColor == Color.Gray)
  2736. // {
  2737. // e.Cancel = true; //不让选中禁用节点
  2738. // return;
  2739. // }
  2740. //}
  2741. if (XmlTree_ZeroElementRules.SelectedNode != null)
  2742. {
  2743. if (XmlTree_ZeroElementRules.SelectedNode.Text.Contains("="))
  2744. {
  2745. if (!comboBox_PeriodicTable.Items.Contains(XmlTree_ZeroElementRules.SelectedNode.Text.Split('=')[0]))
  2746. {
  2747. MessageBox.Show(XmlTree_ZeroElementRules.SelectedNode.Text + table["message9"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  2748. SetGrayExceptSelectedNode(XmlTree_ZeroElementRules, XmlTree_ZeroElementRules.SelectedNode);
  2749. e.Cancel = true;
  2750. return;
  2751. }
  2752. }
  2753. else
  2754. {
  2755. MessageBox.Show(XmlTree_ZeroElementRules.SelectedNode.Text + table["message9"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  2756. SetGrayExceptSelectedNode(XmlTree_ZeroElementRules, XmlTree_ZeroElementRules.SelectedNode);
  2757. e.Cancel = true;
  2758. return;
  2759. }
  2760. if (!Checktextbox_STDEditor())
  2761. {
  2762. SetGrayExceptSelectedNode(XmlTree_ZeroElementRules, XmlTree_ZeroElementRules.SelectedNode);
  2763. e.Cancel = true;
  2764. return;
  2765. }
  2766. XmlTree_ZeroElementRules.SelectedNode.Tag = this.textbox_STDEditor.Text;
  2767. }
  2768. }
  2769. private void tabControl_Rules_Selecting(object sender, TabControlCancelEventArgs e)
  2770. {
  2771. if (!Flag_TabControlChange)
  2772. {
  2773. e.Cancel = true;
  2774. }
  2775. else
  2776. {
  2777. }
  2778. }
  2779. private void XmlTree_ZeroElementRules_AfterSelect(object sender, TreeViewEventArgs e)
  2780. {
  2781. SetBlackAllNodes(XmlTree_ZeroElementRules);
  2782. this.textbox_STDEditor.Text = XmlTree_ZeroElementRules.SelectedNode.Tag.ToString();
  2783. }
  2784. private void XmlTree_STDlist_BeforeSelect(object sender, TreeViewCancelEventArgs e)
  2785. {
  2786. if (XmlTree_STDlist.SelectedNode != null)
  2787. {
  2788. //判断Hardness、Density、Electrical_conductivity
  2789. double dHardness = 0, dDensity = 0, dElectrical_conductivity = 0;
  2790. if (!double.TryParse(textBox_Hardness.Text, out dHardness) || (double.Parse(textBox_Hardness.Text) <= 0))
  2791. {
  2792. MessageBox.Show(table["message10"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  2793. SetGrayExceptSelectedNode(XmlTree_STDlist, XmlTree_STDlist.SelectedNode);
  2794. Flag_SelStatus = false;
  2795. e.Cancel = true;
  2796. return;
  2797. }
  2798. if (!double.TryParse(textBox_Density.Text, out dDensity) || double.Parse(textBox_Density.Text) <= 0)
  2799. {
  2800. MessageBox.Show(table["message11"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  2801. SetGrayExceptSelectedNode(XmlTree_STDlist, XmlTree_STDlist.SelectedNode);
  2802. Flag_SelStatus = false;
  2803. e.Cancel = true;
  2804. return;
  2805. }
  2806. if (!double.TryParse(textBox_Electrical_conductivity.Text, out dElectrical_conductivity) || double.Parse(textBox_Electrical_conductivity.Text) <= 0)
  2807. {
  2808. MessageBox.Show(table["message12"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  2809. SetGrayExceptSelectedNode(XmlTree_STDlist, XmlTree_STDlist.SelectedNode);
  2810. Flag_SelStatus = false;
  2811. e.Cancel = true;
  2812. return;
  2813. }
  2814. if (textBox_BSEValue.Text.LastIndexOf("_") > 0)
  2815. {
  2816. MessageBox.Show(table["message13"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  2817. textBox_BSEValue.Focus();
  2818. return;
  2819. }
  2820. if (textBox_Formula.Text.LastIndexOf("_") > 0)
  2821. {
  2822. MessageBox.Show(table["message14"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  2823. textBox_Formula.Focus();
  2824. return;
  2825. }
  2826. if (textBox_Element.Text.LastIndexOf("_") > 0)
  2827. {
  2828. MessageBox.Show(table["message15"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  2829. textBox_Element.Focus();
  2830. return;
  2831. }
  2832. //判断textbox_STDEditor
  2833. if (!Checktextbox_STDEditor())
  2834. {
  2835. SetGrayExceptSelectedNode(XmlTree_STDlist, XmlTree_STDlist.SelectedNode);
  2836. Flag_SelStatus = false;
  2837. e.Cancel = true;
  2838. return;
  2839. }
  2840. XmlTree_STDlist.SelectedNode.Tag = this.textbox_STDEditor.Text;
  2841. if (dataGridView_KeyElements.Rows.Count == 0 && dataGridView_SubElements.Rows.Count == 0)
  2842. {
  2843. string str_RemoveBlank = textbox_STDEditor.Text.ToString().Replace(" ", "");
  2844. str_RemoveBlank = str_RemoveBlank.Replace("\r\n", "");
  2845. str_RemoveBlank = str_RemoveBlank.Replace("forth_elem", "");
  2846. string[] str_Removeand = System.Text.RegularExpressions.Regex.Split(str_RemoveBlank, "and", System.Text.RegularExpressions.RegexOptions.None);
  2847. List<string> str_Removeandor = new List<string>();
  2848. for (int i = 0; i < str_Removeand.Length; i++)
  2849. {
  2850. str_Removeandor.AddRange(System.Text.RegularExpressions.Regex.Split(str_Removeand[i], "or", System.Text.RegularExpressions.RegexOptions.None));
  2851. }
  2852. List<string> list_all = new List<string>();
  2853. for (int i = 0; i < str_Removeandor.Count; i++)
  2854. {
  2855. list_all.AddRange(str_Removeandor[i].Split(new char[] { '+', '-', '*', '/', '=', '>', '<', '(', ')' }));
  2856. }
  2857. List<string> UsingElementL = new List<string>();
  2858. for (int i = 0; i < list_all.Count; i++)
  2859. {
  2860. if (this.comboBox_PeriodicTable.Items.Contains(list_all[i]))
  2861. {
  2862. if (!UsingElementL.Contains(list_all[i]))
  2863. {
  2864. UsingElementL.Add(list_all[i]);
  2865. }
  2866. }
  2867. }
  2868. for (int i = 0; i < UsingElementL.Count; i++)
  2869. {
  2870. DataGridViewButtonColumn dataGridViewButtonColumn = new DataGridViewButtonColumn();
  2871. dataGridViewButtonColumn.Name = dataGridView_KeyElements.Columns.Count.ToString();
  2872. dataGridView_KeyElements.Columns.Add(dataGridViewButtonColumn);
  2873. if (dataGridView_KeyElements.Rows.Count == 0)
  2874. {
  2875. DataGridViewRow row = new DataGridViewRow();
  2876. dataGridView_KeyElements.Rows.Add(row);
  2877. }
  2878. dataGridView_KeyElements.Rows[0].Cells[i].Value = UsingElementL[i];
  2879. }
  2880. }
  2881. XmlTree_STDlist.SelectedNode.Name = textBox_Hardness.Text + "_" + textBox_Density.Text + "_" + textBox_Electrical_conductivity.Text + "_" + textBox_BSEValue.Text + "_" + textBox_Formula.Text + "_" + textBox_Element.Text; ;
  2882. string sKeyElements = "";
  2883. for (int i = 0; i < dataGridView_KeyElements.Columns.Count; i++)
  2884. {
  2885. sKeyElements += dataGridView_KeyElements.Rows[0].Cells[i].Value.ToString() + ",";
  2886. }
  2887. if (sKeyElements.Length > 0)
  2888. {
  2889. sKeyElements = sKeyElements.Substring(0, sKeyElements.Length - 1);
  2890. }
  2891. string sSubElements = "";
  2892. for (int i = 0; i < dataGridView_SubElements.Columns.Count; i++)
  2893. {
  2894. sSubElements += dataGridView_SubElements.Rows[0].Cells[i].Value.ToString() + ",";
  2895. }
  2896. if (sSubElements.Length > 0)
  2897. {
  2898. sSubElements = sSubElements.Substring(0, sSubElements.Length - 1);
  2899. }
  2900. XmlTree_STDlist.SelectedNode.Name += "$" + sKeyElements + "$" + sSubElements;
  2901. XmlTree_STDlist.SelectedNode.BackColor = btn_dbs.BackColor;
  2902. }
  2903. }
  2904. private void XmlTree_MaxEDSRules_AfterSelect(object sender, TreeViewEventArgs e)
  2905. {
  2906. SetBlackAllNodes(XmlTree_MaxEDSRules);
  2907. this.textbox_STDEditor.Text = XmlTree_MaxEDSRules.SelectedNode.Tag.ToString();
  2908. //textBox_MaxEDSTime.Text = XmlTree_MaxEDSRules.SelectedNode.Name;
  2909. }
  2910. private void XmlTree_MaxEDSRules_BeforeSelect(object sender, TreeViewCancelEventArgs e)
  2911. {
  2912. if (XmlTree_MaxEDSRules.SelectedNode != null)
  2913. {
  2914. if (!Checktextbox_STDEditor())
  2915. {
  2916. SetGrayExceptSelectedNode(XmlTree_MaxEDSRules, XmlTree_MaxEDSRules.SelectedNode);
  2917. e.Cancel = true;
  2918. return;
  2919. }
  2920. //double dMaxEDSTime = 0;
  2921. //if (!double.TryParse(textBox_MaxEDSTime.Text, out dMaxEDSTime)||double.Parse(textBox_MaxEDSTime.Text)<=0)
  2922. //{
  2923. // MessageBox.Show("MaxEDSTime请填写数字!", "提示");
  2924. // e.Cancel = true;
  2925. //}
  2926. XmlTree_MaxEDSRules.SelectedNode.Tag = this.textbox_STDEditor.Text;
  2927. //XmlTree_MaxEDSRules.SelectedNode.Name = this.textBox_MaxEDSTime.Text;
  2928. }
  2929. }
  2930. string ElementKeyOrSub = "";
  2931. private void dataGridView_KeyElements_CellClick(object sender, DataGridViewCellEventArgs e)
  2932. {
  2933. ElementKeyOrSub = dataGridView_KeyElements.CurrentCell.Value.ToString();
  2934. dataGridView_KeyElements.Columns.RemoveAt(e.ColumnIndex);
  2935. DataGridViewButtonColumn dataGridViewButtonColumn = new DataGridViewButtonColumn();
  2936. dataGridViewButtonColumn.Name = dataGridView_SubElements.Columns.Count.ToString();
  2937. dataGridView_SubElements.Columns.Add(dataGridViewButtonColumn);
  2938. if (dataGridView_SubElements.Rows.Count == 0)
  2939. {
  2940. DataGridViewRow row = new DataGridViewRow();
  2941. dataGridView_SubElements.Rows.Add(row);
  2942. }
  2943. dataGridView_SubElements.Rows[0].Cells[dataGridView_SubElements.Columns.Count - 1].Value = ElementKeyOrSub;
  2944. dataGridView_SubElements.ClearSelection();
  2945. dataGridView_KeyElements.ClearSelection();
  2946. XmlTree_STDlist.Focus();
  2947. }
  2948. private void dataGridView_SubElements_CellClick(object sender, DataGridViewCellEventArgs e)
  2949. {
  2950. ElementKeyOrSub = dataGridView_SubElements.CurrentCell.Value.ToString();
  2951. dataGridView_SubElements.Columns.RemoveAt(e.ColumnIndex);
  2952. DataGridViewButtonColumn dataGridViewButtonColumn = new DataGridViewButtonColumn();
  2953. dataGridViewButtonColumn.Name = dataGridView_SubElements.Columns.Count.ToString();
  2954. dataGridView_KeyElements.Columns.Add(dataGridViewButtonColumn);
  2955. if (dataGridView_KeyElements.Rows.Count == 0)
  2956. {
  2957. DataGridViewRow row = new DataGridViewRow();
  2958. dataGridView_KeyElements.Rows.Add(row);
  2959. }
  2960. dataGridView_KeyElements.Rows[0].Cells[dataGridView_KeyElements.Columns.Count - 1].Value = ElementKeyOrSub;
  2961. dataGridView_KeyElements.ClearSelection();
  2962. dataGridView_SubElements.ClearSelection();
  2963. XmlTree_STDlist.Focus();
  2964. }
  2965. private void textbox_STDEditor_TextChanged(object sender, EventArgs e)
  2966. {
  2967. //string str_RemoveBlank = textbox_STDEditor.Text.ToString().Replace(" ", "");
  2968. //str_RemoveBlank = str_RemoveBlank.Replace("forth_elem", "");
  2969. //string[] str_Removeand = System.Text.RegularExpressions.Regex.Split(str_RemoveBlank, "and", System.Text.RegularExpressions.RegexOptions.None);
  2970. //List<string> str_Removeandor = new List<string>();
  2971. //for (int i = 0; i < str_Removeand.Length; i++)
  2972. //{
  2973. // str_Removeandor.AddRange(System.Text.RegularExpressions.Regex.Split(str_Removeand[i], "or", System.Text.RegularExpressions.RegexOptions.None));
  2974. //}
  2975. //List<string> list_all = new List<string>();
  2976. //for (int i = 0; i < str_Removeandor.Count; i++)
  2977. //{
  2978. // list_all.AddRange(str_Removeandor[i].Split(new char[] { '+', '-', '*', '/', '=', '>', '<', '(', ')' }));
  2979. //}
  2980. //List<string> UsingElementL = new List<string>();
  2981. //for (int i = 0; i < list_all.Count; i++)
  2982. //{
  2983. // if (this.comboBox_PeriodicTable.Items.Contains(list_all[i]))
  2984. // {
  2985. // if (!UsingElementL.Contains(list_all[i]))
  2986. // {
  2987. // UsingElementL.Add(list_all[i]);
  2988. // }
  2989. // }
  2990. //}
  2991. //for (int i = 0; i < UsingElementL.Count; i++)
  2992. //{
  2993. // DataGridViewButtonColumn dataGridViewButtonColumn = new DataGridViewButtonColumn();
  2994. // dataGridViewButtonColumn.Name = dataGridView_KeyElements.Columns.Count.ToString();
  2995. // dataGridView_KeyElements.Columns.Add(dataGridViewButtonColumn);
  2996. // if (dataGridView_KeyElements.Rows.Count == 0)
  2997. // {
  2998. // DataGridViewRow row = new DataGridViewRow();
  2999. // dataGridView_KeyElements.Rows.Add(row);
  3000. // }
  3001. // dataGridView_KeyElements.Rows[0].Cells[i].Value = UsingElementL[i];
  3002. //}
  3003. }
  3004. private void textbox_STDEditor_KeyPress(object sender, KeyPressEventArgs e)
  3005. {
  3006. //if (e.KeyChar == '\r')
  3007. //{
  3008. // dataGridView_KeyElements.Rows.Clear();
  3009. // dataGridView_KeyElements.Columns.Clear();
  3010. // dataGridView_SubElements.Rows.Clear();
  3011. // dataGridView_SubElements.Columns.Clear();
  3012. // string str_RemoveBlank = textbox_STDEditor.Text.ToString().Replace(" ", "");
  3013. // str_RemoveBlank = str_RemoveBlank.Replace("\r\n", "");
  3014. // str_RemoveBlank = str_RemoveBlank.Replace("forth_elem", "");
  3015. // string[] str_Removeand = System.Text.RegularExpressions.Regex.Split(str_RemoveBlank, "and", System.Text.RegularExpressions.RegexOptions.None);
  3016. // List<string> str_Removeandor = new List<string>();
  3017. // for (int i = 0; i < str_Removeand.Length; i++)
  3018. // {
  3019. // str_Removeandor.AddRange(System.Text.RegularExpressions.Regex.Split(str_Removeand[i], "or", System.Text.RegularExpressions.RegexOptions.None));
  3020. // }
  3021. // List<string> list_all = new List<string>();
  3022. // for (int i = 0; i < str_Removeandor.Count; i++)
  3023. // {
  3024. // list_all.AddRange(str_Removeandor[i].Split(new char[] { '+', '-', '*', '/', '=', '>', '<', '(', ')' }));
  3025. // }
  3026. // List<string> UsingElementL = new List<string>();
  3027. // for (int i = 0; i < list_all.Count; i++)
  3028. // {
  3029. // if (this.comboBox_PeriodicTable.Items.Contains(list_all[i]))
  3030. // {
  3031. // if (!UsingElementL.Contains(list_all[i]))
  3032. // {
  3033. // UsingElementL.Add(list_all[i]);
  3034. // }
  3035. // }
  3036. // }
  3037. // for (int i = 0; i < UsingElementL.Count; i++)
  3038. // {
  3039. // DataGridViewButtonColumn dataGridViewButtonColumn = new DataGridViewButtonColumn();
  3040. // dataGridViewButtonColumn.Name = dataGridView_KeyElements.Columns.Count.ToString();
  3041. // dataGridView_KeyElements.Columns.Add(dataGridViewButtonColumn);
  3042. // if(dataGridView_KeyElements.Rows.Count==0)
  3043. // {
  3044. // DataGridViewRow row = new DataGridViewRow();
  3045. // dataGridView_KeyElements.Rows.Add(row);
  3046. // }
  3047. // dataGridView_KeyElements.Rows[0].Cells[i].Value = UsingElementL[i];
  3048. // }
  3049. //}
  3050. }
  3051. private void textbox_STDEditor_Leave(object sender, EventArgs e)
  3052. {
  3053. if (tabControl_Rules.SelectedIndex == 0)
  3054. {
  3055. dataGridView_KeyElements.Rows.Clear();
  3056. dataGridView_KeyElements.Columns.Clear();
  3057. string str_RemoveBlank = textbox_STDEditor.Text.ToString().Replace(" ", "");
  3058. str_RemoveBlank = str_RemoveBlank.Replace("\r\n", "");
  3059. str_RemoveBlank = str_RemoveBlank.Replace("forth_elem", "");
  3060. string[] str_Removeand = System.Text.RegularExpressions.Regex.Split(str_RemoveBlank, "and", System.Text.RegularExpressions.RegexOptions.None);
  3061. List<string> str_Removeandor = new List<string>();
  3062. for (int i = 0; i < str_Removeand.Length; i++)
  3063. {
  3064. str_Removeandor.AddRange(System.Text.RegularExpressions.Regex.Split(str_Removeand[i], "or", System.Text.RegularExpressions.RegexOptions.None));
  3065. }
  3066. List<string> list_all = new List<string>();
  3067. for (int i = 0; i < str_Removeandor.Count; i++)
  3068. {
  3069. list_all.AddRange(str_Removeandor[i].Split(new char[] { '+', '-', '*', '/', '=', '>', '<', '(', ')' }));
  3070. }
  3071. List<string> UsingElementL = new List<string>();
  3072. for (int i = 0; i < list_all.Count; i++)
  3073. {
  3074. if (this.comboBox_PeriodicTable.Items.Contains(list_all[i]))
  3075. {
  3076. if (!UsingElementL.Contains(list_all[i]))
  3077. {
  3078. UsingElementL.Add(list_all[i]);
  3079. }
  3080. }
  3081. }
  3082. List<string> SubElements = new List<string>();
  3083. for (int i = 0; i < dataGridView_SubElements.ColumnCount; i++)
  3084. {
  3085. if (UsingElementL.Contains(dataGridView_SubElements.Rows[0].Cells[i].Value))
  3086. {
  3087. SubElements.Add(dataGridView_SubElements.Rows[0].Cells[i].Value.ToString());
  3088. }
  3089. }
  3090. dataGridView_SubElements.Rows.Clear();
  3091. dataGridView_SubElements.Columns.Clear();
  3092. for (int i = 0; i < SubElements.Count; i++)
  3093. {
  3094. DataGridViewButtonColumn dataGridViewButtonColumn = new DataGridViewButtonColumn();
  3095. dataGridViewButtonColumn.Name = dataGridView_SubElements.Columns.Count.ToString();
  3096. dataGridView_SubElements.Columns.Add(dataGridViewButtonColumn);
  3097. if (dataGridView_SubElements.Rows.Count == 0)
  3098. {
  3099. DataGridViewRow row = new DataGridViewRow();
  3100. dataGridView_SubElements.Rows.Add(row);
  3101. }
  3102. dataGridView_SubElements.Rows[0].Cells[dataGridView_SubElements.ColumnCount - 1].Value = SubElements[i];
  3103. }
  3104. if (SubElements.Count > 0)
  3105. {
  3106. for (int i = 0; i < UsingElementL.Count; i++)
  3107. {
  3108. if (!SubElements.Contains(UsingElementL[i]))
  3109. {
  3110. DataGridViewButtonColumn dataGridViewButtonColumn = new DataGridViewButtonColumn();
  3111. dataGridViewButtonColumn.Name = dataGridView_KeyElements.Columns.Count.ToString();
  3112. dataGridView_KeyElements.Columns.Add(dataGridViewButtonColumn);
  3113. if (dataGridView_KeyElements.Rows.Count == 0)
  3114. {
  3115. DataGridViewRow row = new DataGridViewRow();
  3116. dataGridView_KeyElements.Rows.Add(row);
  3117. }
  3118. dataGridView_KeyElements.Rows[0].Cells[dataGridView_KeyElements.ColumnCount - 1].Value = UsingElementL[i];
  3119. }
  3120. }
  3121. }
  3122. else
  3123. {
  3124. for (int i = 0; i < UsingElementL.Count; i++)
  3125. {
  3126. DataGridViewButtonColumn dataGridViewButtonColumn = new DataGridViewButtonColumn();
  3127. dataGridViewButtonColumn.Name = dataGridView_KeyElements.Columns.Count.ToString();
  3128. dataGridView_KeyElements.Columns.Add(dataGridViewButtonColumn);
  3129. if (dataGridView_KeyElements.Rows.Count == 0)
  3130. {
  3131. DataGridViewRow row = new DataGridViewRow();
  3132. dataGridView_KeyElements.Rows.Add(row);
  3133. }
  3134. dataGridView_KeyElements.Rows[0].Cells[i].Value = UsingElementL[i];
  3135. }
  3136. }
  3137. dataGridView_KeyElements.ClearSelection();
  3138. dataGridView_SubElements.ClearSelection();
  3139. XmlTree_STDlist.Focus();
  3140. }
  3141. else if(tabControl_Rules.SelectedIndex == 1)
  3142. {
  3143. XmlTree_MaxEDSRules.Focus();
  3144. }
  3145. else if (tabControl_Rules.SelectedIndex == 2)
  3146. {
  3147. XmlTree_ZeroElementRules.Focus();
  3148. }
  3149. }
  3150. #region 为配合textbox_STDEditor_Leave时事件,点击其它groupbox组件时使焦点转移
  3151. private void Form_ConstantsEditor_Click(object sender, EventArgs e)
  3152. {
  3153. groupBox_XmlTree_MaxEDSRules.Focus();
  3154. }
  3155. private void groupBox_Data_Click(object sender, EventArgs e)
  3156. {
  3157. groupBox_Data.Focus();
  3158. }
  3159. private void groupBox_ChemicalElement_Click(object sender, EventArgs e)
  3160. {
  3161. groupBox_ChemicalElement.Focus();
  3162. }
  3163. private void groupBox_OtherCommonlyUsedSymbols_Click(object sender, EventArgs e)
  3164. {
  3165. groupBox_OtherCommonlyUsedSymbols.Focus();
  3166. }
  3167. private void groupBox_XmlTree_STDlist1_Click(object sender, EventArgs e)
  3168. {
  3169. groupBox_XmlTree_STDlist1.Focus();
  3170. }
  3171. private void groupBox_CalculatingSymbols_Click(object sender, EventArgs e)
  3172. {
  3173. groupBox_CalculatingSymbols.Focus();
  3174. }
  3175. private void groupBox_XmlTree_MaxEDSRules_Click(object sender, EventArgs e)
  3176. {
  3177. groupBox_XmlTree_MaxEDSRules.Focus();
  3178. }
  3179. #endregion
  3180. #region 采集Xray 按钮事件
  3181. private void btnCollectXray_Click(object sender, EventArgs e)
  3182. {
  3183. string strTime = txtCollectTime.Text.Trim();
  3184. if (txtCollectTime.Equals(""))
  3185. {
  3186. showMessage(table["message33"].ToString());
  3187. txtCollectTime.Focus();
  3188. return;
  3189. }
  3190. if (!IsMatch(strTime, 1))
  3191. {
  3192. showMessage(table["message34"].ToString());
  3193. txtCollectTime.Focus();
  3194. return;
  3195. }
  3196. if (Convert.ToInt32(strTime) < 100)
  3197. {
  3198. showMessage(table["message35"].ToString());
  3199. txtCollectTime.Focus();
  3200. return;
  3201. }
  3202. //显示Xray
  3203. xrayByteData = IntArrToByteArr(GetCollectXray(strTime));
  3204. int color = Convert.ToInt32(ParseRGB(btn_dbs.BackColor));
  3205. //根据树节点修改对应的Xray信息
  3206. UpdateSTDXray(XmlTree_STDlist.SelectedNode, xrayByteData);
  3207. ShowXrayAtlas(color, xrayByteData);
  3208. }
  3209. /// <summary>
  3210. /// 获取采集当前的Xray信息
  3211. /// </summary>
  3212. /// <returns></returns>
  3213. protected uint[] GetCollectXray(string strTime)
  3214. {
  3215. try
  3216. {
  3217. if (null == m_cfun)
  3218. {
  3219. m_cfun = COTSControlFunExport.GetControllerInstance();
  3220. }
  3221. if (ConnectionSem(connectionEnumType.EDSOnlyPointXRay))
  3222. {
  3223. if (EDSInit())
  3224. {
  3225. int iSize = 2000;
  3226. uint[] iXrayData = new uint[iSize];
  3227. //采集XRay数据
  3228. if (m_cfun.CollectSpectrum(uint.Parse(strTime), ref iXrayData))
  3229. {
  3230. return iXrayData;
  3231. }
  3232. }
  3233. }
  3234. return null;
  3235. }
  3236. catch /*(Exception ex)*/
  3237. {
  3238. return null;
  3239. }
  3240. finally
  3241. {
  3242. //EDS过程结束
  3243. //m_cfun.EDSFinishedInstance();
  3244. //关闭连接
  3245. DisConnectSem(connectionEnumType.EDSOnlyPointXRay);
  3246. }
  3247. }
  3248. private void btnReadXray_Click(object sender, EventArgs e)
  3249. {
  3250. OpenFileDialog fileSel = new OpenFileDialog();
  3251. fileSel.Filter = "|*.txt";
  3252. if (DialogResult.OK == fileSel.ShowDialog())
  3253. {
  3254. String str = "";
  3255. //读取Xray文件
  3256. using (StreamReader sr = new StreamReader(fileSel.FileName))
  3257. {
  3258. while (!sr.EndOfStream)
  3259. {
  3260. str += sr.ReadLine() + ",";
  3261. }
  3262. str = str.Substring(0, str.Length - 1);
  3263. string[] xrayData = str.Split(',');
  3264. if (xrayData.Length != 2000)
  3265. {
  3266. return;
  3267. }
  3268. uint[] data = new uint[xrayData.Length];
  3269. for (int i = 0; i < xrayData.Length; i++)
  3270. {
  3271. data[i] = Convert.ToUInt32(xrayData[i]);
  3272. }
  3273. //Xray数据
  3274. xrayByteData = IntArrToByteArr(data);
  3275. int color = Convert.ToInt32(ParseRGB(btn_dbs.BackColor));
  3276. //根据树节点修改对应的Xray信息
  3277. UpdateSTDXray(XmlTree_STDlist.SelectedNode, xrayByteData);
  3278. ShowXrayAtlas(color, xrayByteData);
  3279. }
  3280. }
  3281. }
  3282. /// <summary>
  3283. /// 将int[] 转换为 byte[]
  3284. /// </summary>
  3285. /// <param name="intArr"></param>
  3286. /// <returns></returns>
  3287. public static byte[] IntArrToByteArr(uint[] intArr)
  3288. {
  3289. int intSize = sizeof(int) * intArr.Length;
  3290. byte[] bytArr = new byte[intSize];
  3291. //申请一块非托管内存  
  3292. //IntPtr ptr = Marshal.AllocHGlobal(intSize);
  3293. //复制int数组到该内存块  
  3294. //Marshal.Copy(intArr, 0, ptr, intArr.Length);
  3295. ////复制回byte数组  
  3296. //Marshal.Copy(ptr, bytArr, 0, bytArr.Length);
  3297. ////释放申请的非托管内存  
  3298. //Marshal.FreeHGlobal(ptr);
  3299. for (int i = 0; i < intSize; i++)
  3300. {
  3301. byte[] c1 = BitConverter.GetBytes(intArr[i]);
  3302. c1.CopyTo(bytArr, i * intSize);
  3303. }
  3304. return bytArr;
  3305. }
  3306. /// <summary>
  3307. /// 将颜色对象转换为uint
  3308. /// </summary>
  3309. /// <param name="color"></param>
  3310. /// <returns></returns>
  3311. public uint ParseRGB(Color color)
  3312. {
  3313. return (uint)(((uint)color.B << 16) | (ushort)(((ushort)color.G << 8) | color.R));
  3314. }
  3315. #region 显示Xray图谱
  3316. /// <summary>
  3317. /// 显示Xray图谱
  3318. /// </summary>
  3319. protected void ShowXrayAtlas(int colorValue = 0, byte[] XrayData = null)
  3320. {
  3321. DataTable dt = new DataTable();
  3322. dt.Columns.Add("Color", typeof(int));
  3323. dt.Columns.Add("SPEC", typeof(byte[]));
  3324. DataRow dRow = dt.NewRow();
  3325. dRow["Color"] = colorValue;
  3326. if (XrayData != null)
  3327. {
  3328. dRow["SPEC"] = XrayData;
  3329. }
  3330. else
  3331. {
  3332. dRow["SPEC"] = new byte[8000];
  3333. }
  3334. //将选择行的数据传递给Xray控件
  3335. XrayControl.Dr = dRow;
  3336. XrayControl.Refresh();
  3337. XrayData = null;
  3338. }
  3339. #endregion
  3340. #region 常用数据验证的封装,数字字符的验证
  3341. /// <summary>
  3342. /// 常用数据验证的封装,数字字符的验证
  3343. /// </summary>
  3344. /// <param name="inputVal">需要验证的数值【字符串,或者数字】</param>
  3345. /// <param name="type">类型为哪一个验证</param>
  3346. /// <returns>如果验证成功则返回True,否则返回false</returns>
  3347. public bool IsMatch(string inputVal, int type)
  3348. {
  3349. switch (type)
  3350. {
  3351. case 0:
  3352. return Regex.IsMatch(inputVal, @"^[1-9]d*$"); //匹配正整数
  3353. case 1:
  3354. return Regex.IsMatch(inputVal, @"^-?\d+$"); //匹配整数
  3355. case 2:
  3356. return Regex.IsMatch(inputVal, @"^[A-Za-z0-9]+$"); //匹配由数字和26个英文字母组成的字符串
  3357. case 3:
  3358. 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]*))$"); //匹配正浮点数
  3359. case 4:
  3360. return Regex.IsMatch(inputVal, @"^[\u4e00-\u9fa5]{0,}$"); //匹配汉字
  3361. case 5:
  3362. return Regex.IsMatch(inputVal, @"^[0-9]+(.[0-9]{1,3})?$"); //匹配1~3位小数的正实数
  3363. case 6:
  3364. return Regex.IsMatch(inputVal, @"^[A-Za-z]+$"); //匹配英文字符
  3365. default:
  3366. return true;
  3367. }
  3368. }
  3369. #endregion
  3370. #region 弹出提示
  3371. /// <summary>
  3372. /// 弹出提示
  3373. /// </summary>
  3374. /// <param name="strContent"></param>
  3375. protected void showMessage(string strContent)
  3376. {
  3377. MessageBox.Show(strContent, table["message32"].ToString());
  3378. }
  3379. #endregion
  3380. #region 连接与关闭设备
  3381. public bool ConnectionSem(connectionEnumType connectionType)
  3382. {
  3383. //获取连接电镜类型
  3384. string connTypeStr = GetConnectionType(connectionType);
  3385. //连接电镜标识
  3386. bool bDisConnResult = false;
  3387. //判断连接状态
  3388. if (!m_bConnectionState)
  3389. {
  3390. //连接电镜设置
  3391. bDisConnResult = m_cfun.ConncetSem();
  3392. }
  3393. if (bDisConnResult)
  3394. {
  3395. m_bConnectionState = true;
  3396. }
  3397. else
  3398. {
  3399. m_bConnectionState = false;
  3400. }
  3401. return bDisConnResult;
  3402. }
  3403. public bool DisConnectSem(connectionEnumType disConnectType)
  3404. {
  3405. //获取关闭电镜类型
  3406. string connTypeStr = GetConnectionType(disConnectType);
  3407. bool bDisConnResult = false;
  3408. if (m_bConnectionState)
  3409. {
  3410. //bDisConnResult = m_cfun.DisConnectSem();
  3411. }
  3412. if (bDisConnResult)
  3413. {
  3414. m_bConnectionState = false;
  3415. }
  3416. else
  3417. {
  3418. m_bConnectionState = true;
  3419. }
  3420. return bDisConnResult;
  3421. }
  3422. private string GetConnectionType(connectionEnumType connectionType)
  3423. {
  3424. string connString = string.Empty;
  3425. switch (connectionType)
  3426. {
  3427. //设置单点采集文字内容
  3428. case connectionEnumType.EDSOnlyPointXRay:
  3429. connString = "OnlyPointXRay";
  3430. break;
  3431. //设置多点采集文字内容
  3432. case connectionEnumType.EDSMultiPointXRay:
  3433. connString = "MultiPointXRay";
  3434. break;
  3435. //设置面采集文字内容
  3436. case connectionEnumType.EDSAreaXRay:
  3437. connString = "AreaXRay";
  3438. break;
  3439. //设置图片
  3440. case connectionEnumType.ScanImage:
  3441. connString = "Image";
  3442. break;
  3443. default: break;
  3444. }
  3445. return connString;
  3446. }
  3447. /// <summary>
  3448. /// EDS初始化
  3449. /// </summary>
  3450. public bool EDSInit()
  3451. {
  3452. bool bResult = false;
  3453. //线程调用 加载
  3454. bResult = m_cfun.EDSInit();
  3455. return bResult;
  3456. }
  3457. public enum connectionEnumType
  3458. {
  3459. EDSOnlyPointXRay = 0,
  3460. EDSMultiPointXRay = 1,
  3461. EDSAreaXRay = 2,
  3462. ScanImage = 3
  3463. }
  3464. /// <summary>
  3465. /// 标准Xray状态
  3466. /// </summary>
  3467. public enum STDXrayInfoState
  3468. {
  3469. Add = 0,
  3470. Modify = 1,
  3471. Delete = 2
  3472. }
  3473. #endregion
  3474. /// <summary>
  3475. /// 记录修改后的标准中的Xray信息
  3476. /// </summary>
  3477. public class STDXray
  3478. {
  3479. /// <summary>
  3480. /// 标准编号
  3481. /// </summary>
  3482. private string stdID;
  3483. /// <summary>
  3484. /// Xray数据
  3485. /// </summary>
  3486. private byte[] xrayData;
  3487. /// <summary>
  3488. /// 状态
  3489. /// </summary>
  3490. private int infoState=-1;
  3491. public string StdID { get => stdID; set => stdID = value; }
  3492. public byte[] XrayData { get => xrayData; set => xrayData = value; }
  3493. public int InfoState { get => infoState; set => infoState = value; }
  3494. }
  3495. #endregion
  3496. #region Xray 与 STDDB数据操作
  3497. /// <summary>
  3498. /// 绑定数据库中已存在的Xray信息
  3499. /// </summary>
  3500. protected void BindSTDXray()
  3501. {
  3502. //清空STDXray列表中的集合
  3503. m_STDXrayList.Clear();
  3504. //查询
  3505. DataTable dt = m_sc.GetDTFormSysSTDBySQLString("select Id,SPEC from STDMinerals");
  3506. if (dt != null)
  3507. {
  3508. if (dt.Rows.Count > 0)
  3509. {
  3510. foreach (DataRow item in dt.Rows)
  3511. {
  3512. STDXray sXray = new STDXray();
  3513. sXray.StdID = item["Id"].ToString();
  3514. sXray.XrayData = (byte[])item["SPEC"];
  3515. m_STDXrayList.Add(sXray);
  3516. }
  3517. }
  3518. }
  3519. }
  3520. /// <summary>
  3521. /// 保存STDXray至数据库
  3522. /// </summary>
  3523. protected void SaveSTDXray()
  3524. {
  3525. ArrayList delArrayList = new ArrayList();
  3526. if (m_STDXrayList != null)
  3527. {
  3528. //if (m_STDXrayList.Count > 0)
  3529. //{
  3530. foreach (STDXray item in m_STDXrayList)
  3531. {
  3532. int infoState = item.InfoState;
  3533. //添加状态 根据Xray信息当前只能按照一条操作
  3534. if (infoState == (int)STDXrayInfoState.Add)
  3535. {
  3536. if (item.XrayData == null)
  3537. {
  3538. item.XrayData = new byte[8000];
  3539. }
  3540. string strvaluename = "@data";
  3541. //编辑添加语句
  3542. StringBuilder strSqlAdd = new StringBuilder();
  3543. strSqlAdd.Append("insert into STDMinerals(Id,SPEC) values(" + item.StdID + "," + strvaluename + ");");
  3544. bool addResult = m_sc.ExecuteBlob(strSqlAdd.ToString(), strvaluename, (byte[])item.XrayData, ((byte[])item.XrayData).Length);
  3545. if (!addResult)
  3546. {
  3547. continue;
  3548. }
  3549. }
  3550. //修改状态
  3551. else if (infoState == (int)STDXrayInfoState.Modify)
  3552. {
  3553. //判断STDID在数据库中是否存在
  3554. bool selResult = SelSTDDBBySTDId(item.StdID);
  3555. if (selResult)
  3556. {
  3557. UpdateSTDDB(item.StdID, xrayByteData);
  3558. }
  3559. else
  3560. {
  3561. AddSTDDB(item.StdID, xrayByteData);
  3562. }
  3563. }
  3564. //删除状态 编辑批量删除语句
  3565. else if (infoState == (int)STDXrayInfoState.Delete)
  3566. {
  3567. //编辑删除语句
  3568. delArrayList.Add("delete from STDMinerals where id=" + item.StdID + ";");
  3569. }
  3570. }
  3571. //批量删除
  3572. if (delArrayList.Count>0)
  3573. {
  3574. bool delResult = m_sc.DelSTDInfo(delArrayList);
  3575. }
  3576. //}
  3577. }
  3578. }
  3579. /// <summary>
  3580. /// 添加STD信息至数据库
  3581. /// </summary>
  3582. protected bool AddSTDDB(string stdID,byte[] XrayData)
  3583. {
  3584. if (XrayData == null)
  3585. {
  3586. XrayData = new byte[8000];
  3587. }
  3588. string strvaluename = "@data";
  3589. StringBuilder sqlStrAdd = new StringBuilder();
  3590. sqlStrAdd.Append("insert into STDMinerals(Id,SPEC) values(" + stdID + "," + strvaluename + ");");
  3591. bool addResult = m_sc.ExecuteBlob(sqlStrAdd.ToString(), strvaluename, (byte[])XrayData, ((byte[])XrayData).Length);
  3592. return addResult;
  3593. }
  3594. /// <summary>
  3595. /// 修改STD信息至数据库
  3596. /// </summary>
  3597. protected bool UpdateSTDDB(string stdID, byte[] XrayData)
  3598. {
  3599. if (XrayData == null)
  3600. {
  3601. XrayData = new byte[8000];
  3602. }
  3603. string strValueName = "@data";
  3604. StringBuilder sqlStrUpdate = new StringBuilder();
  3605. sqlStrUpdate.Append("update STDMinerals set SPEC=" + strValueName + " where id=" + stdID + ";");
  3606. bool updateResult = m_sc.ExecuteBlob(sqlStrUpdate.ToString(), strValueName, (byte[])XrayData, ((byte[])XrayData).Length);
  3607. return updateResult;
  3608. }
  3609. /// <summary>
  3610. /// 查询是否存在标准编号
  3611. /// </summary>
  3612. /// <param name="stdID"></param>
  3613. protected bool SelSTDDBBySTDId(string stdID)
  3614. {
  3615. bool selResult = false;
  3616. //编辑查询语句
  3617. StringBuilder sqlStr = new StringBuilder();
  3618. sqlStr.Append("select * from STDMinerals where id=" + stdID + "");
  3619. DataTable dt = m_sc.GetDTFormSysSTDBySQLString(sqlStr.ToString());
  3620. if (dt != null)
  3621. {
  3622. if (dt.Rows.Count > 0)
  3623. {
  3624. //已存在状态
  3625. selResult = true;
  3626. }
  3627. }
  3628. return selResult;
  3629. }
  3630. /// <summary>
  3631. /// 根据选择树节点显示对应的Xray信息
  3632. /// </summary>
  3633. protected void SelSTDXray(TreeNode tn)
  3634. {
  3635. if (tn == null)
  3636. {
  3637. return;
  3638. }
  3639. if (m_STDXrayList != null)
  3640. {
  3641. if (m_STDXrayList.Count > 0)
  3642. {
  3643. bool isExists = false;
  3644. foreach (STDXray item in m_STDXrayList)
  3645. {
  3646. //修改XrayData信息
  3647. if (item.StdID == tn.ToolTipText.ToString())
  3648. {
  3649. string selColor = ParseRGB(tn.BackColor).ToString();
  3650. int colorValue = Convert.ToInt32(selColor);
  3651. //显示Xray信息
  3652. if (item.XrayData != null)
  3653. {
  3654. isExists = true;
  3655. ShowXrayAtlas(colorValue, item.XrayData);
  3656. }
  3657. break;
  3658. }
  3659. }
  3660. if (!isExists)
  3661. {
  3662. ShowXrayAtlas();
  3663. }
  3664. }
  3665. }
  3666. }
  3667. /// <summary>
  3668. /// 根据树节点修改对应的Xray信息
  3669. /// </summary>
  3670. /// <param name="tn"></param>
  3671. protected void UpdateSTDXray(TreeNode tn,byte[] xrayData)
  3672. {
  3673. if (tn == null)
  3674. {
  3675. return;
  3676. }
  3677. if (m_STDXrayList != null)
  3678. {
  3679. //if (m_STDXrayList.Count > 0)
  3680. //{
  3681. bool isExists = false;
  3682. foreach (STDXray item in m_STDXrayList)
  3683. {
  3684. //修改XrayData信息
  3685. if (item.StdID == tn.ToolTipText.ToString())
  3686. {
  3687. item.XrayData = xrayData;
  3688. item.InfoState = (int)STDXrayInfoState.Modify;
  3689. isExists = true;
  3690. break;
  3691. }
  3692. }
  3693. if (!isExists)
  3694. {
  3695. if (!tn.ToolTipText.ToString().Equals(""))
  3696. {
  3697. //添加STD XrayData信息
  3698. STDXray stdXray = new STDXray();
  3699. stdXray.StdID = tn.ToolTipText.ToString();
  3700. stdXray.XrayData = xrayData;
  3701. stdXray.InfoState = (int)STDXrayInfoState.Add;
  3702. m_STDXrayList.Add(stdXray);
  3703. }
  3704. }
  3705. //}
  3706. }
  3707. }
  3708. /// <summary>
  3709. /// 添加STDXray信息
  3710. /// </summary>
  3711. /// <param name="tn">所选树节点</param>
  3712. /// <param name="xrayData">Xray信息</param>
  3713. /// <returns></returns>
  3714. protected bool AddSTDXray(TreeNode tn, byte[] xrayData)
  3715. {
  3716. bool addResult = false;
  3717. if (tn == null)
  3718. {
  3719. return false;
  3720. }
  3721. if (m_STDXrayList != null)
  3722. {
  3723. if (m_STDXrayList.Count > 0)
  3724. {
  3725. if (!tn.ToolTipText.ToString().Equals(""))
  3726. {
  3727. //添加STD XrayData信息
  3728. STDXray stdXray = new STDXray();
  3729. stdXray.StdID = tn.ToolTipText.ToString();
  3730. stdXray.XrayData = xrayData;
  3731. stdXray.InfoState = (int)STDXrayInfoState.Add;
  3732. m_STDXrayList.Add(stdXray);
  3733. addResult = true;
  3734. }
  3735. }
  3736. }
  3737. return addResult;
  3738. }
  3739. /// <summary>
  3740. /// 删除STDXray信息
  3741. /// </summary>
  3742. /// <param name="tn">所选要删除的树节点</param>
  3743. /// <returns></returns>
  3744. protected bool DelSTDXray(TreeNode tn)
  3745. {
  3746. bool delResult = false;
  3747. if (tn == null)
  3748. {
  3749. return false;
  3750. }
  3751. if (m_STDXrayList != null)
  3752. {
  3753. if (m_STDXrayList.Count > 0)
  3754. {
  3755. if (!tn.ToolTipText.ToString().Equals(""))
  3756. {
  3757. foreach (STDXray item in m_STDXrayList)
  3758. {
  3759. //修改XrayData信息
  3760. if (item.StdID == tn.ToolTipText.ToString())
  3761. {
  3762. item.InfoState = (int)STDXrayInfoState.Delete;
  3763. delResult = true;
  3764. break;
  3765. }
  3766. }
  3767. }
  3768. }
  3769. }
  3770. return delResult;
  3771. }
  3772. #endregion
  3773. #region 控制BSE、化学式、元素本文框中不能输入下划线
  3774. /// <summary>
  3775. /// 控件不能输入下划线
  3776. /// </summary>
  3777. /// <param name="sender"></param>
  3778. /// <param name="e"></param>
  3779. private void textBox_KeyPress(object sender, KeyPressEventArgs e)
  3780. {
  3781. if ((e.KeyChar >= '0' && e.KeyChar <= '9') || (e.KeyChar >= 'A' && e.KeyChar <= 'Z') ||
  3782. (e.KeyChar >= 'a' && e.KeyChar <= 'z') || (e.KeyChar == 8) || !(e.KeyChar == '_'))
  3783. {
  3784. e.Handled = false;
  3785. }
  3786. else
  3787. {
  3788. e.Handled = true;
  3789. }
  3790. }
  3791. #endregion
  3792. private void button_1_Click(object sender, EventArgs e)
  3793. {
  3794. //textbox_STDEditor 中的光标
  3795. int index = textbox_STDEditor.SelectionStart;
  3796. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "1");
  3797. textbox_STDEditor.Focus();
  3798. textbox_STDEditor.Select(index + 1, 0);
  3799. textbox_STDEditor.ScrollToCaret();
  3800. }
  3801. private void button_2_Click(object sender, EventArgs e)
  3802. {
  3803. //textbox_STDEditor 中的光标
  3804. int index = textbox_STDEditor.SelectionStart;
  3805. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "2");
  3806. textbox_STDEditor.Focus();
  3807. textbox_STDEditor.Select(index + 1, 0);
  3808. textbox_STDEditor.ScrollToCaret();
  3809. }
  3810. private void button_3_Click(object sender, EventArgs e)
  3811. {
  3812. //textbox_STDEditor 中的光标
  3813. int index = textbox_STDEditor.SelectionStart;
  3814. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "3");
  3815. textbox_STDEditor.Focus();
  3816. textbox_STDEditor.Select(index + 1, 0);
  3817. textbox_STDEditor.ScrollToCaret();
  3818. }
  3819. private void button_4_Click(object sender, EventArgs e)
  3820. {
  3821. //textbox_STDEditor 中的光标
  3822. int index = textbox_STDEditor.SelectionStart;
  3823. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "4");
  3824. textbox_STDEditor.Focus();
  3825. textbox_STDEditor.Select(index + 1, 0);
  3826. textbox_STDEditor.ScrollToCaret();
  3827. }
  3828. private void button_5_Click(object sender, EventArgs e)
  3829. {
  3830. //textbox_STDEditor 中的光标
  3831. int index = textbox_STDEditor.SelectionStart;
  3832. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "5");
  3833. textbox_STDEditor.Focus();
  3834. textbox_STDEditor.Select(index + 1, 0);
  3835. textbox_STDEditor.ScrollToCaret();
  3836. }
  3837. private void button_6_Click(object sender, EventArgs e)
  3838. {
  3839. //textbox_STDEditor 中的光标
  3840. int index = textbox_STDEditor.SelectionStart;
  3841. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "6");
  3842. textbox_STDEditor.Focus();
  3843. textbox_STDEditor.Select(index + 1, 0);
  3844. textbox_STDEditor.ScrollToCaret();
  3845. }
  3846. private void button_7_Click(object sender, EventArgs e)
  3847. {
  3848. //textbox_STDEditor 中的光标
  3849. int index = textbox_STDEditor.SelectionStart;
  3850. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "7");
  3851. textbox_STDEditor.Focus();
  3852. textbox_STDEditor.Select(index + 1, 0);
  3853. textbox_STDEditor.ScrollToCaret();
  3854. }
  3855. private void button_8_Click(object sender, EventArgs e)
  3856. {
  3857. //textbox_STDEditor 中的光标
  3858. int index = textbox_STDEditor.SelectionStart;
  3859. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "8");
  3860. textbox_STDEditor.Focus();
  3861. textbox_STDEditor.Select(index + 1, 0);
  3862. textbox_STDEditor.ScrollToCaret();
  3863. }
  3864. private void button_9_Click(object sender, EventArgs e)
  3865. {
  3866. //textbox_STDEditor 中的光标
  3867. int index = textbox_STDEditor.SelectionStart;
  3868. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "9");
  3869. textbox_STDEditor.Focus();
  3870. textbox_STDEditor.Select(index + 1, 0);
  3871. textbox_STDEditor.ScrollToCaret();
  3872. }
  3873. private void button_0_Click(object sender, EventArgs e)
  3874. {
  3875. int index = textbox_STDEditor.SelectionStart;
  3876. textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "0");
  3877. textbox_STDEditor.Focus();
  3878. textbox_STDEditor.Select(index + 1, 0);
  3879. textbox_STDEditor.ScrollToCaret();
  3880. }
  3881. private void tabSTDStandrad_SelectedIndexChanged(object sender, EventArgs e)
  3882. {
  3883. if (tabSTDStandrad.SelectedIndex == 1)
  3884. {
  3885. tabControl_Rules.SelectedIndex = 0;
  3886. XmlTree_STDlist.Focus();
  3887. }
  3888. }
  3889. private void btnTest_Click(object sender, EventArgs e)
  3890. {
  3891. XrayContrastForm xrayContrastForm = new XrayContrastForm();
  3892. //xrayContrastForm.XmlTree_STDlist = XmlTree_STDlist.Nodes;
  3893. xrayContrastForm.ShowDialog();
  3894. }
  3895. private void XmlTree_STDlist_AfterSelect(object sender, TreeViewEventArgs e)
  3896. {
  3897. SetBlackAllNodes(XmlTree_STDlist);
  3898. this.textbox_STDEditor.Text = XmlTree_STDlist.SelectedNode.Tag.ToString();
  3899. btn_dbs.BackColor = XmlTree_STDlist.SelectedNode.BackColor;
  3900. string[] strOther = XmlTree_STDlist.SelectedNode.Name.Split('$');
  3901. string[] strOther2 = strOther[0].Split('_');
  3902. textBox_Hardness.Text = strOther2[0];
  3903. textBox_Density.Text = strOther2[1];
  3904. textBox_Electrical_conductivity.Text = strOther2[2];
  3905. dataGridView_KeyElements.Rows.Clear();
  3906. dataGridView_KeyElements.Columns.Clear();
  3907. string[] KeyElement = strOther[1].Split(',');
  3908. for (int i = 0; i < KeyElement.Length; i++)
  3909. {
  3910. if (KeyElement[0] != "")
  3911. {
  3912. DataGridViewButtonColumn dataGridViewButtonColumn = new DataGridViewButtonColumn();
  3913. dataGridViewButtonColumn.Name = dataGridView_SubElements.Columns.Count.ToString();
  3914. dataGridView_KeyElements.Columns.Add(dataGridViewButtonColumn);
  3915. if (dataGridView_KeyElements.Rows.Count == 0)
  3916. {
  3917. DataGridViewRow row = new DataGridViewRow();
  3918. dataGridView_KeyElements.Rows.Add(row);
  3919. }
  3920. dataGridView_KeyElements.Rows[0].Cells[i].Value = KeyElement[i];
  3921. }
  3922. }
  3923. dataGridView_SubElements.Rows.Clear();
  3924. dataGridView_SubElements.Columns.Clear();
  3925. string[] SubElement = strOther[2].Split(',');
  3926. for (int i = 0; i < SubElement.Length; i++)
  3927. {
  3928. if (SubElement[i] != "")
  3929. {
  3930. DataGridViewButtonColumn dataGridViewButtonColumn = new DataGridViewButtonColumn();
  3931. dataGridViewButtonColumn.Name = dataGridView_SubElements.Columns.Count.ToString();
  3932. dataGridView_SubElements.Columns.Add(dataGridViewButtonColumn);
  3933. if (dataGridView_SubElements.Rows.Count == 0)
  3934. {
  3935. DataGridViewRow row = new DataGridViewRow();
  3936. dataGridView_SubElements.Rows.Add(row);
  3937. }
  3938. dataGridView_SubElements.Rows[0].Cells[i].Value = SubElement[i];
  3939. }
  3940. }
  3941. if (button_UpOrder.Enabled == false)
  3942. {
  3943. button_UpOrder.Enabled = true;
  3944. }
  3945. if (button_DownOrder.Enabled == false)
  3946. {
  3947. button_DownOrder.Enabled = true;
  3948. }
  3949. if (XmlTree_STDlist.SelectedNode.PrevNode == null)
  3950. {
  3951. button_UpOrder.Enabled = false;
  3952. }
  3953. else if (XmlTree_STDlist.SelectedNode.NextNode == null)
  3954. {
  3955. button_DownOrder.Enabled = false;
  3956. }
  3957. dataGridView_KeyElements.ClearSelection();
  3958. dataGridView_SubElements.ClearSelection();
  3959. ShowEditContent(XmlTree_STDlist.SelectedNode);
  3960. SelSTDXray(XmlTree_STDlist.SelectedNode);
  3961. }
  3962. protected void ShowEditContent(TreeNode tn)
  3963. {
  3964. if (m_STDXrayList != null)
  3965. {
  3966. for (int i = 0; i < m_STDXrayList.Count; i++)
  3967. {
  3968. if (m_STDXrayList[i].StdID == tn.ToolTipText.ToString())
  3969. {
  3970. //获取修改行的信息
  3971. xrayByteData = (byte[])m_STDXrayList[i].XrayData;
  3972. }
  3973. }
  3974. }
  3975. }
  3976. }
  3977. }