#include "StdAfx.h" #include "DBInterface.h" #define MSG_SHOWPROMPTING WM_USER + 101 extern HWND g_hwnd; BOOL CDBInterface::m_bEndofThread = FALSE; CDBInterface::CDBInterface(void) { m_bOpen = FALSE; m_bSolve = FALSE; m_pdbInstance = NULL; m_hReConnectEvent = NULL; m_hReConnectThread = NULL; m_hWaitableTimer = NULL; } CDBInterface::~CDBInterface(void) { CloseDatabase(); EndofThread(); } BOOL CDBInterface::SolveDBError(CONST DWORD &dwError,LPCTSTR lpErrorString) { AutoThreadSection aSection(&s_critSection); if(m_bSolve) return TRUE; switch(dwError) { case ERROR_PIPE_NOT_CONNECTED: case WSAECONNRESET: case WSAECONNABORTED: { m_bSolve = TRUE; m_strConnectErrorDescriptor = lpErrorString; // 启用重连线程; CloseDatabase(); StartThread(); LOG4C_NO_FILENUM((LOG_NOTICE,"数据库连接失败,请检查配置信息或数据库服务是否启动!")); } break; default: // 其他错误,输出日志; #ifdef UNICODE LOG4C_NO_FILENUM((LOG_NOTICE,"数据库错误信息:%s",CW2A(lpErrorString))); #else LOG4C_NO_FILENUM((LOG_NOTICE,"数据库错误信息:%s",lpErrorString)); #endif break; } return FALSE; } int CDBInterface::StartThread() { #if JEFF_TEST_OFF // 计时器; SYSTEMTIME st; FILETIME ftLocal, ftUTC; LARGE_INTEGER liUTC; st.wYear = 2014; // Year st.wMonth = 12; // January st.wDayOfWeek = 0; // Ignored st.wDay = 1; // The first of the month st.wHour = 13; // 1PM st.wMinute = 0; // 0 minutes into the hour st.wSecond = 0; // 0 seconds into the minute st.wMilliseconds = 0; // 0 milliseconds into the second SystemTimeToFileTime(&st, &ftLocal); // Convert local time to UTC time. LocalFileTimeToFileTime(&ftLocal, &ftUTC); // Convert FILETIME to LARGE_INTEGER because of different alignment. liUTC.LowPart = ftUTC.dwLowDateTime; liUTC.HighPart = ftUTC.dwHighDateTime; //liUTC.QuadPart = -(2*10000000); m_bEndofThread = FALSE; m_hWaitableTimer = CreateWaitableTimer(NULL,FALSE,NULL); const int nTimerUnitsPerSecond = 10000000; SetWaitableTimer(m_hWaitableTimer,&liUTC,3*60*60*1000,NULL,NULL,FALSE); // 3小时执行一次; #else if(m_hReConnectEvent == NULL) m_hReConnectEvent = CreateEvent(NULL, TRUE, FALSE, NULL); // 无信号事件; if (m_hReConnectEvent == NULL) { m_bSolve = FALSE; return -1; } if(m_hReConnectThread == NULL) m_hReConnectThread = CreateThread(NULL, 0, ReConnectDatabaseThread, this, 0, NULL); if (m_hReConnectThread == NULL) { m_bSolve = FALSE; return -1; } else { CloseHandle(m_hReConnectThread); m_hReConnectThread = NULL; } #endif return 0; } int CDBInterface::EndofThread() { #if JEFF_TEST_OFF // 重置等待时间,立即返回; LARGE_INTEGER li; const int nTimerUnitsPerSecond = 10000000; li.QuadPart = 1*nTimerUnitsPerSecond; SetWaitableTimer(m_hWaitableTimer,&li,NULL,NULL,NULL,FALSE); m_bEndofThread = TRUE; #else if (m_hReConnectEvent) SetEvent(m_hReConnectEvent); if (m_hReConnectThread) { if (WaitForSingleObject(m_hReConnectThread, INFINITE) != WAIT_TIMEOUT) CloseHandle(m_hReConnectThread); m_hReConnectThread = NULL; } if (m_hReConnectEvent) CloseHandle(m_hReConnectEvent); m_hReConnectEvent = NULL; #endif return 0L; } DWORD CDBInterface::ReConnectDatabaseThread(LPVOID lpPara) { CDBInterface *pInstance = (CDBInterface*)lpPara; #if JEFF_TEST_OFF while ( !m_bEndofThread ) { WaitForSingleObject(pInstance->m_hWaitableTimer,INFINITE); if ( !m_bEndofThread) { if( pInstance->OpenDatabase()) { pInstance->m_bSolve = FALSE; break; } } } if (pInstance->m_hReConnectEvent) CloseHandle(pInstance->m_hReConnectEvent); pInstance->m_hReConnectEvent = NULL; #else do { if( pInstance->OpenDatabase()) { pInstance->m_bSolve = FALSE; break; } } while (WaitForSingleObject(pInstance->m_hReConnectEvent,5000L) == WAIT_TIMEOUT); if (pInstance->m_hReConnectEvent) CloseHandle(pInstance->m_hReConnectEvent); pInstance->m_hReConnectEvent = NULL; #endif return 0L; } BOOL CDBInterface::OpenDatabase(LPCTSTR lpSQLConnectString /* = NULL */) { AutoThreadSection aSection(&s_critSection); if (m_pdbInstance == NULL) { m_pdbInstance = new CDatabase; if (lpSQLConnectString == NULL) lpSQLConnectString = g_szConnectString; try { m_pdbInstance->OpenEx(lpSQLConnectString, CDatabase::noOdbcDialog); } catch (CDBException* e) { //m_strConnectErrorDescriptor = e->m_strError; delete m_pdbInstance; m_pdbInstance = NULL; e->Delete(); return FALSE; } m_bOpen = TRUE; } return m_bOpen; } void CDBInterface::CloseDatabase() { m_bOpen = FALSE; if (m_pdbInstance) delete m_pdbInstance; m_pdbInstance = NULL; } BOOL CDBInterface::Execute(LPCTSTR lpSQL) { try { AutoThreadSection aSection(&s_critSection); if (!m_bOpen) return FALSE; //m_pdbInstance->BeginTrans(); m_pdbInstance->ExecuteSQL(lpSQL); //m_pdbInstance->CommitTrans(); } catch (CDBException* e) { //m_pdbInstance->Rollback(); #ifdef UNICODE LOG4C_NO_FILENUM((LOG_NOTICE,"%s",CW2A(e->m_strError))); #else LOG4C_NO_FILENUM((LOG_NOTICE,"%s",e->m_strError)); #endif SolveDBError(GetLastError(),e->m_strError); e->Delete(); return FALSE; } return TRUE; } int CDBInterface::GetSelectCount(LPCTSTR lpTableName, LPCTSTR lpFilter) { try { AutoThreadSection aSection(&s_critSection); if (!m_bOpen) return -1; CString strSQL; if (lpFilter && _tcsicmp(lpFilter, _T("")) != 0) strSQL.Format(_T("select count(*) as cot from %s where %s"), lpTableName, lpFilter); else strSQL.Format(_T("select count(*) as cot from %s"), lpTableName); CRecordset tagRecordset(m_pdbInstance); tagRecordset.Open(CRecordset::forwardOnly, strSQL); tagRecordset.GetFieldValue(_T("cot"), strSQL); tagRecordset.Close(); return _ttoi(strSQL); } catch (CDBException* e) { SolveDBError(GetLastError(),e->m_strError); e->Delete(); return -1; } } BOOL CDBInterface::GetDBViewDindanclientRecord(CArray &strListArray, LPCTSTR lpfilter /* = NULL */) { try{ AutoThreadSection aSection(&s_critSection); if (!m_bOpen) return FALSE; CRecordset myset(m_pdbInstance); static CString strSQL; if (lpfilter && _tcsicmp(lpfilter, _T("")) != 0) strSQL.Format(_T("select count(*) as cot from dindanclient where %s"), lpfilter); else strSQL = _T("select count(*) as cot from dindanclient"); #if defined(_DEBUG) && defined(UNICODE) LOG4C_NO_FILENUM((LOG_NOTICE,"订单表:%s",CW2A(lpfilter))); LOG4C_NO_FILENUM((LOG_NOTICE,"订单表:%s",CW2A(strSQL))); #else LOG4C_NO_FILENUM((LOG_NOTICE,"订单表:%s",lpfilter)); LOG4C_NO_FILENUM((LOG_NOTICE,"订单表:%s",strSQL)); #endif myset.Open(CRecordset::forwardOnly, strSQL); myset.GetFieldValue(_T("cot"), strSQL); myset.Close(); if (_ttol(strSQL) == 0) return TRUE; strListArray.SetSize(_ttol(strSQL), 1); CDBViewDindanclient rsSt; rsSt.m_pDatabase = m_pdbInstance; if (lpfilter && _tcsicmp(lpfilter, _T("")) != 0) rsSt.m_strFilter = lpfilter; rsSt.Open(); INT_PTR nIndex = 0; while (!rsSt.IsEOF()) { strListArray.ElementAt(nIndex).RemoveAll(); if (CHILD_VERSION) { strListArray.ElementAt(nIndex).Add(rsSt.m_name1); strListArray.ElementAt(nIndex).Add(rsSt.m_name2); strListArray.ElementAt(nIndex).Add(rsSt.m_phone1); strListArray.ElementAt(nIndex).Add(rsSt.m_birthday1); strListArray.ElementAt(nIndex).Add(rsSt.m_check1); } else { strListArray.ElementAt(nIndex).Add(rsSt.m_name1); strListArray.ElementAt(nIndex).Add(rsSt.m_name2); strListArray.ElementAt(nIndex).Add(rsSt.m_phone1); strListArray.ElementAt(nIndex).Add(rsSt.m_phone2); strListArray.ElementAt(nIndex).Add(rsSt.m_birthday1); strListArray.ElementAt(nIndex).Add(rsSt.m_birthday2); strListArray.ElementAt(nIndex).Add(rsSt.m_time3); strListArray.ElementAt(nIndex).Add(rsSt.m_check1); strListArray.ElementAt(nIndex).Add(rsSt.m_check2); strListArray.ElementAt(nIndex).Add(rsSt.m_check3); } nIndex++; rsSt.MoveNext(); if (strListArray.GetSize() <= nIndex)break; } rsSt.Close(); strListArray.SetSize(nIndex, 1); } catch (CDBException *e) { SolveDBError(GetLastError(),e->m_strError); e->Delete(); return FALSE; } return TRUE; } BOOL CDBInterface::GetTableChildmsg(CArray &strListArray, LPCTSTR lpfilter /* = NULL */) { try{ AutoThreadSection aSection(&s_critSection); if (!m_bOpen) return FALSE; CRecordset myset(m_pdbInstance); static CString strSQL; if (lpfilter && _tcsicmp(lpfilter, _T("")) != 0) strSQL.Format(_T("select count(*) as cot from childmsg where %s"), lpfilter); else strSQL = _T("select count(*) as cot from childmsg"); #if defined(_DEBUG) && defined(UNICODE) LOG4C_NO_FILENUM((LOG_NOTICE,"短信配置表:%s",CW2A(lpfilter))); LOG4C_NO_FILENUM((LOG_NOTICE,"短信配置表:%s",CW2A(strSQL))); #else LOG4C_NO_FILENUM((LOG_NOTICE,"短信配置表:%s",lpfilter)); LOG4C_NO_FILENUM((LOG_NOTICE,"短信配置表:%s",strSQL)); #endif myset.Open(CRecordset::forwardOnly, strSQL); myset.GetFieldValue(_T("cot"), strSQL); myset.Close(); if (_ttol(strSQL) == 0) return TRUE; strListArray.SetSize(_ttol(strSQL), 1); CTableChildmsg rsSt; rsSt.m_pDatabase = m_pdbInstance; if (lpfilter && _tcsicmp(lpfilter, _T("")) != 0) rsSt.m_strFilter = lpfilter; rsSt.Open(); INT_PTR nIndex = 0; while (!rsSt.IsEOF()) { strListArray.ElementAt(nIndex).RemoveAll(); strListArray.ElementAt(nIndex).Add(rsSt.m_check); // 是否自动发送; if ( IsDigit(rsSt.m_days)) { strListArray.ElementAt(nIndex).Add(rsSt.m_days); // 满x天; } else { if (rsSt.m_days == "一周") strSQL.Format(_T("%d"),7); else if (rsSt.m_days == "两周") strSQL.Format(_T("%d"),14); else if (rsSt.m_days == "三周") strSQL.Format(_T("%d"),21); else if (rsSt.m_days == "一个月" || rsSt.m_days == _T("满月")) strSQL.Format(_T("%d"),30); else if (rsSt.m_days == "两个月") strSQL.Format(_T("%d"),61); else if (rsSt.m_days == "三个月") strSQL.Format(_T("%d"),91); else if (rsSt.m_days == "四个月") strSQL.Format(_T("%d"),122); else if (rsSt.m_days == "五个月") strSQL.Format(_T("%d"),152); else if (rsSt.m_days == "六个月") strSQL.Format(_T("%d"),183); else if (rsSt.m_days == "七个月") strSQL.Format(_T("%d"),213); else if (rsSt.m_days == "八个月") strSQL.Format(_T("%d"),244); else if (rsSt.m_days == "九个月") strSQL.Format(_T("%d"),274); else if ( rsSt.m_days == _T("一岁")) strSQL.Format(_T("%d"),366); else if ( rsSt.m_days == _T("两岁")) strSQL.Format(_T("%d"),732); else if ( rsSt.m_days == _T("三岁")) strSQL.Format(_T("%d"),1098); strListArray.ElementAt(nIndex).Add(strSQL); // 满x天; } strListArray.ElementAt(nIndex).Add(rsSt.m_content); // 短信内容; strListArray.ElementAt(nIndex).Add(rsSt.m_mode); // ==0同样是儿童的;==1:表示儿童; ==2:表示孕妇怀孕 nIndex++; rsSt.MoveNext(); if (strListArray.GetSize() <= nIndex)break; } rsSt.Close(); strListArray.SetSize(nIndex, 1); } catch (CDBException *e) { SolveDBError(GetLastError(),e->m_strError); e->Delete(); return FALSE; } return TRUE; } BOOL CDBInterface::GetTableClient2(CArray &strListArray, LPCTSTR lpfilter /* = NULL */) { try{ AutoThreadSection aSection(&s_critSection); if (!m_bOpen) return FALSE; CRecordset myset(m_pdbInstance); static CString strSQL; if (lpfilter && _tcsicmp(lpfilter, _T("")) != 0) strSQL.Format(_T("select count(*) as cot from client2 where %s"), lpfilter); else strSQL = _T("select count(*) as cot from client2"); #if _DEBUG LOG4C_NO_FILENUM((LOG_NOTICE,"老客户表:%s",CW2A(lpfilter))); LOG4C_NO_FILENUM((LOG_NOTICE,"表客户表:%s",CW2A(strSQL))); #endif myset.Open(CRecordset::forwardOnly, strSQL); myset.GetFieldValue(_T("cot"), strSQL); myset.Close(); if (_ttol(strSQL) == 0) return TRUE; strListArray.SetSize(_ttol(strSQL), 1); CTableClient2 rsSt; rsSt.m_pDatabase = m_pdbInstance; if (lpfilter && _tcsicmp(lpfilter, _T("")) != 0) rsSt.m_strFilter = lpfilter; rsSt.Open(); INT_PTR nIndex = 0; static CString strTemp; while (!rsSt.IsEOF()) { strTemp.Format(_T("%ld"), rsSt.m_id); strListArray.ElementAt(nIndex).RemoveAll(); #ifdef LYFZ_VERSION strListArray.ElementAt(nIndex).Add(strTemp); strListArray.ElementAt(nIndex).Add(rsSt.m_name); strListArray.ElementAt(nIndex).Add(rsSt.m_name2); strListArray.ElementAt(nIndex).Add(rsSt.m_ren); strListArray.ElementAt(nIndex).Add(rsSt.m_phone); strListArray.ElementAt(nIndex).Add(rsSt.m_qq); strListArray.ElementAt(nIndex).Add(rsSt.m_addr); strListArray.ElementAt(nIndex).Add(rsSt.m_from); strListArray.ElementAt(nIndex).Add(rsSt.m_status); strListArray.ElementAt(nIndex).Add(rsSt.m_bz); strListArray.ElementAt(nIndex).Add(rsSt.m_date); strListArray.ElementAt(nIndex).Add(rsSt.m_pinyin); strListArray.ElementAt(nIndex).Add(rsSt.m_pinyin2); #else strListArray.ElementAt(nIndex).Add(strTemp); // 0. strListArray.ElementAt(nIndex).Add(rsSt.m_name); // 1. strListArray.ElementAt(nIndex).Add(rsSt.m_sex); // 2. strListArray.ElementAt(nIndex).Add(rsSt.m_phone); // 3. strListArray.ElementAt(nIndex).Add(rsSt.m_birthday); // 4. strListArray.ElementAt(nIndex).Add(rsSt.m_date); // 5. strListArray.ElementAt(nIndex).Add(rsSt.m_check1); // 6. #endif nIndex++; rsSt.MoveNext(); if (strListArray.GetSize() <= nIndex)break; } rsSt.Close(); strListArray.SetSize(nIndex, 1); } catch (CDBException *e) { SolveDBError(GetLastError(),e->m_strError); e->Delete(); return FALSE; } return TRUE; } BOOL CDBInterface::GetTableClient3(CArray &strListArray, LPCTSTR lpfilter /* = NULL */) { try{ AutoThreadSection aSection(&s_critSection); if (!m_bOpen) return FALSE; CRecordset myset(m_pdbInstance); static CString strSQL; if (lpfilter && _tcsicmp(lpfilter, _T("")) != 0) strSQL.Format(_T("select count(*) as cot from client3 where %s"), lpfilter); else strSQL = _T("select count(*) as cot from client3"); #if _DEBUG LOG4C_NO_FILENUM((LOG_NOTICE,"意向客户表:%s",CW2A(lpfilter))); LOG4C_NO_FILENUM((LOG_NOTICE,"意向客户表:%s",CW2A(strSQL))); #endif myset.Open(CRecordset::forwardOnly, strSQL); myset.GetFieldValue(_T("cot"), strSQL); myset.Close(); if (_ttol(strSQL) == 0) return TRUE; strListArray.SetSize(_ttol(strSQL), 1); CTableClient3 rsSt; rsSt.m_pDatabase = m_pdbInstance; if (lpfilter && _tcsicmp(lpfilter, _T("")) != 0) rsSt.m_strFilter = lpfilter; rsSt.Open(); INT_PTR nIndex = 0; static CString strTemp; while (!rsSt.IsEOF()) { strTemp.Format(_T("%ld"), rsSt.m_id); strListArray.ElementAt(nIndex).RemoveAll(); if (CHILD_VERSION) { strListArray.ElementAt(nIndex).Add(strTemp); strListArray.ElementAt(nIndex).Add(rsSt.m_name); strListArray.ElementAt(nIndex).Add(rsSt.m_name2); strListArray.ElementAt(nIndex).Add(rsSt.m_sex); strListArray.ElementAt(nIndex).Add(rsSt.m_phone); strListArray.ElementAt(nIndex).Add(rsSt.m_birthday); strListArray.ElementAt(nIndex).Add(rsSt.m_dandate); strListArray.ElementAt(nIndex).Add(rsSt.m_date); strListArray.ElementAt(nIndex).Add(rsSt.m_check1); } else { strListArray.ElementAt(nIndex).Add(strTemp); strListArray.ElementAt(nIndex).Add(rsSt.m_name); strListArray.ElementAt(nIndex).Add(rsSt.m_name2); strListArray.ElementAt(nIndex).Add(rsSt.m_phone); strListArray.ElementAt(nIndex).Add(rsSt.m_phone2); strListArray.ElementAt(nIndex).Add(rsSt.m_birthday); strListArray.ElementAt(nIndex).Add(rsSt.m_birthday2); strListArray.ElementAt(nIndex).Add(rsSt.m_time3); strListArray.ElementAt(nIndex).Add(rsSt.m_dandate); strListArray.ElementAt(nIndex).Add(rsSt.m_date); strListArray.ElementAt(nIndex).Add(rsSt.m_check1); strListArray.ElementAt(nIndex).Add(rsSt.m_check2); strListArray.ElementAt(nIndex).Add(rsSt.m_check3); } nIndex++; rsSt.MoveNext(); if (strListArray.GetSize() <= nIndex)break; } rsSt.Close(); strListArray.SetSize(nIndex, 1); } catch (CDBException *e) { SolveDBError(GetLastError(),e->m_strError); e->Delete(); return FALSE; } return TRUE; } BOOL CDBInterface::GetTableSendreg(CArray &strListArray, LPCTSTR lpfilter /* = NULL */) { try { AutoThreadSection aSection(&s_critSection); if (!m_bOpen) return FALSE; CRecordset myset(m_pdbInstance); static CString strSQL; if (lpfilter && _tcsicmp(lpfilter, _T("")) != 0) strSQL.Format(_T("select count(*) as cot from sendreg where %s"), lpfilter); else strSQL = _T("select count(*) as cot from sendreg"); //LOG4C_NO_FILENUM((LOG_NOTICE,"%s",CW2A(strSQL))); myset.Open(CRecordset::forwardOnly, strSQL); myset.GetFieldValue(_T("cot"), strSQL); myset.Close(); if (_ttol(strSQL) == 0) return TRUE; strListArray.SetSize(_ttol(strSQL), 1); CTableSendreg rsSt; rsSt.m_pDatabase = m_pdbInstance; if (lpfilter && _tcsicmp(lpfilter, _T("")) != 0) rsSt.m_strFilter = lpfilter; rsSt.m_strSort = "timestamp"; rsSt.Open(); INT_PTR nIndex = 0; static CString strTemp; while (!rsSt.IsEOF()) { strTemp.Format(_T("%ld"), rsSt.m_autoid); strListArray.ElementAt(nIndex).RemoveAll(); strListArray.ElementAt(nIndex).Add(rsSt.m_phones); // 电话; strListArray.ElementAt(nIndex).Add(rsSt.m_content); // 短信内容; strListArray.ElementAt(nIndex).Add(rsSt.m_timestamp); // 短信生成日期; strListArray.ElementAt(nIndex).Add(strTemp); // 自增id strListArray.ElementAt(nIndex).Add(rsSt.m_status); // 若查询则为sid; nIndex++; rsSt.MoveNext(); if (strListArray.GetSize() <= nIndex)break; } rsSt.Close(); strListArray.SetSize(nIndex, 1); } catch (CDBException* e) { SolveDBError(GetLastError(),e->m_strError); e->Delete(); return FALSE; } return TRUE; } BOOL CDBInterface::GetTableSendregcard(CArray &strListArray, LPCTSTR lpfilter /* = NULL */) { try{ AutoThreadSection aSection(&s_critSection); if (!m_bOpen) return FALSE; CRecordset myset(m_pdbInstance); static CString strSQL; if (lpfilter && _tcsicmp(lpfilter, _T("")) != 0) strSQL.Format(_T("select count(*) as cot from sendregcard where %s"), lpfilter); else strSQL = _T("select count(*) as cot from sendregcard"); myset.Open(CRecordset::forwardOnly, strSQL); myset.GetFieldValue(_T("cot"), strSQL); myset.Close(); if (_ttol(strSQL) == 0) return TRUE; strListArray.SetSize(_ttol(strSQL), 1); CTableSendregcard rsSt; rsSt.m_pDatabase = m_pdbInstance; if (lpfilter && _tcsicmp(lpfilter, _T("")) != 0) rsSt.m_strFilter = lpfilter; rsSt.Open(); INT_PTR nIndex = 0; while (!rsSt.IsEOF()) { strListArray.ElementAt(nIndex).RemoveAll(); strListArray.ElementAt(nIndex).Add(rsSt.m_timestamp); strListArray.ElementAt(nIndex).Add(rsSt.m_phones); nIndex++; rsSt.MoveNext(); if (strListArray.GetSize() <= nIndex)break; } rsSt.Close(); strListArray.SetSize(nIndex, 1); } catch (CDBException *e) { SolveDBError(GetLastError(),e->m_strError); e->Delete(); return FALSE; } return TRUE; } BOOL CDBInterface::GetTableHospitalclient(CArray &strListArray, LPCTSTR lpfilter /* = NULL */) { try { AutoThreadSection aSection(&s_critSection); if (!m_bOpen) return FALSE; CRecordset myset(m_pdbInstance); static CString strSQL; if (lpfilter && _tcsicmp(lpfilter, _T("")) != 0) strSQL.Format(_T("select count(*) as cot from hospitalclient where %s"), lpfilter); else strSQL = _T("select count(*) as cot from hospitalclient"); #if _DEBUG LOG4C_NO_FILENUM((LOG_NOTICE,"儿童医院跟踪系统:%s",CW2A(lpfilter))); LOG4C_NO_FILENUM((LOG_NOTICE,"儿童医院跟踪系统:%s",CW2A(strSQL))); #endif myset.Open(CRecordset::forwardOnly, strSQL); myset.GetFieldValue(_T("cot"), strSQL); myset.Close(); if (_ttol(strSQL) == 0) return TRUE; strListArray.SetSize(_ttol(strSQL), 1); CTableHospitalclient rsSt; rsSt.m_pDatabase = m_pdbInstance; if (lpfilter && _tcsicmp(lpfilter, _T("")) != 0) rsSt.m_strFilter = lpfilter; rsSt.Open(); INT_PTR nIndex = 0; while (!rsSt.IsEOF()) { strListArray.ElementAt(nIndex).RemoveAll(); strListArray.ElementAt(nIndex).Add(rsSt.m_id); strListArray.ElementAt(nIndex).Add(rsSt.m_name1); strListArray.ElementAt(nIndex).Add(rsSt.m_name2); strListArray.ElementAt(nIndex).Add(rsSt.m_sex); strListArray.ElementAt(nIndex).Add(rsSt.m_check1); strListArray.ElementAt(nIndex).Add(rsSt.m_birthdaytype); // ==0 儿童生日; ==1孕妇怀满n天; strListArray.ElementAt(nIndex).Add(rsSt.m_birthday); strListArray.ElementAt(nIndex).Add(rsSt.m_pregnancydays); strListArray.ElementAt(nIndex).Add(rsSt.m_date1); strListArray.ElementAt(nIndex).Add(rsSt.m_type); strListArray.ElementAt(nIndex).Add(rsSt.m_phone1); nIndex++; rsSt.MoveNext(); if (strListArray.GetSize() <= nIndex)break; } rsSt.Close(); strListArray.SetSize(nIndex, 1); } catch (CDBException* e) { SolveDBError(GetLastError(),e->m_strError); e->Delete(); return FALSE; } return TRUE; } BOOL CDBInterface::GetSMSInfo(SMSInfo &tSMSInfo) { try { AutoThreadSection aSection(&s_critSection); if (!m_bOpen) return FALSE; CTableVersion rsSt; rsSt.m_pDatabase = m_pdbInstance; rsSt.Open(); if (!rsSt.IsEOF()) { tSMSInfo.msgaccount = rsSt.m_msgaccount; tSMSInfo.msgpassword = rsSt.m_msgpsw; tSMSInfo.msgused = rsSt.m_msgused; tSMSInfo.msgbalance = rsSt.m_msgbalance; tSMSInfo.msgCheck1 = rsSt.m_msgcheck1; tSMSInfo.msgCheck2 = rsSt.m_msgcheck2; tSMSInfo.msgCheck15 = rsSt.m_msgcheck15; tSMSInfo.hospitalmsgcheck1 = rsSt.m_hospitalmsgcheck1; tSMSInfo.hospitalmsgcheck2 = rsSt.m_hospitalmsgcheck2; tSMSInfo.msgDays1 = rsSt.m_msgdays1; tSMSInfo.msgDays2 = rsSt.m_msgdays2; tSMSInfo.msgContent1 = rsSt.m_msgcontent1; tSMSInfo.msgContent2 = rsSt.m_msgcontent2; tSMSInfo.msgContent15 = rsSt.m_msgcontent15; } rsSt.Close(); } catch (CDBException *e) { SolveDBError(GetLastError(),e->m_strError); e->Delete(); return FALSE ; } return TRUE; } BOOL CDBInterface::GetSMSType(std::vector &vtSMSInfo,BOOL bhospitalcheck1,std::vector &vtSMSInfo2,BOOL bhospitalcheck2) { try { AutoThreadSection aSection(&s_critSection); if (!m_bOpen) return FALSE; //if ( g_bSoftWareReg == FALSE) return TRUE; vtSMSInfo.clear(); vtSMSInfo2.clear(); // childmsg表; CArray strArray; GetTableChildmsg(strArray,_T("[check] = '1'")); int nSize = strArray.GetSize(); for (int i = 0; i < nSize; i++) { CStringArray &saInfo = strArray.ElementAt(i); if ( saInfo.ElementAt(3) == _T("0")) // 0 和 1 表示儿童类的短信, 0时不与医院跟踪系统挂勾; { SmsType tSMSType; tSMSType.nChoose = 0; tSMSType.nDays = _ttoi(saInfo.ElementAt(1)); tSMSType.nSMSType = 10000 + tSMSType.nDays; vtSMSInfo.push_back(tSMSType); } if ( bhospitalcheck1 && saInfo.ElementAt(3) == _T("1")) // 0 和 1 表示儿童类的短信; { SmsType tSMSType; tSMSType.nChoose = 1; tSMSType.nDays = _ttoi(saInfo.ElementAt(1)); tSMSType.nSMSType = 10000 + tSMSType.nDays; vtSMSInfo.push_back(tSMSType); } if ( bhospitalcheck2 && saInfo.ElementAt(3) == _T("2") ) // ElementAt(3) == 2 孕妇短信; { SmsType tSMSType; tSMSType.nChoose = 2; tSMSType.nDays = _ttoi(saInfo.ElementAt(1)); tSMSType.nSMSType = 20000 + tSMSType.nDays; vtSMSInfo2.push_back(tSMSType); } } } catch (CDBException *e) { vtSMSInfo.clear(); SolveDBError(GetLastError(),e->m_strError); e->Delete(); return FALSE ; } return TRUE; }