📄 listinformation.cpp
字号:
// listinformation.cpp : implementation file
//
#include "stdafx.h"
#include "shop.h"
#include "listinformation.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern CShopApp theApp;
/////////////////////////////////////////////////////////////////////////////
// Clistinformation dialog
Clistinformation::Clistinformation(CWnd* pParent /*=NULL*/)
: CDialog(Clistinformation::IDD, pParent)
{
//{{AFX_DATA_INIT(Clistinformation)
m_mode1 = _T("");
m_mode2 = _T("");
m_condition1 = _T("");
m_condition2 = _T("");
//}}AFX_DATA_INIT
}
void Clistinformation::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(Clistinformation)
DDX_Control(pDX, IDC_USERLIST, m_userlist);
DDX_CBString(pDX, IDC_mode1, m_mode1);
DDX_CBString(pDX, IDC_mode2, m_mode2);
DDX_Text(pDX, IDC_condition1, m_condition1);
DDX_Text(pDX, IDC_condition2, m_condition2);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(Clistinformation, CDialog)
//{{AFX_MSG_MAP(Clistinformation)
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_BN_CLICKED(IDC_RADIO4, OnRadio4)
ON_BN_CLICKED(IDC_RADIO5, OnRadio5)
ON_BN_CLICKED(IDC_RADIO6, OnRadio6)
ON_BN_CLICKED(IDC_RADIO9, OnRadio9)
ON_BN_CLICKED(IDC_RADIO10, OnRadio10)
ON_BN_CLICKED(IDC_RADIO11, OnRadio11)
ON_BN_CLICKED(IDC_RADIO8, OnRadio8)
ON_BN_CLICKED(IDC_RADIO7, OnRadio7)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// Clistinformation message handlers
BOOL Clistinformation::OnInitDialog()
{
CDialog::OnInitDialog();
mode1 = "";
mode2 = "";
option1 = "";
option2 = "";
andor = "";
option11 = false;
option22 = false;
andor00 = false;
::SendMessage(m_userlist.m_hWnd, LVM_SETEXTENDEDLISTVIEWSTYLE,LVS_EX_FULLROWSELECT, LVS_EX_FULLROWSELECT);//当被选中时,所有子项都处于选中状态
//////////为列表控件添加列//////////
m_userlist.InsertColumn(0,"订单号",LVCFMT_LEFT,100);
m_userlist.InsertColumn(1,"订货日期",LVCFMT_LEFT,100);
m_userlist.InsertColumn (2,"顾客号",LVCFMT_LEFT,100);
m_userlist.InsertColumn(3,"顾客名",LVCFMT_LEFT,100);
m_userlist.InsertColumn(4,"货号",LVCFMT_LEFT,100);
m_userlist.InsertColumn(5,"货物名称",LVCFMT_LEFT,100);
m_userlist.InsertColumn(6,"订货数量",LVCFMT_LEFT,100);
//////////读取数据库中的信息添加到列表控件///////////
displayintheuserlist();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void Clistinformation::displayintheuserlist()
{
try
{
m_userlist.DeleteAllItems();
m_pRecordset.CreateInstance("ADODB.Recordset");
m_pRecordset->Open("select * from listinformationview order by listno",_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);
//m_bSuccess = TRUE;
while(!m_pRecordset->adoEOF)
{
vlistno= m_pRecordset->GetCollect("listno");
vdate = m_pRecordset->GetCollect("date");
vconsumerno=m_pRecordset->GetCollect("consumerno");
vconsumername = m_pRecordset->GetCollect("consumername");
vgoodno = m_pRecordset->GetCollect("goodno");
vgoodname= m_pRecordset->GetCollect("goodname");
vamount= m_pRecordset->GetCollect("amount");
nItem=m_userlist.InsertItem(0xffff,(_bstr_t)vlistno);//先插第一个项
m_userlist.SetItem(nItem,1,1,(_bstr_t)vdate,NULL,0,0,0);
m_userlist.SetItem(nItem,2,1,(_bstr_t)vconsumerno,NULL,0,0,0);
m_userlist.SetItem(nItem,3,1,(_bstr_t)vconsumername ,NULL,0,0,0);
m_userlist.SetItem(nItem,4,1,(_bstr_t)vgoodno,NULL,0,0,0);
m_userlist.SetItem(nItem,5,1,(_bstr_t)vgoodname,NULL,0,0,0);
m_userlist.SetItem(nItem,6,1,(_bstr_t)vamount,NULL,0,0,0);
m_pRecordset->MoveNext();
}
}
catch(_com_error e)///捕捉异常
{
//AfxMessageBox("读取数据库失败!");///显示错误信息
}
}
void Clistinformation::OnButton1()
{
UpdateData(true);
//订单号
// 订货日期
// 顾客编号
//顾客姓名
//货号
//货物名称
//货物数量
///////////////////////////////////
if (m_mode1=="订单号")
mode1="listno";
if (m_mode1=="订货日期")
mode1="date";
if (m_mode1=="顾客编号")
mode1="consumerno";
if (m_mode1=="顾客姓名")
mode1="consumername";
if (m_mode1=="货号")
mode1="goodno";
if (m_mode1=="货物名称")
mode1="goodname";
if (m_mode1=="货物数量")
mode1="amount";
//////////////////////////////////
if (m_mode2=="订单号")
mode2="listno";
if (m_mode2=="订货日期")
mode2="date";
if (m_mode2=="顾客编号")
mode2="consumerno";
if (m_mode2=="顾客姓名")
mode2="consumername";
if (m_mode2=="货号")
mode2="goodno";
if (m_mode2=="货物名称")
mode2="goodname";
if (m_mode2=="货物数量")
mode2="amount";
condition1 = m_condition1;
condition2 = m_condition2;
if(mode1 == "" && mode2 == "")
AfxMessageBox("请选择查询方式!");
if(option11 == true && option22 == true && andor00 == true)
{
sql = "select * from listinformationview where " + mode1 +" "+ option1 +" " + "'"+ condition1 + "'" + " " + andor + " " + mode2 + " "+ option2 +" " + "'" + condition2 + "'";
}
else if(option11 == true && andor00 == false)
{
sql = "select * from listinformationview where " + mode1 + " " + option1 + " " + "'" + condition1+"'";
}
else if(option22 == true && andor == false)
{
sql = "select * from listinformationview where " + mode2 + " " + option2 + " " + "'" + condition2 + "'";
}
else
goto label;
//sql = (mode1 + option1 + condition1) + (andor + mode2 + option2 + condition2);
try
{
//AfxMessageBox("请选择查询方式!");
m_pRecordset->Close();
m_pRecordset = NULL;
m_userlist.DeleteAllItems();
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)
{
AfxMessageBox("没有满足您的查询条件的结果!");
goto label;
}
while(!m_pRecordset->adoEOF)
{
//AfxMessageBox("请选择查询方式!");
vlistno= m_pRecordset->GetCollect("listno");
vdate = m_pRecordset->GetCollect("date");
vconsumerno=m_pRecordset->GetCollect("consumerno");
vconsumername = m_pRecordset->GetCollect("consumername");
vgoodno = m_pRecordset->GetCollect("goodno");
vgoodname= m_pRecordset->GetCollect("goodname");
vamount= m_pRecordset->GetCollect("amount");
nItem=m_userlist.InsertItem(0xffff,(_bstr_t)vlistno);//先插第一个项
m_userlist.SetItem(nItem,1,1,(_bstr_t)vdate,NULL,0,0,0);
m_userlist.SetItem(nItem,2,1,(_bstr_t)vconsumerno ,NULL,0,0,0);
m_userlist.SetItem(nItem,3,1,(_bstr_t)vconsumername,NULL,0,0,0);
m_userlist.SetItem(nItem,4,1,(_bstr_t)vgoodno,NULL,0,0,0);
m_userlist.SetItem(nItem,5,1,(_bstr_t)vgoodname,NULL,0,0,0);
m_userlist.SetItem(nItem,6,1,(_bstr_t)vamount,NULL,0,0,0);
m_pRecordset->MoveNext();
}
}
catch(_com_error e)///捕捉异常
{
//AfxMessageBox("读取数据库失败 ");///显示错误信息
}
label: //AfxMessageBox("请选择查询方式!");
UpdateData(false);
}
void Clistinformation::OnRadio4()
{
option1 = "<";
option11 = true;
}
void Clistinformation::OnRadio5()
{
option1 = "=";
option11 = true;
}
void Clistinformation::OnRadio6()
{
option1 = ">";
option11 = true;
}
void Clistinformation::OnRadio9()
{
option2 = "<";
option22 = true;
}
void Clistinformation::OnRadio10()
{
option2 = "=";
option22 = true;
}
void Clistinformation::OnRadio11()
{
option2 = ">";
option22 = true;
}
void Clistinformation::OnRadio8()
{
andor = "or";
andor00 = true;
}
void Clistinformation::OnRadio7()
{
andor = "and";
andor00 = true;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -