📄 page2.cpp
字号:
// page2.cpp : implementation file
//
#include "stdafx.h"
#include "BusStop.h"
#include "page2.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern CBusStopApp theApp;
/////////////////////////////////////////////////////////////////////////////
// page2 dialog
page2::page2(CWnd* pParent /*=NULL*/)
: CDialog(page2::IDD, pParent)
{ ado_once=0;
//{{AFX_DATA_INIT(page2)
m_stopname = _T("");
//}}AFX_DATA_INIT
}
void page2::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(page2)
DDX_Control(pDX, IDC_LIST3, m_list2);
DDX_Control(pDX, IDC_LIST2, m_list1);
DDX_Control(pDX, IDC_LIST1, m_ListBusLine);
DDX_Text(pDX, IDC_EDIT1, m_stopname);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(page2, CDialog)
//{{AFX_MSG_MAP(page2)
ON_BN_CLICKED(IDC_Search, OnSearch)
ON_LBN_SELCHANGE(IDC_LIST1, OnSelchangeList1)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// page2 message handlers
BOOL page2::OnInitDialog()
{
CDialog::OnInitDialog();
m_list1.SetExtendedStyle(LVS_EX_GRIDLINES|LVS_EX_FULLROWSELECT);
m_list1.InsertColumn(0,"站号",LVCFMT_LEFT,50);
m_list1.InsertColumn(1,"站名",LVCFMT_LEFT,145);
m_list2.SetExtendedStyle(LVS_EX_GRIDLINES|LVS_EX_FULLROWSELECT);
m_list2.InsertColumn(0,"站号",LVCFMT_LEFT,50);
m_list2.InsertColumn(1,"站名",LVCFMT_LEFT,146);
m_pRecordset.CreateInstance(__uuidof(Recordset));
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void page2::OnSearch()
{m_list1.DeleteAllItems();
m_list2.DeleteAllItems();
if(ado_once==0)
{ try
{
m_pRecordset->Open("SELECT * FROM bus", // 查询DemoTable表中所有字段
theApp.m_pConnection.GetInterfacePtr(), // 获取库接库的IDispatch指针
adOpenDynamic,
adLockOptimistic,
adCmdText);
}
catch(_com_error *e)
{
AfxMessageBox(e->ErrorMessage());
}
ado_once=1;
}
int num=m_ListBusLine.GetCount();
for(int j=0;j<num;j++)
m_ListBusLine.DeleteString(0);
UpdateData(TRUE);
CString strSql;
strSql.Format("SELECT * FROM bus WHERE stop_name='%s' AND flag=0",
m_stopname);
try
{
m_pRecordset->Close();
m_pRecordset->Open(strSql.AllocSysString(),
theApp.m_pConnection.GetInterfacePtr(),
adOpenDynamic,
adLockOptimistic,
adCmdText);
}
catch(_com_error *e)
{
AfxMessageBox(e->ErrorMessage());
}
_variant_t var;
CString busline;
try
{
if(!m_pRecordset->BOF)
m_pRecordset->MoveFirst();
else
{
AfxMessageBox("没有这个站点!");
return;
}
while(!m_pRecordset->adoEOF)
{
var = m_pRecordset->GetCollect("bus_number_text");
if(var.vt != VT_NULL)
busline=(LPCSTR)_bstr_t(var);
m_ListBusLine.AddString(busline);
m_pRecordset->MoveNext();
}
}
catch(_com_error *e)
{
AfxMessageBox(e->ErrorMessage());
}
}
void page2::OnSelchangeList1()
{
CString m_busline;
int flag;
m_ListBusLine.GetCurSel();
m_ListBusLine.GetText(m_ListBusLine.GetCurSel(),m_busline);
CString strSql;
flag=1;
strSql.Format("SELECT * FROM bus WHERE bus_number_text = '%s' AND flag=%d ORDER BY stop_number ASC",
m_busline,flag);
try
{
m_pRecordset->Close();
m_pRecordset->Open(strSql.AllocSysString(),
theApp.m_pConnection.GetInterfacePtr(),
adOpenDynamic,
adLockOptimistic,
adCmdText);
}
catch(_com_error *e)
{
AfxMessageBox(e->ErrorMessage());
}
int i=0;
_variant_t var;
CString stop_number,stop_name;
m_list1.DeleteAllItems();
stop_number=stop_name="";
try
{
if(!m_pRecordset->BOF)
m_pRecordset->MoveFirst();
else
{
AfxMessageBox("表内数据为空");
return;
}
while(!m_pRecordset->adoEOF)
{
var = m_pRecordset->GetCollect("stop_number");
if(var.vt != VT_NULL)
stop_number = (LPCSTR)_bstr_t(var);
var = m_pRecordset->GetCollect("stop_name");
if(var.vt != VT_NULL)
stop_name = (LPCSTR)_bstr_t(var);
m_list1.InsertItem(i,stop_number);
m_list1.SetItemText(i,1,stop_name);
i++;
m_pRecordset->MoveNext();
}
}
catch(_com_error *e)
{
AfxMessageBox(e->ErrorMessage());
}
flag=0;
strSql.Format("SELECT * FROM bus WHERE bus_number_text = '%s' AND flag=%d order by stop_number ASC",
m_busline,flag);
try
{
m_pRecordset->Close();
m_pRecordset->Open(strSql.AllocSysString(),
theApp.m_pConnection.GetInterfacePtr(),
adOpenDynamic,
adLockOptimistic,
adCmdText);
}
catch(_com_error *e)
{
AfxMessageBox(e->ErrorMessage());
}
m_list2.DeleteAllItems();
stop_number=stop_name="";
i=0;
try
{
if(!m_pRecordset->BOF)
m_pRecordset->MoveFirst();
else
{
AfxMessageBox("表内数据为空");
return;
}
while(!m_pRecordset->adoEOF)
{
var = m_pRecordset->GetCollect("stop_number");
if(var.vt != VT_NULL)
stop_number = (LPCSTR)_bstr_t(var);
var = m_pRecordset->GetCollect("stop_name");
if(var.vt != VT_NULL)
stop_name = (LPCSTR)_bstr_t(var);
m_list2.InsertItem(i,stop_number);
m_list2.SetItemText (i,1,stop_name);
m_pRecordset->MoveNext();
i++;
}
}
catch(_com_error *e)
{
AfxMessageBox(e->ErrorMessage());
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -