DBInterface.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785
  1. #include "StdAfx.h"
  2. #include "DBInterface.h"
  3. #define MSG_SHOWPROMPTING WM_USER + 101
  4. extern HWND g_hwnd;
  5. BOOL CDBInterface::m_bEndofThread = FALSE;
  6. CDBInterface::CDBInterface(void)
  7. {
  8. m_bOpen = FALSE;
  9. m_bSolve = FALSE;
  10. m_pdbInstance = NULL;
  11. m_hReConnectEvent = NULL;
  12. m_hReConnectThread = NULL;
  13. m_hWaitableTimer = NULL;
  14. }
  15. CDBInterface::~CDBInterface(void)
  16. {
  17. CloseDatabase();
  18. EndofThread();
  19. }
  20. BOOL CDBInterface::SolveDBError(CONST DWORD &dwError,LPCTSTR lpErrorString)
  21. {
  22. AutoThreadSection aSection(&s_critSection);
  23. if(m_bSolve) return TRUE;
  24. switch(dwError)
  25. {
  26. case ERROR_PIPE_NOT_CONNECTED:
  27. case WSAECONNRESET:
  28. case WSAECONNABORTED:
  29. {
  30. m_bSolve = TRUE;
  31. m_strConnectErrorDescriptor = lpErrorString;
  32. // 启用重连线程;
  33. CloseDatabase();
  34. StartThread();
  35. WriteClientLog(_T("数据库连接失败,请检查配置信息或数据库服务是否启动!"));
  36. }
  37. break;
  38. default:
  39. // 其他错误,输出日志;
  40. WriteClientLog(lpErrorString);
  41. break;
  42. }
  43. return FALSE;
  44. }
  45. int CDBInterface::StartThread()
  46. {
  47. #if JEFF_TEST_OFF
  48. // 计时器;
  49. SYSTEMTIME st;
  50. FILETIME ftLocal, ftUTC;
  51. LARGE_INTEGER liUTC;
  52. st.wYear = 2014; // Year
  53. st.wMonth = 12; // January
  54. st.wDayOfWeek = 0; // Ignored
  55. st.wDay = 1; // The first of the month
  56. st.wHour = 13; // 1PM
  57. st.wMinute = 0; // 0 minutes into the hour
  58. st.wSecond = 0; // 0 seconds into the minute
  59. st.wMilliseconds = 0; // 0 milliseconds into the second
  60. SystemTimeToFileTime(&st, &ftLocal);
  61. // Convert local time to UTC time.
  62. LocalFileTimeToFileTime(&ftLocal, &ftUTC);
  63. // Convert FILETIME to LARGE_INTEGER because of different alignment.
  64. liUTC.LowPart = ftUTC.dwLowDateTime;
  65. liUTC.HighPart = ftUTC.dwHighDateTime;
  66. //liUTC.QuadPart = -(2*10000000);
  67. m_bEndofThread = FALSE;
  68. m_hWaitableTimer = CreateWaitableTimer(NULL,FALSE,NULL);
  69. const int nTimerUnitsPerSecond = 10000000;
  70. SetWaitableTimer(m_hWaitableTimer,&liUTC,3*60*60*1000,NULL,NULL,FALSE); // 3小时执行一次;
  71. #else
  72. if(m_hReConnectEvent == NULL)
  73. m_hReConnectEvent = CreateEvent(NULL, TRUE, FALSE, NULL); // 无信号事件;
  74. if (m_hReConnectEvent == NULL)
  75. {
  76. m_bSolve = FALSE;
  77. return -1;
  78. }
  79. if(m_hReConnectThread == NULL)
  80. m_hReConnectThread = CreateThread(NULL, 0, ReConnectDatabaseThread, this, 0, NULL);
  81. if (m_hReConnectThread == NULL)
  82. {
  83. m_bSolve = FALSE;
  84. return -1;
  85. }
  86. else
  87. {
  88. CloseHandle(m_hReConnectThread);
  89. m_hReConnectThread = NULL;
  90. }
  91. #endif
  92. return 0;
  93. }
  94. int CDBInterface::EndofThread()
  95. {
  96. #if JEFF_TEST_OFF
  97. // 重置等待时间,立即返回;
  98. LARGE_INTEGER li;
  99. const int nTimerUnitsPerSecond = 10000000;
  100. li.QuadPart = 1*nTimerUnitsPerSecond;
  101. SetWaitableTimer(m_hWaitableTimer,&li,NULL,NULL,NULL,FALSE);
  102. m_bEndofThread = TRUE;
  103. #else
  104. if (m_hReConnectEvent)
  105. SetEvent(m_hReConnectEvent);
  106. if (m_hReConnectThread)
  107. {
  108. if (WaitForSingleObject(m_hReConnectThread, INFINITE) != WAIT_TIMEOUT)
  109. CloseHandle(m_hReConnectThread);
  110. m_hReConnectThread = NULL;
  111. }
  112. if (m_hReConnectEvent)
  113. CloseHandle(m_hReConnectEvent);
  114. m_hReConnectEvent = NULL;
  115. #endif
  116. return 0L;
  117. }
  118. DWORD CDBInterface::ReConnectDatabaseThread(LPVOID lpPara)
  119. {
  120. CDBInterface *pInstance = (CDBInterface*)lpPara;
  121. #if JEFF_TEST_OFF
  122. while ( !m_bEndofThread )
  123. {
  124. WaitForSingleObject(pInstance->m_hWaitableTimer,INFINITE);
  125. if ( !m_bEndofThread)
  126. {
  127. if( pInstance->OpenDatabase())
  128. {
  129. pInstance->m_bSolve = FALSE;
  130. break;
  131. }
  132. }
  133. }
  134. if (pInstance->m_hReConnectEvent)
  135. CloseHandle(pInstance->m_hReConnectEvent);
  136. pInstance->m_hReConnectEvent = NULL;
  137. #else
  138. do
  139. {
  140. if( pInstance->OpenDatabase())
  141. {
  142. pInstance->m_bSolve = FALSE;
  143. break;
  144. }
  145. } while (WaitForSingleObject(pInstance->m_hReConnectEvent,5000L) == WAIT_TIMEOUT);
  146. if (pInstance->m_hReConnectEvent)
  147. CloseHandle(pInstance->m_hReConnectEvent);
  148. pInstance->m_hReConnectEvent = NULL;
  149. #endif
  150. return 0L;
  151. }
  152. BOOL CDBInterface::OpenDatabase(LPCTSTR lpSQLConnectString /* = NULL */)
  153. {
  154. AutoThreadSection aSection(&s_critSection);
  155. if (m_pdbInstance == NULL)
  156. {
  157. m_pdbInstance = new CDatabase;
  158. if (lpSQLConnectString == NULL)
  159. lpSQLConnectString = g_szConnectString;
  160. try
  161. {
  162. m_pdbInstance->OpenEx(lpSQLConnectString, CDatabase::noOdbcDialog);
  163. }
  164. catch (CDBException* e)
  165. {
  166. //m_strConnectErrorDescriptor = e->m_strError;
  167. delete m_pdbInstance;
  168. m_pdbInstance = NULL;
  169. e->Delete();
  170. return FALSE;
  171. }
  172. m_bOpen = TRUE;
  173. }
  174. return m_bOpen;
  175. }
  176. void CDBInterface::CloseDatabase()
  177. {
  178. m_bOpen = FALSE;
  179. if (m_pdbInstance)
  180. delete m_pdbInstance;
  181. m_pdbInstance = NULL;
  182. }
  183. BOOL CDBInterface::Execute(LPCTSTR lpSQL)
  184. {
  185. try
  186. {
  187. AutoThreadSection aSection(&s_critSection);
  188. if (!m_bOpen) return FALSE;
  189. //m_pdbInstance->BeginTrans();
  190. m_pdbInstance->ExecuteSQL(lpSQL);
  191. //m_pdbInstance->CommitTrans();
  192. }
  193. catch (CDBException* e)
  194. {
  195. //m_pdbInstance->Rollback();
  196. SolveDBError(GetLastError(),e->m_strError);
  197. e->Delete();
  198. return FALSE;
  199. }
  200. return TRUE;
  201. }
  202. int CDBInterface::GetSelectCount(LPCTSTR lpTableName, LPCTSTR lpFilter)
  203. {
  204. try
  205. {
  206. AutoThreadSection aSection(&s_critSection);
  207. if (!m_bOpen) return -1;
  208. CString strSQL;
  209. if (lpFilter && _tcsicmp(lpFilter, _T("")) != 0)
  210. strSQL.Format(_T("select count(*) as cot from %s where %s"), lpTableName, lpFilter);
  211. else
  212. strSQL.Format(_T("select count(*) as cot from %s"), lpTableName);
  213. CRecordset tagRecordset(m_pdbInstance);
  214. tagRecordset.Open(CRecordset::forwardOnly, strSQL);
  215. tagRecordset.GetFieldValue(_T("cot"), strSQL);
  216. tagRecordset.Close();
  217. return _ttoi(strSQL);
  218. }
  219. catch (CDBException* e)
  220. {
  221. SolveDBError(GetLastError(),e->m_strError);
  222. e->Delete();
  223. return -1;
  224. }
  225. }
  226. BOOL CDBInterface::GetDBViewDindanclientRecord(CArray<CStringArray, CStringArray> &strListArray, LPCTSTR lpfilter /* = NULL */)
  227. {
  228. try{
  229. AutoThreadSection aSection(&s_critSection);
  230. if (!m_bOpen) return FALSE;
  231. CRecordset myset(m_pdbInstance);
  232. static CString strSQL;
  233. if (lpfilter && _tcsicmp(lpfilter, _T("")) != 0)
  234. strSQL.Format(_T("select count(*) as cot from dindanclient where %s"), lpfilter);
  235. else
  236. strSQL = _T("select count(*) as cot from dindanclient");
  237. //WriteClientLog(strSQL);
  238. myset.Open(CRecordset::forwardOnly, strSQL);
  239. myset.GetFieldValue(_T("cot"), strSQL);
  240. myset.Close();
  241. if (_ttol(strSQL) == 0) return TRUE;
  242. strListArray.SetSize(_ttol(strSQL), 1);
  243. CDBViewDindanclient rsSt;
  244. rsSt.m_pDatabase = m_pdbInstance;
  245. if (lpfilter && _tcsicmp(lpfilter, _T("")) != 0)
  246. rsSt.m_strFilter = lpfilter;
  247. rsSt.Open();
  248. INT_PTR nIndex = 0;
  249. while (!rsSt.IsEOF())
  250. {
  251. strListArray.ElementAt(nIndex).RemoveAll();
  252. if (CHILD_VERSION)
  253. {
  254. strListArray.ElementAt(nIndex).Add(rsSt.m_name1);
  255. strListArray.ElementAt(nIndex).Add(rsSt.m_name2);
  256. strListArray.ElementAt(nIndex).Add(rsSt.m_phone1);
  257. strListArray.ElementAt(nIndex).Add(rsSt.m_birthday1);
  258. strListArray.ElementAt(nIndex).Add(rsSt.m_check1);
  259. }
  260. else
  261. {
  262. strListArray.ElementAt(nIndex).Add(rsSt.m_name1);
  263. strListArray.ElementAt(nIndex).Add(rsSt.m_name2);
  264. strListArray.ElementAt(nIndex).Add(rsSt.m_phone1);
  265. strListArray.ElementAt(nIndex).Add(rsSt.m_phone2);
  266. strListArray.ElementAt(nIndex).Add(rsSt.m_birthday1);
  267. strListArray.ElementAt(nIndex).Add(rsSt.m_birthday2);
  268. strListArray.ElementAt(nIndex).Add(rsSt.m_time3);
  269. strListArray.ElementAt(nIndex).Add(rsSt.m_check1);
  270. strListArray.ElementAt(nIndex).Add(rsSt.m_check2);
  271. strListArray.ElementAt(nIndex).Add(rsSt.m_check3);
  272. }
  273. nIndex++;
  274. rsSt.MoveNext();
  275. if (strListArray.GetSize() <= nIndex)break;
  276. }
  277. rsSt.Close();
  278. strListArray.SetSize(nIndex, 1);
  279. }
  280. catch (CDBException *e)
  281. {
  282. SolveDBError(GetLastError(),e->m_strError);
  283. e->Delete();
  284. return FALSE;
  285. }
  286. return TRUE;
  287. }
  288. BOOL CDBInterface::GetTableChildmsg(CArray<CStringArray, CStringArray> &strListArray, LPCTSTR lpfilter /* = NULL */)
  289. {
  290. try{
  291. AutoThreadSection aSection(&s_critSection);
  292. if (!m_bOpen) return FALSE;
  293. CRecordset myset(m_pdbInstance);
  294. static CString strSQL;
  295. if (lpfilter && _tcsicmp(lpfilter, _T("")) != 0)
  296. strSQL.Format(_T("select count(*) as cot from childmsg where %s"), lpfilter);
  297. else
  298. strSQL = _T("select count(*) as cot from childmsg");
  299. //WriteClientLog(strSQL);
  300. myset.Open(CRecordset::forwardOnly, strSQL);
  301. myset.GetFieldValue(_T("cot"), strSQL);
  302. myset.Close();
  303. if (_ttol(strSQL) == 0) return TRUE;
  304. strListArray.SetSize(_ttol(strSQL), 1);
  305. CTableChildmsg rsSt;
  306. rsSt.m_pDatabase = m_pdbInstance;
  307. if (lpfilter && _tcsicmp(lpfilter, _T("")) != 0)
  308. rsSt.m_strFilter = lpfilter;
  309. rsSt.Open();
  310. INT_PTR nIndex = 0;
  311. while (!rsSt.IsEOF())
  312. {
  313. strListArray.ElementAt(nIndex).RemoveAll();
  314. strListArray.ElementAt(nIndex).Add(rsSt.m_check); // 是否自动发送;
  315. strListArray.ElementAt(nIndex).Add(rsSt.m_days); // 满x天;
  316. strListArray.ElementAt(nIndex).Add(rsSt.m_content); // 短信内容;
  317. strListArray.ElementAt(nIndex).Add(rsSt.m_mode); // ==0???;==1:表示儿童; ==2:表示孕妇怀孕
  318. nIndex++;
  319. rsSt.MoveNext();
  320. if (strListArray.GetSize() <= nIndex)break;
  321. }
  322. rsSt.Close();
  323. strListArray.SetSize(nIndex, 1);
  324. }
  325. catch (CDBException *e)
  326. {
  327. SolveDBError(GetLastError(),e->m_strError);
  328. e->Delete();
  329. return FALSE;
  330. }
  331. return TRUE;
  332. }
  333. BOOL CDBInterface::GetTableClient2(CArray<CStringArray, CStringArray> &strListArray, LPCTSTR lpfilter /* = NULL */)
  334. {
  335. try{
  336. AutoThreadSection aSection(&s_critSection);
  337. if (!m_bOpen) return FALSE;
  338. CRecordset myset(m_pdbInstance);
  339. static CString strSQL;
  340. if (lpfilter && _tcsicmp(lpfilter, _T("")) != 0)
  341. strSQL.Format(_T("select count(*) as cot from client2 where %s"), lpfilter);
  342. else
  343. strSQL = _T("select count(*) as cot from client2");
  344. //WriteClientLog(strSQL);
  345. myset.Open(CRecordset::forwardOnly, strSQL);
  346. myset.GetFieldValue(_T("cot"), strSQL);
  347. myset.Close();
  348. if (_ttol(strSQL) == 0) return TRUE;
  349. strListArray.SetSize(_ttol(strSQL), 1);
  350. CTableClient2 rsSt;
  351. rsSt.m_pDatabase = m_pdbInstance;
  352. if (lpfilter && _tcsicmp(lpfilter, _T("")) != 0)
  353. rsSt.m_strFilter = lpfilter;
  354. rsSt.Open();
  355. INT_PTR nIndex = 0;
  356. static CString strTemp;
  357. while (!rsSt.IsEOF())
  358. {
  359. strTemp.Format(_T("%ld"), rsSt.m_id);
  360. strListArray.ElementAt(nIndex).RemoveAll();
  361. #ifdef LYFZ_VERSION
  362. strListArray.ElementAt(nIndex).Add(strTemp);
  363. strListArray.ElementAt(nIndex).Add(rsSt.m_name);
  364. strListArray.ElementAt(nIndex).Add(rsSt.m_name2);
  365. strListArray.ElementAt(nIndex).Add(rsSt.m_ren);
  366. strListArray.ElementAt(nIndex).Add(rsSt.m_phone);
  367. strListArray.ElementAt(nIndex).Add(rsSt.m_qq);
  368. strListArray.ElementAt(nIndex).Add(rsSt.m_addr);
  369. strListArray.ElementAt(nIndex).Add(rsSt.m_from);
  370. strListArray.ElementAt(nIndex).Add(rsSt.m_status);
  371. strListArray.ElementAt(nIndex).Add(rsSt.m_bz);
  372. strListArray.ElementAt(nIndex).Add(rsSt.m_date);
  373. strListArray.ElementAt(nIndex).Add(rsSt.m_pinyin);
  374. strListArray.ElementAt(nIndex).Add(rsSt.m_pinyin2);
  375. #else
  376. strListArray.ElementAt(nIndex).Add(strTemp); // 0.
  377. strListArray.ElementAt(nIndex).Add(rsSt.m_name); // 1.
  378. strListArray.ElementAt(nIndex).Add(rsSt.m_sex); // 2.
  379. strListArray.ElementAt(nIndex).Add(rsSt.m_phone); // 3.
  380. strListArray.ElementAt(nIndex).Add(rsSt.m_birthday); // 4.
  381. strListArray.ElementAt(nIndex).Add(rsSt.m_date); // 5.
  382. strListArray.ElementAt(nIndex).Add(rsSt.m_check1); // 6.
  383. #endif
  384. nIndex++;
  385. rsSt.MoveNext();
  386. if (strListArray.GetSize() <= nIndex)break;
  387. }
  388. rsSt.Close();
  389. strListArray.SetSize(nIndex, 1);
  390. }
  391. catch (CDBException *e)
  392. {
  393. SolveDBError(GetLastError(),e->m_strError);
  394. e->Delete();
  395. return FALSE;
  396. }
  397. return TRUE;
  398. }
  399. BOOL CDBInterface::GetTableClient3(CArray<CStringArray, CStringArray> &strListArray, LPCTSTR lpfilter /* = NULL */)
  400. {
  401. try{
  402. AutoThreadSection aSection(&s_critSection);
  403. if (!m_bOpen) return FALSE;
  404. CRecordset myset(m_pdbInstance);
  405. static CString strSQL;
  406. if (lpfilter && _tcsicmp(lpfilter, _T("")) != 0)
  407. strSQL.Format(_T("select count(*) as cot from client3 where %s"), lpfilter);
  408. else
  409. strSQL = _T("select count(*) as cot from client3");
  410. //WriteClientLog(strSQL);
  411. myset.Open(CRecordset::forwardOnly, strSQL);
  412. myset.GetFieldValue(_T("cot"), strSQL);
  413. myset.Close();
  414. if (_ttol(strSQL) == 0) return TRUE;
  415. strListArray.SetSize(_ttol(strSQL), 1);
  416. CTableClient3 rsSt;
  417. rsSt.m_pDatabase = m_pdbInstance;
  418. if (lpfilter && _tcsicmp(lpfilter, _T("")) != 0)
  419. rsSt.m_strFilter = lpfilter;
  420. rsSt.Open();
  421. INT_PTR nIndex = 0;
  422. static CString strTemp;
  423. while (!rsSt.IsEOF())
  424. {
  425. strTemp.Format(_T("%ld"), rsSt.m_id);
  426. strListArray.ElementAt(nIndex).RemoveAll();
  427. if (CHILD_VERSION)
  428. {
  429. strListArray.ElementAt(nIndex).Add(strTemp);
  430. strListArray.ElementAt(nIndex).Add(rsSt.m_name);
  431. strListArray.ElementAt(nIndex).Add(rsSt.m_name2);
  432. strListArray.ElementAt(nIndex).Add(rsSt.m_sex);
  433. strListArray.ElementAt(nIndex).Add(rsSt.m_phone);
  434. strListArray.ElementAt(nIndex).Add(rsSt.m_birthday);
  435. strListArray.ElementAt(nIndex).Add(rsSt.m_dandate);
  436. strListArray.ElementAt(nIndex).Add(rsSt.m_date);
  437. strListArray.ElementAt(nIndex).Add(rsSt.m_check1);
  438. }
  439. else
  440. {
  441. strListArray.ElementAt(nIndex).Add(strTemp);
  442. strListArray.ElementAt(nIndex).Add(rsSt.m_name);
  443. strListArray.ElementAt(nIndex).Add(rsSt.m_name2);
  444. strListArray.ElementAt(nIndex).Add(rsSt.m_phone);
  445. strListArray.ElementAt(nIndex).Add(rsSt.m_phone2);
  446. strListArray.ElementAt(nIndex).Add(rsSt.m_birthday);
  447. strListArray.ElementAt(nIndex).Add(rsSt.m_birthday2);
  448. strListArray.ElementAt(nIndex).Add(rsSt.m_time3);
  449. strListArray.ElementAt(nIndex).Add(rsSt.m_dandate);
  450. strListArray.ElementAt(nIndex).Add(rsSt.m_date);
  451. strListArray.ElementAt(nIndex).Add(rsSt.m_check1);
  452. strListArray.ElementAt(nIndex).Add(rsSt.m_check2);
  453. strListArray.ElementAt(nIndex).Add(rsSt.m_check3);
  454. }
  455. nIndex++;
  456. rsSt.MoveNext();
  457. if (strListArray.GetSize() <= nIndex)break;
  458. }
  459. rsSt.Close();
  460. strListArray.SetSize(nIndex, 1);
  461. }
  462. catch (CDBException *e)
  463. {
  464. SolveDBError(GetLastError(),e->m_strError);
  465. e->Delete();
  466. return FALSE;
  467. }
  468. return TRUE;
  469. }
  470. BOOL CDBInterface::GetTableSendreg(CArray<CStringArray, CStringArray> &strListArray, LPCTSTR lpfilter /* = NULL */)
  471. {
  472. try
  473. {
  474. AutoThreadSection aSection(&s_critSection);
  475. if (!m_bOpen) return FALSE;
  476. CRecordset myset(m_pdbInstance);
  477. static CString strSQL;
  478. if (lpfilter && _tcsicmp(lpfilter, _T("")) != 0)
  479. strSQL.Format(_T("select count(*) as cot from sendreg where %s"), lpfilter);
  480. else
  481. strSQL = _T("select count(*) as cot from sendreg");
  482. //WriteClientLog(strSQL);
  483. myset.Open(CRecordset::forwardOnly, strSQL);
  484. myset.GetFieldValue(_T("cot"), strSQL);
  485. myset.Close();
  486. if (_ttol(strSQL) == 0) return TRUE;
  487. strListArray.SetSize(_ttol(strSQL), 1);
  488. CTableSendreg rsSt;
  489. rsSt.m_pDatabase = m_pdbInstance;
  490. if (lpfilter && _tcsicmp(lpfilter, _T("")) != 0)
  491. rsSt.m_strFilter = lpfilter;
  492. rsSt.m_strSort = "timestamp";
  493. rsSt.Open();
  494. INT_PTR nIndex = 0;
  495. static CString strTemp;
  496. while (!rsSt.IsEOF())
  497. {
  498. strTemp.Format(_T("%ld"), rsSt.m_autoid);
  499. strListArray.ElementAt(nIndex).RemoveAll();
  500. strListArray.ElementAt(nIndex).Add(rsSt.m_phones); // 电话;
  501. strListArray.ElementAt(nIndex).Add(rsSt.m_content); // 短信内容;
  502. strListArray.ElementAt(nIndex).Add(rsSt.m_timestamp); // 短信生成日期;
  503. strListArray.ElementAt(nIndex).Add(strTemp); // 自增id
  504. strListArray.ElementAt(nIndex).Add(rsSt.m_status); // 若查询则为sid;
  505. nIndex++;
  506. rsSt.MoveNext();
  507. if (strListArray.GetSize() <= nIndex)break;
  508. }
  509. rsSt.Close();
  510. strListArray.SetSize(nIndex, 1);
  511. }
  512. catch (CDBException* e)
  513. {
  514. SolveDBError(GetLastError(),e->m_strError);
  515. e->Delete();
  516. return FALSE;
  517. }
  518. return TRUE;
  519. }
  520. BOOL CDBInterface::GetTableSendregcard(CArray<CStringArray, CStringArray> &strListArray, LPCTSTR lpfilter /* = NULL */)
  521. {
  522. try{
  523. AutoThreadSection aSection(&s_critSection);
  524. if (!m_bOpen) return FALSE;
  525. CRecordset myset(m_pdbInstance);
  526. static CString strSQL;
  527. if (lpfilter && _tcsicmp(lpfilter, _T("")) != 0)
  528. strSQL.Format(_T("select count(*) as cot from sendregcard where %s"), lpfilter);
  529. else
  530. strSQL = _T("select count(*) as cot from sendregcard");
  531. //WriteClientLog(strSQL);
  532. myset.Open(CRecordset::forwardOnly, strSQL);
  533. myset.GetFieldValue(_T("cot"), strSQL);
  534. myset.Close();
  535. if (_ttol(strSQL) == 0) return TRUE;
  536. strListArray.SetSize(_ttol(strSQL), 1);
  537. CTableSendregcard rsSt;
  538. rsSt.m_pDatabase = m_pdbInstance;
  539. if (lpfilter && _tcsicmp(lpfilter, _T("")) != 0)
  540. rsSt.m_strFilter = lpfilter;
  541. rsSt.Open();
  542. INT_PTR nIndex = 0;
  543. while (!rsSt.IsEOF())
  544. {
  545. strListArray.ElementAt(nIndex).RemoveAll();
  546. strListArray.ElementAt(nIndex).Add(rsSt.m_timestamp);
  547. strListArray.ElementAt(nIndex).Add(rsSt.m_phones);
  548. nIndex++;
  549. rsSt.MoveNext();
  550. if (strListArray.GetSize() <= nIndex)break;
  551. }
  552. rsSt.Close();
  553. strListArray.SetSize(nIndex, 1);
  554. }
  555. catch (CDBException *e)
  556. {
  557. SolveDBError(GetLastError(),e->m_strError);
  558. e->Delete();
  559. return FALSE;
  560. }
  561. return TRUE;
  562. }
  563. BOOL CDBInterface::GetTableHospitalclient(CArray<CStringArray, CStringArray> &strListArray, LPCTSTR lpfilter /* = NULL */)
  564. {
  565. try
  566. {
  567. AutoThreadSection aSection(&s_critSection);
  568. if (!m_bOpen) return FALSE;
  569. CRecordset myset(m_pdbInstance);
  570. static CString strSQL;
  571. if (lpfilter && _tcsicmp(lpfilter, _T("")) != 0)
  572. strSQL.Format(_T("select count(*) as cot from hospitalclient where %s"), lpfilter);
  573. else
  574. strSQL = _T("select count(*) as cot from hospitalclient");
  575. //WriteClientLog(strSQL);
  576. myset.Open(CRecordset::forwardOnly, strSQL);
  577. myset.GetFieldValue(_T("cot"), strSQL);
  578. myset.Close();
  579. if (_ttol(strSQL) == 0) return TRUE;
  580. strListArray.SetSize(_ttol(strSQL), 1);
  581. CTableHospitalclient rsSt;
  582. rsSt.m_pDatabase = m_pdbInstance;
  583. if (lpfilter && _tcsicmp(lpfilter, _T("")) != 0)
  584. rsSt.m_strFilter = lpfilter;
  585. rsSt.Open();
  586. INT_PTR nIndex = 0;
  587. while (!rsSt.IsEOF())
  588. {
  589. strListArray.ElementAt(nIndex).RemoveAll();
  590. strListArray.ElementAt(nIndex).Add(rsSt.m_id);
  591. strListArray.ElementAt(nIndex).Add(rsSt.m_name1);
  592. strListArray.ElementAt(nIndex).Add(rsSt.m_name2);
  593. strListArray.ElementAt(nIndex).Add(rsSt.m_sex);
  594. strListArray.ElementAt(nIndex).Add(rsSt.m_check1);
  595. strListArray.ElementAt(nIndex).Add(rsSt.m_birthdaytype); // ==0 儿童生日; ==1孕妇怀满n天;
  596. strListArray.ElementAt(nIndex).Add(rsSt.m_birthday);
  597. strListArray.ElementAt(nIndex).Add(rsSt.m_pregnancydays);
  598. strListArray.ElementAt(nIndex).Add(rsSt.m_date1);
  599. strListArray.ElementAt(nIndex).Add(rsSt.m_type);
  600. strListArray.ElementAt(nIndex).Add(rsSt.m_phone1);
  601. nIndex++;
  602. rsSt.MoveNext();
  603. if (strListArray.GetSize() <= nIndex)break;
  604. }
  605. rsSt.Close();
  606. strListArray.SetSize(nIndex, 1);
  607. }
  608. catch (CDBException* e)
  609. {
  610. SolveDBError(GetLastError(),e->m_strError);
  611. e->Delete();
  612. return FALSE;
  613. }
  614. return TRUE;
  615. }
  616. BOOL CDBInterface::GetSMSInfo(SMSInfo &tSMSInfo)
  617. {
  618. try
  619. {
  620. AutoThreadSection aSection(&s_critSection);
  621. if (!m_bOpen) return FALSE;
  622. CTableVersion rsSt;
  623. rsSt.m_pDatabase = m_pdbInstance;
  624. rsSt.Open();
  625. if (!rsSt.IsEOF())
  626. {
  627. tSMSInfo.msgaccount = rsSt.m_msgaccount;
  628. tSMSInfo.msgpassword = rsSt.m_msgpsw;
  629. tSMSInfo.msgused = rsSt.m_msgused;
  630. tSMSInfo.msgbalance = rsSt.m_msgbalance;
  631. tSMSInfo.msgCheck1 = rsSt.m_msgcheck1;
  632. tSMSInfo.msgCheck2 = rsSt.m_msgcheck2;
  633. tSMSInfo.msgCheck15 = rsSt.m_msgcheck15;
  634. tSMSInfo.hospitalmsgcheck1 = rsSt.m_hospitalmsgcheck1;
  635. tSMSInfo.hospitalmsgcheck2 = rsSt.m_hospitalmsgcheck2;
  636. tSMSInfo.msgDays1 = rsSt.m_msgdays1;
  637. tSMSInfo.msgDays2 = rsSt.m_msgdays2;
  638. tSMSInfo.msgContent1 = rsSt.m_msgcontent1;
  639. tSMSInfo.msgContent2 = rsSt.m_msgcontent2;
  640. tSMSInfo.msgContent15 = rsSt.m_msgcontent15;
  641. }
  642. rsSt.Close();
  643. }
  644. catch (CDBException *e)
  645. {
  646. SolveDBError(GetLastError(),e->m_strError);
  647. e->Delete();
  648. return FALSE ;
  649. }
  650. return TRUE;
  651. }
  652. BOOL CDBInterface::GetSMSType(std::vector<SmsType> &vtSMSInfo,BOOL bhospitalcheck1,std::vector<SmsType> &vtSMSInfo2,BOOL bhospitalcheck2)
  653. {
  654. try
  655. {
  656. AutoThreadSection aSection(&s_critSection);
  657. if (!m_bOpen) return FALSE;
  658. if ( g_bSoftWareReg == FALSE) return TRUE;
  659. vtSMSInfo.clear();
  660. vtSMSInfo2.clear();
  661. // childmsg表;
  662. CArray<CStringArray,CStringArray> strArray;
  663. GetTableChildmsg(strArray,_T("[check] = '1'"));
  664. int nSize = strArray.GetSize();
  665. for (int i = 0; i < nSize; i++)
  666. {
  667. CStringArray &saInfo = strArray.ElementAt(i);
  668. if ( bhospitalcheck1 && saInfo.ElementAt(3) != _T("2")) // ElementAt(3) == 2 孕妇短信;
  669. {
  670. SmsType tSMSType;
  671. tSMSType.nDays = _ttoi(saInfo.ElementAt(1));
  672. tSMSType.TypeOfMsg = 10000 + tSMSType.nDays;
  673. vtSMSInfo.push_back(tSMSType);
  674. }
  675. if ( bhospitalcheck2 && saInfo.ElementAt(3) == _T("2") )
  676. {
  677. SmsType tSMSType;
  678. tSMSType.nDays = _ttoi(saInfo.ElementAt(1));
  679. tSMSType.TypeOfMsg = 20000 + tSMSType.nDays;
  680. vtSMSInfo2.push_back(tSMSType);
  681. }
  682. }
  683. }
  684. catch (CDBException *e)
  685. {
  686. vtSMSInfo.clear();
  687. SolveDBError(GetLastError(),e->m_strError);
  688. e->Delete();
  689. return FALSE ;
  690. }
  691. return TRUE;
  692. }