?? statdlg.cpp
字號:
// StatDlg.cpp : implementation file
//
#include "stdafx.h"
#include "MyPos.h"
#include "StatDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CStatDlg dialog
extern CMyPosApp theApp;
CStatDlg::CStatDlg(CWnd* pParent /*=NULL*/)
: CDialog(CStatDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CStatDlg)
//}}AFX_DATA_INIT
}
void CStatDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CStatDlg)
DDX_Control(pDX, IDC_DATETIMEPICKER_SD, m_oSdate);
DDX_Control(pDX, IDC_DATETIMEPICKER_OD, m_oOdate);
DDX_Control(pDX, IDC_RADIO_WEEK, m_oWeek);
DDX_Control(pDX, IDC_EDIT_LISTTITLE, m_oListtitle);
DDX_Control(pDX, IDC_LIST_REPORT, m_oListreport);
DDX_Control(pDX, IDC_EDIT_ST, m_oSt);
DDX_Control(pDX, IDC_EDIT_OT, m_oOt);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CStatDlg, CDialog)
//{{AFX_MSG_MAP(CStatDlg)
ON_BN_CLICKED(IDC_BUTTON_STAT, OnButtonStat)
ON_BN_CLICKED(IDC_BUTTON_PRINTREPORT, OnButtonPrintreport)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CStatDlg message handlers
BOOL CStatDlg::OnInitDialog()
{
CDialog::OnInitDialog();
m_oWeek.SetCheck(1);
m_oSt.SetWindowText("00:00:00");
m_oOt.SetWindowText("23:59:59");
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CStatDlg::OnButtonStat()
{
int n;
CString sql,sfloor,scompany,ssdate,sodate,sstime,sotime;
CString sbegin,send,stotal;
_RecordsetPtr m_pRecordset;
int nselect=GetCheckedRadioButton(IDC_RADIO_SINGLE,IDC_RADIO_WEEK);
switch(nselect)//Get if it is discount.
{
case IDC_RADIO_WEEK:
n=0;
m_oListtitle.SetWindowText(" ** 銷售匯總報表 **");
break;
case IDC_RADIO_SINGLE:
n=1;
m_oListtitle.SetWindowText(" ** 單品報表 **");
break;
default:
break;
}
int ncount=m_oListreport.GetCount()-1;
for(int i=ncount;i>=0;i--)//Clear report listbox.
m_oListreport.DeleteString(i);
sql="Select * from COMPANY";
try
{
m_pRecordset.CreateInstance("ADODB.Recordset");
m_pRecordset->Open((_variant_t)sql,_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);
if(!m_pRecordset->adoEOF)
{
sfloor=(LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("FLOORNUMBER");
scompany=(LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("COMPANYNAME");
}
m_pRecordset->Close();
}
catch(_com_error e)///捕捉異常
{
CString sdate;
sdate.Format("讀取樓層號出錯:%s",e.ErrorMessage());
AfxMessageBox(sdate);
}
m_oListreport.AddString(" ");
int ns=32-scompany.GetLength()-sfloor.GetLength();
CString space=" ";
for(int j=0;j<ns-1;j++)
space=space+" ";
m_oListreport.AddString(scompany+space+"樓層號 "+sfloor);
m_oListreport.AddString("---------------------------------------");
m_oSdate.GetWindowText(ssdate);
ssdate=Dateformat(ssdate);
m_oSt.GetWindowText(sstime);
sbegin=ssdate+" "+sstime;
m_oListreport.AddString("開始時間: "+sbegin);
m_oOdate.GetWindowText(sodate);
sodate=Dateformat(sodate);
m_oOt.GetWindowText(sotime);
send=sodate+" "+sotime;
m_oListreport.AddString("結束時間: "+send);
m_oListreport.AddString("---------------------------------------");
sql="where ENDDATE>='"+sbegin+"' and ENDDATE<='"+send+"' and STATUS='已結帳'";
if(n==0)
SumBillTotal(sql);
if(n==1)
{
m_oListreport.AddString("商品名稱 數量");
SumSingleItem(sql);
}
}
CString CStatDlg::Dateformat(CString sdate)
{
if(sdate.GetLength()==8)
{
sdate.Insert(7,'0');
sdate.Insert(5,'0');
}
if(sdate.GetLength()==9)
{
if(sdate.GetAt(6)=='-')
sdate.Insert(5,'0');
else
sdate.Insert(8,'0');
}
return sdate;
}
void CStatDlg::SumBillTotal(CString scondition)
{
float fsum,fttl;
long lcount,lpersonqa,lbillqa;
CString sql,ssum,scount,spersonqa,sbillqa;
_RecordsetPtr m_pRecordset; //Must define it in function!!!!
CString space,space1;
int i,n;
//count bills quantity.
sql="Select COUNT(*) as XXX from SALEBILL "+scondition+"";
try
{
m_pRecordset.CreateInstance("ADODB.Recordset");
m_pRecordset->Open((_variant_t)sql,_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);
lcount=(long)m_pRecordset->GetCollect("XXX");
m_pRecordset->Close();
}
catch(_com_error e)///捕捉異常
{
CString stemp;
stemp.Format("[報表]讀取記錄數出錯:%s",e.ErrorMessage());
AfxMessageBox(stemp);
}
if(lcount==0)
{
m_oListreport.AddString("人民幣: 0.00");
return;
}
//Calculate sum acttotal , people's quantity and bill's quantity.
sql="Select SUM(ACTTOTAL) as AAA,SUM(PEOPLES) as BBB,COUNT(*) as CCC from SALEBILL "+scondition+"";
try
{
m_pRecordset.CreateInstance("ADODB.Recordset");
m_pRecordset->Open((_variant_t)sql,_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);
if(!m_pRecordset->adoEOF)
{
fsum =m_pRecordset->GetCollect("AAA");
fttl=fsum;
lpersonqa=m_pRecordset->GetCollect("BBB");
lbillqa=m_pRecordset->GetCollect("CCC");
}
ssum.Format("%.2f",fsum);
spersonqa.Format("%d",lpersonqa);
sbillqa.Format("%d",lbillqa);
n=31-ssum.GetLength();
space=" ";
for(i=0;i<n-1;i++)
space=space+" ";
m_oListreport.AddString("人民幣:"+space+ssum);
m_pRecordset->Close();
}
catch(_com_error e)///捕捉異常
{
CString stemp;
stemp.Format("[報表]計算單據金額出錯:%s",e.ErrorMessage());
AfxMessageBox(stemp);
}
//Sum hang bills total.
_variant_t vtemp;
sql="Select SUM(TOTAL) as XXX from SALEBILL "+scondition+"";
sql.Replace("已結帳","掛帳");
sql.Replace("ENDDATE","BEGINDATE");
try
{
m_pRecordset.CreateInstance("ADODB.Recordset");
m_pRecordset->Open((_variant_t)sql,_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);
vtemp=m_pRecordset->GetCollect("XXX");
fsum=vtemp.dblVal;
if(fsum>0)
{
fttl=fttl+fsum;
ssum.Format("%.2f",fsum);
}
else
ssum="0.00";
n=33-ssum.GetLength();
space=" ";
for(i=0;i<n-1;i++)
space=space+" ";
m_oListreport.AddString("掛帳:"+space+ssum);
m_pRecordset->Close();
}
catch(_com_error e)///捕捉異常
{
CString stemp;
stemp.Format("[報表]計算單據掛帳金額出錯:%s",e.ErrorMessage());
AfxMessageBox(stemp);
}
//Sum RF bills total.
sql="Select SUM(TOTAL) as XXX from SALEBILL "+scondition+" and PAYMODE=88";
// sql="Select SUM(TOTAL) as XXX from (Select * from SALEBILL "+scondition+") where PAYMODE=88";
try
{
m_pRecordset.CreateInstance("ADODB.Recordset");
m_pRecordset->Open((_variant_t)sql,_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);
vtemp=m_pRecordset->GetCollect("XXX");
fsum=vtemp.dblVal;
if(fsum>0)
{
fttl=fttl+fsum;
ssum.Format("%.2f",fsum);
}
else
ssum="0.00";
n=35-ssum.GetLength();
space=" ";
for(i=0;i<n-1;i++)
space=space+" ";
m_oListreport.AddString("RF:"+space+ssum);
m_oListreport.AddString(" ----------------");
CString sttl;
sttl.Format("%.2f",fttl);
n=38-sttl.GetLength();
space=" ";
for(i=0;i<n-1;i++)
space=space+" ";
m_oListreport.AddString(space+sttl);
m_oListreport.AddString(" ");
m_oListreport.AddString("類別 匯總 折扣");
m_pRecordset->Close();
}
catch(_com_error e)///捕捉異常
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -