采用snmp协议 监控交换机(d-link)实现

//头文件

 

// NetworkMonitorView.h : interface of the CNetworkMonitorView class
//
/

#if !defined(AFX_NETWORKMONITORVIEW_H__39998FA7_50E2_4D0D_86F3_414B184C444F__INCLUDED_)
#define AFX_NETWORKMONITORVIEW_H__39998FA7_50E2_4D0D_86F3_414B184C444F__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "BtnST.h"
#include "Winsnmp.h"

typedef struct _s{
 int nPort ;
 COleDateTimeSpan Datetime ;
 CString sRoom ;
}PORTINFO;

// "房间号","上网时间","流量","单价/时","总价"} ;
typedef struct _n{
 CString sRoom ;
 CString sTimeOnline ;
 CString sLL ;
 CString sDJ ;
 CString sZJ ;
}NONEVALUE;

class CNetworkMonitorView : public CFormView
{
protected: // create from serialization only
 CNetworkMonitorView();
 DECLARE_DYNCREATE(CNetworkMonitorView)

public:
 //{{AFX_DATA(CNetworkMonitorView)
 enum { IDD = IDD_NETWORKMONITOR_FORM };

 CWinXPButtonST m_Port9;
 CWinXPButtonST m_Port8;
 CWinXPButtonST m_Port7;
 CWinXPButtonST m_Port6;
 CWinXPButtonST m_Port5;
 CWinXPButtonST m_Port48;
 CWinXPButtonST m_Port47;
 CWinXPButtonST m_Port46;
 CWinXPButtonST m_Port45;
 CWinXPButtonST m_Port44;
 CWinXPButtonST m_Port43;
 CWinXPButtonST m_Port42;
 CWinXPButtonST m_Port41;
 CWinXPButtonST m_Port40;
 CWinXPButtonST m_Port4;
 CWinXPButtonST m_Port39;
 CWinXPButtonST m_Port38;
 CWinXPButtonST m_Port37;
 CWinXPButtonST m_Port34;
 CWinXPButtonST m_Port36;
 CWinXPButtonST m_Port35;
 CWinXPButtonST m_Port33;
 CWinXPButtonST m_Port32;
 CWinXPButtonST m_Port31;
 CWinXPButtonST m_Port30;
 CWinXPButtonST m_Port3;
 CWinXPButtonST m_Port29;
 CWinXPButtonST m_Port28;
 CWinXPButtonST m_Port27;
 CWinXPButtonST m_Port26;
 CWinXPButtonST m_Port25;
 CWinXPButtonST m_Port24;
 CWinXPButtonST m_Port23;
 CWinXPButtonST m_Port22;
 CWinXPButtonST m_Port21;
 CWinXPButtonST m_Port20;
 CWinXPButtonST m_Port2;
 CWinXPButtonST m_Port19;
 CWinXPButtonST m_Port18;
 CWinXPButtonST m_Port17;
 CWinXPButtonST m_Port16;
 CWinXPButtonST m_Port15;
 CWinXPButtonST m_Port14;
 CWinXPButtonST m_Port13;
 CWinXPButtonST m_Port12;
 CWinXPButtonST m_Port11;
 CWinXPButtonST m_Port10;
 CListCtrl m_ListCtrl;
 CWinXPButtonST m_Port1;
 //}}AFX_DATA

 
// Attributes
public:
 CNetworkMonitorDoc* GetDocument();
 CBrush m_BackgoundBrush;
 void InitivalPort() ;
 
 void ConnectionSwitch() ;
 void SetValue(CString sIP1, CString sIP2, CString sDJ, CString sFreq) ;
 
protected:

 static DWORD WINAPI ThreadProc(LPVOID lpParam) ;
 static DWORD WINAPI ThreadProc2(LPVOID lpParam) ;

 void UpdateRow(int nPort, CString sRomm, COleDateTimeSpan *pOleDateTime, int nLL ) ;

 BOOL Computer(CString sRoom, int nPort, PORTINFO **pPortInfo) ;
 void SaveNoneValue(CString sRomm, COleDateTimeSpan *pOleDateTime, int nLL) ;
 void LoadNoneValue() ;
 void ShowNoneValue() ;

private:

 BOOL m_b1 ;
 BOOL m_b2 ;

 int m_IndexItem ;
 static HANDLE m_ThreadHandle1 ;
 static HSNMP_ENTITY  m_hsrcAgent1;
 static HSNMP_CONTEXT m_hContext1;

 static HANDLE m_ThreadHandle2 ;
 static HSNMP_ENTITY  m_hsrcAgent2;
 static HSNMP_CONTEXT m_hContext2;

 static BOOL bIsFi ;
 static BOOL bIsFi2 ;

 int nListItemIndex ;
 float m_fDJ ;
 
 BOOL m_bIsFirst ;
 BOOL m_bISFirst2 ;
 
 BOOL m_bFerq;

 CString m_sDJ ;
 CString m_sIP1;
 CString m_sIP2 ;

 CString m_sFreq ;
 int m_nFreq ;

 CString m_sRoom ;
 

 int m_nFerq ;
 CArray<PORTINFO* ,PORTINFO*> m_PortInfo ;
 CArray<NONEVALUE* , NONEVALUE*> m_NoneValue ;
 BOOL m_bIsUpdate ;

// Operations
public:

// Overrides
 // ClassWizard generated virtual function overrides
 //{{AFX_VIRTUAL(CNetworkMonitorView)
 public:
 virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
 protected:
 
 virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
 virtual void OnInitialUpdate(); // called first time after construct
 virtual BOOL OnPreparePrinting(CPrintInfo* pInfo);
 virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo);
 virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo);
 virtual void OnPrint(CDC* pDC, CPrintInfo* pInfo);

 //}}AFX_VIRTUAL
 afx_msg void OnMessageBlock(UINT nID); 
// Implementation
public:
 virtual ~CNetworkMonitorView();
#ifdef _DEBUG
 virtual void AssertValid() const;
 virtual void Dump(CDumpContext& dc) const;
#endif

protected:

// Generated message map functions
protected:
 //{{AFX_MSG(CNetworkMonitorView)
 afx_msg void OnButtonPort19();
 afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor);
 afx_msg void OnSize(UINT nType, int cx, int cy);
 afx_msg void OnDestroy();
 afx_msg void OnTimer(UINT nIDEvent);
 afx_msg void OnRclickList1(NMHDR* pNMHDR, LRESULT* pResult);
 afx_msg void OnMenuJz();
 //}}AFX_MSG

 afx_msg void OnSanComplie(WPARAM wParam, LPARAM lParam);
 DECLARE_MESSAGE_MAP()
};

#ifndef _DEBUG  // debug version in NetworkMonitorView.cpp
inline CNetworkMonitorDoc* CNetworkMonitorView::GetDocument()
   { return (CNetworkMonitorDoc*)m_pDocument; }
#endif

/

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_NETWORKMONITORVIEW_H__39998FA7_50E2_4D0D_86F3_414B184C444F__INCLUDED_)

 

// 实现cpp

// NetworkMonitorView.cpp : implementation of the CNetworkMonitorView class
//

#include "stdafx.h"
#include "NetworkMonitor.h"

#include "NetworkMonitorDoc.h"
#include "NetworkMonitorView.h"

 

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

/
// CNetworkMonitorView


#define WM_SCANCOMPLIE    WM_USER+203

static LPCTSTR g_sIREventName = "NETMONITORZBJ" ;
static LPCTSTR g_sIREventName2 = "NETMONITORZBJ2" ;

CString      g_sValue1 ;
smiOID          g_Oid ;
char      g_buffer[40] ;
int    g_Counter = 0 ;
int    g_TimeCounter = 0 ;

CString      g_sValue2 ;
smiOID          g_Oid2 ;
char      g_buffer2[40] ;
int    g_Counter2 = 0 ;
int    g_TimeCounter2 = 0 ;


smiINT PortFlag[28] ;
smiINT PortTime[28] ;
smiINT PortFirstLL[28] ;

smiINT PortFlag2[28] ;
smiINT PortTime2[28] ;
smiINT PortFirstLL2[28] ;


SNMPAPI_STATUS CALLBACK mycall(
          HSNMP_SESSION hSession,  // handle to the WinSNMP session
          HWND hWnd,               // handle to the notification window
          UINT wMsg,               // window notification message number
          WPARAM wParam,           // type of notification
          LPARAM lParam,           // request identifier of PDU
          LPVOID lpClientData      // optional application-defined data
          ) ;

SNMPAPI_STATUS CALLBACK mycall2(
          HSNMP_SESSION hSession,  // handle to the WinSNMP session
          HWND hWnd,               // handle to the notification window
          UINT wMsg,               // window notification message number
          WPARAM wParam,           // type of notification
          LPARAM lParam,           // request identifier of PDU
          LPVOID lpClientData      // optional application-defined data
          ) ;


char *OIDBuf[] = {
 "1.3.6.1.2.1.2.2.1.5.1",
  "1.3.6.1.2.1.2.2.1.5.2",
  "1.3.6.1.2.1.2.2.1.5.3",
  "1.3.6.1.2.1.2.2.1.5.4",
  "1.3.6.1.2.1.2.2.1.5.5",
  "1.3.6.1.2.1.2.2.1.5.6",
  "1.3.6.1.2.1.2.2.1.5.7",
  "1.3.6.1.2.1.2.2.1.5.8",
  "1.3.6.1.2.1.2.2.1.5.9",
  "1.3.6.1.2.1.2.2.1.5.10",
  "1.3.6.1.2.1.2.2.1.5.11",
  "1.3.6.1.2.1.2.2.1.5.12",
  "1.3.6.1.2.1.2.2.1.5.13",
  "1.3.6.1.2.1.2.2.1.5.14",
  "1.3.6.1.2.1.2.2.1.5.15",
  "1.3.6.1.2.1.2.2.1.5.16",
  "1.3.6.1.2.1.2.2.1.5.17",
  "1.3.6.1.2.1.2.2.1.5.18",
  "1.3.6.1.2.1.2.2.1.5.19",
  "1.3.6.1.2.1.2.2.1.5.20",
  "1.3.6.1.2.1.2.2.1.5.21",
  "1.3.6.1.2.1.2.2.1.5.22",
  "1.3.6.1.2.1.2.2.1.5.23",
  "1.3.6.1.2.1.2.2.1.5.24",
  "1.3.6.1.2.1.2.2.1.5.25",
  "1.3.6.1.2.1.2.2.1.5.26",
  "1.3.6.1.2.1.2.2.1.5.27",
  "1.3.6.1.2.1.2.2.1.5.28"
} ;


char *OIDTime[] = {
 "1.3.6.1.2.1.2.2.1.10.1",
  "1.3.6.1.2.1.2.2.1.10.2",
  "1.3.6.1.2.1.2.2.1.10.3",
  "1.3.6.1.2.1.2.2.1.10.4",
  "1.3.6.1.2.1.2.2.1.10.5",
  "1.3.6.1.2.1.2.2.1.10.6",
  "1.3.6.1.2.1.2.2.1.10.7",
  "1.3.6.1.2.1.2.2.1.10.8",
  "1.3.6.1.2.1.2.2.1.10.9",
  "1.3.6.1.2.1.2.2.1.10.10",
  "1.3.6.1.2.1.2.2.1.10.11",
  "1.3.6.1.2.1.2.2.1.10.12",
  "1.3.6.1.2.1.2.2.1.10.13",
  "1.3.6.1.2.1.2.2.1.10.14",
  "1.3.6.1.2.1.2.2.1.10.15",
  "1.3.6.1.2.1.2.2.1.10.16",
  "1.3.6.1.2.1.2.2.1.10.17",
  "1.3.6.1.2.1.2.2.1.10.18",
  "1.3.6.1.2.1.2.2.1.10.19",
  "1.3.6.1.2.1.2.2.1.10.20",
  "1.3.6.1.2.1.2.2.1.10.21",
  "1.3.6.1.2.1.2.2.1.10.22",
  "1.3.6.1.2.1.2.2.1.10.23",
  "1.3.6.1.2.1.2.2.1.10.24",
  "1.3.6.1.2.1.2.2.1.10.25",
  "1.3.6.1.2.1.2.2.1.10.26",
  "1.3.6.1.2.1.2.2.1.10.27",
  "1.3.6.1.2.1.2.2.1.10.28"
} ;

IMPLEMENT_DYNCREATE(CNetworkMonitorView, CFormView)

HANDLE CNetworkMonitorView::m_ThreadHandle1 ;
HSNMP_ENTITY  CNetworkMonitorView::m_hsrcAgent1 ;
HSNMP_CONTEXT CNetworkMonitorView::m_hContext1 ;
HANDLE CNetworkMonitorView::m_ThreadHandle2 ;
HSNMP_ENTITY  CNetworkMonitorView::m_hsrcAgent2 ;
HSNMP_CONTEXT CNetworkMonitorView::m_hContext2 ;

BOOL CNetworkMonitorView::bIsFi = FALSE ;
BOOL CNetworkMonitorView::bIsFi2 = FALSE ;

HSNMP_SESSION m_hSession1 ;
HSNMP_SESSION m_hSession2 ;

HANDLE m_GetEvent1 ;
HANDLE m_GetEvent2 ;

BEGIN_MESSAGE_MAP(CNetworkMonitorView, CFormView)
 ON_CONTROL_RANGE(BN_CLICKED,IDC_BUTTON_PORT1,IDC_BUTTON_PORT23,OnMessageBlock)
 //{{AFX_MSG_MAP(CNetworkMonitorView)
 ON_BN_CLICKED(IDC_BUTTON_PORT19, OnButtonPort19)
 ON_WM_CTLCOLOR()
 ON_WM_SIZE()
 ON_WM_DESTROY()
 ON_WM_TIMER()
 ON_NOTIFY(NM_RCLICK, IDC_LIST1, OnRclickList1)
 ON_COMMAND(ID_MENU_JZ, OnMenuJz)
 //}}AFX_MSG_MAP
 // Standard printing commands
 ON_COMMAND(ID_FILE_PRINT, CFormView::OnFilePrint)
 ON_COMMAND(ID_FILE_PRINT_DIRECT, CFormView::OnFilePrint)
 ON_COMMAND(ID_FILE_PRINT_PREVIEW, CFormView::OnFilePrintPreview)
 ON_MESSAGE(WM_SCANCOMPLIE,OnSanComplie)
END_MESSAGE_MAP()

/
// CNetworkMonitorView construction/destruction

CNetworkMonitorView::CNetworkMonitorView()
 : CFormView(CNetworkMonitorView::IDD)
{
 //{{AFX_DATA_INIT(CNetworkMonitorView)
 //}}AFX_DATA_INIT
 // TODO: add construction code here

 m_BackgoundBrush.CreateSolidBrush(RGB(32,47,75)) ;
 nListItemIndex = 0 ;

 m_sDJ  = "1.5";
 m_sIP1 = "192.168.0.1";
 m_sIP2 = "192.168.0.2";

 m_nFerq = 1 ;
 m_bIsUpdate = FALSE ;

 m_bFerq = FALSE ;

 m_b1 = FALSE;
 m_b2 = FALSE ;

 m_nFreq = 1 ;
}

CNetworkMonitorView::~CNetworkMonitorView()
{
}

void CNetworkMonitorView::DoDataExchange(CDataExchange* pDX)
{
 CFormView::DoDataExchange(pDX);
 //{{AFX_DATA_MAP(CNetworkMonitorView)
 DDX_Control(pDX, IDC_BUTTON_PORT9, m_Port9);
 DDX_Control(pDX, IDC_BUTTON_PORT8, m_Port8);
 DDX_Control(pDX, IDC_BUTTON_PORT7, m_Port7);
 DDX_Control(pDX, IDC_BUTTON_PORT6, m_Port6);
 DDX_Control(pDX, IDC_BUTTON_PORT5, m_Port5);
 DDX_Control(pDX, IDC_BUTTON_PORT48, m_Port48);
 DDX_Control(pDX, IDC_BUTTON_PORT47, m_Port47);
 DDX_Control(pDX, IDC_BUTTON_PORT46, m_Port46);
 DDX_Control(pDX, IDC_BUTTON_PORT45, m_Port45);
 DDX_Control(pDX, IDC_BUTTON_PORT44, m_Port44);
 DDX_Control(pDX, IDC_BUTTON_PORT43, m_Port43);
 DDX_Control(pDX, IDC_BUTTON_PORT42, m_Port42);
 DDX_Control(pDX, IDC_BUTTON_PORT41, m_Port41);
 DDX_Control(pDX, IDC_BUTTON_PORT40, m_Port40);
 DDX_Control(pDX, IDC_BUTTON_PORT4, m_Port4);
 DDX_Control(pDX, IDC_BUTTON_PORT39, m_Port39);
 DDX_Control(pDX, IDC_BUTTON_PORT38, m_Port38);
 DDX_Control(pDX, IDC_BUTTON_PORT37, m_Port37);
 DDX_Control(pDX, IDC_BUTTON_PORT34, m_Port34);
 DDX_Control(pDX, IDC_BUTTON_PORT36, m_Port36);
 DDX_Control(pDX, IDC_BUTTON_PORT35, m_Port35);
 DDX_Control(pDX, IDC_BUTTON_PORT33, m_Port33);
 DDX_Control(pDX, IDC_BUTTON_PORT32, m_Port32);
 DDX_Control(pDX, IDC_BUTTON_PORT31, m_Port31);
 DDX_Control(pDX, IDC_BUTTON_PORT30, m_Port30);
 DDX_Control(pDX, IDC_BUTTON_PORT3, m_Port3);
 DDX_Control(pDX, IDC_BUTTON_PORT29, m_Port29);
 DDX_Control(pDX, IDC_BUTTON_PORT28, m_Port28);
 DDX_Control(pDX, IDC_BUTTON_PORT27, m_Port27);
 DDX_Control(pDX, IDC_BUTTON_PORT26, m_Port26);
 DDX_Control(pDX, IDC_BUTTON_PORT25, m_Port25);
 DDX_Control(pDX, IDC_BUTTON_PORT24, m_Port24);
 DDX_Control(pDX, IDC_BUTTON_PORT23, m_Port23);
 DDX_Control(pDX, IDC_BUTTON_PORT22, m_Port22);
 DDX_Control(pDX, IDC_BUTTON_PORT21, m_Port21);
 DDX_Control(pDX, IDC_BUTTON_PORT20, m_Port20);
 DDX_Control(pDX, IDC_BUTTON_PORT2, m_Port2);
 DDX_Control(pDX, IDC_BUTTON_PORT19, m_Port19);
 DDX_Control(pDX, IDC_BUTTON_PORT18, m_Port18);
 DDX_Control(pDX, IDC_BUTTON_PORT17, m_Port17);
 DDX_Control(pDX, IDC_BUTTON_PORT16, m_Port16);
 DDX_Control(pDX, IDC_BUTTON_PORT15, m_Port15);
 DDX_Control(pDX, IDC_BUTTON_PORT14, m_Port14);
 DDX_Control(pDX, IDC_BUTTON_PORT13, m_Port13);
 DDX_Control(pDX, IDC_BUTTON_PORT12, m_Port12);
 DDX_Control(pDX, IDC_BUTTON_PORT11, m_Port11);
 DDX_Control(pDX, IDC_BUTTON_PORT10, m_Port10);
 DDX_Control(pDX, IDC_LIST1, m_ListCtrl);
 DDX_Control(pDX, IDC_BUTTON_PORT1, m_Port1);
 //}}AFX_DATA_MAP
}

BOOL CNetworkMonitorView::PreCreateWindow(CREATESTRUCT& cs)
{
 // TODO: Modify the Window class or styles here by modifying
 //  the CREATESTRUCT cs

 return CFormView::PreCreateWindow(cs);
}

void CNetworkMonitorView::OnInitialUpdate()
{
 CFormView::OnInitialUpdate();
 GetParentFrame()->RecalcLayout();
 ResizeParentToFit();

 InitivalPort() ;

 smiLPUINT32 m_nMajorVersion , m_nMinorVersion , m_nLevel , m_nTranslateMode , m_nRetransmitMode ;
 if (SNMPAPI_SUCCESS == SnmpStartup((smiLPUINT32)&m_nMajorVersion, (smiLPUINT32)&m_nMinorVersion, /
  (smiLPUINT32)&m_nLevel, (smiLPUINT32)&m_nTranslateMode, (smiLPUINT32)&m_nRetransmitMode))
 {
  
 }
 
 if(SnmpSetTranslateMode(SNMPAPI_UNTRANSLATED_V1)!=SNMPAPI_SUCCESS)
  AfxMessageBox("SetTranslateMode failure");
 
 if(SnmpSetRetransmitMode(SNMPAPI_ON)!=SNMPAPI_SUCCESS)
  AfxMessageBox("SetRetransmitMode failure");
 
 m_hSession1 = SnmpCreateSession(NULL, 0, mycall, this);
 //SNMPAPI_STATUS   trasMode=SnmpSetTranslateMode(SNMPAPI_UNTRANSLATED_V1);   //设置传输模式 
 
 m_hsrcAgent1 = SnmpStrToEntity(m_hSession1,   m_sIP1);
 
 char   *   comm="public";                                                           //团体字不便透露,用public替代  
 smiOCTETS   community;  
 community.len=6;  
 community.ptr=(unsigned   char   *)comm;  
 m_hContext1 = SnmpStrToContext(m_hSession1, &community);
 

 m_hSession2 = SnmpCreateSession(NULL, 0, mycall2, this);
 m_hsrcAgent2 = SnmpStrToEntity(m_hSession2,   m_sIP2);
 m_hContext2 = SnmpStrToContext(m_hSession2, &community);

 memset(&PortFlag, 0, sizeof(PortFlag)) ;
 memset(&PortTime, 0, sizeof(PortTime)) ;
 memset(&PortFirstLL, 0, sizeof(PortFirstLL)) ;


 memset(&PortFlag2, 0, sizeof(PortFlag2)) ;
 memset(&PortTime2, 0, sizeof(PortTime2)) ;
 memset(&PortFirstLL2, 0, sizeof(PortFirstLL2)) ;

 ConnectionSwitch() ;

 
 m_bIsFirst = TRUE ;
 m_bISFirst2 = TRUE ;
 

 m_GetEvent1 = ::CreateEvent(NULL,TRUE,TRUE,g_sIREventName) ;
 m_GetEvent2 = ::CreateEvent(NULL,TRUE,TRUE,g_sIREventName2) ;

 SetTimer(100,1000*60*m_nFreq, NULL) ;

 LoadNoneValue() ;
 ShowNoneValue() ;
}

void CNetworkMonitorView::LoadNoneValue()
{
 char inBuf[80];  
 CString str ;

 for(int i = 1 ; i <= ALL_PORT ; i++ )
 {
  str.Format("%d", i) ;
  memset(inBuf,0,sizeof(inBuf)) ;
  if(GetPrivateProfileString ("nonevalue", "room"+str, NULL,inBuf,80,".//config.ini") >=1)
  {

   NONEVALUE * pNoneValue = new NONEVALUE ;

   pNoneValue->sRoom = inBuf ;

   GetPrivateProfileString ("nonevalue", "Time"+str, NULL,inBuf,80,".//config.ini") ;
   pNoneValue->sTimeOnline = inBuf ;
   
   GetPrivateProfileString ("nonevalue", "LL"+str, NULL,inBuf,80,".//config.ini") ;
   pNoneValue->sLL = inBuf ;
  
   GetPrivateProfileString ("nonevalue", "DJ"+str, NULL,inBuf,80,".//config.ini");
   pNoneValue->sDJ = inBuf ;

   GetPrivateProfileString ("nonevalue", "ZJ"+str, NULL,inBuf,80,".//config.ini");
   pNoneValue->sZJ = inBuf ;
   m_NoneValue.Add(pNoneValue) ;
  }
  
 }


}

void CNetworkMonitorView::InitivalPort()
{
 
 for( UINT ID = IDC_BUTTON_PORT1 ; ID <= IDC_BUTTON_PORT24 ; ID++)
 {
  CWinXPButtonST *pWinXpButton = (CWinXPButtonST*)GetDlgItem(ID) ;
  pWinXpButton->SetIcon(IDI_ICON1) ;

  pWinXpButton->SetID(ID-(IDC_BUTTON_PORT1-1)) ;
 }

 for( ID = IDC_BUTTON_PORT25 ; ID <= IDC_BUTTON_PORT48 ; ID++)
 {
  CWinXPButtonST *pWinXpButton = (CWinXPButtonST*)GetDlgItem(ID) ;
  pWinXpButton->SetIcon(IDI_ICON1) ;
  pWinXpButton->SetID(ID-(IDC_BUTTON_PORT25-1)+24) ;
 }


 DWORD dwLStyle = LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT;
 
 
 
 
 m_ListCtrl.SetExtendedStyle(dwLStyle);
 
 LV_COLUMN m_Column;
 m_Column.mask = LVCF_FMT|LVCF_SUBITEM|LVCF_TEXT|LVCF_WIDTH;
 m_Column.fmt = LVCFMT_LEFT;

 int   iFieldCx[5] = {150,250    ,100,250    ,250};
 char*pszArray[5] = {"房间号","上网时间","流量","单价/时","总价"} ;
 for(int i = 0;i<5;i++)
 {
  m_Column.pszText = pszArray[i] ;
  m_Column.cx = iFieldCx[i];
  m_Column.iSubItem = i;
  
  m_ListCtrl.InsertColumn(i,&m_Column);
 }


 char inBuf[80];  
 
 memset(inBuf,0,sizeof(inBuf)) ;
 GetPrivateProfileString ("set", "ip1", "192.168.0.1",inBuf,80,".//config.ini");
 m_sIP1 = inBuf ;
 
 
 memset(inBuf,0,sizeof(inBuf)) ;
 GetPrivateProfileString ("set", "ip2", "192.168.0.2",inBuf,80,".//config.ini");
 m_sIP2 = inBuf ;
 
 memset(inBuf,0,sizeof(inBuf)) ;
 GetPrivateProfileString ("set", "DJ", "1.5",inBuf,80,".//config.ini");
 m_sDJ = inBuf ;
 m_fDJ = atof(m_sDJ) ;

 memset(inBuf,0,sizeof(inBuf)) ;
 GetPrivateProfileString ("set", "freq", "1",inBuf,80,".//config.ini");
 m_sFreq = inBuf ;
 m_nFreq = atoi(m_sFreq) ;
 


}


/
// CNetworkMonitorView printing

BOOL CNetworkMonitorView::OnPreparePrinting(CPrintInfo* pInfo)
{
 // default preparation
 return DoPreparePrinting(pInfo);
}

void CNetworkMonitorView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
 // TODO: add extra initialization before printing
}

void CNetworkMonitorView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
 // TODO: add cleanup after printing
}

void CNetworkMonitorView::OnPrint(CDC* pDC, CPrintInfo* /*pInfo*/)
{
 // TODO: add customized printing code here
}

/
// CNetworkMonitorView diagnostics

#ifdef _DEBUG
void CNetworkMonitorView::AssertValid() const
{
 CFormView::AssertValid();
}

void CNetworkMonitorView::Dump(CDumpContext& dc) const
{
 CFormView::Dump(dc);
}

CNetworkMonitorDoc* CNetworkMonitorView::GetDocument() // non-debug version is inline
{
 ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CNetworkMonitorDoc)));
 return (CNetworkMonitorDoc*)m_pDocument;
}
#endif //_DEBUG

/
// CNetworkMonitorView message handlers

void CNetworkMonitorView::OnButtonPort19()
{
 // TODO: Add your control notification handler code here
 
}

HBRUSH CNetworkMonitorView::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
 HBRUSH hbr = CFormView::OnCtlColor(pDC, pWnd, nCtlColor);
 
 // TODO: Change any attributes of the DC here
 if(pWnd == this)
  return m_BackgoundBrush ;
 
 if(nCtlColor== CTLCOLOR_STATIC)
 {  
  pDC->SetBkMode(TRANSPARENT) ;
  
  //pDC->SetBkColor(RGB(20,200,20)) ;
  pDC->SetTextColor(RGB(255,255,255)) ;
  HBRUSH hBrush = (HBRUSH)::GetStockObject(HOLLOW_BRUSH) ;
  return hBrush ;
 }
 
 // TODO: Return a different brush if the default is not desired
 return hbr;
}

void CNetworkMonitorView::OnSize(UINT nType, int cx, int cy)
{
 CFormView::OnSize(nType, cx, cy);
 
 // TODO: Add your message handler code here
 CRect rect ;
 GetClientRect(&rect) ;

 if(m_ListCtrl)
 m_ListCtrl.SetWindowPos(&CWnd::wndTop,rect.left,rect.bottom - 200,rect.Width(),200,SWP_NOOWNERZORDER) ;
 
}

// 1052 ~ 1111
void CNetworkMonitorView::OnMessageBlock(UINT nID)
{
 // TODO: Add your control notification handler code here 
 //CWinXPButtonST* pWnd;
 UINT nBaseID;
 //LV_COLUMN m_Column;

 nBaseID = IDC_BUTTON_PORT1;
 if((nID>=IDC_BUTTON_PORT1) && (nID<=IDC_BUTTON_PORT23))
 {
  
 } 
}

 

SNMPAPI_STATUS CALLBACK mycall(
          HSNMP_SESSION hSession,  // handle to the WinSNMP session
          HWND hWnd,               // handle to the notification window
          UINT wMsg,               // window notification message number
          WPARAM wParam,           // type of notification
          LPARAM lParam,           // request identifier of PDU
          LPVOID lpClientData      // optional application-defined data
          )
         
{
 HSNMP_ENTITY   recsrcEntity;  
 HSNMP_ENTITY   recdisEntity;  
 HSNMP_CONTEXT   reccontext;  
 HSNMP_PDU   recPDU;  

 SNMPAPI_STATUS   recStat=SnmpRecvMsg(hSession,&recsrcEntity,&recdisEntity,&reccontext,&recPDU);     //接受消息  

 if(SNMPAPI_FAILURE == recStat )
 {

  SNMPAPI_STATUS st = SnmpGetLastError(hSession) ;
  return 1L;
 }
 
 smiINT    PduType, ErrorStatus, ErrorIndex;
 HSNMP_VBL   recVBL;  
 smiINT32   nReqId;
 smiVALUE   sVal;
 smiOID    sOid;
 

 SNMPAPI_STATUS   GetPDUstat=SnmpGetPduData(recPDU,&PduType,&nReqId,&ErrorStatus,/
  &ErrorIndex,&recVBL);   //提取PDU  
 
 if( SNMPAPI_FAILURE == GetPDUstat) 
 {
  return 1L;
 }
 
 smiINT Val ;
 char cTmp[1024] ;

 if (PduType == SNMP_PDU_RESPONSE)
 {
  SNMPAPI_STATUS Stat = SnmpGetVb(recVBL, 1, &sOid, &sVal);
  memcpy(&g_Oid,&sOid,sizeof(smiOID));

  SnmpOidToStr(&sOid, 40 ,g_buffer) ;
  
  switch (sVal.syntax) {
  case SNMP_SYNTAX_INT32:
  case SNMP_SYNTAX_UINT32:
  case SNMP_SYNTAX_CNTR32:
  case SNMP_SYNTAX_GAUGE32:
  
   Val = sVal.value.sNumber;
   if (g_Counter < 28)
   {
    if(strcmp(OIDBuf[g_Counter], g_buffer) == 0)
    {
     PortFlag[g_Counter] = Val ;
     g_Counter++ ;
    }
   }
   else if (g_TimeCounter < 28)
   {
    if(strcmp(OIDTime[g_TimeCounter], g_buffer) == 0)
    {
     PortTime[g_TimeCounter] = Val ;
     g_TimeCounter++ ;
    }
   }
   
   break;
  case SNMP_SYNTAX_TIMETICKS:

//    
//       days = tt / 8640000;
//       tt %= 8640000;
//       
//       // hours
//       hours = tt / 360000;
//       tt %= 360000;
//       
//       // minutes
//       minutes = tt / 6000;
//       tt %= 6000;
//       
//       seconds = tt / 100;
//       tt %= 100;
//       
//       hseconds = tt;
   
   Val = sVal.value.sNumber;

   
   
   break ;
  case SNMP_SYNTAX_CNTR64:
   Val = sVal.value.hNumber.hipart << 32;
   Val += sVal.value.hNumber.lopart;
   break;
  case SNMP_SYNTAX_OCTETS:
  case SNMP_SYNTAX_BITS:
  case SNMP_SYNTAX_OPAQUE:
   {
    memset(cTmp, 0, 1024);
    for (int i=0; i<(int)sVal.value.string.len; i++)
     cTmp[i] = sVal.value.string.ptr[i];
    g_sValue1.Format("String: %s",cTmp);
   }
   
   break;
  case SNMP_SYNTAX_IPADDR:
  case SNMP_SYNTAX_NSAPADDR:
   {
    memset(cTmp, 0, 1024);
    sprintf(cTmp, "%d.%d.%d.%d",
     sVal.value.string.ptr[0],
     sVal.value.string.ptr[1],
     sVal.value.string.ptr[2],
     sVal.value.string.ptr[3]);
    //Re.Format("String: %s",cTmp);
   }
   
   break;
  case SNMP_SYNTAX_OID:
   {
    memset(cTmp, 0, 1024);
    for (int i=0; i<(int)sVal.value.string.len; i++)
     cTmp[i] = sVal.value.string.ptr[i];
    g_sValue1.Format("String: %s",cTmp);
   }
   break;
  default:
   break;
  }

 
  
 }

 SetEvent(m_GetEvent1) ;
 return 1L;
}

SNMPAPI_STATUS CALLBACK mycall2(
          HSNMP_SESSION hSession,  // handle to the WinSNMP session
          HWND hWnd,               // handle to the notification window
          UINT wMsg,               // window notification message number
          WPARAM wParam,           // type of notification
          LPARAM lParam,           // request identifier of PDU
          LPVOID lpClientData      // optional application-defined data
          )
         
{
 HSNMP_ENTITY   recsrcEntity;  
 HSNMP_ENTITY   recdisEntity;  
 HSNMP_CONTEXT   reccontext;  
 HSNMP_PDU   recPDU;  

 SNMPAPI_STATUS   recStat=SnmpRecvMsg(hSession,&recsrcEntity,&recdisEntity,&reccontext,&recPDU);     //接受消息  

 if(SNMPAPI_FAILURE == recStat )
 {

  SNMPAPI_STATUS st = SnmpGetLastError(hSession) ;
  return 1L;
 }
 
 smiINT    PduType, ErrorStatus, ErrorIndex;
 HSNMP_VBL   recVBL;  
 smiINT32   nReqId;
 smiVALUE   sVal;
 smiOID    sOid;
 

 SNMPAPI_STATUS   GetPDUstat=SnmpGetPduData(recPDU,&PduType,&nReqId,&ErrorStatus,/
  &ErrorIndex,&recVBL);   //提取PDU  
 
 if( SNMPAPI_FAILURE == GetPDUstat) 
 {
  return 1L;
 }
 
 smiINT Val ;

 if (PduType == SNMP_PDU_RESPONSE)
 {
  SNMPAPI_STATUS Stat = SnmpGetVb(recVBL, 1, &sOid, &sVal);
  memcpy(&g_Oid,&sOid,sizeof(smiOID));

  SnmpOidToStr(&sOid, 40 ,g_buffer2) ;
  
  switch (sVal.syntax) {
  case SNMP_SYNTAX_INT32:
  case SNMP_SYNTAX_UINT32:
  case SNMP_SYNTAX_CNTR32:
  case SNMP_SYNTAX_GAUGE32:
  
   Val = sVal.value.sNumber;
   if (g_Counter2 < 28)
   {
    if(strcmp(OIDBuf[g_Counter2], g_buffer2) == 0)
    {
     PortFlag2[g_Counter2] = Val ;
     g_Counter2++ ;
    }
   }
   else if (g_TimeCounter2 < 28)
   {
    if(strcmp(OIDTime[g_TimeCounter2], g_buffer2) == 0)
    {
     PortTime2[g_TimeCounter2] = Val ;
     g_TimeCounter2++ ;
    }
   }
   
   break;
  case SNMP_SYNTAX_TIMETICKS:
  case SNMP_SYNTAX_CNTR64:
  case SNMP_SYNTAX_OCTETS:
  case SNMP_SYNTAX_BITS:
  case SNMP_SYNTAX_OPAQUE:
  case SNMP_SYNTAX_IPADDR:
  case SNMP_SYNTAX_NSAPADDR:
   break;
  case SNMP_SYNTAX_OID:
   break;
  default:
   break;
  }

 
  
 }

 SetEvent(m_GetEvent2) ;
 return 1L;
}

 

void CNetworkMonitorView::ConnectionSwitch()


                           //建立oid

 m_bFerq = FALSE ;
 m_b1 = FALSE;
 m_b2 = FALSE ;

 m_ThreadHandle1 = CreateThread(NULL, 0, ThreadProc , reinterpret_cast<LPVOID>(this) , 0 , NULL ) ;
 
 m_ThreadHandle2 = CreateThread(NULL, 0, ThreadProc2 , reinterpret_cast<LPVOID>(this) , 0 , NULL ) ;


}


DWORD WINAPI CNetworkMonitorView::ThreadProc(LPVOID lpParam)
{
 CNetworkMonitorView* pImageShow = reinterpret_cast<CNetworkMonitorView *>(lpParam) ;
 //ASSERT(pImageShow) ;
 
 smiOID   myOid;
 HSNMP_VBL hVbl ;
 HSNMP_PDU   m_hpdu ;

 static int nTempCounter = 0 ;

 nTempCounter = 0 ;
 g_Counter = 0 ;

 memset(&PortFlag, 0, sizeof(PortFlag)) ;

 bIsFi = FALSE ;
 while (!bIsFi)
 {
  ::WaitForSingleObject(m_GetEvent1,INFINITE);
  ResetEvent(m_GetEvent1) ;

  if (g_Counter == 0 )
  {
   LPCSTR   pOid="1.3.6.1.2.1.2.2.1.4.604";  
   
   SNMPAPI_STATUS   oidstatu   =   SnmpStrToOid(pOid,&myOid); 

   
  }
  else
  {
   if(strcmp("1.3.6.1.2.1.2.2.1.5.604" ,g_buffer ) == 0 )
   {
    
    bIsFi = TRUE ;
    continue ;
   }
   LPCSTR   pOid= g_buffer;  
   SNMPAPI_STATUS   oidstatu   =   SnmpStrToOid(pOid,&myOid);
  }
  
  hVbl = SnmpCreateVbl(m_hSession1, &myOid, NULL);
  m_hpdu=SnmpCreatePdu(m_hSession1,SNMP_PDU_GETNEXT,NULL,NULL,NULL,hVbl);  //创建PDU
  
  SnmpSendMsg(m_hSession1, NULL, m_hsrcAgent1, m_hContext1, m_hpdu) ;
  
  SnmpFreePdu(m_hpdu) ;
  SnmpFreeVbl(hVbl) ;
  nTempCounter++ ;

  if (nTempCounter > 5 )
  {
   if (g_Counter == 0 )
   {
    bIsFi = TRUE ;
   }   
  }

 }

 // 发送时间timetick
 bIsFi = FALSE ;
 nTempCounter = 0 ;
 g_TimeCounter = 0 ;
 SetEvent(m_GetEvent1) ;
 while (!bIsFi)
 {
  ::WaitForSingleObject(m_GetEvent1,INFINITE);
  ResetEvent(m_GetEvent1) ;
  
  if (g_TimeCounter == 0 )
  {
   LPCSTR   pOid="1.3.6.1.2.1.2.2.1.9.604";  
   
   SNMPAPI_STATUS   oidstatu   =   SnmpStrToOid(pOid,&myOid); 

  }
  else
  {
   if(strcmp("1.3.6.1.2.1.2.2.1.10.604" ,g_buffer ) == 0 )
   {
    
    bIsFi = TRUE ;
    continue ;
   }
   LPCSTR   pOid= g_buffer;  
   SNMPAPI_STATUS   oidstatu   =   SnmpStrToOid(pOid,&myOid);
  }
  
  hVbl = SnmpCreateVbl(m_hSession1, &myOid, NULL);
  m_hpdu=SnmpCreatePdu(m_hSession1,SNMP_PDU_GETNEXT,NULL,NULL,NULL,hVbl);  //创建PDU
  
  SnmpSendMsg(m_hSession1, NULL, m_hsrcAgent1, m_hContext1, m_hpdu) ;
  
  SnmpFreePdu(m_hpdu) ;
  SnmpFreeVbl(hVbl) ;
  nTempCounter++ ;

  if (nTempCounter > 5 )
  {
   if (g_TimeCounter == 0 )
   {
    bIsFi = TRUE ;
   }   
  }
 }
 
 nTempCounter = 0 ;

 ::PostMessage(pImageShow->GetSafeHwnd(), WM_SCANCOMPLIE,0,0) ;
 return 0l ;
}

DWORD WINAPI CNetworkMonitorView::ThreadProc2(LPVOID lpParam)
{
 CNetworkMonitorView* pImageShow = reinterpret_cast<CNetworkMonitorView *>(lpParam) ;
 //ASSERT(pImageShow) ;
 
 smiOID   myOid;
 HSNMP_VBL hVbl ;
 HSNMP_PDU   m_hpdu ;

 static int nTempCounter = 0 ;

 nTempCounter = 0 ;
 g_Counter2 = 0 ;

 memset(&PortFlag2, 0, sizeof(PortFlag2)) ;

 bIsFi2 = FALSE ;
 while (!bIsFi2)
 {
  ::WaitForSingleObject(m_GetEvent2,INFINITE);
  ResetEvent(m_GetEvent2) ;

  if (g_Counter2 == 0 )
  {
   LPCSTR   pOid="1.3.6.1.2.1.2.2.1.4.604";  
   
   SNMPAPI_STATUS   oidstatu   =   SnmpStrToOid(pOid,&myOid); 

   
  }
  else
  {
   if(strcmp("1.3.6.1.2.1.2.2.1.5.604" ,g_buffer2 ) == 0 )
   {
    
    bIsFi2 = TRUE ;
    continue ;
   }
   LPCSTR   pOid= g_buffer2;  
   SNMPAPI_STATUS   oidstatu   =   SnmpStrToOid(pOid,&myOid);
  }
  
  hVbl = SnmpCreateVbl(m_hSession2, &myOid, NULL);
  m_hpdu=SnmpCreatePdu(m_hSession2,SNMP_PDU_GETNEXT,NULL,NULL,NULL,hVbl);  //创建PDU
  
  SnmpSendMsg(m_hSession2, NULL, m_hsrcAgent2, m_hContext2, m_hpdu) ;
  
  SnmpFreePdu(m_hpdu) ;
  SnmpFreeVbl(hVbl) ;
  nTempCounter++ ;

  if (nTempCounter > 5 )
  {
   if (g_Counter2 == 0 )
   {
    bIsFi = TRUE ;
   }   
  }

 }

 // 发送时间timetick
 bIsFi2 = FALSE ;
 nTempCounter = 0 ;
 g_TimeCounter2 = 0 ;
 SetEvent(m_GetEvent2) ;
 while (!bIsFi2)
 {
  ::WaitForSingleObject(m_GetEvent2,INFINITE);
  ResetEvent(m_GetEvent2) ;
  
  if (g_TimeCounter2 == 0 )
  {
   LPCSTR   pOid="1.3.6.1.2.1.2.2.1.9.604";  
   
   SNMPAPI_STATUS   oidstatu   =   SnmpStrToOid(pOid,&myOid); 

  }
  else
  {
   if(strcmp("1.3.6.1.2.1.2.2.1.10.604" ,g_buffer2 ) == 0 )
   {
    
    bIsFi2 = TRUE ;
    continue ;
   }
   LPCSTR   pOid= g_buffer2;  
   SNMPAPI_STATUS   oidstatu   =   SnmpStrToOid(pOid,&myOid);
  }
  
  hVbl = SnmpCreateVbl(m_hSession2, &myOid, NULL);
  m_hpdu=SnmpCreatePdu(m_hSession2,SNMP_PDU_GETNEXT,NULL,NULL,NULL,hVbl);  //创建PDU
  
  SnmpSendMsg(m_hSession2, NULL, m_hsrcAgent2, m_hContext2, m_hpdu) ;
  
  SnmpFreePdu(m_hpdu) ;
  SnmpFreeVbl(hVbl) ;
  nTempCounter++ ;

  if (nTempCounter > 5 )
  {
   if (g_TimeCounter2 == 0 )
   {
    bIsFi = TRUE ;
   }   
  }
 }
 
 nTempCounter = 0 ;

 ::PostMessage(pImageShow->GetSafeHwnd(), WM_SCANCOMPLIE,0,1) ;
 return 0l ;
}

void CNetworkMonitorView::OnSanComplie(WPARAM wParam, LPARAM lParam)
{

 int nCounter = 0 ;
 PORTINFO *pPortInfo = NULL ;


 if (!m_bFerq)
 {
  if (lParam == 0)
     m_b2 = TRUE ;
  else
   m_b1 = TRUE ;

  m_bFerq = TRUE ;
  
 }


 if (lParam == 0)
 {

  if(m_bIsFirst)
  {
   m_bIsFirst = FALSE ;
   memcpy(&PortFirstLL, &PortTime, sizeof(PortTime)) ;
  }
  
  
  for( UINT ID = IDC_BUTTON_PORT1 ; ID <= IDC_BUTTON_PORT24 ; ID++)
  {
   CWinXPButtonST *pWinXpButton = (CWinXPButtonST*)GetDlgItem(ID) ;

   if (PortFlag[nCounter] == 100000000)
   {
    pWinXpButton->SetIcon(IDI_ICON3) ;
    
    Computer(pWinXpButton->GetText(),nCounter, &pPortInfo) ;
    //UpdateRow(nCounter, pWinXpButton->GetText(),&pPortInfo->Datetime,PortTime[nCounter] - PortFirstLL[nCounter]) ;
   }
   else
   {
    pWinXpButton->SetIcon(IDI_ICON1) ;
   }
   nCounter++ ;
  }

  if(m_b1)
   ShowNoneValue()  ;

 }
 else if(lParam == 1)
 {

  if(m_bISFirst2)
  {
   m_bISFirst2 = FALSE ;
   memcpy(&PortFirstLL2, &PortTime2, sizeof(PortTime2)) ;
  }
  
  
  for( UINT ID = IDC_BUTTON_PORT25 ; ID <= IDC_BUTTON_PORT48 ; ID++)
  {
   CWinXPButtonST *pWinXpButton = (CWinXPButtonST*)GetDlgItem(ID) ;
   
   if (PortFlag2[nCounter] == 100000000)
   {
    pWinXpButton->SetIcon(IDI_ICON3) ;
    
    Computer(pWinXpButton->GetText(),nCounter+24, &pPortInfo) ;
    //UpdateRow(nCounter+24, pWinXpButton->GetText(),&pPortInfo->Datetime,PortTime2[nCounter] - PortFirstLL2[nCounter]) ;
   }
   else
   {
    pWinXpButton->SetIcon(IDI_ICON1) ;
   }
   nCounter++ ;
  }

  if(m_b2)
   ShowNoneValue() ;
 }
  
}

void CNetworkMonitorView::ShowNoneValue()
{

 nListItemIndex = 0 ;
 m_ListCtrl.DeleteAllItems() ;


 

 int nLL ;
 for(int i = 0 ; i < m_PortInfo.GetSize() ; i++ )
 {

  if (m_PortInfo[i]->nPort > 24)
  {
   nLL = PortTime2[m_PortInfo[i]->nPort-24] - PortFirstLL2[m_PortInfo[i]->nPort-24] ;
  }
  else
  {
   nLL = PortTime[m_PortInfo[i]->nPort] - PortFirstLL[m_PortInfo[i]->nPort] ;
  }

  UpdateRow(m_PortInfo[i]->nPort, m_PortInfo[i]->sRoom,&m_PortInfo[i]->Datetime, nLL) ;
  
 }

 
 for(i = 0 ; i < m_NoneValue.GetSize() ; i++ )
 {
  m_ListCtrl.InsertItem(nListItemIndex,m_NoneValue[i]->sRoom+"(未付 仅提示一次)") ;
  m_ListCtrl.SetItemText(nListItemIndex,1,m_NoneValue[i]->sTimeOnline) ;
  
  m_ListCtrl.SetItemText(nListItemIndex,2,m_NoneValue[i]->sLL) ;
  
  m_ListCtrl.SetItemText(nListItemIndex,3,m_NoneValue[i]->sDJ) ;
  
  
  m_ListCtrl.SetItemText(nListItemIndex,4,m_NoneValue[i]->sZJ) ;
  
  nListItemIndex++ ;
 }

}

BOOL CNetworkMonitorView::Computer(CString sRoom, int nPort, PORTINFO **pPortInfo)
{
 COleDateTimeSpan TimeSpan(0,0,m_nFreq,0) ;

 BOOL bFlag = FALSE ;

 for(int i = 0 ; i < m_PortInfo.GetSize() ; i++ )
 {
  if(m_PortInfo[i]->nPort == nPort)
  {
   bFlag = TRUE ;
   m_PortInfo[i]->Datetime = m_PortInfo[i]->Datetime + TimeSpan ;
   *pPortInfo = m_PortInfo[i] ;

   break ;
  }

 }

 

 if (!bFlag)
 {
  PORTINFO *pPInfo = new PORTINFO ;
  pPInfo->nPort = nPort ;
  pPInfo->sRoom = sRoom ;
  pPInfo->Datetime.SetDateTimeSpan(0,0,0,0) ;   // 包括设定时间为 00:00:00
  m_PortInfo.Add(pPInfo) ;
  *pPortInfo = pPInfo ;
 }


 return TRUE ;
}

 

// "房间号","上网时间","流量","单价/时","总价"} ;
void CNetworkMonitorView::UpdateRow(int nPort, CString sRomm, COleDateTimeSpan *pOleDateTime, int nLL )
{
 
 CString sDatetime ;
 CString strLL ;
 CString str ;
 str.Format("%d", nPort) ;
 
 WritePrivateProfileString("nonevalue","room"+str , sRomm,".//config.ini");

 int fLL = nLL ;
 if (fLL < 1024)
 {
  strLL.Format("%dB", fLL) ;
 }
 else if (fLL>=1024 && fLL < 1024*1024)
 {
  fLL = fLL / 1024 ;
  strLL.Format("%dKB", fLL) ;
 }
 else
 {
  fLL = fLL / (1024*1024) ;
  strLL.Format("%dMB", fLL) ;

 }

 sDatetime.Format("%d天 %d时 %d分", pOleDateTime->GetDays(), pOleDateTime->GetHours(), pOleDateTime->GetMinutes()) ;
 
 WritePrivateProfileString("nonevalue","Time"+str , sDatetime,".//config.ini");

 m_ListCtrl.InsertItem(nListItemIndex,sRomm) ;
 m_ListCtrl.SetItemText(nListItemIndex,1,sDatetime) ;

 WritePrivateProfileString("nonevalue","LL" + str , strLL,".//config.ini");
 m_ListCtrl.SetItemText(nListItemIndex,2,strLL) ;

 strLL.Format("%.1f", m_fDJ) ;
 m_ListCtrl.SetItemText(nListItemIndex,3,strLL) ;
 WritePrivateProfileString("nonevalue","DJ" + str , strLL,".//config.ini");

 float fValue = pOleDateTime->GetDays() * 24.0f ;
 fValue = fValue + pOleDateTime->GetHours() + pOleDateTime->GetMinutes() / 60.0f  ;
 
 fValue = fValue * m_fDJ ;

 strLL.Format("%.1f", fValue) ;
 m_ListCtrl.SetItemText(nListItemIndex,4,strLL) ;
 WritePrivateProfileString("nonevalue","ZJ"+str , strLL,".//config.ini");

 nListItemIndex++ ;
}

void CNetworkMonitorView::SetValue(CString sIP1, CString sIP2, CString sDJ, CString sFreq)
{

 m_sDJ = sDJ ;
 m_sIP1 = sIP1 ;
 m_sIP2 = sIP2 ;

 if (m_sFreq != sFreq)
 {
  KillTimer(100) ;

  m_nFreq = atoi(sFreq) ;
  SetTimer(100,1000*60*m_nFreq,NULL) ;
 }
 m_sFreq = sFreq ;


}

void CNetworkMonitorView::OnDestroy()
{
 CFormView::OnDestroy();
 
 // TODO: Add your message handler code here
 m_PortInfo.RemoveAll() ;

 m_NoneValue.RemoveAll() ;
}

void CNetworkMonitorView::OnTimer(UINT nIDEvent)
{
 // TODO: Add your message handler code here and/or call default
 
 if (nIDEvent == 100)
 {
  SetEvent(m_GetEvent1) ;
  SetEvent(m_GetEvent2) ;
  ConnectionSwitch() ;

 }

 CFormView::OnTimer(nIDEvent);
}

void CNetworkMonitorView::OnRclickList1(NMHDR* pNMHDR, LRESULT* pResult)
{
 // TODO: Add your control notification handler code here

 m_IndexItem = -1 ;
 if(m_ListCtrl.GetSelectedCount()<=0)
  return;
 //
 int ndx = 0 ;
 int nItems = m_ListCtrl.GetItemCount();
 while ( m_IndexItem < nItems )
 {
  if ( m_ListCtrl.GetItemState( ndx, LVIS_SELECTED ) == LVIS_SELECTED )
  {
   m_IndexItem = ndx ;
   break;   
  }
  ++ndx;
 }

 if(m_IndexItem < 0 ) return ;

 m_sRoom = m_ListCtrl.GetItemText(m_IndexItem,0);

 CMenu mu,*pSubMenu;
 CPoint p;  
 
 mu.LoadMenu(IDR_MENU1);
 pSubMenu=mu.GetSubMenu(0);
 ::GetCursorPos(&p);    
 pSubMenu->TrackPopupMenu(TPM_LEFTALIGN,p.x,p.y,this);
 *pResult = 0;

}

void CNetworkMonitorView::OnMenuJz()
{
 // TODO: Add your command handler code here
 m_ListCtrl.DeleteItem(m_IndexItem) ;
 
 int nHeight = m_PortInfo.GetSize() + m_NoneValue.GetSize() ;
 

 for(int i = 0; i < m_PortInfo.GetSize() ; i++ )
 {
  if(m_PortInfo[i]->sRoom == m_sRoom)
  {
   m_PortInfo.RemoveAt(i);
   break ;
  }
 }


 if(m_IndexItem <= m_PortInfo.GetSize() - 1 )
 {
  //m_PortInfo.RemoveAt(m_IndexItem) ;
 }
 else
 {

  m_IndexItem = m_IndexItem - m_PortInfo.GetSize() ;
  //m_IndexItem = m_NoneValue.GetSize() - m_IndexItem - 1 ;
  m_NoneValue.RemoveAt( m_IndexItem );

 }

 //WritePrivateProfileString("nonevalue", NULL, _T(""), ".//config.ini");

}

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值