📄 monthpagedlg.cpp
字号:
// MonthPageDlg.cpp : implementation file
//
#include "stdafx.h"
#include "account.h"
#include "MonthPageDlg.h"
#include "AccountTabs.h"
#include "AccountAdo.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMonthPageDlg dialog
CMonthPageDlg::CMonthPageDlg(CWnd* pParent /*=NULL*/)
: CTabPageDlg(CMonthPageDlg::IDD, pParent)
{
CTime t=CTime::GetCurrentTime();
//{{AFX_DATA_INIT(CMonthPageDlg)
m_cmbMonth = t.Format("%m");
m_cmbYear = t.Format("%Y");
//}}AFX_DATA_INIT
}
void CMonthPageDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMonthPageDlg)
DDX_Control(pDX, IDC_COUNT, m_btnCount);
DDX_Control(pDX, IDC_LIST_MONTHRPT, m_MonthList);
DDX_CBString(pDX, IDC_COMBO_MONTH, m_cmbMonth);
DDX_CBString(pDX, IDC_COMBO_YEAR, m_cmbYear);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CMonthPageDlg, CDialog)
//{{AFX_MSG_MAP(CMonthPageDlg)
ON_BN_CLICKED(IDC_COUNT, OnCount)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMonthPageDlg message handlers
BOOL CMonthPageDlg::Create(CWnd* pParentWnd)
{
ASSERT(pParentWnd!=NULL);
m_pAccountTabs=(CAccountTabs*)pParentWnd;
return CDialog::Create(CMonthPageDlg::IDD, pParentWnd);
}
BOOL CMonthPageDlg::OnInitDialog()
{
CDialog::OnInitDialog();
//1、初始化LISTCTRL
InitMonthList();
//2、
//增加按钮的提示及图标
m_btnCount.SubclassDlgItem ( IDI_COUNT, this ); //将一个Windows控件连接给一个CWnd对象并使期通过该CWnd对象传递消息
m_btnCount.SetIcon ( IDI_COUNT );
m_btnCount.SetBtnCursor( IDC_HAND );
m_btnCount.AddToolTip ( "保存" );
//3、
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CMonthPageDlg::InitMonthList()
{
m_MonthList.ModifyStyle (0, LVS_REPORT|LVS_SHOWSELALWAYS);//LVS_SINGLESEL|
m_MonthList.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);
// m_MonthList.SetBkColor(RGB(0,0,0));
// m_MonthList.SetTextBkColor(RGB(0,0,0));
m_MonthList.SetTextColor(RGB(051,000,150));
static int ColumnWidth[10] = {60, 60, 84, 48, 48,48,48,60,48,60};
LV_COLUMN lvc;
lvc.mask = LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM ;
lvc.iSubItem = 0;
lvc.pszText = "消费日期" ;
lvc.cx = ColumnWidth[0];
m_MonthList.InsertColumn(0,&lvc);
lvc.iSubItem = 1;
lvc.pszText = "消费合计";
lvc.cx = ColumnWidth[1];
m_MonthList.InsertColumn(1,&lvc);
lvc.iSubItem = 2;
lvc.pszText = "日常生活消费";
lvc.cx = ColumnWidth[2];
m_MonthList.InsertColumn(2,&lvc);
lvc.iSubItem = 3;
lvc.pszText = "食消费";
lvc.cx = ColumnWidth[3];
m_MonthList.InsertColumn(3,&lvc);
lvc.iSubItem = 4;
lvc.pszText = "行消费";
lvc.cx = ColumnWidth[4];
m_MonthList.InsertColumn(4,&lvc);
lvc.iSubItem = 5;
lvc.pszText = "衣消费";
lvc.cx = ColumnWidth[5];
m_MonthList.InsertColumn(5,&lvc);
lvc.iSubItem = 6;
lvc.pszText = "住消费";
lvc.cx = ColumnWidth[6];
m_MonthList.InsertColumn(6,&lvc);
lvc.iSubItem = 7;
lvc.pszText = "其他消费";
lvc.cx = ColumnWidth[7];
m_MonthList.InsertColumn(7,&lvc);
lvc.iSubItem = 8;
lvc.pszText = "登记人";
lvc.cx = ColumnWidth[8];
m_MonthList.InsertColumn(8,&lvc);
lvc.iSubItem = 9;
lvc.pszText = "登记日期";
lvc.cx = ColumnWidth[9];
m_MonthList.InsertColumn(9,&lvc);
// char dig[3];
// for(int i=0;i<150;i++)
// m_MonthList.InsertItem(i,_itoa(i,dig,10));
}
void CMonthPageDlg::OnCount()
{
UpdateData();
// m_MonthList.ResetContent();
//--
CString sErrInfo;
CString sSql;
_variant_t vRecsAffected(0L);
_variant_t var;
_RecordsetPtr pRecordset;
//--
m_MonthList.DeleteAllItems();
if(m_cmbYear.IsEmpty())
{
MessageBox("消费日期年份不能为空,请重新选择年份!","警告",MB_OK);
return;
}
if(m_cmbMonth.IsEmpty())
{
MessageBox("消费日期月份不能为空,请重新选择月份!","警告",MB_OK);
return;
}
//--生成月份结束日
CString sEndDay;
if(m_cmbMonth=="01" || m_cmbMonth=="03" || m_cmbMonth=="05" ||
m_cmbMonth=="07" || m_cmbMonth=="08" ||m_cmbMonth=="10" ||m_cmbMonth=="12")
{
sEndDay="31";
}else if(m_cmbMonth=="04" || m_cmbMonth=="06" || m_cmbMonth=="09" || m_cmbMonth=="11"){
sEndDay="30";
}else if(m_cmbMonth=="02"){
if(atoi(m_cmbYear.GetBuffer(100))%4){
sEndDay="28";
}else{
sEndDay="29";
}
}else{
AfxMessageBox("选择的月份不合法,请重新选择月份!");
return;
}
sSql.Format("Select * From Account Where ConsumeDate >= CDate('%s-%s-01') and ConsumeDate <= CDate('%s-%s-%s')",
m_cmbYear,m_cmbMonth,m_cmbYear,m_cmbMonth,sEndDay);
TRACE("%s\n",sSql);
//--
try{
pRecordset = m_pAccountTabs->m_pAccountAdo->GetActiveConnect()->Execute(_bstr_t(sSql),&vRecsAffected,adOptionUnspecified);
if(!pRecordset->BOF)
pRecordset->MoveFirst();
else
{
sErrInfo.Format("没有 [%s年%s月] 的数据, 请重新选择年月!!!",m_cmbYear,m_cmbMonth);
AfxMessageBox(sErrInfo);
pRecordset->Close();
return;
}
m_MonthList.EnableWindow(FALSE);
int nCount=0;
// 读入库中各字段并加入列表框中
while(!pRecordset->adoEOF)
{
var=pRecordset->GetCollect("ConsumeDate");
if(var.vt != VT_NULL)
{
m_MonthList.InsertItem(nCount, "lizhongya");//每一行必须有一个ITEM值。
m_MonthList.SetItemText(nCount,0,(LPCSTR)_bstr_t(var));
}
var=pRecordset->GetCollect("Total");
if(var.vt != VT_NULL)
m_MonthList.SetItemText(nCount,1,(LPCSTR)_bstr_t(var));
var=pRecordset->GetCollect("Normal");
if(var.vt != VT_NULL)
m_MonthList.SetItemText(nCount,2,(LPCSTR)_bstr_t(var));
var=pRecordset->GetCollect("Eat");
if(var.vt != VT_NULL)
m_MonthList.SetItemText(nCount,3,(LPCSTR)_bstr_t(var));
var=pRecordset->GetCollect("Bus");
if(var.vt != VT_NULL)
m_MonthList.SetItemText(nCount,4,(LPCSTR)_bstr_t(var));
var=pRecordset->GetCollect("Rent");
if(var.vt != VT_NULL)
m_MonthList.SetItemText(nCount,5,(LPCSTR)_bstr_t(var));
var=pRecordset->GetCollect("Clothing");
if(var.vt != VT_NULL)
m_MonthList.SetItemText(nCount,6,(LPCSTR)_bstr_t(var));
var=pRecordset->GetCollect("Other");
if(var.vt != VT_NULL)
m_MonthList.SetItemText(nCount,7,(LPCSTR)_bstr_t(var));
var=pRecordset->GetCollect("Operator");
if(var.vt != VT_NULL)
m_MonthList.SetItemText(nCount,8,(LPCSTR)_bstr_t(var));
var=pRecordset->GetCollect("OperDate");
if(var.vt != VT_NULL)
m_MonthList.SetItemText(nCount,9,(LPCSTR)_bstr_t(var));
pRecordset->MoveNext();
}
m_MonthList.EnableWindow(TRUE);
pRecordset->Close();
}
catch(_com_error &e){
m_pAccountTabs->m_pAccountAdo->dump_com_error(e);
}
UpdateData(FALSE);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -