| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092 |
- /*************************************************************
- /* 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);
- }
- //获取设备类型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 sTemp = list1.begin()->c_str();
- CString s;
- for( int i=sTemp.GetLength()-1;i>0;i-- )
- {
- if( sTemp[i]=='.' )
- {
- s = sTemp.Mid( i+1,sTemp.GetLength()-i );
- break;
- }
- }
- strcpy(pDevNum, s);
- }
- 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::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( CHAR *pUserID, 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 userid = \'%s\' " \
- " and uid = \'%s\' and userid <> \'admin\'", pUserID, pUid);
- }
- else if (!_stricmp(m_chDBType, "ACCESS97"))
- {
- sprintf(strSQLText, "select top 1 uid from t_role_equip where userid = \'%s\' " \
- " and uid = \'%s\' and userid <> \'admin\'", pUserID, pUid);
- }
- else if (!_stricmp(m_chDBType, "ACCESS2000"))
- {
- sprintf(strSQLText, "select top 1 uid from t_role_equip where userid = \'%s\' " \
- " and uid = \'%s\' and userid <> \'admin\'", pUserID, pUid);
- }
- else if(!_stricmp(m_chDBType, "PGSQL"))
- {
- sprintf(strSQLText, "select uid from t_role_equip where userid = \'%s\' " \
- " and uid = \'%s\' and userid <> \'admin\' limit 1", pUserID, 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(CHAR *pUserID)
- {
- CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
- sprintf(strSQLText, "delete from t_role_equip where userid = \'%s\'", pUserID);
- return CDBConnection::GetInstancePtr()->Execute(strSQLText);
- }
- //添加设备权限信息
- INT CDBInterface::AddUserDevInfo(int nID, CHAR *pUserID, CHAR *pUid)
- {
- CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
- sprintf(strSQLText, "insert into t_role_equip(id, userid, uid) values (%d, " \
- "\'%s\', \'%s\')", nID, pUserID, 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;
- }
- 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 nRet;
- }
- 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");
- }
- 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();
- if( strName.Compare("管理员" ) )
- 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::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 nRet;
- }
- //得到用戶所屬的組
- 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("") )
- {
- bTel = true;
- 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;
- }
- };
|