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

📄 linedlg.cpp

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

#include "stdafx.h"
#include "Public_TGIS.h"
#include "LineDlg.h"
#include "MainFrm.h"
#include "Crack.h"
#include "AppApi.h"
#include "Public_TGISView.h"
#include "BusQueryDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CLineDlg dialog


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


void CLineDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CLineDlg)
	DDX_Control(pDX, IDC_LINE_TRANSLINELIST, m_LineList);
	DDX_Control(pDX, IDC_LINE_STATIONLIST, m_StationList);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CLineDlg, CDialog)
	//{{AFX_MSG_MAP(CLineDlg)
	ON_LBN_SELCHANGE(IDC_LINE_STATIONLIST, OnSelchangeLineStationlist)
	ON_LBN_DBLCLK(IDC_LINE_STATIONLIST, OnDblclkLineStationlist)
	ON_WM_CLOSE()
	ON_BN_CLICKED(IDC_NAVIGATION_BUTTON, OnNavigationButton)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CLineDlg message handlers

BOOL CLineDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	GetDlgItem(IDC_LINE_LINENAME)->SetWindowText("线路名称:" + m_szLineName);
	// 在车站列表框中列出某公交线路经过的所有站点
	LoadStationListBox();
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}
//-----------------------------------------------------------------------------------------
// 从“公交车站路线”数据表中,查询szLineName指定的公交路线经过的所有站点
void CLineDlg::LoadStationListBox()
{
	m_StationList.ResetContent();
	if ("" == m_szLineName)
		return ;

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

	CDaoRecordset rs(tmpDB);
	try
	{
		CString szSQL = "Select 站名 From 公交车站路线 Where 线路名='"
			+ m_szLineName + "' Order By 顺序";

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

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

		delete tmpDB;
		tmpDB = NULL;
	}
}

void CLineDlg::OnSelchangeLineStationlist() 
{
	// TODO: Add your control notification handler code here
	int nIndex = m_StationList.GetCurSel();
	if(nIndex < 0)
		return;
	CString szStation;
	m_StationList.GetText(nIndex, szStation);

	// 查询所有经过某站点的公交路线
	LoadLineList(szStation);
}

// 从“公交车站路线”数据表中查询所有经过szStaName指定站点的公交路线
void CLineDlg::LoadLineList(CString szStaName)
{
	if ("" == szStaName)
		return ;
    
	m_LineList.ResetContent();
	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;
	}

	CDaoRecordset rs(tmpDB);
	try
	{
		CString szSQL = "Select 线路名 From 公交车站路线 Where 站名='" + szStaName + "'";
		if(pMainWnd->m_environment.m_szBusFilter != "")
		{
			szSQL += " And ";
			szSQL += pMainWnd->m_environment.m_szBusFilter;
		}
		szSQL += "  Order By 线路名";

		rs.Open(dbOpenDynaset, szSQL);
		while(!rs.IsEOF())
		{
			COleVariant var;
			var = rs.GetFieldValue("线路名");
			CString str = CCrack::strVARIANT(var);
			m_LineList.AddString(str);
            
			rs.MoveNext();
		}
	}
	catch (CDaoException* e)
	{
		DisplayDaoException(e);
		tmpDB->Close();
		delete tmpDB;
		e->Delete();
		return;
	}

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

		delete tmpDB;
		tmpDB = NULL;
	}
}
//-----------------------------------------------------------------------

void CLineDlg::OnDblclkLineStationlist() 
{
	// TODO: Add your control notification handler code here

int nIndex = m_StationList.GetCurSel();
	if(nIndex < 0)
		return;

	CString szName;
	m_StationList.GetText(nIndex, szName);
	CMainFrame* pMainWnd = (CMainFrame*)AfxGetMainWnd();
	CPublic_TGISView* pMapView = (CPublic_TGISView*)(pMainWnd->
		                   m_wndSplitter.GetPane(0,0));
	CString szLayer = pMainWnd->m_environment.GetLayerName(szName,"地名索引");   
	CString szTable = pMainWnd->m_environment.GetTableName(szName,"地名索引");
			
	nIndex =  pMainWnd->m_environment.GetLayerIndexByName(szTable); 
	if (nIndex < 0)
		return;

	CMoRecordset rs;
	rs = pMainWnd->m_environment.m_layerInfos[nIndex].layer.SearchExpression(
		           "名称 like '"+szName +"'");
	if (rs)
	{
		rs.MoveFirst(); 
		if (!rs.GetEof())
		{
			CMoFields fields(rs.GetFields());
			CMoField shapeField(fields.Item(COleVariant("shape")));
			CMoPoint pt(shapeField.GetValue().pdispVal);
			if (!IsWithin(pMapView->m_map.GetExtent(), pt))  
			{
				pMapView->m_map.CenterAt(pt.GetX(), pt.GetY());   
			}

			if(pMainWnd->m_environment.m_layerInfos[nIndex].nCharacterIndex >= 0 &&
				pMainWnd->m_environment.m_layerInfos[nIndex].layer.GetShapeType()
				       == moShapeTypePoint)
			{
				if(pMainWnd->m_environment.m_selectedSymbol.m_lpDispatch)
					pMainWnd->m_environment.m_selectedSymbol.ReleaseDispatch();
				pMainWnd->m_environment.m_selectedSymbol.CreateDispatch(
					                             _T("MapObjects2.Symbol"));
				pMainWnd->m_environment.m_selectedSymbol.SetSymbolType(moPointSymbol);
				pMainWnd->m_environment.m_selectedSymbol.GetFont().SetName(
					pMainWnd->m_environment.m_layerInfos[nIndex].szFontName);
				pMainWnd->m_environment.m_selectedSymbol.SetStyle(4);
				pMainWnd->m_environment.m_selectedSymbol.SetSize(
					pMainWnd->m_environment.m_layerInfos[nIndex].nSymSize);
				pMainWnd->m_environment.m_selectedSymbol.SetCharacterIndex(
				pMainWnd->m_environment.m_layerInfos[nIndex].nCharacterIndex);
				pMainWnd->m_environment.m_selectedSymbol.SetColor(0xff);
			}
			else
				pMainWnd->m_environment.m_selectedSymbol = NULL;
			
			pMainWnd->m_environment.m_selectedFeature =
				shapeField.GetValue().pdispVal;
			pMapView->m_map.FlashShape(
				pMainWnd->m_environment.m_selectedFeature, 4);
			pMapView->m_map.SetExtent(pMapView->m_map.GetExtent()); 		
		}
	}
}
//-----------------------------------------------------------------------------------------

void CLineDlg::OnClose() 
{
	// TODO: Add your message handler code here and/or call default
	
	CDialog::OnClose();
	CBusQueryDlg dlg;
	dlg.DoModal();
}

void CLineDlg::OnNavigationButton() 
{
	// TODO: Add your control notification handler code here
	CMainFrame* pMainWnd = (CMainFrame*)AfxGetMainWnd();
	CPublic_TGISView* pMapView = (CPublic_TGISView*)(pMainWnd->
		                   m_wndSplitter.GetPane(0,0));
    pMapView->LineNavigation();
}

⌨️ 快捷键说明

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