MainFrm.cpp 118 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607
  1. // MainFrm.cpp : CMainFrame 类的实现
  2. //
  3. #include "stdafx.h"
  4. #include "IDE.h"
  5. #include "Dlg_Pwd.h"
  6. #include "MainFrm.h"
  7. #include ".\mainfrm.h"
  8. #include <afxwin.h>
  9. #include <afxext.h>
  10. #include <math.h>
  11. #include <io.h>
  12. #include <time.h>
  13. #include <afxdao.h>
  14. //#include <afxtempl.h>
  15. #include "Shlwapi.h"
  16. #include "DrawObj.h"
  17. #include "Graph.h"
  18. #include "ViewNameDlg.h"
  19. #include "Login.h"
  20. #include "IDEView.h"
  21. #include "SystemParaSetDlg.h"
  22. #include "public.h"
  23. #include "SysLib.h"
  24. #include "analogdlg.h"
  25. #include "ffsco.h"
  26. #include "Wizard.h"
  27. #include "Serial.h"
  28. #include "Network.h"
  29. #include "DlgUserManager.h"
  30. #include "Dlg_GroupManage.h"
  31. #include "ScriptSetDlg.h"
  32. #include "DlgEditPwd.h"
  33. #include "DlgQueryWarningRec.h"
  34. #include "DlgSystemLog.h"
  35. #include "DlgNoticeRec.h"
  36. #include "Dlg_ActionWithAlarm.h"
  37. #include "Dlg_EditView.h"
  38. #include "FileAndFolderClass.h"
  39. using namespace helper_coffs;
  40. #pragma warning ( disable: 4800 )
  41. #ifdef _DEBUG
  42. #define new DEBUG_NEW
  43. #endif
  44. #if USE_TRAYICON
  45. #define WM_MY_TRAY_NOTIFICATION WM_USER + 1
  46. const UINT WM_TASKBARCREATED =
  47. ::RegisterWindowMessage(_T("TaskbarCreated"));
  48. #endif
  49. // CMainFrame
  50. IMPLEMENT_DYNAMIC(CMainFrame, CMDIAutoHideFrame)
  51. BEGIN_MESSAGE_MAP(CMainFrame, CMDIAutoHideFrame)
  52. ON_WM_CREATE()
  53. ON_COMMAND(IP_SUPER_END, OnSuperEnd)
  54. ON_COMMAND(ID_TRAY_OPEN, OnTrayOpen)
  55. #if USE_TRAYICON
  56. ON_MESSAGE(WM_MY_TRAY_NOTIFICATION, OnTrayNotification)
  57. ON_REGISTERED_MESSAGE(WM_TASKBARCREATED, OnTaskBarCreated)
  58. #endif
  59. ON_WM_CLOSE()
  60. ON_COMMAND(ID_ADDDEVOCE, OnAdddevoce)
  61. ON_UPDATE_COMMAND_UI(ID_ADDDEVOCE, OnUpdateAdddevoce)
  62. ON_COMMAND(IDM_MENU_ZUTAIADD, OnZuTaiAdd)
  63. ON_UPDATE_COMMAND_UI(IDM_MENU_ZUTAIADD, OnUpdateZuTaiAdd)
  64. ON_COMMAND(ID_DELETEPORT, OnDeleteport)
  65. ON_UPDATE_COMMAND_UI(ID_DELETEPORT, OnUpdateDeleteport)
  66. ON_COMMAND(ID_ADD_PORT, OnAddPort)
  67. ON_UPDATE_COMMAND_UI(ID_ADD_PORT, OnUpdateAddPort)
  68. ON_COMMAND(ID_ADD_SCRIPT, OnAddScript)
  69. ON_UPDATE_COMMAND_UI(ID_ADD_SCRIPT, OnUpdateAddScript)
  70. ON_COMMAND(ID_ADDVIEW, OnAddview)
  71. ON_UPDATE_COMMAND_UI(ID_ADDVIEW, OnUpdateAddview)
  72. ON_COMMAND(ID_ADDVIEW2, OnAddview2)
  73. ON_UPDATE_COMMAND_UI(ID_ADDVIEW2, OnUpdateAddview2)
  74. ON_COMMAND(ID_ONLYADD_SORT, OnEditSort)
  75. ON_UPDATE_COMMAND_UI(ID_ONLYADD_SORT, OnUpdateEditSort)
  76. ON_COMMAND(ID_DELETEDEVICE, OnDeletedevice)
  77. ON_UPDATE_COMMAND_UI(ID_DELETEDEVICE, OnUpdateDeletedevice)
  78. ON_COMMAND(ID_DELETEVIEW, OnDeleteview)
  79. ON_UPDATE_COMMAND_UI(ID_DELETEVIEW, OnUpdateDeleteview)
  80. ON_COMMAND(ID_MODIFYVIEWNAME, OnModifyViewName)
  81. ON_UPDATE_COMMAND_UI(ID_MODIFYVIEWNAME, OnUpdateModifyViewName)
  82. ON_COMMAND(ID_DELETESCRIPT, OnDeletescript)
  83. ON_UPDATE_COMMAND_UI(ID_DELETESCRIPT, OnUpdateDeletescript)
  84. ON_COMMAND(ID_SETSCRIPT, OnSetscript)
  85. ON_UPDATE_COMMAND_UI(ID_SETSCRIPT, OnUpdateSetscript)
  86. ON_COMMAND(ID_EDITSCRIPT, OnEditscript)
  87. ON_UPDATE_COMMAND_UI(ID_EDITSCRIPT, OnUpdateEditscript)
  88. ON_COMMAND(ID_USERS, OnUsers)
  89. ON_UPDATE_COMMAND_UI(ID_USERS, OnUpdateUsers)
  90. ON_COMMAND(ID_EDITPWD, OnEditPwdTool)
  91. ON_UPDATE_COMMAND_UI(ID_EDITPWD, OnUpdateEditPwd)
  92. ON_COMMAND(ID_SYSPARE, OnSysPara)
  93. ON_UPDATE_COMMAND_UI(ID_SYSPARE, OnUpdateSysPare)
  94. ON_COMMAND(ID_EVENTMANAGE, OnEventmanage)
  95. ON_COMMAND(ID_EVENT, OnEvent)
  96. ON_COMMAND(ID_SUMMARY_LOG, OnSummaryLog)
  97. ON_UPDATE_COMMAND_UI(ID_EVENT, OnUpdateEvent)
  98. ON_UPDATE_COMMAND_UI(ID_SUMMARY_LOG, OnUpdateSummaryLog)
  99. ON_COMMAND(ID_CONTROLDIALOG, OnControldialog)
  100. ON_WM_DESTROY()
  101. ON_WM_TIMER()
  102. ON_COMMAND(ID_SYSTEMLOG, OnSystemLog)
  103. ON_UPDATE_COMMAND_UI(ID_SYSTEMLOG, OnUpdateSystemLog)
  104. ON_COMMAND(ID_NOTICEREC, OnNoticeRec)
  105. ON_UPDATE_COMMAND_UI(ID_NOTICEREC, OnUpdateNoticeRec)
  106. ON_COMMAND(ID_USER_MANAGER, OnUserManager)
  107. ON_COMMAND(ID_EDIT_PWD, OnEditPwd)
  108. ON_COMMAND(ID_GROUP_MANAGER, OnGroupManager)
  109. ON_COMMAND(ID_SINGLE_ANALOG, OnSingleAnalog)
  110. ON_UPDATE_COMMAND_UI(ID_SINGLE_ANALOG, OnUpdateSingleAnalog)
  111. ON_UPDATE_COMMAND_UI(ID_FILE_PRINT, OnUpdatePrint)
  112. END_MESSAGE_MAP()
  113. static UINT indicators[] =
  114. {
  115. ID_SEPARATOR, // 状态行指示器
  116. ID_INDICATOR_CAPS,
  117. ID_INDICATOR_NUM,
  118. ID_INDICATOR_SCRL,
  119. };
  120. HANDLE m_hFreshVarThread;
  121. HANDLE m_hReConnectSrvThread;
  122. static DWORD WINAPI FreshVarThread( void *pData );
  123. static DWORD WINAPI FreshVarCurPicThread( void *pData );
  124. CRITICAL_SECTION g_CSLimit;
  125. // CMainFrame 构造/析构
  126. CMainFrame::CMainFrame():m_trayIcon(IDR_TRAYICON)
  127. {
  128. // TODO: 在此添加成员初始化代码
  129. m_bShowTrayNotifications = TRUE;//zxn
  130. m_bShutdown = FALSE;//zxn
  131. #if USE_NEWTOP
  132. m_pToolBar = NULL;
  133. #else
  134. m_wndOfTop = NULL;
  135. #endif
  136. g_bRun=FALSE;
  137. g_nElementNo=0; //选择
  138. g_bEdit=TRUE;
  139. m_bHideLeft=FALSE;
  140. m_mousePoint=CPoint(0,0);
  141. // View个数
  142. m_nViewCount = 0;
  143. m_nPortNum = 0;
  144. m_nScripts = 0;
  145. int i, j;
  146. //mdi子窗体
  147. for( i = 0; i < MAX_VIEW_NUM; i++ )
  148. {
  149. m_pViewIDE[i] = NULL;
  150. }
  151. //串口设备
  152. for( i = 0; i < MAX_SERIAL_NUM; i++ )
  153. {
  154. for( j = 0; j < MAX_DEVICE_NUM; j++ )
  155. {
  156. m_hSerialDev[i][j] = NULL;
  157. }
  158. }
  159. //串口组
  160. for( i = 0; i < MAX_SERIAL_NUM; i++ )
  161. {
  162. m_hSerialGroup[i] = NULL;
  163. }
  164. //以太网设备
  165. for( i = 0; i < MAX_NETWORK_NUM; i++ )
  166. {
  167. m_hNetworkDev[i] = NULL;
  168. }
  169. //脚本
  170. for( i = 0; i < MAX_SCRIPT_NUM; i++ )
  171. {
  172. m_hScriptGroup[i] = NULL;
  173. }
  174. m_bEvent = true;
  175. m_bPrint = true;
  176. m_bUsers = true;
  177. m_bSysPare = true;
  178. m_bAnalog = true;
  179. m_bDeviceLog = true;
  180. m_bSystemLog = true;
  181. m_bNoticeRec = true;
  182. m_bEditPwd = true;
  183. m_hCurrent = NULL;
  184. for( int i=0;i<VIEW_MAX_NUM;i++ )
  185. {
  186. m_PIC_VAR[i].sPicPath = "";
  187. for( int j=0;j<1000;j++ )
  188. {
  189. m_PIC_VAR[i].sCaption[j] = "";
  190. m_PIC_VAR[i].nType[i] = 0;
  191. }
  192. }
  193. g_nRunEditVarTick = 0;//在运行状态编辑变量的TICK
  194. g_bRunEditVar = false;//是否在运行状态编辑变量
  195. m_dlgEvent = NULL;
  196. m_dlgControl = NULL;
  197. m_pDlgZuTaiAdd = NULL;
  198. }
  199. CMainFrame::~CMainFrame()
  200. {
  201. }
  202. #if USE_TRAYICON
  203. BOOL CMainFrame::InstallIcons()
  204. {
  205. return Shell_NotifyIcon(NIM_ADD, &m_trayIcon.m_nid);
  206. }
  207. LRESULT CMainFrame::OnTaskBarCreated(WPARAM wp, LPARAM lp)
  208. {
  209. VERIFY(InstallIcons());
  210. return 0;
  211. }
  212. //////////////////
  213. // Handle notification from tray icon: display a message.
  214. //
  215. LRESULT CMainFrame::OnTrayNotification(WPARAM uID, LPARAM lEvent)
  216. {
  217. if (m_bShowTrayNotifications) {
  218. static LPCSTR MouseMessages[] = { "WM_MOUSEMOVE",
  219. "WM_LBUTTONDOWN", "WM_LBUTTONUP", "WM_LBUTTONDBLCLK",
  220. "WM_RBUTTONDOWN", "WM_RBUTTONUP", "WM_RBUTTONDBLCLK",
  221. "WM_MBUTTONDOWN", "WM_MBUTTONUP", "WM_MBUTTONDBLCLK" };
  222. }
  223. // let tray icon do default stuff
  224. return m_trayIcon.OnTrayNotification(uID, lEvent);
  225. }
  226. #endif
  227. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  228. {
  229. if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
  230. return -1;
  231. if (!m_wndTree.Create(WS_CHILD|WS_VISIBLE|
  232. TVS_HASLINES|TVS_HASBUTTONS|TVS_LINESATROOT,
  233. CRect(0, 0, 0, 0), this, IDD_TREE_LEFT))
  234. {
  235. TRACE0("Failed to create instant bar child\n");
  236. return -1;
  237. }
  238. if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
  239. | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
  240. !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
  241. {
  242. TRACE0(g_strTrace2);
  243. return -1; // 未能创建
  244. }
  245. if (!m_wndDrawToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
  246. | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
  247. !m_wndDrawToolBar.LoadToolBar(IDR_DRAWTOOLS))
  248. {
  249. TRACE0("Failed to create toolbar\n");
  250. return -1; // fail to create
  251. }
  252. if (!m_wndDrawAlignBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
  253. | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
  254. !m_wndDrawAlignBar.LoadToolBar(IDR_ALIGN))
  255. {
  256. TRACE0("Failed to create toolbar\n");
  257. return -1; // fail to create
  258. }
  259. //if (!m_wndRunToolBar.Create(this) ||
  260. // !m_wndRunToolBar.LoadToolBar(IDR_RUNTOOLBAR))
  261. //{
  262. // TRACE0("Failed to create toolbar\n");
  263. // return -1; // fail to create
  264. //}
  265. if (!m_wndStatusBar.Create(this) ||
  266. !m_wndStatusBar.SetIndicators(indicators,
  267. sizeof(indicators)/sizeof(UINT)))
  268. {
  269. TRACE0("未能创建状态栏\n");
  270. return -1; // 未能创建
  271. }
  272. // m_wndRunToolBar.SetBitmap( IDB_LG, COOBmpToolBar::LargeHot, RGB( 33, 231, 222 ) );
  273. // m_wndRunToolBar.SetBitmap( IDB_LG, COOBmpToolBar::LargeStandard, RGB( 33, 231, 222 ) );
  274. // m_wndRunToolBar.InitImageList();
  275. //m_wndRunToolBar.SetTextMode(TRUE);
  276. // TODO: 如果不需要工具栏可停靠,则删除这三行
  277. m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
  278. m_wndDrawToolBar.EnableDocking(CBRS_ALIGN_ANY);
  279. m_wndDrawAlignBar.EnableDocking(CBRS_ALIGN_ANY);
  280. EnableDocking(CBRS_ALIGN_ANY);
  281. DockControlBar(&m_wndToolBar);
  282. m_wndStatusBar.SetPaneInfo(1, ID_INDICATOR_LOG, SBPS_NOBORDERS,160);
  283. m_wndStatusBar.SetPaneInfo(3, ID_INDICATOR_LOG, SBPS_NOBORDERS,80);
  284. RecalcLayout();
  285. CRect rect;
  286. m_wndToolBar.GetWindowRect(rect);
  287. rect.OffsetRect(1, 0); //偏移一个位置
  288. DockControlBar(&m_wndDrawAlignBar, CBRS_ALIGN_ANY, rect);
  289. DockControlBar(&m_wndDrawToolBar);
  290. //m_wndRunToolBar.EnableDocking(FALSE);
  291. //m_wndRunToolBar.ShowWindow(SW_HIDE);
  292. //上面工具栏
  293. if( g_bStartRun && g_nToolbarRun )
  294. {
  295. //if (!m_wndDockPageBar3.Create(_T("DockPageBar3"), this, CSize(230,105),TRUE,123))
  296. // CSize(),是用来设置高和宽的.
  297. if (!m_htopDockBar.Create(_T("topDockbar"), this, CSize(1920,78),TRUE,123))
  298. {
  299. TRACE0("创建顶部工具栏失败.\n");
  300. return -1;
  301. }
  302. m_htopDockBar.SetBarStyle(m_htopDockBar.GetBarStyle() | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC );
  303. m_htopDockBar.EnableDocking (CBRS_ALIGN_ANY);
  304. m_htopDockBar.m_bDrawTitleBar = false;
  305. DockControlBar(&m_htopDockBar, AFX_IDW_DOCKBAR_TOP);
  306. }
  307. //左边树形
  308. if (!m_hleftDockBar.Create(_T("leftDockbar"), this, CSize(180,260),TRUE,123))
  309. {
  310. TRACE0("创建左侧边栏失败.\n");
  311. return -1;
  312. }
  313. m_hleftDockBar.SetBarStyle(m_hleftDockBar.GetBarStyle() |
  314. CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC );
  315. m_hleftDockBar.EnableDocking (CBRS_ALIGN_ANY);
  316. DockControlBar(&m_hleftDockBar, AFX_IDW_DOCKBAR_LEFT);
  317. CString strTitle;
  318. strTitle.LoadString(IDS_TREE_TITLE);
  319. m_hleftDockBar.AddPage(&m_wndTree, strTitle, IDR_MAINFRAME);
  320. //下面通知列表
  321. if (!m_hbottomDockBar.Create(_T("bottomDockbar"), this, CSize(230,120),TRUE,123))
  322. {
  323. TRACE0("创建底部通知栏失败.\n");
  324. return -1;
  325. }
  326. m_hbottomDockBar.SetBarStyle(m_hbottomDockBar.GetBarStyle() |
  327. CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC );
  328. m_hbottomDockBar.EnableDocking (CBRS_ALIGN_BOTTOM);
  329. DockControlBar(&m_hbottomDockBar, AFX_IDW_DOCKBAR_BOTTOM);
  330. CDrawObj::RegisterClass(g_strTline,RUNTIME_CLASS(CDrawTLine));
  331. CDrawObj::RegisterClass(g_strText,RUNTIME_CLASS(CDrawText));
  332. CDrawObj::RegisterClass(g_strRect,RUNTIME_CLASS(CDrawRect));
  333. CDrawObj::RegisterClass(g_strOval,RUNTIME_CLASS(CDrawOval));
  334. CDrawObj::RegisterClass(g_strButton,RUNTIME_CLASS(CDrawButton));
  335. CDrawObj::RegisterClass(g_strData,RUNTIME_CLASS(CDrawDatabox));
  336. CDrawObj::RegisterClass(g_strLed,RUNTIME_CLASS(CDraw3dCircle));
  337. CDrawObj::RegisterClass(g_strBar,RUNTIME_CLASS(CDrawBar));
  338. CDrawObj::RegisterClass(g_strCurve,RUNTIME_CLASS(CDrawCurve));
  339. CDrawObj::RegisterClass(g_strLine,RUNTIME_CLASS(CDrawLine));
  340. CDrawObj::RegisterClass(g_strBreaker,RUNTIME_CLASS(CDrawBreaker));
  341. CDrawObj::RegisterClass(g_strSwitch,RUNTIME_CLASS(CDrawSwitch));
  342. CDrawObj::RegisterClass(g_strGrid,RUNTIME_CLASS(CDrawGrid));
  343. CDrawObj::RegisterClass(g_strBitmap,RUNTIME_CLASS(CDrawBitmap));
  344. //CDrawObj::RegisterClass(g_strGif, RUNTIME_CLASS(CDrawGif));
  345. CDrawObj::RegisterClass(g_strTransfer,RUNTIME_CLASS(CDrawTransfer));
  346. CDrawObj::RegisterClass(g_strArc,RUNTIME_CLASS(CDrawArc));
  347. CDrawObj::RegisterClass(g_strArrow,RUNTIME_CLASS(CDrawArrow));
  348. CDrawObj::RegisterClass(g_strPoly,RUNTIME_CLASS(CDrawPoly));
  349. CDrawObj::RegisterClass(g_strMLine,RUNTIME_CLASS(CDrawMLine));
  350. CDrawObj::RegisterClass(g_strPipe,RUNTIME_CLASS(CDrawPipe));
  351. CDrawObj::RegisterClass(g_strZhePipe,RUNTIME_CLASS(CDrawZhePipe));
  352. CDrawObj::RegisterClass(g_strYPipe,RUNTIME_CLASS(CDrawYPipe));
  353. CDrawObj::RegisterClass(g_strWatch,RUNTIME_CLASS(CDrawWatch));
  354. CDrawObj::RegisterClass(g_strSingleBar,RUNTIME_CLASS(CDrawSingleBar));
  355. CDrawObj::RegisterClass(g_strRoundRect,RUNTIME_CLASS(CDrawRoundRect));
  356. CDrawObj::RegisterClass(g_strPie,RUNTIME_CLASS(CDrawPie));
  357. CDrawObj::RegisterClass(g_strFan,RUNTIME_CLASS(CDrawFan));
  358. CDrawObj::RegisterClass(g_strHisCurve,RUNTIME_CLASS(CDrawHisCurve));
  359. CDrawObj::RegisterClass(g_strTable,RUNTIME_CLASS(CDrawTable));
  360. CDrawObj::RegisterClass(g_strComposite,RUNTIME_CLASS(CDrawComposite));
  361. CDrawObj::RegisterClass(g_strOCX,RUNTIME_CLASS(CDrawOCX));
  362. //CDrawObj::RegisterClass(g_strGIF,RUNTIME_CLASS(CDrawGif));
  363. CDrawObj::RegisterClass(g_strFlash,RUNTIME_CLASS(CDrawFlash));
  364. pDevicesManager = new CDevicesManager;
  365. pVariantsManager = new CVariantsManager;
  366. pDevicesManager->SetDBType(g_strDBType);
  367. pVariantsManager->SetDBType(g_strDBType);
  368. pVariantsManager->m_strLowerLimit = CString(g_strLowerLimit)+CString(g_strAlarm);
  369. pVariantsManager->m_strUpperLimit = CString(g_strUpperLimit)+CString(g_strAlarm);
  370. pVariantsManager->m_strCurrValue = CString(g_strCurrValue);
  371. pVariantsManager->m_strReturnNormal = CString(g_strReturnNormal2);
  372. pEventServer = new CEventServer;
  373. pEventServer->m_bValid = true;
  374. pEventServer->Validate( g_bEventAlarm );
  375. // 一定要先load设备管理,否则变量无法关联到设备
  376. if( g_nIsDemo == 1 )
  377. {
  378. pDevicesManager->Load(g_strDirectory);
  379. pVariantsManager->Load(g_strDirectory);
  380. }
  381. else
  382. {
  383. pDevicesManager->GetDevInfo();//pDevicesManager->Load(g_strDirectory);//
  384. pVariantsManager->GetVarInfo();//pVariantsManager->Load(g_strDirectory);
  385. pVariantsManager->ReadAreaDericeUid(g_strDirectory);
  386. }
  387. LoadRunPara();
  388. ///////////////////////////////////////////////////////////////////////
  389. //MakeFolderExist( "D:\\isP-Other\\StoueULog\\" );
  390. //////////////////////////////////////////////////////////////
  391. if( g_nIsDemo == 0 )
  392. {
  393. bool bIsBoxAppear = false;
  394. for( int iPortIndex=0;iPortIndex<2;iPortIndex++ )
  395. {
  396. CString sPortTemp;
  397. sPortTemp.Format("%d",atoi(g_strServerPort)+iPortIndex );
  398. if( !pDevicesManager->Connection(g_strServerIP,sPortTemp) )
  399. {
  400. LOG4C((LOG_NOTICE, "Socket Port %s 连接失败(%d)",sPortTemp,GetLastError()));
  401. if( !bIsBoxAppear && g_iAutoRunSystem==0 )
  402. MessageBox(g_strConnectionFailed, g_strTip, MB_ICONINFORMATION);
  403. bIsBoxAppear = true;
  404. pDevicesManager->SetSocketStatus(FALSE,sPortTemp);
  405. //break;
  406. }
  407. else
  408. {
  409. pDevicesManager->SetSocketStatus(TRUE,sPortTemp);
  410. pVariantsManager->SetSysComunicationVar( 0.0 );
  411. if( TRUE == pDevicesManager->GetSocketStatus( sPortTemp ) )
  412. {
  413. LOG4C((LOG_NOTICE, "Socket Port %s 连接成功(%d)",sPortTemp,GetLastError()));
  414. }
  415. if( iPortIndex==0 )
  416. pDevicesManager->GetServerVer( sPortTemp );
  417. }
  418. }
  419. }
  420. CRect rect1;
  421. GetWindowRect(&rect1);
  422. ScreenToClient(&rect1);
  423. pVariantsManager->m_bAnalogAlarm = g_bYcEvent;
  424. if( g_nAlarmModeIsDlg && g_bStartRun )
  425. {
  426. int screenx=GetSystemMetrics(SM_CXSCREEN);
  427. int screeny=GetSystemMetrics(SM_CYSCREEN);
  428. //系统任务栏的高度
  429. HWND hWnd = ::FindWindow("Shell_TrayWnd", NULL);
  430. RECT rc;
  431. ::GetWindowRect(hWnd, &rc);
  432. int nHeight = rc.bottom-rc.top;
  433. m_dlgEvent = new CRealEventDlg();
  434. m_dlgEvent->Create(IDD_REALEVENT, this);
  435. //m_dlgEvent->ShowWindow(SW_HIDE);
  436. CRect rct;
  437. m_dlgEvent->GetWindowRect(&rct);
  438. m_dlgEvent->SetWindowPos(&wndTop, (screenx-rct.Width())/2, screeny-rct.Height()-nHeight, rct.Width(), rct.Height(), SWP_NOZORDER);
  439. m_dlgControl = new CDlgBmp();
  440. m_dlgControl->Create(IDD_DIALOGCONTROL, this);
  441. m_dlgControl->ShowWindow(SW_HIDE);
  442. CRect rct1;
  443. m_dlgControl->GetWindowRect(&rct1);
  444. m_dlgControl->SetWindowPos(&wndTop, screenx-rct1.Width(), screeny-rct1.Height(), rct1.Width(), rct1.Height(), SWP_NOZORDER);
  445. m_hbottomDockBar.AddPage(m_dlgEvent, g_strNoticeList, IDI_WARING);
  446. }
  447. if( !g_bStartRun )
  448. {
  449. m_pDlgZuTaiAdd = new CDlg_ZuTaiAdd();
  450. m_pDlgZuTaiAdd->Create(IDD_DLG_ZUTAI_ADD, this);
  451. m_pDlgZuTaiAdd->ShowWindow(SW_HIDE);
  452. int screenx=GetSystemMetrics(SM_CXSCREEN);
  453. int screeny=GetSystemMetrics(SM_CYSCREEN);
  454. //系统任务栏的高度
  455. HWND hWnd = ::FindWindow("Shell_TrayWnd", NULL);
  456. RECT rc;
  457. ::GetWindowRect(hWnd, &rc);
  458. int nHeight = rc.bottom-rc.top;
  459. CRect rct;
  460. m_pDlgZuTaiAdd->GetWindowRect(&rct);
  461. m_pDlgZuTaiAdd->SetWindowPos(&wndTop, (screenx-rct.Width())/2, (screeny-rct.Height())/2, rct.Width(), rct.Height(), SWP_NOZORDER);
  462. }
  463. // 初始化左边树形
  464. InitTreeInfo();
  465. int W=0,H=0;
  466. if (g_bStartRun)
  467. {
  468. if( g_nIsDemo == 0 )
  469. {
  470. // 加载脚本信息
  471. //LoadScriptFromFiles();
  472. }
  473. OnRun();
  474. }
  475. else
  476. {
  477. //LONG style=::GetWindowLong(m_hWnd,GWL_STYLE);
  478. //style&=~WS_CAPTION;
  479. //style&=~WS_BORDER;
  480. //::SetWindowLong(m_hWnd,GWL_STYLE,style);
  481. int screenx=GetSystemMetrics(SM_CXSCREEN);
  482. int screeny=GetSystemMetrics(SM_CYSCREEN);
  483. //系统任务栏的高度
  484. HWND hWnd = ::FindWindow("Shell_TrayWnd", NULL);
  485. RECT rc;
  486. ::GetWindowRect(hWnd, &rc);
  487. int nHeight = rc.bottom -rc.top;
  488. if( !g_bFullScreen )
  489. {
  490. W = screenx;
  491. H = screeny-nHeight;
  492. //SetWindowPos(&wndTopMost,0,0,screenx,screeny-nHeight,SWP_NOZORDER);
  493. }
  494. else
  495. {
  496. W = screenx;
  497. H = screeny;
  498. //SetWindowPos(NULL,0,0,screenx,screeny,SWP_NOZORDER);// 全屏
  499. }
  500. }
  501. #if USE_TRAYICON
  502. m_trayIcon.SetNotificationWnd(this, WM_MY_TRAY_NOTIFICATION);
  503. m_trayIcon.SetIcon(IDR_MAINFRAME);
  504. #endif
  505. // Install the tab view here
  506. VERIFY(m_MDIClient.SubclassMDIClient(this, &m_wndViewManager));
  507. if( g_nToolbarTop )
  508. {
  509. m_wndViewManager.ShowWindow(SW_SHOW);
  510. }
  511. else
  512. {
  513. m_wndViewManager.ShowWindow(SW_HIDE);
  514. }
  515. if( g_strStartPic.Compare("") )
  516. {
  517. char picDir[_MAX_PATH] = {0};
  518. strcpy(picDir, g_strDirectory);
  519. strcat(picDir, "\\");
  520. strcat(picDir, _PICTUREDIR);
  521. strcat(picDir, g_strStartPic);
  522. strcat(picDir, ".view");
  523. AddIDEView( g_strStartPic, CString(picDir) );
  524. }
  525. if( g_nIsPoll == 1 )
  526. {
  527. SetTimer(1, 1000, NULL);
  528. }
  529. if( g_bStartRun )
  530. {
  531. ShowCaptionMenu(FALSE);
  532. }
  533. if( -1==PMS_VerifyUserPermit( g_nUserID,PMS_R_ALARM_SEARCH,"" ) )
  534. {
  535. m_bEvent = false;
  536. }
  537. if( -1==PMS_VerifyUserPermit( g_nUserID,PMS_R_PRINT,"" ) )
  538. {
  539. m_bPrint = false;
  540. }
  541. if( -1==PMS_VerifyUserPermit( g_nUserID,PMS_R_USER_MANAGE,"" ) )
  542. {
  543. m_bUsers = false;
  544. }
  545. if( -1==PMS_VerifyUserPermit( g_nUserID,PMS_R_RUNSTATUS,"" ) )
  546. {
  547. m_bSysPare = false;
  548. }
  549. if( -1==PMS_VerifyUserPermit( g_nUserID,PMS_R_DICT,"" ) )
  550. {
  551. m_bAnalog = false;
  552. }
  553. if( -1==PMS_VerifyUserPermit( g_nUserID,PMS_R_DEVICELOG,"" ) )
  554. {
  555. m_bDeviceLog = false;
  556. }
  557. if( -1==PMS_VerifyUserPermit( g_nUserID,PMS_R_SYSTEMLOG,"" ) )
  558. {
  559. m_bSystemLog = false;
  560. }
  561. if( -1==PMS_VerifyUserPermit( g_nUserID,PMS_R_NITICEREC,"" ) )
  562. {
  563. m_bNoticeRec = false;
  564. }
  565. if( -1==PMS_VerifyUserPermit( g_nUserID,PMS_R_EDITPWD,"" ) )
  566. {
  567. m_bEditPwd = false;
  568. }
  569. //展开树
  570. //m_wndTree.Expand(m_wndTree.GetRootItem(),TVE_EXPAND);
  571. //HTREEITEM handleTreeItem = m_wndTree.GetRootItem();
  572. //while(handleTreeItem)
  573. //{
  574. // handleTreeItem = m_wndTree.GetChildItem(handleTreeItem);
  575. // m_wndTree.Expand(handleTreeItem, TVE_EXPAND);
  576. //}
  577. MyExpandTree( m_wndTree.GetRootItem() );
  578. m_wndStatusBar.SetPaneText(2, "ver");
  579. m_wndStatusBar.SetPaneText(3, g_strVersion);
  580. if( g_bRun )
  581. SetTimer(2, 1000*15*1, NULL);//狗信息定时器
  582. //SetTimer(3, 1000*60*2, NULL);//判断变量在这个时间段时否报警
  583. if( !g_nToolbarLeft && g_bStartRun )
  584. m_hleftDockBar.ShowWindow( SW_HIDE );
  585. //m_wndDockPageBar1.OnStudClick();
  586. //通知列表
  587. if( g_nAlarmModeIsDlg && g_bRun )
  588. {
  589. m_hbottomDockBar.ShowWindow(SW_SHOW);
  590. CSize sz;
  591. sz = m_hbottomDockBar.GetHorSize();
  592. m_dlgEvent->SetPos( sz.cx,sz.cy );
  593. m_hbottomDockBar.OnStudClick();
  594. }
  595. else
  596. {
  597. m_hbottomDockBar.ShowWindow(SW_HIDE);
  598. }
  599. //工具栏
  600. if( g_bStartRun && g_nToolbarRun )
  601. {
  602. #if USE_NEWTOP
  603. m_pToolBar = new CDlg_ToolBar();
  604. m_pToolBar->Create(IDD_DLG_TOOLBAR, this);
  605. m_pToolBar->ShowWindow( SW_SHOW );
  606. m_htopDockBar.AddPage( m_pToolBar, "工具栏", IDR_MAINFRAME );
  607. m_htopDockBar.ShowWindow(SW_SHOW);
  608. CSize sz;
  609. sz = m_htopDockBar.GetHorSize(); // 获取顶部工具栏大小;
  610. m_pToolBar->SetPos( sz.cx,sz.cy );
  611. #else
  612. // 1.获取实际工具栏长宽 [8/29/2013 Z.t]
  613. CSize sz;
  614. sz = m_htopDockBar.GetHorSize();
  615. // 2.创建工具栏上的对话框 [8/29/2013 Z.t]
  616. m_wndOfTop = new CDlgOfTop();
  617. // 3.传递对话框的大小;
  618. m_wndOfTop->_ClientSize.cx = sz.cx;
  619. m_wndOfTop->_ClientSize.cy = sz.cy;
  620. m_wndOfTop->Create(IDD_TOP, this);
  621. m_wndOfTop->ShowWindow( SW_SHOW );
  622. m_htopDockBar.AddPage( m_wndOfTop, "工具栏", IDR_MAINFRAME );
  623. m_htopDockBar.ShowWindow(SW_SHOW);
  624. //m_wndOfTop->CalcWindowRect(sz);
  625. #if 0 // 一直为1 [8/29/2013 Z.t]
  626. m_wndOfTop->MoveWindow(0,0,sz.cx,sz.cy);
  627. CRect rtOfTop;
  628. m_wndOfTop->GetWindowRect(rtOfTop);
  629. // sz,得到是运行后工具栏的实际长宽 [7/27/2013 Zero]
  630. // sy,得到是创建m_htopDockBar时的原始大小 [7/27/2013 Zero]
  631. CSize sy = m_htopDockBar.GetVerSize();
  632. //m_wndOfTop->SetPos( sz.cx,sz.cy );
  633. TRACE("--on--");
  634. #endif
  635. #endif
  636. }
  637. if( !g_bStartRun && g_nIsDemo==0 )
  638. {
  639. this->SetFocus();
  640. SetWindowPos(NULL,0,0,W,H,SWP_NOZORDER);//使连接服务器失败的情况下,第一时间显示在桌面
  641. }
  642. else if( g_nIsDemo==1 )
  643. {
  644. int screenx=GetSystemMetrics(SM_CXSCREEN);
  645. int screeny=GetSystemMetrics(SM_CYSCREEN);
  646. //系统任务栏的高度
  647. HWND hWnd = ::FindWindow("Shell_TrayWnd", NULL);
  648. RECT rc;
  649. ::GetWindowRect(hWnd, &rc);
  650. int nHeight = rc.bottom-rc.top;
  651. SetWindowPos(NULL,0,0,screenx,screeny-nHeight,SWP_NOZORDER);
  652. }
  653. return 0;
  654. }
  655. void CMainFrame::MyExpandTree(HTREEITEM hTreeItem)
  656. {
  657. if(!m_wndTree.ItemHasChildren(hTreeItem))
  658. {
  659. return;
  660. }
  661. HTREEITEM hNextItem = m_wndTree.GetChildItem(hTreeItem);
  662. while (hNextItem != NULL)
  663. {
  664. MyExpandTree(hNextItem);
  665. hNextItem = m_wndTree.GetNextItem(hNextItem, TVGN_NEXT);
  666. }
  667. m_wndTree.Expand(hTreeItem,TVE_EXPAND);
  668. }
  669. DWORD WINAPI CMainFrame::ViewPollThread( void *pData )
  670. {
  671. CMainFrame *pMainFrm = (CMainFrame *)pData;
  672. DWORD dwTick = 0;
  673. do
  674. {
  675. if (g_bStartRun && g_nIsPoll == 1)
  676. {
  677. for( int i = 0; i < g_nPollCount; i++ )
  678. {
  679. if( dwTick == 0 )
  680. {
  681. if( g_nPollIndex == i )
  682. {
  683. dwTick = GetTickCount();
  684. if( pMainFrm )
  685. {
  686. //TRACE("Enter AddIDEView %s, %s\r\n", g_strPollPath, g_strPollDesc);
  687. //pMainFrm->AddIDEView(g_strPollDesc[i], g_strPollPath[i]);
  688. //TRACE("Leave AddIDEView\r\n");
  689. ((CIDEView *)pMainFrm->m_pActiveView)->ChangeView();
  690. int nIndex = pMainFrm->GetIDEViewIndex(g_strPollPath[i]);
  691. if( nIndex == -1 )
  692. {
  693. nIndex = pMainFrm->GetIDEViewFreeIndex(g_strPollPath[i]);
  694. if( nIndex == -1 ) nIndex = 0;
  695. CCreateContext context;
  696. pMainFrm->m_pViewIDE[nIndex] = new CChildFrame;
  697. pMainFrm->m_pViewIDE[nIndex]->m_strPath = g_strPollPath[i];
  698. pMainFrm->m_pViewIDE[nIndex]->m_strDesc = g_strPollDesc[i];
  699. context.m_pCurrentDoc = pMainFrm->m_pDoc;
  700. context.m_pNewDocTemplate = pMainFrm->m_pDoc->GetDocTemplate();
  701. context.m_pNewViewClass = RUNTIME_CLASS( CIDEView );
  702. context.m_pCurrentFrame = pMainFrm;
  703. context.m_pLastView = NULL;
  704. if( !pMainFrm->m_pViewIDE[nIndex]->LoadFrame(IDI_SUMMARY, WS_MAXIMIZE|WS_OVERLAPPEDWINDOW, pMainFrm, &context) )
  705. {
  706. }
  707. pMainFrm->m_pViewIDE[nIndex]->ShowWindow(SW_SHOWMAXIMIZED);
  708. pMainFrm->m_pViewIDE[nIndex]->InitialUpdateFrame(pMainFrm->m_pDoc,true);
  709. pMainFrm->m_pViewIDE[nIndex]->MDIActivate();
  710. pMainFrm->m_nViewCount++;
  711. }
  712. else
  713. {
  714. pMainFrm->m_pActiveView = (CFormView *)pMainFrm->m_pViewIDE[nIndex]->GetActiveView();
  715. pMainFrm->m_pViewIDE[nIndex]->MDIActivate();
  716. }
  717. pMainFrm->m_pViewIDE[ nIndex ]->m_bClose = FALSE;
  718. pMainFrm->m_pActiveView = (CFormView *)pMainFrm->m_pViewIDE[nIndex]->GetActiveView();
  719. g_strViewName = g_strPollPath[i];
  720. ((CIDEView *)pMainFrm->m_pActiveView)->ChangeView();
  721. }
  722. }
  723. }
  724. else if( GetTickCount() - dwTick > (DWORD)g_nPollInterval * 1000 )
  725. {
  726. if( g_nPollIndex == g_nPollCount - 1 )
  727. {
  728. g_nPollIndex = 0;
  729. }
  730. else
  731. {
  732. g_nPollIndex++;
  733. }
  734. dwTick = 0;
  735. }
  736. }
  737. }
  738. }while( WaitForSingleObject( g_hRunObject, 125L ) == WAIT_TIMEOUT );
  739. return 0;
  740. }
  741. void CMainFrame::ShowCaptionMenu(BOOL bShow)
  742. {
  743. static HMENU hMenu=NULL;
  744. if(hMenu == NULL)
  745. {
  746. hMenu=::GetMenu(this->GetSafeHwnd());
  747. }
  748. if(bShow)
  749. {
  750. ::SetMenu(this->GetSafeHwnd(),hMenu);
  751. this->ModifyStyle(0,WS_CAPTION,SWP_FRAMECHANGED);
  752. }
  753. else
  754. {
  755. ::SetMenu(this->GetSafeHwnd(),NULL);
  756. this->ModifyStyle(WS_CAPTION,0,SWP_FRAMECHANGED);
  757. }
  758. }
  759. void CMainFrame::LoadRunPara()
  760. {
  761. char Path[_MAX_PATH] = {0};
  762. strcat(Path, g_strDirectory);
  763. strcat(Path,"\\");
  764. strcat(Path, _PROJECTDIR);
  765. strcat(Path,"\\");
  766. strcat(Path, "runpara.ini");
  767. char RUN[MAX_PATH] = {0};
  768. memset(RUN, 0, sizeof(RUN));
  769. //CString str;
  770. if ( GetPrivateProfileString("RUNPARA", "STARTRUN","",RUN, 10, Path) != 0)
  771. {
  772. g_bStartRun = (RUN[0] == '1' ? true:false);
  773. }
  774. if ( GetPrivateProfileString("RUNPARA", "STARTPIC","", RUN, sizeof(RUN), Path) != 0)
  775. {
  776. g_strStartPic = RUN;
  777. }
  778. if ( GetPrivateProfileString("RUNPARA", "STARTPATH","",RUN, sizeof(RUN), Path) != 0)
  779. {
  780. g_strStartPath = RUN;
  781. }
  782. if ( GetPrivateProfileString("RUNPARA", "ALARM","",RUN, 10, Path) != 0)
  783. {
  784. g_bEventAlarm = RUN[0] == '1' ? true:false;
  785. }
  786. if ( GetPrivateProfileString("RUNPARA", "VOICE", "",RUN, 10, Path) != 0)
  787. {
  788. g_bAlarmVoice = RUN[0] == '1' ? true:false;
  789. }
  790. if ( GetPrivateProfileString("RUNPARA", "HIDETASK","",RUN, 10, Path) != 0)
  791. {
  792. g_bHideTask = RUN[0] == '1' ? true:false;
  793. }
  794. }
  795. BOOL CMainFrame::DirSearch(CString strPath, CString strFileName)
  796. {
  797. BOOL bResult = FALSE;
  798. long hDir;
  799. struct _finddata_t fDir;
  800. int nDone;
  801. strPath += "*.*";
  802. hDir = _findfirst( (char *)(LPCTSTR)strPath, &fDir );
  803. if( -1L != hDir )
  804. {
  805. while( !( nDone = _findnext(hDir, &fDir) ) )
  806. {
  807. if( !strcmp(fDir.name, "..") ) continue;
  808. if( (_A_SUBDIR == fDir.attrib) )
  809. {
  810. CString str = fDir.name;
  811. if( !str.Compare(strFileName) )
  812. {
  813. bResult = TRUE;
  814. }
  815. }
  816. }
  817. }
  818. return bResult;
  819. }
  820. int CMainFrame::GetLevel( CString sContent )
  821. {
  822. int nRet=0;
  823. for( int i=0;i<sContent.GetLength();i++ )
  824. {
  825. if( sContent[i]=='\\' )
  826. nRet++;
  827. if( sContent[i]=='[' )
  828. break;
  829. }
  830. return nRet;
  831. }
  832. CString CMainFrame::GetPreStr( CString sContent )
  833. {
  834. CString sRet;
  835. for( int i=sContent.GetLength()-1;i>=0;i-- )
  836. {
  837. if( sContent[i]=='\\' )
  838. {
  839. sRet = sContent.Left( i );
  840. break;
  841. }
  842. }
  843. return sRet;
  844. }
  845. CString CMainFrame::GetLastStr( CString sContent )
  846. {
  847. CString sRet;
  848. for( int i=sContent.GetLength()-1;i>=0;i-- )
  849. {
  850. if( sContent[i]=='\\' )
  851. {
  852. sRet = sContent.Right( sContent.GetLength()-i-1 );
  853. break;
  854. }
  855. }
  856. return sRet;
  857. }
  858. void CMainFrame::InsertToCStringArray( CStringArray &SA,int iInsertIndex,CString sContent,CString sPath )
  859. {
  860. CString str;
  861. if( sContent.Find(".view")!=-1 )
  862. sContent = sContent.Left( sContent.GetLength()-5 );
  863. CString sParent;
  864. if( m_sPath!=sPath )
  865. sParent = sPath.Right( sPath.GetLength()-m_sPath.GetLength() );
  866. if( sParent!="" )
  867. {
  868. sContent = sParent+sContent;
  869. }
  870. bool bExist=false;
  871. for( int i=0;i<SA.GetCount();i++ )
  872. {
  873. str = SA.GetAt( i );
  874. if( str==sContent )
  875. {
  876. bExist = true;
  877. break;
  878. }
  879. }
  880. if( !bExist )
  881. {
  882. int nInsert=SA.GetCount();
  883. CString s1;
  884. s1 = GetPreStr( sContent );
  885. for( int i=nInsert-1;i>=0;i-- )
  886. {
  887. str = SA.GetAt( i );
  888. if( str.Find( s1 )==0 )
  889. {
  890. nInsert = i+1;
  891. break;
  892. }
  893. }
  894. SA.InsertAt( nInsert,sContent );
  895. }
  896. }
  897. void CMainFrame::FileSearchCHN( CStringArray &SA,CStringArray &SATemp,int iInsertIndex, CString strPath, CString strFileName, int nLayer )
  898. {
  899. long hfile;
  900. struct _finddata_t fFile;
  901. CString strCurr = strPath + strFileName; // + "\\" +
  902. CString sIndex,sContent;
  903. int nDone=0;
  904. int nTime = 0;
  905. hfile = _findfirst( (char *)(LPCTSTR)strCurr, &fFile );
  906. if( -1L != hfile )
  907. {
  908. while( !( nDone = _findnext(hfile, &fFile) ) )
  909. {
  910. if( !strcmp(fFile.name,"..") ) continue;
  911. if( (_A_SUBDIR == fFile.attrib) )
  912. {
  913. strCurr = strPath + "\\" + fFile.name + "\\";
  914. int nPos = strCurr.Find("\\\\");
  915. if( nPos!=-1 )
  916. {
  917. strCurr.Delete( nPos );
  918. }
  919. CString str = fFile.name;
  920. sContent = str;
  921. InsertToCStringArray( SA,iInsertIndex,sContent,strPath );
  922. ////////////////////////////////////////////////////////////
  923. if( sContent.Find(".view")!=-1 )
  924. sContent = sContent.Left( sContent.GetLength()-5 );
  925. CString sParent;
  926. if( m_sPath!=strPath )
  927. sParent = strPath.Right( strPath.GetLength()-m_sPath.GetLength() );
  928. if( sParent!="" )
  929. {
  930. sContent = sParent+sContent;
  931. }
  932. SATemp.Add( sContent );
  933. ////////////////////////////////////////////////////////////
  934. iInsertIndex++;
  935. FileSearchCHN( SA,SATemp,iInsertIndex, strCurr, "*.*", nLayer + 1);
  936. if( g_bStartRun )
  937. {
  938. CString sPath = strCurr;
  939. int nPos = sPath.Find("*");
  940. if( nPos!=-1 )
  941. {
  942. sPath = sPath.Left( sPath.GetLength()-3 );
  943. }
  944. sPath = sPath+".view";
  945. nPos = sPath.Find("\\.");
  946. if( nPos!=-1 )
  947. {
  948. sPath.Delete( nPos );
  949. }
  950. }
  951. }
  952. else
  953. {
  954. CString str = fFile.name;
  955. if( str.Right(4).Compare("view") ) continue;
  956. CString strTemp = str.Left(str.GetLength()-5);
  957. if( !DirSearch(strPath + "\\", strTemp ) )
  958. {
  959. sContent = str;
  960. InsertToCStringArray( SA,iInsertIndex,sContent,strPath );
  961. iInsertIndex++;
  962. ////////////////////////////////////////////////////////////
  963. CString str;
  964. if( sContent.Find(".view")!=-1 )
  965. sContent = sContent.Left( sContent.GetLength()-5 );
  966. CString sParent;
  967. if( m_sPath!=strPath )
  968. sParent = strPath.Right( strPath.GetLength()-m_sPath.GetLength() );
  969. if( sParent!="" )
  970. {
  971. sContent = sParent+sContent;
  972. }
  973. SATemp.Add( sContent );
  974. ////////////////////////////////////////////////////////////
  975. }
  976. }
  977. }
  978. _findclose(hfile);
  979. }
  980. }
  981. //交换机
  982. //服务器
  983. //服务器\1号服务器
  984. //服务器\1号服务器\1号服务器
  985. //服务器\1号服务器\2号服务器
  986. //服务器\1号服务器\3号服务器
  987. //服务器\2号服务器
  988. //服务器\2号服务器\1号服务器
  989. //服务器\2号服务器\2号服务器
  990. //a
  991. void CMainFrame::AddViewToTree( HTREEITEM hItem, CStringArray &SA )
  992. {
  993. HTREEITEM hRoot;
  994. HTREEITEM hTemp[10];
  995. HTREEITEM hItemInsert=hItem;
  996. hRoot = hItem;
  997. hTemp[0] = hItem;
  998. int nSize = SA.GetCount();
  999. int nLevel1=0,nLevel2=0;
  1000. CString sView,sPath,sTemp;
  1001. for( int i=0;i<nSize;i++ )
  1002. {
  1003. sView = SA.GetAt( i );
  1004. sTemp = sView;
  1005. nLevel2 = GetLevel( sView );
  1006. if( nLevel2==0 )
  1007. hItemInsert = hRoot;
  1008. else
  1009. {
  1010. hItemInsert = hTemp[nLevel2-1];
  1011. }
  1012. if( nLevel2>0 )
  1013. sView = GetLastStr( sView );
  1014. hItem = m_wndTree.InsertItem(sView, 1, 1, hItemInsert);
  1015. hTemp[nLevel2] = hItem;
  1016. if( nLevel1!=nLevel2 )
  1017. nLevel1 = nLevel2;
  1018. sPath = m_sPath + sTemp+".view";
  1019. int nInsertIndex=0;
  1020. if( !GetPicIndexByPicPath( nInsertIndex,sPath ) )
  1021. {
  1022. InsertPicPathToStruct( nInsertIndex,sPath );
  1023. //LOG4C((LOG_NOTICE, "画面%d:%s", nInsertIndex,sPath));
  1024. }
  1025. }
  1026. }
  1027. void CMainFrame::FileSearch(HTREEITEM hItem, CString strPath, CString strFileName, int nLayer)
  1028. {
  1029. long hfile;
  1030. struct _finddata_t fFile;
  1031. CString strCurr = strPath + strFileName; // + "\\" +
  1032. HTREEITEM hTemp = hItem;
  1033. int nDone=0;
  1034. int nTime = 0;
  1035. hfile = _findfirst( (char *)(LPCTSTR)strCurr, &fFile );
  1036. if( -1L != hfile )
  1037. {
  1038. while( !( nDone = _findnext(hfile, &fFile) ) )
  1039. {
  1040. if( !strcmp(fFile.name,"..") ) continue;
  1041. if( (_A_SUBDIR == fFile.attrib) )
  1042. {
  1043. strCurr = strPath + "\\" + fFile.name + "\\";
  1044. int nPos = strCurr.Find("\\\\");
  1045. if( nPos!=-1 )
  1046. {
  1047. strCurr.Delete( nPos );
  1048. }
  1049. CString str = fFile.name;
  1050. HTREEITEM hReturn = hItem;
  1051. hItem = m_wndTree.InsertItem(str, 1, 1, hItem);
  1052. FileSearch(hItem, strCurr, "*.*", nLayer + 1);
  1053. hItem = hReturn;
  1054. if( g_bStartRun )
  1055. {
  1056. CString sPath = strCurr;
  1057. int nPos = sPath.Find("*");
  1058. if( nPos!=-1 )
  1059. {
  1060. sPath = sPath.Left( sPath.GetLength()-3 );
  1061. }
  1062. sPath = sPath+".view";
  1063. nPos = sPath.Find("\\.");
  1064. if( nPos!=-1 )
  1065. {
  1066. sPath.Delete( nPos );
  1067. }
  1068. int nInsertIndex=0;
  1069. if( !GetPicIndexByPicPath( nInsertIndex,sPath ) )
  1070. {
  1071. InsertPicPathToStruct( nInsertIndex,sPath );
  1072. //LOG4C((LOG_NOTICE, "画面%d:%s", nInsertIndex,sPath));
  1073. }
  1074. }
  1075. }
  1076. else
  1077. {
  1078. CString str = fFile.name;
  1079. if( str.Right(4).Compare("view") ) continue;
  1080. CString strTemp = str.Left(str.GetLength()-5);
  1081. if( !DirSearch(strPath + "\\", strTemp ) )
  1082. {
  1083. m_wndTree.InsertItem(strTemp, 1, 1, hTemp);
  1084. }
  1085. //m_wndTree.SortChildren( hItem );
  1086. if( g_bStartRun )
  1087. {
  1088. CString sPath = strPath;
  1089. int nPos = sPath.Find("*");
  1090. if( nPos!=-1 )
  1091. {
  1092. sPath = sPath.Left( sPath.GetLength()-3 );
  1093. }
  1094. sPath = sPath+strTemp+".view";
  1095. int nInsertIndex=0;
  1096. if( !GetPicIndexByPicPath( nInsertIndex,sPath ) )
  1097. {
  1098. InsertPicPathToStruct( nInsertIndex,sPath );
  1099. //LOG4C((LOG_NOTICE, "画面%d:%s", nInsertIndex,sPath));
  1100. }
  1101. }
  1102. }
  1103. }
  1104. _findclose(hfile);
  1105. }
  1106. }
  1107. // 删除目录
  1108. void CMainFrame::DeleteDirectory(CString strDir)
  1109. {
  1110. if(strDir.IsEmpty())
  1111. {
  1112. RemoveDirectory(strDir);
  1113. return;
  1114. }
  1115. // 首先删除文件及子文件夹
  1116. CFileFind ff;
  1117. BOOL bFound = ff.FindFile(strDir+"\\*", 0);
  1118. while(bFound)
  1119. {
  1120. bFound = ff.FindNextFile();
  1121. if(ff.GetFileName()=="."||ff.GetFileName()=="..") continue;
  1122. // 去掉文件(夹)只读等属性
  1123. SetFileAttributes(ff.GetFilePath(), FILE_ATTRIBUTE_NORMAL);
  1124. if(ff.IsDirectory())
  1125. {
  1126. // 递归删除子文件夹
  1127. DeleteDirectory(ff.GetFilePath());
  1128. RemoveDirectory(ff.GetFilePath());
  1129. }
  1130. else
  1131. {
  1132. DeleteFile(ff.GetFilePath()); // 删除文件
  1133. }
  1134. }
  1135. ff.Close();
  1136. // 然后删除该文件夹
  1137. if (!RemoveDirectory(strDir))
  1138. {
  1139. //ff.Close();
  1140. //Sleep( 1000 );
  1141. RemoveDirectory(strDir);
  1142. }
  1143. }
  1144. void CMainFrame::InitTreeInfo(void)
  1145. {
  1146. m_wndTree.SetItemHeight(20);
  1147. m_wndImageList.DeleteImageList();
  1148. m_wndImageList.Create(IDB_LEFT, 16, 1, RGB(255, 0, 255));
  1149. m_wndTree.SetImageList(&m_wndImageList, LVSIL_NORMAL);
  1150. m_wndTree.SetBkColor( RGB(230,241,249) );
  1151. m_wndTree.DeleteAllItems();
  1152. m_hMonitor = m_wndTree.InsertItem(g_strMoniterSite,0,0);
  1153. if( !g_bStartRun )
  1154. {
  1155. m_hleftDockBar.m_bDrawStudBtn = true;
  1156. m_hIOGroup = m_wndTree.InsertItem(g_strDevice,2,2);
  1157. m_hEtherNet = m_wndTree.InsertItem(g_strEthernet,3,3,m_hIOGroup);
  1158. m_hSerial = m_wndTree.InsertItem(g_strSerial,4,4,m_hIOGroup);
  1159. m_hVariant = m_wndTree.InsertItem(g_strDataDict,11,11);
  1160. m_hAnalog = m_wndTree.InsertItem(g_strVarSet,15,15,m_hVariant);
  1161. m_hScript = m_wndTree.InsertItem(g_strScriptManage,13,13);
  1162. m_hActionWithAlarm = m_wndTree.InsertItem(g_strActionWithAlarm,13,13);
  1163. m_hSystem = m_wndTree.InsertItem(g_strSysParam,9,9);
  1164. //插入串口和网络设备
  1165. int nComportSize = pDevicesManager->m_channels.GetSize();
  1166. for (int i = 0; i < nComportSize; i++)
  1167. {
  1168. CChannel* pComport = pDevicesManager->m_channels[i];
  1169. if( pComport->m_nCommunicateType == 0 ) // 串口设备
  1170. {
  1171. m_hSerialGroup[i] = m_wndTree.InsertItem(pComport->m_strName,5,5,m_hSerial);
  1172. m_nPortNum++;
  1173. int nDeviceSize = pComport->m_Devices.GetSize();
  1174. for (int j = 0; j < nDeviceSize; j++)
  1175. {
  1176. CDevice* pDev = pComport->m_Devices[j];
  1177. m_hSerialDev[i][j] = m_wndTree.InsertItem(pDev->m_strName,4,4,m_hSerialGroup[i]);
  1178. }
  1179. }
  1180. else if( pComport->m_nCommunicateType == 1 ) // 网络设备
  1181. {
  1182. int nDeviceSize = pComport->m_Devices.GetSize();
  1183. for( int j = 0; j < nDeviceSize; j++ )
  1184. {
  1185. CDevice *pDev = pComport->m_Devices[j];
  1186. m_hNetworkDev[j] = m_wndTree.InsertItem(pDev->m_strName, 2, 2, m_hEtherNet);
  1187. }
  1188. }
  1189. }
  1190. }
  1191. //显示画面
  1192. CString strFindPicFile = "*.view";
  1193. char szPicDir[MAX_PATH] = {0};
  1194. strcpy(szPicDir, g_strDirectory);
  1195. strcat(szPicDir, "\\");
  1196. strcat(szPicDir, _PICTUREDIR);
  1197. m_sPath.Format( "%s",szPicDir );
  1198. //FileSearch(m_hMonitor, szPicDir, "*.*", 0);
  1199. ///////////////////////
  1200. strcpy(szPicDir, g_strDirectory);
  1201. strcat(szPicDir, "\\");
  1202. strcat(szPicDir, _PICTUREDIR);
  1203. strcat(szPicDir, "sort.txt");
  1204. CStringArray SA,SATemp;
  1205. if( PathFileExists( szPicDir ) )
  1206. {
  1207. CString sTemp,strTemp1,strTemp2,sTemp2;
  1208. CStdioFile File;
  1209. if(!File.Open(szPicDir,CFile::modeRead))
  1210. File.Open(szPicDir,CFile::modeCreate|CFile::modeRead);
  1211. while(File.ReadString(sTemp))
  1212. {
  1213. SA.Add( sTemp );
  1214. }
  1215. File.Close();
  1216. }
  1217. strcpy(szPicDir, g_strDirectory);
  1218. strcat(szPicDir, "\\");
  1219. strcat(szPicDir, _PICTUREDIR);
  1220. FileSearchCHN( SA,SATemp,0, szPicDir, "*.*", 0);
  1221. CString sShow,s;
  1222. for( int i=0;i<SA.GetCount();i++ )
  1223. {
  1224. s = SA.GetAt( i );
  1225. sShow = sShow + s + "\n";
  1226. }
  1227. //AfxMessageBox( sShow );
  1228. bool bExist=false;
  1229. int nSize1=SA.GetCount();
  1230. int nSize2=SATemp.GetCount();
  1231. CString str1,str2;
  1232. for( int i=nSize1-1;i>=0;i-- )
  1233. {
  1234. str1 = SA.GetAt(i);
  1235. for( int j=0;j<nSize2;j++ )
  1236. {
  1237. str2 = SATemp.GetAt(j);
  1238. if( str1==str2 )
  1239. {
  1240. bExist = true;
  1241. break;
  1242. }
  1243. }
  1244. if( !bExist )
  1245. SA.RemoveAt( i );
  1246. bExist = false;
  1247. }
  1248. AddViewToTree( m_hMonitor,SA );
  1249. ///////////////////////
  1250. //m_wndTree.SortChildren( m_hMonitor );
  1251. if( !g_bStartRun )
  1252. {
  1253. // 显示脚本
  1254. struct _finddata_t f;
  1255. long hfile;
  1256. strFindPicFile = "*.srp";
  1257. strcpy(szPicDir, g_strDirectory);
  1258. strcat(szPicDir, "\\");
  1259. strcat(szPicDir, _SCRIPTDIR);
  1260. strcat(szPicDir, strFindPicFile);
  1261. hfile = _findfirst((const char*)szPicDir,&f);
  1262. if (-1L != hfile)
  1263. {
  1264. CString strFileName = f.name;
  1265. m_hScriptGroup[m_nScripts++] = m_wndTree.InsertItem(strFileName.Left(strFileName.GetLength()-4),
  1266. 1,1,m_hScript);
  1267. while (0 == _findnext(hfile,&f))
  1268. {
  1269. strFileName = f.name;
  1270. m_hScriptGroup[m_nScripts++] = m_wndTree.InsertItem(strFileName.Left(strFileName.GetLength()-4),
  1271. 1,1,m_hScript);
  1272. }
  1273. _findclose(hfile);
  1274. }
  1275. }
  1276. }
  1277. void CMainFrame::OnFullScreen()
  1278. {
  1279. GetWindowPlacement(&m_OldWndPlacement);
  1280. CRect WindowRect;
  1281. GetWindowRect(&WindowRect);
  1282. CRect ClientRect;
  1283. RepositionBars(0, 0xffff, AFX_IDW_PANE_FIRST, reposQuery, &ClientRect);
  1284. ClientToScreen(&ClientRect);// 获取屏幕的分辨率
  1285. int nFullWidth=GetSystemMetrics(SM_CXSCREEN);
  1286. int nFullHeight=GetSystemMetrics(SM_CYSCREEN);// 将除控制条外的客户区全屏显示到从(0,0)到(nFullWidth, nFullHeight)区
  1287. //域, 将(0,0)和(nFullWidth, nFullHeight)两个点外扩充原窗口和除控制条之外的 客
  1288. //户区位置间的差值, 就得到全屏显示的窗口位置
  1289. m_FullScreenRect.left=0;//WindowRect.left-ClientRect.left-1;
  1290. m_FullScreenRect.top=0;//WindowRect.top-ClientRect.top-1;
  1291. m_FullScreenRect.right=WindowRect.right-ClientRect.right+nFullWidth+2;
  1292. m_FullScreenRect.bottom=nFullHeight;//WindowRect.bottom-ClientRect.bottom+nFullHeight+2;
  1293. // 进入全屏显示状态
  1294. WINDOWPLACEMENT wndpl;
  1295. wndpl.length=sizeof(WINDOWPLACEMENT);
  1296. wndpl.flags=0;
  1297. wndpl.showCmd=SW_SHOWNORMAL;
  1298. wndpl.rcNormalPosition=m_FullScreenRect;
  1299. SetWindowPlacement(&wndpl);
  1300. }
  1301. void CMainFrame::OnRun()
  1302. {
  1303. g_bRun = TRUE; //运行否
  1304. g_bEdit = FALSE; //编辑否
  1305. CDrawObj::bRuning = TRUE;
  1306. m_wndToolBar.ShowWindow(SW_HIDE);
  1307. m_wndDrawToolBar.ShowWindow(SW_HIDE);
  1308. m_wndDrawAlignBar.ShowWindow(SW_HIDE);
  1309. //if( g_nToolbarRun )//&& !g_bFullScreen )
  1310. //{
  1311. // m_wndRunToolBar.ShowWindow(SW_SHOW);
  1312. //}
  1313. //else
  1314. //{
  1315. // m_wndRunToolBar.ShowWindow(SW_HIDE);
  1316. //}
  1317. RecalcLayout();
  1318. if( g_nToolBarStatus )//&& !g_bFullScreen )
  1319. {
  1320. m_wndStatusBar.ShowWindow(SW_SHOW);
  1321. }
  1322. else
  1323. {
  1324. m_wndStatusBar.ShowWindow(SW_HIDE);
  1325. }
  1326. m_hleftDockBar.ShowWindow(SW_SHOW);
  1327. //if( g_nToolbarLeft )
  1328. //{
  1329. // m_wndDockPageBar1.ShowWindow(SW_SHOW);
  1330. //}
  1331. //else
  1332. //{
  1333. // m_wndDockPageBar1.ShowWindow(SW_HIDE);
  1334. //}
  1335. if ( g_bHideTask )
  1336. {
  1337. HWND wnd = ::FindWindow("Shell_TrayWnd", NULL);
  1338. ::ShowWindow(wnd, SW_HIDE);
  1339. }
  1340. //else
  1341. //{
  1342. // HWND wnd = ::FindWindow("Shell_TrayWnd", NULL);
  1343. // ::ShowWindow(wnd, SW_SHOW);
  1344. //}
  1345. LONG style=::GetWindowLong(m_hWnd,GWL_STYLE);
  1346. style&=~WS_CAPTION;
  1347. style&=~WS_BORDER;
  1348. ::SetWindowLong(m_hWnd,GWL_STYLE,style);
  1349. int screenx=GetSystemMetrics(SM_CXSCREEN);
  1350. int screeny=GetSystemMetrics(SM_CYSCREEN);
  1351. //系统任务栏的高度
  1352. HWND hWnd = ::FindWindow("Shell_TrayWnd", NULL);
  1353. RECT rc;
  1354. ::GetWindowRect(hWnd, &rc);
  1355. int nHeight = rc.bottom-rc.top;
  1356. if( g_nIsDemo == 0 )
  1357. {
  1358. if(!g_bFullScreen)
  1359. {
  1360. SetWindowPos(NULL,0,0,screenx,screeny-nHeight,SWP_NOZORDER);
  1361. }
  1362. else
  1363. {
  1364. SetWindowPos(NULL,0,0,screenx,screeny+0,SWP_FRAMECHANGED);//关于全屏
  1365. }
  1366. }
  1367. SetMenu((CMenu*)NULL);
  1368. }
  1369. BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
  1370. {
  1371. if( !CMDIFrameWnd::PreCreateWindow(cs) )
  1372. return FALSE;
  1373. // TODO: 在此处通过修改 CREATESTRUCT cs 来修改窗口类或
  1374. // 样式
  1375. if (!g_bStartRun)
  1376. {
  1377. cs.style = WS_OVERLAPPED | WS_CAPTION | FWS_ADDTOTITLE
  1378. | WS_THICKFRAME | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_MAXIMIZE;
  1379. }
  1380. else
  1381. {
  1382. cs.style=WS_OVERLAPPED | WS_SYSMENU |WS_MINIMIZEBOX |WS_TILED ;
  1383. }
  1384. return TRUE;
  1385. }
  1386. // CMainFrame 诊断
  1387. #ifdef _DEBUG
  1388. void CMainFrame::AssertValid() const
  1389. {
  1390. CMDIFrameWnd::AssertValid();
  1391. }
  1392. void CMainFrame::Dump(CDumpContext& dc) const
  1393. {
  1394. CMDIFrameWnd::Dump(dc);
  1395. }
  1396. #endif //_DEBUG
  1397. // CMainFrame 消息处理程序
  1398. void CMainFrame::OnSuperEnd()
  1399. {
  1400. // TODO: 在此添加命令处理程序代码
  1401. m_bShutdown = TRUE; // really exit
  1402. SendMessage(WM_CLOSE);
  1403. }
  1404. void CMainFrame::OnTrayOpen()
  1405. {
  1406. // TODO: 在此添加命令处理程序代码
  1407. ShowWindow(SW_MAXIMIZE);
  1408. SetForegroundWindow();
  1409. }
  1410. void CMainFrame::OnClose()
  1411. {
  1412. // TODO: 在此添加消息处理程序代码和/或调用默认值
  1413. #if USE_TRAYICON
  1414. #else
  1415. m_bShutdown = TRUE;
  1416. #endif
  1417. if( m_bShutdown )
  1418. {
  1419. if( g_nIsDemo == 1 )
  1420. {
  1421. if(MessageBox(g_strExitConfirm, g_strTip, MB_YESNO|MB_ICONQUESTION)==IDNO)
  1422. {
  1423. return;
  1424. }
  1425. }
  1426. #if 0 // 暂时不使用登陆框 [8/29/2013 hero]
  1427. else
  1428. {
  1429. CLogin dlg;
  1430. dlg.m_bShutdown = true;
  1431. if (dlg.DoModal()!=IDOK)
  1432. {
  1433. m_bShutdown = false;
  1434. return;
  1435. }
  1436. CString sContent;
  1437. sContent.Format("用戶< %s >注销",dlg.m_sUserID );
  1438. CDBInterface::GetInstancePtr()->InsertLogRecord( LOG_LOGOUT,0,"",(char *)(LPCTSTR)sContent );
  1439. }
  1440. #endif
  1441. if (g_bRun )
  1442. {
  1443. pDevicesManager->Store(g_strDirectory);
  1444. pVariantsManager->Store(g_strDirectory);
  1445. }
  1446. // 清除所有事件
  1447. for(POSITION pos = pEventServer->eventList.GetHeadPosition();pos!=NULL;)
  1448. {
  1449. POSITION pos1 = pos ; //要在这里做一个备份
  1450. CAlarmEvent* pEvent = pEventServer->eventList.GetNext(pos);//他会改变 pos的值
  1451. pEventServer->eventList.RemoveAt(pos1);
  1452. if( pEvent )
  1453. {
  1454. delete pEvent;
  1455. pEvent = NULL;
  1456. }
  1457. }
  1458. //if( g_nAlarmModeIsDlg && g_bStartRun )
  1459. {
  1460. if( m_dlgEvent )
  1461. delete m_dlgEvent;
  1462. if( m_dlgControl )
  1463. delete m_dlgControl;
  1464. }
  1465. if( m_pDlgZuTaiAdd )
  1466. {
  1467. delete m_pDlgZuTaiAdd;
  1468. m_pDlgZuTaiAdd = NULL ;
  1469. }
  1470. int i;
  1471. for( i = 0; i < MAX_VIEW_NUM; i++ )
  1472. {
  1473. if( m_pViewIDE[ i ] )
  1474. {
  1475. ::SendMessage(m_pViewIDE[ i ]->m_hWnd, WM_CLOSE, 0, 0 );
  1476. m_pViewIDE[ i ] = NULL;
  1477. }
  1478. }
  1479. #if USE_NEWTOP
  1480. if( g_bRun && g_nToolbarRun )
  1481. {
  1482. if( m_pToolBar )
  1483. delete m_pToolBar;
  1484. m_pToolBar = NULL ;
  1485. }
  1486. #else
  1487. if( g_bRun && g_nToolbarRun )
  1488. {
  1489. if( m_wndOfTop )
  1490. delete m_wndOfTop;
  1491. m_wndOfTop = NULL ;
  1492. }
  1493. #endif
  1494. CMDIAutoHideFrame::OnClose();
  1495. }
  1496. else
  1497. {
  1498. ShowWindow(SW_HIDE);
  1499. }
  1500. }
  1501. void CMainFrame::OnDestroy()
  1502. {
  1503. if( g_nIsPoll == 1 )
  1504. {
  1505. #if VIEW_USE_THREAD
  1506. if( m_hViewPollThread != NULL )
  1507. {
  1508. MTVERIFY( WaitForSingleObject( m_hViewPollThread, INFINITE ) != WAIT_FAILED );
  1509. MTVERIFY( CloseHandle( m_hViewPollThread ) );
  1510. m_hViewPollThread = NULL;
  1511. }
  1512. #else
  1513. KillTimer(1);
  1514. #endif
  1515. }
  1516. CMDIAutoHideFrame::OnDestroy();
  1517. // TODO: 在此处添加消息处理程序代码
  1518. int i;
  1519. for( i = 0; i < MAX_VIEW_NUM; i++ )
  1520. {
  1521. if( m_pViewIDE[ i ] )
  1522. {
  1523. ::SendMessage(m_pViewIDE[ i ]->m_hWnd, WM_DESTROY, 0, 0 );
  1524. m_pViewIDE[ i ] = NULL;
  1525. }
  1526. }
  1527. }
  1528. BOOL CMainFrame::FindTreeItem(HTREEITEM hSrcItem, HTREEITEM hDestItem)
  1529. {
  1530. HTREEITEM hItem = m_wndTree.GetParentItem( hSrcItem );
  1531. while( hItem != NULL )
  1532. {
  1533. if( hItem == hDestItem ) return TRUE;
  1534. hItem = m_wndTree.GetParentItem( hItem );
  1535. }
  1536. return FALSE;
  1537. }
  1538. int CMainFrame::ShowDevProperty(HTREEITEM hSelectedItem)
  1539. {
  1540. CString strOldUid, strNewUid;
  1541. int i, j;
  1542. int nChannelIndex = -1, nDeviceIndex = -1;
  1543. int nChannelSize = pDevicesManager->m_channels.GetSize();
  1544. // 串口设备属性设置
  1545. for (i = 0; i < nChannelSize; i++)
  1546. {
  1547. if( nChannelIndex != -1 && nDeviceIndex != -1 ) break;
  1548. int nDeviceSize = pDevicesManager->m_channels[i]->m_Devices.GetSize();
  1549. for( j = 0; j < nDeviceSize; j++)
  1550. {
  1551. if (m_hSerialDev[i][j]==hSelectedItem )
  1552. {
  1553. nChannelIndex = i;
  1554. nDeviceIndex = j;
  1555. break;
  1556. }
  1557. if( m_hNetworkDev[j] == hSelectedItem && pDevicesManager->m_channels[i]->m_nCommunicateType == 1 )
  1558. {
  1559. nChannelIndex = i;
  1560. nDeviceIndex = j;
  1561. break;
  1562. }
  1563. }
  1564. }
  1565. if( nChannelIndex == -1 || nDeviceIndex == -1 ) return -1;
  1566. CChannel* pChannel = pDevicesManager->m_channels[nChannelIndex];
  1567. CDevice* pDev = pChannel->m_Devices[nDeviceIndex];
  1568. //CSerial* pSerial = (CSerial *)pChannel;
  1569. CNetwork *pNetwork = (CNetwork *)pChannel;
  1570. CWizard MyWizard(g_strMywizard,this,1);
  1571. // 通信方式
  1572. m_wndDevice.m_nCommuniteType = pChannel->m_nCommunicateType;
  1573. // 设备驱动名称
  1574. m_wndDevice.m_strDevDriveName = pDev->m_strDevDriveName;
  1575. // 设备厂家名称
  1576. m_wndDevice.m_strDevFactoryName = pDev->m_strDevFactoryName;
  1577. // 设备型号
  1578. m_wndDevice.m_strDevTypeName = pDev->m_strType;
  1579. // 通信协议(例:Modbus rtu, modbus ascii, modbus tcp)
  1580. m_wndDevice.m_nProtocolType = pDev->m_nProtocolType;
  1581. // 配置文件名称
  1582. m_wndDevice.m_strIniName = pDev->m_strIniName;
  1583. // 协议驱动动态库名称
  1584. m_wndDevice.m_strProtocolName = pDev->m_strProtocolName;
  1585. // 是否为采集设备
  1586. m_wndDevice.m_nCollectDev = pDev->m_nIsCollectDev;
  1587. // 是否启用设备
  1588. m_wndDevice.m_nDevEnable = (int)pDev->m_bUsed;
  1589. // CString类型预留
  1590. //m_wndDevice.m_strReserved1 = pDev->m_strReserved1;
  1591. m_wndDevice.m_strReserved2 = pDev->m_strReserved2;
  1592. m_wndDevice.m_strReserved3 = pDev->m_strReserved3;
  1593. m_wndDevice.m_strReserved4 = pDev->m_strReserved4;
  1594. m_wndDevice.m_strReserved5 = pDev->m_strReserved5;
  1595. // Int类型预留
  1596. m_wndDevice.m_nReserved1 = pDev->m_nReserved1;
  1597. m_wndDevice.m_nReserved2 = pDev->m_nReserved2;
  1598. m_wndDevice.m_nReserved3 = pDev->m_nReserved3;
  1599. m_wndDevice.m_nReserved4 = pDev->m_nReserved4;
  1600. m_wndDevice.m_nReserved5 = pDev->m_nReserved5;
  1601. // BOOL类型预留
  1602. m_wndDevice.m_bReserved1 = pDev->m_bReserved1;
  1603. m_wndDevice.m_bReserved2 = pDev->m_bReserved2;
  1604. m_wndDevice.m_bReserved3 = pDev->m_bReserved3;
  1605. m_wndDevice.m_bReserved4 = pDev->m_bReserved4;
  1606. m_wndDevice.m_bReserved5 = pDev->m_bReserved5;
  1607. // 设备UID
  1608. m_wndComport.m_strUID = pDev->m_strUID;
  1609. strOldUid = pDev->m_strUID;
  1610. // 设备名称
  1611. m_wndComport.m_strDevName = pDev->m_strName;
  1612. // 设备所属区域
  1613. m_wndComport.m_strDevArea = pDev->m_strReserved1;
  1614. // 通讯超时
  1615. m_wndComport.m_nTimeout = pDev->m_nTimeout;
  1616. // 设备地址
  1617. m_wndComport.m_nDevAddr = (int)pDev->m_Address;
  1618. // 串行端口
  1619. m_wndComport.m_nCommPort = atoi(pChannel->m_strPort.Mid(3));
  1620. // 数据位
  1621. m_wndComport.m_nDataBit = pChannel->m_nByteSize;
  1622. // 波特率
  1623. m_wndComport.m_nRate = pChannel->m_nBaudRate;
  1624. // 停止位
  1625. m_wndComport.m_nStopBit = pChannel->m_nStopBits;
  1626. // 校验位
  1627. m_wndComport.m_nCheckCode = pChannel->m_nParity;
  1628. // CString类型预留
  1629. m_wndComport.m_strReserved6 = pDev->m_strReserved6;
  1630. m_wndComport.m_strReserved7 = pDev->m_strReserved7;
  1631. m_wndComport.m_strReserved8 = pDev->m_strReserved8;
  1632. m_wndComport.m_strReserved9 = pDev->m_strReserved9;
  1633. m_wndComport.m_strReserved10 = pDev->m_strReserved10;
  1634. // Int类型预留
  1635. m_wndComport.m_nReserved6 = pDev->m_nReserved6;
  1636. m_wndComport.m_nReserved7 = pDev->m_nReserved7;
  1637. m_wndComport.m_nReserved8 = pDev->m_nReserved8;
  1638. m_wndComport.m_nReserved9 = pDev->m_nReserved9;
  1639. m_wndComport.m_nReserved10 = pDev->m_nReserved10;
  1640. // BOOL类型预留
  1641. m_wndComport.m_bReserved6 = pDev->m_bReserved6;
  1642. m_wndComport.m_bReserved7 = pDev->m_bReserved7;
  1643. m_wndComport.m_bReserved8 = pDev->m_bReserved8;
  1644. m_wndComport.m_bReserved9 = pDev->m_bReserved9;
  1645. m_wndComport.m_bReserved10 = pDev->m_bReserved10;
  1646. if( pChannel->m_nCommunicateType == 1 )
  1647. {
  1648. // 设备IP
  1649. m_wndComport.m_nNetIP = htonl(inet_addr(pDev->m_strDevIP));
  1650. // 通讯端口
  1651. m_wndComport.m_nNetPort = pDev->m_nNetPort;
  1652. }
  1653. m_wndDevice.m_operation = CDlgDevice::EDIT;
  1654. MyWizard.AddPage( &m_wndDevice );
  1655. MyWizard.AddPage( &m_wndComport );
  1656. MyWizard.SetWizardMode();
  1657. MyWizard.SetActivePage( &m_wndDevice );
  1658. int nTmpChannelIndex = -1, nTmpDeviceIndex = -1;
  1659. if( MyWizard.DoModal() == ID_WIZFINISH )
  1660. {
  1661. if( !m_wndComport.m_strDevName.Compare("") )
  1662. {
  1663. MessageBox(g_strDevNumCannotBlank, g_strTip, MB_ICONINFORMATION);
  1664. return -1;
  1665. }
  1666. else if( pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_strName != m_wndComport.m_strDevName )
  1667. {
  1668. if( pDevicesManager->FindDev(m_wndComport.m_strDevName, nTmpChannelIndex, nTmpDeviceIndex) )
  1669. {
  1670. MessageBox(g_strDevNameInUse, g_strTip, MB_ICONINFORMATION);
  1671. return -1;
  1672. }
  1673. }
  1674. int nIP = htonl(m_wndComport.m_nNetIP);
  1675. if( m_wndDevice.m_nCommuniteType == 0 )
  1676. {
  1677. CString strName;
  1678. strName.Format("COM%d", m_wndComport.m_nCommPort);
  1679. CString sTemp;
  1680. sTemp.Format("%s",pDevicesManager->m_channels[nChannelIndex]->m_strName );
  1681. //TRACE("串口名称=%s\r\n", pDevicesManager->m_channels[nChannelIndex]->m_strName);
  1682. if( pDevicesManager->m_channels[nChannelIndex]->m_strName.Compare("") &&
  1683. pDevicesManager->m_channels[nChannelIndex]->m_strName != strName )//以前是串口,现在串口号改变
  1684. {
  1685. int nIndex;
  1686. nIndex = pDevicesManager->FindCommPort(strName);
  1687. if( nIndex == -1 )//串口号不存在
  1688. {
  1689. if( FinishedAddDevice(1, pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_strUID) == 1 )
  1690. {
  1691. //m_wndTree.DeleteItem( m_hCurrent );
  1692. for( j = nDeviceIndex; j < MAX_DEVICE_NUM; j++ )
  1693. {
  1694. m_hSerialDev[nChannelIndex][j] = m_hSerialDev[nChannelIndex][j+1];
  1695. }
  1696. delete pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex];
  1697. pDevicesManager->m_channels[nChannelIndex]->m_Devices.RemoveAt(nDeviceIndex);
  1698. //InitTreeInfo();
  1699. }
  1700. return 1;
  1701. }
  1702. else//串口号存在
  1703. {
  1704. if( pDevicesManager->FindCommPort(strName, m_wndComport.m_nDevAddr, nTmpChannelIndex, nTmpDeviceIndex) )
  1705. {
  1706. MessageBox(g_strSerialPortInUse, g_strTip, MB_ICONINFORMATION);
  1707. return -1;
  1708. }
  1709. if( pDevicesManager->FindDev(strName, nTmpChannelIndex, nTmpDeviceIndex) )
  1710. {
  1711. MessageBox(g_strDevNameInUse, g_strTip, MB_ICONINFORMATION);
  1712. return -1;
  1713. }
  1714. //nChannelIndex = nIndex;
  1715. if( FinishedAddDevice(1, pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_strUID) == 1 )
  1716. {
  1717. //m_wndTree.DeleteItem( m_hCurrent );
  1718. for( j = nDeviceIndex; j < MAX_DEVICE_NUM; j++ )
  1719. {
  1720. m_hSerialDev[nChannelIndex][j] = m_hSerialDev[nChannelIndex][j+1];
  1721. }
  1722. delete pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex];
  1723. pDevicesManager->m_channels[nChannelIndex]->m_Devices.RemoveAt(nDeviceIndex);
  1724. //DeleteDevInfo((char *)(LPCTSTR)strUid);
  1725. }
  1726. return 1;
  1727. //nDeviceIndex = pDevicesManager->m_channels[nChannelIndex]->m_Devices.GetSize();
  1728. }
  1729. }
  1730. else//1.以前是串口,现在串口号不变,但设备号改变 2.以前是网络设备,现在改成串口
  1731. {
  1732. if( 0==pDevicesManager->m_channels[nChannelIndex]->m_strName.Compare("") )//2.以前是网络设备,现在改成串口
  1733. {
  1734. if( FinishedAddDevice(1, pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_strUID) == 1 )
  1735. {
  1736. //m_wndTree.DeleteItem( m_hCurrent );
  1737. for( j = nDeviceIndex; j < MAX_DEVICE_NUM; j++ )
  1738. {
  1739. m_hNetworkDev[j] = m_hNetworkDev[j+1];
  1740. }
  1741. delete pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex];
  1742. pDevicesManager->m_channels[nChannelIndex]->m_Devices.RemoveAt(nDeviceIndex);
  1743. }
  1744. return 1;
  1745. }
  1746. else
  1747. {
  1748. if( pDevicesManager->FindDev(strName, nTmpChannelIndex, nTmpDeviceIndex) )////1.以前是串口,现在串口号不变,但设备号改变
  1749. {
  1750. MessageBox(g_strDevNameInUse, g_strTip, MB_ICONINFORMATION);
  1751. return -1;
  1752. }
  1753. }
  1754. }
  1755. }
  1756. else//网络通信协议
  1757. {
  1758. CString strName;
  1759. strName.Format("%s", pDevicesManager->m_channels[nChannelIndex]->m_strName);//是網絡的話為空
  1760. if( 0==strName.Compare("") )//以前是网络,现在也网络
  1761. {
  1762. if( m_wndComport.m_nNetIP == 0 )
  1763. {
  1764. MessageBox(g_strIPNotBlank, g_strTip, MB_ICONWARNING);
  1765. pDev->Destroy();
  1766. delete pDev;
  1767. return 0;
  1768. }
  1769. if( m_wndComport.m_nNetPort == 0 )
  1770. {
  1771. MessageBox(g_strComcanNot0, g_strTip, MB_ICONWARNING);
  1772. pDev->Destroy();
  1773. delete pDev;
  1774. return 0;
  1775. }
  1776. CString strIP = inet_ntoa(*(struct in_addr *)&nIP);
  1777. if( (pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex])->m_strDevIP != strIP )
  1778. {
  1779. if( pDevicesManager->FindDev(strIP, m_wndComport.m_nNetPort, nTmpChannelIndex, nTmpDeviceIndex) )
  1780. {
  1781. MessageBox(g_strIPComoccupy, g_strTip, MB_ICONINFORMATION);
  1782. return -1;
  1783. }
  1784. }
  1785. }
  1786. else//以前是串口,现在是网络
  1787. {
  1788. if( FinishedAddDevice(1, pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_strUID) == 1 )
  1789. {
  1790. //m_wndTree.DeleteItem( m_hCurrent );
  1791. for( j = nDeviceIndex; j < MAX_DEVICE_NUM; j++ )
  1792. {
  1793. m_hSerialDev[nChannelIndex][j] = m_hSerialDev[nChannelIndex][j+1];
  1794. }
  1795. delete pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex];
  1796. pDevicesManager->m_channels[nChannelIndex]->m_Devices.RemoveAt(nDeviceIndex);
  1797. }
  1798. return 1;
  1799. }
  1800. }
  1801. // 通信方式
  1802. pDevicesManager->m_channels[nChannelIndex]->m_nCommunicateType = m_wndDevice.m_nCommuniteType;
  1803. // 设备驱动名称
  1804. pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_strDevDriveName = m_wndDevice.m_strDevDriveName;
  1805. // 设备厂家名称
  1806. pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_strDevFactoryName = m_wndDevice.m_strDevFactoryName;
  1807. // 设备型号
  1808. pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_strType = m_wndDevice.m_strDevTypeName;
  1809. // 通信协议(例:Modbus rtu, modbus ascii, modbus tcp)
  1810. pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_nProtocolType = m_wndDevice.m_nProtocolType;
  1811. // 协议驱动动态库名称
  1812. pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_strProtocolName = m_wndDevice.m_strProtocolName;
  1813. // 是否为采集设备
  1814. pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_nIsCollectDev = m_wndDevice.m_nCollectDev;
  1815. // 是否启用设备
  1816. pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_bUsed = (BOOL)m_wndDevice.m_nDevEnable;
  1817. // 设备UID
  1818. pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_strUID = m_wndComport.m_strUID;
  1819. strNewUid = m_wndComport.m_strUID;
  1820. // 设备名称
  1821. pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_strName = m_wndComport.m_strDevName;
  1822. // 设备所属区域
  1823. pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_strReserved1 = m_wndComport.m_strDevArea;
  1824. // 通讯超时
  1825. pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_nTimeout = m_wndComport.m_nTimeout;
  1826. // 设备地址
  1827. pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_Address = (BYTE)m_wndComport.m_nDevAddr;
  1828. //配置文件名称
  1829. pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_strIniName = m_wndDevice.m_strIniName;
  1830. //预留
  1831. //pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_strReserved1 = m_wndDevice.m_strReserved1;
  1832. pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_strReserved2 = m_wndDevice.m_strReserved2;
  1833. pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_strReserved3 = m_wndDevice.m_strReserved3;
  1834. pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_strReserved4 = m_wndDevice.m_strReserved4;
  1835. pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_strReserved5 = m_wndDevice.m_strReserved5;
  1836. pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_strReserved6 = m_wndComport.m_strReserved6;
  1837. pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_strReserved7 = m_wndComport.m_strReserved7;
  1838. pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_strReserved8 = m_wndComport.m_strReserved8;
  1839. pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_strReserved9 = m_wndComport.m_strReserved9;
  1840. pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_strReserved10 = m_wndComport.m_strReserved10;
  1841. pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_nReserved1 = m_wndDevice.m_nReserved1;
  1842. pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_nReserved2 = m_wndDevice.m_nReserved2;
  1843. pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_nReserved3 = m_wndDevice.m_nReserved3;
  1844. pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_nReserved4 = m_wndDevice.m_nReserved4;
  1845. pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_nReserved5 = m_wndDevice.m_nReserved5;
  1846. pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_nReserved6 = m_wndComport.m_nReserved6;
  1847. pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_nReserved7 = m_wndComport.m_nReserved7;
  1848. pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_nReserved8 = m_wndComport.m_nReserved8;
  1849. pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_nReserved9 = m_wndComport.m_nReserved9;
  1850. pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_nReserved10 = m_wndComport.m_nReserved10;
  1851. pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_bReserved1 = m_wndDevice.m_bReserved1;
  1852. pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_bReserved2 = m_wndDevice.m_bReserved2;
  1853. pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_bReserved3 = m_wndDevice.m_bReserved3;
  1854. pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_bReserved4 = m_wndDevice.m_bReserved4;
  1855. pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_bReserved5 = m_wndDevice.m_bReserved5;
  1856. pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_bReserved6 = m_wndComport.m_bReserved6;
  1857. pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_bReserved7 = m_wndComport.m_bReserved7;
  1858. pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_bReserved8 = m_wndComport.m_bReserved8;
  1859. pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_bReserved9 = m_wndComport.m_bReserved9;
  1860. pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_bReserved10 = m_wndComport.m_bReserved10;
  1861. if( m_wndDevice.m_nCommuniteType == 0 )
  1862. {
  1863. pDevicesManager->m_channels[nChannelIndex]->m_strName.Format("COM%d", m_wndComport.m_nCommPort);
  1864. // 串行端口
  1865. pDevicesManager->m_channels[nChannelIndex]->m_strPort.Format("COM%d", m_wndComport.m_nCommPort);
  1866. // 数据位
  1867. pDevicesManager->m_channels[nChannelIndex]->m_nByteSize = m_wndComport.m_nDataBit;
  1868. // 波特率
  1869. pDevicesManager->m_channels[nChannelIndex]->m_nBaudRate = m_wndComport.m_nRate;
  1870. // 停止位
  1871. pDevicesManager->m_channels[nChannelIndex]->m_nStopBits = m_wndComport.m_nStopBit;
  1872. // 校验位
  1873. pDevicesManager->m_channels[nChannelIndex]->m_nParity = m_wndComport.m_nCheckCode;
  1874. }
  1875. else if( m_wndDevice.m_nCommuniteType == 1 )
  1876. {
  1877. // 设备IP
  1878. pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_strDevIP = inet_ntoa(*(struct in_addr *)&nIP);
  1879. // 通讯端口
  1880. pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_nNetPort = m_wndComport.m_nNetPort;
  1881. }
  1882. CHAR chDevTypeID[MAX_ID + 1] = {0};
  1883. // 获取设备类型ID
  1884. int nRet = CDBInterface::GetInstancePtr()->GetDevTypeID((char *)(LPCTSTR)m_wndDevice.m_strDevTypeName, chDevTypeID);
  1885. if( -1 == nRet )
  1886. {
  1887. return nRet;
  1888. }
  1889. else
  1890. {
  1891. CDBInterface::GetInstancePtr()->EditDevInfo(
  1892. (char *)(LPCTSTR)strOldUid,
  1893. (char *)(LPCTSTR)strNewUid,
  1894. m_wndComport.m_nCommPort,
  1895. m_wndComport.m_nDevAddr,
  1896. (char *)(LPCTSTR)m_wndComport.m_strDevName,
  1897. atoi(chDevTypeID),
  1898. m_wndComport.m_nRate,
  1899. m_wndComport.m_nDataBit,
  1900. m_wndComport.m_nStopBit,
  1901. m_wndComport.m_nCheckCode,
  1902. 0,
  1903. inet_ntoa(*(struct in_addr *)&nIP),
  1904. m_wndComport.m_nNetPort,
  1905. m_wndComport.m_nCommunicateMode,
  1906. m_wndDevice.m_nCollectDev,
  1907. m_wndDevice.m_nProtocolType,
  1908. m_wndComport.m_nTimeout,
  1909. m_wndDevice.m_nDevEnable,
  1910. (char *)(LPCTSTR)m_wndDevice.m_strProtocolName,
  1911. (char *)(LPCTSTR)m_wndDevice.m_strIniName,
  1912. (char *)(LPCTSTR)m_wndComport.m_strDevArea,
  1913. //(char *)(LPCTSTR)m_wndDevice.m_strReserved1,
  1914. (char *)(LPCTSTR)m_wndDevice.m_strReserved2,
  1915. (char *)(LPCTSTR)m_wndDevice.m_strReserved3,
  1916. (char *)(LPCTSTR)m_wndDevice.m_strReserved4,
  1917. (char *)(LPCTSTR)m_wndDevice.m_strReserved5,
  1918. (char *)(LPCTSTR)m_wndComport.m_strReserved6,
  1919. (char *)(LPCTSTR)m_wndComport.m_strReserved7,
  1920. (char *)(LPCTSTR)m_wndComport.m_strReserved8,
  1921. (char *)(LPCTSTR)m_wndComport.m_strReserved9,
  1922. (char *)(LPCTSTR)m_wndComport.m_strReserved10,
  1923. m_wndDevice.m_nReserved1,
  1924. m_wndDevice.m_nReserved2,
  1925. m_wndDevice.m_nReserved3,
  1926. m_wndDevice.m_nReserved4,
  1927. m_wndDevice.m_nReserved5,
  1928. m_wndComport.m_nReserved6,
  1929. m_wndComport.m_nReserved7,
  1930. m_wndComport.m_nReserved8,
  1931. m_wndComport.m_nReserved9,
  1932. m_wndComport.m_nReserved10,
  1933. (int)m_wndDevice.m_bReserved1,
  1934. (int)m_wndDevice.m_bReserved2,
  1935. (int)m_wndDevice.m_bReserved3,
  1936. (int)m_wndDevice.m_bReserved4,
  1937. (int)m_wndDevice.m_bReserved5,
  1938. (int)m_wndComport.m_bReserved6,
  1939. (int)m_wndComport.m_bReserved7,
  1940. (int)m_wndComport.m_bReserved8,
  1941. (int)m_wndComport.m_bReserved9,
  1942. (int)m_wndComport.m_bReserved10
  1943. );
  1944. }
  1945. CString sContent;
  1946. sContent.Format("编辑设备< %s >",m_wndComport.m_strDevName.TrimRight() );
  1947. CDBInterface::GetInstancePtr()->InsertLogRecord( LOG_DEV_EDIT,0,"",(char *)(LPCTSTR)sContent );
  1948. pDevicesManager->SendNoticeToServer( CMD_NOTICE_READ_DB_DEV,CMD_OPERATE_EDIT,"",m_wndComport.m_strUID,0,"64320" );
  1949. }
  1950. m_wndTree.SetItemText(hSelectedItem, pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_strName);
  1951. Invalidate(FALSE);
  1952. return 0;
  1953. }
  1954. bool CMainFrame::ShowView(void)
  1955. {
  1956. HTREEITEM hSelectedItem = m_wndTree.GetSelectedItem();
  1957. HTREEITEM hItem;
  1958. int i;
  1959. m_hCurrent = hSelectedItem;
  1960. //如果是视图
  1961. char szPicDir[MAX_PATH] = {0};
  1962. CString strTempDir = "", strPicFile;
  1963. strcpy(szPicDir, g_strDirectory);
  1964. strcat(szPicDir, "\\");
  1965. strcat(szPicDir, _PICTUREDIR);
  1966. hItem = m_wndTree.GetParentItem( hSelectedItem );
  1967. while( hItem != NULL )
  1968. {
  1969. if( hItem == m_hMonitor )
  1970. {
  1971. CString strSelect = m_wndTree.GetItemText( hSelectedItem );
  1972. if( !strTempDir.Compare("") )
  1973. {
  1974. strPicFile += strSelect;
  1975. }
  1976. else
  1977. {
  1978. strPicFile += strTempDir;
  1979. //strPicFile += "\\";//chn modify 12.28
  1980. strPicFile += strSelect;
  1981. }
  1982. AddIDEView( strSelect, CString(szPicDir) + strPicFile + ".view" );
  1983. return true;
  1984. }
  1985. else
  1986. {
  1987. CString str = m_wndTree.GetItemText( hItem );
  1988. strTempDir = str + "\\" + strTempDir;
  1989. hItem = m_wndTree.GetParentItem( hItem );
  1990. }
  1991. }
  1992. // 如果是脚本
  1993. for (i = 0; i < MAX_SCRIPT_NUM; i++)
  1994. {
  1995. if (m_hScriptGroup[i] == hSelectedItem)
  1996. {
  1997. CString scriptFile;
  1998. scriptFile = _SCRIPTDIR;
  1999. scriptFile = g_strDirectory + CString("\\") + scriptFile + m_wndTree.GetItemText(hSelectedItem) + ".srp";
  2000. CString strScript;
  2001. strScript.Format("%s\\ScriptEdit.exe", g_strDirectory);
  2002. ShellExecute(NULL,"open", (char *)(LPCTSTR)strScript, scriptFile, NULL, SW_SHOWNORMAL);
  2003. return true;
  2004. }
  2005. }
  2006. // 报警联动
  2007. if (hSelectedItem == m_hActionWithAlarm)
  2008. {
  2009. CDlg_ActionWithAlarm dlg;
  2010. dlg.DoModal();
  2011. }
  2012. // 系统参数
  2013. if (hSelectedItem == m_hSystem)
  2014. {
  2015. SetRunPara();
  2016. }
  2017. // 变量编辑
  2018. else if (m_hAnalog == hSelectedItem)
  2019. {
  2020. if( g_nIsDemo == 0 )
  2021. {
  2022. CAnalogDlg dlg;
  2023. dlg.DoModal();
  2024. }
  2025. }
  2026. else // 设备属性设置xs
  2027. {
  2028. if( g_nIsDemo == 0 )
  2029. {
  2030. int nRet = ShowDevProperty(hSelectedItem);
  2031. if( nRet == 1 )
  2032. {
  2033. if( hSelectedItem )
  2034. {
  2035. // 这里一删除就报异常,只能先注释,待解决 for Jesse 100106
  2036. //m_wndTree.DeleteItem( m_hCurrent );//hSelectedItem
  2037. }
  2038. }
  2039. pDevicesManager->Store(g_strDirectory);
  2040. }
  2041. }
  2042. return true;
  2043. }
  2044. BOOL CMainFrame::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
  2045. {
  2046. // TODO: 在此添加专用代码和/或调用基类
  2047. LPNMHDR pNmhdr = (LPNMHDR)lParam;
  2048. int i, j;
  2049. //if( m_bShutdown ) return FALSE; //chn dele
  2050. int idCtrl = LOWORD(wParam);
  2051. if( idCtrl == IDD_TREE_LEFT ) // Is my tree's id?
  2052. {
  2053. CPoint point;
  2054. ::GetCursorPos(&point);
  2055. m_wndTree.ScreenToClient(&point);
  2056. switch( pNmhdr->code )
  2057. {
  2058. case NM_CLICK:
  2059. {
  2060. // Get Click item's
  2061. UINT uFlags;
  2062. HTREEITEM hItem = m_wndTree.HitTest(point, &uFlags);
  2063. if((hItem != NULL) && (TVHT_ONITEM & uFlags))
  2064. {
  2065. m_wndTree.SelectItem(hItem);
  2066. }
  2067. return true;//Already process the notify
  2068. }
  2069. case NM_RCLICK:
  2070. {
  2071. // Get RightClick item's
  2072. if( g_bStartRun ) return true;
  2073. UINT uFlags;
  2074. HTREEITEM hItem = m_wndTree.HitTest(point, &uFlags);
  2075. m_wndTree.SelectItem(hItem);
  2076. if((hItem != NULL) && (TVHT_ONITEM & uFlags))
  2077. {
  2078. GetCursorPos(&m_mousePoint);
  2079. HTREEITEM hSelectedItem = m_wndTree.GetSelectedItem();
  2080. //新建设备
  2081. if( hSelectedItem == m_hIOGroup )
  2082. {
  2083. CMenu menu;
  2084. menu.LoadMenu(IDR_MENU_ADDDEVICE);
  2085. menu.GetSubMenu(0)->TrackPopupMenu(TPM_LEFTALIGN,m_mousePoint.x,m_mousePoint.y,this);
  2086. }
  2087. //删除设备
  2088. int nChannelIndex = -1, nDeviceIndex = -1;
  2089. int nChannelSize = pDevicesManager->m_channels.GetSize();
  2090. // 串口设备属性设置
  2091. for (i = 0; i < nChannelSize; i++)
  2092. {
  2093. #if 0 // 删除COM时有BUG,待解决 for Jesse 091104
  2094. if( m_hSerialGroup[i] == hSelectedItem )
  2095. {
  2096. CMenu menu;
  2097. menu.LoadMenu(IDR_MENU_DELDEVICE);
  2098. menu.GetSubMenu(0)->TrackPopupMenu(TPM_LEFTALIGN,m_mousePoint.x,m_mousePoint.y,this);
  2099. return true;
  2100. }
  2101. #endif
  2102. int nDeviceSize = pDevicesManager->m_channels[i]->m_Devices.GetSize();
  2103. for( j = 0; j < nDeviceSize; j++)
  2104. {
  2105. if (m_hSerialDev[i][j]==hSelectedItem)
  2106. {
  2107. CMenu menu;
  2108. menu.LoadMenu(IDR_MENU_DELDEVICE);
  2109. menu.GetSubMenu(0)->TrackPopupMenu(TPM_LEFTALIGN,m_mousePoint.x,m_mousePoint.y,this);
  2110. return true;
  2111. }
  2112. if( m_hNetworkDev[j] == hSelectedItem &&
  2113. pDevicesManager->m_channels[i]->m_nCommunicateType == 1 )
  2114. {
  2115. CMenu menu;
  2116. menu.LoadMenu(IDR_MENU_DELDEVICE);
  2117. menu.GetSubMenu(0)->TrackPopupMenu(TPM_LEFTALIGN,m_mousePoint.x,m_mousePoint.y,this);
  2118. return true;
  2119. }
  2120. }
  2121. }
  2122. //新建或删除监控画面
  2123. if (hSelectedItem == m_hMonitor)
  2124. {
  2125. CMenu menu;
  2126. menu.LoadMenu(IDR_MENU_ADDVIEW);
  2127. menu.GetSubMenu(1)->TrackPopupMenu(TPM_LEFTALIGN,m_mousePoint.x,m_mousePoint.y,this);
  2128. }
  2129. else
  2130. {
  2131. if( FindTreeItem( hSelectedItem, m_hMonitor ) )
  2132. {
  2133. CMenu menu;
  2134. menu.LoadMenu(IDR_MENU_ADDVIEW);
  2135. menu.GetSubMenu(0)->TrackPopupMenu(TPM_LEFTALIGN,m_mousePoint.x,m_mousePoint.y,this);
  2136. }
  2137. }
  2138. //设定脚本
  2139. for (i = 0; i < MAX_SCRIPT_NUM; i++)
  2140. {
  2141. if (m_hScriptGroup[i] == hSelectedItem)
  2142. {
  2143. CMenu menu;
  2144. menu.LoadMenu(IDR_MENU_SETSCRIPT);
  2145. menu.GetSubMenu(0)->TrackPopupMenu(TPM_LEFTALIGN,m_mousePoint.x,m_mousePoint.y,this);
  2146. }
  2147. }
  2148. //新建脚本
  2149. if (hSelectedItem == m_hScript)
  2150. {
  2151. CMenu menu;
  2152. menu.LoadMenu(IDR_MENU_ADDSCRIPT);
  2153. menu.GetSubMenu(0)->TrackPopupMenu(TPM_LEFTALIGN,m_mousePoint.x,m_mousePoint.y,this);
  2154. }
  2155. }
  2156. return true;//Already process the notify
  2157. }
  2158. case NM_DBLCLK:
  2159. {
  2160. ShowView();
  2161. return true;
  2162. }
  2163. }
  2164. return false; // no match
  2165. }
  2166. return CMDIAutoHideFrame::OnNotify(wParam, lParam, pResult);
  2167. }
  2168. int CMainFrame::GetFreeSerialTreeItem()
  2169. {
  2170. CString str;
  2171. #if 1
  2172. for( int i = MAX_SERIAL_NUM-1; i >=0 ; i-- )
  2173. {
  2174. //if( m_hSerialGroup[i] == NULL ) break;
  2175. str = m_wndTree.GetItemText(m_hSerialGroup[i]);
  2176. if( str.Compare("") )
  2177. {
  2178. return i+1;
  2179. }
  2180. }
  2181. #else
  2182. for( int i = 0; i < MAX_SERIAL_NUM; i++ )
  2183. {
  2184. //if( m_hSerialGroup[i] == NULL ) break;
  2185. str = m_wndTree.GetItemText(m_hSerialGroup[i]);
  2186. if( !str.Compare("") )
  2187. {
  2188. return i;
  2189. }
  2190. }
  2191. #endif
  2192. return 0;
  2193. }
  2194. int CMainFrame::GetNetworkChannelIndex()
  2195. {
  2196. int i;
  2197. int nChannelNo = -1;
  2198. int nChannelSize = pDevicesManager->m_channels.GetSize();
  2199. for (i = 0; i < nChannelSize; i++)
  2200. {
  2201. // 网络设备,在m_channels中永远只有一个
  2202. if( pDevicesManager->m_channels[i]->m_nCommunicateType == 1 )
  2203. {
  2204. return i;
  2205. }
  2206. }
  2207. return -1;
  2208. }
  2209. int CMainFrame::GetFreeNetworkTreeItem()
  2210. {
  2211. CString str;
  2212. for( int i = 0; i < MAX_NETWORK_NUM; i++ )
  2213. {
  2214. //if( m_hNetworkDev[i] == NULL ) break;
  2215. str = m_wndTree.GetItemText(m_hNetworkDev[i]);
  2216. if( !str.Compare("") )
  2217. {
  2218. return i;
  2219. }
  2220. }
  2221. return -1;
  2222. }
  2223. int CMainFrame::GetIndexSerialTreeItem(CString strSrc)
  2224. {
  2225. CString str;
  2226. for( int i = 0; i < MAX_SERIAL_NUM; i++ )
  2227. {
  2228. //if( m_hSerialGroup[i] == NULL ) break;
  2229. str = m_wndTree.GetItemText(m_hSerialGroup[i]);
  2230. if( !str.Compare(strSrc) )
  2231. {
  2232. return i;
  2233. }
  2234. }
  2235. return -1;
  2236. }
  2237. int CMainFrame::GetIndexNetworkTreeItem(CString strSrc)
  2238. {
  2239. CString str;
  2240. for( int i = 0; i < MAX_NETWORK_NUM; i++ )
  2241. {
  2242. //if( m_hNetworkDev[i] == NULL ) break;
  2243. str = m_wndTree.GetItemText(m_hNetworkDev[i]);
  2244. if( !str.Compare(strSrc) )
  2245. {
  2246. return i;
  2247. }
  2248. }
  2249. return -1;
  2250. }
  2251. int CMainFrame::FinishedAddDevice(int nIsDelete, CString strUid)
  2252. {
  2253. // 加入该设备的参数
  2254. CChannel* pChannel = NULL;
  2255. CDevice* pDev = new CDevice();
  2256. pDev->Create();
  2257. int nIP;
  2258. nIP = htonl(m_wndComport.m_nNetIP);
  2259. // 通信协议(例:Modbus rtu, Modbus Ascii, Modbus tcp)
  2260. pDev->m_nProtocolType = m_wndDevice.m_nProtocolType;
  2261. // 协议动态库名称
  2262. pDev->m_strProtocolName = m_wndDevice.m_strProtocolName;
  2263. // 是否为采集模块
  2264. pDev->m_nIsCollectDev = m_wndDevice.m_nCollectDev;
  2265. // 是否启用设备
  2266. pDev->m_bUsed = m_wndDevice.m_nDevEnable;
  2267. // 设备UID
  2268. if( nIsDelete == 1 && m_wndDevice.m_sUidOld!=m_wndComport.m_strUID )
  2269. pDev->m_strUID = m_wndComport.m_strUID2==""?m_wndComport.m_strUID:m_wndComport.m_strUID2;
  2270. else
  2271. pDev->m_strUID = m_wndComport.m_strUID;
  2272. // 设备名称
  2273. pDev->m_strName = m_wndComport.m_strDevName.Trim();
  2274. // 设备类型
  2275. pDev->m_strType = m_wndDevice.m_strDevTypeName.Trim();
  2276. // 设备地址
  2277. pDev->m_Address = (BYTE)m_wndComport.m_nDevAddr;
  2278. // 驱动名称(例:UPS、空调)
  2279. pDev->m_strDevDriveName = m_wndDevice.m_strDevDriveName;
  2280. // 设备厂家名称
  2281. pDev->m_strDevFactoryName = m_wndDevice.m_strDevFactoryName;
  2282. // 通讯超时
  2283. pDev->m_nTimeout = m_wndComport.m_nTimeout;
  2284. // 网络设备IP
  2285. pDev->m_strDevIP = inet_ntoa(*(struct in_addr *)&nIP);
  2286. // 网络设备通信端口
  2287. pDev->m_nNetPort = m_wndComport.m_nNetPort;
  2288. // 配置文件名称
  2289. pDev->m_strIniName = m_wndDevice.m_strIniName;
  2290. // 预留1 设备所属区域
  2291. pDev->m_strReserved1 = m_wndComport.m_strDevArea.Trim();
  2292. // 预留2
  2293. pDev->m_strReserved2 = m_wndDevice.m_strReserved2;
  2294. // 预留3
  2295. pDev->m_strReserved3 = m_wndDevice.m_strReserved3;
  2296. // 预留4
  2297. pDev->m_strReserved4 = m_wndDevice.m_strReserved4;
  2298. // 预留5
  2299. pDev->m_strReserved5 = m_wndDevice.m_strReserved5;
  2300. // 预留6
  2301. pDev->m_strReserved6 = m_wndComport.m_strReserved6;
  2302. // 预留7
  2303. pDev->m_strReserved7 = m_wndComport.m_strReserved7;
  2304. // 预留8
  2305. pDev->m_strReserved8 = m_wndComport.m_strReserved8;
  2306. // 预留9
  2307. pDev->m_strReserved9 = m_wndComport.m_strReserved9;
  2308. // 预留10
  2309. pDev->m_strReserved10 = m_wndComport.m_strReserved10;
  2310. // 预留1
  2311. pDev->m_nReserved1 = m_wndDevice.m_nReserved1;
  2312. // 预留2
  2313. pDev->m_nReserved2 = m_wndDevice.m_nReserved2;
  2314. // 预留3
  2315. pDev->m_nReserved3 = m_wndDevice.m_nReserved3;
  2316. // 预留4
  2317. pDev->m_nReserved4 = m_wndDevice.m_nReserved4;
  2318. // 预留5
  2319. pDev->m_nReserved5 = m_wndDevice.m_nReserved5;
  2320. // 预留6
  2321. pDev->m_nReserved6 = m_wndComport.m_nReserved6;
  2322. // 预留7
  2323. pDev->m_nReserved7 = m_wndComport.m_nReserved7;
  2324. // 预留8
  2325. pDev->m_nReserved8 = m_wndComport.m_nReserved8;
  2326. // 预留9
  2327. pDev->m_nReserved9 = m_wndComport.m_nReserved9;
  2328. // 预留10
  2329. pDev->m_nReserved10 = m_wndComport.m_nReserved10;
  2330. // 预留1
  2331. pDev->m_bReserved1 = m_wndDevice.m_bReserved1;
  2332. // 预留2
  2333. pDev->m_bReserved2 = m_wndDevice.m_bReserved2;
  2334. // 预留3
  2335. pDev->m_bReserved3 = m_wndDevice.m_bReserved3;
  2336. // 预留4
  2337. pDev->m_bReserved4 = m_wndDevice.m_bReserved4;
  2338. // 预留5
  2339. pDev->m_bReserved5 = m_wndDevice.m_bReserved5;
  2340. // 预留6
  2341. pDev->m_bReserved6 = m_wndComport.m_bReserved6;
  2342. // 预留7
  2343. pDev->m_bReserved7 = m_wndComport.m_bReserved7;
  2344. // 预留8
  2345. pDev->m_bReserved8 = m_wndComport.m_bReserved8;
  2346. // 预留9
  2347. pDev->m_bReserved9 = m_wndComport.m_bReserved9;
  2348. // 预留10
  2349. pDev->m_bReserved10 = m_wndComport.m_bReserved10;
  2350. CString strCommPort;
  2351. int nIndex, nFreeIndex;
  2352. int nChannelSize;
  2353. int nDeviceSize;
  2354. CHAR szMaxID[MAX_ID + 1] = {0};
  2355. CHAR szDevTypeID[MAX_ID + 1] = {0};
  2356. // 获取t_dev_property设备属性表字段ID的最大值
  2357. int nRet = CDBInterface::GetInstancePtr()->GetMaxID("t_dev_property", "id", szMaxID);
  2358. if( -1 == nRet )
  2359. {
  2360. pDev->Destroy();
  2361. delete pDev;
  2362. return -1;
  2363. }
  2364. int nID;
  2365. if( atoi(szMaxID) > 0 )
  2366. {
  2367. nID = atoi(szMaxID) + 1;
  2368. }
  2369. else if( atoi(szMaxID) == 0 )
  2370. {
  2371. nID = 1;
  2372. }
  2373. // 获取设备类型ID
  2374. CDBInterface::GetInstancePtr()->GetDevTypeID((char *)(LPCTSTR)m_wndDevice.m_strDevTypeName, szDevTypeID);
  2375. if( !m_wndComport.m_strDevName.Compare("") )
  2376. {
  2377. MessageBox(g_strDevNumCannotBlank,g_strTip,MB_ICONWARNING);
  2378. pDev->Destroy();
  2379. delete pDev;
  2380. return 0;
  2381. }
  2382. //检查合法值
  2383. if( m_wndDevice.m_operation == CDlgDevice::NEW )
  2384. {
  2385. CHAR szDevName[MAX_DESC + 1] = {0};
  2386. CHAR szDevUID[MAX_DESC + 1] = {0};
  2387. int nRet = CDBInterface::GetInstancePtr()->GetDevName((char *)(LPCTSTR)m_wndComport.m_strUID, szDevName);
  2388. if( nRet > 0 )
  2389. {
  2390. MessageBox(g_strDevUidExist,g_strTip,MB_ICONWARNING);
  2391. pDev->Destroy();
  2392. delete pDev;
  2393. return 0;
  2394. }
  2395. nRet = CDBInterface::GetInstancePtr()->GetDevUID( (char *)(LPCTSTR)m_wndComport.m_strDevName, szDevUID );
  2396. if( nRet > 0 )
  2397. {
  2398. MessageBox(g_strDevNameExist,g_strTip,MB_ICONWARNING);
  2399. pDev->Destroy();
  2400. delete pDev;
  2401. return 0;
  2402. }
  2403. }
  2404. // 串口设备
  2405. if( m_wndComport.m_nCommunicateMode == 0 )
  2406. {
  2407. strCommPort.Format("COM%d", m_wndComport.m_nCommPort);
  2408. nIndex = GetIndexSerialTreeItem(strCommPort);//得到COM的序列号
  2409. if( nIndex == -1 )
  2410. {
  2411. nFreeIndex = GetFreeSerialTreeItem();
  2412. CChannel* pComport = new CChannel();
  2413. //CSerial* pComport = new CSerial();
  2414. // 串行端口
  2415. pComport->m_strPort = strCommPort.Trim();
  2416. // 串行端口地址
  2417. pComport->m_nAddr = m_wndComport.m_nDevAddr;
  2418. // 波特率
  2419. pComport->m_nBaudRate = m_wndComport.m_nRate; // 1200;2400;4800;9600;14400;19200;38400;57600;115200;128000;256000
  2420. // 数据位
  2421. pComport->m_nByteSize = m_wndComport.m_nDataBit; // 0-1=7,8
  2422. // 检验位
  2423. pComport->m_nParity = m_wndComport.m_nCheckCode; // 0-4=no,odd,even,mark
  2424. // 停止位
  2425. pComport->m_nStopBits = m_wndComport.m_nStopBit; // 0-2=1,1.5,2
  2426. pDevicesManager->m_channels.Add(pComport);
  2427. nChannelSize = pDevicesManager->m_channels.GetSize();
  2428. pChannel = pDevicesManager->m_channels[nChannelSize - 1];
  2429. pChannel->m_strName = strCommPort.Trim();
  2430. pChannel->m_nCommunicateType = m_wndComport.m_nCommunicateMode;
  2431. nDeviceSize = pChannel->m_Devices.GetSize();
  2432. //if( m_hCurrent )
  2433. // m_wndTree.DeleteItem( m_hCurrent );
  2434. m_hSerialGroup[nFreeIndex] = m_wndTree.InsertItem(strCommPort, 4, 4, m_hSerial);
  2435. m_hSerialDev[nFreeIndex][nDeviceSize] = m_wndTree.InsertItem(m_wndComport.m_strDevName, 4, 4, m_hSerialGroup[nFreeIndex]);
  2436. }
  2437. else
  2438. {
  2439. nChannelSize = pDevicesManager->m_channels.GetSize();
  2440. for( int i = 0; i < nChannelSize; i++ )
  2441. {
  2442. CChannel* pCommPort =pDevicesManager->m_channels[i];
  2443. //CSerial *pCommPort = (CSerial *)(pDevicesManager->m_channels[i]);
  2444. if( ( !pCommPort->m_strPort.Compare(strCommPort) ) && pCommPort->m_Devices.GetSize() > 0 )
  2445. {
  2446. nDeviceSize = pCommPort->m_Devices.GetSize();
  2447. for( int j = 0; j < nDeviceSize; j++ )
  2448. {
  2449. if( (int)pCommPort->m_Devices[j]->m_Address == m_wndComport.m_nDevAddr )
  2450. {
  2451. MessageBox(g_strSerialPortInUse,g_strTip,MB_ICONWARNING);
  2452. pDev->Destroy();
  2453. delete pDev;
  2454. return 0;
  2455. }
  2456. }
  2457. }
  2458. }
  2459. for( int i = 0; i < nChannelSize; i++ )
  2460. {
  2461. CChannel* pCommPort = pDevicesManager->m_channels[i];
  2462. //CSerial *pCommPort = (CSerial *)(pDevicesManager->m_channels[i]);
  2463. if( !pCommPort->m_strPort.Compare(strCommPort) )
  2464. {
  2465. nDeviceSize = pCommPort->m_Devices.GetSize();
  2466. pChannel = pDevicesManager->m_channels[i];
  2467. //nDeviceSize = pChannel->m_Devices.GetSize();
  2468. break;
  2469. }
  2470. }
  2471. //pChannel = pDevicesManager->m_channels[nChannelSize - 1];
  2472. //nDeviceSize = pChannel->m_Devices.GetSize();
  2473. m_hSerialDev[nIndex][nDeviceSize] = m_wndTree.InsertItem(m_wndComport.m_strDevName, 4, 4, m_hSerialGroup[nIndex]);
  2474. }
  2475. if( pChannel != NULL )
  2476. {
  2477. pDev->m_pChannel = pChannel;
  2478. pChannel->m_Devices.Add(pDev);
  2479. }
  2480. }
  2481. // 网络设备
  2482. else
  2483. {
  2484. int nChannelIndex;
  2485. // 得到m_channels数组中网络设备的索引,有且只有一个
  2486. nIndex = GetIndexNetworkTreeItem( m_wndComport.m_strDevName );
  2487. if( nIndex == -1 )
  2488. {
  2489. if( m_wndComport.m_nNetIP == 0 )
  2490. {
  2491. MessageBox(g_strIPNotBlank, g_strTip, MB_ICONWARNING);
  2492. pDev->Destroy();
  2493. delete pDev;
  2494. return 0;
  2495. }
  2496. if( m_wndComport.m_nNetPort == 0 )
  2497. {
  2498. MessageBox(g_strComcanNot0, g_strTip, MB_ICONWARNING);
  2499. pDev->Destroy();
  2500. delete pDev;
  2501. return 0;
  2502. }
  2503. nChannelIndex = GetNetworkChannelIndex();
  2504. if( nChannelIndex == -1 )
  2505. {
  2506. CNetwork *pNetwork = new CNetwork();
  2507. pNetwork->m_strName = g_strNetDev;
  2508. pDevicesManager->m_channels.Add(pNetwork);
  2509. nChannelIndex = pDevicesManager->m_channels.GetSize() - 1;
  2510. }
  2511. else
  2512. {
  2513. pChannel = pDevicesManager->m_channels[nChannelIndex];
  2514. for( int j = 0; j < pChannel->m_Devices.GetSize(); j ++ )
  2515. {
  2516. if( !m_wndDevice.m_bIsStu2000 )
  2517. {
  2518. if( !(pChannel->m_Devices[j]->m_strDevIP.Compare(inet_ntoa(*(struct in_addr *)&nIP))) &&
  2519. (pChannel->m_Devices[j]->m_nNetPort == m_wndComport.m_nNetPort ) )
  2520. {
  2521. MessageBox(g_strIPConflict, g_strTip, MB_ICONWARNING);
  2522. pDev->Destroy();
  2523. delete pDev;
  2524. return 0;
  2525. }
  2526. }
  2527. else
  2528. {
  2529. if( !(pChannel->m_Devices[j]->m_strDevIP.Compare(inet_ntoa(*(struct in_addr *)&nIP))) &&
  2530. (pChannel->m_Devices[j]->m_nNetPort == m_wndComport.m_nNetPort ) &&
  2531. ((int)pChannel->m_Devices[j]->m_Address == m_wndComport.m_nDevAddr ) )
  2532. {
  2533. MessageBox(g_strIPConflict, g_strTip, MB_ICONWARNING);
  2534. pDev->Destroy();
  2535. delete pDev;
  2536. return 0;
  2537. }
  2538. }
  2539. }
  2540. }
  2541. pChannel = pDevicesManager->m_channels[nChannelIndex];
  2542. pChannel->m_nCommunicateType = m_wndComport.m_nCommunicateMode;
  2543. nDeviceSize = pChannel->m_Devices.GetSize();
  2544. nFreeIndex = GetFreeNetworkTreeItem();
  2545. m_hNetworkDev[nFreeIndex] = m_wndTree.InsertItem( m_wndComport.m_strDevName, 2, 2, m_hEtherNet);
  2546. pDev->m_pChannel = pChannel;
  2547. pChannel->m_Devices.Add(pDev);
  2548. }
  2549. else
  2550. {
  2551. MessageBox(g_strDevNameExist,g_strTip,MB_ICONWARNING);
  2552. pDev->Destroy();
  2553. delete pDev;
  2554. return 0;
  2555. }
  2556. }
  2557. if( nIsDelete == 1 )
  2558. {
  2559. //删除数据库数据
  2560. CDBInterface::GetInstancePtr()->DeleteDevInfo((char *)(LPCTSTR)strUid);
  2561. }
  2562. // 插入设备信息
  2563. CDBInterface::GetInstancePtr()->InsertDevInfo(
  2564. nID,
  2565. (char *)(LPCTSTR)pDev->m_strUID,
  2566. m_wndComport.m_nCommPort,
  2567. m_wndComport.m_nDevAddr,
  2568. (char *)(LPCTSTR)m_wndComport.m_strDevName,
  2569. atoi(szDevTypeID),
  2570. m_wndComport.m_nRate,
  2571. m_wndComport.m_nDataBit,
  2572. m_wndComport.m_nStopBit,
  2573. m_wndComport.m_nCheckCode,
  2574. 0,
  2575. inet_ntoa( *(struct in_addr *)&nIP ),
  2576. m_wndComport.m_nNetPort,
  2577. m_wndComport.m_nCommunicateMode,
  2578. m_wndDevice.m_nCollectDev,
  2579. m_wndDevice.m_nProtocolType,
  2580. m_wndComport.m_nTimeout,
  2581. m_wndDevice.m_nDevEnable,
  2582. (char *)(LPCTSTR)m_wndDevice.m_strProtocolName,
  2583. (char *)(LPCTSTR)m_wndDevice.m_strIniName,
  2584. (char *)(LPCTSTR)pDev->m_strReserved1,
  2585. //(char *)(LPCTSTR)m_wndDevice.m_strReserved1,
  2586. (char *)(LPCTSTR)m_wndDevice.m_strReserved2,
  2587. (char *)(LPCTSTR)m_wndDevice.m_strReserved3,
  2588. (char *)(LPCTSTR)m_wndDevice.m_strReserved4,
  2589. (char *)(LPCTSTR)m_wndDevice.m_strReserved5,
  2590. (char *)(LPCTSTR)m_wndComport.m_strReserved6,
  2591. (char *)(LPCTSTR)m_wndComport.m_strReserved7,
  2592. (char *)(LPCTSTR)m_wndComport.m_strReserved8,
  2593. (char *)(LPCTSTR)m_wndComport.m_strReserved9,
  2594. (char *)(LPCTSTR)m_wndComport.m_strReserved10,
  2595. m_wndDevice.m_nReserved1,
  2596. m_wndDevice.m_nReserved2,
  2597. m_wndDevice.m_nReserved3,
  2598. m_wndDevice.m_nReserved4,
  2599. m_wndDevice.m_nReserved5,
  2600. m_wndComport.m_nReserved6,
  2601. m_wndComport.m_nReserved7,
  2602. m_wndComport.m_nReserved8,
  2603. m_wndComport.m_nReserved9,
  2604. m_wndComport.m_nReserved10,
  2605. (int)m_wndDevice.m_bReserved1,
  2606. (int)m_wndDevice.m_bReserved2,
  2607. (int)m_wndDevice.m_bReserved3,
  2608. (int)m_wndDevice.m_bReserved4,
  2609. (int)m_wndDevice.m_bReserved5,
  2610. (int)m_wndComport.m_bReserved6,
  2611. (int)m_wndComport.m_bReserved7,
  2612. (int)m_wndComport.m_bReserved8,
  2613. (int)m_wndComport.m_bReserved9,
  2614. (int)m_wndComport.m_bReserved10
  2615. );
  2616. return 1;
  2617. }
  2618. void CMainFrame::AddDevice()
  2619. {
  2620. CWizard MyWizard(g_strMywizard,this,1);
  2621. MyWizard.AddPage( &m_wndDevice );
  2622. MyWizard.AddPage( &m_wndComport );
  2623. MyWizard.SetWizardMode();
  2624. MyWizard.SetActivePage( &m_wndDevice );
  2625. m_wndDevice.m_operation = CDlgDevice::NEW;
  2626. void* pType = NULL;
  2627. if( MyWizard.DoModal() == ID_WIZFINISH )
  2628. {
  2629. int nRet = FinishedAddDevice(0, "");
  2630. if( -1!=nRet && 0!=nRet )
  2631. {
  2632. CString sContent;
  2633. sContent.Format("%s %s< %s >",g_strAdd,g_strDevice1,m_wndComport.m_strDevName );
  2634. CDBInterface::GetInstancePtr()->InsertLogRecord( LOG_DEV_ADD,0,"",(char *)(LPCTSTR)sContent );
  2635. pDevicesManager->SendNoticeToServer( CMD_NOTICE_READ_DB_DEV,CMD_OPERATE_ADD,"",m_wndComport.m_strUID,0,"64320" );
  2636. MyWizard.RemovePage( &m_wndDevice );
  2637. MyWizard.RemovePage( &m_wndComport );
  2638. }
  2639. if( 0==nRet )
  2640. {
  2641. MyWizard.RemovePage( &m_wndDevice );
  2642. MyWizard.RemovePage( &m_wndComport );
  2643. AddDevice();
  2644. }
  2645. }
  2646. }
  2647. void CMainFrame::OnAdddevoce()
  2648. {
  2649. // TODO: 在此添加命令处理程序代码
  2650. AddDevice();
  2651. }
  2652. void CMainFrame::OnUpdateAdddevoce(CCmdUI *pCmdUI)
  2653. {
  2654. // TODO: 在此添加命令更新用户界面处理程序代码
  2655. }
  2656. void CMainFrame::OnZuTaiAdd()
  2657. {
  2658. if( !m_pDlgZuTaiAdd->m_bIsExistExcel )
  2659. {
  2660. MessageBox( "没有安装Excel软件,组态功能不能用!","提示" );
  2661. return;
  2662. }
  2663. CDlg_Pwd Dlg_Pwd;
  2664. Dlg_Pwd.m_nShowType = 2;
  2665. if( Dlg_Pwd.DoModal()!=IDOK )
  2666. return;
  2667. m_pDlgZuTaiAdd->ReadResource();
  2668. m_pDlgZuTaiAdd->ShowWindow( SW_SHOW );
  2669. }
  2670. void CMainFrame::OnUpdateZuTaiAdd(CCmdUI *pCmdUI)
  2671. {
  2672. }
  2673. void CMainFrame::OnDeleteport()
  2674. {
  2675. // TODO: 在此添加命令处理程序代码
  2676. }
  2677. void CMainFrame::OnUpdateDeleteport(CCmdUI *pCmdUI)
  2678. {
  2679. // TODO: 在此添加命令更新用户界面处理程序代码
  2680. }
  2681. void CMainFrame::OnAddPort()
  2682. {
  2683. // TODO: 在此添加命令处理程序代码
  2684. }
  2685. void CMainFrame::OnUpdateAddPort(CCmdUI *pCmdUI)
  2686. {
  2687. // TODO: 在此添加命令更新用户界面处理程序代码
  2688. }
  2689. void CMainFrame::OnAddScript()
  2690. {
  2691. // TODO: 在此添加命令处理程序代码
  2692. CScriptSetDlg dlg;
  2693. if (dlg.DoModal() == IDOK)
  2694. {
  2695. m_hScriptGroup[m_nScripts++] = m_wndTree.InsertItem(dlg.m_strName,1,1,m_hScript);
  2696. CString strFileName = dlg.m_strName;
  2697. strFileName = CString(g_strDirectory) + "\\" + _SCRIPTDIR + strFileName;
  2698. strFileName = strFileName + ".srp";
  2699. CFile fileSpt;
  2700. if (fileSpt.Open(strFileName, CFile::modeCreate)) // | CFile::modeWrite
  2701. {
  2702. fileSpt.Close();
  2703. }
  2704. strFileName.Replace(".srp", ".con");
  2705. if ( dlg.m_bUsed )
  2706. {
  2707. WritePrivateProfileString("RUNPARA", "USE", "1", strFileName);
  2708. }
  2709. else
  2710. {
  2711. WritePrivateProfileString("RUNPARA", "USE", "0", strFileName);
  2712. }
  2713. WritePrivateProfileString("RUNPARA", "CONDITON", dlg.m_strCondition, strFileName);
  2714. char tmp[10];
  2715. sprintf(tmp, "%d", dlg.m_nType);
  2716. WritePrivateProfileString("RUNPARA", "TYPE", tmp, strFileName);
  2717. sprintf(tmp, "%d", dlg.m_nCircle);
  2718. WritePrivateProfileString("RUNPARA", "CIRCLE", tmp, strFileName);
  2719. }
  2720. }
  2721. void CMainFrame::OnUpdateAddScript(CCmdUI *pCmdUI)
  2722. {
  2723. // TODO: 在此添加命令更新用户界面处理程序代码
  2724. }
  2725. void CMainFrame::HideRunBar()
  2726. {
  2727. //m_wndRunToolBar.ShowWindow(SW_HIDE);
  2728. }
  2729. void CMainFrame::OnAddview()
  2730. {
  2731. // TODO: 在此添加命令处理程序代码
  2732. CViewNameDlg dlg;
  2733. if (dlg.DoModal() == IDOK)
  2734. {
  2735. if( dlg.m_strViewName.Compare("")==0 )
  2736. {
  2737. MessageBox(g_strMonitorNameIsBlank, g_strTip, MB_ICONINFORMATION);
  2738. return;
  2739. }
  2740. char szPicDir[MAX_PATH] = {0};
  2741. CString strTempDir = "";
  2742. strcpy(szPicDir, g_strDirectory);
  2743. strcat(szPicDir, "\\");
  2744. strcat(szPicDir, _PICTUREDIR);
  2745. int cx=GetSystemMetrics(SM_CXSCREEN)-10;
  2746. int cy=GetSystemMetrics(SM_CYSCREEN)-100;
  2747. CGraph* pic=new CGraph(CSize(cx, cy));
  2748. pic->m_strPicFile = CString(szPicDir);
  2749. HTREEITEM hSelectedItem = m_wndTree.GetSelectedItem();
  2750. HTREEITEM hItem;
  2751. m_wndTree.InsertItem(dlg.m_strViewName, 1, 1, hSelectedItem);
  2752. if( hSelectedItem == m_hMonitor )
  2753. {
  2754. pic->m_strPicFile = pic->m_strPicFile + dlg.m_strViewName + ".view";
  2755. pic->Store();
  2756. }
  2757. else
  2758. {
  2759. hItem = m_wndTree.GetParentItem( hSelectedItem );
  2760. while( hItem != NULL )
  2761. {
  2762. if( hItem == m_hMonitor )
  2763. {
  2764. CString strSelect = m_wndTree.GetItemText( hSelectedItem );
  2765. if( !strTempDir.Compare("") )
  2766. {
  2767. pic->m_strPicFile += strSelect;
  2768. }
  2769. else
  2770. {
  2771. pic->m_strPicFile += strTempDir;
  2772. pic->m_strPicFile += "\\";
  2773. pic->m_strPicFile += strSelect;
  2774. }
  2775. if( !PathFileExists(pic->m_strPicFile) )
  2776. {
  2777. SECURITY_ATTRIBUTES sa;
  2778. sa.nLength = sizeof(SECURITY_ATTRIBUTES);
  2779. sa.lpSecurityDescriptor = NULL;
  2780. sa.bInheritHandle = 0;
  2781. int nRet = CreateDirectory(pic->m_strPicFile, &sa);
  2782. if( !nRet )
  2783. {
  2784. MessageBox(g_strCannotCreateDirecitory,g_strTip,MB_ICONWARNING);
  2785. delete pic;
  2786. return;
  2787. }
  2788. }
  2789. pic->m_strPicFile = pic->m_strPicFile + "\\" + dlg.m_strViewName + ".view";
  2790. pic->Store();
  2791. delete pic;
  2792. return;
  2793. }
  2794. else
  2795. {
  2796. CString str = m_wndTree.GetItemText( hItem );
  2797. strTempDir = str + "\\" + strTempDir;
  2798. hItem = m_wndTree.GetParentItem( hItem );
  2799. }
  2800. }
  2801. }
  2802. delete pic;
  2803. CString sContent;
  2804. sContent.Format("添加画面< %s >",dlg.m_strViewName.TrimRight() );
  2805. CDBInterface::GetInstancePtr()->InsertLogRecord( LOG_MONITOR_ADD,0,"",(char *)(LPCTSTR)sContent );
  2806. }
  2807. }
  2808. void CMainFrame::OnAddview2()
  2809. {
  2810. OnAddview();
  2811. }
  2812. void CMainFrame::OnUpdateAddview(CCmdUI *pCmdUI)
  2813. {
  2814. // TODO: 在此添加命令更新用户界面处理程序代码
  2815. }
  2816. void CMainFrame::OnEditSort()
  2817. {
  2818. CDlg_EditView dlg;
  2819. dlg.DoModal();
  2820. }
  2821. void CMainFrame::OnUpdateEditSort(CCmdUI *pCmdUI)
  2822. {
  2823. // TODO: 在此添加命令更新用户界面处理程序代码
  2824. }
  2825. void CMainFrame::OnUpdateAddview2(CCmdUI *pCmdUI)
  2826. {
  2827. // TODO: 在此添加命令更新用户界面处理程序代码
  2828. }
  2829. void CMainFrame::DeleteDev(int nIsHint)
  2830. {
  2831. int i, j;
  2832. CString strMessage, strSelect;
  2833. HTREEITEM hSelectedItem = m_wndTree.GetSelectedItem();
  2834. strSelect = m_wndTree.GetItemText( hSelectedItem );
  2835. int nChannelNo = -1, nDeviceNo = -1;
  2836. int nChannelSize = pDevicesManager->m_channels.GetSize();
  2837. // 串口设备属性设置
  2838. for (i = 0; i < nChannelSize; i++)
  2839. {
  2840. if( nChannelNo != -1 && nDeviceNo != -1 ) break;
  2841. int nDeviceSize = pDevicesManager->m_channels[i]->m_Devices.GetSize();
  2842. for( j = 0; j < nDeviceSize; j++)
  2843. {
  2844. if (m_hSerialDev[i][j]==hSelectedItem &&
  2845. pDevicesManager->m_channels[i]->m_nCommunicateType == 0 )
  2846. {
  2847. nChannelNo = i;
  2848. nDeviceNo = j;
  2849. break;
  2850. }
  2851. if( m_hNetworkDev[j] == hSelectedItem &&
  2852. pDevicesManager->m_channels[i]->m_nCommunicateType == 1 )
  2853. {
  2854. nChannelNo = i;
  2855. nDeviceNo = j;
  2856. break;
  2857. }
  2858. }
  2859. }
  2860. CChannel* pChannel = pDevicesManager->m_channels[nChannelNo];
  2861. CDevice* pDev = pChannel->m_Devices[nDeviceNo];
  2862. if( nIsHint )
  2863. {
  2864. strMessage.Format(g_strDelDev,pDev->m_strName,pDev->m_strName);
  2865. int nRet = MessageBox(strMessage,g_strConfirm,MB_YESNOCANCEL|MB_ICONQUESTION);
  2866. if( nRet==IDCANCEL)
  2867. return;
  2868. else if( nRet==IDYES )
  2869. {
  2870. CString sContent;
  2871. sContent.Format("%s %s< %s >",g_strAdd,g_strDevice1,strSelect );
  2872. CDBInterface::GetInstancePtr()->InsertLogRecord( LOG_DEV_DELETE,0,"",(char *)(LPCTSTR)sContent );
  2873. pDevicesManager->SendNoticeToServer( CMD_NOTICE_READ_DB_DEV,CMD_OPERATE_DELETE,"",(char *)(LPCTSTR)pChannel->m_Devices[nDeviceNo]->m_strUID,0,"64320" );
  2874. CDBInterface::GetInstancePtr()->DelTableData( "t_dev_variant_item","uid",(char *)(LPCTSTR)pChannel->m_Devices[nDeviceNo]->m_strUID,1 );
  2875. CDBInterface::GetInstancePtr()->DelTableData( "t_dev_variant","uid",(char *)(LPCTSTR)pChannel->m_Devices[nDeviceNo]->m_strUID,1 );
  2876. CDBInterface::GetInstancePtr()->DelTableData( "t_var_status","devuid",(char *)(LPCTSTR)pChannel->m_Devices[nDeviceNo]->m_strUID,1 );
  2877. }
  2878. else
  2879. {
  2880. CString sContent;
  2881. sContent.Format("%s %s< %s >",g_strAdd,g_strDevice1,strSelect );
  2882. CDBInterface::GetInstancePtr()->InsertLogRecord( LOG_DEV_DELETE,0,"",(char *)(LPCTSTR)sContent );
  2883. }
  2884. }
  2885. m_wndTree.DeleteItem(hSelectedItem);
  2886. if( pChannel->m_nCommunicateType == 0 )
  2887. {
  2888. for( j = nDeviceNo; j < MAX_DEVICE_NUM; j++ )
  2889. {
  2890. m_hSerialDev[nChannelNo][j] = m_hSerialDev[nChannelNo][j+1];
  2891. }
  2892. }
  2893. else if( pChannel->m_nCommunicateType = 1 )
  2894. {
  2895. for( j = nDeviceNo; j < MAX_DEVICE_NUM; j++ )
  2896. {
  2897. m_hNetworkDev[j] = m_hNetworkDev[j+1];
  2898. }
  2899. }
  2900. //在设备与组的关系表中把相关的设备信息删掉
  2901. CDBInterface::GetInstancePtr()->DelTableData( "t_role_equip","uid",(char *)(LPCTSTR)pChannel->m_Devices[nDeviceNo]->m_strUID,1 );
  2902. CDBInterface::GetInstancePtr()->DeleteDevInfo( (char *)(LPCTSTR)pChannel->m_Devices[nDeviceNo]->m_strUID );
  2903. delete pChannel->m_Devices[nDeviceNo];
  2904. pChannel->m_Devices.RemoveAt(nDeviceNo);
  2905. }
  2906. void CMainFrame::OnDeletedevice()
  2907. {
  2908. // TODO: 在此添加命令处理程序代码
  2909. DeleteDev(1);
  2910. }
  2911. void CMainFrame::OnUpdateDeletedevice(CCmdUI *pCmdUI)
  2912. {
  2913. // TODO: 在此添加命令更新用户界面处理程序代码
  2914. pCmdUI->Enable(TRUE);
  2915. }
  2916. void CMainFrame::OnDeleteview()
  2917. {
  2918. // TODO: 在此添加命令处理程序代码
  2919. //删除文件,同时再数状控件中删除
  2920. CString strPath, strTemp;
  2921. CString strPathFile,strPathFolder;
  2922. HTREEITEM hSelectedItem = m_wndTree.GetSelectedItem();
  2923. if( m_hMonitor==hSelectedItem )
  2924. {
  2925. MessageBox(g_strMonitorNameCannotDel, g_strTip, MB_ICONINFORMATION);
  2926. return;
  2927. }
  2928. CString strSelect = m_wndTree.GetItemText( hSelectedItem );
  2929. CString strMessage;
  2930. strMessage.Format(g_strDelView,strSelect);
  2931. if (MessageBox(strMessage,g_strConfirm,MB_YESNO|MB_ICONQUESTION) == IDNO)
  2932. return;
  2933. GetPicPathByTree( hSelectedItem,strTemp );
  2934. strPathFile.Format( "%s\\%s%s.view",g_strDirectory,CString(_PICTUREDIR),strTemp.Left( strTemp.GetLength()-1) );
  2935. strPathFolder.Format( "%s\\%s%s\0\0",g_strDirectory,CString(_PICTUREDIR),strTemp.Left( strTemp.GetLength()-1) );
  2936. if( PathFileExists( strPathFile ) )
  2937. {
  2938. DeleteFile( strPathFile );
  2939. m_wndTree.DeleteItem(hSelectedItem);
  2940. hSelectedItem = NULL;
  2941. }
  2942. if( PathFileExists( strPathFolder ) )
  2943. {
  2944. //strPathFolder += "\0\0";
  2945. DeleteDirectory( strPathFolder );
  2946. //_DeleteFile( strPathFolder,FOF_ALLOWUNDO|FOF_NOCONFIRMATION );
  2947. if( hSelectedItem )
  2948. m_wndTree.DeleteItem(hSelectedItem);
  2949. }
  2950. CString sContent;
  2951. sContent.Format("删除画面< %s >",strSelect.TrimRight() );
  2952. CDBInterface::GetInstancePtr()->InsertLogRecord( LOG_MONITOR_DELETE,0,"",(char *)(LPCTSTR)sContent );
  2953. return;
  2954. //strPath = g_strDirectory + CString("\\") + CString(_PICTUREDIR);
  2955. //ffsco o;
  2956. //o.dirs(1); //查找子目录
  2957. //o.find( LPCSTR(strPath), "*.view" );
  2958. //ffsco::typeT coo;
  2959. //ffsco::typeT::iterator it;
  2960. //HTREEITEM hSelectedItem = m_wndTree.GetSelectedItem();
  2961. //if( m_hMonitor==hSelectedItem )
  2962. //{
  2963. // MessageBox(g_strMonitorNameCannotDel, g_strTip, MB_ICONINFORMATION);
  2964. // return;
  2965. //}
  2966. //CString strSelect = m_wndTree.GetItemText( hSelectedItem );
  2967. //CString strMessage;
  2968. //strMessage.Format(g_strDelView,strSelect);
  2969. //if (MessageBox(strMessage,g_strConfirm,MB_YESNO|MB_ICONQUESTION) == IDNO)
  2970. // return;
  2971. ////文件
  2972. //coo = o.co_file();
  2973. //for (it = coo.begin(); coo.end() != it; it++)
  2974. //{
  2975. // strTemp = (*it).c_str();
  2976. // strPath = strTemp;
  2977. // strTemp = strTemp.Right( strTemp.GetLength() - strTemp.ReverseFind('\\') - 1 );
  2978. // if( !strTemp.Compare(strSelect + ".view") )
  2979. // {
  2980. // CFile::Remove( strPath );
  2981. // m_wndTree.DeleteItem(hSelectedItem);
  2982. // break;
  2983. // }
  2984. //}
  2985. ////目录
  2986. //coo = o.co_dir();
  2987. //for( it = coo.begin(); coo.end() != it; it++ )
  2988. //{
  2989. // strTemp = (*it).c_str();
  2990. // strPath = strTemp;
  2991. // int nFind = strTemp.ReverseFind('\\');
  2992. // strTemp = strTemp.Left( nFind );
  2993. // strTemp = strTemp.Right( strTemp.GetLength() - strTemp.ReverseFind('\\') - 1 );
  2994. // if( !strTemp.Compare(strSelect) )
  2995. // {
  2996. // DeleteDirectory( strPath );
  2997. // m_wndTree.DeleteItem(hSelectedItem);
  2998. // break;
  2999. // }
  3000. //}
  3001. //CString sContent;
  3002. //sContent.Format("删除画面< %s >",strSelect.TrimRight() );
  3003. //CDBInterface::GetInstancePtr()->InsertLogRecord( LOG_MONITOR_DELETE,0,"",(char *)(LPCTSTR)sContent );
  3004. }
  3005. void CMainFrame::OnUpdateDeleteview(CCmdUI *pCmdUI)
  3006. {
  3007. // TODO: 在此添加命令更新用户界面处理程序代码
  3008. }
  3009. void CMainFrame::OnModifyViewName()
  3010. {
  3011. // TODO: 在此添加命令处理程序代码
  3012. CString strNew, strTemp,sViewName;
  3013. CString strPathFile,strPathFolder;
  3014. HTREEITEM hSelectedItem = m_wndTree.GetSelectedItem();
  3015. if( m_hMonitor==hSelectedItem )
  3016. {
  3017. return;
  3018. }
  3019. CString strSelect = m_wndTree.GetItemText( hSelectedItem );
  3020. CViewNameDlg dlg;
  3021. dlg.m_strViewName = strSelect;
  3022. if (dlg.DoModal() != IDOK)
  3023. return;
  3024. GetPicPathByTree( hSelectedItem,strTemp );
  3025. strPathFile.Format( "%s\\%s%s.view",g_strDirectory,CString(_PICTUREDIR),strTemp.Left( strTemp.GetLength()-1) );
  3026. strPathFolder.Format( "%s\\%s%s\0\0",g_strDirectory,CString(_PICTUREDIR),strTemp.Left( strTemp.GetLength()-1) );
  3027. if( PathFileExists( strPathFile ) )
  3028. {
  3029. strTemp = strSelect + ".view";
  3030. sViewName = dlg.m_strViewName + ".view";
  3031. strNew = strPathFile;
  3032. strNew.Replace( strTemp,sViewName );
  3033. MoveFile( strPathFile,strNew );
  3034. m_wndTree.SetItemText( hSelectedItem,dlg.m_strViewName );
  3035. hSelectedItem = NULL;
  3036. }
  3037. if( PathFileExists( strPathFolder ) )
  3038. {
  3039. strTemp = "\\" + strSelect;
  3040. sViewName = "\\" + dlg.m_strViewName;
  3041. strNew = strPathFolder;
  3042. strNew.Replace( strTemp,sViewName );
  3043. CopyDirectory( strPathFolder,strNew );
  3044. DeleteDirectory( strPathFolder );
  3045. if( hSelectedItem )
  3046. m_wndTree.DeleteItem(hSelectedItem);
  3047. }
  3048. }
  3049. void CMainFrame::OnUpdateModifyViewName(CCmdUI *pCmdUI)
  3050. {
  3051. // TODO: 在此添加命令更新用户界面处理程序代码
  3052. }
  3053. void CMainFrame::OnDeletescript()
  3054. {
  3055. // TODO: 在此添加命令处理程序代码
  3056. HTREEITEM hSelectedItem = m_wndTree.GetSelectedItem();
  3057. CFile::Remove( _SCRIPTDIR + m_wndTree.GetItemText(hSelectedItem) + ".srp");
  3058. CFile::Remove( _SCRIPTDIR + m_wndTree.GetItemText(hSelectedItem) + ".con");
  3059. m_wndTree.DeleteItem(hSelectedItem);
  3060. int nPos = -1;
  3061. for(int i = 0; i < m_nScripts; i++)
  3062. {
  3063. if (hSelectedItem == m_hScriptGroup[i])
  3064. {
  3065. nPos = i;
  3066. }
  3067. }
  3068. for( i = nPos; i < m_nScripts; i++)
  3069. {
  3070. m_hScriptGroup[i] = m_hScriptGroup[i+1];
  3071. }
  3072. }
  3073. void CMainFrame::OnUpdateDeletescript(CCmdUI *pCmdUI)
  3074. {
  3075. // TODO: 在此添加命令更新用户界面处理程序代码
  3076. }
  3077. void CMainFrame::OnSetscript()
  3078. {
  3079. // TODO: 在此添加命令处理程序代码
  3080. HTREEITEM hSelectedItem = m_wndTree.GetSelectedItem();
  3081. for (int m = 0; m < 32; m++)
  3082. {
  3083. if (m_hScriptGroup[m] == hSelectedItem)
  3084. {
  3085. CString conFile;
  3086. //SetCurrentDirectory(g_CurrentDir);
  3087. conFile = CString(g_strDirectory) + "\\" + _SCRIPTDIR;
  3088. conFile = conFile + m_wndTree.GetItemText(hSelectedItem) + ".con";
  3089. CScriptSetDlg dlg;
  3090. dlg.m_nCircle = GetPrivateProfileInt("RUNPARA", "CIRCLE", -1, conFile);
  3091. dlg.m_nType = GetPrivateProfileInt("RUNPARA", "TYPE", -1, conFile);
  3092. dlg.m_bUsed = GetPrivateProfileInt("RUNPARA", "USE", -1, conFile);
  3093. char szCon[MAX_PATH] = {0};
  3094. GetPrivateProfileString("RUNPARA", "CONDITON", "", szCon, MAX_PATH, conFile);
  3095. dlg.m_strCondition = szCon;
  3096. dlg.m_strName = m_wndTree.GetItemText(hSelectedItem);
  3097. if (dlg.DoModal() == IDOK)
  3098. {
  3099. WritePrivateProfileString("RUNPARA", "CONDITON", dlg.m_strCondition, conFile);
  3100. char tmp[10];
  3101. sprintf(tmp, "%d", dlg.m_nType);
  3102. WritePrivateProfileString("RUNPARA", "TYPE", tmp, conFile);
  3103. sprintf(tmp, "%d", dlg.m_nCircle);
  3104. WritePrivateProfileString("RUNPARA", "CIRCLE", tmp, conFile);
  3105. if ( dlg.m_bUsed )
  3106. {
  3107. WritePrivateProfileString("RUNPARA", "USE", "1", conFile);
  3108. }
  3109. else
  3110. {
  3111. WritePrivateProfileString("RUNPARA", "USE", "0", conFile);
  3112. }
  3113. }
  3114. }
  3115. }
  3116. }
  3117. void CMainFrame::OnUpdateSetscript(CCmdUI *pCmdUI)
  3118. {
  3119. // TODO: 在此添加命令更新用户界面处理程序代码
  3120. }
  3121. void CMainFrame::OnEditscript()
  3122. {
  3123. // TODO: 在此添加命令处理程序代码
  3124. HTREEITEM hSelectedItem = m_wndTree.GetSelectedItem();
  3125. for (int m = 0; m < 32; m++)
  3126. {
  3127. if (m_hScriptGroup[m] == hSelectedItem)
  3128. {
  3129. CString scriptFile;
  3130. scriptFile = CString(g_strDirectory) + "\\" + _SCRIPTDIR;
  3131. scriptFile = scriptFile + m_wndTree.GetItemText(hSelectedItem) + ".srp";
  3132. ShellExecute(NULL,"open", "ScriptEdit.exe", scriptFile, NULL, SW_SHOWNORMAL);
  3133. }
  3134. }
  3135. }
  3136. void CMainFrame::OnUpdateEditscript(CCmdUI *pCmdUI)
  3137. {
  3138. // TODO: 在此添加命令更新用户界面处理程序代码
  3139. }
  3140. void CMainFrame::SetRunPara()
  3141. {
  3142. OnSysPara();
  3143. }
  3144. int CMainFrame::GetIDEViewIndex(CString strPath)
  3145. {
  3146. int i;
  3147. for( i = 0; i < MAX_VIEW_NUM; i++ )
  3148. {
  3149. if( !m_pViewIDE[i] ) continue;
  3150. CString str;
  3151. str = m_pViewIDE[i]->m_strPath;
  3152. str.Replace("\\\\", "\\");
  3153. strPath.Replace("\\\\", "\\");
  3154. if( !str.Compare(strPath) )
  3155. {
  3156. return i;
  3157. }
  3158. }
  3159. return -1;
  3160. }
  3161. int CMainFrame::GetIDEViewFreeIndex(CString strPath)
  3162. {
  3163. int i;
  3164. for( i = 0; i < MAX_VIEW_NUM; i++ )
  3165. {
  3166. if( !m_pViewIDE[i] ) return i;
  3167. if( m_pViewIDE[i]->m_bClose ) continue;
  3168. if( !m_pViewIDE[i]->m_strPath.Compare("") )
  3169. {
  3170. return i;
  3171. }
  3172. }
  3173. return -1;
  3174. }
  3175. void CMainFrame::AddIDEView(CString strDesc, CString strPath)
  3176. {
  3177. //如果是当前画面,退出
  3178. if( g_strViewName==strPath )
  3179. return;
  3180. g_sCurrentPageName = strDesc;
  3181. // 打开新的画面,先保存旧的。
  3182. CIDEView *pView = (CIDEView *)m_pActiveView;
  3183. if( pView )
  3184. {
  3185. pView->ChangeView();
  3186. }
  3187. int nIndex = GetIDEViewIndex(strPath);
  3188. if( nIndex == -1 )
  3189. {
  3190. nIndex = GetIDEViewFreeIndex(strPath);
  3191. if( nIndex == -1 ) nIndex = 0;
  3192. CCreateContext context;
  3193. m_pViewIDE[nIndex] = new CChildFrame;
  3194. m_pViewIDE[nIndex]->m_strPath = strPath;
  3195. m_pViewIDE[nIndex]->m_strDesc = strDesc;
  3196. context.m_pCurrentDoc = m_pDoc;
  3197. context.m_pNewDocTemplate = m_pDoc->GetDocTemplate();
  3198. context.m_pNewViewClass = RUNTIME_CLASS( CIDEView );
  3199. context.m_pCurrentFrame = this;
  3200. context.m_pLastView = NULL;
  3201. if( !m_pViewIDE[nIndex]->LoadFrame(IDI_SUMMARY, WS_MAXIMIZE|WS_OVERLAPPEDWINDOW, this, &context) )
  3202. {
  3203. return;
  3204. }
  3205. m_pViewIDE[nIndex]->ShowWindow(SW_SHOWMAXIMIZED);
  3206. m_pViewIDE[nIndex]->InitialUpdateFrame(m_pDoc,true);
  3207. m_pViewIDE[nIndex]->MDIActivate();
  3208. m_nViewCount++;
  3209. }
  3210. else
  3211. {
  3212. m_pActiveView = (CFormView *)m_pViewIDE[nIndex]->GetActiveView();
  3213. m_pViewIDE[nIndex]->MDIActivate();
  3214. }
  3215. m_pViewIDE[ nIndex ]->m_bClose = FALSE;
  3216. m_pActiveView = (CFormView *)m_pViewIDE[nIndex]->GetActiveView();
  3217. g_strViewName = strPath;
  3218. ((CIDEView *)m_pActiveView)->ChangeView();
  3219. //取当前所有的变量到SA中
  3220. GetCurPicVarToSArray( strPath );
  3221. /////////////////////把当前画面名保存到C:\\PageName.txt中,给视频用///////////////////////////////////
  3222. CString sPath = "C:\\PageName.txt";
  3223. DeleteFile( sPath );
  3224. CString strTemp;
  3225. CStdioFile MyFile;
  3226. if(!MyFile.Open(sPath,CFile::modeWrite))
  3227. MyFile.Open(sPath,CFile::modeCreate|CFile::modeWrite);
  3228. strTemp.Format("%s\n",strDesc);
  3229. MyFile.SeekToEnd();
  3230. MyFile.WriteString(strTemp);
  3231. MyFile.Close();
  3232. }
  3233. void CMainFrame::OnUsers()
  3234. {
  3235. if( g_nIsDemo == 0 )
  3236. {
  3237. CDlgUserManager dlg;
  3238. if( dlg.DoModal() == IDOK )
  3239. {
  3240. }
  3241. }
  3242. }
  3243. void CMainFrame::OnEditPwdTool()
  3244. {
  3245. if( g_nIsDemo == 0 )
  3246. {
  3247. CDlgEditPwd dlg;
  3248. if( dlg.DoModal() == IDOK )
  3249. {
  3250. CString sContent;
  3251. sContent.Format("%s%s",g_strEdit,g_strPwd );
  3252. CDBInterface::GetInstancePtr()->InsertLogRecord( LOG_PWD_EDIT,0,"",(char *)(LPCTSTR)sContent );
  3253. }
  3254. }
  3255. }
  3256. void CMainFrame::OnSysPara()
  3257. {
  3258. CSystemParaSetDlg dlg;
  3259. dlg.m_bStartRun = g_bStartRun;
  3260. dlg.m_bAlarmVoice = g_bAlarmVoice;
  3261. dlg.m_bEventAlarm = g_bEventAlarm;
  3262. dlg.m_bHideTask = g_bHideTask;
  3263. dlg.m_strStartPic = g_strStartPic;
  3264. dlg.m_strStartPath = g_strStartPath;
  3265. if ( dlg.DoModal() == IDOK )
  3266. {
  3267. #if 0 //程序退出之前不改变状态
  3268. g_bStartRun = dlg.m_bStartRun;
  3269. #endif
  3270. //int nPos = dlg.m_strStartPath.Find("\\\\");
  3271. //if( nPos!=-1 )
  3272. //{
  3273. // dlg.m_strStartPath.Delete( nPos );
  3274. //}
  3275. //
  3276. //int nLen = dlg.m_strStartPath.GetLength();
  3277. //nPos = dlg.m_strStartPath.Find("view");
  3278. //CString sTemp;
  3279. //if( nPos<nLen-7 )
  3280. // sTemp = dlg.m_strStartPath.Right( nLen-nPos-7 );
  3281. //if( sTemp!="" )
  3282. // g_strStartPic = sTemp+"\\"+dlg.m_strStartPic;
  3283. //else
  3284. g_strStartPic = dlg.m_strStartPic;
  3285. g_strStartPath = dlg.m_strStartPath;
  3286. g_bEventAlarm = dlg.m_bEventAlarm;
  3287. g_bAlarmVoice = dlg.m_bAlarmVoice;
  3288. g_bHideTask = dlg.m_bHideTask;
  3289. StoreRunPara(dlg.m_bStartRun);
  3290. }
  3291. }
  3292. void CMainFrame::OnEventmanage()
  3293. {
  3294. #if 0
  3295. CEventSetDlg dlg;
  3296. dlg.m_bControlEvent = g_bControlEvent;
  3297. dlg.g_strYkWave =g_strYkWave;
  3298. dlg.m_bLoginEvent = g_bLoginEvent;
  3299. dlg.m_strLoginWave = g_strLoginWave;
  3300. dlg.m_bReguEvent = g_bReguEvent;
  3301. dlg.m_strReguWave = g_strReguWave;
  3302. dlg.m_bSetEvent = g_bSetEvent;
  3303. dlg.m_strSetWave = g_strSetWave;
  3304. dlg.m_bYcEvent = g_bYcEvent;
  3305. dlg.m_strYcWave = g_strYcWave;
  3306. dlg.m_bYxChangeEve = g_bYxChangeEve;
  3307. dlg.m_strYxChangeWave = g_strYxChangeWave;
  3308. if (dlg.DoModal() == IDOK)
  3309. {
  3310. g_bControlEvent = dlg.m_bControlEvent;
  3311. g_strYkWave = dlg.g_strYkWave;
  3312. g_bLoginEvent = dlg.m_bLoginEvent;
  3313. g_strLoginWave = dlg.m_strLoginWave;
  3314. g_bReguEvent = dlg.m_bReguEvent;
  3315. g_strReguWave = dlg.m_strReguWave;
  3316. g_bSetEvent = dlg.m_bSetEvent;
  3317. g_strSetWave = dlg.m_strSetWave;
  3318. g_bYcEvent = dlg.m_bYcEvent;
  3319. g_strYcWave = dlg.m_strYcWave;
  3320. g_bYxChangeEve = dlg.m_bYxChangeEve;
  3321. g_strYxChangeWave = dlg.m_strYxChangeWave;
  3322. StoreEventPara();
  3323. pVariantsManager->m_bDigitalAlarm = g_bYxChangeEve;
  3324. pVariantsManager->m_bAnalogAlarm = g_bYcEvent;
  3325. }
  3326. #endif
  3327. }
  3328. void CMainFrame::OnEvent()
  3329. {
  3330. if( g_nIsDemo == 0 )
  3331. {
  3332. CDlgQueryWarningRec dlg;
  3333. if( dlg.DoModal() == IDOK )
  3334. {
  3335. }
  3336. }
  3337. }
  3338. void CMainFrame::OnSystemLog()
  3339. {
  3340. if( g_nIsDemo == 0 )
  3341. {
  3342. CDlgSystemLog dlg;
  3343. dlg.DoModal();
  3344. }
  3345. }
  3346. void CMainFrame::OnNoticeRec()
  3347. {
  3348. if( g_nIsDemo == 0 )
  3349. {
  3350. CDlgNoticeRec dlg;
  3351. dlg.DoModal();
  3352. }
  3353. }
  3354. void CMainFrame::OnUpdateEvent(CCmdUI* pCmdUI)
  3355. {
  3356. // TODO: Add your command update UI handler code here
  3357. pCmdUI->Enable(m_bEvent);
  3358. }
  3359. void CMainFrame::OnUpdateSystemLog(CCmdUI* pCmdUI)
  3360. {
  3361. // TODO: Add your command update UI handler code here
  3362. pCmdUI->Enable(m_bSystemLog);
  3363. }
  3364. void CMainFrame::OnUpdateNoticeRec(CCmdUI* pCmdUI)
  3365. {
  3366. // TODO: Add your command update UI handler code here
  3367. pCmdUI->Enable(m_bNoticeRec);
  3368. }
  3369. void CMainFrame::OnUpdateUsers(CCmdUI* pCmdUI)
  3370. {
  3371. // TODO: Add your command update UI handler code here
  3372. pCmdUI->Enable(m_bUsers);
  3373. }
  3374. void CMainFrame::OnUpdateEditPwd(CCmdUI* pCmdUI)
  3375. {
  3376. // TODO: Add your command update UI handler code here
  3377. pCmdUI->Enable(m_bEditPwd);
  3378. }
  3379. void CMainFrame::OnUpdateSysPare(CCmdUI* pCmdUI)
  3380. {
  3381. // TODO: Add your command update UI handler code here
  3382. pCmdUI->Enable(m_bSysPare);
  3383. }
  3384. void CMainFrame::OnUpdateSingleAnalog(CCmdUI* pCmdUI)
  3385. {
  3386. // TODO: Add your command update UI handler code here
  3387. pCmdUI->Enable(m_bAnalog);
  3388. }
  3389. void CMainFrame::OnUpdatePrint(CCmdUI* pCmdUI)
  3390. {
  3391. // TODO: Add your command update UI handler code here
  3392. pCmdUI->Enable(m_bPrint);
  3393. }
  3394. void CMainFrame::OnSummaryLog()
  3395. {
  3396. if( g_nIsDemo == 0 )
  3397. {
  3398. #if 0
  3399. CDlgQuerySummaryLog dlg;
  3400. if( dlg.DoModal() == IDOK )
  3401. {
  3402. }
  3403. #endif
  3404. CString sIDE,sReport;
  3405. sIDE.Format( "%s",g_strDirectory );
  3406. int nEnd = 0;
  3407. for (int i = sIDE.GetLength()-1; i >= 0; i--)
  3408. {
  3409. if (g_strDirectory[i] == '\\')
  3410. {
  3411. nEnd = i;
  3412. break;
  3413. }
  3414. }
  3415. sReport = sIDE.Left( nEnd ) + "\\report";
  3416. CString strFileName;
  3417. strFileName.Format("%s\\DBMonitorReport.exe", sReport);
  3418. ShellExecute(0, "open", strFileName, NULL, NULL, SW_SHOWNORMAL);
  3419. }
  3420. }
  3421. void CMainFrame::OnUpdateSummaryLog(CCmdUI* pCmdUI)
  3422. {
  3423. // TODO: Add your command update UI handler code here
  3424. pCmdUI->Enable(m_bDeviceLog);
  3425. }
  3426. void CMainFrame::StoreRunPara(BOOL bStartRun)
  3427. {
  3428. char Path[_MAX_PATH] = {0};
  3429. strcat(Path, g_strDirectory);
  3430. strcat(Path,"\\");
  3431. strcat(Path, _PROJECTDIR);
  3432. strcat(Path,"\\");
  3433. strcat(Path, "runpara.ini");
  3434. if ( bStartRun )
  3435. {
  3436. WritePrivateProfileString("RUNPARA", "STARTRUN", "1", Path);
  3437. }
  3438. else
  3439. {
  3440. WritePrivateProfileString("RUNPARA", "STARTRUN", "0", Path);
  3441. }
  3442. if ( g_bEventAlarm )
  3443. {
  3444. WritePrivateProfileString("RUNPARA", "ALARM", "1", Path);
  3445. }
  3446. else
  3447. {
  3448. WritePrivateProfileString("RUNPARA", "ALARM", "0", Path);
  3449. }
  3450. if ( g_bAlarmVoice )
  3451. {
  3452. WritePrivateProfileString("RUNPARA", "VOICE", "1", Path);
  3453. }
  3454. else
  3455. {
  3456. WritePrivateProfileString("RUNPARA", "VOICE", "0", Path);
  3457. }
  3458. if ( g_bHideTask )
  3459. {
  3460. WritePrivateProfileString("RUNPARA", "HIDETASK", "1", Path);
  3461. }
  3462. else
  3463. {
  3464. WritePrivateProfileString("RUNPARA", "HIDETASK", "0", Path);
  3465. }
  3466. if ( g_bFullScreen )
  3467. {
  3468. WritePrivateProfileString("RUNPARA", "FULLSCREEN", "1", Path);
  3469. }
  3470. else
  3471. {
  3472. WritePrivateProfileString("RUNPARA", "FULLSCREEN", "0", Path);
  3473. }
  3474. WritePrivateProfileString("RUNPARA", "STARTPIC", g_strStartPic, Path);
  3475. WritePrivateProfileString("RUNPARA", "STARTPATH", g_strStartPath, Path);
  3476. }
  3477. // 存储事件参数
  3478. void CMainFrame::StoreEventPara()
  3479. {
  3480. char Path[_MAX_PATH] = {0};
  3481. strcat(Path, g_strDirectory);
  3482. strcat(Path,"\\");
  3483. strcat(Path, _PROJECTDIR);
  3484. strcat(Path,"\\");
  3485. strcat(Path, "event.ini");
  3486. if ( g_bControlEvent )
  3487. {
  3488. WritePrivateProfileString("IFALARM", "CONTROL", "1", Path);
  3489. }
  3490. else
  3491. {
  3492. WritePrivateProfileString("IFALARM", "CONTROL", "0", Path);
  3493. }
  3494. if ( g_bLoginEvent )
  3495. {
  3496. WritePrivateProfileString("IFALARM", "LOGIN", "1", Path);
  3497. }
  3498. else
  3499. {
  3500. WritePrivateProfileString("IFALARM", "LOGIN", "0", Path);
  3501. }
  3502. if ( g_bSetEvent )
  3503. {
  3504. WritePrivateProfileString("IFALARM", "SET", "1", Path);
  3505. }
  3506. else
  3507. {
  3508. WritePrivateProfileString("IFALARM", "SET", "0", Path);
  3509. }
  3510. if ( g_bReguEvent )
  3511. {
  3512. WritePrivateProfileString("IFALARM", "REGU", "1", Path);
  3513. }
  3514. else
  3515. {
  3516. WritePrivateProfileString("IFALARM", "REGU", "0", Path);
  3517. }
  3518. if ( g_bYxChangeEve )
  3519. {
  3520. WritePrivateProfileString("IFALARM", "YXCHANGE", "1", Path);
  3521. }
  3522. else
  3523. {
  3524. WritePrivateProfileString("IFALARM", "YXCHANGE", "0", Path);
  3525. }
  3526. if ( g_bYcEvent )
  3527. {
  3528. WritePrivateProfileString("IFALARM", "YCOVERLIMIT", "1", Path);
  3529. }
  3530. else
  3531. {
  3532. WritePrivateProfileString("IFALARM", "YCOVERLIMIT", "0", Path);
  3533. }
  3534. WritePrivateProfileString("WAVEFILE", "CONTROL", g_strYkWave, Path);
  3535. WritePrivateProfileString("WAVEFILE", "LOGIN", g_strLoginWave, Path);
  3536. WritePrivateProfileString("WAVEFILE", "SET", g_strSetWave, Path);
  3537. WritePrivateProfileString("WAVEFILE", "REGU", g_strReguWave, Path);
  3538. WritePrivateProfileString("WAVEFILE", "YXCHANGE", g_strYxChangeWave, Path);
  3539. WritePrivateProfileString("WAVEFILE", "YCOVERLIMIT", g_strYcWave, Path);
  3540. }
  3541. void CMainFrame::OnControldialog()
  3542. {
  3543. CRect rctDlg;
  3544. int screenx = GetSystemMetrics(SM_CXSCREEN);
  3545. int screeny = GetSystemMetrics(SM_CYSCREEN);
  3546. m_dlgControl->GetWindowRect(&rctDlg);
  3547. m_dlgControl->SetWindowPos(&wndTop, screenx - rctDlg.Width(), screeny - rctDlg.Height(),
  3548. rctDlg.Width(), rctDlg.Height(), SWP_NOZORDER);
  3549. m_dlgControl->ShowWindow(SW_SHOW);
  3550. }
  3551. void CMainFrame::OnTimer(UINT nIDEvent)
  3552. {
  3553. // TODO: 在此添加消息处理程序代码和/或调用默认值
  3554. if( nIDEvent == 1 )
  3555. {
  3556. if (g_bStartRun && g_nIsPoll == 1)
  3557. {
  3558. for( int i = 0; i < g_nPollCount; i++ )
  3559. {
  3560. if( g_dwTick == 0 )
  3561. {
  3562. if( g_nPollIndex == i )
  3563. {
  3564. g_dwTick = GetTickCount();
  3565. TRACE("Enter AddIDEView %s, %s\r\n", g_strPollPath, g_strPollDesc);
  3566. AddIDEView(g_strPollDesc[i], g_strPollPath[i]);
  3567. TRACE("Leave AddIDEView\r\n");
  3568. }
  3569. }
  3570. else if( GetTickCount() - g_dwTick > (DWORD)g_nPollInterval * 1000 )
  3571. {
  3572. if( g_nPollIndex == g_nPollCount - 1 )
  3573. {
  3574. g_nPollIndex = 0;
  3575. }
  3576. else
  3577. {
  3578. g_nPollIndex++;
  3579. }
  3580. g_dwTick = 0;
  3581. }
  3582. }
  3583. }
  3584. }
  3585. if( nIDEvent==2 )//定时得到狗信息/定时判断是否过期
  3586. {
  3587. //pDevicesManager->GetDogInfo( "64320" );
  3588. if( pDevicesManager->m_bIsPastDue )
  3589. {
  3590. pDevicesManager->m_bIsPastDue = false;
  3591. static bool bShow=false;
  3592. if( !bShow )
  3593. {
  3594. bShow = true;
  3595. CString sShow;
  3596. sShow.Format(g_strPastDue,pDevicesManager->m_sPassDueInfo );
  3597. if( MessageBox( sShow, g_strTip, MB_ICONWARNING)==IDOK )
  3598. bShow = false;
  3599. }
  3600. }
  3601. if( !pDevicesManager->m_bIsBlanceSmall )//余额不足
  3602. {
  3603. pDevicesManager->m_bIsBlanceSmall = true;
  3604. CString sShow;
  3605. sShow.Format("%s",pDevicesManager->m_sBanceContent );
  3606. MessageBox( sShow, g_strTip, MB_ICONWARNING);
  3607. }
  3608. }
  3609. //if( nIDEvent==3 )//判断变量在这个时间段时否报警
  3610. //{
  3611. // static int nStaticHours = -1;
  3612. // CTime time = CTime::GetCurrentTime();
  3613. // int nHours = time.GetHour();
  3614. // if( nStaticHours!=nHours )
  3615. // {
  3616. // nStaticHours = nHours;
  3617. // pVariantsManager->AllocDatePlan();
  3618. // }
  3619. //}
  3620. CMDIAutoHideFrame::OnTimer(nIDEvent);
  3621. }
  3622. void CMainFrame::OnUserManager()
  3623. {
  3624. // TODO: 在此添加命令处理程序代码
  3625. CDlgUserManager dlg;
  3626. int nResult = dlg.DoModal();
  3627. if( nResult == IDOK )
  3628. {
  3629. }
  3630. }
  3631. void CMainFrame::OnGroupManager()
  3632. {
  3633. // TODO: 在此添加命令处理程序代码
  3634. CDlg_GroupManage dlg;
  3635. int nResult = dlg.DoModal();
  3636. if( nResult == IDOK )
  3637. {
  3638. }
  3639. }
  3640. void CMainFrame::OnEditPwd()
  3641. {
  3642. // TODO: 在此添加命令处理程序代码
  3643. CDlgEditPwd dlg;
  3644. if( dlg.DoModal() == IDOK )
  3645. {
  3646. CString sContent;
  3647. sContent.Format("修改密码");
  3648. CDBInterface::GetInstancePtr()->InsertLogRecord( LOG_PWD_EDIT,0,"",(char *)(LPCTSTR)sContent );
  3649. }
  3650. }
  3651. void CMainFrame::OnSingleAnalog()
  3652. {
  3653. // TODO: 在此添加命令处理程序代码
  3654. CAnalogDlg dlg;
  3655. dlg.DoModal();
  3656. }
  3657. LRESULT CMainFrame::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
  3658. {
  3659. // TODO: 在此添加专用代码和/或调用基类
  3660. switch( message )
  3661. {
  3662. case WM_MY_NEW_ALERT:
  3663. {
  3664. CString sPath;
  3665. CString sVarName = (char *)wParam;
  3666. //LOG4C((LOG_NOTICE, "报警变量:%s", sVarName));
  3667. if( GetPicPathByVarName( sPath,sVarName ) )
  3668. {
  3669. int nPos1=0,nPos2=0;
  3670. for( int i=sPath.GetLength()-1;i>0;i-- )
  3671. {
  3672. if( sPath[i]=='\\' )
  3673. {
  3674. nPos1 = i;
  3675. break;
  3676. }
  3677. }
  3678. for( int i=sPath.GetLength()-1;i>0;i-- )
  3679. {
  3680. if( sPath[i]=='.' )
  3681. {
  3682. nPos2 = i;
  3683. break;
  3684. }
  3685. }
  3686. CString sName = sPath.Mid( nPos1+1,nPos2-nPos1-1 );
  3687. AddIDEView( sName,sPath );
  3688. }
  3689. //LOG4C((LOG_NOTICE, "报警画面:%s", sPath));
  3690. }
  3691. break;
  3692. case WM_MY_SIZECHANGE:
  3693. {
  3694. CString str;
  3695. str.Format( "%d,%d",wParam,lParam );
  3696. m_dlgEvent->SetPos( wParam,lParam );
  3697. }
  3698. break;
  3699. case WM_MY_SIZECHANGE2:
  3700. {
  3701. #if USE_NEWTOP
  3702. CString str;
  3703. str.Format( "%d,%d",wParam,lParam );
  3704. m_pToolBar->SetPos( wParam,lParam );
  3705. #endif
  3706. }
  3707. break;
  3708. }
  3709. return CMDIAutoHideFrame::WindowProc(message, wParam, lParam);
  3710. }
  3711. bool CMainFrame::GetPicIndexByPicPath( int &iIndex,CString sPicPath )
  3712. {
  3713. bool bRet=false;
  3714. for( int i=0;i<VIEW_MAX_NUM;i++ )
  3715. {
  3716. if( m_PIC_VAR[i].sPicPath=="" )
  3717. {
  3718. iIndex=i;
  3719. break;
  3720. }
  3721. if( m_PIC_VAR[i].sPicPath==sPicPath )
  3722. {
  3723. bRet = true;
  3724. break;
  3725. }
  3726. }
  3727. return bRet;
  3728. }
  3729. //通过变量名查找画面
  3730. bool CMainFrame::GetPicPathByVarName( CString &sPicPath,CString sVarName )
  3731. {
  3732. bool bRet=false;
  3733. bool bBreak=false;
  3734. for( int i=0;i<VIEW_MAX_NUM;i++ )
  3735. {
  3736. if( m_PIC_VAR[i].sPicPath=="" )
  3737. break;
  3738. for( int j=0;j<1000;j++ )
  3739. {
  3740. if( m_PIC_VAR[i].sCaption[j]=="" )
  3741. {
  3742. break;
  3743. }
  3744. if( -1 != m_PIC_VAR[i].sCaption[j].Find( sVarName ) )
  3745. {
  3746. sPicPath = m_PIC_VAR[i].sPicPath;
  3747. bRet = true;
  3748. bBreak = true;
  3749. break;
  3750. }
  3751. }
  3752. if( bBreak )
  3753. break;
  3754. }
  3755. return bRet;
  3756. }
  3757. // 判断是有效变量名
  3758. BOOL CMainFrame::IsValidChar(char chr)
  3759. {
  3760. if ( chr >= '0' && chr <= '9')
  3761. return TRUE;
  3762. else if ((chr >= 'A' && chr <= 'Z') || (chr >= 'a' && chr <= 'z') )
  3763. return TRUE;
  3764. else if (chr == '_')
  3765. return TRUE;
  3766. else
  3767. return FALSE;
  3768. }
  3769. //从组合公式中找出变量名加入到画面结构中
  3770. void CMainFrame::GetVarFromGSAddToStruct( int iIndex,CString sGS )
  3771. {
  3772. //LOG4C((LOG_NOTICE, "GetVarFromGSAddToStruct sGS :%s", sGS));
  3773. //sGS = "(HG7053_DI10>=3)OR(HG7053_LinkStatus<=33)";
  3774. //sGS = "((HG7053_DI10>=3))";
  3775. //sGS = "(HG7053_DI10>=3)AND(HG7053_LinkStatus<=33)OR(HG7053_DI15<3)";
  3776. int nLen = sGS.GetLength();
  3777. int nPos1=0,nPos2=0;
  3778. int nPos3=0,nPos4=0;
  3779. CString sTemp,s1,s2,s3;
  3780. CString sGS2[100];
  3781. int nCount=0;
  3782. //OR AND NOT
  3783. for( int i=0;i<nLen;i++ )
  3784. {
  3785. if( sGS.Mid( i,2)=="OR" && !IsValidChar(sGS[i+2]) )
  3786. {
  3787. sGS2[nCount++] = sGS.Mid( nPos1,i-nPos1 );
  3788. nPos1 = i+2;
  3789. }
  3790. if( (sGS.Mid( i,3)=="AND" || sGS.Mid( i,3)=="NOT") && !IsValidChar(sGS[i+3]) )
  3791. {
  3792. sGS2[nCount++] = sGS.Mid( nPos1,i-nPos1 );
  3793. nPos1 = i+3;
  3794. }
  3795. }
  3796. if( nPos1<nLen )
  3797. {
  3798. sGS2[nCount++] = sGS.Mid( nPos1,nLen-nPos1 );
  3799. }
  3800. for( int iGSIndex=0;iGSIndex<nCount;iGSIndex++ )
  3801. {
  3802. nPos3=0;
  3803. nPos4=0;
  3804. nLen = sGS2[iGSIndex].GetLength();
  3805. if( !IsValidChar( sGS2[iGSIndex][0] ) )
  3806. {
  3807. if( IsValidChar( sGS2[iGSIndex][1] ) )
  3808. nPos3 = 1;
  3809. else
  3810. nPos3 = 2;
  3811. for( int i=nPos3;i<nLen;i++ )
  3812. {
  3813. if( !IsValidChar( sGS2[iGSIndex][i] ) )
  3814. {
  3815. nPos4 = i-0;
  3816. break;
  3817. }
  3818. }
  3819. sTemp = sGS2[iGSIndex].Mid( nPos3,nPos4-nPos3 );
  3820. int nInsert=0;
  3821. if( !VarIsExistInPic( iIndex,sTemp,nInsert ) && sTemp!="" )
  3822. m_PIC_VAR[iIndex].sCaption[nInsert] = sTemp;
  3823. }
  3824. else
  3825. {
  3826. for( int i=nPos3;i<nLen;i++ )
  3827. {
  3828. if( !IsValidChar( sGS2[iGSIndex][i] ) )
  3829. {
  3830. nPos4 = i-0;
  3831. break;
  3832. }
  3833. }
  3834. sTemp = sGS2[iGSIndex].Mid( nPos3,nPos4-nPos3 );
  3835. int nInsert=0;
  3836. if( !VarIsExistInPic( iIndex,sTemp,nInsert ) && sTemp!="" )
  3837. m_PIC_VAR[iIndex].sCaption[nInsert] = sTemp;
  3838. }
  3839. }
  3840. }
  3841. //把变量插入到相对应的画面结构
  3842. void CMainFrame::InsertPicPathToStruct( int iIndex,CString sPicPath )
  3843. {
  3844. //LOG4C((LOG_NOTICE, "InsertPicPathToStruct :%s", sPicPath));
  3845. CDrawObjList _ObjList;
  3846. m_PIC_VAR[iIndex].sPicPath = sPicPath;
  3847. BYTE m_Type;
  3848. CSize m_sizePic;
  3849. CSize m_sizeGrid;
  3850. BOOL m_bGrid;
  3851. COLORREF m_clrBack;
  3852. CFile file;
  3853. if(file.Open(sPicPath,CFile::modeRead))
  3854. {
  3855. CArchive ar(&file,CArchive::load);
  3856. ar >> m_Type;
  3857. ar >> m_sizePic;
  3858. ar >> m_sizeGrid;
  3859. ar >> m_bGrid;
  3860. ar >> m_clrBack;
  3861. _ObjList.Serialize(ar);
  3862. if( !_ObjList.IsEmpty() )
  3863. {
  3864. for(POSITION pos = _ObjList.GetHeadPosition();pos!=NULL;)
  3865. {
  3866. POSITION pos1 = pos ;
  3867. CDrawObj *ct = (CDrawObj *)_ObjList.GetNext(pos);
  3868. int nInsert=0;
  3869. if( ct->m_bVariant && ct->m_strCaption!="" && !VarIsExistInPic( iIndex,ct->m_strCaption,nInsert ) )
  3870. m_PIC_VAR[iIndex].sCaption[nInsert] = ct->m_strCaption;
  3871. if( ct->m_strDynShow!="" )
  3872. GetVarFromGSAddToStruct( iIndex,ct->m_strDynShow );
  3873. if( ct->m_strDynForeCon!="" )
  3874. GetVarFromGSAddToStruct( iIndex,ct->m_strDynForeCon );
  3875. if( ct->m_strDynBackCon!="" )
  3876. GetVarFromGSAddToStruct( iIndex,ct->m_strDynBackCon );
  3877. if( ct->m_strDynLineCon!="" )
  3878. GetVarFromGSAddToStruct( iIndex,ct->m_strDynLineCon );
  3879. if( ct->m_strHoriPos!="" )
  3880. GetVarFromGSAddToStruct( iIndex,ct->m_strHoriPos );
  3881. if( ct->m_strHoriSize!="" )
  3882. GetVarFromGSAddToStruct( iIndex,ct->m_strHoriSize );
  3883. if( ct->m_strVertiPos!="" )
  3884. GetVarFromGSAddToStruct( iIndex,ct->m_strVertiPos );
  3885. if( ct->m_strVertiSize!="" )
  3886. GetVarFromGSAddToStruct( iIndex,ct->m_strVertiSize );
  3887. if( ct->m_strCurrentCaption!="" )
  3888. GetVarFromGSAddToStruct( iIndex,ct->m_strCurrentCaption );
  3889. if( ct->IsKindOf( RUNTIME_CLASS(CDrawBitmap) ) )
  3890. {
  3891. if( ((CDrawBitmap *)ct)->m_strDynCondition!="" )
  3892. GetVarFromGSAddToStruct( iIndex,((CDrawBitmap *)ct)->m_strDynCondition );
  3893. }
  3894. if( ct->IsKindOf( RUNTIME_CLASS(CDrawGif) ) )
  3895. {
  3896. if( ((CDrawGif *)ct)->m_strDynCondition!="" )
  3897. GetVarFromGSAddToStruct( iIndex,((CDrawGif *)ct)->m_strDynCondition );
  3898. }
  3899. }
  3900. }
  3901. ///////////////////////////////////////
  3902. ar.Close();
  3903. file.Close();
  3904. }
  3905. if(!_ObjList.IsEmpty())
  3906. {
  3907. for(POSITION pos = _ObjList.GetHeadPosition();pos!=NULL;)
  3908. {
  3909. POSITION pos1 = pos ;
  3910. CDrawObj *ct = (CDrawObj *)_ObjList.GetNext(pos);
  3911. _ObjList.RemoveAt(pos1);
  3912. delete ct;
  3913. }
  3914. _ObjList.RemoveAll();
  3915. ASSERT(_ObjList.IsEmpty());
  3916. }
  3917. }
  3918. //查找这个画面结构里是否已经有这个变量
  3919. bool CMainFrame::VarIsExistInPic( int iIndex,CString sVarName,int &iInsertIndex )
  3920. {
  3921. bool bRet=false;
  3922. for( int j=0;j<1000;j++ )
  3923. {
  3924. if( m_PIC_VAR[iIndex].sCaption[j]=="" )
  3925. {
  3926. iInsertIndex = j;
  3927. break;
  3928. }
  3929. //if( -1 != m_PIC_VAR[iIndex].sCaption[j].Find( sVarName ) )
  3930. if( m_PIC_VAR[iIndex].sCaption[j] == sVarName )
  3931. {
  3932. bRet = true;
  3933. break;
  3934. }
  3935. }
  3936. return bRet;
  3937. }
  3938. void CMainFrame::GetCurPicVarToSArray( CString sPicPath )
  3939. {
  3940. //LOG4C((LOG_NOTICE, "开始获取 当前画面%s 变量", sPicPath));
  3941. for( int i=0;i<VIEW_MAX_NUM;i++ )
  3942. {
  3943. if( m_PIC_VAR[i].sPicPath=="" )
  3944. {
  3945. LOG4C((LOG_NOTICE, "没有画面" ));
  3946. break;
  3947. }
  3948. if( m_PIC_VAR[i].sPicPath==sPicPath )//是当前画面
  3949. {
  3950. //pVariantsManager->m_bIsChangeView = true;
  3951. //Sleep(300);
  3952. //LOG4C((LOG_NOTICE, "init"));
  3953. //EnterCriticalSection( &g_CSLimit );
  3954. //LOG4C((LOG_NOTICE, "in"));
  3955. //pVariantsManager->m_analogTemp.RemoveAll();
  3956. for( int j=0;j<1000;j++ )
  3957. {
  3958. if( m_PIC_VAR[i].sCaption[j]=="" )
  3959. {
  3960. break;
  3961. }
  3962. //////////////////////////////////////////////////
  3963. int nVarSize = pVariantsManager->m_analog.GetSize();
  3964. for ( int nVarIndex = 0; nVarIndex< nVarSize; nVarIndex++)
  3965. {
  3966. CAnalog* analog = pVariantsManager->m_analog.GetAt(nVarIndex);
  3967. if( analog->m_strName == m_PIC_VAR[i].sCaption[j] )
  3968. {
  3969. //LOG4C((LOG_NOTICE, "当前画面变量 %s", analog->m_strName));
  3970. pVariantsManager->m_analogTemp.Add( analog );
  3971. }
  3972. }
  3973. //////////////////////////////////////////////////
  3974. }
  3975. //LOG4C((LOG_NOTICE, "out"));
  3976. //LeaveCriticalSection( &g_CSLimit );
  3977. //LOG4C((LOG_NOTICE, "end"));
  3978. pVariantsManager->m_bIsChangeView = true;
  3979. break;
  3980. }
  3981. }
  3982. //LOG4C((LOG_NOTICE, "结束获取 当前画面%s 变量", sPicPath));
  3983. }
  3984. bool CMainFrame::MakeFolderExist( CString DirectoryName )
  3985. {
  3986. if(DirectoryName[DirectoryName.GetLength()-1]!='\\')
  3987. DirectoryName += "\\";
  3988. int nStart = 3;
  3989. CString sTemp;
  3990. for(int n = nStart;n<DirectoryName.GetLength();n++)
  3991. {
  3992. if(DirectoryName[n]=='\\')
  3993. {
  3994. sTemp = DirectoryName.Left(n);
  3995. bool f = ExistFolder(sTemp);
  3996. if(!ExistFolder(sTemp))
  3997. CreateDirectoryCHN(sTemp);
  3998. }
  3999. }
  4000. return true;
  4001. }
  4002. bool CMainFrame::CreateDirectoryCHN(CString DirectoryName)
  4003. {
  4004. bool re=false;
  4005. ::CreateDirectory(DirectoryName,NULL);
  4006. //DWORD dwAttrs;
  4007. //dwAttrs=GetFileAttributes(DirectoryName);
  4008. //if(!(dwAttrs & FILE_ATTRIBUTE_HIDDEN))
  4009. //{
  4010. // SetFileAttributes(DirectoryName,dwAttrs|FILE_ATTRIBUTE_HIDDEN);
  4011. //}
  4012. return re;
  4013. }
  4014. bool CMainFrame::ExistFolder(CString FilePath)
  4015. {
  4016. return PathFileExists( FilePath );
  4017. }
  4018. void CMainFrame::CopyDirectory( CString sScrPath,CString sDescPath )
  4019. {
  4020. CString StrSourceFolder= sScrPath;
  4021. CString StrDestFolder=sDescPath;
  4022. char SourceFolder[MAX_PATH+1]= " ";
  4023. strcpy(SourceFolder,StrSourceFolder);
  4024. char TargetFolder[MAX_PATH+1]= " ";
  4025. strcpy(TargetFolder,StrDestFolder);
  4026. SHFILEOPSTRUCT lpFile;
  4027. lpFile.hwnd=GetSafeHwnd();
  4028. lpFile.wFunc=FO_COPY;
  4029. lpFile.pFrom=SourceFolder;
  4030. lpFile.pTo=TargetFolder;
  4031. lpFile.fFlags=FOF_ALLOWUNDO;
  4032. lpFile.fAnyOperationsAborted=FALSE;
  4033. lpFile.hNameMappings=NULL;
  4034. lpFile.lpszProgressTitle=NULL;
  4035. int ReturnValue=SHFileOperation(&lpFile);
  4036. if(ReturnValue==0)
  4037. {
  4038. if(lpFile.fAnyOperationsAborted==TRUE)
  4039. ;//MessageBox( "复制文件夹的操作被取消 ", "信息提示 ",MB_OK+MB_ICONWARNING);
  4040. else
  4041. ;//MessageBox( "复制文件夹操作成功 ", "信息提示 ",MB_OK+MB_ICONWARNING);
  4042. }
  4043. else
  4044. ;//MessageBox( "复制文件夹操作失败 ", "信息提示 ",MB_OK+MB_ICONEXCLAMATION);
  4045. }
  4046. void CMainFrame::GetPicPathByTree( HTREEITEM hItemSelect,CString &sPath )
  4047. {
  4048. if( m_hMonitor==hItemSelect )
  4049. {
  4050. return;
  4051. }
  4052. CString strSelect = m_wndTree.GetItemText( hItemSelect );
  4053. sPath = strSelect + "\\" + sPath;
  4054. HTREEITEM hItemParent = m_wndTree.GetParentItem( hItemSelect );
  4055. if( hItemParent )
  4056. GetPicPathByTree( hItemParent,sPath );
  4057. }