OrderCourse.cpp
上传用户:hnzycx
上传日期:2022-08-09
资源大小:12567k
文件大小:5k
开发平台:

Visual C++

  1. // OrderCourse.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "MobileClient.h"
  5. #include "OrderCourse.h"
  6. #include "DataParsing.h"
  7. // COrderCourse dialog
  8. IMPLEMENT_DYNAMIC(COrderCourse, CDialog)
  9. COrderCourse::COrderCourse(CWnd* pParent /*=NULL*/)
  10. : CDialog(COrderCourse::IDD, pParent)
  11. {
  12. CMobileClientApp* App=(CMobileClientApp*)AfxGetApp();
  13. App->m_tcp.OnRead = OnReadOrderCourse;
  14. }
  15. COrderCourse::~COrderCourse()
  16. {
  17. }
  18. void COrderCourse::DoDataExchange(CDataExchange* pDX)
  19. {
  20. CDialog::DoDataExchange(pDX);
  21. DDX_Control(pDX, IDC_LIST1, m_MenuList);
  22. DDX_Control(pDX, IDC_LIST2, m_OrderList);
  23. DDX_Control(pDX, IDC_COMBO1, m_combobox);
  24. DDX_Control(pDX, IDC_EDIT1, m_recv);
  25. }
  26. BEGIN_MESSAGE_MAP(COrderCourse, CDialog)
  27. ON_BN_CLICKED(IDC_BUTTON1, &COrderCourse::OnBnClickedAdd)
  28. ON_BN_CLICKED(IDDelete, &COrderCourse::OnBnClickedDelete)
  29. ON_BN_CLICKED(IDC_submit, &COrderCourse::OnBnClickedSubmit)
  30. ON_BN_CLICKED(IDC_CANCEL, &COrderCourse::OnBnClickedCancel)
  31. END_MESSAGE_MAP()
  32. //回调函数
  33. void CALLBACK COrderCourse::OnReadOrderCourse(CWnd* pWnd,const char *buf,int len)
  34. {
  35. CString strRecv(buf);
  36.     CMobileClientApp* App = (CMobileClientApp*)AfxGetApp();
  37. App->context = strRecv;
  38. }
  39. BOOL COrderCourse::OnInitDialog()
  40. {
  41. CDialog::OnInitDialog();
  42. CMobileClientApp* App=(CMobileClientApp*)AfxGetApp();
  43. //设置桌号
  44. m_combobox.AddString(_T("1"));
  45. m_combobox.AddString(_T("2"));
  46. m_combobox.AddString(_T("3"));
  47. m_combobox.AddString(_T("4"));
  48. m_combobox.AddString(_T("5"));
  49. m_combobox.AddString(_T("6"));
  50. m_combobox.AddString(_T("包厢1"));
  51. m_combobox.AddString(_T("包厢2"));
  52. m_combobox.AddString(_T("包厢3"));
  53. m_combobox.AddString(_T("包厢4"));
  54. m_MenuList.SetExtendedStyle(LVS_EX_FULLROWSELECT);
  55. m_MenuList.InsertColumn(0,_T("菜名"),LVCFMT_LEFT,120,-1);
  56. m_MenuList.InsertColumn(1,_T("价格"),LVCFMT_LEFT,100,-1);
  57. CStringList returnValue;
  58. CDataParsing *dp = new CDataParsing(App->context);
  59. dp->ProcessDataForDB(returnValue); 
  60. POSITION pos = returnValue.GetHeadPosition();
  61. Sleep(3000);
  62. CString tail;
  63. tail = returnValue.GetTail();
  64. //如果得到"END"结尾,解析,接收菜单
  65. if(tail==_T("END"))
  66. {
  67. int k = returnValue.GetCount();
  68. k = (k-2)/2;
  69. int i = 0;
  70. CString arg1;
  71. CString arg2;
  72. arg1 = returnValue.GetNext(pos);
  73. while(k)
  74. {
  75. arg1 = returnValue.GetNext(pos);
  76.         arg2 = returnValue.GetNext(pos);
  77. m_MenuList.InsertItem(i,arg1);
  78. m_MenuList.SetItemText(i,1,arg2);
  79. k--;
  80. i++;
  81. }
  82. }
  83. m_OrderList.SetExtendedStyle(LVS_EX_FULLROWSELECT);
  84. m_OrderList.InsertColumn(0,_T("已选菜"),LVCFMT_LEFT,120,-1);
  85. m_OrderList.InsertColumn(1,_T("价格"),LVCFMT_LEFT,100,-1);
  86. return TRUE;
  87. }
  88. //添加餐单
  89. void COrderCourse::OnBnClickedAdd()
  90. {
  91. int nItem = -1;
  92. nItem = m_MenuList.GetNextItem(nItem, LVNI_SELECTED);  
  93. if(nItem == -1) return;
  94. CString selectDish;
  95. CString selectPrice;
  96. selectDish = m_MenuList.GetItemText(nItem,0);
  97. selectPrice = m_MenuList.GetItemText(nItem,1);
  98. m_OrderList.InsertItem(0,selectDish);
  99. m_OrderList.SetItemText(0,1,selectPrice);
  100. }
  101. //删除餐单中的菜品
  102. void COrderCourse::OnBnClickedDelete()
  103. {
  104. int nItem = -1;
  105. nItem = m_OrderList.GetNextItem(nItem, LVNI_SELECTED);  
  106. if(nItem == -1) return;
  107. m_OrderList.DeleteItem(nItem);
  108. }
  109. //提交餐单
  110. void COrderCourse::OnBnClickedSubmit()
  111. {
  112. CMobileClientApp* App=(CMobileClientApp*)AfxGetApp();
  113. int nItem = m_OrderList.GetItemCount();
  114. CTime tRecordTime = CTime::GetCurrentTime();
  115. CString strRecordTime = tRecordTime.Format(_T("%Y年%m月%d日%H:%M:%S"));
  116. CString sendOrderList;
  117. CString table;
  118. m_combobox.GetWindowTextW(table);
  119. sendOrderList = _T("M@")+table+_T("@")+strRecordTime+_T("@")+App->sername+_T("@");
  120. int i = 0;
  121. while(i < nItem-1 )
  122. {
  123. CString sendDish;
  124. sendDish = m_OrderList.GetItemText(i,0);
  125. CString sendPrice;
  126. sendPrice = m_OrderList.GetItemText(i,1);
  127. sendOrderList += sendDish +_T("$")+sendPrice +_T("*");
  128. i++;
  129. }
  130. sendOrderList += m_OrderList.GetItemText(nItem-1,0)+_T("$")+m_OrderList.GetItemText(nItem-1,1)+_T("@END");
  131. char * sendBuf;
  132. int sendLen = 0;
  133. sendLen = sendOrderList.GetLength();
  134. sendBuf = new char[sendLen*2];
  135. WideCharToMultiByte(CP_OEMCP,NULL,sendOrderList,-1,sendBuf,sendLen*2,NULL,FALSE);
  136. //若未选择桌号,提示重新选择
  137. while(table == _T(""))
  138. {
  139. AfxMessageBox(_T("请选择桌号"));
  140. return;
  141. }
  142. if (!App->m_tcp.SendData(sendBuf,sendLen*2))
  143. {
  144. AfxMessageBox(_T("发送餐单失败"));
  145. }
  146. delete []sendBuf;
  147. sendBuf = NULL;
  148. //返回是否发送餐单成功
  149. Sleep(3000);
  150. if (App->context == "M@1@END")
  151. m_recv.SetWindowTextW(_T("成功"));
  152. if (App->context == "M@0@END")
  153. m_recv.SetWindowTextW(_T("超时"));
  154. }
  155. //返回主界面
  156. void COrderCourse::OnBnClickedCancel()
  157. {
  158. OnCancel();