📄 mainfrm.cpp
字号:
}
delete L;
lower = hight;
}while(hight < max);
dm.m_db.Close();
MessageBox("success");
}
void CMainFrame::OnMacth() //匹配(单向、双向)
{
// TODO: Add your command handler code here
database_show match;
CDBVariant varValue;
match.DBConnect();
CRecordset rs(&match.m_db);
CRecordset rs1(&match.m_db);
CRecordset rs2(&match.m_db);
CRecordset rs3(&match.m_db);
CString l_time;
CString b_time;
CString strSQL;
rs.Open(CRecordset::dynaset,"select * from frequency");
if(rs.GetRecordCount()!=0)
rs.MoveFirst();
else
{
MessageBox("频繁项集为空");
return;
}
while(!rs.IsEOF())
{
int temp = 0;
rs.GetFieldValue(temp,varValue);
b_time.Format("%d-%d-%d %d:%d:%d",varValue.m_pdate->year,varValue.m_pdate->month,varValue.m_pdate->day,
varValue.m_pdate->hour,varValue.m_pdate->minute,varValue.m_pdate->second);
rs.GetFieldValue(1,varValue);
l_time.Format("%d",varValue.m_iVal);
//根据频繁项集搜索格式化后的数据库表,得到<源IP,目的IP,区域号>三元组,按照代理节点是出、入度保存到不同的链表
rs1.Open(CRecordset::dynaset,"select * from src_pck where b_time = '" + b_time + "' and l_time = '" + l_time +"'");
if(rs1.GetRecordCount()!=0)
rs1.MoveFirst();
struct p_node *in_head = new p_node;
in_head->next = NULL;
struct p_node *out_head = new p_node;
out_head->next = NULL;
while(!rs1.IsEOF())
{
struct p_node *p = new p_node;
rs1.GetFieldValue(1,varValue);
p->p_src_ip = varValue.m_pstring->GetBuffer(1);
rs1.GetFieldValue(2,varValue);
p->p_dst_ip = varValue.m_pstring->GetBuffer(1);
rs1.GetFieldValue(5,varValue);
p->zone = varValue.m_chVal;
rs2.Open(CRecordset::dynaset,"select * from agent where a_ip = '" + p->p_src_ip + "'");
if(rs2.GetRecordCount()!=0)//被匹配元组的源IP是代理节点,保存所处代理集合编号
{
rs2.MoveFirst();
rs2.GetFieldValue(1,varValue);
p->a_zone = varValue.m_chVal;
p->next = out_head->next;
out_head->next = p;
}
else //被匹配元组的目的IP是代理节点,保存所处代理集合编号
{
rs3.Open(CRecordset::dynaset,"select * from agent where a_ip = '" + p->p_dst_ip + "'");
if(rs3.GetRecordCount()!=0)
{
rs3.MoveFirst();
rs3.GetFieldValue(1,varValue);
p->a_zone = varValue.m_chVal;
p->next = in_head->next;
in_head->next = p;
}
rs3.Close();
}
rs2.Close();
rs1.MoveNext();
}
rs1.Close();
//两两单向匹配
struct p_node *in_p = in_head->next;
while(in_p != NULL)
{
struct p_node *out_p = out_head->next;
while(out_p != NULL)
{
if(in_p->a_zone == out_p->a_zone && in_p->zone != out_p->zone)
{
//保存信息到定位结果表
strSQL.Format("insert into location(ip1,zone1,agent1,ip2,zone2,agent2,a_zone,b_time,l_time) values('%s','%d','%s','%s','%d','%s','%d','%s','%s')",
in_p->p_src_ip,in_p->zone,in_p->p_dst_ip,out_p->p_dst_ip,out_p->zone,out_p->p_src_ip,out_p->a_zone,b_time,l_time);
match.m_db.ExecuteSQL(strSQL);
}
out_p = out_p->next;
}
in_p = in_p->next;
}
//释放链表
while(in_head->next != NULL)
{
struct p_node *temp = in_head->next;
in_head->next = in_head->next->next;
delete temp;
}
while(out_head->next != NULL)
{
struct p_node *temp = out_head->next;
out_head->next = out_head->next->next;
delete temp;
}
delete in_head;
delete out_head;
rs.MoveNext();
}
MessageBox("success");//执行结束标志
rs.Close();
/////////////////////////////////////////////////////////////////////////////////////
//双向匹配
CString ip1,ip2,zone1,zone2;
while(1)
{
rs.Open(CRecordset::dynaset,"select * from location where sign is null");
if(rs.GetRecordCount() != 0)
{
rs.MoveFirst();
int temp = 0;
rs.GetFieldValue(temp,varValue);
ip1 = varValue.m_pstring->GetBuffer(1);
rs.GetFieldValue(1,varValue);
zone1.Format("%d",varValue.m_chVal);
rs.GetFieldValue(3,varValue);
ip2 = varValue.m_pstring->GetBuffer(1);
rs.GetFieldValue(4,varValue);
zone2.Format("%d",varValue.m_chVal);
rs.GetFieldValue(7,varValue);
b_time.Format("%d-%d-%d %d:%d:%d",varValue.m_pdate->year,varValue.m_pdate->month,varValue.m_pdate->day,
varValue.m_pdate->hour,varValue.m_pdate->minute,varValue.m_pdate->second);
rs.GetFieldValue(8,varValue);
l_time.Format("%d",varValue.m_iVal);
rs1.Open(CRecordset::dynaset,"select * from location where sign is null and ip1 = '" + ip2 + "' and zone1 = '" + zone2 + "' and ip2 = '" + ip1 + "' and zone2 = '" + zone1 + "' and b_time = '" + b_time + "' and l_time = '" + l_time + "'");
if(rs1.GetRecordCount() == 0)
{
strSQL.Format("update location set sign = '0' where ip1 = '" + ip1 + "' and zone1 = '" + zone1 + "' and ip2 = '" + ip2 + "' and zone2 = '" + zone2 + "' and b_time = '" + b_time + "' and l_time = '" + l_time + "'");
match.m_db.ExecuteSQL(strSQL);
}
else
{
strSQL.Format("update location set sign = '1' where ip1 = '" + ip2 + "' and zone1 = '" + zone2 + "' and ip2 = '" + ip1 + "' and zone2 = '" + zone1 + "' and b_time = '" + b_time + "' and l_time = '" + l_time + "' or ip1 = '" + ip1 + "' and zone1 = '" + zone1 + "' and ip2 = '" + ip2 + "' and zone2 = '" + zone2 + "' and b_time = '" + b_time + "' and l_time = '" + l_time + "'");
match.m_db.ExecuteSQL(strSQL);
}
rs1.Close();
rs.Close();
}
else
{
rs.Close();
break;
}
}
MessageBox("pi pei wan cheng");
match.m_db.Close();
}
void CMainFrame::OnFilter()
{
// TODO: Add your command handler code here
pck_filter dlg;
dlg.DoModal();
}
void CMainFrame::Data_Pretreatment()//预处理(数据规格化)
{
// TODO: Add your command handler code here
database_show pre;
pre.DBConnect();
CDBVariant varValue;
CString strSQL;
CRecordset rs(&pre.m_db);
CRecordset rs1(&pre.m_db);
CRecordset rs2(&pre.m_db);
CTime t1(2006, 1, 1, 0, 0, 0);
int temp = 0;
//将冗余的纪录删除,即把源IP或目的IP是代理节点的纪录留下
rs.Open(CRecordset::dynaset,"select src_ip,dst_ip from src_pck where r_sign is null");
if(rs.GetRecordCount()!=0)
{
rs.MoveFirst();
CString src_ip,dst_ip,strSQL;
do
{
rs.GetFieldValue(temp,varValue);
src_ip = varValue.m_pstring->GetBuffer(1);
rs.GetFieldValue(1,varValue);
dst_ip = varValue.m_pstring->GetBuffer(1);
rs1.Open(CRecordset::dynaset,"select * from agent where a_ip = '" + src_ip + "' or a_ip = '" + dst_ip + "'");
if(rs1.GetRecordCount()!=0)
{
strSQL.Format("update src_pck set r_sign = '1' where src_ip = '" + src_ip + "' and dst_ip = '" + dst_ip + "'");
}
else
{
strSQL.Format("update src_pck set r_sign = '0' where src_ip = '" + src_ip + "' and dst_ip = '" + dst_ip + "'");
}
pre.m_db.ExecuteSQL(strSQL);
rs1.Close();
rs.MoveNext();
}while(!rs.IsEOF());
rs.Close();
}
else
{
rs.Close();
//MessageBox("没有未处理的纪录");
}
//strSQL.Format("delete from src_pck where r_sign = '0'"); //删除冗余项
//pre.m_db.ExecuteSQL(strSQL);
////////////////////////////////////////////////////////////////////////////////////////////
//将时间字段由日期类型转换为整型,以便规格
rs.Open(CRecordset::dynaset,"select * from src_pck where b_time_int is null");
if(rs.GetRecordCount() != 0)
{
//CTime t1(2006, 1, 1, 0, 0, 0);
CTimeSpan ts;
CString b_time;
rs.MoveFirst();
do
{
rs.GetFieldValue(3,varValue);
b_time.Format("%d-%d-%d %d:%d:%d",varValue.m_pdate->year,varValue.m_pdate->month,varValue.m_pdate->day,
varValue.m_pdate->hour,varValue.m_pdate->minute,varValue.m_pdate->second);
CTime t2(varValue.m_pdate->year,varValue.m_pdate->month,varValue.m_pdate->day,
varValue.m_pdate->hour,varValue.m_pdate->minute,varValue.m_pdate->second);
ts = t2 - t1 ;
strSQL.Format("update src_pck set b_time_int = '%d' where b_time = '" + b_time + "'",ts.GetTotalSeconds());
pre.m_db.ExecuteSQL(strSQL);
rs.MoveNext();
}while(!rs.IsEOF());
}
rs.Close();
////////////////////////////////////////////////////////////////////////////////////////////////
//规格开始时间和通信时间
int i = 1;
CString sign;
while(1)
{
//rs.Open(CRecordset::dynaset,"select * from src_pck ");
rs.Open(CRecordset::dynaset,"select * from src_pck where sign is null order by b_time");
if(rs.GetRecordCount()!=0)
{
//按开始时间分类(初设范围为3秒)
rs.MoveFirst();
rs.GetFieldValue(6,varValue);
strSQL.Format("update src_pck set sign = '%d' where b_time_int <= '%d' + 3 and b_time_int >= '%d'",i,varValue.m_lVal,varValue.m_lVal);
pre.m_db.ExecuteSQL(strSQL);
//对同一类的数据进行规格
sign.Format("%d",i);
//开始时间的规格(求平均值)
rs1.Open(CRecordset::dynaset,"select max(b_time_int),min(b_time_int) from src_pck where sign = '" + sign + "'");
long max,min;
rs1.MoveFirst();
rs1.GetFieldValue(temp,varValue);
max = varValue.m_lVal;
rs1.GetFieldValue(1,varValue);
min = varValue.m_lVal;
CTimeSpan ts(0,0,0,(max+min)/2);
CTime t = t1 + ts;
//MessageBox(t.Format("%Y-%m-%d %H:%M:%S"));
rs1.Close();
//通信时间的规格
rs1.Open(CRecordset::dynaset,"select * from src_pck where sign = '" + sign + "' order by l_time DESC");
//保存记录到单向链表
struct pre_node *head = new pre_node;
head->next = NULL;
rs1.MoveFirst();
while(!rs1.IsEOF())
{
struct pre_node *p = new pre_node;
rs1.GetFieldValue(1,varValue);
p->src_ip = varValue.m_pstring->GetBuffer(1);
rs1.GetFieldValue(2,varValue);
p->dst_ip = varValue.m_pstring->GetBuffer(1);
rs1.GetFieldValue(4,varValue);
p->l_time = varValue.m_iVal;
rs1.GetFieldValue(5,varValue);
p->zone = varValue.m_chVal;
p->next = head->next;
head->next = p;
rs1.MoveNext();
}
rs1.Close();
//判断
while(head->next != NULL)
{
struct pre_node *q = head->next;
struct pre_node *r = head->next;
while(r->next != NULL)
{
if((r->next->l_time - q->l_time) > 5)//相邻记录的通信时间差超过5s
break;
else
r = r->next;
}
//取l_time的平均值
int average = (q->l_time + r->l_time)/2;
while(q!=r->next)
{
strSQL.Format("insert into dm_pck values('%s','%s','%s','%d','%d')",q->src_ip,q->dst_ip,t.Format("%Y-%m-%d %H:%M:%S"),average,q->zone);
//strSQL.Format("insert into dm_pck(d_src_ip,d_dst_ip,d_l_time,zone_no) values('%s','%s','%d','%d')",q->src_ip,q->dst_ip,average,q->zone);
pre.m_db.ExecuteSQL(strSQL);
q = q->next;
}
//释放节点
q = head->next;
head->next = r->next;
if(q != r)
{
while(q->next != r)
{
struct pre_node *M = q->next;
q->next = q->next->next;
delete M;
}
delete q;
delete r;
}
else
{
delete q;
}
}
delete head;
//开始时间的规格
//rs1.Open(CRecordset::dynaset,"select b_time_int from dm_pck where b_time is null");
}
else
{
rs.Close();
break;
}
i++;
rs.Close();
}
pre.m_db.Close();
}
void CMainFrame::On_Results_show()
{
// TODO: Add your command handler code here
result_show dbdlg;
dbdlg.DoModal();
}
void CMainFrame::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
CTime time;
time = CTime::GetCurrentTime();
CString s = time.Format("%H:%M:%S");
m_wndStatusBar.SetPaneText(m_wndStatusBar.CommandToIndex(ID_SHOW_TIME),s);
CFrameWnd::OnTimer(nIDEvent);
}
void CMainFrame::OnSafeCheck()
{
// TODO: Add your command handler code here
safe_audit sdlg;
sdlg.DoModal();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -