/////////////////////////////////////////////////////////// // // File: // UserDBProcess.cpp // Author: // 严晓斌 // Date: // 2008-05-23 // Comments: // 主要用户信息、权限数据库处理模块 // /////////////////////////////////////////////////////////// #include "stdafx.h" #include "Global.h" #include #include #include #include "Ado.h" #include "DBConnection.h" #include "PrintQueue.h" #include "ChineseRes/resource.h" //验证用户名、密码是否合法 INT ValidateUser(CHAR *pUserID, CHAR *pUserPwd) { CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = ""; CHAR strSQLText[MAX_SQL_LENGTH + 1] = ""; CADORecordset* pRSet = NULL; INT iRetCode = 0; int nRet = 0; try { if (g_pADODatabase != NULL && g_pADODatabase->IsOpen()) { pRSet = new CADORecordset(g_pADODatabase); if (NULL == pRSet) { nRet = 0; } if(!_stricmp(g_strDBType, "PGSQL")) { sprintf(strSQLText, "select 1 from t_user_info where uid = \'%s\' and pwd = \'%s\' LIMIT 1", pUserID, pUserPwd); } else { sprintf(strSQLText, "select top 1 1 from t_user_info where uid = \'%s\' and pwd = \'%s\'", pUserID, pUserPwd); } iRetCode = pRSet->Open(strSQLText, CADORecordset::openQuery); if (iRetCode == 0) { nRet = -1; } if (pRSet->GetRecordCount() > 0) { nRet = 1; } } } catch (...) { if( pRSet ) { delete pRSet; pRSet = NULL; } sprintf(strMsg, g_strErrorExecSql, strSQLText); AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg)); nRet = -1; } if( pRSet ) { delete pRSet; pRSet = NULL; } return nRet; } //验证用户是否启用 INT ValidateUserEnable(CHAR *pUserID, CHAR *pStatus) { CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = {0}; CHAR strSQLText[MAX_SQL_LENGTH + 1] = {0}; CString str; CADORecordset* pRSet = NULL; INT iRetCode = 0; int nRecordCount = 0; try { if (g_pADODatabase != NULL && g_pADODatabase->IsOpen()) { pRSet = new CADORecordset(g_pADODatabase); if (NULL == pRSet) { return -1; } sprintf(strSQLText, "select status from t_user_info where uid = \'%s\'", pUserID); iRetCode = pRSet->Open(strSQLText, CADORecordset::openQuery); if (iRetCode == 0) { delete pRSet; pRSet = NULL; return -1; } nRecordCount = pRSet->GetRecordCount(); if (nRecordCount == 0) { if( pRSet ) { delete pRSet; pRSet = NULL; } return 0; } if (!pRSet->IsFieldNull("status")) { pRSet->GetFieldValue("status", str); strcpy(pStatus, (char*)(LPCTSTR)str); } } } catch (...) { if( pRSet ) { delete pRSet; pRSet = NULL; } sprintf(strMsg, g_strErrorExecSql, strSQLText); AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg)); return -1; } if( pRSet ) { delete pRSet; pRSet = NULL; } return 0; } //修改密码 INT ModifyPwd(CHAR *pUserID, CHAR *pUserPwd) { CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = ""; CHAR strSQLText[MAX_SQL_LENGTH + 1] = ""; INT iRetCode = 0; try { if (g_pADODatabase != NULL && g_pADODatabase->IsOpen()) { sprintf(strSQLText, "UPDATE t_user_info SET uid=\'%s\', pwd=\'%s\'", pUserID, pUserPwd); iRetCode = g_pADODatabase->Execute(strSQLText); } } catch (...) { sprintf(strMsg, g_strErrorExecSql, strSQLText); AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg)); return 0; } return iRetCode; } //添加用户信息 INT AddUser(CHAR *pUserID, CHAR *pUserPwd, CHAR *pUserName, CHAR *pTel, CHAR *pMobileTel, CHAR *pEmail, CHAR *pFax, int nStatus) { CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = ""; CHAR strSQLText[MAX_SQL_LENGTH + 1] = ""; INT iRetCode = 0; try { if (g_pADODatabase != NULL && g_pADODatabase->IsOpen()) { sprintf(strSQLText, "insert into t_user_info(uid, pwd, username, tel, " \ "mobiletel, email, fax, status) values (\'%s\', \'%s\', \'%s\', \'%s\', " \ "\'%s\', \'%s\', \'%s\', %d)", pUserID, pUserPwd, pUserName, pTel, pMobileTel, pEmail, pFax, nStatus); iRetCode = g_pADODatabase->Execute(strSQLText); } } catch (...) { sprintf(strMsg, g_strErrorExecSql, strSQLText); AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg)); return 0; } return iRetCode; } //修改用户信息 INT EditUser(int nID, CHAR *pUserName, CHAR *pTel, CHAR *pMobileTel, CHAR *pEmail, CHAR *pFax, int nStatus) { CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = ""; CHAR strSQLText[MAX_SQL_LENGTH + 1] = ""; INT iRetCode = 0; try { if (g_pADODatabase != NULL && g_pADODatabase->IsOpen()) { sprintf(strSQLText, "update t_user_info set username = \'%s\', tel = \'%s\', " \ "mobiletel = \'%s\', email = \'%s\', fax = \'%s\', status = %d " "where id = %d", pUserName, pTel, pMobileTel, pEmail, pFax, nStatus, nID); iRetCode = g_pADODatabase->Execute(strSQLText); } } catch (...) { sprintf(strMsg, g_strErrorExecSql, strSQLText); AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg)); return 0; } return iRetCode; } //添加用户信息列表 INT InsertUserList(CListCtrl *list) { CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = ""; CHAR strSQLText[MAX_SQL_LENGTH + 1] = ""; CADORecordset* pRSet = NULL; INT iRetCode = 0; CString cstrValue, str; INT nID; CHAR strUserIDGet[MAX_NAME_LENGTH + 1] = ""; CHAR strUserNameGet[MAX_NAME_LENGTH + 1] = ""; int nRet = 0; CString strTel, strMobileTel, strEmail, strFax, strStatus; try { if (g_pADODatabase != NULL && g_pADODatabase->IsOpen()) { pRSet = new CADORecordset(g_pADODatabase); if (NULL == pRSet) { nRet = -1; } sprintf(strSQLText, "select * from t_user_info where uid != \'admin\' order by id asc"); iRetCode = pRSet->Open(strSQLText, CADORecordset::openQuery); if (iRetCode == 0) { nRet = -1; } if (pRSet->GetRecordCount() == 0) { nRet = -1; } for( int i = 0; i < (int)pRSet->GetRecordCount(); i++ ) { //获取Id if (!pRSet->IsFieldNull("ID")) { pRSet->GetFieldValue("ID", nID); cstrValue.Format("%d", nID); //list->SetItemText( i, 0, cstrValue ); list->InsertItem(i, cstrValue); } //获取用户名 if (!pRSet->IsFieldNull("uid")) { pRSet->GetFieldValue("uid", cstrValue); strcpy(strUserIDGet, (char*)(LPCTSTR)cstrValue); list->SetItemText( i, 1, cstrValue ); } //获取用户姓名 if (!pRSet->IsFieldNull("username")) { pRSet->GetFieldValue("username", cstrValue); strcpy(strUserNameGet, (char*)(LPCTSTR)cstrValue); list->SetItemText( i, 2, cstrValue ); } else { list->SetItemText( i, 2, "" ); } //获取电话 if (!pRSet->IsFieldNull("tel")) { pRSet->GetFieldValue("tel", strTel); list->SetItemText( i, 3, strTel ); } //获取手机 if (!pRSet->IsFieldNull("mobiletel")) { pRSet->GetFieldValue("mobiletel", strMobileTel); list->SetItemText( i, 4, strMobileTel ); } //获取Email if (!pRSet->IsFieldNull("email")) { pRSet->GetFieldValue("email", strEmail); list->SetItemText( i, 5, strEmail ); } //获取Fax if (!pRSet->IsFieldNull("fax")) { pRSet->GetFieldValue("fax", strFax); list->SetItemText( i, 6, strFax ); } //获取状态 if (!pRSet->IsFieldNull("status")) { pRSet->GetFieldValue("status", strStatus); if( atoi(strStatus) == 0 ) { str.LoadString(IDS_COMBO_ENABLE); list->SetItemText( i, 7, str); } else if( atoi(strStatus) == 1 ) { str.LoadString(IDS_COMBO_DISABLE); list->SetItemText( i, 7, str ); } } pRSet->MoveNext(); } } } catch (...) { if( pRSet ) { delete pRSet; pRSet = NULL; } sprintf(strMsg, g_strErrorExecSql, strSQLText); AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg)); nRet = -1; } if( pRSet ) { delete pRSet; pRSet = NULL; } return nRet; } //删除用户信息 By 表自增ID INT DelUserInfo(int ID) { CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = ""; CHAR strSQLText[MAX_SQL_LENGTH + 1] = ""; INT iRetCode = 0; try { if (g_pADODatabase != NULL && g_pADODatabase->IsOpen()) { sprintf(strSQLText, "Delete from t_user_info where id = %d", ID); iRetCode = g_pADODatabase->Execute(strSQLText); } } catch (...) { sprintf(strMsg, g_strErrorExecSql, strSQLText); AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg)); return 0; } return iRetCode; } //删除用户角色信息 INT DelUserRoleInfo(CHAR *pUserID) { CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = ""; CHAR strSQLText[MAX_SQL_LENGTH + 1] = ""; INT iRetCode = 0; try { if (g_pADODatabase != NULL && g_pADODatabase->IsOpen()) { sprintf(strSQLText, "Delete from t_role_user where userid = \'%s\'", pUserID); iRetCode = g_pADODatabase->Execute(strSQLText); } } catch (...) { sprintf(strMsg, g_strErrorExecSql, strSQLText); AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg)); return 0; } return iRetCode; } //删除用户已分配权限 INT DelUserEquipInfo(CHAR *pUserID) { CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = ""; CHAR strSQLText[MAX_SQL_LENGTH + 1] = ""; INT iRetCode = 0; try { if (g_pADODatabase != NULL && g_pADODatabase->IsOpen()) { sprintf(strSQLText, "Delete from t_role_equip where userid = \'%s\'", pUserID); iRetCode = g_pADODatabase->Execute(strSQLText); } } catch (...) { sprintf(strMsg, g_strErrorExecSql, strSQLText); AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg)); return 0; } return iRetCode; } //得到用户信息最大ID INT GetUserMaxID( CHAR *pMaxID ) { CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = {0}; CHAR strSQLText[MAX_SQL_LENGTH + 1] = {0}; CString str; CADORecordset* pRSet = NULL; INT iRetCode = 0; int nRecordCount = 0; try { if (g_pADODatabase != NULL && g_pADODatabase->IsOpen()) { pRSet = new CADORecordset(g_pADODatabase); if (NULL == pRSet) { return -1; } sprintf(strSQLText, "select id from t_user_info order by ID desc LIMIT 1"); iRetCode = pRSet->Open(strSQLText, CADORecordset::openQuery); if (iRetCode == 0) { delete pRSet; pRSet = NULL; return -1; } nRecordCount = pRSet->GetRecordCount(); if (nRecordCount == 0) { if( pRSet ) { delete pRSet; pRSet = NULL; } return 0; } if (!pRSet->IsFieldNull("id")) { pRSet->GetFieldValue("id", str); strcpy(pMaxID, (char*)(LPCTSTR)str); } } } catch (...) { if( pRSet ) { delete pRSet; pRSet = NULL; } sprintf(strMsg, g_strErrorExecSql, strSQLText); AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg)); return -1; } if( pRSet ) { delete pRSet; pRSet = NULL; } return 0; } //得到用户信息ID INT GetUserID( CHAR *pID, CHAR *pUserID ) { CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = {0}; CHAR strSQLText[MAX_SQL_LENGTH + 1] = {0}; CString str; CADORecordset* pRSet = NULL; INT iRetCode = 0; int nRecordCount = 0; try { if (g_pADODatabase != NULL && g_pADODatabase->IsOpen()) { pRSet = new CADORecordset(g_pADODatabase); if (NULL == pRSet) { return -1; } sprintf(strSQLText, "select id from t_user_info where uid = \'%s\'", pUserID); iRetCode = pRSet->Open(strSQLText, CADORecordset::openQuery); if (iRetCode == 0) { delete pRSet; pRSet = NULL; return -1; } nRecordCount = pRSet->GetRecordCount(); if (nRecordCount == 0) { if( pRSet ) { delete pRSet; pRSet = NULL; } return 0; } if (!pRSet->IsFieldNull("id")) { pRSet->GetFieldValue("id", str); strcpy(pID, (char*)(LPCTSTR)str); } if( pRSet ) { delete pRSet; pRSet = NULL; } return nRecordCount; } } catch (...) { if( pRSet ) { delete pRSet; pRSet = NULL; } sprintf(strMsg, g_strErrorExecSql, strSQLText); AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg)); return -1; } if( pRSet ) { delete pRSet; pRSet = NULL; } return 0; } //添加用户组信息列表 INT InsertUserGroupInfoList(CListCtrl *list, CHAR *pSQLText) { CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = ""; //CHAR strSQLText[MAX_SQL_LENGTH + 1] = ""; CADORecordset* pRSet = NULL; INT iRetCode = 0; int nRet = 0; CString strID, strGroupName, strGroupDesc; try { if (g_pADODatabase != NULL && g_pADODatabase->IsOpen()) { pRSet = new CADORecordset(g_pADODatabase); if (NULL == pRSet) nRet = -1; iRetCode = pRSet->Open(pSQLText, CADORecordset::openQuery); if (iRetCode == 0) { nRet = -1; } if (pRSet->GetRecordCount() == 0) { nRet = -1; } for( int i = 0; i < (int)pRSet->GetRecordCount(); i++ ) { //ID if (!pRSet->IsFieldNull("ID")) { pRSet->GetFieldValue("ID", strID); list->InsertItem(i, strID); } //组名称 if( !pRSet->IsFieldNull("groupname") ) { pRSet->GetFieldValue("groupname", strGroupName); list->SetItemText( i, 1, strGroupName ); } //组描述 if( !pRSet->IsFieldNull("groupdesc") ) { pRSet->GetFieldValue("groupdesc", strGroupDesc); list->SetItemText( i, 2, strGroupDesc ); } pRSet->MoveNext(); } } } catch (...) { if( pRSet ) { delete pRSet; pRSet = NULL; } sprintf(strMsg, g_strErrorExecSql, pSQLText); AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg)); nRet = -1; } if( pRSet ) { delete pRSet; pRSet = NULL; } return nRet; } //添加用户组信息 INT AddUserGroupInfo(CHAR *pGroupName, CHAR *pGroupDesc) { CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = ""; CHAR strSQLText[MAX_SQL_LENGTH + 1] = ""; INT iRetCode = 0; try { if (g_pADODatabase != NULL && g_pADODatabase->IsOpen()) { sprintf(strSQLText, "insert into t_user_group(groupname, groupdesc) values (\'%s\', " \ "\'%s\')", pGroupName, pGroupDesc); iRetCode = g_pADODatabase->Execute(strSQLText); } } catch (...) { sprintf(strMsg, g_strErrorExecSql, strSQLText); AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg)); return 0; } return iRetCode; } //修改用户组信息 INT EditUserGroupInfo(int nID, CHAR *pGroupName, CHAR *pGroupDesc) { CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = ""; CHAR strSQLText[MAX_SQL_LENGTH + 1] = ""; INT iRetCode = 0; try { if (g_pADODatabase != NULL && g_pADODatabase->IsOpen()) { sprintf(strSQLText, "update t_user_group set groupname = \'%s\', groupdesc = \'%s\' " \ " where id = %d", pGroupName, pGroupDesc, nID); iRetCode = g_pADODatabase->Execute(strSQLText); } } catch (...) { sprintf(strMsg, g_strErrorExecSql, strSQLText); AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg)); return 0; } return iRetCode; } //删除用户组信息 INT DelUserGroupInfo(int nID) { CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = ""; CHAR strSQLText[MAX_SQL_LENGTH + 1] = ""; INT iRetCode = 0; try { if (g_pADODatabase != NULL && g_pADODatabase->IsOpen()) { sprintf(strSQLText, "delete from t_user_group where id = %d", nID); iRetCode = g_pADODatabase->Execute(strSQLText); } } catch (...) { sprintf(strMsg, g_strErrorExecSql, strSQLText); AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg)); return 0; } return iRetCode; } //得到用户组信息最大ID INT GetUserGroupMaxID( CHAR *pMaxID ) { CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = {0}; CHAR strSQLText[MAX_SQL_LENGTH + 1] = {0}; CString str; CADORecordset* pRSet = NULL; INT iRetCode = 0; int nRecordCount = 0; try { if (g_pADODatabase != NULL && g_pADODatabase->IsOpen()) { pRSet = new CADORecordset(g_pADODatabase); if (NULL == pRSet) { return -1; } sprintf(strSQLText, "select id from t_user_group order by ID desc LIMIT 1"); iRetCode = pRSet->Open(strSQLText, CADORecordset::openQuery); if (iRetCode == 0) { delete pRSet; pRSet = NULL; return -1; } nRecordCount = pRSet->GetRecordCount(); if (nRecordCount == 0) { if( pRSet ) { delete pRSet; pRSet = NULL; } return 0; } if (!pRSet->IsFieldNull("id")) { pRSet->GetFieldValue("id", str); strcpy(pMaxID, (char*)(LPCTSTR)str); } } } catch (...) { if( pRSet ) { delete pRSet; pRSet = NULL; } sprintf(strMsg, g_strErrorExecSql, strSQLText); AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg)); return -1; } if( pRSet ) { delete pRSet; pRSet = NULL; } return 0; } //添加用户权限信息列表 INT InsertUserPurviewInfoList(CListCtrl *list, CHAR *pSQLText) { CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = ""; //CHAR strSQLText[MAX_SQL_LENGTH + 1] = ""; CADORecordset* pRSet = NULL; INT iRetCode = 0; int nRet = 0; CString strID, strPurviewName, strPurviewDesc; try { if (g_pADODatabase != NULL && g_pADODatabase->IsOpen()) { pRSet = new CADORecordset(g_pADODatabase); if (NULL == pRSet) nRet = -1; iRetCode = pRSet->Open(pSQLText, CADORecordset::openQuery); if (iRetCode == 0) { nRet = -1; } if (pRSet->GetRecordCount() == 0) { nRet = -1; } for( int i = 0; i < (int)pRSet->GetRecordCount(); i++ ) { //ID if (!pRSet->IsFieldNull("ID")) { pRSet->GetFieldValue("ID", strID); list->InsertItem(i, strID); } //权限名称 if( !pRSet->IsFieldNull("purview_name") ) { pRSet->GetFieldValue("purview_name", strPurviewName); list->SetItemText( i, 1, strPurviewName ); } //权限描述 if( !pRSet->IsFieldNull("purview_desc") ) { pRSet->GetFieldValue("purview_desc", strPurviewDesc); list->SetItemText( i, 2, strPurviewDesc ); } pRSet->MoveNext(); } } } catch (...) { if( pRSet ) { delete pRSet; pRSet = NULL; } sprintf(strMsg, g_strErrorExecSql, pSQLText); AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg)); nRet = -1; } if( pRSet ) { delete pRSet; pRSet = NULL; } return nRet; } //添加用户权限信息 INT AddUserPurviewInfo(CHAR *pPurviewName, CHAR *pPurviewDesc) { CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = ""; CHAR strSQLText[MAX_SQL_LENGTH + 1] = ""; INT iRetCode = 0; try { if (g_pADODatabase != NULL && g_pADODatabase->IsOpen()) { sprintf(strSQLText, "insert into t_user_purview(purview_name, purview_desc) values (\'%s\', " \ "\'%s\')", pPurviewName, pPurviewDesc); iRetCode = g_pADODatabase->Execute(strSQLText); } } catch (...) { sprintf(strMsg, g_strErrorExecSql, strSQLText); AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg)); return 0; } return iRetCode; } //修改用户权限信息 INT EditUserPurviewInfo(int nID, CHAR *pPurviewName, CHAR *pPurviewDesc) { CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = ""; CHAR strSQLText[MAX_SQL_LENGTH + 1] = ""; INT iRetCode = 0; try { if (g_pADODatabase != NULL && g_pADODatabase->IsOpen()) { sprintf(strSQLText, "update t_user_purview set purview_name = \'%s\', purview_desc = \'%s\' " \ " where id = %d", pPurviewName, pPurviewDesc, nID); iRetCode = g_pADODatabase->Execute(strSQLText); } } catch (...) { sprintf(strMsg, g_strErrorExecSql, strSQLText); AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg)); return 0; } return iRetCode; } //删除用户权限信息 INT DelUserPurviewInfo(int nID) { CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = ""; CHAR strSQLText[MAX_SQL_LENGTH + 1] = ""; INT iRetCode = 0; try { if (g_pADODatabase != NULL && g_pADODatabase->IsOpen()) { sprintf(strSQLText, "delete from t_user_purview where id = %d", nID); iRetCode = g_pADODatabase->Execute(strSQLText); } } catch (...) { sprintf(strMsg, g_strErrorExecSql, strSQLText); AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg)); return 0; } return iRetCode; } //得到用户权限信息最大ID INT GetUserPurviewMaxID( CHAR *pMaxID ) { CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = {0}; CHAR strSQLText[MAX_SQL_LENGTH + 1] = {0}; CString str; CADORecordset* pRSet = NULL; INT iRetCode = 0; int nRecordCount = 0; try { if (g_pADODatabase != NULL && g_pADODatabase->IsOpen()) { pRSet = new CADORecordset(g_pADODatabase); if (NULL == pRSet) { return -1; } sprintf(strSQLText, "select id from t_user_purview order by ID desc LIMIT 1"); iRetCode = pRSet->Open(strSQLText, CADORecordset::openQuery); if (iRetCode == 0) { delete pRSet; pRSet = NULL; return -1; } nRecordCount = pRSet->GetRecordCount(); if (nRecordCount == 0) { if( pRSet ) { delete pRSet; pRSet = NULL; } return 0; } if (!pRSet->IsFieldNull("id")) { pRSet->GetFieldValue("id", str); strcpy(pMaxID, (char*)(LPCTSTR)str); } } } catch (...) { if( pRSet ) { delete pRSet; pRSet = NULL; } sprintf(strMsg, g_strErrorExecSql, strSQLText); AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg)); return -1; } if( pRSet ) { delete pRSet; pRSet = NULL; } return 0; } //得到组权限已分配列表 INT GetUserGroupPurviewAllocList( int nGroupID, CHAR *pGroupPurViewAllocIDList ) { CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = ""; CHAR strSQLText[MAX_SQL_LENGTH + 1] = ""; CString strID; CADORecordset* pRSet = NULL; INT iRetCode = 0; int nCount = 0, i; strcpy(pGroupPurViewAllocIDList, ""); try { if (g_pADODatabase != NULL && g_pADODatabase->IsOpen()) { pRSet = new CADORecordset(g_pADODatabase); if (NULL == pRSet) { return -1; } sprintf(strSQLText, "select id from t_user_purview where id not in " \ "(select purview_id from t_user_group_purview "\ "where group_id = %d) order by id asc", nGroupID); iRetCode = pRSet->Open(strSQLText, CADORecordset::openQuery); if (iRetCode == 0) { delete pRSet; pRSet = NULL; return -1; } nCount = pRSet->GetRecordCount(); if (nCount == 0) { if( pRSet ) { delete pRSet; pRSet = NULL; } return 0; } for( i = 0; i < nCount; i++ ) { // 获取区域名称 if (!pRSet->IsFieldNull("id")) { pRSet->GetFieldValue("id", strID); } strcat(pGroupPurViewAllocIDList, strID); strcat(pGroupPurViewAllocIDList, ","); pRSet->MoveNext(); } if( pRSet ) { delete pRSet; pRSet = NULL; } return nCount; } } catch (...) { if( pRSet ) { delete pRSet; pRSet = NULL; } sprintf(strMsg, g_strErrorExecSql, strSQLText); AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg)); return -1; } if( pRSet ) { delete pRSet; pRSet = NULL; } return 0; } //得到组权限未分配列表 INT GetUserGroupPurviewNotAllocList( int nGroupID, CHAR *pGroupPurViewNotAllocIDList ) { CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = ""; CHAR strSQLText[MAX_SQL_LENGTH + 1] = ""; CString strID; CADORecordset* pRSet = NULL; INT iRetCode = 0; int nCount = 0, i; strcpy(pGroupPurViewNotAllocIDList, ""); try { if (g_pADODatabase != NULL && g_pADODatabase->IsOpen()) { pRSet = new CADORecordset(g_pADODatabase); if (NULL == pRSet) { return -1; } sprintf(strSQLText, "select id from t_user_purview where id in " \ "(select purview_id from t_user_group_purview "\ "where group_id = %d) order by id asc", nGroupID); iRetCode = pRSet->Open(strSQLText, CADORecordset::openQuery); if (iRetCode == 0) { delete pRSet; pRSet = NULL; return -1; } nCount = pRSet->GetRecordCount(); if (nCount == 0) { if( pRSet ) { delete pRSet; pRSet = NULL; } return 0; } for( i = 0; i < nCount; i++ ) { // 获取区域名称 if (!pRSet->IsFieldNull("id")) { pRSet->GetFieldValue("id", strID); } strcat(pGroupPurViewNotAllocIDList, strID); strcat(pGroupPurViewNotAllocIDList, ","); pRSet->MoveNext(); } if( pRSet ) { delete pRSet; pRSet = NULL; } return nCount; } } catch (...) { if( pRSet ) { delete pRSet; pRSet = NULL; } sprintf(strMsg, g_strErrorExecSql, strSQLText); AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg)); return -1; } if( pRSet ) { delete pRSet; pRSet = NULL; } return 0; } //得到权限名称 INT GetUserPurviewName( int nID, CHAR *pPurviewName ) { CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = {0}; CHAR strSQLText[MAX_SQL_LENGTH + 1] = {0}; CString str; CADORecordset* pRSet = NULL; INT iRetCode = 0; int nRecordCount = 0; try { if (g_pADODatabase != NULL && g_pADODatabase->IsOpen()) { pRSet = new CADORecordset(g_pADODatabase); if (NULL == pRSet) { return -1; } sprintf(strSQLText, "select purview_name from t_user_purview where id=%d", nID); iRetCode = pRSet->Open(strSQLText, CADORecordset::openQuery); if (iRetCode == 0) { delete pRSet; pRSet = NULL; return -1; } nRecordCount = pRSet->GetRecordCount(); if (nRecordCount == 0) { if( pRSet ) { delete pRSet; pRSet = NULL; } return 0; } if (!pRSet->IsFieldNull("purview_name")) { pRSet->GetFieldValue("purview_name", str); strcpy(pPurviewName, (char*)(LPCTSTR)str); } } } catch (...) { if( pRSet ) { delete pRSet; pRSet = NULL; } sprintf(strMsg, g_strErrorExecSql, strSQLText); AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg)); return -1; } if( pRSet ) { delete pRSet; pRSet = NULL; } return 0; } //得到权限ID INT GetUserPurviewID( CHAR *pID, CHAR *pPurviewName ) { CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = {0}; CHAR strSQLText[MAX_SQL_LENGTH + 1] = {0}; CString str; CADORecordset* pRSet = NULL; INT iRetCode = 0; int nRecordCount = 0; try { if (g_pADODatabase != NULL && g_pADODatabase->IsOpen()) { pRSet = new CADORecordset(g_pADODatabase); if (NULL == pRSet) { return -1; } sprintf(strSQLText, "select id from t_user_purview where purview_name=\'%s\'", pPurviewName); iRetCode = pRSet->Open(strSQLText, CADORecordset::openQuery); if (iRetCode == 0) { delete pRSet; pRSet = NULL; return -1; } nRecordCount = pRSet->GetRecordCount(); if (nRecordCount == 0) { if( pRSet ) { delete pRSet; pRSet = NULL; } return 0; } if (!pRSet->IsFieldNull("id")) { pRSet->GetFieldValue("id", str); strcpy(pID, (char*)(LPCTSTR)str); } if( pRSet ) { delete pRSet; pRSet = NULL; } return nRecordCount; } } catch (...) { if( pRSet ) { delete pRSet; pRSet = NULL; } sprintf(strMsg, g_strErrorExecSql, strSQLText); AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg)); return -1; } if( pRSet ) { delete pRSet; pRSet = NULL; } return 0; } //得到权限ID INT GetUserPurviewID( int nGroupID, CHAR *pID, CHAR *pPurviewName ) { CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = {0}; CHAR strSQLText[MAX_SQL_LENGTH + 1] = {0}; CString str; CADORecordset* pRSet = NULL; INT iRetCode = 0; int nRecordCount = 0; try { if (g_pADODatabase != NULL && g_pADODatabase->IsOpen()) { pRSet = new CADORecordset(g_pADODatabase); if (NULL == pRSet) { return -1; } sprintf(strSQLText, "select purview_id from t_user_group_purview a, t_user_purview b " \ "where a.purview_id = b.id and b.purview_name=\'%s\' and a.group_id = %d", pPurviewName, nGroupID); iRetCode = pRSet->Open(strSQLText, CADORecordset::openQuery); if (iRetCode == 0) { delete pRSet; pRSet = NULL; return -1; } nRecordCount = pRSet->GetRecordCount(); if (nRecordCount == 0) { if( pRSet ) { delete pRSet; pRSet = NULL; } return 0; } if (!pRSet->IsFieldNull("purview_id")) { pRSet->GetFieldValue("purview_id", str); strcpy(pID, (char*)(LPCTSTR)str); } if( pRSet ) { delete pRSet; pRSet = NULL; } return nRecordCount; } } catch (...) { if( pRSet ) { delete pRSet; pRSet = NULL; } sprintf(strMsg, g_strErrorExecSql, strSQLText); AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg)); return -1; } if( pRSet ) { delete pRSet; pRSet = NULL; } return 0; } //添加用户组权限信息 INT AddUserGroupPurviewInfo(int nGroupID, int nPurviewID, CHAR *pPurviewDesc) { CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = ""; CHAR strSQLText[MAX_SQL_LENGTH + 1] = ""; INT iRetCode = 0; try { if (g_pADODatabase != NULL && g_pADODatabase->IsOpen()) { sprintf(strSQLText, "insert into t_user_group_purview(group_id, purview_id, group_purview_desc) values (%d, %d, " \ "\'%s\')", nGroupID, nPurviewID, pPurviewDesc); iRetCode = g_pADODatabase->Execute(strSQLText); } } catch (...) { sprintf(strMsg, g_strErrorExecSql, strSQLText); AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg)); return 0; } return iRetCode; } //删除用户组权限信息 INT DelUserGroupPurviewInfo(int nGroupID, int nPurviewID) { CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = ""; CHAR strSQLText[MAX_SQL_LENGTH + 1] = ""; INT iRetCode = 0; try { if (g_pADODatabase != NULL && g_pADODatabase->IsOpen()) { sprintf(strSQLText, "delete from t_user_group_purview where group_id = %d and purview_id=%d", nGroupID, nPurviewID); iRetCode = g_pADODatabase->Execute(strSQLText); } } catch (...) { sprintf(strMsg, g_strErrorExecSql, strSQLText); AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg)); return 0; } return iRetCode; } //得到已隶属于户组列表 INT GetUserGroupAllocList( CHAR *pUserID, CHAR *pGroupAllocIDList ) { CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = ""; CHAR strSQLText[MAX_SQL_LENGTH + 1] = ""; CString strID; CADORecordset* pRSet = NULL; INT iRetCode = 0; int nCount = 0, i; strcpy(pGroupAllocIDList, ""); try { if (g_pADODatabase != NULL && g_pADODatabase->IsOpen()) { pRSet = new CADORecordset(g_pADODatabase); if (NULL == pRSet) { return -1; } sprintf(strSQLText, "select id from t_user_group where id not in " \ "(select group_id from t_role_user "\ "where userid = \'%s\') order by id asc", pUserID); iRetCode = pRSet->Open(strSQLText, CADORecordset::openQuery); if (iRetCode == 0) { delete pRSet; pRSet = NULL; return -1; } nCount = pRSet->GetRecordCount(); if (nCount == 0) { if( pRSet ) { delete pRSet; pRSet = NULL; } return 0; } for( i = 0; i < nCount; i++ ) { // 获取用户组ID if (!pRSet->IsFieldNull("id")) { pRSet->GetFieldValue("id", strID); } strcat(pGroupAllocIDList, strID); strcat(pGroupAllocIDList, ","); pRSet->MoveNext(); } if( pRSet ) { delete pRSet; pRSet = NULL; } return nCount; } } catch (...) { if( pRSet ) { delete pRSet; pRSet = NULL; } sprintf(strMsg, g_strErrorExecSql, strSQLText); AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg)); return -1; } if( pRSet ) { delete pRSet; pRSet = NULL; } return 0; } //得到未隶属于户组列表 INT GetUserGroupNotAllocList( CHAR *pUserID, CHAR *pGroupNotAllocIDList ) { CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = ""; CHAR strSQLText[MAX_SQL_LENGTH + 1] = ""; CString strID; CADORecordset* pRSet = NULL; INT iRetCode = 0; int nCount = 0, i; strcpy(pGroupNotAllocIDList, ""); try { if (g_pADODatabase != NULL && g_pADODatabase->IsOpen()) { pRSet = new CADORecordset(g_pADODatabase); if (NULL == pRSet) { return -1; } sprintf(strSQLText, "select id from t_user_group where id in " \ "(select group_id from t_role_user "\ "where userid = \'%s\') order by id asc", pUserID); iRetCode = pRSet->Open(strSQLText, CADORecordset::openQuery); if (iRetCode == 0) { delete pRSet; pRSet = NULL; return -1; } nCount = pRSet->GetRecordCount(); if (nCount == 0) { if( pRSet ) { delete pRSet; pRSet = NULL; } return 0; } for( i = 0; i < nCount; i++ ) { // 获取用户组ID if (!pRSet->IsFieldNull("id")) { pRSet->GetFieldValue("id", strID); } strcat(pGroupNotAllocIDList, strID); strcat(pGroupNotAllocIDList, ","); pRSet->MoveNext(); } if( pRSet ) { delete pRSet; pRSet = NULL; } return nCount; } } catch (...) { if( pRSet ) { delete pRSet; pRSet = NULL; } sprintf(strMsg, g_strErrorExecSql, strSQLText); AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg)); return -1; } if( pRSet ) { delete pRSet; pRSet = NULL; } return 0; } //得到用户组名称 INT GetUserGroupName( int nID, CHAR *pGroupName ) { CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = {0}; CHAR strSQLText[MAX_SQL_LENGTH + 1] = {0}; CString str; CADORecordset* pRSet = NULL; INT iRetCode = 0; int nRecordCount = 0; try { if (g_pADODatabase != NULL && g_pADODatabase->IsOpen()) { pRSet = new CADORecordset(g_pADODatabase); if (NULL == pRSet) { return -1; } sprintf(strSQLText, "select groupname from t_user_group where id=%d", nID); iRetCode = pRSet->Open(strSQLText, CADORecordset::openQuery); if (iRetCode == 0) { delete pRSet; pRSet = NULL; return -1; } nRecordCount = pRSet->GetRecordCount(); if (nRecordCount == 0) { if( pRSet ) { delete pRSet; pRSet = NULL; } return 0; } if (!pRSet->IsFieldNull("groupname")) { pRSet->GetFieldValue("groupname", str); strcpy(pGroupName, (char*)(LPCTSTR)str); } } } catch (...) { if( pRSet ) { delete pRSet; pRSet = NULL; } sprintf(strMsg, g_strErrorExecSql, strSQLText); AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg)); return -1; } if( pRSet ) { delete pRSet; pRSet = NULL; } return 0; } //得到用户组ID INT GetUserGroupID( CHAR *pID, CHAR *pGroupName ) { CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = {0}; CHAR strSQLText[MAX_SQL_LENGTH + 1] = {0}; CString str; CADORecordset* pRSet = NULL; INT iRetCode = 0; int nRecordCount = 0; try { if (g_pADODatabase != NULL && g_pADODatabase->IsOpen()) { pRSet = new CADORecordset(g_pADODatabase); if (NULL == pRSet) { return -1; } sprintf(strSQLText, "select id from t_user_group where groupname=\'%s\'", pGroupName); iRetCode = pRSet->Open(strSQLText, CADORecordset::openQuery); if (iRetCode == 0) { delete pRSet; pRSet = NULL; return -1; } nRecordCount = pRSet->GetRecordCount(); if (nRecordCount == 0) { if( pRSet ) { delete pRSet; pRSet = NULL; } return 0; } if (!pRSet->IsFieldNull("id")) { pRSet->GetFieldValue("id", str); strcpy(pID, (char*)(LPCTSTR)str); } if( pRSet ) { delete pRSet; pRSet = NULL; } return nRecordCount; } } catch (...) { if( pRSet ) { delete pRSet; pRSet = NULL; } sprintf(strMsg, g_strErrorExecSql, strSQLText); AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg)); return -1; } if( pRSet ) { delete pRSet; pRSet = NULL; } return 0; } //得到用户组ID INT GetUserGroupID( CHAR *pUserID, CHAR *pID, CHAR *pGroupName ) { CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = {0}; CHAR strSQLText[MAX_SQL_LENGTH + 1] = {0}; CString str; CADORecordset* pRSet = NULL; INT iRetCode = 0; int nRecordCount = 0; try { if (g_pADODatabase != NULL && g_pADODatabase->IsOpen()) { pRSet = new CADORecordset(g_pADODatabase); if (NULL == pRSet) { return -1; } sprintf(strSQLText, "select group_id from t_role_user a, t_user_group b " \ "where a.group_id = b.id and b.groupname=\'%s\' and a.userid = \'%s\'", pGroupName, pUserID); iRetCode = pRSet->Open(strSQLText, CADORecordset::openQuery); if (iRetCode == 0) { delete pRSet; pRSet = NULL; return -1; } nRecordCount = pRSet->GetRecordCount(); if (nRecordCount == 0) { if( pRSet ) { delete pRSet; pRSet = NULL; } return 0; } if (!pRSet->IsFieldNull("group_id")) { pRSet->GetFieldValue("group_id", str); strcpy(pID, (char*)(LPCTSTR)str); } if( pRSet ) { delete pRSet; pRSet = NULL; } return nRecordCount; } } catch (...) { if( pRSet ) { delete pRSet; pRSet = NULL; } sprintf(strMsg, g_strErrorExecSql, strSQLText); AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg)); return -1; } if( pRSet ) { delete pRSet; pRSet = NULL; } return 0; } //添加用户角色信息 INT AddUserPurviewInfo(CHAR *pUserID, int nGroupID, CHAR *pPurviewDesc) { CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = ""; CHAR strSQLText[MAX_SQL_LENGTH + 1] = ""; INT iRetCode = 0; try { if (g_pADODatabase != NULL && g_pADODatabase->IsOpen()) { sprintf(strSQLText, "insert into t_role_user(userid, group_id, roledesc) values (\'%s\', %d, " \ "\'%s\')", pUserID, nGroupID, pPurviewDesc); iRetCode = g_pADODatabase->Execute(strSQLText); } } catch (...) { sprintf(strMsg, g_strErrorExecSql, strSQLText); AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg)); return 0; } return iRetCode; } //删除用户角色信息 INT DelUserPurviewInfo(CHAR *pUserID, int nGroupID) { CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = ""; CHAR strSQLText[MAX_SQL_LENGTH + 1] = ""; INT iRetCode = 0; try { if (g_pADODatabase != NULL && g_pADODatabase->IsOpen()) { sprintf(strSQLText, "delete from t_role_user where userid = \'%s\' and group_id=%d", pUserID, nGroupID); iRetCode = g_pADODatabase->Execute(strSQLText); } } catch (...) { sprintf(strMsg, g_strErrorExecSql, strSQLText); AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg)); return 0; } return iRetCode; } //插入时间计划 INT InsertDatePlan( int nPlanType, CHAR *pPlanID, int nStartHours, int nEndHours, int nStartWeek, int nEndWeek ) { CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = ""; CHAR strSQLText[MAX_SQL_LENGTH + 1] = ""; INT iRetCode = 0; try { if (g_pADODatabase != NULL && g_pADODatabase->IsOpen()) { 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); iRetCode = g_pADODatabase->Execute(strSQLText); } } catch (...) { sprintf(strMsg, g_strErrorExecSql, strSQLText); AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg)); return 0; } return iRetCode; } //插入时间计划 INT InsertDatePlan( int nPlanType, int nEquipTypeID, int nEquipID, int nPort, int nStartHours, int nEndHours, int nStartWeek, int nEndWeek ) { CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = ""; CHAR strSQLText[MAX_SQL_LENGTH + 1] = ""; INT iRetCode = 0; try { if (g_pADODatabase != NULL && g_pADODatabase->IsOpen()) { sprintf(strSQLText, "insert into t_plan_info(plantype, equip_type_id, equip_id, port, starttime, endtime, " \ "startweekofday, endweekofday) values (%d, %d, %d, %d, %d, %d, %d, %d) ", nPlanType, nEquipTypeID, nEquipID, nPort, nStartHours, nEndHours, nStartWeek, nEndWeek); iRetCode = g_pADODatabase->Execute(strSQLText); } } catch (...) { sprintf(strMsg, g_strErrorExecSql, strSQLText); AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg)); return 0; } return iRetCode; } //删除原有的时间计划 INT DeleteDatePlan( int nPlanType, CHAR *pPlanID ) { CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = ""; CHAR strSQLText[MAX_SQL_LENGTH + 1] = ""; INT iRetCode = 0; try { if (g_pADODatabase != NULL && g_pADODatabase->IsOpen()) { sprintf(strSQLText, "delete from t_plan_info where planid = \'%s\' and plantype=%d", pPlanID, nPlanType); iRetCode = g_pADODatabase->Execute(strSQLText); } } catch (...) { sprintf(strMsg, g_strErrorExecSql, strSQLText); AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg)); return 0; } return iRetCode; } //删除原有的时间计划 INT DeleteDatePlan( int nPlanType, int nEquipTypeID, int nEquipID, int nPort ) { CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = ""; CHAR strSQLText[MAX_SQL_LENGTH + 1] = ""; INT iRetCode = 0; try { if (g_pADODatabase != NULL && g_pADODatabase->IsOpen()) { sprintf(strSQLText, "delete from t_plan_info where equip_type_id = %d and equip_id = %d and port = %d and plantype=%d", nEquipTypeID, nEquipID, nPort, nPlanType); iRetCode = g_pADODatabase->Execute(strSQLText); } } catch (...) { sprintf(strMsg, g_strErrorExecSql, strSQLText); AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg)); return 0; } return iRetCode; } //删除原有的时间计划 INT DeleteDatePlan( int nPlanType, int nEquipTypeID, int nEquipID ) { CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = ""; CHAR strSQLText[MAX_SQL_LENGTH + 1] = ""; INT iRetCode = 0; try { if (g_pADODatabase != NULL && g_pADODatabase->IsOpen()) { sprintf(strSQLText, "delete from t_plan_info where equip_type_id = %d and equip_id = %d and plantype=%d", nEquipTypeID, nEquipID, nPlanType); iRetCode = g_pADODatabase->Execute(strSQLText); } } catch (...) { sprintf(strMsg, g_strErrorExecSql, strSQLText); AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg)); return 0; } return iRetCode; } //得到时间计划 INT GetDatePlan( int nPlanType, CHAR *pPlanID, unsigned char nBufDate[7][24] ) { CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = {0}; CHAR strSQLText[MAX_SQL_LENGTH + 1] = {0}; CString str; CADORecordset* pRSet = NULL; INT iRetCode = 0; int nRecordCount = 0; double fStartTime = 0,fEndTime = 0; int nStartWeek = 0,nEndWeek = 0; try { if (g_pADODatabase != NULL && g_pADODatabase->IsOpen()) { pRSet = new CADORecordset(g_pADODatabase); if (NULL == pRSet) { return -1; } sprintf(strSQLText, "select starttime, endtime, startweekofday, endweekofday " \ "from t_plan_info where planid=\'%s\' and plantype = %d", pPlanID, nPlanType); iRetCode = pRSet->Open(strSQLText, CADORecordset::openQuery); if (iRetCode == 0) { delete pRSet; pRSet = NULL; return -1; } nRecordCount = pRSet->GetRecordCount(); if (nRecordCount == 0) { if( pRSet ) { delete pRSet; pRSet = NULL; } return 0; } for( int i = 0; i < nRecordCount; i++ ) { if (!pRSet->IsFieldNull("starttime")) { pRSet->GetFieldValue("starttime", fStartTime); } if (!pRSet->IsFieldNull("endtime")) { pRSet->GetFieldValue("endtime", fEndTime); } if (!pRSet->IsFieldNull("startweekofday")) { pRSet->GetFieldValue("startweekofday", nStartWeek); } if (!pRSet->IsFieldNull("endweekofday")) { pRSet->GetFieldValue("endweekofday", nEndWeek); } for(int y = nStartWeek;yMoveNext(); } if( pRSet ) { delete pRSet; pRSet = NULL; } return nRecordCount; } } catch (...) { if( pRSet ) { delete pRSet; pRSet = NULL; } sprintf(strMsg, g_strErrorExecSql, strSQLText); AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg)); return -1; } if( pRSet ) { delete pRSet; pRSet = NULL; } return 0; } //得到时间计划 INT GetDatePlan( int nPlanType, int nEquipTypeID, int nEquipID, int nPort, unsigned char nBufDate[7][24] ) { CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = {0}; CHAR strSQLText[MAX_SQL_LENGTH + 1] = {0}; CString str; CADORecordset* pRSet = NULL; INT iRetCode = 0; int nRecordCount = 0; double fStartTime = 0,fEndTime = 0; int nStartWeek = 0,nEndWeek = 0; try { if (g_pADODatabase != NULL && g_pADODatabase->IsOpen()) { pRSet = new CADORecordset(g_pADODatabase); if (NULL == pRSet) { return -1; } sprintf(strSQLText, "select starttime, endtime, startweekofday, endweekofday " \ "from t_plan_info where equip_type_id=%d and equip_id = %d and port = %d and plantype = %d", nEquipTypeID, nEquipID, nPort, nPlanType); iRetCode = pRSet->Open(strSQLText, CADORecordset::openQuery); if (iRetCode == 0) { delete pRSet; pRSet = NULL; return -1; } nRecordCount = pRSet->GetRecordCount(); if (nRecordCount == 0) { if( pRSet ) { delete pRSet; pRSet = NULL; } return 0; } for( int i = 0; i < nRecordCount; i++ ) { if (!pRSet->IsFieldNull("starttime")) { pRSet->GetFieldValue("starttime", fStartTime); } if (!pRSet->IsFieldNull("endtime")) { pRSet->GetFieldValue("endtime", fEndTime); } if (!pRSet->IsFieldNull("startweekofday")) { pRSet->GetFieldValue("startweekofday", nStartWeek); } if (!pRSet->IsFieldNull("endweekofday")) { pRSet->GetFieldValue("endweekofday", nEndWeek); } for(int y = nStartWeek;yMoveNext(); } if( pRSet ) { delete pRSet; pRSet = NULL; } return nRecordCount; } } catch (...) { if( pRSet ) { delete pRSet; pRSet = NULL; } sprintf(strMsg, g_strErrorExecSql, strSQLText); AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg)); return -1; } if( pRSet ) { delete pRSet; pRSet = NULL; } return 0; } //得到组权限ID列表 INT GetUserGroupPurviewIDList( CHAR *pUserID, CHAR *pGroupPurViewIDList ) { CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = ""; CHAR strSQLText[MAX_SQL_LENGTH + 1] = ""; CString strID; CADORecordset* pRSet = NULL; INT iRetCode = 0; int nCount = 0, i; strcpy(pGroupPurViewIDList, ""); try { if (g_pADODatabase != NULL && g_pADODatabase->IsOpen()) { pRSet = new CADORecordset(g_pADODatabase); if (NULL == pRSet) { return -1; } sprintf(strSQLText, "select group_id from t_role_user " \ "where userid = \'%s\'", pUserID); iRetCode = pRSet->Open(strSQLText, CADORecordset::openQuery); if (iRetCode == 0) { delete pRSet; pRSet = NULL; return -1; } nCount = pRSet->GetRecordCount(); if (nCount == 0) { if( pRSet ) { delete pRSet; pRSet = NULL; } return 0; } for( i = 0; i < nCount; i++ ) { // 获取区域名称 if (!pRSet->IsFieldNull("group_id")) { pRSet->GetFieldValue("group_id", strID); } strcat(pGroupPurViewIDList, strID); strcat(pGroupPurViewIDList, ","); pRSet->MoveNext(); } if( pRSet ) { delete pRSet; pRSet = NULL; } return nCount; } } catch (...) { if( pRSet ) { delete pRSet; pRSet = NULL; } sprintf(strMsg, g_strErrorExecSql, strSQLText); AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg)); return -1; } if( pRSet ) { delete pRSet; pRSet = NULL; } return 0; } //得到用户可控房间ID列表 INT GetUserRoomIDList( CHAR *pUserID, CHAR *pUserRoomIDList ) { CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = ""; CHAR strSQLText[MAX_SQL_LENGTH + 1] = ""; CString strID; CADORecordset* pRSet = NULL; INT iRetCode = 0; int nCount = 0, i; strcpy(pUserRoomIDList, ""); try { if (g_pADODatabase != NULL && g_pADODatabase->IsOpen()) { pRSet = new CADORecordset(g_pADODatabase); if (NULL == pRSet) { return -1; } if( strcmp(pUserID, "admin") == 0 ) { sprintf(strSQLText, "select id as room_id from t_base_room"); } else { sprintf(strSQLText, "select distinct room_id from t_role_equip " \ "where userid = \'%s\'", pUserID); } iRetCode = pRSet->Open(strSQLText, CADORecordset::openQuery); if (iRetCode == 0) { delete pRSet; pRSet = NULL; return -1; } nCount = pRSet->GetRecordCount(); if (nCount == 0) { if( pRSet ) { delete pRSet; pRSet = NULL; } return 0; } for( i = 0; i < nCount; i++ ) { // 获取区域名称 if (!pRSet->IsFieldNull("room_id")) { pRSet->GetFieldValue("room_id", strID); } strcat(pUserRoomIDList, strID); strcat(pUserRoomIDList, ","); pRSet->MoveNext(); } if( pRSet ) { delete pRSet; pRSet = NULL; } return nCount; } } catch (...) { if( pRSet ) { delete pRSet; pRSet = NULL; } sprintf(strMsg, g_strErrorExecSql, strSQLText); AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg)); return -1; } if( pRSet ) { delete pRSet; pRSet = NULL; } return 0; } //得到用户可控设备ID列表 INT GetUserEquipIDList( CHAR *pUserID, CHAR *pUserEquipTypeIDList, CHAR *pUserEquipIDList ) { CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = ""; CHAR strSQLText[MAX_SQL_LENGTH + 1] = ""; CString strEquipTypeID, strEquipID; CADORecordset* pRSet = NULL; INT iRetCode = 0; int nCount = 0, i; strcpy(pUserEquipIDList, ""); strcpy(pUserEquipTypeIDList, ""); try { if (g_pADODatabase != NULL && g_pADODatabase->IsOpen()) { pRSet = new CADORecordset(g_pADODatabase); if (NULL == pRSet) { return -1; } if( strcmp(pUserID, "admin") == 0 ) { sprintf(strSQLText, "select id, equip_type_id from t_view_equip_all"); } else { sprintf(strSQLText, "select id, equip_type_id from t_view_equip_all " \ "where id in (select equip_id from t_role_equip " \ "where userid = \'%s\' ) ", pUserID); } iRetCode = pRSet->Open(strSQLText, CADORecordset::openQuery); if (iRetCode == 0) { delete pRSet; pRSet = NULL; return -1; } nCount = pRSet->GetRecordCount(); if (nCount == 0) { if( pRSet ) { delete pRSet; pRSet = NULL; } return 0; } for( i = 0; i < nCount; i++ ) { // 获取设备ID if (!pRSet->IsFieldNull("id")) { pRSet->GetFieldValue("id", strEquipID); } // 获取设备类型ID if (!pRSet->IsFieldNull("equip_type_id")) { pRSet->GetFieldValue("equip_type_id", strEquipTypeID); } strcat(pUserEquipIDList, strEquipID); strcat(pUserEquipIDList, ","); strcat(pUserEquipTypeIDList, strEquipTypeID); strcat(pUserEquipTypeIDList, ","); pRSet->MoveNext(); } if( pRSet ) { delete pRSet; pRSet = NULL; } return nCount; } } catch (...) { if( pRSet ) { delete pRSet; pRSet = NULL; } sprintf(strMsg, g_strErrorExecSql, strSQLText); AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg)); return -1; } if( pRSet ) { delete pRSet; pRSet = NULL; } return 0; } //得到该设备可控的用户信息列表 INT GetUserEquipInfoList( int nEquipTypeID, int nEquipID, CHAR *pTelList, CHAR *pMobileTelList, CHAR *pFaxList, CHAR *pEmailList ) { CString str; CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = ""; CHAR strSQLText[MAX_SQL_LENGTH + 1] = ""; CHAR szTel[MAX_TEL_LENGTH + 1] = {0}; CHAR szMobileTel[MAX_TEL_LENGTH + 1] = {0}; CHAR szFaxTel[MAX_TEL_LENGTH + 1] = {0}; CHAR szEmail[MAX_EMAIL_LENGTH + 1] = {0}; CADORecordset* pRSet = NULL; INT iRetCode = 0; int nCount = 0, i; strcpy(pTelList, ""); strcpy(pMobileTelList, ""); strcpy(pFaxList, ""); strcpy(pEmailList, ""); try { if (g_pADODatabase != NULL && g_pADODatabase->IsOpen()) { pRSet = new CADORecordset(g_pADODatabase); if (NULL == pRSet) { return -1; } if( strcmp(g_strLoginUserID, "admin") == 0 ) { sprintf(strSQLText, "select tel, mobiletel, fax, email from t_user_info where uid <> 'admin'"); } else { sprintf(strSQLText, "select tel, mobiletel, fax, email from t_user_info where uid in (" \ "select userid from t_role_equip where equip_type_id = %d and equip_id = %d )", nEquipTypeID, nEquipID); } iRetCode = pRSet->Open(strSQLText, CADORecordset::openQuery); if (iRetCode == 0) { delete pRSet; pRSet = NULL; return -1; } nCount = pRSet->GetRecordCount(); if (nCount == 0) { if( pRSet ) { delete pRSet; pRSet = NULL; } return 0; } for( i = 0; i < nCount; i++ ) { // 获取电话号码 if (!pRSet->IsFieldNull("tel")) { pRSet->GetFieldValue("tel", str); strcpy( szTel, (char *)(LPCTSTR)str ); } // 获取手机号码 if (!pRSet->IsFieldNull("mobiletel")) { pRSet->GetFieldValue("mobiletel", str); strcpy( szMobileTel, (char *)(LPCTSTR)str ); } // 获取传真号码 if (!pRSet->IsFieldNull("fax")) { pRSet->GetFieldValue("fax", str); strcpy( szFaxTel, (char *)(LPCTSTR)str ); } // 获取Email if (!pRSet->IsFieldNull("email")) { pRSet->GetFieldValue("email", str); strcpy( szEmail, (char *)(LPCTSTR)str ); } strcat(pTelList, szTel); strcat(pTelList, ","); strcat(pMobileTelList, szMobileTel); strcat(pMobileTelList, ","); strcat(pFaxList, szFaxTel); strcat(pFaxList, ","); strcat(pEmailList, szEmail); strcat(pEmailList, ","); pRSet->MoveNext(); } if( pRSet ) { delete pRSet; pRSet = NULL; } return nCount; } } catch (...) { if( pRSet ) { delete pRSet; pRSet = NULL; } sprintf(strMsg, g_strErrorExecSql, strSQLText); AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg)); return -1; } if( pRSet ) { delete pRSet; pRSet = NULL; } return 0; } //得到已分配设备名称列表 INT GetUserEquipAllocList( CHAR *pUserID, int nAreaID, CHAR *pEquipAllocIDList ) { CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = ""; CHAR strSQLText[MAX_SQL_LENGTH + 1] = ""; CString strID; CADORecordset* pRSet = NULL; INT iRetCode = 0; int nCount = 0, i; strcpy(pEquipAllocIDList, ""); try { if (g_pADODatabase != NULL && g_pADODatabase->IsOpen()) { pRSet = new CADORecordset(g_pADODatabase); if (NULL == pRSet) { return -1; } sprintf(strSQLText, "select equipdesc from t_view_equip_all " \ "where id in (select equip_id from t_role_equip where " \ "userid = \'%s\') " \ "and room_id in (select id from t_base_room where areaid = %d)", pUserID, nAreaID); iRetCode = pRSet->Open(strSQLText, CADORecordset::openQuery); if (iRetCode == 0) { delete pRSet; pRSet = NULL; return -1; } nCount = pRSet->GetRecordCount(); if (nCount == 0) { if( pRSet ) { delete pRSet; pRSet = NULL; } return 0; } for( i = 0; i < nCount; i++ ) { // 获取设备ID if (!pRSet->IsFieldNull("equipdesc")) { pRSet->GetFieldValue("equipdesc", strID); } strcat(pEquipAllocIDList, strID); strcat(pEquipAllocIDList, ","); pRSet->MoveNext(); } if( pRSet ) { delete pRSet; pRSet = NULL; } return nCount; } } catch (...) { if( pRSet ) { delete pRSet; pRSet = NULL; } sprintf(strMsg, g_strErrorExecSql, strSQLText); AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg)); return -1; } if( pRSet ) { delete pRSet; pRSet = NULL; } return 0; } //得到已分配设备名称列表 INT GetUserEquipAllocList( CHAR *pUserID, CHAR *pEquipAllocIDList ) { CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = ""; CHAR strSQLText[MAX_SQL_LENGTH + 1] = ""; CString strID; CADORecordset* pRSet = NULL; INT iRetCode = 0; int nCount = 0, i; strcpy(pEquipAllocIDList, ""); try { if (g_pADODatabase != NULL && g_pADODatabase->IsOpen()) { pRSet = new CADORecordset(g_pADODatabase); if (NULL == pRSet) { return -1; } sprintf(strSQLText, "select equipdesc from t_view_equip_all " \ "where id in (select equip_id from t_role_equip where " \ "userid = \'%s\') ", pUserID); iRetCode = pRSet->Open(strSQLText, CADORecordset::openQuery); if (iRetCode == 0) { delete pRSet; pRSet = NULL; return -1; } nCount = pRSet->GetRecordCount(); if (nCount == 0) { if( pRSet ) { delete pRSet; pRSet = NULL; } return 0; } for( i = 0; i < nCount; i++ ) { // 获取设备描述 if (!pRSet->IsFieldNull("equipdesc")) { pRSet->GetFieldValue("equipdesc", strID); } strcat(pEquipAllocIDList, strID); strcat(pEquipAllocIDList, ","); pRSet->MoveNext(); } if( pRSet ) { delete pRSet; pRSet = NULL; } return nCount; } } catch (...) { if( pRSet ) { delete pRSet; pRSet = NULL; } sprintf(strMsg, g_strErrorExecSql, strSQLText); AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg)); return -1; } if( pRSet ) { delete pRSet; pRSet = NULL; } return 0; } //获取设备资料列表, 返回设备总数 INT GetEquipInfoListByRoomID(CHAR *pUserID, int nRoomID, CHAR *pStrEquipDescList) { CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = ""; CHAR strSQLText[MAX_SQL_LENGTH + 1] = ""; CHAR strEquipIP[MAX_EQUIP_IP + 1] = {0}; CHAR strEquipDesc[MAX_EQUIP_DESC + 1] = {0}; CString str; CADORecordset* pRSet = NULL; INT iRetCode = 0; int nCount = 0, i; strcpy(pStrEquipDescList, ""); try { if (g_pADODatabase != NULL && g_pADODatabase->IsOpen()) { pRSet = new CADORecordset(g_pADODatabase); if (NULL == pRSet) { return -1; } sprintf(strSQLText, "select EquipDesc from t_view_equip_all " \ "where id not in (select equip_id from t_role_equip where " \ "room_id = %d and userid = \'%s\') " \ "and room_id = %d", nRoomID, pUserID, nRoomID); iRetCode = pRSet->Open(strSQLText, CADORecordset::openQuery); if (iRetCode == 0) { delete pRSet; pRSet = NULL; return -1; } nCount = pRSet->GetRecordCount(); if (nCount == 0) { if( pRSet ) { delete pRSet; pRSet = NULL; } return 0; } for( i = 0; i < nCount; i++ ) { // 获取设备描述 if( !pRSet->IsFieldNull("EquipDesc") ) { pRSet->GetFieldValue("EquipDesc", str); strcpy(strEquipDesc, (char*)(LPCTSTR)str); } strcat(pStrEquipDescList, strEquipDesc); strcat(pStrEquipDescList, ","); pRSet->MoveNext(); } if( pRSet ) { delete pRSet; pRSet = NULL; } return nCount; } } catch (...) { if( pRSet ) { delete pRSet; pRSet = NULL; } sprintf(strMsg, g_strErrorExecSql, strSQLText); AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg)); return -1; } if( pRSet ) { delete pRSet; pRSet = NULL; } return 0; } //得到房间名称 INT GetRoomName( int nID, CHAR *pRoomName ) { CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = {0}; CHAR strSQLText[MAX_SQL_LENGTH + 1] = {0}; CString str; CADORecordset* pRSet = NULL; INT iRetCode = 0; int nRecordCount = 0; try { if (g_pADODatabase != NULL && g_pADODatabase->IsOpen()) { pRSet = new CADORecordset(g_pADODatabase); if (NULL == pRSet) { return -1; } sprintf(strSQLText, "select roomdesc from t_base_room where id=%d", nID); iRetCode = pRSet->Open(strSQLText, CADORecordset::openQuery); if (iRetCode == 0) { delete pRSet; pRSet = NULL; return -1; } nRecordCount = pRSet->GetRecordCount(); if (nRecordCount == 0) { if( pRSet ) { delete pRSet; pRSet = NULL; } return 0; } if (!pRSet->IsFieldNull("roomdesc")) { pRSet->GetFieldValue("roomdesc", str); strcpy(pRoomName, (char*)(LPCTSTR)str); } } } catch (...) { if( pRSet ) { delete pRSet; pRSet = NULL; } sprintf(strMsg, g_strErrorExecSql, strSQLText); AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg)); return -1; } if( pRSet ) { delete pRSet; pRSet = NULL; } return 0; } //得到已分配设备权限列表中的EquipID INT GetUserEquipID( CHAR *pUserID, CHAR *pEquipDesc, CHAR *pEquipID, CHAR *pEquipTypeID ) { CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = {0}; CHAR strSQLText[MAX_SQL_LENGTH + 1] = {0}; CString str; CADORecordset* pRSet = NULL; INT iRetCode = 0; int nRecordCount = 0; try { if (g_pADODatabase != NULL && g_pADODatabase->IsOpen()) { pRSet = new CADORecordset(g_pADODatabase); if (NULL == pRSet) { return -1; } sprintf(strSQLText, "select id, equip_type_id from t_view_equip_all where id in (" \ "select equip_id from t_role_equip where userid = \'%s\') " \ " and equipdesc = \'%s\'", pUserID, pEquipDesc); iRetCode = pRSet->Open(strSQLText, CADORecordset::openQuery); if (iRetCode == 0) { delete pRSet; pRSet = NULL; return -1; } nRecordCount = pRSet->GetRecordCount(); if (nRecordCount == 0) { if( pRSet ) { delete pRSet; pRSet = NULL; } return 0; } if (!pRSet->IsFieldNull("id")) { pRSet->GetFieldValue("id", str); strcpy(pEquipID, (char*)(LPCTSTR)str); } if (!pRSet->IsFieldNull("equip_type_id")) { pRSet->GetFieldValue("equip_type_id", str); strcpy(pEquipTypeID, (char*)(LPCTSTR)str); } if( pRSet ) { delete pRSet; pRSet = NULL; } return nRecordCount; } } catch (...) { if( pRSet ) { delete pRSet; pRSet = NULL; } sprintf(strMsg, g_strErrorExecSql, strSQLText); AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg)); return -1; } if( pRSet ) { delete pRSet; pRSet = NULL; } return 0; } //添加房间权限信息 INT AddUserEquipInfo(CHAR *pUserID, int nEquipTypeID, int nEquipID, int nRoomID) { CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = ""; CHAR strSQLText[MAX_SQL_LENGTH + 1] = ""; INT iRetCode = 0; try { if (g_pADODatabase != NULL && g_pADODatabase->IsOpen()) { sprintf(strSQLText, "insert into t_role_equip(equip_id, equip_type_id, room_id, userid) values (%d, %d, %d, " \ "\'%s\')", nEquipID, nEquipTypeID, nRoomID, pUserID); iRetCode = g_pADODatabase->Execute(strSQLText); } } catch (...) { sprintf(strMsg, g_strErrorExecSql, strSQLText); AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg)); return 0; } return iRetCode; } //删除房间权限信息 INT DelUserEquipInfo(CHAR *pUserID, int nEquipTypeID, int nEquipID, int nRoomID) { CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = ""; CHAR strSQLText[MAX_SQL_LENGTH + 1] = ""; INT iRetCode = 0; try { if (g_pADODatabase != NULL && g_pADODatabase->IsOpen()) { sprintf(strSQLText, "delete from t_role_equip where equip_id = %d and room_id = %d " \ "and userid = \'%s\' and equip_type_id = %d", nEquipID, nRoomID, pUserID, nEquipTypeID); iRetCode = g_pADODatabase->Execute(strSQLText); } } catch (...) { sprintf(strMsg, g_strErrorExecSql, strSQLText); AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg)); return 0; } return iRetCode; } //得到用户手机号码 INT GetUserMobileTel( CHAR *pUserID, CHAR *pMobileTel ) { CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = {0}; CHAR strSQLText[MAX_SQL_LENGTH + 1] = {0}; CString str; CADORecordset* pRSet = NULL; INT iRetCode = 0; int nRecordCount = 0; try { if (g_pADODatabase != NULL && g_pADODatabase->IsOpen()) { pRSet = new CADORecordset(g_pADODatabase); if (NULL == pRSet) { return -1; } sprintf(strSQLText, "select mobiletel from t_user_info where uid=\'%s\'", pUserID); iRetCode = pRSet->Open(strSQLText, CADORecordset::openQuery); if (iRetCode == 0) { delete pRSet; pRSet = NULL; return -1; } nRecordCount = pRSet->GetRecordCount(); if (nRecordCount == 0) { if( pRSet ) { delete pRSet; pRSet = NULL; } return 0; } if (!pRSet->IsFieldNull("mobiletel")) { pRSet->GetFieldValue("mobiletel", str); strcpy(pMobileTel, (char*)(LPCTSTR)str); } } } catch (...) { if( pRSet ) { delete pRSet; pRSet = NULL; } sprintf(strMsg, g_strErrorExecSql, strSQLText); AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg)); return -1; } if( pRSet ) { delete pRSet; pRSet = NULL; } return 0; } //得到用户电话号码 INT GetUserTel( CHAR *pUserID, CHAR *pTel ) { CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = {0}; CHAR strSQLText[MAX_SQL_LENGTH + 1] = {0}; CString str; CADORecordset* pRSet = NULL; INT iRetCode = 0; int nRecordCount = 0; try { if (g_pADODatabase != NULL && g_pADODatabase->IsOpen()) { pRSet = new CADORecordset(g_pADODatabase); if (NULL == pRSet) { return -1; } sprintf(strSQLText, "select tel from t_user_info where uid=\'%s\'", pUserID); iRetCode = pRSet->Open(strSQLText, CADORecordset::openQuery); if (iRetCode == 0) { delete pRSet; pRSet = NULL; return -1; } nRecordCount = pRSet->GetRecordCount(); if (nRecordCount == 0) { if( pRSet ) { delete pRSet; pRSet = NULL; } return 0; } if (!pRSet->IsFieldNull("tel")) { pRSet->GetFieldValue("tel", str); strcpy(pTel, (char*)(LPCTSTR)str); } } } catch (...) { if( pRSet ) { delete pRSet; pRSet = NULL; } sprintf(strMsg, g_strErrorExecSql, strSQLText); AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg)); return -1; } if( pRSet ) { delete pRSet; pRSet = NULL; } return 0; } //得到用户Email INT GetUserEmail( CHAR *pUserID, CHAR *pEmail ) { CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = {0}; CHAR strSQLText[MAX_SQL_LENGTH + 1] = {0}; CString str; CADORecordset* pRSet = NULL; INT iRetCode = 0; int nRecordCount = 0; try { if (g_pADODatabase != NULL && g_pADODatabase->IsOpen()) { pRSet = new CADORecordset(g_pADODatabase); if (NULL == pRSet) { return -1; } sprintf(strSQLText, "select email from t_user_info where uid=\'%s\'", pUserID); iRetCode = pRSet->Open(strSQLText, CADORecordset::openQuery); if (iRetCode == 0) { delete pRSet; pRSet = NULL; return -1; } nRecordCount = pRSet->GetRecordCount(); if (nRecordCount == 0) { if( pRSet ) { delete pRSet; pRSet = NULL; } return 0; } if (!pRSet->IsFieldNull("email")) { pRSet->GetFieldValue("email", str); strcpy(pEmail, (char*)(LPCTSTR)str); } } } catch (...) { if( pRSet ) { delete pRSet; pRSet = NULL; } sprintf(strMsg, g_strErrorExecSql, strSQLText); AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg)); return -1; } if( pRSet ) { delete pRSet; pRSet = NULL; } return 0; }