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

家庭/个人应用

开发平台:

Visual C++

  1. // DialogFinanceQuery.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "HomeFinanceManager.h"
  5. #include "DialogFinanceQuery.h"
  6. #include "DBOperator.h"
  7. #include "DialogRecord.h"
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13. /////////////////////////////////////////////////////////////////////////////
  14. // CDialogFinanceQuery dialog
  15. CDialogFinanceQuery::CDialogFinanceQuery(CWnd* pParent /*=NULL*/)
  16. : CDialog(CDialogFinanceQuery::IDD, pParent)
  17. {
  18. //{{AFX_DATA_INIT(CDialogFinanceQuery)
  19. m_strTotalIn = _T("");
  20. m_dateEnd = 0;
  21. m_dateStart = 0;
  22. //}}AFX_DATA_INIT
  23. }
  24. void CDialogFinanceQuery::DoDataExchange(CDataExchange* pDX)
  25. {
  26. CDialog::DoDataExchange(pDX);
  27. //{{AFX_DATA_MAP(CDialogFinanceQuery)
  28. DDX_Control(pDX, IDC_BTN_QUERY, m_btnQuery);
  29. DDX_Text(pDX, IDC_TOTALIN, m_strTotalIn);
  30. DDX_DateTimeCtrl(pDX, IDC_DATE_END, m_dateEnd);
  31. DDX_DateTimeCtrl(pDX, IDC_DATE_START, m_dateStart);
  32. //}}AFX_DATA_MAP
  33. }
  34. BEGIN_MESSAGE_MAP(CDialogFinanceQuery, CDialog)
  35. //{{AFX_MSG_MAP(CDialogFinanceQuery)
  36. ON_BN_CLICKED(IDC_BTN_QUERY, OnBtnQuery)
  37. ON_WM_SHOWWINDOW()
  38. ON_NOTIFY(NM_DBLCLK, IDC_LISTCTRL_FIANCEDATE, OnClickDBgridFinanceIn)
  39. ON_NOTIFY(LVN_COLUMNCLICK, IDC_LISTCTRL_FIANCEDATE, OnColumnclickDBgridFinanceIn)
  40. //}}AFX_MSG_MAP
  41. ON_WM_ERASEBKGND() 
  42. ON_WM_CTLCOLOR()
  43. END_MESSAGE_MAP()
  44. /////////////////////////////////////////////////////////////////////////////
  45. // CDialogFinanceQuery message handlers
  46. void CDialogFinanceQuery::OnOK( )
  47. {
  48. }
  49. //-----------------------------------------------------------------------------
  50. BOOL CDialogFinanceQuery::OnInitDialog( )
  51. {
  52. CDialog::OnInitDialog();
  53. //显示收入dbgrid
  54. RECT rcClient;
  55. this->GetClientRect(&rcClient);
  56. rcClient.top += 200;
  57. rcClient.bottom += 90;
  58. m_dbgridFinanceIn.Create(LVS_REPORT, rcClient, this, IDC_LISTCTRL_FIANCEDATE);
  59. m_dbgridFinanceIn.ShowWindow(SW_SHOW);
  60. m_dateStart = CTime::GetCurrentTime();
  61. m_dateEnd = CTime::GetCurrentTime();
  62. this->UpdateData(FALSE);
  63. CButton* pRadio = (CButton*)GetDlgItem(IDC_ORDERBYASC);
  64. pRadio->SetCheck(TRUE);
  65. return TRUE;
  66. }
  67. //-----------------------------------------------------------------------------
  68. BOOL CDialogFinanceQuery::OnEraseBkgnd( CDC* pDC )
  69. {
  70. RECT rcClient;
  71. this->GetClientRect(&rcClient);
  72. HBRUSH hOldBrush;
  73. HBRUSH hBrush = ::CreateSolidBrush(RGB(213, 247, 209));
  74. hOldBrush = (HBRUSH)pDC->SelectObject(hBrush);
  75. pDC->Rectangle(&rcClient);
  76. pDC->SelectObject(hOldBrush);
  77. ::DeleteObject(hBrush);
  78. return TRUE;
  79. }
  80. //-----------------------------------------------------------------------------
  81. HBRUSH CDialogFinanceQuery::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,0,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 CDialogFinanceQuery::OnBtnQuery() 
  102. {
  103. // TODO: Add your control notification handler code here
  104. CString strStart;
  105. CString strEnd;
  106. UpdateData(TRUE);
  107. strStart.Format("%d-%d-%d", m_dateStart.GetYear(),
  108. m_dateStart.GetMonth(),
  109. m_dateStart.GetDay());
  110. strEnd.Format("%d-%d-%d", m_dateEnd.GetYear(),
  111. m_dateEnd.GetMonth(),
  112. m_dateEnd.GetDay());
  113. CString strTotalIn;
  114. gDBOperator.selectFinanceIn(strStart, strEnd, m_dbgridFinanceIn, strTotalIn);
  115. m_strTotalIn = strTotalIn;
  116. UpdateData(FALSE);
  117. }
  118. //-----------------------------------------------------------------------------
  119. void CDialogFinanceQuery::OnShowWindow(BOOL bShow, UINT nStatus) 
  120. {
  121. CDialog::OnShowWindow(bShow, nStatus);
  122. // TODO: Add your message handler code here
  123. OnBtnQuery();
  124. }
  125. //-----------------------------------------------------------------------------
  126. void CDialogFinanceQuery::OnClickDBgridFinanceIn(NMHDR* pNMHDR, LRESULT* pResult)
  127. {
  128. for(int i = 0; i < m_dbgridFinanceIn.GetItemCount(); i++)
  129. {
  130. if(m_dbgridFinanceIn.GetItemState(i, LVIS_SELECTED) == LVIS_SELECTED)
  131. {
  132. char strID[50];
  133. char strSum[50];
  134. char strClass[50];
  135. char strDate[50];
  136. char strOperator[50];
  137. char strRemark[200];
  138. m_dbgridFinanceIn.GetItemText(i, 0, strID, 50);
  139. m_dbgridFinanceIn.GetItemText(i, 1, strSum, 50);
  140. m_dbgridFinanceIn.GetItemText(i, 2, strClass, 50);
  141. m_dbgridFinanceIn.GetItemText(i, 3, strDate, 50);
  142. m_dbgridFinanceIn.GetItemText(i, 4, strOperator, 50);
  143. m_dbgridFinanceIn.GetItemText(i, 5, strRemark, 200);
  144. CSysDataStruct::CClassInfo ClassInfo;
  145. gDBOperator.getMoneyInClassInfo(ClassInfo);
  146. CDialogRecord DialogRecord;
  147. DialogRecord.setRecordInfo(strID, strSum, strOperator, strClass, strDate, strRemark, ClassInfo);
  148. DialogRecord.IsMoneyIn(true);
  149. DialogRecord.DoModal();
  150. break;
  151. }
  152. }
  153. *pResult = 0;
  154. }
  155. //-----------------------------------------------------------------------------
  156. void CDialogFinanceQuery::OnColumnclickDBgridFinanceIn(NMHDR* pNMHDR, LRESULT* pResult)
  157. {
  158. NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
  159. // TODO: Add your control notification handler code here
  160. int iColumIndex = pNMListView->iSubItem;
  161. LVCOLUMN column;
  162. column.mask = LVCF_TEXT;
  163. char strTitle[256];
  164. column.pszText = strTitle;
  165. column.cchTextMax=256;
  166. int iResutl = m_dbgridFinanceIn.GetColumn(iColumIndex, &column);
  167. CString strStart;
  168. CString strEnd;
  169. UpdateData(TRUE);
  170. strStart.Format("%d-%d-%d", m_dateStart.GetYear(),
  171. m_dateStart.GetMonth(),
  172. m_dateStart.GetDay());
  173. strEnd.Format("%d-%d-%d",   m_dateEnd.GetYear(),
  174. m_dateEnd.GetMonth(),
  175. m_dateEnd.GetDay());
  176. CButton* pRadio = (CButton*)GetDlgItem(IDC_ORDERBYASC);
  177. if(pRadio->GetCheck())
  178. {
  179. gDBOperator.ReOrderFinanceIn(strStart, strEnd, m_dbgridFinanceIn, m_strTotalIn,CString(strTitle), CString("asc"));
  180. }
  181. pRadio = (CButton*)GetDlgItem(IDC_ORDERBYDESC);
  182. if(pRadio->GetCheck())
  183. {
  184. gDBOperator.ReOrderFinanceIn(strStart, strEnd, m_dbgridFinanceIn, m_strTotalIn,CString(strTitle), CString("desc"));
  185. }
  186. UpdateData(FALSE);
  187. }