?? statqueryview.cpp
字號:
// StatQueryView.cpp : implementation file
//
#include "stdafx.h"
#include "FinanceMIS.h"
#include "StatQueryView.h"
#include "vcdatagrid.h"
#include "vcplot.h"
#include "vcseriescollection.h"
#include "vcseries.h"
#include "vcdatapoints.h"
#include "vcdatapoint.h"
#include "vcdatapointlabel.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CStatQueryView
IMPLEMENT_DYNCREATE(CStatQueryView, CFormView)
CStatQueryView::CStatQueryView()
: CFormView(CStatQueryView::IDD)
{
//{{AFX_DATA_INIT(CStatQueryView)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
CStatQueryView::~CStatQueryView()
{
}
void CStatQueryView::DoDataExchange(CDataExchange* pDX)
{
CFormView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CStatQueryView)
DDX_Control(pDX, IDC_MSCHART1, m_chartTotal);
DDX_Control(pDX, IDC_MSCHART2, m_chartIn);
DDX_Control(pDX, IDC_MSCHART3, m_chartExp);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CStatQueryView, CFormView)
//{{AFX_MSG_MAP(CStatQueryView)
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CStatQueryView diagnostics
#ifdef _DEBUG
void CStatQueryView::AssertValid() const
{
CFormView::AssertValid();
}
void CStatQueryView::Dump(CDumpContext& dc) const
{
CFormView::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CStatQueryView message handlers
void CStatQueryView::OnDraw(CDC* pDC)
{
// TODO: Add your specialized code here and/or call the base class
//設置收支總額信息
SetTotalChartData();
//設置收入類別統計信息
SetInChartData();
//設置支出類別統計消息
SetExpChartData();
}
void CStatQueryView::SetTotalChartData()
{
if(!g_adoDB.IsOpen())
return;
//獲取總的收入和支出金額統計
CString value;
g_adoDB.ExecuteQueryValue("select sum(money) from in_exp_info_tab "
"where ix_type = 0",value);
double income = atof(value);
g_adoDB.ExecuteQueryValue("select sum(money) from in_exp_info_tab "
"where ix_type = 1",value);
double expense = atof(value);
//設定一組柱狀圖的列的個數為3個
m_chartTotal.SetColumnCount(3);
//設置柱狀圖上的數據
m_chartTotal.GetDataGrid().SetData(1, 1, income, (short)0);
m_chartTotal.GetDataGrid().SetData(1, 2, expense, (short)0);
m_chartTotal.GetDataGrid().SetData(1, 3, income-expense, (short)0);
//設置柱狀圖上列的名稱,包含收支信息和收支余額
m_chartTotal.SetColumn(1);
CString temp;
temp.Format("總收入(%.2f元)",income);
m_chartTotal.SetColumnLabel(temp);
m_chartTotal.SetColumn(2);
temp.Format("總支出(%.2f元)",expense);
m_chartTotal.SetColumnLabel(temp);
m_chartTotal.SetColumn(3);
temp.Format("收支余額(%.2f元)",income-expense);
m_chartTotal.SetColumnLabel(temp);
m_chartTotal.SetRowLabel("總的收支統計信息");
//顯示數據
m_chartTotal.Refresh();
}
void CStatQueryView::SetChartRowData(CMSChart& chart,int row,double money)
{
//設置每一組柱狀圖有1列
chart.SetColumnCount(1);
//設置第row組柱狀圖的總額數據
chart.GetDataGrid().SetData(row, 1, money, (short)0);
//設置柱狀圖上列的名稱
chart.SetColumn(1);
chart.SetColumnLabel("總額(元)");
}
void CStatQueryView::SetInChartData()
{
if(!g_adoDB.IsOpen())
return;
//設置柱狀圖上顯示數據的格式
m_chartIn.GetPlot().GetSeriesCollection().GetItem(1).GetDataPoints().GetItem(-1).GetDataPointLabel().SetLocationType(1);
//獲取總的收入類型的數目
CString value;
g_adoDB.ExecuteQueryValue("select count(id) from in_type_tab",value);
int rowCount = atoi(value);
//設置MSChart組的個數
m_chartIn.SetRowCount(rowCount);
CDStrs typeFields,inFields;
g_adoDB.ExecuteQuery("select name from in_type_tab",typeFields);
//分組插入顯示的每種類別的總額數據
for(int i = 0 ; i < typeFields.size() ; i++)
{
CStrs strs = typeFields[i];
CString typeName = strs[0];
CString sql;
sql.Format("select sum(money) from in_exp_info_tab "
"where ix_name = '%s' and ix_type =0",typeName);
g_adoDB.ExecuteQueryValue(sql,value);
//設置該i+1組的顯示數據
m_chartIn.SetRow(i+1);
m_chartIn.SetRowLabel(typeName);
SetChartRowData(m_chartIn,i+1,atof(value));
}
//顯示數據
m_chartIn.Refresh();
}
void CStatQueryView::SetExpChartData()
{
if(!g_adoDB.IsOpen())
return;
//設置柱狀圖上顯示數據的格式
m_chartExp.GetPlot().GetSeriesCollection().GetItem(1).GetDataPoints().GetItem(-1).GetDataPointLabel().SetLocationType(1);
//獲取總的支出類型的數目
CString value;
g_adoDB.ExecuteQueryValue("select count(id) from exp_type_tab",value);
int rowCount = atoi(value);
//設置MSChart組的個數
m_chartExp.SetRowCount(rowCount);
CDStrs typeFields,expFields;
g_adoDB.ExecuteQuery("select name from exp_type_tab",expFields);
//分組插入顯示的每種類別的總額數據
for(int i = 0 ; i < expFields.size() ; i++)
{
CStrs strs = expFields[i];
CString typeName = strs[0];
CString sql;
sql.Format("select sum(money) from in_exp_info_tab "
"where ix_name = '%s' and ix_type =1",typeName);
g_adoDB.ExecuteQueryValue(sql,value);
//設置該i+1組的顯示數據
m_chartExp.SetRow(i+1);
m_chartExp.SetRowLabel(typeName);
SetChartRowData(m_chartExp,i+1,atof(value));
}
//顯示數據
m_chartExp.Refresh();
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -