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

📄 busdlg.cpp

📁 公交查询系统源代码 是武汉的 提供简单的查询和乘车方案 vc++
💻 CPP
字号:
// BusDlg.cpp : implementation file
//

#include "stdafx.h"
#include "Public_TGIS.h"
#include "BusDlg.h"
#include "Mainfrm.h"
#include "AppApi.h"
#include "Crack.h"
#include "NrstPath.h"
#include "Bus.h"
#include "BusQueryDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CBusDlg dialog


CBusDlg::CBusDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CBusDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CBusDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


void CBusDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CBusDlg)
	DDX_Control(pDX, IDC_BUS_ENDLIST, m_EndList);
	DDX_Control(pDX, IDC_BUS_STARTLIST, m_StartList);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CBusDlg, CDialog)
	//{{AFX_MSG_MAP(CBusDlg)
	ON_LBN_SELCHANGE(IDC_BUS_STARTLIST, OnSelchangeBusStartlist)
	ON_LBN_SELCHANGE(IDC_BUS_ENDLIST, OnSelchangeBusEndlist)
	ON_EN_CHANGE(IDC_BUS_STARTEDT, OnChangeBusStartedt)
	ON_EN_CHANGE(IDC_BUS_ENDEDT, OnChangeBusEndedt)
	ON_BN_CLICKED(IDC_BUTTON_BACK, OnButtonBack)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CBusDlg message handlers

BOOL CBusDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	LoadListBox();
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CBusDlg::LoadListBox()
{
	CMainFrame* pMainWnd = (CMainFrame*)AfxGetMainWnd();
	CDaoDatabase* tmpDB = new CDaoDatabase;
	try
	{
		tmpDB->Open(pMainWnd->m_environment.m_szDBName);
	}
	catch (CDaoException* e)
	{
		DisplayDaoException(e);
		delete tmpDB;
		e->Delete();
		return ;
	}

	m_StartList.ResetContent();
	m_EndList.ResetContent();
	CDaoRecordset rs(tmpDB);
	try
	{
		CString szSQL = "Select distinct 站名 From 公交车站路线 Order By 站名";
		rs.Open(dbOpenDynaset, szSQL);
		while(!rs.IsEOF())
		{
			COleVariant var;
			var = rs.GetFieldValue("站名");
			CString str = CCrack::strVARIANT(var);
			m_StartList.AddString(str);
            
			rs.MoveNext();
		}
		rs.Close();

		szSQL = "Select * From 公交站点";
		rs.Open(dbOpenDynaset, szSQL);
		while(!rs.IsEOF())
		{
			COleVariant var;
			var = rs.GetFieldValue("站名");
			CString str = CCrack::strVARIANT(var);
			m_EndList.AddString(str);
            
			rs.MoveNext();
		}
		rs.Close();
	}
	catch (CDaoException* e)
	{
		DisplayDaoException(e);
		tmpDB->Close();
		delete tmpDB;
		e->Delete();
		return ;
	}

	if(tmpDB)
	{
		if(tmpDB->IsOpen())
		{
			tmpDB->Close();
		}

		delete tmpDB;
		tmpDB = NULL;
	}
}

void CBusDlg::OnSelchangeBusStartlist() 
{
	// TODO: Add your control notification handler code here
	CString strName;
	m_StartList.GetText(m_StartList.GetCurSel(), strName);
	GetDlgItem(IDC_BUS_STARTEDT)->SetWindowText(strName);
}

void CBusDlg::OnSelchangeBusEndlist() 
{
	// TODO: Add your control notification handler code here
	CString strName;
	m_EndList.GetText(m_EndList.GetCurSel(), strName);
	GetDlgItem(IDC_BUS_ENDEDT)->SetWindowText(strName);
}

void CBusDlg::OnChangeBusStartedt() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	CString strName;	
	GetDlgItem(IDC_BUS_STARTEDT)->GetWindowText(strName);
	int nIndex = m_StartList.FindString(0, strName);
	if(nIndex != LB_ERR)
		m_StartList.SetCurSel(nIndex);
}

void CBusDlg::OnChangeBusEndedt() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	CString strName;	
	GetDlgItem(IDC_BUS_ENDEDT)->GetWindowText(strName);
	int nIndex = m_EndList.FindString(0, strName);
	if(nIndex != LB_ERR)
		m_EndList.SetCurSel(nIndex);
}

void CBusDlg::OnOK() 
{
	// TODO: Add extra validation here
// 判断站名的正确性
	CString strStartName;	
	GetDlgItem(IDC_BUS_STARTEDT)->GetWindowText(strStartName);
	CString strEndName;	
	GetDlgItem(IDC_BUS_ENDEDT)->GetWindowText(strEndName);
	if(strStartName == "" || strEndName == "")
		return;
	
	if (!IsValidStation(strStartName))
	{
		AfxMessageBox("错误的起始站名。");
		return;
	}
	if (!IsValidStation(strEndName))
	{
		AfxMessageBox("错误的终点站名。");
		return;
	}
    
	CMainFrame* pMainWnd = (CMainFrame*)AfxGetMainWnd();
	CEnvironment* env = &(pMainWnd->m_environment);
	CWaitCursor WaitCursor;
	CList<PathNode, PathNode&> array;
	env->m_path.Search(strStartName, strEndName, &array);
    
	if (array.GetCount() == 0)
	{
		AfxMessageBox("没有合适的乘车路线。");
		return;
	}
	else
	{
		ModifyStyle(WS_VISIBLE, 0);// 隐藏对话框
		CBus* pBusResultDlg = new CBus(pMainWnd);
		pBusResultDlg->m_array = &array;
		pBusResultDlg->DoModal();
		delete pBusResultDlg;
		pBusResultDlg = NULL;
	}

	int nCount = array.GetCount();
	for(int i=0; i<nCount; i++)
	{
		PathNode node = array.GetTail();
		array.RemoveTail();
		delete []node.szFromStationName;
		delete []node.szRoutineName;
		delete []node.szToStationName;
	}	


	CDialog::OnOK(); //关闭对话框
}
//-----------------------------------------------------------------------------------------
// 判断用于输入的站点名是否正确
BOOL CBusDlg::IsValidStation(CString szStation)
{
	CMainFrame* pMainWnd = (CMainFrame*)AfxGetMainWnd();
	CDaoDatabase* tmpDB = new CDaoDatabase;
	try
	{
		tmpDB->Open(pMainWnd->m_environment.m_szDBName);
	}
	catch (CDaoException* e)
	{
		DisplayDaoException(e);
		delete tmpDB;
		e->Delete();
		return FALSE;
	}

	BOOL bResult = FALSE;
	CDaoRecordset rs(tmpDB);
	try
	{
		CString szSQL = "Select distinct 站名 From 公交车站路线 Order By 站名";
		rs.Open(dbOpenDynaset, szSQL);
		if(rs.GetRecordCount() > 0)
			bResult = TRUE;
		rs.Close();
	}
	catch (CDaoException* e)
	{
		DisplayDaoException(e);
		tmpDB->Close();
		delete tmpDB;
		e->Delete();
		return FALSE;
	}

	if(tmpDB)
	{
		if(tmpDB->IsOpen())
		{
			tmpDB->Close();
		}

		delete tmpDB;
		tmpDB = NULL;
	}

	return bResult;
}
//------------------------------------------------------------------------

void CBusDlg::OnButtonBack() 
{
	// TODO: Add your control notification handler code here
	CDialog::OnOK(); //关闭对话框
	CBusQueryDlg dlg;
	dlg.DoModal();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -