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

📄 dialogrout.cpp

📁 铁路列车车辆监控系统本系统要求PC机有两个串行通讯串口
💻 CPP
字号:
// DialogRout.cpp : implementation file
//

#include "stdafx.h"
#include "EagleView.h"
#include "DialogRout.h"
#include "MainFrm.h"
#include "EagleViewView.h"

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

#import "C:\Program Files\Common Files\System\ado\msado15.dll" no_namespace rename("EOF","adoEOF")

/////////////////////////////////////////////////////////////////////////////
// CDialogRout dialog


CDialogRout::CDialogRout(CWnd* pParent /*=NULL*/)
	: CDialog(CDialogRout::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDialogRout)
	m_RoutEnd = _T("");
	m_RoutStart = _T("");
	//}}AFX_DATA_INIT
}


void CDialogRout::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDialogRout)
	DDX_Control(pDX, IDC_ADODC_ROUT, m_RoutAdodc);
	DDX_Text(pDX, IDC_EDIT_ROUT_END, m_RoutEnd);
	DDX_Text(pDX, IDC_EDIT_ROUT_START, m_RoutStart);
	DDX_Control(pDX, IDC_DATAGRID_ROUT, m_DGrid);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDialogRout, CDialog)
	//{{AFX_MSG_MAP(CDialogRout)
	ON_BN_CLICKED(IDC_BUTTON_EXIT, OnButtonExit)
	ON_BN_CLICKED(IDC_BUTTON_ROUT, OnButtonRout)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDialogRout message handlers

void CDialogRout::OnButtonExit() 
{
	// TODO: Add your control notification handler code here
	CMainFrame *pFram=(CMainFrame *)AfxGetApp()->m_pMainWnd;
	CEagleViewView  *pView=(CEagleViewView* )pFram->m_SplitterH.GetPane(0,0);
	CMapXLayer layerR=pView->m_mainmap.GetLayers().Item("铁路网");
	CMapXLayer layerM=pView->m_mainmap.GetLayers().Item("省会");
	CMapXLayer layerN=pView->m_mainmap.GetLayers().Item("一般城市");
	layerR.GetSelection().ClearSelection();
	layerM.GetSelection().ClearSelection();
	layerN.GetSelection().ClearSelection();
	CDialog::OnCancel();
}

void CDialogRout::OnButtonRout() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	CMainFrame *pFram=(CMainFrame *)AfxGetApp()->m_pMainWnd;
	CEagleViewView  *pView=(CEagleViewView* )pFram->m_SplitterH.GetPane(0,0);

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

	if(m_RoutStart.IsEmpty()&&m_RoutEnd.IsEmpty())
	{
		MessageBox("至少输入一个查询项!");
	}
	else
	{
		if(m_RoutStart.IsEmpty())
		{
			_ConnectionPtr m_pConnection;
			_RecordsetPtr m_pRecordset;
			m_pRecordset.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 strSQL="select 城市号 from CItyNum where 城市名 ='"+m_RoutEnd+"'";
			m_pRecordset->Open(strSQL,_variant_t((IDispatch *)m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);
			int i=m_pRecordset->GetCollect("城市号").intVal;
			m_pRecordset->Close();
			m_pConnection->Close();
			CString str;
			str.Format("%d",i);
			if(i>=300)
			{
				CString strSQL="select * from XMRoutInfo where 路段终点 = '"+m_RoutEnd+"'";
				m_RoutAdodc.SetRecordSource(strSQL);
				m_RoutAdodc.Refresh();
				
				CString strNum;
				strNum.Format("%d",i-300);
				pView->m_mainmap.ZoomTo(1000,layerM.GetFind().Search(strNum).GetCenterX(),layerM.GetFind().Search(strNum).GetCenterY());
				layerM.GetSelection().Add(layerM.GetFind().Search(strNum));
				int row=m_DGrid.GetApproxCount();
				for(int count=0;count<row;count++)
				{
					////////主视图中选中每行对应的图元//////////
					m_DGrid.SetRow(count);
					m_DGrid.SetCol(0);
					layerR.GetSelection().Add(layerR.GetFind().Search(m_DGrid.GetText()));
				}
			}
			else//一般城市
			{
				CString strSQL="select * from XNRoutInfo where 路段终点 = '"+m_RoutEnd+"'";
				m_RoutAdodc.SetRecordSource(strSQL);
				m_RoutAdodc.Refresh();
				
				CString strNum;
				strNum.Format("%d",i);
				pView->m_mainmap.ZoomTo(1000,layerN.GetFind().Search(strNum).GetCenterX(),layerN.GetFind().Search(strNum).GetCenterY());
				layerN.GetSelection().Add(layerN.GetFind().Search(strNum));
				int row=m_DGrid.GetApproxCount();
				for(int count=0;count<row;count++)
				{
					////////主视图中选中每行对应的图元//////////
					m_DGrid.SetRow(count);
					m_DGrid.SetCol(0);
					layerR.GetSelection().Add(layerR.GetFind().Search(m_DGrid.GetText()));
				}
			}
		}
		else
			if(m_RoutEnd.IsEmpty())
			{
				_ConnectionPtr m_pConnection;
				_RecordsetPtr m_pRecordset;
				m_pRecordset.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 strSQL="select 城市号 from CItyNum where 城市名 ='"+m_RoutStart+"'";
				m_pRecordset->Open(strSQL,_variant_t((IDispatch *)m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);
				int i=m_pRecordset->GetCollect("城市号").intVal;
				m_pRecordset->Close();
				m_pConnection->Close();
				CString str;
				str.Format("%d",i);
				if(i>=300)
				{
					CString strSQL="select * from MXRoutInfo where 路段起点 = '"+m_RoutStart+"'";
					m_RoutAdodc.SetRecordSource(strSQL);
					m_RoutAdodc.Refresh();

					CString strNum;
					strNum.Format("%d",i-300);
					pView->m_mainmap.ZoomTo(1000,layerM.GetFind().Search(strNum).GetCenterX(),layerM.GetFind().Search(strNum).GetCenterY());
					layerM.GetSelection().Add(layerM.GetFind().Search(strNum));
					int row=m_DGrid.GetApproxCount();
					for(int count=0;count<row;count++)
					{
						////////主视图中选中每行对应的图元//////////
						m_DGrid.SetRow(count);
						m_DGrid.SetCol(0);
						layerR.GetSelection().Add(layerR.GetFind().Search(m_DGrid.GetText()));
					}
				}
				else
				{
					CString strSQL="select * from NXRoutInfo where 路段起点 = '"+m_RoutStart+"'";
					m_RoutAdodc.SetRecordSource(strSQL);
					m_RoutAdodc.Refresh();

					CString strNum;
					strNum.Format("%d",i);
					pView->m_mainmap.ZoomTo(1000,layerN.GetFind().Search(strNum).GetCenterX(),layerN.GetFind().Search(strNum).GetCenterY());
					layerN.GetSelection().Add(layerN.GetFind().Search(strNum));
					int row=m_DGrid.GetApproxCount();
					for(int count=0;count<row;count++)
					{
						////////主视图中选中每行对应的图元//////////
						m_DGrid.SetRow(count);
						m_DGrid.SetCol(0);
						layerR.GetSelection().Add(layerR.GetFind().Search(m_DGrid.GetText()));
					}
				}
			}
			else
			{
				_ConnectionPtr m_pConnection;
				_RecordsetPtr m_pRecordset1;
				m_pRecordset1.CreateInstance("ADODB.Recordset");
				_RecordsetPtr m_pRecordset2;
				m_pRecordset2.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 CItyNum where 城市名 ='"+m_RoutStart+"'";
				_variant_t strSQL2="select 城市号 from CItyNum where 城市名 ='"+m_RoutEnd+"'";
				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);
				int i=m_pRecordset1->GetCollect("城市号").intVal;
				int j=m_pRecordset2->GetCollect("城市号").intVal;
				m_pRecordset1->Close();
				m_pRecordset2->Close();
				m_pConnection->Close();
				if(i>=300)
				{
					if(j>=300)
					{
						CString strNum1,strNum2;
						strNum1.Format("%d",i-300);
						strNum2.Format("%d",j-300);
						CString strSQL="select * from MMRoutInfo where 路段起点 = '"+m_RoutStart+"' and 路段终点 ='"+m_RoutEnd+"'";
						m_RoutAdodc.SetRecordSource(strSQL);
						m_RoutAdodc.Refresh();

						pView->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",i-300);
						strNum2.Format("%d",j);
						CString strSQL="select * from MNRoutInfo where 路段起点 = '"+m_RoutStart+"' and 路段终点 ='"+m_RoutEnd+"'";
						m_RoutAdodc.SetRecordSource(strSQL);
						m_RoutAdodc.Refresh();

						pView->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(j>=300)
					{
						CString strNum1,strNum2;
						strNum1.Format("%d",i);
						strNum2.Format("%d",j-300);

						CString strSQL="select * from NMRoutInfo where 路段起点 = '"+m_RoutStart+"' and 路段终点 ='"+m_RoutEnd+"'";
						m_RoutAdodc.SetRecordSource(strSQL);
						m_RoutAdodc.Refresh();

						pView->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",i);
						strNum2.Format("%d",j);

						CString strSQL="select * from NNRoutInfo where 路段起点 = '"+m_RoutStart+"' and 路段终点 ='"+m_RoutEnd+"'";
						m_RoutAdodc.SetRecordSource(strSQL);
						m_RoutAdodc.Refresh();

						pView->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));
					}
				}
				//选中路段
				if(m_DGrid.GetApproxCount()==0)
					return;
				m_DGrid.SetRow(0);
				m_DGrid.SetCol(0);
				layerR.GetSelection().Add(layerR.GetFind().Search(m_DGrid.GetText()));
			}
	}
}

⌨️ 快捷键说明

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