1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265 |
- /*************************************************************
- /* Copyright (C), 2008-2010, StoneU Tech. Co., Ltd.
- /* 文件名: DBInterface.h
- /* 作者: Jesse
- /* 创建日期: 2010-08-02
- /* 版本号: V1.0
- /* 描述: 实现多种数据库的支持
- /* 其它:
- /* 主要类模块: CDBInterface
- /* 历史修改记录:
- 作者 时间 版本 描述
- Jesse 10/08/02 1.0 创建这个模块
- ***************************************************************/
- #include "stdafx.h"
- #include "DBInterface.h"
- namespace DBInterface
- {
- CDBInterface* CDBInterface::m_pDBInterface = NULL;
- // 静态成员函数,提供全局访问的接口
- CDBInterface* CDBInterface::GetInstancePtr()
- {
- if( NULL == m_pDBInterface )
- {
- m_pDBInterface = new CDBInterface();
- }
- return m_pDBInterface;
- }
- // 释放资源
- void CDBInterface::Release()
- {
- if( m_pDBInterface )
- delete m_pDBInterface;
- m_pDBInterface = NULL;
- }
- // 设置数据库类型
- void CDBInterface::SetDBType(char *pDBType)
- {
- strcpy(m_chDBType, pDBType);
- }
- //插入设备资料
- INT CDBInterface::InsertDevInfo(int nID, CHAR *pUid, int nPort, int nAddr, CHAR *pDevName, int nDevTypeID,
- int nRate, int nDataBit, int nStopBit, int nParityBit, int nRsMode,
- CHAR *pIPAddr, int nIPPort, int nCommMode, int nDevFlag, int nSpecialDev,
- int nTimeout, int nIsuse, CHAR *pProtocalName, CHAR *pIniName,
- CHAR *pReserved1, CHAR *pReserved2, CHAR *pReserved3, CHAR *pReserved4, CHAR *pReserved5,
- CHAR *pReserved6, CHAR *pReserved7, CHAR *pReserved8, CHAR *pReserved9, CHAR *pReserved10,
- int nReserved1, int nReserved2, int nReserved3, int nReserved4, int nReserved5,
- int nReserved6, int nReserved7, int nReserved8, int nReserved9, int nReserved10,
- int bReserved1, int bReserved2, int bReserved3, int bReserved4, int bReserved5,
- int bReserved6, int bReserved7, int bReserved8, int bReserved9, int bReserved10)
- {
- CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
- sprintf(strSQLText, "insert into t_dev_property(id, uid, port, devideaddr, devicename, " \
- "devicetype, baudrate, databit, stopbit, paritybit, ip, ipport, " \
- "commmode, deviceflag, specialdevice, timeout, isuse, protocoldllname, ininame, " \
- "strreserved1, strreserved2, strreserved3, strreserved4, strreserved5, " \
- "strreserved6, strreserved7, strreserved8, strreserved9, strreserved10, " \
- "intreserved1, intreserved2, intreserved3, intreserved4, intreserved5, " \
- "intreserved6, intreserved7, intreserved8, intreserved9, intreserved10, " \
- "boolreserved1, boolreserved2, boolreserved3, boolreserved4, boolreserved5, " \
- "boolreserved6, boolreserved7, boolreserved8, boolreserved9, boolreserved10 " \
- ") values (" \
- "%d, \'%s\', %d, %d, \'%s\', " \
- "%d, %d, %d, %d, %d, \'%s\', %d, " \
- "%d, %d, \'%d\', %d, \'%d\', \'%s\', \'%s\', " \
- "\'%s\', \'%s\', \'%s\', \'%s\', \'%s\', " \
- "\'%s\', \'%s\', \'%s\', \'%s\', \'%s\', " \
- "%d, %d, %d, %d, %d, " \
- "%d, %d, %d, %d, %d, " \
- "\'%d\', \'%d\', \'%d\', \'%d\', \'%d\', " \
- "\'%d\', \'%d\', \'%d\', \'%d\', \'%d\' " \
- ")",
- nID, pUid, nPort, nAddr, pDevName, nDevTypeID, nRate, nDataBit, nStopBit,
- nParityBit, pIPAddr, nIPPort, nCommMode, nDevFlag, nSpecialDev,
- nTimeout, nIsuse, pProtocalName, pIniName,
- pReserved1, pReserved2, pReserved3, pReserved4, pReserved5,
- pReserved6, pReserved7, pReserved8, pReserved9, pReserved10,
- nReserved1, nReserved2, nReserved3, nReserved4, nReserved5,
- nReserved6, nReserved7, nReserved8, nReserved9, nReserved10,
- bReserved1, bReserved2, bReserved3, bReserved4, bReserved5,
- bReserved6, bReserved7, bReserved8, bReserved9, bReserved10
- );
- return CDBConnection::GetInstancePtr()->Execute(strSQLText);
- }
- //修改设备资料,标准的SQL,多种数据库都一样
- INT CDBInterface::EditDevInfo(CHAR *pOldUid, CHAR *pNewUid, int nPort, int nAddr, CHAR *pDevName, int nDevTypeID,
- int nRate, int nDataBit, int nStopBit, int nParityBit, int nRsMode,
- CHAR *pIPAddr, int nIPPort, int nCommMode, int nDevFlag, int nSpecialDev,
- int nTimeout, int nIsuse, CHAR *pProtocalName, CHAR *pIniName,
- CHAR *pReserved1, CHAR *pReserved2, CHAR *pReserved3, CHAR *pReserved4, CHAR *pReserved5,
- CHAR *pReserved6, CHAR *pReserved7, CHAR *pReserved8, CHAR *pReserved9, CHAR *pReserved10,
- int nReserved1, int nReserved2, int nReserved3, int nReserved4, int nReserved5,
- int nReserved6, int nReserved7, int nReserved8, int nReserved9, int nReserved10,
- int bReserved1, int bReserved2, int bReserved3, int bReserved4, int bReserved5,
- int bReserved6, int bReserved7, int bReserved8, int bReserved9, int bReserved10)
- {
- CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
- sprintf(strSQLText, "update t_dev_property set uid = \'%s\', port = %d, devideaddr = %d, devicename = \'%s\', " \
- "devicetype = %d, baudrate = %d, databit = %d, stopbit = %d, paritybit = %d, ip = \'%s\', ipport = %d, " \
- "commmode = %d, deviceflag = %d, specialdevice = \'%d\', timeout = %d, isuse = \'%d\', protocoldllname = \'%s\', " \
- "ininame = \'%s\', " \
- "strreserved1 = \'%s\', strreserved2 = \'%s\', strreserved3 = \'%s\', strreserved4 = \'%s\', strreserved5 = \'%s\', " \
- "strreserved6 = \'%s\', strreserved7 = \'%s\', strreserved8 = \'%s\', strreserved9 = \'%s\', strreserved10 = \'%s\', " \
- "intreserved1 = %d, intreserved2 = %d, intreserved3 = %d, intreserved4 = %d, intreserved5 = %d, " \
- "intreserved6 = %d, intreserved7 = %d, intreserved8 = %d, intreserved9 = %d, intreserved10 = %d, " \
- "boolreserved1 = \'%d\', boolreserved2 = \'%d\', boolreserved3 = \'%d\', boolreserved4 = \'%d\', boolreserved5 = \'%d\', " \
- "boolreserved6 = \'%d\', boolreserved7 = \'%d\', boolreserved8 = \'%d\', boolreserved9 = \'%d\', boolreserved10 = \'%d\' " \
- "where uid = \'%s\'",
- pNewUid, nPort, nAddr, pDevName, nDevTypeID, nRate, nDataBit, nStopBit,
- nParityBit, pIPAddr, nIPPort, nCommMode, nDevFlag, nSpecialDev,
- nTimeout, nIsuse, pProtocalName, pIniName,
- pReserved1, pReserved2, pReserved3, pReserved4, pReserved5,
- pReserved6, pReserved7, pReserved8, pReserved9, pReserved10,
- nReserved1, nReserved2, nReserved3, nReserved4, nReserved5,
- nReserved6, nReserved7, nReserved8, nReserved9, nReserved10,
- bReserved1, bReserved2, bReserved3, bReserved4, bReserved5,
- bReserved6, bReserved7, bReserved8, bReserved9, bReserved10,
- pOldUid);
- return CDBConnection::GetInstancePtr()->Execute(strSQLText);
- }
- //删除设备资料
- INT CDBInterface::DeleteDevInfo(CHAR *pUid)
- {
- CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
- sprintf(strSQLText, "delete from t_dev_property where uid = \'%s\'", pUid);
- return CDBConnection::GetInstancePtr()->Execute(strSQLText);
- }
- //插入变量信息
- INT CDBInterface::InsertVarInfo(int nID, int nDevTypeID,CHAR *pVarName,CHAR *pVarDesc,int nVarTypeID,
- int nMinValues,int nMaxValues,int nMaxConvtRate,int nMinConvtRate,int nCollectFreq,
- int bIsDDE,int nRegStartAddr,int nWaringLevel,CHAR *pSetValue,CHAR *pUnit,
- CHAR *pUid,CHAR *pRelatepage,int bRecCurve,int nRegNum,CHAR *pOnDesc,
- CHAR *pOffDesc,int nUpperLimit,int nLowerLimit,int nChildid,int nVarItemID,
- int nNormalState,CHAR *pFields,CHAR *pSnmpOid,int nRearm,int nOffset,
- int nFuncCode,int nDataLen,float fCoef,int bRealtimeFlag,int bIsSave,
- CHAR *pRs232Cmd,CHAR *pRs232Type,int nRs232Index,int nIdentifyTime,int nRedetectTime,
- int bIsNormalAlarm,int nPurview,
- CHAR *pReserved1,CHAR *pReserved2,CHAR *pReserved3,CHAR *pReserved4,CHAR *pReserved5,
- CHAR *pReserved6,CHAR *pReserved7,CHAR *pReserved8,CHAR *pReserved9,CHAR *pReserved10,
- int nReserved1,int nReserved2,int nReserved3,int nReserved4,int nReserved5,
- int nReserved6,int nReserved7,int nReserved8,int nReserved9,int nReserved10,
- int bReserved1,int bReserved2,int bReserved3,int bReserved4,int bReserved5,
- int bReserved6,int bReserved7,int bReserved8,int bReserved9,int bReserved10 )
- {
- CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
- sprintf(strSQLText, "insert into t_dev_variant(id, devtypeid, varname, description, vartypeid, "\
- "minvalues, maxvalues,maxconvtrate, minconvtrate, collectfrequence, " \
- "isdde, address,warnlevel, setvalue, unit, " \
- "uid, relatepage, reccurve, registernum,ondesc, " \
- "offdesc,upperlimit,lowerlimit,childid,var_item_id, "\
- "normalstate,fields,snmpoid,rearm,offsets, "\
- "funcid,datalen,coefficient,realtimeflag,issave, "\
- "rs232cmd,rs232type,rs232index,identifytime,redetecttime, "\
- "normalisnotice,readonly, "\
- "strreserved1, strreserved2, strreserved3, strreserved4, strreserved5, " \
- "strreserved6, strreserved7, strreserved8, strreserved9, strreserved10, " \
- "intreserved1, intreserved2, intreserved3, intreserved4, intreserved5, " \
- "intreserved6, intreserved7, intreserved8, intreserved9, intreserved10, " \
- "boolreserved1, boolreserved2, boolreserved3, boolreserved4, boolreserved5, " \
- "boolreserved6, boolreserved7, boolreserved8, boolreserved9, boolreserved10 " \
- ") values (" \
- "%d, %d, \'%s\',\'%s\', %d, " \
- "%d, %d, %d, %d, %d, " \
- "\'%d\', %d, %d,\'%s\', \'%s\', " \
- "\'%s\', \'%s\',\'%d\', %d, \'%s\', " \
- "\'%s\', %d,%d, %d, %d, " \
- "%d, \'%s\', \'%s\',%d, %d, " \
- "%d, %d, %f, \'%d\', \'%d\', " \
- "\'%s\', \'%s\',%d, %d, %d, " \
- "\'%d\', \'%d\', " \
- "\'%s\', \'%s\', \'%s\', \'%s\', \'%s\', " \
- "\'%s\', \'%s\', \'%s\', \'%s\', \'%s\', " \
- "%d, %d, %d, %d, %d, " \
- "%d, %d, %d, %d, %d, " \
- "\'%d\', \'%d\', \'%d\', \'%d\', \'%d\', " \
- "\'%d\', \'%d\', \'%d\', \'%d\', \'%d\' " \
- ")",
- nID, nDevTypeID, pVarName, pVarDesc, nVarTypeID,
- nMinValues,nMaxValues,nMaxConvtRate,nMinConvtRate,nCollectFreq,
- bIsDDE,nRegStartAddr,nWaringLevel,pSetValue,pUnit,
- pUid,pRelatepage,bRecCurve,nRegNum,pOnDesc,
- pOffDesc,nUpperLimit,nLowerLimit,nChildid,nVarItemID,
- nNormalState,pFields,pSnmpOid,nRearm,nOffset,
- nFuncCode,nDataLen,fCoef,bRealtimeFlag,bIsSave,
- pRs232Cmd,pRs232Type,nRs232Index,nIdentifyTime,nRedetectTime,
- bIsNormalAlarm,nPurview,
- pReserved1, pReserved2, pReserved3, pReserved4, pReserved5,
- pReserved6, pReserved7, pReserved8, pReserved9, pReserved10,
- nReserved1, nReserved2, nReserved3, nReserved4, nReserved5,
- nReserved6, nReserved7, nReserved8, nReserved9, nReserved10,
- bReserved1, bReserved2, bReserved3, bReserved4, bReserved5,
- bReserved6, bReserved7, bReserved8, bReserved9, bReserved10
- );
- int a=0;
- return CDBConnection::GetInstancePtr()->Execute(strSQLText);
- }
- //插入数据记录
- INT CDBInterface::InsertDataRecord(
- CHAR* pDevName, // 设备名称
- CHAR* pHappenTime, // 发生时间
- CHAR* pVarName, // 变量名称
- CHAR *pVarDesc, // 变量描述
- double dbCurrValue // 当前值
- )
- {
- CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
- int iMaxID;
- CHAR chMaxID[MAX_ID] = {0};
- GetMaxID("t_data_rec", "id", chMaxID);
- if( 0 == atoi(chMaxID) )
- {
- iMaxID = 1;
- }
- else
- {
- iMaxID = atoi(chMaxID) + 1;
- }
- sprintf(strSQLText, "insert into t_data_rec(id,devname, happentime,varname,vardesc,datavalue) values(" \
- "%d, \'%s\', \'%s\', \'%s\', \'%s\', %.1f)",
- iMaxID, pDevName, pHappenTime,pVarName, pVarDesc, dbCurrValue );
- //LOG4C((LOG_NOTICE, "InsertDataRecord: %s", strSQLText ));
- return CDBConnection::GetInstancePtr()->Execute(strSQLText);
- }
- //获取设备类型ID
- INT CDBInterface::GetDevTypeID( CHAR *pDevTypeName, CHAR *pDevTypeID )
- {
- CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
- list<string> list1;
- list<string>::iterator it;
- if (!_stricmp(m_chDBType, "SQL SERVER"))
- {
- sprintf(strSQLText, "select top 1 id from t_dev_type where equiptype = \'%s\'", pDevTypeName);
- }
- else if (!_stricmp(m_chDBType, "ACCESS97"))
- {
- sprintf(strSQLText, "select top 1 id from t_dev_type where equiptype = \'%s\'", pDevTypeName);
- }
- else if (!_stricmp(m_chDBType, "ACCESS2000"))
- {
- sprintf(strSQLText, "select top 1 id from t_dev_type where equiptype = \'%s\'", pDevTypeName);
- }
- else if(!_stricmp(m_chDBType, "PGSQL"))
- {
- sprintf(strSQLText, "select id from t_dev_type where equiptype = \'%s\' limit 1", pDevTypeName);
- }
- int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList1(strSQLText, list1);
- if( 0 == list1.size() )
- {
- return 0;
- }
- if( nRet != -1 )
- {
- strcpy(pDevTypeID, list1.begin()->c_str());
- }
- for( it = list1.begin(); it != list1.end(); )
- {
- list1.erase(it++);
- }
- return nRet;
- }
- //获取指定厂家的设备型号ID
- INT CDBInterface::GetDevTypeID( int nDriverID, int nFactoryID, CHAR *pDevTypeName, CHAR *pDevTypeID )
- {
- CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
- list<string> list1;
- list<string>::iterator it;
- if (!_stricmp(m_chDBType, "SQL SERVER"))
- {
- sprintf(strSQLText, "select top 1 id from t_dev_type where driveid = %d and factoryid = %d and equiptype = \'%s\'",
- nDriverID, nFactoryID, pDevTypeName);
- }
- else if (!_stricmp(m_chDBType, "ACCESS97"))
- {
- sprintf(strSQLText, "select top 1 id from t_dev_type where driveid = %d and factoryid = %d and equiptype = \'%s\'",
- nDriverID, nFactoryID, pDevTypeName);
- }
- else if (!_stricmp(m_chDBType, "ACCESS2000"))
- {
- sprintf(strSQLText, "select top 1 id from t_dev_type where driveid = %d and factoryid = %d and equiptype = \'%s\'",
- nDriverID, nFactoryID, pDevTypeName);
- }
- else if(!_stricmp(m_chDBType, "PGSQL"))
- {
- sprintf(strSQLText, "select id from t_dev_type where driveid = %d and factoryid = %d and equiptype = \'%s\' limit 1",
- nDriverID, nFactoryID, pDevTypeName);
- }
- int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList1(strSQLText, list1);
- if( 0 == list1.size() )
- {
- return 0;
- }
- if( nRet != -1 )
- {
- strcpy(pDevTypeID, list1.begin()->c_str());
- }
- for( it = list1.begin(); it != list1.end(); )
- {
- list1.erase(it++);
- }
- return nRet;
- }
- //获取设备名称
- INT CDBInterface::GetDevName( CHAR *pDevUID, CHAR *pDevName )
- {
- CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
- list<string> list1;
- list<string>::iterator it;
- if (!_stricmp(m_chDBType, "SQL SERVER"))
- {
- sprintf(strSQLText, "select top 1 devicename from t_dev_property where uid = \'%s\'", pDevUID);
- }
- else if (!_stricmp(m_chDBType, "ACCESS97"))
- {
- sprintf(strSQLText, "select top 1 devicename from t_dev_property where uid = \'%s\'", pDevUID);
- }
- else if (!_stricmp(m_chDBType, "ACCESS2000"))
- {
- sprintf(strSQLText, "select top 1 devicename from t_dev_property where uid = \'%s\'", pDevUID);
- }
- else if(!_stricmp(m_chDBType, "PGSQL"))
- {
- sprintf(strSQLText, "select devicename from t_dev_property where uid = \'%s\' LIMIT 1", pDevUID);
- }
- int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList1(strSQLText, list1);
- if( 0 == list1.size() )
- {
- return 0;
- }
- if( nRet != -1 )
- {
- strcpy(pDevName, list1.begin()->c_str());
- }
- for( it = list1.begin(); it != list1.end(); )
- {
- list1.erase(it++);
- }
- return nRet;
- }
- //获取设备UID
- INT CDBInterface::GetDevUID( CHAR *pDevName, CHAR *pDevUID )
- {
- CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
- list<string> list1;
- list<string>::iterator it;
- if (!_stricmp(m_chDBType, "SQL SERVER"))
- {
- sprintf(strSQLText, "select top 1 uid from t_dev_property where devicename = \'%s\'", pDevName);
- }
- else if (!_stricmp(m_chDBType, "ACCESS97"))
- {
- sprintf(strSQLText, "select top 1 uid from t_dev_property where devicename = \'%s\'", pDevName);
- }
- else if (!_stricmp(m_chDBType, "ACCESS2000"))
- {
- sprintf(strSQLText, "select top 1 uid from t_dev_property where devicename = \'%s\'", pDevName);
- }
- else if(!_stricmp(m_chDBType, "PGSQL"))
- {
- sprintf(strSQLText, "select uid from t_dev_property where devicename = \'%s\' LIMIT 1", pDevName);
- }
- int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList1(strSQLText, list1);
- if( 0 == list1.size() )
- {
- return 0;
- }
- if( nRet != -1 )
- {
- strcpy(pDevUID, list1.begin()->c_str());
- }
- for( it = list1.begin(); it != list1.end(); )
- {
- list1.erase(it++);
- }
- return nRet;
- }
- //获取表最大的ID, 通用函数
- INT CDBInterface::GetMaxID( CHAR *pTableName, CHAR *pFieldName, CHAR *pMaxID )
- {
- CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
- list<string> list1;
- list<string>::iterator it;
- sprintf(strSQLText, "select max(%s) as maxid from %s", pFieldName, pTableName);
- int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList1(strSQLText, list1);
- if( 0 == list1.size() )
- {
- return 0;
- }
- if( nRet != -1 )
- {
- strcpy(pMaxID, list1.begin()->c_str());
- }
- for( it = list1.begin(); it != list1.end(); )
- {
- list1.erase(it++);
- }
- return nRet;
- }
- //获取驱动ID
- INT CDBInterface::GetDevDriveID( CHAR *pDevDriverName, CHAR *pDevDriverID )
- {
- CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
- list<string> list1;
- list<string>::iterator it;
- if (!_stricmp(m_chDBType, "SQL SERVER"))
- {
- sprintf(strSQLText, "select top 1 id from t_dev_drive where drivename = \'%s\'", pDevDriverName);
- }
- else if (!_stricmp(m_chDBType, "ACCESS97"))
- {
- sprintf(strSQLText, "select top 1 id from t_dev_drive where drivename = \'%s\'", pDevDriverName);
- }
- else if (!_stricmp(m_chDBType, "ACCESS2000"))
- {
- sprintf(strSQLText, "select top 1 id from t_dev_drive where drivename = \'%s\'", pDevDriverName);
- }
- else if(!_stricmp(m_chDBType, "PGSQL"))
- {
- sprintf(strSQLText, "select id from t_dev_drive where drivename = \'%s\' limit 1", pDevDriverName);
- }
- int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList1(strSQLText, list1);
- if( 0 == list1.size() )
- {
- return 0;
- }
- if( nRet != -1 )
- {
- strcpy(pDevDriverID, list1.begin()->c_str());
- }
- for( it = list1.begin(); it != list1.end(); )
- {
- list1.erase(it++);
- }
- return nRet;
- }
- //获取指定驱动的厂家ID
- INT CDBInterface::GetDevFactoryID( int nDriverID, CHAR *pDevFactoryName, CHAR *pDevFactoryID )
- {
- CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
- list<string> list1;
- list<string>::iterator it;
- if (!_stricmp(m_chDBType, "SQL SERVER"))
- {
- sprintf(strSQLText, "select top 1 factoryid from t_dev_factory where deviceid = %d and factoryname = \'%s\'",
- nDriverID, pDevFactoryName);
- }
- else if (!_stricmp(m_chDBType, "ACCESS97"))
- {
- sprintf(strSQLText, "select top 1 factoryid from t_dev_factory where deviceid = %d and factoryname = \'%s\'",
- nDriverID, pDevFactoryName);
- }
- else if (!_stricmp(m_chDBType, "ACCESS2000"))
- {
- sprintf(strSQLText, "select top 1 factoryid from t_dev_factory where deviceid = %d and factoryname = \'%s\'",
- nDriverID, pDevFactoryName);
- }
- else if(!_stricmp(m_chDBType, "PGSQL"))
- {
- sprintf(strSQLText, "select factoryid from t_dev_factory where deviceid = %d and factoryname = \'%s\' limit 1",
- nDriverID, pDevFactoryName);
- }
- int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList1(strSQLText, list1);
- if( 0 == list1.size() )
- {
- return 0;
- }
- if( nRet != -1 )
- {
- strcpy(pDevFactoryID, list1.begin()->c_str());
- }
- for( it = list1.begin(); it != list1.end(); )
- {
- list1.erase(it++);
- }
- return nRet;
- }
- //根据UID查找同一类型设备的个数
- INT CDBInterface::FindDevInfoByUID( CHAR *pUID, CHAR *pDevNum )
- {
- CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
- list<string> list1;
- list<string>::iterator it;
- #if 1
- if (!_stricmp(m_chDBType, "SQL SERVER"))
- {
- sprintf(strSQLText, "select uid from t_dev_property where uid like \'%s%s%s\' order by id desc", "%", pUID, "%");
- }
- else if (!_stricmp(m_chDBType, "ACCESS97"))
- {
- sprintf(strSQLText, "select uid from t_dev_property where uid like \'%s%s%s\' order by id desc", "%", pUID, "%");
- }
- else if (!_stricmp(m_chDBType, "ACCESS2000"))
- {
- sprintf(strSQLText, "select uid from t_dev_property where uid like \'%s%s%s\' order by id desc", "%", pUID, "%");
- }
- else if(!_stricmp(m_chDBType, "PGSQL"))
- {
- sprintf(strSQLText, "select uid from t_dev_property where uid like \'%s%s%s\' order by id desc", "%", pUID, "%");
- }
- #else
- if (!_stricmp(m_chDBType, "SQL SERVER"))
- {
- sprintf(strSQLText, "select count(id) as Num from t_dev_property where uid like \'%s%s%s\'", "%", pUID, "%");
- }
- else if (!_stricmp(m_chDBType, "ACCESS97"))
- {
- sprintf(strSQLText, "select count(id) as Num from t_dev_property where uid like \'%s%s%s\'", "%", pUID, "%");
- }
- else if (!_stricmp(m_chDBType, "ACCESS2000"))
- {
- sprintf(strSQLText, "select count(id) as Num from t_dev_property where uid like \'%s%s%s\'", "%", pUID, "%");
- }
- else if(!_stricmp(m_chDBType, "PGSQL"))
- {
- sprintf(strSQLText, "select count(id) as Num from t_dev_property where uid like \'%s%s%s\'", "%", pUID, "%");
- }
- #endif
- int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList1(strSQLText, list1);
- if( 0 == list1.size() )
- {
- return 0;
- }
- if( nRet != -1 )
- {
- CString s;
- int nMax=0;
- for( it = list1.begin(); it != list1.end(); )
- {
- CString sTemp = (*it++).c_str();
-
- for( int i=sTemp.GetLength()-1;i>0;i-- )
- {
- if( sTemp[i]=='.' )
- {
- int n = atoi( sTemp.Mid( i+1,sTemp.GetLength()-i ) );
- if( n>nMax )
- nMax = n;
- break;
- }
- }
- }
- s.Format( "%d",nMax );
- strcpy(pDevNum, s);
- }
- for( it = list1.begin(); it != list1.end(); )
- {
- list1.erase(it++);
- }
- return nRet;
- }
- //得到可以用的设备名称
- INT CDBInterface::FindDevNameByName( CHAR *pName, CString &sDevName,int &nDevIndex )
- {
- CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
- list<string> list1;
- list<string>::iterator it;
- if (!_stricmp(m_chDBType, "SQL SERVER"))
- {
- sprintf(strSQLText, "select devicename from t_dev_property where devicename like \'%s%s\' order by id desc", pName, "%");
- }
- else if (!_stricmp(m_chDBType, "ACCESS97"))
- {
- sprintf(strSQLText, "select devicename from t_dev_property where devicename like \'%s%s\' order by id desc", pName, "%");
- }
- else if (!_stricmp(m_chDBType, "ACCESS2000"))
- {
- sprintf(strSQLText, "select devicename from t_dev_property where devicename like \'%s%s\' order by id desc", pName, "%");
- }
- else if(!_stricmp(m_chDBType, "PGSQL"))
- {
- sprintf(strSQLText, "select devicename from t_dev_property where devicename like \'%s%s\' order by id desc", pName, "%");
- }
- int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList1(strSQLText, list1);
- if( 0 == list1.size() )
- {
- sDevName.Format( "%s1",pName );
- nDevIndex = 1;
- return 0;
- }
- if( nRet != -1 )
- {
- CString s;
- int nMax=0;
- for( it = list1.begin(); it != list1.end(); )
- {
- CString sTemp = (*it++).c_str();
- s.Format( "%s",pName );
- int n = atoi( sTemp.Right( sTemp.GetLength()-s.GetLength() ) );
- if( n>nMax )
- nMax = n;
- }
- nDevIndex = nMax+1;
- sDevName.Format( "%s%d",pName,nMax+1 );
- }
- for( it = list1.begin(); it != list1.end(); )
- {
- list1.erase(it++);
- }
- return nRet;
- }
- //得到时间计划
- INT CDBInterface::GetDatePlan( int nPlanType, CHAR *pPlanID, unsigned char nBufDate[7][24] )
- {
- CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
- list<string> list1, list2, list3, list4;
- list<string>::iterator it_list1, it_list2, it_list3, it_list4;
- sprintf(strSQLText, "select starttime, endtime, startweekofday, endweekofday " \
- "from t_plan_info where planid=\'%s\' and plantype = %d",
- pPlanID, nPlanType);
- int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList4(strSQLText, list1, list2, list3, list4);
- if( list1.size() == 0 || list2.size() == 0 || list3.size() == 0 || list4.size() == 0 )
- {
- return 0;
- }
- if( nRet != -1 )
- {
- for( it_list1 = list1.begin(), it_list2 = list2.begin(), it_list3 = list3.begin(), it_list4 = list4.begin();
- it_list1 != list1.end() && it_list2 != list2.end() && it_list3 != list3.end() && it_list4 != list4.end();
- it_list1++, it_list2++, it_list3++, it_list4++)
- {
- for( int i = atoi((*it_list3).c_str()); i < atoi((*it_list4).c_str()) + 1; i++ )
- {
- for( int j = atoi((*it_list1).c_str()); j < atoi((*it_list2).c_str()) + 1; j++ )
- {
- nBufDate[i][j] = 15;
- }
- }
- }
- }
- for( it_list1 = list1.begin(), it_list2 = list2.begin(), it_list3 = list3.begin(), it_list4 = list4.begin();
- it_list1 != list1.end(), it_list2 != list2.end(), it_list3 != list3.end(), it_list4 != list4.end(); )
- {
- list1.erase(it_list1++);
- list2.erase(it_list2++);
- list3.erase(it_list3++);
- list4.erase(it_list4++);
- }
- return nRet;
- }
- //得到时间计划
- INT CDBInterface::GetDatePlan( int nPlanType, CHAR *pUid, int nVarID, unsigned char nBufDate[7][24] )
- {
- CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
- list<string> list1, list2, list3, list4;
- list<string>::iterator it_list1, it_list2, it_list3, it_list4;
- sprintf(strSQLText, "select starttime, endtime, startweekofday, endweekofday " \
- "from t_plan_info where uid=\'%s\' and varid = %d and plantype = %d",
- pUid, nVarID, nPlanType);
- int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList4(strSQLText, list1, list2, list3, list4);
- if( list1.size() == 0 || list2.size() == 0 || list3.size() == 0 || list4.size() == 0 )
- {
- return 0;
- }
- if( nRet != -1 )
- {
- for( it_list1 = list1.begin(), it_list2 = list2.begin(), it_list3 = list3.begin(), it_list4 = list4.begin();
- it_list1 != list1.end() && it_list2 != list2.end() && it_list3 != list3.end() && it_list4 != list4.end();
- it_list1++, it_list2++, it_list3++, it_list4++ )
- {
- for( int i = atoi((*it_list3).c_str()); i < atoi((*it_list4).c_str()) + 1; i++ )
- {
- for( int j = atoi((*it_list1).c_str()); j < atoi((*it_list2).c_str()) + 1; j++ )
- {
- nBufDate[i][j] = 15;
- }
- }
- }
- }
- for( it_list1 = list1.begin(), it_list2 = list2.begin(), it_list3 = list3.begin(), it_list4 = list4.begin();
- it_list1 != list1.end(), it_list2 != list2.end(), it_list3 != list3.end(), it_list4 != list4.end(); )
- {
- list1.erase(it_list1++);
- list2.erase(it_list2++);
- list3.erase(it_list3++);
- list4.erase(it_list4++);
- }
- return nRet;
- }
- //删除原有的时间计划
- INT CDBInterface::DeleteDatePlan( int nPlanType, CHAR *pPlanID )
- {
- CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
- sprintf(strSQLText, "delete from t_plan_info where planid = \'%s\' and plantype=%d",pPlanID, nPlanType);
- return CDBConnection::GetInstancePtr()->Execute(strSQLText);
- }
- //删除原有的时间计划
- INT CDBInterface::DeleteDatePlan( int nPlanType, CString strUid, int nVarID )
- {
- CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
- sprintf(strSQLText, "delete from t_plan_info where uid = \'%s\' and varid = %d and plantype=%d", strUid, nVarID, nPlanType);
- return CDBConnection::GetInstancePtr()->Execute(strSQLText);
- }
- //插入时间计划
- INT CDBInterface::InsertDatePlan( int nPlanType, CHAR *pPlanID, int nStartHours, int nEndHours, int nStartWeek, int nEndWeek )
- {
- CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
- sprintf(strSQLText, "insert into t_plan_info(plantype, planid, starttime, endtime, " \
- "startweekofday, endweekofday) values (%d, \'%s\', %d, %d, %d, %d) ",
- nPlanType, pPlanID, nStartHours, nEndHours, nStartWeek, nEndWeek);
- return CDBConnection::GetInstancePtr()->Execute(strSQLText);
- }
- //插入时间计划
- INT CDBInterface::InsertDatePlan( int nPlanType, CString strUid, int nVarID, int nStartHours, int nEndHours, int nStartWeek, int nEndWeek )
- {
- CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
- sprintf(strSQLText, "insert into t_plan_info(plantype, uid, varid, starttime, endtime, " \
- "startweekofday, endweekofday) values (%d, \'%s\', %d, %d, %d, %d, %d) ",
- nPlanType, strUid, nVarID, nStartHours, nEndHours, nStartWeek, nEndWeek);
- return CDBConnection::GetInstancePtr()->Execute(strSQLText);
- }
- //获取系统支持所有的驱动类型
- INT CDBInterface::GetDevDriveList( list<string>& list1, list<string>& list2 )
- {
- CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
- sprintf(strSQLText, "select id, drivename from t_dev_drive");
- int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList2(strSQLText, list1, list2);
- return nRet;
- }
- //获取指定驱动的厂家资料
- INT CDBInterface::GetDevFactoryList( int nDriverID, list<string>& list1, list<string>& list2 )
- {
- CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
- sprintf(strSQLText, "select factoryid, factoryname from t_dev_factory where deviceid = %d", nDriverID);
- int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList2(strSQLText, list1, list2);
- return nRet;
- }
- //获取指定厂家的设备型号列表
- INT CDBInterface::GetDevTypeList( int nDriverID, int nFactoryID, list<string>& list1, list<string>& list2 )
- {
- CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
- sprintf(strSQLText, "select id, equiptype from t_dev_type where driveid = %d and factoryid = %d", nDriverID, nFactoryID);
- int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList2(strSQLText, list1, list2);
- return nRet;
- }
- //获取变量状态列表
- INT CDBInterface::GetVarStatusList( CHAR *pVarUID, int nVarID, list<string>& list1, list<string>& list2 )
- {
- CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
- sprintf(strSQLText, "select statusid, statusdesc from t_var_status where devuid = \'%s\' " \
- "and varid = %d ", pVarUID, nVarID);
- int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList2(strSQLText, list1, list2);
- return nRet;
- }
- //设置变量bit位的ID
- INT CDBInterface::SetVarBitID( CHAR *pVarUID, int nStartBit, int nEndBit, int &nBitID )
- {
- CHAR szVarBitID[MAX_ID] = {0};
- if( 0!=GetVarBitID( pVarUID,nStartBit,nEndBit,szVarBitID ) )
- {
- nBitID = atoi( szVarBitID );
- return 1;
- }
- else
- {
- CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
- int nID = 0;
- CHAR szMaxID[MAX_ID] = {0};
- GetMaxID("t_dev_variant_item", "id", szMaxID);
- nID = atoi( szMaxID )+1;
- sprintf(strSQLText, "insert into t_dev_variant_item(id, uid, startbit, endbit) values (%d, \'%s\', %d, %d) ",
- nID, pVarUID, nStartBit, nEndBit );
- nBitID = nID;
- return CDBConnection::GetInstancePtr()->Execute(strSQLText);
- }
- return 1;
- }
- //获取变量bit位的ID
- INT CDBInterface::GetVarBitID( CHAR *pVarUID, int nStartBit, int nEndBit, CHAR *pVarBitID )
- {
- CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
- list<string> list1;
- list<string>::iterator it;
- if (!_stricmp(m_chDBType, "SQL SERVER"))
- {
- sprintf(strSQLText, "select top 1 id from t_dev_variant_item where uid = \'%s\' " \
- "and startbit = %d and endbit = %d", pVarUID, nStartBit, nEndBit);
- }
- else if (!_stricmp(m_chDBType, "ACCESS97"))
- {
- sprintf(strSQLText, "select top 1 id from t_dev_variant_item where uid = \'%s\' " \
- "and startbit = %d and endbit = %d", pVarUID, nStartBit, nEndBit);
- }
- else if (!_stricmp(m_chDBType, "ACCESS2000"))
- {
- sprintf(strSQLText, "select top 1 id from t_dev_variant_item where uid = \'%s\' " \
- "and startbit = %d and endbit = %d", pVarUID, nStartBit, nEndBit);
- }
- else if(!_stricmp(m_chDBType, "PGSQL"))
- {
- sprintf(strSQLText, "select id from t_dev_variant_item where uid = \'%s\' " \
- "and startbit = %d and endbit = %d limit 1", pVarUID, nStartBit, nEndBit);
- }
- int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList1(strSQLText, list1);
- if( 0 == list1.size() )
- {
- return 0;
- }
- if( nRet != -1 )
- {
- strcpy(pVarBitID, list1.begin()->c_str());
- }
- for( it = list1.begin(); it != list1.end(); )
- {
- list1.erase(it++);
- }
- return nRet;
- }
- //获取变量类型
- INT CDBInterface::GetVarTypeName( int nVarTypeID, CHAR *pVarTypeName )
- {
- CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
- list<string> list1;
- list<string>::iterator it;
- if (!_stricmp(m_chDBType, "SQL SERVER"))
- {
- sprintf(strSQLText, "select top 1 vartype from t_var_type where id = %d", nVarTypeID);
- }
- else if (!_stricmp(m_chDBType, "ACCESS97"))
- {
- sprintf(strSQLText, "select top 1 vartype from t_var_type where id = %d", nVarTypeID);
- }
- else if (!_stricmp(m_chDBType, "ACCESS2000"))
- {
- sprintf(strSQLText, "select top 1 vartype from t_var_type where id = %d", nVarTypeID);
- }
- else if(!_stricmp(m_chDBType, "PGSQL"))
- {
- sprintf(strSQLText, "select vartype from t_var_type where id = %d LIMIT 1", nVarTypeID);
- }
-
- int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList1(strSQLText, list1);
- if( 0 == list1.size() )
- {
- return 0;
- }
- if( nRet != -1 )
- {
- strcpy(pVarTypeName, list1.begin()->c_str());
- }
- for( it = list1.begin(); it != list1.end(); )
- {
- list1.erase(it++);
- }
- return nRet;
- }
- //获取功能码
- INT CDBInterface::GetFuncCodeName( int nFuncID, CHAR *pFuncName )
- {
- CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
- list<string> list1;
- list<string>::iterator it;
- if (!_stricmp(m_chDBType, "SQL SERVER"))
- {
- sprintf(strSQLText, "select top 1 funcname from t_dev_func_code where id = %d", nFuncID);
- }
- else if (!_stricmp(m_chDBType, "ACCESS97"))
- {
- sprintf(strSQLText, "select top 1 funcname from t_dev_func_code where id = %d", nFuncID);
- }
- else if (!_stricmp(m_chDBType, "ACCESS2000"))
- {
- sprintf(strSQLText, "select top 1 funcname from t_dev_func_code where id = %d", nFuncID);
- }
- else if(!_stricmp(m_chDBType, "PGSQL"))
- {
- sprintf(strSQLText, "select funcname from t_dev_func_code where id = %d LIMIT 1", nFuncID);
- }
-
- int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList1(strSQLText, list1);
- if( 0 == list1.size() )
- {
- return 0;
- }
- if( nRet != -1 )
- {
- strcpy(pFuncName, list1.begin()->c_str());
- }
- for( it = list1.begin(); it != list1.end(); )
- {
- list1.erase(it++);
- }
- return nRet;
- }
- //获取变量ID
- INT CDBInterface::GetVarID( CHAR *pVarName, CHAR *pVarID )
- {
- CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
- list<string> list1;
- list<string>::iterator it;
- if (!_stricmp(m_chDBType, "SQL SERVER"))
- {
- sprintf(strSQLText, "select top 1 id from t_dev_variant where varname = \'%s\'", pVarName);
- }
- else if (!_stricmp(m_chDBType, "ACCESS97"))
- {
- sprintf(strSQLText, "select top 1 id from t_dev_variant where varname = \'%s\'", pVarName);
- }
- else if (!_stricmp(m_chDBType, "ACCESS2000"))
- {
- sprintf(strSQLText, "select top 1 id from t_dev_variant where varname = \'%s\'", pVarName);
- }
- else if(!_stricmp(m_chDBType, "PGSQL"))
- {
- sprintf(strSQLText, "select id from t_dev_variant where varname = \'%s\' limit 1", pVarName);
- }
-
- int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList1(strSQLText, list1);
- if( 0 == list1.size() )
- {
- return 0;
- }
- if( nRet != -1 )
- {
- strcpy(pVarID, list1.begin()->c_str());
- }
- for( it = list1.begin(); it != list1.end(); )
- {
- list1.erase(it++);
- }
- return nRet;
- }
- //获取变量ID
- INT CDBInterface::GetVarID( int nStartAddr, int nFuncCode, int nRegNum, CHAR *pVarID )
- {
- CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
- list<string> list1;
- list<string>::iterator it;
- if (!_stricmp(m_chDBType, "SQL SERVER"))
- {
- sprintf(strSQLText, "select top 1 id from t_dev_variant where address = %d and funcid = %d and registernum limit 1",
- nStartAddr, nFuncCode, nRegNum);
- }
- else if (!_stricmp(m_chDBType, "ACCESS97"))
- {
- sprintf(strSQLText, "select top 1 id from t_dev_variant where address = %d and funcid = %d and registernum limit 1",
- nStartAddr, nFuncCode, nRegNum);
- }
- else if (!_stricmp(m_chDBType, "ACCESS2000"))
- {
- sprintf(strSQLText, "select top 1 id from t_dev_variant where address = %d and funcid = %d and registernum limit 1",
- nStartAddr, nFuncCode, nRegNum);
- }
- else if(!_stricmp(m_chDBType, "PGSQL"))
- {
- sprintf(strSQLText, "select id from t_dev_variant where address = %d and funcid = %d and registernum limit 1",
- nStartAddr, nFuncCode, nRegNum);
- }
-
- int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList1(strSQLText, list1);
- if( 0 == list1.size() )
- {
- return 0;
- }
- if( nRet != -1 )
- {
- strcpy(pVarID, list1.begin()->c_str());
- }
- for( it = list1.begin(); it != list1.end(); )
- {
- list1.erase(it++);
- }
- return nRet;
- }
- //获取变量类型ID
- INT CDBInterface::GetVarTypeID( CHAR *pVarTypeName, CHAR *pVarTypeID )
- {
- CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
- list<string> list1;
- list<string>::iterator it;
- if (!_stricmp(m_chDBType, "SQL SERVER"))
- {
- sprintf(strSQLText, "select top 1 id from t_var_type where vartype = \'%s\'", pVarTypeName);
- }
- else if (!_stricmp(m_chDBType, "ACCESS97"))
- {
- sprintf(strSQLText, "select top 1 id from t_var_type where vartype = \'%s\'", pVarTypeName);
- }
- else if (!_stricmp(m_chDBType, "ACCESS2000"))
- {
- sprintf(strSQLText, "select top 1 id from t_var_type where vartype = \'%s\'", pVarTypeName);
- }
- else if(!_stricmp(m_chDBType, "PGSQL"))
- {
- sprintf(strSQLText, "select id from t_var_type where vartype = \'%s\' LIMIT 1", pVarTypeName);
- }
-
- int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList1(strSQLText, list1);
- if( 0 == list1.size() )
- {
- return 0;
- }
- if( nRet != -1 )
- {
- strcpy(pVarTypeID, list1.begin()->c_str());
- }
- for( it = list1.begin(); it != list1.end(); )
- {
- list1.erase(it++);
- }
- return nRet;
- }
- //获取功能码ID
- INT CDBInterface::GetFuncCodeID( CHAR *pFuncName, CHAR *pFuncID )
- {
- CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
- list<string> list1;
- list<string>::iterator it;
- if (!_stricmp(m_chDBType, "SQL SERVER"))
- {
- sprintf(strSQLText, "select top 1 id from t_dev_func_code where funcname = \'%s\'", pFuncName);
- }
- else if (!_stricmp(m_chDBType, "ACCESS97"))
- {
- sprintf(strSQLText, "select top 1 id from t_dev_func_code where funcname = \'%s\'", pFuncName);
- }
- else if (!_stricmp(m_chDBType, "ACCESS2000"))
- {
- sprintf(strSQLText, "select top 1 id from t_dev_func_code where funcname = \'%s\'", pFuncName);
- }
- else if(!_stricmp(m_chDBType, "PGSQL"))
- {
- sprintf(strSQLText, "select id from t_dev_func_code where funcname = \'%s\' LIMIT 1", pFuncName);
- }
-
- int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList1(strSQLText, list1);
- if( 0 == list1.size() )
- {
- return 0;
- }
- if( nRet != -1 )
- {
- strcpy(pFuncID, list1.begin()->c_str());
- }
- for( it = list1.begin(); it != list1.end(); )
- {
- list1.erase(it++);
- }
- return nRet;
- }
- //获取设备名称
- INT CDBInterface::GetDevInfo( CHAR *pDevUID, CHAR *pDllName, CHAR *pIniName, CHAR *pDevProtocolType )
- {
- CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
- list<string> list1, list2, list3;
- list<string>::iterator it1, it2, it3;
- if (!_stricmp(m_chDBType, "SQL SERVER"))
- {
- sprintf(strSQLText, "select top 1 protocoldllname, specialdevice, ininame from t_dev_property where uid = \'%s\'", pDevUID);
- }
- else if (!_stricmp(m_chDBType, "ACCESS97"))
- {
- sprintf(strSQLText, "select top 1 protocoldllname, specialdevice, ininame from t_dev_property where uid = \'%s\'", pDevUID);
- }
- else if (!_stricmp(m_chDBType, "ACCESS2000"))
- {
- sprintf(strSQLText, "select top 1 protocoldllname, specialdevice, ininame from t_dev_property where uid = \'%s\'", pDevUID);
- }
- else if(!_stricmp(m_chDBType, "PGSQL"))
- {
- sprintf(strSQLText, "select protocoldllname, specialdevice, ininame from t_dev_property where uid = \'%s\' LIMIT 1", pDevUID);
- }
-
- int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList3(strSQLText, list1, list2, list3);
- if( 0 == list1.size() || 0 == list2.size() || 0 == list3.size() )
- {
- return 0;
- }
- if( nRet != -1 )
- {
- strcpy(pDllName, list1.begin()->c_str());
- strcpy(pDevProtocolType, list2.begin()->c_str());
- strcpy(pIniName, list3.begin()->c_str());
- }
- for( it1 = list1.begin(), it2 = list2.begin(), it3 = list3.begin();
- it1 != list1.end(), it2 != list2.end(), it3 != list3.end(); )
- {
- list1.erase(it1++);
- list2.erase(it2++);
- list3.erase(it3++);
- }
- return nRet;
- }
- //修改密码
- INT CDBInterface::ModifyPwd(CHAR *pUserID, CHAR *pUserPwd)
- {
- CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
- sprintf(strSQLText, "UPDATE t_user_info SET pwd=\'%s\' where uid=\'%s\'",
- pUserPwd, pUserID);
- return CDBConnection::GetInstancePtr()->Execute(strSQLText);
- }
- //验证用户名、密码是否合法
- INT CDBInterface::ValidateUser(CHAR *pUserID, CHAR *pUserPwd)
- {
- CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
- list<string> list1;
- list<string>::iterator it;
- if (!_stricmp(m_chDBType, "SQL SERVER"))
- {
- sprintf(strSQLText, "select top 1 1 from t_user_info where uid = \'%s\' and pwd = \'%s\'", pUserID, pUserPwd);
- }
- else if (!_stricmp(m_chDBType, "ACCESS97"))
- {
- sprintf(strSQLText, "select top 1 1 from t_user_info where uid = \'%s\' and pwd = \'%s\'", pUserID, pUserPwd);
- }
- else if (!_stricmp(m_chDBType, "ACCESS2000"))
- {
- sprintf(strSQLText, "select top 1 1 from t_user_info where uid = \'%s\' and pwd = \'%s\'", pUserID, pUserPwd);
- }
- else if(!_stricmp(m_chDBType, "PGSQL"))
- {
- sprintf(strSQLText, "select id from t_user_info where uid = \'%s\' and pwd = \'%s\' LIMIT 1", pUserID, pUserPwd);
- }
-
- int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList1(strSQLText, list1);
- //LOG4C((LOG_NOTICE, "ValidateUser GetFieldValueList1 return %d", nRet));
- if( 0 == list1.size() )
- {
- return 0;
- }
- for( it = list1.begin(); it != list1.end(); )
- {
- list1.erase(it++);
- }
- return nRet;
- }
- //验证用户是否启用
- INT CDBInterface::ValidateUserEnable(CHAR *pUserID, CHAR *pStatus)
- {
- CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
- list<string> list1;
- list<string>::iterator it;
- if (!_stricmp(m_chDBType, "SQL SERVER"))
- {
- sprintf(strSQLText, "select top 1 status from t_user_info where uid = \'%s\'", pUserID);
- }
- else if (!_stricmp(m_chDBType, "ACCESS97"))
- {
- sprintf(strSQLText, "select top 1 status from t_user_info where uid = \'%s\'", pUserID);
- }
- else if (!_stricmp(m_chDBType, "ACCESS2000"))
- {
- sprintf(strSQLText, "select top 1 status from t_user_info where uid = \'%s\'", pUserID);
- }
- else if(!_stricmp(m_chDBType, "PGSQL"))
- {
- sprintf(strSQLText, "select status from t_user_info where uid = \'%s\' limit 1", pUserID);
- }
-
- int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList1(strSQLText, list1);
- if( 0 == list1.size() )
- {
- return 0;
- }
- if( nRet != -1 )
- {
- strcpy(pStatus, list1.begin()->c_str());
- }
- for( it = list1.begin(); it != list1.end(); )
- {
- list1.erase(it++);
- }
- return nRet;
- }
- //得到用户信息ID
- INT CDBInterface::GetUserID( CHAR *pID, CHAR *pUserID )
- {
- CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
- list<string> list1;
- list<string>::iterator it;
- if (!_stricmp(m_chDBType, "SQL SERVER"))
- {
- sprintf(strSQLText, "select top 1 id from t_user_info where uid = \'%s\'", pUserID);
- }
- else if (!_stricmp(m_chDBType, "ACCESS97"))
- {
- sprintf(strSQLText, "select top 1 id from t_user_info where uid = \'%s\'", pUserID);
- }
- else if (!_stricmp(m_chDBType, "ACCESS2000"))
- {
- sprintf(strSQLText, "select top 1 id from t_user_info where uid = \'%s\'", pUserID);
- }
- else if(!_stricmp(m_chDBType, "PGSQL"))
- {
- sprintf(strSQLText, "select id from t_user_info where uid = \'%s\' limit 1", pUserID);
- }
-
- int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList1(strSQLText, list1);
- if( 0 == list1.size() )
- {
- return 0;
- }
- if( nRet != -1 )
- {
- strcpy(pUserID, list1.begin()->c_str());
- }
- for( it = list1.begin(); it != list1.end(); )
- {
- list1.erase(it++);
- }
- return nRet;
- }
- // 判断用户是否管理设备权限
- INT CDBInterface::HasDevAlloc( int iGroupID, CHAR *pUid )
- {
- CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
- list<string> list1;
- list<string>::iterator it;
- if (!_stricmp(m_chDBType, "SQL SERVER"))
- {
- sprintf(strSQLText, "select top 1 uid from t_role_equip where group_id = %d " \
- " and uid = \'%s\' ", iGroupID, pUid);
- }
- else if (!_stricmp(m_chDBType, "ACCESS97"))
- {
- sprintf(strSQLText, "select top 1 uid from t_role_equip where group_id = %d " \
- " and uid = \'%s\' ", iGroupID, pUid);
- }
- else if (!_stricmp(m_chDBType, "ACCESS2000"))
- {
- sprintf(strSQLText, "select top 1 uid from t_role_equip where group_id = %d " \
- " and uid = \'%s\' ", iGroupID, pUid);
- }
- else if(!_stricmp(m_chDBType, "PGSQL"))
- {
- sprintf(strSQLText, "select uid from t_role_equip where group_id = %d " \
- " and uid = \'%s\' limit 1", iGroupID, pUid);
- }
-
- int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList1(strSQLText, list1);
- if( 0 == list1.size() )
- {
- return 0;
- }
- for( it = list1.begin(); it != list1.end(); )
- {
- list1.erase(it++);
- }
- return nRet;
- }
- //删除设备权限信息
- INT CDBInterface::DelUserDevInfo( int iGroupID )
- {
- CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
- sprintf(strSQLText, "delete from t_role_equip where group_id = %d", iGroupID);
- return CDBConnection::GetInstancePtr()->Execute(strSQLText);
- }
- //添加设备权限信息
- INT CDBInterface::AddUserDevInfo(int nID, int iGroupID, CHAR *pUid)
- {
- CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
- sprintf(strSQLText, "insert into t_role_equip(id, group_id, uid) values (%d, " \
- "%d, \'%s\')", nID, iGroupID, pUid);
- return CDBConnection::GetInstancePtr()->Execute(strSQLText);
- }
- //获取变量状态表ID
- INT CDBInterface::GetVarStatusID( CHAR *pVarUID, int nVarID, int nStatusID, CHAR *pStatusDesc, CHAR *pID )
- {
- CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
- list<string> list1;
- list<string>::iterator it;
- if (!_stricmp(m_chDBType, "SQL SERVER"))
- {
- sprintf(strSQLText, "select top 1 id from t_var_status where devuid = \'%s\' " \
- "and varid = %d and statusid = %d and statusdesc = \'%s\'",
- pVarUID, nVarID, nStatusID, pStatusDesc);
- }
- else if (!_stricmp(m_chDBType, "ACCESS97"))
- {
- sprintf(strSQLText, "select top 1 id from t_var_status where devuid = \'%s\' " \
- "and varid = %d and statusid = %d and statusdesc = \'%s\'",
- pVarUID, nVarID, nStatusID, pStatusDesc);
- }
- else if (!_stricmp(m_chDBType, "ACCESS2000"))
- {
- sprintf(strSQLText, "select top 1 id from t_var_status where devuid = \'%s\' " \
- "and varid = %d and statusid = %d and statusdesc = \'%s\'",
- pVarUID, nVarID, nStatusID, pStatusDesc);
- }
- else if(!_stricmp(m_chDBType, "PGSQL"))
- {
- sprintf(strSQLText, "select id from t_var_status where devuid = \'%s\' " \
- "and varid = %d and statusid = %d and statusdesc = \'%s\' limit 1",
- pVarUID, nVarID, nStatusID, pStatusDesc);
- }
-
- int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList1(strSQLText, list1);
- if( 0 == list1.size() )
- {
- return 0;
- }
- if( nRet != -1 )
- {
- strcpy(pID, list1.begin()->c_str());
- }
- for( it = list1.begin(); it != list1.end(); )
- {
- list1.erase(it++);
- }
- return nRet;
- }
- //设置变量状态表ID
- INT CDBInterface::SetVarStatusID( CHAR *pVarUID, int nVarID, int nStatusID, CHAR *pStatusDesc )
- {
- CHAR szID[MAX_ID] = {0};
- if( 0!=GetVarStatusID( pVarUID,nVarID,nStatusID,pStatusDesc,szID ) )
- {
- return 1;
- }
- else
- {
- CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
- int nID = 0;
- CHAR szMaxID[MAX_ID] = {0};
- GetMaxID("t_var_status", "id", szMaxID);
- nID = atoi( szMaxID )+1;
- sprintf(strSQLText, "insert into t_var_status(id, devuid, varid, statusid,statusdesc) values (%d, \'%s\', %d, %d,\'%s\') ",
- nID, pVarUID, nVarID, nStatusID,pStatusDesc );
- return CDBConnection::GetInstancePtr()->Execute(strSQLText);
- }
- }
- INT CDBInterface::AddGroupToDll()
- {
- CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
- list<string> list1, list2, list3;
- list<string>::iterator it_list1, it_list2, it_list3;
- int nGroupID = 0;
- CString strName,str,strDesc,strPermitName;
- int nPermitID=0;
- if(!_stricmp(g_strDBType, "PGSQL"))
- {
- sprintf(strSQLText, "select id, groupname, groupdesc from t_user_group");
- }
- else
- {
- sprintf(strSQLText, "select id, groupname, groupdesc from t_user_group");
- }
- int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList3(strSQLText, list1, list2, list3);
- if( 0 == list1.size() || 0 == list2.size() || 0 == list3.size() )
- {
- return 0;
- }
- if( nRet != -1 )
- {
- for( it_list1 = list1.begin(), it_list2 = list2.begin(), it_list3 = list3.begin();
- it_list1 != list1.end() && it_list2 != list2.end() && it_list3 != list3.end();
- it_list1++, it_list2++, it_list3++)
- {
- nGroupID = atoi((*it_list1).c_str());
- strName = (*it_list2).c_str();
- strDesc = (*it_list3).c_str();
- PMS_AddGroup(strName, nGroupID);
- int nS=0,nE=0;
- for( int i=0;i<strDesc.GetLength();i++ )
- {
- if( strDesc[i]=='-' )
- {
- nE = i;
- str = strDesc.Mid( nS,nE-nS );
- nS = nE+1;
-
- nPermitID = atoi(str);
- GetPermitNameByID( strPermitName,nPermitID );
- PMS_AddPermitToGroup( strPermitName,nPermitID,nGroupID );
- }
- }
- str = strDesc.Mid( nS,strDesc.GetLength()-nS );
- nPermitID = atoi(str);
- GetPermitNameByID( strPermitName,nPermitID );
- PMS_AddPermitToGroup( strPermitName,nPermitID,nGroupID );
- }
- }
- for( it_list1 = list1.begin(), it_list2 = list2.begin(), it_list3 = list3.begin();
- it_list1 != list1.end(), it_list2 != list2.end(), it_list3 != list3.end(); )
- {
- list1.erase(it_list1++);
- list2.erase(it_list2++);
- list3.erase(it_list3++);
- }
- return 0;
- }
- INT CDBInterface::GetAllGroupToTree( CTreeCtrl *pTreeCtrl,HTREEITEM hRoot )
- {
- CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
- list<string> list1;
- list<string>::iterator it_list1;
- CString strName;
- if(!_stricmp(g_strDBType, "PGSQL"))
- {
- sprintf(strSQLText, "select groupname from t_user_group order by id");
- }
- else
- {
- sprintf(strSQLText, "select groupname from t_user_group order by id");
- }
- int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList1(strSQLText, list1);
- if( 0 == list1.size() )
- {
- return 0;
- }
- if( nRet != -1 )
- {
- for( it_list1 = list1.begin(); it_list1 != list1.end(); it_list1++ )
- {
- strName = (*it_list1).c_str();
- strName = strName.Trim();
- CString s;
- s.Format( "%s",g_strLoginUserID );
- if( strName.Compare("管理员" ) )//|| s=="admin" )
- pTreeCtrl->InsertItem(strName,5,5,hRoot);
- }
- }
- for( it_list1 = list1.begin(); it_list1 != list1.end(); )
- {
- list1.erase(it_list1++);
- }
- return nRet;
- }
- INT CDBInterface::AddGroup(int iID, CString sGroupName, CString sGroupDesc)
- {
- CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
- sprintf(strSQLText, "insert into t_user_group(id, groupname,groupdesc) values (" \
- "%d, \'%s\', \'%s\')",
- iID, sGroupName,sGroupDesc);
- return CDBConnection::GetInstancePtr()->Execute(strSQLText);
- }
- INT CDBInterface::ModifyGroup(CString sGroupName, CString sGroupDesc)
- {
- CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
- sprintf(strSQLText, "UPDATE t_user_group SET groupdesc=\'%s\' where groupname=\'%s\' ",
- sGroupDesc, sGroupName);
- return CDBConnection::GetInstancePtr()->Execute(strSQLText);
- }
- INT CDBInterface::DelGroup(int iGroupID)
- {
- CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
- sprintf(strSQLText, "delete from t_user_group where id=%d",iGroupID);
- return CDBConnection::GetInstancePtr()->Execute(strSQLText);
- }
- //添加用户所属组信息
- INT CDBInterface::AddUserToGroup(int iID, CHAR * pUserID, int iGroupID, CHAR *pUserName)
- {
- CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
- sprintf(strSQLText, "insert into t_role_user(id, userid, group_id,roledesc) values (%d, " \
- " \'%s\', %d, \'%s\')", iID, pUserID, iGroupID,pUserName);
- return CDBConnection::GetInstancePtr()->Execute(strSQLText);
- }
- //刪除用戶所屬組
- INT CDBInterface::DeleteUserGroup(CHAR * pUserID, int iGroupID )
- {
- CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
- sprintf(strSQLText, "delete from t_role_user where userid=\'%s\' ", pUserID);
- return CDBConnection::GetInstancePtr()->Execute(strSQLText);
- }
- //刪除組的用戶
- INT CDBInterface::DeleteGroupUser( int iGroupID )
- {
- CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
- sprintf(strSQLText, "delete from t_role_user where group_id=%d ", iGroupID);
- return CDBConnection::GetInstancePtr()->Execute(strSQLText);
- }
- // 插入日志记录
- INT CDBInterface::InsertLogRecord( int LogType, int ModuleType, CHAR *pHappenTime, CHAR *pContent )
- {
- CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
- int nID = 0;
- CHAR szMaxID[MAX_ID] = {0};
- GetMaxID("t_sys_log", "id", szMaxID);
- nID = atoi( szMaxID )+1;
- CString sTime,sContent;
- SYSTEMTIME systime;
- GetLocalTime( &systime );
- sTime.Format( "%d-%02d-%02d %02d:%02d:%02d",systime.wYear,systime.wMonth,systime.wDay,systime.wHour,systime.wMinute,systime.wSecond );
- sprintf(strSQLText, "insert into t_sys_log(LogType, ModuleType, HappenTime, Contents, id) values (" \
- "%d, %d, \'%s\', \'%s\',%d)",
- LogType, ModuleType, sTime, pContent,nID );
- return CDBConnection::GetInstancePtr()->Execute(strSQLText);
- }
- //得到組的ID通過組名稱
- INT CDBInterface::GetGroupIDByName( CString sGroupName,int &iGroupID )
- {
- CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
- list<string> list1;
- list<string>::iterator it;
- if (!_stricmp(m_chDBType, "SQL SERVER"))
- {
- sprintf(strSQLText, "select top 1 id from t_user_group where groupname = \'%s\'", sGroupName);
- }
- else if (!_stricmp(m_chDBType, "ACCESS97"))
- {
- sprintf(strSQLText, "select top 1 id from t_user_group where groupname = \'%s\'", sGroupName);
- }
- else if (!_stricmp(m_chDBType, "ACCESS2000"))
- {
- sprintf(strSQLText, "select top 1 id from t_user_group where groupname = \'%s\'", sGroupName);
- }
- else if(!_stricmp(m_chDBType, "PGSQL"))
- {
- sprintf(strSQLText, "select id from t_user_group where groupname = \'%s\' limit 1", sGroupName);
- }
-
- int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList1(strSQLText, list1);
- if( 0 == list1.size() )
- {
- return 0;
- }
- if( nRet != -1 )
- {
- CString str;
- str = list1.begin()->c_str();
- iGroupID = atoi(str);
- }
- for( it = list1.begin(); it != list1.end(); )
- {
- list1.erase(it++);
- }
- return nRet;
- }
- // 根據權限名得到ID
- INT CDBInterface::GetPermitIDByName( CString sPermitName,int &iPermitID )
- {
- CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
- list<string> list1;
- list<string>::iterator it;
- if (!_stricmp(m_chDBType, "SQL SERVER"))
- {
- sprintf(strSQLText, "select top 1 id from t_user_purview where purview_name = \'%s\'", sPermitName);
- }
- else if (!_stricmp(m_chDBType, "ACCESS97"))
- {
- sprintf(strSQLText, "select top 1 id from t_user_purview where purview_name = \'%s\'", sPermitName);
- }
- else if (!_stricmp(m_chDBType, "ACCESS2000"))
- {
- sprintf(strSQLText, "select top 1 id from t_user_purview where purview_name = \'%s\'", sPermitName);
- }
- else if(!_stricmp(m_chDBType, "PGSQL"))
- {
- sprintf(strSQLText, "select id from t_user_purview where purview_name = \'%s\'", sPermitName);/* limit 1*/
- }
-
- int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList1(strSQLText, list1);
- if( 0 == list1.size() )
- {
- return 0;
- }
- if( nRet != -1 )
- {
- CString str;
- str = list1.begin()->c_str();
- iPermitID = atoi(str);
- }
- for( it = list1.begin(); it != list1.end(); )
- {
- list1.erase(it++);
- }
- return nRet;
- }
- // 根據組的ID得到該組的所有權限
- INT CDBInterface::GetGroupPermitByID( CListBox *pListBox,int iGroupID )
- {
- int nCount = pListBox->GetCount();
- for( int i = nCount-1; i >=0; i-- )
- {
- pListBox->DeleteString( i );
- }
- CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
- list<string> list1;
- list<string>::iterator it_list1;
- int nPermitID=0;
- CString strPermitName, strDesc, str;
- if(!_stricmp(g_strDBType, "PGSQL"))
- {
- sprintf(strSQLText, "select groupdesc from t_user_group where id = %d /*limit 1*/", iGroupID);
- }
- else
- {
- sprintf(strSQLText, "select top 1 groupdesc from t_user_group where id = %d", iGroupID);
- }
- int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList1(strSQLText, list1);
- if( 0 == list1.size() )
- {
- return 0;
- }
- if( nRet != -1 )
- {
- for( it_list1 = list1.begin(); it_list1 != list1.end(); it_list1++ )
- {
- strDesc = (*it_list1).c_str();
- strDesc = strDesc.Trim();
- int nS=0,nE=0;
- for( int i=0;i<strDesc.GetLength();i++ )
- {
- if( strDesc[i]=='-' )
- {
- nE = i;
- str = strDesc.Mid( nS,nE-nS );
- nS = nE+1;
-
- nPermitID = atoi(str);
- GetPermitNameByID( strPermitName, nPermitID );
- if( strPermitName!="" && strPermitName[0]!='*' )
- {
- pListBox->AddString( strPermitName );
- }
- }
- }
-
- str = strDesc.Mid( nS,strDesc.GetLength()-nS );
- if( str!="" )
- {
- nPermitID = atoi(str);
- GetPermitNameByID( strPermitName,nPermitID );
- if( strPermitName[0]!='*' )
- {
- pListBox->AddString( strPermitName );
- }
- }
- }
- }
- for( it_list1 = list1.begin(); it_list1 != list1.end(); )
- {
- list1.erase(it_list1++);
- }
- return 0;
- }
- // 如果2中有則1沒
- INT CDBInterface::GetGroupPermitByID( CListBox *pListBox1,CListBox *pListBox2 )
- {
- int nCount2 = pListBox2->GetCount();
- int nCount1 = pListBox1->GetCount();
- for( int i = nCount1-1; i >=0; i-- )
- {
- pListBox1->DeleteString( i );
- }
- CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
- list<string> list1;
- list<string>::iterator it_list1;
- int nPermitID=0;
- CString strName, str;
- if(!_stricmp(g_strDBType, "PGSQL"))
- {
- sprintf(strSQLText, "select purview_name from t_user_purview");
- }
- else
- {
- sprintf(strSQLText, "select purview_name from t_user_purview");
- }
- int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList1(strSQLText, list1);
- if( 0 == list1.size() )
- {
- return 0;
- }
- if( nRet != -1 )
- {
- for( it_list1 = list1.begin(); it_list1 != list1.end(); it_list1++ )
- {
- strName = (*it_list1).c_str();
- strName = strName.Trim();
- bool bExist = false;
- for( int i=0;i<nCount2;i++ )
- {
- pListBox2->GetText( i, str );
- if( str==strName )
- {
- bExist = true;
- break;
- }
- }
- if( !bExist )
- {
- if( strName[0]!='*' )
- {
- pListBox1->AddString( strName );
- }
- }
- }
- }
- for( it_list1 = list1.begin(); it_list1 != list1.end(); )
- {
- list1.erase(it_list1++);
- }
- return nRet;
- }
- INT CDBInterface::FindGroupByName(CString sGroupName)
- {
- CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
- list<string> list1;
- list<string>::iterator it;
- if (!_stricmp(m_chDBType, "SQL SERVER"))
- {
- sprintf(strSQLText, "select top 1 id from t_user_group where groupname = \'%s\'", sGroupName);
- }
- else if (!_stricmp(m_chDBType, "ACCESS97"))
- {
- sprintf(strSQLText, "select top 1 id from t_user_group where groupname = \'%s\'", sGroupName);
- }
- else if (!_stricmp(m_chDBType, "ACCESS2000"))
- {
- sprintf(strSQLText, "select top 1 id from t_user_group where groupname = \'%s\'", sGroupName);
- }
- else if(!_stricmp(m_chDBType, "PGSQL"))
- {
- sprintf(strSQLText, "select id from t_user_group where groupname = \'%s\' limit 1", sGroupName);
- }
-
- int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList1(strSQLText, list1);
- if( 0 == list1.size() )
- {
- return 0;
- }
- for( it = list1.begin(); it != list1.end(); )
- {
- list1.erase(it++);
- }
- return nRet;
- }
- // 根據用戶名得到ID
- INT CDBInterface::GetUserIDByName( CString sUserName,int &iUserID )
- {
- CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
- list<string> list1;
- list<string>::iterator it;
- if (!_stricmp(m_chDBType, "SQL SERVER"))
- {
- sprintf(strSQLText, "select top 1 id from t_user_info where uid = \'%s\'", sUserName);
- }
- else if (!_stricmp(m_chDBType, "ACCESS97"))
- {
- sprintf(strSQLText, "select top 1 id from t_user_info where uid = \'%s\'", sUserName);
- }
- else if (!_stricmp(m_chDBType, "ACCESS2000"))
- {
- sprintf(strSQLText, "select top 1 id from t_user_info where uid = \'%s\'", sUserName);
- }
- else if(!_stricmp(m_chDBType, "PGSQL"))
- {
- sprintf(strSQLText, "select id from t_user_info where uid = \'%s\' limit 1", sUserName);
- }
-
- int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList1(strSQLText, list1);
- if( 0 == list1.size() )
- {
- return 0;
- }
- if( nRet != -1 )
- {
- CString str;
- str = list1.begin()->c_str();
- iUserID = atoi(str);
- }
- for( it = list1.begin(); it != list1.end(); )
- {
- list1.erase(it++);
- }
- return nRet;
- }
- INT CDBInterface::AddUserToDll()
- {
- CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
- list<string> list1, list2, list3;
- list<string>::iterator it_list1, it_list2, it_list3;
- int nUserID = 0;
- int nGroupID = 0;
- int nPermitID = 0;
- CString strName,str;
- if(!_stricmp(g_strDBType, "PGSQL"))
- {
- 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");
- }
- else
- {
- 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");
- }
- int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList3(strSQLText, list1, list2, list3);
- if( 0 == list1.size() || 0 == list2.size() || 0 == list3.size() )
- {
- return 0;
- }
- if( nRet != -1 )
- {
- for( it_list1 = list1.begin(), it_list2 = list2.begin(), it_list3 = list3.begin();
- it_list1 != list1.end() && it_list2 != list2.end() && it_list3 != list3.end();
- it_list1++, it_list2++, it_list3++)
- {
- str = (*it_list1).c_str();
- nUserID = atoi( str.Trim() );
- str = (*it_list2).c_str();
- strName = str.Trim();
- str = (*it_list3).c_str();
- nGroupID = atoi( str.Trim() );
- PMS_AddUserToGroup( strName,nUserID,nGroupID );
- }
- }
- for( it_list1 = list1.begin(), it_list2 = list2.begin(), it_list3 = list3.begin();
- it_list1 != list1.end(), it_list2 != list2.end(), it_list3 != list3.end(); )
- {
- list1.erase(it_list1++);
- list2.erase(it_list2++);
- list3.erase(it_list3++);
- }
- return 0;
- }
- //得到用戶所屬的組
- INT CDBInterface::GetAllGroupByUserID( CListBox *pListBox,CHAR * pUserID )
- {
- CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
- list<string> list1;
- list<string>::iterator it_list1;
- int nPermitID=0;
- CString strName, str;
- if(!_stricmp(g_strDBType, "PGSQL"))
- {
- sprintf(strSQLText, "select t_user_group.groupname from t_role_user,t_user_group "\
- "where t_user_group.id=t_role_user.group_id and t_role_user.userid=\'%s\'",pUserID );
- }
- else
- {
- sprintf(strSQLText, "select t_user_group.groupname from t_role_user,t_user_group "\
- "where t_user_group.id=t_role_user.group_id and t_role_user.userid=\'%s\'",pUserID );
- }
- int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList1(strSQLText, list1);
- if( 0 == list1.size() )
- {
- return 0;
- }
- if( nRet != -1 )
- {
- for( it_list1 = list1.begin(); it_list1 != list1.end(); it_list1++ )
- {
- strName = (*it_list1).c_str();
- strName = strName.Trim();
- pListBox->AddString( strName );
- }
- }
- for( it_list1 = list1.begin(); it_list1 != list1.end(); )
- {
- list1.erase(it_list1++);
- }
- return nRet;
- }
- INT CDBInterface::GetAllGroupByUserID( CListBox *pListBox1,CListBox *pListBox2 )
- {
- int nCount2 = pListBox2->GetCount();
- CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
- list<string> list1;
- list<string>::iterator it_list1;
- int nPermitID=0;
- CString strName, str;
- if(!_stricmp(g_strDBType, "PGSQL"))
- {
- sprintf(strSQLText, "select groupname from t_user_group");
- }
- else
- {
- sprintf(strSQLText, "select groupname from t_user_group");
- }
- int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList1(strSQLText, list1);
- if( 0 == list1.size() )
- {
- return 0;
- }
- if( nRet != -1 )
- {
- for( it_list1 = list1.begin(); it_list1 != list1.end(); it_list1++ )
- {
- strName = (*it_list1).c_str();
- strName = strName.Trim();
- bool bExist = false;
- for( int i=0;i<nCount2;i++ )
- {
- pListBox2->GetText( i, str );
- if( str == strName )
- {
- bExist = true;
- break;
- }
- }
- if( !bExist && strName.Compare("管理员") )
- pListBox1->AddString( strName );
- }
- }
- for( it_list1 = list1.begin(); it_list1 != list1.end(); )
- {
- list1.erase(it_list1++);
- }
- return nRet;
- }
- // 根據權限ID得到名
- INT CDBInterface::GetPermitNameByID( CString &sPermitName,int iPermitID )
- {
- CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
- list<string> list1;
- list<string>::iterator it;
- if (!_stricmp(g_strDBType, "SQL SERVER"))
- {
- sprintf(strSQLText, "select top 1 purview_name from t_user_purview where id = %d", iPermitID);
- }
- else if (!_stricmp(g_strDBType, "ACCESS97"))
- {
- sprintf(strSQLText, "select top 1 purview_name from t_user_purview where id = %d", iPermitID);
- }
- else if (!_stricmp(g_strDBType, "ACCESS2000"))
- {
- sprintf(strSQLText, "select top 1 purview_name from t_user_purview where id = %d", iPermitID);
- }
- else if(!_stricmp(g_strDBType, "PGSQL"))
- {
- sprintf(strSQLText, "select purview_name from t_user_purview where id = %d limit 1", iPermitID);
- }
-
- int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList1(strSQLText, list1);
- if( 0 == list1.size() )
- {
- return 0;
- }
- if( nRet != -1 )
- {
- CString str;
- str = list1.begin()->c_str();
- sPermitName = str.Trim();
- }
- for( it = list1.begin(); it != list1.end(); )
- {
- list1.erase(it++);
- }
- return nRet;
- }
- //根据指定内容删除表内容, 通用函数 //0:不操作 1:字符串 2:整型
- INT CDBInterface::DelTableData( CHAR *pTableName, CHAR *pFieldName1,CHAR *pContent1,int iType1,
- CHAR *pFieldName2,CHAR *pContent2,int iType2,
- CHAR *pFieldName3,CHAR *pContent3,int iType3 )
- {
- CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
- CHAR sTemp[MAX_SQL_LENGTH + 1] = "";
- sprintf(strSQLText, "delete from %s where ", pTableName);
- switch( iType1 )
- {
- case 1://字符串
- sprintf( sTemp, "%s = \'%s\' ", pFieldName1,pContent1 );
- strcat( strSQLText, sTemp );
- break;
- case 2://整型
- sprintf(sTemp, "%s = \'%d\' ", pFieldName1,atoi(pContent1));
- strcat( strSQLText, sTemp );
- break;
- }
- switch( iType2 )
- {
- case 1://字符串
- sprintf( sTemp, "and %s = \'%s\' ", pFieldName2,pContent2 );
- strcat( strSQLText, sTemp );
- break;
- case 2://整型
- sprintf(sTemp, "and %s = \'%d\' ", pFieldName2,atoi(pContent2));
- strcat( strSQLText, sTemp );
- break;
- }
- switch( iType3 )
- {
- case 1://字符串
- sprintf( sTemp, "and %s = \'%s\'", pFieldName3,pContent3 );
- strcat( strSQLText, sTemp );
- break;
- case 2://整型
- sprintf(sTemp, "and %s = \'%d\'", pFieldName3,atoi(pContent3));
- strcat( strSQLText, sTemp );
- break;
- }
- return CDBConnection::GetInstancePtr()->Execute(strSQLText);
- }
- //判断是否有电话,短信,EMAIL功能
- INT CDBInterface::JudgeIsTSE( bool &bTel,bool &bSms,bool &bEmail )
- {
- CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
- list<string> list1, list2, list3,list4;
- list<string>::iterator it_list1, it_list2, it_list3, it_list4;
- CString sUid,sTel,sMobile,sEmail;
- CString str;
- if(!_stricmp(g_strDBType, "PGSQL"))
- {
- sprintf(strSQLText, "select uid,tel,mobiletel,email from t_user_info");
- }
- else
- {
- sprintf(strSQLText, "select uid,tel,mobiletel,email from t_user_info");
- }
- int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList4(strSQLText, list1, list2, list3,list4);
- if( 0 == list1.size() || 0 == list2.size() || 0 == list3.size() || 0 == list4.size() )
- {
- return 0;
- }
- if( nRet != -1 )
- {
- for( it_list1 = list1.begin(), it_list2 = list2.begin(), it_list3 = list3.begin(), it_list4 = list4.begin();
- it_list1 != list1.end() && it_list2 != list2.end() && it_list3 != list3.end() && it_list4 != list4.end();
- it_list1++, it_list2++, it_list3++, it_list4++)
- {
- str = (*it_list1).c_str();
- sUid = str.Trim();
- str = (*it_list2).c_str();
- sTel = str.Trim();
- str = (*it_list3).c_str();
- sMobile = str.Trim();
- str = (*it_list4).c_str();
- sEmail = str.Trim();
- if( sUid.Compare("admin") )
- {
- if( sTel.Compare("") )
- {
- bTel = true;
- }
- if( sMobile.Compare("") )
- {
- bSms = true;
- }
- if( sEmail.Compare("") )
- {
- bEmail = true;
- }
- }
- }
- }
- for( it_list1 = list1.begin(), it_list2 = list2.begin(), it_list3 = list3.begin(), it_list4 = list4.begin();
- it_list1 != list1.end(), it_list2 != list2.end(), it_list3 != list3.end(), it_list4 != list4.end(); )
- {
- list1.erase(it_list1++);
- list2.erase(it_list2++);
- list3.erase(it_list3++);
- list4.erase(it_list4++);
- }
- return nRet;
- }
- //
- INT CDBInterface::GetAllActionWithAlarm( CListCtrl *pListCtrl )
- {
- pListCtrl->DeleteAllItems();
- CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
- list<string> list1,list2,list3,list4;
- list<string>::iterator it_list1,it_list2,it_list3,it_list4;
- CString s1,s2,s3,s4;
- if(!_stricmp(g_strDBType, "PGSQL"))
- {
- sprintf(strSQLText, "select doset_varname,dostatus_varname,alarmdata,resumedata from t_actionwithalarm");
- }
- else
- {
- sprintf(strSQLText, "select doset_varname,dostatus_varname,alarmdata,resumedata from t_actionwithalarm");
- }
- int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList4(strSQLText, list1, list2, list3, list4);
- if( 0 == list1.size() || 0 == list2.size() || 0 == list3.size() || 0 == list4.size() )
- {
- return 0;
- }
- if( nRet != -1 )
- {
- for( it_list1 = list1.begin(),it_list2 = list2.begin(),it_list3 = list3.begin(),it_list4 = list4.begin();
- it_list1 != list1.end() && it_list2 != list2.end() && it_list3 != list3.end() && it_list4 != list4.end();
- it_list1++, it_list2++, it_list3++, it_list4++ )
- {
- s1 = (*it_list1).c_str();
- s1 = s1.Trim();
- s2 = (*it_list2).c_str();
- s2 = s2.Trim();
- s3 = (*it_list3).c_str();
- s3 = s3.Trim();
- s4 = (*it_list4).c_str();
- s4 = s4.Trim();
- bool f=false;
- for( int i=0;i<pListCtrl->GetItemCount();i++ )
- {
- CString str;
- str = pListCtrl->GetItemText( i,0 );
- if( str==s1 )
- {
- f = true;
- break;
- }
- }
- if( !f )
- {
- int n = pListCtrl->GetItemCount();
- pListCtrl->InsertItem( n,s1 );
- pListCtrl->SetItemText( n,1,s2 );
- pListCtrl->SetItemText( n,2,s3 );
- pListCtrl->SetItemText( n,3,s4 );
- }
- }
- }
- for( it_list1 = list1.begin(),it_list2 = list2.begin(),it_list3 = list3.begin(),it_list4 = list4.begin();
- it_list1 != list1.end(), it_list2 != list2.end(), it_list3 != list3.end(), it_list4 != list4.end(); )
- {
- list1.erase(it_list1++);
- list2.erase(it_list2++);
- list3.erase(it_list3++);
- list4.erase(it_list4++);
- }
- return nRet;
- }
- INT CDBInterface::GetAWAPlanTime( CString sDoSet,CString &sPlanTime )
- {
- CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
- list<string> list1;
- list<string>::iterator it_list1;
- CString s1;
- if(!_stricmp(g_strDBType, "PGSQL"))
- {
- sprintf(strSQLText, "select strreserved1 from t_actionwithalarm where doset_varname=\'%s\'",sDoSet );
- }
- else
- {
- sprintf(strSQLText, "select strreserved1 from t_actionwithalarm where doset_varname=\'%s\',sDoSet");
- }
- int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList1(strSQLText, list1 );
- if( 0 == list1.size() )
- {
- return 0;
- }
- if( nRet != -1 )
- {
- for( it_list1 = list1.begin();
- it_list1 != list1.end();
- it_list1++ )
- {
- s1 = (*it_list1).c_str();
- s1 = s1.Trim();
- sPlanTime = s1;
- }
- }
- for( it_list1 = list1.begin();
- it_list1 != list1.end(); )
- {
- list1.erase(it_list1++);
- }
- return nRet;
- }
- INT CDBInterface::SetAWAPlanTime( CString sDoSet,CString sPlanTime )
- {
- CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
- sprintf(strSQLText, "UPDATE t_actionwithalarm SET strreserved1=\'%s\' where doset_varname=\'%s\' ",
- sPlanTime,sDoSet );
- return CDBConnection::GetInstancePtr()->Execute(strSQLText);
- }
- INT CDBInterface::AddActionWithAlarm( CString sDoSet,CString sDoStatus,int iAlarmData,int iResumeData,CString sDoPlanTime )
- {
- CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
- int nID = 0;
- CHAR szMaxID[MAX_ID] = {0};
- GetMaxID("t_actionwithalarm", "id", szMaxID);
- nID = atoi( szMaxID )+1;
- sprintf(strSQLText, "insert into t_actionwithalarm(id, doset_varname,dostatus_varname,alarmdata,resumedata,strreserved1) values (" \
- "%d, \'%s\', \'%s\',%d,%d, \'%s\' )",
- nID, sDoSet,sDoStatus,iAlarmData,iResumeData,sDoPlanTime);
- return CDBConnection::GetInstancePtr()->Execute(strSQLText);
- }
- INT CDBInterface::AddActionWithAlarm( CString sDoSet,CString sDoStatus,int iAlarmData,int iResumeData,CString sDoPlanTime,CStringArray &SA )
- {
- int nSize = SA.GetCount();
-
- //先删除
- DelActionWithAlarm( sDoSet );
- if( nSize==0 )
- {
- AddActionWithAlarm( sDoSet,sDoStatus,iAlarmData,iResumeData,sDoPlanTime );
- }
- else
- {
- int X=nSize%30;
- if( X!=0 )
- {
- X = ( 30-X );
- nSize += X;
- }
- for( int i=0;i<X;i++ )
- {
- SA.Add( "" );
- }
- CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
- int nID = 0;
- CHAR szMaxID[MAX_ID] = {0};
- int n=0;
- for( int n=0;n<nSize/30;n++ )
- {
- GetMaxID("t_actionwithalarm", "id", szMaxID);
- nID = atoi( szMaxID )+1;
- sprintf(strSQLText, "insert into t_actionwithalarm(id, doset_varname,dostatus_varname,alarmdata,resumedata,strreserved1,"\
- "varname1,varname2,varname3,varname4,varname5,varname6,varname7,varname8,varname9,varname10,"\
- "varname11,varname12,varname13,varname14,varname15,varname16,varname17,varname18,varname19,varname20,"\
- "varname21,varname22,varname23,varname24,varname25,varname26,varname27,varname28,varname29,varname30 ) "\
- "values (%d,\'%s\',\'%s\',%d,%d,\'%s\', "\
- "\'%s\',\'%s\',\'%s\',\'%s\',\'%s\',\'%s\',\'%s\',\'%s\',\'%s\',\'%s\',"\
- "\'%s\',\'%s\',\'%s\',\'%s\',\'%s\',\'%s\',\'%s\',\'%s\',\'%s\',\'%s\',"\
- "\'%s\',\'%s\',\'%s\',\'%s\',\'%s\',\'%s\',\'%s\',\'%s\',\'%s\',\'%s\')", nID, sDoSet,sDoStatus,iAlarmData,iResumeData,sDoPlanTime,
- 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),
- 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),
- 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) );
-
- CDBConnection::GetInstancePtr()->Execute(strSQLText);
- }
- }
- return 0;
- }
- INT CDBInterface::ModifyActionWithAlarm( CString sOldDoSet,CString sDoSet, CString sDoStatus,int iAlarmData,int iResumeData,CString sDoPlanTime )
- {
- CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
- sprintf(strSQLText, "UPDATE t_actionwithalarm SET doset_varname=\'%s\',dostatus_varname=\'%s\',alarmdata=%d,resumedata=%d,strreserved1=\'%s\' where doset_varname=\'%s\' ",
- sDoSet,sDoStatus,iAlarmData,iResumeData,sDoPlanTime,sOldDoSet );
- return CDBConnection::GetInstancePtr()->Execute(strSQLText);
- }
- INT CDBInterface::DelActionWithAlarm( CString sDosetVarName )
- {
- CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
- sprintf(strSQLText, "delete from t_actionwithalarm where doset_varname=\'%s\'",sDosetVarName);
- return CDBConnection::GetInstancePtr()->Execute(strSQLText);
- }
- INT CDBInterface::GetActionWithAlarmVar( CListBox *pListBox,CString sDoSet )
- {
- CHAR strSQLText[MAX_SQL_LENGTH * 2] = {0};
- list<string> list_str_doset, list_str_dostatus;
- list<string> list_int_alarmdata,list_int_resumedata;
- list<string> list_str_reserved1, list_str_reserved2, list_str_reserved3;
- list<string> list_int_reserved1, list_int_reserved2, list_int_reserved3;
- list<string> list_bool_reserved1, list_bool_reserved2, list_bool_reserved3;
- list<string> list_var1, list_var2, list_var3, list_var4, list_var5, list_var6, list_var7, list_var8, list_var9, list_var10;
- list<string> list_var11, list_var12, list_var13, list_var14, list_var15, list_var16, list_var17, list_var18, list_var19, list_var20;
- list<string> list_var21, list_var22, list_var23, list_var24, list_var25, list_var26, list_var27, list_var28, list_var29, list_var30;
- list<string>::iterator it_str_doset, it_str_dostatus;
- list<string>::iterator it_int_alarmdata, it_int_resumedata;
- list<string>::iterator it_str_reserved1, it_str_reserved2, it_str_reserved3;
- list<string>::iterator it_int_reserved1, it_int_reserved2, it_int_reserved3;
- list<string>::iterator it_bool_reserved1, it_bool_reserved2, it_bool_reserved3;
- list<string>::iterator it_var1, it_var2, it_var3, it_var4, it_var5, it_var6, it_var7, it_var8, it_var9, it_var10;
- list<string>::iterator it_var11, it_var12, it_var13, it_var14, it_var15, it_var16, it_var17, it_var18, it_var19, it_var20;
- list<string>::iterator it_var21, it_var22, it_var23, it_var24, it_var25, it_var26, it_var27, it_var28, it_var29, it_var30;
- if (!_stricmp(m_chDBType, "SQL SERVER"))
- {
- sprintf(strSQLText, "select doset_varname,dostatus_varname,alarmdata,resumedata, " \
- "strreserved1, strreserved2, strreserved3, " \
- "intreserved1, intreserved2, intreserved3, " \
- "boolreserved1, boolreserved2, boolreserved3, " \
- "varname1, varname2, varname3, varname4, varname5, varname6, varname7, varname8,varname9,varname10, " \
- "varname11, varname12, varname13, varname14, varname15, varname16, varname17, varname18,varname19,varname20, " \
- "varname21, varname22, varname23, varname24, varname25, varname26, varname27, varname28,varname29,varname30" \
- "from t_actionwithalarm where doset_varname=\'%s\'",sDoSet );
- }
- else if (!_stricmp(m_chDBType, "ACCESS97"))
- {
- }
- else if (!_stricmp(m_chDBType, "ACCESS2000"))
- {
- }
- else if(!_stricmp(m_chDBType, "PGSQL"))
- {
- sprintf(strSQLText, "select doset_varname,dostatus_varname,alarmdata,resumedata, " \
- "strreserved1, strreserved2, strreserved3, " \
- "intreserved1, intreserved2, intreserved3, " \
- "boolreserved1, boolreserved2, boolreserved3, " \
- "varname1, varname2, varname3, varname4, varname5, varname6, varname7, varname8,varname9,varname10, " \
- "varname11, varname12, varname13, varname14, varname15, varname16, varname17, varname18,varname19,varname20, " \
- "varname21, varname22, varname23, varname24, varname25, varname26, varname27, varname28,varname29,varname30 " \
- "from t_actionwithalarm where doset_varname=\'%s\'",sDoSet );
- }
- //LOG4C((LOG_NOTICE, "%s", strSQLText));
- int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList43(strSQLText
- ,list_str_doset,list_str_dostatus
- ,list_int_alarmdata,list_int_resumedata
- ,list_str_reserved1, list_str_reserved2, list_str_reserved3
- ,list_int_reserved1, list_int_reserved2, list_int_reserved3
- ,list_bool_reserved1, list_bool_reserved2, list_bool_reserved3
- ,list_var1, list_var2, list_var3, list_var4, list_var5, list_var6, list_var7, list_var8, list_var9, list_var10
- ,list_var11, list_var12, list_var13, list_var14, list_var15, list_var16, list_var17, list_var18, list_var19, list_var20
- ,list_var21, list_var22, list_var23, list_var24, list_var25, list_var26, list_var27, list_var28, list_var29, list_var30 );
- if( 0 == list_str_reserved1.size() || 0 == list_str_reserved2.size() || 0 == list_str_reserved3.size()
- || 0 == list_int_reserved1.size() || 0 == list_int_reserved2.size() || 0 == list_int_reserved3.size()
- || 0 == list_bool_reserved1.size() || 0 == list_bool_reserved2.size() || 0 == list_bool_reserved3.size()
- )
- {
- return 0;
- }
- if( nRet != -1 )
- {
- 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()
- ,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()
- ,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()
- ,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()
- ,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()
- ,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();
- 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()
- ,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()
- ,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()
- ,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()
- ,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()
- ,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();
- )
- {
- CString str;
- str = (*it_var1++).c_str(); str = str.Trim();
- if( str!="" && pVariantsManager->IsExistVar(str) ) pListBox->AddString( str );
- str = (*it_var2++).c_str(); str = str.Trim();
- if( str!="" && pVariantsManager->IsExistVar(str) ) pListBox->AddString( str );
- str = (*it_var3++).c_str(); str = str.Trim();
- if( str!="" && pVariantsManager->IsExistVar(str) ) pListBox->AddString( str );
- str = (*it_var4++).c_str(); str = str.Trim();
- if( str!="" && pVariantsManager->IsExistVar(str) ) pListBox->AddString( str );
- str = (*it_var5++).c_str(); str = str.Trim();
- if( str!="" && pVariantsManager->IsExistVar(str) ) pListBox->AddString( str );
- str = (*it_var6++).c_str(); str = str.Trim();
- if( str!="" && pVariantsManager->IsExistVar(str) ) pListBox->AddString( str );
- str = (*it_var7++).c_str(); str = str.Trim();
- if( str!="" && pVariantsManager->IsExistVar(str) ) pListBox->AddString( str );
- str = (*it_var8++).c_str(); str = str.Trim();
- if( str!="" && pVariantsManager->IsExistVar(str) ) pListBox->AddString( str );
- str = (*it_var9++).c_str(); str = str.Trim();
- if( str!="" && pVariantsManager->IsExistVar(str) ) pListBox->AddString( str );
- str = (*it_var10++).c_str(); str = str.Trim();
- if( str!="" && pVariantsManager->IsExistVar(str) ) pListBox->AddString( str );
- //11
- str = (*it_var11++).c_str(); str = str.Trim();
- if( str!="" && pVariantsManager->IsExistVar(str) ) pListBox->AddString( str );
- str = (*it_var12++).c_str(); str = str.Trim();
- if( str!="" && pVariantsManager->IsExistVar(str) ) pListBox->AddString( str );
- str = (*it_var13++).c_str(); str = str.Trim();
- if( str!="" && pVariantsManager->IsExistVar(str) ) pListBox->AddString( str );
- str = (*it_var14++).c_str(); str = str.Trim();
- if( str!="" && pVariantsManager->IsExistVar(str) ) pListBox->AddString( str );
- str = (*it_var15++).c_str(); str = str.Trim();
- if( str!="" && pVariantsManager->IsExistVar(str) ) pListBox->AddString( str );
- str = (*it_var16++).c_str(); str = str.Trim();
- if( str!="" && pVariantsManager->IsExistVar(str) ) pListBox->AddString( str );
- str = (*it_var17++).c_str(); str = str.Trim();
- if( str!="" && pVariantsManager->IsExistVar(str) ) pListBox->AddString( str );
- str = (*it_var18++).c_str(); str = str.Trim();
- if( str!="" && pVariantsManager->IsExistVar(str) ) pListBox->AddString( str );
- str = (*it_var19++).c_str(); str = str.Trim();
- if( str!="" && pVariantsManager->IsExistVar(str) ) pListBox->AddString( str );
- str = (*it_var20++).c_str(); str = str.Trim();
- if( str!="" && pVariantsManager->IsExistVar(str) ) pListBox->AddString( str );
- //21
- str = (*it_var21++).c_str(); str = str.Trim();
- if( str!="" && pVariantsManager->IsExistVar(str) ) pListBox->AddString( str );
- str = (*it_var22++).c_str(); str = str.Trim();
- if( str!="" && pVariantsManager->IsExistVar(str) ) pListBox->AddString( str );
- str = (*it_var23++).c_str(); str = str.Trim();
- if( str!="" && pVariantsManager->IsExistVar(str) ) pListBox->AddString( str );
- str = (*it_var24++).c_str(); str = str.Trim();
- if( str!="" && pVariantsManager->IsExistVar(str) ) pListBox->AddString( str );
- str = (*it_var25++).c_str(); str = str.Trim();
- if( str!="" && pVariantsManager->IsExistVar(str) ) pListBox->AddString( str );
- str = (*it_var26++).c_str(); str = str.Trim();
- if( str!="" && pVariantsManager->IsExistVar(str) ) pListBox->AddString( str );
- str = (*it_var27++).c_str(); str = str.Trim();
- if( str!="" && pVariantsManager->IsExistVar(str) ) pListBox->AddString( str );
- str = (*it_var28++).c_str(); str = str.Trim();
- if( str!="" && pVariantsManager->IsExistVar(str) ) pListBox->AddString( str );
- str = (*it_var29++).c_str(); str = str.Trim();
- if( str!="" && pVariantsManager->IsExistVar(str) ) pListBox->AddString( str );
- str = (*it_var30++).c_str(); str = str.Trim();
- if( str!="" && pVariantsManager->IsExistVar(str) ) pListBox->AddString( str );
- }
- }
- for( it_str_doset=list_str_doset.begin(),it_str_dostatus=list_str_dostatus.begin()
- ,it_int_alarmdata=list_int_alarmdata.begin(),it_int_resumedata=list_int_resumedata.begin()
- ,it_str_reserved1=list_str_reserved1.begin(),it_str_reserved2=list_str_reserved2.begin(),it_str_reserved3=list_str_reserved3.begin()
- ,it_int_reserved1=list_int_reserved1.begin(),it_int_reserved2=list_int_reserved2.begin(),it_int_reserved3=list_int_reserved3.begin()
- ,it_bool_reserved1=list_bool_reserved1.begin(),it_bool_reserved2=list_bool_reserved2.begin(),it_bool_reserved3=list_bool_reserved3.begin()
- ,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()
- ,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()
- ,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()
- ,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()
- ,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()
- ,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();
- it_str_doset!=list_str_doset.end(),it_str_dostatus!=list_str_dostatus.end()
- ,it_int_alarmdata!=list_int_alarmdata.end(),it_int_resumedata!=list_int_resumedata.end()
- ,it_str_reserved1!=list_str_reserved1.end(),it_str_reserved2!=list_str_reserved2.end(),it_str_reserved3!=list_str_reserved3.end()
- ,it_int_reserved1!=list_int_reserved1.end(),it_int_reserved2!=list_int_reserved2.end(),it_int_reserved3!=list_int_reserved3.end()
- ,it_bool_reserved1!=list_bool_reserved1.end(),it_bool_reserved3!=list_bool_reserved2.end(),it_bool_reserved3!=list_bool_reserved3.end()
- ,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()
- ,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()
- ,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()
- ,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()
- ,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()
- ,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();
- )
- {
- list_str_doset.erase( it_str_doset++ );
- list_str_dostatus.erase( it_str_dostatus++ );
- list_int_alarmdata.erase( it_int_alarmdata++ );
- list_int_resumedata.erase( it_int_resumedata++ );
- list_str_reserved1.erase( it_str_reserved1++ );
- list_str_reserved2.erase( it_str_reserved2++ );
- list_str_reserved3.erase( it_str_reserved3++ );
- list_int_reserved1.erase( it_int_reserved1++ );
- list_int_reserved2.erase( it_int_reserved2++ );
- list_int_reserved3.erase( it_int_reserved3++ );
- list_bool_reserved1.erase( it_bool_reserved1++ );
- list_bool_reserved2.erase( it_bool_reserved2++ );
- list_bool_reserved3.erase( it_bool_reserved3++ );
- list_var1.erase(it_var1++);
- list_var2.erase(it_var2++);
- list_var3.erase(it_var3++);
- list_var4.erase(it_var4++);
- list_var5.erase(it_var5++);
- list_var6.erase(it_var6++);
- list_var7.erase(it_var7++);
- list_var8.erase(it_var8++);
- list_var9.erase(it_var9++);
- list_var10.erase(it_var10++);
- list_var11.erase(it_var11++);
- list_var12.erase(it_var12++);
- list_var13.erase(it_var13++);
- list_var14.erase(it_var14++);
- list_var15.erase(it_var15++);
- list_var16.erase(it_var16++);
- list_var17.erase(it_var17++);
- list_var18.erase(it_var18++);
- list_var19.erase(it_var19++);
- list_var20.erase(it_var20++);
- list_var21.erase(it_var21++);
- list_var22.erase(it_var22++);
- list_var23.erase(it_var23++);
- list_var24.erase(it_var24++);
- list_var25.erase(it_var25++);
- list_var26.erase(it_var26++);
- list_var27.erase(it_var27++);
- list_var28.erase(it_var28++);
- list_var29.erase(it_var29++);
- list_var30.erase(it_var30++);
- }
- return nRet;
- }
- // 如果2中有則1沒
- INT CDBInterface::GetActionWithAlarmVar( CListBox *pListBox1,CListBox *pListBox2 )
- {
- int nCount2 = pListBox2->GetCount();
- int nCount1 = pListBox1->GetCount();
- for( int i = nCount1-1; i >=0; i-- )
- {
- pListBox1->DeleteString( i );
- }
- CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
- list<string> list1,list2;
- list<string>::iterator it_list1,it_list2;
- int nPermitID=0;
- CString strName, str;
- int nCanAlarm=0;
- if(!_stricmp(g_strDBType, "PGSQL"))
- {
- sprintf(strSQLText, "select varname,boolreserved2 from t_dev_variant");
- }
- else
- {
- sprintf(strSQLText, "select varname,boolreserved2 from t_dev_variant");
- }
- int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList2(strSQLText, list1, list2);
- if( 0 == list1.size() || 0 == list2.size() )
- {
- return 0;
- }
- if( nRet != -1 )
- {
- for( it_list1 = list1.begin(),it_list2 = list2.begin(); it_list1 != list1.end(),it_list2 != list2.end(); it_list1++,it_list2++ )
- {
- strName = (*it_list1).c_str();
- strName = strName.Trim();
- str = (*it_list2).c_str();
- str = str.Trim();
- if( str=="0" )
- nCanAlarm = 0;
- else
- nCanAlarm = 1;
- bool bExist = false;
- for( int i=0;i<nCount2;i++ )
- {
- pListBox2->GetText( i, str );
- if( str==strName )
- {
- bExist = true;
- break;
- }
- }
- if( !bExist && nCanAlarm==1 )
- {
- pListBox1->AddString( strName );
- }
- }
- }
- for( it_list1 = list1.begin(),it_list2 = list2.begin(); it_list1 != list1.end(),it_list2 != list2.end(); )
- {
- list1.erase(it_list1++);
- list2.erase(it_list2++);
- }
- return nRet;
- }
- INT CDBInterface::UpDownUserInfo( int iID1,int iID2 )
- {
- int nTemp = 10000;
- CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
- sprintf(strSQLText, "UPDATE t_user_info SET id=%d where id=%d",nTemp,iID1 );
- CDBConnection::GetInstancePtr()->Execute(strSQLText);
- sprintf(strSQLText, "UPDATE t_user_info SET id=%d where id=%d",iID1,iID2 );
- CDBConnection::GetInstancePtr()->Execute(strSQLText);
- sprintf(strSQLText, "UPDATE t_user_info SET id=%d where id=%d",iID2,nTemp );
- CDBConnection::GetInstancePtr()->Execute(strSQLText);
- return 1;
- }
- // 根據組的ID得到該組的所有设备
- INT CDBInterface::GetGroupDeviceByID( CListBox *pListBox,int iGroupID )
- {
- int nCount = pListBox->GetCount();
- for( int i = nCount-1; i >=0; i-- )
- {
- pListBox->DeleteString( i );
- }
- CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
- list<string> list1;
- list<string>::iterator it_list1;
- int nPermitID=0;
- CString strPermitName, strDesc, str;
- if(!_stricmp(g_strDBType, "PGSQL"))
- {
- sprintf(strSQLText, "select uid from t_role_equip where id = %d /*limit 1*/", iGroupID);
- }
- else
- {
- sprintf(strSQLText, "select top 1 uid from t_role_equip where id = %d", iGroupID);
- }
- int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList1(strSQLText, list1);
- if( 0 == list1.size() )
- {
- return 0;
- }
- if( nRet != -1 )
- {
- for( it_list1 = list1.begin(); it_list1 != list1.end(); it_list1++ )
- {
- strDesc = (*it_list1).c_str();
- strDesc = strDesc.Trim();
- int nS=0,nE=0;
- for( int i=0;i<strDesc.GetLength();i++ )
- {
- if( strDesc[i]=='-' )
- {
- nE = i;
- str = strDesc.Mid( nS,nE-nS );
- nS = nE+1;
-
- nPermitID = atoi(str);
- GetPermitNameByID( strPermitName, nPermitID );
- if( strPermitName!="" && strPermitName[0]!='*' )
- {
- pListBox->AddString( strPermitName );
- }
- }
- }
-
- str = strDesc.Mid( nS,strDesc.GetLength()-nS );
- if( str!="" )
- {
- nPermitID = atoi(str);
- GetPermitNameByID( strPermitName,nPermitID );
- if( strPermitName[0]!='*' )
- {
- pListBox->AddString( strPermitName );
- }
- }
- }
- }
- for( it_list1 = list1.begin(); it_list1 != list1.end(); )
- {
- list1.erase(it_list1++);
- }
- return 0;
- }
- // 如果2中有則1沒
- INT CDBInterface::GetGroupDeviceByID( CListBox *pListBox1,CListBox *pListBox2 )
- {
- int nCount2 = pListBox2->GetCount();
- int nCount1 = pListBox1->GetCount();
- for( int i = nCount1-1; i >=0; i-- )
- {
- pListBox1->DeleteString( i );
- }
- CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
- list<string> list1;
- list<string>::iterator it_list1;
- int nPermitID=0;
- CString strName, str;
- if(!_stricmp(g_strDBType, "PGSQL"))
- {
- sprintf(strSQLText, "select purview_name from t_user_purview");
- }
- else
- {
- sprintf(strSQLText, "select purview_name from t_user_purview");
- }
- int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList1(strSQLText, list1);
- if( 0 == list1.size() )
- {
- return 0;
- }
- if( nRet != -1 )
- {
- for( it_list1 = list1.begin(); it_list1 != list1.end(); it_list1++ )
- {
- strName = (*it_list1).c_str();
- strName = strName.Trim();
- bool bExist = false;
- for( int i=0;i<nCount2;i++ )
- {
- pListBox2->GetText( i, str );
- if( str==strName )
- {
- bExist = true;
- break;
- }
- }
- if( !bExist )
- {
- if( strName[0]!='*' )
- {
- pListBox1->AddString( strName );
- }
- }
- }
- }
- for( it_list1 = list1.begin(); it_list1 != list1.end(); )
- {
- list1.erase(it_list1++);
- }
- return nRet;
- }
- // 根據組的ID得到該組的所有用户
- INT CDBInterface::GetGroupUserByID( CListBox *pListBox,int iGroupID )
- {
- int nCount = pListBox->GetCount();
- for( int i = nCount-1; i >=0; i-- )
- {
- pListBox->DeleteString( i );
- }
- CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
- list<string> list1;
- list<string>::iterator it_list1;
- int nPermitID=0;
- CString strPermitName, strDesc, str;
- if(!_stricmp(g_strDBType, "PGSQL"))
- {
- sprintf(strSQLText, "select userid from t_role_user where group_id = %d order by id", iGroupID);
- }
- else
- {
- sprintf(strSQLText, "select userid from t_role_user where group_id = %d order by id", iGroupID);
- }
- int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList1(strSQLText, list1);
- if( 0 == list1.size() )
- {
- return 0;
- }
- if( nRet != -1 )
- {
- for( it_list1 = list1.begin(); it_list1 != list1.end(); it_list1++ )
- {
- strDesc = (*it_list1).c_str();
- strDesc = strDesc.Trim();
- pListBox->AddString( strDesc );
- }
- }
- for( it_list1 = list1.begin(); it_list1 != list1.end(); )
- {
- list1.erase(it_list1++);
- }
- return 0;
- }
- // 如果2中有則1沒
- INT CDBInterface::GetGroupUserByID( CListBox *pListBox1,CListBox *pListBox2 )
- {
- int nCount2 = pListBox2->GetCount();
- int nCount1 = pListBox1->GetCount();
- for( int i = nCount1-1; i >=0; i-- )
- {
- pListBox1->DeleteString( i );
- }
- CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
- list<string> list1;
- list<string>::iterator it_list1;
- int nPermitID=0;
- CString strName, str;
- if(!_stricmp(g_strDBType, "PGSQL"))
- {
- sprintf(strSQLText, "select uid from t_user_info order by id");
- }
- else
- {
- sprintf(strSQLText, "select uid from t_user_info order by id");
- }
- int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList1(strSQLText, list1);
- if( 0 == list1.size() )
- {
- return 0;
- }
- if( nRet != -1 )
- {
- for( it_list1 = list1.begin(); it_list1 != list1.end(); it_list1++ )
- {
- strName = (*it_list1).c_str();
- strName = strName.Trim();
- bool bExist = false;
- for( int i=0;i<nCount2;i++ )
- {
- pListBox2->GetText( i, str );
- if( str==strName )
- {
- bExist = true;
- break;
- }
- }
- if( !bExist && strName!="admin" )
- {
- pListBox1->AddString( strName );
- }
- }
- }
- for( it_list1 = list1.begin(); it_list1 != list1.end(); )
- {
- list1.erase(it_list1++);
- }
- return nRet;
- }
- //获取指定厂家的设备型号ID
- INT CDBInterface::GetDriverName( int nDriverID, CString &sDriverName )
- {
- CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
- list<string> list1;
- list<string>::iterator it;
- if (!_stricmp(m_chDBType, "SQL SERVER"))
- {
- sprintf(strSQLText, "select top 1 drivename from t_dev_drive where id = %d", nDriverID );
- }
- else if (!_stricmp(m_chDBType, "ACCESS97"))
- {
- sprintf(strSQLText, "select top 1 drivename from t_dev_drive where id = %d", nDriverID );
- }
- else if (!_stricmp(m_chDBType, "ACCESS2000"))
- {
- sprintf(strSQLText, "select top 1 drivename from t_dev_drive where id = %d", nDriverID );
- }
- else if(!_stricmp(m_chDBType, "PGSQL"))
- {
- sprintf(strSQLText, "select drivename from t_dev_drive where id = %d limit 1", nDriverID );
- }
- int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList1(strSQLText, list1);
- if( 0 == list1.size() )
- {
- return 0;
- }
- if( nRet != -1 )
- {
- sDriverName = list1.begin()->c_str();
- //strcpy( pDriverName, list1.begin()->c_str() );
- }
- for( it = list1.begin(); it != list1.end(); )
- {
- list1.erase(it++);
- }
- return nRet;
- }
- //获取指定驱动ID和厂家ID的厂家名称
- INT CDBInterface::GetFactoryName( int nDriverID, int nFactoryID, CString &sFactoryName )
- {
- CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
- list<string> list1;
- list<string>::iterator it;
- if (!_stricmp(m_chDBType, "SQL SERVER"))
- {
- sprintf(strSQLText, "select top 1 factoryname from t_dev_factory where deviceid = %d and factoryid = %d", nDriverID, nFactoryID );
- }
- else if (!_stricmp(m_chDBType, "ACCESS97"))
- {
- sprintf(strSQLText, "select top 1 factoryname from t_dev_factory where deviceid = %d and factoryid = %d", nDriverID, nFactoryID );
- }
- else if (!_stricmp(m_chDBType, "ACCESS2000"))
- {
- sprintf(strSQLText, "select top 1 factoryname from t_dev_factory where deviceid = %d and factoryid = %d", nDriverID, nFactoryID );
- }
- else if(!_stricmp(m_chDBType, "PGSQL"))
- {
- sprintf(strSQLText, "select factoryname from t_dev_factory where deviceid = %d and factoryid = %d limit 1", nDriverID, nFactoryID );
- }
- int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList1(strSQLText, list1);
- if( 0 == list1.size() )
- {
- return 0;
- }
- if( nRet != -1 )
- {
- sFactoryName = list1.begin()->c_str();
- //strcpy( pFactoryName, list1.begin()->c_str() );
- }
- for( it = list1.begin(); it != list1.end(); )
- {
- list1.erase(it++);
- }
- return nRet;
- }
- //获取指定驱动ID,厂家ID和设备类型ID的名称
- INT CDBInterface::GetDevicesName( int nDriverID, int nFactoryID, int nDevicesID,CString &sDevicesName )
- {
- CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
- list<string> list1;
- list<string>::iterator it;
- if (!_stricmp(m_chDBType, "SQL SERVER"))
- {
- sprintf(strSQLText, "select top 1 equiptype from t_dev_type where id = %d and factoryid = %d and driveid = %d", nDevicesID,nFactoryID, nDriverID );
- }
- else if (!_stricmp(m_chDBType, "ACCESS97"))
- {
- sprintf(strSQLText, "select top 1 equiptype from t_dev_type where id = %d and factoryid = %d and driveid = %d", nDevicesID,nFactoryID, nDriverID );
- }
- else if (!_stricmp(m_chDBType, "ACCESS2000"))
- {
- sprintf(strSQLText, "select top 1 equiptype from t_dev_type where id = %d and factoryid = %d and driveid = %d", nDevicesID,nFactoryID, nDriverID );
- }
- else if(!_stricmp(m_chDBType, "PGSQL"))
- {
- sprintf(strSQLText, "select equiptype from t_dev_type where id = %d and factoryid = %d and driveid = %d limit 1", nDevicesID,nFactoryID, nDriverID );
- }
- int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList1(strSQLText, list1);
- if( 0 == list1.size() )
- {
- return 0;
- }
- if( nRet != -1 )
- {
- sDevicesName = list1.begin()->c_str();
- //strcpy( pDevicesName, list1.begin()->c_str() );
- }
- for( it = list1.begin(); it != list1.end(); )
- {
- list1.erase(it++);
- }
- return nRet;
- }
- //当编辑用户时要更新其它表的对应用户的帐号
- INT CDBInterface::UpdateOtherTableUserName( CHAR *pUserID_Old,CHAR *pUserID_New )
- {
- CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
- sprintf(strSQLText, "UPDATE t_role_user SET userid=\'%s\' where userid=\'%s\'",
- pUserID_New, pUserID_Old);
- return CDBConnection::GetInstancePtr()->Execute(strSQLText);
- }
- };
|