⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 page1.cpp

📁 全国公交车系统,可查询线路和车站, 寻找转车路线
💻 CPP
字号:
// page1.cpp : implementation file
//

#include "stdafx.h"
#include "BusStop.h"
#include "page1.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
CListBox  m_addline;

extern CBusStopApp theApp; 

/////////////////////////////////////////////////////////////////////////////
// page1 dialog


page1::page1(CWnd* pParent /*=NULL*/)
	: CDialog(page1::IDD, pParent)
{
	//{{AFX_DATA_INIT(page1)
	//}}AFX_DATA_INIT
}


void page1::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(page1)
	DDX_Control(pDX, IDC_LIST4, m_addline);

	DDX_Control(pDX, IDC_LIST2, m_list2);

	DDX_Control(pDX, IDC_LIST1, m_list1);
	
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(page1, CDialog)
	//{{AFX_MSG_MAP(page1)
   
	ON_LBN_SELCHANGE(IDC_LIST4, OnSelchangeList4)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// page1 message handlers


BOOL page1::OnInitDialog() 
{   ado_once=0;


	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 page1::OnSelchangeList4() 

{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;
}

CString  m_busline;

int flag;

m_addline.GetCurSel();
m_addline.GetText(m_addline.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 + -