📄 lhj_cyglxtdlg.cpp
字号:
// Lhj_cyglxtDlg.cpp : implementation file
//
#include "stdafx.h"
#include "Lhj_cyglxt.h"
#include "Lhj_cyglxtDlg.h"
#include "DlgLogin.h"
#include "DlgPos.h"
#include "DlgUnpayedBill.h"
#include "Dlgcheckout.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
CDatabase m_db;//连接数据库
BOOL billisnew;//传递给 CDlgpos 的菜单号 是否为新单
CString GetBillId;//传递给 CDlgpos 的菜单号
CString TableNo;//传递给 CDlgpos 的桌号
CString cookfoodid[51];//作为 点菜 添加 删除 foodid 的中间容器 结帐或挂单时 一次性写入数据库
int tableuseinfor[61];
int nownumber;
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()
/////////////////////////////////////////////////////////////////////////////
// CLhj_cyglxtDlg dialog
CLhj_cyglxtDlg::CLhj_cyglxtDlg(CWnd* pParent /*=NULL*/)
: CDialog(CLhj_cyglxtDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CLhj_cyglxtDlg)
// 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 CLhj_cyglxtDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CLhj_cyglxtDlg)
DDX_Control(pDX, IDC_BUTTON1, m_button1);
DDX_Control(pDX, IDC_COMBO_billid, m_billlist);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CLhj_cyglxtDlg, CDialog)
//{{AFX_MSG_MAP(CLhj_cyglxtDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON_unpayedbill, OnBUTTONunpayedbill)
ON_BN_CLICKED(IDC_BUTTON_newbill, OnBUTTONnewbill)
ON_BN_CLICKED(IDC_BUTTON_getbill, OnBUTTONgetbill)
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
ON_BN_CLICKED(IDC_BUTTON4, OnButton4)
ON_BN_CLICKED(IDC_BUTTON5, OnButton5)
ON_BN_CLICKED(IDC_BUTTON6, OnButton6)
ON_BN_CLICKED(IDC_BUTTON7, OnButton7)
ON_BN_CLICKED(IDC_BUTTON8, OnButton8)
ON_BN_CLICKED(IDC_BUTTON9, OnButton9)
ON_BN_CLICKED(IDC_BUTTON10, OnButton10)
ON_BN_CLICKED(IDC_BUTTON11, OnButton11)
ON_BN_CLICKED(IDC_BUTTON12, OnButton12)
ON_BN_CLICKED(IDC_BUTTON14, OnButton14)
ON_BN_CLICKED(IDC_BUTTON15, OnButton15)
ON_BN_CLICKED(IDC_BUTTON16, OnButton16)
ON_BN_CLICKED(IDC_BUTTON17, OnButton17)
ON_BN_CLICKED(IDC_BUTTON18, OnButton18)
ON_BN_CLICKED(IDC_BUTTON19, OnButton19)
ON_BN_CLICKED(IDC_BUTTON20, OnButton20)
ON_BN_CLICKED(IDC_BUTTON21, OnButton21)
ON_BN_CLICKED(IDC_BUTTON22, OnButton22)
ON_BN_CLICKED(IDC_BUTTON23, OnButton23)
ON_BN_CLICKED(IDC_BUTTON24, OnButton24)
ON_BN_CLICKED(IDC_BUTTON25, OnButton25)
ON_BN_CLICKED(IDC_BUTTON26, OnButton26)
ON_BN_CLICKED(IDC_BUTTON27, OnButton27)
ON_BN_CLICKED(IDC_BUTTON28, OnButton28)
ON_BN_CLICKED(IDC_BUTTON29, OnButton29)
ON_BN_CLICKED(IDC_BUTTON30, OnButton30)
ON_BN_CLICKED(IDC_BUTTON31, OnButton31)
ON_BN_CLICKED(IDC_BUTTON32, OnButton32)
ON_BN_CLICKED(IDC_BUTTON33, OnButton33)
ON_BN_CLICKED(IDC_BUTTON34, OnButton34)
ON_BN_CLICKED(IDC_BUTTON35, OnButton35)
ON_BN_CLICKED(IDC_BUTTON36, OnButton36)
ON_BN_CLICKED(IDC_BUTTON37, OnButton37)
ON_BN_CLICKED(IDC_BUTTON38, OnButton38)
ON_BN_CLICKED(IDC_BUTTON39, OnButton39)
ON_BN_CLICKED(IDC_BUTTON40, OnButton40)
ON_BN_CLICKED(IDC_BUTTON41, OnButton41)
ON_BN_CLICKED(IDC_BUTTON42, OnButton42)
ON_BN_CLICKED(IDC_BUTTON43, OnButton43)
ON_BN_CLICKED(IDC_BUTTON44, OnButton44)
ON_BN_CLICKED(IDC_BUTTON45, OnButton45)
ON_BN_CLICKED(IDC_BUTTON46, OnButton46)
ON_BN_CLICKED(IDC_BUTTON47, OnButton47)
ON_BN_CLICKED(IDC_BUTTON48, OnButton48)
ON_BN_CLICKED(IDC_BUTTON49, OnButton49)
ON_BN_CLICKED(IDC_BUTTON50, OnButton50)
ON_BN_CLICKED(IDC_BUTTON51, OnButton51)
ON_BN_CLICKED(IDC_BUTTON52, OnButton52)
ON_BN_CLICKED(IDC_BUTTON53, OnButton53)
ON_BN_CLICKED(IDC_BUTTON54, OnButton54)
ON_BN_CLICKED(IDC_BUTTON55, OnButton55)
ON_BN_CLICKED(IDC_BUTTON56, OnButton56)
ON_BN_CLICKED(IDC_BUTTON57, OnButton57)
ON_BN_CLICKED(IDC_BUTTON58, OnButton58)
ON_BN_CLICKED(IDC_BUTTON59, OnButton59)
ON_BN_CLICKED(IDC_BUTTON60, OnButton60)
ON_BN_CLICKED(IDC_BUTTON13, OnButton13)
ON_WM_DESTROY()
ON_WM_CTLCOLOR()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CLhj_cyglxtDlg message handlers
BOOL CLhj_cyglxtDlg::OnInitDialog()
{
CDialog::OnInitDialog();
CDlgLogin dlglogin;//先调出登录对话框
if (dlglogin.DoModal()!=IDOK)
{
exit(1);
}
m_brush.CreateSolidBrush(RGB(0,0,255)); //初始化为蓝色
//显示 桌子 使用情况 "开单" 或 "结帐"
inittablestate();
initcombox();
// 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
return TRUE; // return TRUE unless you set the focus to a control
}
void CLhj_cyglxtDlg::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 CLhj_cyglxtDlg::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 CLhj_cyglxtDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CLhj_cyglxtDlg::OnOK()
{
// TODO: Add extra validation here
CDialog::OnOK();
}
void CLhj_cyglxtDlg::OnBUTTONunpayedbill()
{
// TODO: Add your control notification handler code here
CDlgUnpayedBill unpayedbill;
unpayedbill.DoModal();
}
void CLhj_cyglxtDlg::OnBUTTONnewbill()
{
// TODO: Add your control notification handler code here
billisnew=TRUE;
TableNo="null";
CDlgPos pos;
pos.DoModal();
//返回后更新combox
initcombox();
inittablestate();
UpdateData(FALSE);
}
void CLhj_cyglxtDlg::OnBUTTONgetbill()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
//判断 账单的合法性
CString checkbillid,sql;CRecordset rs(&m_db);
m_billlist.GetWindowText(checkbillid);
int get_bill_id=atoi(checkbillid);
sql.Format("select bill_id from bill where bill_id=%d",get_bill_id);
rs.Open(CRecordset::dynaset, sql);
if(rs.IsEOF())
{
rs.Close();
AfxMessageBox("您输入的账单号不存在");
return;
}
rs.Close();
billisnew=FALSE;
m_billlist.GetWindowText(GetBillId);
CString notpay="未付";
get_bill_id=atoi(GetBillId);//得到的账单号
sql.Format("select bill_id from bill where bill_id=%d and pay_state='%s'",get_bill_id,notpay);
rs.Open(CRecordset::dynaset, sql);
if(rs.IsEOF())
{ //得到的账单号为已付的 去另外一个对话框显示更详细信息
rs.Close();//注意及时关闭 不然下次rs打不开了
CDlgcheckout checkDlg;
checkDlg.DoModal();
}
else
{//得到的账单号为未付的 显示已有信息
rs.Close();
CDlgPos pos;
pos.DoModal();
}
//返回后更新combox table
initcombox();
inittablestate();
UpdateData(FALSE);
}
//有了这个 就不能用 ESC 了
//DEL BOOL CLhj_cyglxtDlg::PreTranslateMessage(MSG *pMsg)
//DEL {
//DEL
//DEL
//DEL if(pMsg->message==WM_KEYDOWN)
//DEL {
//DEL switch(pMsg->wParam)
//DEL {
//DEL case VK_F1:
//DEL OnBUTTONnewbill();
//DEL break;
//DEL case VK_F2:
//DEL OnBUTTONgetbill();
//DEL break;
//DEL case VK_F3:
//DEL OnBUTTONunpayedbill();
//DEL break;
//DEL }
//DEL
//DEL }
//DEL return CDialog::PreTranslateMessage(pMsg);
//DEL
//DEL }
void CLhj_cyglxtDlg::initcombox()
{
TRY
{ m_billlist.ResetContent();
CRecordset rs(&m_db);
CString sql="select bill_id from bill group by bill_id ";
rs.Open(CRecordset::dynaset, sql);
CString bill_id;long billid;
while (!rs.IsEOF())
{
CDBVariant var;
rs.GetFieldValue((short)0, var, SQL_C_SLONG);
if (var.m_dwType != DBVT_NULL)
billid= var.m_lVal;
var.Clear();
bill_id.Format("%d",billid);
m_billlist.AddString(bill_id);
rs.MoveNext();
}
m_billlist.SetWindowText(bill_id);
rs.Close();
}
CATCH(CDBException,ex)
{
AfxMessageBox ("db open failed!");
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
billisnew=FALSE;
UpdateData(FALSE);
}
void CLhj_cyglxtDlg::inittablestate()
{
//显示 桌子 使用情况 "开单" 或 "结帐"
TRY{
UpdateData(TRUE);
int table_no;int i=0;
/*
IDC_STATIC_1 1081
IDC_BUTTON1 1082 桌号1
IDC_STATIC_2 1083
IDC_BUTTON2 1084 桌号2
IDC_STATIC_3 1085
IDC_BUTTON3 1086
*/
//初始
for(table_no=1;table_no<=60;table_no++)
{
SetDlgItemText(1080+table_no*2,"开单");
SetDlgItemText(1079+table_no*2,"空闲");
}
CRecordset rs(&m_db);
CString sql,s;
//CDC *pDC=GetDC();
sql.Format("select table_no,bill_id from bill where pay_state='未付'");
rs.Open(CRecordset::dynaset, sql);nownumber=1;
while (!rs.IsEOF())
{
CDBVariant var;
rs.GetFieldValue((short)0, var, SQL_C_SLONG);
if (var.m_dwType != DBVT_NULL)
table_no= var.m_lVal;
//pDC->SetTextColor(RGB(255,0,0));
//pDC->SetBkMode(TRANSPARENT);
//最好设置颜色
SetDlgItemText(1080+table_no*2,"结帐");
SetDlgItemText(1079+table_no*2,"就餐中");
tableuseinfor[nownumber]=table_no;//记录桌号 供画颜色时用
var.Clear();
nownumber++;
rs.MoveNext();
}
rs.Close();
UpdateData(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
}
void CLhj_cyglxtDlg::OnButton1()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
CString state;
GetDlgItemText(IDC_BUTTON1,state);
if (state=="开单")
{
TableNo="1";
billisnew=TRUE;
CDlgPos pos;
pos.DoModal();
inittablestate();
initcombox();
}
else
{
if (state=="结帐")
{
ToPayDialog(1);
}
}
}
void CLhj_cyglxtDlg::ToPayDialog(int tablenumber)
{
TRY{
CRecordset rs(&m_db);
CString sql,s; int ibillid;
sql.Format("select bill_id from bill where pay_state='未付' and table_no=%d",tablenumber);
rs.Open(CRecordset::dynaset, sql);
if(!rs.IsEOF())
{
CDBVariant var;
rs.GetFieldValue((short)0, var, SQL_C_SLONG);
if (var.m_dwType != DBVT_NULL)
ibillid= var.m_lVal;
GetBillId.Format("%d",ibillid);
var.Clear();
//结帐
CDlgcheckout checkoutDlg;
checkoutDlg.DoModal();
}
rs.Close();
inittablestate();//不用 SetDlgItemText(.....); 有可能未结帐
UpdateData(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
}
void CLhj_cyglxtDlg::OnButton2()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
CString state;
GetDlgItemText(IDC_BUTTON2,state);
if (state=="开单")
{
TableNo="2";
billisnew=TRUE;
CDlgPos pos;
pos.DoModal();
//更新
initcombox();
inittablestate();
}
else
{
if (state=="结帐")
{
ToPayDialog(2);
}
}
}
void CLhj_cyglxtDlg::OnButton3()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
CString state;
GetDlgItemText(IDC_BUTTON3,state);
if (state=="开单")
{
TableNo="3";
billisnew=TRUE;
CDlgPos pos;
pos.DoModal();
//更新
inittablestate();
initcombox();
}
else
{
if (state=="结帐")
{
ToPayDialog(3);
}
}
}
void CLhj_cyglxtDlg::OnButton4()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
CString state;
GetDlgItemText(IDC_BUTTON4,state);
if (state=="开单")
{
TableNo="4";
billisnew=TRUE;
CDlgPos pos;
pos.DoModal();//更新
inittablestate();
initcombox();
}
else
{
if (state=="结帐")
{
ToPayDialog(4);
}
}
}
void CLhj_cyglxtDlg::OnButton5()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
CString state;
GetDlgItemText(IDC_BUTTON5,state);
if (state=="开单")
{
TableNo="5";
billisnew=TRUE;
CDlgPos pos;
pos.DoModal();
//更新
inittablestate();
initcombox();
}
else
{
if (state=="结帐")
{
ToPayDialog(5);
}
}
}
void CLhj_cyglxtDlg::OnButton6()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
CString state;
GetDlgItemText(IDC_BUTTON6,state);
if (state=="开单")
{
TableNo="6";
billisnew=TRUE;
CDlgPos pos;
pos.DoModal();
//更新
inittablestate();
initcombox();
}
else
{
if (state=="结帐")
{
ToPayDialog(6);
}
}
}
void CLhj_cyglxtDlg::OnButton7()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
CString state;
GetDlgItemText(IDC_BUTTON7,state);
if (state=="开单")
{
TableNo="7";
billisnew=TRUE;
CDlgPos pos;
pos.DoModal();
//更新
inittablestate();
initcombox();
}
else
{
if (state=="结帐")
{
ToPayDialog(7);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -