📄 comparesaletotal.cpp
字号:
// CompareSaleTotal.cpp : implementation file
//
#include "stdafx.h"
#include "ClientRelationship.h"
#include "CompareSaleTotal.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CCompareSaleTotal dialog
CCompareSaleTotal::CCompareSaleTotal(CWnd* pParent /*=NULL*/)
: CDialog(CCompareSaleTotal::IDD, pParent)
{
//{{AFX_DATA_INIT(CCompareSaleTotal)
m_dateBegin = COleDateTime::GetCurrentTime();
m_dateEnd = COleDateTime::GetCurrentTime();
m_clientName = _T("");
m_opponentName = _T("");
m_summary = _T("");
//}}AFX_DATA_INIT
}
void CCompareSaleTotal::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CCompareSaleTotal)
DDX_Control(pDX, IDC_opponentName, m_opponentNameCombo);
DDX_Control(pDX, IDC_clientName, m_clientNameCombo);
DDX_DateTimeCtrl(pDX, IDC_dateBegin, m_dateBegin);
DDX_DateTimeCtrl(pDX, IDC_dateEnd, m_dateEnd);
DDX_CBString(pDX, IDC_clientName, m_clientName);
DDX_CBString(pDX, IDC_opponentName, m_opponentName);
DDX_Text(pDX, IDC_EDIT1, m_summary);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CCompareSaleTotal, CDialog)
//{{AFX_MSG_MAP(CCompareSaleTotal)
ON_BN_CLICKED(IDC_BUTTON1, OnAnalysis)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCompareSaleTotal message handlers
BOOL CCompareSaleTotal::OnInitDialog()
{
CDialog::OnInitDialog();
CString strSQL;
_RecordsetPtr m_pRecordset;
HRESULT hTRes;
hTRes = m_pRecordset.CreateInstance(_T("ADODB.Recordset"));
strSQL="select distinct clientName from client";
hTRes = m_pRecordset->Open((LPTSTR)strSQL.GetBuffer(130),
((CClientRelationshipApp*)AfxGetApp())->m_pConn.GetInterfacePtr(),
adOpenDynamic,adLockPessimistic,adCmdText);
int i=0;
while(!(m_pRecordset->adoEOF))
{
m_clientNameCombo.InsertString(i,((CClientRelationshipApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("clientName")));
m_pRecordset->MoveNext();
i++;
}
m_pRecordset->Close();
strSQL="select distinct opponentName from opponent";
hTRes = m_pRecordset->Open((LPTSTR)strSQL.GetBuffer(130),
((CClientRelationshipApp*)AfxGetApp())->m_pConn.GetInterfacePtr(),
adOpenDynamic,adLockPessimistic,adCmdText);
i=0;
while(!(m_pRecordset->adoEOF))
{
m_opponentNameCombo.InsertString(i,((CClientRelationshipApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("opponentName")));
m_pRecordset->MoveNext();
i++;
}
m_pRecordset->Close();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CCompareSaleTotal::OnAnalysis()
{
UpdateData(true);
CString strSQL;
CString str;
strSQL="exec clientSaleTotal '";//构造执行本公司销售额的存储过程的sql语句
str.Format("%d-%d-%d",m_dateBegin.GetYear(),m_dateBegin.GetMonth(),m_dateBegin.GetDay());
strSQL+=str+"','";//开始日期
str.Format("%d-%d-%d",m_dateEnd.GetYear(),m_dateEnd.GetMonth(),m_dateEnd.GetDay());
strSQL+=str+"','"+m_clientName+"'";//结束日期,客户姓名
_RecordsetPtr m_pRecordset;
HRESULT hTRes;
hTRes = m_pRecordset.CreateInstance(_T("ADODB.Recordset"));
//执行存储过程并返回结果
m_pRecordset=(((CClientRelationshipApp*)AfxGetApp())->m_pConn)->Execute((_bstr_t)strSQL,NULL,adCmdText);
//取出执行结果
str=((CClientRelationshipApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("totalMoney"));
m_pRecordset->Close();
//显示结果
m_summary="本公司销售额为:"+str;
strSQL="exec opponentSaleTotal '";//构造对手销售额的存储过程执行语句
str.Format("%d-%d-%d",m_dateBegin.GetYear(),m_dateBegin.GetMonth(),m_dateBegin.GetDay());
strSQL+=str+"','";
str.Format("%d-%d-%d",m_dateEnd.GetYear(),m_dateEnd.GetMonth(),m_dateEnd.GetDay());
strSQL+=str+"','"+m_opponentName+"'";
//执行存储过程
m_pRecordset=(((CClientRelationshipApp*)AfxGetApp())->m_pConn)->Execute((_bstr_t)strSQL,NULL,adCmdText);
str=((CClientRelationshipApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("totalMoney"));
m_pRecordset->Close();
//显示结果
m_summary+=" 对手销售额为:"+str;
UpdateData(false); //将数据更新到对话框
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -