📄 nmsinfoconfig.cpp
字号:
// NMSInfoConfig.cpp : implementation file
//
#include "stdafx.h"
#include "..\nms.h"
#include "NMSInfoConfig.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern CBrush *g_pWhiteBrush; /* 背景颜色 */
/////////////////////////////////////////////////////////////////////////////
// CNMSInfoConfig dialog
static _TCHAR* g_szTestConnectLabel[]=
{
"子网",
"网元",
"测试结果",
"测试时间"
};
CNMSInfoConfig::CNMSInfoConfig(CWnd* pParent /*=NULL*/)
: CDialog(CNMSInfoConfig::IDD, pParent)
{
//{{AFX_DATA_INIT(CNMSInfoConfig)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
pNe = NULL;
m_pos = 0;
}
void CNMSInfoConfig::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CNMSInfoConfig)
// NOTE: the ClassWizard will add DDX and DDV calls here
DDX_Control(pDX, IDC_TEST_CONNECT_LIST, m_list);
DDX_Control(pDX, IDC_TEST_CONNECTION, m_TestConnect);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CNMSInfoConfig, CDialog)
//{{AFX_MSG_MAP(CNMSInfoConfig)
ON_MESSAGE(WM_HYPER_LINK , OnHttpLinkClick)
ON_MESSAGE(WM_QUERYCOMPELETE, OnMibQuerySet)
ON_WM_CTLCOLOR()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CNMSInfoConfig message handlers
/*-----------------------------------------------------------------*/
void CNMSInfoConfig::OnHttpLinkClick(WPARAM wParam, LPARAM lParam)
{
CString str;
if(IDC_TEST_CONNECTION == wParam)
{
if(!pApp->pThreadNMS)
{
AfxMessageBox("请首先启动网管!");
return;
}
TestConnect();
return ;
}
}
/*-----------------------------------------------------------------*/
void CNMSInfoConfig::NMSConfigSave()
{
CString str;
// CComboBox *pComBox=(CComboBox *)GetDlgItem(IDC_SNMP_SEND_IP);
GetDlgItem(IDC_NMS_CONFIG_PATH)->GetWindowText(str);
if(str.Compare(pApp->NmsConfigPath))
{
if( MessageConfirmBox("改变配置文件目录") == TRUE)
{
strcpy( pApp->NmsConfigPath , (char*)(LPCTSTR)str);
/*GetNmsConfigPath(pApp->NmsConfigPath , FALSE);*/
}
}
GetDlgItem(IDC_NMS_LOGFILE_PATH)->GetWindowText(str);
if(str.Compare(pApp->NmsLogFilePath))
{
if( MessageConfirmBox("改变LOG-FILE目录") == TRUE)
{
strcpy( pApp->NmsLogFilePath , (char*)(LPCTSTR)str);
/*GetNmsLogPath(pApp->NmsLogFilePath , FALSE);*/
str.Format("%s%s" , "产生目录" , pApp->NmsLogFilePath );
if(GetFileAttributes(pApp->NmsLogFilePath) == 0xFFFFFFFF)
{
if(MessageConfirmBox((char*)(LPCTSTR)str) == TRUE)
{
if(CreateDirectory(pApp->NmsLogFilePath , NULL) == FALSE)
{
MyMessageBox("创建目录失败!");
}
else
{
MyMessageBox("创建目录成功!");
}
}
}
}
}
return;
}
/*-----------------------------------------------------------------*/
void CNMSInfoConfig::TestConnect()
{
char buf[MAX_COMMON_LEN+1];
time_t itmp ;
if( (pNe == 0) &&(m_pos > 0))
{
sprintf(buf , "%d个网元查询完毕!" , m_pos);
AfxMessageBox(buf);
pNe=NULL;
m_pos=0;
return ;
}
if(pNe == 0)
{
pNe = pApp->pNeFirst;
m_list.DeleteAllItems();
}
if(pNe == 0)
{
return ;
}
/* 子网号 */
sprintf(buf , "%d" , (pNe->ne_id)>>16);
m_list.InsertItem(m_pos , buf);
/* 网元号 */
sprintf(buf , "%d" , pNe->ne_id );
m_list.SetItemText(m_pos , 1 , buf);
/* 测试时间 */
time((time_t*)&itmp);
m_list.SetItemText(m_pos , 3 , ctime(&itmp));
sprintf(buf , "%s" , "请等待");
m_list.SetItemText(m_pos , 2 , buf);
/* 测试结果 */
int retcode = IsConnect(pNe) ;
m_pos++;
pNe = pNe->next;
if(retcode < 0)
{
m_list.SetItemText(m_pos-1 , 2 , "不可达-请稍后重试");
PostMessage(WM_HYPER_LINK , IDC_TEST_CONNECTION , 0);
}
}
/*-----------------------------------------------------------------*/
// 测试网元是否可达
int CNMSInfoConfig::IsConnect(CNe *pNe)
{
if(pNe == NULL)
{
return -1;
}
//1.3.6.1.2.1.1.1.0
QueryNMS sQueryNMS;
memset( &sQueryNMS , 0 , sizeof(QueryNMS));
/* 查询返回到本窗口 */
sQueryNMS.cb_func = 0;
sQueryNMS.hWnd = m_hWnd;
if(pApp->m_ProtocolUsed == PROTOCOL_SNMP)
{
/*
* Snmp Get -- Send Request Msg to Snmp Wnd(Thread NMS)
*/
/* Snmp Action Type */
sQueryNMS.query.snmp_query.action = ACTION_MIB_GET;
/* Target(子网) IP */
memcpy( sQueryNMS.query.snmp_query.gw_ip , pNe->gw_ip , MAX_IP_LEN);
/* Target(网元-再定位) No. */
sQueryNMS.query.snmp_query.listen_port = pNe->listen_port;
/* MIB OID */
strcpy( sQueryNMS.query.snmp_query.oid , "1.3.6.1.2.1.1.1.0");
/* 查询序列 */
sQueryNMS.query.snmp_query.dSequence = pNe->ne_id;
}
else
{
/*
* CMD Protocol
*/
memcpy(sQueryNMS.query.cmd_query.gw_ip , pNe->gw_ip , MAX_IP_LEN);
sQueryNMS.query.cmd_query.listen_port = pNe->listen_port;
sQueryNMS.query.cmd_query.cmd_type = CMD_GET_COPYRIGHT;
sQueryNMS.query.cmd_query.cmd_len = 0;
}
if(pApp->pThreadNMS)
{
/* Send Request Msg */
if( pApp->pThreadNMS->m_pNMSWnd->Query(&sQueryNMS) < 0)
{
return -1;
}
return 0;
}
return -1;
}
/*-----------------------------------------------------------------*/
LRESULT CNMSInfoConfig::OnMibQuerySet(WPARAM wParam, LPARAM lParam)
{
AnswerQuery_S sAnSwerQuery = *(PAnswerQuery_S)lParam;
BOOL bConnect=FALSE;
char szItemNEID[MAX_IP_LEN+1];
LVITEM lvItem;
if(m_pos < 0)
{
return true;
}
lvItem.mask = LVIF_TEXT;
lvItem.iSubItem = 1; // NEID
lvItem.iItem = m_pos-1;
lvItem.pszText = szItemNEID;
lvItem.cchTextMax = MAX_IP_LEN;
m_list.GetItem(&lvItem);
if( (pApp->m_ProtocolUsed == PROTOCOL_SNMP) &&
(sAnSwerQuery.snmp.error == 0) )
{
bConnect = TRUE;
}
else if( (pApp->m_ProtocolUsed == PROTOCOL_NOT_SNMP) &&
(sAnSwerQuery.cmd.cmd_type != CMD_ERROR) )
{
bConnect = TRUE;
}
if(bConnect == TRUE)
{
sprintf(szItemNEID , "测试联接成功");
}
else
{
sprintf(szItemNEID , "测试联接失败");
}
m_list.SetItemText(m_pos-1 , 2 , szItemNEID);
PostMessage(WM_HYPER_LINK , IDC_TEST_CONNECTION , 0);
return true;
}
/*-----------------------------------------------------------------*/
BOOL CNMSInfoConfig::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
GetDlgItem(IDC_NMS_CONFIG_PATH)->SetWindowText(pApp->NmsConfigPath);
GetDlgItem(IDC_NMS_LOGFILE_PATH)->SetWindowText(pApp->NmsLogFilePath);
m_TestConnect.SetFireChild(1);
m_list.ModifyStyle(0 , /*LVS_EDITLABELS |*/ LVS_REPORT , 0);
m_list.SetExtendedStyle(m_list.GetExtendedStyle()|LVS_EX_GRIDLINES|LVS_EX_FULLROWSELECT);
m_list.InsertColumn(0,g_szTestConnectLabel[0],LVCFMT_LEFT,50,0);
m_list.InsertColumn(1,g_szTestConnectLabel[1],LVCFMT_LEFT,80,1);
m_list.InsertColumn(2,g_szTestConnectLabel[2],LVCFMT_LEFT,80,2);
m_list.InsertColumn(3,g_szTestConnectLabel[3],LVCFMT_LEFT,80,3);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
/*-----------------------------------------------------------------*/
HBRUSH CNMSInfoConfig::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
pDC->SetBkMode(TRANSPARENT);
return (HBRUSH)g_pWhiteBrush->m_hObject;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -