/************************************************************* /* 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::GetDatePlan( int nPlanType, CHAR *pPlanID, unsigned char nBufDate[7][24] ) {//0:星期一 1:星期二 6:星期天 CHAR strSQLText[MAX_SQL_LENGTH + 1] = ""; list list1, list2, list3, list4; list::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 list1, list2, list3, list4; list::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; } };