【VC开源代码栏目提醒】:网学会员在VC开源代码频道为大家收集整理了ChargeStatDlg.cpp提供大家参考,希望对大家有所帮助!
// ChargeStatDlg.cpp : implementation file
//
#include "stdafx.h"
#include "ChargeManage.h"
#include "ChargeStatDlg.h"
#include "DepSelDlg.h"
#include "StuCharge.h"
#include "COMDEF.H"
#include "Columns.h"
#include "Column.h"
#include "_Recordset.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CChargeStatDlg dialog
CChargeStatDlg::CChargeStatDlg(CWnd* pParent /*=NULL*/)
: CDialog(CChargeStatDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CChargeStatDlg)
m_DepName = _T("");
//}}AFX_DATA_INIT
}
void CChargeStatDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CChargeStatDlg)
DDX_Control(pDX, IDC_YEAR_COMBO, m_year);
DDX_Control(pDX, IDC_MONTH_COMBO, m_month);
DDX_Text(pDX, IDC_DEPNAME_STATIC, m_DepName);
DDX_Control(pDX, IDC_ADODC1, m_Adodc);
DDX_Control(pDX, IDC_DATAGRID1, m_Datagrid);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CChargeStatDlg, CDialog)
//{{AFX_MSG_MAP(CChargeStatDlg)
ON_BN_CLICKED(IDC_SEL_DEP_BUTTON, OnSelDepButton)
ON_BN_CLICKED(IDC_RESERCH_BUTTON, OnReserchButton)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CChargeStatDlg message handlers
BOOL CChargeStatDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
iDepId = 0;
m_DepName = "全部院系";
int i;
// m_year.AddString("请选择");
for(i=1980; i<=2050; i++)
{
cYear.Format("%d", i);
m_year.AddString(cYear);
}
// m_year.SetCurSel(0);
// m_month.AddString("请选择");
for(i=1; i<=9; i++)
{
cMonth.Format("%d", i);
m_month.AddString("0" + cMonth);
}
for(i=10; i<=12; i++)
{
cMonth.Format("%d", i);
m_month.AddString(cMonth);
}
// m_month.SetCurSel(0);
CTime CurrentTime = CTime::GetCurrentTime();
// index = m_month.GetCount();
// 设置当前年份
i = 0;
while(i < m_year.GetCount())
{
m_year.GetLBText(i, cYear);
if(cYear == CurrentTime.Format("%Y"))
{
m_year.SetCurSel(i);
break;
}
i++;
}
// 设置当前月份
i = 0;
while(i < m_month.GetCount())
{
m_month.GetLBText(i, cMonth);
if(cMonth == CurrentTime.Format("%m"))
{
m_month.SetCurSel(i);
break;
}
i++;
}
UpdateData(FALSE);
RefreshData();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
// 刷新数据
void CChargeStatDlg::RefreshData()
{
UpdateData(TRUE);
CString cNDate,cBDate; // 定义日期范围
//如果月份=12,则为下一年度,月份为1月
if(m_month.GetCurSel()==12)
{
m_year.GetLBText(m_year.GetCurSel(), cYear);
cBDate = cYear + "-12-01";
m_year.GetLBText(m_year.GetCurSel()+1, cYear);
cNDate = cYear + "-01-01";
}
else
{
m_year.GetLBText(m_year.GetCurSel(), cYear);
m_month.GetLBText(m_month.GetCurSel(), cMonth);
// 如果月份大约9,则在月份前加0
if(m_month.GetCurSel()>9)
cBDate = cYear + "-" + cMonth + "-01";
else
cBDate = cYear + "-0" + cMonth + "-01";
m_month.GetLBText(m_month.GetCurSel()+1, cMonth);
if(m_month.GetCurSel()+1>9)
cNDate = cYear + "-" + cMonth + "-01";
else
cNDate = cYear + "-0" + cMonth + "-01";
}
// 设置SELECT语句
CString cSource = "SELECT d.DepName AS 院系名称, s.Name AS 专业名称, ISNULL(t.学生总数, 0) AS 学生总数,"
" ISNULL(c.交费总额, 0.0) AS 交费总额, ISNULL(c.学费总额, 0.0) AS 学费总额,"
" ISNULL(c.杂费总额, 0.0) AS 杂费总额, ISNULL(c.机时费总额, 0.0) AS 机时费总额,"
" ISNULL(c.保险费总额, 0.0) AS 保险费总额, ISNULL(c.住宿费总额, 0.0) AS 住宿费总额,"
" ISNULL(c.存车费总额, 0.0) AS 存车费总额, ISNULL(c.书费总额, 0.0) AS 书费总额,"
" ISNULL(c.资料费总额, 0.0) AS 资料费总额 FROM Speciality s"
" INNER JOIN DepInfo d ON s.DepId = d.DepId"
" LEFT OUTER JOIN"
" (SELECT SpeId, COUNT(*) AS 学生总数 FROM Student GROUP BY SpeId) t"
" ON s.SpeId = t.SpeId LEFT OUTER JOIN"
" (Select st.SpeId,SUM(c.Fact_Total) AS 交费总额, SUM(c.Fact_Tuition) AS 学费总额, "
" SUM(c.Fact_Incidental) AS 杂费总额,SUM(c.Fact_MacTimeFee) AS 机时费总额,"
" SUM(c.Fact_Insurance) AS 保险费总额,SUM(c.Fact_DormFee) AS 住宿费总额,"
" SUM(c.Fact_BicycleFee) AS 存车费总额, SUM(c.Fact_BookFee) AS 书费总额,"
" SUM(c.Fact_FileFee) AS 资料费总额"
" FROM StuCharge c,Speciality s ,Student st"
" WHERE c.StuId=st.StuId And s.SpeId=st.SpeId And c.ChargeDate>='" + cBDate + "' And "
" c.ChargeDate<'" + cNDate + "' GROUP BY st.SpeId) c ON s.SpeId = c.SpeId";
//MessageBox(cSource);
//根据院系编号设置SELECT语句
CString cDepId;
cDepId.Format("%d", iDepId);
if(cDepId != "0") // 不是全部院系
cSource += " WHERE s.DepId = " + cDepId;
// 设置排序条件
cSource += " ORDER BY d.DepName, s.Name";
//刷新ADO Data控件的记录源
m_Adodc.SetRecordSource(cSource);
m_Adodc.Refresh();
int i;
//设置列宽度
_variant_t vIndex;
vIndex = long(0);
m_Datagrid.GetColumns().GetItem(vIndex).SetWidth(80);
vIndex = long(1);
m_Datagrid.GetColumns().GetItem(vIndex).SetWidth(80);
vIndex = long(2);
m_Datagrid.GetColumns().GetItem(vIndex).SetWidth(50);
for(i=3;i<12;i++)
{
vIndex = long(i);
m_Datagrid.GetColumns().GetItem(vIndex).SetWidth(65);
}
}
// 选择院系按钮
void CChargeStatDlg::OnSelDepButton()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
//打开选择院系对话框
CDepSelDlg dlg;
dlg.DoModal();
//从对话框中读取选择院系的信息
iDepId = dlg.DepId;
m_DepName = dlg.DepName;
UpdateData(FALSE);
}
// 检索按钮
void CChargeStatDlg::OnReserchButton()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
if(m_year.GetCurSel() == 0)
{
MessageBox("请选择年份");
return;
}
if(m_month.GetCurSel() == 0)
{
MessageBox("请选择月份");
return;
}
//根据选择的院系信息,刷新表格数据
RefreshData();
}
上一篇:
ChargeSelDlg.cpp
下一篇:
文中参考文献书写规范