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

对话框与窗口

开发平台:

Visual C++

  1. // MessageRecord.cpp: implementation of the CMessageRecord class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "ReportDialog.h"
  6. #include "MessageRecord.h"
  7. #ifdef _DEBUG
  8. #undef THIS_FILE
  9. static char THIS_FILE[]=__FILE__;
  10. #define new DEBUG_NEW
  11. #endif
  12. IMPLEMENT_SERIAL(CMessageRecord, CXTPReportRecord, VERSIONABLE_SCHEMA | _XTP_SCHEMA_CURRENT)
  13. IMPLEMENT_SERIAL(CMessageRecordItemPrice, CXTPReportRecordItemNumber, VERSIONABLE_SCHEMA | _XTP_SCHEMA_CURRENT)
  14. IMPLEMENT_SERIAL(CMessageRecordItemCheck, CXTPReportRecordItem, VERSIONABLE_SCHEMA | _XTP_SCHEMA_CURRENT)
  15. IMPLEMENT_SERIAL(CMessageRecordItemImportance, CXTPReportRecordItem, VERSIONABLE_SCHEMA | _XTP_SCHEMA_CURRENT)
  16. IMPLEMENT_SERIAL(CMessageRecordItemAttachment, CXTPReportRecordItem, VERSIONABLE_SCHEMA | _XTP_SCHEMA_CURRENT)
  17. IMPLEMENT_SERIAL(CMessageRecordItemIcon, CXTPReportRecordItem, VERSIONABLE_SCHEMA | _XTP_SCHEMA_CURRENT)
  18. IMPLEMENT_SERIAL(CMessageRecordItemDate, CXTPReportRecordItemDateTime, VERSIONABLE_SCHEMA | _XTP_SCHEMA_CURRENT)
  19. //////////////////////////////////////////////////////////////////////////
  20. // CMessageRecordItemPrice
  21. CMessageRecordItemPrice::CMessageRecordItemPrice(double dValue)
  22. : CXTPReportRecordItemNumber(dValue, _T("$ %.2f"))
  23. {
  24. }
  25. CString CMessageRecordItemPrice::GetGroupCaption(CXTPReportColumn* /*pColumn*/)
  26. {
  27. if (m_dValue > 20)
  28. return _T("Record Price > 20");
  29. if (m_dValue > 5)
  30. return _T("Record Price 5 - 20");
  31. return _T("Record Price < 5");
  32. }
  33. int CMessageRecordItemPrice::CompareGroupCaption(CXTPReportColumn* pColumn, CXTPReportRecordItem* pItem)
  34. {
  35. return GetGroupCaption(pColumn).Compare(pItem->GetGroupCaption(pColumn));
  36. }
  37. //////////////////////////////////////////////////////////////////////////
  38. // CMessageRecordItemCheck
  39. CMessageRecordItemCheck::CMessageRecordItemCheck(BOOL bCheck)
  40. {
  41. HasCheckbox(TRUE);
  42. SetChecked(bCheck);
  43. }
  44. int CMessageRecordItemCheck::GetGroupCaptionID(CXTPReportColumn* /*pColumn*/)
  45. {
  46. return IsChecked()? IDS_GROUP_CHECKED_TRUE: IDS_GROUP_CHECKED_FALSE;
  47. }
  48. int CMessageRecordItemCheck::Compare(CXTPReportColumn* /*pColumn*/, CXTPReportRecordItem* pItem)
  49. {
  50. return int(IsChecked()) - int(pItem->IsChecked());
  51. }
  52. //////////////////////////////////////////////////////////////////////////
  53. // CMessageRecordItemImportance
  54. CMessageRecordItemImportance::CMessageRecordItemImportance(MESSAGE_IMPORTANCE eImportance)
  55. : m_eImportance(eImportance)
  56. {
  57. SetIconIndex(eImportance == msgImportanceHigh ? 6 :
  58.  eImportance == msgImportanceLow ? 9: -1);
  59. SetGroupPriority(
  60. m_eImportance == msgImportanceHigh? IDS_GROUP_IMPOPRTANCE_HIGH:
  61. m_eImportance == msgImportanceLow?  IDS_GROUP_IMPOPRTANCE_LOW: IDS_GROUP_IMPOPRTANCE_NORMAL);
  62. SetSortPriority(GetGroupPriority());
  63. CString strToolTip;
  64. strToolTip.LoadString(GetGroupPriority());
  65. SetTooltip(strToolTip);
  66. }
  67. void CMessageRecordItemImportance::DoPropExchange(CXTPPropExchange* pPX)
  68. {
  69. CXTPReportRecordItem::DoPropExchange(pPX);
  70. PX_Enum(pPX, _T("Importance"), m_eImportance, msgImportanceNormal);
  71. }
  72. //////////////////////////////////////////////////////////////////////////
  73. // CMessageRecordItemAttachment
  74. CMessageRecordItemAttachment::CMessageRecordItemAttachment(BOOL bHasAttachment)
  75. : m_bHasAttachment(bHasAttachment)
  76. {
  77. SetIconIndex(bHasAttachment ? 8 : -1);
  78. SetGroupPriority(m_bHasAttachment? IDS_GROUP_ATTACHMENTS_TRUE: IDS_GROUP_ATTACHMENTS_FALSE);
  79. SetSortPriority(GetGroupPriority());
  80. }
  81. void CMessageRecordItemAttachment::DoPropExchange(CXTPPropExchange* pPX)
  82. {
  83. CXTPReportRecordItem::DoPropExchange(pPX);
  84. PX_Bool(pPX, _T("HasAttachment"), m_bHasAttachment);
  85. }
  86. //////////////////////////////////////////////////////////////////////////
  87. // CMessageRecordItemIcon
  88. CMessageRecordItemIcon::CMessageRecordItemIcon(BOOL bRead)
  89. : m_bRead(bRead)
  90. {
  91. UpdateReadIcon();
  92. }
  93. void CMessageRecordItemIcon::UpdateReadIcon()
  94. {
  95. SetIconIndex(m_bRead ? 4 : 3);
  96. }
  97. int CMessageRecordItemIcon::Compare(CXTPReportColumn* /*pColumn*/, CXTPReportRecordItem* pItem)
  98. {
  99. return int(m_bRead) - int(((CMessageRecordItemIcon*)pItem)->m_bRead);
  100. }
  101. CString CMessageRecordItemIcon::GetGroupCaption(CXTPReportColumn* /*pColumn*/)
  102. {
  103. if (m_bRead)
  104. return _T("Message status: Read");
  105. else
  106. return _T("Message status: Unread");
  107. }
  108. int CMessageRecordItemIcon::CompareGroupCaption(CXTPReportColumn* pColumn, CXTPReportRecordItem* pItem)
  109. {
  110. return GetGroupCaption(pColumn).Compare(pItem->GetGroupCaption(pColumn));
  111. }
  112. void CMessageRecordItemIcon::DoPropExchange(CXTPPropExchange* pPX)
  113. {
  114. CXTPReportRecordItem::DoPropExchange(pPX);
  115. PX_Bool(pPX, _T("Read"), m_bRead);
  116. }
  117. //////////////////////////////////////////////////////////////////////////
  118. // CMessageRecordItemSent
  119. CMessageRecordItemDate::CMessageRecordItemDate(COleDateTime odtValue)
  120. : CXTPReportRecordItemDateTime(odtValue)
  121. {
  122. }
  123. int CMessageRecordItemDate::GetGroupCaptionID(CXTPReportColumn* /*pColumn*/)
  124. {
  125. COleDateTime odtNow(COleDateTime::GetCurrentTime());
  126. if (m_odtValue.GetYear() < odtNow.GetYear())
  127. return IDS_GROUP_DATE_OLDER;
  128. if (m_odtValue.GetMonth() < odtNow.GetMonth())
  129. return IDS_GROUP_DATE_THISYEAR;
  130. if (m_odtValue.GetDay() < odtNow.GetDay())
  131. return IDS_GROUP_DATE_THISMONTH;
  132. if (m_odtValue.m_dt <= odtNow.m_dt)
  133. return IDS_GROUP_DATE_TODAY;
  134. return -1;
  135. }
  136. //////////////////////////////////////////////////////////////////////
  137. // CMessageRecord class
  138. //////////////////////////////////////////////////////////////////////
  139. // Construction/Destruction
  140. //////////////////////////////////////////////////////////////////////
  141. CMessageRecord::CMessageRecord()
  142. {
  143. m_pItemIcon = NULL;
  144. m_pItemReceived = NULL;
  145. m_pItemSize = NULL;
  146. CreateItems();
  147. }
  148. CMessageRecord::CMessageRecord(
  149. MESSAGE_IMPORTANCE eImportance, BOOL bChecked, int  nAttachmentBitmap,
  150. CString strFromName, CString strSubject,
  151. COleDateTime odtReceived, int nMessageSize, BOOL bRead,
  152. double dPrice, COleDateTime odtSent, COleDateTime odtCreated,
  153. CString strConversation, CString strContact, CString strMessage,
  154. CString strCC, CString strCategories, CString strAutoforward,
  155. CString strDoNotAutoarch, CString strDueBy,
  156. CString strPreview)
  157. {
  158. AddItem(new CMessageRecordItemImportance(eImportance));
  159. m_pItemIcon = (CMessageRecordItemIcon*)AddItem(new CMessageRecordItemIcon(bRead));
  160. AddItem(new CMessageRecordItemAttachment(nAttachmentBitmap));
  161. AddItem(new CXTPReportRecordItemText(strFromName));
  162. AddItem(new CXTPReportRecordItemText(strSubject));
  163. m_pItemReceived = (CMessageRecordItemDate*)AddItem(new CMessageRecordItemDate(odtReceived));
  164. m_pItemSize = AddItem(new CXTPReportRecordItemNumber(nMessageSize));
  165. AddItem(new CMessageRecordItemCheck(bChecked));
  166. AddItem(new CMessageRecordItemPrice(dPrice));
  167. AddItem(new CMessageRecordItemDate(odtCreated));
  168. AddItem(new CMessageRecordItemDate(odtSent));
  169. AddItem(new CXTPReportRecordItemText(strConversation));
  170. AddItem(new CXTPReportRecordItemText(strContact));
  171. AddItem(new CXTPReportRecordItemText(strMessage));
  172. AddItem(new CXTPReportRecordItemText(strCC));
  173. AddItem(new CXTPReportRecordItemText(strCategories));
  174. AddItem(new CXTPReportRecordItemText(strAutoforward));
  175. AddItem(new CXTPReportRecordItemText(strDoNotAutoarch));
  176. AddItem(new CXTPReportRecordItemText(strDueBy));
  177. SetPreviewItem(new CXTPReportRecordItemPreview(strPreview));
  178. }
  179. void CMessageRecord::CreateItems()
  180. {
  181. // Initialize record items with empty values
  182. COleDateTime dtNow(COleDateTime::GetCurrentTime());
  183. // 0 
  184. AddItem(new CMessageRecordItemImportance(msgImportanceNormal));
  185. // 1 ***
  186. m_pItemIcon = (CMessageRecordItemIcon*)AddItem(new CMessageRecordItemIcon(TRUE));
  187. // 2 
  188. AddItem(new CMessageRecordItemAttachment(0));
  189. // 3 
  190. AddItem(new CXTPReportRecordItemText(_T("")));
  191. // 4 
  192. AddItem(new CXTPReportRecordItemText(_T("")));
  193. // 5 ***
  194. m_pItemReceived = (CMessageRecordItemDate*)AddItem(new CMessageRecordItemDate(dtNow));
  195. // 6 ***
  196. m_pItemSize = AddItem(new CXTPReportRecordItemNumber(0));
  197. AddItem(new CMessageRecordItemCheck(FALSE));
  198. AddItem(new CMessageRecordItemPrice(0));
  199. AddItem(new CMessageRecordItemDate(dtNow));
  200. AddItem(new CMessageRecordItemDate(dtNow));
  201. AddItem(new CXTPReportRecordItemText(_T("")));
  202. AddItem(new CXTPReportRecordItemText(_T("")));
  203. AddItem(new CXTPReportRecordItemText(_T("")));
  204. AddItem(new CXTPReportRecordItemText(_T("")));
  205. AddItem(new CXTPReportRecordItemText(_T("")));
  206. AddItem(new CXTPReportRecordItemText(_T("")));
  207. AddItem(new CXTPReportRecordItemText(_T("")));
  208. AddItem(new CXTPReportRecordItemText(_T("")));
  209. SetPreviewItem(new CXTPReportRecordItemPreview(_T("")));
  210. }
  211. CMessageRecord::~CMessageRecord()
  212. {
  213. }
  214. BOOL CMessageRecord::SetRead()
  215. {
  216. ASSERT(m_pItemIcon);
  217. if (m_pItemIcon->m_bRead)
  218. return FALSE;
  219. m_pItemIcon->m_bRead = TRUE;
  220. m_pItemIcon->UpdateReadIcon();
  221. return TRUE;
  222. }
  223. void CMessageRecord::GetItemMetrics(XTP_REPORTRECORDITEM_DRAWARGS* pDrawArgs, XTP_REPORTRECORDITEM_METRICS* pItemMetrics)
  224. {
  225. CXTPReportRecord::GetItemMetrics(pDrawArgs, pItemMetrics);
  226. }
  227. void CMessageRecord::DoPropExchange(CXTPPropExchange* pPX)
  228. {
  229. CXTPReportRecord::DoPropExchange(pPX);
  230. if (pPX->IsLoading())
  231. {
  232. // 1 - m_pItemIcon = (CMessageRecordItemIcon*)AddItem(new CMessageRecordItemIcon(TRUE));
  233. ASSERT_KINDOF(CMessageRecordItemIcon, GetItem(1));
  234. m_pItemIcon = DYNAMIC_DOWNCAST(CMessageRecordItemIcon, GetItem(1));
  235. ASSERT(m_pItemIcon);
  236. // 5 - m_pItemReceived = (CMessageRecordItemDate*)AddItem(new CMessageRecordItemDate(dtNow));
  237. ASSERT_KINDOF(CMessageRecordItemDate, GetItem(5));
  238. m_pItemReceived = DYNAMIC_DOWNCAST(CMessageRecordItemDate, GetItem(5));
  239. ASSERT(m_pItemReceived);
  240. // 6 - m_pItemSize = AddItem(new CXTPReportRecordItemNumber(0));
  241. ASSERT_KINDOF(CXTPReportRecordItemNumber, GetItem(6));
  242. m_pItemSize = DYNAMIC_DOWNCAST(CXTPReportRecordItemNumber, GetItem(6));
  243. ASSERT(m_pItemSize);
  244. }
  245. }