CleardataDlg.cpp
上传用户:sztwq510
上传日期:2013-06-26
资源大小:4045k
文件大小:4k
源码类别:

酒店行业

开发平台:

Java

  1. // CleardataDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "MyPos.h"
  5. #include "CleardataDlg.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. // CCleardataDlg dialog
  13. extern CMyPosApp theApp;
  14. CCleardataDlg::CCleardataDlg(CWnd* pParent /*=NULL*/)
  15. : CDialog(CCleardataDlg::IDD, pParent)
  16. {
  17. //{{AFX_DATA_INIT(CCleardataDlg)
  18. // NOTE: the ClassWizard will add member initialization here
  19. //}}AFX_DATA_INIT
  20. }
  21. void CCleardataDlg::DoDataExchange(CDataExchange* pDX)
  22. {
  23. CDialog::DoDataExchange(pDX);
  24. //{{AFX_DATA_MAP(CCleardataDlg)
  25. DDX_Control(pDX, IDC_DATETIMEPICKER_TO, m_oDateto);
  26. DDX_Control(pDX, IDC_DATETIMEPICKER_FROM, m_oDatefrom);
  27. //}}AFX_DATA_MAP
  28. }
  29. BEGIN_MESSAGE_MAP(CCleardataDlg, CDialog)
  30. //{{AFX_MSG_MAP(CCleardataDlg)
  31. ON_BN_CLICKED(IDC_BUTTON_CLEAR, OnButtonClear)
  32. //}}AFX_MSG_MAP
  33. END_MESSAGE_MAP()
  34. /////////////////////////////////////////////////////////////////////////////
  35. // CCleardataDlg message handlers
  36. void CCleardataDlg::OnButtonClear() 
  37. {
  38. CString sfrom,sto,sdate1,sdate2,sbeginid,sendid,sql;
  39. _RecordsetPtr m_pRecordset;
  40. m_oDatefrom.GetWindowText(sfrom);
  41. sdate1=Dateformat(sfrom);
  42. sfrom.Format("%s 00:00:00",sdate1);
  43. m_oDateto.GetWindowText(sto);
  44. sdate2=Dateformat(sto);
  45. sto.Format("%s 00:00:00",sdate2);
  46. sql="Select ID from SALEBILL where ENDDATE>='"+sfrom+"' and ENDDATE<='"+sto+"' and STATUS='已结帐'";
  47. if(AfxMessageBox("确定清除数据吗?",MB_YESNO)==IDYES)
  48. {
  49. try
  50. m_pRecordset.CreateInstance("ADODB.Recordset");
  51. m_pRecordset->Open((_variant_t)sql,_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);
  52. if(!m_pRecordset->adoEOF)
  53. {
  54. m_pRecordset->MoveFirst();
  55. sbeginid=(LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("ID");
  56. m_pRecordset->MoveLast();
  57. sendid=(LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("ID");
  58. }
  59. }
  60. catch(_com_error e)///捕捉异常
  61. {
  62. CString temp;
  63. temp.Format("[清除数据]获得单据编号出错:%s",e.ErrorMessage());
  64. AfxMessageBox(temp);
  65. return;
  66. }
  67. sql="Delete * from SALEBILL where ENDDATE>='"+sfrom+"' and ENDDATE<='"+sto+"' and STATUS='已结帐'";
  68. try
  69. _variant_t RecordsAffected;
  70. theApp.m_pConnection->Execute((_bstr_t)sql,&RecordsAffected,adCmdText);
  71. }
  72. catch(_com_error e)///捕捉异常
  73. {
  74. CString temp;
  75. temp.Format("[清除数据]删除单据头:%s",e.ErrorMessage());
  76. AfxMessageBox(temp);
  77. return;
  78. }
  79. if(sbeginid=="" || sendid=="")
  80. return;
  81. sql="Delete * from SALEDETAIL where BILLID>='"+sbeginid+"' and BILLID<='"+sendid+"'";
  82. try
  83. _variant_t RecordsAffected;
  84. theApp.m_pConnection->Execute((_bstr_t)sql,&RecordsAffected,adCmdText);
  85. sql="Delete * from PAYDETAIL where BILLID>='"+sbeginid+"' and BILLID<='"+sendid+"'";
  86. theApp.m_pConnection->Execute((_bstr_t)sql,&RecordsAffected,adCmdText);
  87. }
  88. catch(_com_error e)///捕捉异常
  89. {
  90. CString temp;
  91. temp.Format("[清除数据]删除单据商品或付款明细出错:%s",e.ErrorMessage());
  92. AfxMessageBox(temp);
  93. return;
  94. }
  95. }
  96. }
  97. CString CCleardataDlg::Dateformat(CString sdate)
  98. {
  99. if(sdate.GetLength()==8)
  100. {
  101. sdate.Insert(7,'0');
  102. sdate.Insert(5,'0');
  103. }
  104. if(sdate.GetLength()==9)
  105. {
  106. if(sdate.GetAt(6)=='-')
  107. sdate.Insert(5,'0');
  108. else
  109. sdate.Insert(8,'0');
  110. }
  111. return sdate;
  112. }
  113. BOOL CCleardataDlg::OnInitDialog() 
  114. {
  115. CDialog::OnInitDialog();
  116. // TODO: Add extra initialization here
  117. return TRUE;  // return TRUE unless you set the focus to a control
  118.               // EXCEPTION: OCX Property Pages should return FALSE
  119. }