www.gusucode.com > 铁路列车车辆监控系统本系统要求PC机有两个串行通讯串口, > 铁路列车车辆监控系统本系统要求PC机有两个串行通讯串口,有线MODEM一个。其它配置没有严格的要求,一般配置即可。/铁路列车车辆监控系统/电子地图显示模块(江军)/EagleViewNew/DemoDialog.cpp
// DemoDialog.cpp : implementation file // #include "stdafx.h" #include "EagleView.h" #include "DemoDialog.h" #include "InfoWnd.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") ///////////////////////////////////////////////////////////////////////////// // CDemoDialog dialog CDemoDialog::CDemoDialog(CWnd* pParent /*=NULL*/) : CDialog(CDemoDialog::IDD, pParent) { m_T=FALSE; //{{AFX_DATA_INIT(CDemoDialog) m_PointStart = _T(""); m_Point1 = _T(""); m_Point2 = _T(""); m_TrianNum = _T(""); //}}AFX_DATA_INIT } void CDemoDialog::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CDemoDialog) DDX_Text(pDX, IDC_EDIT_POINT_START, m_PointStart); DDX_Text(pDX, IDC_EDIT_POINT1, m_Point1); DDX_Text(pDX, IDC_EDIT_POINT2, m_Point2); DDX_Text(pDX, IDC_EDIT_TRIANNUM, m_TrianNum); DDX_Control(pDX, IDC_ADODC_MESSAGE, m_Adodc); DDX_Control(pDX, IDC_DATAGRID1, m_DGrid); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CDemoDialog, CDialog) //{{AFX_MSG_MAP(CDemoDialog) ON_BN_CLICKED(IDOK, OnAdd) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CDemoDialog message handlers void CDemoDialog::OnCancel() { // TODO: Add extra cleanup here CMainFrame *pFram=(CMainFrame *)AfxGetApp()->m_pMainWnd;//获取框架类指针 CEagleViewView *pView=(CEagleViewView* )pFram->m_SplitterH.GetPane(0,0);//pView指向主视图 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(); _ConnectionPtr m_pConnection; 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); } _bstr_t strSQL="delete 短信"; m_pConnection->Execute(strSQL,NULL,adCmdText); m_pConnection->Close(); m_T=FALSE; CInfoWnd *pInfoView=(CInfoWnd* )pFram->m_SplitterV.GetPane(0,0); pInfoView->m_TrianNum=""; pInfoView->m_PointStart=""; pInfoView->m_RoutStart=""; pInfoView->m_RoutEnd=""; pInfoView->UpdateData(FALSE); CDialog::OnCancel(); } void CDemoDialog::OnAdd() { // 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);//pView指向主视图 CMapXLayer layerR=pView->m_mainmap.GetLayers().Item("铁路网"); CMapXLayer layerM=pView->m_mainmap.GetLayers().Item("省会"); CMapXLayer layerN=pView->m_mainmap.GetLayers().Item("一般城市"); if(m_PointStart.IsEmpty()||m_TrianNum.IsEmpty()) { MessageBox("请先输入列车信息!"); } else { if(!m_T) { _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_PointStart+"'"; 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; } SYSTEMTIME sys; GetLocalTime( &sys );//获取系统时间 CString strT; strT.Format("%4d/%02d/%02d %02d:%02d:%02d",sys.wYear,sys.wMonth,sys.wDay,sys.wHour,sys.wMinute,sys.wSecond); _bstr_t strSQL="insert 短信 values('"+strT+"','"+m_TrianNum+","+m_PointStart+"')"; m_pConnection->Execute(strSQL,NULL,adCmdText); int i=m_pRecordset->GetCollect("城市号").intVal; m_pRecordset->Close(); m_pConnection->Close(); if(i>=300) { CString strNum; strNum.Format("%d",i-300); CMapXLayer layer=pView->m_mainmap.GetLayers().Item("省会"); if(layer.GetFind().Search(strNum).GetCenterX()==0&&layer.GetFind().Search(strNum).GetCenterY()==0) { MessageBox("不存在这样的省会!"); } else { pView->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=pView->m_mainmap.GetLayers().Item("一般城市"); if(layer.GetFind().Search(strNum).GetCenterX()==0&&layer.GetFind().Search(strNum).GetCenterY()==0) { MessageBox("不存在这样的一般城市!"); } else { pView->m_mainmap.ZoomTo(1000,layer.GetFind().Search(strNum).GetCenterX(),layer.GetFind().Search(strNum).GetCenterY()); layer.GetSelection().Add(layer.GetFind().Search(strNum)); } } m_T=TRUE; m_Point=m_PointStart; } else { /*加入路段信息*/ if(m_Point1.IsEmpty()||m_Point2.IsEmpty()) { MessageBox("请先输入路段信息!"); return; } if(m_Point1!=m_Point) { 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_Point1+"'and 路段终点 ='"+m_Point2+"'"; _variant_t strSQL2="SELECT 路段号 FROM RoutInfo where 路段起点='"+m_Point2+"'and 路段终点 ='"+m_Point1+"'"; 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_Point=m_Point2; SYSTEMTIME sys; GetLocalTime( &sys ); CString strT; strT.Format("%4d/%02d/%02d %02d:%02d:%02d",sys.wYear,sys.wMonth,sys.wDay,sys.wHour,sys.wMinute,sys.wSecond); _bstr_t strSQL="insert 短信 values('"+strT+"','"+m_Point1+","+m_Point2+"')"; m_pConnection->Execute(strSQL,NULL,adCmdText); _variant_t strT0="select 城市号 from CityNum where 城市名 = '"+m_Point2+"'"; 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_Point1+"'"; _variant_t strT02="select 城市号 from CityNum where 城市名 = '"+m_Point2+"'"; 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); 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",Num1-300); strNum2.Format("%d",Num2); 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(Num2>=300) { CString strNum1,strNum2; strNum1.Format("%d",Num1); strNum2.Format("%d",Num2-300); 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",Num1); strNum2.Format("%d",Num2); 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)); } } //选中路段 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)); } m_pRecordset02->Close(); m_pRecordset01->Close(); m_pRecordset->Close(); m_pRecordset2->Close(); m_pRecordset1->Close(); m_pConnection->Close(); } } } m_Adodc.SetRecordSource("select * from 短信"); m_Adodc.Refresh(); //路段信息反映到InfoWnd中 CInfoWnd *pInfoView=(CInfoWnd* )pFram->m_SplitterV.GetPane(0,0); pInfoView->m_TrianNum=m_TrianNum; pInfoView->m_PointStart=m_PointStart; pInfoView->m_RoutStart=m_Point1; pInfoView->m_RoutEnd=m_Point2; pInfoView->UpdateData(FALSE); }