DBInterface.cpp 23 KB

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