📄 drinksellmachinedlg.cpp
字号:
// DrinkSellMachineDlg.cpp : implementation file
//
#include "stdafx.h"
#include "DrinkSellMachine.h"
#include "DrinkSellMachineDlg.h"
#include "FillDrink.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDrinkSellMachineDlg dialog
CDrinkSellMachineDlg::CDrinkSellMachineDlg(CWnd* pParent /*=NULL*/)
: CDialog(CDrinkSellMachineDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CDrinkSellMachineDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CDrinkSellMachineDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDrinkSellMachineDlg)
DDX_Control(pDX, IDC_COMBO_COINVALUE, m_cmbCoinValue);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDrinkSellMachineDlg, CDialog)
//{{AFX_MSG_MAP(CDrinkSellMachineDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BTN_INSERTCOIN, OnBtnInsertcoin)
ON_BN_CLICKED(IDC_BTN_EJECTCOIN, OnBtnEjectcoin)
ON_BN_CLICKED(IDC_BUTTON_FIRST_KEY, OnButtonFirstKey)
ON_BN_CLICKED(IDC_BUTTON_SECORD_KEY, OnButtonSecordKey)
ON_BN_CLICKED(IDC_BUTTON_THIRD_KEY, OnButtonThirdKey)
ON_BN_CLICKED(IDC_BUTTON_FOURTH_KEY, OnButtonFourthKey)
ON_BN_CLICKED(IDC_BUTTON_FIFTH_KEY, OnButtonFifthKey)
ON_BN_CLICKED(IDC_BTN_GET_BACK_BLANCE, OnBtnGetBackBlance)
ON_BN_CLICKED(IDC_BTN_GET_BACK_BUYED_DRINK, OnBtnGetBackBuyedDrink)
ON_BN_CLICKED(IDC_BTN_FILL_DRINK, OnBtnFillDrink)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDrinkSellMachineDlg message handlers
BOOL CDrinkSellMachineDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
m_cmbCoinValue.InsertString(0,"0.5");
m_cmbCoinValue.InsertString(1,"1");
m_cmbCoinValue.InsertString(2,"5");
m_cmbCoinValue.InsertString(3,"10");
m_cmbCoinValue.SetCurSel(1);
GetDlgItem(IDC_STATIC_TOTALCOIN)->SetWindowText("金额:0.00");
GetDlgItem(IDC_STATIC_BALANCE)->SetWindowText("余额:0.00");
m_drinkMachine.SetSellOverLights();
DisSellOverLights();
DisplayDrinkName();
return TRUE; // return TRUE unless you set the focus to a control
}
void CDrinkSellMachineDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CDrinkSellMachineDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CDrinkSellMachineDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CDrinkSellMachineDlg::OnBtnInsertcoin()
{
// TODO: Add your control notification handler code here
//CString strtemp;
//m_cmbCoinValue.GetLBText(m_cmbCoinValue.GetCurSel(),strtemp);
//nCoinValue = atof((LPCSTR)strtemp);
double coinValuleTable[] = {0.5,1,5,10};
double nCoinValue = 0;
nCoinValue = coinValuleTable[m_cmbCoinValue.GetCurSel()];
m_drinkMachine.InsertCoin(nCoinValue);
DisplayTotalCoin();
DisSelectLights();
}
void CDrinkSellMachineDlg::OnBtnEjectcoin()
{
// TODO: Add your control notification handler code here
double dBlance = m_drinkMachine.EjectCoin();
DisplayLEDInfo();
DisplayTotalCoin();
DisplayBlance();
DisSelectLights();
}
void CDrinkSellMachineDlg::DisplayTotalCoin()
{
double dTotalCoin = 0;
dTotalCoin = m_drinkMachine.GetTotalCoin();
CString strTemp;
strTemp.Format("%.2f",dTotalCoin);
GetDlgItem(IDC_STATIC_TOTALCOIN)->SetWindowText("金额:"+strTemp);
}
void CDrinkSellMachineDlg::DisplayLEDInfo()
{
GetDlgItem(IDC_STATIC_lEDINFO)->SetWindowText(m_drinkMachine.GetInfoLED());
}
void CDrinkSellMachineDlg::DisplayBlance()
{
double dBlance = 0.00;
dBlance = m_drinkMachine.GetBlnce();
CString strTemp;
strTemp.Format("%.2f",dBlance);
GetDlgItem(IDC_STATIC_BALANCE)->SetWindowText("余额:"+strTemp);
}
void CDrinkSellMachineDlg::OnButtonFirstKey()
{
// TODO: Add your control notification handler code here
m_drinkMachine.SelectDrinkButton(0);
DisplayLEDInfo();
DisplayTotalCoin();
DisplayBlance();
DisplauBuyedName();
DisSellOverLights();
DisSelectLights();
//DisplayBlance(dBlance);
}
void CDrinkSellMachineDlg::OnButtonSecordKey()
{
// TODO: Add your control notification handler code here
m_drinkMachine.SelectDrinkButton(1);
DisplayLEDInfo();
DisplayTotalCoin();
DisplayBlance();
DisplauBuyedName();
DisSellOverLights();
DisSelectLights();
}
void CDrinkSellMachineDlg::OnButtonThirdKey()
{
// TODO: Add your control notification handler code here
m_drinkMachine.SelectDrinkButton(2);
DisplayLEDInfo();
DisplayTotalCoin();
DisplayBlance();
DisplauBuyedName();
DisSellOverLights();
DisSelectLights();
}
void CDrinkSellMachineDlg::OnButtonFourthKey()
{
// TODO: Add your control notification handler code here
m_drinkMachine.SelectDrinkButton(3);
DisplayLEDInfo();
DisplayTotalCoin();
DisplayBlance();
DisplauBuyedName();
DisSellOverLights();
DisSelectLights();
}
void CDrinkSellMachineDlg::OnButtonFifthKey()
{
// TODO: Add your control notification handler code here
m_drinkMachine.SelectDrinkButton(4);
DisplayLEDInfo();
DisplayTotalCoin();
DisplayBlance();
DisplauBuyedName();
DisSellOverLights();
DisSelectLights();
}
void CDrinkSellMachineDlg::DisplauBuyedName()
{
GetDlgItem(IDC_STATIC_BUYED_NAME)->SetWindowText(m_drinkMachine.GetSetBuyedDrinkName());
}
void CDrinkSellMachineDlg::OnBtnGetBackBlance()
{
// TODO: Add your control notification handler code here
m_drinkMachine.GetBackBlnce();
DisplayBlance();
}
void CDrinkSellMachineDlg::OnBtnGetBackBuyedDrink()
{
// TODO: Add your control notification handler code here
m_drinkMachine.GetBackBuyedName();
DisplauBuyedName();
}
void CDrinkSellMachineDlg::DisSelectLights()
{
if (m_drinkMachine.m_bSelectLight[0] == true)
{
GetDlgItem(IDC_STATIC_FIRST)->SetWindowText("亮");
}
else
{
GetDlgItem(IDC_STATIC_FIRST)->SetWindowText("");
}
if (m_drinkMachine.m_bSelectLight[1] == true)
{
GetDlgItem(IDC_STATIC_SECORD)->SetWindowText("亮");
}
else
{
GetDlgItem(IDC_STATIC_SECORD)->SetWindowText("");
}
if (m_drinkMachine.m_bSelectLight[2] == true)
{
GetDlgItem(IDC_STATIC_THIRD)->SetWindowText("亮");
}
else
{
GetDlgItem(IDC_STATIC_THIRD)->SetWindowText("");
}
if (m_drinkMachine.m_bSelectLight[3] == true)
{
GetDlgItem(IDC_STATIC_FOUTH)->SetWindowText("亮");
}
else
{
GetDlgItem(IDC_STATIC_FOUTH)->SetWindowText("");
}
if (m_drinkMachine.m_bSelectLight[4] == true)
{
GetDlgItem(IDC_STATIC_FIFTH)->SetWindowText("亮");
}
else
{
GetDlgItem(IDC_STATIC_FIFTH)->SetWindowText("");
}
}
void CDrinkSellMachineDlg::DisSellOverLights()
{
if (m_drinkMachine.m_bSellOverLight[0] == true)
{
GetDlgItem(IDC_STATIC_SIXTH)->SetWindowText("售完");
}
else
{
GetDlgItem(IDC_STATIC_SIXTH)->SetWindowText("");
}
if (m_drinkMachine.m_bSellOverLight[1] == true)
{
GetDlgItem(IDC_STATIC_SEVEVTH)->SetWindowText("售完");
}
else
{
GetDlgItem(IDC_STATIC_SEVEVTH)->SetWindowText("");
}
if (m_drinkMachine.m_bSellOverLight[2] == true)
{
GetDlgItem(IDC_STATIC_ENGHTH )->SetWindowText("售完");
}
else
{
GetDlgItem(IDC_STATIC_ENGHTH )->SetWindowText("");
}
if (m_drinkMachine.m_bSellOverLight[3] == true)
{
GetDlgItem(IDC_STATIC_NINTH)->SetWindowText("售完");
}
else
{
GetDlgItem(IDC_STATIC_NINTH)->SetWindowText("");
}
if (m_drinkMachine.m_bSellOverLight[4] == true)
{
GetDlgItem(IDC_STATIC_TENTH)->SetWindowText("售完");
}
else
{
GetDlgItem(IDC_STATIC_TENTH)->SetWindowText("");
}
}
void CDrinkSellMachineDlg::OnBtnFillDrink()
{
// TODO: Add your control notification handler code here
CFillDrink FillDlg(m_drinkMachine.m_drinkStorage);
if (FillDlg.DoModal() == IDOK)
{
m_drinkMachine.m_drinkStorage[0]->SetDrinkCount(FillDlg.m_numFirst);
m_drinkMachine.m_drinkStorage[1]->SetDrinkCount(FillDlg.m_numSecord);
m_drinkMachine.m_drinkStorage[2]->SetDrinkCount(FillDlg.m_numThird);
m_drinkMachine.m_drinkStorage[3]->SetDrinkCount(FillDlg.m_numFourth);
m_drinkMachine.m_drinkStorage[4]->SetDrinkCount(FillDlg.m_numFifth);
m_drinkMachine.m_drinkStorage[0]->SetDrinkPrice(FillDlg.m_priceFirst);
m_drinkMachine.m_drinkStorage[1]->SetDrinkPrice(FillDlg.m_priceSecord);
m_drinkMachine.m_drinkStorage[2]->SetDrinkPrice(FillDlg.m_priceThird);
m_drinkMachine.m_drinkStorage[3]->SetDrinkPrice(FillDlg.m_priceFourth);
m_drinkMachine.m_drinkStorage[4]->SetDrinkPrice(FillDlg.m_priceFifth);
m_drinkMachine.m_drinkStorage[0]->SetDrinkName(LPCSTR(FillDlg.m_nameFirst));
m_drinkMachine.m_drinkStorage[1]->SetDrinkName(LPCSTR(FillDlg.m_nameSecord));
m_drinkMachine.m_drinkStorage[2]->SetDrinkName(LPCSTR(FillDlg.m_nameThird));
m_drinkMachine.m_drinkStorage[3]->SetDrinkName(LPCSTR(FillDlg.m_nameFourth));
m_drinkMachine.m_drinkStorage[4]->SetDrinkName(LPCSTR(FillDlg.m_nameFifth));
//m_drinkMachine.SetSelectLights();
m_drinkMachine.SetSellOverLights();
DisSellOverLights();
DisplayDrinkName();
}
}
void CDrinkSellMachineDlg::DisplayDrinkName()
{
CString strTemp;
strTemp.Format("%0.2f",m_drinkMachine.m_drinkStorage[0]->GetDrinkPrice());
GetDlgItem(IDC_STATIC_PRICE_FIRST)->SetWindowText(m_drinkMachine.m_drinkStorage[0]->GetDrinkName().c_str() + strTemp);
strTemp.Format("%0.2f",m_drinkMachine.m_drinkStorage[1]->GetDrinkPrice());
GetDlgItem(IDC_STATIC_PRICE_SECORD)->SetWindowText(m_drinkMachine.m_drinkStorage[1]->GetDrinkName().c_str() + strTemp);
strTemp.Format("%0.2f",m_drinkMachine.m_drinkStorage[2]->GetDrinkPrice());
GetDlgItem(IDC_STATIC_PRICE_THIRD)->SetWindowText(m_drinkMachine.m_drinkStorage[2]->GetDrinkName().c_str() + strTemp);
strTemp.Format("%0.2f",m_drinkMachine.m_drinkStorage[3]->GetDrinkPrice());
GetDlgItem(IDC_STATIC_PRICE_FOURTH)->SetWindowText(m_drinkMachine.m_drinkStorage[3]->GetDrinkName().c_str() + strTemp);
strTemp.Format("%0.2f",m_drinkMachine.m_drinkStorage[4]->GetDrinkPrice());
GetDlgItem(IDC_STATIC_PRICE_FIFTH)->SetWindowText(m_drinkMachine.m_drinkStorage[4]->GetDrinkName().c_str() + strTemp);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -