MainFrm.cpp 117 KB

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