DBInterface.cpp 22 KB

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