📄 dlgorder.cpp
字号:
// DlgOrder.cpp : implementation file
//
#include "stdafx.h"
#include "NorthMIS.h"
#include "DlgOrder.h"
#include "_recordset.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDlgOrder dialog
CDlgOrder::CDlgOrder(CWnd* pParent /*=NULL*/)
: CDialog(CDlgOrder::IDD, pParent)
{
//{{AFX_DATA_INIT(CDlgOrder)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
void CDlgOrder::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDlgOrder)
DDX_Control(pDX, IDC_MSCHART_ORDER, m_chartOrder);
DDX_Control(pDX, IDC_ADODC_ORDER, m_adodcOrder);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDlgOrder, CDialog)
//{{AFX_MSG_MAP(CDlgOrder)
ON_BN_CLICKED(IDC_BUTTON_PIE, OnButtonPie)
ON_BN_CLICKED(IDC_BUTTON_BAR, OnButtonBar)
ON_BN_CLICKED(IDC_BUTTON_LINE, OnButtonLine)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDlgOrder message handlers
void CDlgOrder::InitChart()
{
//设置图表标题
m_chartOrder.SetTitleText("雇员完成订单统计图表");
//显示图例
m_chartOrder.SetShowLegend(TRUE);
CString id;
for(int i=1;i<=9;i++)
{
id.Format("%d",i);
m_chartOrder.SetColumn(i);
m_chartOrder.SetColumnLabel(id);
}
// Y轴设置
VARIANT var;
// 不自动标注Y轴刻度
m_chartOrder.GetPlot().GetAxis(1,var).GetValueScale().SetAuto(FALSE);
// Y轴最大刻度
m_chartOrder.GetPlot().GetAxis(1,var).GetValueScale().SetMaximum(100);
// Y轴最小刻度
m_chartOrder.GetPlot().GetAxis(1,var).GetValueScale().SetMinimum(0);
// Y轴刻度5等分
m_chartOrder.GetPlot().GetAxis(1,var).GetValueScale().SetMajorDivision(5);
// 每刻度一个刻度线
m_chartOrder.GetPlot().GetAxis(1,var).GetValueScale().SetMinorDivision(1);
// Y轴名称
m_chartOrder.GetPlot().GetAxis(1,var).GetAxisTitle().SetText("订单数目");
//9个条目
m_chartOrder.SetColumnCount(9);
//设置走势图中线宽属性以及数据点显示模式
for(int j=1;j<=9;j++)
{
m_chartOrder.GetPlot().GetSeriesCollection().GetItem(j).GetPen().SetWidth(20);
// 数据点类型显示数据值的模式(对柱柱状图和点线图有效)
// 0: 不显示 1: 显示在柱状图外
// 2: 显示在柱状图内上方 3: 显示在柱状图内中间 4: 显示在柱状图内下方
m_chartOrder.GetPlot().GetSeriesCollection().GetItem(j).GetDataPoints().GetItem(-1).GetDataPointLabel().SetLocationType(1);
}
//设置X轴属性,分三段
m_chartOrder.SetRowCount(3);
// 不自动标注X轴刻度
m_chartOrder.GetPlot().GetAxis(0,var).GetCategoryScale().SetAuto(FALSE);
// 每刻度一个标注
m_chartOrder.GetPlot().GetAxis(0,var).GetCategoryScale().SetDivisionsPerLabel(1);
// 每刻度一个刻度线
m_chartOrder.GetPlot().GetAxis(0,var).GetCategoryScale().SetDivisionsPerTick(1);
// X轴名称
m_chartOrder.GetPlot().GetAxis(0,var).GetAxisTitle().SetText("年份");
//设置X轴每段标题
for(int m=1;m<=3;m++)
{
CString rowLabel;
m_chartOrder.SetRow(m);
rowLabel.Format("19%d年",m+95);
m_chartOrder.SetRowLabel(rowLabel);
}
//控件更新
m_chartOrder.Refresh();
}
void CDlgOrder::DrawChart()
{
for(int i=1;i<=9;i++)
{
for(int j=1;j<=3;j++)
{
m_chartOrder.GetDataGrid().SetData(j, i, m_numOfOrder[i-1][j-1], 0);
}
}
m_chartOrder.Refresh();
}
BOOL CDlgOrder::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
InitChart();
GetData();
//默认先显示柱状图
m_chartOrder.SetChartType(1);
DrawChart();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CDlgOrder::GetData()
{
CString strSQL,strDateFrom,strDateTo;
int count;
for(int i=1;i<=9;i++)
for(int j=1;j<=3;j++)
{
strDateFrom.Format("19%d0101",95+j);
strDateTo.Format("19%d1230",95+j);
strSQL.Format("select OrderID from Orders where EmployeeID=%d and OrderDate<='%s' and OrderDate>='%s'",i,strDateTo,strDateFrom);
m_adodcOrder.SetRecordSource(strSQL);
m_adodcOrder.Refresh();
count=m_adodcOrder.GetRecordset().GetRecordCount();
m_numOfOrder[i-1][j-1]=count;
}
}
void CDlgOrder::OnButtonPie()
{
// TODO: Add your control notification handler code here
m_chartOrder.SetChartType(14);
DrawChart();
}
void CDlgOrder::OnButtonBar()
{
// TODO: Add your control notification handler code here
m_chartOrder.SetChartType(1);
DrawChart();
}
void CDlgOrder::OnButtonLine()
{
// TODO: Add your control notification handler code here
m_chartOrder.SetChartType(3);
DrawChart();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -