?? 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);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -