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

Visual C++

  1. // Special.cpp : implementation file
  2. #include "stdafx.h"
  3. #include "MobileClient.h"
  4. #include "Special.h"
  5. #include "DataParsing.h"
  6. // CSpecial dialog
  7. IMPLEMENT_DYNAMIC(CSpecial, CDialog)
  8. //CSpecial构造
  9. CSpecial::CSpecial(CWnd* pParent /*=NULL*/)
  10. : CDialog(CSpecial::IDD, pParent)
  11. {
  12. CMobileClientApp* App=(CMobileClientApp*)AfxGetApp();
  13. App->m_tcp.OnRead = OnReadSpecial;
  14. }
  15. //CSpecial析构
  16. CSpecial::~CSpecial()
  17. {
  18. }
  19. void CSpecial::DoDataExchange(CDataExchange* pDX)
  20. {
  21. CDialog::DoDataExchange(pDX);
  22. DDX_Control(pDX, IDC_LIST1, m_SpecialList);
  23. }
  24. BEGIN_MESSAGE_MAP(CSpecial, CDialog)
  25. ON_BN_CLICKED(IDC_BUTTON1, &CSpecial::OnBnClickedButton1)
  26. END_MESSAGE_MAP()
  27. // CSpecial message handlers
  28. //回调函数
  29. void CALLBACK CSpecial::OnReadSpecial(CWnd* pWnd,const char *buf,int len)
  30. {
  31. CString strRecv(buf);
  32.     CMobileClientApp* App=(CMobileClientApp*)AfxGetApp();
  33. App->context = strRecv;
  34. }
  35. BOOL CSpecial::OnInitDialog()
  36. {
  37. CDialog::OnInitDialog();
  38. CMobileClientApp* App=(CMobileClientApp*)AfxGetApp();
  39. m_SpecialList.SetExtendedStyle(LVS_EX_FULLROWSELECT);
  40. m_SpecialList.InsertColumn(0,_T("特价菜名"),LVCFMT_LEFT,120,-1);
  41. m_SpecialList.InsertColumn(1,_T("价格"),LVCFMT_LEFT,100,-1);
  42. CStringList returnValue;
  43. CDataParsing *dp=new CDataParsing(App->context);
  44. dp->ProcessDataForDB(returnValue); 
  45. POSITION pos=returnValue.GetHeadPosition();
  46. Sleep(3000);
  47. CString tail;
  48. tail=returnValue.GetTail();
  49. //解析,输出优惠/特价菜信息
  50. if(tail==_T("END"))
  51. {
  52. int k = returnValue.GetCount();
  53. k = (k-2)/2;
  54. int i = 0;
  55. CString arg1;
  56. CString arg2;
  57. arg1 = returnValue.GetNext(pos);
  58. while(k)
  59. {
  60. arg1 = returnValue.GetNext(pos);
  61.         arg2 = returnValue.GetNext(pos);
  62. m_SpecialList.InsertItem(i,arg1);
  63. m_SpecialList.SetItemText(i,1,arg2);
  64. k--;
  65. i++;
  66. }
  67. }
  68. return TRUE;
  69. }
  70. //返回主界面
  71. void CSpecial::OnBnClickedButton1()
  72. {
  73. OnCancel();
  74. }