⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dlgdetect.cpp

📁 扫描局域网
💻 CPP
字号:
// DlgDetect.cpp : implementation file
//

#include "stdafx.h"
#include "ScanLAN.h"
#include "DlgDetect.h"

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

/////////////////////////////////////////////////////////////////////////////
// CDlgDetect dialog


CDlgDetect::CDlgDetect(CWnd* pParent /*=NULL*/)
	: CDialog(CDlgDetect::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDlgDetect)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


void CDlgDetect::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDlgDetect)
	DDX_Control(pDX, IDC_LIST1, m_list);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDlgDetect, CDialog)
	//{{AFX_MSG_MAP(CDlgDetect)
	ON_BN_CLICKED(IDC_STATISTICS, OnStatistics)
	ON_BN_CLICKED(IDC_DEL, OnDel)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDlgDetect message handlers

void CDlgDetect::OnStatistics() 
{
	// TODO: Add your control notification handler code here
	
}

void CDlgDetect::Del()
{

}

void CDlgDetect::ShowData()
{
	int i = 0, iCount;
	m_list.DeleteAllItems();//首先清空listview

	iCount = m_list.GetHeaderCtrl()->GetItemCount();
	for(i = 0; i < iCount; i++)
	{
		m_list.DeleteColumn(0);
	}
	for(i = 0; i < iCount; i++)
	{
		m_list.GetHeaderCtrl()->DeleteItem(0);
	}

	CString strSql;
	strSql = "select * from emd";
	CMyODBC db;
	db.ConnectDB("dalid","", "");
	CODBCSet set;
	db.PrepareSql(strSql, set);
	for(i = 0; i < set.GetCols(); i++)
	{
		m_list.InsertColumn(i, set.m_coldatafmt[i].name,LVCFMT_CENTER,80);
	}

	int iRow = 0;
	
	

	while(db.FetchData())
	{
		for(i = 0; i < set.GetCols(); i++)
		{
			if(i == 0)
			{
				m_list.InsertItem(iRow, set.m_coldata[0].value);
			}
			else
			{
				m_list.SetItemText(iRow, i, set.m_coldata[i].value);
			}
		
		}
		iRow++;
	}

	set.Empty();
	db.DisConnect();

}

void CDlgDetect::Insert(MessDef2VC mess)
{
	UpdateData(TRUE);
	CString strTime;
	time_t nowtime; 
	struct tm *timeinfo; 
	time( &nowtime ); 
	timeinfo = localtime( &nowtime ); 
/*	int year, month, day; 
	year = timeinfo->tm_year + 1900; 
	month = timeinfo->tm_mon + 1; 
	day = timeinfo->tm_mday; 
	printf("%d %d %d\n", year, month, day);*/
//	strTime.Format("%d-%d-%d-%d-%d",timeinfo->tm_year + 1900,
//		timeinfo->tm_mon + 1,timeinfo->tm_mday,timeinfo->tm_hour, timeinfo->tm_min);
	strTime.Format("%d-%d",timeinfo->tm_hour, timeinfo->tm_min);

	int index = m_list.GetItemCount();
	CString strSql;
	strSql.Format("insert into emd values(%d,'%s','%s','%d','%d','%d','%d','%d','%d','%d','%d','%s')"
		, index, UL2IP(mess.addSrc), UL2IP(mess.addDes),
		mess.portSrc,mess.portDes,mess.hideMethod,
		mess.insert,mess.cut,mess.set,
		mess.sum,mess.defNum,strTime);
	CMyODBC db;
	db.ConnectDB("dalid","", "");//连接数据库
	db.ExeSqlDirect(strSql);//执行sql语句
	db.DisConnect();//断开连接
//	this->ShowData();//刷新数据

}

CString CDlgDetect::UL2IP(unsigned long ulval)
{
	CString str;
	str.Format("%d.%d.%d.%d",(ulval>>24)&0xff,(ulval>>16)&0xff,(ulval>>8)&0xff,ulval&0xff);
	return str;

}

BOOL CDlgDetect::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	ShowData();
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CDlgDetect::OnDel() 
{
	// TODO: Add your control notification handler code here
	UpdateData();
	CString strSql;
	strSql.Format("delete from emd" ); //where 索引 = %d", 4);
	CMyODBC db;
	db.ConnectDB("dalid","", "");//连接数据库
	db.ExeSqlDirect(strSql);//执行sql语句
	db.DisConnect();//断开连接
	this->ShowData();//刷新数据
	UpdateData(FALSE);
	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -