📄 chtview.cpp
字号:
// ChtView.cpp : implementation file
//
#include "stdafx.h"
#include "FFMS.h"
#include "ChtView.h"
#include "GeneralDef.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CChtView
IMPLEMENT_DYNCREATE(CChtView, CFormView)
CChtView::CChtView()
: CFormView(CChtView::IDD)
{
//{{AFX_DATA_INIT(CChtView)
m_nIOType = 0;
m_nTotalType = -1;
//}}AFX_DATA_INIT
}
CChtView::~CChtView()
{
}
void CChtView::DoDataExchange(CDataExchange* pDX)
{
CFormView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CChtView)
DDX_Control(pDX, IDC_CHT_VAL, m_ctrlTypeRes);
DDX_Control(pDX, IDC_CHT_IO, m_ctrIOType);
DDX_Control(pDX, IDC_MSCHART1, m_chartTotal);
DDX_Control(pDX, IDC_CHT_USER, m_dcIOUser);
DDX_Radio(pDX, IDC_RADIO1, m_nIOType);
DDX_Control(pDX, IDC_MSCHART2, m_chartType);
DDX_Control(pDX, IDC_MSCHART3, m_chartAsset);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CChtView, CFormView)
//{{AFX_MSG_MAP(CChtView)
ON_BN_CLICKED(IDC_RADIO1, OnRadio1)
ON_BN_CLICKED(IDC_RADIO2, OnRadio2)
ON_BN_CLICKED(IDC_BTN_LOOK, OnBtnLook)
ON_CBN_SELCHANGE(IDC_CHT_IO, OnSelchangeChtIo)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CChtView diagnostics
#ifdef _DEBUG
void CChtView::AssertValid() const
{
CFormView::AssertValid();
}
void CChtView::Dump(CDumpContext& dc) const
{
CFormView::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CChtView message handlers
void CChtView::OnInitialUpdate()
{
CFormView::OnInitialUpdate();
// TODO: Add your specialized code here and/or call the base class
CString sql="Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=Finance;Data Source=(local)";
if(adoDB.Open(sql)==TRUE)
{
SetTotalChartData("");
SetTypeChartData();
SetAssetChartData();
}
}
void CChtView::SetTotalChartData(CString strExtra)
{
if(!adoDB.IsOpen())
return;
CString value;
CString strSql;
strSql="select sum(io_mon) from FNC_IO where io_type='收入'"+strExtra;
adoDB.ExecuteQueryValue(strSql,value);
double income=atof(value);
strSql="select sum(io_mon) from FNC_IO where io_type='支出'"+strExtra;
adoDB.ExecuteQueryValue(strSql,value);
double expense=atof(value);
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 CChtView::OnRadio1()
{
// TODO: Add your control notification handler code here
m_nIOType=0;
SetTypeChartData();
}
void CChtView::OnRadio2()
{
// TODO: Add your control notification handler code here
m_nIOType=1;
SetTypeChartData();
}
void CChtView::OnBtnLook()
{
// TODO: Add your control notification handler code here
int index=m_ctrlTypeRes.GetCurSel();
if(index==-1)
return;
CString strConn;
CString strName=m_dcIOUser.GetText();
CTime tm=CTime::GetCurrentTime();
int year=tm.GetYear();
switch(m_nTotalType)
{
case 0:
strConn.Format(" and substring(io_date,1,7) between'%d-%s' and '%d-%s'",year,SetFillMonth(3*index+1),year,SetFillMonth(3*index+4));
if(!strName.IsEmpty())
{
strConn+="and io_user='"+strName;
strConn+="'";
}
break;
case 1:
strConn.Format(" and substring(io_date,1,4)='%d'",1990+index);
if(!strName.IsEmpty())
{
strConn+="and io_user='"+strName;
strConn+="'";
}
break;
case 2:
strConn.Format(" and substring(io_date,1,7)='%d-%s'",year,SetFillMonth(index+1));
if(!strName.IsEmpty())
{
strConn+="and io_user='"+strName;
strConn+="'";
}
break;
default:
break;
}
SetTotalChartData(strConn);
}
void CChtView::SetChartRowData(int row, double mon)
{
m_chartType.SetColumn(1);
m_chartType.GetDataGrid().SetData(row,1,mon,(short)0);
m_chartType.SetColumn(1);
m_chartType.SetColumnLabel("总额(元)");
}
void CChtView::SetTypeChartData()
{
if(!adoDB.IsOpen())
return;
m_chartType.GetPlot().GetSeriesCollection().GetItem(1).GetDataPoints().GetItem(-1).GetDataPointLabel().SetLocationType(1);
int rowCount;
CString value;
CDStrs typeFields,ioFields;
CStrs strs;
CString typeName;
CString sql;
if(m_nIOType==0)
{
adoDB.ExecuteQueryValue("select count(in_id) from MSG_IN",value);
rowCount=atoi(value);
m_chartType.SetRowCount(rowCount);
adoDB.ExecuteQuery("select in_type from MSG_IN",typeFields);
for(int i=0;i<typeFields.size();i++)
{
strs=typeFields[i];
typeName=strs[0];
sql.Format("select sum(io_mon) from FNC_IO where io_name='%s' and io_type='收入'",typeName);
adoDB.ExecuteQueryValue(sql,value);
m_chartType.SetRow(i+1);
m_chartType.SetRowLabel(typeName);
SetChartRowData(i+1,atof(value));
}
}
else
{
adoDB.ExecuteQueryValue("select count(out_id) from MSG_OUT",value);
rowCount=atoi(value);
m_chartType.SetRowCount(rowCount);
adoDB.ExecuteQuery("select out_type from MSG_OUT",typeFields);
for(int i=0;i<typeFields.size();i++)
{
strs=typeFields[i];
typeName=strs[0];
sql.Format("select sum(io_mon) from FNC_IO where io_name='%s' and io_type='支出'",typeName);
adoDB.ExecuteQueryValue(sql,value);
m_chartType.SetRow(i+1);
m_chartType.SetRowLabel(typeName);
SetChartRowData(i+1,atof(value));
}
}
m_chartType.Refresh();
}
void CChtView::OnSelchangeChtIo()
{
// TODO: Add your control notification handler code here
int i=m_ctrIOType.GetCurSel();
int j;
CString str;
m_ctrlTypeRes.ResetContent();
switch(i)
{
case 0:
m_nTotalType=0;
m_ctrlTypeRes.SetCurSel(-1);
for(j=0;j<4;j++)
{
str.Format("第%d季度",j+1);
m_ctrlTypeRes.AddString(str);
}
break;
case 1:
m_nTotalType=1;
m_ctrlTypeRes.SetCurSel(-1);
for(j=0;j<61;j++)
{
str.Format("%d年",j+1990);
m_ctrlTypeRes.AddString(str);
}
break;
case 2:
m_nTotalType=2;
m_ctrlTypeRes.SetCurSel(-1);
for(j=0;j<12;j++)
{
str.Format("%s月",SetFillMonth(j+1));
m_ctrlTypeRes.AddString(str);
}
break;
default:
break;
}
}
CString CChtView::SetFillMonth(int month)
{
CString str;
if(month<10)
str.Format("0%d",month);
else
str.Format("%d",month);
return str;
}
void CChtView::SetAssetChartData()
{
if(!adoDB.IsOpen())
return;
m_chartAsset.GetPlot().GetSeriesCollection().GetItem(1).GetDataPoints().GetItem(-1).GetDataPointLabel().SetLocationType(1);
int rowCount;
CString value;
CDStrs nameFields,monFields;
CStrs strs;
CString name;
CString sql;
adoDB.ExecuteQueryValue("select count(asset_id) from MSG_ASSET",value);
rowCount=atoi(value);
m_chartAsset.SetRowCount(rowCount);
adoDB.ExecuteQuery("select asset_type from MSG_ASSET",nameFields);
for(int i=0;i<nameFields.size();i++)
{
strs=nameFields[i];
name=strs[0];
sql.Format("select sum(asset_mon) from FNC_ASSET where asset_name='%s'",name);
adoDB.ExecuteQueryValue(sql,value);
m_chartAsset.SetRow(i+1);
m_chartAsset.SetRowLabel(name);
m_chartAsset.SetColumn(1);
m_chartAsset.GetDataGrid().SetData(i+1,1,atof(value),(short)0);
m_chartAsset.SetColumn(1);
m_chartAsset.SetColumnLabel("总额(元)");
}
m_chartAsset.Refresh();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -