📄 mttestdlg.cpp
字号:
// MTTestDlg.cpp : implementation file
//
#include "stdafx.h"
#include "MTTest.h"
#include "MTTestDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
int CMTTestDlg::m_nSeq = 0;
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMTTestDlg dialog
CMTTestDlg::CMTTestDlg(CWnd* pParent /*=NULL*/)
: CDialog(CMTTestDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CMTTestDlg)
m_strSucIP = _T("127.0.0.1");
m_nPort = 6001;
m_strUserID = _T("000000000");
m_strPWD = _T("1234");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CMTTestDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMTTestDlg)
DDX_Control(pDX, IDC_LIST2, m_ctrlPosList);
DDX_Control(pDX, IDC_TREE1, m_ctrlCarTree);
DDX_Text(pDX, IDC_IP, m_strSucIP);
DDX_Text(pDX, IDC_PORT, m_nPort);
DDX_Text(pDX, IDC_USERID, m_strUserID);
DDX_Text(pDX, IDC_PWD, m_strPWD);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CMTTestDlg, CDialog)
//{{AFX_MSG_MAP(CMTTestDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_LOGON, OnLogon)
ON_BN_CLICKED(IDC_GETDATA, OnGetdata)
ON_BN_CLICKED(IDC_CALL, OnCall)
ON_BN_CLICKED(IDC_HISTORYLIST, OnHistorylist)
ON_WM_TIMER()
ON_BN_CLICKED(IDC_CLEAR, OnClear)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMTTestDlg message handlers
BOOL CMTTestDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
CoInitialize(NULL);
if (!AfxSocketInit())
{
AfxMessageBox(IDP_SOCKETS_INIT_FAILED);
return FALSE;
}
this->SetTimer(1, 30000, NULL);
m_LinkSocket.SetOwner(this);
m_ctrlPosList.SetExtendedStyle(LVS_EX_GRIDLINES|LVS_EX_FULLROWSELECT);
m_ctrlPosList.InsertColumn(0,"SID",LVCFMT_LEFT,60);
m_ctrlPosList.InsertColumn(1,"经度",LVCFMT_LEFT,80);
m_ctrlPosList.InsertColumn(2,"纬度",LVCFMT_LEFT,80);
m_ctrlPosList.InsertColumn(3,"速度",LVCFMT_LEFT,50);
m_ctrlPosList.InsertColumn(4,"方向",LVCFMT_LEFT,40);
m_ctrlPosList.InsertColumn(5,"时间",LVCFMT_LEFT,110);
m_ctrlPosList.InsertColumn(6,"状态",LVCFMT_LEFT,40);
HRESULT hr;
try {
hr = m_pConn.CreateInstance(__uuidof(Connection));
if (SUCCEEDED(hr)) {
m_pConn->Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=mtdb.mdb", "", "", -1);
}
}
catch(_com_error& e) {
MessageBox(_T("数据库初始化错误:") + e.Description());
return FALSE;
}
catch(...){
MessageBox(_T("数据库初始化未知错误"));
return FALSE;
}
return TRUE; // return TRUE unless you set the focus to a control
}
void CMTTestDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CMTTestDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CMTTestDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
//连接到SUC,然后发送登录数据包
void CMTTestDlg::OnLogon()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
m_LinkSocket.Close();
m_bLinked = FALSE;
m_bLogon = FALSE;
//与SUC建立TCP连接
m_LinkSocket.Create();
if(m_LinkSocket.Connect(m_strSucIP, m_nPort) == FALSE)
{
m_bLinked = FALSE;
MessageBox("连接SUC失败,请检查连接参数!");
return;
}
else
{
m_bLinked = TRUE;
MessageBox("连接SUC成功!");
}
//合成登录数据包
CString strXML;
strXML = GetLogonXML();
//发送登录信息
m_LinkSocket.Send(strXML.LockBuffer(), strXML.GetLength());
}
////发送数据同步请求
void CMTTestDlg::OnGetdata()
{
// TODO: Add your control notification handler code here
if(m_bLogon == FALSE)
{
MessageBox("请先登录!");
return;
}
//合成数据同步请求包
CString strXML;
strXML = GetDataXML();
//发送数据同步请求包
m_LinkSocket.Send(strXML.LockBuffer(), strXML.GetLength());
}
//呼叫车辆
void CMTTestDlg::OnCall()
{
// TODO: Add your control notification handler code here
if(m_bLogon == FALSE)
{
MessageBox("请先登录!");
return;
}
CString strSID, strVTType;
//获取车辆列表中选中的车辆的SID和终端类型
if(GetSelVehicle(strSID, strVTType) == FALSE)
{
MessageBox("请先选择需要控制的车辆!");
return;
}
//根据被控车辆的SID和终端类型合成点名数据包
CString strXML;
strXML = GetCallXML(strSID, strVTType);
//MessageBox(strXML);
//发送点名数据包
m_LinkSocket.Send(strXML.LockBuffer(), strXML.GetLength());
}
//显示某量车的所有历史记录
void CMTTestDlg::OnHistorylist()
{
// TODO: Add your control notification handler code here
CString str;
HTREEITEM th, thp;
th = m_ctrlCarTree.GetSelectedItem();
if(th == NULL)
{
MessageBox("请先选择车辆!");
return;
}
//获得选中车辆的SID
thp = m_ctrlCarTree.GetParentItem(th);
if(thp != NULL)
{
th = thp;
}
CString strSID = m_ctrlCarTree.GetItemText(th);
//在历史记录表中查询SID等于选中车辆的SID的所有记录
_RecordsetPtr pRs("ADODB.Recordset");
CString strSQL;
strSQL = "SELECT * FROM history_gdata WHERE SID='" + strSID + "'";
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -