MainFrm.cpp 119 KB

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