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

📄 linedlg.cpp

📁 程序编写环境为Visual Studio.NET 2002
💻 CPP
字号:
// LineDlg.cpp : implementation file
//

#include "stdafx.h"
#include "NameGis.h"
#include "LineDlg.h"
#include "MainFrm.h"
#include "Crack.h"
#include "AppApi.h"
#include "NameGisView.h"
#include "MoFields.h"
#include "MoField.h"
#include "MapObjects2.h"

// CLineDlg dialog

IMPLEMENT_DYNAMIC(CLineDlg, CDialog)
CLineDlg::CLineDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CLineDlg::IDD, pParent)
{
	m_szLineName = "";
}

CLineDlg::~CLineDlg()
{
}

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


BEGIN_MESSAGE_MAP(CLineDlg, CDialog)
	ON_LBN_SELCHANGE(IDC_LINE_STATIONLIST, OnLbnSelchangeLineStationlist)
	ON_LBN_DBLCLK(IDC_LINE_STATIONLIST, OnLbnDblclkLineStationlist)
END_MESSAGE_MAP()


// CLineDlg message handlers
//-----------------------------------------------------------------------------------------
BOOL CLineDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	GetDlgItem(IDC_LINE_LINENAME)->SetWindowText("线路名称:" + m_szLineName);
	// 在车站列表框中列出某公交线路经过的所有站点
	LoadStationListBox();

	return TRUE;  
}
//-----------------------------------------------------------------------------------------
// 从“公交车站路线”数据表中,查询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::OnLbnSelchangeLineStationlist()
{
	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::OnLbnDblclkLineStationlist()
{
	int nIndex = m_StationList.GetCurSel();
	if(nIndex < 0)
		return;

	CString szName;
	m_StationList.GetText(nIndex, szName);
	CMainFrame* pMainWnd = (CMainFrame*)AfxGetMainWnd();
	CNameGisView* pMapView = (CNameGisView*)(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()); 		
		}
	}
}
//-----------------------------------------------------------------------------------------

⌨️ 快捷键说明

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