1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633 |
- // MainFrm.cpp : CMainFrame 类的实现
- //
- #include "stdafx.h"
- #include "IDE.h"
- #include "Dlg_Pwd.h"
- #include "MainFrm.h"
- #include ".\mainfrm.h"
- #include <afxwin.h>
- #include <afxext.h>
- #include <math.h>
- #include <io.h>
- #include <time.h>
- #include <afxdao.h>
- //#include <afxtempl.h>
- #include "Shlwapi.h"
- #include "DrawObj.h"
- #include "Graph.h"
- #include "ViewNameDlg.h"
- #include "Login.h"
- #include "IDEView.h"
- #include "SystemParaSetDlg.h"
- #include "public.h"
- #include "SysLib.h"
- #include "analogdlg.h"
- #include "ffsco.h"
- #include "Wizard.h"
- #include "Serial.h"
- #include "Network.h"
- #include "DlgUserManager.h"
- #include "Dlg_GroupManage.h"
- #include "ScriptSetDlg.h"
- #include "DlgEditPwd.h"
- #include "DlgQueryWarningRec.h"
- #include "DlgSystemLog.h"
- #include "DlgNoticeRec.h"
- #include "Dlg_ActionWithAlarm.h"
- #include "Dlg_EditView.h"
- #include "FileAndFolderClass.h"
- using namespace helper_coffs;
- #pragma warning ( disable: 4800 )
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #endif
- #if USE_TRAYICON
- #define WM_MY_TRAY_NOTIFICATION WM_USER + 1
- const UINT WM_TASKBARCREATED =
- ::RegisterWindowMessage(_T("TaskbarCreated"));
- #endif
- // CMainFrame
- IMPLEMENT_DYNAMIC(CMainFrame, CMDIAutoHideFrame)
- BEGIN_MESSAGE_MAP(CMainFrame, CMDIAutoHideFrame)
- ON_WM_CREATE()
- ON_COMMAND(IP_SUPER_END, OnSuperEnd)
- ON_COMMAND(ID_TRAY_OPEN, OnTrayOpen)
- #if USE_TRAYICON
- ON_MESSAGE(WM_MY_TRAY_NOTIFICATION, OnTrayNotification)
- ON_REGISTERED_MESSAGE(WM_TASKBARCREATED, OnTaskBarCreated)
- #endif
- ON_WM_CLOSE()
- ON_COMMAND(ID_ADDDEVOCE, OnAdddevoce)
- ON_UPDATE_COMMAND_UI(ID_ADDDEVOCE, OnUpdateAdddevoce)
- ON_COMMAND(IDM_MENU_ZUTAIADD, OnZuTaiAdd)
- ON_UPDATE_COMMAND_UI(IDM_MENU_ZUTAIADD, OnUpdateZuTaiAdd)
- ON_COMMAND(ID_DELETEPORT, OnDeleteport)
- ON_UPDATE_COMMAND_UI(ID_DELETEPORT, OnUpdateDeleteport)
- ON_COMMAND(ID_ADD_PORT, OnAddPort)
- ON_UPDATE_COMMAND_UI(ID_ADD_PORT, OnUpdateAddPort)
- ON_COMMAND(ID_ADD_SCRIPT, OnAddScript)
- ON_UPDATE_COMMAND_UI(ID_ADD_SCRIPT, OnUpdateAddScript)
- ON_COMMAND(ID_ADDVIEW, OnAddview)
- ON_UPDATE_COMMAND_UI(ID_ADDVIEW, OnUpdateAddview)
- ON_COMMAND(ID_ADDVIEW2, OnAddview2)
- ON_UPDATE_COMMAND_UI(ID_ADDVIEW2, OnUpdateAddview2)
- ON_COMMAND(ID_ONLYADD_SORT, OnEditSort)
- ON_UPDATE_COMMAND_UI(ID_ONLYADD_SORT, OnUpdateEditSort)
- ON_COMMAND(ID_DELETEDEVICE, OnDeletedevice)
- ON_UPDATE_COMMAND_UI(ID_DELETEDEVICE, OnUpdateDeletedevice)
- ON_COMMAND(ID_DELETEVIEW, OnDeleteview)
- ON_UPDATE_COMMAND_UI(ID_DELETEVIEW, OnUpdateDeleteview)
- ON_COMMAND(ID_MODIFYVIEWNAME, OnModifyViewName)
- ON_UPDATE_COMMAND_UI(ID_MODIFYVIEWNAME, OnUpdateModifyViewName)
- ON_COMMAND(ID_DELETESCRIPT, OnDeletescript)
- ON_UPDATE_COMMAND_UI(ID_DELETESCRIPT, OnUpdateDeletescript)
- ON_COMMAND(ID_SETSCRIPT, OnSetscript)
- ON_UPDATE_COMMAND_UI(ID_SETSCRIPT, OnUpdateSetscript)
- ON_COMMAND(ID_EDITSCRIPT, OnEditscript)
- ON_UPDATE_COMMAND_UI(ID_EDITSCRIPT, OnUpdateEditscript)
- ON_COMMAND(ID_USERS, OnUsers)
- ON_UPDATE_COMMAND_UI(ID_USERS, OnUpdateUsers)
- ON_COMMAND(ID_EDITPWD, OnEditPwdTool)
- ON_UPDATE_COMMAND_UI(ID_EDITPWD, OnUpdateEditPwd)
- ON_COMMAND(ID_SYSPARE, OnSysPara)
- ON_UPDATE_COMMAND_UI(ID_SYSPARE, OnUpdateSysPare)
- ON_COMMAND(ID_EVENTMANAGE, OnEventmanage)
- ON_COMMAND(ID_EVENT, OnEvent)
- ON_COMMAND(ID_SUMMARY_LOG, OnSummaryLog)
- ON_UPDATE_COMMAND_UI(ID_EVENT, OnUpdateEvent)
- ON_UPDATE_COMMAND_UI(ID_SUMMARY_LOG, OnUpdateSummaryLog)
- ON_COMMAND(ID_CONTROLDIALOG, OnControldialog)
- ON_WM_DESTROY()
- ON_WM_TIMER()
- ON_COMMAND(ID_SYSTEMLOG, OnSystemLog)
- ON_UPDATE_COMMAND_UI(ID_SYSTEMLOG, OnUpdateSystemLog)
- ON_COMMAND(ID_NOTICEREC, OnNoticeRec)
- ON_UPDATE_COMMAND_UI(ID_NOTICEREC, OnUpdateNoticeRec)
- ON_COMMAND(ID_USER_MANAGER, OnUserManager)
- ON_COMMAND(ID_EDIT_PWD, OnEditPwd)
- ON_COMMAND(ID_GROUP_MANAGER, OnGroupManager)
- ON_COMMAND(ID_SINGLE_ANALOG, OnSingleAnalog)
- ON_UPDATE_COMMAND_UI(ID_SINGLE_ANALOG, OnUpdateSingleAnalog)
- ON_UPDATE_COMMAND_UI(ID_FILE_PRINT, OnUpdatePrint)
- END_MESSAGE_MAP()
- static UINT indicators[] =
- {
- ID_SEPARATOR, // 状态行指示器
- ID_INDICATOR_CAPS,
- ID_INDICATOR_NUM,
- ID_INDICATOR_SCRL,
- };
- HANDLE m_hFreshVarThread;
- HANDLE m_hReConnectSrvThread;
- static DWORD WINAPI FreshVarThread( void *pData );
- static DWORD WINAPI FreshVarCurPicThread( void *pData );
- CRITICAL_SECTION g_CSLimit;
- // CMainFrame 构造/析构
- CMainFrame::CMainFrame():m_trayIcon(IDR_TRAYICON)
- {
- // TODO: 在此添加成员初始化代码
- m_bShowTrayNotifications = TRUE;//zxn
- m_bShutdown = FALSE;//zxn
- #if USE_NEWTOP
- m_pToolBar = NULL;
- #else
- m_wndOfTop = NULL;
- #endif
- g_bRun=FALSE;
- g_nElementNo=0; //选择
- g_bEdit=TRUE;
- m_bHideLeft=FALSE;
- m_mousePoint=CPoint(0,0);
- // View个数
- m_nViewCount = 0;
- m_nPortNum = 0;
- m_nScripts = 0;
- int i, j;
- //mdi子窗体
- for( i = 0; i < MAX_VIEW_NUM; i++ )
- {
- m_pViewIDE[i] = NULL;
- }
- //串口设备
- for( i = 0; i < MAX_SERIAL_NUM; i++ )
- {
- for( j = 0; j < MAX_DEVICE_NUM; j++ )
- {
- m_hSerialDev[i][j] = NULL;
- }
- }
- //串口组
- for( i = 0; i < MAX_SERIAL_NUM; i++ )
- {
- m_hSerialGroup[i] = NULL;
- }
- //以太网设备
- for( i = 0; i < MAX_NETWORK_NUM; i++ )
- {
- m_hNetworkDev[i] = NULL;
- }
- //脚本
- for( i = 0; i < MAX_SCRIPT_NUM; i++ )
- {
- m_hScriptGroup[i] = NULL;
- }
- m_bEvent = true;
- m_bPrint = true;
- m_bUsers = true;
- m_bSysPare = true;
- m_bAnalog = true;
- m_bDeviceLog = true;
- m_bSystemLog = true;
- m_bNoticeRec = true;
- m_bEditPwd = true;
- m_hCurrent = NULL;
- for( int i=0;i<VIEW_MAX_NUM;i++ )
- {
- m_PIC_VAR[i].sPicPath = "";
- for( int j=0;j<1000;j++ )
- {
- m_PIC_VAR[i].sCaption[j] = "";
- m_PIC_VAR[i].nType[i] = 0;
- }
- }
- g_nRunEditVarTick = 0;//在运行状态编辑变量的TICK
- g_bRunEditVar = false;//是否在运行状态编辑变量
- m_dlgEvent = NULL;
- m_dlgControl = NULL;
- m_pDlgZuTaiAdd = NULL;
- }
- CMainFrame::~CMainFrame()
- {
- }
- #if USE_TRAYICON
- BOOL CMainFrame::InstallIcons()
- {
- return Shell_NotifyIcon(NIM_ADD, &m_trayIcon.m_nid);
- }
- LRESULT CMainFrame::OnTaskBarCreated(WPARAM wp, LPARAM lp)
- {
- VERIFY(InstallIcons());
- return 0;
- }
- //////////////////
- // Handle notification from tray icon: display a message.
- //
- LRESULT CMainFrame::OnTrayNotification(WPARAM uID, LPARAM lEvent)
- {
- if (m_bShowTrayNotifications) {
- static LPCSTR MouseMessages[] = { "WM_MOUSEMOVE",
- "WM_LBUTTONDOWN", "WM_LBUTTONUP", "WM_LBUTTONDBLCLK",
- "WM_RBUTTONDOWN", "WM_RBUTTONUP", "WM_RBUTTONDBLCLK",
- "WM_MBUTTONDOWN", "WM_MBUTTONUP", "WM_MBUTTONDBLCLK" };
- }
- // let tray icon do default stuff
- return m_trayIcon.OnTrayNotification(uID, lEvent);
- }
- #endif
- int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
- {
- if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
- return -1;
- if (!m_wndTree.Create(WS_CHILD|WS_VISIBLE|
- TVS_HASLINES|TVS_HASBUTTONS|TVS_LINESATROOT,
- CRect(0, 0, 0, 0), this, IDD_TREE_LEFT))
- {
- TRACE0("Failed to create instant bar child\n");
- return -1;
- }
-
- if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
- | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
- !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
- {
- TRACE0(g_strTrace2);
- return -1; // 未能创建
- }
- if (!m_wndDrawToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
- | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
- !m_wndDrawToolBar.LoadToolBar(IDR_DRAWTOOLS))
- {
- TRACE0("Failed to create toolbar\n");
- return -1; // fail to create
- }
- if (!m_wndDrawAlignBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
- | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
- !m_wndDrawAlignBar.LoadToolBar(IDR_ALIGN))
- {
- TRACE0("Failed to create toolbar\n");
- return -1; // fail to create
- }
- //if (!m_wndRunToolBar.Create(this) ||
- // !m_wndRunToolBar.LoadToolBar(IDR_RUNTOOLBAR))
- //{
- // TRACE0("Failed to create toolbar\n");
- // return -1; // fail to create
- //}
- if (!m_wndStatusBar.Create(this) ||
- !m_wndStatusBar.SetIndicators(indicators,
- sizeof(indicators)/sizeof(UINT)))
- {
- TRACE0("未能创建状态栏\n");
- return -1; // 未能创建
- }
- // m_wndRunToolBar.SetBitmap( IDB_LG, COOBmpToolBar::LargeHot, RGB( 33, 231, 222 ) );
- // m_wndRunToolBar.SetBitmap( IDB_LG, COOBmpToolBar::LargeStandard, RGB( 33, 231, 222 ) );
- // m_wndRunToolBar.InitImageList();
- //m_wndRunToolBar.SetTextMode(TRUE);
- // TODO: 如果不需要工具栏可停靠,则删除这三行
- m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
- m_wndDrawToolBar.EnableDocking(CBRS_ALIGN_ANY);
- m_wndDrawAlignBar.EnableDocking(CBRS_ALIGN_ANY);
- EnableDocking(CBRS_ALIGN_ANY);
- DockControlBar(&m_wndToolBar);
- m_wndStatusBar.SetPaneInfo(1, ID_INDICATOR_LOG, SBPS_NOBORDERS,160);
- m_wndStatusBar.SetPaneInfo(3, ID_INDICATOR_LOG, SBPS_NOBORDERS,80);
- RecalcLayout();
- CRect rect;
- m_wndToolBar.GetWindowRect(rect);
- rect.OffsetRect(1, 0); //偏移一个位置
- DockControlBar(&m_wndDrawAlignBar, CBRS_ALIGN_ANY, rect);
- DockControlBar(&m_wndDrawToolBar);
- //m_wndRunToolBar.EnableDocking(FALSE);
- //m_wndRunToolBar.ShowWindow(SW_HIDE);
- //上面工具栏
- if( g_bStartRun && g_nToolbarRun )
- {
- //if (!m_wndDockPageBar3.Create(_T("DockPageBar3"), this, CSize(230,105),TRUE,123))
- // CSize(),是用来设置高和宽的.
- if (!m_htopDockBar.Create(_T("topDockbar"), this, CSize(1920,78),TRUE,123))
- {
- TRACE0("创建顶部工具栏失败.\n");
- return -1;
- }
- m_htopDockBar.SetBarStyle(m_htopDockBar.GetBarStyle() | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC );
- m_htopDockBar.EnableDocking (CBRS_ALIGN_ANY);
- m_htopDockBar.m_bDrawTitleBar = false;
- DockControlBar(&m_htopDockBar, AFX_IDW_DOCKBAR_TOP);
- }
- //左边树形
- if (!m_hleftDockBar.Create(_T("leftDockbar"), this, CSize(180,260),TRUE,123))
- {
- TRACE0("创建左侧边栏失败.\n");
- return -1;
- }
- m_hleftDockBar.SetBarStyle(m_hleftDockBar.GetBarStyle() |
- CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC );
- m_hleftDockBar.EnableDocking (CBRS_ALIGN_ANY);
- DockControlBar(&m_hleftDockBar, AFX_IDW_DOCKBAR_LEFT);
-
- CString strTitle;
- strTitle.LoadString(IDS_TREE_TITLE);
- m_hleftDockBar.AddPage(&m_wndTree, strTitle, IDR_MAINFRAME);
- //下面通知列表
- if (!m_hbottomDockBar.Create(_T("bottomDockbar"), this, CSize(230,120),TRUE,123))
- {
- TRACE0("创建底部通知栏失败.\n");
- return -1;
- }
- m_hbottomDockBar.SetBarStyle(m_hbottomDockBar.GetBarStyle() |
- CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC );
- m_hbottomDockBar.EnableDocking (CBRS_ALIGN_BOTTOM);
-
- DockControlBar(&m_hbottomDockBar, AFX_IDW_DOCKBAR_BOTTOM);
- CDrawObj::RegisterClass(g_strTline,RUNTIME_CLASS(CDrawTLine));
- CDrawObj::RegisterClass(g_strText,RUNTIME_CLASS(CDrawText));
- CDrawObj::RegisterClass(g_strRect,RUNTIME_CLASS(CDrawRect));
- CDrawObj::RegisterClass(g_strOval,RUNTIME_CLASS(CDrawOval));
- CDrawObj::RegisterClass(g_strButton,RUNTIME_CLASS(CDrawButton));
- CDrawObj::RegisterClass(g_strData,RUNTIME_CLASS(CDrawDatabox));
- CDrawObj::RegisterClass(g_strLed,RUNTIME_CLASS(CDraw3dCircle));
- CDrawObj::RegisterClass(g_strBar,RUNTIME_CLASS(CDrawBar));
- CDrawObj::RegisterClass(g_strCurve,RUNTIME_CLASS(CDrawCurve));
- CDrawObj::RegisterClass(g_strLine,RUNTIME_CLASS(CDrawLine));
- CDrawObj::RegisterClass(g_strBreaker,RUNTIME_CLASS(CDrawBreaker));
- CDrawObj::RegisterClass(g_strSwitch,RUNTIME_CLASS(CDrawSwitch));
- CDrawObj::RegisterClass(g_strGrid,RUNTIME_CLASS(CDrawGrid));
- CDrawObj::RegisterClass(g_strBitmap,RUNTIME_CLASS(CDrawBitmap));
- //CDrawObj::RegisterClass(g_strGif, RUNTIME_CLASS(CDrawGif));
- CDrawObj::RegisterClass(g_strTransfer,RUNTIME_CLASS(CDrawTransfer));
- CDrawObj::RegisterClass(g_strArc,RUNTIME_CLASS(CDrawArc));
- CDrawObj::RegisterClass(g_strArrow,RUNTIME_CLASS(CDrawArrow));
- CDrawObj::RegisterClass(g_strPoly,RUNTIME_CLASS(CDrawPoly));
- CDrawObj::RegisterClass(g_strMLine,RUNTIME_CLASS(CDrawMLine));
- CDrawObj::RegisterClass(g_strPipe,RUNTIME_CLASS(CDrawPipe));
- CDrawObj::RegisterClass(g_strZhePipe,RUNTIME_CLASS(CDrawZhePipe));
- CDrawObj::RegisterClass(g_strYPipe,RUNTIME_CLASS(CDrawYPipe));
- CDrawObj::RegisterClass(g_strWatch,RUNTIME_CLASS(CDrawWatch));
- CDrawObj::RegisterClass(g_strSingleBar,RUNTIME_CLASS(CDrawSingleBar));
- CDrawObj::RegisterClass(g_strRoundRect,RUNTIME_CLASS(CDrawRoundRect));
- CDrawObj::RegisterClass(g_strPie,RUNTIME_CLASS(CDrawPie));
- CDrawObj::RegisterClass(g_strFan,RUNTIME_CLASS(CDrawFan));
- CDrawObj::RegisterClass(g_strHisCurve,RUNTIME_CLASS(CDrawHisCurve));
- CDrawObj::RegisterClass(g_strTable,RUNTIME_CLASS(CDrawTable));
- CDrawObj::RegisterClass(g_strComposite,RUNTIME_CLASS(CDrawComposite));
- CDrawObj::RegisterClass(g_strOCX,RUNTIME_CLASS(CDrawOCX));
- //CDrawObj::RegisterClass(g_strGIF,RUNTIME_CLASS(CDrawGif));
- CDrawObj::RegisterClass(g_strFlash,RUNTIME_CLASS(CDrawFlash));
- pDevicesManager = new CDevicesManager;
- if ( pDevicesManager == NULL )
- {
- printf("创建CDevicesManager失败\n");
- }
- else
- {
- printf("pDevicesManager = %p\n", pDevicesManager);
- }
- pVariantsManager = new CVariantsManager;
- if ( pVariantsManager == NULL )
- {
- printf("创建CVariantsManager失败\n");
- }
- else
- {
- printf("pVariantsManager = %p\n", pVariantsManager);
- }
- pDevicesManager->SetDBType(g_strDBType);
- pVariantsManager->SetDBType(g_strDBType);
- pVariantsManager->m_strLowerLimit = CString(g_strLowerLimit)+CString(g_strAlarm);
- pVariantsManager->m_strUpperLimit = CString(g_strUpperLimit)+CString(g_strAlarm);
- pVariantsManager->m_strCurrValue = CString(g_strCurrValue);
- pVariantsManager->m_strReturnNormal = CString(g_strReturnNormal2);
- pEventServer = new CEventServer;
- pEventServer->m_bValid = true;
- pEventServer->Validate( g_bEventAlarm );
- // 一定要先load设备管理,否则变量无法关联到设备
- if( g_nIsDemo == 1 )
- {
- pDevicesManager->Load(g_strDirectory);
- pVariantsManager->Load(g_strDirectory);
- }
- else
- {
- pDevicesManager->GetDevInfo();//pDevicesManager->Load(g_strDirectory);//
- pVariantsManager->GetVarInfo();//pVariantsManager->Load(g_strDirectory);
- pVariantsManager->ReadAreaDericeUid(g_strDirectory);
- }
- LoadRunPara();
- ///////////////////////////////////////////////////////////////////////
- //MakeFolderExist( "D:\\isP-Other\\StoueULog\\" );
- //////////////////////////////////////////////////////////////
- if( g_nIsDemo == 0 )
- {
- bool bIsBoxAppear = false;
- for( int iPortIndex=0;iPortIndex<2;iPortIndex++ )
- {
- CString sPortTemp;
- sPortTemp.Format("%d",atoi(g_strServerPort)+iPortIndex );
- if( !pDevicesManager->Connection(g_strServerIP,sPortTemp) )
- {
- LOG4C((LOG_NOTICE, "Socket Port %s 连接失败(%d)",sPortTemp,GetLastError()));
- if( !bIsBoxAppear && g_iAutoRunSystem==0 )
- MessageBox(g_strConnectionFailed, g_strTip, MB_ICONINFORMATION);
- bIsBoxAppear = true;
- pDevicesManager->SetSocketStatus(FALSE,sPortTemp);
- //break;
- }
- else
- {
- pDevicesManager->SetSocketStatus(TRUE,sPortTemp);
- pVariantsManager->SetSysComunicationVar( 0.0 );
- if( TRUE == pDevicesManager->GetSocketStatus( sPortTemp ) )
- {
- LOG4C((LOG_NOTICE, "Socket Port %s 连接成功(%d)",sPortTemp,GetLastError()));
- }
- if( iPortIndex==0 )
- pDevicesManager->GetServerVer( sPortTemp );
- }
- }
- }
- CRect rect1;
- GetWindowRect(&rect1);
- ScreenToClient(&rect1);
- pVariantsManager->m_bAnalogAlarm = g_bYcEvent;
- if( g_nAlarmModeIsDlg && g_bStartRun )
- {
- int screenx=GetSystemMetrics(SM_CXSCREEN);
- int screeny=GetSystemMetrics(SM_CYSCREEN);
- //系统任务栏的高度
- HWND hWnd = ::FindWindow("Shell_TrayWnd", NULL);
- RECT rc;
- ::GetWindowRect(hWnd, &rc);
- int nHeight = rc.bottom-rc.top;
- m_dlgEvent = new CRealEventDlg();
- m_dlgEvent->Create(IDD_REALEVENT, this);
- //m_dlgEvent->ShowWindow(SW_HIDE);
- CRect rct;
- m_dlgEvent->GetWindowRect(&rct);
- m_dlgEvent->SetWindowPos(&wndTop, (screenx-rct.Width())/2, screeny-rct.Height()-nHeight, rct.Width(), rct.Height(), SWP_NOZORDER);
- m_dlgControl = new CDlgBmp();
- m_dlgControl->Create(IDD_DIALOGCONTROL, this);
- m_dlgControl->ShowWindow(SW_HIDE);
- CRect rct1;
- m_dlgControl->GetWindowRect(&rct1);
- m_dlgControl->SetWindowPos(&wndTop, screenx-rct1.Width(), screeny-rct1.Height(), rct1.Width(), rct1.Height(), SWP_NOZORDER);
- m_hbottomDockBar.AddPage(m_dlgEvent, g_strNoticeList, IDI_WARING);
- }
- if( !g_bStartRun )
- {
- m_pDlgZuTaiAdd = new CDlg_ZuTaiAdd();
- m_pDlgZuTaiAdd->Create(IDD_DLG_ZUTAI_ADD, this);
- m_pDlgZuTaiAdd->ShowWindow(SW_HIDE);
- int screenx=GetSystemMetrics(SM_CXSCREEN);
- int screeny=GetSystemMetrics(SM_CYSCREEN);
- //系统任务栏的高度
- HWND hWnd = ::FindWindow("Shell_TrayWnd", NULL);
- RECT rc;
- ::GetWindowRect(hWnd, &rc);
- int nHeight = rc.bottom-rc.top;
- CRect rct;
- m_pDlgZuTaiAdd->GetWindowRect(&rct);
- m_pDlgZuTaiAdd->SetWindowPos(&wndTop, (screenx-rct.Width())/2, (screeny-rct.Height())/2, rct.Width(), rct.Height(), SWP_NOZORDER);
- }
- // 初始化左边树形
- InitTreeInfo();
- int W=0,H=0;
- if (g_bStartRun)
- {
- if( g_nIsDemo == 0 )
- {
- // 加载脚本信息
- //LoadScriptFromFiles();
- }
- OnRun();
- }
- else
- {
- //LONG style=::GetWindowLong(m_hWnd,GWL_STYLE);
- //style&=~WS_CAPTION;
- //style&=~WS_BORDER;
- //::SetWindowLong(m_hWnd,GWL_STYLE,style);
- int screenx=GetSystemMetrics(SM_CXSCREEN);
- int screeny=GetSystemMetrics(SM_CYSCREEN);
- // 系统任务栏的高度;
- HWND hWnd = ::FindWindow("Shell_TrayWnd", NULL);
- RECT rc;
- ::GetWindowRect(hWnd, &rc);
- int nHeight = rc.bottom -rc.top;
- printf("非全屏下计算任务栏高度:%d\n", nHeight);
- if( !g_bFullScreen )
- {
- W = screenx;
- H = screeny - nHeight;
- // 以屏幕尺寸的3/2来显示 [5/11/2016 IT]
- W /= 2;
- H /= 2;
- printf("W:%d, H:%d\n", W, H);
- //SetWindowPos(&wndTopMost,0,0,screenx,screeny-nHeight,SWP_NOZORDER);
- }
- else
- {
- W = screenx;
- H = screeny;
- //SetWindowPos(NULL,0,0,screenx,screeny,SWP_NOZORDER);// 全屏
- }
- }
- #if USE_TRAYICON
- m_trayIcon.SetNotificationWnd(this, WM_MY_TRAY_NOTIFICATION);
- m_trayIcon.SetIcon(IDR_MAINFRAME);
- #endif
- // Install the tab view here
- VERIFY(m_MDIClient.SubclassMDIClient(this, &m_wndViewManager));
- if( g_nToolbarTop )
- {
- m_wndViewManager.ShowWindow(SW_SHOW);
- }
- else
- {
- m_wndViewManager.ShowWindow(SW_HIDE);
- }
- if( g_strStartPic.Compare("") )
- {
- char picDir[_MAX_PATH] = {0};
- strcpy(picDir, g_strDirectory);
- strcat(picDir, "\\");
- strcat(picDir, _PICTUREDIR);
- strcat(picDir, g_strStartPic);
- strcat(picDir, ".view");
- AddIDEView( g_strStartPic, CString(picDir) );
- }
- if( g_nIsPoll == 1 )
- {
- SetTimer(1, 1000, NULL);
- }
- if( g_bStartRun )
- {
- ShowCaptionMenu(FALSE);
- }
- if( -1==PMS_VerifyUserPermit( g_nUserID,PMS_R_ALARM_SEARCH,"" ) )
- {
- m_bEvent = false;
- }
- if( -1==PMS_VerifyUserPermit( g_nUserID,PMS_R_PRINT,"" ) )
- {
- m_bPrint = false;
- }
- if( -1==PMS_VerifyUserPermit( g_nUserID,PMS_R_USER_MANAGE,"" ) )
- {
- m_bUsers = false;
- }
- if( -1==PMS_VerifyUserPermit( g_nUserID,PMS_R_RUNSTATUS,"" ) )
- {
- m_bSysPare = false;
- }
- if( -1==PMS_VerifyUserPermit( g_nUserID,PMS_R_DICT,"" ) )
- {
- m_bAnalog = false;
- }
- if( -1==PMS_VerifyUserPermit( g_nUserID,PMS_R_DEVICELOG,"" ) )
- {
- m_bDeviceLog = false;
- }
- if( -1==PMS_VerifyUserPermit( g_nUserID,PMS_R_SYSTEMLOG,"" ) )
- {
- m_bSystemLog = false;
- }
- if( -1==PMS_VerifyUserPermit( g_nUserID,PMS_R_NITICEREC,"" ) )
- {
- m_bNoticeRec = false;
- }
- if( -1==PMS_VerifyUserPermit( g_nUserID,PMS_R_EDITPWD,"" ) )
- {
- m_bEditPwd = false;
- }
- //展开树
- //m_wndTree.Expand(m_wndTree.GetRootItem(),TVE_EXPAND);
- //HTREEITEM handleTreeItem = m_wndTree.GetRootItem();
- //while(handleTreeItem)
- //{
- // handleTreeItem = m_wndTree.GetChildItem(handleTreeItem);
- // m_wndTree.Expand(handleTreeItem, TVE_EXPAND);
- //}
- MyExpandTree( m_wndTree.GetRootItem() );
- m_wndStatusBar.SetPaneText(2, "ver");
- m_wndStatusBar.SetPaneText(3, g_strVersion);
- if( g_bRun )
- SetTimer(2, 1000*15*1, NULL);//狗信息定时器
- //SetTimer(3, 1000*60*2, NULL);//判断变量在这个时间段时否报警
- if( !g_nToolbarLeft && g_bStartRun )
- m_hleftDockBar.ShowWindow( SW_HIDE );
- //m_wndDockPageBar1.OnStudClick();
- //通知列表
- if( g_nAlarmModeIsDlg && g_bRun )
- {
- m_hbottomDockBar.ShowWindow(SW_SHOW);
- CSize sz;
- sz = m_hbottomDockBar.GetHorSize();
- m_dlgEvent->SetPos( sz.cx,sz.cy );
- m_hbottomDockBar.OnStudClick();
- }
- else
- {
- m_hbottomDockBar.ShowWindow(SW_HIDE);
- }
- //工具栏
- if( g_bStartRun && g_nToolbarRun )
- {
- #if USE_NEWTOP
- m_pToolBar = new CDlg_ToolBar();
- m_pToolBar->Create(IDD_DLG_TOOLBAR, this);
- m_pToolBar->ShowWindow( SW_SHOW );
- m_htopDockBar.AddPage( m_pToolBar, "工具栏", IDR_MAINFRAME );
- m_htopDockBar.ShowWindow(SW_SHOW);
- CSize sz;
- sz = m_htopDockBar.GetHorSize(); // 获取顶部工具栏大小;
- m_pToolBar->SetPos( sz.cx,sz.cy );
- #else
- // 1.获取实际工具栏长宽 [8/29/2013 Z.t]
- CSize sz;
- sz = m_htopDockBar.GetHorSize();
- printf("x:%d, y:%d \n",sz.cx, sz.cy);
- // 2.创建工具栏上的对话框 [8/29/2013 Z.t]
- m_wndOfTop = new CDlgOfTop();
- // 3.传递对话框的大小;
- m_wndOfTop->_ClientSize.cx = sz.cx;
- m_wndOfTop->_ClientSize.cy = sz.cy;
- m_wndOfTop->Create(IDD_TOP, this);
- m_wndOfTop->ShowWindow( SW_SHOW );
- m_htopDockBar.AddPage( m_wndOfTop, "工具栏", IDR_MAINFRAME );
- m_htopDockBar.ShowWindow(SW_SHOW);
- //m_wndOfTop->CalcWindowRect(sz);
- #if 0 // 一直为1 [8/29/2013 Z.t]
- m_wndOfTop->MoveWindow(0,0,sz.cx,sz.cy);
- CRect rtOfTop;
- m_wndOfTop->GetWindowRect(rtOfTop);
- // sz,得到是运行后工具栏的实际长宽 [7/27/2013 Zero]
- // sy,得到是创建m_htopDockBar时的原始大小 [7/27/2013 Zero]
- CSize sy = m_htopDockBar.GetVerSize();
-
- //m_wndOfTop->SetPos( sz.cx,sz.cy );
- TRACE("--on--");
- #endif
- #endif
- }
-
- if( !g_bStartRun && g_nIsDemo==0 )
- {
- this->SetFocus();
- // 使连接服务器失败的情况下,第一时间显示在桌面;
- SetWindowPos(NULL,0,0,W,H,SWP_NOZORDER);
- CenterWindow();
- }
- else if( g_nIsDemo==1 )
- {
- printf("g_nIsDemo = 1\n");
- int screenx=GetSystemMetrics(SM_CXSCREEN);
- int screeny=GetSystemMetrics(SM_CYSCREEN);
- //系统任务栏的高度
- HWND hWnd = ::FindWindow("Shell_TrayWnd", NULL);
- RECT rc;
- ::GetWindowRect(hWnd, &rc);
- int nHeight = rc.bottom-rc.top;
- SetWindowPos(NULL,0,0,screenx,screeny-nHeight,SWP_NOZORDER);
- }
- return 0;
- }
- void CMainFrame::MyExpandTree(HTREEITEM hTreeItem)
- {
- if(!m_wndTree.ItemHasChildren(hTreeItem))
- {
- return;
- }
- HTREEITEM hNextItem = m_wndTree.GetChildItem(hTreeItem);
- while (hNextItem != NULL)
- {
- MyExpandTree(hNextItem);
- hNextItem = m_wndTree.GetNextItem(hNextItem, TVGN_NEXT);
- }
- m_wndTree.Expand(hTreeItem,TVE_EXPAND);
- }
- DWORD WINAPI CMainFrame::ViewPollThread( void *pData )
- {
- CMainFrame *pMainFrm = (CMainFrame *)pData;
- DWORD dwTick = 0;
- do
- {
- if (g_bStartRun && g_nIsPoll == 1)
- {
- for( int i = 0; i < g_nPollCount; i++ )
- {
- if( dwTick == 0 )
- {
- if( g_nPollIndex == i )
- {
- dwTick = GetTickCount();
- if( pMainFrm )
- {
- //TRACE("Enter AddIDEView %s, %s\r\n", g_strPollPath, g_strPollDesc);
- //pMainFrm->AddIDEView(g_strPollDesc[i], g_strPollPath[i]);
- //TRACE("Leave AddIDEView\r\n");
- ((CIDEView *)pMainFrm->m_pActiveView)->ChangeView();
- int nIndex = pMainFrm->GetIDEViewIndex(g_strPollPath[i]);
- if( nIndex == -1 )
- {
- nIndex = pMainFrm->GetIDEViewFreeIndex(g_strPollPath[i]);
- if( nIndex == -1 ) nIndex = 0;
- CCreateContext context;
- pMainFrm->m_pViewIDE[nIndex] = new CChildFrame;
- pMainFrm->m_pViewIDE[nIndex]->m_strPath = g_strPollPath[i];
- pMainFrm->m_pViewIDE[nIndex]->m_strDesc = g_strPollDesc[i];
- context.m_pCurrentDoc = pMainFrm->m_pDoc;
- context.m_pNewDocTemplate = pMainFrm->m_pDoc->GetDocTemplate();
- context.m_pNewViewClass = RUNTIME_CLASS( CIDEView );
- context.m_pCurrentFrame = pMainFrm;
- context.m_pLastView = NULL;
- if( !pMainFrm->m_pViewIDE[nIndex]->LoadFrame(IDI_SUMMARY, WS_MAXIMIZE|WS_OVERLAPPEDWINDOW, pMainFrm, &context) )
- {
- }
- pMainFrm->m_pViewIDE[nIndex]->ShowWindow(SW_SHOWMAXIMIZED);
- pMainFrm->m_pViewIDE[nIndex]->InitialUpdateFrame(pMainFrm->m_pDoc,true);
- pMainFrm->m_pViewIDE[nIndex]->MDIActivate();
- pMainFrm->m_nViewCount++;
- }
- else
- {
- pMainFrm->m_pActiveView = (CFormView *)pMainFrm->m_pViewIDE[nIndex]->GetActiveView();
- pMainFrm->m_pViewIDE[nIndex]->MDIActivate();
- }
- pMainFrm->m_pViewIDE[ nIndex ]->m_bClose = FALSE;
- pMainFrm->m_pActiveView = (CFormView *)pMainFrm->m_pViewIDE[nIndex]->GetActiveView();
- g_strViewName = g_strPollPath[i];
- ((CIDEView *)pMainFrm->m_pActiveView)->ChangeView();
- }
- }
- }
- else if( GetTickCount() - dwTick > (DWORD)g_nPollInterval * 1000 )
- {
- if( g_nPollIndex == g_nPollCount - 1 )
- {
- g_nPollIndex = 0;
- }
- else
- {
- g_nPollIndex++;
- }
- dwTick = 0;
- }
- }
- }
- }while( WaitForSingleObject( g_hRunObject, 125L ) == WAIT_TIMEOUT );
- return 0;
- }
- void CMainFrame::ShowCaptionMenu(BOOL bShow)
- {
- static HMENU hMenu=NULL;
- if(hMenu == NULL)
- {
- hMenu=::GetMenu(this->GetSafeHwnd());
- }
- if(bShow)
- {
- ::SetMenu(this->GetSafeHwnd(),hMenu);
- this->ModifyStyle(0,WS_CAPTION,SWP_FRAMECHANGED);
- }
- else
- {
- ::SetMenu(this->GetSafeHwnd(),NULL);
- this->ModifyStyle(WS_CAPTION,0,SWP_FRAMECHANGED);
- }
- }
- void CMainFrame::LoadRunPara()
- {
- char Path[_MAX_PATH] = {0};
- strcat(Path, g_strDirectory);
- strcat(Path,"\\");
- strcat(Path, _PROJECTDIR);
- strcat(Path,"\\");
- strcat(Path, "runpara.ini");
- char RUN[MAX_PATH] = {0};
- memset(RUN, 0, sizeof(RUN));
- //CString str;
- if ( GetPrivateProfileString("RUNPARA", "STARTRUN","",RUN, 10, Path) != 0)
- {
- g_bStartRun = (RUN[0] == '1' ? true:false);
- }
- if ( GetPrivateProfileString("RUNPARA", "STARTPIC","", RUN, sizeof(RUN), Path) != 0)
- {
- g_strStartPic = RUN;
- }
- if ( GetPrivateProfileString("RUNPARA", "STARTPATH","",RUN, sizeof(RUN), Path) != 0)
- {
- g_strStartPath = RUN;
- }
- if ( GetPrivateProfileString("RUNPARA", "ALARM","",RUN, 10, Path) != 0)
- {
- g_bEventAlarm = RUN[0] == '1' ? true:false;
- }
- if ( GetPrivateProfileString("RUNPARA", "VOICE", "",RUN, 10, Path) != 0)
- {
- g_bAlarmVoice = RUN[0] == '1' ? true:false;
- }
- if ( GetPrivateProfileString("RUNPARA", "HIDETASK","",RUN, 10, Path) != 0)
- {
- g_bHideTask = RUN[0] == '1' ? true:false;
- }
- }
- BOOL CMainFrame::DirSearch(CString strPath, CString strFileName)
- {
- BOOL bResult = FALSE;
- long hDir;
- struct _finddata_t fDir;
- int nDone;
- strPath += "*.*";
- hDir = _findfirst( (char *)(LPCTSTR)strPath, &fDir );
- if( -1L != hDir )
- {
- while( !( nDone = _findnext(hDir, &fDir) ) )
- {
- if( !strcmp(fDir.name, "..") ) continue;
- if( (_A_SUBDIR == fDir.attrib) )
- {
- CString str = fDir.name;
- if( !str.Compare(strFileName) )
- {
- bResult = TRUE;
- }
- }
- }
- }
- return bResult;
- }
- int CMainFrame::GetLevel( CString sContent )
- {
- int nRet=0;
- for( int i=0;i<sContent.GetLength();i++ )
- {
- if( sContent[i]=='\\' )
- nRet++;
- if( sContent[i]=='[' )
- break;
- }
- return nRet;
- }
- CString CMainFrame::GetPreStr( CString sContent )
- {
- CString sRet;
- for( int i=sContent.GetLength()-1;i>=0;i-- )
- {
- if( sContent[i]=='\\' )
- {
- sRet = sContent.Left( i );
- break;
- }
- }
- return sRet;
- }
- CString CMainFrame::GetLastStr( CString sContent )
- {
- CString sRet;
- for( int i=sContent.GetLength()-1;i>=0;i-- )
- {
- if( sContent[i]=='\\' )
- {
- sRet = sContent.Right( sContent.GetLength()-i-1 );
- break;
- }
- }
- return sRet;
- }
- void CMainFrame::InsertToCStringArray( CStringArray &SA,int iInsertIndex,CString sContent,CString sPath )
- {
- CString str;
- if( sContent.Find(".view")!=-1 )
- sContent = sContent.Left( sContent.GetLength()-5 );
- CString sParent;
- if( m_sPath!=sPath )
- sParent = sPath.Right( sPath.GetLength()-m_sPath.GetLength() );
- if( sParent!="" )
- {
- sContent = sParent+sContent;
- }
- bool bExist=false;
- for( int i=0;i<SA.GetCount();i++ )
- {
- str = SA.GetAt( i );
-
- if( str==sContent )
- {
- bExist = true;
- break;
- }
- }
- if( !bExist )
- {
- int nInsert=SA.GetCount();
- CString s1;
- s1 = GetPreStr( sContent );
- for( int i=nInsert-1;i>=0;i-- )
- {
- str = SA.GetAt( i );
-
- if( str.Find( s1 )==0 )
- {
- nInsert = i+1;
- break;
- }
- }
- SA.InsertAt( nInsert,sContent );
- }
- }
- void CMainFrame::FileSearchCHN( CStringArray &SA,CStringArray &SATemp,int iInsertIndex, CString strPath, CString strFileName, int nLayer )
- {
- long hfile;
- struct _finddata_t fFile;
- CString strCurr = strPath + strFileName; // + "\\" +
-
- CString sIndex,sContent;
- int nDone=0;
- int nTime = 0;
- hfile = _findfirst( (char *)(LPCTSTR)strCurr, &fFile );
- if( -1L != hfile )
- {
- while( !( nDone = _findnext(hfile, &fFile) ) )
- {
- if( !strcmp(fFile.name,"..") ) continue;
- if( (_A_SUBDIR == fFile.attrib) )
- {
- strCurr = strPath + "\\" + fFile.name + "\\";
- int nPos = strCurr.Find("\\\\");
- if( nPos!=-1 )
- {
- strCurr.Delete( nPos );
- }
- CString str = fFile.name;
- sContent = str;
-
- InsertToCStringArray( SA,iInsertIndex,sContent,strPath );
- ////////////////////////////////////////////////////////////
- if( sContent.Find(".view")!=-1 )
- sContent = sContent.Left( sContent.GetLength()-5 );
- CString sParent;
- if( m_sPath!=strPath )
- sParent = strPath.Right( strPath.GetLength()-m_sPath.GetLength() );
- if( sParent!="" )
- {
- sContent = sParent+sContent;
- }
- SATemp.Add( sContent );
- ////////////////////////////////////////////////////////////
- iInsertIndex++;
- FileSearchCHN( SA,SATemp,iInsertIndex, strCurr, "*.*", nLayer + 1);
-
- if( g_bStartRun )
- {
- CString sPath = strCurr;
- int nPos = sPath.Find("*");
- if( nPos!=-1 )
- {
- sPath = sPath.Left( sPath.GetLength()-3 );
- }
-
- sPath = sPath+".view";
-
- nPos = sPath.Find("\\.");
- if( nPos!=-1 )
- {
- sPath.Delete( nPos );
- }
- }
- }
- else
- {
- CString str = fFile.name;
- if( str.Right(4).Compare("view") ) continue;
- CString strTemp = str.Left(str.GetLength()-5);
- if( !DirSearch(strPath + "\\", strTemp ) )
- {
- sContent = str;
- InsertToCStringArray( SA,iInsertIndex,sContent,strPath );
- iInsertIndex++;
- ////////////////////////////////////////////////////////////
- CString str;
- if( sContent.Find(".view")!=-1 )
- sContent = sContent.Left( sContent.GetLength()-5 );
- CString sParent;
- if( m_sPath!=strPath )
- sParent = strPath.Right( strPath.GetLength()-m_sPath.GetLength() );
- if( sParent!="" )
- {
- sContent = sParent+sContent;
- }
- SATemp.Add( sContent );
- ////////////////////////////////////////////////////////////
- }
- }
- }
- _findclose(hfile);
- }
- }
- //交换机
- //服务器
- //服务器\1号服务器
- //服务器\1号服务器\1号服务器
- //服务器\1号服务器\2号服务器
- //服务器\1号服务器\3号服务器
- //服务器\2号服务器
- //服务器\2号服务器\1号服务器
- //服务器\2号服务器\2号服务器
- //a
- void CMainFrame::AddViewToTree( HTREEITEM hItem, CStringArray &SA )
- {
- HTREEITEM hRoot;
- HTREEITEM hTemp[10];
- HTREEITEM hItemInsert=hItem;
- hRoot = hItem;
- hTemp[0] = hItem;
- int nSize = SA.GetCount();
- int nLevel1=0,nLevel2=0;
- CString sView,sPath,sTemp;
- for( int i=0;i<nSize;i++ )
- {
- sView = SA.GetAt( i );
- sTemp = sView;
- nLevel2 = GetLevel( sView );
- if( nLevel2==0 )
- hItemInsert = hRoot;
- else
- {
- hItemInsert = hTemp[nLevel2-1];
- }
- if( nLevel2>0 )
- sView = GetLastStr( sView );
- hItem = m_wndTree.InsertItem(sView, 1, 1, hItemInsert);
-
- hTemp[nLevel2] = hItem;
- if( nLevel1!=nLevel2 )
- nLevel1 = nLevel2;
-
- sPath = m_sPath + sTemp+".view";
- int nInsertIndex=0;
- if( !GetPicIndexByPicPath( nInsertIndex,sPath ) )
- {
- InsertPicPathToStruct( nInsertIndex,sPath );
- //LOG4C((LOG_NOTICE, "画面%d:%s", nInsertIndex,sPath));
- }
- }
- }
- void CMainFrame::FileSearch(HTREEITEM hItem, CString strPath, CString strFileName, int nLayer)
- {
- long hfile;
- struct _finddata_t fFile;
- CString strCurr = strPath + strFileName; // + "\\" +
- HTREEITEM hTemp = hItem;
- int nDone=0;
- int nTime = 0;
- hfile = _findfirst( (char *)(LPCTSTR)strCurr, &fFile );
- if( -1L != hfile )
- {
- while( !( nDone = _findnext(hfile, &fFile) ) )
- {
- if( !strcmp(fFile.name,"..") ) continue;
- if( (_A_SUBDIR == fFile.attrib) )
- {
- strCurr = strPath + "\\" + fFile.name + "\\";
- int nPos = strCurr.Find("\\\\");
- if( nPos!=-1 )
- {
- strCurr.Delete( nPos );
- }
- CString str = fFile.name;
- HTREEITEM hReturn = hItem;
- hItem = m_wndTree.InsertItem(str, 1, 1, hItem);
- FileSearch(hItem, strCurr, "*.*", nLayer + 1);
- hItem = hReturn;
-
- if( g_bStartRun )
- {
- CString sPath = strCurr;
- int nPos = sPath.Find("*");
- if( nPos!=-1 )
- {
- sPath = sPath.Left( sPath.GetLength()-3 );
- }
-
- sPath = sPath+".view";
-
- nPos = sPath.Find("\\.");
- if( nPos!=-1 )
- {
- sPath.Delete( nPos );
- }
- int nInsertIndex=0;
- if( !GetPicIndexByPicPath( nInsertIndex,sPath ) )
- {
- InsertPicPathToStruct( nInsertIndex,sPath );
- //LOG4C((LOG_NOTICE, "画面%d:%s", nInsertIndex,sPath));
- }
- }
- }
- else
- {
- CString str = fFile.name;
- if( str.Right(4).Compare("view") ) continue;
- CString strTemp = str.Left(str.GetLength()-5);
- if( !DirSearch(strPath + "\\", strTemp ) )
- {
- m_wndTree.InsertItem(strTemp, 1, 1, hTemp);
- }
- //m_wndTree.SortChildren( hItem );
- if( g_bStartRun )
- {
- CString sPath = strPath;
- int nPos = sPath.Find("*");
- if( nPos!=-1 )
- {
- sPath = sPath.Left( sPath.GetLength()-3 );
- }
- sPath = sPath+strTemp+".view";
- int nInsertIndex=0;
- if( !GetPicIndexByPicPath( nInsertIndex,sPath ) )
- {
- InsertPicPathToStruct( nInsertIndex,sPath );
- //LOG4C((LOG_NOTICE, "画面%d:%s", nInsertIndex,sPath));
- }
- }
- }
- }
- _findclose(hfile);
- }
- }
- // 删除目录
- void CMainFrame::DeleteDirectory(CString strDir)
- {
- if(strDir.IsEmpty())
- {
- RemoveDirectory(strDir);
- return;
- }
- // 首先删除文件及子文件夹
- CFileFind ff;
- BOOL bFound = ff.FindFile(strDir+"\\*", 0);
- while(bFound)
- {
- bFound = ff.FindNextFile();
- if(ff.GetFileName()=="."||ff.GetFileName()=="..") continue;
- // 去掉文件(夹)只读等属性
- SetFileAttributes(ff.GetFilePath(), FILE_ATTRIBUTE_NORMAL);
- if(ff.IsDirectory())
- {
- // 递归删除子文件夹
- DeleteDirectory(ff.GetFilePath());
- RemoveDirectory(ff.GetFilePath());
- }
- else
- {
- DeleteFile(ff.GetFilePath()); // 删除文件
- }
- }
- ff.Close();
- // 然后删除该文件夹
- if (!RemoveDirectory(strDir))
- {
- //ff.Close();
- //Sleep( 1000 );
- RemoveDirectory(strDir);
- }
- }
-
- void CMainFrame::InitTreeInfo(void)
- {
- m_wndTree.SetItemHeight(20);
- m_wndImageList.DeleteImageList();
- m_wndImageList.Create(IDB_LEFT, 16, 1, RGB(255, 0, 255));
- m_wndTree.SetImageList(&m_wndImageList, LVSIL_NORMAL);
- m_wndTree.SetBkColor( RGB(230,241,249) );
- m_wndTree.DeleteAllItems();
- m_hMonitor = m_wndTree.InsertItem(g_strMoniterSite,0,0);
-
- if( !g_bStartRun )
- {
- m_hleftDockBar.m_bDrawStudBtn = true;
- m_hIOGroup = m_wndTree.InsertItem(g_strDevice,2,2);
- m_hEtherNet = m_wndTree.InsertItem(g_strEthernet,3,3,m_hIOGroup);
- m_hSerial = m_wndTree.InsertItem(g_strSerial,4,4,m_hIOGroup);
-
- m_hVariant = m_wndTree.InsertItem(g_strDataDict,11,11);
- m_hAnalog = m_wndTree.InsertItem(g_strVarSet,15,15,m_hVariant);
- m_hScript = m_wndTree.InsertItem(g_strScriptManage,13,13);
- m_hActionWithAlarm = m_wndTree.InsertItem(g_strActionWithAlarm,13,13);
- m_hSystem = m_wndTree.InsertItem(g_strSysParam,9,9);
- //插入串口和网络设备
- int nComportSize = pDevicesManager->m_channels.GetSize();
- for (int i = 0; i < nComportSize; i++)
- {
- CChannel* pComport = pDevicesManager->m_channels[i];
- if( pComport->m_nCommunicateType == 0 ) // 串口设备
- {
- m_hSerialGroup[i] = m_wndTree.InsertItem(pComport->m_strName,5,5,m_hSerial);
- m_nPortNum++;
- int nDeviceSize = pComport->m_Devices.GetSize();
- for (int j = 0; j < nDeviceSize; j++)
- {
- CDevice* pDev = pComport->m_Devices[j];
- m_hSerialDev[i][j] = m_wndTree.InsertItem(pDev->m_strName,4,4,m_hSerialGroup[i]);
- }
- }
- else if( pComport->m_nCommunicateType == 1 ) // 网络设备
- {
- int nDeviceSize = pComport->m_Devices.GetSize();
- for( int j = 0; j < nDeviceSize; j++ )
- {
- CDevice *pDev = pComport->m_Devices[j];
- m_hNetworkDev[j] = m_wndTree.InsertItem(pDev->m_strName, 2, 2, m_hEtherNet);
- }
- }
- }
- }
- //显示画面
- CString strFindPicFile = "*.view";
- char szPicDir[MAX_PATH] = {0};
- strcpy(szPicDir, g_strDirectory);
- strcat(szPicDir, "\\");
- strcat(szPicDir, _PICTUREDIR);
- m_sPath.Format( "%s",szPicDir );
- //FileSearch(m_hMonitor, szPicDir, "*.*", 0);
- ///////////////////////
- strcpy(szPicDir, g_strDirectory);
- strcat(szPicDir, "\\");
- strcat(szPicDir, _PICTUREDIR);
- strcat(szPicDir, "sort.txt");
- CStringArray SA,SATemp;
- if( PathFileExists( szPicDir ) )
- {
- CString sTemp,strTemp1,strTemp2,sTemp2;
- CStdioFile File;
-
- if(!File.Open(szPicDir,CFile::modeRead))
- File.Open(szPicDir,CFile::modeCreate|CFile::modeRead);
- while(File.ReadString(sTemp))
- {
- SA.Add( sTemp );
- }
- File.Close();
- }
- strcpy(szPicDir, g_strDirectory);
- strcat(szPicDir, "\\");
- strcat(szPicDir, _PICTUREDIR);
- FileSearchCHN( SA,SATemp,0, szPicDir, "*.*", 0);
- CString sShow,s;
- for( int i=0;i<SA.GetCount();i++ )
- {
- s = SA.GetAt( i );
- sShow = sShow + s + "\n";
- }
- //AfxMessageBox( sShow );
- bool bExist=false;
- int nSize1=SA.GetCount();
- int nSize2=SATemp.GetCount();
- CString str1,str2;
- for( int i=nSize1-1;i>=0;i-- )
- {
- str1 = SA.GetAt(i);
- for( int j=0;j<nSize2;j++ )
- {
- str2 = SATemp.GetAt(j);
- if( str1==str2 )
- {
- bExist = true;
- break;
- }
- }
- if( !bExist )
- SA.RemoveAt( i );
- bExist = false;
- }
- AddViewToTree( m_hMonitor,SA );
- ///////////////////////
- //m_wndTree.SortChildren( m_hMonitor );
- if( !g_bStartRun )
- {
- // 显示脚本
- struct _finddata_t f;
- long hfile;
- strFindPicFile = "*.srp";
- strcpy(szPicDir, g_strDirectory);
- strcat(szPicDir, "\\");
- strcat(szPicDir, _SCRIPTDIR);
- strcat(szPicDir, strFindPicFile);
- hfile = _findfirst((const char*)szPicDir,&f);
- if (-1L != hfile)
- {
- CString strFileName = f.name;
- m_hScriptGroup[m_nScripts++] = m_wndTree.InsertItem(strFileName.Left(strFileName.GetLength()-4),
- 1,1,m_hScript);
- while (0 == _findnext(hfile,&f))
- {
- strFileName = f.name;
- m_hScriptGroup[m_nScripts++] = m_wndTree.InsertItem(strFileName.Left(strFileName.GetLength()-4),
- 1,1,m_hScript);
- }
- _findclose(hfile);
- }
- }
- }
- void CMainFrame::OnFullScreen()
- {
- GetWindowPlacement(&m_OldWndPlacement);
- CRect WindowRect;
- GetWindowRect(&WindowRect);
- CRect ClientRect;
- RepositionBars(0, 0xffff, AFX_IDW_PANE_FIRST, reposQuery, &ClientRect);
- ClientToScreen(&ClientRect);// 获取屏幕的分辨率
- int nFullWidth=GetSystemMetrics(SM_CXSCREEN);
- int nFullHeight=GetSystemMetrics(SM_CYSCREEN);// 将除控制条外的客户区全屏显示到从(0,0)到(nFullWidth, nFullHeight)区
- //域, 将(0,0)和(nFullWidth, nFullHeight)两个点外扩充原窗口和除控制条之外的 客
- //户区位置间的差值, 就得到全屏显示的窗口位置
- m_FullScreenRect.left=0;//WindowRect.left-ClientRect.left-1;
- m_FullScreenRect.top=0;//WindowRect.top-ClientRect.top-1;
- m_FullScreenRect.right=WindowRect.right-ClientRect.right+nFullWidth+2;
- m_FullScreenRect.bottom=nFullHeight;//WindowRect.bottom-ClientRect.bottom+nFullHeight+2;
- // 进入全屏显示状态
- WINDOWPLACEMENT wndpl;
- wndpl.length=sizeof(WINDOWPLACEMENT);
- wndpl.flags=0;
- wndpl.showCmd=SW_SHOWNORMAL;
- wndpl.rcNormalPosition=m_FullScreenRect;
- SetWindowPlacement(&wndpl);
- }
- void CMainFrame::OnRun()
- {
- g_bRun = TRUE; //运行否
- g_bEdit = FALSE; //编辑否
- CDrawObj::bRuning = TRUE;
- m_wndToolBar.ShowWindow(SW_HIDE);
- m_wndDrawToolBar.ShowWindow(SW_HIDE);
- m_wndDrawAlignBar.ShowWindow(SW_HIDE);
-
- //if( g_nToolbarRun )//&& !g_bFullScreen )
- //{
- // m_wndRunToolBar.ShowWindow(SW_SHOW);
- //}
- //else
- //{
- // m_wndRunToolBar.ShowWindow(SW_HIDE);
- //}
- RecalcLayout();
- if( g_nToolBarStatus )//&& !g_bFullScreen )
- {
- m_wndStatusBar.ShowWindow(SW_SHOW);
- }
- else
- {
- m_wndStatusBar.ShowWindow(SW_HIDE);
- }
- m_hleftDockBar.ShowWindow(SW_SHOW);
- //if( g_nToolbarLeft )
- //{
- // m_wndDockPageBar1.ShowWindow(SW_SHOW);
- //}
- //else
- //{
- // m_wndDockPageBar1.ShowWindow(SW_HIDE);
- //}
- if ( g_bHideTask )
- {
- HWND wnd = ::FindWindow("Shell_TrayWnd", NULL);
- ::ShowWindow(wnd, SW_HIDE);
- }
- //else
- //{
- // HWND wnd = ::FindWindow("Shell_TrayWnd", NULL);
- // ::ShowWindow(wnd, SW_SHOW);
- //}
- LONG style=::GetWindowLong(m_hWnd,GWL_STYLE);
- style&=~WS_CAPTION;
- style&=~WS_BORDER;
- ::SetWindowLong(m_hWnd,GWL_STYLE,style);
- int screenx=GetSystemMetrics(SM_CXSCREEN);
- int screeny=GetSystemMetrics(SM_CYSCREEN);
- //系统任务栏的高度
- HWND hWnd = ::FindWindow("Shell_TrayWnd", NULL);
- RECT rc;
- ::GetWindowRect(hWnd, &rc);
- int nHeight = rc.bottom-rc.top;
- if( g_nIsDemo == 0 )
- {
- if(!g_bFullScreen)
- {
- SetWindowPos(NULL,0,0,screenx,screeny-nHeight,SWP_NOZORDER);
- }
- else
- {
- SetWindowPos(NULL,0,0,screenx,screeny+0,SWP_FRAMECHANGED);//关于全屏
- }
- }
-
- SetMenu((CMenu*)NULL);
- }
- BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
- {
- if( !CMDIFrameWnd::PreCreateWindow(cs) )
- return FALSE;
- // TODO: 在此处通过修改 CREATESTRUCT cs 来修改窗口类或
- // 样式
- if (!g_bStartRun)
- {
- cs.style = WS_OVERLAPPED | WS_CAPTION | FWS_ADDTOTITLE
- | WS_THICKFRAME | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_MAXIMIZE;
- }
- else
- {
- cs.style=WS_OVERLAPPED | WS_SYSMENU |WS_MINIMIZEBOX |WS_TILED ;
- }
- return TRUE;
- }
- // CMainFrame 诊断
- #ifdef _DEBUG
- void CMainFrame::AssertValid() const
- {
- CMDIFrameWnd::AssertValid();
- }
- void CMainFrame::Dump(CDumpContext& dc) const
- {
- CMDIFrameWnd::Dump(dc);
- }
- #endif //_DEBUG
- // CMainFrame 消息处理程序
- void CMainFrame::OnSuperEnd()
- {
- // TODO: 在此添加命令处理程序代码
- m_bShutdown = TRUE; // really exit
- SendMessage(WM_CLOSE);
- }
- void CMainFrame::OnTrayOpen()
- {
- // TODO: 在此添加命令处理程序代码
- ShowWindow(SW_MAXIMIZE);
- SetForegroundWindow();
- }
- void CMainFrame::OnClose()
- {
- // TODO: 在此添加消息处理程序代码和/或调用默认值
- #if USE_TRAYICON
- #else
- m_bShutdown = TRUE;
- #endif
- if( m_bShutdown )
- {
- if( g_nIsDemo == 1 )
- {
- if(MessageBox(g_strExitConfirm, g_strTip, MB_YESNO|MB_ICONQUESTION)==IDNO)
- {
- return;
- }
- }
- #if 0 // 暂时不使用登陆框 [8/29/2013 hero]
- else
- {
- CLogin dlg;
- dlg.m_bShutdown = true;
- if (dlg.DoModal()!=IDOK)
- {
- m_bShutdown = false;
- return;
- }
- CString sContent;
- sContent.Format("用戶< %s >注销",dlg.m_sUserID );
- CDBInterface::GetInstancePtr()->InsertLogRecord( LOG_LOGOUT,0,"",(char *)(LPCTSTR)sContent );
- }
- #endif
- if (g_bRun )
- {
- pDevicesManager->Store(g_strDirectory);
- pVariantsManager->Store(g_strDirectory);
- }
- // 清除所有事件
- for(POSITION pos = pEventServer->eventList.GetHeadPosition();pos!=NULL;)
- {
- POSITION pos1 = pos ; //要在这里做一个备份
- CAlarmEvent* pEvent = pEventServer->eventList.GetNext(pos);//他会改变 pos的值
- pEventServer->eventList.RemoveAt(pos1);
- if( pEvent )
- {
- delete pEvent;
- pEvent = NULL;
- }
- }
- //if( g_nAlarmModeIsDlg && g_bStartRun )
- {
- if( m_dlgEvent )
- delete m_dlgEvent;
- if( m_dlgControl )
- delete m_dlgControl;
- }
- if( m_pDlgZuTaiAdd )
- {
- delete m_pDlgZuTaiAdd;
- m_pDlgZuTaiAdd = NULL ;
- }
- int i;
- for( i = 0; i < MAX_VIEW_NUM; i++ )
- {
- if( m_pViewIDE[ i ] )
- {
- ::SendMessage(m_pViewIDE[ i ]->m_hWnd, WM_CLOSE, 0, 0 );
- m_pViewIDE[ i ] = NULL;
- }
- }
- #if USE_NEWTOP
- if( g_bRun && g_nToolbarRun )
- {
- if( m_pToolBar )
- delete m_pToolBar;
- m_pToolBar = NULL ;
- }
- #else
- if( g_bRun && g_nToolbarRun )
- {
- if( m_wndOfTop )
- delete m_wndOfTop;
- m_wndOfTop = NULL ;
- }
- #endif
- CMDIAutoHideFrame::OnClose();
- }
- else
- {
- ShowWindow(SW_HIDE);
- }
- }
- void CMainFrame::OnDestroy()
- {
- if( g_nIsPoll == 1 )
- {
- #if VIEW_USE_THREAD
- if( m_hViewPollThread != NULL )
- {
- MTVERIFY( WaitForSingleObject( m_hViewPollThread, INFINITE ) != WAIT_FAILED );
- MTVERIFY( CloseHandle( m_hViewPollThread ) );
- m_hViewPollThread = NULL;
- }
- #else
- KillTimer(1);
- #endif
- }
- CMDIAutoHideFrame::OnDestroy();
- // TODO: 在此处添加消息处理程序代码
- int i;
- for( i = 0; i < MAX_VIEW_NUM; i++ )
- {
- if( m_pViewIDE[ i ] )
- {
- ::SendMessage(m_pViewIDE[ i ]->m_hWnd, WM_DESTROY, 0, 0 );
- m_pViewIDE[ i ] = NULL;
- }
- }
- }
- BOOL CMainFrame::FindTreeItem(HTREEITEM hSrcItem, HTREEITEM hDestItem)
- {
- HTREEITEM hItem = m_wndTree.GetParentItem( hSrcItem );
- while( hItem != NULL )
- {
- if( hItem == hDestItem ) return TRUE;
- hItem = m_wndTree.GetParentItem( hItem );
- }
- return FALSE;
- }
- int CMainFrame::ShowDevProperty(HTREEITEM hSelectedItem)
- {
- CString strOldUid, strNewUid;
- int i, j;
- int nChannelIndex = -1, nDeviceIndex = -1;
- int nChannelSize = pDevicesManager->m_channels.GetSize();
- // 串口设备属性设置
- for (i = 0; i < nChannelSize; i++)
- {
- if( nChannelIndex != -1 && nDeviceIndex != -1 ) break;
- int nDeviceSize = pDevicesManager->m_channels[i]->m_Devices.GetSize();
- for( j = 0; j < nDeviceSize; j++)
- {
- if (m_hSerialDev[i][j]==hSelectedItem )
- {
- nChannelIndex = i;
- nDeviceIndex = j;
- break;
- }
- if( m_hNetworkDev[j] == hSelectedItem && pDevicesManager->m_channels[i]->m_nCommunicateType == 1 )
- {
- nChannelIndex = i;
- nDeviceIndex = j;
- break;
- }
- }
- }
- if( nChannelIndex == -1 || nDeviceIndex == -1 ) return -1;
- CChannel* pChannel = pDevicesManager->m_channels[nChannelIndex];
- CDevice* pDev = pChannel->m_Devices[nDeviceIndex];
- //CSerial* pSerial = (CSerial *)pChannel;
- CNetwork *pNetwork = (CNetwork *)pChannel;
- CWizard MyWizard(g_strMywizard,this,1);
- // 通信方式
- m_wndDevice.m_nCommuniteType = pChannel->m_nCommunicateType;
- // 设备驱动名称
- m_wndDevice.m_strDevDriveName = pDev->m_strDevDriveName;
- // 设备厂家名称
- m_wndDevice.m_strDevFactoryName = pDev->m_strDevFactoryName;
- // 设备型号
- m_wndDevice.m_strDevTypeName = pDev->m_strType;
- // 通信协议(例:Modbus rtu, modbus ascii, modbus tcp)
- m_wndDevice.m_nProtocolType = pDev->m_nProtocolType;
- // 配置文件名称
- m_wndDevice.m_strIniName = pDev->m_strIniName;
- // 协议驱动动态库名称
- m_wndDevice.m_strProtocolName = pDev->m_strProtocolName;
- // 是否为采集设备
- m_wndDevice.m_nCollectDev = pDev->m_nIsCollectDev;
- // 是否启用设备
- m_wndDevice.m_nDevEnable = (int)pDev->m_bUsed;
- // CString类型预留
- //m_wndDevice.m_strReserved1 = pDev->m_strReserved1;
- m_wndDevice.m_strReserved2 = pDev->m_strReserved2;
- m_wndDevice.m_strReserved3 = pDev->m_strReserved3;
- m_wndDevice.m_strReserved4 = pDev->m_strReserved4;
- m_wndDevice.m_strReserved5 = pDev->m_strReserved5;
- // Int类型预留
- m_wndDevice.m_nReserved1 = pDev->m_nReserved1;
- m_wndDevice.m_nReserved2 = pDev->m_nReserved2;
- m_wndDevice.m_nReserved3 = pDev->m_nReserved3;
- m_wndDevice.m_nReserved4 = pDev->m_nReserved4;
- m_wndDevice.m_nReserved5 = pDev->m_nReserved5;
- // BOOL类型预留
- m_wndDevice.m_bReserved1 = pDev->m_bReserved1;
- m_wndDevice.m_bReserved2 = pDev->m_bReserved2;
- m_wndDevice.m_bReserved3 = pDev->m_bReserved3;
- m_wndDevice.m_bReserved4 = pDev->m_bReserved4;
- m_wndDevice.m_bReserved5 = pDev->m_bReserved5;
- // 设备UID
- m_wndComport.m_strUID = pDev->m_strUID;
- strOldUid = pDev->m_strUID;
- // 设备名称
- m_wndComport.m_strDevName = pDev->m_strName;
- // 设备所属区域
- m_wndComport.m_strDevArea = pDev->m_strReserved1;
- // 通讯超时
- m_wndComport.m_nTimeout = pDev->m_nTimeout;
- // 设备地址
- m_wndComport.m_nDevAddr = (int)pDev->m_Address;
- // 串行端口
- m_wndComport.m_nCommPort = atoi(pChannel->m_strPort.Mid(3));
- // 数据位
- m_wndComport.m_nDataBit = pChannel->m_nByteSize;
- // 波特率
- m_wndComport.m_nRate = pChannel->m_nBaudRate;
- // 停止位
- m_wndComport.m_nStopBit = pChannel->m_nStopBits;
- // 校验位
- m_wndComport.m_nCheckCode = pChannel->m_nParity;
- // CString类型预留
- m_wndComport.m_strReserved6 = pDev->m_strReserved6;
- m_wndComport.m_strReserved7 = pDev->m_strReserved7;
- m_wndComport.m_strReserved8 = pDev->m_strReserved8;
- m_wndComport.m_strReserved9 = pDev->m_strReserved9;
- m_wndComport.m_strReserved10 = pDev->m_strReserved10;
- // Int类型预留
- m_wndComport.m_nReserved6 = pDev->m_nReserved6;
- m_wndComport.m_nReserved7 = pDev->m_nReserved7;
- m_wndComport.m_nReserved8 = pDev->m_nReserved8;
- m_wndComport.m_nReserved9 = pDev->m_nReserved9;
- m_wndComport.m_nReserved10 = pDev->m_nReserved10;
- // BOOL类型预留
- m_wndComport.m_bReserved6 = pDev->m_bReserved6;
- m_wndComport.m_bReserved7 = pDev->m_bReserved7;
- m_wndComport.m_bReserved8 = pDev->m_bReserved8;
- m_wndComport.m_bReserved9 = pDev->m_bReserved9;
- m_wndComport.m_bReserved10 = pDev->m_bReserved10;
- if( pChannel->m_nCommunicateType == 1 )
- {
- // 设备IP
- m_wndComport.m_nNetIP = htonl(inet_addr(pDev->m_strDevIP));
- // 通讯端口
- m_wndComport.m_nNetPort = pDev->m_nNetPort;
- }
- m_wndDevice.m_operation = CDlgDevice::EDIT;
- MyWizard.AddPage( &m_wndDevice );
- MyWizard.AddPage( &m_wndComport );
- MyWizard.SetWizardMode();
- MyWizard.SetActivePage( &m_wndDevice );
- int nTmpChannelIndex = -1, nTmpDeviceIndex = -1;
- if( MyWizard.DoModal() == ID_WIZFINISH )
- {
- if( !m_wndComport.m_strDevName.Compare("") )
- {
- MessageBox(g_strDevNumCannotBlank, g_strTip, MB_ICONINFORMATION);
- return -1;
- }
- else if( pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_strName != m_wndComport.m_strDevName )
- {
- if( pDevicesManager->FindDev(m_wndComport.m_strDevName, nTmpChannelIndex, nTmpDeviceIndex) )
- {
- MessageBox(g_strDevNameInUse, g_strTip, MB_ICONINFORMATION);
- return -1;
- }
- }
- int nIP = htonl(m_wndComport.m_nNetIP);
- if( m_wndDevice.m_nCommuniteType == 0 )
- {
- CString strName;
- strName.Format("COM%d", m_wndComport.m_nCommPort);
- CString sTemp;
- sTemp.Format("%s",pDevicesManager->m_channels[nChannelIndex]->m_strName );
- //TRACE("串口名称=%s\r\n", pDevicesManager->m_channels[nChannelIndex]->m_strName);
- if( pDevicesManager->m_channels[nChannelIndex]->m_strName.Compare("") &&
- pDevicesManager->m_channels[nChannelIndex]->m_strName != strName )//以前是串口,现在串口号改变
- {
- int nIndex;
- nIndex = pDevicesManager->FindCommPort(strName);
- if( nIndex == -1 )//串口号不存在
- {
- if( FinishedAddDevice(1, pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_strUID) == 1 )
- {
- //m_wndTree.DeleteItem( m_hCurrent );
- for( j = nDeviceIndex; j < MAX_DEVICE_NUM; j++ )
- {
- m_hSerialDev[nChannelIndex][j] = m_hSerialDev[nChannelIndex][j+1];
- }
- delete pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex];
- pDevicesManager->m_channels[nChannelIndex]->m_Devices.RemoveAt(nDeviceIndex);
- //InitTreeInfo();
- }
-
- return 1;
- }
- else//串口号存在
- {
- if( pDevicesManager->FindCommPort(strName, m_wndComport.m_nDevAddr, nTmpChannelIndex, nTmpDeviceIndex) )
- {
- MessageBox(g_strSerialPortInUse, g_strTip, MB_ICONINFORMATION);
- return -1;
- }
- if( pDevicesManager->FindDev(strName, nTmpChannelIndex, nTmpDeviceIndex) )
- {
- MessageBox(g_strDevNameInUse, g_strTip, MB_ICONINFORMATION);
- return -1;
- }
- //nChannelIndex = nIndex;
- if( FinishedAddDevice(1, pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_strUID) == 1 )
- {
- //m_wndTree.DeleteItem( m_hCurrent );
- for( j = nDeviceIndex; j < MAX_DEVICE_NUM; j++ )
- {
- m_hSerialDev[nChannelIndex][j] = m_hSerialDev[nChannelIndex][j+1];
- }
- delete pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex];
- pDevicesManager->m_channels[nChannelIndex]->m_Devices.RemoveAt(nDeviceIndex);
- //DeleteDevInfo((char *)(LPCTSTR)strUid);
- }
- return 1;
- //nDeviceIndex = pDevicesManager->m_channels[nChannelIndex]->m_Devices.GetSize();
- }
- }
- else//1.以前是串口,现在串口号不变,但设备号改变 2.以前是网络设备,现在改成串口
- {
- if( 0==pDevicesManager->m_channels[nChannelIndex]->m_strName.Compare("") )//2.以前是网络设备,现在改成串口
- {
- if( FinishedAddDevice(1, pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_strUID) == 1 )
- {
- //m_wndTree.DeleteItem( m_hCurrent );
- for( j = nDeviceIndex; j < MAX_DEVICE_NUM; j++ )
- {
- m_hNetworkDev[j] = m_hNetworkDev[j+1];
- }
- delete pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex];
- pDevicesManager->m_channels[nChannelIndex]->m_Devices.RemoveAt(nDeviceIndex);
- }
-
- return 1;
- }
- else
- {
- if( pDevicesManager->FindDev(strName, nTmpChannelIndex, nTmpDeviceIndex) )////1.以前是串口,现在串口号不变,但设备号改变
- {
- MessageBox(g_strDevNameInUse, g_strTip, MB_ICONINFORMATION);
- return -1;
- }
- }
- }
- }
- else//网络通信协议
- {
- CString strName;
- strName.Format("%s", pDevicesManager->m_channels[nChannelIndex]->m_strName);//是網絡的話為空
- if( 0==strName.Compare("") )//以前是网络,现在也网络
- {
- if( m_wndComport.m_nNetIP == 0 )
- {
- MessageBox(g_strIPNotBlank, g_strTip, MB_ICONWARNING);
- pDev->Destroy();
- delete pDev;
- return 0;
- }
- if( m_wndComport.m_nNetPort == 0 )
- {
- MessageBox(g_strComcanNot0, g_strTip, MB_ICONWARNING);
- pDev->Destroy();
- delete pDev;
- return 0;
- }
- CString strIP = inet_ntoa(*(struct in_addr *)&nIP);
- if( (pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex])->m_strDevIP != strIP )
- {
- if( pDevicesManager->FindDev(strIP, m_wndComport.m_nNetPort, nTmpChannelIndex, nTmpDeviceIndex) )
- {
- MessageBox(g_strIPComoccupy, g_strTip, MB_ICONINFORMATION);
- return -1;
- }
- }
- }
- else//以前是串口,现在是网络
- {
- if( FinishedAddDevice(1, pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_strUID) == 1 )
- {
- //m_wndTree.DeleteItem( m_hCurrent );
- for( j = nDeviceIndex; j < MAX_DEVICE_NUM; j++ )
- {
- m_hSerialDev[nChannelIndex][j] = m_hSerialDev[nChannelIndex][j+1];
- }
- delete pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex];
- pDevicesManager->m_channels[nChannelIndex]->m_Devices.RemoveAt(nDeviceIndex);
- }
-
- return 1;
- }
- }
- // 通信方式
- pDevicesManager->m_channels[nChannelIndex]->m_nCommunicateType = m_wndDevice.m_nCommuniteType;
- // 设备驱动名称
- pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_strDevDriveName = m_wndDevice.m_strDevDriveName;
- // 设备厂家名称
- pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_strDevFactoryName = m_wndDevice.m_strDevFactoryName;
- // 设备型号
- pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_strType = m_wndDevice.m_strDevTypeName;
- // 通信协议(例:Modbus rtu, modbus ascii, modbus tcp)
- pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_nProtocolType = m_wndDevice.m_nProtocolType;
- // 协议驱动动态库名称
- pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_strProtocolName = m_wndDevice.m_strProtocolName;
- // 是否为采集设备
- pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_nIsCollectDev = m_wndDevice.m_nCollectDev;
- // 是否启用设备
- pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_bUsed = (BOOL)m_wndDevice.m_nDevEnable;
- // 设备UID
- pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_strUID = m_wndComport.m_strUID;
- strNewUid = m_wndComport.m_strUID;
- // 设备名称
- pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_strName = m_wndComport.m_strDevName;
- // 设备所属区域
- pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_strReserved1 = m_wndComport.m_strDevArea;
- // 通讯超时
- pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_nTimeout = m_wndComport.m_nTimeout;
- // 设备地址
- pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_Address = (BYTE)m_wndComport.m_nDevAddr;
- //配置文件名称
- pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_strIniName = m_wndDevice.m_strIniName;
- //预留
- //pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_strReserved1 = m_wndDevice.m_strReserved1;
- pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_strReserved2 = m_wndDevice.m_strReserved2;
- pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_strReserved3 = m_wndDevice.m_strReserved3;
- pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_strReserved4 = m_wndDevice.m_strReserved4;
- pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_strReserved5 = m_wndDevice.m_strReserved5;
- pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_strReserved6 = m_wndComport.m_strReserved6;
- pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_strReserved7 = m_wndComport.m_strReserved7;
- pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_strReserved8 = m_wndComport.m_strReserved8;
- pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_strReserved9 = m_wndComport.m_strReserved9;
- pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_strReserved10 = m_wndComport.m_strReserved10;
- pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_nReserved1 = m_wndDevice.m_nReserved1;
- pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_nReserved2 = m_wndDevice.m_nReserved2;
- pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_nReserved3 = m_wndDevice.m_nReserved3;
- pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_nReserved4 = m_wndDevice.m_nReserved4;
- pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_nReserved5 = m_wndDevice.m_nReserved5;
- pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_nReserved6 = m_wndComport.m_nReserved6;
- pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_nReserved7 = m_wndComport.m_nReserved7;
- pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_nReserved8 = m_wndComport.m_nReserved8;
- pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_nReserved9 = m_wndComport.m_nReserved9;
- pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_nReserved10 = m_wndComport.m_nReserved10;
- pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_bReserved1 = m_wndDevice.m_bReserved1;
- pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_bReserved2 = m_wndDevice.m_bReserved2;
- pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_bReserved3 = m_wndDevice.m_bReserved3;
- pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_bReserved4 = m_wndDevice.m_bReserved4;
- pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_bReserved5 = m_wndDevice.m_bReserved5;
- pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_bReserved6 = m_wndComport.m_bReserved6;
- pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_bReserved7 = m_wndComport.m_bReserved7;
- pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_bReserved8 = m_wndComport.m_bReserved8;
- pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_bReserved9 = m_wndComport.m_bReserved9;
- pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_bReserved10 = m_wndComport.m_bReserved10;
- if( m_wndDevice.m_nCommuniteType == 0 )
- {
- pDevicesManager->m_channels[nChannelIndex]->m_strName.Format("COM%d", m_wndComport.m_nCommPort);
- // 串行端口
- pDevicesManager->m_channels[nChannelIndex]->m_strPort.Format("COM%d", m_wndComport.m_nCommPort);
- // 数据位
- pDevicesManager->m_channels[nChannelIndex]->m_nByteSize = m_wndComport.m_nDataBit;
- // 波特率
- pDevicesManager->m_channels[nChannelIndex]->m_nBaudRate = m_wndComport.m_nRate;
- // 停止位
- pDevicesManager->m_channels[nChannelIndex]->m_nStopBits = m_wndComport.m_nStopBit;
- // 校验位
- pDevicesManager->m_channels[nChannelIndex]->m_nParity = m_wndComport.m_nCheckCode;
- }
- else if( m_wndDevice.m_nCommuniteType == 1 )
- {
- // 设备IP
- pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_strDevIP = inet_ntoa(*(struct in_addr *)&nIP);
- // 通讯端口
- pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_nNetPort = m_wndComport.m_nNetPort;
- }
- CHAR chDevTypeID[MAX_ID + 1] = {0};
- // 获取设备类型ID
- int nRet = CDBInterface::GetInstancePtr()->GetDevTypeID((char *)(LPCTSTR)m_wndDevice.m_strDevTypeName, chDevTypeID);
- if( -1 == nRet )
- {
- return nRet;
- }
- else
- {
- CDBInterface::GetInstancePtr()->EditDevInfo(
- (char *)(LPCTSTR)strOldUid,
- (char *)(LPCTSTR)strNewUid,
- m_wndComport.m_nCommPort,
- m_wndComport.m_nDevAddr,
- (char *)(LPCTSTR)m_wndComport.m_strDevName,
- atoi(chDevTypeID),
- m_wndComport.m_nRate,
- m_wndComport.m_nDataBit,
- m_wndComport.m_nStopBit,
- m_wndComport.m_nCheckCode,
- 0,
- inet_ntoa(*(struct in_addr *)&nIP),
- m_wndComport.m_nNetPort,
- m_wndComport.m_nCommunicateMode,
- m_wndDevice.m_nCollectDev,
- m_wndDevice.m_nProtocolType,
- m_wndComport.m_nTimeout,
- m_wndDevice.m_nDevEnable,
- (char *)(LPCTSTR)m_wndDevice.m_strProtocolName,
- (char *)(LPCTSTR)m_wndDevice.m_strIniName,
- (char *)(LPCTSTR)m_wndComport.m_strDevArea,
- //(char *)(LPCTSTR)m_wndDevice.m_strReserved1,
- (char *)(LPCTSTR)m_wndDevice.m_strReserved2,
- (char *)(LPCTSTR)m_wndDevice.m_strReserved3,
- (char *)(LPCTSTR)m_wndDevice.m_strReserved4,
- (char *)(LPCTSTR)m_wndDevice.m_strReserved5,
- (char *)(LPCTSTR)m_wndComport.m_strReserved6,
- (char *)(LPCTSTR)m_wndComport.m_strReserved7,
- (char *)(LPCTSTR)m_wndComport.m_strReserved8,
- (char *)(LPCTSTR)m_wndComport.m_strReserved9,
- (char *)(LPCTSTR)m_wndComport.m_strReserved10,
- m_wndDevice.m_nReserved1,
- m_wndDevice.m_nReserved2,
- m_wndDevice.m_nReserved3,
- m_wndDevice.m_nReserved4,
- m_wndDevice.m_nReserved5,
- m_wndComport.m_nReserved6,
- m_wndComport.m_nReserved7,
- m_wndComport.m_nReserved8,
- m_wndComport.m_nReserved9,
- m_wndComport.m_nReserved10,
- (int)m_wndDevice.m_bReserved1,
- (int)m_wndDevice.m_bReserved2,
- (int)m_wndDevice.m_bReserved3,
- (int)m_wndDevice.m_bReserved4,
- (int)m_wndDevice.m_bReserved5,
- (int)m_wndComport.m_bReserved6,
- (int)m_wndComport.m_bReserved7,
- (int)m_wndComport.m_bReserved8,
- (int)m_wndComport.m_bReserved9,
- (int)m_wndComport.m_bReserved10
- );
- }
- CString sContent;
- sContent.Format("编辑设备< %s >",m_wndComport.m_strDevName.TrimRight() );
- CDBInterface::GetInstancePtr()->InsertLogRecord( LOG_DEV_EDIT,0,"",(char *)(LPCTSTR)sContent );
- pDevicesManager->SendNoticeToServer( CMD_NOTICE_READ_DB_DEV,CMD_OPERATE_EDIT,"",m_wndComport.m_strUID,0,"64320" );
- }
- m_wndTree.SetItemText(hSelectedItem, pDevicesManager->m_channels[nChannelIndex]->m_Devices[nDeviceIndex]->m_strName);
- Invalidate(FALSE);
- return 0;
- }
- bool CMainFrame::ShowView(void)
- {
- HTREEITEM hSelectedItem = m_wndTree.GetSelectedItem();
- HTREEITEM hItem;
- int i;
- m_hCurrent = hSelectedItem;
- //如果是视图
- char szPicDir[MAX_PATH] = {0};
- CString strTempDir = "", strPicFile;
- strcpy(szPicDir, g_strDirectory);
- strcat(szPicDir, "\\");
- strcat(szPicDir, _PICTUREDIR);
- hItem = m_wndTree.GetParentItem( hSelectedItem );
- while( hItem != NULL )
- {
- if( hItem == m_hMonitor )
- {
- CString strSelect = m_wndTree.GetItemText( hSelectedItem );
- if( !strTempDir.Compare("") )
- {
- strPicFile += strSelect;
- }
- else
- {
- strPicFile += strTempDir;
- //strPicFile += "\\";//chn modify 12.28
- strPicFile += strSelect;
- }
- AddIDEView( strSelect, CString(szPicDir) + strPicFile + ".view" );
- return true;
- }
- else
- {
- CString str = m_wndTree.GetItemText( hItem );
- strTempDir = str + "\\" + strTempDir;
- hItem = m_wndTree.GetParentItem( hItem );
- }
- }
- // 如果是脚本
- for (i = 0; i < MAX_SCRIPT_NUM; i++)
- {
- if (m_hScriptGroup[i] == hSelectedItem)
- {
- CString scriptFile;
- scriptFile = _SCRIPTDIR;
- scriptFile = g_strDirectory + CString("\\") + scriptFile + m_wndTree.GetItemText(hSelectedItem) + ".srp";
- CString strScript;
- strScript.Format("%s\\ScriptEdit.exe", g_strDirectory);
- ShellExecute(NULL,"open", (char *)(LPCTSTR)strScript, scriptFile, NULL, SW_SHOWNORMAL);
- return true;
- }
- }
- // 报警联动
- if (hSelectedItem == m_hActionWithAlarm)
- {
- CDlg_ActionWithAlarm dlg;
- dlg.DoModal();
- }
- // 系统参数
- if (hSelectedItem == m_hSystem)
- {
- SetRunPara();
- }
- // 变量编辑
- else if (m_hAnalog == hSelectedItem)
- {
- if( g_nIsDemo == 0 )
- {
- CAnalogDlg dlg;
- dlg.DoModal();
- }
- }
- else // 设备属性设置xs
- {
- if( g_nIsDemo == 0 )
- {
- int nRet = ShowDevProperty(hSelectedItem);
- if( nRet == 1 )
- {
- if( hSelectedItem )
- {
- // 这里一删除就报异常,只能先注释,待解决 for Jesse 100106
- //m_wndTree.DeleteItem( m_hCurrent );//hSelectedItem
- }
- }
- pDevicesManager->Store(g_strDirectory);
- }
- }
- return true;
- }
- BOOL CMainFrame::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
- {
- // TODO: 在此添加专用代码和/或调用基类
- LPNMHDR pNmhdr = (LPNMHDR)lParam;
- int i, j;
- //if( m_bShutdown ) return FALSE; //chn dele
- int idCtrl = LOWORD(wParam);
- if( idCtrl == IDD_TREE_LEFT ) // Is my tree's id?
- {
- CPoint point;
- ::GetCursorPos(&point);
- m_wndTree.ScreenToClient(&point);
- switch( pNmhdr->code )
- {
- case NM_CLICK:
- {
- // Get Click item's
- UINT uFlags;
- HTREEITEM hItem = m_wndTree.HitTest(point, &uFlags);
- if((hItem != NULL) && (TVHT_ONITEM & uFlags))
- {
- m_wndTree.SelectItem(hItem);
- }
- return true;//Already process the notify
- }
- case NM_RCLICK:
- {
- // Get RightClick item's
-
- if( g_bStartRun ) return true;
- UINT uFlags;
- HTREEITEM hItem = m_wndTree.HitTest(point, &uFlags);
- m_wndTree.SelectItem(hItem);
- if((hItem != NULL) && (TVHT_ONITEM & uFlags))
- {
- GetCursorPos(&m_mousePoint);
- HTREEITEM hSelectedItem = m_wndTree.GetSelectedItem();
- //新建设备
- if( hSelectedItem == m_hIOGroup )
- {
- CMenu menu;
- menu.LoadMenu(IDR_MENU_ADDDEVICE);
- menu.GetSubMenu(0)->TrackPopupMenu(TPM_LEFTALIGN,m_mousePoint.x,m_mousePoint.y,this);
- }
- //删除设备
- int nChannelIndex = -1, nDeviceIndex = -1;
- int nChannelSize = pDevicesManager->m_channels.GetSize();
- // 串口设备属性设置
- for (i = 0; i < nChannelSize; i++)
- {
- #if 0 // 删除COM时有BUG,待解决 for Jesse 091104
- if( m_hSerialGroup[i] == hSelectedItem )
- {
- CMenu menu;
- menu.LoadMenu(IDR_MENU_DELDEVICE);
- menu.GetSubMenu(0)->TrackPopupMenu(TPM_LEFTALIGN,m_mousePoint.x,m_mousePoint.y,this);
- return true;
- }
- #endif
- int nDeviceSize = pDevicesManager->m_channels[i]->m_Devices.GetSize();
- for( j = 0; j < nDeviceSize; j++)
- {
- if (m_hSerialDev[i][j]==hSelectedItem)
- {
- CMenu menu;
- menu.LoadMenu(IDR_MENU_DELDEVICE);
- menu.GetSubMenu(0)->TrackPopupMenu(TPM_LEFTALIGN,m_mousePoint.x,m_mousePoint.y,this);
- return true;
- }
- if( m_hNetworkDev[j] == hSelectedItem &&
- pDevicesManager->m_channels[i]->m_nCommunicateType == 1 )
- {
- CMenu menu;
- menu.LoadMenu(IDR_MENU_DELDEVICE);
- menu.GetSubMenu(0)->TrackPopupMenu(TPM_LEFTALIGN,m_mousePoint.x,m_mousePoint.y,this);
- return true;
- }
- }
- }
- //新建或删除监控画面
- if (hSelectedItem == m_hMonitor)
- {
- CMenu menu;
- menu.LoadMenu(IDR_MENU_ADDVIEW);
- menu.GetSubMenu(1)->TrackPopupMenu(TPM_LEFTALIGN,m_mousePoint.x,m_mousePoint.y,this);
- }
- else
- {
- if( FindTreeItem( hSelectedItem, m_hMonitor ) )
- {
- CMenu menu;
- menu.LoadMenu(IDR_MENU_ADDVIEW);
- menu.GetSubMenu(0)->TrackPopupMenu(TPM_LEFTALIGN,m_mousePoint.x,m_mousePoint.y,this);
- }
- }
- //设定脚本
- for (i = 0; i < MAX_SCRIPT_NUM; i++)
- {
- if (m_hScriptGroup[i] == hSelectedItem)
- {
- CMenu menu;
- menu.LoadMenu(IDR_MENU_SETSCRIPT);
- menu.GetSubMenu(0)->TrackPopupMenu(TPM_LEFTALIGN,m_mousePoint.x,m_mousePoint.y,this);
- }
- }
- //新建脚本
- if (hSelectedItem == m_hScript)
- {
- CMenu menu;
- menu.LoadMenu(IDR_MENU_ADDSCRIPT);
- menu.GetSubMenu(0)->TrackPopupMenu(TPM_LEFTALIGN,m_mousePoint.x,m_mousePoint.y,this);
- }
- }
- return true;//Already process the notify
- }
- case NM_DBLCLK:
- {
- ShowView();
- return true;
- }
- }
- return false; // no match
- }
- return CMDIAutoHideFrame::OnNotify(wParam, lParam, pResult);
- }
- int CMainFrame::GetFreeSerialTreeItem()
- {
- CString str;
- #if 1
- for( int i = MAX_SERIAL_NUM-1; i >=0 ; i-- )
- {
- //if( m_hSerialGroup[i] == NULL ) break;
- str = m_wndTree.GetItemText(m_hSerialGroup[i]);
- if( str.Compare("") )
- {
- return i+1;
- }
- }
- #else
- for( int i = 0; i < MAX_SERIAL_NUM; i++ )
- {
- //if( m_hSerialGroup[i] == NULL ) break;
- str = m_wndTree.GetItemText(m_hSerialGroup[i]);
- if( !str.Compare("") )
- {
- return i;
- }
- }
- #endif
- return 0;
- }
- int CMainFrame::GetNetworkChannelIndex()
- {
- int i;
- int nChannelNo = -1;
- int nChannelSize = pDevicesManager->m_channels.GetSize();
- for (i = 0; i < nChannelSize; i++)
- {
- // 网络设备,在m_channels中永远只有一个
- if( pDevicesManager->m_channels[i]->m_nCommunicateType == 1 )
- {
- return i;
- }
- }
- return -1;
- }
- int CMainFrame::GetFreeNetworkTreeItem()
- {
- CString str;
- for( int i = 0; i < MAX_NETWORK_NUM; i++ )
- {
- //if( m_hNetworkDev[i] == NULL ) break;
- str = m_wndTree.GetItemText(m_hNetworkDev[i]);
- if( !str.Compare("") )
- {
- return i;
- }
- }
- return -1;
- }
- int CMainFrame::GetIndexSerialTreeItem(CString strSrc)
- {
- CString str;
- for( int i = 0; i < MAX_SERIAL_NUM; i++ )
- {
- //if( m_hSerialGroup[i] == NULL ) break;
- str = m_wndTree.GetItemText(m_hSerialGroup[i]);
- if( !str.Compare(strSrc) )
- {
- return i;
- }
- }
- return -1;
- }
- int CMainFrame::GetIndexNetworkTreeItem(CString strSrc)
- {
- CString str;
- for( int i = 0; i < MAX_NETWORK_NUM; i++ )
- {
- //if( m_hNetworkDev[i] == NULL ) break;
- str = m_wndTree.GetItemText(m_hNetworkDev[i]);
- if( !str.Compare(strSrc) )
- {
- return i;
- }
- }
- return -1;
- }
- int CMainFrame::FinishedAddDevice(int nIsDelete, CString strUid)
- {
- // 加入该设备的参数
- CChannel* pChannel = NULL;
-
- CDevice* pDev = new CDevice();
- pDev->Create();
- int nIP;
- nIP = htonl(m_wndComport.m_nNetIP);
- // 通信协议(例:Modbus rtu, Modbus Ascii, Modbus tcp)
- pDev->m_nProtocolType = m_wndDevice.m_nProtocolType;
- // 协议动态库名称
- pDev->m_strProtocolName = m_wndDevice.m_strProtocolName;
- // 是否为采集模块
- pDev->m_nIsCollectDev = m_wndDevice.m_nCollectDev;
- // 是否启用设备
- pDev->m_bUsed = m_wndDevice.m_nDevEnable;
- // 设备UID
- if( nIsDelete == 1 && m_wndDevice.m_sUidOld!=m_wndComport.m_strUID )
- pDev->m_strUID = m_wndComport.m_strUID2==""?m_wndComport.m_strUID:m_wndComport.m_strUID2;
- else
- pDev->m_strUID = m_wndComport.m_strUID;
- // 设备名称
- pDev->m_strName = m_wndComport.m_strDevName.Trim();
- // 设备类型
- pDev->m_strType = m_wndDevice.m_strDevTypeName.Trim();
- // 设备地址
- pDev->m_Address = (BYTE)m_wndComport.m_nDevAddr;
- // 驱动名称(例:UPS、空调)
- pDev->m_strDevDriveName = m_wndDevice.m_strDevDriveName;
- // 设备厂家名称
- pDev->m_strDevFactoryName = m_wndDevice.m_strDevFactoryName;
- // 通讯超时
- pDev->m_nTimeout = m_wndComport.m_nTimeout;
- // 网络设备IP
- pDev->m_strDevIP = inet_ntoa(*(struct in_addr *)&nIP);
- // 网络设备通信端口
- pDev->m_nNetPort = m_wndComport.m_nNetPort;
- // 配置文件名称
- pDev->m_strIniName = m_wndDevice.m_strIniName;
- // 预留1 设备所属区域
- pDev->m_strReserved1 = m_wndComport.m_strDevArea.Trim();
- // 预留2
- pDev->m_strReserved2 = m_wndDevice.m_strReserved2;
- // 预留3
- pDev->m_strReserved3 = m_wndDevice.m_strReserved3;
- // 预留4
- pDev->m_strReserved4 = m_wndDevice.m_strReserved4;
- // 预留5
- pDev->m_strReserved5 = m_wndDevice.m_strReserved5;
- // 预留6
- pDev->m_strReserved6 = m_wndComport.m_strReserved6;
- // 预留7
- pDev->m_strReserved7 = m_wndComport.m_strReserved7;
- // 预留8
- pDev->m_strReserved8 = m_wndComport.m_strReserved8;
- // 预留9
- pDev->m_strReserved9 = m_wndComport.m_strReserved9;
- // 预留10
- pDev->m_strReserved10 = m_wndComport.m_strReserved10;
- // 预留1
- pDev->m_nReserved1 = m_wndDevice.m_nReserved1;
- // 预留2
- pDev->m_nReserved2 = m_wndDevice.m_nReserved2;
- // 预留3
- pDev->m_nReserved3 = m_wndDevice.m_nReserved3;
- // 预留4
- pDev->m_nReserved4 = m_wndDevice.m_nReserved4;
- // 预留5
- pDev->m_nReserved5 = m_wndDevice.m_nReserved5;
- // 预留6
- pDev->m_nReserved6 = m_wndComport.m_nReserved6;
- // 预留7
- pDev->m_nReserved7 = m_wndComport.m_nReserved7;
- // 预留8
- pDev->m_nReserved8 = m_wndComport.m_nReserved8;
- // 预留9
- pDev->m_nReserved9 = m_wndComport.m_nReserved9;
- // 预留10
- pDev->m_nReserved10 = m_wndComport.m_nReserved10;
- // 预留1
- pDev->m_bReserved1 = m_wndDevice.m_bReserved1;
- // 预留2
- pDev->m_bReserved2 = m_wndDevice.m_bReserved2;
- // 预留3
- pDev->m_bReserved3 = m_wndDevice.m_bReserved3;
- // 预留4
- pDev->m_bReserved4 = m_wndDevice.m_bReserved4;
- // 预留5
- pDev->m_bReserved5 = m_wndDevice.m_bReserved5;
- // 预留6
- pDev->m_bReserved6 = m_wndComport.m_bReserved6;
- // 预留7
- pDev->m_bReserved7 = m_wndComport.m_bReserved7;
- // 预留8
- pDev->m_bReserved8 = m_wndComport.m_bReserved8;
- // 预留9
- pDev->m_bReserved9 = m_wndComport.m_bReserved9;
- // 预留10
- pDev->m_bReserved10 = m_wndComport.m_bReserved10;
- CString strCommPort;
- int nIndex, nFreeIndex;
- int nChannelSize;
- int nDeviceSize;
- CHAR szMaxID[MAX_ID + 1] = {0};
- CHAR szDevTypeID[MAX_ID + 1] = {0};
- // 获取t_dev_property设备属性表字段ID的最大值
- int nRet = CDBInterface::GetInstancePtr()->GetMaxID("t_dev_property", "id", szMaxID);
- if( -1 == nRet )
- {
- pDev->Destroy();
- delete pDev;
- return -1;
- }
- int nID;
- if( atoi(szMaxID) > 0 )
- {
- nID = atoi(szMaxID) + 1;
- }
- else if( atoi(szMaxID) == 0 )
- {
- nID = 1;
- }
- // 获取设备类型ID
- CDBInterface::GetInstancePtr()->GetDevTypeID((char *)(LPCTSTR)m_wndDevice.m_strDevTypeName, szDevTypeID);
- if( !m_wndComport.m_strDevName.Compare("") )
- {
- MessageBox(g_strDevNumCannotBlank,g_strTip,MB_ICONWARNING);
- pDev->Destroy();
- delete pDev;
- return 0;
- }
- //检查合法值
- if( m_wndDevice.m_operation == CDlgDevice::NEW )
- {
- CHAR szDevName[MAX_DESC + 1] = {0};
- CHAR szDevUID[MAX_DESC + 1] = {0};
- int nRet = CDBInterface::GetInstancePtr()->GetDevName((char *)(LPCTSTR)m_wndComport.m_strUID, szDevName);
- if( nRet > 0 )
- {
- MessageBox(g_strDevUidExist,g_strTip,MB_ICONWARNING);
- pDev->Destroy();
- delete pDev;
- return 0;
- }
-
- nRet = CDBInterface::GetInstancePtr()->GetDevUID( (char *)(LPCTSTR)m_wndComport.m_strDevName, szDevUID );
- if( nRet > 0 )
- {
- MessageBox(g_strDevNameExist,g_strTip,MB_ICONWARNING);
- pDev->Destroy();
- delete pDev;
- return 0;
- }
- }
- // 串口设备
- if( m_wndComport.m_nCommunicateMode == 0 )
- {
- strCommPort.Format("COM%d", m_wndComport.m_nCommPort);
- nIndex = GetIndexSerialTreeItem(strCommPort);//得到COM的序列号
- if( nIndex == -1 )
- {
- nFreeIndex = GetFreeSerialTreeItem();
- CChannel* pComport = new CChannel();
- //CSerial* pComport = new CSerial();
- // 串行端口
- pComport->m_strPort = strCommPort.Trim();
- // 串行端口地址
- pComport->m_nAddr = m_wndComport.m_nDevAddr;
- // 波特率
- pComport->m_nBaudRate = m_wndComport.m_nRate; // 1200;2400;4800;9600;14400;19200;38400;57600;115200;128000;256000
- // 数据位
- pComport->m_nByteSize = m_wndComport.m_nDataBit; // 0-1=7,8
- // 检验位
- pComport->m_nParity = m_wndComport.m_nCheckCode; // 0-4=no,odd,even,mark
- // 停止位
- pComport->m_nStopBits = m_wndComport.m_nStopBit; // 0-2=1,1.5,2
-
- pDevicesManager->m_channels.Add(pComport);
- nChannelSize = pDevicesManager->m_channels.GetSize();
- pChannel = pDevicesManager->m_channels[nChannelSize - 1];
- pChannel->m_strName = strCommPort.Trim();
- pChannel->m_nCommunicateType = m_wndComport.m_nCommunicateMode;
- nDeviceSize = pChannel->m_Devices.GetSize();
- //if( m_hCurrent )
- // m_wndTree.DeleteItem( m_hCurrent );
- m_hSerialGroup[nFreeIndex] = m_wndTree.InsertItem(strCommPort, 4, 4, m_hSerial);
- m_hSerialDev[nFreeIndex][nDeviceSize] = m_wndTree.InsertItem(m_wndComport.m_strDevName, 4, 4, m_hSerialGroup[nFreeIndex]);
- }
- else
- {
- nChannelSize = pDevicesManager->m_channels.GetSize();
- for( int i = 0; i < nChannelSize; i++ )
- {
- CChannel* pCommPort =pDevicesManager->m_channels[i];
- //CSerial *pCommPort = (CSerial *)(pDevicesManager->m_channels[i]);
- if( ( !pCommPort->m_strPort.Compare(strCommPort) ) && pCommPort->m_Devices.GetSize() > 0 )
- {
- nDeviceSize = pCommPort->m_Devices.GetSize();
- for( int j = 0; j < nDeviceSize; j++ )
- {
- if( (int)pCommPort->m_Devices[j]->m_Address == m_wndComport.m_nDevAddr )
- {
- MessageBox(g_strSerialPortInUse,g_strTip,MB_ICONWARNING);
- pDev->Destroy();
- delete pDev;
- return 0;
- }
- }
- }
- }
- for( int i = 0; i < nChannelSize; i++ )
- {
- CChannel* pCommPort = pDevicesManager->m_channels[i];
- //CSerial *pCommPort = (CSerial *)(pDevicesManager->m_channels[i]);
- if( !pCommPort->m_strPort.Compare(strCommPort) )
- {
- nDeviceSize = pCommPort->m_Devices.GetSize();
- pChannel = pDevicesManager->m_channels[i];
- //nDeviceSize = pChannel->m_Devices.GetSize();
- break;
- }
- }
- //pChannel = pDevicesManager->m_channels[nChannelSize - 1];
- //nDeviceSize = pChannel->m_Devices.GetSize();
- m_hSerialDev[nIndex][nDeviceSize] = m_wndTree.InsertItem(m_wndComport.m_strDevName, 4, 4, m_hSerialGroup[nIndex]);
- }
- if( pChannel != NULL )
- {
- pDev->m_pChannel = pChannel;
- pChannel->m_Devices.Add(pDev);
- }
- }
- // 网络设备
- else
- {
- int nChannelIndex;
- // 得到m_channels数组中网络设备的索引,有且只有一个
- nIndex = GetIndexNetworkTreeItem( m_wndComport.m_strDevName );
- if( nIndex == -1 )
- {
- if( m_wndComport.m_nNetIP == 0 )
- {
- MessageBox(g_strIPNotBlank, g_strTip, MB_ICONWARNING);
- pDev->Destroy();
- delete pDev;
- return 0;
- }
- if( m_wndComport.m_nNetPort == 0 )
- {
- MessageBox(g_strComcanNot0, g_strTip, MB_ICONWARNING);
- pDev->Destroy();
- delete pDev;
- return 0;
- }
- nChannelIndex = GetNetworkChannelIndex();
- if( nChannelIndex == -1 )
- {
- CNetwork *pNetwork = new CNetwork();
- pNetwork->m_strName = g_strNetDev;
- pDevicesManager->m_channels.Add(pNetwork);
- nChannelIndex = pDevicesManager->m_channels.GetSize() - 1;
- }
- else
- {
- pChannel = pDevicesManager->m_channels[nChannelIndex];
- for( int j = 0; j < pChannel->m_Devices.GetSize(); j ++ )
- {
- if( !m_wndDevice.m_bIsStu2000 )
- {
- if( !(pChannel->m_Devices[j]->m_strDevIP.Compare(inet_ntoa(*(struct in_addr *)&nIP))) &&
- (pChannel->m_Devices[j]->m_nNetPort == m_wndComport.m_nNetPort ) )
- {
- MessageBox(g_strIPConflict, g_strTip, MB_ICONWARNING);
- pDev->Destroy();
- delete pDev;
- return 0;
- }
- }
- else
- {
- if( !(pChannel->m_Devices[j]->m_strDevIP.Compare(inet_ntoa(*(struct in_addr *)&nIP))) &&
- (pChannel->m_Devices[j]->m_nNetPort == m_wndComport.m_nNetPort ) &&
- ((int)pChannel->m_Devices[j]->m_Address == m_wndComport.m_nDevAddr ) )
- {
- MessageBox(g_strIPConflict, g_strTip, MB_ICONWARNING);
- pDev->Destroy();
- delete pDev;
- return 0;
- }
- }
- }
- }
-
- pChannel = pDevicesManager->m_channels[nChannelIndex];
- pChannel->m_nCommunicateType = m_wndComport.m_nCommunicateMode;
- nDeviceSize = pChannel->m_Devices.GetSize();
- nFreeIndex = GetFreeNetworkTreeItem();
- m_hNetworkDev[nFreeIndex] = m_wndTree.InsertItem( m_wndComport.m_strDevName, 2, 2, m_hEtherNet);
- pDev->m_pChannel = pChannel;
- pChannel->m_Devices.Add(pDev);
- }
- else
- {
- MessageBox(g_strDevNameExist,g_strTip,MB_ICONWARNING);
- pDev->Destroy();
- delete pDev;
- return 0;
- }
- }
- if( nIsDelete == 1 )
- {
- //删除数据库数据
- CDBInterface::GetInstancePtr()->DeleteDevInfo((char *)(LPCTSTR)strUid);
- }
- // 插入设备信息
- CDBInterface::GetInstancePtr()->InsertDevInfo(
- nID,
- (char *)(LPCTSTR)pDev->m_strUID,
- m_wndComport.m_nCommPort,
- m_wndComport.m_nDevAddr,
- (char *)(LPCTSTR)m_wndComport.m_strDevName,
- atoi(szDevTypeID),
- m_wndComport.m_nRate,
- m_wndComport.m_nDataBit,
- m_wndComport.m_nStopBit,
- m_wndComport.m_nCheckCode,
- 0,
- inet_ntoa( *(struct in_addr *)&nIP ),
- m_wndComport.m_nNetPort,
- m_wndComport.m_nCommunicateMode,
- m_wndDevice.m_nCollectDev,
- m_wndDevice.m_nProtocolType,
- m_wndComport.m_nTimeout,
- m_wndDevice.m_nDevEnable,
- (char *)(LPCTSTR)m_wndDevice.m_strProtocolName,
- (char *)(LPCTSTR)m_wndDevice.m_strIniName,
- (char *)(LPCTSTR)pDev->m_strReserved1,
- //(char *)(LPCTSTR)m_wndDevice.m_strReserved1,
- (char *)(LPCTSTR)m_wndDevice.m_strReserved2,
- (char *)(LPCTSTR)m_wndDevice.m_strReserved3,
- (char *)(LPCTSTR)m_wndDevice.m_strReserved4,
- (char *)(LPCTSTR)m_wndDevice.m_strReserved5,
- (char *)(LPCTSTR)m_wndComport.m_strReserved6,
- (char *)(LPCTSTR)m_wndComport.m_strReserved7,
- (char *)(LPCTSTR)m_wndComport.m_strReserved8,
- (char *)(LPCTSTR)m_wndComport.m_strReserved9,
- (char *)(LPCTSTR)m_wndComport.m_strReserved10,
- m_wndDevice.m_nReserved1,
- m_wndDevice.m_nReserved2,
- m_wndDevice.m_nReserved3,
- m_wndDevice.m_nReserved4,
- m_wndDevice.m_nReserved5,
- m_wndComport.m_nReserved6,
- m_wndComport.m_nReserved7,
- m_wndComport.m_nReserved8,
- m_wndComport.m_nReserved9,
- m_wndComport.m_nReserved10,
- (int)m_wndDevice.m_bReserved1,
- (int)m_wndDevice.m_bReserved2,
- (int)m_wndDevice.m_bReserved3,
- (int)m_wndDevice.m_bReserved4,
- (int)m_wndDevice.m_bReserved5,
- (int)m_wndComport.m_bReserved6,
- (int)m_wndComport.m_bReserved7,
- (int)m_wndComport.m_bReserved8,
- (int)m_wndComport.m_bReserved9,
- (int)m_wndComport.m_bReserved10
- );
- return 1;
- }
- void CMainFrame::AddDevice()
- {
- CWizard MyWizard(g_strMywizard,this,1);
- MyWizard.AddPage( &m_wndDevice );
- MyWizard.AddPage( &m_wndComport );
- MyWizard.SetWizardMode();
- MyWizard.SetActivePage( &m_wndDevice );
- m_wndDevice.m_operation = CDlgDevice::NEW;
- void* pType = NULL;
- if( MyWizard.DoModal() == ID_WIZFINISH )
- {
- int nRet = FinishedAddDevice(0, "");
- if( -1!=nRet && 0!=nRet )
- {
- CString sContent;
- sContent.Format("%s %s< %s >",g_strAdd,g_strDevice1,m_wndComport.m_strDevName );
- CDBInterface::GetInstancePtr()->InsertLogRecord( LOG_DEV_ADD,0,"",(char *)(LPCTSTR)sContent );
-
- pDevicesManager->SendNoticeToServer( CMD_NOTICE_READ_DB_DEV,CMD_OPERATE_ADD,"",m_wndComport.m_strUID,0,"64320" );
- MyWizard.RemovePage( &m_wndDevice );
- MyWizard.RemovePage( &m_wndComport );
- }
- if( 0==nRet )
- {
- MyWizard.RemovePage( &m_wndDevice );
- MyWizard.RemovePage( &m_wndComport );
- AddDevice();
- }
- }
- }
- void CMainFrame::OnAdddevoce()
- {
- // TODO: 在此添加命令处理程序代码
- AddDevice();
- }
- void CMainFrame::OnUpdateAdddevoce(CCmdUI *pCmdUI)
- {
- // TODO: 在此添加命令更新用户界面处理程序代码
- }
- void CMainFrame::OnZuTaiAdd()
- {
- if( !m_pDlgZuTaiAdd->m_bIsExistExcel )
- {
- MessageBox( "没有安装Excel软件,组态功能不能用!","提示" );
- return;
- }
- CDlg_Pwd Dlg_Pwd;
- Dlg_Pwd.m_nShowType = 2;
- if( Dlg_Pwd.DoModal()!=IDOK )
- return;
- m_pDlgZuTaiAdd->ReadResource();
- m_pDlgZuTaiAdd->ShowWindow( SW_SHOW );
- }
- void CMainFrame::OnUpdateZuTaiAdd(CCmdUI *pCmdUI)
- {
- }
- void CMainFrame::OnDeleteport()
- {
- // TODO: 在此添加命令处理程序代码
- }
- void CMainFrame::OnUpdateDeleteport(CCmdUI *pCmdUI)
- {
- // TODO: 在此添加命令更新用户界面处理程序代码
- }
- void CMainFrame::OnAddPort()
- {
- // TODO: 在此添加命令处理程序代码
- }
- void CMainFrame::OnUpdateAddPort(CCmdUI *pCmdUI)
- {
- // TODO: 在此添加命令更新用户界面处理程序代码
- }
- void CMainFrame::OnAddScript()
- {
- // TODO: 在此添加命令处理程序代码
- CScriptSetDlg dlg;
- if (dlg.DoModal() == IDOK)
- {
- m_hScriptGroup[m_nScripts++] = m_wndTree.InsertItem(dlg.m_strName,1,1,m_hScript);
-
- CString strFileName = dlg.m_strName;
- strFileName = CString(g_strDirectory) + "\\" + _SCRIPTDIR + strFileName;
- strFileName = strFileName + ".srp";
-
- CFile fileSpt;
- if (fileSpt.Open(strFileName, CFile::modeCreate)) // | CFile::modeWrite
- {
- fileSpt.Close();
- }
- strFileName.Replace(".srp", ".con");
- if ( dlg.m_bUsed )
- {
- WritePrivateProfileString("RUNPARA", "USE", "1", strFileName);
- }
- else
- {
- WritePrivateProfileString("RUNPARA", "USE", "0", strFileName);
- }
- WritePrivateProfileString("RUNPARA", "CONDITON", dlg.m_strCondition, strFileName);
- char tmp[10];
- sprintf(tmp, "%d", dlg.m_nType);
- WritePrivateProfileString("RUNPARA", "TYPE", tmp, strFileName);
- sprintf(tmp, "%d", dlg.m_nCircle);
- WritePrivateProfileString("RUNPARA", "CIRCLE", tmp, strFileName);
- }
- }
- void CMainFrame::OnUpdateAddScript(CCmdUI *pCmdUI)
- {
- // TODO: 在此添加命令更新用户界面处理程序代码
- }
- void CMainFrame::HideRunBar()
- {
- //m_wndRunToolBar.ShowWindow(SW_HIDE);
- }
- void CMainFrame::OnAddview()
- {
- // TODO: 在此添加命令处理程序代码
- CViewNameDlg dlg;
- if (dlg.DoModal() == IDOK)
- {
- if( dlg.m_strViewName.Compare("")==0 )
- {
- MessageBox(g_strMonitorNameIsBlank, g_strTip, MB_ICONINFORMATION);
- return;
- }
- char szPicDir[MAX_PATH] = {0};
- CString strTempDir = "";
- strcpy(szPicDir, g_strDirectory);
- strcat(szPicDir, "\\");
- strcat(szPicDir, _PICTUREDIR);
- int cx=GetSystemMetrics(SM_CXSCREEN)-10;
- int cy=GetSystemMetrics(SM_CYSCREEN)-100;
- CGraph* pic=new CGraph(CSize(cx, cy));
- pic->m_strPicFile = CString(szPicDir);
- HTREEITEM hSelectedItem = m_wndTree.GetSelectedItem();
- HTREEITEM hItem;
- m_wndTree.InsertItem(dlg.m_strViewName, 1, 1, hSelectedItem);
- if( hSelectedItem == m_hMonitor )
- {
- pic->m_strPicFile = pic->m_strPicFile + dlg.m_strViewName + ".view";
- pic->Store();
- }
- else
- {
- hItem = m_wndTree.GetParentItem( hSelectedItem );
- while( hItem != NULL )
- {
- if( hItem == m_hMonitor )
- {
- CString strSelect = m_wndTree.GetItemText( hSelectedItem );
- if( !strTempDir.Compare("") )
- {
- pic->m_strPicFile += strSelect;
- }
- else
- {
- pic->m_strPicFile += strTempDir;
- pic->m_strPicFile += "\\";
- pic->m_strPicFile += strSelect;
- }
- if( !PathFileExists(pic->m_strPicFile) )
- {
- SECURITY_ATTRIBUTES sa;
- sa.nLength = sizeof(SECURITY_ATTRIBUTES);
- sa.lpSecurityDescriptor = NULL;
- sa.bInheritHandle = 0;
- int nRet = CreateDirectory(pic->m_strPicFile, &sa);
- if( !nRet )
- {
- MessageBox(g_strCannotCreateDirecitory,g_strTip,MB_ICONWARNING);
- delete pic;
- return;
- }
- }
- pic->m_strPicFile = pic->m_strPicFile + "\\" + dlg.m_strViewName + ".view";
- pic->Store();
- delete pic;
- return;
- }
- else
- {
- CString str = m_wndTree.GetItemText( hItem );
- strTempDir = str + "\\" + strTempDir;
- hItem = m_wndTree.GetParentItem( hItem );
- }
- }
- }
- delete pic;
- CString sContent;
- sContent.Format("添加画面< %s >",dlg.m_strViewName.TrimRight() );
- CDBInterface::GetInstancePtr()->InsertLogRecord( LOG_MONITOR_ADD,0,"",(char *)(LPCTSTR)sContent );
- }
- }
- void CMainFrame::OnAddview2()
- {
- OnAddview();
- }
- void CMainFrame::OnUpdateAddview(CCmdUI *pCmdUI)
- {
- // TODO: 在此添加命令更新用户界面处理程序代码
- }
- void CMainFrame::OnEditSort()
- {
- CDlg_EditView dlg;
- dlg.DoModal();
- }
- void CMainFrame::OnUpdateEditSort(CCmdUI *pCmdUI)
- {
- // TODO: 在此添加命令更新用户界面处理程序代码
- }
- void CMainFrame::OnUpdateAddview2(CCmdUI *pCmdUI)
- {
- // TODO: 在此添加命令更新用户界面处理程序代码
- }
- void CMainFrame::DeleteDev(int nIsHint)
- {
- int i, j;
- CString strMessage, strSelect;
- HTREEITEM hSelectedItem = m_wndTree.GetSelectedItem();
- strSelect = m_wndTree.GetItemText( hSelectedItem );
- int nChannelNo = -1, nDeviceNo = -1;
- int nChannelSize = pDevicesManager->m_channels.GetSize();
- // 串口设备属性设置
- for (i = 0; i < nChannelSize; i++)
- {
- if( nChannelNo != -1 && nDeviceNo != -1 ) break;
- int nDeviceSize = pDevicesManager->m_channels[i]->m_Devices.GetSize();
- for( j = 0; j < nDeviceSize; j++)
- {
- if (m_hSerialDev[i][j]==hSelectedItem &&
- pDevicesManager->m_channels[i]->m_nCommunicateType == 0 )
- {
- nChannelNo = i;
- nDeviceNo = j;
- break;
- }
- if( m_hNetworkDev[j] == hSelectedItem &&
- pDevicesManager->m_channels[i]->m_nCommunicateType == 1 )
- {
- nChannelNo = i;
- nDeviceNo = j;
- break;
- }
- }
- }
- CChannel* pChannel = pDevicesManager->m_channels[nChannelNo];
- CDevice* pDev = pChannel->m_Devices[nDeviceNo];
- if( nIsHint )
- {
- strMessage.Format(g_strDelDev,pDev->m_strName,pDev->m_strName);
- int nRet = MessageBox(strMessage,g_strConfirm,MB_YESNOCANCEL|MB_ICONQUESTION);
- if( nRet==IDCANCEL)
- return;
- else if( nRet==IDYES )
- {
- CString sContent;
- sContent.Format("%s %s< %s >",g_strAdd,g_strDevice1,strSelect );
- CDBInterface::GetInstancePtr()->InsertLogRecord( LOG_DEV_DELETE,0,"",(char *)(LPCTSTR)sContent );
- pDevicesManager->SendNoticeToServer( CMD_NOTICE_READ_DB_DEV,CMD_OPERATE_DELETE,"",(char *)(LPCTSTR)pChannel->m_Devices[nDeviceNo]->m_strUID,0,"64320" );
- CDBInterface::GetInstancePtr()->DelTableData( "t_dev_variant_item","uid",(char *)(LPCTSTR)pChannel->m_Devices[nDeviceNo]->m_strUID,1 );
- CDBInterface::GetInstancePtr()->DelTableData( "t_dev_variant","uid",(char *)(LPCTSTR)pChannel->m_Devices[nDeviceNo]->m_strUID,1 );
- CDBInterface::GetInstancePtr()->DelTableData( "t_var_status","devuid",(char *)(LPCTSTR)pChannel->m_Devices[nDeviceNo]->m_strUID,1 );
- }
- else
- {
- CString sContent;
- sContent.Format("%s %s< %s >",g_strAdd,g_strDevice1,strSelect );
- CDBInterface::GetInstancePtr()->InsertLogRecord( LOG_DEV_DELETE,0,"",(char *)(LPCTSTR)sContent );
- }
- }
- m_wndTree.DeleteItem(hSelectedItem);
- if( pChannel->m_nCommunicateType == 0 )
- {
- for( j = nDeviceNo; j < MAX_DEVICE_NUM; j++ )
- {
- m_hSerialDev[nChannelNo][j] = m_hSerialDev[nChannelNo][j+1];
- }
- }
- else if( pChannel->m_nCommunicateType = 1 )
- {
- for( j = nDeviceNo; j < MAX_DEVICE_NUM; j++ )
- {
- m_hNetworkDev[j] = m_hNetworkDev[j+1];
- }
- }
- //在设备与组的关系表中把相关的设备信息删掉
- CDBInterface::GetInstancePtr()->DelTableData( "t_role_equip","uid",(char *)(LPCTSTR)pChannel->m_Devices[nDeviceNo]->m_strUID,1 );
-
- CDBInterface::GetInstancePtr()->DeleteDevInfo( (char *)(LPCTSTR)pChannel->m_Devices[nDeviceNo]->m_strUID );
- delete pChannel->m_Devices[nDeviceNo];
- pChannel->m_Devices.RemoveAt(nDeviceNo);
- }
- void CMainFrame::OnDeletedevice()
- {
- // TODO: 在此添加命令处理程序代码
- DeleteDev(1);
- }
- void CMainFrame::OnUpdateDeletedevice(CCmdUI *pCmdUI)
- {
- // TODO: 在此添加命令更新用户界面处理程序代码
- pCmdUI->Enable(TRUE);
- }
- void CMainFrame::OnDeleteview()
- {
- // TODO: 在此添加命令处理程序代码
- //删除文件,同时再数状控件中删除
- CString strPath, strTemp;
- CString strPathFile,strPathFolder;
- HTREEITEM hSelectedItem = m_wndTree.GetSelectedItem();
- if( m_hMonitor==hSelectedItem )
- {
- MessageBox(g_strMonitorNameCannotDel, g_strTip, MB_ICONINFORMATION);
- return;
- }
- CString strSelect = m_wndTree.GetItemText( hSelectedItem );
- CString strMessage;
- strMessage.Format(g_strDelView,strSelect);
- if (MessageBox(strMessage,g_strConfirm,MB_YESNO|MB_ICONQUESTION) == IDNO)
- return;
- GetPicPathByTree( hSelectedItem,strTemp );
- strPathFile.Format( "%s\\%s%s.view",g_strDirectory,CString(_PICTUREDIR),strTemp.Left( strTemp.GetLength()-1) );
- strPathFolder.Format( "%s\\%s%s\0\0",g_strDirectory,CString(_PICTUREDIR),strTemp.Left( strTemp.GetLength()-1) );
- if( PathFileExists( strPathFile ) )
- {
- DeleteFile( strPathFile );
- m_wndTree.DeleteItem(hSelectedItem);
- hSelectedItem = NULL;
- }
- if( PathFileExists( strPathFolder ) )
- {
- //strPathFolder += "\0\0";
- DeleteDirectory( strPathFolder );
- //_DeleteFile( strPathFolder,FOF_ALLOWUNDO|FOF_NOCONFIRMATION );
- if( hSelectedItem )
- m_wndTree.DeleteItem(hSelectedItem);
- }
- CString sContent;
- sContent.Format("删除画面< %s >",strSelect.TrimRight() );
- CDBInterface::GetInstancePtr()->InsertLogRecord( LOG_MONITOR_DELETE,0,"",(char *)(LPCTSTR)sContent );
- return;
- //strPath = g_strDirectory + CString("\\") + CString(_PICTUREDIR);
- //ffsco o;
- //o.dirs(1); //查找子目录
- //o.find( LPCSTR(strPath), "*.view" );
- //ffsco::typeT coo;
- //ffsco::typeT::iterator it;
- //HTREEITEM hSelectedItem = m_wndTree.GetSelectedItem();
- //if( m_hMonitor==hSelectedItem )
- //{
- // MessageBox(g_strMonitorNameCannotDel, g_strTip, MB_ICONINFORMATION);
- // return;
- //}
- //CString strSelect = m_wndTree.GetItemText( hSelectedItem );
- //CString strMessage;
- //strMessage.Format(g_strDelView,strSelect);
- //if (MessageBox(strMessage,g_strConfirm,MB_YESNO|MB_ICONQUESTION) == IDNO)
- // return;
- ////文件
- //coo = o.co_file();
- //for (it = coo.begin(); coo.end() != it; it++)
- //{
- // strTemp = (*it).c_str();
- // strPath = strTemp;
- // strTemp = strTemp.Right( strTemp.GetLength() - strTemp.ReverseFind('\\') - 1 );
- // if( !strTemp.Compare(strSelect + ".view") )
- // {
- // CFile::Remove( strPath );
- // m_wndTree.DeleteItem(hSelectedItem);
- // break;
- // }
- //}
- ////目录
- //coo = o.co_dir();
- //for( it = coo.begin(); coo.end() != it; it++ )
- //{
- // strTemp = (*it).c_str();
- // strPath = strTemp;
- // int nFind = strTemp.ReverseFind('\\');
- // strTemp = strTemp.Left( nFind );
- // strTemp = strTemp.Right( strTemp.GetLength() - strTemp.ReverseFind('\\') - 1 );
- // if( !strTemp.Compare(strSelect) )
- // {
- // DeleteDirectory( strPath );
- // m_wndTree.DeleteItem(hSelectedItem);
- // break;
- // }
- //}
- //CString sContent;
- //sContent.Format("删除画面< %s >",strSelect.TrimRight() );
- //CDBInterface::GetInstancePtr()->InsertLogRecord( LOG_MONITOR_DELETE,0,"",(char *)(LPCTSTR)sContent );
- }
- void CMainFrame::OnUpdateDeleteview(CCmdUI *pCmdUI)
- {
- // TODO: 在此添加命令更新用户界面处理程序代码
- }
- void CMainFrame::OnModifyViewName()
- {
- // TODO: 在此添加命令处理程序代码
- CString strNew, strTemp,sViewName;
- CString strPathFile,strPathFolder;
- HTREEITEM hSelectedItem = m_wndTree.GetSelectedItem();
- if( m_hMonitor==hSelectedItem )
- {
- return;
- }
- CString strSelect = m_wndTree.GetItemText( hSelectedItem );
- CViewNameDlg dlg;
- dlg.m_strViewName = strSelect;
- if (dlg.DoModal() != IDOK)
- return;
- GetPicPathByTree( hSelectedItem,strTemp );
- strPathFile.Format( "%s\\%s%s.view",g_strDirectory,CString(_PICTUREDIR),strTemp.Left( strTemp.GetLength()-1) );
- strPathFolder.Format( "%s\\%s%s\0\0",g_strDirectory,CString(_PICTUREDIR),strTemp.Left( strTemp.GetLength()-1) );
- if( PathFileExists( strPathFile ) )
- {
- strTemp = strSelect + ".view";
- sViewName = dlg.m_strViewName + ".view";
- strNew = strPathFile;
- strNew.Replace( strTemp,sViewName );
- MoveFile( strPathFile,strNew );
- m_wndTree.SetItemText( hSelectedItem,dlg.m_strViewName );
- hSelectedItem = NULL;
- }
- if( PathFileExists( strPathFolder ) )
- {
- strTemp = "\\" + strSelect;
- sViewName = "\\" + dlg.m_strViewName;
- strNew = strPathFolder;
- strNew.Replace( strTemp,sViewName );
- CopyDirectory( strPathFolder,strNew );
- DeleteDirectory( strPathFolder );
- if( hSelectedItem )
- m_wndTree.DeleteItem(hSelectedItem);
- }
- }
- void CMainFrame::OnUpdateModifyViewName(CCmdUI *pCmdUI)
- {
- // TODO: 在此添加命令更新用户界面处理程序代码
- }
- void CMainFrame::OnDeletescript()
- {
- // TODO: 在此添加命令处理程序代码
- HTREEITEM hSelectedItem = m_wndTree.GetSelectedItem();
- CFile::Remove( _SCRIPTDIR + m_wndTree.GetItemText(hSelectedItem) + ".srp");
- CFile::Remove( _SCRIPTDIR + m_wndTree.GetItemText(hSelectedItem) + ".con");
- m_wndTree.DeleteItem(hSelectedItem);
- int i = 0, nPos = -1;
- for( i = 0; i < m_nScripts; i++)
- {
- if (hSelectedItem == m_hScriptGroup[i])
- {
- nPos = i;
- }
- }
-
- for( i = nPos; i < m_nScripts; i++)
- {
- m_hScriptGroup[i] = m_hScriptGroup[i+1];
- }
- }
- void CMainFrame::OnUpdateDeletescript(CCmdUI *pCmdUI)
- {
- // TODO: 在此添加命令更新用户界面处理程序代码
- }
- void CMainFrame::OnSetscript()
- {
- // TODO: 在此添加命令处理程序代码
- HTREEITEM hSelectedItem = m_wndTree.GetSelectedItem();
- for (int m = 0; m < 32; m++)
- {
- if (m_hScriptGroup[m] == hSelectedItem)
- {
- CString conFile;
- //SetCurrentDirectory(g_CurrentDir);
- conFile = CString(g_strDirectory) + "\\" + _SCRIPTDIR;
- conFile = conFile + m_wndTree.GetItemText(hSelectedItem) + ".con";
-
- CScriptSetDlg dlg;
- dlg.m_nCircle = GetPrivateProfileInt("RUNPARA", "CIRCLE", -1, conFile);
- dlg.m_nType = GetPrivateProfileInt("RUNPARA", "TYPE", -1, conFile);
- dlg.m_bUsed = GetPrivateProfileInt("RUNPARA", "USE", -1, conFile);
-
- char szCon[MAX_PATH] = {0};
- GetPrivateProfileString("RUNPARA", "CONDITON", "", szCon, MAX_PATH, conFile);
- dlg.m_strCondition = szCon;
- dlg.m_strName = m_wndTree.GetItemText(hSelectedItem);
- if (dlg.DoModal() == IDOK)
- {
- WritePrivateProfileString("RUNPARA", "CONDITON", dlg.m_strCondition, conFile);
- char tmp[10];
- sprintf(tmp, "%d", dlg.m_nType);
- WritePrivateProfileString("RUNPARA", "TYPE", tmp, conFile);
- sprintf(tmp, "%d", dlg.m_nCircle);
- WritePrivateProfileString("RUNPARA", "CIRCLE", tmp, conFile);
- if ( dlg.m_bUsed )
- {
- WritePrivateProfileString("RUNPARA", "USE", "1", conFile);
- }
- else
- {
- WritePrivateProfileString("RUNPARA", "USE", "0", conFile);
- }
- }
- }
- }
- }
- void CMainFrame::OnUpdateSetscript(CCmdUI *pCmdUI)
- {
- // TODO: 在此添加命令更新用户界面处理程序代码
- }
- void CMainFrame::OnEditscript()
- {
- // TODO: 在此添加命令处理程序代码
- HTREEITEM hSelectedItem = m_wndTree.GetSelectedItem();
- for (int m = 0; m < 32; m++)
- {
- if (m_hScriptGroup[m] == hSelectedItem)
- {
- CString scriptFile;
- scriptFile = CString(g_strDirectory) + "\\" + _SCRIPTDIR;
- scriptFile = scriptFile + m_wndTree.GetItemText(hSelectedItem) + ".srp";
- ShellExecute(NULL,"open", "ScriptEdit.exe", scriptFile, NULL, SW_SHOWNORMAL);
- }
- }
- }
- void CMainFrame::OnUpdateEditscript(CCmdUI *pCmdUI)
- {
- // TODO: 在此添加命令更新用户界面处理程序代码
- }
- void CMainFrame::SetRunPara()
- {
- OnSysPara();
- }
- int CMainFrame::GetIDEViewIndex(CString strPath)
- {
- int i;
- for( i = 0; i < MAX_VIEW_NUM; i++ )
- {
- if( !m_pViewIDE[i] ) continue;
- CString str;
- str = m_pViewIDE[i]->m_strPath;
- str.Replace("\\\\", "\\");
- strPath.Replace("\\\\", "\\");
- if( !str.Compare(strPath) )
- {
- return i;
- }
- }
- return -1;
- }
- int CMainFrame::GetIDEViewFreeIndex(CString strPath)
- {
- int i;
- for( i = 0; i < MAX_VIEW_NUM; i++ )
- {
- if( !m_pViewIDE[i] ) return i;
- if( m_pViewIDE[i]->m_bClose ) continue;
- if( !m_pViewIDE[i]->m_strPath.Compare("") )
- {
- return i;
- }
- }
- return -1;
- }
- void CMainFrame::AddIDEView(CString strDesc, CString strPath)
- {
- //如果是当前画面,退出
- if( g_strViewName==strPath )
- return;
- g_sCurrentPageName = strDesc;
- // 打开新的画面,先保存旧的。
- CIDEView *pView = (CIDEView *)m_pActiveView;
- if( pView )
- {
- pView->ChangeView();
- }
-
- int nIndex = GetIDEViewIndex(strPath);
- if( nIndex == -1 )
- {
- nIndex = GetIDEViewFreeIndex(strPath);
- if( nIndex == -1 ) nIndex = 0;
- CCreateContext context;
- m_pViewIDE[nIndex] = new CChildFrame;
- m_pViewIDE[nIndex]->m_strPath = strPath;
- m_pViewIDE[nIndex]->m_strDesc = strDesc;
- context.m_pCurrentDoc = m_pDoc;
- context.m_pNewDocTemplate = m_pDoc->GetDocTemplate();
- context.m_pNewViewClass = RUNTIME_CLASS( CIDEView );
- context.m_pCurrentFrame = this;
- context.m_pLastView = NULL;
- if( !m_pViewIDE[nIndex]->LoadFrame(IDI_SUMMARY, WS_MAXIMIZE|WS_OVERLAPPEDWINDOW, this, &context) )
- {
- return;
- }
- m_pViewIDE[nIndex]->ShowWindow(SW_SHOWMAXIMIZED);
- m_pViewIDE[nIndex]->InitialUpdateFrame(m_pDoc,true);
- m_pViewIDE[nIndex]->MDIActivate();
- m_nViewCount++;
- }
- else
- {
- m_pActiveView = (CFormView *)m_pViewIDE[nIndex]->GetActiveView();
- m_pViewIDE[nIndex]->MDIActivate();
- }
- m_pViewIDE[ nIndex ]->m_bClose = FALSE;
- m_pActiveView = (CFormView *)m_pViewIDE[nIndex]->GetActiveView();
- g_strViewName = strPath;
- ((CIDEView *)m_pActiveView)->ChangeView();
- //取当前所有的变量到SA中
- GetCurPicVarToSArray( strPath );
- /////////////////////把当前画面名保存到C:\\PageName.txt中,给视频用///////////////////////////////////
- CString sPath = "C:\\PageName.txt";
- DeleteFile( sPath );
- CString strTemp;
- CStdioFile MyFile;
- CFileException e;
- if ( MyFile.Open(sPath,CFile::modeCreate|CFile::modeWrite,&e) )
- {
- strTemp.Format("%s\n",strDesc);
- MyFile.SeekToEnd();
- MyFile.WriteString(strTemp);
- MyFile.Close();
- }
- }
- void CMainFrame::OnUsers()
- {
- if( g_nIsDemo == 0 )
- {
- CDlgUserManager dlg;
- if( dlg.DoModal() == IDOK )
- {
- }
- }
- }
- void CMainFrame::OnEditPwdTool()
- {
- if( g_nIsDemo == 0 )
- {
- CDlgEditPwd dlg;
- if( dlg.DoModal() == IDOK )
- {
- CString sContent;
- sContent.Format("%s%s",g_strEdit,g_strPwd );
- CDBInterface::GetInstancePtr()->InsertLogRecord( LOG_PWD_EDIT,0,"",(char *)(LPCTSTR)sContent );
- }
- }
- }
- void CMainFrame::OnSysPara()
- {
- CSystemParaSetDlg dlg;
- dlg.m_bStartRun = g_bStartRun;
- dlg.m_bAlarmVoice = g_bAlarmVoice;
- dlg.m_bEventAlarm = g_bEventAlarm;
- dlg.m_bHideTask = g_bHideTask;
- dlg.m_strStartPic = g_strStartPic;
- dlg.m_strStartPath = g_strStartPath;
- if ( dlg.DoModal() == IDOK )
- {
- #if 0 //程序退出之前不改变状态
- g_bStartRun = dlg.m_bStartRun;
- #endif
- //int nPos = dlg.m_strStartPath.Find("\\\\");
- //if( nPos!=-1 )
- //{
- // dlg.m_strStartPath.Delete( nPos );
- //}
- //
- //int nLen = dlg.m_strStartPath.GetLength();
- //nPos = dlg.m_strStartPath.Find("view");
- //CString sTemp;
- //if( nPos<nLen-7 )
- // sTemp = dlg.m_strStartPath.Right( nLen-nPos-7 );
- //if( sTemp!="" )
- // g_strStartPic = sTemp+"\\"+dlg.m_strStartPic;
- //else
- g_strStartPic = dlg.m_strStartPic;
- g_strStartPath = dlg.m_strStartPath;
- g_bEventAlarm = dlg.m_bEventAlarm;
- g_bAlarmVoice = dlg.m_bAlarmVoice;
- g_bHideTask = dlg.m_bHideTask;
- StoreRunPara(dlg.m_bStartRun);
- }
- }
- void CMainFrame::OnEventmanage()
- {
- #if 0
- CEventSetDlg dlg;
- dlg.m_bControlEvent = g_bControlEvent;
- dlg.g_strYkWave =g_strYkWave;
- dlg.m_bLoginEvent = g_bLoginEvent;
- dlg.m_strLoginWave = g_strLoginWave;
- dlg.m_bReguEvent = g_bReguEvent;
- dlg.m_strReguWave = g_strReguWave;
- dlg.m_bSetEvent = g_bSetEvent;
- dlg.m_strSetWave = g_strSetWave;
- dlg.m_bYcEvent = g_bYcEvent;
- dlg.m_strYcWave = g_strYcWave;
- dlg.m_bYxChangeEve = g_bYxChangeEve;
- dlg.m_strYxChangeWave = g_strYxChangeWave;
- if (dlg.DoModal() == IDOK)
- {
- g_bControlEvent = dlg.m_bControlEvent;
- g_strYkWave = dlg.g_strYkWave;
- g_bLoginEvent = dlg.m_bLoginEvent;
- g_strLoginWave = dlg.m_strLoginWave;
- g_bReguEvent = dlg.m_bReguEvent;
- g_strReguWave = dlg.m_strReguWave;
- g_bSetEvent = dlg.m_bSetEvent;
- g_strSetWave = dlg.m_strSetWave;
- g_bYcEvent = dlg.m_bYcEvent;
- g_strYcWave = dlg.m_strYcWave;
- g_bYxChangeEve = dlg.m_bYxChangeEve;
- g_strYxChangeWave = dlg.m_strYxChangeWave;
- StoreEventPara();
- pVariantsManager->m_bDigitalAlarm = g_bYxChangeEve;
- pVariantsManager->m_bAnalogAlarm = g_bYcEvent;
- }
- #endif
- }
- void CMainFrame::OnEvent()
- {
- if( g_nIsDemo == 0 )
- {
- CDlgQueryWarningRec dlg;
- if( dlg.DoModal() == IDOK )
- {
- }
- }
- }
- void CMainFrame::OnSystemLog()
- {
- if( g_nIsDemo == 0 )
- {
- CDlgSystemLog dlg;
- dlg.DoModal();
- }
- }
- void CMainFrame::OnNoticeRec()
- {
- if( g_nIsDemo == 0 )
- {
- CDlgNoticeRec dlg;
- dlg.DoModal();
- }
- }
- void CMainFrame::OnUpdateEvent(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
- pCmdUI->Enable(m_bEvent);
- }
- void CMainFrame::OnUpdateSystemLog(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
- pCmdUI->Enable(m_bSystemLog);
- }
- void CMainFrame::OnUpdateNoticeRec(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
- pCmdUI->Enable(m_bNoticeRec);
- }
- void CMainFrame::OnUpdateUsers(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
- pCmdUI->Enable(m_bUsers);
- }
- void CMainFrame::OnUpdateEditPwd(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
- pCmdUI->Enable(m_bEditPwd);
- }
- void CMainFrame::OnUpdateSysPare(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
- pCmdUI->Enable(m_bSysPare);
- }
- void CMainFrame::OnUpdateSingleAnalog(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
- pCmdUI->Enable(m_bAnalog);
- }
- void CMainFrame::OnUpdatePrint(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
- pCmdUI->Enable(m_bPrint);
- }
- void CMainFrame::OnSummaryLog()
- {
- if( g_nIsDemo == 0 )
- {
- #if 0
- CDlgQuerySummaryLog dlg;
- if( dlg.DoModal() == IDOK )
- {
- }
- #endif
- CString sIDE,sReport;
- sIDE.Format( "%s",g_strDirectory );
- int nEnd = 0;
- for (int i = sIDE.GetLength()-1; i >= 0; i--)
- {
- if (g_strDirectory[i] == '\\')
- {
- nEnd = i;
- break;
- }
- }
- sReport = sIDE.Left( nEnd ) + "\\report";
- CString strFileName;
- strFileName.Format("%s\\DBMonitorReport.exe", sReport);
- ShellExecute(0, "open", strFileName, NULL, NULL, SW_SHOWNORMAL);
- }
- }
- void CMainFrame::OnUpdateSummaryLog(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
- pCmdUI->Enable(m_bDeviceLog);
- }
- void CMainFrame::StoreRunPara(BOOL bStartRun)
- {
- char Path[_MAX_PATH] = {0};
- strcat(Path, g_strDirectory);
- strcat(Path,"\\");
- strcat(Path, _PROJECTDIR);
- strcat(Path,"\\");
- strcat(Path, "runpara.ini");
- if ( bStartRun )
- {
- WritePrivateProfileString("RUNPARA", "STARTRUN", "1", Path);
- }
- else
- {
- WritePrivateProfileString("RUNPARA", "STARTRUN", "0", Path);
- }
- if ( g_bEventAlarm )
- {
- WritePrivateProfileString("RUNPARA", "ALARM", "1", Path);
- }
- else
- {
- WritePrivateProfileString("RUNPARA", "ALARM", "0", Path);
- }
- if ( g_bAlarmVoice )
- {
- WritePrivateProfileString("RUNPARA", "VOICE", "1", Path);
- }
- else
- {
- WritePrivateProfileString("RUNPARA", "VOICE", "0", Path);
- }
- if ( g_bHideTask )
- {
- WritePrivateProfileString("RUNPARA", "HIDETASK", "1", Path);
- }
- else
- {
- WritePrivateProfileString("RUNPARA", "HIDETASK", "0", Path);
- }
- if ( g_bFullScreen )
- {
- WritePrivateProfileString("RUNPARA", "FULLSCREEN", "1", Path);
- }
- else
- {
- WritePrivateProfileString("RUNPARA", "FULLSCREEN", "0", Path);
- }
- WritePrivateProfileString("RUNPARA", "STARTPIC", g_strStartPic, Path);
- WritePrivateProfileString("RUNPARA", "STARTPATH", g_strStartPath, Path);
- }
- // 存储事件参数
- void CMainFrame::StoreEventPara()
- {
- char Path[_MAX_PATH] = {0};
- strcat(Path, g_strDirectory);
- strcat(Path,"\\");
- strcat(Path, _PROJECTDIR);
- strcat(Path,"\\");
- strcat(Path, "event.ini");
-
- if ( g_bControlEvent )
- {
- WritePrivateProfileString("IFALARM", "CONTROL", "1", Path);
- }
- else
- {
- WritePrivateProfileString("IFALARM", "CONTROL", "0", Path);
- }
- if ( g_bLoginEvent )
- {
- WritePrivateProfileString("IFALARM", "LOGIN", "1", Path);
- }
- else
- {
- WritePrivateProfileString("IFALARM", "LOGIN", "0", Path);
- }
- if ( g_bSetEvent )
- {
- WritePrivateProfileString("IFALARM", "SET", "1", Path);
- }
- else
- {
- WritePrivateProfileString("IFALARM", "SET", "0", Path);
- }
- if ( g_bReguEvent )
- {
- WritePrivateProfileString("IFALARM", "REGU", "1", Path);
- }
- else
- {
- WritePrivateProfileString("IFALARM", "REGU", "0", Path);
- }
- if ( g_bYxChangeEve )
- {
- WritePrivateProfileString("IFALARM", "YXCHANGE", "1", Path);
- }
- else
- {
- WritePrivateProfileString("IFALARM", "YXCHANGE", "0", Path);
- }
- if ( g_bYcEvent )
- {
- WritePrivateProfileString("IFALARM", "YCOVERLIMIT", "1", Path);
- }
- else
- {
- WritePrivateProfileString("IFALARM", "YCOVERLIMIT", "0", Path);
- }
- WritePrivateProfileString("WAVEFILE", "CONTROL", g_strYkWave, Path);
- WritePrivateProfileString("WAVEFILE", "LOGIN", g_strLoginWave, Path);
- WritePrivateProfileString("WAVEFILE", "SET", g_strSetWave, Path);
- WritePrivateProfileString("WAVEFILE", "REGU", g_strReguWave, Path);
- WritePrivateProfileString("WAVEFILE", "YXCHANGE", g_strYxChangeWave, Path);
- WritePrivateProfileString("WAVEFILE", "YCOVERLIMIT", g_strYcWave, Path);
- }
- void CMainFrame::OnControldialog()
- {
- CRect rctDlg;
- int screenx = GetSystemMetrics(SM_CXSCREEN);
- int screeny = GetSystemMetrics(SM_CYSCREEN);
- m_dlgControl->GetWindowRect(&rctDlg);
- m_dlgControl->SetWindowPos(&wndTop, screenx - rctDlg.Width(), screeny - rctDlg.Height(),
- rctDlg.Width(), rctDlg.Height(), SWP_NOZORDER);
- m_dlgControl->ShowWindow(SW_SHOW);
- }
- void CMainFrame::OnTimer(UINT nIDEvent)
- {
- // TODO: 在此添加消息处理程序代码和/或调用默认值
- if( nIDEvent == 1 )
- {
- if (g_bStartRun && g_nIsPoll == 1)
- {
- for( int i = 0; i < g_nPollCount; i++ )
- {
- if( g_dwTick == 0 )
- {
- if( g_nPollIndex == i )
- {
- g_dwTick = GetTickCount();
- TRACE("Enter AddIDEView %s, %s\r\n", g_strPollPath, g_strPollDesc);
- AddIDEView(g_strPollDesc[i], g_strPollPath[i]);
- TRACE("Leave AddIDEView\r\n");
- }
- }
- else if( GetTickCount() - g_dwTick > (DWORD)g_nPollInterval * 1000 )
- {
- if( g_nPollIndex == g_nPollCount - 1 )
- {
- g_nPollIndex = 0;
- }
- else
- {
- g_nPollIndex++;
- }
- g_dwTick = 0;
- }
- }
- }
- }
- if( nIDEvent==2 )//定时得到狗信息/定时判断是否过期
- {
- //pDevicesManager->GetDogInfo( "64320" );
- if( pDevicesManager->m_bIsPastDue )
- {
- pDevicesManager->m_bIsPastDue = false;
- static bool bShow=false;
- if( !bShow )
- {
- bShow = true;
- CString sShow;
- sShow.Format(g_strPastDue,pDevicesManager->m_sPassDueInfo );
- if( MessageBox( sShow, g_strTip, MB_ICONWARNING)==IDOK )
- bShow = false;
- }
- }
- if( !pDevicesManager->m_bIsBlanceSmall )//余额不足
- {
- pDevicesManager->m_bIsBlanceSmall = true;
- CString sShow;
- sShow.Format("%s",pDevicesManager->m_sBanceContent );
- MessageBox( sShow, g_strTip, MB_ICONWARNING);
- }
- }
- //if( nIDEvent==3 )//判断变量在这个时间段时否报警
- //{
- // static int nStaticHours = -1;
- // CTime time = CTime::GetCurrentTime();
- // int nHours = time.GetHour();
- // if( nStaticHours!=nHours )
- // {
- // nStaticHours = nHours;
- // pVariantsManager->AllocDatePlan();
- // }
- //}
- CMDIAutoHideFrame::OnTimer(nIDEvent);
- }
- void CMainFrame::OnUserManager()
- {
- // TODO: 在此添加命令处理程序代码
- CDlgUserManager dlg;
- int nResult = dlg.DoModal();
- if( nResult == IDOK )
- {
- }
- }
- void CMainFrame::OnGroupManager()
- {
- // TODO: 在此添加命令处理程序代码
- CDlg_GroupManage dlg;
- int nResult = dlg.DoModal();
- if( nResult == IDOK )
- {
- }
- }
- void CMainFrame::OnEditPwd()
- {
- // TODO: 在此添加命令处理程序代码
- CDlgEditPwd dlg;
- if( dlg.DoModal() == IDOK )
- {
- CString sContent;
- sContent.Format("修改密码");
- CDBInterface::GetInstancePtr()->InsertLogRecord( LOG_PWD_EDIT,0,"",(char *)(LPCTSTR)sContent );
- }
- }
- void CMainFrame::OnSingleAnalog()
- {
- // TODO: 在此添加命令处理程序代码
- CAnalogDlg dlg;
- dlg.DoModal();
- }
- LRESULT CMainFrame::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
- {
- // TODO: 在此添加专用代码和/或调用基类
- switch( message )
- {
- case WM_MY_NEW_ALERT:
- {
- CString sPath;
- CString sVarName = (char *)wParam;
- //LOG4C((LOG_NOTICE, "报警变量:%s", sVarName));
- if( GetPicPathByVarName( sPath,sVarName ) )
- {
- int nPos1=0,nPos2=0;
- for( int i=sPath.GetLength()-1;i>0;i-- )
- {
- if( sPath[i]=='\\' )
- {
- nPos1 = i;
- break;
- }
- }
- for( int i=sPath.GetLength()-1;i>0;i-- )
- {
- if( sPath[i]=='.' )
- {
- nPos2 = i;
- break;
- }
- }
- CString sName = sPath.Mid( nPos1+1,nPos2-nPos1-1 );
- AddIDEView( sName,sPath );
- }
- //LOG4C((LOG_NOTICE, "报警画面:%s", sPath));
- }
- break;
- case WM_MY_SIZECHANGE:
- {
- CString str;
- str.Format( "%d,%d",wParam,lParam );
- m_dlgEvent->SetPos( wParam,lParam );
- }
- break;
- case WM_MY_SIZECHANGE2:
- {
- #if USE_NEWTOP
- CString str;
- str.Format( "%d,%d",wParam,lParam );
- m_pToolBar->SetPos( wParam,lParam );
- #endif
- }
- break;
- }
- return CMDIAutoHideFrame::WindowProc(message, wParam, lParam);
- }
- bool CMainFrame::GetPicIndexByPicPath( int &iIndex,CString sPicPath )
- {
- bool bRet=false;
- for( int i=0;i<VIEW_MAX_NUM;i++ )
- {
- if( m_PIC_VAR[i].sPicPath=="" )
- {
- iIndex=i;
- break;
- }
- if( m_PIC_VAR[i].sPicPath==sPicPath )
- {
- bRet = true;
- break;
- }
- }
- return bRet;
- }
- //通过变量名查找画面
- bool CMainFrame::GetPicPathByVarName( CString &sPicPath,CString sVarName )
- {
- bool bRet=false;
- bool bBreak=false;
- for( int i=0;i<VIEW_MAX_NUM;i++ )
- {
- if( m_PIC_VAR[i].sPicPath=="" )
- break;
- for( int j=0;j<1000;j++ )
- {
- if( m_PIC_VAR[i].sCaption[j]=="" )
- {
- break;
- }
- if( -1 != m_PIC_VAR[i].sCaption[j].Find( sVarName ) )
- {
- sPicPath = m_PIC_VAR[i].sPicPath;
- bRet = true;
- bBreak = true;
- break;
- }
- }
- if( bBreak )
- break;
- }
- return bRet;
- }
- // 判断是有效变量名
- BOOL CMainFrame::IsValidChar(char chr)
- {
- if ( chr >= '0' && chr <= '9')
- return TRUE;
- else if ((chr >= 'A' && chr <= 'Z') || (chr >= 'a' && chr <= 'z') )
- return TRUE;
- else if (chr == '_')
- return TRUE;
- else
- return FALSE;
- }
- //从组合公式中找出变量名加入到画面结构中
- void CMainFrame::GetVarFromGSAddToStruct( int iIndex,CString sGS )
- {
- //LOG4C((LOG_NOTICE, "GetVarFromGSAddToStruct sGS :%s", sGS));
- //sGS = "(HG7053_DI10>=3)OR(HG7053_LinkStatus<=33)";
- //sGS = "((HG7053_DI10>=3))";
- //sGS = "(HG7053_DI10>=3)AND(HG7053_LinkStatus<=33)OR(HG7053_DI15<3)";
- int nLen = sGS.GetLength();
- int nPos1=0,nPos2=0;
- int nPos3=0,nPos4=0;
- CString sTemp,s1,s2,s3;
- CString sGS2[100];
- int nCount=0;
-
- //OR AND NOT
- for( int i=0;i<nLen;i++ )
- {
- if( sGS.Mid( i,2)=="OR" && !IsValidChar(sGS[i+2]) )
- {
- sGS2[nCount++] = sGS.Mid( nPos1,i-nPos1 );
- nPos1 = i+2;
- }
- if( (sGS.Mid( i,3)=="AND" || sGS.Mid( i,3)=="NOT") && !IsValidChar(sGS[i+3]) )
- {
- sGS2[nCount++] = sGS.Mid( nPos1,i-nPos1 );
- nPos1 = i+3;
- }
- }
- if( nPos1<nLen )
- {
- sGS2[nCount++] = sGS.Mid( nPos1,nLen-nPos1 );
- }
- for( int iGSIndex=0;iGSIndex<nCount;iGSIndex++ )
- {
- nPos3=0;
- nPos4=0;
- nLen = sGS2[iGSIndex].GetLength();
- if( !IsValidChar( sGS2[iGSIndex][0] ) )
- {
- if( IsValidChar( sGS2[iGSIndex][1] ) )
- nPos3 = 1;
- else
- nPos3 = 2;
- for( int i=nPos3;i<nLen;i++ )
- {
- if( !IsValidChar( sGS2[iGSIndex][i] ) )
- {
- nPos4 = i-0;
- break;
- }
- }
- sTemp = sGS2[iGSIndex].Mid( nPos3,nPos4-nPos3 );
- int nInsert=0;
- if( !VarIsExistInPic( iIndex,sTemp,nInsert ) && sTemp!="" )
- m_PIC_VAR[iIndex].sCaption[nInsert] = sTemp;
- }
- else
- {
- for( int i=nPos3;i<nLen;i++ )
- {
- if( !IsValidChar( sGS2[iGSIndex][i] ) )
- {
- nPos4 = i-0;
- break;
- }
- }
- sTemp = sGS2[iGSIndex].Mid( nPos3,nPos4-nPos3 );
-
- int nInsert=0;
- if( !VarIsExistInPic( iIndex,sTemp,nInsert ) && sTemp!="" )
- m_PIC_VAR[iIndex].sCaption[nInsert] = sTemp;
- }
- }
- }
- //把变量插入到相对应的画面结构
- void CMainFrame::InsertPicPathToStruct( int iIndex,CString sPicPath )
- {
- //LOG4C((LOG_NOTICE, "InsertPicPathToStruct :%s", sPicPath));
- CDrawObjList _ObjList;
- m_PIC_VAR[iIndex].sPicPath = sPicPath;
- BYTE m_Type;
- CSize m_sizePic;
- CSize m_sizeGrid;
- BOOL m_bGrid;
- COLORREF m_clrBack;
- CFile file;
- if(file.Open(sPicPath,CFile::modeRead))
- {
- CArchive ar(&file,CArchive::load);
- ar >> m_Type;
- ar >> m_sizePic;
- ar >> m_sizeGrid;
- ar >> m_bGrid;
- ar >> m_clrBack;
- _ObjList.Serialize(ar);
- if( !_ObjList.IsEmpty() )
- {
- for(POSITION pos = _ObjList.GetHeadPosition();pos!=NULL;)
- {
- POSITION pos1 = pos ;
- CDrawObj *ct = (CDrawObj *)_ObjList.GetNext(pos);
- int nInsert=0;
- if( ct->m_bVariant && ct->m_strCaption!="" && !VarIsExistInPic( iIndex,ct->m_strCaption,nInsert ) )
- m_PIC_VAR[iIndex].sCaption[nInsert] = ct->m_strCaption;
- if( ct->m_strDynShow!="" )
- GetVarFromGSAddToStruct( iIndex,ct->m_strDynShow );
- if( ct->m_strDynForeCon!="" )
- GetVarFromGSAddToStruct( iIndex,ct->m_strDynForeCon );
- if( ct->m_strDynBackCon!="" )
- GetVarFromGSAddToStruct( iIndex,ct->m_strDynBackCon );
- if( ct->m_strDynLineCon!="" )
- GetVarFromGSAddToStruct( iIndex,ct->m_strDynLineCon );
- if( ct->m_strHoriPos!="" )
- GetVarFromGSAddToStruct( iIndex,ct->m_strHoriPos );
- if( ct->m_strHoriSize!="" )
- GetVarFromGSAddToStruct( iIndex,ct->m_strHoriSize );
- if( ct->m_strVertiPos!="" )
- GetVarFromGSAddToStruct( iIndex,ct->m_strVertiPos );
- if( ct->m_strVertiSize!="" )
- GetVarFromGSAddToStruct( iIndex,ct->m_strVertiSize );
- if( ct->m_strCurrentCaption!="" )
- GetVarFromGSAddToStruct( iIndex,ct->m_strCurrentCaption );
- if( ct->IsKindOf( RUNTIME_CLASS(CDrawBitmap) ) )
- {
- if( ((CDrawBitmap *)ct)->m_strDynCondition!="" )
- GetVarFromGSAddToStruct( iIndex,((CDrawBitmap *)ct)->m_strDynCondition );
- }
- if( ct->IsKindOf( RUNTIME_CLASS(CDrawGif) ) )
- {
- if( ((CDrawGif *)ct)->m_strDynCondition!="" )
- GetVarFromGSAddToStruct( iIndex,((CDrawGif *)ct)->m_strDynCondition );
- }
- }
- }
- ///////////////////////////////////////
- ar.Close();
- file.Close();
- }
- if(!_ObjList.IsEmpty())
- {
- for(POSITION pos = _ObjList.GetHeadPosition();pos!=NULL;)
- {
- POSITION pos1 = pos ;
- CDrawObj *ct = (CDrawObj *)_ObjList.GetNext(pos);
- _ObjList.RemoveAt(pos1);
- delete ct;
- }
- _ObjList.RemoveAll();
- ASSERT(_ObjList.IsEmpty());
- }
- }
- //查找这个画面结构里是否已经有这个变量
- bool CMainFrame::VarIsExistInPic( int iIndex,CString sVarName,int &iInsertIndex )
- {
- bool bRet=false;
- for( int j=0;j<1000;j++ )
- {
- if( m_PIC_VAR[iIndex].sCaption[j]=="" )
- {
- iInsertIndex = j;
- break;
- }
-
- //if( -1 != m_PIC_VAR[iIndex].sCaption[j].Find( sVarName ) )
- if( m_PIC_VAR[iIndex].sCaption[j] == sVarName )
- {
- bRet = true;
- break;
- }
- }
-
- return bRet;
- }
- void CMainFrame::GetCurPicVarToSArray( CString sPicPath )
- {
- //LOG4C((LOG_NOTICE, "开始获取 当前画面%s 变量", sPicPath));
- for( int i=0;i<VIEW_MAX_NUM;i++ )
- {
- if( m_PIC_VAR[i].sPicPath=="" )
- {
- LOG4C((LOG_NOTICE, "没有画面" ));
- break;
- }
- if( m_PIC_VAR[i].sPicPath==sPicPath )//是当前画面
- {
- //pVariantsManager->m_bIsChangeView = true;
- //Sleep(300);
-
- //LOG4C((LOG_NOTICE, "init"));
- //EnterCriticalSection( &g_CSLimit );
- //LOG4C((LOG_NOTICE, "in"));
-
- //pVariantsManager->m_analogTemp.RemoveAll();
- for( int j=0;j<1000;j++ )
- {
- if( m_PIC_VAR[i].sCaption[j]=="" )
- {
- break;
- }
- //////////////////////////////////////////////////
- int nVarSize = pVariantsManager->m_analog.GetSize();
- for ( int nVarIndex = 0; nVarIndex< nVarSize; nVarIndex++)
- {
- CAnalog* analog = pVariantsManager->m_analog.GetAt(nVarIndex);
- if( analog->m_strName == m_PIC_VAR[i].sCaption[j] )
- {
- //LOG4C((LOG_NOTICE, "当前画面变量 %s", analog->m_strName));
- pVariantsManager->m_analogTemp.Add( analog );
- }
- }
- //////////////////////////////////////////////////
- }
- //LOG4C((LOG_NOTICE, "out"));
- //LeaveCriticalSection( &g_CSLimit );
- //LOG4C((LOG_NOTICE, "end"));
- pVariantsManager->m_bIsChangeView = true;
- break;
- }
- }
- //LOG4C((LOG_NOTICE, "结束获取 当前画面%s 变量", sPicPath));
- }
- bool CMainFrame::MakeFolderExist( CString DirectoryName )
- {
- if(DirectoryName[DirectoryName.GetLength()-1]!='\\')
- DirectoryName += "\\";
- int nStart = 3;
- CString sTemp;
- for(int n = nStart;n<DirectoryName.GetLength();n++)
- {
- if(DirectoryName[n]=='\\')
- {
- sTemp = DirectoryName.Left(n);
- bool f = ExistFolder(sTemp);
- if(!ExistFolder(sTemp))
- CreateDirectoryCHN(sTemp);
- }
- }
- return true;
- }
- bool CMainFrame::CreateDirectoryCHN(CString DirectoryName)
- {
- bool re=false;
- ::CreateDirectory(DirectoryName,NULL);
- //DWORD dwAttrs;
- //dwAttrs=GetFileAttributes(DirectoryName);
- //if(!(dwAttrs & FILE_ATTRIBUTE_HIDDEN))
- //{
- // SetFileAttributes(DirectoryName,dwAttrs|FILE_ATTRIBUTE_HIDDEN);
- //}
- return re;
- }
- bool CMainFrame::ExistFolder(CString FilePath)
- {
- return PathFileExists( FilePath );
- }
- void CMainFrame::CopyDirectory( CString sScrPath,CString sDescPath )
- {
- CString StrSourceFolder= sScrPath;
- CString StrDestFolder=sDescPath;
- char SourceFolder[MAX_PATH+1]= " ";
- strcpy(SourceFolder,StrSourceFolder);
- char TargetFolder[MAX_PATH+1]= " ";
- strcpy(TargetFolder,StrDestFolder);
- SHFILEOPSTRUCT lpFile;
- lpFile.hwnd=GetSafeHwnd();
- lpFile.wFunc=FO_COPY;
- lpFile.pFrom=SourceFolder;
- lpFile.pTo=TargetFolder;
- lpFile.fFlags=FOF_ALLOWUNDO;
- lpFile.fAnyOperationsAborted=FALSE;
- lpFile.hNameMappings=NULL;
- lpFile.lpszProgressTitle=NULL;
- int ReturnValue=SHFileOperation(&lpFile);
- if(ReturnValue==0)
- {
- if(lpFile.fAnyOperationsAborted==TRUE)
- ;//MessageBox( "复制文件夹的操作被取消 ", "信息提示 ",MB_OK+MB_ICONWARNING);
- else
- ;//MessageBox( "复制文件夹操作成功 ", "信息提示 ",MB_OK+MB_ICONWARNING);
- }
- else
- ;//MessageBox( "复制文件夹操作失败 ", "信息提示 ",MB_OK+MB_ICONEXCLAMATION);
- }
- void CMainFrame::GetPicPathByTree( HTREEITEM hItemSelect,CString &sPath )
- {
- if( m_hMonitor==hItemSelect )
- {
- return;
- }
- CString strSelect = m_wndTree.GetItemText( hItemSelect );
-
- sPath = strSelect + "\\" + sPath;
- HTREEITEM hItemParent = m_wndTree.GetParentItem( hItemSelect );
- if( hItemParent )
- GetPicPathByTree( hItemParent,sPath );
- }
|