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

📄 find.cpp

📁 ARP test mode. According to the idea we design the arithmetic for the key part, first the system sen
💻 CPP
字号:
// Find.cpp : implementation file
//

#include "stdafx.h"
#include "LANDetect.h"
#include "Find.h"

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

/////////////////////////////////////////////////////////////////////////////
// CFind dialog

CFind::CFind(CWnd* pParent /*=NULL*/)
	: CDialog(CFind::IDD, pParent)
{
	//{{AFX_DATA_INIT(CFind)
	m_findtype = -1;
	m_time1 = 0;
	m_time2 = 0;
	m_time3 = 0;
	//}}AFX_DATA_INIT
}


void CFind::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CFind)
	DDX_Control(pDX, IDC_IPADDRESS, m_find_IP);
	DDX_Control(pDX, IDC_LIST1, m_find_list);
	DDX_Radio(pDX, IDC_RADIO1, m_findtype);
	DDX_DateTimeCtrl(pDX, IDC_DATETIMEPICKER1, m_time1);
	DDX_DateTimeCtrl(pDX, IDC_DATETIMEPICKER2, m_time2);
	DDX_DateTimeCtrl(pDX, IDC_DATETIMEPICKER3, m_time3);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CFind, CDialog)
	//{{AFX_MSG_MAP(CFind)
	ON_BN_CLICKED(IDC_RADIO1, OnRadio1)
	ON_BN_CLICKED(IDC_RADIO2, OnRadio2)
	ON_BN_CLICKED(IDC_RADIO3, OnRadio3)
	ON_BN_CLICKED(IDC_BUTTON_FIND, OnButtonFind)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CFind message handlers

BOOL CFind::OnInitDialog() 
{
	CDialog::OnInitDialog();
	m_findtype=0;
	m_time1=CTime::GetCurrentTime();
	m_time2=CTime::GetCurrentTime();
	m_time3=CTime::GetCurrentTime();
	//设置LIST控件的初始化
	DWORD dwStyle=GetWindowLong(m_find_list.GetSafeHwnd(),GWL_STYLE);
	dwStyle&=~LVS_TYPEMASK;
	dwStyle|=LVS_REPORT;
	SetWindowLong(m_find_list.GetSafeHwnd(),GWL_STYLE,dwStyle);
    m_find_list.InsertColumn(0,"序号",LVCFMT_CENTER,50);
	m_find_list.InsertColumn(1,"IP地址",LVCFMT_LEFT,100);
	m_find_list.InsertColumn(2,"MAC地址",LVCFMT_CENTER,150);
	m_find_list.InsertColumn(3,"时间",LVCFMT_LEFT,150);
	m_find_list.SetExtendedStyle(LVS_EX_GRIDLINES);
    ::SendMessage(m_find_list.m_hWnd, LVM_SETEXTENDEDLISTVIEWSTYLE,
      LVS_EX_FULLROWSELECT, LVS_EX_FULLROWSELECT);	
	GetDlgItem(IDC_DATETIMEPICKER2)->EnableWindow(false);
	GetDlgItem(IDC_DATETIMEPICKER3)->EnableWindow(false);
	GetDlgItem(IDC_IPADDRESS)->EnableWindow(false);
	UpdateData(false);
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CFind::OnRadio1() 
{
	GetDlgItem(IDC_DATETIMEPICKER1)->EnableWindow(true);
	GetDlgItem(IDC_DATETIMEPICKER2)->EnableWindow(false);
	GetDlgItem(IDC_DATETIMEPICKER3)->EnableWindow(false);
	GetDlgItem(IDC_IPADDRESS)->EnableWindow(false);
	m_findtype=0;
	UpdateData(true);
}

void CFind::OnRadio2() 
{
	GetDlgItem(IDC_DATETIMEPICKER1)->EnableWindow(false);
	GetDlgItem(IDC_DATETIMEPICKER2)->EnableWindow(true);
	GetDlgItem(IDC_DATETIMEPICKER3)->EnableWindow(true);
	GetDlgItem(IDC_IPADDRESS)->EnableWindow(false);
	m_findtype=1;
	UpdateData(true);
}

void CFind::OnRadio3() 
{
	GetDlgItem(IDC_DATETIMEPICKER1)->EnableWindow(false);
	GetDlgItem(IDC_DATETIMEPICKER2)->EnableWindow(false);
	GetDlgItem(IDC_DATETIMEPICKER3)->EnableWindow(false);
	GetDlgItem(IDC_IPADDRESS)->EnableWindow(true);
	m_findtype=2;
	UpdateData(true);
}

void CFind::OnButtonFind() 
{

	m_find_list.DeleteAllItems();
	UpdateData(true);
	CString t1,t2,t3;
	if(m_db.IsOpen())
		m_db.Close();
	CString sql,seq;
	sql="select * from Record";   
	m_db.Open(CRecordset::dynaset,_T(sql));
	int n=0;
	switch(m_findtype){
	case 0:                       //按天查询
		{t1.Format("%d-%d-%d",m_time1.GetYear(),m_time1.GetMonth(),m_time1.GetDay());
		while(!m_db.IsEOF())
		{
			if(t1==getdate(m_db.m_DTimes))
			{
				CString SIP,SMAC,STIME;
				seq.Format("%d",n+1);
				SIP=m_db.m_DIP;
				SMAC=m_db.m_DMAC;
				STIME=m_db.m_DTimes;
				m_find_list.InsertItem(n,seq,0);
				m_find_list.SetItemText(n,1,SIP);
				m_find_list.SetItemText(n,2,SMAC);
				m_find_list.SetItemText(n,3,STIME);
				n++;
			}
			m_db.MoveNext();
		}
		break;
		}
	case 1:                       //按日期范围查询
		{
			if(m_time2.GetYear()>m_time3.GetYear())
			{
				MessageBox("时间范围有误,请确认后再执行查询");
				return;
			}
			else if(m_time2.GetYear()==m_time3.GetYear())
			{
				if(m_time2.GetMonth()>m_time3.GetMonth())
				{
					MessageBox("时间范围有误,请确认后再执行查询");
					return;
				}
				else if(m_time2.GetMonth()==m_time3.GetMonth())
				{
					if(m_time2.GetDay()>=m_time3.GetDay())
					{
						MessageBox("时间范围有误,请确认后再执行查询");
						return;
					}
				}	
			}
			//t2.Format("%d-%d-%d",m_time2.GetYear(),m_time2.GetMonth(),m_time2.GetDay());
			//t3.Format("%d-%d-%d",m_time3.GetYear(),m_time3.GetMonth(),m_time3.GetDay());
			while(!m_db.IsEOF())
			{
				if(Compare(m_time2,m_time3,m_db.m_DTimes))
				{
					CString SIP,SMAC,STIME;
					seq.Format("%d",n+1);
					SIP=m_db.m_DIP;
					SMAC=m_db.m_DMAC;
					STIME=m_db.m_DTimes;
					m_find_list.InsertItem(n,seq,0);
					m_find_list.SetItemText(n,1,SIP);
					m_find_list.SetItemText(n,2,SMAC);
					m_find_list.SetItemText(n,3,STIME);
					n++;
				}
				m_db.MoveNext();
			}
			break;
		}
	case 2:                       //按IP查询
		{CString FIP;
		BYTE P[4];
		m_find_IP.GetAddress(P[0],P[1],P[2],P[3]);
		FIP.Format("%d.%d.%d.%d",int(P[0]),int(P[1]),int(P[2]),int(P[3]));
		while(!m_db.IsEOF())
		{
			if(FIP==m_db.m_DIP)
			{
				CString SIP,SMAC,STIME;
				seq.Format("%d",n+1);
				SIP=m_db.m_DIP;
				SMAC=m_db.m_DMAC;
				STIME=m_db.m_DTimes;
				m_find_list.InsertItem(n,seq,0);
				m_find_list.SetItemText(n,1,SIP);
				m_find_list.SetItemText(n,2,SMAC);
				m_find_list.SetItemText(n,3,STIME);
				n++;
			}
			m_db.MoveNext();
		}
		break;
		}
	default:
		break;
	}
}

CString CFind::getdate(CString time)
{
	CString date;
	int num;         //用于记录日期字符串的长度
	if(time.GetAt(6)=='-')
	{
		if(time.GetAt(8)==' ')
			num=8;
		else
			num=9;
	}
	else
	{
		if(time.GetAt(9)==' ')
			num=9;
		else
			num=10;
	}
	date.Format("%c%c%c%c%c%c%c%c",time.GetAt(0),time.GetAt(1),time.GetAt(2),time.GetAt(3),time.GetAt(4),time.GetAt(5),time.GetAt(6),time.GetAt(7));
	if(num==9)
		date=date+time.GetAt(8);
	else if(num==10)
		date=date+time.GetAt(8)+time.GetAt(9);
	return date;
}
BOOL CFind::Compare(CTime time1,CTime time2,CString time)
{
	CString year,month,day;
	year.Format("%c%c%c%c",time.GetAt(0),time.GetAt(1),time.GetAt(2),time.GetAt(3));
	if(time.GetAt(6)=='-')             //获取月、日
	{
		month.Format("%c",time.GetAt(5));
		if(time.GetAt(8)==' ')
			day.Format("%c",time.GetAt(7));
		else
			day.Format("%c%c",time.GetAt(7),time.GetAt(8));
	}
	else
	{
		month.Format("%c%c",time.GetAt(5),time.GetAt(6));
		if(time.GetAt(9)==' ')
			day.Format("%c",time.GetAt(8));
		else
			day.Format("%c%c",time.GetAt(8),time.GetAt(9));
	}
	BOOL pflag=true;
	//判断记录的时间是否在设定的范围内
	if(time1.GetYear()>atoi(LPCSTR(year))||time2.GetYear()<atoi(LPCSTR(year)))
		pflag=false;
	else if(time1.GetYear()==atoi(LPCSTR(year)))
	{
		if(time1.GetMonth()>atoi(LPCSTR(month)))
			pflag=false;
		else if(time1.GetMonth()==atoi(LPCSTR(month)))
		{
			if(time1.GetDay()>atoi(LPCSTR(day)))
				pflag=false;
		}
	}
	else if(time2.GetYear()==atoi(LPCSTR(year)))
	{
		if(time2.GetMonth()<atoi(LPCSTR(month)))
			pflag=false;
		else if(time2.GetMonth()==atoi(LPCSTR(month)))
		{
			if(time2.GetDay()<atoi(LPCSTR(day)))
				pflag=false;
		}
	}
	return pflag;
}

⌨️ 快捷键说明

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