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

📄 dlgdefence.cpp

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

#include "stdafx.h"
#include "ScanLAN.h"
#include "DlgDefence.h"
#include "ODBCSet.h"
#include "MyODBC.h"

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

/////////////////////////////////////////////////////////////////////////////
// CDlgDefence dialog


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


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


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

/////////////////////////////////////////////////////////////////////////////
// CDlgDefence message handlers

BOOL CDlgDefence::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here

/*	ImageList.Create(16,16,ILC_COLOR8,0,5);
	ImageList.Add(AfxGetApp()->LoadIcon(IDI_ICON1));
	DWORD dwStyle=GetWindowLong(m_list.GetSafeHwnd(),GWL_STYLE);
	dwStyle |= LVS_REPORT;
	SetWindowLongA(m_list.GetSafeHwnd(),GWL_STYLE,dwStyle);
	m_list.SetExtendedStyle(LVS_EX_HEADERDRAGDROP|LVS_EX_FULLROWSELECT|LVS_EX_TRACKSELECT);
	m_list.SetImageList(&ImageList, LVSIL_SMALL);*/
	ShowData();

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CDlgDefence::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 emp";
	CMyODBC db;
	db.ConnectDB("daliu","", "");
	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 CDlgDefence::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 emp 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("daliu","", "");//连接数据库
	db.ExeSqlDirect(strSql);//执行sql语句
	db.DisConnect();//断开连接
//	this->ShowData();//刷新数据
}

void CDlgDefence::OnStatistics() 
{
	// TODO: Add your control notification handler code here
/*	MessDef2VC mess;
	mess.addSrc = 10*256*256*256+4*256*256+3*256+6;
	mess.addDes = 10*256*256*256+4*256*256+3*256+16;
	mess.portSrc=123;
	mess.portDes=456;
	mess.cut=1;
	mess.insert=1;
	mess.set=0;
	mess.hideMethod=8;
	mess.sum=100;
	mess.defNum =56;
	Insert(mess);*/
	this->ShowData();//刷新数据
}

void CDlgDefence::Del()
{
	UpdateData();
	CString strSql;
	strSql.Format("delete from emp where 索引 = %d", 4);
	CMyODBC db;
	db.ConnectDB("daliu","", "");//连接数据库
	db.ExeSqlDirect(strSql);//执行sql语句
	db.DisConnect();//断开连接
	this->ShowData();//刷新数据
	UpdateData(FALSE);
}

CString CDlgDefence::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;
}

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

⌨️ 快捷键说明

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