MainFrm.cpp 100 KB

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