www.gusucode.com > 铁路列车车辆监控系统本系统要求PC机有两个串行通讯串口, > 铁路列车车辆监控系统本系统要求PC机有两个串行通讯串口,有线MODEM一个。其它配置没有严格的要求,一般配置即可。/铁路列车车辆监控系统/电子地图显示模块(江军)/EagleViewNew/EagleViewView.cpp

    // EagleViewView.cpp : implementation of the CEagleViewView class
//

#include "stdafx.h"
#include "EagleView.h"

#include "EagleViewDoc.h"
#include "EagleViewView.h"
#include "EagleWnd.h"
#include "MainFrm.h"
#include "DialogMain.h"
#include "DialogNormalCity.h"
#include "DialogRout.h"
#include "DemoDialog.h"
#include "InfoWnd.h"
#include "DialogDisplay.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern CEagleWnd* CEagleMap;
/////////////////////////////////////////////////////////////////////////////
// CEagleViewView

IMPLEMENT_DYNCREATE(CEagleViewView, CView)

BEGIN_MESSAGE_MAP(CEagleViewView, CView)
	//{{AFX_MSG_MAP(CEagleViewView)
	ON_WM_CREATE()
	ON_WM_SIZE()
	ON_WM_SETFOCUS()
	ON_COMMAND(IDC_ENTIRE_MAP, OnEntireMap)
	ON_COMMAND(IDC_MAP_TOOL_ARROW, OnMapToolArrow)
	ON_COMMAND(IDC_ZOOMIN, OnZoomin)
	ON_COMMAND(IDC_ZOOMOUT, OnZoomout)
	ON_COMMAND(IDC_PAN, OnPan)
	ON_COMMAND(IDC_MAP_TOOL_CENTER, OnMapToolCenter)
	ON_COMMAND(IDC_MAP_TOOL_SELECT, OnMapToolSelect)
	ON_COMMAND(IDC_MAP_TOOL_RADIUSSELECT, OnMapToolRadiusselect)
	ON_COMMAND(IDC_MAP_TOOL_RECTANGLESELECT, OnMapToolRectangleselect)
	ON_COMMAND(IDC_MAP_PROPERTIES, OnMapProperties)
	ON_COMMAND(IDC_MAP_LAYERCONTROL, OnMapLayercontrol)
	ON_COMMAND(IDC_INFO, OnInfo)
	ON_COMMAND(IDC_LONGTHTEST, OnLongthtest)
	ON_COMMAND(IDC_DATA_MAINCITY, OnDataMaincity)
	ON_COMMAND(IDC_DATA_NORMALCITY, OnDataNormalcity)
	ON_COMMAND(IDC_DATA_ROUT, OnDataRout)
	ON_COMMAND(IDC_DEMO, OnDemo)
	ON_COMMAND(IDC_START, OnStart)
	ON_COMMAND(IDC_STOP, OnStop)
	ON_WM_TIMER()
	ON_COMMAND(IDC_DISPLAY, OnDisplay)
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CEagleViewView construction/destruction

CEagleViewView::CEagleViewView()
{
	// TODO: add construction code here
	TNum=0;
	count=0;
	FlashOn=FALSE;
	m_PolyLongth=FALSE;
	m_Num=0;
}

CEagleViewView::~CEagleViewView()
{
	_ConnectionPtr m_pConnect0;

	HRESULT hr;
	try
	{
		hr = m_pConnect0.CreateInstance("ADODB.Connection");
		if(SUCCEEDED(hr))
		{
			hr = m_pConnect0->Open("driver=SQL Server;Server=.;DATABASE=MapXDB;UID=sa;PWD=;","","",adModeUnknown);
		}
	}catch(_com_error e)
	{
		CString errormessage;
		errormessage.Format("连接数据库失败!\r\n错误信息:%s",e.ErrorMessage());
		AfxMessageBox(errormessage);
	}
	for(int i=0;i<TNum;i++)
	{
		CString strNum;
		strNum.Format("%d",i);
		_bstr_t strSQL="drop table 轨迹"+strNum;
		m_pConnect0->Execute(strSQL,NULL,adCmdText);
	}

	_bstr_t strSQL1="delete 轨迹";
	_bstr_t strSQL2="delete 短信";
	m_pConnect0->Execute(strSQL1,NULL,adCmdText);
	m_pConnect0->Execute(strSQL2,NULL,adCmdText);

	m_pConnect0->Close();
}

BOOL CEagleViewView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CEagleViewView drawing

void CEagleViewView::OnDraw(CDC* pDC)
{
	CEagleViewDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
}

/////////////////////////////////////////////////////////////////////////////
// CEagleViewView printing

BOOL CEagleViewView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CEagleViewView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CEagleViewView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CEagleViewView diagnostics

#ifdef _DEBUG
void CEagleViewView::AssertValid() const
{
	CView::AssertValid();
}

void CEagleViewView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

CEagleViewDoc* CEagleViewView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CEagleViewDoc)));
	return (CEagleViewDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CEagleViewView message handlers
BEGIN_EVENTSINK_MAP(CEagleViewView, CView)
    //{{AFX_EVENTSINK_MAP(CXXXView)
	ON_EVENT(CEagleViewView, IDC_MAINMAP, 6 /* MapViewChanged */, OnMapViewChangedMap, VTS_NONE)
	ON_EVENT(CEagleViewView, IDC_MAINMAP, DISPID_MOUSEMOVE, OnMouseMoveInMap,VTS_I2 VTS_I2 VTS_XPOS_PIXELS VTS_YPOS_PIXELS)
	ON_EVENT(CEagleViewView, IDC_MAINMAP, MAPX_DISPID_POLYTOOLUSED, OnPolyToolUsedMap, VTS_I2 VTS_I4 VTS_DISPATCH VTS_BOOL VTS_BOOL VTS_PBOOL)
	//}}AFX_EVENTSINK_MAP

END_EVENTSINK_MAP()

void CEagleViewView::OnMapViewChangedMap()
{
	//My Sample On_Event_Function
	count++;
	if(count>5)
	{
		CMapXRectangle rect;
		rect.CreateDispatch(rect.GetClsid());
		//m_mainmap.GetClientRect(rect);
		rect=m_mainmap.GetBounds();
		double X1=rect.GetXMin();
		double X2=rect.GetXMax();
		double Y1=rect.GetYMin();
		double Y2=rect.GetYMax();
		double x2,y2,x4,y4;
		VARIANT scx, scy, scx1, scy1;
		VARIANT mapx1,mapy1,mapx2,mapy2;
		CMapXFeatureFactory cFactory=CEagleMap->m_eaglemap.GetFeatureFactory();
		CMapXLayer  layer;
		CMapXFeature feature;
		CMapXFeatures features;
		CMapXPoints points;
		points.CreateDispatch(points.GetClsid());
		CEagleMap->m_eaglemap.ConvertCoordV(&scx,&scy,COleVariant(X1),COleVariant(Y1),miMapToScreen);
		CEagleMap->m_eaglemap.ConvertCoordV(&scx1,&scy1,COleVariant(X2),COleVariant(Y2),miMapToScreen);
		CEagleMap->m_eaglemap.ConvertCoordV(&scx,&scy1,&mapx1,&mapy1,miScreenToMap);
		CEagleMap->m_eaglemap.ConvertCoordV(&scx1,&scy,&mapx2,&mapy2,miScreenToMap);
		x2=mapx1.dblVal;
		y2=mapy1.dblVal;
		x4=mapx2.dblVal;
		y4=mapy2.dblVal;
		
		layer=CEagleMap->m_eaglemap.GetLayers().Item("RectLayer");
		features=layer.AllFeatures();
		if(features.GetCount()==0)
		{
			points.AddXY(X1,Y1);
			points.AddXY(x2,y2);
			points.AddXY(X2,Y2); 
			points.AddXY(x4,y4);
			COleVariant vtPoints;
			vtPoints.vt = VT_DISPATCH;
			vtPoints.pdispVal = points.m_lpDispatch;
			vtPoints.pdispVal->AddRef();
			feature=cFactory.CreateRegion(vtPoints);
			CMapXStyle style=feature.GetStyle();
			style.SetRegionPattern(miPatternNoFill);
			style.SetRegionBorderColor(miColorRed); 
			style.SetRegionBorderWidth(2);
			feature.SetStyle(style.m_lpDispatch);
			CEagleMap->m_eaglefeature=layer.AddFeature(feature);
		}
		else
		{
			feature=features.Item(1);
			CMapXParts parts=feature.GetParts();
			CMapXPoints points=parts.Item(1);
			points.RemoveAll();
			points.AddXY(X1,Y1);
			points.AddXY(x2,y2);
			points.AddXY(X2,Y2);
			points.AddXY(x4,y4);
			feature.Update();
		}
		layer.Refresh();
	}
}

int CEagleViewView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	//short Type;
	//VARIANT SourceData,Name,GeoField,SecondaryGeoField,BindLayerName,Fields;
//	GetDlgItem(IDC_START)->EnableWindow(TRUE);
//	GetDlgItem(IDC_STOP)->EnableWindow(FALSE);

	if (CView::OnCreate(lpCreateStruct) == -1)
		return -1;
	if(!m_mainmap.Create(NULL,WS_VISIBLE,CRect(0,0,100,100),this,IDC_MAINMAP))
		return -1;
	m_mainmap.SetGeoSet("ChinaTrianMap.gst");
	m_mainmap.SetTitleText("");
	m_mainmap.CreateCustomTool(MYTOOL_DISTANCE,miToolTypePoly,miCrossCursor);

	m_DataPoint1="";
	m_DataPoint2="";
	m_DataPoint="";

	m_T=FALSE;

	return 0;
}

void CEagleViewView::OnSize(UINT nType, int cx, int cy) 
{
	CView::OnSize(nType, cx, cy);
	
	if(cx!=0&&cy!=0)
	{
		m_mainmap.MoveWindow(0,0,cx,cy,TRUE);
	}
	
	// TODO: Add your message handler code here
	
}

void CEagleViewView::OnSetFocus(CWnd* pOldWnd) 
{
	CView::OnSetFocus(pOldWnd);

	m_mainmap.SetFocus();
	// TODO: Add your message handler code here
	
}

void CEagleViewView::OnEntireMap() 
{
	// TODO: Add your command handler code here
	CString mapname=m_mainmap.GetGeoSet();
	this->m_mainmap.SetGeoSet(mapname);
	this->m_mainmap.SetTitleText("");
}

void CEagleViewView::OnMapToolArrow() 
{
	// TODO: Add your command handler code here
	this->m_mainmap.SetCurrentTool(miArrowTool);
}

void CEagleViewView::OnZoomin() 
{
	// TODO: Add your command handler code here
	this->m_mainmap.SetCurrentTool(miZoomInTool);
}

void CEagleViewView::OnZoomout() 
{
	// TODO: Add your command handler code here
	this->m_mainmap.SetCurrentTool(miZoomOutTool);
}

void CEagleViewView::OnPan() 
{
	// TODO: Add your command handler code here
	this->m_mainmap.SetCurrentTool(miPanTool);
}

void CEagleViewView::OnMapToolCenter() 
{
	// TODO: Add your command handler code here
	this->m_mainmap.SetCurrentTool(miCenterTool);
}

void CEagleViewView::OnMapToolSelect() 
{
	// TODO: Add your command handler code here
	this->m_mainmap.SetCurrentTool(miSelectTool);
}

void CEagleViewView::OnMapToolRadiusselect() 
{
	// TODO: Add your command handler code here
	this->m_mainmap.SetCurrentTool(miRadiusSelectTool);
}

void CEagleViewView::OnMapToolRectangleselect() 
{
	// TODO: Add your command handler code here
	this->m_mainmap.SetCurrentTool(miRectSelectTool);
}

void CEagleViewView::OnMapProperties() 
{
	// TODO: Add your command handler code here
	this->m_mainmap.PropertyPage();
}

void CEagleViewView::OnMapLayercontrol() 
{
	// TODO: Add your command handler code here
	this->m_mainmap.GetLayers().LayersDlg();
}

void CEagleViewView::OnInfo() 
{
	// TODO: Add your command handler code here
	this->m_mainmap.SetCurrentTool(miLabelTool);
}

BOOL CEagleViewView::OnMouseMoveInMap(short button,short shift,OLE_XPOS_PIXELS x,OLE_YPOS_PIXELS y)
{
	double mapx;
	double mapy;
	float screenX = (float)x;
    float screenY = (float)y;
	CMainFrame* pfram=(CMainFrame*)AfxGetApp()->m_pMainWnd;
	m_mainmap.ConvertCoord(&screenX,&screenY,&mapx,&mapy,miScreenToMap);
	CString str1,str2;
	str1.Format("经度:%5f",mapx);
	str2.Format("纬度:%5f",mapy);
	CClientDC dc(this);
	CSize sz=dc.GetTextExtent(str1);
	pfram->m_wndStatusBar.SetPaneInfo(1,IDS_JINGDU,SBPS_NORMAL,sz.cx);
	pfram->m_wndStatusBar.SetPaneText(1,str1);
	pfram->m_wndStatusBar.SetPaneInfo(2,IDS_WEIDU,SBPS_NORMAL,sz.cx);
	pfram->m_wndStatusBar.SetPaneText(2,str2);
	return TRUE;
}

void CEagleViewView::OnLongthtest() 
{
	// TODO: Add your command handler code here
	m_mainmap.SetCurrentTool(MYTOOL_DISTANCE);
}

void CEagleViewView::OnPolyToolUsedMap(short ToolNum, long Flags, LPDISPATCH Points, BOOL bShift, BOOL bCtrl, BOOL FAR* EnableDefault)
{
	if(Flags==miPolyToolInProgress) 
	{
		if(ToolNum==MYTOOL_DISTANCE)
		{
			CMapXPoints pts;
			long n;
			long i;
			try{
				pts.AttachDispatch (Points, FALSE);
				double dDistanceTot=0.0;
				n=pts.GetCount ();
				for (i=1; i<n;i++)
				{
					CMapXPoint pt1=pts.Item(i);
					CMapXPoint pt2=pts.Item(i+1);
					double d=m_mainmap.Distance (pt1.GetX(),pt1.GetY(),pt2.GetX (),pt2.GetY ());
					dDistanceTot+=d;
				}
				CString str;
				str.Format ("总距离为:%f公里",dDistanceTot);
				((CMainFrame*)AfxGetMainWnd())->m_wndStatusBar.SetPaneText(0,str);
			}
			catch (COleDispatchException *e){
				e->ReportError ();
				e->Delete ();
			}
			catch (COleException *e){
				e->ReportError ();
				e->Delete ();
			}
		}
	}
}

void CEagleViewView::OnDataMaincity() 
{
	// TODO: Add your command handler code here
	CDialogMain dlgm;
	dlgm.DoModal();
}

void CEagleViewView::OnDataNormalcity() 
{
	// TODO: Add your command handler code here
	CDialogNormalCity dlgn;
	dlgn.DoModal();
}

void CEagleViewView::OnDataRout() 
{
	// TODO: Add your command handler code here
	CDialogRout dlgr;
	dlgr.DoModal();
}

void CEagleViewView::OnDemo() 
{
	// TODO: Add your command handler code here
	m_Demo.DoModal();
}

void CEagleViewView::OnStart() 
{
	// TODO: Add your command handler code here
	
	TimerID=SetTimer(2,2000,NULL);
	CMainFrame* pfram=(CMainFrame*)AfxGetApp()->m_pMainWnd;
	pfram->m_Enabled=FALSE;
	CString strNum;
	strNum.Format("%d",TNum);
	
	_RecordsetPtr m_pRecord0;
	_ConnectionPtr m_pConnect0;
	m_pRecord0.CreateInstance("ADODB.Recordset");
	HRESULT hr;
	try
	{
		hr = m_pConnect0.CreateInstance("ADODB.Connection");
		if(SUCCEEDED(hr))
		{
			hr = m_pConnect0->Open("driver=SQL Server;Server=.;DATABASE=MapXDB;UID=sa;PWD=;","","",adModeUnknown);
		}
	}catch(_com_error e)
	{
		CString errormessage;
		errormessage.Format("连接数据库失败!\r\n错误信息:%s",e.ErrorMessage());
		AfxMessageBox(errormessage);
	}
	_bstr_t strSQL1="select * from 短信";
	_bstr_t strSQL2="create table 轨迹"+strNum+"(路段号 int NOT NULL PRIMARY KEY,起点 nvarchar(255) NOT NULL,终点 nvarchar(255) NOT NULL)";
	_bstr_t strSQL3="insert 轨迹 values('"+strNum+"')";
	m_pRecord0->Open(strSQL1,_variant_t((IDispatch *)m_pConnect0,true),adOpenStatic,adLockOptimistic,adCmdText);
	m_pConnect0->Execute(strSQL2,NULL,adCmdText);
	m_pConnect0->Execute(strSQL3,NULL,adCmdText);
	RecordCount=m_pRecord0->GetRecordCount();
	m_pRecord0->Close();
	m_pConnect0->Close();
}

void CEagleViewView::OnStop() 
{
	// TODO: Add your command handler code here
	CMainFrame* pfram=(CMainFrame*)AfxGetApp()->m_pMainWnd;
	pfram->m_Enabled=TRUE;
	if(TimerID==0)
		return;
	else
		KillTimer(TimerID);
	m_T=FALSE;

	TNum++;

	CMainFrame *pFram=(CMainFrame *)AfxGetApp()->m_pMainWnd;//获取框架类指针
	CInfoWnd  *pInfoView=(CInfoWnd* )pFram->m_SplitterV.GetPane(0,0);

	CMapXLayer layerR=this->m_mainmap.GetLayers().Item("铁路网");
	CMapXLayer layerM=this->m_mainmap.GetLayers().Item("省会");
	CMapXLayer layerN=this->m_mainmap.GetLayers().Item("一般城市");

	layerR.GetSelection().ClearSelection();
	layerM.GetSelection().ClearSelection();
	layerN.GetSelection().ClearSelection();

	pInfoView->m_TrianNum="";
	pInfoView->m_PointStart="";
	pInfoView->m_RoutStart="";
	pInfoView->m_RoutEnd="";
	pInfoView->UpdateData(FALSE);
}

void CEagleViewView::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	m_DataPoint1="";
	m_DataPoint2="";
	CMainFrame *pFram=(CMainFrame *)AfxGetApp()->m_pMainWnd;//获取框架类指针
	CInfoWnd  *pInfoView=(CInfoWnd* )pFram->m_SplitterV.GetPane(0,0);

	CMapXLayer layerR=this->m_mainmap.GetLayers().Item("铁路网");
	CMapXLayer layerM=this->m_mainmap.GetLayers().Item("省会");
	CMapXLayer layerN=this->m_mainmap.GetLayers().Item("一般城市");

	_RecordsetPtr m_pRecord0;
	_ConnectionPtr m_pConnect0;
	m_pRecord0.CreateInstance("ADODB.Recordset");
	HRESULT hr;
	try
	{
		hr = m_pConnect0.CreateInstance("ADODB.Connection");
		if(SUCCEEDED(hr))
		{
			hr = m_pConnect0->Open("driver=SQL Server;Server=.;DATABASE=MapXDB;UID=sa;PWD=;","","",adModeUnknown);
		}
	}catch(_com_error e)
	{
		CString errormessage;
		errormessage.Format("连接数据库失败!\r\n错误信息:%s",e.ErrorMessage());
		AfxMessageBox(errormessage);
	}
	_variant_t strSQL="select * from 短信";
	m_pRecord0->Open(strSQL,_variant_t((IDispatch *)m_pConnect0,true),adOpenStatic,adLockOptimistic,adCmdText);
	
	if(m_pRecord0->GetRecordCount()==RecordCount)
		return;
	RecordCount=m_pRecord0->GetRecordCount();
	m_pRecord0->MoveLast();
	Context=m_pRecord0->GetCollect("短信内容").bstrVal;
	m_pRecord0->Close();
	//处理函数//

	if(!m_T)//列车信息
	{
		m_T=TRUE;
		int m;
		for(m=0;m<Context.GetLength();m++)
		{
			if(Context.GetAt(m)==',')
			{
				m++;
				break;
			}	
			m_DataPoint1+=Context.GetAt(m);
		}
		for(;m<Context.GetLength();m++)
			m_DataPoint2+=Context.GetAt(m);

		_ConnectionPtr m_pConnection;//连接
		_RecordsetPtr m_pRecordset;//结果记录集

		HRESULT hr;
		try
		{
			hr = m_pConnection.CreateInstance("ADODB.Connection");
			if(SUCCEEDED(hr))
			{
				hr = m_pConnection->Open("driver=SQL Server;Server=.;DATABASE=MapXDB;UID=sa;PWD=;","","",adModeUnknown);
			}
		}catch(_com_error e)
		{
			CString errormessage;
			errormessage.Format("连接数据库失败!\r\n错误信息:%s",e.ErrorMessage());
			AfxMessageBox(errormessage);
		}
	
		_variant_t strSQL0="select 城市号 from CityNum where 城市名 = '"+m_DataPoint2+"'";
		m_pRecordset.CreateInstance("ADODB.Recordset");
		m_pRecordset->Open(strSQL0,_variant_t((IDispatch *)m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);
		if(m_pRecordset->GetRecordCount()==0)
		{
			MessageBox("没有这样的省会或一般城市!");
			return;
		}
		int i=m_pRecordset->GetCollect("城市号").intVal;
			
		m_pRecordset->Close();
		m_pConnection->Close();

		if(i>=300)
		{
			CString strNum;
			strNum.Format("%d",i-300);
			CMapXLayer layer=this->m_mainmap.GetLayers().Item("省会");
			if(layer.GetFind().Search(strNum).GetCenterX()==0&&layer.GetFind().Search(strNum).GetCenterY()==0)
			{
				MessageBox("不存在这样的省会!");
				return;
			}
			else
			{
				this->m_mainmap.ZoomTo(1000,layer.GetFind().Search(strNum).GetCenterX(),layer.GetFind().Search(strNum).GetCenterY());
				layer.GetSelection().Add(layer.GetFind().Search(strNum));
			}
		}
		else//一般城市
		{
			CString strNum;
			strNum.Format("%d",i);
			CMapXLayer layer=this->m_mainmap.GetLayers().Item("一般城市");
			if(layer.GetFind().Search(strNum).GetCenterX()==0&&layer.GetFind().Search(strNum).GetCenterY()==0)
			{
				MessageBox("不存在这样的一般城市!");
				return;
			}
			else
			{
				this->m_mainmap.ZoomTo(1000,layer.GetFind().Search(strNum).GetCenterX(),layer.GetFind().Search(strNum).GetCenterY());
				layer.GetSelection().Add(layer.GetFind().Search(strNum));
			}
		}
		m_DataPoint=m_DataPoint2;
		pInfoView->m_TrianNum=m_DataPoint1;
		pInfoView->m_PointStart=m_DataPoint2;
	}
	else//路段信息
	{
		int m;
		for(m=0;m<Context.GetLength();m++)
		{
			if(Context.GetAt(m)==',')
			{
				m++;
				break;
			}
				
			m_DataPoint1+=Context.GetAt(m);
		}
		for(;m<Context.GetLength();m++)
			m_DataPoint2+=Context.GetAt(m);
		if(m_DataPoint1!=m_DataPoint)
		{
			MessageBox("站点不可达!");
			return;
		}
		else
		{
			_ConnectionPtr m_pConnection;
			_RecordsetPtr m_pRecordset1;
			m_pRecordset1.CreateInstance("ADODB.Recordset");
			_RecordsetPtr m_pRecordset2;
			m_pRecordset2.CreateInstance("ADODB.Recordset");
			_RecordsetPtr m_pRecordset;
			m_pRecordset.CreateInstance("ADODB.Recordset");
			_RecordsetPtr m_pRecordset01;
			m_pRecordset01.CreateInstance("ADODB.Recordset");
			_RecordsetPtr m_pRecordset02;
			m_pRecordset02.CreateInstance("ADODB.Recordset");

			HRESULT hr;
			try
			{
				hr = m_pConnection.CreateInstance("ADODB.Connection");
				if(SUCCEEDED(hr))
				{
					hr = m_pConnection->Open("driver=SQL Server;Server=.;DATABASE=MapXDB;UID=sa;PWD=;","","",adModeUnknown);
				}
			}catch(_com_error e)
			{
				CString errormessage;
				errormessage.Format("连接数据库失败!\r\n错误信息:%s",e.ErrorMessage());
				AfxMessageBox(errormessage);
			}
			_variant_t strSQL1="SELECT 路段号 FROM RoutInfo where 路段起点='"+m_DataPoint1+"'and 路段终点 ='"+m_DataPoint2+"'";
			_variant_t strSQL2="SELECT 路段号 FROM RoutInfo where 路段起点='"+m_DataPoint2+"'and 路段终点 ='"+m_DataPoint1+"'";
			m_pRecordset1->Open(strSQL1,_variant_t((IDispatch *)m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);
			m_pRecordset2->Open(strSQL2,_variant_t((IDispatch *)m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);
			if(m_pRecordset1->GetRecordCount()==0&&m_pRecordset2->GetRecordCount()==0)
			{
				MessageBox("站点不可达!");
				return;
			}

			m_DataPoint=m_DataPoint2;
			_variant_t strT0="select 城市号 from CityNum where 城市名 = '"+m_DataPoint2+"'";
			m_pRecordset->Open(strT0,_variant_t((IDispatch *)m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);
			int i=m_pRecordset->GetCollect("城市号").intVal;

			_variant_t strT01="select 城市号 from CityNum where 城市名 = '"+m_DataPoint1+"'";
			_variant_t strT02="select 城市号 from CityNum where 城市名 = '"+m_DataPoint2+"'";
			m_pRecordset01->Open(strT01,_variant_t((IDispatch *)m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);
			m_pRecordset02->Open(strT02,_variant_t((IDispatch *)m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);
			int Num1=m_pRecordset01->GetCollect("城市号").intVal;
			int Num2=m_pRecordset02->GetCollect("城市号").intVal;

			if(Num1>=300)
			{
				if(Num2>=300)
				{
					CString strNum1,strNum2;
					strNum1.Format("%d",Num1-300);
					strNum2.Format("%d",Num2-300);

					this->m_mainmap.ZoomTo(1000,layerM.GetFind().Search(strNum1).GetCenterX(),layerM.GetFind().Search(strNum1).GetCenterY());
					layerM.GetSelection().Add(layerM.GetFind().Search(strNum1));
					layerM.GetSelection().Add(layerM.GetFind().Search(strNum2));
				}
				else
				{
					CString strNum1,strNum2;
					strNum1.Format("%d",Num1-300);
					strNum2.Format("%d",Num2);

					this->m_mainmap.ZoomTo(1000,layerM.GetFind().Search(strNum1).GetCenterX(),layerM.GetFind().Search(strNum1).GetCenterY());
					layerM.GetSelection().Add(layerM.GetFind().Search(strNum1));
					layerN.GetSelection().Add(layerN.GetFind().Search(strNum2));
				}
					
			}
			else
			{
				if(Num2>=300)
				{
					CString strNum1,strNum2;
					strNum1.Format("%d",Num1);
					strNum2.Format("%d",Num2-300);

					this->m_mainmap.ZoomTo(1000,layerN.GetFind().Search(strNum1).GetCenterX(),layerN.GetFind().Search(strNum1).GetCenterY());
					layerN.GetSelection().Add(layerN.GetFind().Search(strNum1));
					layerM.GetSelection().Add(layerM.GetFind().Search(strNum2));
				}
				else
				{
					CString strNum1,strNum2;
					strNum1.Format("%d",Num1);
					strNum2.Format("%d",Num2);

					this->m_mainmap.ZoomTo(1000,layerN.GetFind().Search(strNum1).GetCenterX(),layerN.GetFind().Search(strNum1).GetCenterY());
					layerN.GetSelection().Add(layerN.GetFind().Search(strNum1));
					layerN.GetSelection().Add(layerN.GetFind().Search(strNum2));
				}
			}
			//选中路段
			CString strRout;
			if(m_pRecordset1->GetRecordCount()!=0)
			{
					
				strRout=m_pRecordset1->GetCollect("路段号").bstrVal;
				layerR.GetSelection().Add(layerR.GetFind().Search(strRout));
			}
			else
			{
				strRout=m_pRecordset2->GetCollect("路段号").bstrVal;
				layerR.GetSelection().Add(layerR.GetFind().Search(strRout));
			}

			CString strNum;
			strNum.Format("%d",TNum);
			CString strNum1;
			strNum1.Format("%d",m_Num++);
			
			_bstr_t strSQL="insert 轨迹"+strNum+" values ("+strNum1+",'"+m_DataPoint1+"','"+m_DataPoint2+"')";
			
			m_pConnection->Execute(strSQL,NULL,adCmdText);

			m_pRecordset02->Close();
			m_pRecordset01->Close();
			m_pRecordset->Close();
			m_pRecordset2->Close();
			m_pRecordset1->Close();
			m_pConnection->Close();
		}

		pInfoView->m_RoutStart=m_DataPoint1;
		pInfoView->m_RoutEnd=m_DataPoint2;
	}
	pInfoView->UpdateData(FALSE);

	CView::OnTimer(nIDEvent);
}

void CEagleViewView::OnDisplay() 
{
	// TODO: Add your command handler code here
	CDialogDisplay disp;
	disp.DoModal();
}