📄 wastebookview.cpp
字号:
// WasteBookView.cpp : implementation of the CWasteBookView class
//
#include "stdafx.h"
#include "WasteBook.h"
#include "WasteBookSet.h"
#include "WasteBookDoc.h"
#include "WasteBookView.h"
#include "DlgNew.h"
#include "DlgUpdate.h"
#include "DlgQuery.h"
#include "OutgoSet.h"
#include <afxcmn.h>
/////////////////////////////////////////////////////////////////////////////
// CWasteBookView
IMPLEMENT_DYNCREATE(CWasteBookView, CRecordView)
BEGIN_MESSAGE_MAP(CWasteBookView, CRecordView)
//{{AFX_MSG_MAP(CWasteBookView)
ON_WM_SIZE()
ON_NOTIFY(TCN_SELCHANGE, IDC_TAB, OnSelchangeTab)
ON_COMMAND(ID_Btn_Add, OnBtnAdd)
ON_COMMAND(ID_Btn_Delete, OnBtnDelete)
ON_COMMAND(ID_Btn_Update, OnBtnUpdate)
ON_NOTIFY(NM_DBLCLK, IDC_LIST1, OnDblclkList)
ON_COMMAND(ID_Btn_Sum, OnBtnSum)
ON_COMMAND(ID_Btn_Sum2, OnBtnSum2)
ON_COMMAND(ID_Btn_Query, OnBtnQuery)
ON_NOTIFY(LVN_COLUMNCLICK, IDC_LIST1, OnColumnclickList1)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CRecordView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CRecordView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CRecordView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CWasteBookView construction/destruction
CWasteBookView::CWasteBookView()
: CRecordView(CWasteBookView::IDD)
{
//{{AFX_DATA_INIT(CWasteBookView)
// NOTE: the ClassWizard will add member initialization here
m_pSet = NULL;
//}}AFX_DATA_INIT
// TODO: add construction code here
m_pSet2=new COutgoSet;
m_pSet2->Open();
}
CWasteBookView::~CWasteBookView()
{
m_pSet2->Close();
}
void CWasteBookView::DoDataExchange(CDataExchange* pDX)
{
CRecordView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CWasteBookView)
DDX_Control(pDX, IDC_LIST1, m_list);
DDX_Control(pDX, IDC_TAB, m_Tab);
//}}AFX_DATA_MAP
}
BOOL CWasteBookView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CRecordView::PreCreateWindow(cs);
}
void CWasteBookView::OnInitialUpdate()
{
m_pSet = &GetDocument()->m_wasteBookSet;
CRecordView::OnInitialUpdate();
GetParentFrame()->RecalcLayout();
ResizeParentToFit();
TC_ITEM TabCtrlItem;
TabCtrlItem.mask = TCIF_TEXT;
TabCtrlItem.pszText = "Income";
m_Tab.InsertItem( 0, &TabCtrlItem );
TabCtrlItem.pszText = "Outgo";
m_Tab.InsertItem( 1, &TabCtrlItem );
TabCtrlItem.pszText = "summary";
m_Tab.InsertItem( 2, &TabCtrlItem );
m_Tab.SetCurSel(0);
m_list.SetExtendedStyle(LVS_EX_FULLROWSELECT);
m_pSet->m_strSort="Number DESC";
m_pSet2->m_strSort="Number ASC";
RefreshList();
bSort=0;
AddTypeToList(0);
AddTypeToList(1);
}
/////////////////////////////////////////////////////////////////////////////
// CWasteBookView printing
BOOL CWasteBookView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CWasteBookView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CWasteBookView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CWasteBookView diagnostics
#ifdef _DEBUG
void CWasteBookView::AssertValid() const
{
CRecordView::AssertValid();
}
void CWasteBookView::Dump(CDumpContext& dc) const
{
CRecordView::Dump(dc);
}
CWasteBookDoc* CWasteBookView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CWasteBookDoc)));
return (CWasteBookDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CWasteBookView database support
CRecordset* CWasteBookView::OnGetRecordset()
{
return m_pSet;
}
/////////////////////////////////////////////////////////////////////////////
// CWasteBookView message handlers
void CWasteBookView::RefreshList()
{
for(int i=0;i<4;i++)
m_list.DeleteColumn(0);
m_list.DeleteAllItems();
LV_COLUMN lvColumn;
lvColumn.mask=LVCF_FMT|LVCF_WIDTH|LVCF_TEXT|LVCF_SUBITEM;
lvColumn.fmt=LVCFMT_LEFT;
CRect rect;
GetClientRect(rect);
int colum1=(rect.Width()-4)/4;
lvColumn.cx=colum1;
lvColumn.iSubItem=0;
lvColumn.pszText="Date";
m_list.InsertColumn(0,&lvColumn);
lvColumn.iSubItem=1;
lvColumn.pszText="Name";
m_list.InsertColumn(1,&lvColumn);
lvColumn.iSubItem=2;
lvColumn.pszText="Type";
m_list.InsertColumn(2,&lvColumn);
lvColumn.iSubItem=3;
lvColumn.pszText="Number";
m_list.InsertColumn(3,&lvColumn);
LV_ITEM lvItem;
lvItem.mask=LVIF_TEXT|LVIF_IMAGE|LVIF_STATE;
lvItem.state=0;
lvItem.stateMask=0;
lvItem.iSubItem=0;
m_pSet->Requery(); //to rebuild (refresh) a recordset
m_pSet2->Requery();
if(m_Tab.GetCurSel()==0)
{
i=0;
if(!m_pSet->IsBOF())
m_pSet->MoveFirst();
while(!m_pSet->IsEOF())
{
lvItem.iItem=i;
CString strDate=m_pSet->m_Date.Format("%Y-%m-%d");
lvItem.pszText=(LPSTR)(LPCTSTR)strDate;
m_list.InsertItem(&lvItem);
m_list.SetItemText(i,1,m_pSet->m_Name);
m_list.SetItemText(i,2,m_pSet->m_Type);
CString strNumber;
strNumber.Format("%d",m_pSet->m_Number);
m_list.SetItemText(i,3,strNumber);
i++;
m_pSet->MoveNext();
}
}
else if(m_Tab.GetCurSel()==1)
{
i=0;
if(!m_pSet2->IsBOF())
m_pSet2->MoveFirst();
while(!m_pSet2->IsEOF())
{
lvItem.iItem=i;
CString strDate=m_pSet2->m_Date.Format("%Y-%m-%d");
lvItem.pszText=(LPSTR)(LPCTSTR)strDate;
m_list.InsertItem(&lvItem);
m_list.SetItemText(i,1,m_pSet2->m_Name);
m_list.SetItemText(i,2,m_pSet2->m_Type);
CString strNumber;
strNumber.Format("%d",m_pSet2->m_Number);
m_list.SetItemText(i,3,strNumber);
i++;
m_pSet2->MoveNext();
}
}
else if(m_Tab.GetCurSel()==2)
{
GetSum();
int index=0;
lvItem.iItem=0;
CTime time=CTime::GetCurrentTime();
CString strDate=time.Format("%Y-%m-%d");
lvItem.pszText=(LPSTR)(LPCTSTR)strDate;
m_list.InsertItem(&lvItem);
m_list.SetItemText(0,2,"All Income");
CString strNumber;
strNumber.Format("%d",sumIn);
m_list.SetItemText(0,3,strNumber);
index=1;
int i=0;
int countIn=theApp.InListType.GetCount();
POSITION posIn=theApp.InListType.GetHeadPosition();
while(i<countIn)
{
lvItem.iItem=index;
lvItem.pszText="";
m_list.InsertItem(&lvItem);
m_list.SetItemText(index,2,theApp.InListType.GetNext(posIn));
CString strNumber;
strNumber.Format("%d",nSum[i]);
m_list.SetItemText(index,3,strNumber);
i++;
index++;
}
lvItem.iItem=index;
lvItem.pszText="";
m_list.InsertItem(&lvItem);
index++;
lvItem.iItem=index;
lvItem.pszText=(LPSTR)(LPCTSTR)strDate;
m_list.InsertItem(&lvItem);
m_list.SetItemText(index,2,"All Outgo");
strNumber.Format("%d",sumOut);
m_list.SetItemText(index,3,strNumber);
index++;
i=0;
int countOut=theApp.OutListType.GetCount();
POSITION posOut=theApp.OutListType.GetHeadPosition();
while(i<countOut)
{
lvItem.iItem=index;
lvItem.pszText="";
m_list.InsertItem(&lvItem);
m_list.SetItemText(index,2,theApp.OutListType.GetNext(posOut));
CString strNumber;
strNumber.Format("%d",nSum2[i]);
m_list.SetItemText(index,3,strNumber);
index++;
i++;
}
}
}
void CWasteBookView::OnSize(UINT nType, int cx, int cy)
{
CRecordView::OnSize(nType, cx, cy);
// TODO: Add your message handler code here
if(m_list.GetSafeHwnd())
{
CRect rect;
GetClientRect(rect);
m_Tab.MoveWindow(rect);
rect.OffsetRect(0,24);
m_list.MoveWindow(rect);
RefreshList();
}
}
void CWasteBookView::OnSelchangeTab(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
RefreshList();
*pResult = 0;
}
void CWasteBookView::OnBtnAdd()
{
// TODO: Add your command handler code here
if(m_Tab.GetCurSel()==0)
{
CDlgNew dlg;
dlg.bAddIncome=0;
if(dlg.DoModal()==IDOK)
{
if(dlg.m_Type=="" || dlg.m_Num==0)
{
AfxMessageBox("You haven't input it completely!");
return;
}
m_pSet->AddNew();
m_pSet->m_Date=dlg.m_Date;
m_pSet->m_Name=dlg.m_Name;
m_pSet->m_Type=dlg.m_Type;
m_pSet->m_Number=dlg.m_Num;
m_pSet->Update();
AddTypeToList(0);
}
}
else if(m_Tab.GetCurSel()==1)
{
CDlgNew dlg;
dlg.bAddIncome=1;
if(dlg.DoModal()==IDOK)
{
if(dlg.m_Type=="" || dlg.m_Num==0)
{
AfxMessageBox("You haven't input it completely!");
return;
}
m_pSet2->AddNew();
m_pSet2->m_Date=dlg.m_Date;
m_pSet2->m_Name=dlg.m_Name;
m_pSet2->m_Type=dlg.m_Type;
m_pSet2->m_Number=dlg.m_Num;
m_pSet2->Update();
AddTypeToList(1);
}
}
RefreshList();
}
void CWasteBookView::OnBtnDelete()
{
// TODO: Add your command handler code here
int iSel=m_list.GetSelectionMark();
if(iSel>=0)
{
if(AfxMessageBox("DELETE it really?",MB_OKCANCEL)==IDCANCEL)
return;
if(m_Tab.GetCurSel()==0)
{
m_pSet->MoveFirst();
for(int i=0;i<iSel;i++)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -