XTPCalendarDatabaseDataProvider.cpp
上传用户:szled88
上传日期:2015-04-09
资源大小:43957k
文件大小:113k
源码类别:

对话框与窗口

开发平台:

Visual C++

  1. // XTPCalendarDatabaseDataProvider.cpp: implementation of the CXTPCalendarDatabaseDataProvider class.
  2. //
  3. // This file is a part of the XTREME CALENDAR MFC class library.
  4. // (c)1998-2008 Codejock Software, All Rights Reserved.
  5. //
  6. // THIS SOURCE FILE IS THE PROPERTY OF CODEJOCK SOFTWARE AND IS NOT TO BE
  7. // RE-DISTRIBUTED BY ANY MEANS WHATSOEVER WITHOUT THE EXPRESSED WRITTEN
  8. // CONSENT OF CODEJOCK SOFTWARE.
  9. //
  10. // THIS SOURCE CODE CAN ONLY BE USED UNDER THE TERMS AND CONDITIONS OUTLINED
  11. // IN THE XTREME TOOLKIT PRO LICENSE AGREEMENT. CODEJOCK SOFTWARE GRANTS TO
  12. // YOU (ONE SOFTWARE DEVELOPER) THE LIMITED RIGHT TO USE THIS SOFTWARE ON A
  13. // SINGLE COMPUTER.
  14. //
  15. // CONTACT INFORMATION:
  16. // support@codejock.com
  17. // http://www.codejock.com
  18. //
  19. /////////////////////////////////////////////////////////////////////////////
  20. #include "stdafx.h"
  21. #include "Common/XTPPropExchange.h"
  22. #include "Common/XTPVC50Helpers.h"
  23. #include "Common/XTPVC80Helpers.h"
  24. #include "Common/XTPResourceManager.h"
  25. #include "XTPCalendarDatabaseDataProvider.h"
  26. #include "XTPCalendarUtils.h"
  27. #include "XTPCalendarNotifications.h"
  28. #include "XTPCalendarControl.h"
  29. #include "XTPCalendarCustomProperties.h"
  30. #include "XTPCalendarResource.h"
  31. #pragma warning(disable: 4571) // warning C4571: catch(...) blocks compiled with /EHs do not catch or re-throw Structured Exceptions
  32. #ifdef _DEBUG
  33. #define new DEBUG_NEW
  34. #undef THIS_FILE
  35. static char THIS_FILE[] = __FILE__;
  36. #endif
  37. /////////////////////////////////////////////////////////////////////////////
  38. AFX_INLINE CString MakeSQLDateTime(DATE t)
  39. {
  40. COleDateTime ct(t);
  41. return ct.Format(_T("#%Y-%m-%d %H:%M:%S#"));
  42. }
  43. AFX_INLINE const _variant_t DATE2VAR(DATE dt)
  44. {
  45. return _variant_t(dt, VT_DATE);
  46. }
  47. AFX_INLINE const _variant_t STRING2VAR(const CString& str)
  48. {
  49. VARIANT vtStr;
  50. vtStr.vt = VT_BSTR;
  51. vtStr.bstrVal = str.AllocSysString();
  52. return _variant_t(vtStr, false); // Will deallocate in destructor
  53. }
  54. template<class _TData>
  55. _TData _GetField(XTPADODB::_Recordset* pRS, LPCWSTR pcszFName, _TData defVal)
  56. {
  57. _TData dataValue;
  58. try
  59. {
  60. XTPADODB::FieldPtr ptrField = pRS->Fields->GetItem(pcszFName);
  61. if (ptrField)
  62. {
  63. _variant_t vtValue = ptrField->Value;
  64. if (vtValue.vt == VT_NULL || vtValue.vt == VT_EMPTY ||
  65. vtValue.vt == VT_ERROR)
  66. {
  67. return defVal;
  68. }
  69. dataValue = (_TData)vtValue;
  70. return dataValue;
  71. }
  72. }
  73. catch (_com_error &e)
  74. {
  75. e;
  76. #ifdef _DEBUG
  77. if (pRS->GetActiveConnection().vt == VT_DISPATCH &&
  78. pRS->GetActiveConnection().pdispVal)
  79. {
  80. XTPADODB::_Connection* pConnDB = NULL;
  81. HRESULT hr = pRS->GetActiveConnection().pdispVal->QueryInterface(__uuidof(XTPADODB::_Connection), (void**)&pConnDB);
  82. if (SUCCEEDED(hr))
  83. {
  84. CXTPCalendarDatabaseDataProvider::TRACE_ProviderError(pConnDB);
  85. }
  86. }
  87. CXTPCalendarDatabaseDataProvider::TRACE_ComError(e);
  88. #endif
  89. }
  90. catch(...)
  91. {}
  92. TRACE(_T("ERROR: CalendarDB provider: Cannot Get field '%s' n"), pcszFName);
  93. return defVal;
  94. }
  95. inline CString VariantToString(VARIANT vtValue, LPCTSTR lpszDefault)
  96. {
  97. if (vtValue.vt != VT_BSTR)
  98. {
  99. if (FAILED(::VariantChangeType(&vtValue, &vtValue, 0, VT_BSTR)))
  100. {
  101. return lpszDefault;
  102. }
  103. }
  104. return CString(V_BSTR(&vtValue));
  105. }
  106. CString _GetFieldString(XTPADODB::_Recordset* pRS, LPCWSTR pcszFName, LPCTSTR defVal = NULL)
  107. {
  108. try
  109. {
  110. XTPADODB::FieldPtr ptrField = pRS->Fields->GetItem(pcszFName);
  111. if (ptrField)
  112. {
  113. _variant_t vtValue = ptrField->Value;
  114. if (vtValue.vt == VT_NULL || vtValue.vt == VT_EMPTY ||
  115. vtValue.vt == VT_ERROR)
  116. {
  117. return defVal;
  118. }
  119. return VariantToString(vtValue, defVal);
  120. }
  121. }
  122. catch (_com_error &e)
  123. {
  124. e;
  125. #ifdef _DEBUG
  126. if (pRS->GetActiveConnection().vt == VT_DISPATCH &&
  127. pRS->GetActiveConnection().pdispVal)
  128. {
  129. XTPADODB::_Connection* pConnDB = NULL;
  130. HRESULT hr = pRS->GetActiveConnection().pdispVal->QueryInterface(__uuidof(XTPADODB::_Connection), (void**)&pConnDB);
  131. if (SUCCEEDED(hr))
  132. {
  133. CXTPCalendarDatabaseDataProvider::TRACE_ProviderError(pConnDB);
  134. }
  135. }
  136. CXTPCalendarDatabaseDataProvider::TRACE_ComError(e);
  137. #endif
  138. }
  139. catch(...)
  140. {}
  141. TRACE(_T("ERROR: CalendarDB provider: Cannot Get field '%s' n"), pcszFName);
  142. return defVal;
  143. }
  144. class CXTPCalendarDatabaseDataProvider::CADOCommand : public CCmdTarget
  145. {
  146. public:
  147. CADOCommand(XTPADODB::_ConnectionPtr pConnection, LPCWSTR pcszSQLText);
  148. ~CADOCommand();
  149. void CreateParameter(LPCWSTR pcszParamName, XTPADODB::DataTypeEnum adDataType,
  150. XTPADODB::ParameterDirectionEnum adDirection, long nSize,
  151. const _variant_t& vtValue);
  152. void SetParameter(XTPADODB::DataTypeEnum adDataType, long nSize,
  153. const _variant_t& vtValue);
  154. void SetSQLString(LPCWSTR pcszSQLText);
  155. void SetParameterValue(LPCWSTR pcszParamName, const _variant_t& vtValue);
  156. XTPADODB::_RecordsetPtr Execute();
  157. void ClearParams();
  158. void TraceComError(_com_error &e);
  159. private:
  160. XTPADODB::_CommandPtr     m_pcmdSQL;
  161. XTPADODB::_ConnectionPtr  m_pconnDb;
  162. };
  163. //===========================================================================
  164. // Summary:
  165. //     Define Empty DB string.
  166. //===========================================================================
  167. #define EMPTY_DB_STR L"abcdefghabcdefghabcdefghabcdefghabcde"
  168. //////////////////////////////////////////////////////////////////////
  169. IMPLEMENT_DYNAMIC(CXTPCalendarDatabaseDataProvider, CXTPCalendarData)
  170. //////////////////////////////////////////////////////////////////////
  171. void AFX_CDECL CXTPCalendarDatabaseDataProvider::TRACE_ComError(_com_error &e)
  172. {
  173. LPCWSTR bstrSource(e.Source());
  174. // Print COM errors.
  175. TRACE(_T("COM_ERROR: HRESULT = %08lx, Code meaning = %s, Source = %lsn"),
  176.   e.Error(), (LPCTSTR)e.ErrorMessage(), (LPCWSTR)bstrSource);
  177. }
  178. //===========================================================================
  179. void AFX_CDECL CXTPCalendarDatabaseDataProvider::TRACE_ProviderError(XTPADODB::_Connection* pConnDB)
  180. {
  181. // Print Provider Errors from Connection object.
  182. ASSERT(pConnDB);
  183. if (!pConnDB)
  184. return;
  185. if (pConnDB->Errors->Count > 0)
  186. {
  187. long nCount = pConnDB->Errors->Count;
  188. TRACE(_T("DB ERROR(s): "));
  189. for (long i = 0; i < nCount; i++)
  190. {
  191. XTPADODB::ErrorPtr ptrErr = pConnDB->Errors->GetItem(i);
  192. TRACE(_T(" (Error- %x, '%ls'); "), ptrErr->Number, (LPCWSTR)ptrErr->Description);
  193. }
  194. TRACE(_T(" n"));
  195. }
  196. }
  197. //////////////////////////////////////////////////////////////////////
  198. // Construction/Destruction
  199. //////////////////////////////////////////////////////////////////////
  200. CXTPCalendarDatabaseDataProvider::CXTPCalendarDatabaseDataProvider()
  201. {
  202. m_pconnDb = NULL;
  203. m_bCloseDbConnection = TRUE;
  204. m_bTraceOptions = FALSE;
  205. m_typeProvider = xtpCalendarDataProviderDatabase;
  206. SetCacheMode(xtpCalendarDPCacheModeOnRepeat);
  207. m_pcmdAddEvent = NULL;
  208. m_pcmdDelEvent = NULL;
  209. m_pcmdUpdEvent = NULL;
  210. m_pcmdUpdEventPatternID = NULL;
  211. m_pcmdGetDayEvents = NULL;
  212. m_pcmdGetRExceptions = NULL;
  213. m_pcmdGetLastID = NULL;
  214. m_pcmdGetEvent = NULL;
  215. m_pcmdAddRPattern = NULL;
  216. m_pcmdDelRPattern = NULL;
  217. m_pcmdUpdRPattern = NULL;
  218. m_pcmdGetRPattern = NULL;
  219. m_pcmdRemoveAllEvents = NULL;
  220. m_pcmdRemoveAllRPatterns = NULL;
  221. m_pcmdRemoveAllOptions = NULL;
  222. m_pcmdGetOptions = NULL;
  223. m_pcmdAddOptions = NULL;
  224. m_pcmdAddSchedule = NULL;
  225. m_pcmdUpdSchedule = NULL;
  226. try
  227. {
  228. HRESULT hr = m_pconnDb.CreateInstance(__uuidof(XTPADODB::Connection));
  229. ASSERT(SUCCEEDED(hr));
  230. if (FAILED(hr))
  231. {
  232. TRACE(_T("ERROR: Cannot create XTPADODB::Connection. (HRESULT = %08lx) n"), hr);
  233. }
  234. }
  235. catch(...)
  236. {
  237. ASSERT(FALSE);
  238. TRACE(_T("ERROR: Cannot create XTPADODB::Connection. Exception was happend. n"));
  239. }
  240. }
  241. CXTPCalendarDatabaseDataProvider::~CXTPCalendarDatabaseDataProvider()
  242. {
  243. try
  244. {
  245. DeleteAllDBCommands();
  246. Close();
  247. return;
  248. }
  249. catch (_com_error &e)
  250. {
  251. TRACE_ProviderError(m_pconnDb);
  252. TRACE_ComError(e);
  253. ASSERT(FALSE);
  254. }
  255. catch (...)
  256. {
  257. ASSERT(FALSE);
  258. }
  259. TRACE(_T("ERROR: Exeption in ~CXTPCalendarDatabaseDataProvider()"));
  260. }
  261. void CXTPCalendarDatabaseDataProvider::DeleteAllDBCommands()
  262. {
  263. CMDTARGET_RELEASE(m_pcmdAddEvent);
  264. CMDTARGET_RELEASE(m_pcmdDelEvent);
  265. CMDTARGET_RELEASE(m_pcmdUpdEvent);
  266. CMDTARGET_RELEASE(m_pcmdGetDayEvents);
  267. CMDTARGET_RELEASE(m_pcmdGetLastID);
  268. CMDTARGET_RELEASE(m_pcmdAddRPattern);
  269. CMDTARGET_RELEASE(m_pcmdDelRPattern);
  270. CMDTARGET_RELEASE(m_pcmdUpdRPattern);
  271. CMDTARGET_RELEASE(m_pcmdGetRPattern);
  272. CMDTARGET_RELEASE(m_pcmdGetRExceptions);
  273. CMDTARGET_RELEASE(m_pcmdGetEvent);
  274. CMDTARGET_RELEASE(m_pcmdUpdEventPatternID);
  275. CMDTARGET_RELEASE(m_pcmdRemoveAllEvents);
  276. CMDTARGET_RELEASE(m_pcmdRemoveAllRPatterns);
  277. CMDTARGET_RELEASE(m_pcmdRemoveAllOptions);
  278. CMDTARGET_RELEASE(m_pcmdGetOptions);
  279. CMDTARGET_RELEASE(m_pcmdAddOptions);
  280. CMDTARGET_RELEASE(m_pcmdAddSchedule);
  281. CMDTARGET_RELEASE(m_pcmdUpdSchedule);
  282. }
  283. BOOL CXTPCalendarDatabaseDataProvider::Open()
  284. {
  285. if (m_strConnectionString.IsEmpty())
  286. return FALSE;
  287. if (IsOpen())
  288. {
  289. TRACE(_T("Provider is alredy opened. CXTPCalendarDatabaseDataProvider::Open(ConnectionString='%s') n"), (LPCTSTR)m_strConnectionString);
  290. return TRUE;
  291. }
  292. if (m_pconnDb == NULL)
  293. {
  294. return FALSE;
  295. }
  296. // Check is the special mode to use OpenEx later.
  297. CString strConn = m_strConnectionString;
  298. strConn.MakeLower();
  299. if (strConn.Find(_T("provider=access;")) >= 0 || strConn == _T("provider=access") ||
  300. strConn.Find(_T("provider=ado;")) >= 0 || strConn == _T("provider=ado"))
  301. {
  302. return TRUE;
  303. }
  304. //-----------------------------------------------------------
  305. try
  306. {
  307. m_bCloseDbConnection = TRUE;
  308. HRESULT hr = m_pconnDb->Open(_bstr_t(XTP_CT2CW(m_strConnectionString)), L"", L"", -1);
  309. ASSERT(SUCCEEDED(hr));
  310. if (SUCCEEDED(hr) && _Open())
  311. {
  312. return TRUE;
  313. }
  314. TRACE(_T("ERROR: Cannot open DB Connection. (HRESULT = %08lx, ConnectionString='%s') n"), hr, (LPCTSTR)m_strConnectionString);
  315. return FALSE;
  316. }
  317. catch (_com_error &e)
  318. {
  319. TRACE_ProviderError(m_pconnDb);
  320. TRACE_ComError(e);
  321. }
  322. catch (...)
  323. {}
  324. TRACE(_T("ERROR: Exeption in CXTPCalendarDatabaseDataProvider::Open(ConnectionString='%s') n"), (LPCTSTR)m_strConnectionString);
  325. return FALSE;
  326. }
  327. BOOL CXTPCalendarDatabaseDataProvider::OpenEx(LPDISPATCH pdispADOConnection)
  328. {
  329. if (IsOpen())
  330. {
  331. TRACE(_T("Provider is alredy opened. CXTPCalendarDatabaseDataProvider::OpenEx() n"));
  332. return TRUE;
  333. }
  334. if (m_pconnDb == NULL) // Object was not created on constructor. ADO is not installed ???
  335. {
  336. return FALSE;
  337. }
  338. try
  339. {
  340. _variant_t vtADOConn(pdispADOConnection);
  341. m_pconnDb = vtADOConn;
  342. m_bCloseDbConnection = FALSE;
  343. if (_Open())
  344. {
  345. return TRUE;
  346. }
  347. TRACE(_T("ERROR: Cannot open using External ADO Connection. n") );
  348. return FALSE;
  349. }
  350. catch (_com_error &e)
  351. {
  352. TRACE_ProviderError(m_pconnDb);
  353. TRACE_ComError(e);
  354. }
  355. catch (...)
  356. {}
  357. TRACE(_T("ERROR: Exeption in CXTPCalendarDatabaseDataProvider::OpenEx() n"), (LPCTSTR)m_strConnectionString);
  358. return FALSE;
  359. }
  360. BOOL CXTPCalendarDatabaseDataProvider::_Open()
  361. {
  362. if (m_pconnDb == NULL)
  363. {
  364. ASSERT(FALSE);
  365. return FALSE;
  366. }
  367. VERIFY(UpdateDBStructure(m_pconnDb));
  368. CreateGetLastIDCommand();
  369. CreateAddEventCommand();
  370. CreateDelEventCommand();
  371. CreateUpdEventCommand();
  372. CreateGetDayEventCommand();
  373. CreateAddRPatternCommand();
  374. CreateDelRPatternCommand();
  375. CreateUpdRPatternCommand();
  376. CreateGetRPatternCommand();
  377. CreateGetRExceptionsCommand();
  378. CreateGetEventCommand();
  379. CreateUpdEventPatternIDCommand();
  380. CreateRemoveAllCommands();
  381. CreateGetOptionsCommand();
  382. CreateAddOptionsCommand();
  383. CreateAddScheduleCommand();
  384. CreateUpdScheduleCommand();
  385. CXTPCalendarData::Open();
  386. LoadOptions();
  387. CXTPCalendarSchedulesPtr ptrSchedules = LoadSchedules();
  388. if (ptrSchedules)
  389. {
  390. CMDTARGET_RELEASE(m_pSchedules);
  391. m_pSchedules = ptrSchedules;
  392. CMDTARGET_ADDREF(m_pSchedules);
  393. }
  394. else if (m_pSchedules)
  395. {
  396. m_pSchedules->RemoveAll();
  397. }
  398. return IsOpen();
  399. }
  400. BOOL CXTPCalendarDatabaseDataProvider::IsTableExist(XTPADOX::_CatalogPtr ptrCatalog, LPCWSTR pwszTableName)
  401. {
  402. try
  403. {
  404. XTPADOX::_TablePtr ptrTable = ptrCatalog->Tables->GetItem(pwszTableName);
  405. return ptrTable != NULL;
  406. }
  407. catch (...)
  408. {}
  409. return FALSE;
  410. }
  411. void CXTPCalendarDatabaseDataProvider::CreateSchedulesTable(XTPADOX::_CatalogPtr ptrCatalog)
  412. {
  413. XTPADOX::_TablePtr ptrTable;
  414. // Event table
  415. ptrTable.CreateInstance(__uuidof (XTPADOX::Table));
  416. ptrTable->Name = L"Schedules";
  417. // ------ Columns -------
  418. // ScheduleID
  419. XTPADOX::_ColumnPtr ptrID(__uuidof(XTPADOX::Column));
  420. ptrID->Name = L"ScheduleID";
  421. ptrID->Type = XTPADOX::adInteger;
  422. ptrID->ParentCatalog = ptrCatalog;
  423. ptrID->Properties->GetItem(L"AutoIncrement")->PutValue(_variant_t(true));
  424. ptrTable->Columns->Append(_variant_t((IDispatch*)ptrID, true), XTPADOX::adInteger, 0);
  425. // Name
  426. XTPADOX::_ColumnPtr ptrName(__uuidof(XTPADOX::Column));
  427. ptrName->Name = L"Name";
  428. ptrName->Type = XTPADOX::adWChar;
  429. ptrName->ParentCatalog = ptrCatalog;
  430. ptrName->Properties->GetItem(L"Nullable")->PutValue(_variant_t(true));
  431. ptrTable->Columns->Append(_variant_t((IDispatch*)ptrName, true), XTPADOX::adWChar, 255);
  432. // XMLData
  433. XTPADOX::_ColumnPtr ptrXMLData(__uuidof(XTPADOX::Column));
  434. ptrXMLData->Name = L"CustomPropertiesXMLData";
  435. ptrXMLData->Type = XTPADOX::adLongVarWChar;
  436. ptrXMLData->ParentCatalog = ptrCatalog;
  437. ptrXMLData->Properties->GetItem(L"Nullable")->PutValue(_variant_t(true));
  438. ptrTable->Columns->Append(_variant_t((IDispatch*)ptrXMLData, true), XTPADOX::adLongVarWChar, 0);
  439. // SaveDateTime
  440. XTPADOX::_ColumnPtr ptrSaveDateTime(__uuidof(XTPADOX::Column));
  441. ptrSaveDateTime->Name = L"Modified";
  442. ptrSaveDateTime->Type = XTPADOX::adDate;
  443. ptrSaveDateTime->ParentCatalog = ptrCatalog;
  444. ptrSaveDateTime->Properties->GetItem(L"Nullable")->PutValue(_variant_t(true));
  445. ptrTable->Columns->Append(_variant_t((IDispatch*)ptrSaveDateTime, true),   XTPADOX::adDate,   0);
  446. // --------- Keys ---------
  447. // Table key
  448. ptrTable->Keys->Append(L"PK", XTPADOX::adKeyPrimary, L"ScheduleID", L"", L"");
  449. ptrCatalog->Tables->Append(_variant_t((IDispatch *)ptrTable));
  450. ptrTable = NULL;
  451. }
  452. void CXTPCalendarDatabaseDataProvider::CreateOptionsTable(XTPADOX::_CatalogPtr ptrCatalog)
  453. {
  454. XTPADOX::_TablePtr ptrTable;
  455. // Event table
  456. ptrTable.CreateInstance(__uuidof (XTPADOX::Table));
  457. ptrTable->Name = L"Options";
  458. // ------ Columns -------
  459. // EventID
  460. XTPADOX::_ColumnPtr ptrOID(__uuidof(XTPADOX::Column));
  461. ptrOID->Name = L"OptionsID";
  462. ptrOID->Type = XTPADOX::adInteger;
  463. ptrOID->ParentCatalog = ptrCatalog;
  464. ptrOID->Properties->GetItem(L"AutoIncrement")->PutValue(_variant_t(true));
  465. ptrTable->Columns->Append(_variant_t((IDispatch*)ptrOID, true), XTPADOX::adInteger, 0);
  466. // SaveDateTime
  467. XTPADOX::_ColumnPtr ptrSaveDateTime(__uuidof(XTPADOX::Column));
  468. ptrSaveDateTime->Name = L"SaveDateTime";
  469. ptrSaveDateTime->Type = XTPADOX::adDate;
  470. ptrSaveDateTime->ParentCatalog = ptrCatalog;
  471. ptrSaveDateTime->Properties->GetItem(L"Nullable")->PutValue(_variant_t(true));
  472. ptrTable->Columns->Append(_variant_t((IDispatch*)ptrSaveDateTime, true),   XTPADOX::adDate,   0);
  473. // XMLData
  474. XTPADOX::_ColumnPtr ptrXMLData(__uuidof(XTPADOX::Column));
  475. ptrXMLData->Name = L"XMLData";
  476. ptrXMLData->Type = XTPADOX::adLongVarWChar;
  477. ptrXMLData->ParentCatalog = ptrCatalog;
  478. ptrTable->Columns->Append(_variant_t((IDispatch*)ptrXMLData, true), XTPADOX::adLongVarWChar, 0);
  479. // --------- Keys ---------
  480. // Table key
  481. ptrTable->Keys->Append(L"PK", XTPADOX::adKeyPrimary, L"OptionsID", L"", L"");
  482. ptrCatalog->Tables->Append(_variant_t((IDispatch *)ptrTable));
  483. ptrTable = NULL;
  484. }
  485. void CXTPCalendarDatabaseDataProvider::CreateEventTable(XTPADOX::_CatalogPtr ptrCatalog)
  486. {
  487. XTPADOX::_TablePtr ptrTable;
  488. // Event table
  489. ptrTable.CreateInstance(__uuidof (XTPADOX::Table));
  490. ptrTable->Name = L"Event";
  491. // ------ Columns -------
  492. // EventID
  493. XTPADOX::_ColumnPtr ptrEID(__uuidof(XTPADOX::Column));
  494. ptrEID->Name = L"EventID";
  495. ptrEID->Type = XTPADOX::adInteger;
  496. ptrEID->ParentCatalog = ptrCatalog;
  497. ptrEID->Properties->GetItem(L"AutoIncrement")->PutValue(_variant_t(true));
  498. ptrTable->Columns->Append(_variant_t((IDispatch*)ptrEID, true), XTPADOX::adInteger, 0);
  499. // StartDateTime
  500. XTPADOX::_ColumnPtr ptrStartDateTime(__uuidof(XTPADOX::Column));
  501. ptrStartDateTime->Name = L"StartDateTime";
  502. ptrStartDateTime->Type = XTPADOX::adDate;
  503. ptrStartDateTime->ParentCatalog = ptrCatalog;
  504. ptrStartDateTime->Properties->GetItem(L"Nullable")->PutValue(_variant_t(true));
  505. ptrTable->Columns->Append(_variant_t((IDispatch*)ptrStartDateTime, true),   XTPADOX::adDate,   0);
  506. // EndDateTime
  507. XTPADOX::_ColumnPtr ptrEndDateTime(__uuidof(XTPADOX::Column));
  508. ptrEndDateTime->Name = L"EndDateTime";
  509. ptrEndDateTime->Type = XTPADOX::adDate;
  510. ptrEndDateTime->ParentCatalog = ptrCatalog;
  511. ptrEndDateTime->Properties->GetItem(L"Nullable")->PutValue(_variant_t(true));
  512. ptrTable->Columns->Append(_variant_t((IDispatch*)ptrEndDateTime, true), XTPADOX::adDate,   0);
  513. // RecurrenceState
  514. XTPADOX::_ColumnPtr ptrRS(__uuidof(XTPADOX::Column));
  515. ptrRS->Name = L"RecurrenceState";
  516. ptrRS->Type = XTPADOX::adInteger;
  517. ptrRS->ParentCatalog = ptrCatalog;
  518. ptrRS->Properties->GetItem(L"Nullable")->PutValue(_variant_t(false));
  519. ptrRS->Properties->GetItem(L"Default")->PutValue(_variant_t((long)0, VT_I4));
  520. ptrRS->Properties->GetItem(L"Description")->PutValue(_variant_t(L"normal - 0, master 1, exception 3"));
  521. ptrTable->Columns->Append(_variant_t((IDispatch*)ptrRS, true), XTPADOX::adInteger, 0);
  522. // IsAllDayEvent
  523. XTPADOX::_ColumnPtr ptrIsADE(__uuidof(XTPADOX::Column));
  524. ptrIsADE->Name = L"IsAllDayEvent";
  525. ptrIsADE->Type = XTPADOX::adInteger;
  526. ptrIsADE->ParentCatalog = ptrCatalog;
  527. ptrIsADE->Properties->GetItem(L"Nullable")->PutValue(_variant_t(true));
  528. ptrIsADE->Properties->GetItem(L"Default")->PutValue(_variant_t((long)0, VT_I4));
  529. ptrIsADE->Properties->GetItem(L"Description")->PutValue(_variant_t(L"all day event 1, 0 - otherwise"));
  530. ptrTable->Columns->Append(_variant_t((IDispatch*)ptrIsADE, true), XTPADOX::adInteger, 0);
  531. // Subject
  532. XTPADOX::_ColumnPtr ptrSubject(__uuidof(XTPADOX::Column));
  533. ptrSubject->Name = L"Subject";
  534. ptrSubject->Type = XTPADOX::adLongVarWChar;
  535. ptrSubject->ParentCatalog = ptrCatalog;
  536. ptrSubject->Properties->GetItem(L"Nullable")->PutValue(_variant_t(true));
  537. ptrTable->Columns->Append(_variant_t((IDispatch*)ptrSubject, true), XTPADOX::adLongVarWChar, 0);
  538. // Location
  539. XTPADOX::_ColumnPtr ptrLocation(__uuidof(XTPADOX::Column));
  540. ptrLocation->Name = L"Location";
  541. ptrLocation->Type = XTPADOX::adLongVarWChar;
  542. ptrLocation->ParentCatalog = ptrCatalog;
  543. ptrLocation->Properties->GetItem(L"Nullable")->PutValue(_variant_t(true));
  544. ptrTable->Columns->Append(_variant_t((IDispatch*)ptrLocation, true), XTPADOX::adLongVarWChar, 0);
  545. // RemainderSoundFile
  546. XTPADOX::_ColumnPtr ptrRSF(__uuidof(XTPADOX::Column));
  547. ptrRSF->Name = L"RemainderSoundFile";
  548. ptrRSF->Type = XTPADOX::adWChar;
  549. ptrRSF->ParentCatalog = ptrCatalog;
  550. ptrRSF->Properties->GetItem(L"Nullable")->PutValue(_variant_t(true));
  551. ptrTable->Columns->Append(_variant_t((IDispatch*)ptrRSF, true), XTPADOX::adWChar, 255);
  552. // Body
  553. XTPADOX::_ColumnPtr ptrBody(__uuidof(XTPADOX::Column));
  554. ptrBody->Name = L"Body";
  555. ptrBody->Type = XTPADOX::adLongVarWChar;
  556. ptrBody->ParentCatalog = ptrCatalog;
  557. ptrBody->Properties->GetItem(L"Nullable")->PutValue(_variant_t(true));
  558. ptrTable->Columns->Append(_variant_t((IDispatch*)ptrBody, true), XTPADOX::adLongVarWChar, 0);
  559. // Created
  560. XTPADOX::_ColumnPtr ptrCreated(__uuidof(XTPADOX::Column));
  561. ptrCreated->Name = L"Created";
  562. ptrCreated->Type = XTPADOX::adDate;
  563. ptrCreated->ParentCatalog = ptrCatalog;
  564. ptrCreated->Properties->GetItem(L"Nullable")->PutValue(_variant_t(true));
  565. ptrTable->Columns->Append(_variant_t((IDispatch*)ptrCreated, true), XTPADOX::adDate,   0);
  566. // Modified
  567. XTPADOX::_ColumnPtr ptrModified(__uuidof(XTPADOX::Column));
  568. ptrModified->Name = L"Modified";
  569. ptrModified->Type = XTPADOX::adDate;
  570. ptrModified->ParentCatalog = ptrCatalog;
  571. ptrModified->Properties->GetItem(L"Nullable")->PutValue(_variant_t(true));
  572. ptrTable->Columns->Append(_variant_t((IDispatch*)ptrModified, true),    XTPADOX::adDate,   0);
  573. // BusyStatus
  574. XTPADOX::_ColumnPtr ptrBusyStatus(__uuidof(XTPADOX::Column));
  575. ptrBusyStatus->Name = L"BusyStatus";
  576. ptrBusyStatus->Type = XTPADOX::adInteger;
  577. ptrBusyStatus->ParentCatalog = ptrCatalog;
  578. ptrBusyStatus->Properties->GetItem(L"Nullable")->PutValue(_variant_t(true));
  579. ptrBusyStatus->Properties->GetItem(L"Default")->PutValue(_variant_t((long)0, VT_I4));
  580. ptrTable->Columns->Append(_variant_t((IDispatch*)ptrBusyStatus, true), XTPADOX::adInteger, 0);
  581. // ImportanceLevel
  582. XTPADOX::_ColumnPtr ptrImportanceLevel(__uuidof(XTPADOX::Column));
  583. ptrImportanceLevel->Name = L"ImportanceLevel";
  584. ptrImportanceLevel->Type = XTPADOX::adInteger;
  585. ptrImportanceLevel->ParentCatalog = ptrCatalog;
  586. ptrImportanceLevel->Properties->GetItem(L"Nullable")->PutValue(_variant_t(true));
  587. ptrImportanceLevel->Properties->GetItem(L"Default")->PutValue(_variant_t((long)0, VT_I4));
  588. ptrTable->Columns->Append(_variant_t((IDispatch*)ptrImportanceLevel, true), XTPADOX::adInteger, 0);
  589. // LabelID
  590. XTPADOX::_ColumnPtr ptrLabelID(__uuidof(XTPADOX::Column));
  591. ptrLabelID->Name = L"LabelID";
  592. ptrLabelID->Type = XTPADOX::adInteger;
  593. ptrLabelID->ParentCatalog = ptrCatalog;
  594. ptrLabelID->Properties->GetItem(L"Nullable")->PutValue(_variant_t(true));
  595. ptrLabelID->Properties->GetItem(L"Default")->PutValue(_variant_t((long)0, VT_I4));
  596. ptrTable->Columns->Append(_variant_t((IDispatch*)ptrLabelID, true), XTPADOX::adInteger, 0);
  597. // RecurrencePatternID
  598. XTPADOX::_ColumnPtr ptrRecurrencePatternID(__uuidof(XTPADOX::Column));
  599. ptrRecurrencePatternID->Name = L"RecurrencePatternID";
  600. ptrRecurrencePatternID->Type = XTPADOX::adInteger;
  601. ptrRecurrencePatternID->ParentCatalog = ptrCatalog;
  602. ptrRecurrencePatternID->Properties->GetItem(L"Nullable")->PutValue(_variant_t(true));
  603. ptrRecurrencePatternID->Properties->GetItem(L"Default")->PutValue(_variant_t((long)0, VT_I4));
  604. ptrTable->Columns->Append(_variant_t((IDispatch*)ptrRecurrencePatternID, true), XTPADOX::adInteger, 0);
  605. // ScheduleID
  606. XTPADOX::_ColumnPtr ptrScheduleID(__uuidof(XTPADOX::Column));
  607. ptrScheduleID->Name = L"ScheduleID";
  608. ptrScheduleID->Type = XTPADOX::adInteger;
  609. ptrScheduleID->ParentCatalog = ptrCatalog;
  610. ptrScheduleID->Properties->GetItem(L"Nullable")->PutValue(_variant_t(true));
  611. ptrScheduleID->Properties->GetItem(L"Default")->PutValue(_variant_t((long)0, VT_I4));
  612. ptrTable->Columns->Append(_variant_t((IDispatch*)ptrScheduleID, true), XTPADOX::adInteger, 0);
  613. // ISRecurrenceExceptionDeleted
  614. XTPADOX::_ColumnPtr ptrIsRED(__uuidof(XTPADOX::Column));
  615. ptrIsRED->Name = L"ISRecurrenceExceptionDeleted";
  616. ptrIsRED->Type = XTPADOX::adInteger;
  617. ptrIsRED->ParentCatalog = ptrCatalog;
  618. ptrIsRED->Properties->GetItem(L"Nullable")->PutValue(_variant_t(true));
  619. ptrIsRED->Properties->GetItem(L"Default")->PutValue(_variant_t((long)0, VT_I4));
  620. ptrTable->Columns->Append(_variant_t((IDispatch*)ptrIsRED, true), XTPADOX::adInteger, 0);
  621. // RExceptionStartTimeOrig
  622. XTPADOX::_ColumnPtr ptrREStart(__uuidof(XTPADOX::Column));
  623. ptrREStart->Name = L"RExceptionStartTimeOrig";
  624. ptrREStart->Type = XTPADOX::adDate;
  625. ptrREStart->ParentCatalog = ptrCatalog;
  626. ptrREStart->Properties->GetItem(L"Nullable")->PutValue(_variant_t(true));
  627. ptrTable->Columns->Append(_variant_t((IDispatch*)ptrREStart, true), XTPADOX::adDate,   0);
  628. // RExceptionEndTimeOrig
  629. XTPADOX::_ColumnPtr ptrREEnd(__uuidof(XTPADOX::Column));
  630. ptrREEnd->Name = L"RExceptionEndTimeOrig";
  631. ptrREEnd->Type = XTPADOX::adDate;
  632. ptrREEnd->ParentCatalog = ptrCatalog;
  633. ptrREEnd->Properties->GetItem(L"Nullable")->PutValue(_variant_t(true));
  634. ptrTable->Columns->Append(_variant_t((IDispatch*)ptrREEnd, true),   XTPADOX::adDate,   0);
  635. // IsMeeting
  636. XTPADOX::_ColumnPtr ptrIsMeeting(__uuidof(XTPADOX::Column));
  637. ptrIsMeeting->Name = L"IsMeeting";
  638. ptrIsMeeting->Type = XTPADOX::adInteger;
  639. ptrIsMeeting->ParentCatalog = ptrCatalog;
  640. ptrIsMeeting->Properties->GetItem(L"Nullable")->PutValue(_variant_t(true));
  641. ptrIsMeeting->Properties->GetItem(L"Default")->PutValue(_variant_t((long)0, VT_I4));
  642. ptrTable->Columns->Append(_variant_t((IDispatch*)ptrIsMeeting, true), XTPADOX::adInteger, 0);
  643. // IsPrivate
  644. XTPADOX::_ColumnPtr ptrIsPrivate(__uuidof(XTPADOX::Column));
  645. ptrIsPrivate->Name = L"IsPrivate";
  646. ptrIsPrivate->Type = XTPADOX::adInteger;
  647. ptrIsPrivate->ParentCatalog = ptrCatalog;
  648. ptrIsPrivate->Properties->GetItem(L"Nullable")->PutValue(_variant_t(true));
  649. ptrIsPrivate->Properties->GetItem(L"Default")->PutValue(_variant_t((long)0, VT_I4));
  650. ptrTable->Columns->Append(_variant_t((IDispatch*)ptrIsPrivate, true), XTPADOX::adInteger, 0);
  651. // IsReminder
  652. XTPADOX::_ColumnPtr ptrIsReminder(__uuidof(XTPADOX::Column));
  653. ptrIsReminder->Name = L"IsReminder";
  654. ptrIsReminder->Type = XTPADOX::adInteger;
  655. ptrIsReminder->ParentCatalog = ptrCatalog;
  656. ptrIsReminder->Properties->GetItem(L"Nullable")->PutValue(_variant_t(true));
  657. ptrIsReminder->Properties->GetItem(L"Default")->PutValue(_variant_t((long)0, VT_I4));
  658. ptrTable->Columns->Append(_variant_t((IDispatch*)ptrIsReminder, true), XTPADOX::adInteger, 0);
  659. // ReminderMinutesBeforeStart
  660. XTPADOX::_ColumnPtr ptrReminderMin(__uuidof(XTPADOX::Column));
  661. ptrReminderMin->Name = L"ReminderMinutesBeforeStart";
  662. ptrReminderMin->Type = XTPADOX::adInteger;
  663. ptrReminderMin->ParentCatalog = ptrCatalog;
  664. ptrReminderMin->Properties->GetItem(L"Nullable")->PutValue(_variant_t(true));
  665. ptrReminderMin->Properties->GetItem(L"Default")->PutValue(_variant_t((long)0, VT_I4));
  666. ptrTable->Columns->Append(_variant_t((IDispatch*)ptrReminderMin, true), XTPADOX::adInteger, 0);
  667. // CustomProperties
  668. XTPADOX::_ColumnPtr ptrXMLData(__uuidof(XTPADOX::Column));
  669. ptrXMLData->Name = L"CustomPropertiesXMLData";
  670. ptrXMLData->Type = XTPADOX::adLongVarWChar;
  671. ptrXMLData->ParentCatalog = ptrCatalog;
  672. ptrTable->Columns->Append(_variant_t((IDispatch*)ptrXMLData, true), XTPADOX::adLongVarWChar, 0);
  673. // --------- Keys ---------
  674. // Table key
  675. ptrTable->Keys->Append(L"PK", XTPADOX::adKeyPrimary, L"EventID", L"", L"");
  676. ptrCatalog->Tables->Append(_variant_t((IDispatch *)ptrTable));
  677. ptrTable = NULL;
  678. }
  679. void CXTPCalendarDatabaseDataProvider::CreateRPatternTable(XTPADOX::_CatalogPtr ptrCatalog)
  680. {
  681. XTPADOX::_TablePtr ptrTable;
  682. // Event table
  683. ptrTable.CreateInstance(__uuidof (XTPADOX::Table));
  684. ptrTable->Name = L"RecurrencePattern";
  685. // -------- Columns -------
  686. // RecurrencePatternID
  687. XTPADOX::_ColumnPtr ptrRPID(__uuidof(XTPADOX::Column));
  688. ptrRPID->Name = L"RecurrencePatternID";
  689. ptrRPID->Type = XTPADOX::adInteger;
  690. ptrRPID->ParentCatalog = ptrCatalog;
  691. ptrRPID->Properties->GetItem(L"AutoIncrement")->PutValue(_variant_t(true));
  692. ptrTable->Columns->Append(_variant_t((IDispatch*)ptrRPID, true), XTPADOX::adInteger, 0);
  693. // PatternStartDateTime
  694. XTPADOX::_ColumnPtr ptrPatternStartDateTime(__uuidof(XTPADOX::Column));
  695. ptrPatternStartDateTime->Name = L"PatternStartDateTime";
  696. ptrPatternStartDateTime->Type = XTPADOX::adDate;
  697. ptrPatternStartDateTime->ParentCatalog = ptrCatalog;
  698. ptrPatternStartDateTime->Properties->GetItem(L"Nullable")->PutValue(_variant_t(true));
  699. ptrTable->Columns->Append(_variant_t((IDispatch*)ptrPatternStartDateTime, true),    XTPADOX::adDate,   0);
  700. // PatternEndDateTime
  701. XTPADOX::_ColumnPtr ptrEndDateTime(__uuidof(XTPADOX::Column));
  702. ptrEndDateTime->Name = L"PatternEndDateTime";
  703. ptrEndDateTime->Type = XTPADOX::adDate;
  704. ptrEndDateTime->ParentCatalog = ptrCatalog;
  705. ptrEndDateTime->Properties->GetItem(L"Nullable")->PutValue(_variant_t(true));
  706. ptrTable->Columns->Append(_variant_t((IDispatch*)ptrEndDateTime, true), XTPADOX::adDate,   0);
  707. // StartDateTime
  708. XTPADOX::_ColumnPtr ptrStartDateTime(__uuidof(XTPADOX::Column));
  709. ptrStartDateTime->Name = L"StartDateTime";
  710. ptrStartDateTime->Type = XTPADOX::adDate;
  711. ptrStartDateTime->ParentCatalog = ptrCatalog;
  712. ptrStartDateTime->Properties->GetItem(L"Nullable")->PutValue(_variant_t(true));
  713. ptrTable->Columns->Append(_variant_t((IDispatch*)ptrStartDateTime, true),   XTPADOX::adDate,   0);
  714. // Duration
  715. XTPADOX::_ColumnPtr ptrDuration(__uuidof(XTPADOX::Column));
  716. ptrDuration->Name = L"Duration";
  717. ptrDuration->Type = XTPADOX::adInteger;
  718. ptrDuration->ParentCatalog = ptrCatalog;
  719. ptrDuration->Properties->GetItem(L"Nullable")->PutValue(_variant_t(true));
  720. ptrDuration->Properties->GetItem(L"Default")->PutValue(_variant_t((long)0, VT_I4));
  721. ptrTable->Columns->Append(_variant_t((IDispatch*)ptrDuration, true), XTPADOX::adInteger, 0);
  722. // EndAfterOccurrence
  723. XTPADOX::_ColumnPtr ptrEndAfterOccurrence(__uuidof(XTPADOX::Column));
  724. ptrEndAfterOccurrence->Name = L"EndAfterOccurrence";
  725. ptrEndAfterOccurrence->Type = XTPADOX::adInteger;
  726. ptrEndAfterOccurrence->ParentCatalog = ptrCatalog;
  727. ptrEndAfterOccurrence->Properties->GetItem(L"Nullable")->PutValue(_variant_t(true));
  728. ptrEndAfterOccurrence->Properties->GetItem(L"Default")->PutValue(_variant_t((long)0, VT_I4));
  729. ptrTable->Columns->Append(_variant_t((IDispatch*)ptrEndAfterOccurrence, true), XTPADOX::adInteger, 0);
  730. // UseEnd
  731. XTPADOX::_ColumnPtr ptrUseEnd(__uuidof(XTPADOX::Column));
  732. ptrUseEnd->Name = L"UseEnd";
  733. ptrUseEnd->Type = XTPADOX::adInteger;
  734. ptrUseEnd->ParentCatalog = ptrCatalog;
  735. ptrUseEnd->Properties->GetItem(L"Nullable")->PutValue(_variant_t(true));
  736. ptrUseEnd->Properties->GetItem(L"Default")->PutValue(_variant_t((long)0, VT_I4));
  737. ptrTable->Columns->Append(_variant_t((IDispatch*)ptrUseEnd, true), XTPADOX::adInteger, 0);
  738. // RecurrenceTypeID
  739. XTPADOX::_ColumnPtr ptrRecurrenceTypeID(__uuidof(XTPADOX::Column));
  740. ptrRecurrenceTypeID->Name = L"RecurrenceTypeID";
  741. ptrRecurrenceTypeID->Type = XTPADOX::adInteger;
  742. ptrRecurrenceTypeID->ParentCatalog = ptrCatalog;
  743. ptrRecurrenceTypeID->Properties->GetItem(L"Nullable")->PutValue(_variant_t(true));
  744. ptrRecurrenceTypeID->Properties->GetItem(L"Default")->PutValue(_variant_t((long)0, VT_I4));
  745. ptrRecurrenceTypeID->Properties->GetItem(L"Description")->PutValue(_variant_t(L"XTPCalendarEventRecurrenceType"));
  746. ptrTable->Columns->Append(_variant_t((IDispatch*)ptrRecurrenceTypeID, true), XTPADOX::adInteger, 0);
  747. // OccurrenceInterval
  748. XTPADOX::_ColumnPtr ptrOccurrenceInterval(__uuidof(XTPADOX::Column));
  749. ptrOccurrenceInterval->Name = L"OccurrenceInterval";
  750. ptrOccurrenceInterval->Type = XTPADOX::adInteger;
  751. ptrOccurrenceInterval->ParentCatalog = ptrCatalog;
  752. ptrOccurrenceInterval->Properties->GetItem(L"Nullable")->PutValue(_variant_t(true));
  753. ptrOccurrenceInterval->Properties->GetItem(L"Default")->PutValue(_variant_t((long)0, VT_I4));
  754. ptrOccurrenceInterval->Properties->GetItem(L"Description")->PutValue(_variant_t(L"occurs evere Nth (day, week, month)"));
  755. ptrTable->Columns->Append(_variant_t((IDispatch*)ptrOccurrenceInterval, true), XTPADOX::adInteger, 0);
  756. // DayOfWeekMask
  757. XTPADOX::_ColumnPtr ptrDayOfWeekMask(__uuidof(XTPADOX::Column));
  758. ptrDayOfWeekMask->Name = L"DayOfWeekMask";
  759. ptrDayOfWeekMask->Type = XTPADOX::adInteger;
  760. ptrDayOfWeekMask->ParentCatalog = ptrCatalog;
  761. ptrDayOfWeekMask->Properties->GetItem(L"Nullable")->PutValue(_variant_t(true));
  762. ptrDayOfWeekMask->Properties->GetItem(L"Default")->PutValue(_variant_t((long)0, VT_I4));
  763. ptrDayOfWeekMask->Properties->GetItem(L"Description")->PutValue(_variant_t(L"stores weeks day (for  weeks, month) in packed form"));
  764. ptrTable->Columns->Append(_variant_t((IDispatch*)ptrDayOfWeekMask, true), XTPADOX::adInteger, 0);
  765. // DayOfMonth
  766. XTPADOX::_ColumnPtr ptrDayOfMonth(__uuidof(XTPADOX::Column));
  767. ptrDayOfMonth->Name = L"DayOfMonth";
  768. ptrDayOfMonth->Type = XTPADOX::adInteger;
  769. ptrDayOfMonth->ParentCatalog = ptrCatalog;
  770. ptrDayOfMonth->Properties->GetItem(L"Nullable")->PutValue(_variant_t(true));
  771. ptrDayOfMonth->Properties->GetItem(L"Default")->PutValue(_variant_t((long)0, VT_I4));
  772. ptrDayOfMonth->Properties->GetItem(L"Description")->PutValue(_variant_t(L"day of month number (for monthly, yearly)"));
  773. ptrTable->Columns->Append(_variant_t((IDispatch*)ptrDayOfMonth, true), XTPADOX::adInteger, 0);
  774. // MonthOfYear
  775. XTPADOX::_ColumnPtr ptrMonthOfYear(__uuidof(XTPADOX::Column));
  776. ptrMonthOfYear->Name = L"MonthOfYear";
  777. ptrMonthOfYear->Type = XTPADOX::adInteger;
  778. ptrMonthOfYear->ParentCatalog = ptrCatalog;
  779. ptrMonthOfYear->Properties->GetItem(L"Nullable")->PutValue(_variant_t(true));
  780. ptrMonthOfYear->Properties->GetItem(L"Default")->PutValue(_variant_t((long)0, VT_I4));
  781. ptrMonthOfYear->Properties->GetItem(L"Description")->PutValue(_variant_t(L"for yearly: (month number mapped to month name)"));
  782. ptrTable->Columns->Append(_variant_t((IDispatch*)ptrMonthOfYear, true), XTPADOX::adInteger, 0);
  783. // IsEveryWeekDay
  784. XTPADOX::_ColumnPtr ptrIsEveryWeekDay(__uuidof(XTPADOX::Column));
  785. ptrIsEveryWeekDay->Name = L"IsEveryWeekDay";
  786. ptrIsEveryWeekDay->Type = XTPADOX::adInteger;
  787. ptrIsEveryWeekDay->ParentCatalog = ptrCatalog;
  788. ptrIsEveryWeekDay->Properties->GetItem(L"Nullable")->PutValue(_variant_t(true));
  789. ptrIsEveryWeekDay->Properties->GetItem(L"Default")->PutValue(_variant_t((long)0, VT_I4));
  790. ptrIsEveryWeekDay->Properties->GetItem(L"Description")->PutValue(_variant_t(L"For daily: is occured each weekday"));
  791. ptrTable->Columns->Append(_variant_t((IDispatch*)ptrIsEveryWeekDay, true), XTPADOX::adInteger, 0);
  792. // DayOccurrenceTypeID
  793. XTPADOX::_ColumnPtr ptrDayOccurrenceTypeID(__uuidof(XTPADOX::Column));
  794. ptrDayOccurrenceTypeID->Name = L"DayOccurrenceTypeID";
  795. ptrDayOccurrenceTypeID->Type = XTPADOX::adInteger;
  796. ptrDayOccurrenceTypeID->ParentCatalog = ptrCatalog;
  797. ptrDayOccurrenceTypeID->Properties->GetItem(L"Nullable")->PutValue(_variant_t(true));
  798. ptrDayOccurrenceTypeID->Properties->GetItem(L"Default")->PutValue(_variant_t((long)0, VT_I4));
  799. ptrDayOccurrenceTypeID->Properties->GetItem(L"Description")->PutValue(_variant_t(L"Day occurrence:  first, second, third, fourth or last occurrence of day  ( WhichDay)"));
  800. ptrTable->Columns->Append(_variant_t((IDispatch*)ptrDayOccurrenceTypeID, true), XTPADOX::adInteger, 0);
  801. // DayMask
  802. XTPADOX::_ColumnPtr ptrDayMask(__uuidof(XTPADOX::Column));
  803. ptrDayMask->Name = L"DayMask";
  804. ptrDayMask->Type = XTPADOX::adInteger;
  805. ptrDayMask->ParentCatalog = ptrCatalog;
  806. ptrDayMask->Properties->GetItem(L"Nullable")->PutValue(_variant_t(true));
  807. ptrDayMask->Properties->GetItem(L"Default")->PutValue(_variant_t((long)0, VT_I4));
  808. ptrTable->Columns->Append(_variant_t((IDispatch*)ptrDayMask, true), XTPADOX::adInteger, 0);
  809. // MasterEventID
  810. XTPADOX::_ColumnPtr ptrMasterEventID(__uuidof(XTPADOX::Column));
  811. ptrMasterEventID->Name = L"MasterEventID";
  812. ptrMasterEventID->Type = XTPADOX::adInteger;
  813. ptrMasterEventID->ParentCatalog = ptrCatalog;
  814. ptrMasterEventID->Properties->GetItem(L"Nullable")->PutValue(_variant_t(true));
  815. ptrMasterEventID->Properties->GetItem(L"Default")->PutValue(_variant_t((long)0, VT_I4));
  816. ptrMasterEventID->Properties->GetItem(L"Description")->PutValue(_variant_t(L"EventID of master event"));
  817. ptrTable->Columns->Append(_variant_t((IDispatch*)ptrMasterEventID, true), XTPADOX::adInteger, 0);
  818. // CustomProperties
  819. XTPADOX::_ColumnPtr ptrXMLData(__uuidof(XTPADOX::Column));
  820. ptrXMLData->Name = L"CustomPropertiesXMLData";
  821. ptrXMLData->Type = XTPADOX::adLongVarWChar;
  822. ptrXMLData->ParentCatalog = ptrCatalog;
  823. ptrTable->Columns->Append(_variant_t((IDispatch*)ptrXMLData, true), XTPADOX::adLongVarWChar, 0);
  824. // --------- Keys ---------
  825. // Table primary key
  826. ptrTable->Keys->Append(L"PK", XTPADOX::adKeyPrimary, L"RecurrencePatternID", L"", L"");
  827. // Event key
  828. {
  829. //      XTPADOX::_KeyPtr ptrKey(__uuidof(XTPADOX::Key));
  830. //      ptrKey->PutName(_T("RTForeign"));
  831. //      ptrKey->PutType(XTPADOX::adKeyForeign);
  832. //      ptrKey->PutRelatedTable(_T("Event"));
  833. //      XTPADOX::ColumnsPtr cols = ptrKey->GetColumns();
  834. //      cols->Append(_T("RecurrencePatternID"), XTPADOX::adInteger, 0);
  835. //      cols->GetItem(L"RecurrencePatternID"))->PutRelatedColumn(_T("RecurrencePatternID"));
  836. // reference index
  837. //      XTPADOX::_IndexPtr ptrIndex(__uuidof(XTPADOX::Index));
  838. //      ptrIndex->PutName(_T("ref_RecurrencePatternID"));
  839. //      ptrIndex->PutUnique(_variant_t(false));
  840. //      ptrIndex->Columns->Append(_T("RecurrencePatternID"), XTPADOX::adInteger, 0);
  841. //      ptrCatalog->GetTables()->GetItem(L"Event"))->Indexes->Append(_variant_t((IDispatch *)ptrIndex));
  842. //
  843. //      ptrTable->Keys->Append(_T("FK1"), XTPADOX::adKeyForeign, _T("RecurrencePatternID"), _T("Event"), _T("RecurrencePatternID"));
  844. }
  845. ptrCatalog->Tables->Append(_variant_t((IDispatch *)ptrTable));
  846. ptrTable = NULL;
  847. }
  848. //void CXTPCalendarDatabaseDataProvider::CreateDicTable(XTPADOX::_CatalogPtr ptrCatalog,
  849. //      LPCWSTR strTable, LPCWSTR strNameID, bool bAuto)
  850. //{
  851. //  XTPADOX::_TablePtr ptrTable;
  852. //
  853. //  // Event table
  854. //  ptrTable.CreateInstance(__uuidof (XTPADOX::Table));
  855. //  ptrTable->Name = strTable;
  856. //
  857. //  // -------- Columns -------
  858. //  // ID
  859. //  XTPADOX::_ColumnPtr ptrID(__uuidof(XTPADOX::Column));
  860. //  ptrID->Name = strNameID;
  861. //  ptrID->Type = XTPADOX::adInteger;
  862. //  ptrID->ParentCatalog = ptrCatalog;
  863. //  if (bAuto)
  864. //  {
  865. //      ptrID->Properties->GetItem(L"AutoIncrement")->PutValue(_variant_t(true));
  866. //  }
  867. //  ptrTable->Columns->Append(_variant_t((IDispatch*)ptrID, true), XTPADOX::adInteger, 0);
  868. //
  869. //  // Body
  870. //  XTPADOX::_ColumnPtr ptrBody(__uuidof(XTPADOX::Column));
  871. //  ptrBody->Name = L"Desc";
  872. //  ptrBody->Type = XTPADOX::adWChar;
  873. //  ptrBody->ParentCatalog = ptrCatalog;
  874. //  ptrBody->Properties->GetItem(L"Nullable")->PutValue(_variant_t(true));
  875. //
  876. //  ptrTable->Columns->Append(_variant_t((IDispatch*)ptrBody, true), XTPADOX::adWChar, 255);
  877. //
  878. //  // --------- Keys ---------
  879. //  // Table key
  880. //  ptrTable->Keys->Append(L"PK", XTPADOX::adKeyPrimary, strNameID, L"", L"");
  881. //
  882. //  ptrCatalog->Tables->Append(_variant_t((IDispatch *)ptrTable));
  883. //  ptrTable = NULL;
  884. //}
  885. BOOL CXTPCalendarDatabaseDataProvider::Create()
  886. {
  887. try
  888. {
  889. XTPADOX::_CatalogPtr ptrCatalog;
  890. // Create database file
  891. if (FAILED(ptrCatalog.CreateInstance(__uuidof(XTPADOX::Catalog))))
  892. return FALSE;
  893. ptrCatalog->Create(_bstr_t(XTP_CT2CW(m_strConnectionString)));
  894. // Create main tables
  895. CreateEventTable(ptrCatalog);
  896. CreateRPatternTable(ptrCatalog);
  897. // Create Schedules table
  898. CreateSchedulesTable(ptrCatalog);
  899. // Create options table
  900. CreateOptionsTable(ptrCatalog);
  901. ptrCatalog = NULL;
  902. }
  903. catch (_com_error &e)
  904. {
  905. e;
  906. #ifdef _DEBUG
  907. TRACE(_T("ERROR: CXTPCalendarDatabaseDataProvider::Create: "));
  908. LPCWSTR err(e.Description());
  909. if (err) TRACE(_T("%ls"), err);
  910. #endif
  911. return FALSE;
  912. }
  913. return Open();
  914. }
  915. BOOL CXTPCalendarDatabaseDataProvider::UpdateDBStructure(XTPADODB::_Connection* pconnDb)
  916. {
  917. try
  918. {
  919. XTPADOX::_CatalogPtr ptrCatalog;
  920. if (FAILED(ptrCatalog.CreateInstance(__uuidof(XTPADOX::Catalog))))
  921. return FALSE;
  922. ptrCatalog->PutRefActiveConnection((IDispatch*)pconnDb);
  923. if (!IsTableExist(ptrCatalog, L"Event"))
  924. CreateEventTable(ptrCatalog);
  925. if (!IsTableExist(ptrCatalog, L"RecurrencePattern"))
  926. CreateRPatternTable(ptrCatalog);
  927. if (!IsTableExist(ptrCatalog, L"Options"))
  928. CreateOptionsTable(ptrCatalog);
  929. if (!IsTableExist(ptrCatalog, L"Schedules"))
  930. CreateSchedulesTable(ptrCatalog);
  931. return TRUE;
  932. }
  933. catch (_com_error &e)
  934. {
  935. e;
  936. #ifdef _DEBUG
  937. TRACE(_T("ERROR: CXTPCalendarDatabaseDataProvider::UpdateDB: "));
  938. LPCWSTR err(e.Description());
  939. if (err) TRACE(_T("%ls"), err);
  940. #endif
  941. }
  942. return FALSE;
  943. }
  944. BOOL CXTPCalendarDatabaseDataProvider::Save()
  945. {
  946. VERIFY( CXTPCalendarData::Save() );
  947. UpdateSchedules();
  948. // Save calendar's options
  949. #ifndef _XTP_EXCLUDE_XML
  950. CXTPPropExchangeXMLNode px(FALSE, 0, _T("Calendar"));
  951. px.ExchangeLocale();
  952. CXTPPropExchangeSection secOptions(px.GetSection(_T("Options")));
  953. secOptions->EmptySection();
  954. // TODO:
  955. if (m_pCalendarOptions)
  956. {
  957. m_pCalendarOptions->DoPropExchange(&secOptions);
  958. }
  959. CString strXML(px.GetXML());
  960. return SaveOptions(strXML);
  961. #else
  962. return TRUE;
  963. #endif
  964. }
  965. BOOL CXTPCalendarDatabaseDataProvider::LoadOptions()
  966. {
  967. // Load calendar's options
  968. if (!m_pCalendarOptions)
  969. {
  970. return FALSE;
  971. }
  972. #ifndef _XTP_EXCLUDE_XML
  973. // Load data from the database
  974. XTPADODB::_RecordsetPtr ptrDataRS = m_pcmdGetOptions->Execute();
  975. if (ptrDataRS == NULL || ptrDataRS->bEOF)
  976. return FALSE;
  977. CString strXMLData = _GetFieldString(ptrDataRS, L"XMLData");
  978. ptrDataRS->Close();
  979. // Populate XML node with data
  980. CXTPPropExchangeXMLNode px(TRUE, 0, _T("Calendar"));
  981. if (!px.LoadFromString(strXMLData))
  982. return FALSE;
  983. // Apply data to the calendar
  984. px.ExchangeLocale();
  985. CXTPPropExchangeSection secOptions(px.GetSection(_T("Options")));
  986. m_pCalendarOptions->DoPropExchange(&secOptions);
  987. return TRUE;
  988. #else
  989. return FALSE;
  990. #endif
  991. }
  992. CXTPCalendarSchedulesPtr CXTPCalendarDatabaseDataProvider::LoadSchedules()
  993. {
  994. if (!IsOpen())
  995. {
  996. return NULL;
  997. }
  998. CXTPCalendarSchedulesPtr ptrSchedules = new CXTPCalendarSchedules();
  999. if (!ptrSchedules)
  1000. return NULL;
  1001. CADOCommand cmdGetSchedules(m_pconnDb.GetInterfacePtr(),
  1002. L"SELECT * FROM Schedules");
  1003. try
  1004. {
  1005. XTPADODB::_RecordsetPtr ptrDataRS = cmdGetSchedules.Execute();
  1006. if (ptrDataRS == NULL)
  1007. {
  1008. ASSERT(FALSE);
  1009. return NULL;
  1010. }
  1011. // process recordset
  1012. while (!ptrDataRS->bEOF)
  1013. {
  1014. CXTPCalendarSchedule* pNewSch = _ReadSchedule(ptrDataRS);
  1015. if (pNewSch)
  1016. ptrSchedules->Add(pNewSch, FALSE);
  1017. // next record
  1018. ptrDataRS->MoveNext();
  1019. }
  1020. ptrDataRS->Close();
  1021. return ptrSchedules;
  1022. }
  1023. catch (_com_error &e)
  1024. {
  1025. TRACE_ProviderError(m_pconnDb);
  1026. TRACE_ComError(e);
  1027. }
  1028. catch(...)
  1029. {}
  1030. TRACE(_T("ERROR: Exeption in CXTPCalendarDatabaseDataProvider::LoadSchedules() n"));
  1031. return NULL;
  1032. }
  1033. CXTPCalendarSchedule* CXTPCalendarDatabaseDataProvider::_ReadSchedule(XTPADODB::_Recordset* pRS)
  1034. {
  1035. ASSERT(pRS);
  1036. if (!pRS)
  1037. return NULL;
  1038. try
  1039. {   ULONG ulID = (ULONG)(long)pRS->Fields->GetItem(L"ScheduleID")->Value;
  1040. CString strName = _GetFieldString(pRS, L"Name");
  1041. CString strPropsXMLData = _GetFieldString(pRS, L"CustomPropertiesXMLData");
  1042. CXTPCalendarSchedule* pNewSch = new CXTPCalendarSchedule(ulID, strName);
  1043. if (pNewSch && pNewSch->GetCustomProperties())
  1044. pNewSch->GetCustomProperties()->LoadFromXML(strPropsXMLData);
  1045. return pNewSch;
  1046. }
  1047. catch (_com_error &e)
  1048. {
  1049. TRACE_ProviderError(m_pconnDb);
  1050. TRACE_ComError(e);
  1051. }
  1052. catch(...)
  1053. {
  1054. ASSERT(FALSE);
  1055. }
  1056. return NULL;
  1057. }
  1058. void CXTPCalendarDatabaseDataProvider::UpdateSchedules()
  1059. {
  1060. if (!m_pSchedules)
  1061. return;
  1062. CXTPCalendarSchedulesPtr ptrSchedulesOrig = LoadSchedules();
  1063. if (!ptrSchedulesOrig || ptrSchedulesOrig->GetCount() == 0)
  1064. {
  1065. _AddSchedules(m_pSchedules);
  1066. return;
  1067. }
  1068. CXTPCalendarSchedules arAdd;
  1069. CXTPCalendarSchedules arUpdate;
  1070. CUIntArray arDelete;
  1071. int i;
  1072. int nCount = m_pSchedules->GetCount();
  1073. for (i = 0; i < nCount; i++)
  1074. {
  1075. CXTPCalendarSchedule* pSch = m_pSchedules->GetAt(i, FALSE);
  1076. int nIdx = ptrSchedulesOrig->FindIndex(pSch->GetID());
  1077. if (nIdx >= 0)
  1078. arUpdate.Add(pSch, TRUE);
  1079. else
  1080. arAdd.Add(pSch, TRUE);
  1081. }
  1082. int nCount_orig = ptrSchedulesOrig->GetCount();
  1083. for (i = 0; i < nCount_orig; i++)
  1084. {
  1085. CXTPCalendarSchedule* pSch = ptrSchedulesOrig->GetAt(i, FALSE);
  1086. int nIdx = m_pSchedules->FindIndex(pSch->GetID());
  1087. if (nIdx < 0)
  1088. arDelete.Add(pSch->GetID());
  1089. }
  1090. _AddSchedules(&arAdd);
  1091. _UpdateSchedules(&arUpdate, ptrSchedulesOrig);
  1092. _DeleteSchedules(&arDelete);
  1093. }
  1094. void CXTPCalendarDatabaseDataProvider::_AddSchedules(CXTPCalendarSchedules* pAddSet)
  1095. {
  1096. if (!IsOpen())
  1097. {
  1098. return;
  1099. }
  1100. if (!pAddSet || !m_pcmdAddSchedule)
  1101. {
  1102. return;
  1103. }
  1104. _variant_t vtdtNow = DATE2VAR(COleDateTime::GetCurrentTime());
  1105. int nCount = pAddSet->GetCount();
  1106. for (int i = 0; i < nCount; i++)
  1107. {
  1108. CXTPCalendarSchedule* pSch = pAddSet->GetAt(i, FALSE);
  1109. ASSERT(pSch);
  1110. if (!pSch)
  1111. continue;
  1112. try
  1113. {
  1114. CString strName = pSch->GetName();
  1115. CString strData;
  1116. if (pSch->GetCustomProperties())
  1117. pSch->GetCustomProperties()->SaveToXML(strData);
  1118. m_pcmdAddSchedule->SetParameterValue(L"prm_Name", STRING2VAR(strName));
  1119. m_pcmdAddSchedule->SetParameterValue(L"prm_Modified", vtdtNow);
  1120. m_pcmdAddSchedule->SetParameterValue(L"prm_CustomPropertiesXMLData", STRING2VAR(strData));
  1121. m_pcmdAddSchedule->Execute();
  1122. // get ID
  1123. CADOCommand cmdGetLastID(m_pconnDb.GetInterfacePtr(), L"SELECT MAX(ScheduleID) AS NewScheduleID FROM Schedules");
  1124. XTPADODB::_RecordsetPtr ptrRS_NewID = cmdGetLastID.Execute();
  1125. ASSERT(ptrRS_NewID != NULL);
  1126. if (ptrRS_NewID)
  1127. {
  1128. ASSERT(!ptrRS_NewID->bEOF);
  1129. if (!ptrRS_NewID->bEOF)
  1130. {
  1131. UINT uNewSchID = (DWORD)(long)ptrRS_NewID->Fields->GetItem(L"NewScheduleID")->Value;
  1132. pSch->SetID(uNewSchID);
  1133. }
  1134. ptrRS_NewID->Close();
  1135. }
  1136. }
  1137. catch (_com_error &e)
  1138. {
  1139. TRACE(_T("ERROR: Exeption in CXTPCalendarDatabaseDataProvider::_AddSchedules()"));
  1140. TRACE_ProviderError(m_pconnDb);
  1141. TRACE_ComError(e);
  1142. }
  1143. catch(...)
  1144. {
  1145. TRACE(_T("ERROR: Exeption in CXTPCalendarDatabaseDataProvider::_AddSchedules()"));
  1146. }
  1147. }
  1148. }
  1149. void CXTPCalendarDatabaseDataProvider::_UpdateSchedules(CXTPCalendarSchedules* pUpdateSet, CXTPCalendarSchedules* pOrigSet)
  1150. {
  1151. if (!IsOpen())
  1152. {
  1153. return;
  1154. }
  1155. if (!pUpdateSet || !m_pcmdUpdSchedule)
  1156. {
  1157. return;
  1158. }
  1159. _variant_t vtdtNow = DATE2VAR(COleDateTime::GetCurrentTime());
  1160. int nCount = pUpdateSet->GetCount();
  1161. for (int i = 0; i < nCount; i++)
  1162. {
  1163. CXTPCalendarSchedule* pSch = pUpdateSet->GetAt(i, FALSE);
  1164. ASSERT(pSch);
  1165. if (!pSch)
  1166. continue;
  1167. long nID = pSch->GetID();
  1168. CString strName = pSch->GetName();
  1169. CString strData;
  1170. XTP_SAFE_CALL2(pSch, GetCustomProperties(), SaveToXML(strData));
  1171. // check is changed
  1172. if (pOrigSet)
  1173. {
  1174. int nIdx = pOrigSet->FindIndex(nID);
  1175. ASSERT(nIdx >= 0);
  1176. CXTPCalendarSchedule* pSch_orig = pOrigSet->GetAt(nIdx, FALSE);
  1177. ASSERT(pSch_orig);
  1178. if (pSch_orig)
  1179. {
  1180. CString strData_orig;
  1181. XTP_SAFE_CALL2(pSch_orig, GetCustomProperties(), SaveToXML(strData_orig));
  1182. if (strName == pSch_orig->GetName() &&
  1183. strData_orig == strData)
  1184. {
  1185. continue; // skip update if no changes
  1186. }
  1187. }
  1188. }
  1189. try
  1190. {
  1191. m_pcmdUpdSchedule->SetParameterValue(L"prm_ScheduleID", nID);
  1192. m_pcmdUpdSchedule->SetParameterValue(L"prm_Name", STRING2VAR(strName));
  1193. m_pcmdUpdSchedule->SetParameterValue(L"prm_Modified", vtdtNow);
  1194. m_pcmdUpdSchedule->SetParameterValue(L"prm_CustomPropertiesXMLData", STRING2VAR(strData));
  1195. m_pcmdUpdSchedule->Execute();
  1196. }
  1197. catch (_com_error &e)
  1198. {
  1199. TRACE(_T("ERROR: Exeption in CXTPCalendarDatabaseDataProvider::_UpdateSchedules()"));
  1200. TRACE_ProviderError(m_pconnDb);
  1201. TRACE_ComError(e);
  1202. }
  1203. catch(...)
  1204. {
  1205. TRACE(_T("ERROR: Exeption in CXTPCalendarDatabaseDataProvider::_UpdateSchedules()"));
  1206. }
  1207. }
  1208. }
  1209. void CXTPCalendarDatabaseDataProvider::_DeleteSchedules(CUIntArray* pDeleteIDs)
  1210. {
  1211. if (!IsOpen() || !pDeleteIDs || pDeleteIDs->GetSize() == 0)
  1212. {
  1213. return;
  1214. }
  1215. TCHAR szBuff[64];
  1216. CString strIDs;
  1217. int nCount = (int)pDeleteIDs->GetSize();
  1218. for (int i = 0; i < nCount; i++)
  1219. {
  1220. int nID = (int)pDeleteIDs->GetAt(i);
  1221. if (i)
  1222. strIDs += _T(",");
  1223. ITOT_S(nID, szBuff, 64, 10);
  1224. strIDs += szBuff;
  1225. }
  1226. CString strSqlText = _T("DELETE FROM Schedules WHERE ScheduleID IN ( ");
  1227. strSqlText += strIDs;
  1228. strSqlText += _T(" )");
  1229. try
  1230. {
  1231. CADOCommand cmdDeleteSchedules(m_pconnDb.GetInterfacePtr(), XTP_CT2CW(strSqlText));
  1232. cmdDeleteSchedules.Execute();
  1233. return;
  1234. }
  1235. catch (_com_error &e)
  1236. {
  1237. TRACE_ProviderError(m_pconnDb);
  1238. TRACE_ComError(e);
  1239. }
  1240. catch(...)
  1241. {
  1242. }
  1243. TRACE(_T("ERROR: Exeption in CXTPCalendarDatabaseDataProvider::_DeleteSchedules()"));
  1244. }
  1245. void CXTPCalendarDatabaseDataProvider::Close()
  1246. {
  1247. if (!IsOpen())
  1248. return;
  1249. CXTPCalendarData::Close();
  1250. try
  1251. {
  1252. DeleteAllDBCommands();
  1253. if (m_bCloseDbConnection)
  1254. {
  1255. HRESULT hr = m_pconnDb->Close();
  1256. ASSERT(SUCCEEDED(hr));
  1257. if (FAILED(hr))
  1258. {
  1259. TRACE(_T("ERROR: Cannot close XTPADODB::Connection. (HRESULT = %08lx). CXTPCalendarDatabaseDataProvider::Close() n"), hr);
  1260. }
  1261. }
  1262. return;
  1263. }
  1264. catch (_com_error &e)
  1265. {
  1266. TRACE_ProviderError(m_pconnDb);
  1267. TRACE_ComError(e);
  1268. }
  1269. catch(...)
  1270. {
  1271. }
  1272. TRACE(_T("ERROR: Exeption in CXTPCalendarDatabaseDataProvider::Close"));
  1273. }
  1274. CXTPCalendarEventPtr CXTPCalendarDatabaseDataProvider::_ReadEvent_common(XTPADODB::_Recordset* pRS,
  1275.  BOOL bEcxception)
  1276. {
  1277. if (!IsOpen())
  1278. {
  1279. return NULL;
  1280. }
  1281. try
  1282. {
  1283. DWORD dwEventID = (DWORD)(long)pRS->Fields->GetItem(L"EventID")->Value;
  1284. CXTPCalendarEventPtr ptrEvent = CreateNewEvent(dwEventID);
  1285. ptrEvent->SetEndTime((DATE)pRS->Fields->GetItem(L"EndDateTime")->Value);
  1286. ptrEvent->SetStartTime((DATE)pRS->Fields->GetItem(L"StartDateTime")->Value);
  1287. ptrEvent->SetAllDayEvent(_GetField<long>(pRS, L"IsAllDayEvent", 0) != 0);
  1288. ptrEvent->SetSubject(_GetFieldString(pRS, L"Subject"));
  1289. ptrEvent->SetLocation(_GetFieldString(pRS, L"Location"));
  1290. ptrEvent->SetBody(_GetFieldString(pRS, L"Body"));
  1291. ptrEvent->SetReminderSoundFile(_GetFieldString(pRS, L"RemainderSoundFile"));
  1292. ptrEvent->SetBusyStatus(_GetField<long>(pRS, L"BusyStatus", 0));
  1293. ptrEvent->SetImportance(_GetField<long>(pRS, L"ImportanceLevel", 0));
  1294. ptrEvent->SetLabelID(_GetField<long>(pRS, L"LabelID", 0));
  1295. ptrEvent->SetScheduleID(_GetField<long>(pRS, L"ScheduleID", 0));
  1296. ptrEvent->SetCreationTime(_GetField<DATE>(pRS, L"Created", 0));
  1297. ptrEvent->SetLastModificationTime(_GetField<DATE>(pRS, L"Modified", 0));
  1298. ptrEvent->SetMeeting(_GetField<long>(pRS, L"IsMeeting", 0) != 0);
  1299. ptrEvent->SetPrivate(_GetField<long>(pRS, L"IsPrivate", 0) != 0);
  1300. ptrEvent->SetReminder(_GetField<long>(pRS, L"IsReminder", 0) != 0);
  1301. ptrEvent->SetReminderMinutesBeforeStart(_GetField<long>(pRS, L"ReminderMinutesBeforeStart", 0));
  1302. if (ptrEvent->GetCustomProperties())
  1303. {
  1304. CString bstrPropsXMLData = _GetFieldString(pRS, L"CustomPropertiesXMLData");
  1305. ptrEvent->GetCustomProperties()->LoadFromXML(bstrPropsXMLData);
  1306. COleVariant ovarIDs;
  1307. // update CustomIcons
  1308. if (ptrEvent->GetCustomProperties()->GetProperty(cszEventCustProp_IconsIDs, ovarIDs))
  1309. {
  1310. VERIFY(ptrEvent->GetCustomProperties()->RemoveProperty(cszEventCustProp_IconsIDs));
  1311. CString strArray = VariantToString(ovarIDs, NULL);
  1312. ptrEvent->GetCustomIcons()->LoadFromString(strArray);
  1313. }
  1314. // update Categories
  1315. if (ptrEvent->GetCustomProperties()->GetProperty(cszEventCustProp_CategoryIDs, ovarIDs))
  1316. {
  1317. VERIFY(ptrEvent->GetCustomProperties()->RemoveProperty(cszEventCustProp_CategoryIDs));
  1318. CString strArray = VariantToString(ovarIDs, NULL);
  1319. ptrEvent->GetCategories()->LoadFromString(strArray);
  1320. }
  1321. }
  1322. if (!bEcxception)
  1323. {
  1324. long nRState = _GetField<long>(pRS, L"RecurrenceState", xtpCalendarRecurrenceNotRecurring);
  1325. long nPatternID = _GetField<long>(pRS, L"RecurrencePatternID", XTP_CALENDAR_UNKNOWN_RECURRENCE_PATTERN_ID);
  1326. ptrEvent->GetCustomProperties()->SetProperty(cszProcess_RecurrenceState, COleVariant((long)nRState));
  1327. ptrEvent->GetCustomProperties()->SetProperty(cszProcess_RecurrencePatternID, COleVariant((long)nPatternID));
  1328. }
  1329. return ptrEvent;
  1330. }
  1331. catch (_com_error &e)
  1332. {
  1333. TRACE_ProviderError(m_pconnDb);
  1334. TRACE_ComError(e);
  1335. }
  1336. catch(...)
  1337. {}
  1338. TRACE(_T("ERROR: Exeption in CXTPCalendarDatabaseDataProvider::ReadEvent()"));
  1339. return NULL;
  1340. }
  1341. CXTPCalendarEventsPtr CXTPCalendarDatabaseDataProvider::DoRetrieveDayEvents(COleDateTime dtDay)
  1342. {
  1343. if (!IsOpen())
  1344. {
  1345. return NULL;
  1346. }
  1347. dtDay = CXTPCalendarUtils::ResetTime(dtDay);
  1348. CXTPCalendarEventsPtr ptrEvents = new CXTPCalendarEvents();
  1349. if (!ptrEvents)
  1350. {
  1351. return NULL;
  1352. }
  1353. CXTPCalendarEventPtr  ptrEvent;
  1354. if (!m_pcmdGetDayEvents)
  1355. {
  1356. ASSERT(FALSE);
  1357. return NULL;
  1358. }
  1359. m_pcmdGetDayEvents->SetParameterValue(L"prm_DayDate", DATE2VAR(dtDay));
  1360. try
  1361. {
  1362. XTPADODB::_RecordsetPtr ptrDataRS = m_pcmdGetDayEvents->Execute();
  1363. if (ptrDataRS == NULL)
  1364. {
  1365. ASSERT(FALSE);
  1366. return NULL;
  1367. }
  1368. // process recordset
  1369. while (!ptrDataRS->bEOF) //
  1370. {
  1371. ptrEvent = _ReadEvent_common(ptrDataRS, FALSE);
  1372. if (!ptrEvent)
  1373. {
  1374. ASSERT(FALSE);
  1375. ptrDataRS->MoveNext();
  1376. continue;
  1377. }
  1378. ptrEvents->Add(ptrEvent);
  1379. // next record
  1380. ptrDataRS->MoveNext();
  1381. }
  1382. ptrDataRS->Close();
  1383. return ptrEvents;
  1384. }
  1385. catch (_com_error &e)
  1386. {
  1387. TRACE_ProviderError(m_pconnDb);
  1388. TRACE_ComError(e);
  1389. }
  1390. catch(...)
  1391. {}
  1392. TRACE(_T("ERROR: Exeption in CXTPCalendarDatabaseDataProvider::RetrieveDayEvents(%s) n"), (LPCTSTR)dtDay.Format());
  1393. return NULL;
  1394. }
  1395. CXTPCalendarEventsPtr CXTPCalendarDatabaseDataProvider::DoGetAllEvents_raw()
  1396. {
  1397. if (!IsOpen())
  1398. {
  1399. return NULL;
  1400. }
  1401. CXTPCalendarEventsPtr ptrEvents = new CXTPCalendarEvents();
  1402. if (!ptrEvents)
  1403. {
  1404. return NULL;
  1405. }
  1406. CString strSqlText;
  1407. strSqlText.Format(_T("SELECT * FROM Event WHERE RecurrenceState = %d OR RecurrenceState = %d"),
  1408. xtpCalendarRecurrenceNotRecurring, xtpCalendarRecurrenceMaster);
  1409. CADOCommand cmdGetAllEvents_raw(m_pconnDb.GetInterfacePtr(), XTP_CT2CW(strSqlText));
  1410. CXTPCalendarEventPtr  ptrEvent;
  1411. try
  1412. {
  1413. XTPADODB::_RecordsetPtr ptrDataRS = cmdGetAllEvents_raw.Execute();
  1414. if (ptrDataRS == NULL)
  1415. {
  1416. ASSERT(FALSE);
  1417. return NULL;
  1418. }
  1419. // process recordset
  1420. while (!ptrDataRS->bEOF) //
  1421. {
  1422. ptrEvent = _ReadEvent_common(ptrDataRS, FALSE);
  1423. if (!ptrEvent)
  1424. {
  1425. ASSERT(FALSE);
  1426. ptrDataRS->MoveNext();
  1427. continue;
  1428. }
  1429. ptrEvents->Add(ptrEvent);
  1430. // next record
  1431. ptrDataRS->MoveNext();
  1432. }
  1433. ptrDataRS->Close();
  1434. return ptrEvents;
  1435. }
  1436. catch (_com_error &e)
  1437. {
  1438. TRACE_ProviderError(m_pconnDb);
  1439. TRACE_ComError(e);
  1440. }
  1441. catch(...)
  1442. {}
  1443. TRACE(_T("ERROR: Exeption in CXTPCalendarDatabaseDataProvider::DoGetAllEvents_raw() n"));
  1444. return NULL;
  1445. }
  1446. CXTPCalendarEventsPtr CXTPCalendarDatabaseDataProvider::DoGetUpcomingEvents(
  1447. COleDateTime dtFrom, COleDateTimeSpan spPeriod)
  1448. {
  1449. if (!IsOpen())
  1450. {
  1451. return NULL;
  1452. }
  1453. //-----------------------------------------------------------------------
  1454. if ((double)spPeriod == 0)
  1455. {
  1456. return DoGetAllEvents_raw();
  1457. }
  1458. //-----------------------------------------------------------------------
  1459. CXTPCalendarEventsPtr ptrEvents = new CXTPCalendarEvents();
  1460. if (!ptrEvents)
  1461. {
  1462. return NULL;
  1463. }
  1464. COleDateTime dtTo = dtFrom + spPeriod;
  1465. CString strDateTo = MakeSQLDateTime(dtTo);
  1466. CString strSqlText;
  1467. strSqlText.Format(_T("SELECT * FROM Event 
  1468. WHERE 
  1469. (RecurrenceState = $normal$ OR RecurrenceState = $master$ ) AND 
  1470. ( IsReminder <> 0 OR 
  1471. ( RecurrenceState = $master$ AND 
  1472.   RecurrencePatternID IN 
  1473. ( SELECT RecurrencePatternID  FROM Event 
  1474. WHERE 
  1475.   RecurrenceState = $exception$ And 
  1476.   IsReminder <> 0 AND 
  1477.   DATEADD("n", -1 * ReminderMinutesBeforeStart, StartDateTime) <= %s 
  1478. ) AND 
  1479. DATEADD("n", -1 * ReminderMinutesBeforeStart, StartDateTime) <= %s 
  1480. "),
  1481. (LPCTSTR)strDateTo, (LPCTSTR)strDateTo);
  1482. TCHAR szBuff[64];
  1483. REPLACE_S(strSqlText, _T("$normal$"), ITOT_S((int)xtpCalendarRecurrenceNotRecurring, szBuff, 64, 10));
  1484. REPLACE_S(strSqlText, _T("$master$"), ITOT_S((int)xtpCalendarRecurrenceMaster, szBuff, 64, 10));
  1485. REPLACE_S(strSqlText, _T("$exception$"), ITOT_S((int)xtpCalendarRecurrenceException, szBuff, 64, 10));
  1486. CADOCommand cmdGetUpcomingEvents(m_pconnDb.GetInterfacePtr(), XTP_CT2CW(strSqlText));
  1487. CXTPCalendarEventPtr  ptrEvent;
  1488. try
  1489. {
  1490. XTPADODB::_RecordsetPtr ptrDataRS = cmdGetUpcomingEvents.Execute();
  1491. if (ptrDataRS == NULL)
  1492. {
  1493. ASSERT(FALSE);
  1494. return NULL;
  1495. }
  1496. // process recordset
  1497. while (!ptrDataRS->bEOF) //
  1498. {
  1499. ptrEvent = _ReadEvent_common(ptrDataRS, FALSE);
  1500. if (!ptrEvent)
  1501. {
  1502. ASSERT(FALSE);
  1503. ptrDataRS->MoveNext();
  1504. continue;
  1505. }
  1506. ptrEvents->Add(ptrEvent);
  1507. // next record
  1508. ptrDataRS->MoveNext();
  1509. }
  1510. ptrDataRS->Close();
  1511. return ptrEvents;
  1512. }
  1513. catch (_com_error &e)
  1514. {
  1515. TRACE_ProviderError(m_pconnDb);
  1516. TRACE_ComError(e);
  1517. }
  1518. catch(...)
  1519. {}
  1520. TRACE(_T("ERROR: Exeption in CXTPCalendarDatabaseDataProvider::DoGetAllEvents_raw() n"));
  1521. return NULL;
  1522. }
  1523. BOOL CXTPCalendarDatabaseDataProvider::DoCreate_Event(CXTPCalendarEvent* pEvent, DWORD& rdwNewEventID)
  1524. {
  1525. if (!IsOpen())
  1526. {
  1527. return FALSE;
  1528. }
  1529. if (!pEvent || !m_pcmdAddEvent || !m_pcmdUpdEventPatternID)
  1530. {
  1531. ASSERT(FALSE);
  1532. return FALSE;
  1533. }
  1534. try
  1535. {
  1536. COleDateTime dtNow = CXTPCalendarUtils::GetCurrentTime();
  1537. pEvent->SetLastModificationTime(dtNow);
  1538. int nRState = (long)pEvent->GetRecurrenceState();
  1539. ASSERT(nRState == xtpCalendarRecurrenceMaster || nRState == xtpCalendarRecurrenceNotRecurring ||
  1540.    nRState == xtpCalendarRecurrenceException);
  1541. m_pcmdAddEvent->SetParameterValue(L"prm_StartDateTime", DATE2VAR(pEvent->GetStartTime()));
  1542. m_pcmdAddEvent->SetParameterValue(L"prm_EndDateTime", DATE2VAR(pEvent->GetEndTime()));
  1543. m_pcmdAddEvent->SetParameterValue(L"prm_RecurrenceState", _variant_t((long)nRState));
  1544. _variant_t vtIsAllDayEvent = (long)(pEvent->IsAllDayEvent() ? 1 : 0);
  1545. m_pcmdAddEvent->SetParameterValue(L"prm_IsAllDayEvent", vtIsAllDayEvent);
  1546. CString strData = pEvent->GetSubject();
  1547. m_pcmdAddEvent->SetParameterValue(L"prm_Subject", STRING2VAR(strData));
  1548. strData = pEvent->GetLocation();
  1549. m_pcmdAddEvent->SetParameterValue(L"prm_Location", STRING2VAR(strData));
  1550. strData = pEvent->GetReminderSoundFile();
  1551. m_pcmdAddEvent->SetParameterValue(L"prm_RemainderSoundFile", STRING2VAR(strData));
  1552. strData = pEvent->GetBody();
  1553. m_pcmdAddEvent->SetParameterValue(L"prm_Body", STRING2VAR(strData));
  1554. m_pcmdAddEvent->SetParameterValue(L"prm_Created", DATE2VAR(pEvent->GetCreationTime()));
  1555. m_pcmdAddEvent->SetParameterValue(L"prm_Modified", DATE2VAR(pEvent->GetLastModificationTime()));
  1556. m_pcmdAddEvent->SetParameterValue(L"prm_BusyStatus", _variant_t((long)pEvent->GetBusyStatus()));
  1557. m_pcmdAddEvent->SetParameterValue(L"prm_ImportanceLevel", _variant_t((long)pEvent->GetImportance()));
  1558. m_pcmdAddEvent->SetParameterValue(L"prm_LabelID", _variant_t((long)pEvent->GetLabelID()));
  1559. m_pcmdAddEvent->SetParameterValue(L"prm_RecurrencePatternID", _variant_t((long)pEvent->GetRecurrencePatternID()));
  1560. m_pcmdAddEvent->SetParameterValue(L"prm_ScheduleID", _variant_t((long)pEvent->GetScheduleID()));
  1561. _variant_t vtIsRecurrenceExceptionDeleted = (long)(pEvent->IsRExceptionDeleted() ? 1 : 0);
  1562. m_pcmdAddEvent->SetParameterValue(L"prm_IsRecurrenceExceptionDeleted", vtIsRecurrenceExceptionDeleted);
  1563. m_pcmdAddEvent->SetParameterValue(L"prm_RExceptionStartTimeOrig", DATE2VAR(pEvent->GetRException_StartTimeOrig()) );
  1564. m_pcmdAddEvent->SetParameterValue(L"prm_RExceptionEndTimeOrig", DATE2VAR(pEvent->GetRException_EndTimeOrig()) );
  1565. _variant_t vtIsMeeting = (long)(pEvent->IsMeeting() ? 1 : 0);
  1566. m_pcmdAddEvent->SetParameterValue(L"prm_IsMeeting", vtIsMeeting);
  1567. _variant_t vtIsPrivate = (long)(pEvent->IsPrivate() ? 1 : 0);
  1568. m_pcmdAddEvent->SetParameterValue(L"prm_IsPrivate", vtIsPrivate);
  1569. _variant_t vtIsReminder = (long)(pEvent->IsReminder() ? 1 : 0);
  1570. m_pcmdAddEvent->SetParameterValue(L"prm_IsReminder", vtIsReminder);
  1571. m_pcmdAddEvent->SetParameterValue(L"prm_ReminderMinutesBeforeStart", _variant_t((long)pEvent->GetReminderMinutesBeforeStart()));
  1572. if (pEvent->GetCustomProperties())
  1573. {
  1574. // update CustomIcons
  1575. pEvent->GetCustomProperties()->RemoveProperty(cszEventCustProp_IconsIDs);
  1576. if (pEvent->GetCustomIcons() && pEvent->GetCustomIcons()->GetSize())
  1577. {
  1578. CString strArray = pEvent->GetCustomIcons()->SaveToString();
  1579. VERIFY(pEvent->GetCustomProperties()->SetProperty(cszEventCustProp_IconsIDs, STRING2VAR(strArray)));
  1580. }
  1581. // update Categories
  1582. pEvent->GetCustomProperties()->RemoveProperty(cszEventCustProp_CategoryIDs);
  1583. if (pEvent->GetCategories() && pEvent->GetCategories()->GetSize())
  1584. {
  1585. CString strArray = pEvent->GetCategories()->SaveToString();
  1586. VERIFY(pEvent->GetCustomProperties()->SetProperty(cszEventCustProp_CategoryIDs, STRING2VAR(strArray)));
  1587. }
  1588. // Save CustomProperties
  1589. pEvent->GetCustomProperties()->SaveToXML(strData);
  1590. // remove temporary data
  1591. pEvent->GetCustomProperties()->RemoveProperty(cszEventCustProp_IconsIDs);
  1592. pEvent->GetCustomProperties()->RemoveProperty(cszEventCustProp_CategoryIDs);
  1593. }
  1594. m_pcmdAddEvent->SetParameterValue(L"prm_CustomPropertiesXMLData", STRING2VAR(strData));
  1595. m_pcmdAddEvent->Execute();
  1596. // get event ID
  1597. m_pcmdGetLastID->SetSQLString(L"SELECT MAX(EventID) AS NewEventID FROM Event");
  1598. XTPADODB::_RecordsetPtr ptrDataRS = m_pcmdGetLastID->Execute();
  1599. ASSERT(ptrDataRS != NULL);
  1600. if (ptrDataRS)
  1601. {
  1602. ASSERT(!ptrDataRS->bEOF);
  1603. if (!ptrDataRS->bEOF)
  1604. {
  1605. rdwNewEventID = (DWORD)(long)ptrDataRS->Fields->GetItem(L"NewEventID")->Value;
  1606. }
  1607. }
  1608. ptrDataRS->Close();
  1609. return TRUE;
  1610. }
  1611. catch (_com_error &e)
  1612. {
  1613. TRACE_ProviderError(m_pconnDb);
  1614. TRACE_ComError(e);
  1615. }
  1616. catch(...)
  1617. {}
  1618. TRACE(_T("ERROR: Exeption in CXTPCalendarDatabaseDataProvider::_AddEvent()"));
  1619. return FALSE;
  1620. }
  1621. BOOL CXTPCalendarDatabaseDataProvider::DoDelete_Event(CXTPCalendarEvent* pEvent)
  1622. {
  1623. if (!IsOpen())
  1624. {
  1625. return FALSE;
  1626. }
  1627. if (!m_pcmdDelEvent || !pEvent)
  1628. {
  1629. ASSERT(FALSE);
  1630. return FALSE;
  1631. }
  1632. DWORD dwEventID = pEvent->GetEventID();
  1633. ASSERT(dwEventID != XTP_CALENDAR_UNKNOWN_EVENT_ID);
  1634. m_pcmdDelEvent->SetParameterValue(L"EventID", _variant_t((long)dwEventID));
  1635. m_pcmdDelEvent->Execute();
  1636. return TRUE;
  1637. }
  1638. BOOL CXTPCalendarDatabaseDataProvider::DoUpdate_Event(CXTPCalendarEvent* pEvent)
  1639. {
  1640. if (!IsOpen())
  1641. {
  1642. return FALSE;
  1643. }
  1644. if (!pEvent || !m_pcmdUpdEvent)
  1645. {
  1646. ASSERT(FALSE);
  1647. return FALSE;
  1648. }
  1649. COleDateTime dtNow = CXTPCalendarUtils::GetCurrentTime();
  1650. pEvent->SetLastModificationTime(dtNow);
  1651. DWORD dwEventID = pEvent->GetEventID();
  1652. ASSERT(dwEventID != XTP_CALENDAR_UNKNOWN_EVENT_ID);
  1653. //===========================================================================
  1654. try
  1655. {
  1656. // Update Event properties
  1657. m_pcmdUpdEvent->SetParameterValue(L"prm_StartDateTime", DATE2VAR(pEvent->GetStartTime()));
  1658. m_pcmdUpdEvent->SetParameterValue(L"prm_EndDateTime", DATE2VAR(pEvent->GetEndTime()));
  1659. m_pcmdUpdEvent->SetParameterValue(L"prm_RecurrenceState", _variant_t((long)pEvent->GetRecurrenceState()));
  1660. _variant_t vtIsAllDayEvent((long)0);
  1661. if (pEvent->IsAllDayEvent())
  1662. vtIsAllDayEvent = _variant_t((long)1);
  1663. m_pcmdUpdEvent->SetParameterValue(L"prm_IsAllDayEvent", vtIsAllDayEvent);
  1664. CString strData = pEvent->GetSubject();
  1665. m_pcmdUpdEvent->SetParameterValue(L"prm_Subject", STRING2VAR(strData));
  1666. strData = pEvent->GetLocation();
  1667. m_pcmdUpdEvent->SetParameterValue(L"prm_Location", STRING2VAR(strData));
  1668. strData = pEvent->GetReminderSoundFile();
  1669. m_pcmdUpdEvent->SetParameterValue(L"prm_RemainderSoundFile", STRING2VAR(strData));
  1670. strData = pEvent->GetBody();
  1671. m_pcmdUpdEvent->SetParameterValue(L"prm_Body", STRING2VAR(strData));
  1672. m_pcmdUpdEvent->SetParameterValue(L"prm_Created", DATE2VAR(pEvent->GetCreationTime()));
  1673. m_pcmdUpdEvent->SetParameterValue(L"prm_Modified", DATE2VAR(pEvent->GetLastModificationTime()));
  1674. m_pcmdUpdEvent->SetParameterValue(L"prm_BusyStatus", _variant_t((long)pEvent->GetBusyStatus()));
  1675. m_pcmdUpdEvent->SetParameterValue(L"prm_ImportanceLevel", _variant_t((long)pEvent->GetImportance()));
  1676. m_pcmdUpdEvent->SetParameterValue(L"prm_LabelID", _variant_t((long)pEvent->GetLabelID()));
  1677. m_pcmdUpdEvent->SetParameterValue(L"prm_RecurrencePatternID", _variant_t((long)pEvent->GetRecurrencePatternID()));
  1678. m_pcmdUpdEvent->SetParameterValue(L"prm_ScheduleID", _variant_t((long)pEvent->GetScheduleID()));
  1679. _variant_t vtIsRecurrenceExceptionDeleted = (long)(pEvent->IsRExceptionDeleted() ? 1 : 0);
  1680. m_pcmdUpdEvent->SetParameterValue(L"prm_IsRecurrenceExceptionDeleted", vtIsRecurrenceExceptionDeleted);
  1681. m_pcmdUpdEvent->SetParameterValue(L"prm_RExceptionStartTimeOrig", DATE2VAR(pEvent->GetRException_StartTimeOrig()) );
  1682. m_pcmdUpdEvent->SetParameterValue(L"prm_RExceptionEndTimeOrig", DATE2VAR(pEvent->GetRException_EndTimeOrig()) );
  1683. _variant_t vtIsMeeting = (long)(pEvent->IsMeeting() ? 1 : 0);
  1684. m_pcmdUpdEvent->SetParameterValue(L"prm_IsMeeting", vtIsMeeting);
  1685. _variant_t vtIsPrivate = (long)(pEvent->IsPrivate() ? 1 : 0);
  1686. m_pcmdUpdEvent->SetParameterValue(L"prm_IsPrivate", vtIsPrivate);
  1687. _variant_t vtIsReminder = (long)(pEvent->IsReminder() ? 1 : 0);
  1688. m_pcmdUpdEvent->SetParameterValue(L"prm_IsReminder", vtIsReminder);
  1689. m_pcmdUpdEvent->SetParameterValue(L"prm_ReminderMinutesBeforeStart", _variant_t((long)pEvent->GetReminderMinutesBeforeStart()));
  1690. if (pEvent->GetCustomProperties())
  1691. {
  1692. // update CustomIcons
  1693. pEvent->GetCustomProperties()->RemoveProperty(cszEventCustProp_IconsIDs);
  1694. if (pEvent->GetCustomIcons() && pEvent->GetCustomIcons()->GetSize())
  1695. {
  1696. CString strArray = pEvent->GetCustomIcons()->SaveToString();
  1697. VERIFY(pEvent->GetCustomProperties()->SetProperty(cszEventCustProp_IconsIDs, STRING2VAR(strArray)));
  1698. }
  1699. // update Categories
  1700. pEvent->GetCustomProperties()->RemoveProperty(cszEventCustProp_CategoryIDs);
  1701. if (pEvent->GetCategories() && pEvent->GetCategories()->GetSize())
  1702. {
  1703. CString strArray = pEvent->GetCategories()->SaveToString();
  1704. VERIFY(pEvent->GetCustomProperties()->SetProperty(cszEventCustProp_CategoryIDs, STRING2VAR(strArray)));
  1705. }
  1706. // Save CustomProperties
  1707. pEvent->GetCustomProperties()->SaveToXML(strData);
  1708. // remove temporary data
  1709. pEvent->GetCustomProperties()->RemoveProperty(cszEventCustProp_IconsIDs);
  1710. pEvent->GetCustomProperties()->RemoveProperty(cszEventCustProp_CategoryIDs);
  1711. }
  1712. m_pcmdUpdEvent->SetParameterValue(L"prm_CustomPropertiesXMLData", STRING2VAR(strData));
  1713. //"EventID"
  1714. m_pcmdUpdEvent->SetParameterValue(L"prm_EventID", _variant_t((long)dwEventID));
  1715. m_pcmdUpdEvent->Execute();
  1716. return TRUE;
  1717. }
  1718. catch (_com_error &e)
  1719. {
  1720. TRACE_ProviderError(m_pconnDb);
  1721. TRACE_ComError(e);
  1722. }
  1723. catch(...)
  1724. {}
  1725. TRACE(_T("ERROR: Exeption in CXTPCalendarDatabaseDataProvider::UpdateEvent(ID = %d)"), dwEventID);
  1726. return FALSE;
  1727. }
  1728. // ------------------- RecurrencePattern processing -----------------------------
  1729. CXTPCalendarRecurrencePatternPtr CXTPCalendarDatabaseDataProvider::DoRead_RPattern(DWORD dwPatternID)
  1730. {
  1731. if (!IsOpen())
  1732. {
  1733. return NULL;
  1734. }
  1735. if (!m_pcmdGetRPattern)
  1736. {
  1737. ASSERT(FALSE);
  1738. return NULL;
  1739. }
  1740. try
  1741. {
  1742. m_pcmdGetRPattern->SetParameterValue(L"RecurrencePatternID", _variant_t((long)dwPatternID));
  1743. XTPADODB::_RecordsetPtr ptrDataRS = m_pcmdGetRPattern->Execute();
  1744. // process recordset
  1745. if (ptrDataRS == NULL || ptrDataRS->bEOF)
  1746. {
  1747. return NULL;
  1748. }
  1749. //ChangePatternID(pPattern, dwPatternID);
  1750. CXTPCalendarRecurrencePatternPtr ptrPattern = CreateNewRecurrencePattern(dwPatternID);
  1751. ptrPattern->SetMasterEventID((DWORD)(long)ptrDataRS->Fields->GetItem(L"MasterEventID")->Value);
  1752. ptrPattern->SetStartTime((DATE)ptrDataRS->Fields->GetItem(L"StartDateTime")->Value);
  1753. ptrPattern->SetDurationMinutes((long)ptrDataRS->Fields->GetItem(L"Duration")->Value);
  1754. ptrPattern->SetPatternStartDate((DATE)ptrDataRS->Fields->GetItem(L"PatternStartDateTime")->Value);
  1755. int nUseEnd = _GetField<long>(ptrDataRS, L"UseEnd", xtpCalendarPatternEndNoDate);
  1756. if (nUseEnd == xtpCalendarPatternEndDate)
  1757. {
  1758. ptrPattern->SetPatternEndDate(_GetField<DATE>(ptrDataRS, L"PatternEndDateTime", 0));
  1759. }
  1760. else if (nUseEnd == xtpCalendarPatternEndAfterOccurrences)
  1761. {
  1762. ptrPattern->SetEndAfterOccurrences(_GetField<long>(ptrDataRS, L"EndAfterOccurrence", 1));
  1763. }
  1764. else if (nUseEnd == xtpCalendarPatternEndNoDate)
  1765. {
  1766. ptrPattern->SetNoEndDate();
  1767. }
  1768. XTP_CALENDAR_RECURRENCE_OPTIONS tmp_options;
  1769. if (!_GetRPatternOptions(ptrDataRS, tmp_options))
  1770. {
  1771. ASSERT(FALSE);
  1772. ptrDataRS->Close();
  1773. return NULL;
  1774. }
  1775. ptrPattern->SetRecurrenceOptions(tmp_options);
  1776. if (ptrPattern->GetCustomProperties())
  1777. {
  1778. CString bstrPropsXMLData = _GetFieldString(ptrDataRS, L"CustomPropertiesXMLData");
  1779. ptrPattern->GetCustomProperties()->LoadFromXML(bstrPropsXMLData);
  1780. }
  1781. ptrDataRS->Close();
  1782. if (!_ReadRExceptions(ptrPattern))
  1783. {
  1784. ASSERT(FALSE);
  1785. return NULL;
  1786. }
  1787. return ptrPattern;
  1788. }
  1789. catch (_com_error &e)
  1790. {
  1791. TRACE_ProviderError(m_pconnDb);
  1792. TRACE_ComError(e);
  1793. }
  1794. catch(...)
  1795. {}
  1796. TRACE(_T("ERROR: Exeption in CXTPCalendarDatabaseDataProvider::ReadRPattern(ID = %d)"), dwPatternID);
  1797. return FALSE;
  1798. }
  1799. BOOL CXTPCalendarDatabaseDataProvider::_ReadRExceptions(CXTPCalendarRecurrencePattern* pPattern)
  1800. {
  1801. if (!IsOpen())
  1802. {
  1803. return FALSE;
  1804. }
  1805. if (!pPattern || !m_pcmdGetRExceptions)
  1806. {
  1807. ASSERT(FALSE);
  1808. return FALSE;
  1809. }
  1810. DWORD dwPatternID = pPattern->GetPatternID();
  1811. try
  1812. {
  1813. m_pcmdGetRExceptions->SetParameterValue(L"PatternID", (long)dwPatternID);
  1814. XTPADODB::_RecordsetPtr ptrDataRS = m_pcmdGetRExceptions->Execute();
  1815. if (ptrDataRS == NULL)
  1816. {
  1817. ASSERT(FALSE);
  1818. return FALSE;
  1819. }
  1820. // process recordset
  1821. while (!ptrDataRS->bEOF) //
  1822. {
  1823. CXTPCalendarEventPtr  ptrEvent = _ReadEvent_common(ptrDataRS, TRUE);
  1824. if (!ptrEvent)
  1825. {
  1826. #ifdef _DEBUG
  1827. long nID = _GetField<long>(ptrDataRS, L"EventID", 0);
  1828. TRACE(_T("! Cannot Read Exception event. ID = %d"), nID);
  1829. #endif
  1830. ptrDataRS->MoveNext();
  1831. continue;
  1832. }
  1833. int nRState = _GetField<long>(ptrDataRS, L"RecurrenceState", xtpCalendarRecurrenceUnknown);
  1834. ASSERT(nRState == xtpCalendarRecurrenceException);
  1835. if (nRState == xtpCalendarRecurrenceException)
  1836. {
  1837. if (!ptrEvent->MakeAsRException(dwPatternID))
  1838. {
  1839. ASSERT(FALSE);
  1840. ptrDataRS->MoveNext();
  1841. continue;
  1842. }
  1843. ptrEvent->SetRExceptionDeleted(0 != _GetField<long>(ptrDataRS, L"IsRecurrenceExceptionDeleted", 1));
  1844. DATE dtStartOrig = _GetField<DATE>(ptrDataRS, L"RExceptionStartTimeOrig", INT_MAX);
  1845. DATE dtEndOrig = _GetField<DATE>(ptrDataRS, L"RExceptionEndTimeOrig", INT_MAX);
  1846. if (dtStartOrig != INT_MAX && dtEndOrig != INT_MAX)
  1847. {
  1848. ptrEvent->SetRException_StartTimeOrig(dtStartOrig);
  1849. ptrEvent->SetRException_EndTimeOrig(dtEndOrig);
  1850. VERIFY(pPattern->SetException(ptrEvent));
  1851. }
  1852. else
  1853. {
  1854. ASSERT(FALSE);
  1855. }
  1856. }
  1857. // next record
  1858. ptrDataRS->MoveNext();
  1859. }
  1860. ptrDataRS->Close();
  1861. return TRUE;
  1862. }
  1863. catch (_com_error &e)
  1864. {
  1865. TRACE_ProviderError(m_pconnDb);
  1866. TRACE_ComError(e);
  1867. }
  1868. catch(...)
  1869. {}
  1870. TRACE(_T("ERROR: Exeption in CXTPCalendarDatabaseDataProvider::ReadRExceptions(PatternID = %d)"), dwPatternID);
  1871. return FALSE;
  1872. }
  1873. BOOL CXTPCalendarDatabaseDataProvider::DoCreate_RPattern(CXTPCalendarRecurrencePattern* pPattern, DWORD& rdwNewPatternID)
  1874. {
  1875. if (!IsOpen())
  1876. {
  1877. return FALSE;
  1878. }
  1879. if (!pPattern || !m_pcmdAddRPattern)
  1880. {
  1881. return FALSE;
  1882. }
  1883. try
  1884. {
  1885. m_pcmdAddRPattern->SetParameterValue(L"prm_MasterEventID", _variant_t((long)pPattern->GetMasterEventID()));
  1886. m_pcmdAddRPattern->SetParameterValue(L"prm_PatternStartDateTime", DATE2VAR(pPattern->GetPatternStartDate()));
  1887. m_pcmdAddRPattern->SetParameterValue(L"prm_StartDateTime", DATE2VAR(pPattern->GetStartTime()));
  1888. m_pcmdAddRPattern->SetParameterValue(L"prm_Duration", _variant_t((long)pPattern->GetDurationMinutes()));
  1889. int nUseEnd = pPattern->GetUseEndMethod();
  1890. m_pcmdAddRPattern->SetParameterValue(L"prm_UseEnd", _variant_t((long)nUseEnd));
  1891. m_pcmdAddRPattern->SetParameterValue(L"prm_PatternEndDateTime", DATE2VAR((nUseEnd == xtpCalendarPatternEndDate) ? (DATE)pPattern->GetPatternEndDate() : (DATE)0));
  1892. m_pcmdAddRPattern->SetParameterValue(L"prm_EndAfterOccurrences", (long)pPattern->GetEndAfterOccurrences());
  1893. _SetRPatternOptions(m_pcmdAddRPattern, pPattern);
  1894. CString strData;
  1895. if (pPattern->GetCustomProperties())
  1896. pPattern->GetCustomProperties()->SaveToXML(strData);
  1897. m_pcmdAddRPattern->SetParameterValue(L"prm_CustomPropertiesXMLData", STRING2VAR(strData));
  1898. m_pcmdAddRPattern->Execute();
  1899. // get event ID
  1900. m_pcmdGetLastID->SetSQLString(L"SELECT MAX(RecurrencePatternID) AS NewRecurrencePatternID FROM RecurrencePattern");
  1901. XTPADODB::_RecordsetPtr ptrDataRS = m_pcmdGetLastID->Execute();
  1902. ASSERT(ptrDataRS != NULL);
  1903. if (ptrDataRS)
  1904. {
  1905. ASSERT(!ptrDataRS->bEOF);
  1906. if (!ptrDataRS->bEOF)
  1907. {
  1908. rdwNewPatternID = (DWORD)(long)ptrDataRS->Fields->GetItem(L"NewRecurrencePatternID")->Value;
  1909. }
  1910. ptrDataRS->Close();
  1911. }
  1912. return TRUE;
  1913. }
  1914. catch (_com_error &e)
  1915. {
  1916. TRACE_ProviderError(m_pconnDb);
  1917. TRACE_ComError(e);
  1918. }
  1919. catch(...)
  1920. {}
  1921. TRACE(_T("ERROR: Exeption in CXTPCalendarDatabaseDataProvider::AddRPattern()"));
  1922. return FALSE;
  1923. }
  1924. BOOL CXTPCalendarDatabaseDataProvider::DoDelete_RPattern(CXTPCalendarRecurrencePattern* pPattern)
  1925. {
  1926. if (!IsOpen())
  1927. {
  1928. return FALSE;
  1929. }
  1930. if (!m_pcmdDelRPattern || !pPattern)
  1931. {
  1932. ASSERT(FALSE);
  1933. return FALSE;
  1934. }
  1935. DWORD dwPatternID = pPattern->GetPatternID();
  1936. m_pcmdDelRPattern->SetParameterValue(L"RecurrencePatternID", _variant_t((long)dwPatternID));
  1937. m_pcmdDelRPattern->Execute();
  1938. //-------------------------------------------
  1939. m_pConnect->SendEvent(XTP_NC_CALENDARPATTERNWASDELETED, dwPatternID, 0);
  1940. return TRUE;
  1941. }
  1942. BOOL CXTPCalendarDatabaseDataProvider::DoUpdate_RPattern(CXTPCalendarRecurrencePattern* pPattern)
  1943. {
  1944. if (!IsOpen())
  1945. {
  1946. return FALSE;
  1947. }
  1948. if (!pPattern || !m_pcmdUpdRPattern)
  1949. {
  1950. ASSERT(FALSE);
  1951. return FALSE;
  1952. }
  1953. DWORD dwPatternID = pPattern->GetPatternID();
  1954. //-------------------------------------
  1955. m_pcmdUpdRPattern->SetParameterValue(L"prm_MasterEventID", _variant_t((long)pPattern->GetMasterEventID()));
  1956. m_pcmdUpdRPattern->SetParameterValue(L"prm_StartDateTime", DATE2VAR(pPattern->GetStartTime()));
  1957. m_pcmdUpdRPattern->SetParameterValue(L"prm_Duration", DATE2VAR(pPattern->GetDurationMinutes()));
  1958. m_pcmdUpdRPattern->SetParameterValue(L"prm_PatternStartDateTime", DATE2VAR(pPattern->GetPatternStartDate()));
  1959. int nUseEnd = pPattern->GetUseEndMethod();
  1960. m_pcmdUpdRPattern->SetParameterValue(L"prm_UseEnd", _variant_t((long)nUseEnd));
  1961. m_pcmdUpdRPattern->SetParameterValue(L"prm_PatternEndDateTime", DATE2VAR((nUseEnd == xtpCalendarPatternEndDate) ? (DATE)pPattern->GetPatternEndDate() : (DATE)0));
  1962. m_pcmdUpdRPattern->SetParameterValue(L"prm_EndAfterOccurrences", (long)pPattern->GetEndAfterOccurrences());
  1963. if (!_SetRPatternOptions(m_pcmdUpdRPattern, pPattern))
  1964. {
  1965. ASSERT(FALSE);
  1966. return FALSE;
  1967. }
  1968. CString strData;
  1969. if (pPattern->GetCustomProperties())
  1970. pPattern->GetCustomProperties()->SaveToXML(strData);
  1971. m_pcmdUpdRPattern->SetParameterValue(L"prm_CustomPropertiesXMLData", STRING2VAR(strData));
  1972. m_pcmdUpdRPattern->SetParameterValue(L"prm_RecurrencePatternID", _variant_t((long)dwPatternID)); //
  1973. m_pcmdUpdRPattern->Execute();
  1974. //-------------------------------------
  1975. return TRUE;
  1976. }
  1977. BOOL CXTPCalendarDatabaseDataProvider::_GetRPatternOptions(XTPADODB::_Recordset* pRS, XTP_CALENDAR_RECURRENCE_OPTIONS& rROptions)
  1978. {
  1979. try
  1980. {
  1981. rROptions.m_nRecurrenceType = (XTPCalendarEventRecurrenceType)(long)pRS->Fields->GetItem(L"RecurrenceTypeID")->Value;
  1982. switch (rROptions.m_nRecurrenceType)
  1983. {
  1984. case xtpCalendarRecurrenceDaily :  // = 1
  1985. rROptions.m_Daily.bEveryWeekDayOnly = (long)pRS->Fields->GetItem(L"IsEveryWeekDay")->Value > 0;
  1986. if (rROptions.m_Daily.bEveryWeekDayOnly)
  1987. {
  1988. rROptions.m_Daily.nIntervalDays = 1;
  1989. }
  1990. else
  1991. {
  1992. rROptions.m_Daily.nIntervalDays = (long)pRS->Fields->GetItem(L"OccurrenceInterval")->Value;
  1993. }
  1994. break;
  1995. case xtpCalendarRecurrenceWeekly : //   = 2,
  1996. rROptions.m_Weekly.nIntervalWeeks = (long)pRS->Fields->GetItem(L"OccurrenceInterval")->Value;
  1997. rROptions.m_Weekly.nDayOfWeekMask = (long)pRS->Fields->GetItem(L"DayOfWeekMask")->Value;
  1998. break;
  1999. case xtpCalendarRecurrenceMonthly : //      = 3,
  2000. rROptions.m_Monthly.nIntervalMonths = (long)pRS->Fields->GetItem(L"OccurrenceInterval")->Value;
  2001. rROptions.m_Monthly.nDayOfMonth = (long)pRS->Fields->GetItem(L"DayOfMonth")->Value;
  2002. break;
  2003. case xtpCalendarRecurrenceMonthNth : // = 4,
  2004. rROptions.m_MonthNth.nIntervalMonths =  (long)pRS->Fields->GetItem(L"OccurrenceInterval")->Value;
  2005. rROptions.m_MonthNth.nWhichDay = (long)pRS->Fields->GetItem(L"DayOccurrenceTypeID")->Value;
  2006. rROptions.m_MonthNth.nWhichDayMask = (long)pRS->Fields->GetItem(L"DayMask")->Value;
  2007. break;
  2008. case xtpCalendarRecurrenceYearly : //   = 5,
  2009. rROptions.m_Yearly.nMonthOfYear = (long)pRS->Fields->GetItem(L"MonthOfYear")->Value;
  2010. rROptions.m_Yearly.nDayOfMonth = (long)pRS->Fields->GetItem(L"DayOfMonth")->Value;
  2011. break;
  2012. case xtpCalendarRecurrenceYearNth : //      = 6,
  2013. rROptions.m_YearNth.nWhichDay = (long)pRS->Fields->GetItem(L"DayOccurrenceTypeID")->Value;
  2014. rROptions.m_YearNth.nWhichDayMask = (long)pRS->Fields->GetItem(L"DayMask")->Value;
  2015. rROptions.m_YearNth.nMonthOfYear = (long)pRS->Fields->GetItem(L"MonthOfYear")->Value;
  2016. break;
  2017. default:
  2018. ASSERT(FALSE);
  2019. return FALSE;
  2020. }
  2021. return TRUE;
  2022. }
  2023. catch (_com_error &e)
  2024. {
  2025. TRACE_ProviderError(m_pconnDb);
  2026. TRACE_ComError(e);
  2027. }
  2028. catch(...)
  2029. {}
  2030. TRACE(_T("ERROR: Exeption in CXTPCalendarDatabaseDataProvider::GetRPatternOptions()"));
  2031. return FALSE;
  2032. }
  2033. BOOL CXTPCalendarDatabaseDataProvider::_SetRPatternOptions(CXTPCalendarDatabaseDataProvider::CADOCommand* pCmd, CXTPCalendarRecurrencePattern* pPattern)
  2034. {
  2035. try
  2036. {
  2037. int nRecurrenceTypeID = pPattern->GetRecurrenceType();
  2038. pCmd->SetParameterValue(L"prm_RecurrenceTypeID", _variant_t((long)nRecurrenceTypeID));
  2039. XTP_CALENDAR_RECURRENCE_OPTIONS pROptions = pPattern->GetRecurrenceOptions();
  2040. switch (nRecurrenceTypeID)
  2041. {
  2042. case xtpCalendarRecurrenceDaily :  // = 1
  2043. if (pROptions.m_Daily.bEveryWeekDayOnly)
  2044. {
  2045. pCmd->SetParameterValue(L"prm_IsEveryWeekDay", _variant_t((long)1));
  2046. pCmd->SetParameterValue(L"prm_OccurrenceInterval", _variant_t((long)0));
  2047. }
  2048. else
  2049. {
  2050. pCmd->SetParameterValue(L"prm_IsEveryWeekDay", _variant_t((long)0));
  2051. pCmd->SetParameterValue(L"prm_OccurrenceInterval", _variant_t((long)pROptions.m_Daily.nIntervalDays));
  2052. }
  2053. break;
  2054. case xtpCalendarRecurrenceWeekly : //   = 2,
  2055. pCmd->SetParameterValue(L"prm_OccurrenceInterval", _variant_t((long)pROptions.m_Weekly.nIntervalWeeks));
  2056. pCmd->SetParameterValue(L"prm_DayOfWeekMask", _variant_t((long)pROptions.m_Weekly.nDayOfWeekMask));
  2057. break;
  2058. case xtpCalendarRecurrenceMonthly : //      = 3,
  2059. pCmd->SetParameterValue(L"prm_OccurrenceInterval", _variant_t((long)pROptions.m_Monthly.nIntervalMonths));
  2060. pCmd->SetParameterValue(L"prm_DayOfMonth", _variant_t((long)pROptions.m_Monthly.nDayOfMonth));
  2061. break;
  2062. case xtpCalendarRecurrenceMonthNth : // = 4,
  2063. pCmd->SetParameterValue(L"prm_OccurrenceInterval", _variant_t((long)pROptions.m_MonthNth.nIntervalMonths));
  2064. pCmd->SetParameterValue(L"prm_DayOccurrenceType", _variant_t((long)pROptions.m_MonthNth.nWhichDay));
  2065. pCmd->SetParameterValue(L"prm_DayMask", _variant_t((long)pROptions.m_MonthNth.nWhichDayMask));
  2066. break;
  2067. case xtpCalendarRecurrenceYearly : //   = 5,
  2068. pCmd->SetParameterValue(L"prm_MonthOfYear", _variant_t((long)pROptions.m_Yearly.nMonthOfYear));
  2069. pCmd->SetParameterValue(L"prm_DayOfMonth", _variant_t((long)pROptions.m_Yearly.nDayOfMonth));
  2070. break;
  2071. case xtpCalendarRecurrenceYearNth : //      = 6,
  2072. pCmd->SetParameterValue(L"prm_DayOccurrenceType", _variant_t((long)pROptions.m_YearNth.nWhichDay));
  2073. pCmd->SetParameterValue(L"prm_DayMask",  _variant_t((long)pROptions.m_YearNth.nWhichDayMask));
  2074. pCmd->SetParameterValue(L"prm_MonthOfYear", _variant_t((long)pROptions.m_YearNth.nMonthOfYear));
  2075. break;
  2076. default:
  2077. ASSERT(FALSE);
  2078. return FALSE;
  2079. }
  2080. return TRUE;
  2081. }
  2082. catch (_com_error &e)
  2083. {
  2084. TRACE_ProviderError(m_pconnDb);
  2085. TRACE_ComError(e);
  2086. }
  2087. catch(...)
  2088. {}
  2089. TRACE(_T("ERROR: Exeption in CXTPCalendarDatabaseDataProvider::SetRPatternOptions()"));
  2090. return FALSE;
  2091. }
  2092. BOOL CXTPCalendarDatabaseDataProvider::SaveOptions(const CString& strOptionsData)
  2093. {
  2094. if (!IsOpen())
  2095. return FALSE;
  2096. if (!m_pcmdAddOptions || !m_pcmdRemoveAllOptions)
  2097. {
  2098. ASSERT(FALSE);
  2099. return FALSE;
  2100. }
  2101. try
  2102. {
  2103. // Remove old options records if necessary
  2104. if (!m_bTraceOptions)
  2105. {
  2106. m_pcmdRemoveAllOptions->Execute();
  2107. }
  2108. // Add new options record
  2109. COleDateTime dtNow = CXTPCalendarUtils::GetCurrentTime();
  2110. m_pcmdAddOptions->SetParameterValue(L"prm_SaveDateTime", DATE2VAR(dtNow));
  2111. m_pcmdAddOptions->SetParameterValue(L"prm_XMLData", STRING2VAR(strOptionsData));
  2112. m_pcmdAddOptions->Execute();
  2113. return TRUE;
  2114. }
  2115. catch (_com_error &e)
  2116. {
  2117. TRACE_ProviderError(m_pconnDb);
  2118. TRACE_ComError(e);
  2119. }
  2120. catch(...)
  2121. {}
  2122. TRACE(_T("ERROR: Exeption in CXTPCalendarDatabaseDataProvider::SaveOptions()"));
  2123. return FALSE;
  2124. }
  2125. CXTPCalendarEventPtr CXTPCalendarDatabaseDataProvider::DoRead_Event(DWORD dwEventID)
  2126. {
  2127. if (!IsOpen())
  2128. {
  2129. return NULL;
  2130. }
  2131. if (!m_pcmdGetEvent)
  2132. {
  2133. ASSERT(FALSE);
  2134. return NULL;
  2135. }
  2136. m_pcmdGetEvent->SetParameterValue(L"EventID", (long)dwEventID);
  2137. XTPADODB::_RecordsetPtr ptrDataRS = m_pcmdGetEvent->Execute();
  2138. if (ptrDataRS == NULL || ptrDataRS->bEOF)
  2139. {
  2140. return NULL;
  2141. }
  2142. CXTPCalendarEventPtr ptrEvent = _ReadEvent_common(ptrDataRS, FALSE);
  2143. if (!ptrEvent)
  2144. {
  2145. ptrDataRS->Close();
  2146. return NULL;
  2147. }
  2148. ptrDataRS->Close();
  2149. return ptrEvent;
  2150. }
  2151. void CXTPCalendarDatabaseDataProvider::DoRemoveAllEvents()
  2152. {
  2153. if (!IsOpen())
  2154. {
  2155. return;
  2156. }
  2157. if (!m_pcmdRemoveAllEvents || !m_pcmdRemoveAllRPatterns)
  2158. {
  2159. ASSERT(FALSE);
  2160. return;
  2161. }
  2162. m_pcmdRemoveAllEvents->Execute();
  2163. m_pcmdRemoveAllRPatterns->Execute();
  2164. }
  2165. void CXTPCalendarDatabaseDataProvider::CreateGetLastIDCommand()
  2166. {
  2167. m_pcmdGetLastID = new CADOCommand(m_pconnDb.GetInterfacePtr(), L"");
  2168. }
  2169. void CXTPCalendarDatabaseDataProvider::CreateAddEventCommand()
  2170. {
  2171. LPCWSTR strSqlText =
  2172. //---------------- sql statement body -------------------------
  2173. L"PARAMETERS 
  2174. prm_StartDateTime   DateTime, 
  2175. prm_EndDateTime     DateTime, 
  2176. prm_RecurrenceState Integer, 
  2177. prm_IsAllDayEvent   Integer, 
  2178. prm_Subject             TEXT, 
  2179. prm_Location            TEXT, 
  2180. prm_RemainderSoundFile  CHARACTER,
  2181. prm_Body            TEXT, 
  2182. prm_Created     DateTime, 
  2183. prm_Modified    DateTime, 
  2184. prm_BusyStatus      Integer, 
  2185. prm_ImportanceLevel Integer, 
  2186. prm_LabelID         Integer, 
  2187. prm_RecurrencePatternID             Integer, 
  2188. prm_ScheduleID                      Integer, 
  2189. prm_IsRecurrenceExceptionDeleted    Integer, 
  2190. prm_RExceptionStartTimeOrig         DateTime, 
  2191. prm_RExceptionEndTimeOrig           DateTime, 
  2192. prm_IsMeeting   Integer, 
  2193. prm_IsPrivate   Integer, 
  2194. prm_IsReminder  Integer, 
  2195. prm_ReminderMinutesBeforeStart      Integer, 
  2196. prm_CustomPropertiesXMLData         TEXT; "
  2197. L" 
  2198. INSERT INTO Event ( 
  2199. StartDateTime, 
  2200. EndDateTime, 
  2201. RecurrenceState, 
  2202. IsAllDayEvent, 
  2203. Subject, 
  2204. Location, 
  2205. RemainderSoundFile,
  2206. Body, 
  2207. Created, 
  2208. Modified, 
  2209. BusyStatus, 
  2210. ImportanceLevel, 
  2211. LabelID, 
  2212. RecurrencePatternID, 
  2213. ScheduleID, 
  2214. IsRecurrenceExceptionDeleted, 
  2215. RExceptionStartTimeOrig, 
  2216. RExceptionEndTimeOrig, 
  2217. IsMeeting, 
  2218. IsPrivate, 
  2219. IsReminder, 
  2220. ReminderMinutesBeforeStart, 
  2221. CustomPropertiesXMLData
  2222. VALUES ( 
  2223. prm_StartDateTime, 
  2224. prm_EndDateTime, 
  2225. prm_RecurrenceState, 
  2226. prm_IsAllDayEvent, 
  2227. prm_Subject, 
  2228. prm_Location, 
  2229. prm_RemainderSoundFile,
  2230. prm_Body, 
  2231. prm_Created, 
  2232. prm_Modified, 
  2233. prm_BusyStatus, 
  2234. prm_ImportanceLevel, 
  2235. prm_LabelID, 
  2236. prm_RecurrencePatternID, 
  2237. prm_ScheduleID, 
  2238. prm_IsRecurrenceExceptionDeleted, 
  2239. prm_RExceptionStartTimeOrig, 
  2240. prm_RExceptionEndTimeOrig, 
  2241. prm_IsMeeting, 
  2242. prm_IsPrivate, 
  2243. prm_IsReminder, 
  2244. prm_ReminderMinutesBeforeStart, 
  2245. prm_CustomPropertiesXMLData
  2246. ";
  2247. //---------------- sql statement body -------------------------
  2248. m_pcmdAddEvent = new CADOCommand(m_pconnDb.GetInterfacePtr(), strSqlText);
  2249. _variant_t vtEmpty((long)0);
  2250. _variant_t vtEmptyStr(EMPTY_DB_STR);
  2251. //m_pcmdAddEvent->CreateParameter(L"StartDateTime", XTPADODB::adDate, XTPADODB::adParamInput, -1, vtEmpty);
  2252. //m_pcmdAddEvent->CreateParameter(L"EndDateTime", XTPADODB::adDate, XTPADODB::adParamInput, -1, vtEmpty);
  2253. m_pcmdAddEvent->CreateParameter(L"prm_StartDateTime", XTPADODB::adDate, XTPADODB::adParamInput, -1, vtEmpty);
  2254. m_pcmdAddEvent->CreateParameter(L"prm_EndDateTime", XTPADODB::adDate, XTPADODB::adParamInput, -1, vtEmpty);
  2255. m_pcmdAddEvent->CreateParameter(L"prm_RecurrenceState", XTPADODB::adInteger, XTPADODB::adParamInput, -1, vtEmpty);
  2256. m_pcmdAddEvent->CreateParameter(L"prm_IsAllDayEvent", XTPADODB::adInteger, XTPADODB::adParamInput, -1, vtEmpty);
  2257. m_pcmdAddEvent->CreateParameter(L"prm_Subject", XTPADODB::adBSTR, XTPADODB::adParamInput, 0, vtEmptyStr);
  2258. m_pcmdAddEvent->CreateParameter(L"prm_Location", XTPADODB::adBSTR, XTPADODB::adParamInput, 0, vtEmptyStr);
  2259. m_pcmdAddEvent->CreateParameter(L"prm_RemainderSoundFile", XTPADODB::adBSTR, XTPADODB::adParamInput, 255, vtEmptyStr);
  2260. m_pcmdAddEvent->CreateParameter(L"prm_Body", XTPADODB::adBSTR, XTPADODB::adParamInput, 0, vtEmptyStr);
  2261. m_pcmdAddEvent->CreateParameter(L"prm_Created", XTPADODB::adDate, XTPADODB::adParamInput, -1, vtEmpty);
  2262. m_pcmdAddEvent->CreateParameter(L"prm_Modified", XTPADODB::adDate, XTPADODB::adParamInput, -1, vtEmpty);
  2263. m_pcmdAddEvent->CreateParameter(L"prm_BusyStatus", XTPADODB::adInteger, XTPADODB::adParamInput, -1, vtEmpty);
  2264. m_pcmdAddEvent->CreateParameter(L"prm_ImportanceLevel", XTPADODB::adInteger, XTPADODB::adParamInput, -1, vtEmpty);
  2265. m_pcmdAddEvent->CreateParameter(L"prm_LabelID", XTPADODB::adInteger, XTPADODB::adParamInput, -1, vtEmpty);
  2266. m_pcmdAddEvent->CreateParameter(L"prm_RecurrencePatternID", XTPADODB::adInteger, XTPADODB::adParamInput, -1, vtEmpty);
  2267. m_pcmdAddEvent->CreateParameter(L"prm_ScheduleID", XTPADODB::adInteger, XTPADODB::adParamInput, -1, vtEmpty);
  2268. m_pcmdAddEvent->CreateParameter(L"prm_IsRecurrenceExceptionDeleted", XTPADODB::adInteger, XTPADODB::adParamInput, -1, vtEmpty);
  2269. m_pcmdAddEvent->CreateParameter(L"prm_RExceptionStartTimeOrig", XTPADODB::adDate, XTPADODB::adParamInput, -1, vtEmpty);
  2270. m_pcmdAddEvent->CreateParameter(L"prm_RExceptionEndTimeOrig", XTPADODB::adDate, XTPADODB::adParamInput, -1, vtEmpty);
  2271. m_pcmdAddEvent->CreateParameter(L"prm_IsMeeting", XTPADODB::adInteger, XTPADODB::adParamInput, -1, vtEmpty);
  2272. m_pcmdAddEvent->CreateParameter(L"prm_IsPrivate", XTPADODB::adInteger, XTPADODB::adParamInput, -1, vtEmpty);
  2273. m_pcmdAddEvent->CreateParameter(L"prm_IsReminder", XTPADODB::adInteger, XTPADODB::adParamInput, -1, vtEmpty);
  2274. m_pcmdAddEvent->CreateParameter(L"prm_ReminderMinutesBeforeStart", XTPADODB::adInteger, XTPADODB::adParamInput, -1, vtEmpty);
  2275. m_pcmdAddEvent->CreateParameter(L"prm_CustomPropertiesXMLData", XTPADODB::adBSTR, XTPADODB::adParamInput, 0, vtEmptyStr);
  2276. }
  2277. void CXTPCalendarDatabaseDataProvider::CreateDelEventCommand()
  2278. {
  2279. LPCWSTR strSqlText =
  2280. //---------------- sql statement body -------------------------
  2281. L"DELETE FROM Event WHERE EventID = ?";
  2282. //---------------- sql statement body -------------------------
  2283. _variant_t vtEmpty((long)0);
  2284. m_pcmdDelEvent = new CADOCommand(m_pconnDb.GetInterfacePtr(), strSqlText);
  2285. m_pcmdDelEvent->CreateParameter(L"EventID", XTPADODB::adInteger, XTPADODB::adParamInput, -1, vtEmpty);
  2286. }
  2287. void CXTPCalendarDatabaseDataProvider::CreateUpdEventCommand()
  2288. {
  2289. LPCWSTR strSqlText =
  2290. //---------------- sql statement body -------------------------
  2291. L"PARAMETERS 
  2292. prm_StartDateTime   DateTime, 
  2293. prm_EndDateTime     DateTime, 
  2294. prm_RecurrenceState Integer, 
  2295. prm_IsAllDayEvent   Integer, 
  2296. prm_Subject             TEXT, 
  2297. prm_Location            TEXT, 
  2298. prm_RemainderSoundFile  CHARACTER,
  2299. prm_Body            TEXT, 
  2300. prm_Created     DateTime, 
  2301. prm_Modified    DateTime, 
  2302. prm_BusyStatus      Integer, 
  2303. prm_ImportanceLevel Integer, 
  2304. prm_LabelID         Integer, 
  2305. prm_RecurrencePatternID             Integer, 
  2306. prm_ScheduleID                      Integer, 
  2307. prm_IsRecurrenceExceptionDeleted    Integer, 
  2308. prm_RExceptionStartTimeOrig         DateTime, 
  2309. prm_RExceptionEndTimeOrig           DateTime, 
  2310. prm_IsMeeting   Integer, 
  2311. prm_IsPrivate   Integer, 
  2312. prm_IsReminder  Integer, 
  2313. prm_ReminderMinutesBeforeStart      Integer, 
  2314. prm_CustomPropertiesXMLData         TEXT,
  2315. prm_EventID     Integer; "
  2316. L" 
  2317. UPDATE Event SET 
  2318.    StartDateTime   = prm_StartDateTime, 
  2319.    EndDateTime     = prm_EndDateTime, 
  2320.    RecurrenceState = prm_RecurrenceState, 
  2321.    IsAllDayEvent   = prm_IsAllDayEvent, 
  2322.    Subject         = prm_Subject, 
  2323.    Location            = prm_Location, 
  2324.    RemainderSoundFile = prm_RemainderSoundFile, 
  2325.    Body                = prm_Body, 
  2326.    Created         = prm_Created, 
  2327.    Modified            = prm_Modified, 
  2328.    BusyStatus      = prm_BusyStatus, 
  2329.    ImportanceLevel = prm_ImportanceLevel, 
  2330.    LabelID         = prm_LabelID, 
  2331.    RecurrencePatternID         = prm_RecurrencePatternID, 
  2332.    ScheduleID                  = prm_ScheduleID, 
  2333.    "
  2334.    L" 
  2335.    IsRecurrenceExceptionDeleted = prm_IsRecurrenceExceptionDeleted, 
  2336.    RExceptionStartTimeOrig     = prm_RExceptionStartTimeOrig, 
  2337.    RExceptionEndTimeOrig       = prm_RExceptionEndTimeOrig, 
  2338.    IsMeeting               = prm_IsMeeting, 
  2339.    IsPrivate               = prm_IsPrivate, 
  2340.    IsReminder              = prm_IsReminder, 
  2341.    ReminderMinutesBeforeStart = prm_ReminderMinutesBeforeStart, 
  2342.    CustomPropertiesXMLData = prm_CustomPropertiesXMLData 
  2343.    
  2344.    WHERE EventID           = prm_EventID 
  2345. ";
  2346. //---------------- sql statement body -------------------------
  2347. m_pcmdUpdEvent = new CADOCommand(m_pconnDb.GetInterfacePtr(), strSqlText);
  2348. _variant_t vtEmpty((long)0);
  2349. _variant_t vtEmptyStr(EMPTY_DB_STR);
  2350. m_pcmdUpdEvent->CreateParameter(L"prm_StartDateTime", XTPADODB::adDate, XTPADODB::adParamInput, -1, vtEmpty);
  2351. m_pcmdUpdEvent->CreateParameter(L"prm_EndDateTime", XTPADODB::adDate, XTPADODB::adParamInput, -1, vtEmpty);
  2352. m_pcmdUpdEvent->CreateParameter(L"prm_RecurrenceState", XTPADODB::adInteger, XTPADODB::adParamInput, -1, vtEmpty);
  2353. m_pcmdUpdEvent->CreateParameter(L"prm_IsAllDayEvent", XTPADODB::adInteger, XTPADODB::adParamInput, -1, vtEmpty);
  2354. m_pcmdUpdEvent->CreateParameter(L"prm_Subject", XTPADODB::adBSTR, XTPADODB::adParamInput, 0, vtEmptyStr);
  2355. m_pcmdUpdEvent->CreateParameter(L"prm_Location", XTPADODB::adBSTR, XTPADODB::adParamInput, 0, vtEmptyStr);
  2356. m_pcmdUpdEvent->CreateParameter(L"prm_RemainderSoundFile", XTPADODB::adBSTR, XTPADODB::adParamInput, 255, vtEmptyStr);
  2357. m_pcmdUpdEvent->CreateParameter(L"prm_Body", XTPADODB::adBSTR, XTPADODB::adParamInput, 0, vtEmptyStr);
  2358. m_pcmdUpdEvent->CreateParameter(L"prm_Created", XTPADODB::adDate, XTPADODB::adParamInput, -1, vtEmpty);
  2359. m_pcmdUpdEvent->CreateParameter(L"prm_Modified", XTPADODB::adDate, XTPADODB::adParamInput, -1, vtEmpty);
  2360. m_pcmdUpdEvent->CreateParameter(L"prm_BusyStatus", XTPADODB::adInteger, XTPADODB::adParamInput, -1, vtEmpty);
  2361. m_pcmdUpdEvent->CreateParameter(L"prm_ImportanceLevel", XTPADODB::adInteger, XTPADODB::adParamInput, -1, vtEmpty);
  2362. m_pcmdUpdEvent->CreateParameter(L"prm_LabelID", XTPADODB::adInteger, XTPADODB::adParamInput, -1, vtEmpty);
  2363. m_pcmdUpdEvent->CreateParameter(L"prm_RecurrencePatternID", XTPADODB::adInteger, XTPADODB::adParamInput, -1, vtEmpty);
  2364. m_pcmdUpdEvent->CreateParameter(L"prm_ScheduleID", XTPADODB::adInteger, XTPADODB::adParamInput, -1, vtEmpty);
  2365. m_pcmdUpdEvent->CreateParameter(L"prm_IsRecurrenceExceptionDeleted", XTPADODB::adInteger, XTPADODB::adParamInput, -1, vtEmpty);
  2366. m_pcmdUpdEvent->CreateParameter(L"prm_RExceptionStartTimeOrig", XTPADODB::adDate, XTPADODB::adParamInput, -1, vtEmpty);
  2367. m_pcmdUpdEvent->CreateParameter(L"prm_RExceptionEndTimeOrig", XTPADODB::adDate, XTPADODB::adParamInput, -1, vtEmpty);
  2368. m_pcmdUpdEvent->CreateParameter(L"prm_IsMeeting", XTPADODB::adInteger, XTPADODB::adParamInput, -1, vtEmpty);
  2369. m_pcmdUpdEvent->CreateParameter(L"prm_IsPrivate", XTPADODB::adInteger, XTPADODB::adParamInput, -1, vtEmpty);
  2370. m_pcmdUpdEvent->CreateParameter(L"prm_IsReminder", XTPADODB::adInteger, XTPADODB::adParamInput, -1, vtEmpty);
  2371. m_pcmdUpdEvent->CreateParameter(L"prm_ReminderMinutesBeforeStart", XTPADODB::adInteger, XTPADODB::adParamInput, -1, vtEmpty);
  2372. m_pcmdUpdEvent->CreateParameter(L"prm_CustomPropertiesXMLData", XTPADODB::adBSTR, XTPADODB::adParamInput, 0, vtEmptyStr);
  2373. m_pcmdUpdEvent->CreateParameter(L"prm_EventID", XTPADODB::adInteger, XTPADODB::adParamInput, -1, vtEmpty);
  2374. }
  2375. void CXTPCalendarDatabaseDataProvider::CreateUpdEventPatternIDCommand()
  2376. {
  2377. LPCWSTR strSqlText;
  2378. strSqlText =
  2379. //---------------- sql statement body -------------------------
  2380. L"UPDATE Event 
  2381.    SET RecurrencePatternID = ? 
  2382.    WHERE EventID = ? 
  2383.    ";
  2384. //---------------- sql statement body -------------------------
  2385. m_pcmdUpdEventPatternID = new CADOCommand(m_pconnDb.GetInterfacePtr(), strSqlText);
  2386. _variant_t vtEmpty((long)0);
  2387. m_pcmdUpdEventPatternID->CreateParameter(L"RecurrencePatternID", XTPADODB::adInteger, XTPADODB::adParamInput, -1, vtEmpty);
  2388. m_pcmdUpdEventPatternID->CreateParameter(L"EventID", XTPADODB::adInteger, XTPADODB::adParamInput, -1, vtEmpty);
  2389. }
  2390. void CXTPCalendarDatabaseDataProvider::CreateGetDayEventCommand()
  2391. {
  2392. CString strSqlText;
  2393. strSqlText.Format(
  2394. //---------------- sql statement body -------------------------
  2395. _T("PARAMETERS prm_DayDate DateTime; 
  2396. SELECT EventID, 
  2397.    StartDateTime, 
  2398.    EndDateTime, 
  2399.    RecurrenceState, 
  2400.    IsAllDayEvent, 
  2401.    Subject, 
  2402.    Location, 
  2403.    RemainderSoundFile,
  2404.    Body, 
  2405.    Created, 
  2406.    Modified, 
  2407.    BusyStatus, 
  2408.    ImportanceLevel, 
  2409.    LabelID, 
  2410.    RecurrencePatternID, 
  2411.    ScheduleID, 
  2412.    IsRecurrenceExceptionDeleted, 
  2413.    IsMeeting, 
  2414.    IsPrivate, 
  2415.    IsReminder, 
  2416.    ReminderMinutesBeforeStart, 
  2417.    CustomPropertiesXMLData 
  2418.    FROM Event 
  2419.    WHERE DateValue(StartDateTime) <= DateValue(prm_DayDate) 
  2420.    AND DateValue(prm_DayDate) <= DateValue(EndDateTime) 
  2421.    AND (RecurrenceState = %d OR RecurrenceState = %d) 
  2422.    "),
  2423. xtpCalendarRecurrenceNotRecurring, xtpCalendarRecurrenceMaster);
  2424. //---------------- sql statement body -------------------------
  2425. m_pcmdGetDayEvents = new CADOCommand(m_pconnDb.GetInterfacePtr(), XTP_CT2CW(strSqlText));
  2426. _variant_t vtEmpty((long)0);
  2427. m_pcmdGetDayEvents->CreateParameter(L"prm_DayDate", XTPADODB::adDate, XTPADODB::adParamInput, -1, vtEmpty);
  2428. //  m_pcmdGetDayEvents->CreateParameter(L"DayDate2", XTPADODB::adDate, XTPADODB::adParamInput, -1, vtEmpty);
  2429. }
  2430. void CXTPCalendarDatabaseDataProvider::CreateGetEventCommand()
  2431. {
  2432. LPCWSTR strSqlText =
  2433. //---------------- sql statement body -------------------------
  2434. L"SELECT EventID, 
  2435.    StartDateTime, 
  2436.    EndDateTime, 
  2437.    RecurrenceState, 
  2438.    IsAllDayEvent, 
  2439.    Subject, 
  2440.    Location, 
  2441.    RemainderSoundFile,
  2442.    Body, 
  2443.    Created, 
  2444.    Modified, 
  2445.    BusyStatus, 
  2446.    ImportanceLevel, 
  2447.    LabelID, 
  2448.    RecurrencePatternID, 
  2449.    ScheduleID, 
  2450.    IsRecurrenceExceptionDeleted, 
  2451.    IsMeeting, 
  2452.    IsPrivate, 
  2453.    IsReminder, 
  2454.    ReminderMinutesBeforeStart, 
  2455.    CustomPropertiesXMLData 
  2456.    FROM Event 
  2457.    WHERE EventID = ? 
  2458.    ";
  2459. //---------------- sql statement body -------------------------
  2460. _variant_t vtEmpty((long)0);
  2461. m_pcmdGetEvent = new CADOCommand(m_pconnDb.GetInterfacePtr(), strSqlText);
  2462. m_pcmdGetEvent->CreateParameter(L"EventID", XTPADODB::adInteger, XTPADODB::adParamInput, -1, vtEmpty);
  2463. }
  2464. void CXTPCalendarDatabaseDataProvider::CreateGetRExceptionsCommand()
  2465. {
  2466. CString strSqlText;
  2467. strSqlText.Format(
  2468. //---------------- sql statement body -------------------------
  2469. _T("SELECT EventID, 
  2470.    StartDateTime, 
  2471.    EndDateTime, 
  2472.    RecurrenceState, 
  2473.    IsAllDayEvent, 
  2474.    Subject, 
  2475.    Location, 
  2476.    RemainderSoundFile,
  2477.    Body, 
  2478.    Created, 
  2479.    Modified, 
  2480.    BusyStatus, 
  2481.    ImportanceLevel, 
  2482.    LabelID, 
  2483.    RecurrencePatternID, 
  2484.    ScheduleID, 
  2485.    IsRecurrenceExceptionDeleted, 
  2486.    RExceptionStartTimeOrig, 
  2487.    RExceptionEndTimeOrig, 
  2488.    IsMeeting, 
  2489.    IsPrivate, 
  2490.    IsReminder, 
  2491.    ReminderMinutesBeforeStart, 
  2492.    CustomPropertiesXMLData 
  2493.    FROM Event 
  2494.    WHERE RecurrencePatternID = ? 
  2495.    AND RecurrenceState = %d 
  2496.    "),
  2497. xtpCalendarRecurrenceException);
  2498. //---------------- sql statement body -------------------------
  2499. _variant_t vtEmpty((long)0);
  2500. m_pcmdGetRExceptions = new CADOCommand(m_pconnDb.GetInterfacePtr(), XTP_CT2CW(strSqlText));
  2501. m_pcmdGetRExceptions->CreateParameter(L"PatternID", XTPADODB::adInteger, XTPADODB::adParamInput, -1, vtEmpty);
  2502. }
  2503. void CXTPCalendarDatabaseDataProvider::CreateAddRPatternCommand()
  2504. {
  2505. LPCWSTR strSqlText =
  2506. //---------------- sql statement body -------------------------
  2507. L"PARAMETERS 
  2508.    prm_PatternStartDateTime    DateTime, 
  2509.    prm_PatternEndDateTime  DateTime, 
  2510.    prm_StartDateTime       DateTime, 
  2511.    prm_Duration                Integer, 
  2512.    prm_EndAfterOccurrence  Integer, 
  2513.    prm_UseEnd              Integer, 
  2514.    prm_RecurrenceTypeID        Integer, 
  2515.    prm_OccurrenceInterval  Integer, 
  2516.    prm_DayOfWeekMask       Integer, 
  2517.    prm_DayOfMonth          Integer, 
  2518.    prm_MonthOfYear         Integer, 
  2519.    prm_IsEveryWeekDay      Integer, 
  2520.    prm_DayOccurrenceTypeID Integer, 
  2521.    prm_DayMask             Integer, 
  2522.    prm_MasterEventID       Integer, 
  2523.    prm_CustomPropertiesXMLData TEXT;  "
  2524.   L" 
  2525. INSERT INTO RecurrencePattern( 
  2526.    PatternStartDateTime, 
  2527.    PatternEndDateTime, 
  2528.    StartDateTime, 
  2529.    Duration, 
  2530.    EndAfterOccurrence, 
  2531.    UseEnd, 
  2532.    RecurrenceTypeID, 
  2533.    OccurrenceInterval, 
  2534.    DayOfWeekMask, 
  2535.    DayOfMonth, 
  2536.    MonthOfYear, 
  2537.    IsEveryWeekDay, 
  2538.    DayOccurrenceTypeID, 
  2539.    DayMask, 
  2540.    MasterEventID, 
  2541.    CustomPropertiesXMLData
  2542.    ) 
  2543.    VALUES( 
  2544.    prm_PatternStartDateTime, 
  2545.    prm_PatternEndDateTime, 
  2546.    prm_StartDateTime, 
  2547.    prm_Duration, 
  2548.    prm_EndAfterOccurrence, 
  2549.    prm_UseEnd, 
  2550.    prm_RecurrenceTypeID, 
  2551.    prm_OccurrenceInterval, 
  2552.    prm_DayOfWeekMask, 
  2553.    prm_DayOfMonth, 
  2554.    prm_MonthOfYear, 
  2555.    prm_IsEveryWeekDay, 
  2556.    prm_DayOccurrenceTypeID, 
  2557.    prm_DayMask, 
  2558.    prm_MasterEventID, 
  2559.    prm_CustomPropertiesXMLData 
  2560.    ) 
  2561.    ";
  2562. //---------------- sql statement body -------------------------
  2563. m_pcmdAddRPattern = new CADOCommand(m_pconnDb.GetInterfacePtr(), strSqlText);
  2564. _variant_t vtEmpty((long)0);
  2565. _variant_t vtEmptyStr(EMPTY_DB_STR);
  2566. m_pcmdAddRPattern->CreateParameter(L"prm_PatternStartDateTime", XTPADODB::adDate, XTPADODB::adParamInput, -1, vtEmpty);
  2567. m_pcmdAddRPattern->CreateParameter(L"prm_PatternEndDateTime", XTPADODB::adDate, XTPADODB::adParamInput, -1, vtEmpty);
  2568. m_pcmdAddRPattern->CreateParameter(L"prm_StartDateTime", XTPADODB::adDate, XTPADODB::adParamInput, -1, vtEmpty);
  2569. m_pcmdAddRPattern->CreateParameter(L"prm_Duration", XTPADODB::adInteger, XTPADODB::adParamInput, -1, vtEmpty);
  2570. m_pcmdAddRPattern->CreateParameter(L"prm_EndAfterOccurrences", XTPADODB::adInteger, XTPADODB::adParamInput, -1, vtEmpty);
  2571. m_pcmdAddRPattern->CreateParameter(L"prm_UseEnd", XTPADODB::adInteger, XTPADODB::adParamInput, -1, vtEmpty);
  2572. m_pcmdAddRPattern->CreateParameter(L"prm_RecurrenceTypeID", XTPADODB::adInteger, XTPADODB::adParamInput, -1, vtEmpty);
  2573. m_pcmdAddRPattern->CreateParameter(L"prm_OccurrenceInterval", XTPADODB::adInteger, XTPADODB::adParamInput, -1, vtEmpty);
  2574. m_pcmdAddRPattern->CreateParameter(L"prm_DayOfWeekMask", XTPADODB::adInteger, XTPADODB::adParamInput, -1, vtEmpty);
  2575. m_pcmdAddRPattern->CreateParameter(L"prm_DayOfMonth", XTPADODB::adInteger, XTPADODB::adParamInput, -1, vtEmpty);
  2576. m_pcmdAddRPattern->CreateParameter(L"prm_MonthOfYear", XTPADODB::adInteger, XTPADODB::adParamInput, -1, vtEmpty);
  2577. m_pcmdAddRPattern->CreateParameter(L"prm_IsEveryWeekDay", XTPADODB::adInteger, XTPADODB::adParamInput, -1, vtEmpty);
  2578. m_pcmdAddRPattern->CreateParameter(L"prm_DayOccurrenceType", XTPADODB::adInteger, XTPADODB::adParamInput, -1, vtEmpty);
  2579. m_pcmdAddRPattern->CreateParameter(L"prm_DayMask", XTPADODB::adInteger, XTPADODB::adParamInput, -1, vtEmpty);
  2580. m_pcmdAddRPattern->CreateParameter(L"prm_MasterEventID", XTPADODB::adInteger, XTPADODB::adParamInput, -1, vtEmpty);
  2581. m_pcmdAddRPattern->CreateParameter(L"prm_CustomPropertiesXMLData", XTPADODB::adBSTR, XTPADODB::adParamInput, 0, vtEmptyStr);
  2582. }
  2583. void CXTPCalendarDatabaseDataProvider::CreateDelRPatternCommand()
  2584. {
  2585. LPCWSTR strSqlText =
  2586. //---------------- sql statement body -------------------------
  2587. L"DELETE FROM RecurrencePattern WHERE RecurrencePatternID = ?";
  2588. //---------------- sql statement body -------------------------
  2589. _variant_t vtEmpty((long)0);
  2590. m_pcmdDelRPattern = new CADOCommand(m_pconnDb.GetInterfacePtr(), strSqlText);
  2591. m_pcmdDelRPattern->CreateParameter(L"RecurrencePatternID", XTPADODB::adInteger, XTPADODB::adParamInput, -1, vtEmpty);
  2592. }
  2593. void CXTPCalendarDatabaseDataProvider::CreateRemoveAllCommands()
  2594. {
  2595. LPCWSTR strSqlText;
  2596. strSqlText = L"DELETE FROM Event";
  2597. m_pcmdRemoveAllEvents = new CADOCommand(m_pconnDb.GetInterfacePtr(), strSqlText);
  2598. strSqlText = L"DELETE FROM RecurrencePattern";
  2599. m_pcmdRemoveAllRPatterns = new CADOCommand(m_pconnDb.GetInterfacePtr(), strSqlText);
  2600. strSqlText = L"DELETE FROM Options";
  2601. m_pcmdRemoveAllOptions = new CADOCommand(m_pconnDb.GetInterfacePtr(), strSqlText);
  2602. }
  2603. void CXTPCalendarDatabaseDataProvider::CreateUpdRPatternCommand()
  2604. {
  2605. LPCWSTR strSqlText =
  2606. //---------------- sql statement body -------------------------
  2607. L"PARAMETERS 
  2608.    prm_PatternStartDateTime    DateTime, 
  2609.    prm_PatternEndDateTime  DateTime, 
  2610.    prm_StartDateTime       DateTime, 
  2611.    prm_Duration                Integer, 
  2612.    prm_EndAfterOccurrence  Integer, 
  2613.    prm_UseEnd              Integer, 
  2614.    prm_RecurrenceTypeID        Integer, 
  2615.    prm_OccurrenceInterval  Integer, 
  2616.    prm_DayOfWeekMask       Integer, 
  2617.    prm_DayOfMonth          Integer, 
  2618.    prm_MonthOfYear         Integer, 
  2619.    prm_IsEveryWeekDay      Integer, 
  2620.    prm_DayOccurrenceTypeID Integer, 
  2621.    prm_DayMask             Integer, 
  2622.    prm_MasterEventID       Integer, 
  2623.    prm_CustomPropertiesXMLData TEXT, 
  2624.    
  2625.    prm_RecurrencePatternID Integer;  "
  2626. L" 
  2627. UPDATE RecurrencePattern SET 
  2628.    PatternStartDateTime    = prm_PatternStartDateTime, 
  2629.    PatternEndDateTime  = prm_PatternEndDateTime, 
  2630.    StartDateTime       = prm_StartDateTime, 
  2631.    Duration                = prm_Duration, 
  2632.    EndAfterOccurrence  = prm_EndAfterOccurrence, 
  2633.    UseEnd              = prm_UseEnd, 
  2634.    RecurrenceTypeID        = prm_RecurrenceTypeID, 
  2635.    OccurrenceInterval  = prm_OccurrenceInterval, 
  2636.    DayOfWeekMask       = prm_DayOfWeekMask, 
  2637.    DayOfMonth          = prm_DayOfMonth, 
  2638.    MonthOfYear         = prm_MonthOfYear, 
  2639.    IsEveryWeekDay      = prm_IsEveryWeekDay, 
  2640.    DayOccurrenceTypeID = prm_DayOccurrenceTypeID, 
  2641.    DayMask             = prm_DayMask,  
  2642.    MasterEventID       = prm_MasterEventID, 
  2643.    CustomPropertiesXMLData = prm_CustomPropertiesXMLData 
  2644.    
  2645.    WHERE RecurrencePatternID = prm_RecurrencePatternID 
  2646.    ";
  2647. //---------------- sql statement body -------------------------
  2648. m_pcmdUpdRPattern = new CADOCommand(m_pconnDb.GetInterfacePtr(), strSqlText);
  2649. _variant_t vtEmpty((long)0);
  2650. _variant_t vtEmptyStr(EMPTY_DB_STR);
  2651. m_pcmdUpdRPattern->CreateParameter(L"prm_PatternStartDateTime", XTPADODB::adDate, XTPADODB::adParamInput, -1, vtEmpty);
  2652. m_pcmdUpdRPattern->CreateParameter(L"prm_PatternEndDateTime", XTPADODB::adDate, XTPADODB::adParamInput, -1, vtEmpty);
  2653. m_pcmdUpdRPattern->CreateParameter(L"prm_StartDateTime", XTPADODB::adDate, XTPADODB::adParamInput, -1, vtEmpty);
  2654. m_pcmdUpdRPattern->CreateParameter(L"prm_Duration", XTPADODB::adInteger, XTPADODB::adParamInput, -1, vtEmpty);
  2655. m_pcmdUpdRPattern->CreateParameter(L"prm_EndAfterOccurrences", XTPADODB::adInteger, XTPADODB::adParamInput, -1, vtEmpty);
  2656. m_pcmdUpdRPattern->CreateParameter(L"prm_UseEnd", XTPADODB::adInteger, XTPADODB::adParamInput, -1, vtEmpty);
  2657. m_pcmdUpdRPattern->CreateParameter(L"prm_RecurrenceTypeID", XTPADODB::adInteger, XTPADODB::adParamInput, -1, vtEmpty);
  2658. m_pcmdUpdRPattern->CreateParameter(L"prm_OccurrenceInterval", XTPADODB::adInteger, XTPADODB::adParamInput, -1, vtEmpty);
  2659. m_pcmdUpdRPattern->CreateParameter(L"prm_DayOfWeekMask", XTPADODB::adInteger, XTPADODB::adParamInput, -1, vtEmpty);
  2660. m_pcmdUpdRPattern->CreateParameter(L"prm_DayOfMonth", XTPADODB::adInteger, XTPADODB::adParamInput, -1, vtEmpty);
  2661. m_pcmdUpdRPattern->CreateParameter(L"prm_MonthOfYear", XTPADODB::adInteger, XTPADODB::adParamInput, -1, vtEmpty);
  2662. m_pcmdUpdRPattern->CreateParameter(L"prm_IsEveryWeekDay", XTPADODB::adInteger, XTPADODB::adParamInput, -1, vtEmpty);
  2663. m_pcmdUpdRPattern->CreateParameter(L"prm_DayOccurrenceType", XTPADODB::adInteger, XTPADODB::adParamInput, -1, vtEmpty);
  2664. m_pcmdUpdRPattern->CreateParameter(L"prm_DayMask", XTPADODB::adInteger, XTPADODB::adParamInput, -1, vtEmpty);
  2665. m_pcmdUpdRPattern->CreateParameter(L"prm_MasterEventID", XTPADODB::adInteger, XTPADODB::adParamInput, -1, vtEmpty);
  2666. m_pcmdUpdRPattern->CreateParameter(L"prm_CustomPropertiesXMLData", XTPADODB::adBSTR, XTPADODB::adParamInput, 0, vtEmptyStr);
  2667. m_pcmdUpdRPattern->CreateParameter(L"prm_RecurrencePatternID", XTPADODB::adInteger, XTPADODB::adParamInput, -1, vtEmpty);
  2668. }
  2669. void CXTPCalendarDatabaseDataProvider::CreateGetRPatternCommand()
  2670. {
  2671. LPCWSTR strSqlText =
  2672. //---------------- sql statement body -------------------------
  2673. L"SELECT RecurrencePatternID, 
  2674.    PatternStartDateTime, 
  2675.    PatternEndDateTime, 
  2676.    StartDateTime, 
  2677.    Duration, 
  2678.    EndAfterOccurrence, 
  2679.    UseEnd, 
  2680.    RecurrenceTypeID, 
  2681.    OccurrenceInterval, 
  2682.    DayOfWeekMask, 
  2683.    DayOfMonth, 
  2684.    MonthOfYear, 
  2685.    IsEveryWeekDay, 
  2686.    DayOccurrenceTypeID, 
  2687.    DayMask, 
  2688.    MasterEventID, 
  2689.    CustomPropertiesXMLData 
  2690.    
  2691.    FROM RecurrencePattern 
  2692.    WHERE RecurrencePatternID = ? 
  2693.    ";
  2694. //---------------- sql statement body -------------------------
  2695. m_pcmdGetRPattern = new CADOCommand(m_pconnDb.GetInterfacePtr(), strSqlText);
  2696. _variant_t vtEmpty((long)0);
  2697. m_pcmdGetRPattern->CreateParameter(L"RecurrencePatternID", XTPADODB::adInteger, XTPADODB::adParamInput, -1, vtEmpty);
  2698. }
  2699. void CXTPCalendarDatabaseDataProvider::CreateGetOptionsCommand()
  2700. {
  2701. LPCWSTR strSqlText =
  2702. //---------------- sql statement body -------------------------
  2703. L"SELECT TOP 1 OptionsID, SaveDateTime, XMLData 
  2704. FROM Options 
  2705. ORDER BY OptionsID DESC;";
  2706. //---------------- sql statement body -------------------------
  2707. m_pcmdGetOptions = new CADOCommand(m_pconnDb.GetInterfacePtr(), strSqlText);
  2708. }
  2709. void CXTPCalendarDatabaseDataProvider::CreateAddOptionsCommand()
  2710. {
  2711. LPCWSTR strSqlText =
  2712. //---------------- sql statement body -------------------------
  2713. L"PARAMETERS prm_SaveDateTime DateTime, prm_XMLData TEXT; 
  2714. INSERT INTO Options (SaveDateTime, XMLData) 
  2715. VALUES (prm_SaveDateTime, prm_XMLData) ";
  2716. //---------------- sql statement body -------------------------
  2717. m_pcmdAddOptions = new CADOCommand(m_pconnDb.GetInterfacePtr(), strSqlText);
  2718. _variant_t vtEmpty((long)0);
  2719. _variant_t vtEmptyStr(EMPTY_DB_STR);
  2720. m_pcmdAddOptions->CreateParameter(L"prm_SaveDateTime", XTPADODB::adDate, XTPADODB::adParamInput, -1, vtEmpty);
  2721. m_pcmdAddOptions->CreateParameter(L"prm_XMLData", XTPADODB::adBSTR, XTPADODB::adParamInput, 0, vtEmptyStr);
  2722. }
  2723. void CXTPCalendarDatabaseDataProvider::CreateAddScheduleCommand()
  2724. {
  2725. LPCWSTR strSqlText =
  2726. //---------------- sql statement body -------------------------
  2727. L"PARAMETERS 
  2728.    prm_Name                        CHARACTER, 
  2729.    prm_CustomPropertiesXMLData TEXT, 
  2730.    prm_Modified                    DateTime; 
  2731.    
  2732. INSERT INTO Schedules ( 
  2733. Name, 
  2734. CustomPropertiesXMLData, 
  2735. Modified) 
  2736. VALUES ( 
  2737. prm_Name, 
  2738. prm_CustomPropertiesXMLData, 
  2739. prm_Modified) ";
  2740. //---------------- sql statement body -------------------------
  2741. m_pcmdAddSchedule = new CADOCommand(m_pconnDb.GetInterfacePtr(), strSqlText);
  2742. _variant_t vtEmpty((long)0);
  2743. _variant_t vtEmptyStr(EMPTY_DB_STR);
  2744. m_pcmdAddSchedule->CreateParameter(L"prm_Name", XTPADODB::adBSTR, XTPADODB::adParamInput, 0, vtEmptyStr);
  2745. m_pcmdAddSchedule->CreateParameter(L"prm_CustomPropertiesXMLData", XTPADODB::adBSTR, XTPADODB::adParamInput, 0, vtEmptyStr);
  2746. m_pcmdAddSchedule->CreateParameter(L"prm_Modified", XTPADODB::adDate, XTPADODB::adParamInput, -1, vtEmpty);
  2747. }
  2748. void CXTPCalendarDatabaseDataProvider::CreateUpdScheduleCommand()
  2749. {
  2750. LPCWSTR strSqlText =
  2751. //---------------- sql statement body -------------------------
  2752. L"PARAMETERS 
  2753.    prm_ScheduleID              Integer, 
  2754.    prm_Name                        CHARACTER, 
  2755.    prm_CustomPropertiesXMLData TEXT, 
  2756.    prm_Modified                    DateTime;"
  2757. L" 
  2758. UPDATE Schedules SET 
  2759.    Name                        = prm_Name, 
  2760.    CustomPropertiesXMLData = prm_CustomPropertiesXMLData, 
  2761.    Modified                    = prm_Modified 
  2762.    
  2763.    WHERE ScheduleID = prm_ScheduleID 
  2764.    ";
  2765. //---------------- sql statement body -------------------------
  2766. m_pcmdUpdSchedule = new CADOCommand(m_pconnDb.GetInterfacePtr(), strSqlText);
  2767. _variant_t vtEmpty((long)0);
  2768. _variant_t vtEmptyStr(EMPTY_DB_STR);
  2769. m_pcmdUpdSchedule->CreateParameter(L"prm_ScheduleID", XTPADODB::adInteger, XTPADODB::adParamInput, -1, vtEmpty);
  2770. m_pcmdUpdSchedule->CreateParameter(L"prm_Name", XTPADODB::adBSTR, XTPADODB::adParamInput, 0, vtEmptyStr);
  2771. m_pcmdUpdSchedule->CreateParameter(L"prm_CustomPropertiesXMLData", XTPADODB::adBSTR, XTPADODB::adParamInput, 0, vtEmptyStr);
  2772. m_pcmdUpdSchedule->CreateParameter(L"prm_Modified", XTPADODB::adDate, XTPADODB::adParamInput, -1, vtEmpty);
  2773. }
  2774. /////////////////////////////////////////////////////////////////////////////
  2775. // CADOCommand
  2776. CXTPCalendarDatabaseDataProvider::CADOCommand::CADOCommand(XTPADODB::_ConnectionPtr pConnection, LPCWSTR pcszSQLText)
  2777. {
  2778. m_pconnDb = NULL;
  2779. try
  2780. {
  2781. m_pcmdSQL.CreateInstance(__uuidof(XTPADODB::Command));
  2782. m_pcmdSQL->ActiveConnection = pConnection.GetInterfacePtr();
  2783. m_pcmdSQL->CommandText = pcszSQLText;
  2784. m_pconnDb = pConnection.GetInterfacePtr();
  2785. }
  2786. catch (_com_error &e)
  2787. {
  2788. TRACE_ProviderError(m_pconnDb);
  2789. TRACE_ComError(e);
  2790. }
  2791. catch(...)
  2792. {
  2793. TRACE(_T("Unknown error in CADOCommand() n"));
  2794. }
  2795. }
  2796. CXTPCalendarDatabaseDataProvider::CADOCommand::~CADOCommand()
  2797. {
  2798. m_pconnDb = NULL;
  2799. }
  2800. void CXTPCalendarDatabaseDataProvider::CADOCommand::SetSQLString(LPCWSTR pcszSQLText)
  2801. {
  2802. try
  2803. {
  2804. m_pcmdSQL->CommandText = pcszSQLText;
  2805. }
  2806. catch (_com_error &e)
  2807. {
  2808. TRACE_ProviderError(m_pconnDb);
  2809. TRACE_ComError(e);
  2810. }
  2811. catch(...)
  2812. {
  2813. TRACE(_T("Unknown error in CADOCommand::SetSQLString() n"));
  2814. }
  2815. }
  2816. void CXTPCalendarDatabaseDataProvider::CADOCommand::SetParameter(
  2817. XTPADODB::DataTypeEnum adDataType,
  2818. long nSize,
  2819. const _variant_t& vtValue)
  2820. {
  2821. CreateParameter(L"",
  2822. adDataType,
  2823. XTPADODB::adParamInput,
  2824. nSize,
  2825. vtValue);
  2826. }
  2827. void CXTPCalendarDatabaseDataProvider::CADOCommand::CreateParameter(
  2828. LPCWSTR pcszParamName,
  2829. XTPADODB::DataTypeEnum adDataType,
  2830. XTPADODB::ParameterDirectionEnum adDirection,
  2831. long nSize,
  2832. const _variant_t& vtValue)
  2833. {
  2834. XTPADODB::_ParameterPtr pParam = NULL;
  2835. try
  2836. {
  2837. pParam = m_pcmdSQL->CreateParameter(pcszParamName,
  2838.  adDataType,
  2839.  adDirection,
  2840.  nSize,
  2841.  vtValue
  2842.   );
  2843. m_pcmdSQL->Parameters->Append(pParam);
  2844. }
  2845. catch (_com_error &e)
  2846. {
  2847. TRACE_ProviderError(m_pconnDb);
  2848. TRACE_ComError(e);
  2849. }
  2850. catch (...)
  2851. {
  2852. TRACE(_T("Unknown error in CreateParameter() n"));
  2853. }
  2854. }
  2855. void CXTPCalendarDatabaseDataProvider::CADOCommand::SetParameterValue(LPCWSTR pcszParamName, const _variant_t& vtValue)
  2856. {
  2857. try
  2858. {
  2859. m_pcmdSQL->GetParameters()->GetItem(pcszParamName)->PutValue(vtValue);
  2860. }
  2861. catch (_com_error &e)
  2862. {
  2863. TRACE_ProviderError(m_pconnDb);
  2864. TRACE_ComError(e);
  2865. }
  2866. catch(...)
  2867. {
  2868. TRACE(_T("Unknown error in CADOCommand() n"));
  2869. }
  2870. }
  2871. XTPADODB::_RecordsetPtr CXTPCalendarDatabaseDataProvider::CADOCommand::Execute()
  2872. {
  2873. XTPADODB::_RecordsetPtr pRecordSet = NULL;
  2874. try
  2875. {
  2876. pRecordSet = m_pcmdSQL->Execute(NULL, NULL, XTPADODB::adCmdText);
  2877. return pRecordSet;
  2878. }
  2879. catch (_com_error &e)
  2880. {
  2881. //ClearParams();
  2882. TRACE_ProviderError(m_pconnDb);
  2883. TRACE_ComError(e);
  2884. }
  2885. catch(...)
  2886. {
  2887. TRACE(_T("Unknown error in Execute() n"));
  2888. }
  2889. ASSERT(FALSE);
  2890. return NULL;
  2891. }
  2892. void CXTPCalendarDatabaseDataProvider::CADOCommand::ClearParams()
  2893. {
  2894. long nParamCount = m_pcmdSQL->Parameters->Count;
  2895. for (long nParamCounter = 0; nParamCount > nParamCounter; nParamCounter++)
  2896. {
  2897. try
  2898. {
  2899. m_pcmdSQL->Parameters->Delete(_variant_t((long)nParamCounter));
  2900. }
  2901. catch(...)
  2902. {
  2903. TRACE(_T("Unknown error in ClearParams() n"));
  2904. }
  2905. }
  2906. }