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

📄 busquerydlg.cpp

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

#include "stdafx.h"
#include "Public_TGIS.h"
#include "BusQueryDlg.h"
#include "MainFrm.h"
#include "MapControlView.h"
#include "AppApi.h"
#include "Crack.h"
#include "Public_TGISView.h"
#include "HawkView.h"
#include "StationDlg.h"
#include "LineDlg.h"
#include "BusDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CBusQueryDlg dialog


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


void CBusQueryDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CBusQueryDlg)
	DDX_Control(pDX, IDC_BUSQUERY_NAMELIST, m_NameList);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CBusQueryDlg, CDialog)
	//{{AFX_MSG_MAP(CBusQueryDlg)
	ON_EN_CHANGE(IDC_BUSQUERY_NAMEEDT, OnChangeBusqueryNameedit)
	ON_BN_CLICKED(IDC_BUSQUERY_STATIONCONDT, OnBusqueryStationcondt)
	ON_BN_CLICKED(IDC_BUSQUERY_LINECONDT, OnBusqueryLinecondt)
	ON_LBN_SELCHANGE(IDC_BUSQUERY_NAMELIST, OnSelchangeBusqueryNamelist)
	ON_LBN_DBLCLK(IDC_BUSQUERY_NAMELIST, OnDblclkBusqueryNamelist)
	ON_BN_CLICKED(IDC_BUSQUERY_QUERY, OnBusqueryQuery)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CBusQueryDlg message handlers

BOOL CBusQueryDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	// 设置公交查询类型过滤字符串
	SetBusFilter();
	// 在列表框中加入公交站点或公交路线名称
	LoadBusData();	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

//-----------------------------------------------------------------------------------------
// 设置公交查询类型过滤字符串
void CBusQueryDlg::SetBusFilter()
{
	CMainFrame* pMainWnd = (CMainFrame*)AfxGetMainWnd();
	pMainWnd->m_environment.m_bPathInit = false;
	CString szFilter = "";
  	if (szFilter != "")
			szFilter += ",'巴士专线'";
	else
			szFilter = "'巴士专线'";
    
	if (szFilter != "")
		pMainWnd->m_environment.m_szBusFilter = "类型 In (" + szFilter + ")";
	else
		pMainWnd->m_environment.m_szBusFilter = "";
}

BOOL CBusQueryDlg::LoadBusData()
{
	CMainFrame* pMainWnd = (CMainFrame*)AfxGetMainWnd();
	CMapControlView* pCtrlView = (CMapControlView*)(pMainWnd->m_wndSplitter2.GetPane(0,0));
	CDaoDatabase* tmpDB = new CDaoDatabase;
	try
	{
		tmpDB->Open(pMainWnd->m_environment.m_szDBName);
	}
	catch (CDaoException* e)
	{
		DisplayDaoException(e);
		delete tmpDB;
		e->Delete();
		return FALSE;
	}

	m_NameList.ResetContent();
	CDaoRecordset rs(tmpDB);
	try
	{
		CString szSQL;
        
		if (((CButton*)GetDlgItem(IDC_BUSQUERY_STATIONCONDT))->GetCheck())
		{
			if (pMainWnd->m_environment.m_szBusFilter  == "")
				szSQL = "Select distinct 站名 From 公交车站路线 Order By 站名";
			else
				szSQL = "Select distinct 站名 From 公交车站路线 Where "
				  + pMainWnd->m_environment.m_szBusFilter +" Order By 站名";

			rs.Open(dbOpenDynaset, szSQL);
			while(!rs.IsEOF())
			{
				COleVariant var;
				var = rs.GetFieldValue("站名");
				CString str = CCrack::strVARIANT(var);
				m_NameList.AddString(str);

				rs.MoveNext();
			}
		}
		else
		{
			if (pMainWnd->m_environment.m_szBusFilter  == "")
				szSQL = "Select distinct 线路名 From 公交车站路线 Order By 线路名";
			else
				szSQL = "Select distinct 线路名 From 公交车站路线 Where "
				  + pMainWnd->m_environment.m_szBusFilter + " Order By 线路名";
            
			rs.Open(dbOpenDynaset, szSQL);
			while(!rs.IsEOF())
			{
				COleVariant var;
				var = rs.GetFieldValue("线路名");
				CString str = CCrack::strVARIANT(var);
				m_NameList.AddString(str);

				rs.MoveNext();
			}
		}
	}
	catch (CDaoException* e)
	{
		DisplayDaoException(e);
		tmpDB->Close();
		delete tmpDB;
		e->Delete();
		return FALSE;
	}

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

		delete tmpDB;
		tmpDB = NULL;
	}

	GetDlgItem(IDC_BUSQUERY_NAMEEDT)->SetWindowText("");
    return true;
}

void CBusQueryDlg::OnChangeBusqueryNameedit() 
{
	// 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_BUSQUERY_NAMEEDT)->GetWindowText(strName);
	// 在列表框中进行查询
	int nIndex = m_NameList.FindString(0, strName);
	if(nIndex != LB_ERR)
		// 设置为当前选择项
		m_NameList.SetCurSel(nIndex);
}

void CBusQueryDlg::OnBusqueryStationcondt() 
{
	// TODO: Add your control notification handler code here
	LoadBusData();
}

void CBusQueryDlg::OnBusqueryLinecondt() 
{
	// TODO: Add your control notification handler code here
	LoadBusData();
}

void CBusQueryDlg::OnSelchangeBusqueryNamelist() 
{
	// TODO: Add your control notification handler code here
	CString strName;
	m_NameList.GetText(m_NameList.GetCurSel(), strName);
	GetDlgItem(IDC_BUSQUERY_NAMEEDT)->SetWindowText(strName);
}

void CBusQueryDlg::OnDblclkBusqueryNamelist() 
{
	// TODO: Add your control notification handler code here
	CMainFrame* pMainWnd = (CMainFrame*)AfxGetMainWnd();
	CPublic_TGISView* pMapView = (CPublic_TGISView*)(pMainWnd->m_wndSplitter.GetPane(0,0));
	CHawkView* pHawkView = (CHawkView*)(pMainWnd->m_wndSplitter2.GetPane(1,0));
	pMainWnd->m_bBusTextBox = FALSE;

	if (m_NameList.GetCount() <= 0)
		return;
	
	CString szName;
	m_NameList.GetText(m_NameList.GetCurSel(), szName);	
	CString szLayer = pMainWnd->m_environment.GetLayerName(szName, "地名索引");   
	CString szTable = pMainWnd->m_environment.GetTableName(szName, "地名索引");
	
	int nIndex = pMainWnd->m_environment.GetLayerIndexByName(szTable); 

	if (nIndex < 0)
	{
		// 属性库中没有这个车站或线路
		pMainWnd->m_environment.m_selectedFeature = NULL;
		pMainWnd->m_environment.m_selectedSymbol = NULL;
		pMapView->m_map.SetExtent(pMapView->m_map.GetExtent());

		return;
	}

	CMoRecordset rs;
	rs = pMainWnd->m_environment.m_layerInfos[nIndex].layer.SearchExpression("名称 like '"+szName +"'");

	if (rs)
	{
		rs.MoveFirst();
 		if (!rs.GetEof())
		{
			CMoPoint pt;
			CMoLine line;

			CMoFields fields(rs.GetFields());
			CMoField  shapeField(fields.Item(COleVariant(TEXT("Shape"))));
			if(((CButton*)GetDlgItem(IDC_BUSQUERY_STATIONCONDT))->GetCheck())
			{
				pt.m_lpDispatch = shapeField.GetValue().pdispVal;
			}
			else
			{
				line = shapeField.GetValue().pdispVal;
				pt = line.GetExtent().GetCenter();
			}

			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.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].layer.GetSymbol().GetSize());
				pMainWnd->m_environment.m_selectedSymbol.SetCharacterIndex(
					pMainWnd->m_environment.m_layerInfos[nIndex].nCharacterIndex);
				pMainWnd->m_environment.m_selectedSymbol.SetColor(0xff);

				pMainWnd->m_environment.m_selectedSymbolSize = 
					pMainWnd->m_environment.m_layerInfos[nIndex].nSymSize;
				pMainWnd->m_environment.m_selectedScale = 
					pMainWnd->m_environment.m_layerInfos[nIndex].dScale; 
			}
			else
			{
				if (pMainWnd->m_environment.m_layerInfos[nIndex].layer.GetShapeType() 
					== moShapeTypePoint)
				{					
					if(!pMainWnd->m_environment.m_selectedSymbol.m_lpDispatch)
						pMainWnd->m_environment.m_selectedSymbol.CreateDispatch(_T("MapObjects2.Symbol"));
					pMainWnd->m_environment.m_selectedSymbol.SetSymbolType(
						pMainWnd->m_environment.m_layerInfos[nIndex].layer.GetSymbol().GetSymbolType());
					pMainWnd->m_environment.m_selectedSymbol.SetStyle(
						pMainWnd->m_environment.m_layerInfos[nIndex].layer.GetSymbol().GetStyle());
					pMainWnd->m_environment.m_selectedSymbol.SetSize(
						pMainWnd->m_environment.m_layerInfos[nIndex].layer.GetSymbol().GetSize());
					pMainWnd->m_environment.m_selectedSymbol.SetColor(0xff);

					pMainWnd->m_environment.m_selectedSymbolSize = 
						pMainWnd->m_environment.m_layerInfos[nIndex].nSymSize;
					pMainWnd->m_environment.m_selectedScale = 
						pMainWnd->m_environment.m_layerInfos[nIndex].dScale; 
				}
				else
					pMainWnd->m_environment.m_selectedSymbol = NULL;
			}

			if (((CButton*)GetDlgItem(IDC_BUSQUERY_STATIONCONDT))->GetCheck())
			{
				//车站
				CMoFields fields(rs.GetFields());
				CMoField  shapeField(fields.Item(COleVariant(TEXT("Shape"))));
				pMainWnd->m_environment.m_selectedFeature = shapeField.GetValue().pdispVal;
			}
			else
			{
				long temp = 0;
				CMoPoints pts(line.GetParts().Item(COleVariant(temp,VT_I4)));

				if(pMainWnd->m_environment.m_drawLine)
				{
					for(int i=0; i<pMainWnd->m_environment.m_nSelectedLineNum; i++)
					{
						delete pMainWnd->m_environment.m_drawLine[i].pPoint;
						pMainWnd->m_environment.m_drawLine[i].pPoint = NULL;
					}
					delete pMainWnd->m_environment.m_drawLine;
					pMainWnd->m_environment.m_drawLine = NULL;				
				}
				pMainWnd->m_environment.m_nSelectedLineNum = 1;
				pMainWnd->m_environment.m_drawLine = new MLine[1];
				pMainWnd->m_environment.m_drawLine[0].nPointNumber = pts.GetCount();
				pMainWnd->m_environment.m_drawLine[0].pPoint = new MPoint[pts.GetCount()];

				for (long i = 0; i < pts.GetCount(); i ++)
				{
					pt = pts.Item(COleVariant(i, VT_I4));					
					pMainWnd->m_environment.m_drawLine[0].pPoint[i].x = pt.GetX();
					pMainWnd->m_environment.m_drawLine[0].pPoint[i].y = pt.GetY();	

				}

				pMainWnd->m_environment.m_buses = new Buses();
				int nCount = 0;
				if(!pMainWnd->m_environment.GetStation(szName, pMainWnd->m_environment.m_buses, &nCount)) 
					pMainWnd->m_environment.m_buses = NULL;
				else
					pMainWnd->m_environment.m_buses->nNum = nCount;
			}
			
			pMapView->m_map.FlashShape(rs.GetFields().Item(COleVariant("shape")).GetValue().pdispVal, 4);
			pMapView->m_map.SetExtent(pMapView->m_map.GetExtent()); 
			pHawkView->m_HawkMap.SetExtent(pHawkView->m_HawkMap.GetExtent());

			if (((CButton*)GetDlgItem(IDC_BUSQUERY_STATIONCONDT))->GetCheck())
			{				
				CStationDlg stationDlg = new CStationDlg(pMapView);
				stationDlg.m_szStaName = szName;
				CDialog::OnOK();
				stationDlg.DoModal();				
			}
			else
			{
				CLineDlg lineDlg = new CLineDlg(pMapView);
				lineDlg.m_szLineName = szName;
				CDialog::OnOK();
				lineDlg.DoModal();
			}
		}
		else
		{
			AfxMessageBox("电子地图上没有这个地物。"); 
		}
	}
}

void CBusQueryDlg::OnBusqueryQuery() 
{
	// TODO: Add your control notification handler code here
	CMainFrame* pMainWnd = (CMainFrame*)AfxGetMainWnd();
	CPublic_TGISView* pMapView = (CPublic_TGISView*)(pMainWnd->m_wndSplitter.GetPane(0,0));
	if (!pMainWnd->m_environment.m_bPathInit)
	{
		CWaitCursor waitCursor;
		pMainWnd->m_environment.m_path.Build();
		pMainWnd->m_environment.m_bPathInit = true;
	}

	CBusDlg BusDlg(pMapView); 
	CDialog::OnOK();
	BusDlg.DoModal();
}

⌨️ 快捷键说明

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