📄 statdlg.cpp
字号:
// StatDlg.cpp : implementation file
//
#include "stdafx.h"
#include "MarketManager.h"
#include "StatDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
////////////////////////////////////////////////
//peter statements
extern CMarketManagerApp theApp;
//peter statements
////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// CStatDlg dialog
CStatDlg::CStatDlg(CWnd* pParent /*=NULL*/)
: CDialog(CStatDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CStatDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
//////////////////////////////////////////////////////
//peter statements
m_pRdset.CreateInstance(__uuidof(Recordset));
//peter statements
///////////////////////////////////////////////////////
}
void CStatDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CStatDlg)
DDX_Control(pDX, ID_STAT_LISTVIEW, m_pListView);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CStatDlg, CDialog)
//{{AFX_MSG_MAP(CStatDlg)
ON_BN_CLICKED(ID_STAT_QUANTITY, OnStatQuantity)
ON_BN_CLICKED(ID_STAT_CAPITAL, OnStatCapital)
ON_BN_CLICKED(ID_STAT_CLEAR, OnStatClear)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CStatDlg message handlers
void CStatDlg::OnStatQuantity()
{
CString str,info;
int tmp;
_variant_t var;
m_pListView.ResetContent();
str.Format("select * from Record order by Record_Quantity desc");
try
{
//打开销售记录表,按销售数量降序排列
m_pRdset->Open(str.AllocSysString(),theApp.m_pConnection.GetInterfacePtr(),adOpenStatic,adLockReadOnly,adCmdText);
if(!m_pRdset->BOF)
{
m_pRdset->MoveFirst();
///peter: strange statement! variant i is the key to sort????
int i=0;
while(!m_pRdset->adoEOF)
{
info.Format("序号: %d ",i++);
info+="日期: ";
var=m_pRdset->GetCollect("Record_Date");
str=(LPCSTR)_bstr_t(var);
str.TrimRight(" ");
info+=str;
var=m_pRdset->GetCollect("Record_No");
str=(LPCSTR)_bstr_t(var);
str.TrimRight(" ");
info+=" 货物编号: ";
info+=str;
var=m_pRdset->GetCollect("Record_Quantity");
tmp=var.intVal;
str.Format(" 数量: %d ",tmp);
info+=str;
var=m_pRdset->GetCollect("Record_SaleSum");
tmp=var.intVal;
str.Format("总金额: %d",tmp);
info+=str;
m_pListView.AddString(info);
m_pRdset->MoveNext();
}
}
else
{
MessageBox("历史纪录已被清空","系统提示",MB_OK|MB_ICONWARNING);
}
}
catch(_com_error *e)
{
AfxMessageBox(e->ErrorMessage());
}
m_pRdset->Close();
}
void CStatDlg::OnStatCapital()
{
CString str,info;
int tmp;
_variant_t var;
//清除显示
m_pListView.ResetContent();
str.Format("select * from Record order by Record_SaleSum desc");
try
{
//打开销售纪录表,按销售总金额降序排列
m_pRdset->Open(str.AllocSysString(),theApp.m_pConnection.GetInterfacePtr(),adOpenStatic,adLockReadOnly,adCmdText);
if(!m_pRdset->BOF)
{//循环遍历Datebase并显示
m_pRdset->MoveFirst();
int i=0;
while(!m_pRdset->adoEOF)
{
info.Format("序号: %d ",i);
info+="日期 : ";
var=m_pRdset->GetCollect("Record_Date");
str=(LPCSTR)_bstr_t(var);
str.TrimRight(" ");
info+=str;
var=m_pRdset->GetCollect("Record_No");
str=(LPCSTR)_bstr_t(var);
str.TrimRight(" ");
info+=" 货物编号: ";
info+=str;
var=m_pRdset->GetCollect("Record_Quantity");
tmp=var.intVal;
str.Format(" 数量: %d ",tmp);
info+=str;
var=m_pRdset->GetCollect("Record_SaleSum");
tmp=var.intVal;
str.Format("总金额: %d",tmp);
info+=str;
m_pListView.InsertString(i,info);
i++;
m_pRdset->MoveNext();
}
}
else
{
MessageBox("历史纪录已被清空","系统提示",MB_OK|MB_ICONWARNING);
}
}
catch(_com_error *e)
{
AfxMessageBox(e->ErrorMessage());
}
m_pRdset->Close();
}
void CStatDlg::OnStatClear()
{
CString str;
str.Format("select * from Record");
try
{
//打开销售记录表
m_pRdset->Open(str.AllocSysString(),theApp.m_pConnection.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText);
if(!m_pRdset->BOF)
{//确认删除操作
str.Format("历史纪录将被清空!\n确认操作点击OK\n撤销操作点击Cancel");
if(MessageBox(str,"系统确认",MB_OKCANCEL|MB_ICONQUESTION)==IDOK)
{//循环遍历Datebase,执行删除操作
m_pRdset->MoveFirst();
while(!m_pRdset->adoEOF)
{
m_pRdset->Delete(adAffectCurrent);
m_pRdset->MoveNext();
}
m_pListView.ResetContent();//清除显示
MessageBox("历史纪录成功删除","系统提示",MB_OK|MB_ICONINFORMATION);
}
}
else
{
MessageBox("历史纪录已被清空","系统提示",MB_OK|MB_ICONWARNING);
}
}
catch(_com_error *e)
{
AfxMessageBox(e->ErrorMessage());
}
m_pRdset->Close();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -