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

📄 dlgcheckout.cpp

📁 本系统功能主要有两大块组成:前台销售管理功能和后台数据管理功能。 前台销售管理系统,包括:开单
💻 CPP
字号:
// Dlgcheckout.cpp : implementation file
//

#include "stdafx.h"
#include "Lhj_cyglxt.h"
#include "Dlgcheckout.h"
#include "DlgLogin.h"

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

/////////////////////////////////////////////////////////////////////////////
// CDlgcheckout dialog
extern CString GetBillId;
extern CDatabase m_db;
extern CString username;


CDlgcheckout::CDlgcheckout(CWnd* pParent /*=NULL*/)
	: CDialog(CDlgcheckout::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDlgcheckout)
	m_begintime = _T("");
	m_billid = _T("");
	m_cardid = _T("");
	m_change = _T("");
	m_endtime = _T("");
	m_getmoney = _T("");
	m_getmoneyperson = _T("");
	m_jifen = _T("");
	m_paymoney = _T("");
	m_personnum = _T("");
	m_subprice = _T("");
	m_tableno = _T("");
	m_totalprice = _T("");
	m_paystation = _T("");
	//}}AFX_DATA_INIT
}


void CDlgcheckout::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDlgcheckout)
	DDX_Control(pDX, IDC_EDIT_getmoney, m_ogetmenoy);
	DDX_Control(pDX, IDC_LIST_showmenu, m_menulist);
	DDX_Text(pDX, IDC_EDIT_begintime, m_begintime);
	DDX_Text(pDX, IDC_EDIT_billid, m_billid);
	DDX_Text(pDX, IDC_EDIT_cardid, m_cardid);
	DDX_Text(pDX, IDC_EDIT_change, m_change);
	DDX_Text(pDX, IDC_EDIT_endtime, m_endtime);
	DDX_Text(pDX, IDC_EDIT_getmoney, m_getmoney);
	DDX_Text(pDX, IDC_EDIT_getmoneyperson, m_getmoneyperson);
	DDX_Text(pDX, IDC_EDIT_jifen, m_jifen);
	DDX_Text(pDX, IDC_EDIT_paymoney, m_paymoney);
	DDX_Text(pDX, IDC_EDIT_personnum, m_personnum);
	DDX_Text(pDX, IDC_EDIT_subprice, m_subprice);
	DDX_Text(pDX, IDC_EDIT_tableno, m_tableno);
	DDX_Text(pDX, IDC_EDIT_totalprice, m_totalprice);
	DDX_Text(pDX, IDC_EDIT_paystation, m_paystation);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDlgcheckout, CDialog)
	//{{AFX_MSG_MAP(CDlgcheckout)
	ON_EN_CHANGE(IDC_EDIT_getmoney, OnChangeEDITgetmoney)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDlgcheckout message handlers

BOOL CDlgcheckout::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	if(!UpdateData())
		return 0;
	if(!m_db.IsOpen())
	{
		MessageBox("数据库未打开");
		return 0;
	}
TRY
{
	    DWORD dwExStyle = LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES |
    LVS_EX_HEADERDRAGDROP | LVS_EX_ONECLICKACTIVATE | LVS_EX_UNDERLINEHOT;
		m_menulist.SetExtendedStyle(dwExStyle);
		m_menulist.InsertColumn(0,"菜类别",LVCFMT_CENTER,80);
		m_menulist.InsertColumn(1,"菜编号",LVCFMT_CENTER,100);
		m_menulist.InsertColumn(2,"菜名",LVCFMT_CENTER,120);
		m_menulist.InsertColumn(3,"价格",LVCFMT_CENTER,60);
		CRecordset rs(&m_db);
		CString sql;
		int get_bill_id=atoi(GetBillId);//从 CLhj_cyglxtDlg  下拉框 得到的账单号
		sql.Format("select bill_id,bill.vip_card,person_num,table_no,get_money_person,pay_state,begin_time,end_time,total_price,receive,change_back,vip_integral from bill,users_infor,vip_infor where vip_infor.vip_card=bill.vip_card and bill_id=%d",get_bill_id);
		rs.Open(CRecordset::dynaset, sql);
		int temp;
		CDBVariant var;
		rs.GetFieldValue((short)0, var, SQL_C_SLONG);// bill_id
		if (var.m_dwType != DBVT_NULL)	
				temp= var.m_lVal;
		m_billid.Format("%d",temp);
		var.Clear();
		
		rs.GetFieldValue((short)1,m_cardid);// vip_card
		
		rs.GetFieldValue((short)2, var, SQL_C_SLONG);// person_num
		if (var.m_dwType != DBVT_NULL)	
				temp= var.m_lVal;
		m_personnum.Format("%d",temp);
		var.Clear();
		
		rs.GetFieldValue((short)3, var, SQL_C_SLONG);// table_no,,,,
		if (var.m_dwType != DBVT_NULL)	
				temp= var.m_lVal;
		m_tableno.Format("%d",temp);
		var.Clear();
		
		rs.GetFieldValue((short)4,m_getmoneyperson);// get_money_person
		//m_getmoneyperson 为空说明是未结帐  //结帐人填 登录人
		rs.GetFieldValue((short)5,m_paystation);// pay_state
		rs.GetFieldValue((short)6,m_begintime);// begin_time
		rs.GetFieldValue((short)7,m_endtime);// end_time  
		rs.GetFieldValue((short)8,m_totalprice);// total_price,
		rs.GetFieldValue((short)9,m_getmoney);// receive,
		rs.GetFieldValue((short)10,m_change);// change_back,
		rs.GetFieldValue((short)11, var, SQL_C_SLONG);//  vip_integral
		if (var.m_dwType != DBVT_NULL)	
				temp= var.m_lVal;
		m_jifen.Format("%d",temp);
		var.Clear();
		rs.Close();

		sql.Format("select class_name,menu_infor.food_id,food_name,food_price from menu_infor,food_class,bill_menu where bill_menu.food_id=menu_infor.food_id and food_class.food_class=menu_infor.food_class and bill_id=%d",get_bill_id);
		rs.Open(CRecordset::dynaset, sql);
		CString classname,foodid,foodname,price;int i=0;double sumprice=0,subprice,paymoney;
		while (!rs.IsEOF()) 
		{ 
		   rs.GetFieldValue((short)0,classname);
		   m_menulist.InsertItem(i,classname);
		   rs.GetFieldValue(1,foodid);
		   m_menulist.SetItemText(i,1,foodid);
		   rs.GetFieldValue(2,foodname);
		   m_menulist.SetItemText(i,2,foodname);
		   rs.GetFieldValue(3,price);
		   m_menulist.SetItemText(i,3,price);
		   sumprice=sumprice+atoi(price);
			rs.MoveNext();
		}
		m_totalprice.Format("%.1f",sumprice);
		subprice=(sumprice+atoi(m_jifen))*0.05;
		m_subprice.Format("%.1f",subprice);
		paymoney=sumprice-subprice;
		m_paymoney.Format("%.1f",paymoney);
		rs.Close();

		if (m_paystation=="已付")
		{
			m_ogetmenoy.EnableWindow(FALSE);
		}
		else
		{//登录 用户作为结帐人   显示编号
			sql.Format("select user_id from users_infor where user_loginname='%s'",username);
			rs.Open(CRecordset::dynaset, sql);
			if (!rs.IsEOF())
			{
				rs.GetFieldValue((short)0,m_getmoneyperson);
			}
			rs.Close();
			
		}//或
			/*
			if (m_getmoneyperson=="")
			{
			sql.Format("select user_id from users_infor where user_loginname='%s'",username);
			rs.Open(CRecordset::dynaset, sql);
			rs.GetFieldValue((short)0,m_getmoneyperson);
			rs.Close();
			}
			*/

}

	CATCH(CDBException,ex)
	{
		AfxMessageBox (ex->m_strError);
		AfxMessageBox (ex->m_strStateNativeOrigin);		
	}
	AND_CATCH(CMemoryException,pEx)
	{
		pEx->ReportError();
		AfxMessageBox ("memory exception");
	}
	AND_CATCH(CException,e)
	{
		TCHAR szError[100];
		e->GetErrorMessage(szError,100);
		AfxMessageBox (szError);
	}
	END_CATCH   
	UpdateData(FALSE);
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CDlgcheckout::OnOK() 
{
	// TODO: Add extra validation here
        UpdateData(TRUE);
TRY
{   if(!UpdateData())
		return;
	if(!m_db.IsOpen())
	{
		MessageBox("数据库未打开");
		return;
	}
	if (m_paystation=="未付")
	{
		float pay,getmoney;
		pay=atof(m_paymoney);getmoney=atof(m_getmoney);
		if (pay>getmoney)
		{
			AfxMessageBox("您支付的钱不够!!");
			return;
		}
		else
		{
			float change;change=getmoney-pay;
			m_change.Format("%.1f",change);
			CTime currenttime=CTime::GetCurrentTime();
			CString nowtime=currenttime.Format("%H:%M:%S/%#Y/%#m/%#d");//得到系统时间
			m_endtime=nowtime;
			m_paystation="已付";
			CString sql;
			int temp;temp=atoi(m_billid);
			sql.Format("update bill set get_money_person='%s',pay_state='%s',end_time='%s',total_price='%s',receive='%s',change_back='%s' where bill_id=%d",m_getmoneyperson,m_paystation,m_endtime,m_paymoney,m_getmoney,m_change,temp);
			TRACE(sql);
			m_db.ExecuteSQL(sql);
			
			if (m_cardid!="100000")
			{//是系统的 会员卡   积分不累加   一直为 0
				temp=atof(m_jifen)+atof(m_totalprice)*0.03;//总消费的3% 作为积分累加
				sql.Format("update vip_infor set vip_integral=%d where vip_card='%s'",temp,m_cardid);
				TRACE(sql);
				m_db.ExecuteSQL(sql);
				m_jifen.Format("%d",temp);
			}
			AfxMessageBox("支付成功");
			UpdateData(FALSE);
		}
	}
	m_ogetmenoy.EnableWindow(FALSE);
}
	CATCH(CDBException,ex)
	{
		AfxMessageBox (ex->m_strError);
		AfxMessageBox (ex->m_strStateNativeOrigin);		
	}
	AND_CATCH(CMemoryException,pEx)
	{
		pEx->ReportError();
		AfxMessageBox ("memory exception");
	}
	AND_CATCH(CException,e)
	{
		TCHAR szError[100];
		e->GetErrorMessage(szError,100);
		AfxMessageBox (szError);
	}
	END_CATCH   
	UpdateData(FALSE);
	//CDialog::OnOK();
}

void CDlgcheckout::OnChangeEDITgetmoney() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	UpdateData(TRUE);
	CString getmoney;
	m_ogetmenoy.GetWindowText(getmoney);
	float change;change=atof(getmoney)-atof(m_paymoney);
	m_change.Format("%.1f",change);
	UpdateData(FALSE);
	
	// TODO: Add your control notification handler code here
	
}

⌨️ 快捷键说明

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