DialogBalance.cpp
上传用户:xiaoke98
上传日期:2014-06-29
资源大小:5718k
文件大小:7k
- // DialogBalance.cpp : implementation file
- //
- #include "stdafx.h"
- #include "HomeFinanceManager.h"
- #include "DialogBalance.h"
- #include "DBOperator.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CDialogBalance dialog
- CDialogBalance::CDialogBalance(CWnd* pParent /*=NULL*/)
- : CDialog(CDialogBalance::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CDialogBalance)
- m_timeStart = 0;
- m_timeEnd = 0;
- m_strBalanceIn = _T("");
- m_strBalanceOut = _T("");
- m_strBalanceSurplus = _T("");
- //}}AFX_DATA_INIT
- }
- void CDialogBalance::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CDialogBalance)
- DDX_Control(pDX, IDC_SEARCH, m_btnSearch);
- DDX_Control(pDX, IDC_TREE_BALANCE, m_treeBalance);
- DDX_DateTimeCtrl(pDX, IDC_STARTTIME, m_timeStart);
- DDX_DateTimeCtrl(pDX, IDC_ENDTIME, m_timeEnd);
- DDX_Text(pDX, IDC_BALANCE_IN, m_strBalanceIn);
- DDX_Text(pDX, IDC_BALANCE_OUT, m_strBalanceOut);
- DDX_Text(pDX, IDC_BALANCE_SURPLUS, m_strBalanceSurplus);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CDialogBalance, CDialog)
- //{{AFX_MSG_MAP(CDialogBalance)
- ON_BN_CLICKED(IDC_SEARCH, OnSearch)
- //}}AFX_MSG_MAP
- ON_WM_ERASEBKGND()
- ON_WM_CTLCOLOR()
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CDialogBalance message handlers
- //-----------------------------------------------------------------------------
- BOOL CDialogBalance::OnInitDialog()
- {
- CDialog::OnInitDialog();
- m_timeStart = CTime::GetCurrentTime();
- m_timeEnd = CTime::GetCurrentTime();
-
- this->UpdateData(FALSE);
-
- return TRUE;
- }
- //-----------------------------------------------------------------------------
- void CDialogBalance::DispalyBackBmp(CDC* pDC)
- {
- CBitmap Bitmap;
- Bitmap.LoadBitmap(IDB_MAINBACK);
-
- BITMAP bmpInfo;
- Bitmap.GetBitmap(&bmpInfo);
-
-
- CDC* pDlgDC = this->GetDC();
- CDC MemDC;
- MemDC.CreateCompatibleDC(pDlgDC);
- MemDC.SelectObject(Bitmap);
-
- RECT rcClient;
- this->GetClientRect(&rcClient);
- int iWidth = rcClient.right - rcClient.left;
- int iHeight = rcClient.bottom - rcClient.top;
-
-
- pDC->BitBlt(0, 0, iWidth, iHeight, &MemDC, 0, 0,SRCCOPY);
- }
- //-----------------------------------------------------------------------------
- //绘制位图
- BOOL CDialogBalance::OnEraseBkgnd( CDC* pDC )
- {
- DispalyBackBmp(pDC);
- return TRUE;
- }
- //-----------------------------------------------------------------------------
- HBRUSH CDialogBalance::OnCtlColor( CDC* pDC, CWnd* pWnd, UINT nCtlColor)
- {
- HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
- //改变控件的颜色
- if(nCtlColor == CTLCOLOR_STATIC)
- {
- pDC->SetBkMode(TRANSPARENT);
- pDC->SetTextColor(RGB(0,255,0));
-
- LOGBRUSH logBrush;
- logBrush.lbStyle = BS_HOLLOW;
- hbr = CreateBrushIndirect(&logBrush);
- }
- if(nCtlColor == CTLCOLOR_EDIT)
- {
- pDC->SetTextColor(RGB(255,0,0));//字体色
- //pDC->SetBkColor(RGB(170, 243, 162));
- }
-
- return hbr;
- }
- //-----------------------------------------------------------------------------
- void CDialogBalance::OnOK( )
- {
-
- }
- //-----------------------------------------------------------------------------
- void CDialogBalance::SearchBalance(CString& strStartTime,
- CString& strEndTime,
- CString& strBalanceIn,
- CString& strBalanceOut)
- {
- gDBOperator.getBalance(strStartTime, strEndTime, m_treeBalance, strBalanceIn, strBalanceOut);
- double dBalanceIn = atof(strBalanceIn);
- double dBalanceOut = atof(strBalanceOut);
- double dBalanceSurplus = dBalanceIn - dBalanceOut;
- m_strBalanceSurplus.Format("%5.2f", dBalanceSurplus);
-
- CSysDataStruct::CClassInfo ClassInfo;
- gDBOperator.getMoneyInClassTotal(strStartTime, strEndTime, ClassInfo);
-
- CSysDataStruct::CClassInfo OutClass;
- gDBOperator.getMoneyOutClassTotal(strStartTime, strEndTime, OutClass);
-
-
- m_treeBalance.DeleteAllItems();
-
- TVINSERTSTRUCT CondtionRoot;
- CondtionRoot.hParent = TVI_ROOT;
- CondtionRoot.hInsertAfter = TVI_LAST;
- CondtionRoot.item.mask = TVIF_TEXT;
- CString strCondtion;
- strCondtion.Format("从%s到%s的收支情况表", strStartTime, strEndTime);
- CondtionRoot.item.pszText = strCondtion.GetBuffer(0);
- m_treeBalance.InsertItem(&CondtionRoot);
-
- TVINSERTSTRUCT InRoot;
- InRoot.hParent = TVI_ROOT;
- InRoot.hInsertAfter = TVI_LAST;
- InRoot.item.mask = TVIF_TEXT;
- CString strMoneyIn;
- strMoneyIn.Format("收入:%s元", strBalanceIn);
- InRoot.item.pszText = strMoneyIn.GetBuffer(0);
- HTREEITEM hInRoot = m_treeBalance.InsertItem(&InRoot);
- for(int i = 0; i < ClassInfo.m_iClassNum; i++)
- {
- TVINSERTSTRUCT InClassItem;
- InClassItem.hParent = hInRoot;
- InClassItem.hInsertAfter = TVI_LAST;
- InClassItem.item.mask = TVIF_TEXT;
-
- if(ClassInfo.m_dTotal[i] > 0.001)
- {
- CString strTotalInfo;
- strTotalInfo.Format("%s:%4.2f元", ClassInfo.m_Classes[i], ClassInfo.m_dTotal[i]);
- InClassItem.item.pszText = strTotalInfo.GetBuffer(0);
- m_treeBalance.InsertItem(&InClassItem);
- }
-
- }
-
- TVINSERTSTRUCT OutRoot;
- OutRoot.hParent = TVI_ROOT;
- OutRoot.hInsertAfter = TVI_LAST;
- OutRoot.item.mask = TVIF_TEXT;
-
- CString strMoneyOut;
- strMoneyOut.Format("支出:%s元", strBalanceOut);
- OutRoot.item.pszText = strMoneyOut.GetBuffer(0);
- HTREEITEM hOutRoot = m_treeBalance.InsertItem(&OutRoot);
- for(int j = 0; j < OutClass.m_iClassNum; j++)
- {
- TVINSERTSTRUCT OutClassItem;
- OutClassItem.hParent = hOutRoot;
- OutClassItem.hInsertAfter = TVI_LAST;
- OutClassItem.item.mask = TVIF_TEXT;
-
- if(OutClass.m_dTotal[j] > 0.001)
- {
- CString strTotalInfo;
- strTotalInfo.Format("%s:%4.2f元", OutClass.m_Classes[j], OutClass.m_dTotal[j]);
- OutClassItem.item.pszText = strTotalInfo.GetBuffer(0);
- m_treeBalance.InsertItem(&OutClassItem);
- }
-
- }
-
-
-
- m_treeBalance.Expand(hInRoot, TVE_EXPAND);
- m_treeBalance.Expand(hOutRoot, TVE_EXPAND);
-
-
- this->UpdateData(FALSE);
- }
- //-----------------------------------------------------------------------------------------------
- void CDialogBalance::OnSearch()
- {
- // TODO: Add your control notification handler code here
- UpdateData(TRUE);
- CString strStartTime;
- CString strEndTime;
- strStartTime.Format("%d-%d-%d",
- m_timeStart.GetYear(),
- m_timeStart.GetMonth(),
- m_timeStart.GetDay());
- strEndTime.Format("%d-%d-%d",
- m_timeEnd.GetYear(),
- m_timeEnd.GetMonth(),
- m_timeEnd.GetDay());
-
-
- SearchBalance(strStartTime, strEndTime, m_strBalanceIn, m_strBalanceOut);
-
- }