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

📄 sell.cpp

📁 基于UML的饮料自动售货机系统设计该设计模拟自动售货机的工作原理和方式
💻 CPP
字号:
// Sell.cpp : implementation file
//

#include "stdafx.h"
#include "Wumei.h"
#include "Sell.h"

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

/////////////////////////////////////////////////////////////////////////////
// CSell dialog


CSell::CSell(CWnd* pParent /*=NULL*/)
	: CDialog(CSell::IDD, pParent)
{
	
	//{{AFX_DATA_INIT(CSell)
	m_baishi = FALSE;
	m_kekou = FALSE;
	m_xue = FALSE;
	m_lvcha = FALSE;
	m_10yuan = FALSE;
	m_5yuan = FALSE;
	m_1yuan = FALSE;
	m_05yuan = FALSE;
	m_pesi = _T("");
	m_cola = _T("");
	m_xuebi = _T("");
	m_tea = _T("");
	m_10 = _T("");
	m_5 = _T("");
	m_1 = _T("");
	m_05 = _T("");
	m_money = -1;
	//}}AFX_DATA_INIT
}


void CSell::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CSell)
	DDX_Control(pDX, IDC_LIST2, m_list_money);
	DDX_Control(pDX, IDC_LIST1, m_list);
	DDX_Check(pDX, IDC_CHECK1, m_baishi);
	DDX_Check(pDX, IDC_CHECK2, m_kekou);
	DDX_Check(pDX, IDC_CHECK3, m_xue);
	DDX_Check(pDX, IDC_CHECK4, m_lvcha);
	DDX_Check(pDX, IDC_CHECK5, m_10yuan);
	DDX_Check(pDX, IDC_CHECK6, m_5yuan);
	DDX_Check(pDX, IDC_CHECK7, m_1yuan);
	DDX_Check(pDX, IDC_CHECK8, m_05yuan);
	DDX_Text(pDX, IDC_EDIT1, m_pesi);
	DDX_Text(pDX, IDC_EDIT3, m_cola);
	DDX_Text(pDX, IDC_EDIT4, m_xuebi);
	DDX_Text(pDX, IDC_EDIT5, m_tea);
	DDX_Text(pDX, IDC_EDIT6, m_10);
	DDX_Text(pDX, IDC_EDIT7, m_5);
	DDX_Text(pDX, IDC_EDIT8, m_1);
	DDX_Text(pDX, IDC_EDIT9, m_05);
	DDX_Radio(pDX, IDC_RADIO1, m_money);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CSell, CDialog)
	//{{AFX_MSG_MAP(CSell)
	ON_BN_CLICKED(IDC_BTN_CHECK, OnBtnCheck)
	ON_BN_CLICKED(IDC_BTN_MONEY, OnBtnMoney)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSell message handlers





void CSell::OnBtnCheck() 
{
	// TODO: Add your control notification handler code here
		while(m_list.GetCount())
			m_list.DeleteString(0);

		CoInitialize(NULL);
		_ConnectionPtr pCon(__uuidof(Connection));
		_RecordsetPtr pRed(__uuidof(Recordset));
		
		pCon->ConnectionString="Provider=SQLOLEDB.1;Persist Security Info=True;User ID=sa;Password=000;Initial Catalog=master;Data Source=.";
		pCon->Open("","","",adConnectUnspecified);
		pRed=pCon->Execute("select * from drinks",NULL,adCmdText);

		while(!pRed->rsEOF)
		{
			((CListBox*)GetDlgItem(IDC_LIST1))->AddString(
				(_bstr_t)pRed->GetCollect("dName")+" "
				+(_bstr_t)pRed->GetCollect("dAmount")+"瓶  单价:"
				+(_bstr_t)pRed->GetCollect("dPrice")+"元");

			pRed->MoveNext();
		}

		pRed->Close();
		pCon->Close();

		pRed.Release();
		pCon.Release();


		CoUninitialize();
}

void CSell::OnOK() 
{
	// TODO: Add extra validation here
	UpdateData();

		CoInitialize(NULL);
		_ConnectionPtr pCon(__uuidof(Connection));
		_RecordsetPtr pRed(__uuidof(Recordset));
		
		pCon->ConnectionString="Provider=SQLOLEDB.1;Persist Security Info=True;User ID=sa;Password=000;Initial Catalog=master;Data Source=.";
		pCon->Open("","","",adConnectUnspecified);
//////添加饮料
		CString str1="update drinks set dAmount=dAmount+";
		CString str2;
	if(m_baishi)
	{
		str2=" where dName='百事可乐'";
		pCon->Execute(_bstr_t(str1+m_pesi+str2),NULL,adCmdText);
	}
	if(m_kekou)
	{
		str2=" where dName='可口可乐'";
		pCon->Execute(_bstr_t(str1+m_cola+str2),NULL,adCmdText);
	}
	if(m_xue)
	{
		str2=" where dName='雪碧'";
		pCon->Execute(_bstr_t(str1+m_xuebi+str2),NULL,adCmdText);
	}
	if(m_lvcha)
	{
		str2=" where dName='绿茶'";
		pCon->Execute(_bstr_t(str1+m_tea+str2),NULL,adCmdText);
	}

/////////添加钱币/取走钱币

	CString str3="update moneyInfo set moneyAmount=moneyAmount+";//add
	CString str4="update moneyInfo set moneyAmount=moneyAmount-";//sub
	CString str5;

	if(m_money==0)//set money
	{
		if(m_10yuan)//复选了10元
		{
			str5=" where moneyType='10元'";
			pCon->Execute(_bstr_t(str3+m_10+str5),NULL,adCmdText);
		}
		if(m_5yuan)//复选了5元
		{
			str5=" where moneyType='5元'";
			pCon->Execute(_bstr_t(str3+m_5+str5),NULL,adCmdText);
		}
		if(m_1yuan)//复选了1元
		{
			str5=" where moneyType='1元'";
			pCon->Execute(_bstr_t(str3+m_1+str5),NULL,adCmdText);
		}
		if(m_05yuan)//复选了10元
		{
			str5=" where moneyType='0.5元'";
			pCon->Execute(_bstr_t(str3+m_05+str5),NULL,adCmdText);
		}
	}//if set money
	else if(m_money==1)
	{
		
		if(m_10yuan)//复选了10元
		{
			
			pRed=pCon->Execute("select moneyAmount from moneyInfo where moneyType='10元'",NULL,adCmdText);
			_variant_t vCount=pRed->GetCollect("moneyAmount");
			int amount=atoi(m_10) ;
			if(amount <= vCount.lVal)//ok
            {
				str5=" where moneyType='10元'";
				pCon->Execute(_bstr_t(str4+m_10+str5),NULL,adCmdText);
			}
			else
			{
				MessageBox("you can't get so much...");
			}
			 
		}
		if(m_5yuan)//复选了5元
		{
			pRed=pCon->Execute("select moneyAmount from moneyInfo where moneyType='5元'",NULL,adCmdText);
			_variant_t vCount=pRed->GetCollect("moneyAmount");
			int amount=atoi(m_5) ;
			if(amount <= vCount.lVal)//ok
            {
				str5=" where moneyType='5元'";
				pCon->Execute(_bstr_t(str4+m_5+str5),NULL,adCmdText);
			}
			else
			{
				MessageBox("you can't get so much...");
			}
		}
		if(m_1yuan)//复选了1元
		{
			pRed=pCon->Execute("select moneyAmount from moneyInfo where moneyType='1元'",NULL,adCmdText);
			_variant_t vCount=pRed->GetCollect("moneyAmount");
			int amount=atoi(m_1) ;
			if(amount <= vCount.lVal)//ok
            {
				str5=" where moneyType='1元'";
				pCon->Execute(_bstr_t(str4+m_1+str5),NULL,adCmdText);
			}
			else
			{
				MessageBox("you can't get so much...");
			}
		}
		if(m_05yuan)//复选了0.5元
		{
			pRed=pCon->Execute("select moneyAmount from moneyInfo where moneyType='0.5元'",NULL,adCmdText);
			_variant_t vCount=pRed->GetCollect("moneyAmount");
			int amount=atoi(m_05) ;
			if(amount <= vCount.lVal)//ok
            {
				str5=" where moneyType='0.5元'";
				pCon->Execute(_bstr_t(str4+m_05+str5),NULL,adCmdText);
			}
			else
			{
				MessageBox("you can't get so much...");
			}
		}
		pRed->Close();

		pRed.Release();
	}//else take away money

		pCon->Close();
	   
		pCon.Release();


		CoUninitialize();

	m_baishi = FALSE;
	m_kekou = FALSE;
	m_xue = FALSE;
	m_lvcha = FALSE;
	m_10yuan = FALSE;
	m_5yuan = FALSE;
	m_1yuan = FALSE;
	m_05yuan = FALSE;
	m_pesi = _T("");
	m_cola = _T("");
	m_xuebi = _T("");
	m_tea = _T("");
	m_10 = _T("");
	m_5 = _T("");
	m_1 = _T("");
	m_05 = _T("");
	m_money = -1;

	UpdateData(FALSE);

//	CDialog::OnOK();
}



void CSell::OnBtnMoney() 
{
	// TODO: Add your control notification handler code here

	while(m_list_money.GetCount())
			m_list_money.DeleteString(0);

		CoInitialize(NULL);
		_ConnectionPtr pCon(__uuidof(Connection));
		_RecordsetPtr pRed(__uuidof(Recordset));
		
		pCon->ConnectionString="Provider=SQLOLEDB.1;Persist Security Info=True;User ID=sa;Password=000;Initial Catalog=master;Data Source=.";
		pCon->Open("","","",adConnectUnspecified);
		pRed=pCon->Execute("select * from moneyInfo",NULL,adCmdText);

		while(!pRed->rsEOF)
		{
			((CListBox*)GetDlgItem(IDC_LIST2))->AddString(
				(_bstr_t)pRed->GetCollect("moneyType")+"* "
				+(_bstr_t)pRed->GetCollect("moneyAmount")+" 张");

			pRed->MoveNext();
		}


		pRed->Close();
		pCon->Close();

		pRed.Release();
		pCon.Release();


		CoUninitialize();
}

//DEL void CSell::openDB_drinks()
//DEL {
//DEL 
//DEL }

⌨️ 快捷键说明

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