MainFrm.cpp 97 KB

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