?? sell.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 + -