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

📄 offdutydlg.cpp

📁 该源码的前台用C++编写
💻 CPP
字号:
// OffdutyDlg.cpp : implementation file
//

#include "stdafx.h"
#include "MenuManage.h"
#include "OffdutyDlg.h"

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

extern CMenuManageApp theApp;
/////////////////////////////////////////////////////////////////////////////
// COffdutyDlg dialog


COffdutyDlg::COffdutyDlg(CWnd* pParent /*=NULL*/)
: CDialog(COffdutyDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(COffdutyDlg)
	m_timeDay = 0;
	m_nTotalAcount = 0;
	m_strDayName = _T("");
	//}}AFX_DATA_INIT
}


void COffdutyDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(COffdutyDlg)
	DDX_Control(pDX, IDC_DATETIMEPICKER_OFFTIME, m_timectrlOff);
	DDX_Control(pDX, IDC_DATAGRID_OFF, m_dbTotalDay);
	DDX_DateTimeCtrl(pDX, IDC_DATETIMEPICKER_OFFTIME, m_timeDay);
	DDX_Text(pDX, IDC_EDIT_CHECK_ACOUNT, m_nTotalAcount);
	DDX_Text(pDX, IDC_EDIT_OFF_NAME, m_strDayName);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(COffdutyDlg, CDialog)
//{{AFX_MSG_MAP(COffdutyDlg)
ON_BN_CLICKED(IDC_CAL_DAY_BTN, OnCalDayBtn)
ON_BN_CLICKED(IDC_PRINT_DAY_BTN, OnPrintDayBtn)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// COffdutyDlg message handlers

BOOL COffdutyDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	m_timeDay=CTime::GetCurrentTime();
	
	m_strDayName = theApp.m_name;
	UpdateData(FALSE);
	
	return TRUE;  // return TRUE unless you set the focus to a control
	// EXCEPTION: OCX Property Pages should return FALSE
}

void COffdutyDlg::OnCalDayBtn() 
{
	// TODO: Add your control notification handler code here
	CString sql,str;
	int temp = 1;
	str.Format("%d" , temp);
	//该收银员经手已结帐的单子
	sql = "Select * From DeskInfo Where DeskCheck = "+str+" and DeskName = '"+m_strDayName+"'";
	m_pRecordset_Desk.CreateInstance("ADODB.Recordset");
	m_pRecordset_Desk->Open((_variant_t)sql,_variant_t((IDispatch *)theApp.m_pConnection,true),adOpenDynamic,adLockPessimistic,adCmdText);
	
	int renminbi_jine=0;
	int qita_jine = 0;
	int total_jine=0;
	int acount=0;
	//计算总单数,并统计人民币及其他结算金额
	if(m_pRecordset_Desk->GetRecordCount()!=0)
	{
		while(!m_pRecordset_Desk->adoEOF)
		{
			str = m_pRecordset_Desk->GetCollect("DeskPaymode").bstrVal;
			if(str.CompareNoCase("人民币") == 0)
				renminbi_jine += m_pRecordset_Desk->GetCollect("DeskPrice").lVal;
			else
				qita_jine += m_pRecordset_Desk->GetCollect("DeskPrice").lVal;
			
			acount++;
			m_pRecordset_Desk ->MoveNext();
		}
	}
	
	total_jine = renminbi_jine + qita_jine;
	
	
	m_pRecordset_Off.CreateInstance("ADODB.Recordset");
	m_pRecordset_Off->Open("Select * From CalDayInfo",_variant_t((IDispatch *)theApp.m_pConnection,true),adOpenDynamic,adLockPessimistic,adCmdText);
	
	if(m_pRecordset_Off->GetRecordCount()!=0)
	{
		while(!m_pRecordset_Off->adoEOF)
		{
			m_pRecordset_Off ->Delete(adAffectCurrent);
			m_pRecordset_Off->MoveNext();
		}
		
	}
	
	m_pRecordset_Off->AddNew();
	m_pRecordset_Off->PutCollect("mode",_variant_t("人民币"));
	str.Format("%d",renminbi_jine);
	m_pRecordset_Off->PutCollect("money",_variant_t(str));
	
	m_pRecordset_Off->AddNew();
	m_pRecordset_Off->PutCollect("mode",_variant_t("其他"));
	str.Format("%d",qita_jine);
	m_pRecordset_Off->PutCollect("money",_variant_t(str));
	
	m_pRecordset_Off->AddNew();
	m_pRecordset_Off->PutCollect("mode",_variant_t("合计"));
	str.Format("%d",total_jine);
	m_pRecordset_Off->PutCollect("money",_variant_t(str));
	
	m_dbTotalDay.SetRefDataSource(NULL);
	m_dbTotalDay.SetRefDataSource((LPUNKNOWN)m_pRecordset_Off);
	m_dbTotalDay.SetColumnHeaders(2) ;
	
	m_dbTotalDay.Refresh();
	
	m_pRecordset_Off->Update();
	
	m_nTotalAcount = acount;
	UpdateData(FALSE);
}

void COffdutyDlg::OnPrintDayBtn() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	
	CDC dc;
	//把打印设备环境附加到DC对象
	CPrintDialog pdlg(FALSE,PD_NOPAGENUMS|PD_NOSELECTION,this);
	BOOL bFindPrinter=pdlg.GetDefaults();
	if(!bFindPrinter)
		return ;
	dc.Attach(pdlg.GetPrinterDC());
	
	//取打印机的横方向和纵方向的分辨率
	//即每英寸点数
	short cxInch = dc.GetDeviceCaps(LOGPIXELSX);
	short cyInch = dc.GetDeviceCaps(LOGPIXELSY);
	//字体
	CFont font;
	VERIFY(font.CreatePointFont(96, "宋体", &dc));//为DC创建字体
	CFont* def_font = dc.SelectObject(&font);//保存现在的字体
	
	//根据字体宽度、高度计算每行最大字数及每页最大行数
	//取打印纸张高度和宽度
	int nPageHeight, nPageWidth;
	nPageHeight = dc.GetDeviceCaps(VERTRES);
	nPageWidth = dc.GetDeviceCaps(HORZRES);
	
	TEXTMETRIC TextM;
	dc.GetTextMetrics(&TextM);
	//字体高度	//字体平均宽度
	int nCharHeight = (unsigned short)TextM.tmHeight;
	int nCharWidth=(unsigned short)TextM.tmAveCharWidth;
	
	//每行最大字数	//每页最大行数
	int	m_MaxLineChar = nPageWidth / nCharWidth - 8; 
	int	m_LinesPerPage = nPageHeight/ nCharHeight; 
	
	//页边距
	int nXMargin = 2;
	int nYMargin = 2;
	
	//获得行数
	int i;	
	
	//设置所需打印纸张数目
	DOCINFO di;
	di.cbSize = sizeof(DOCINFO);
	di.lpszDocName = "CalDay printing"; 
	di.lpszOutput = (LPTSTR) NULL; 
	di.lpszDatatype = (LPTSTR) NULL; 
	di.fwType = 0; 
	dc.StartDoc(&di);
	dc.StartPage();
	
	//输出报表名称
	CString stitle,sftitle,space="";
	stitle="当日销售报表";
	int n=(36-stitle.GetLength())/2;
	for(i=0;i<n;i++)
		space=space+" ";
	sftitle=space+stitle;
	dc.TextOut(2, nYMargin+nCharHeight,sftitle, strlen(sftitle));

	//输出收银员
	CString sname;
	sname ="收 银 员:"+m_strDayName;
	dc.TextOut( 2, nYMargin+nCharHeight*3, sname, strlen(sname));	
	//输出下班时间
	CString sofftime;
	m_timectrlOff.GetWindowText(sofftime);
	sofftime=  "下班时间:"+sofftime;
	dc.TextOut( 2+nCharWidth*20, nYMargin+nCharHeight*3, sofftime, strlen(sofftime));
	//输出总单数
	CString sacount;
	sacount.Format("%d",m_nTotalAcount);
	sacount = "总 单 数:" + sacount;
	dc.TextOut( 2, nYMargin+nCharHeight*4, sacount, strlen(sacount));
	
	stitle="--------------销售汇总----------------------";
	dc.TextOut( 2, nYMargin+nCharHeight*6, stitle, strlen(stitle));
	
	//输出列表的列标题
	CString slisttitle;
	slisttitle="付款方式                      金额(元)";
	dc.TextOut( 2, nYMargin+nCharHeight*7,slisttitle, strlen(slisttitle));	
	
	int nMaxLinePerPage = nPageHeight/nCharHeight -3;//每页最大行数
	int nCurPage =1;
	
	//输出各列的数据
	//-------------------------//
	CString sql;
	
	sql =  "SELECT * FROM CalDayInfo ";
	m_pRecordset_Off.CreateInstance("ADODB.Recordset");
	m_pRecordset_Off->Open((_variant_t)sql,_variant_t((IDispatch *)theApp.m_pConnection,true),adOpenDynamic,adLockPessimistic,adCmdText);
	int m_nLineCount = m_pRecordset_Off->GetRecordCount();
	//-------------------------//
	
	CString name,acount;//各种支付方式的综合

	i=0;
	while(!m_pRecordset_Off->adoEOF)
	{
		if(m_nLineCount+7-(nCurPage-1)*nMaxLinePerPage > nMaxLinePerPage)
		{
			//新的一页
			dc.EndPage();
			dc.StartPage();
			nCurPage ++;
		}
		
		name = m_pRecordset_Off->GetCollect("mode").bstrVal;
		acount.Format("%d",m_pRecordset_Off->GetCollect("money").lVal) ;
		
		dc.TextOut( 2, nYMargin+(i+8-(nCurPage-1)*nMaxLinePerPage)*nCharHeight, 
			name, strlen(name));
		dc.TextOut( 2+nCharWidth*30, nYMargin+(i+8-(nCurPage-1)*nMaxLinePerPage)*nCharHeight, 
			acount, strlen(acount));
		
		m_pRecordset_Off->MoveNext();
		i++;
	}
	stitle="------------------------------------";
	
	dc.EndPage();
	dc.EndDoc();
	//打印结束
	//最后不要忘记将字体还原,这一句是必需的
	dc.SelectObject(def_font); //恢复原来的字体
	font.DeleteObject(); 
	
	DeleteDC(dc.Detach()); 
	
	return;// TRUE;			
}

⌨️ 快捷键说明

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