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

📄 paydlg.cpp

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

#include "stdafx.h"
#include "MenuManage.h"
#include "PayDlg.h"
#include "Columns.h"
#include "Column.h"

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

extern CMenuManageApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CPayDlg dialog


CPayDlg::CPayDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CPayDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CPayDlg)
	m_nPayDeskNumber = 0;
	m_nPayRealPrice = 0;
	m_nPayRePrice = 0;
	m_nPayTotalPrice = 0;
	m_strPayUserName = _T("");
	m_strPaymode = _T("人民币");
	m_timePay = COleDateTime::GetCurrentTime();
	//}}AFX_DATA_INIT
}


void CPayDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CPayDlg)
	DDX_Control(pDX, IDC_COMBO_PAYMODE, m_coPaymode);
	DDX_Text(pDX, IDC_PAY_DESK_NUMBER, m_nPayDeskNumber);
	DDX_Text(pDX, IDC_PAY_REALPRICE, m_nPayRealPrice);
	DDX_Text(pDX, IDC_PAY_REPAYPRICE, m_nPayRePrice);
	DDX_Text(pDX, IDC_PAY_TOTALPRICE, m_nPayTotalPrice);
	DDX_Text(pDX, IDC_PAY_PEOPLE, m_strPayUserName);
	DDX_CBString(pDX, IDC_COMBO_PAYMODE, m_strPaymode);
	DDX_Control(pDX, IDC_DATAGRID_PAY, m_dbPay);
	DDX_DateTimeCtrl(pDX, IDC_DATETIMEPICKER_PAY, m_timePay);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CPayDlg, CDialog)
	//{{AFX_MSG_MAP(CPayDlg)
	ON_EN_UPDATE(IDC_PAY_DESK_NUMBER, OnUpdatePayDeskNumber)
	ON_EN_UPDATE(IDC_PAY_REALPRICE, OnUpdatePayRealprice)
	ON_BN_CLICKED(IDC_PAY_PRINT_BTN, OnPayPrintBtn)
	ON_BN_CLICKED(IDC_CANCEL, OnCancel)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPayDlg message handlers

void CPayDlg::OnOK() 
{
	// TODO: Add extra validation here
	//--------desk表已结----------------------//	
	UpdateData(TRUE);

	if(m_nPayDeskNumber == 0)
	{
		AfxMessageBox("请输入餐桌编号");
		return;		
	}
	if(m_nPayRealPrice<m_nPayTotalPrice)
	{
		AfxMessageBox("金额不足");
		return;
	}	
	CString str,sql,str1;
	str.Format("%d",m_nPayDeskNumber);
	int temp=0;
	str1.Format("%d",temp);
	sql =  "SELECT * FROM DeskInfo WHERE DeskNum = "+str+" and DeskCheck = "+str1+"";
	m_pRecordset_Desk.CreateInstance("ADODB.Recordset");
	m_pRecordset_Desk->Open((_variant_t)sql,_variant_t((IDispatch *)theApp.m_pConnection,true),adOpenDynamic,adLockPessimistic,adCmdText);
	
	if(m_pRecordset_Desk->GetRecordCount()!=0)
	{	
		if (AfxMessageBox("是否打印账单?",MB_YESNO)==IDYES) 
		{
			OnPayPrintBtn();
		}
		temp = 1;
		str.Format("%d" , temp);
		m_pRecordset_Desk->PutCollect("DeskCheck",(_variant_t)str);
		
		//付款方式
		int selmode;
		selmode = m_coPaymode.GetCurSel();
		m_coPaymode.GetLBText(selmode,m_strPaymode);
		
		m_pRecordset_Desk->PutCollect("DeskPaymode",_variant_t(m_strPaymode));
		//时间
		CString paytime;
		CTime now=CTime::GetCurrentTime();
		paytime=now.Format(_T("%Y-%m-%d %H:%M:%S"));
		m_pRecordset_Desk->PutCollect("DeskDateTime",(_variant_t)paytime);
		
		//收银员
		m_pRecordset_Desk->PutCollect("DeskName",(_variant_t)m_strPayUserName);		
		m_pRecordset_Desk->Update();	
		m_pRecordset_Desk ->Close();
		
		//-----------order表已结-----------------------------//
		str.Format("%d",m_nPayDeskNumber);
		sql =  "SELECT * FROM OrderInfo WHERE DeskNum = "+str+" and FoodCheck = "+str1+" ";
		m_pRecordset_Order.CreateInstance("ADODB.Recordset");
		m_pRecordset_Order->Open((_variant_t)sql,_variant_t((IDispatch *)theApp.m_pConnection,true),adOpenDynamic,adLockPessimistic,adCmdText);
		
		if(m_pRecordset_Order->GetRecordCount()!=0)
		{
			temp=1;
			str.Format("%d" , temp);
			
			while(!m_pRecordset_Order -> adoEOF)//如果不是最后一条记录
			{
				m_pRecordset_Order->PutCollect("FoodCheck",(_variant_t)str);
				m_pRecordset_Order->Update();
				m_pRecordset_Order->MoveNext();//指针下移
			}
			m_pRecordset_Order ->Close();
		}

	//--------------------------------------------//
	}
	str.Format("%d",m_nPayDeskNumber);
	str += "号桌已结帐";
	AfxMessageBox(str);

//	CDialog::OnOK();
}


void CPayDlg::OnUpdatePayDeskNumber() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	
	CString str,sql,str1;
	str.Format("%d",m_nPayDeskNumber);
	int temp;
	temp = 0;
	str1.Format("%d",temp);

	//自动计算出对应餐桌应付金额
	sql =  "SELECT * FROM DeskInfo WHERE DeskNum = "+str+"and DeskCheck = "+str1+"  ";
	m_pRecordset_Desk.CreateInstance("ADODB.Recordset");
	m_pRecordset_Desk->Open((_variant_t)sql,_variant_t((IDispatch *)theApp.m_pConnection,true),adOpenDynamic,adLockPessimistic,adCmdText);
	
	if(m_pRecordset_Desk->GetRecordCount() != 0)//如果记录集不为空
	{
		m_nPayTotalPrice = m_pRecordset_Desk->GetCollect("DeskPrice").lVal;
	}
	
	m_pRecordset_Desk ->Close();

	//将点菜信息绑定到db
	sql =  "SELECT * FROM OrderInfo WHERE DeskNum = "+str+"and FoodCheck = "+str1+"  ";
	m_pRecordset_Order.CreateInstance("ADODB.Recordset");
	m_pRecordset_Order->Open((_variant_t)sql,_variant_t((IDispatch *)theApp.m_pConnection,true),adOpenDynamic,adLockPessimistic,adCmdText);
	
	m_dbPay.SetRefDataSource(NULL);
	m_dbPay.SetRefDataSource((LPUNKNOWN)m_pRecordset_Order);
	m_dbPay.SetColumnHeaders(1) ;
	
	m_dbPay.Refresh();	
	
	UpdateData(FALSE);	
}

BOOL CPayDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
		
	// TODO: Add extra initialization here
	m_strPayUserName = theApp.m_name;
	CString sql;
	sql="SELECT * FROM PayModeInfo order by ID";
	m_pRecordset_Paymode.CreateInstance("ADODB.Recordset");
	m_pRecordset_Paymode->Open((_variant_t)sql,_variant_t((IDispatch *)theApp.m_pConnection,true),adOpenDynamic,adLockPessimistic,adCmdText);
	
	if(m_pRecordset_Paymode->GetRecordCount()!=0)
	{
		while(!m_pRecordset_Paymode->adoEOF)
		{
			m_coPaymode.AddString((LPCTSTR)(_bstr_t)m_pRecordset_Paymode->GetCollect("NAME"));
			m_pRecordset_Paymode->MoveNext();
		}
		m_pRecordset_Paymode->Close();
		m_coPaymode.SetCurSel(0);
	}
	UpdateData(FALSE);

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CPayDlg::OnUpdatePayRealprice() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	//找零=实收金额-应收金额
	m_nPayRePrice = m_nPayRealPrice - m_nPayTotalPrice;
	
	UpdateData(FALSE);	
}	
	


void CPayDlg::OnPayPrintBtn() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	
	//把打印设备环境附加到DC对象
	CDC 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;
	//为DC创建字体
	VERIFY(font.CreatePointFont(96, "宋体", &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 = "MyMenu 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 stable,speople,spaymode;
	stable.Format("%d",m_nPayDeskNumber);
	speople = m_strPayUserName;
	spaymode = m_strPaymode;

	stable=  "桌    号:"+stable;
	speople= "收 银 员:"+speople;
	spaymode="付款方式:"+spaymode;
	dc.TextOut( 2, nYMargin+nCharHeight*3, stable, strlen(stable));
	dc.TextOut( 2, nYMargin+nCharHeight*4, speople, strlen(speople));
	dc.TextOut( 2, nYMargin+nCharHeight*5, spaymode, strlen(spaymode));

	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 str,sql,str1;
	str.Format("%d",m_nPayDeskNumber);
	int temp=0;
	str1.Format("%d",temp);
	sql =  "SELECT * FROM OrderInfo WHERE DeskNum = "+str+" and FoodCheck = "+str1+"";
	m_pRecordset_Order.CreateInstance("ADODB.Recordset");
	m_pRecordset_Order->Open((_variant_t)sql,_variant_t((IDispatch *)theApp.m_pConnection,true),adOpenDynamic,adLockPessimistic,adCmdText);
	int m_nLineCount = m_pRecordset_Order->GetRecordCount();
	//-------------------------//

	CString name,signalprice,acount,totalprice;
	int totalacount=0;
	i=0;
	while(!m_pRecordset_Order->adoEOF)
	{
		if(m_nLineCount+7-(nCurPage-1)*nMaxLinePerPage > nMaxLinePerPage)
		{
			//新的一页
			dc.EndPage();
			dc.StartPage();
			nCurPage ++;
		}

		name = m_pRecordset_Order->GetCollect("FoodName").bstrVal;
		signalprice.Format("%d",m_pRecordset_Order->GetCollect("FoodSignalPrice").lVal) ;
		acount.Format("%d",m_pRecordset_Order->GetCollect("FoodAcount").lVal);
		totalprice.Format("%d",m_pRecordset_Order->GetCollect("FoodPrice").lVal);
		totalacount += m_pRecordset_Order->GetCollect("FoodAcount").lVal;
				
		dc.TextOut( 2, nYMargin+(i+8-(nCurPage-1)*nMaxLinePerPage)*nCharHeight, 
				name, strlen(name));
		dc.TextOut( 2+nCharWidth*15, nYMargin+(i+8-(nCurPage-1)*nMaxLinePerPage)*nCharHeight, 
				signalprice, strlen(signalprice));
		dc.TextOut( 2+nCharWidth*23, nYMargin+(i+8-(nCurPage-1)*nMaxLinePerPage)*nCharHeight, 
				acount, strlen(acount));
		dc.TextOut( 2+nCharWidth*29, nYMargin+(i+8-(nCurPage-1)*nMaxLinePerPage)*nCharHeight, 
				totalprice, strlen(totalprice));

		m_pRecordset_Order->MoveNext();
		i++;
	}
	stitle="------------------------------------";
	dc.TextOut( 2, nYMargin+(m_nLineCount+8-(nCurPage-1)*nMaxLinePerPage)*nCharHeight, 
		stitle, strlen(stitle));
	//输出数量、件数
	CString snum,sacount;
	snum.Format("%d",totalacount);
	sacount.Format("%d",m_nLineCount);
	snum =  "数    量:"+snum;
	sacount="件    数:"+sacount;
	dc.TextOut( 2, nYMargin+(m_nLineCount+9-(nCurPage-1)*nMaxLinePerPage)*nCharHeight, 
		snum, strlen(snum));
	dc.TextOut( 2, nYMargin+(m_nLineCount+10-(nCurPage-1)*nMaxLinePerPage)*nCharHeight, 
		sacount, strlen(sacount));			
	//输出总金额:应收金额、实收金额、找零
	CString stotal,srealtotal,sdiscount;
	stotal.Format("%d",m_nPayTotalPrice);
	srealtotal.Format("%d",m_nPayRealPrice);	
	sdiscount.Format("%d",m_nPayRePrice);

	stotal=    "应收金额:"+stotal;
	srealtotal="实收金额:"+srealtotal;
	sdiscount= "找    零:"+sdiscount;
	
	dc.TextOut( 2, nYMargin+(m_nLineCount+11-(nCurPage-1)*nMaxLinePerPage)*nCharHeight, 
		stotal, strlen(stotal));
	dc.TextOut( 2, nYMargin+(m_nLineCount+12-(nCurPage-1)*nMaxLinePerPage)*nCharHeight, 
		srealtotal, strlen(srealtotal));
	dc.TextOut( 2, nYMargin+(m_nLineCount+13-(nCurPage-1)*nMaxLinePerPage)*nCharHeight, 
		sdiscount, strlen(sdiscount));
	//------------------------------------------------//
	stitle="------------------------------------";
	dc.TextOut( 2, nYMargin+(m_nLineCount+14-(nCurPage-1)*nMaxLinePerPage)*nCharHeight, 
		stitle, strlen(stitle));

	//输出结帐时间
	CString paytime;
	CTime now=CTime::GetCurrentTime();
	paytime=now.Format(_T("%Y-%m-%d %H:%M:%S"));
	paytime="结账时间:"+paytime;
	dc.TextOut( 2, nYMargin+(m_nLineCount+15-(nCurPage-1)*nMaxLinePerPage)*nCharHeight, 
		paytime, strlen(paytime));

	srealtotal="谢谢惠顾,欢迎再次光临!";
	dc.TextOut( 2, nYMargin+(m_nLineCount+16-(nCurPage-1)*nMaxLinePerPage)*nCharHeight, 
		srealtotal, strlen(srealtotal));

	//打印结束	
	dc.EndPage();	
	dc.EndDoc();

	//恢复原来的字体
	dc.SelectObject(def_font); 
	font.DeleteObject(); 

	DeleteDC(dc.Detach()); 

	return;// TRUE;	
}

void CPayDlg::OnCancel() 
{
	// TODO: Add your control notification handler code here
	CDialog::OnOK();
}

⌨️ 快捷键说明

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