📄 tjshebeidlg.cpp
字号:
// TjshebeiDlg.cpp : implementation file
//
#include "stdafx.h"
#include "kufangDBS.h"
#include "TjshebeiDlg.h"
extern CDatabase m_db;
#include "mschart.h" //添加相关的头文件
#include "VcAxis.h"
#include "VcAxisTitle.h"
#include "VcTextLayout.h"
#include "VcDataGrid.h"
#include "VcPlot.h"
#include "VcValueScale.h"
#include "VcSeriesCollection.h"
#include "VcSeries.h"
#include "VcPen.h"
#include "VcCategoryScale.h"
#include "VcColor.h"
#include "VcDataGrid.h"
#include "VcBackdrop.h"
#include "VcFill.h"
#include "VcBrush.h"
#include "VcDataPoints.h"
#include "VcDataPoint.h"
#include "VcDataPointLabel.h"
#include "VcAxisTitle.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CTjshebeiDlg dialog
CTjshebeiDlg::CTjshebeiDlg(CWnd* pParent /*=NULL*/)
: CDialog(CTjshebeiDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CTjshebeiDlg)
m_strValuea1 = 0.0;
m_strValuea2 = 0.0;
m_strValueb1 = 0.0;
m_strValueb2 = 0.0;
m_strValuec1 = 0.0;
m_strValuec2 = 0.0;
//}}AFX_DATA_INIT
}
void CTjshebeiDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CTjshebeiDlg)
DDX_Control(pDX, IDC_MSCHART1, m_chart1);
DDX_Text(pDX, IDC_EDIT_A1, m_strValuea1);
DDX_Text(pDX, IDC_EDIT_A2, m_strValuea2);
DDX_Text(pDX, IDC_EDIT_B1, m_strValueb1);
DDX_Text(pDX, IDC_EDIT_B2, m_strValueb2);
DDX_Text(pDX, IDC_EDIT_C1, m_strValuec1);
DDX_Text(pDX, IDC_EDIT_C2, m_strValuec2);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CTjshebeiDlg, CDialog)
//{{AFX_MSG_MAP(CTjshebeiDlg)
ON_BN_CLICKED(IDC_BTN_SHEBEI_DJTJ, OnBtnShebeiDjtj)
ON_BN_CLICKED(IDC_BTN_SHEBEI_ERWEI, OnBtnShebeiErwei)
ON_BN_CLICKED(IDC_BTN_SHEBEI_SANWEI, OnBtnShebeiSanwei)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTjshebeiDlg message handlers
void CTjshebeiDlg::OnBtnShebeiDjtj()
{
// TODO: Add your control notification handler code here
CString sql;
//设定柱状图的个数为3个
UpdateData();
m_chart1.SetColumnCount(3);
//sql.Format("select count(DISTINCT yqbh) from sb where dj between f% and f%", m_strValuea1, m_strValuea2);
sql.Format("select count(DISTINCT yqbh) from sb where dj between %f and %f",m_strValuea1,m_strValuea2);
double dj1=GetcountBySql(sql);
m_chart1.GetDataGrid().SetData(1,1, dj1, (short)0);
sql.Format("select count(DISTINCT yqbh) from sb where dj between %f and %f", m_strValueb1, m_strValueb2);
double dj2=GetcountBySql(sql);
m_chart1.GetDataGrid().SetData(1,2, dj2, (short)0);
sql.Format("select count(DISTINCT yqbh) from sb where dj between %f and %f", m_strValuec1, m_strValuec2);
double dj3=GetcountBySql(sql);
m_chart1.GetDataGrid().SetData(1,3, dj3, (short)0);
//设置柱状图上的名称,包含
m_chart1.SetColumn(1);
CString temp;
temp.Format("价格范围1(%.0f个)", dj1);
m_chart1.SetColumnLabel(temp);
m_chart1.SetColumn(2);
temp.Format("价格范围2(%.0f个)", dj2);
m_chart1.SetColumnLabel(temp);
m_chart1.SetColumn(3);
temp.Format("价格范围3(%.0f个)", dj3);
m_chart1.SetColumnLabel(temp);
m_chart1.SetRowLabel("价格统计");
//显示数据
m_chart1.Refresh();
}
BOOL CTjshebeiDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
double country =GetcountBySql("select count(DISTINCT gb) from sb ");
double changjia =GetcountBySql("select count(DISTINCT cj) from sb ");
double supporter =GetcountBySql("select count(DISTINCT gys) from sb ");
//设定柱状图的个数为3个
m_chart1.SetColumnCount(3);
//m_strValuea1="country";
//SetchartData(country,changjia,supporter);
//设置柱状图上的数据
m_chart1.GetDataGrid().SetData(1, 1, country, (short)0);
//GetDataGrid
m_chart1.GetDataGrid().SetData(1,2, changjia, (short)0);
m_chart1.GetDataGrid().SetData(1,3, supporter, (short)0);
//设置柱状图上的名称,包含
m_chart1.SetColumn(1);
CString temp;
temp.Format("国家(%.0f个)",country);
m_chart1.SetColumnLabel(temp);
m_chart1.SetColumn(2);
temp.Format("厂家(%.0f个)", changjia);
m_chart1.SetColumnLabel(temp);
m_chart1.SetColumn(3);
temp.Format("供应商(%.0f家)", supporter);
m_chart1.SetColumnLabel(temp);
m_chart1.SetRowLabel("频数信息");
//显示数据
m_chart1.Refresh();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
double CTjshebeiDlg::GetcountBySql(CString sql)
{
double nCount=0;
TRY{
CRecordset rs;
rs.m_pDatabase = & m_db;
//CString sql
rs.Open(CRecordset::dynaset, sql);
CDBVariant var;
//获取成员字段值
rs.GetFieldValue((short)0,var,SQL_C_SLONG);
if (var.m_dwType !=DBVT_NULL)
nCount = var.m_iVal;
var.Clear();
rs.Close();
}
CATCH(CDBException,ex)
{
AfxMessageBox(ex->m_strError);
AfxMessageBox(ex->m_strStateNativeOrigin);
}
AND_CATCH(CMemoryException,pEx)
{
pEx->ReportError();
AfxMessageBox("memory exception");
}
AND_CATCH(CException,e){
TCHAR szError[100];
e->GetErrorMessage(szError,100);
AfxMessageBox(szError);
}
END_CATCH
return nCount;
}
void CTjshebeiDlg::OnBtnShebeiErwei()
{
// TODO: Add your control notification handler code here
m_chart1.SetChartType(1);//2D(二维) 显示
m_chart1.Refresh();
}
void CTjshebeiDlg::OnBtnShebeiSanwei()
{
// TODO: Add your control notification handler code here
m_chart1.SetChartType(0);//3D(三维) 显示
m_chart1.Refresh();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -