DialogBalance.cpp
上传用户:xiaoke98
上传日期:2014-06-29
资源大小:5718k
文件大小:7k
源码类别:

家庭/个人应用

开发平台:

Visual C++

  1. // DialogBalance.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "HomeFinanceManager.h"
  5. #include "DialogBalance.h"
  6. #include "DBOperator.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CDialogBalance dialog
  14. CDialogBalance::CDialogBalance(CWnd* pParent /*=NULL*/)
  15. : CDialog(CDialogBalance::IDD, pParent)
  16. {
  17. //{{AFX_DATA_INIT(CDialogBalance)
  18. m_timeStart = 0;
  19. m_timeEnd = 0;
  20. m_strBalanceIn = _T("");
  21. m_strBalanceOut = _T("");
  22. m_strBalanceSurplus = _T("");
  23. //}}AFX_DATA_INIT
  24. }
  25. void CDialogBalance::DoDataExchange(CDataExchange* pDX)
  26. {
  27. CDialog::DoDataExchange(pDX);
  28. //{{AFX_DATA_MAP(CDialogBalance)
  29. DDX_Control(pDX, IDC_SEARCH, m_btnSearch);
  30. DDX_Control(pDX, IDC_TREE_BALANCE, m_treeBalance);
  31. DDX_DateTimeCtrl(pDX, IDC_STARTTIME, m_timeStart);
  32. DDX_DateTimeCtrl(pDX, IDC_ENDTIME, m_timeEnd);
  33. DDX_Text(pDX, IDC_BALANCE_IN, m_strBalanceIn);
  34. DDX_Text(pDX, IDC_BALANCE_OUT, m_strBalanceOut);
  35. DDX_Text(pDX, IDC_BALANCE_SURPLUS, m_strBalanceSurplus);
  36. //}}AFX_DATA_MAP
  37. }
  38. BEGIN_MESSAGE_MAP(CDialogBalance, CDialog)
  39. //{{AFX_MSG_MAP(CDialogBalance)
  40. ON_BN_CLICKED(IDC_SEARCH, OnSearch)
  41. //}}AFX_MSG_MAP
  42. ON_WM_ERASEBKGND() 
  43. ON_WM_CTLCOLOR()
  44. END_MESSAGE_MAP()
  45. /////////////////////////////////////////////////////////////////////////////
  46. // CDialogBalance message handlers
  47. //-----------------------------------------------------------------------------
  48. BOOL CDialogBalance::OnInitDialog()
  49. {
  50. CDialog::OnInitDialog();
  51. m_timeStart = CTime::GetCurrentTime();
  52. m_timeEnd = CTime::GetCurrentTime();
  53. this->UpdateData(FALSE);
  54. return TRUE;
  55. }
  56. //-----------------------------------------------------------------------------
  57. void  CDialogBalance::DispalyBackBmp(CDC* pDC)
  58. {
  59. CBitmap Bitmap;
  60. Bitmap.LoadBitmap(IDB_MAINBACK);
  61. BITMAP bmpInfo;
  62. Bitmap.GetBitmap(&bmpInfo);
  63. CDC* pDlgDC = this->GetDC();
  64. CDC MemDC;
  65. MemDC.CreateCompatibleDC(pDlgDC);
  66. MemDC.SelectObject(Bitmap);
  67. RECT rcClient;
  68. this->GetClientRect(&rcClient);
  69. int iWidth = rcClient.right - rcClient.left;
  70. int iHeight = rcClient.bottom - rcClient.top;
  71. pDC->BitBlt(0, 0, iWidth, iHeight, &MemDC, 0, 0,SRCCOPY);
  72. }
  73. //-----------------------------------------------------------------------------
  74. //绘制位图
  75. BOOL CDialogBalance::OnEraseBkgnd( CDC* pDC )
  76. {
  77. DispalyBackBmp(pDC);
  78. return TRUE;
  79. }
  80. //-----------------------------------------------------------------------------
  81. HBRUSH CDialogBalance::OnCtlColor( CDC* pDC, CWnd* pWnd, UINT nCtlColor)
  82. {
  83. HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
  84. //改变控件的颜色
  85. if(nCtlColor == CTLCOLOR_STATIC)
  86. {
  87. pDC->SetBkMode(TRANSPARENT);
  88. pDC->SetTextColor(RGB(0,255,0));
  89. LOGBRUSH  logBrush;
  90. logBrush.lbStyle = BS_HOLLOW;
  91. hbr = CreateBrushIndirect(&logBrush);
  92. }
  93. if(nCtlColor == CTLCOLOR_EDIT)
  94. {
  95. pDC->SetTextColor(RGB(255,0,0));//字体色
  96. //pDC->SetBkColor(RGB(170, 243, 162));
  97. }
  98. return hbr;
  99. }
  100. //-----------------------------------------------------------------------------
  101. void CDialogBalance::OnOK( )
  102. {
  103. }
  104. //-----------------------------------------------------------------------------
  105. void CDialogBalance::SearchBalance(CString& strStartTime, 
  106. CString& strEndTime, 
  107. CString& strBalanceIn, 
  108. CString& strBalanceOut)
  109. {
  110. gDBOperator.getBalance(strStartTime, strEndTime, m_treeBalance, strBalanceIn, strBalanceOut);
  111. double dBalanceIn = atof(strBalanceIn);
  112. double dBalanceOut = atof(strBalanceOut);
  113. double dBalanceSurplus = dBalanceIn - dBalanceOut;
  114. m_strBalanceSurplus.Format("%5.2f", dBalanceSurplus);
  115. CSysDataStruct::CClassInfo ClassInfo;
  116. gDBOperator.getMoneyInClassTotal(strStartTime, strEndTime, ClassInfo);
  117. CSysDataStruct::CClassInfo OutClass;
  118. gDBOperator.getMoneyOutClassTotal(strStartTime, strEndTime, OutClass);
  119. m_treeBalance.DeleteAllItems();
  120. TVINSERTSTRUCT CondtionRoot;
  121. CondtionRoot.hParent = TVI_ROOT;
  122. CondtionRoot.hInsertAfter = TVI_LAST;
  123. CondtionRoot.item.mask = TVIF_TEXT;
  124. CString strCondtion;
  125. strCondtion.Format("从%s到%s的收支情况表", strStartTime, strEndTime);
  126. CondtionRoot.item.pszText = strCondtion.GetBuffer(0);
  127. m_treeBalance.InsertItem(&CondtionRoot);
  128. TVINSERTSTRUCT InRoot;
  129. InRoot.hParent = TVI_ROOT;
  130. InRoot.hInsertAfter = TVI_LAST;
  131. InRoot.item.mask = TVIF_TEXT;
  132. CString strMoneyIn;
  133. strMoneyIn.Format("收入:%s元", strBalanceIn);
  134. InRoot.item.pszText = strMoneyIn.GetBuffer(0);
  135. HTREEITEM  hInRoot = m_treeBalance.InsertItem(&InRoot);
  136. for(int i = 0; i < ClassInfo.m_iClassNum; i++)
  137. {
  138. TVINSERTSTRUCT InClassItem;
  139. InClassItem.hParent = hInRoot;
  140. InClassItem.hInsertAfter = TVI_LAST;
  141. InClassItem.item.mask = TVIF_TEXT;
  142. if(ClassInfo.m_dTotal[i] > 0.001)
  143. {
  144. CString strTotalInfo;
  145. strTotalInfo.Format("%s:%4.2f元", ClassInfo.m_Classes[i], ClassInfo.m_dTotal[i]);
  146. InClassItem.item.pszText = strTotalInfo.GetBuffer(0);
  147. m_treeBalance.InsertItem(&InClassItem);
  148. }
  149. }
  150. TVINSERTSTRUCT OutRoot;
  151. OutRoot.hParent = TVI_ROOT;
  152. OutRoot.hInsertAfter = TVI_LAST;
  153. OutRoot.item.mask = TVIF_TEXT;
  154. CString strMoneyOut;
  155. strMoneyOut.Format("支出:%s元", strBalanceOut);
  156. OutRoot.item.pszText = strMoneyOut.GetBuffer(0);
  157. HTREEITEM  hOutRoot = m_treeBalance.InsertItem(&OutRoot);
  158. for(int j = 0; j < OutClass.m_iClassNum; j++)
  159. {
  160. TVINSERTSTRUCT OutClassItem;
  161. OutClassItem.hParent = hOutRoot;
  162. OutClassItem.hInsertAfter = TVI_LAST;
  163. OutClassItem.item.mask = TVIF_TEXT;
  164. if(OutClass.m_dTotal[j] > 0.001)
  165. {
  166. CString strTotalInfo;
  167. strTotalInfo.Format("%s:%4.2f元", OutClass.m_Classes[j], OutClass.m_dTotal[j]);
  168. OutClassItem.item.pszText = strTotalInfo.GetBuffer(0);
  169. m_treeBalance.InsertItem(&OutClassItem);
  170. }
  171. }
  172. m_treeBalance.Expand(hInRoot, TVE_EXPAND);
  173. m_treeBalance.Expand(hOutRoot, TVE_EXPAND);
  174. this->UpdateData(FALSE);
  175. }
  176. //-----------------------------------------------------------------------------------------------
  177. void CDialogBalance::OnSearch() 
  178. {
  179. // TODO: Add your control notification handler code here
  180. UpdateData(TRUE);
  181. CString strStartTime;
  182. CString strEndTime;
  183. strStartTime.Format("%d-%d-%d", 
  184. m_timeStart.GetYear(),
  185.    m_timeStart.GetMonth(),
  186.    m_timeStart.GetDay());
  187. strEndTime.Format("%d-%d-%d", 
  188. m_timeEnd.GetYear(),
  189. m_timeEnd.GetMonth(),
  190. m_timeEnd.GetDay());
  191. SearchBalance(strStartTime, strEndTime, m_strBalanceIn, m_strBalanceOut);
  192. }