⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 monthreport.cpp

📁 一个可以控制单片机根据通话时间和所拨地区进行计费的软件!
💻 CPP
字号:
// MonthReport.cpp : implementation file
//

#include "stdafx.h"
#include "Commucation.h"
#include "MonthReport.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CMonthReport dialog


CMonthReport::CMonthReport(CWnd* pParent /*=NULL*/)
	: CDialog(CMonthReport::IDD, pParent)
{
	//{{AFX_DATA_INIT(CMonthReport)
	//}}AFX_DATA_INIT
	try
	{	
    	m_pDB.Open("C:\\WINDOWS\\SYSTEM\\record.mdb");
	}
	catch(CDaoException*e)
	{
		DisplayDaoException(e);
		e->Delete();
	}
}


void CMonthReport::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CMonthReport)
	DDX_Control(pDX, IDC_YSTART, m_YStart);
	DDX_Control(pDX, IDC_YEND, m_YEnd);
	DDX_Control(pDX, IDC_MSTART, m_MStart);
	DDX_Control(pDX, IDC_MEND, m_MEnd);
	DDX_Control(pDX, IDC_DSTART, m_DStart);
	DDX_Control(pDX, IDC_DEND, m_DEnd);
	DDX_Control(pDX, IDC_MSFLEXGRID1, m_Statistic);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CMonthReport, CDialog)
	//{{AFX_MSG_MAP(CMonthReport)
	ON_CBN_SELCHANGE(IDC_MSTART, OnSelchangeMstart)
	ON_CBN_SELCHANGE(IDC_MEND, OnSelchangeMend)
	ON_BN_CLICKED(IDC_BUTTON_STATIS, OnButtonStatis)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMonthReport message handlers

BOOL CMonthReport::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here	
	m_Statistic.SetRows(1);
	m_Statistic.SetColWidth(0,0);
	m_Statistic.SetColWidth(1,900);
	m_Statistic.SetColWidth(2,900);
	m_Statistic.SetColWidth(3,1200);
	m_Statistic.SetColWidth(4,1500);
	m_Statistic.SetColWidth(5,1300);
	m_Statistic.SetColWidth(6,1500);
	
	m_Statistic.SetRow(0);	
	m_Statistic.SetCol(1);	
	m_Statistic.SetText("营业员");
	m_Statistic.SetCol(2);	
	m_Statistic.SetText("话单数");
	m_Statistic.SetCol(3);	
	m_Statistic.SetText("本地电话");
	m_Statistic.SetCol(4);	
	m_Statistic.SetText("国内长途电话");
	m_Statistic.SetCol(5);	
	m_Statistic.SetText("港澳台电话");
	m_Statistic.SetCol(6);	
	m_Statistic.SetText("国际长途电话");

	t=CTime::GetCurrentTime();
	curYear=t.GetYear();
	curMonth=t.GetMonth();
	curDay=t.GetDay();
	CString x;
	x.Format("%d",curYear-3);
	m_YStart.InsertString(0,x);
	m_YEnd.InsertString(0,x);
	x.Format("%d",curYear-2);
	m_YStart.InsertString(1,x);
	m_YEnd.InsertString(1,x);
	x.Format("%d",curYear-1);
	m_YStart.InsertString(2,x);
	m_YEnd.InsertString(2,x);
	x.Format("%d",curYear);
	m_YStart.InsertString(3,x);
	m_YEnd.InsertString(3,x);
	m_YStart.SetCurSel(3);
	m_YEnd.SetCurSel(3);

	for(int i=1;i<=12;i++)
	{
		x.Format("%2d",i);
		m_MStart.AddString(x);
		m_MEnd.AddString(x);
	}

	m_MStart.SetCurSel(curMonth-1);
	m_MEnd.SetCurSel(curMonth-1);

	if((curMonth==4)||(curMonth==6)||(curMonth==9)||(curMonth==11))
	{
		for(int i=0;i<30;i++)
		{
			x.Format("%2d",i+1);
			m_DStart.InsertString(i,x);
			m_DEnd.InsertString(i,x);
			m_DStart.SetCurSel(curDay-1);
			m_DEnd.SetCurSel(curDay-1);
		}
	}
	else if(curMonth==2)
	{
		for(int i=0;i<29;i++)
		{
			x.Format("%2d",i+1);
			m_DStart.InsertString(i,x);
			m_DEnd.InsertString(i,x);
			m_DStart.SetCurSel(curDay-1);
			m_DEnd.SetCurSel(curDay-1);
		}
	}
	else
	{
		for(int i=0;i<31;i++)
		{
			x.Format("%2d",i+1);
			m_DStart.InsertString(i,x);
			m_DEnd.InsertString(i,x);
			m_DStart.SetCurSel(curDay-1);
			m_DEnd.SetCurSel(curDay-1);
		}
	}
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CMonthReport::OnSelchangeMstart() 
{
	// TODO: Add your control notification handler code here
	CString x;
	int selMonth;
	selMonth=m_MStart.GetCurSel()+1;
	m_DStart.ResetContent();
	if((selMonth==4)||(selMonth==6)||(selMonth==9)||(selMonth==11))
	{
		for(int i=0;i<30;i++)
		{
			x.Format("%2d",i+1);
			m_DStart.InsertString(i,x);
		}
	}
	else if(selMonth==2)
	{
		for(int i=0;i<29;i++)
		{
			x.Format("%2d",i+1);
			m_DStart.InsertString(i,x);
		}
	}
	else
	{
		for(int i=0;i<31;i++)
		{
			x.Format("%2d",i+1);
			m_DStart.InsertString(i,x);
		}
	}
}

void CMonthReport::OnSelchangeMend() 
{
	// TODO: Add your control notification handler code here
	CString x;
	int selMonth;
	selMonth=m_MEnd.GetCurSel()+1;
	m_DEnd.ResetContent();
	if((selMonth==4)||(selMonth==6)||(selMonth==9)||(selMonth==11))
	{
		for(int i=0;i<30;i++)
		{
			x.Format("%2d",i+1);
			m_DEnd.InsertString(i,x);
		}
	}
	else if(selMonth==2)
	{
		for(int i=0;i<29;i++)
		{
			x.Format("%2d",i+1);
			m_DEnd.InsertString(i,x);
		}
	}
	else
	{
		for(int i=0;i<31;i++)
		{
			x.Format("%2d",i+1);
			m_DEnd.InsertString(i,x);
		}
	}
}

void CMonthReport::OnButtonStatis() 
{
	// TODO: Add your control notification handler code here
	CDaoQueryDef qd(&m_pDB);
	CString sdate,edate,temp,sqlstr,gonghao;
	temp.Format("%d",m_YStart.GetCurSel()+curYear-3);
	sdate=temp;
	temp.Format("%2d",m_MStart.GetCurSel()+1);
	sdate=sdate+"/"+temp+"/";
	temp.Format("%2d",m_DStart.GetCurSel()+1);
	sdate+=temp;

	temp.Format("%d",m_YEnd.GetCurSel()+curYear-3);
	edate=temp;
	temp.Format("%2d",m_MEnd.GetCurSel()+1);
	edate=edate+"/"+temp+"/";
	temp.Format("%2d",m_DEnd.GetCurSel()+1);
	edate+=temp;
	m_Statis.dates="统计时间: "+sdate+"——"+edate;

	sqlstr="select distinct 工号,姓名 from record where 日期>='"+sdate+"' and 日期<='"+edate+"'";
	qd.Create("",sqlstr);
	CDaoRecordset rs(&m_pDB);
	try
	{
		rs.Open(&qd,dbOpenDynaset,dbInconsistent);
	}
	catch(CDaoException* e)
	{
		DisplayDaoException(e);
		e->Delete();
	}
	if(qd.IsOpen())
	{
		qd.Close();
	}
	CString str,tmpid,username;

	int Row,RowCount;
	double Sum;
	if(!rs.IsEOF())
	{
		rs.MoveLast();
		rs.MoveFirst();
	}
	RowCount=rs.GetRecordCount();	
	m_Statistic.SetRows(RowCount+2);
	Row=1;
	while(!rs.IsEOF())
	{
		gonghao=V_BSTRT(&rs.GetFieldValue(0));			
		username=V_BSTRT(&rs.GetFieldValue(1));
		username.TrimRight("-");
		
		m_Statistic.SetRow(Row);
		m_Statistic.SetCol(1);	
		m_Statistic.SetText(username);
		//统计话单数
		sqlstr="select count(*) from record where 日期>='"+sdate+"' and 日期<='"+edate+"' and 工号='"+gonghao+"'";
		qd.Create("",sqlstr);
		CDaoRecordset rst(&m_pDB);
		try
		{
			rst.Open(&qd,dbOpenDynaset,dbInconsistent);
		}
		catch(CDaoException* e)
		{
			DisplayDaoException(e);
			e->Delete();
		}		
		RowCount=V_I4(&rst.GetFieldValue(0));
		temp.Format("%5d",RowCount);
		m_Statistic.SetCol(2);	
		m_Statistic.SetText(temp);
		rst.Close();
		qd.Close();
		//统计国际长途费
		sqlstr="select sum(总价) from record where 日期>='"+sdate+"' and 日期<='"+edate+"' and 工号='"+gonghao+"' and 统计级='1'";
		qd.Create("",sqlstr);
		try
		{
			rst.Open(&qd,dbOpenDynaset,dbInconsistent);
		}
		catch(CDaoException* e)
		{
			DisplayDaoException(e);
			e->Delete();
		}		
		Sum=V_R8(&rst.GetFieldValue(0));
		temp.Format("%8.2f",Sum);
		m_Statistic.SetCol(6);	
		m_Statistic.SetText(temp);
		rst.Close();
		qd.Close();
		//统计港、澳、台长途费
		sqlstr="select sum(总价) from record where 日期>='"+sdate+"' and 日期<='"+edate+"' and 工号='"+gonghao+"' and 统计级>'1' and 统计级<'5'";
		qd.Create("",sqlstr);
		try
		{
			rst.Open(&qd,dbOpenDynaset,dbInconsistent);
		}
		catch(CDaoException* e)
		{
			DisplayDaoException(e);
			e->Delete();
		}		
		Sum=V_R8(&rst.GetFieldValue(0));
		temp.Format("%8.2f",Sum);
		m_Statistic.SetCol(5);	
		m_Statistic.SetText(temp);
		rst.Close();
		qd.Close();
		////统计国内长途费
		sqlstr="select sum(总价) from record where 日期>='"+sdate+"' and 日期<='"+edate+"' and 工号='"+gonghao+"' and 统计级='5'";
		qd.Create("",sqlstr);
		try
		{
			rst.Open(&qd,dbOpenDynaset,dbInconsistent);
		}
		catch(CDaoException* e)
		{
			DisplayDaoException(e);
			e->Delete();
		}		
		Sum=V_R8(&rst.GetFieldValue(0));
		temp.Format("%8.2f",Sum);
		m_Statistic.SetCol(4);	
		m_Statistic.SetText(temp);
		rst.Close();
		qd.Close();
		//统计市内话费
		sqlstr="select sum(总价) from record where 日期>='"+sdate+"' and 日期<='"+edate+"' and 工号='"+gonghao+"' and 统计级>'5'";
		qd.Create("",sqlstr);
		try
		{
			rst.Open(&qd,dbOpenDynaset,dbInconsistent);
		}
		catch(CDaoException* e)
		{
			DisplayDaoException(e);
			e->Delete();
		}		
		Sum=V_R8(&rst.GetFieldValue(0));
		temp.Format("%8.2f",Sum);
		m_Statistic.SetCol(3);	
		m_Statistic.SetText(temp);
		rst.Close();
		qd.Close();

		Row+=1;
		rs.MoveNext();
	}

	m_Statistic.SetRow(Row);
	m_Statistic.SetCol(1);	
	m_Statistic.SetText("合计");

	sqlstr="select count(*) from record where 日期>='"+sdate+"' and 日期<='"+edate+"'";
	qd.Create("",sqlstr);
	CDaoRecordset rst(&m_pDB);
	try
	{
		rst.Open(&qd,dbOpenDynaset,dbInconsistent);
	}
	catch(CDaoException* e)
	{
		DisplayDaoException(e);
		e->Delete();
	}		
	RowCount=V_I4(&rst.GetFieldValue(0));
	temp.Format("%5d",RowCount);
	m_Statistic.SetCol(2);	
	m_Statistic.SetText(temp);
	rst.Close();
	qd.Close();

	sqlstr="select sum(总价) from record where 日期>='"+sdate+"' and 日期<='"+edate+"' and 统计级='1'";
	qd.Create("",sqlstr);
	try
	{
		rst.Open(&qd,dbOpenDynaset,dbInconsistent);
	}
	catch(CDaoException* e)
	{
		DisplayDaoException(e);
		e->Delete();
	}		
	Sum=V_R8(&rst.GetFieldValue(0));
	temp.Format("%8.2f",Sum);
	m_Statistic.SetCol(6);	
	m_Statistic.SetText(temp);
	rst.Close();
	qd.Close();

	sqlstr="select sum(总价) from record where 日期>='"+sdate+"' and 日期<='"+edate+"' and 统计级>'1' and 统计级<'5'";
	qd.Create("",sqlstr);
	try
	{
		rst.Open(&qd,dbOpenDynaset,dbInconsistent);
	}
	catch(CDaoException* e)
	{
		DisplayDaoException(e);
		e->Delete();
	}		
	Sum=V_R8(&rst.GetFieldValue(0));
	temp.Format("%8.2f",Sum);
	m_Statistic.SetCol(5);	
	m_Statistic.SetText(temp);
	rst.Close();
	qd.Close();

	sqlstr="select sum(总价) from record where 日期>='"+sdate+"' and 日期<='"+edate+"' and 统计级='5'";
	qd.Create("",sqlstr);
	try
	{
		rst.Open(&qd,dbOpenDynaset,dbInconsistent);
	}
	catch(CDaoException* e)
	{
		DisplayDaoException(e);
		e->Delete();
	}		
	Sum=V_R8(&rst.GetFieldValue(0));
	temp.Format("%8.2f",Sum);
	m_Statistic.SetCol(4);	
	m_Statistic.SetText(temp);
	rst.Close();
	qd.Close();

	sqlstr="select sum(总价) from record where 日期>='"+sdate+"' and 日期<='"+edate+"' and 统计级>'5'";
	qd.Create("",sqlstr);
	try
	{
		rst.Open(&qd,dbOpenDynaset,dbInconsistent);
	}
	catch(CDaoException* e)
	{
		DisplayDaoException(e);
		e->Delete();
	}		
	Sum=V_R8(&rst.GetFieldValue(0));
	temp.Format("%8.2f",Sum);
	m_Statistic.SetCol(3);	
	m_Statistic.SetText(temp);
	rst.Close();
	qd.Close();
	
}

void CMonthReport::OnOK() 
{
	// TODO: Add extra validation here
	CString str;
	int Rows,temp;
	Rows=m_Statistic.GetRows()-1;
	m_Statis.num=Rows;
	m_Statis.name="";
	m_Statis.huadan="";
	m_Statis.internal="";
	m_Statis.gat="";
	m_Statis.china="";
	m_Statis.local="";
	for(int i=1;i<=Rows;i++)
	{
		//营业员
		m_Statistic.SetRow(i);
		m_Statistic.SetCol(1);
		str=m_Statistic.GetText();
		temp=str.GetLength();
		for(int j=8;j>temp;j--)
			str+=" ";
		m_Statis.name+=str;
		//话单数
		m_Statistic.SetRow(i);
		m_Statistic.SetCol(2);
		str=m_Statistic.GetText();
		m_Statis.huadan+=str;
		//本地
		m_Statistic.SetRow(i);
		m_Statistic.SetCol(3);
		str=m_Statistic.GetText();
		m_Statis.local+=str;
		//本地
		m_Statistic.SetRow(i);
		m_Statistic.SetCol(4);
		str=m_Statistic.GetText();
		m_Statis.china+=str;
		//本地
		m_Statistic.SetRow(i);
		m_Statistic.SetCol(5);
		str=m_Statistic.GetText();
		m_Statis.gat+=str;
		//本地
		m_Statistic.SetRow(i);
		m_Statistic.SetCol(6);
		str=m_Statistic.GetText();
		m_Statis.internal+=str;
	}
	
	CDialog::OnOK();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -