DBInterface.cpp 100 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265
  1. /*************************************************************
  2. /* Copyright (C), 2008-2010, StoneU Tech. Co., Ltd.
  3. /* 文件名: DBInterface.h
  4. /* 作者: Jesse
  5. /* 创建日期: 2010-08-02
  6. /* 版本号: V1.0
  7. /* 描述: 实现多种数据库的支持
  8. /* 其它:
  9. /* 主要类模块: CDBInterface
  10. /* 历史修改记录:
  11. 作者 时间 版本 描述
  12. Jesse 10/08/02 1.0 创建这个模块
  13. ***************************************************************/
  14. #include "stdafx.h"
  15. #include "DBInterface.h"
  16. namespace DBInterface
  17. {
  18. CDBInterface* CDBInterface::m_pDBInterface = NULL;
  19. // 静态成员函数,提供全局访问的接口
  20. CDBInterface* CDBInterface::GetInstancePtr()
  21. {
  22. if( NULL == m_pDBInterface )
  23. {
  24. m_pDBInterface = new CDBInterface();
  25. }
  26. return m_pDBInterface;
  27. }
  28. // 释放资源
  29. void CDBInterface::Release()
  30. {
  31. if( m_pDBInterface )
  32. delete m_pDBInterface;
  33. m_pDBInterface = NULL;
  34. }
  35. // 设置数据库类型
  36. void CDBInterface::SetDBType(char *pDBType)
  37. {
  38. strcpy(m_chDBType, pDBType);
  39. }
  40. //插入设备资料
  41. INT CDBInterface::InsertDevInfo(int nID, CHAR *pUid, int nPort, int nAddr, CHAR *pDevName, int nDevTypeID,
  42. int nRate, int nDataBit, int nStopBit, int nParityBit, int nRsMode,
  43. CHAR *pIPAddr, int nIPPort, int nCommMode, int nDevFlag, int nSpecialDev,
  44. int nTimeout, int nIsuse, CHAR *pProtocalName, CHAR *pIniName,
  45. CHAR *pReserved1, CHAR *pReserved2, CHAR *pReserved3, CHAR *pReserved4, CHAR *pReserved5,
  46. CHAR *pReserved6, CHAR *pReserved7, CHAR *pReserved8, CHAR *pReserved9, CHAR *pReserved10,
  47. int nReserved1, int nReserved2, int nReserved3, int nReserved4, int nReserved5,
  48. int nReserved6, int nReserved7, int nReserved8, int nReserved9, int nReserved10,
  49. int bReserved1, int bReserved2, int bReserved3, int bReserved4, int bReserved5,
  50. int bReserved6, int bReserved7, int bReserved8, int bReserved9, int bReserved10)
  51. {
  52. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  53. sprintf(strSQLText, "insert into t_dev_property(id, uid, port, devideaddr, devicename, " \
  54. "devicetype, baudrate, databit, stopbit, paritybit, ip, ipport, " \
  55. "commmode, deviceflag, specialdevice, timeout, isuse, protocoldllname, ininame, " \
  56. "strreserved1, strreserved2, strreserved3, strreserved4, strreserved5, " \
  57. "strreserved6, strreserved7, strreserved8, strreserved9, strreserved10, " \
  58. "intreserved1, intreserved2, intreserved3, intreserved4, intreserved5, " \
  59. "intreserved6, intreserved7, intreserved8, intreserved9, intreserved10, " \
  60. "boolreserved1, boolreserved2, boolreserved3, boolreserved4, boolreserved5, " \
  61. "boolreserved6, boolreserved7, boolreserved8, boolreserved9, boolreserved10 " \
  62. ") values (" \
  63. "%d, \'%s\', %d, %d, \'%s\', " \
  64. "%d, %d, %d, %d, %d, \'%s\', %d, " \
  65. "%d, %d, \'%d\', %d, \'%d\', \'%s\', \'%s\', " \
  66. "\'%s\', \'%s\', \'%s\', \'%s\', \'%s\', " \
  67. "\'%s\', \'%s\', \'%s\', \'%s\', \'%s\', " \
  68. "%d, %d, %d, %d, %d, " \
  69. "%d, %d, %d, %d, %d, " \
  70. "\'%d\', \'%d\', \'%d\', \'%d\', \'%d\', " \
  71. "\'%d\', \'%d\', \'%d\', \'%d\', \'%d\' " \
  72. ")",
  73. nID, pUid, nPort, nAddr, pDevName, nDevTypeID, nRate, nDataBit, nStopBit,
  74. nParityBit, pIPAddr, nIPPort, nCommMode, nDevFlag, nSpecialDev,
  75. nTimeout, nIsuse, pProtocalName, pIniName,
  76. pReserved1, pReserved2, pReserved3, pReserved4, pReserved5,
  77. pReserved6, pReserved7, pReserved8, pReserved9, pReserved10,
  78. nReserved1, nReserved2, nReserved3, nReserved4, nReserved5,
  79. nReserved6, nReserved7, nReserved8, nReserved9, nReserved10,
  80. bReserved1, bReserved2, bReserved3, bReserved4, bReserved5,
  81. bReserved6, bReserved7, bReserved8, bReserved9, bReserved10
  82. );
  83. return CDBConnection::GetInstancePtr()->Execute(strSQLText);
  84. }
  85. //修改设备资料,标准的SQL,多种数据库都一样
  86. INT CDBInterface::EditDevInfo(CHAR *pOldUid, CHAR *pNewUid, int nPort, int nAddr, CHAR *pDevName, int nDevTypeID,
  87. int nRate, int nDataBit, int nStopBit, int nParityBit, int nRsMode,
  88. CHAR *pIPAddr, int nIPPort, int nCommMode, int nDevFlag, int nSpecialDev,
  89. int nTimeout, int nIsuse, CHAR *pProtocalName, CHAR *pIniName,
  90. CHAR *pReserved1, CHAR *pReserved2, CHAR *pReserved3, CHAR *pReserved4, CHAR *pReserved5,
  91. CHAR *pReserved6, CHAR *pReserved7, CHAR *pReserved8, CHAR *pReserved9, CHAR *pReserved10,
  92. int nReserved1, int nReserved2, int nReserved3, int nReserved4, int nReserved5,
  93. int nReserved6, int nReserved7, int nReserved8, int nReserved9, int nReserved10,
  94. int bReserved1, int bReserved2, int bReserved3, int bReserved4, int bReserved5,
  95. int bReserved6, int bReserved7, int bReserved8, int bReserved9, int bReserved10)
  96. {
  97. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  98. sprintf(strSQLText, "update t_dev_property set uid = \'%s\', port = %d, devideaddr = %d, devicename = \'%s\', " \
  99. "devicetype = %d, baudrate = %d, databit = %d, stopbit = %d, paritybit = %d, ip = \'%s\', ipport = %d, " \
  100. "commmode = %d, deviceflag = %d, specialdevice = \'%d\', timeout = %d, isuse = \'%d\', protocoldllname = \'%s\', " \
  101. "ininame = \'%s\', " \
  102. "strreserved1 = \'%s\', strreserved2 = \'%s\', strreserved3 = \'%s\', strreserved4 = \'%s\', strreserved5 = \'%s\', " \
  103. "strreserved6 = \'%s\', strreserved7 = \'%s\', strreserved8 = \'%s\', strreserved9 = \'%s\', strreserved10 = \'%s\', " \
  104. "intreserved1 = %d, intreserved2 = %d, intreserved3 = %d, intreserved4 = %d, intreserved5 = %d, " \
  105. "intreserved6 = %d, intreserved7 = %d, intreserved8 = %d, intreserved9 = %d, intreserved10 = %d, " \
  106. "boolreserved1 = \'%d\', boolreserved2 = \'%d\', boolreserved3 = \'%d\', boolreserved4 = \'%d\', boolreserved5 = \'%d\', " \
  107. "boolreserved6 = \'%d\', boolreserved7 = \'%d\', boolreserved8 = \'%d\', boolreserved9 = \'%d\', boolreserved10 = \'%d\' " \
  108. "where uid = \'%s\'",
  109. pNewUid, nPort, nAddr, pDevName, nDevTypeID, nRate, nDataBit, nStopBit,
  110. nParityBit, pIPAddr, nIPPort, nCommMode, nDevFlag, nSpecialDev,
  111. nTimeout, nIsuse, pProtocalName, pIniName,
  112. pReserved1, pReserved2, pReserved3, pReserved4, pReserved5,
  113. pReserved6, pReserved7, pReserved8, pReserved9, pReserved10,
  114. nReserved1, nReserved2, nReserved3, nReserved4, nReserved5,
  115. nReserved6, nReserved7, nReserved8, nReserved9, nReserved10,
  116. bReserved1, bReserved2, bReserved3, bReserved4, bReserved5,
  117. bReserved6, bReserved7, bReserved8, bReserved9, bReserved10,
  118. pOldUid);
  119. return CDBConnection::GetInstancePtr()->Execute(strSQLText);
  120. }
  121. //删除设备资料
  122. INT CDBInterface::DeleteDevInfo(CHAR *pUid)
  123. {
  124. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  125. sprintf(strSQLText, "delete from t_dev_property where uid = \'%s\'", pUid);
  126. return CDBConnection::GetInstancePtr()->Execute(strSQLText);
  127. }
  128. //插入变量信息
  129. INT CDBInterface::InsertVarInfo(int nID, int nDevTypeID,CHAR *pVarName,CHAR *pVarDesc,int nVarTypeID,
  130. int nMinValues,int nMaxValues,int nMaxConvtRate,int nMinConvtRate,int nCollectFreq,
  131. int bIsDDE,int nRegStartAddr,int nWaringLevel,CHAR *pSetValue,CHAR *pUnit,
  132. CHAR *pUid,CHAR *pRelatepage,int bRecCurve,int nRegNum,CHAR *pOnDesc,
  133. CHAR *pOffDesc,int nUpperLimit,int nLowerLimit,int nChildid,int nVarItemID,
  134. int nNormalState,CHAR *pFields,CHAR *pSnmpOid,int nRearm,int nOffset,
  135. int nFuncCode,int nDataLen,float fCoef,int bRealtimeFlag,int bIsSave,
  136. CHAR *pRs232Cmd,CHAR *pRs232Type,int nRs232Index,int nIdentifyTime,int nRedetectTime,
  137. int bIsNormalAlarm,int nPurview,
  138. CHAR *pReserved1,CHAR *pReserved2,CHAR *pReserved3,CHAR *pReserved4,CHAR *pReserved5,
  139. CHAR *pReserved6,CHAR *pReserved7,CHAR *pReserved8,CHAR *pReserved9,CHAR *pReserved10,
  140. int nReserved1,int nReserved2,int nReserved3,int nReserved4,int nReserved5,
  141. int nReserved6,int nReserved7,int nReserved8,int nReserved9,int nReserved10,
  142. int bReserved1,int bReserved2,int bReserved3,int bReserved4,int bReserved5,
  143. int bReserved6,int bReserved7,int bReserved8,int bReserved9,int bReserved10 )
  144. {
  145. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  146. sprintf(strSQLText, "insert into t_dev_variant(id, devtypeid, varname, description, vartypeid, "\
  147. "minvalues, maxvalues,maxconvtrate, minconvtrate, collectfrequence, " \
  148. "isdde, address,warnlevel, setvalue, unit, " \
  149. "uid, relatepage, reccurve, registernum,ondesc, " \
  150. "offdesc,upperlimit,lowerlimit,childid,var_item_id, "\
  151. "normalstate,fields,snmpoid,rearm,offsets, "\
  152. "funcid,datalen,coefficient,realtimeflag,issave, "\
  153. "rs232cmd,rs232type,rs232index,identifytime,redetecttime, "\
  154. "normalisnotice,readonly, "\
  155. "strreserved1, strreserved2, strreserved3, strreserved4, strreserved5, " \
  156. "strreserved6, strreserved7, strreserved8, strreserved9, strreserved10, " \
  157. "intreserved1, intreserved2, intreserved3, intreserved4, intreserved5, " \
  158. "intreserved6, intreserved7, intreserved8, intreserved9, intreserved10, " \
  159. "boolreserved1, boolreserved2, boolreserved3, boolreserved4, boolreserved5, " \
  160. "boolreserved6, boolreserved7, boolreserved8, boolreserved9, boolreserved10 " \
  161. ") values (" \
  162. "%d, %d, \'%s\',\'%s\', %d, " \
  163. "%d, %d, %d, %d, %d, " \
  164. "\'%d\', %d, %d,\'%s\', \'%s\', " \
  165. "\'%s\', \'%s\',\'%d\', %d, \'%s\', " \
  166. "\'%s\', %d,%d, %d, %d, " \
  167. "%d, \'%s\', \'%s\',%d, %d, " \
  168. "%d, %d, %f, \'%d\', \'%d\', " \
  169. "\'%s\', \'%s\',%d, %d, %d, " \
  170. "\'%d\', \'%d\', " \
  171. "\'%s\', \'%s\', \'%s\', \'%s\', \'%s\', " \
  172. "\'%s\', \'%s\', \'%s\', \'%s\', \'%s\', " \
  173. "%d, %d, %d, %d, %d, " \
  174. "%d, %d, %d, %d, %d, " \
  175. "\'%d\', \'%d\', \'%d\', \'%d\', \'%d\', " \
  176. "\'%d\', \'%d\', \'%d\', \'%d\', \'%d\' " \
  177. ")",
  178. nID, nDevTypeID, pVarName, pVarDesc, nVarTypeID,
  179. nMinValues,nMaxValues,nMaxConvtRate,nMinConvtRate,nCollectFreq,
  180. bIsDDE,nRegStartAddr,nWaringLevel,pSetValue,pUnit,
  181. pUid,pRelatepage,bRecCurve,nRegNum,pOnDesc,
  182. pOffDesc,nUpperLimit,nLowerLimit,nChildid,nVarItemID,
  183. nNormalState,pFields,pSnmpOid,nRearm,nOffset,
  184. nFuncCode,nDataLen,fCoef,bRealtimeFlag,bIsSave,
  185. pRs232Cmd,pRs232Type,nRs232Index,nIdentifyTime,nRedetectTime,
  186. bIsNormalAlarm,nPurview,
  187. pReserved1, pReserved2, pReserved3, pReserved4, pReserved5,
  188. pReserved6, pReserved7, pReserved8, pReserved9, pReserved10,
  189. nReserved1, nReserved2, nReserved3, nReserved4, nReserved5,
  190. nReserved6, nReserved7, nReserved8, nReserved9, nReserved10,
  191. bReserved1, bReserved2, bReserved3, bReserved4, bReserved5,
  192. bReserved6, bReserved7, bReserved8, bReserved9, bReserved10
  193. );
  194. int a=0;
  195. return CDBConnection::GetInstancePtr()->Execute(strSQLText);
  196. }
  197. //插入数据记录
  198. INT CDBInterface::InsertDataRecord(
  199. CHAR* pDevName, // 设备名称
  200. CHAR* pHappenTime, // 发生时间
  201. CHAR* pVarName, // 变量名称
  202. CHAR *pVarDesc, // 变量描述
  203. double dbCurrValue // 当前值
  204. )
  205. {
  206. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  207. int iMaxID;
  208. CHAR chMaxID[MAX_ID] = {0};
  209. GetMaxID("t_data_rec", "id", chMaxID);
  210. if( 0 == atoi(chMaxID) )
  211. {
  212. iMaxID = 1;
  213. }
  214. else
  215. {
  216. iMaxID = atoi(chMaxID) + 1;
  217. }
  218. sprintf(strSQLText, "insert into t_data_rec(id,devname, happentime,varname,vardesc,datavalue) values(" \
  219. "%d, \'%s\', \'%s\', \'%s\', \'%s\', %.1f)",
  220. iMaxID, pDevName, pHappenTime,pVarName, pVarDesc, dbCurrValue );
  221. //LOG4C((LOG_NOTICE, "InsertDataRecord: %s", strSQLText ));
  222. return CDBConnection::GetInstancePtr()->Execute(strSQLText);
  223. }
  224. //获取设备类型ID
  225. INT CDBInterface::GetDevTypeID( CHAR *pDevTypeName, CHAR *pDevTypeID )
  226. {
  227. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  228. list<string> list1;
  229. list<string>::iterator it;
  230. if (!_stricmp(m_chDBType, "SQL SERVER"))
  231. {
  232. sprintf(strSQLText, "select top 1 id from t_dev_type where equiptype = \'%s\'", pDevTypeName);
  233. }
  234. else if (!_stricmp(m_chDBType, "ACCESS97"))
  235. {
  236. sprintf(strSQLText, "select top 1 id from t_dev_type where equiptype = \'%s\'", pDevTypeName);
  237. }
  238. else if (!_stricmp(m_chDBType, "ACCESS2000"))
  239. {
  240. sprintf(strSQLText, "select top 1 id from t_dev_type where equiptype = \'%s\'", pDevTypeName);
  241. }
  242. else if(!_stricmp(m_chDBType, "PGSQL"))
  243. {
  244. sprintf(strSQLText, "select id from t_dev_type where equiptype = \'%s\' limit 1", pDevTypeName);
  245. }
  246. int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList1(strSQLText, list1);
  247. if( 0 == list1.size() )
  248. {
  249. return 0;
  250. }
  251. if( nRet != -1 )
  252. {
  253. strcpy(pDevTypeID, list1.begin()->c_str());
  254. }
  255. for( it = list1.begin(); it != list1.end(); )
  256. {
  257. list1.erase(it++);
  258. }
  259. return nRet;
  260. }
  261. //获取指定厂家的设备型号ID
  262. INT CDBInterface::GetDevTypeID( int nDriverID, int nFactoryID, CHAR *pDevTypeName, CHAR *pDevTypeID )
  263. {
  264. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  265. list<string> list1;
  266. list<string>::iterator it;
  267. if (!_stricmp(m_chDBType, "SQL SERVER"))
  268. {
  269. sprintf(strSQLText, "select top 1 id from t_dev_type where driveid = %d and factoryid = %d and equiptype = \'%s\'",
  270. nDriverID, nFactoryID, pDevTypeName);
  271. }
  272. else if (!_stricmp(m_chDBType, "ACCESS97"))
  273. {
  274. sprintf(strSQLText, "select top 1 id from t_dev_type where driveid = %d and factoryid = %d and equiptype = \'%s\'",
  275. nDriverID, nFactoryID, pDevTypeName);
  276. }
  277. else if (!_stricmp(m_chDBType, "ACCESS2000"))
  278. {
  279. sprintf(strSQLText, "select top 1 id from t_dev_type where driveid = %d and factoryid = %d and equiptype = \'%s\'",
  280. nDriverID, nFactoryID, pDevTypeName);
  281. }
  282. else if(!_stricmp(m_chDBType, "PGSQL"))
  283. {
  284. sprintf(strSQLText, "select id from t_dev_type where driveid = %d and factoryid = %d and equiptype = \'%s\' limit 1",
  285. nDriverID, nFactoryID, pDevTypeName);
  286. }
  287. int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList1(strSQLText, list1);
  288. if( 0 == list1.size() )
  289. {
  290. return 0;
  291. }
  292. if( nRet != -1 )
  293. {
  294. strcpy(pDevTypeID, list1.begin()->c_str());
  295. }
  296. for( it = list1.begin(); it != list1.end(); )
  297. {
  298. list1.erase(it++);
  299. }
  300. return nRet;
  301. }
  302. //获取设备名称
  303. INT CDBInterface::GetDevName( CHAR *pDevUID, CHAR *pDevName )
  304. {
  305. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  306. list<string> list1;
  307. list<string>::iterator it;
  308. if (!_stricmp(m_chDBType, "SQL SERVER"))
  309. {
  310. sprintf(strSQLText, "select top 1 devicename from t_dev_property where uid = \'%s\'", pDevUID);
  311. }
  312. else if (!_stricmp(m_chDBType, "ACCESS97"))
  313. {
  314. sprintf(strSQLText, "select top 1 devicename from t_dev_property where uid = \'%s\'", pDevUID);
  315. }
  316. else if (!_stricmp(m_chDBType, "ACCESS2000"))
  317. {
  318. sprintf(strSQLText, "select top 1 devicename from t_dev_property where uid = \'%s\'", pDevUID);
  319. }
  320. else if(!_stricmp(m_chDBType, "PGSQL"))
  321. {
  322. sprintf(strSQLText, "select devicename from t_dev_property where uid = \'%s\' LIMIT 1", pDevUID);
  323. }
  324. int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList1(strSQLText, list1);
  325. if( 0 == list1.size() )
  326. {
  327. return 0;
  328. }
  329. if( nRet != -1 )
  330. {
  331. strcpy(pDevName, list1.begin()->c_str());
  332. }
  333. for( it = list1.begin(); it != list1.end(); )
  334. {
  335. list1.erase(it++);
  336. }
  337. return nRet;
  338. }
  339. //获取设备UID
  340. INT CDBInterface::GetDevUID( CHAR *pDevName, CHAR *pDevUID )
  341. {
  342. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  343. list<string> list1;
  344. list<string>::iterator it;
  345. if (!_stricmp(m_chDBType, "SQL SERVER"))
  346. {
  347. sprintf(strSQLText, "select top 1 uid from t_dev_property where devicename = \'%s\'", pDevName);
  348. }
  349. else if (!_stricmp(m_chDBType, "ACCESS97"))
  350. {
  351. sprintf(strSQLText, "select top 1 uid from t_dev_property where devicename = \'%s\'", pDevName);
  352. }
  353. else if (!_stricmp(m_chDBType, "ACCESS2000"))
  354. {
  355. sprintf(strSQLText, "select top 1 uid from t_dev_property where devicename = \'%s\'", pDevName);
  356. }
  357. else if(!_stricmp(m_chDBType, "PGSQL"))
  358. {
  359. sprintf(strSQLText, "select uid from t_dev_property where devicename = \'%s\' LIMIT 1", pDevName);
  360. }
  361. int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList1(strSQLText, list1);
  362. if( 0 == list1.size() )
  363. {
  364. return 0;
  365. }
  366. if( nRet != -1 )
  367. {
  368. strcpy(pDevUID, list1.begin()->c_str());
  369. }
  370. for( it = list1.begin(); it != list1.end(); )
  371. {
  372. list1.erase(it++);
  373. }
  374. return nRet;
  375. }
  376. //获取表最大的ID, 通用函数
  377. INT CDBInterface::GetMaxID( CHAR *pTableName, CHAR *pFieldName, CHAR *pMaxID )
  378. {
  379. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  380. list<string> list1;
  381. list<string>::iterator it;
  382. sprintf(strSQLText, "select max(%s) as maxid from %s", pFieldName, pTableName);
  383. int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList1(strSQLText, list1);
  384. if( 0 == list1.size() )
  385. {
  386. return 0;
  387. }
  388. if( nRet != -1 )
  389. {
  390. strcpy(pMaxID, list1.begin()->c_str());
  391. }
  392. for( it = list1.begin(); it != list1.end(); )
  393. {
  394. list1.erase(it++);
  395. }
  396. return nRet;
  397. }
  398. //获取驱动ID
  399. INT CDBInterface::GetDevDriveID( CHAR *pDevDriverName, CHAR *pDevDriverID )
  400. {
  401. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  402. list<string> list1;
  403. list<string>::iterator it;
  404. if (!_stricmp(m_chDBType, "SQL SERVER"))
  405. {
  406. sprintf(strSQLText, "select top 1 id from t_dev_drive where drivename = \'%s\'", pDevDriverName);
  407. }
  408. else if (!_stricmp(m_chDBType, "ACCESS97"))
  409. {
  410. sprintf(strSQLText, "select top 1 id from t_dev_drive where drivename = \'%s\'", pDevDriverName);
  411. }
  412. else if (!_stricmp(m_chDBType, "ACCESS2000"))
  413. {
  414. sprintf(strSQLText, "select top 1 id from t_dev_drive where drivename = \'%s\'", pDevDriverName);
  415. }
  416. else if(!_stricmp(m_chDBType, "PGSQL"))
  417. {
  418. sprintf(strSQLText, "select id from t_dev_drive where drivename = \'%s\' limit 1", pDevDriverName);
  419. }
  420. int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList1(strSQLText, list1);
  421. if( 0 == list1.size() )
  422. {
  423. return 0;
  424. }
  425. if( nRet != -1 )
  426. {
  427. strcpy(pDevDriverID, list1.begin()->c_str());
  428. }
  429. for( it = list1.begin(); it != list1.end(); )
  430. {
  431. list1.erase(it++);
  432. }
  433. return nRet;
  434. }
  435. //获取指定驱动的厂家ID
  436. INT CDBInterface::GetDevFactoryID( int nDriverID, CHAR *pDevFactoryName, CHAR *pDevFactoryID )
  437. {
  438. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  439. list<string> list1;
  440. list<string>::iterator it;
  441. if (!_stricmp(m_chDBType, "SQL SERVER"))
  442. {
  443. sprintf(strSQLText, "select top 1 factoryid from t_dev_factory where deviceid = %d and factoryname = \'%s\'",
  444. nDriverID, pDevFactoryName);
  445. }
  446. else if (!_stricmp(m_chDBType, "ACCESS97"))
  447. {
  448. sprintf(strSQLText, "select top 1 factoryid from t_dev_factory where deviceid = %d and factoryname = \'%s\'",
  449. nDriverID, pDevFactoryName);
  450. }
  451. else if (!_stricmp(m_chDBType, "ACCESS2000"))
  452. {
  453. sprintf(strSQLText, "select top 1 factoryid from t_dev_factory where deviceid = %d and factoryname = \'%s\'",
  454. nDriverID, pDevFactoryName);
  455. }
  456. else if(!_stricmp(m_chDBType, "PGSQL"))
  457. {
  458. sprintf(strSQLText, "select factoryid from t_dev_factory where deviceid = %d and factoryname = \'%s\' limit 1",
  459. nDriverID, pDevFactoryName);
  460. }
  461. int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList1(strSQLText, list1);
  462. if( 0 == list1.size() )
  463. {
  464. return 0;
  465. }
  466. if( nRet != -1 )
  467. {
  468. strcpy(pDevFactoryID, list1.begin()->c_str());
  469. }
  470. for( it = list1.begin(); it != list1.end(); )
  471. {
  472. list1.erase(it++);
  473. }
  474. return nRet;
  475. }
  476. //根据UID查找同一类型设备的个数
  477. INT CDBInterface::FindDevInfoByUID( CHAR *pUID, CHAR *pDevNum )
  478. {
  479. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  480. list<string> list1;
  481. list<string>::iterator it;
  482. #if 1
  483. if (!_stricmp(m_chDBType, "SQL SERVER"))
  484. {
  485. sprintf(strSQLText, "select uid from t_dev_property where uid like \'%s%s%s\' order by id desc", "%", pUID, "%");
  486. }
  487. else if (!_stricmp(m_chDBType, "ACCESS97"))
  488. {
  489. sprintf(strSQLText, "select uid from t_dev_property where uid like \'%s%s%s\' order by id desc", "%", pUID, "%");
  490. }
  491. else if (!_stricmp(m_chDBType, "ACCESS2000"))
  492. {
  493. sprintf(strSQLText, "select uid from t_dev_property where uid like \'%s%s%s\' order by id desc", "%", pUID, "%");
  494. }
  495. else if(!_stricmp(m_chDBType, "PGSQL"))
  496. {
  497. sprintf(strSQLText, "select uid from t_dev_property where uid like \'%s%s%s\' order by id desc", "%", pUID, "%");
  498. }
  499. #else
  500. if (!_stricmp(m_chDBType, "SQL SERVER"))
  501. {
  502. sprintf(strSQLText, "select count(id) as Num from t_dev_property where uid like \'%s%s%s\'", "%", pUID, "%");
  503. }
  504. else if (!_stricmp(m_chDBType, "ACCESS97"))
  505. {
  506. sprintf(strSQLText, "select count(id) as Num from t_dev_property where uid like \'%s%s%s\'", "%", pUID, "%");
  507. }
  508. else if (!_stricmp(m_chDBType, "ACCESS2000"))
  509. {
  510. sprintf(strSQLText, "select count(id) as Num from t_dev_property where uid like \'%s%s%s\'", "%", pUID, "%");
  511. }
  512. else if(!_stricmp(m_chDBType, "PGSQL"))
  513. {
  514. sprintf(strSQLText, "select count(id) as Num from t_dev_property where uid like \'%s%s%s\'", "%", pUID, "%");
  515. }
  516. #endif
  517. int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList1(strSQLText, list1);
  518. if( 0 == list1.size() )
  519. {
  520. return 0;
  521. }
  522. if( nRet != -1 )
  523. {
  524. CString s;
  525. int nMax=0;
  526. for( it = list1.begin(); it != list1.end(); )
  527. {
  528. CString sTemp = (*it++).c_str();
  529. for( int i=sTemp.GetLength()-1;i>0;i-- )
  530. {
  531. if( sTemp[i]=='.' )
  532. {
  533. int n = atoi( sTemp.Mid( i+1,sTemp.GetLength()-i ) );
  534. if( n>nMax )
  535. nMax = n;
  536. break;
  537. }
  538. }
  539. }
  540. s.Format( "%d",nMax );
  541. strcpy(pDevNum, s);
  542. }
  543. for( it = list1.begin(); it != list1.end(); )
  544. {
  545. list1.erase(it++);
  546. }
  547. return nRet;
  548. }
  549. //得到可以用的设备名称
  550. INT CDBInterface::FindDevNameByName( CHAR *pName, CString &sDevName,int &nDevIndex )
  551. {
  552. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  553. list<string> list1;
  554. list<string>::iterator it;
  555. if (!_stricmp(m_chDBType, "SQL SERVER"))
  556. {
  557. sprintf(strSQLText, "select devicename from t_dev_property where devicename like \'%s%s\' order by id desc", pName, "%");
  558. }
  559. else if (!_stricmp(m_chDBType, "ACCESS97"))
  560. {
  561. sprintf(strSQLText, "select devicename from t_dev_property where devicename like \'%s%s\' order by id desc", pName, "%");
  562. }
  563. else if (!_stricmp(m_chDBType, "ACCESS2000"))
  564. {
  565. sprintf(strSQLText, "select devicename from t_dev_property where devicename like \'%s%s\' order by id desc", pName, "%");
  566. }
  567. else if(!_stricmp(m_chDBType, "PGSQL"))
  568. {
  569. sprintf(strSQLText, "select devicename from t_dev_property where devicename like \'%s%s\' order by id desc", pName, "%");
  570. }
  571. int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList1(strSQLText, list1);
  572. if( 0 == list1.size() )
  573. {
  574. sDevName.Format( "%s1",pName );
  575. nDevIndex = 1;
  576. return 0;
  577. }
  578. if( nRet != -1 )
  579. {
  580. CString s;
  581. int nMax=0;
  582. for( it = list1.begin(); it != list1.end(); )
  583. {
  584. CString sTemp = (*it++).c_str();
  585. s.Format( "%s",pName );
  586. int n = atoi( sTemp.Right( sTemp.GetLength()-s.GetLength() ) );
  587. if( n>nMax )
  588. nMax = n;
  589. }
  590. nDevIndex = nMax+1;
  591. sDevName.Format( "%s%d",pName,nMax+1 );
  592. }
  593. for( it = list1.begin(); it != list1.end(); )
  594. {
  595. list1.erase(it++);
  596. }
  597. return nRet;
  598. }
  599. //得到时间计划
  600. INT CDBInterface::GetDatePlan( int nPlanType, CHAR *pPlanID, unsigned char nBufDate[7][24] )
  601. {
  602. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  603. list<string> list1, list2, list3, list4;
  604. list<string>::iterator it_list1, it_list2, it_list3, it_list4;
  605. sprintf(strSQLText, "select starttime, endtime, startweekofday, endweekofday " \
  606. "from t_plan_info where planid=\'%s\' and plantype = %d",
  607. pPlanID, nPlanType);
  608. int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList4(strSQLText, list1, list2, list3, list4);
  609. if( list1.size() == 0 || list2.size() == 0 || list3.size() == 0 || list4.size() == 0 )
  610. {
  611. return 0;
  612. }
  613. if( nRet != -1 )
  614. {
  615. for( it_list1 = list1.begin(), it_list2 = list2.begin(), it_list3 = list3.begin(), it_list4 = list4.begin();
  616. it_list1 != list1.end() && it_list2 != list2.end() && it_list3 != list3.end() && it_list4 != list4.end();
  617. it_list1++, it_list2++, it_list3++, it_list4++)
  618. {
  619. for( int i = atoi((*it_list3).c_str()); i < atoi((*it_list4).c_str()) + 1; i++ )
  620. {
  621. for( int j = atoi((*it_list1).c_str()); j < atoi((*it_list2).c_str()) + 1; j++ )
  622. {
  623. nBufDate[i][j] = 15;
  624. }
  625. }
  626. }
  627. }
  628. for( it_list1 = list1.begin(), it_list2 = list2.begin(), it_list3 = list3.begin(), it_list4 = list4.begin();
  629. it_list1 != list1.end(), it_list2 != list2.end(), it_list3 != list3.end(), it_list4 != list4.end(); )
  630. {
  631. list1.erase(it_list1++);
  632. list2.erase(it_list2++);
  633. list3.erase(it_list3++);
  634. list4.erase(it_list4++);
  635. }
  636. return nRet;
  637. }
  638. //得到时间计划
  639. INT CDBInterface::GetDatePlan( int nPlanType, CHAR *pUid, int nVarID, unsigned char nBufDate[7][24] )
  640. {
  641. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  642. list<string> list1, list2, list3, list4;
  643. list<string>::iterator it_list1, it_list2, it_list3, it_list4;
  644. sprintf(strSQLText, "select starttime, endtime, startweekofday, endweekofday " \
  645. "from t_plan_info where uid=\'%s\' and varid = %d and plantype = %d",
  646. pUid, nVarID, nPlanType);
  647. int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList4(strSQLText, list1, list2, list3, list4);
  648. if( list1.size() == 0 || list2.size() == 0 || list3.size() == 0 || list4.size() == 0 )
  649. {
  650. return 0;
  651. }
  652. if( nRet != -1 )
  653. {
  654. for( it_list1 = list1.begin(), it_list2 = list2.begin(), it_list3 = list3.begin(), it_list4 = list4.begin();
  655. it_list1 != list1.end() && it_list2 != list2.end() && it_list3 != list3.end() && it_list4 != list4.end();
  656. it_list1++, it_list2++, it_list3++, it_list4++ )
  657. {
  658. for( int i = atoi((*it_list3).c_str()); i < atoi((*it_list4).c_str()) + 1; i++ )
  659. {
  660. for( int j = atoi((*it_list1).c_str()); j < atoi((*it_list2).c_str()) + 1; j++ )
  661. {
  662. nBufDate[i][j] = 15;
  663. }
  664. }
  665. }
  666. }
  667. for( it_list1 = list1.begin(), it_list2 = list2.begin(), it_list3 = list3.begin(), it_list4 = list4.begin();
  668. it_list1 != list1.end(), it_list2 != list2.end(), it_list3 != list3.end(), it_list4 != list4.end(); )
  669. {
  670. list1.erase(it_list1++);
  671. list2.erase(it_list2++);
  672. list3.erase(it_list3++);
  673. list4.erase(it_list4++);
  674. }
  675. return nRet;
  676. }
  677. //删除原有的时间计划
  678. INT CDBInterface::DeleteDatePlan( int nPlanType, CHAR *pPlanID )
  679. {
  680. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  681. sprintf(strSQLText, "delete from t_plan_info where planid = \'%s\' and plantype=%d",pPlanID, nPlanType);
  682. return CDBConnection::GetInstancePtr()->Execute(strSQLText);
  683. }
  684. //删除原有的时间计划
  685. INT CDBInterface::DeleteDatePlan( int nPlanType, CString strUid, int nVarID )
  686. {
  687. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  688. sprintf(strSQLText, "delete from t_plan_info where uid = \'%s\' and varid = %d and plantype=%d", strUid, nVarID, nPlanType);
  689. return CDBConnection::GetInstancePtr()->Execute(strSQLText);
  690. }
  691. //插入时间计划
  692. INT CDBInterface::InsertDatePlan( int nPlanType, CHAR *pPlanID, int nStartHours, int nEndHours, int nStartWeek, int nEndWeek )
  693. {
  694. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  695. sprintf(strSQLText, "insert into t_plan_info(plantype, planid, starttime, endtime, " \
  696. "startweekofday, endweekofday) values (%d, \'%s\', %d, %d, %d, %d) ",
  697. nPlanType, pPlanID, nStartHours, nEndHours, nStartWeek, nEndWeek);
  698. return CDBConnection::GetInstancePtr()->Execute(strSQLText);
  699. }
  700. //插入时间计划
  701. INT CDBInterface::InsertDatePlan( int nPlanType, CString strUid, int nVarID, int nStartHours, int nEndHours, int nStartWeek, int nEndWeek )
  702. {
  703. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  704. sprintf(strSQLText, "insert into t_plan_info(plantype, uid, varid, starttime, endtime, " \
  705. "startweekofday, endweekofday) values (%d, \'%s\', %d, %d, %d, %d, %d) ",
  706. nPlanType, strUid, nVarID, nStartHours, nEndHours, nStartWeek, nEndWeek);
  707. return CDBConnection::GetInstancePtr()->Execute(strSQLText);
  708. }
  709. //获取系统支持所有的驱动类型
  710. INT CDBInterface::GetDevDriveList( list<string>& list1, list<string>& list2 )
  711. {
  712. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  713. sprintf(strSQLText, "select id, drivename from t_dev_drive");
  714. int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList2(strSQLText, list1, list2);
  715. return nRet;
  716. }
  717. //获取指定驱动的厂家资料
  718. INT CDBInterface::GetDevFactoryList( int nDriverID, list<string>& list1, list<string>& list2 )
  719. {
  720. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  721. sprintf(strSQLText, "select factoryid, factoryname from t_dev_factory where deviceid = %d", nDriverID);
  722. int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList2(strSQLText, list1, list2);
  723. return nRet;
  724. }
  725. //获取指定厂家的设备型号列表
  726. INT CDBInterface::GetDevTypeList( int nDriverID, int nFactoryID, list<string>& list1, list<string>& list2 )
  727. {
  728. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  729. sprintf(strSQLText, "select id, equiptype from t_dev_type where driveid = %d and factoryid = %d", nDriverID, nFactoryID);
  730. int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList2(strSQLText, list1, list2);
  731. return nRet;
  732. }
  733. //获取变量状态列表
  734. INT CDBInterface::GetVarStatusList( CHAR *pVarUID, int nVarID, list<string>& list1, list<string>& list2 )
  735. {
  736. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  737. sprintf(strSQLText, "select statusid, statusdesc from t_var_status where devuid = \'%s\' " \
  738. "and varid = %d ", pVarUID, nVarID);
  739. int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList2(strSQLText, list1, list2);
  740. return nRet;
  741. }
  742. //设置变量bit位的ID
  743. INT CDBInterface::SetVarBitID( CHAR *pVarUID, int nStartBit, int nEndBit, int &nBitID )
  744. {
  745. CHAR szVarBitID[MAX_ID] = {0};
  746. if( 0!=GetVarBitID( pVarUID,nStartBit,nEndBit,szVarBitID ) )
  747. {
  748. nBitID = atoi( szVarBitID );
  749. return 1;
  750. }
  751. else
  752. {
  753. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  754. int nID = 0;
  755. CHAR szMaxID[MAX_ID] = {0};
  756. GetMaxID("t_dev_variant_item", "id", szMaxID);
  757. nID = atoi( szMaxID )+1;
  758. sprintf(strSQLText, "insert into t_dev_variant_item(id, uid, startbit, endbit) values (%d, \'%s\', %d, %d) ",
  759. nID, pVarUID, nStartBit, nEndBit );
  760. nBitID = nID;
  761. return CDBConnection::GetInstancePtr()->Execute(strSQLText);
  762. }
  763. return 1;
  764. }
  765. //获取变量bit位的ID
  766. INT CDBInterface::GetVarBitID( CHAR *pVarUID, int nStartBit, int nEndBit, CHAR *pVarBitID )
  767. {
  768. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  769. list<string> list1;
  770. list<string>::iterator it;
  771. if (!_stricmp(m_chDBType, "SQL SERVER"))
  772. {
  773. sprintf(strSQLText, "select top 1 id from t_dev_variant_item where uid = \'%s\' " \
  774. "and startbit = %d and endbit = %d", pVarUID, nStartBit, nEndBit);
  775. }
  776. else if (!_stricmp(m_chDBType, "ACCESS97"))
  777. {
  778. sprintf(strSQLText, "select top 1 id from t_dev_variant_item where uid = \'%s\' " \
  779. "and startbit = %d and endbit = %d", pVarUID, nStartBit, nEndBit);
  780. }
  781. else if (!_stricmp(m_chDBType, "ACCESS2000"))
  782. {
  783. sprintf(strSQLText, "select top 1 id from t_dev_variant_item where uid = \'%s\' " \
  784. "and startbit = %d and endbit = %d", pVarUID, nStartBit, nEndBit);
  785. }
  786. else if(!_stricmp(m_chDBType, "PGSQL"))
  787. {
  788. sprintf(strSQLText, "select id from t_dev_variant_item where uid = \'%s\' " \
  789. "and startbit = %d and endbit = %d limit 1", pVarUID, nStartBit, nEndBit);
  790. }
  791. int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList1(strSQLText, list1);
  792. if( 0 == list1.size() )
  793. {
  794. return 0;
  795. }
  796. if( nRet != -1 )
  797. {
  798. strcpy(pVarBitID, list1.begin()->c_str());
  799. }
  800. for( it = list1.begin(); it != list1.end(); )
  801. {
  802. list1.erase(it++);
  803. }
  804. return nRet;
  805. }
  806. //获取变量类型
  807. INT CDBInterface::GetVarTypeName( int nVarTypeID, CHAR *pVarTypeName )
  808. {
  809. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  810. list<string> list1;
  811. list<string>::iterator it;
  812. if (!_stricmp(m_chDBType, "SQL SERVER"))
  813. {
  814. sprintf(strSQLText, "select top 1 vartype from t_var_type where id = %d", nVarTypeID);
  815. }
  816. else if (!_stricmp(m_chDBType, "ACCESS97"))
  817. {
  818. sprintf(strSQLText, "select top 1 vartype from t_var_type where id = %d", nVarTypeID);
  819. }
  820. else if (!_stricmp(m_chDBType, "ACCESS2000"))
  821. {
  822. sprintf(strSQLText, "select top 1 vartype from t_var_type where id = %d", nVarTypeID);
  823. }
  824. else if(!_stricmp(m_chDBType, "PGSQL"))
  825. {
  826. sprintf(strSQLText, "select vartype from t_var_type where id = %d LIMIT 1", nVarTypeID);
  827. }
  828. int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList1(strSQLText, list1);
  829. if( 0 == list1.size() )
  830. {
  831. return 0;
  832. }
  833. if( nRet != -1 )
  834. {
  835. strcpy(pVarTypeName, list1.begin()->c_str());
  836. }
  837. for( it = list1.begin(); it != list1.end(); )
  838. {
  839. list1.erase(it++);
  840. }
  841. return nRet;
  842. }
  843. //获取功能码
  844. INT CDBInterface::GetFuncCodeName( int nFuncID, CHAR *pFuncName )
  845. {
  846. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  847. list<string> list1;
  848. list<string>::iterator it;
  849. if (!_stricmp(m_chDBType, "SQL SERVER"))
  850. {
  851. sprintf(strSQLText, "select top 1 funcname from t_dev_func_code where id = %d", nFuncID);
  852. }
  853. else if (!_stricmp(m_chDBType, "ACCESS97"))
  854. {
  855. sprintf(strSQLText, "select top 1 funcname from t_dev_func_code where id = %d", nFuncID);
  856. }
  857. else if (!_stricmp(m_chDBType, "ACCESS2000"))
  858. {
  859. sprintf(strSQLText, "select top 1 funcname from t_dev_func_code where id = %d", nFuncID);
  860. }
  861. else if(!_stricmp(m_chDBType, "PGSQL"))
  862. {
  863. sprintf(strSQLText, "select funcname from t_dev_func_code where id = %d LIMIT 1", nFuncID);
  864. }
  865. int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList1(strSQLText, list1);
  866. if( 0 == list1.size() )
  867. {
  868. return 0;
  869. }
  870. if( nRet != -1 )
  871. {
  872. strcpy(pFuncName, list1.begin()->c_str());
  873. }
  874. for( it = list1.begin(); it != list1.end(); )
  875. {
  876. list1.erase(it++);
  877. }
  878. return nRet;
  879. }
  880. //获取变量ID
  881. INT CDBInterface::GetVarID( CHAR *pVarName, CHAR *pVarID )
  882. {
  883. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  884. list<string> list1;
  885. list<string>::iterator it;
  886. if (!_stricmp(m_chDBType, "SQL SERVER"))
  887. {
  888. sprintf(strSQLText, "select top 1 id from t_dev_variant where varname = \'%s\'", pVarName);
  889. }
  890. else if (!_stricmp(m_chDBType, "ACCESS97"))
  891. {
  892. sprintf(strSQLText, "select top 1 id from t_dev_variant where varname = \'%s\'", pVarName);
  893. }
  894. else if (!_stricmp(m_chDBType, "ACCESS2000"))
  895. {
  896. sprintf(strSQLText, "select top 1 id from t_dev_variant where varname = \'%s\'", pVarName);
  897. }
  898. else if(!_stricmp(m_chDBType, "PGSQL"))
  899. {
  900. sprintf(strSQLText, "select id from t_dev_variant where varname = \'%s\' limit 1", pVarName);
  901. }
  902. int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList1(strSQLText, list1);
  903. if( 0 == list1.size() )
  904. {
  905. return 0;
  906. }
  907. if( nRet != -1 )
  908. {
  909. strcpy(pVarID, list1.begin()->c_str());
  910. }
  911. for( it = list1.begin(); it != list1.end(); )
  912. {
  913. list1.erase(it++);
  914. }
  915. return nRet;
  916. }
  917. //获取变量ID
  918. INT CDBInterface::GetVarID( int nStartAddr, int nFuncCode, int nRegNum, CHAR *pVarID )
  919. {
  920. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  921. list<string> list1;
  922. list<string>::iterator it;
  923. if (!_stricmp(m_chDBType, "SQL SERVER"))
  924. {
  925. sprintf(strSQLText, "select top 1 id from t_dev_variant where address = %d and funcid = %d and registernum limit 1",
  926. nStartAddr, nFuncCode, nRegNum);
  927. }
  928. else if (!_stricmp(m_chDBType, "ACCESS97"))
  929. {
  930. sprintf(strSQLText, "select top 1 id from t_dev_variant where address = %d and funcid = %d and registernum limit 1",
  931. nStartAddr, nFuncCode, nRegNum);
  932. }
  933. else if (!_stricmp(m_chDBType, "ACCESS2000"))
  934. {
  935. sprintf(strSQLText, "select top 1 id from t_dev_variant where address = %d and funcid = %d and registernum limit 1",
  936. nStartAddr, nFuncCode, nRegNum);
  937. }
  938. else if(!_stricmp(m_chDBType, "PGSQL"))
  939. {
  940. sprintf(strSQLText, "select id from t_dev_variant where address = %d and funcid = %d and registernum limit 1",
  941. nStartAddr, nFuncCode, nRegNum);
  942. }
  943. int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList1(strSQLText, list1);
  944. if( 0 == list1.size() )
  945. {
  946. return 0;
  947. }
  948. if( nRet != -1 )
  949. {
  950. strcpy(pVarID, list1.begin()->c_str());
  951. }
  952. for( it = list1.begin(); it != list1.end(); )
  953. {
  954. list1.erase(it++);
  955. }
  956. return nRet;
  957. }
  958. //获取变量类型ID
  959. INT CDBInterface::GetVarTypeID( CHAR *pVarTypeName, CHAR *pVarTypeID )
  960. {
  961. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  962. list<string> list1;
  963. list<string>::iterator it;
  964. if (!_stricmp(m_chDBType, "SQL SERVER"))
  965. {
  966. sprintf(strSQLText, "select top 1 id from t_var_type where vartype = \'%s\'", pVarTypeName);
  967. }
  968. else if (!_stricmp(m_chDBType, "ACCESS97"))
  969. {
  970. sprintf(strSQLText, "select top 1 id from t_var_type where vartype = \'%s\'", pVarTypeName);
  971. }
  972. else if (!_stricmp(m_chDBType, "ACCESS2000"))
  973. {
  974. sprintf(strSQLText, "select top 1 id from t_var_type where vartype = \'%s\'", pVarTypeName);
  975. }
  976. else if(!_stricmp(m_chDBType, "PGSQL"))
  977. {
  978. sprintf(strSQLText, "select id from t_var_type where vartype = \'%s\' LIMIT 1", pVarTypeName);
  979. }
  980. int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList1(strSQLText, list1);
  981. if( 0 == list1.size() )
  982. {
  983. return 0;
  984. }
  985. if( nRet != -1 )
  986. {
  987. strcpy(pVarTypeID, list1.begin()->c_str());
  988. }
  989. for( it = list1.begin(); it != list1.end(); )
  990. {
  991. list1.erase(it++);
  992. }
  993. return nRet;
  994. }
  995. //获取功能码ID
  996. INT CDBInterface::GetFuncCodeID( CHAR *pFuncName, CHAR *pFuncID )
  997. {
  998. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  999. list<string> list1;
  1000. list<string>::iterator it;
  1001. if (!_stricmp(m_chDBType, "SQL SERVER"))
  1002. {
  1003. sprintf(strSQLText, "select top 1 id from t_dev_func_code where funcname = \'%s\'", pFuncName);
  1004. }
  1005. else if (!_stricmp(m_chDBType, "ACCESS97"))
  1006. {
  1007. sprintf(strSQLText, "select top 1 id from t_dev_func_code where funcname = \'%s\'", pFuncName);
  1008. }
  1009. else if (!_stricmp(m_chDBType, "ACCESS2000"))
  1010. {
  1011. sprintf(strSQLText, "select top 1 id from t_dev_func_code where funcname = \'%s\'", pFuncName);
  1012. }
  1013. else if(!_stricmp(m_chDBType, "PGSQL"))
  1014. {
  1015. sprintf(strSQLText, "select id from t_dev_func_code where funcname = \'%s\' LIMIT 1", pFuncName);
  1016. }
  1017. int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList1(strSQLText, list1);
  1018. if( 0 == list1.size() )
  1019. {
  1020. return 0;
  1021. }
  1022. if( nRet != -1 )
  1023. {
  1024. strcpy(pFuncID, list1.begin()->c_str());
  1025. }
  1026. for( it = list1.begin(); it != list1.end(); )
  1027. {
  1028. list1.erase(it++);
  1029. }
  1030. return nRet;
  1031. }
  1032. //获取设备名称
  1033. INT CDBInterface::GetDevInfo( CHAR *pDevUID, CHAR *pDllName, CHAR *pIniName, CHAR *pDevProtocolType )
  1034. {
  1035. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  1036. list<string> list1, list2, list3;
  1037. list<string>::iterator it1, it2, it3;
  1038. if (!_stricmp(m_chDBType, "SQL SERVER"))
  1039. {
  1040. sprintf(strSQLText, "select top 1 protocoldllname, specialdevice, ininame from t_dev_property where uid = \'%s\'", pDevUID);
  1041. }
  1042. else if (!_stricmp(m_chDBType, "ACCESS97"))
  1043. {
  1044. sprintf(strSQLText, "select top 1 protocoldllname, specialdevice, ininame from t_dev_property where uid = \'%s\'", pDevUID);
  1045. }
  1046. else if (!_stricmp(m_chDBType, "ACCESS2000"))
  1047. {
  1048. sprintf(strSQLText, "select top 1 protocoldllname, specialdevice, ininame from t_dev_property where uid = \'%s\'", pDevUID);
  1049. }
  1050. else if(!_stricmp(m_chDBType, "PGSQL"))
  1051. {
  1052. sprintf(strSQLText, "select protocoldllname, specialdevice, ininame from t_dev_property where uid = \'%s\' LIMIT 1", pDevUID);
  1053. }
  1054. int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList3(strSQLText, list1, list2, list3);
  1055. if( 0 == list1.size() || 0 == list2.size() || 0 == list3.size() )
  1056. {
  1057. return 0;
  1058. }
  1059. if( nRet != -1 )
  1060. {
  1061. strcpy(pDllName, list1.begin()->c_str());
  1062. strcpy(pDevProtocolType, list2.begin()->c_str());
  1063. strcpy(pIniName, list3.begin()->c_str());
  1064. }
  1065. for( it1 = list1.begin(), it2 = list2.begin(), it3 = list3.begin();
  1066. it1 != list1.end(), it2 != list2.end(), it3 != list3.end(); )
  1067. {
  1068. list1.erase(it1++);
  1069. list2.erase(it2++);
  1070. list3.erase(it3++);
  1071. }
  1072. return nRet;
  1073. }
  1074. //修改密码
  1075. INT CDBInterface::ModifyPwd(CHAR *pUserID, CHAR *pUserPwd)
  1076. {
  1077. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  1078. sprintf(strSQLText, "UPDATE t_user_info SET pwd=\'%s\' where uid=\'%s\'",
  1079. pUserPwd, pUserID);
  1080. return CDBConnection::GetInstancePtr()->Execute(strSQLText);
  1081. }
  1082. //验证用户名、密码是否合法
  1083. INT CDBInterface::ValidateUser(CHAR *pUserID, CHAR *pUserPwd)
  1084. {
  1085. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  1086. list<string> list1;
  1087. list<string>::iterator it;
  1088. if (!_stricmp(m_chDBType, "SQL SERVER"))
  1089. {
  1090. sprintf(strSQLText, "select top 1 1 from t_user_info where uid = \'%s\' and pwd = \'%s\'", pUserID, pUserPwd);
  1091. }
  1092. else if (!_stricmp(m_chDBType, "ACCESS97"))
  1093. {
  1094. sprintf(strSQLText, "select top 1 1 from t_user_info where uid = \'%s\' and pwd = \'%s\'", pUserID, pUserPwd);
  1095. }
  1096. else if (!_stricmp(m_chDBType, "ACCESS2000"))
  1097. {
  1098. sprintf(strSQLText, "select top 1 1 from t_user_info where uid = \'%s\' and pwd = \'%s\'", pUserID, pUserPwd);
  1099. }
  1100. else if(!_stricmp(m_chDBType, "PGSQL"))
  1101. {
  1102. sprintf(strSQLText, "select id from t_user_info where uid = \'%s\' and pwd = \'%s\' LIMIT 1", pUserID, pUserPwd);
  1103. }
  1104. int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList1(strSQLText, list1);
  1105. //LOG4C((LOG_NOTICE, "ValidateUser GetFieldValueList1 return %d", nRet));
  1106. if( 0 == list1.size() )
  1107. {
  1108. return 0;
  1109. }
  1110. for( it = list1.begin(); it != list1.end(); )
  1111. {
  1112. list1.erase(it++);
  1113. }
  1114. return nRet;
  1115. }
  1116. //验证用户是否启用
  1117. INT CDBInterface::ValidateUserEnable(CHAR *pUserID, CHAR *pStatus)
  1118. {
  1119. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  1120. list<string> list1;
  1121. list<string>::iterator it;
  1122. if (!_stricmp(m_chDBType, "SQL SERVER"))
  1123. {
  1124. sprintf(strSQLText, "select top 1 status from t_user_info where uid = \'%s\'", pUserID);
  1125. }
  1126. else if (!_stricmp(m_chDBType, "ACCESS97"))
  1127. {
  1128. sprintf(strSQLText, "select top 1 status from t_user_info where uid = \'%s\'", pUserID);
  1129. }
  1130. else if (!_stricmp(m_chDBType, "ACCESS2000"))
  1131. {
  1132. sprintf(strSQLText, "select top 1 status from t_user_info where uid = \'%s\'", pUserID);
  1133. }
  1134. else if(!_stricmp(m_chDBType, "PGSQL"))
  1135. {
  1136. sprintf(strSQLText, "select status from t_user_info where uid = \'%s\' limit 1", pUserID);
  1137. }
  1138. int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList1(strSQLText, list1);
  1139. if( 0 == list1.size() )
  1140. {
  1141. return 0;
  1142. }
  1143. if( nRet != -1 )
  1144. {
  1145. strcpy(pStatus, list1.begin()->c_str());
  1146. }
  1147. for( it = list1.begin(); it != list1.end(); )
  1148. {
  1149. list1.erase(it++);
  1150. }
  1151. return nRet;
  1152. }
  1153. //得到用户信息ID
  1154. INT CDBInterface::GetUserID( CHAR *pID, CHAR *pUserID )
  1155. {
  1156. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  1157. list<string> list1;
  1158. list<string>::iterator it;
  1159. if (!_stricmp(m_chDBType, "SQL SERVER"))
  1160. {
  1161. sprintf(strSQLText, "select top 1 id from t_user_info where uid = \'%s\'", pUserID);
  1162. }
  1163. else if (!_stricmp(m_chDBType, "ACCESS97"))
  1164. {
  1165. sprintf(strSQLText, "select top 1 id from t_user_info where uid = \'%s\'", pUserID);
  1166. }
  1167. else if (!_stricmp(m_chDBType, "ACCESS2000"))
  1168. {
  1169. sprintf(strSQLText, "select top 1 id from t_user_info where uid = \'%s\'", pUserID);
  1170. }
  1171. else if(!_stricmp(m_chDBType, "PGSQL"))
  1172. {
  1173. sprintf(strSQLText, "select id from t_user_info where uid = \'%s\' limit 1", pUserID);
  1174. }
  1175. int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList1(strSQLText, list1);
  1176. if( 0 == list1.size() )
  1177. {
  1178. return 0;
  1179. }
  1180. if( nRet != -1 )
  1181. {
  1182. strcpy(pUserID, list1.begin()->c_str());
  1183. }
  1184. for( it = list1.begin(); it != list1.end(); )
  1185. {
  1186. list1.erase(it++);
  1187. }
  1188. return nRet;
  1189. }
  1190. // 判断用户是否管理设备权限
  1191. INT CDBInterface::HasDevAlloc( int iGroupID, CHAR *pUid )
  1192. {
  1193. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  1194. list<string> list1;
  1195. list<string>::iterator it;
  1196. if (!_stricmp(m_chDBType, "SQL SERVER"))
  1197. {
  1198. sprintf(strSQLText, "select top 1 uid from t_role_equip where group_id = %d " \
  1199. " and uid = \'%s\' ", iGroupID, pUid);
  1200. }
  1201. else if (!_stricmp(m_chDBType, "ACCESS97"))
  1202. {
  1203. sprintf(strSQLText, "select top 1 uid from t_role_equip where group_id = %d " \
  1204. " and uid = \'%s\' ", iGroupID, pUid);
  1205. }
  1206. else if (!_stricmp(m_chDBType, "ACCESS2000"))
  1207. {
  1208. sprintf(strSQLText, "select top 1 uid from t_role_equip where group_id = %d " \
  1209. " and uid = \'%s\' ", iGroupID, pUid);
  1210. }
  1211. else if(!_stricmp(m_chDBType, "PGSQL"))
  1212. {
  1213. sprintf(strSQLText, "select uid from t_role_equip where group_id = %d " \
  1214. " and uid = \'%s\' limit 1", iGroupID, pUid);
  1215. }
  1216. int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList1(strSQLText, list1);
  1217. if( 0 == list1.size() )
  1218. {
  1219. return 0;
  1220. }
  1221. for( it = list1.begin(); it != list1.end(); )
  1222. {
  1223. list1.erase(it++);
  1224. }
  1225. return nRet;
  1226. }
  1227. //删除设备权限信息
  1228. INT CDBInterface::DelUserDevInfo( int iGroupID )
  1229. {
  1230. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  1231. sprintf(strSQLText, "delete from t_role_equip where group_id = %d", iGroupID);
  1232. return CDBConnection::GetInstancePtr()->Execute(strSQLText);
  1233. }
  1234. //添加设备权限信息
  1235. INT CDBInterface::AddUserDevInfo(int nID, int iGroupID, CHAR *pUid)
  1236. {
  1237. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  1238. sprintf(strSQLText, "insert into t_role_equip(id, group_id, uid) values (%d, " \
  1239. "%d, \'%s\')", nID, iGroupID, pUid);
  1240. return CDBConnection::GetInstancePtr()->Execute(strSQLText);
  1241. }
  1242. //获取变量状态表ID
  1243. INT CDBInterface::GetVarStatusID( CHAR *pVarUID, int nVarID, int nStatusID, CHAR *pStatusDesc, CHAR *pID )
  1244. {
  1245. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  1246. list<string> list1;
  1247. list<string>::iterator it;
  1248. if (!_stricmp(m_chDBType, "SQL SERVER"))
  1249. {
  1250. sprintf(strSQLText, "select top 1 id from t_var_status where devuid = \'%s\' " \
  1251. "and varid = %d and statusid = %d and statusdesc = \'%s\'",
  1252. pVarUID, nVarID, nStatusID, pStatusDesc);
  1253. }
  1254. else if (!_stricmp(m_chDBType, "ACCESS97"))
  1255. {
  1256. sprintf(strSQLText, "select top 1 id from t_var_status where devuid = \'%s\' " \
  1257. "and varid = %d and statusid = %d and statusdesc = \'%s\'",
  1258. pVarUID, nVarID, nStatusID, pStatusDesc);
  1259. }
  1260. else if (!_stricmp(m_chDBType, "ACCESS2000"))
  1261. {
  1262. sprintf(strSQLText, "select top 1 id from t_var_status where devuid = \'%s\' " \
  1263. "and varid = %d and statusid = %d and statusdesc = \'%s\'",
  1264. pVarUID, nVarID, nStatusID, pStatusDesc);
  1265. }
  1266. else if(!_stricmp(m_chDBType, "PGSQL"))
  1267. {
  1268. sprintf(strSQLText, "select id from t_var_status where devuid = \'%s\' " \
  1269. "and varid = %d and statusid = %d and statusdesc = \'%s\' limit 1",
  1270. pVarUID, nVarID, nStatusID, pStatusDesc);
  1271. }
  1272. int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList1(strSQLText, list1);
  1273. if( 0 == list1.size() )
  1274. {
  1275. return 0;
  1276. }
  1277. if( nRet != -1 )
  1278. {
  1279. strcpy(pID, list1.begin()->c_str());
  1280. }
  1281. for( it = list1.begin(); it != list1.end(); )
  1282. {
  1283. list1.erase(it++);
  1284. }
  1285. return nRet;
  1286. }
  1287. //设置变量状态表ID
  1288. INT CDBInterface::SetVarStatusID( CHAR *pVarUID, int nVarID, int nStatusID, CHAR *pStatusDesc )
  1289. {
  1290. CHAR szID[MAX_ID] = {0};
  1291. if( 0!=GetVarStatusID( pVarUID,nVarID,nStatusID,pStatusDesc,szID ) )
  1292. {
  1293. return 1;
  1294. }
  1295. else
  1296. {
  1297. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  1298. int nID = 0;
  1299. CHAR szMaxID[MAX_ID] = {0};
  1300. GetMaxID("t_var_status", "id", szMaxID);
  1301. nID = atoi( szMaxID )+1;
  1302. sprintf(strSQLText, "insert into t_var_status(id, devuid, varid, statusid,statusdesc) values (%d, \'%s\', %d, %d,\'%s\') ",
  1303. nID, pVarUID, nVarID, nStatusID,pStatusDesc );
  1304. return CDBConnection::GetInstancePtr()->Execute(strSQLText);
  1305. }
  1306. }
  1307. INT CDBInterface::AddGroupToDll()
  1308. {
  1309. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  1310. list<string> list1, list2, list3;
  1311. list<string>::iterator it_list1, it_list2, it_list3;
  1312. int nGroupID = 0;
  1313. CString strName,str,strDesc,strPermitName;
  1314. int nPermitID=0;
  1315. if(!_stricmp(g_strDBType, "PGSQL"))
  1316. {
  1317. sprintf(strSQLText, "select id, groupname, groupdesc from t_user_group");
  1318. }
  1319. else
  1320. {
  1321. sprintf(strSQLText, "select id, groupname, groupdesc from t_user_group");
  1322. }
  1323. int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList3(strSQLText, list1, list2, list3);
  1324. if( 0 == list1.size() || 0 == list2.size() || 0 == list3.size() )
  1325. {
  1326. return 0;
  1327. }
  1328. if( nRet != -1 )
  1329. {
  1330. for( it_list1 = list1.begin(), it_list2 = list2.begin(), it_list3 = list3.begin();
  1331. it_list1 != list1.end() && it_list2 != list2.end() && it_list3 != list3.end();
  1332. it_list1++, it_list2++, it_list3++)
  1333. {
  1334. nGroupID = atoi((*it_list1).c_str());
  1335. strName = (*it_list2).c_str();
  1336. strDesc = (*it_list3).c_str();
  1337. PMS_AddGroup(strName, nGroupID);
  1338. int nS=0,nE=0;
  1339. for( int i=0;i<strDesc.GetLength();i++ )
  1340. {
  1341. if( strDesc[i]=='-' )
  1342. {
  1343. nE = i;
  1344. str = strDesc.Mid( nS,nE-nS );
  1345. nS = nE+1;
  1346. nPermitID = atoi(str);
  1347. GetPermitNameByID( strPermitName,nPermitID );
  1348. PMS_AddPermitToGroup( strPermitName,nPermitID,nGroupID );
  1349. }
  1350. }
  1351. str = strDesc.Mid( nS,strDesc.GetLength()-nS );
  1352. nPermitID = atoi(str);
  1353. GetPermitNameByID( strPermitName,nPermitID );
  1354. PMS_AddPermitToGroup( strPermitName,nPermitID,nGroupID );
  1355. }
  1356. }
  1357. for( it_list1 = list1.begin(), it_list2 = list2.begin(), it_list3 = list3.begin();
  1358. it_list1 != list1.end(), it_list2 != list2.end(), it_list3 != list3.end(); )
  1359. {
  1360. list1.erase(it_list1++);
  1361. list2.erase(it_list2++);
  1362. list3.erase(it_list3++);
  1363. }
  1364. return 0;
  1365. }
  1366. INT CDBInterface::GetAllGroupToTree( CTreeCtrl *pTreeCtrl,HTREEITEM hRoot )
  1367. {
  1368. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  1369. list<string> list1;
  1370. list<string>::iterator it_list1;
  1371. CString strName;
  1372. if(!_stricmp(g_strDBType, "PGSQL"))
  1373. {
  1374. sprintf(strSQLText, "select groupname from t_user_group order by id");
  1375. }
  1376. else
  1377. {
  1378. sprintf(strSQLText, "select groupname from t_user_group order by id");
  1379. }
  1380. int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList1(strSQLText, list1);
  1381. if( 0 == list1.size() )
  1382. {
  1383. return 0;
  1384. }
  1385. if( nRet != -1 )
  1386. {
  1387. for( it_list1 = list1.begin(); it_list1 != list1.end(); it_list1++ )
  1388. {
  1389. strName = (*it_list1).c_str();
  1390. strName = strName.Trim();
  1391. CString s;
  1392. s.Format( "%s",g_strLoginUserID );
  1393. if( strName.Compare("管理员" ) )//|| s=="admin" )
  1394. pTreeCtrl->InsertItem(strName,5,5,hRoot);
  1395. }
  1396. }
  1397. for( it_list1 = list1.begin(); it_list1 != list1.end(); )
  1398. {
  1399. list1.erase(it_list1++);
  1400. }
  1401. return nRet;
  1402. }
  1403. INT CDBInterface::AddGroup(int iID, CString sGroupName, CString sGroupDesc)
  1404. {
  1405. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  1406. sprintf(strSQLText, "insert into t_user_group(id, groupname,groupdesc) values (" \
  1407. "%d, \'%s\', \'%s\')",
  1408. iID, sGroupName,sGroupDesc);
  1409. return CDBConnection::GetInstancePtr()->Execute(strSQLText);
  1410. }
  1411. INT CDBInterface::ModifyGroup(CString sGroupName, CString sGroupDesc)
  1412. {
  1413. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  1414. sprintf(strSQLText, "UPDATE t_user_group SET groupdesc=\'%s\' where groupname=\'%s\' ",
  1415. sGroupDesc, sGroupName);
  1416. return CDBConnection::GetInstancePtr()->Execute(strSQLText);
  1417. }
  1418. INT CDBInterface::DelGroup(int iGroupID)
  1419. {
  1420. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  1421. sprintf(strSQLText, "delete from t_user_group where id=%d",iGroupID);
  1422. return CDBConnection::GetInstancePtr()->Execute(strSQLText);
  1423. }
  1424. //添加用户所属组信息
  1425. INT CDBInterface::AddUserToGroup(int iID, CHAR * pUserID, int iGroupID, CHAR *pUserName)
  1426. {
  1427. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  1428. sprintf(strSQLText, "insert into t_role_user(id, userid, group_id,roledesc) values (%d, " \
  1429. " \'%s\', %d, \'%s\')", iID, pUserID, iGroupID,pUserName);
  1430. return CDBConnection::GetInstancePtr()->Execute(strSQLText);
  1431. }
  1432. //刪除用戶所屬組
  1433. INT CDBInterface::DeleteUserGroup(CHAR * pUserID, int iGroupID )
  1434. {
  1435. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  1436. sprintf(strSQLText, "delete from t_role_user where userid=\'%s\' ", pUserID);
  1437. return CDBConnection::GetInstancePtr()->Execute(strSQLText);
  1438. }
  1439. //刪除組的用戶
  1440. INT CDBInterface::DeleteGroupUser( int iGroupID )
  1441. {
  1442. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  1443. sprintf(strSQLText, "delete from t_role_user where group_id=%d ", iGroupID);
  1444. return CDBConnection::GetInstancePtr()->Execute(strSQLText);
  1445. }
  1446. // 插入日志记录
  1447. INT CDBInterface::InsertLogRecord( int LogType, int ModuleType, CHAR *pHappenTime, CHAR *pContent )
  1448. {
  1449. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  1450. int nID = 0;
  1451. CHAR szMaxID[MAX_ID] = {0};
  1452. GetMaxID("t_sys_log", "id", szMaxID);
  1453. nID = atoi( szMaxID )+1;
  1454. CString sTime,sContent;
  1455. SYSTEMTIME systime;
  1456. GetLocalTime( &systime );
  1457. sTime.Format( "%d-%02d-%02d %02d:%02d:%02d",systime.wYear,systime.wMonth,systime.wDay,systime.wHour,systime.wMinute,systime.wSecond );
  1458. sprintf(strSQLText, "insert into t_sys_log(LogType, ModuleType, HappenTime, Contents, id) values (" \
  1459. "%d, %d, \'%s\', \'%s\',%d)",
  1460. LogType, ModuleType, sTime, pContent,nID );
  1461. return CDBConnection::GetInstancePtr()->Execute(strSQLText);
  1462. }
  1463. //得到組的ID通過組名稱
  1464. INT CDBInterface::GetGroupIDByName( CString sGroupName,int &iGroupID )
  1465. {
  1466. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  1467. list<string> list1;
  1468. list<string>::iterator it;
  1469. if (!_stricmp(m_chDBType, "SQL SERVER"))
  1470. {
  1471. sprintf(strSQLText, "select top 1 id from t_user_group where groupname = \'%s\'", sGroupName);
  1472. }
  1473. else if (!_stricmp(m_chDBType, "ACCESS97"))
  1474. {
  1475. sprintf(strSQLText, "select top 1 id from t_user_group where groupname = \'%s\'", sGroupName);
  1476. }
  1477. else if (!_stricmp(m_chDBType, "ACCESS2000"))
  1478. {
  1479. sprintf(strSQLText, "select top 1 id from t_user_group where groupname = \'%s\'", sGroupName);
  1480. }
  1481. else if(!_stricmp(m_chDBType, "PGSQL"))
  1482. {
  1483. sprintf(strSQLText, "select id from t_user_group where groupname = \'%s\' limit 1", sGroupName);
  1484. }
  1485. int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList1(strSQLText, list1);
  1486. if( 0 == list1.size() )
  1487. {
  1488. return 0;
  1489. }
  1490. if( nRet != -1 )
  1491. {
  1492. CString str;
  1493. str = list1.begin()->c_str();
  1494. iGroupID = atoi(str);
  1495. }
  1496. for( it = list1.begin(); it != list1.end(); )
  1497. {
  1498. list1.erase(it++);
  1499. }
  1500. return nRet;
  1501. }
  1502. // 根據權限名得到ID
  1503. INT CDBInterface::GetPermitIDByName( CString sPermitName,int &iPermitID )
  1504. {
  1505. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  1506. list<string> list1;
  1507. list<string>::iterator it;
  1508. if (!_stricmp(m_chDBType, "SQL SERVER"))
  1509. {
  1510. sprintf(strSQLText, "select top 1 id from t_user_purview where purview_name = \'%s\'", sPermitName);
  1511. }
  1512. else if (!_stricmp(m_chDBType, "ACCESS97"))
  1513. {
  1514. sprintf(strSQLText, "select top 1 id from t_user_purview where purview_name = \'%s\'", sPermitName);
  1515. }
  1516. else if (!_stricmp(m_chDBType, "ACCESS2000"))
  1517. {
  1518. sprintf(strSQLText, "select top 1 id from t_user_purview where purview_name = \'%s\'", sPermitName);
  1519. }
  1520. else if(!_stricmp(m_chDBType, "PGSQL"))
  1521. {
  1522. sprintf(strSQLText, "select id from t_user_purview where purview_name = \'%s\'", sPermitName);/* limit 1*/
  1523. }
  1524. int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList1(strSQLText, list1);
  1525. if( 0 == list1.size() )
  1526. {
  1527. return 0;
  1528. }
  1529. if( nRet != -1 )
  1530. {
  1531. CString str;
  1532. str = list1.begin()->c_str();
  1533. iPermitID = atoi(str);
  1534. }
  1535. for( it = list1.begin(); it != list1.end(); )
  1536. {
  1537. list1.erase(it++);
  1538. }
  1539. return nRet;
  1540. }
  1541. // 根據組的ID得到該組的所有權限
  1542. INT CDBInterface::GetGroupPermitByID( CListBox *pListBox,int iGroupID )
  1543. {
  1544. int nCount = pListBox->GetCount();
  1545. for( int i = nCount-1; i >=0; i-- )
  1546. {
  1547. pListBox->DeleteString( i );
  1548. }
  1549. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  1550. list<string> list1;
  1551. list<string>::iterator it_list1;
  1552. int nPermitID=0;
  1553. CString strPermitName, strDesc, str;
  1554. if(!_stricmp(g_strDBType, "PGSQL"))
  1555. {
  1556. sprintf(strSQLText, "select groupdesc from t_user_group where id = %d /*limit 1*/", iGroupID);
  1557. }
  1558. else
  1559. {
  1560. sprintf(strSQLText, "select top 1 groupdesc from t_user_group where id = %d", iGroupID);
  1561. }
  1562. int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList1(strSQLText, list1);
  1563. if( 0 == list1.size() )
  1564. {
  1565. return 0;
  1566. }
  1567. if( nRet != -1 )
  1568. {
  1569. for( it_list1 = list1.begin(); it_list1 != list1.end(); it_list1++ )
  1570. {
  1571. strDesc = (*it_list1).c_str();
  1572. strDesc = strDesc.Trim();
  1573. int nS=0,nE=0;
  1574. for( int i=0;i<strDesc.GetLength();i++ )
  1575. {
  1576. if( strDesc[i]=='-' )
  1577. {
  1578. nE = i;
  1579. str = strDesc.Mid( nS,nE-nS );
  1580. nS = nE+1;
  1581. nPermitID = atoi(str);
  1582. GetPermitNameByID( strPermitName, nPermitID );
  1583. if( strPermitName!="" && strPermitName[0]!='*' )
  1584. {
  1585. pListBox->AddString( strPermitName );
  1586. }
  1587. }
  1588. }
  1589. str = strDesc.Mid( nS,strDesc.GetLength()-nS );
  1590. if( str!="" )
  1591. {
  1592. nPermitID = atoi(str);
  1593. GetPermitNameByID( strPermitName,nPermitID );
  1594. if( strPermitName[0]!='*' )
  1595. {
  1596. pListBox->AddString( strPermitName );
  1597. }
  1598. }
  1599. }
  1600. }
  1601. for( it_list1 = list1.begin(); it_list1 != list1.end(); )
  1602. {
  1603. list1.erase(it_list1++);
  1604. }
  1605. return 0;
  1606. }
  1607. // 如果2中有則1沒
  1608. INT CDBInterface::GetGroupPermitByID( CListBox *pListBox1,CListBox *pListBox2 )
  1609. {
  1610. int nCount2 = pListBox2->GetCount();
  1611. int nCount1 = pListBox1->GetCount();
  1612. for( int i = nCount1-1; i >=0; i-- )
  1613. {
  1614. pListBox1->DeleteString( i );
  1615. }
  1616. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  1617. list<string> list1;
  1618. list<string>::iterator it_list1;
  1619. int nPermitID=0;
  1620. CString strName, str;
  1621. if(!_stricmp(g_strDBType, "PGSQL"))
  1622. {
  1623. sprintf(strSQLText, "select purview_name from t_user_purview");
  1624. }
  1625. else
  1626. {
  1627. sprintf(strSQLText, "select purview_name from t_user_purview");
  1628. }
  1629. int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList1(strSQLText, list1);
  1630. if( 0 == list1.size() )
  1631. {
  1632. return 0;
  1633. }
  1634. if( nRet != -1 )
  1635. {
  1636. for( it_list1 = list1.begin(); it_list1 != list1.end(); it_list1++ )
  1637. {
  1638. strName = (*it_list1).c_str();
  1639. strName = strName.Trim();
  1640. bool bExist = false;
  1641. for( int i=0;i<nCount2;i++ )
  1642. {
  1643. pListBox2->GetText( i, str );
  1644. if( str==strName )
  1645. {
  1646. bExist = true;
  1647. break;
  1648. }
  1649. }
  1650. if( !bExist )
  1651. {
  1652. if( strName[0]!='*' )
  1653. {
  1654. pListBox1->AddString( strName );
  1655. }
  1656. }
  1657. }
  1658. }
  1659. for( it_list1 = list1.begin(); it_list1 != list1.end(); )
  1660. {
  1661. list1.erase(it_list1++);
  1662. }
  1663. return nRet;
  1664. }
  1665. INT CDBInterface::FindGroupByName(CString sGroupName)
  1666. {
  1667. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  1668. list<string> list1;
  1669. list<string>::iterator it;
  1670. if (!_stricmp(m_chDBType, "SQL SERVER"))
  1671. {
  1672. sprintf(strSQLText, "select top 1 id from t_user_group where groupname = \'%s\'", sGroupName);
  1673. }
  1674. else if (!_stricmp(m_chDBType, "ACCESS97"))
  1675. {
  1676. sprintf(strSQLText, "select top 1 id from t_user_group where groupname = \'%s\'", sGroupName);
  1677. }
  1678. else if (!_stricmp(m_chDBType, "ACCESS2000"))
  1679. {
  1680. sprintf(strSQLText, "select top 1 id from t_user_group where groupname = \'%s\'", sGroupName);
  1681. }
  1682. else if(!_stricmp(m_chDBType, "PGSQL"))
  1683. {
  1684. sprintf(strSQLText, "select id from t_user_group where groupname = \'%s\' limit 1", sGroupName);
  1685. }
  1686. int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList1(strSQLText, list1);
  1687. if( 0 == list1.size() )
  1688. {
  1689. return 0;
  1690. }
  1691. for( it = list1.begin(); it != list1.end(); )
  1692. {
  1693. list1.erase(it++);
  1694. }
  1695. return nRet;
  1696. }
  1697. // 根據用戶名得到ID
  1698. INT CDBInterface::GetUserIDByName( CString sUserName,int &iUserID )
  1699. {
  1700. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  1701. list<string> list1;
  1702. list<string>::iterator it;
  1703. if (!_stricmp(m_chDBType, "SQL SERVER"))
  1704. {
  1705. sprintf(strSQLText, "select top 1 id from t_user_info where uid = \'%s\'", sUserName);
  1706. }
  1707. else if (!_stricmp(m_chDBType, "ACCESS97"))
  1708. {
  1709. sprintf(strSQLText, "select top 1 id from t_user_info where uid = \'%s\'", sUserName);
  1710. }
  1711. else if (!_stricmp(m_chDBType, "ACCESS2000"))
  1712. {
  1713. sprintf(strSQLText, "select top 1 id from t_user_info where uid = \'%s\'", sUserName);
  1714. }
  1715. else if(!_stricmp(m_chDBType, "PGSQL"))
  1716. {
  1717. sprintf(strSQLText, "select id from t_user_info where uid = \'%s\' limit 1", sUserName);
  1718. }
  1719. int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList1(strSQLText, list1);
  1720. if( 0 == list1.size() )
  1721. {
  1722. return 0;
  1723. }
  1724. if( nRet != -1 )
  1725. {
  1726. CString str;
  1727. str = list1.begin()->c_str();
  1728. iUserID = atoi(str);
  1729. }
  1730. for( it = list1.begin(); it != list1.end(); )
  1731. {
  1732. list1.erase(it++);
  1733. }
  1734. return nRet;
  1735. }
  1736. INT CDBInterface::AddUserToDll()
  1737. {
  1738. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  1739. list<string> list1, list2, list3;
  1740. list<string>::iterator it_list1, it_list2, it_list3;
  1741. int nUserID = 0;
  1742. int nGroupID = 0;
  1743. int nPermitID = 0;
  1744. CString strName,str;
  1745. if(!_stricmp(g_strDBType, "PGSQL"))
  1746. {
  1747. sprintf(strSQLText, "select t_user_info.id,t_user_info.uid,t_role_user.group_id from t_user_info,t_role_user where t_user_info.uid=t_role_user.userid");
  1748. }
  1749. else
  1750. {
  1751. sprintf(strSQLText, "select t_user_info.id,t_user_info.uid,t_role_user.group_id from t_user_info,t_role_user where t_user_info.uid=t_role_user.userid");
  1752. }
  1753. int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList3(strSQLText, list1, list2, list3);
  1754. if( 0 == list1.size() || 0 == list2.size() || 0 == list3.size() )
  1755. {
  1756. return 0;
  1757. }
  1758. if( nRet != -1 )
  1759. {
  1760. for( it_list1 = list1.begin(), it_list2 = list2.begin(), it_list3 = list3.begin();
  1761. it_list1 != list1.end() && it_list2 != list2.end() && it_list3 != list3.end();
  1762. it_list1++, it_list2++, it_list3++)
  1763. {
  1764. str = (*it_list1).c_str();
  1765. nUserID = atoi( str.Trim() );
  1766. str = (*it_list2).c_str();
  1767. strName = str.Trim();
  1768. str = (*it_list3).c_str();
  1769. nGroupID = atoi( str.Trim() );
  1770. PMS_AddUserToGroup( strName,nUserID,nGroupID );
  1771. }
  1772. }
  1773. for( it_list1 = list1.begin(), it_list2 = list2.begin(), it_list3 = list3.begin();
  1774. it_list1 != list1.end(), it_list2 != list2.end(), it_list3 != list3.end(); )
  1775. {
  1776. list1.erase(it_list1++);
  1777. list2.erase(it_list2++);
  1778. list3.erase(it_list3++);
  1779. }
  1780. return 0;
  1781. }
  1782. //得到用戶所屬的組
  1783. INT CDBInterface::GetAllGroupByUserID( CListBox *pListBox,CHAR * pUserID )
  1784. {
  1785. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  1786. list<string> list1;
  1787. list<string>::iterator it_list1;
  1788. int nPermitID=0;
  1789. CString strName, str;
  1790. if(!_stricmp(g_strDBType, "PGSQL"))
  1791. {
  1792. sprintf(strSQLText, "select t_user_group.groupname from t_role_user,t_user_group "\
  1793. "where t_user_group.id=t_role_user.group_id and t_role_user.userid=\'%s\'",pUserID );
  1794. }
  1795. else
  1796. {
  1797. sprintf(strSQLText, "select t_user_group.groupname from t_role_user,t_user_group "\
  1798. "where t_user_group.id=t_role_user.group_id and t_role_user.userid=\'%s\'",pUserID );
  1799. }
  1800. int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList1(strSQLText, list1);
  1801. if( 0 == list1.size() )
  1802. {
  1803. return 0;
  1804. }
  1805. if( nRet != -1 )
  1806. {
  1807. for( it_list1 = list1.begin(); it_list1 != list1.end(); it_list1++ )
  1808. {
  1809. strName = (*it_list1).c_str();
  1810. strName = strName.Trim();
  1811. pListBox->AddString( strName );
  1812. }
  1813. }
  1814. for( it_list1 = list1.begin(); it_list1 != list1.end(); )
  1815. {
  1816. list1.erase(it_list1++);
  1817. }
  1818. return nRet;
  1819. }
  1820. INT CDBInterface::GetAllGroupByUserID( CListBox *pListBox1,CListBox *pListBox2 )
  1821. {
  1822. int nCount2 = pListBox2->GetCount();
  1823. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  1824. list<string> list1;
  1825. list<string>::iterator it_list1;
  1826. int nPermitID=0;
  1827. CString strName, str;
  1828. if(!_stricmp(g_strDBType, "PGSQL"))
  1829. {
  1830. sprintf(strSQLText, "select groupname from t_user_group");
  1831. }
  1832. else
  1833. {
  1834. sprintf(strSQLText, "select groupname from t_user_group");
  1835. }
  1836. int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList1(strSQLText, list1);
  1837. if( 0 == list1.size() )
  1838. {
  1839. return 0;
  1840. }
  1841. if( nRet != -1 )
  1842. {
  1843. for( it_list1 = list1.begin(); it_list1 != list1.end(); it_list1++ )
  1844. {
  1845. strName = (*it_list1).c_str();
  1846. strName = strName.Trim();
  1847. bool bExist = false;
  1848. for( int i=0;i<nCount2;i++ )
  1849. {
  1850. pListBox2->GetText( i, str );
  1851. if( str == strName )
  1852. {
  1853. bExist = true;
  1854. break;
  1855. }
  1856. }
  1857. if( !bExist && strName.Compare("管理员") )
  1858. pListBox1->AddString( strName );
  1859. }
  1860. }
  1861. for( it_list1 = list1.begin(); it_list1 != list1.end(); )
  1862. {
  1863. list1.erase(it_list1++);
  1864. }
  1865. return nRet;
  1866. }
  1867. // 根據權限ID得到名
  1868. INT CDBInterface::GetPermitNameByID( CString &sPermitName,int iPermitID )
  1869. {
  1870. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  1871. list<string> list1;
  1872. list<string>::iterator it;
  1873. if (!_stricmp(g_strDBType, "SQL SERVER"))
  1874. {
  1875. sprintf(strSQLText, "select top 1 purview_name from t_user_purview where id = %d", iPermitID);
  1876. }
  1877. else if (!_stricmp(g_strDBType, "ACCESS97"))
  1878. {
  1879. sprintf(strSQLText, "select top 1 purview_name from t_user_purview where id = %d", iPermitID);
  1880. }
  1881. else if (!_stricmp(g_strDBType, "ACCESS2000"))
  1882. {
  1883. sprintf(strSQLText, "select top 1 purview_name from t_user_purview where id = %d", iPermitID);
  1884. }
  1885. else if(!_stricmp(g_strDBType, "PGSQL"))
  1886. {
  1887. sprintf(strSQLText, "select purview_name from t_user_purview where id = %d limit 1", iPermitID);
  1888. }
  1889. int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList1(strSQLText, list1);
  1890. if( 0 == list1.size() )
  1891. {
  1892. return 0;
  1893. }
  1894. if( nRet != -1 )
  1895. {
  1896. CString str;
  1897. str = list1.begin()->c_str();
  1898. sPermitName = str.Trim();
  1899. }
  1900. for( it = list1.begin(); it != list1.end(); )
  1901. {
  1902. list1.erase(it++);
  1903. }
  1904. return nRet;
  1905. }
  1906. //根据指定内容删除表内容, 通用函数 //0:不操作 1:字符串 2:整型
  1907. INT CDBInterface::DelTableData( CHAR *pTableName, CHAR *pFieldName1,CHAR *pContent1,int iType1,
  1908. CHAR *pFieldName2,CHAR *pContent2,int iType2,
  1909. CHAR *pFieldName3,CHAR *pContent3,int iType3 )
  1910. {
  1911. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  1912. CHAR sTemp[MAX_SQL_LENGTH + 1] = "";
  1913. sprintf(strSQLText, "delete from %s where ", pTableName);
  1914. switch( iType1 )
  1915. {
  1916. case 1://字符串
  1917. sprintf( sTemp, "%s = \'%s\' ", pFieldName1,pContent1 );
  1918. strcat( strSQLText, sTemp );
  1919. break;
  1920. case 2://整型
  1921. sprintf(sTemp, "%s = \'%d\' ", pFieldName1,atoi(pContent1));
  1922. strcat( strSQLText, sTemp );
  1923. break;
  1924. }
  1925. switch( iType2 )
  1926. {
  1927. case 1://字符串
  1928. sprintf( sTemp, "and %s = \'%s\' ", pFieldName2,pContent2 );
  1929. strcat( strSQLText, sTemp );
  1930. break;
  1931. case 2://整型
  1932. sprintf(sTemp, "and %s = \'%d\' ", pFieldName2,atoi(pContent2));
  1933. strcat( strSQLText, sTemp );
  1934. break;
  1935. }
  1936. switch( iType3 )
  1937. {
  1938. case 1://字符串
  1939. sprintf( sTemp, "and %s = \'%s\'", pFieldName3,pContent3 );
  1940. strcat( strSQLText, sTemp );
  1941. break;
  1942. case 2://整型
  1943. sprintf(sTemp, "and %s = \'%d\'", pFieldName3,atoi(pContent3));
  1944. strcat( strSQLText, sTemp );
  1945. break;
  1946. }
  1947. return CDBConnection::GetInstancePtr()->Execute(strSQLText);
  1948. }
  1949. //判断是否有电话,短信,EMAIL功能
  1950. INT CDBInterface::JudgeIsTSE( bool &bTel,bool &bSms,bool &bEmail )
  1951. {
  1952. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  1953. list<string> list1, list2, list3,list4;
  1954. list<string>::iterator it_list1, it_list2, it_list3, it_list4;
  1955. CString sUid,sTel,sMobile,sEmail;
  1956. CString str;
  1957. if(!_stricmp(g_strDBType, "PGSQL"))
  1958. {
  1959. sprintf(strSQLText, "select uid,tel,mobiletel,email from t_user_info");
  1960. }
  1961. else
  1962. {
  1963. sprintf(strSQLText, "select uid,tel,mobiletel,email from t_user_info");
  1964. }
  1965. int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList4(strSQLText, list1, list2, list3,list4);
  1966. if( 0 == list1.size() || 0 == list2.size() || 0 == list3.size() || 0 == list4.size() )
  1967. {
  1968. return 0;
  1969. }
  1970. if( nRet != -1 )
  1971. {
  1972. for( it_list1 = list1.begin(), it_list2 = list2.begin(), it_list3 = list3.begin(), it_list4 = list4.begin();
  1973. it_list1 != list1.end() && it_list2 != list2.end() && it_list3 != list3.end() && it_list4 != list4.end();
  1974. it_list1++, it_list2++, it_list3++, it_list4++)
  1975. {
  1976. str = (*it_list1).c_str();
  1977. sUid = str.Trim();
  1978. str = (*it_list2).c_str();
  1979. sTel = str.Trim();
  1980. str = (*it_list3).c_str();
  1981. sMobile = str.Trim();
  1982. str = (*it_list4).c_str();
  1983. sEmail = str.Trim();
  1984. if( sUid.Compare("admin") )
  1985. {
  1986. if( sTel.Compare("") )
  1987. {
  1988. bTel = true;
  1989. }
  1990. if( sMobile.Compare("") )
  1991. {
  1992. bSms = true;
  1993. }
  1994. if( sEmail.Compare("") )
  1995. {
  1996. bEmail = true;
  1997. }
  1998. }
  1999. }
  2000. }
  2001. for( it_list1 = list1.begin(), it_list2 = list2.begin(), it_list3 = list3.begin(), it_list4 = list4.begin();
  2002. it_list1 != list1.end(), it_list2 != list2.end(), it_list3 != list3.end(), it_list4 != list4.end(); )
  2003. {
  2004. list1.erase(it_list1++);
  2005. list2.erase(it_list2++);
  2006. list3.erase(it_list3++);
  2007. list4.erase(it_list4++);
  2008. }
  2009. return nRet;
  2010. }
  2011. //
  2012. INT CDBInterface::GetAllActionWithAlarm( CListCtrl *pListCtrl )
  2013. {
  2014. pListCtrl->DeleteAllItems();
  2015. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  2016. list<string> list1,list2,list3,list4;
  2017. list<string>::iterator it_list1,it_list2,it_list3,it_list4;
  2018. CString s1,s2,s3,s4;
  2019. if(!_stricmp(g_strDBType, "PGSQL"))
  2020. {
  2021. sprintf(strSQLText, "select doset_varname,dostatus_varname,alarmdata,resumedata from t_actionwithalarm");
  2022. }
  2023. else
  2024. {
  2025. sprintf(strSQLText, "select doset_varname,dostatus_varname,alarmdata,resumedata from t_actionwithalarm");
  2026. }
  2027. int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList4(strSQLText, list1, list2, list3, list4);
  2028. if( 0 == list1.size() || 0 == list2.size() || 0 == list3.size() || 0 == list4.size() )
  2029. {
  2030. return 0;
  2031. }
  2032. if( nRet != -1 )
  2033. {
  2034. for( it_list1 = list1.begin(),it_list2 = list2.begin(),it_list3 = list3.begin(),it_list4 = list4.begin();
  2035. it_list1 != list1.end() && it_list2 != list2.end() && it_list3 != list3.end() && it_list4 != list4.end();
  2036. it_list1++, it_list2++, it_list3++, it_list4++ )
  2037. {
  2038. s1 = (*it_list1).c_str();
  2039. s1 = s1.Trim();
  2040. s2 = (*it_list2).c_str();
  2041. s2 = s2.Trim();
  2042. s3 = (*it_list3).c_str();
  2043. s3 = s3.Trim();
  2044. s4 = (*it_list4).c_str();
  2045. s4 = s4.Trim();
  2046. bool f=false;
  2047. for( int i=0;i<pListCtrl->GetItemCount();i++ )
  2048. {
  2049. CString str;
  2050. str = pListCtrl->GetItemText( i,0 );
  2051. if( str==s1 )
  2052. {
  2053. f = true;
  2054. break;
  2055. }
  2056. }
  2057. if( !f )
  2058. {
  2059. int n = pListCtrl->GetItemCount();
  2060. pListCtrl->InsertItem( n,s1 );
  2061. pListCtrl->SetItemText( n,1,s2 );
  2062. pListCtrl->SetItemText( n,2,s3 );
  2063. pListCtrl->SetItemText( n,3,s4 );
  2064. }
  2065. }
  2066. }
  2067. for( it_list1 = list1.begin(),it_list2 = list2.begin(),it_list3 = list3.begin(),it_list4 = list4.begin();
  2068. it_list1 != list1.end(), it_list2 != list2.end(), it_list3 != list3.end(), it_list4 != list4.end(); )
  2069. {
  2070. list1.erase(it_list1++);
  2071. list2.erase(it_list2++);
  2072. list3.erase(it_list3++);
  2073. list4.erase(it_list4++);
  2074. }
  2075. return nRet;
  2076. }
  2077. INT CDBInterface::GetAWAPlanTime( CString sDoSet,CString &sPlanTime )
  2078. {
  2079. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  2080. list<string> list1;
  2081. list<string>::iterator it_list1;
  2082. CString s1;
  2083. if(!_stricmp(g_strDBType, "PGSQL"))
  2084. {
  2085. sprintf(strSQLText, "select strreserved1 from t_actionwithalarm where doset_varname=\'%s\'",sDoSet );
  2086. }
  2087. else
  2088. {
  2089. sprintf(strSQLText, "select strreserved1 from t_actionwithalarm where doset_varname=\'%s\',sDoSet");
  2090. }
  2091. int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList1(strSQLText, list1 );
  2092. if( 0 == list1.size() )
  2093. {
  2094. return 0;
  2095. }
  2096. if( nRet != -1 )
  2097. {
  2098. for( it_list1 = list1.begin();
  2099. it_list1 != list1.end();
  2100. it_list1++ )
  2101. {
  2102. s1 = (*it_list1).c_str();
  2103. s1 = s1.Trim();
  2104. sPlanTime = s1;
  2105. }
  2106. }
  2107. for( it_list1 = list1.begin();
  2108. it_list1 != list1.end(); )
  2109. {
  2110. list1.erase(it_list1++);
  2111. }
  2112. return nRet;
  2113. }
  2114. INT CDBInterface::SetAWAPlanTime( CString sDoSet,CString sPlanTime )
  2115. {
  2116. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  2117. sprintf(strSQLText, "UPDATE t_actionwithalarm SET strreserved1=\'%s\' where doset_varname=\'%s\' ",
  2118. sPlanTime,sDoSet );
  2119. return CDBConnection::GetInstancePtr()->Execute(strSQLText);
  2120. }
  2121. INT CDBInterface::AddActionWithAlarm( CString sDoSet,CString sDoStatus,int iAlarmData,int iResumeData,CString sDoPlanTime )
  2122. {
  2123. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  2124. int nID = 0;
  2125. CHAR szMaxID[MAX_ID] = {0};
  2126. GetMaxID("t_actionwithalarm", "id", szMaxID);
  2127. nID = atoi( szMaxID )+1;
  2128. sprintf(strSQLText, "insert into t_actionwithalarm(id, doset_varname,dostatus_varname,alarmdata,resumedata,strreserved1) values (" \
  2129. "%d, \'%s\', \'%s\',%d,%d, \'%s\' )",
  2130. nID, sDoSet,sDoStatus,iAlarmData,iResumeData,sDoPlanTime);
  2131. return CDBConnection::GetInstancePtr()->Execute(strSQLText);
  2132. }
  2133. INT CDBInterface::AddActionWithAlarm( CString sDoSet,CString sDoStatus,int iAlarmData,int iResumeData,CString sDoPlanTime,CStringArray &SA )
  2134. {
  2135. int nSize = SA.GetCount();
  2136. //先删除
  2137. DelActionWithAlarm( sDoSet );
  2138. if( nSize==0 )
  2139. {
  2140. AddActionWithAlarm( sDoSet,sDoStatus,iAlarmData,iResumeData,sDoPlanTime );
  2141. }
  2142. else
  2143. {
  2144. int X=nSize%30;
  2145. if( X!=0 )
  2146. {
  2147. X = ( 30-X );
  2148. nSize += X;
  2149. }
  2150. for( int i=0;i<X;i++ )
  2151. {
  2152. SA.Add( "" );
  2153. }
  2154. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  2155. int nID = 0;
  2156. CHAR szMaxID[MAX_ID] = {0};
  2157. int n=0;
  2158. for( int n=0;n<nSize/30;n++ )
  2159. {
  2160. GetMaxID("t_actionwithalarm", "id", szMaxID);
  2161. nID = atoi( szMaxID )+1;
  2162. sprintf(strSQLText, "insert into t_actionwithalarm(id, doset_varname,dostatus_varname,alarmdata,resumedata,strreserved1,"\
  2163. "varname1,varname2,varname3,varname4,varname5,varname6,varname7,varname8,varname9,varname10,"\
  2164. "varname11,varname12,varname13,varname14,varname15,varname16,varname17,varname18,varname19,varname20,"\
  2165. "varname21,varname22,varname23,varname24,varname25,varname26,varname27,varname28,varname29,varname30 ) "\
  2166. "values (%d,\'%s\',\'%s\',%d,%d,\'%s\', "\
  2167. "\'%s\',\'%s\',\'%s\',\'%s\',\'%s\',\'%s\',\'%s\',\'%s\',\'%s\',\'%s\',"\
  2168. "\'%s\',\'%s\',\'%s\',\'%s\',\'%s\',\'%s\',\'%s\',\'%s\',\'%s\',\'%s\',"\
  2169. "\'%s\',\'%s\',\'%s\',\'%s\',\'%s\',\'%s\',\'%s\',\'%s\',\'%s\',\'%s\')", nID, sDoSet,sDoStatus,iAlarmData,iResumeData,sDoPlanTime,
  2170. SA.GetAt(n*30+0),SA.GetAt(n*30+1),SA.GetAt(n*30+2),SA.GetAt(n*30+3),SA.GetAt(n*30+4),SA.GetAt(n*30+5),SA.GetAt(n*30+6),SA.GetAt(n*30+7),SA.GetAt(n*30+8),SA.GetAt(n*30+9),
  2171. SA.GetAt(n*30+10),SA.GetAt(n*30+11),SA.GetAt(n*30+12),SA.GetAt(n*30+13),SA.GetAt(n*30+14),SA.GetAt(n*30+15),SA.GetAt(n*30+16),SA.GetAt(n*30+17),SA.GetAt(n*30+18),SA.GetAt(n*30+19),
  2172. SA.GetAt(n*30+20),SA.GetAt(n*30+21),SA.GetAt(n*30+22),SA.GetAt(n*30+23),SA.GetAt(n*30+24),SA.GetAt(n*30+25),SA.GetAt(n*30+26),SA.GetAt(n*30+27),SA.GetAt(n*30+28),SA.GetAt(n*30+29) );
  2173. CDBConnection::GetInstancePtr()->Execute(strSQLText);
  2174. }
  2175. }
  2176. return 0;
  2177. }
  2178. INT CDBInterface::ModifyActionWithAlarm( CString sOldDoSet,CString sDoSet, CString sDoStatus,int iAlarmData,int iResumeData,CString sDoPlanTime )
  2179. {
  2180. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  2181. sprintf(strSQLText, "UPDATE t_actionwithalarm SET doset_varname=\'%s\',dostatus_varname=\'%s\',alarmdata=%d,resumedata=%d,strreserved1=\'%s\' where doset_varname=\'%s\' ",
  2182. sDoSet,sDoStatus,iAlarmData,iResumeData,sDoPlanTime,sOldDoSet );
  2183. return CDBConnection::GetInstancePtr()->Execute(strSQLText);
  2184. }
  2185. INT CDBInterface::DelActionWithAlarm( CString sDosetVarName )
  2186. {
  2187. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  2188. sprintf(strSQLText, "delete from t_actionwithalarm where doset_varname=\'%s\'",sDosetVarName);
  2189. return CDBConnection::GetInstancePtr()->Execute(strSQLText);
  2190. }
  2191. INT CDBInterface::GetActionWithAlarmVar( CListBox *pListBox,CString sDoSet )
  2192. {
  2193. CHAR strSQLText[MAX_SQL_LENGTH * 2] = {0};
  2194. list<string> list_str_doset, list_str_dostatus;
  2195. list<string> list_int_alarmdata,list_int_resumedata;
  2196. list<string> list_str_reserved1, list_str_reserved2, list_str_reserved3;
  2197. list<string> list_int_reserved1, list_int_reserved2, list_int_reserved3;
  2198. list<string> list_bool_reserved1, list_bool_reserved2, list_bool_reserved3;
  2199. list<string> list_var1, list_var2, list_var3, list_var4, list_var5, list_var6, list_var7, list_var8, list_var9, list_var10;
  2200. list<string> list_var11, list_var12, list_var13, list_var14, list_var15, list_var16, list_var17, list_var18, list_var19, list_var20;
  2201. list<string> list_var21, list_var22, list_var23, list_var24, list_var25, list_var26, list_var27, list_var28, list_var29, list_var30;
  2202. list<string>::iterator it_str_doset, it_str_dostatus;
  2203. list<string>::iterator it_int_alarmdata, it_int_resumedata;
  2204. list<string>::iterator it_str_reserved1, it_str_reserved2, it_str_reserved3;
  2205. list<string>::iterator it_int_reserved1, it_int_reserved2, it_int_reserved3;
  2206. list<string>::iterator it_bool_reserved1, it_bool_reserved2, it_bool_reserved3;
  2207. list<string>::iterator it_var1, it_var2, it_var3, it_var4, it_var5, it_var6, it_var7, it_var8, it_var9, it_var10;
  2208. list<string>::iterator it_var11, it_var12, it_var13, it_var14, it_var15, it_var16, it_var17, it_var18, it_var19, it_var20;
  2209. list<string>::iterator it_var21, it_var22, it_var23, it_var24, it_var25, it_var26, it_var27, it_var28, it_var29, it_var30;
  2210. if (!_stricmp(m_chDBType, "SQL SERVER"))
  2211. {
  2212. sprintf(strSQLText, "select doset_varname,dostatus_varname,alarmdata,resumedata, " \
  2213. "strreserved1, strreserved2, strreserved3, " \
  2214. "intreserved1, intreserved2, intreserved3, " \
  2215. "boolreserved1, boolreserved2, boolreserved3, " \
  2216. "varname1, varname2, varname3, varname4, varname5, varname6, varname7, varname8,varname9,varname10, " \
  2217. "varname11, varname12, varname13, varname14, varname15, varname16, varname17, varname18,varname19,varname20, " \
  2218. "varname21, varname22, varname23, varname24, varname25, varname26, varname27, varname28,varname29,varname30" \
  2219. "from t_actionwithalarm where doset_varname=\'%s\'",sDoSet );
  2220. }
  2221. else if (!_stricmp(m_chDBType, "ACCESS97"))
  2222. {
  2223. }
  2224. else if (!_stricmp(m_chDBType, "ACCESS2000"))
  2225. {
  2226. }
  2227. else if(!_stricmp(m_chDBType, "PGSQL"))
  2228. {
  2229. sprintf(strSQLText, "select doset_varname,dostatus_varname,alarmdata,resumedata, " \
  2230. "strreserved1, strreserved2, strreserved3, " \
  2231. "intreserved1, intreserved2, intreserved3, " \
  2232. "boolreserved1, boolreserved2, boolreserved3, " \
  2233. "varname1, varname2, varname3, varname4, varname5, varname6, varname7, varname8,varname9,varname10, " \
  2234. "varname11, varname12, varname13, varname14, varname15, varname16, varname17, varname18,varname19,varname20, " \
  2235. "varname21, varname22, varname23, varname24, varname25, varname26, varname27, varname28,varname29,varname30 " \
  2236. "from t_actionwithalarm where doset_varname=\'%s\'",sDoSet );
  2237. }
  2238. //LOG4C((LOG_NOTICE, "%s", strSQLText));
  2239. int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList43(strSQLText
  2240. ,list_str_doset,list_str_dostatus
  2241. ,list_int_alarmdata,list_int_resumedata
  2242. ,list_str_reserved1, list_str_reserved2, list_str_reserved3
  2243. ,list_int_reserved1, list_int_reserved2, list_int_reserved3
  2244. ,list_bool_reserved1, list_bool_reserved2, list_bool_reserved3
  2245. ,list_var1, list_var2, list_var3, list_var4, list_var5, list_var6, list_var7, list_var8, list_var9, list_var10
  2246. ,list_var11, list_var12, list_var13, list_var14, list_var15, list_var16, list_var17, list_var18, list_var19, list_var20
  2247. ,list_var21, list_var22, list_var23, list_var24, list_var25, list_var26, list_var27, list_var28, list_var29, list_var30 );
  2248. if( 0 == list_str_reserved1.size() || 0 == list_str_reserved2.size() || 0 == list_str_reserved3.size()
  2249. || 0 == list_int_reserved1.size() || 0 == list_int_reserved2.size() || 0 == list_int_reserved3.size()
  2250. || 0 == list_bool_reserved1.size() || 0 == list_bool_reserved2.size() || 0 == list_bool_reserved3.size()
  2251. )
  2252. {
  2253. return 0;
  2254. }
  2255. if( nRet != -1 )
  2256. {
  2257. for( it_var1=list_var1.begin(),it_var2=list_var2.begin(),it_var3=list_var3.begin(),it_var4=list_var4.begin(),it_var5=list_var5.begin()
  2258. ,it_var6=list_var6.begin(),it_var7=list_var7.begin(),it_var8=list_var8.begin(),it_var9=list_var9.begin(),it_var10=list_var10.begin()
  2259. ,it_var11=list_var11.begin(),it_var12=list_var12.begin(),it_var13=list_var13.begin(),it_var14=list_var14.begin(),it_var15=list_var15.begin()
  2260. ,it_var16=list_var16.begin(),it_var17=list_var17.begin(),it_var18=list_var18.begin(),it_var19=list_var19.begin(),it_var20=list_var20.begin()
  2261. ,it_var21=list_var21.begin(),it_var22=list_var22.begin(),it_var23=list_var23.begin(),it_var24=list_var24.begin(),it_var25=list_var25.begin()
  2262. ,it_var26=list_var26.begin(),it_var27=list_var27.begin(),it_var28=list_var28.begin(),it_var29=list_var29.begin(),it_var30=list_var30.begin();
  2263. it_var1!=list_var1.end(),it_var2!=list_var2.end(),it_var3!=list_var3.end(),it_var4!=list_var4.end(),it_var5!=list_var5.end()
  2264. ,it_var6!=list_var6.end(),it_var7!=list_var7.end(),it_var8!=list_var8.end(),it_var9!=list_var9.end(),it_var10!=list_var10.end()
  2265. ,it_var11!=list_var11.end(),it_var12!=list_var12.end(),it_var13!=list_var13.end(),it_var14!=list_var14.end(),it_var15!=list_var15.end()
  2266. ,it_var16!=list_var16.end(),it_var17!=list_var17.end(),it_var18!=list_var18.end(),it_var19!=list_var19.end(),it_var20!=list_var20.end()
  2267. ,it_var21!=list_var21.end(),it_var22!=list_var22.end(),it_var23!=list_var23.end(),it_var24!=list_var24.end(),it_var25!=list_var25.end()
  2268. ,it_var26!=list_var26.end(),it_var27!=list_var27.end(),it_var28!=list_var28.end(),it_var29!=list_var29.end(),it_var30!=list_var30.end();
  2269. )
  2270. {
  2271. CString str;
  2272. str = (*it_var1++).c_str(); str = str.Trim();
  2273. if( str!="" && pVariantsManager->IsExistVar(str) ) pListBox->AddString( str );
  2274. str = (*it_var2++).c_str(); str = str.Trim();
  2275. if( str!="" && pVariantsManager->IsExistVar(str) ) pListBox->AddString( str );
  2276. str = (*it_var3++).c_str(); str = str.Trim();
  2277. if( str!="" && pVariantsManager->IsExistVar(str) ) pListBox->AddString( str );
  2278. str = (*it_var4++).c_str(); str = str.Trim();
  2279. if( str!="" && pVariantsManager->IsExistVar(str) ) pListBox->AddString( str );
  2280. str = (*it_var5++).c_str(); str = str.Trim();
  2281. if( str!="" && pVariantsManager->IsExistVar(str) ) pListBox->AddString( str );
  2282. str = (*it_var6++).c_str(); str = str.Trim();
  2283. if( str!="" && pVariantsManager->IsExistVar(str) ) pListBox->AddString( str );
  2284. str = (*it_var7++).c_str(); str = str.Trim();
  2285. if( str!="" && pVariantsManager->IsExistVar(str) ) pListBox->AddString( str );
  2286. str = (*it_var8++).c_str(); str = str.Trim();
  2287. if( str!="" && pVariantsManager->IsExistVar(str) ) pListBox->AddString( str );
  2288. str = (*it_var9++).c_str(); str = str.Trim();
  2289. if( str!="" && pVariantsManager->IsExistVar(str) ) pListBox->AddString( str );
  2290. str = (*it_var10++).c_str(); str = str.Trim();
  2291. if( str!="" && pVariantsManager->IsExistVar(str) ) pListBox->AddString( str );
  2292. //11
  2293. str = (*it_var11++).c_str(); str = str.Trim();
  2294. if( str!="" && pVariantsManager->IsExistVar(str) ) pListBox->AddString( str );
  2295. str = (*it_var12++).c_str(); str = str.Trim();
  2296. if( str!="" && pVariantsManager->IsExistVar(str) ) pListBox->AddString( str );
  2297. str = (*it_var13++).c_str(); str = str.Trim();
  2298. if( str!="" && pVariantsManager->IsExistVar(str) ) pListBox->AddString( str );
  2299. str = (*it_var14++).c_str(); str = str.Trim();
  2300. if( str!="" && pVariantsManager->IsExistVar(str) ) pListBox->AddString( str );
  2301. str = (*it_var15++).c_str(); str = str.Trim();
  2302. if( str!="" && pVariantsManager->IsExistVar(str) ) pListBox->AddString( str );
  2303. str = (*it_var16++).c_str(); str = str.Trim();
  2304. if( str!="" && pVariantsManager->IsExistVar(str) ) pListBox->AddString( str );
  2305. str = (*it_var17++).c_str(); str = str.Trim();
  2306. if( str!="" && pVariantsManager->IsExistVar(str) ) pListBox->AddString( str );
  2307. str = (*it_var18++).c_str(); str = str.Trim();
  2308. if( str!="" && pVariantsManager->IsExistVar(str) ) pListBox->AddString( str );
  2309. str = (*it_var19++).c_str(); str = str.Trim();
  2310. if( str!="" && pVariantsManager->IsExistVar(str) ) pListBox->AddString( str );
  2311. str = (*it_var20++).c_str(); str = str.Trim();
  2312. if( str!="" && pVariantsManager->IsExistVar(str) ) pListBox->AddString( str );
  2313. //21
  2314. str = (*it_var21++).c_str(); str = str.Trim();
  2315. if( str!="" && pVariantsManager->IsExistVar(str) ) pListBox->AddString( str );
  2316. str = (*it_var22++).c_str(); str = str.Trim();
  2317. if( str!="" && pVariantsManager->IsExistVar(str) ) pListBox->AddString( str );
  2318. str = (*it_var23++).c_str(); str = str.Trim();
  2319. if( str!="" && pVariantsManager->IsExistVar(str) ) pListBox->AddString( str );
  2320. str = (*it_var24++).c_str(); str = str.Trim();
  2321. if( str!="" && pVariantsManager->IsExistVar(str) ) pListBox->AddString( str );
  2322. str = (*it_var25++).c_str(); str = str.Trim();
  2323. if( str!="" && pVariantsManager->IsExistVar(str) ) pListBox->AddString( str );
  2324. str = (*it_var26++).c_str(); str = str.Trim();
  2325. if( str!="" && pVariantsManager->IsExistVar(str) ) pListBox->AddString( str );
  2326. str = (*it_var27++).c_str(); str = str.Trim();
  2327. if( str!="" && pVariantsManager->IsExistVar(str) ) pListBox->AddString( str );
  2328. str = (*it_var28++).c_str(); str = str.Trim();
  2329. if( str!="" && pVariantsManager->IsExistVar(str) ) pListBox->AddString( str );
  2330. str = (*it_var29++).c_str(); str = str.Trim();
  2331. if( str!="" && pVariantsManager->IsExistVar(str) ) pListBox->AddString( str );
  2332. str = (*it_var30++).c_str(); str = str.Trim();
  2333. if( str!="" && pVariantsManager->IsExistVar(str) ) pListBox->AddString( str );
  2334. }
  2335. }
  2336. for( it_str_doset=list_str_doset.begin(),it_str_dostatus=list_str_dostatus.begin()
  2337. ,it_int_alarmdata=list_int_alarmdata.begin(),it_int_resumedata=list_int_resumedata.begin()
  2338. ,it_str_reserved1=list_str_reserved1.begin(),it_str_reserved2=list_str_reserved2.begin(),it_str_reserved3=list_str_reserved3.begin()
  2339. ,it_int_reserved1=list_int_reserved1.begin(),it_int_reserved2=list_int_reserved2.begin(),it_int_reserved3=list_int_reserved3.begin()
  2340. ,it_bool_reserved1=list_bool_reserved1.begin(),it_bool_reserved2=list_bool_reserved2.begin(),it_bool_reserved3=list_bool_reserved3.begin()
  2341. ,it_var1=list_var1.begin(),it_var2=list_var2.begin(),it_var3=list_var3.begin(),it_var4=list_var4.begin(),it_var5=list_var5.begin()
  2342. ,it_var6=list_var6.begin(),it_var7=list_var7.begin(),it_var8=list_var8.begin(),it_var9=list_var9.begin(),it_var10=list_var10.begin()
  2343. ,it_var11=list_var11.begin(),it_var12=list_var12.begin(),it_var13=list_var13.begin(),it_var14=list_var14.begin(),it_var15=list_var15.begin()
  2344. ,it_var16=list_var16.begin(),it_var17=list_var17.begin(),it_var18=list_var18.begin(),it_var19=list_var19.begin(),it_var20=list_var20.begin()
  2345. ,it_var21=list_var21.begin(),it_var22=list_var22.begin(),it_var23=list_var23.begin(),it_var24=list_var24.begin(),it_var25=list_var25.begin()
  2346. ,it_var26=list_var26.begin(),it_var27=list_var27.begin(),it_var28=list_var28.begin(),it_var29=list_var29.begin(),it_var30=list_var30.begin();
  2347. it_str_doset!=list_str_doset.end(),it_str_dostatus!=list_str_dostatus.end()
  2348. ,it_int_alarmdata!=list_int_alarmdata.end(),it_int_resumedata!=list_int_resumedata.end()
  2349. ,it_str_reserved1!=list_str_reserved1.end(),it_str_reserved2!=list_str_reserved2.end(),it_str_reserved3!=list_str_reserved3.end()
  2350. ,it_int_reserved1!=list_int_reserved1.end(),it_int_reserved2!=list_int_reserved2.end(),it_int_reserved3!=list_int_reserved3.end()
  2351. ,it_bool_reserved1!=list_bool_reserved1.end(),it_bool_reserved3!=list_bool_reserved2.end(),it_bool_reserved3!=list_bool_reserved3.end()
  2352. ,it_var1!=list_var1.end(),it_var2!=list_var2.end(),it_var3!=list_var3.end(),it_var4!=list_var4.end(),it_var5!=list_var5.end()
  2353. ,it_var6!=list_var6.end(),it_var7!=list_var7.end(),it_var8!=list_var8.end(),it_var9!=list_var9.end(),it_var10!=list_var10.end()
  2354. ,it_var11!=list_var11.end(),it_var12!=list_var12.end(),it_var13!=list_var13.end(),it_var14!=list_var14.end(),it_var15!=list_var15.end()
  2355. ,it_var16!=list_var16.end(),it_var17!=list_var17.end(),it_var18!=list_var18.end(),it_var19!=list_var19.end(),it_var20!=list_var20.end()
  2356. ,it_var21!=list_var21.end(),it_var22!=list_var22.end(),it_var23!=list_var23.end(),it_var24!=list_var24.end(),it_var25!=list_var25.end()
  2357. ,it_var26!=list_var26.end(),it_var27!=list_var27.end(),it_var28!=list_var28.end(),it_var29!=list_var29.end(),it_var30!=list_var30.end();
  2358. )
  2359. {
  2360. list_str_doset.erase( it_str_doset++ );
  2361. list_str_dostatus.erase( it_str_dostatus++ );
  2362. list_int_alarmdata.erase( it_int_alarmdata++ );
  2363. list_int_resumedata.erase( it_int_resumedata++ );
  2364. list_str_reserved1.erase( it_str_reserved1++ );
  2365. list_str_reserved2.erase( it_str_reserved2++ );
  2366. list_str_reserved3.erase( it_str_reserved3++ );
  2367. list_int_reserved1.erase( it_int_reserved1++ );
  2368. list_int_reserved2.erase( it_int_reserved2++ );
  2369. list_int_reserved3.erase( it_int_reserved3++ );
  2370. list_bool_reserved1.erase( it_bool_reserved1++ );
  2371. list_bool_reserved2.erase( it_bool_reserved2++ );
  2372. list_bool_reserved3.erase( it_bool_reserved3++ );
  2373. list_var1.erase(it_var1++);
  2374. list_var2.erase(it_var2++);
  2375. list_var3.erase(it_var3++);
  2376. list_var4.erase(it_var4++);
  2377. list_var5.erase(it_var5++);
  2378. list_var6.erase(it_var6++);
  2379. list_var7.erase(it_var7++);
  2380. list_var8.erase(it_var8++);
  2381. list_var9.erase(it_var9++);
  2382. list_var10.erase(it_var10++);
  2383. list_var11.erase(it_var11++);
  2384. list_var12.erase(it_var12++);
  2385. list_var13.erase(it_var13++);
  2386. list_var14.erase(it_var14++);
  2387. list_var15.erase(it_var15++);
  2388. list_var16.erase(it_var16++);
  2389. list_var17.erase(it_var17++);
  2390. list_var18.erase(it_var18++);
  2391. list_var19.erase(it_var19++);
  2392. list_var20.erase(it_var20++);
  2393. list_var21.erase(it_var21++);
  2394. list_var22.erase(it_var22++);
  2395. list_var23.erase(it_var23++);
  2396. list_var24.erase(it_var24++);
  2397. list_var25.erase(it_var25++);
  2398. list_var26.erase(it_var26++);
  2399. list_var27.erase(it_var27++);
  2400. list_var28.erase(it_var28++);
  2401. list_var29.erase(it_var29++);
  2402. list_var30.erase(it_var30++);
  2403. }
  2404. return nRet;
  2405. }
  2406. // 如果2中有則1沒
  2407. INT CDBInterface::GetActionWithAlarmVar( CListBox *pListBox1,CListBox *pListBox2 )
  2408. {
  2409. int nCount2 = pListBox2->GetCount();
  2410. int nCount1 = pListBox1->GetCount();
  2411. for( int i = nCount1-1; i >=0; i-- )
  2412. {
  2413. pListBox1->DeleteString( i );
  2414. }
  2415. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  2416. list<string> list1,list2;
  2417. list<string>::iterator it_list1,it_list2;
  2418. int nPermitID=0;
  2419. CString strName, str;
  2420. int nCanAlarm=0;
  2421. if(!_stricmp(g_strDBType, "PGSQL"))
  2422. {
  2423. sprintf(strSQLText, "select varname,boolreserved2 from t_dev_variant");
  2424. }
  2425. else
  2426. {
  2427. sprintf(strSQLText, "select varname,boolreserved2 from t_dev_variant");
  2428. }
  2429. int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList2(strSQLText, list1, list2);
  2430. if( 0 == list1.size() || 0 == list2.size() )
  2431. {
  2432. return 0;
  2433. }
  2434. if( nRet != -1 )
  2435. {
  2436. for( it_list1 = list1.begin(),it_list2 = list2.begin(); it_list1 != list1.end(),it_list2 != list2.end(); it_list1++,it_list2++ )
  2437. {
  2438. strName = (*it_list1).c_str();
  2439. strName = strName.Trim();
  2440. str = (*it_list2).c_str();
  2441. str = str.Trim();
  2442. if( str=="0" )
  2443. nCanAlarm = 0;
  2444. else
  2445. nCanAlarm = 1;
  2446. bool bExist = false;
  2447. for( int i=0;i<nCount2;i++ )
  2448. {
  2449. pListBox2->GetText( i, str );
  2450. if( str==strName )
  2451. {
  2452. bExist = true;
  2453. break;
  2454. }
  2455. }
  2456. if( !bExist && nCanAlarm==1 )
  2457. {
  2458. pListBox1->AddString( strName );
  2459. }
  2460. }
  2461. }
  2462. for( it_list1 = list1.begin(),it_list2 = list2.begin(); it_list1 != list1.end(),it_list2 != list2.end(); )
  2463. {
  2464. list1.erase(it_list1++);
  2465. list2.erase(it_list2++);
  2466. }
  2467. return nRet;
  2468. }
  2469. INT CDBInterface::UpDownUserInfo( int iID1,int iID2 )
  2470. {
  2471. int nTemp = 10000;
  2472. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  2473. sprintf(strSQLText, "UPDATE t_user_info SET id=%d where id=%d",nTemp,iID1 );
  2474. CDBConnection::GetInstancePtr()->Execute(strSQLText);
  2475. sprintf(strSQLText, "UPDATE t_user_info SET id=%d where id=%d",iID1,iID2 );
  2476. CDBConnection::GetInstancePtr()->Execute(strSQLText);
  2477. sprintf(strSQLText, "UPDATE t_user_info SET id=%d where id=%d",iID2,nTemp );
  2478. CDBConnection::GetInstancePtr()->Execute(strSQLText);
  2479. return 1;
  2480. }
  2481. // 根據組的ID得到該組的所有设备
  2482. INT CDBInterface::GetGroupDeviceByID( CListBox *pListBox,int iGroupID )
  2483. {
  2484. int nCount = pListBox->GetCount();
  2485. for( int i = nCount-1; i >=0; i-- )
  2486. {
  2487. pListBox->DeleteString( i );
  2488. }
  2489. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  2490. list<string> list1;
  2491. list<string>::iterator it_list1;
  2492. int nPermitID=0;
  2493. CString strPermitName, strDesc, str;
  2494. if(!_stricmp(g_strDBType, "PGSQL"))
  2495. {
  2496. sprintf(strSQLText, "select uid from t_role_equip where id = %d /*limit 1*/", iGroupID);
  2497. }
  2498. else
  2499. {
  2500. sprintf(strSQLText, "select top 1 uid from t_role_equip where id = %d", iGroupID);
  2501. }
  2502. int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList1(strSQLText, list1);
  2503. if( 0 == list1.size() )
  2504. {
  2505. return 0;
  2506. }
  2507. if( nRet != -1 )
  2508. {
  2509. for( it_list1 = list1.begin(); it_list1 != list1.end(); it_list1++ )
  2510. {
  2511. strDesc = (*it_list1).c_str();
  2512. strDesc = strDesc.Trim();
  2513. int nS=0,nE=0;
  2514. for( int i=0;i<strDesc.GetLength();i++ )
  2515. {
  2516. if( strDesc[i]=='-' )
  2517. {
  2518. nE = i;
  2519. str = strDesc.Mid( nS,nE-nS );
  2520. nS = nE+1;
  2521. nPermitID = atoi(str);
  2522. GetPermitNameByID( strPermitName, nPermitID );
  2523. if( strPermitName!="" && strPermitName[0]!='*' )
  2524. {
  2525. pListBox->AddString( strPermitName );
  2526. }
  2527. }
  2528. }
  2529. str = strDesc.Mid( nS,strDesc.GetLength()-nS );
  2530. if( str!="" )
  2531. {
  2532. nPermitID = atoi(str);
  2533. GetPermitNameByID( strPermitName,nPermitID );
  2534. if( strPermitName[0]!='*' )
  2535. {
  2536. pListBox->AddString( strPermitName );
  2537. }
  2538. }
  2539. }
  2540. }
  2541. for( it_list1 = list1.begin(); it_list1 != list1.end(); )
  2542. {
  2543. list1.erase(it_list1++);
  2544. }
  2545. return 0;
  2546. }
  2547. // 如果2中有則1沒
  2548. INT CDBInterface::GetGroupDeviceByID( CListBox *pListBox1,CListBox *pListBox2 )
  2549. {
  2550. int nCount2 = pListBox2->GetCount();
  2551. int nCount1 = pListBox1->GetCount();
  2552. for( int i = nCount1-1; i >=0; i-- )
  2553. {
  2554. pListBox1->DeleteString( i );
  2555. }
  2556. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  2557. list<string> list1;
  2558. list<string>::iterator it_list1;
  2559. int nPermitID=0;
  2560. CString strName, str;
  2561. if(!_stricmp(g_strDBType, "PGSQL"))
  2562. {
  2563. sprintf(strSQLText, "select purview_name from t_user_purview");
  2564. }
  2565. else
  2566. {
  2567. sprintf(strSQLText, "select purview_name from t_user_purview");
  2568. }
  2569. int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList1(strSQLText, list1);
  2570. if( 0 == list1.size() )
  2571. {
  2572. return 0;
  2573. }
  2574. if( nRet != -1 )
  2575. {
  2576. for( it_list1 = list1.begin(); it_list1 != list1.end(); it_list1++ )
  2577. {
  2578. strName = (*it_list1).c_str();
  2579. strName = strName.Trim();
  2580. bool bExist = false;
  2581. for( int i=0;i<nCount2;i++ )
  2582. {
  2583. pListBox2->GetText( i, str );
  2584. if( str==strName )
  2585. {
  2586. bExist = true;
  2587. break;
  2588. }
  2589. }
  2590. if( !bExist )
  2591. {
  2592. if( strName[0]!='*' )
  2593. {
  2594. pListBox1->AddString( strName );
  2595. }
  2596. }
  2597. }
  2598. }
  2599. for( it_list1 = list1.begin(); it_list1 != list1.end(); )
  2600. {
  2601. list1.erase(it_list1++);
  2602. }
  2603. return nRet;
  2604. }
  2605. // 根據組的ID得到該組的所有用户
  2606. INT CDBInterface::GetGroupUserByID( CListBox *pListBox,int iGroupID )
  2607. {
  2608. int nCount = pListBox->GetCount();
  2609. for( int i = nCount-1; i >=0; i-- )
  2610. {
  2611. pListBox->DeleteString( i );
  2612. }
  2613. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  2614. list<string> list1;
  2615. list<string>::iterator it_list1;
  2616. int nPermitID=0;
  2617. CString strPermitName, strDesc, str;
  2618. if(!_stricmp(g_strDBType, "PGSQL"))
  2619. {
  2620. sprintf(strSQLText, "select userid from t_role_user where group_id = %d order by id", iGroupID);
  2621. }
  2622. else
  2623. {
  2624. sprintf(strSQLText, "select userid from t_role_user where group_id = %d order by id", iGroupID);
  2625. }
  2626. int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList1(strSQLText, list1);
  2627. if( 0 == list1.size() )
  2628. {
  2629. return 0;
  2630. }
  2631. if( nRet != -1 )
  2632. {
  2633. for( it_list1 = list1.begin(); it_list1 != list1.end(); it_list1++ )
  2634. {
  2635. strDesc = (*it_list1).c_str();
  2636. strDesc = strDesc.Trim();
  2637. pListBox->AddString( strDesc );
  2638. }
  2639. }
  2640. for( it_list1 = list1.begin(); it_list1 != list1.end(); )
  2641. {
  2642. list1.erase(it_list1++);
  2643. }
  2644. return 0;
  2645. }
  2646. // 如果2中有則1沒
  2647. INT CDBInterface::GetGroupUserByID( CListBox *pListBox1,CListBox *pListBox2 )
  2648. {
  2649. int nCount2 = pListBox2->GetCount();
  2650. int nCount1 = pListBox1->GetCount();
  2651. for( int i = nCount1-1; i >=0; i-- )
  2652. {
  2653. pListBox1->DeleteString( i );
  2654. }
  2655. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  2656. list<string> list1;
  2657. list<string>::iterator it_list1;
  2658. int nPermitID=0;
  2659. CString strName, str;
  2660. if(!_stricmp(g_strDBType, "PGSQL"))
  2661. {
  2662. sprintf(strSQLText, "select uid from t_user_info order by id");
  2663. }
  2664. else
  2665. {
  2666. sprintf(strSQLText, "select uid from t_user_info order by id");
  2667. }
  2668. int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList1(strSQLText, list1);
  2669. if( 0 == list1.size() )
  2670. {
  2671. return 0;
  2672. }
  2673. if( nRet != -1 )
  2674. {
  2675. for( it_list1 = list1.begin(); it_list1 != list1.end(); it_list1++ )
  2676. {
  2677. strName = (*it_list1).c_str();
  2678. strName = strName.Trim();
  2679. bool bExist = false;
  2680. for( int i=0;i<nCount2;i++ )
  2681. {
  2682. pListBox2->GetText( i, str );
  2683. if( str==strName )
  2684. {
  2685. bExist = true;
  2686. break;
  2687. }
  2688. }
  2689. if( !bExist && strName!="admin" )
  2690. {
  2691. pListBox1->AddString( strName );
  2692. }
  2693. }
  2694. }
  2695. for( it_list1 = list1.begin(); it_list1 != list1.end(); )
  2696. {
  2697. list1.erase(it_list1++);
  2698. }
  2699. return nRet;
  2700. }
  2701. //获取指定厂家的设备型号ID
  2702. INT CDBInterface::GetDriverName( int nDriverID, CString &sDriverName )
  2703. {
  2704. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  2705. list<string> list1;
  2706. list<string>::iterator it;
  2707. if (!_stricmp(m_chDBType, "SQL SERVER"))
  2708. {
  2709. sprintf(strSQLText, "select top 1 drivename from t_dev_drive where id = %d", nDriverID );
  2710. }
  2711. else if (!_stricmp(m_chDBType, "ACCESS97"))
  2712. {
  2713. sprintf(strSQLText, "select top 1 drivename from t_dev_drive where id = %d", nDriverID );
  2714. }
  2715. else if (!_stricmp(m_chDBType, "ACCESS2000"))
  2716. {
  2717. sprintf(strSQLText, "select top 1 drivename from t_dev_drive where id = %d", nDriverID );
  2718. }
  2719. else if(!_stricmp(m_chDBType, "PGSQL"))
  2720. {
  2721. sprintf(strSQLText, "select drivename from t_dev_drive where id = %d limit 1", nDriverID );
  2722. }
  2723. int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList1(strSQLText, list1);
  2724. if( 0 == list1.size() )
  2725. {
  2726. return 0;
  2727. }
  2728. if( nRet != -1 )
  2729. {
  2730. sDriverName = list1.begin()->c_str();
  2731. //strcpy( pDriverName, list1.begin()->c_str() );
  2732. }
  2733. for( it = list1.begin(); it != list1.end(); )
  2734. {
  2735. list1.erase(it++);
  2736. }
  2737. return nRet;
  2738. }
  2739. //获取指定驱动ID和厂家ID的厂家名称
  2740. INT CDBInterface::GetFactoryName( int nDriverID, int nFactoryID, CString &sFactoryName )
  2741. {
  2742. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  2743. list<string> list1;
  2744. list<string>::iterator it;
  2745. if (!_stricmp(m_chDBType, "SQL SERVER"))
  2746. {
  2747. sprintf(strSQLText, "select top 1 factoryname from t_dev_factory where deviceid = %d and factoryid = %d", nDriverID, nFactoryID );
  2748. }
  2749. else if (!_stricmp(m_chDBType, "ACCESS97"))
  2750. {
  2751. sprintf(strSQLText, "select top 1 factoryname from t_dev_factory where deviceid = %d and factoryid = %d", nDriverID, nFactoryID );
  2752. }
  2753. else if (!_stricmp(m_chDBType, "ACCESS2000"))
  2754. {
  2755. sprintf(strSQLText, "select top 1 factoryname from t_dev_factory where deviceid = %d and factoryid = %d", nDriverID, nFactoryID );
  2756. }
  2757. else if(!_stricmp(m_chDBType, "PGSQL"))
  2758. {
  2759. sprintf(strSQLText, "select factoryname from t_dev_factory where deviceid = %d and factoryid = %d limit 1", nDriverID, nFactoryID );
  2760. }
  2761. int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList1(strSQLText, list1);
  2762. if( 0 == list1.size() )
  2763. {
  2764. return 0;
  2765. }
  2766. if( nRet != -1 )
  2767. {
  2768. sFactoryName = list1.begin()->c_str();
  2769. //strcpy( pFactoryName, list1.begin()->c_str() );
  2770. }
  2771. for( it = list1.begin(); it != list1.end(); )
  2772. {
  2773. list1.erase(it++);
  2774. }
  2775. return nRet;
  2776. }
  2777. //获取指定驱动ID,厂家ID和设备类型ID的名称
  2778. INT CDBInterface::GetDevicesName( int nDriverID, int nFactoryID, int nDevicesID,CString &sDevicesName )
  2779. {
  2780. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  2781. list<string> list1;
  2782. list<string>::iterator it;
  2783. if (!_stricmp(m_chDBType, "SQL SERVER"))
  2784. {
  2785. sprintf(strSQLText, "select top 1 equiptype from t_dev_type where id = %d and factoryid = %d and driveid = %d", nDevicesID,nFactoryID, nDriverID );
  2786. }
  2787. else if (!_stricmp(m_chDBType, "ACCESS97"))
  2788. {
  2789. sprintf(strSQLText, "select top 1 equiptype from t_dev_type where id = %d and factoryid = %d and driveid = %d", nDevicesID,nFactoryID, nDriverID );
  2790. }
  2791. else if (!_stricmp(m_chDBType, "ACCESS2000"))
  2792. {
  2793. sprintf(strSQLText, "select top 1 equiptype from t_dev_type where id = %d and factoryid = %d and driveid = %d", nDevicesID,nFactoryID, nDriverID );
  2794. }
  2795. else if(!_stricmp(m_chDBType, "PGSQL"))
  2796. {
  2797. sprintf(strSQLText, "select equiptype from t_dev_type where id = %d and factoryid = %d and driveid = %d limit 1", nDevicesID,nFactoryID, nDriverID );
  2798. }
  2799. int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList1(strSQLText, list1);
  2800. if( 0 == list1.size() )
  2801. {
  2802. return 0;
  2803. }
  2804. if( nRet != -1 )
  2805. {
  2806. sDevicesName = list1.begin()->c_str();
  2807. //strcpy( pDevicesName, list1.begin()->c_str() );
  2808. }
  2809. for( it = list1.begin(); it != list1.end(); )
  2810. {
  2811. list1.erase(it++);
  2812. }
  2813. return nRet;
  2814. }
  2815. //当编辑用户时要更新其它表的对应用户的帐号
  2816. INT CDBInterface::UpdateOtherTableUserName( CHAR *pUserID_Old,CHAR *pUserID_New )
  2817. {
  2818. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  2819. sprintf(strSQLText, "UPDATE t_role_user SET userid=\'%s\' where userid=\'%s\'",
  2820. pUserID_New, pUserID_Old);
  2821. return CDBConnection::GetInstancePtr()->Execute(strSQLText);
  2822. }
  2823. };