OrderCourse.cpp
上传用户:hnzycx
上传日期:2022-08-09
资源大小:12567k
文件大小:5k
- // OrderCourse.cpp : implementation file
- //
- #include "stdafx.h"
- #include "MobileClient.h"
- #include "OrderCourse.h"
- #include "DataParsing.h"
- // COrderCourse dialog
- IMPLEMENT_DYNAMIC(COrderCourse, CDialog)
- COrderCourse::COrderCourse(CWnd* pParent /*=NULL*/)
- : CDialog(COrderCourse::IDD, pParent)
- {
- CMobileClientApp* App=(CMobileClientApp*)AfxGetApp();
- App->m_tcp.OnRead = OnReadOrderCourse;
- }
- COrderCourse::~COrderCourse()
- {
- }
- void COrderCourse::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- DDX_Control(pDX, IDC_LIST1, m_MenuList);
- DDX_Control(pDX, IDC_LIST2, m_OrderList);
- DDX_Control(pDX, IDC_COMBO1, m_combobox);
- DDX_Control(pDX, IDC_EDIT1, m_recv);
- }
- BEGIN_MESSAGE_MAP(COrderCourse, CDialog)
-
- ON_BN_CLICKED(IDC_BUTTON1, &COrderCourse::OnBnClickedAdd)
- ON_BN_CLICKED(IDDelete, &COrderCourse::OnBnClickedDelete)
- ON_BN_CLICKED(IDC_submit, &COrderCourse::OnBnClickedSubmit)
- ON_BN_CLICKED(IDC_CANCEL, &COrderCourse::OnBnClickedCancel)
- END_MESSAGE_MAP()
- //回调函数
- void CALLBACK COrderCourse::OnReadOrderCourse(CWnd* pWnd,const char *buf,int len)
- {
-
-
- CString strRecv(buf);
- CMobileClientApp* App = (CMobileClientApp*)AfxGetApp();
- App->context = strRecv;
-
-
- }
- BOOL COrderCourse::OnInitDialog()
- {
- CDialog::OnInitDialog();
- CMobileClientApp* App=(CMobileClientApp*)AfxGetApp();
- //设置桌号
- m_combobox.AddString(_T("1"));
- m_combobox.AddString(_T("2"));
- m_combobox.AddString(_T("3"));
- m_combobox.AddString(_T("4"));
- m_combobox.AddString(_T("5"));
- m_combobox.AddString(_T("6"));
- m_combobox.AddString(_T("包厢1"));
- m_combobox.AddString(_T("包厢2"));
- m_combobox.AddString(_T("包厢3"));
- m_combobox.AddString(_T("包厢4"));
-
- m_MenuList.SetExtendedStyle(LVS_EX_FULLROWSELECT);
- m_MenuList.InsertColumn(0,_T("菜名"),LVCFMT_LEFT,120,-1);
- m_MenuList.InsertColumn(1,_T("价格"),LVCFMT_LEFT,100,-1);
- CStringList returnValue;
- CDataParsing *dp = new CDataParsing(App->context);
- dp->ProcessDataForDB(returnValue);
- POSITION pos = returnValue.GetHeadPosition();
- Sleep(3000);
- CString tail;
- tail = returnValue.GetTail();
- //如果得到"END"结尾,解析,接收菜单
- if(tail==_T("END"))
- {
- int k = returnValue.GetCount();
- k = (k-2)/2;
-
- int i = 0;
- CString arg1;
- CString arg2;
- arg1 = returnValue.GetNext(pos);
- while(k)
- {
-
- arg1 = returnValue.GetNext(pos);
- arg2 = returnValue.GetNext(pos);
- m_MenuList.InsertItem(i,arg1);
- m_MenuList.SetItemText(i,1,arg2);
- k--;
- i++;
- }
- }
- m_OrderList.SetExtendedStyle(LVS_EX_FULLROWSELECT);
- m_OrderList.InsertColumn(0,_T("已选菜"),LVCFMT_LEFT,120,-1);
- m_OrderList.InsertColumn(1,_T("价格"),LVCFMT_LEFT,100,-1);
- return TRUE;
- }
- //添加餐单
- void COrderCourse::OnBnClickedAdd()
- {
- int nItem = -1;
- nItem = m_MenuList.GetNextItem(nItem, LVNI_SELECTED);
- if(nItem == -1) return;
- CString selectDish;
- CString selectPrice;
- selectDish = m_MenuList.GetItemText(nItem,0);
- selectPrice = m_MenuList.GetItemText(nItem,1);
- m_OrderList.InsertItem(0,selectDish);
- m_OrderList.SetItemText(0,1,selectPrice);
-
- }
- //删除餐单中的菜品
- void COrderCourse::OnBnClickedDelete()
- {
- int nItem = -1;
- nItem = m_OrderList.GetNextItem(nItem, LVNI_SELECTED);
- if(nItem == -1) return;
- m_OrderList.DeleteItem(nItem);
- }
- //提交餐单
- void COrderCourse::OnBnClickedSubmit()
- {
- CMobileClientApp* App=(CMobileClientApp*)AfxGetApp();
- int nItem = m_OrderList.GetItemCount();
- CTime tRecordTime = CTime::GetCurrentTime();
- CString strRecordTime = tRecordTime.Format(_T("%Y年%m月%d日%H:%M:%S"));
- CString sendOrderList;
- CString table;
- m_combobox.GetWindowTextW(table);
- sendOrderList = _T("M@")+table+_T("@")+strRecordTime+_T("@")+App->sername+_T("@");
- int i = 0;
- while(i < nItem-1 )
- {
- CString sendDish;
- sendDish = m_OrderList.GetItemText(i,0);
- CString sendPrice;
- sendPrice = m_OrderList.GetItemText(i,1);
- sendOrderList += sendDish +_T("$")+sendPrice +_T("*");
- i++;
- }
- sendOrderList += m_OrderList.GetItemText(nItem-1,0)+_T("$")+m_OrderList.GetItemText(nItem-1,1)+_T("@END");
- char * sendBuf;
- int sendLen = 0;
- sendLen = sendOrderList.GetLength();
- sendBuf = new char[sendLen*2];
- WideCharToMultiByte(CP_OEMCP,NULL,sendOrderList,-1,sendBuf,sendLen*2,NULL,FALSE);
- //若未选择桌号,提示重新选择
- while(table == _T(""))
- {
- AfxMessageBox(_T("请选择桌号"));
- return;
-
- }
- if (!App->m_tcp.SendData(sendBuf,sendLen*2))
- {
- AfxMessageBox(_T("发送餐单失败"));
- }
- delete []sendBuf;
- sendBuf = NULL;
-
- //返回是否发送餐单成功
- Sleep(3000);
- if (App->context == "M@1@END")
- m_recv.SetWindowTextW(_T("成功"));
- if (App->context == "M@0@END")
- m_recv.SetWindowTextW(_T("超时"));
- }
- //返回主界面
- void COrderCourse::OnBnClickedCancel()
- {
- OnCancel();
- }