// DLG_Corp_Analyse.cpp: 实现文件
//

#include "stdafx.h"
#include "SmsManager.h"
#include "DLG_Corp_Analyse.h"
#include "afxdialogex.h"
#include "MainFrm.h"

// DLG_Corp_Analyse 对话框

IMPLEMENT_DYNAMIC(DLG_Corp_Analyse, CDialogEx)

DLG_Corp_Analyse::DLG_Corp_Analyse(CWnd* pParent /*=nullptr*/)
	: CDialogEx(IDD_CORP_ANALYSE, pParent)
	, m_bShowValue(FALSE)
{

	m_tBegin = COleDateTime::GetCurrentTime()-COleDateTimeSpan(60,0,0,0);
	m_tEnd = COleDateTime::GetCurrentTime();
	m_lAbility = 0;
	m_lDataType = 0;
	m_lGap = 0;
	m_lGraph = 0;
	m_lQueryAll = 0;

	m_lCorpID = 0;
	m_lType = 0;   //0企业,1代理商
	m_lItem = 0;
	m_strName=_T("");
	m_pMainFrame = NULL;

	m_pAnalyse = NULL;
	m_pSmsData = NULL;
	m_pMoneyData = NULL;


}

DLG_Corp_Analyse::~DLG_Corp_Analyse()
{
	CloseData();
}

void DLG_Corp_Analyse::CloseData()
{
	if (m_pAnalyse)
	{
		delete m_pAnalyse;
		m_pAnalyse = NULL;
	}

	if (m_pSmsData)
	{
		delete m_pSmsData;
		m_pSmsData = NULL;
	}

	if (m_pMoneyData)
	{
		delete m_pMoneyData;
		m_pMoneyData = NULL;
	}
}


void DLG_Corp_Analyse::SetParam(CMainFrame * pFrame, long lCorpID, long lType, long lItem, CString strName)
{

	m_lCorpID = lCorpID;
	m_lType = lType;   //0企业,1代理商
	m_lItem = lItem;
	m_strName = strName;
	m_pMainFrame = pFrame;
}

void DLG_Corp_Analyse::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);

	DDX_Control(pDX, IDC_CORP_ANALYSE_CHART, m_Chart);
	DDX_DateTimeCtrl(pDX, IDC_CORP_ANALYSE_TBEGIN, m_tBegin);
	DDX_DateTimeCtrl(pDX, IDC_CORP_ANALYSE_TEND, m_tEnd);

	DDX_CBIndex(pDX, IDC_CORP_ANALYSE_SMSTYPE, m_lAbility);
	DDX_CBIndex(pDX, IDC_CORP_ANALYSE_DATATYPE, m_lDataType);
	DDX_CBIndex(pDX, IDC_CORP_ANALYSE_GAP, m_lGap);
	DDX_CBIndex(pDX, IDC_CORP_ANALYSE_GRAPH, m_lGraph);
	DDX_CBIndex(pDX, IDC_CORP_ANALYSE_QUERYALL, m_lQueryAll);
	DDX_Control(pDX, IDC_CORP_ANALYSE_QUERYALL, m_L_QueryAll);


	DDX_Control(pDX, IDC_CORP_ANALYSE_SHOWVALUE, m_B_ShowValue);
	DDX_Check(pDX, IDC_CORP_ANALYSE_SHOWVALUE, m_bShowValue);
}


BEGIN_MESSAGE_MAP(DLG_Corp_Analyse, CDialogEx)
	ON_BN_CLICKED(IDC_C_PAY_QUERY, &DLG_Corp_Analyse::OnBnClickedCPayQuery)
	ON_WM_SIZE()
	ON_CBN_SELCHANGE(IDC_CORP_ANALYSE_GRAPH, &DLG_Corp_Analyse::OnCbnSelchangeCorpAnalyseGraph)
	ON_CBN_SELCHANGE(IDC_CORP_ANALYSE_DATATYPE, &DLG_Corp_Analyse::OnCbnSelchangeCorpAnalyseDatatype)
	ON_BN_CLICKED(IDC_CORP_ANALYSE_SHOWVALUE, &DLG_Corp_Analyse::OnClickedCorpAnalyseShowvalue)
END_MESSAGE_MAP()


// DLG_Corp_Analyse 消息处理程序


void DLG_Corp_Analyse::OnBnClickedCPayQuery()
{
	UpdateData(true);

	if (m_tEnd < m_tBegin)
	{
		MessageBox(_T("查询结束日期不能小于起始日期,请改正!"), _T("错误"), MB_ICONWARNING);
		GetDlgItem(IDC_CORP_ANALYSE_TBEGIN)->SetFocus();
		return;
	}

	
	REQ_Corp_Analyse * pAnalyse = new REQ_Corp_Analyse; memset(pAnalyse, 0, sizeof(REQ_Corp_Analyse));
	m_tBegin.GetAsSystemTime(pAnalyse->tBegin); //起始时间
	m_tEnd.GetAsSystemTime(pAnalyse->tEnd); //结束时间
	pAnalyse->lItem = m_lItem;   //列表记录位置
	pAnalyse->lType = m_lType;   //0企业数据,1代理商数据
	pAnalyse->lCorpID = m_lCorpID; //企业ID或代理商 ID
	if (m_lQueryAll > 0)  //选择了其它内容
	{
		switch (m_lQueryAll)
		{
		case 1:   //查询所有
			pAnalyse->lCorpID = -1;
			break;
		case 2:   //查询自有企业
			pAnalyse->lCorpID = -2;
			break;
		case 3:   //查询代理商企业
			pAnalyse->lCorpID = -3;
			break;
		}
	}
	_tcscpy(pAnalyse->szName, m_strName);  //企业名称或代理商名称
	pAnalyse->lAbility = m_lAbility;  //能力;0-短信,1-彩信
	pAnalyse->lGap = m_lGap;          //间隔;0-日,1-月,2-年
	pAnalyse->lDataType = m_lDataType; //数据类型;0-充值金额,1-短信量,2-金额+短信量
	pAnalyse->lAbility = m_lAbility;

	//pAnalyse->lCorpID = -3;

	m_pMainFrame->SendFrame(SMSFUNC_CORP_ANALYSE, (BYTE*)pAnalyse, sizeof(REQ_Corp_Analyse));



}


BOOL DLG_Corp_Analyse::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	// TODO:  在此添加额外的初始化

	if (m_pMainFrame->GetUserPurview(PURVIEW_MANAGER_ADD, false))
	{
		GetDlgItem(IDC_CORP_ANALYSE_QUERYALL)->ShowWindow(true);
	}

	if (m_lType == 1)  //代理商
	{
		m_L_QueryAll.ResetContent();
		m_L_QueryAll.InsertString(0,_T("指定代理商"));
		m_L_QueryAll.InsertString(1,_T("所有代理商"));
		m_L_QueryAll.SetCurSel(0);
	}
	return TRUE;  // return TRUE unless you set the focus to a control
				  // 异常: OCX 属性页应返回 FALSE
}


void DLG_Corp_Analyse::OnSize(UINT nType, int cx, int cy)
{
	CDialogEx::OnSize(nType, cx, cy);


	if (m_Chart.GetSafeHwnd())
	{
		m_Chart.MoveWindow(12, 150, cx - 12 - 12, cy - 150 - 12);
/*
		RECT rect,rect2;
		m_Chart.GetWindowRect(&rect);
		m_Chart.GetClientRect(&rect2);

		RECT rect3, rect4;
		this->GetWindowRect(&rect3);
		this->GetClientRect(&rect4);
		m_Chart.MoveWindow((rect3.left - rect.left), (rect3.top - rect.top), cx-(rect3.right-rect.right), cy-(rect3.bottom - rect.bottom));
		int b = 10;
*/
	}
}

BOOL DLG_Corp_Analyse::ProcessSocket(Socket_Head_Add *pHead, BYTE *pFrame)
{
	//查看支付记录
	if (pHead->lFuncType == SMSFUNC_CORP_ANALYSE )
	{
		ANS_Corp_Analyse     * pAnalyse = (ANS_Corp_Analyse     *)pFrame;
		ANS_Corp_Analyse_SmsData * pSmsData = (ANS_Corp_Analyse_SmsData *)(pFrame + sizeof(ANS_Corp_Analyse));
		ANS_Corp_Analyse_MoneyData * pMoneyData = (ANS_Corp_Analyse_MoneyData *)(pFrame + sizeof(ANS_Corp_Analyse) + sizeof(ANS_Corp_Analyse_SmsData)*pAnalyse->lSmsCount);
		if (!pAnalyse->bOK)   //权限不足,返回错误
		{
			//没数据返回,清空统计图

			return true;
		}

		CloseData();
		m_pAnalyse = new ANS_Corp_Analyse;
		*m_pAnalyse = *pAnalyse;
		if (m_pAnalyse->lSmsCount > 0)
		{
			m_pSmsData = new ANS_Corp_Analyse_SmsData[m_pAnalyse->lSmsCount];
			memcpy((BYTE*)m_pSmsData, (BYTE*)pSmsData, sizeof(ANS_Corp_Analyse_SmsData)*m_pAnalyse->lSmsCount);
		}
		if (m_pAnalyse->lMoneyCount > 0)
		{
			m_pMoneyData = new ANS_Corp_Analyse_MoneyData[m_pAnalyse->lMoneyCount];
			memcpy((BYTE*)m_pMoneyData, (BYTE*)pMoneyData, sizeof(ANS_Corp_Analyse_MoneyData)*m_pAnalyse->lMoneyCount);
		}

		ReDrawGraph();

	}

	return false;
}

void DLG_Corp_Analyse::ReDrawGraph()
{

	if (m_lGraph == 0)
	{
		m_Chart.put_chartType(1 | 0); //2D柱状图
	}
	if (m_lGraph == 1)
	{
		m_Chart.put_chartType(1 | 2); //2D线条型
	}
	GetDlgItem(IDC_CORP_ANALYSE_SHOWDATE)->SetWindowText(_T(""));
	CString strTitle;
	m_Chart.put_Stacking(FALSE);   //设置栈模式
	m_Chart.put_ColumnCount(1);  //清空数据
	m_Chart.put_RowCount(1);     //清空数据

	if (m_lType == 0)  //企业客户
	{
		switch (m_lDataType)
		{
		case 0:
		default:
			m_Chart.put_ShowLegend(FALSE);
			m_Chart.put_ColumnCount(1);  //设置列数
			m_Chart.put_Column(1);
			m_Chart.put_ColumnLabel(_T("充值金额"));
			//strTitle.Format(_T("%d-%s 充值金额对比图"),m_lCorpID,m_strName);
			strTitle.Format(_T("ID%d 充值金额对比图"), m_lCorpID);
			break;
		case 1:
			m_Chart.put_ShowLegend(FALSE);
			m_Chart.put_ColumnCount(1);  //设置列数
			m_Chart.put_Column(1);
			m_Chart.put_ColumnLabel(_T("发送量"));
			//strTitle.Format(_T("%d-%s 发送量对比图"), m_lCorpID, m_strName);
			strTitle.Format(_T("ID%d 发送量对比图"), m_lCorpID);
			break;
		case 2:
			m_Chart.put_ShowLegend(TRUE);
			m_Chart.put_ColumnCount(2);  //设置列数
			m_Chart.put_Column(1);
			m_Chart.put_ColumnLabel(_T("充值量"));
			m_Chart.put_Column(2);
			m_Chart.put_ColumnLabel(_T("发送量"));

			//strTitle.Format(_T("%d-%s 充值量+发送量对比图"), m_lCorpID, m_strName);
			strTitle.Format(_T("ID%d 充值量+发送量对比图"), m_lCorpID);
			break;
		}
	}
	else
	{
		switch (m_lDataType)
		{
		case 0:
		default:
			m_Chart.put_ShowLegend(FALSE);
			m_Chart.put_ColumnCount(1);  //设置列数
			m_Chart.put_Column(1);
			m_Chart.put_ColumnLabel(_T("充值金额"));
			//strTitle.Format(_T("%d-%s 充值金额对比图"), m_lCorpID, m_strName);
			strTitle.Format(_T("ID%d 充值金额对比图"), m_lCorpID);
			break;
		case 1:
			m_Chart.put_ShowLegend(FALSE);
			m_Chart.put_ColumnCount(1);  //设置列数
			m_Chart.put_Column(1);
			m_Chart.put_ColumnLabel(_T("充值量"));
			//strTitle.Format(_T("%d-%s 充值量对比图"), m_lCorpID, m_strName);
			strTitle.Format(_T("ID%d 充值量对比图"), m_lCorpID);
			break;
		}
	}
	m_Chart.put_TitleText(strTitle);


	if (!m_pAnalyse)  //没有数据,不画图
		return;

	VARIANT var;
	//((CVcFill)((CVcBackdrop)m_Chart.get_Backdrop()).get_Fill()).put_Style(1);
	//((CVcColor)((CVcBrush)((CVcFill)((CVcBackdrop)m_Chart.get_Backdrop()).get_Fill()).get_Brush()).get_FillColor()).Set(255, 255, 255);
	//((CVcValueScale)((CVcAxis)((CVcPlot)m_Chart.get_Plot()).get_Axis(0, var)).get_ValueScale()).put_Auto(false);//不自动标注Y轴刻度
	//((CVcValueScale)((CVcAxis)((CVcPlot)m_Chart.get_Plot()).get_Axis(0, var)).get_ValueScale()).put_Maximum(1000);// Y轴最大刻度
	//((CVcValueScale)((CVcAxis)((CVcPlot)m_Chart.get_Plot()).get_Axis(0, var)).get_ValueScale()).put_Minimum(0);// Y轴最小刻度
	//((CVcValueScale)((CVcAxis)((CVcPlot)m_Chart.get_Plot()).get_Axis(0, var)).get_ValueScale()).put_MajorDivision(0);//Y轴刻度5等分
	//((CVcValueScale)((CVcAxis)((CVcPlot)m_Chart.get_Plot()).get_Axis(0, var)).get_ValueScale()).put_MinorDivision(0);//每刻度一个刻度线
	//((CVcAxisTitle)((CVcAxis)((CVcPlot)m_Chart.get_Plot()).get_Axis(0, var)).get_AxisTitle()).put_Text(_T("短信量")); //Y轴名称

	//不要与x轴垂直的表格线
	((CVcPen)((CVcAxisGrid)((CVcAxis)((CVcPlot)m_Chart.get_Plot()).get_Axis(0, var)).get_AxisGrid()).get_MajorPen()).put_Style(0);
	//((CVcPen)((CVcAxisGrid)((CVcAxis)((CVcPlot)m_Chart.get_Plot()).get_Axis(1, var)).get_AxisGrid()).get_MajorPen()).put_Style(0);
	//隐藏第二y轴,即右边的y轴
	((CVcAxisScale)((CVcAxis)((CVcPlot)m_Chart.get_Plot()).get_Axis(2, var)).get_AxisScale()).put_Hide(TRUE);
	//设置x轴及y轴的标题。xTitle和yTitle为CString型
	//m_Chart.GetPlot().GetAxis(0, var).GetAxisTitle().SetText(xTitle); //x轴
	//m_Chart.GetPlot().GetAxis(1, var).GetAxisTitle().SetText(yTitle); //y轴


	//m_Chart.put_RowCount(iRow);//设置曲线点数(画曲线一定要设置)
	//((CVcColor)((CVcPen)((CVcSeries)((CVcSeriesCollection)((CVcPlot)m_Chart.get_Plot()).get_SeriesCollection()).get_Item(1)).get_Pen()).get_VtColor()).Set(0, 0, 255);

	// 线宽(对点线图有效)
	//((CVcPen)((CVcSeries)((CVcSeriesCollection)((CVcPlot)m_Chart.get_Plot()).get_SeriesCollection()).get_Item(1)).get_Pen()).put_Width(50);
	//m_Chart.GetPlot().GetSeriesCollection().GetItem(1).GetPen().SetWidth(50);
	//m_Chart.GetPlot().GetSeriesCollection().GetItem(2).GetPen().SetWidth(100);
	//m_Chart.GetPlot().GetSeriesCollection().GetItem(3).GetPen().SetWidth(2);
	// 数据点类型显示数据值的模式(对柱柱状图和点线图有效)
	// 0: 不显示 1: 显示在柱状图外
	// 2: 显示在柱状图内上方 3: 显示在柱状图内中间 4: 显示在柱状图内下方
	long lShowType = 0;
	if (m_B_ShowValue.GetCheck())
		lShowType = 1;
	((CVcDataPointLabel)((CVcDataPoint)((CVcDataPoints)((CVcSeries)((CVcSeriesCollection)((CVcPlot)m_Chart.get_Plot()).get_SeriesCollection()).get_Item(1)).get_DataPoints()).get_Item(-1)).get_DataPointLabel()).put_LocationType(lShowType);
	((CVcDataPointLabel)((CVcDataPoint)((CVcDataPoints)((CVcSeries)((CVcSeriesCollection)((CVcPlot)m_Chart.get_Plot()).get_SeriesCollection()).get_Item(1)).get_DataPoints()).get_Item(-1)).get_DataPointLabel()).put_ValueFormat(_T("0,0"));
	if (m_Chart.get_ColumnCount() >= 2)
	{
		((CVcDataPointLabel)((CVcDataPoint)((CVcDataPoints)((CVcSeries)((CVcSeriesCollection)((CVcPlot)m_Chart.get_Plot()).get_SeriesCollection()).get_Item(2)).get_DataPoints()).get_Item(-1)).get_DataPointLabel()).put_LocationType(lShowType);
		((CVcDataPointLabel)((CVcDataPoint)((CVcDataPoints)((CVcSeries)((CVcSeriesCollection)((CVcPlot)m_Chart.get_Plot()).get_SeriesCollection()).get_Item(2)).get_DataPoints()).get_Item(-1)).get_DataPointLabel()).put_ValueFormat(_T("0,0"));
	}
	

		//图形上数值的显示设置
		//MSChart1.Plot.SeriesCollection(AIndex).DataPoints(-1).DataPointLabel.Component = 2  '1 普通数值 2 百分比
		//MSChart1.Plot.SeriesCollection(AIndex).DataPoints(-1).DataPointLabel.PercentFormat = "0%"   '百分比显示格式
		//普通数值显示格式  为空时将以科学计数法显示 ,为0时按实际显示
		//MSChart1.Plot.SeriesCollection(AIndex).DataPoints(-1).DataPointLabel.ValueFormat = "0"

	//m_Chart.GetPlot().GetSeriesCollection().GetItem(1).GetDataPoints().GetItem(-1).GetDataPointLabel().SetLocationType(1);
	//m_Chart.GetPlot().GetSeriesCollection().GetItem(2).GetDataPoints().GetItem(-1).GetDataPointLabel().SetLocationType(1);
	//m_Chart.GetPlot().GetSeriesCollection().GetItem(3).GetDataPoints().GetItem(-1).GetDataPointLabel().SetLocationType(1);

	//m_Chart.GetPlot().GetAxis(0, var).GetCategoryScale().SetAuto(FALSE);//不自动标注x轴刻度
	//m_Chart.GetPlot().GetAxis(0, var).GetCategoryScale().SetDivisionsPerLabel(1);


	int nRowCount = 1;
	switch (m_lGap)
	{
	case 0:    //日
	default:
		nRowCount = (m_tEnd - m_tBegin).GetTotalDays()+1;
		break;
	case 1:  //月
	{
		long lYear = m_tEnd.GetYear() - m_tBegin.GetYear();
		long lMon = m_tEnd.GetMonth() - m_tBegin.GetMonth()+1;
		if (lMon <= 0)
		{
			lMon = 12 + lMon;
			lYear = lYear - 1;
		}
		nRowCount = lYear * 12 + lMon;
	}
		break;
	case 2:  //年
		nRowCount = m_tEnd.GetYear() - m_tBegin.GetYear()+1;
		break;
	case 3:  //半年
		nRowCount = (m_tEnd.GetYear() - m_tBegin.GetYear() + 1) * 2;
		break;
	case 4:  //同比-上半年
	case 5:  //同比-下半年
	case 6:  //同比-1季度
	case 7:  //同比-2季度
	case 8:  //同比-3季度
	case 9:  //同比-4季度
	case 10:  //同比-1月份
	case 11:  //同比-2月份
	case 12:  //同比-3月份
	case 13:  //同比-4月份
	case 14:  //同比-5月份
	case 15:  //同比-6月份
	case 16:  //同比-7月份
	case 17:  //同比-8月份
	case 18:  //同比-9月份
	case 19:  //同比-10月份
	case 20:  //同比-11月份
	case 21:  //同比-12月份
		nRowCount = m_tEnd.GetYear() - m_tBegin.GetYear() + 1;
		break;
	}
	if (nRowCount < 1) nRowCount = 1;
	if (nRowCount > 500) nRowCount = 500;
	m_Chart.put_RowCount(nRowCount);

	//VARIANT var;
	//((CVcCategoryScale)((CVcAxis)((CVcPlot)m_Chart.get_Plot()).get_Axis(0, var)).get_CategoryScale()).put_Auto(FALSE);// 不自动标注X轴刻度
	//((CVcCategoryScale)((CVcAxis)((CVcPlot)m_Chart.get_Plot()).get_Axis(0, var)).get_CategoryScale()).put_DivisionsPerLabel(0);//每刻度一个标注
	//((CVcCategoryScale)((CVcAxis)((CVcPlot)m_Chart.get_Plot()).get_Axis(0, var)).get_CategoryScale()).put_DivisionsPerTick(0);//每刻度一个刻度线
	//((CVcAxisTitle)((CVcAxis)((CVcPlot)m_Chart.get_Plot()).get_Axis(0, var)).get_AxisTitle()).put_Text(_T("日期"));  // X轴名称

	CString strRow;
	srand((unsigned)time(NULL));
	int iSmsDataIndex = 0;
	int iMoneyDataIndex = 0;
	COleDateTime tDrawDate = m_tBegin;
	int iDarwYear = m_tBegin.GetYear();
	int iDrawMon = m_tBegin.GetMonth();
	for (int row = 1; row <= nRowCount; ++row)
	{
		CString strDate;    //画日期
		long lSmsValue=0;   //画短信数据
		double fMoneyValue=0.0f;  //金额数据
		long lSmsPrepare = 0;  //预充金额
		switch (m_lGap)
		{
		case 0:  //日
		default:
		{
			strDate.Format(_T("%04d.%02d.%02d"), tDrawDate.GetYear(), tDrawDate.GetMonth(), tDrawDate.GetDay());
			if (iSmsDataIndex < m_pAnalyse->lSmsCount)
			{
				if (tDrawDate.GetYear() == m_pSmsData[iSmsDataIndex].tDate.wYear &&   //时间相同,取数据
					tDrawDate.GetMonth() == m_pSmsData[iSmsDataIndex].tDate.wMonth &&
					tDrawDate.GetDay() == m_pSmsData[iSmsDataIndex].tDate.wDay)
				{
					lSmsValue = m_pSmsData[iSmsDataIndex].lSend - m_pSmsData[iSmsDataIndex].lReportFail;
					iSmsDataIndex++;
				}
			}
			if (iMoneyDataIndex < m_pAnalyse->lMoneyCount)
			{
				if (tDrawDate.GetYear() == m_pMoneyData[iMoneyDataIndex].tDate.wYear &&   //时间相同,取数据
					tDrawDate.GetMonth() == m_pMoneyData[iMoneyDataIndex].tDate.wMonth &&
					tDrawDate.GetDay() == m_pMoneyData[iMoneyDataIndex].tDate.wDay)
				{
					fMoneyValue = m_pMoneyData[iMoneyDataIndex].fPrice;
					lSmsPrepare = m_pMoneyData[iMoneyDataIndex].lSmsCount;
					iMoneyDataIndex++;
				}
			}

			tDrawDate = tDrawDate + COleDateTimeSpan(1, 0, 0, 0);
		}
			break;
		case 1:  //月
			strDate.Format(_T("%04d.%02d"), iDarwYear, iDrawMon);
			if (iSmsDataIndex < m_pAnalyse->lSmsCount)
			{
			if (iDarwYear == m_pSmsData[iSmsDataIndex].tDate.wYear &&   //时间相同,取数据
				iDrawMon == m_pSmsData[iSmsDataIndex].tDate.wMonth)
			{
				lSmsValue = m_pSmsData[iSmsDataIndex].lSend - m_pSmsData[iSmsDataIndex].lReportFail;
				iSmsDataIndex++;
			}
			}
			if (iMoneyDataIndex < m_pAnalyse->lMoneyCount)
			{
			if (iDarwYear == m_pMoneyData[iMoneyDataIndex].tDate.wYear &&   //时间相同,取数据
				iDrawMon == m_pMoneyData[iMoneyDataIndex].tDate.wMonth)
			{
				fMoneyValue = m_pMoneyData[iMoneyDataIndex].fPrice;
				lSmsPrepare = m_pMoneyData[iMoneyDataIndex].lSmsCount;
				iMoneyDataIndex++;
			}
			}
			iDrawMon = iDrawMon + 1;  //月加1
			if (iDrawMon > 12)
			{
				iDrawMon = 1;
				iDarwYear += 1;
			}
			break;
		case 2:  //年
			strDate.Format(_T("%04d年"), iDarwYear);
			if (iSmsDataIndex < m_pAnalyse->lSmsCount)
			{
			if (iDarwYear == m_pSmsData[iSmsDataIndex].tDate.wYear )
			{
				lSmsValue = m_pSmsData[iSmsDataIndex].lSend - m_pSmsData[iSmsDataIndex].lReportFail;
				iSmsDataIndex++;
			}
			}
			if (iMoneyDataIndex < m_pAnalyse->lMoneyCount)
			{
			if (iDarwYear == m_pMoneyData[iMoneyDataIndex].tDate.wYear )
			{
				fMoneyValue = m_pMoneyData[iMoneyDataIndex].fPrice;
				lSmsPrepare = m_pMoneyData[iMoneyDataIndex].lSmsCount;
				iMoneyDataIndex++;
			}
			}
			iDarwYear = iDarwYear + 1;  //月加1
			break;

		case 3:  //半年
			if (row % 2 == 1)
			{
				strDate.Format(_T("%04d年上半年"), iDarwYear);

				for (int i = 0; i < 6 && iSmsDataIndex < m_pAnalyse->lSmsCount; i++)
				{
					if (iDarwYear == m_pSmsData[iSmsDataIndex].tDate.wYear && m_pSmsData[iSmsDataIndex].tDate.wMonth <= 6)
					{
						lSmsValue = lSmsValue + m_pSmsData[iSmsDataIndex].lSend - m_pSmsData[iSmsDataIndex].lReportFail;
						iSmsDataIndex++;
					}
					else
						break;

				}
				for (int i = 0; i < 6 && iMoneyDataIndex < m_pAnalyse->lMoneyCount; i++)
				{
					if (iDarwYear == m_pMoneyData[iMoneyDataIndex].tDate.wYear && m_pMoneyData[iMoneyDataIndex].tDate.wMonth <= 6)
					{
						fMoneyValue = fMoneyValue + m_pMoneyData[iMoneyDataIndex].fPrice;
						lSmsPrepare = lSmsPrepare + m_pMoneyData[iMoneyDataIndex].lSmsCount;
						iMoneyDataIndex++;
					}
					else
						break;
				}
			}
			else
			{
				strDate.Format(_T("%04d年下半年"), iDarwYear);

				for (int i = 0; i < 6 && iSmsDataIndex < m_pAnalyse->lSmsCount; i++)
				{
					if (iDarwYear == m_pSmsData[iSmsDataIndex].tDate.wYear && m_pSmsData[iSmsDataIndex].tDate.wMonth > 6)
					{
						lSmsValue = lSmsValue + m_pSmsData[iSmsDataIndex].lSend - m_pSmsData[iSmsDataIndex].lReportFail;
						iSmsDataIndex++;
					}
				}
				for (int i = 0; i < 6 && iMoneyDataIndex < m_pAnalyse->lMoneyCount; i++)
				{
					if (iDarwYear == m_pMoneyData[iMoneyDataIndex].tDate.wYear && m_pMoneyData[iMoneyDataIndex].tDate.wMonth > 6)
					{
						fMoneyValue = fMoneyValue + m_pMoneyData[iMoneyDataIndex].fPrice;
						lSmsPrepare = lSmsPrepare + m_pMoneyData[iMoneyDataIndex].lSmsCount;
						iMoneyDataIndex++;
					}
				}
				iDarwYear = iDarwYear + 1;  //月加1
			}
			break;

		case 4:  //同比-上半年
		case 5:  //同比-下半年
		case 6:  //同比-1季度
		case 7:  //同比-2季度
		case 8:  //同比-3季度
		case 9:  //同比-4季度
		case 10:  //同比-1月份
		case 11:  //同比-2月份
		case 12:  //同比-3月份
		case 13:  //同比-4月份
		case 14:  //同比-5月份
		case 15:  //同比-6月份
		case 16:  //同比-7月份
		case 17:  //同比-8月份
		case 18:  //同比-9月份
		case 19:  //同比-10月份
		case 20:  //同比-11月份
		case 21:  //同比-12月份

			if (m_pAnalyse->lGap == 4) strDate.Format(_T("%04d年上半年"), iDarwYear);
			if (m_pAnalyse->lGap == 5) strDate.Format(_T("%04d年下半年"), iDarwYear);
			if (m_pAnalyse->lGap == 6) strDate.Format(_T("%04d年1季度"), iDarwYear);
			if (m_pAnalyse->lGap == 7) strDate.Format(_T("%04d年2季度"), iDarwYear);
			if (m_pAnalyse->lGap == 8) strDate.Format(_T("%04d年3季度"), iDarwYear);
			if (m_pAnalyse->lGap == 9) strDate.Format(_T("%04d年4季度"), iDarwYear);
			if (m_pAnalyse->lGap >= 10 && m_pAnalyse->lGap <= 21) strDate.Format(_T("%04d年%d月"), iDarwYear, m_pAnalyse->lGap - 9);

			for (int i = 0; i < 12 && iMoneyDataIndex < m_pAnalyse->lMoneyCount; i++)
			{
				if (iDarwYear == m_pMoneyData[iMoneyDataIndex].tDate.wYear && m_pMoneyData[iMoneyDataIndex].tDate.wMonth <= 12)
				{
					BOOL bGetData = false;
					if (m_pAnalyse->lGap == 4 && m_pMoneyData[iMoneyDataIndex].tDate.wMonth <= 6)  //同比-上半年
						bGetData = true;
					if (m_pAnalyse->lGap == 5 && m_pMoneyData[iMoneyDataIndex].tDate.wMonth > 6 && m_pMoneyData[iMoneyDataIndex].tDate.wMonth <= 12)  //同比-下半年
						bGetData = true;
					if (m_pAnalyse->lGap == 6 && m_pMoneyData[iMoneyDataIndex].tDate.wMonth >= 1 && m_pMoneyData[iMoneyDataIndex].tDate.wMonth <= 3)  //同比-1季度
						bGetData = true;
					if (m_pAnalyse->lGap == 7 && m_pMoneyData[iMoneyDataIndex].tDate.wMonth >= 4 && m_pMoneyData[iMoneyDataIndex].tDate.wMonth <= 6)  //同比-2季度
						bGetData = true;
					if (m_pAnalyse->lGap == 8 && m_pMoneyData[iMoneyDataIndex].tDate.wMonth >= 7 && m_pMoneyData[iMoneyDataIndex].tDate.wMonth <= 9)  //同比-3季度
						bGetData = true;
					if (m_pAnalyse->lGap == 9 && m_pMoneyData[iMoneyDataIndex].tDate.wMonth >= 10 && m_pMoneyData[iMoneyDataIndex].tDate.wMonth <= 12)  //同比-4季度
						bGetData = true;
					if (m_pAnalyse->lGap >= 10 && m_pAnalyse->lGap <= 21 && m_pMoneyData[iMoneyDataIndex].tDate.wMonth == m_pAnalyse->lGap - 9)  //同比-月份
						bGetData = true;
					if (bGetData)
					{
						fMoneyValue = fMoneyValue + m_pMoneyData[iMoneyDataIndex].fPrice;
						lSmsPrepare = lSmsPrepare + m_pMoneyData[iMoneyDataIndex].lSmsCount;
					}
					iMoneyDataIndex++;
				}
				else
				{
					break;
				}
			}

			for (int i = 0; i < 12 && iSmsDataIndex < m_pAnalyse->lSmsCount; i++)
			{
				if (iDarwYear == m_pSmsData[iSmsDataIndex].tDate.wYear && m_pSmsData[iSmsDataIndex].tDate.wMonth <= 12)
				{
					BOOL bGetData = false;
					if (m_pAnalyse->lGap == 4 && m_pSmsData[iSmsDataIndex].tDate.wMonth <= 6)  //同比-上半年
						bGetData = true;
					if (m_pAnalyse->lGap == 5 && m_pSmsData[iSmsDataIndex].tDate.wMonth > 6 && m_pSmsData[iSmsDataIndex].tDate.wMonth <= 12)  //同比-下半年
						bGetData = true;
					if (m_pAnalyse->lGap == 6 && m_pSmsData[iSmsDataIndex].tDate.wMonth >= 1 && m_pSmsData[iSmsDataIndex].tDate.wMonth <= 3)  //同比-1季度
						bGetData = true;
					if (m_pAnalyse->lGap == 7 && m_pSmsData[iSmsDataIndex].tDate.wMonth >= 4 && m_pSmsData[iSmsDataIndex].tDate.wMonth <= 6)  //同比-2季度
						bGetData = true;
					if (m_pAnalyse->lGap == 8 && m_pSmsData[iSmsDataIndex].tDate.wMonth >= 7 && m_pSmsData[iSmsDataIndex].tDate.wMonth <= 9)  //同比-3季度
						bGetData = true;
					if (m_pAnalyse->lGap == 9 && m_pSmsData[iSmsDataIndex].tDate.wMonth >= 10 && m_pSmsData[iSmsDataIndex].tDate.wMonth <= 12)  //同比-4季度
						bGetData = true;
					if (m_pAnalyse->lGap >= 10 && m_pAnalyse->lGap <= 21 && m_pSmsData[iSmsDataIndex].tDate.wMonth == m_pAnalyse->lGap - 9)  //同比-月份
						bGetData = true;
					if (bGetData)
					{
						lSmsValue = lSmsValue + m_pSmsData[iSmsDataIndex].lSend - m_pSmsData[iSmsDataIndex].lReportFail;
					}
					iSmsDataIndex++;
				}
				else
				{
					break;
				}
			}

			iDarwYear = iDarwYear + 1;  //月加1
			break;
		}
		m_Chart.put_Row(row);
		m_Chart.put_RowLabel(strDate);

		CString strLable;
		if (m_lType == 0)  //企业客户
		{
			switch (m_lDataType)
			{
			case 0:
			default:
				((CVcDataGrid)m_Chart.get_DataGrid()).SetData(row, 1, fMoneyValue, 0);  //充值金额
				//strLable.Format(_T("%.2f"), fMoneyValue);
				//((CVcDataGrid)m_Chart.get_DataGrid()).put_RowLabel(row, 1, strLable);
				break;
			case 1:
				((CVcDataGrid)m_Chart.get_DataGrid()).SetData(row, 1, lSmsValue, 0);  //发送量
				break;
			case 2:
				((CVcDataGrid)m_Chart.get_DataGrid()).SetData(row, 1, lSmsPrepare, 0);  //充值量
				((CVcDataGrid)m_Chart.get_DataGrid()).SetData(row, 2, lSmsValue, 0);  //发送量
				break;
			}
		}
		else
		{
			switch (m_lDataType)
			{
			case 0:
			default:
				((CVcDataGrid)m_Chart.get_DataGrid()).SetData(row, 1, fMoneyValue, 0);  //充值金额
				break;
			case 1:
				((CVcDataGrid)m_Chart.get_DataGrid()).SetData(row, 1, lSmsPrepare, 0);  //充值量
				break;
			}
		}
	}

	m_Chart.Refresh();


}BEGIN_EVENTSINK_MAP(DLG_Corp_Analyse, CDialogEx)
ON_EVENT(DLG_Corp_Analyse, IDC_CORP_ANALYSE_CHART, 9, DLG_Corp_Analyse::PointSelectedCorpAnalyseChart, VTS_PI2 VTS_PI2 VTS_PI2 VTS_PI2)
END_EVENTSINK_MAP()


void DLG_Corp_Analyse::PointSelectedCorpAnalyseChart(short* Series, short* DataPoint, short* MouseFlags, short* Cancel)
{

	CString strOut;
	long lCol = *Series;
	long lRow = *DataPoint;

	double dData=0;
	short sr = 0;
	((CVcDataGrid)m_Chart.get_DataGrid()).GetData(lRow, lCol, &dData, &sr);

	CString strRowLable = ((CVcDataGrid)m_Chart.get_DataGrid()).get_RowLabel(lRow, 1);
	CString strColLable = ((CVcDataGrid)m_Chart.get_DataGrid()).get_ColumnLabel(lCol, 1);
	long sData = (long)dData;

	strOut.Format(_T("数据:%s,%s : %d"), strRowLable, strColLable, sData);
	//AfxMessageBox(strOut);

	GetDlgItem(IDC_CORP_ANALYSE_SHOWDATE)->SetWindowText(strOut);

}


void DLG_Corp_Analyse::OnCbnSelchangeCorpAnalyseGraph()
{
	UpdateData(true);
	ReDrawGraph();
}


void DLG_Corp_Analyse::OnCbnSelchangeCorpAnalyseDatatype()
{
	UpdateData(true);
	ReDrawGraph();
}


void DLG_Corp_Analyse::OnClickedCorpAnalyseShowvalue()
{
	ReDrawGraph();
}