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

📄 loginfoview.cpp

📁 用于数据挖掘
💻 CPP
📖 第 1 页 / 共 2 页
字号:
		AfxMessageBox("这已经是最后一页了!!");

}

void CLogInfoView::OnCreateuser()
{
	// TODO: 在此添加命令处理程序代码

	try
	{
			m_pUserSet->Open("select distinct UserIP from TableLog",
				theApp.m_pConnection.GetInterfacePtr(),
				adOpenDynamic,
				adLockOptimistic,
				adCmdText);
			m_pFieldsPtr=m_pUserSet->Fields;
			m_pUserSet->MoveFirst();
			CString str;
			for(int i=0;i<m_pUserSet->GetRecordCount();i++)
			{
				m_pFieldPtr=m_pFieldsPtr->Item["UserIP"];
				str=m_pFieldPtr->Value;

				str="Insert into TableUser(UserIP) values('" + str + "')";
				m_pCommand->ActiveConnection=theApp.m_pConnection;
				m_pCommand->CommandText=(_bstr_t)str;
				m_pCommand->CommandType=adCmdText;
				m_pCommand->CommandTimeout=15;
				m_pCommand->Execute(NULL,NULL,adCmdText);

				m_pUserSet->MoveNext();
			}
				
	}
	catch(...)
	{
		AfxMessageBox("读取数据库发生错误!");
	}




}

void CLogInfoView::OnInputlog1()
{
	 //TODO: 在此添加命令处理程序代码
	try
	{
		m_pUserSet->Open("select UserIP,UserLogTime,UserLogIPPort,UserVisitAddress,	UserData1,UserData2 from TableLog1",
			theApp.m_pConnection.GetInterfacePtr(),
			adOpenDynamic,
			adLockOptimistic,
			adCmdText);
		m_pFieldsPtr=m_pUserSet->Fields;

		CString str;
		CStdioFile File;
		File.Open("D:\\greenlog",CFile::modeRead);
		CString strTemp[6];

		while(File.ReadString(str))
		{
			//解析字符串
			AnalysisString1(str,strTemp);

			//将读取出来的格式化后的记录写入数据库
			m_pUserSet->AddNew();
			m_pFieldPtr=m_pFieldsPtr->Item["UserIP"];
			if(strTemp[0].IsEmpty())
				strTemp[0]=" ";
			m_pFieldPtr->Value=(_variant_t)strTemp[0];

			m_pFieldPtr=m_pFieldsPtr->Item["UserLogTime"];
			if(strTemp[1].IsEmpty())
				strTemp[1]=" ";
			m_pFieldPtr->Value=(_variant_t)strTemp[1];

			m_pFieldPtr=m_pFieldsPtr->Item["UserLogIPPort"];
			if(strTemp[2].IsEmpty())
				strTemp[2]=" ";
			m_pFieldPtr->Value=(_variant_t)strTemp[2];

			m_pFieldPtr=m_pFieldsPtr->Item["UserVisitAddress"];
			if(strTemp[3].IsEmpty())
				strTemp[3]=" ";
			m_pFieldPtr->Value=(_variant_t)strTemp[3];
			
			m_pFieldPtr=m_pFieldsPtr->Item["UserData1"];
			if(strTemp[4].IsEmpty())
				strTemp[4]=" ";
			m_pFieldPtr->Value=(_variant_t)strTemp[4];

			m_pFieldPtr=m_pFieldsPtr->Item["UserData2"];
			if(strTemp[5].IsEmpty())
				strTemp[5]=" ";
			m_pFieldPtr->Value=(_variant_t)strTemp[5];

			m_pUserSet->Update();			
		}//end while
		m_pUserSet->Update();
		m_pUserSet->Close();

		GetDocument()->UpdateAllViews(NULL);
		AfxMessageBox("记录添加成功!");
	}
	catch(_com_error *e)
	{
		AfxMessageBox(e->ErrorMessage());
	}
	catch(...)
	{
		AfxMessageBox("访问数据库时服务器发生异常.\n请与系统管理员联系,谢谢使用。");
		return;
	}

}
void CLogInfoView::AnalysisString1(CString _str,CString _strTemp[])
{
	int pos=-1;
	pos=_str.Find(" ",0);
	//得到IP
	_strTemp[0]=_str.Left(pos);
	
	pos=_str.Find("[",0);
	_str=_str.Right(_str.GetLength()-pos-1);
	pos=_str.Find("+",0);
	//得到时间
	_strTemp[1]=_str.Left(pos);
	
	_str=_str.Right(_str.GetLength()-pos-1);
	pos=_str.Find("]",0);
	//得到端口号
	_strTemp[2]=_str.Left(pos);
	
	pos=_str.Find("\"",0);
	_str=_str.Right(_str.GetLength()-pos-1);
	pos=0;
	while(_str.Find("\"",pos+1)!=-1)
		pos=_str.Find("\"",pos+1);
	//得到地址
	_strTemp[3]=_str.Left(pos);

	_str=_str.Right(_str.GetLength()-pos-2);
	pos=_str.Find(" ",0);
	//得到数据1
	_strTemp[4]=_str.Left(pos);

	//得到数据2
	_str=_str.Right(_str.GetLength()-pos-1);
	if(_str.GetAt(0)=='-')
	{
		_strTemp[5]="0";
	}
	else
	{
		_strTemp[5]=_str;
	}	
}


void CLogInfoView::OnModifytime()
{
	// TODO: 在此添加命令处理程序代码
	try
	{

		m_pUserSet->Open("select 编号,UserLogTime,UserVisitTime from TableLog",
			theApp.m_pConnection.GetInterfacePtr(),
			adOpenDynamic,
			adLockOptimistic,
			adCmdText);
		m_pFieldsPtr=m_pUserSet->Fields;
		m_pUserSet->MoveFirst();
		CString str;
		CString strNo;
		CString strTime[4];
		//CString strsql;
		int pos=0;
		while(!m_pUserSet->adoEOF)
		{
			//m_pFieldPtr=m_pFieldsPtr->Item["编号"];
			//strNo.Format("%d",m_pFieldPtr->Value);
			m_pFieldPtr=m_pFieldsPtr->Item["UserLogTime"];
			str=m_pFieldPtr->Value;
			
			pos=0;
			//pos=str.Find("/",0);
			//日子
			//strTime[0]=str.Left(pos); 
			pos=str.Find(":",0);
			strTime[3]=str.Right(str.GetLength()-pos-1);

			//strsql="update  TableLog1  set UserVisitTime=" + str + " where 编号=" +  strNo;


			//m_pCommand->ActiveConnection=theApp.m_pConnection;
			//m_pCommand->CommandText=(_bstr_t)strsql;
			//m_pCommand->CommandType=adCmdText;
			//m_pCommand->CommandTimeout=15;
			//m_pCommand->Execute(NULL,NULL,adCmdText);
			m_pFieldPtr=m_pFieldsPtr->Item["UserVisitTime"];
			m_pFieldPtr->Value=(_variant_t)strTime[3];
			m_pUserSet->Update();
			m_pUserSet->MoveNext();
		}
		//m_pUserSet->Update();
		m_pUserSet->Close();
		AfxMessageBox("修正成功!!");

	}
	catch(...)
	{
		AfxMessageBox("日期格式处理失败!!");
	}
    
}

void CLogInfoView::OnModifyaddress()
{
	// TODO: 在此添加命令处理程序代码
		try
	{

		m_pUserSet->Open("select 编号,UserVisitAddress,UserVisitedAddress from TableLog1",
			theApp.m_pConnection.GetInterfacePtr(),
			adOpenDynamic,
			adLockOptimistic,
			adCmdText);
		m_pFieldsPtr=m_pUserSet->Fields;
		m_pUserSet->MoveFirst();
		CString str;
		int pos=0;
		while(!m_pUserSet->adoEOF)
		{
			m_pFieldPtr=m_pFieldsPtr->Item["UserVisitAddress"];
			str=m_pFieldPtr->Value;
			m_pFieldPtr=m_pFieldsPtr->Item["UserVisitedAddress"];
			
			pos=0;
			pos=str.Find(" ",0);
			str=str.Right(str.GetLength()-pos-1);
			pos=str.Find(" ",0);
			str=str.Left(pos);
			//AfxMessageBox(str);

			//strsql="update  TableLog1  set UserVisitTime=" + str + " where 编号=" +  strNo;


			//m_pCommand->ActiveConnection=theApp.m_pConnection;
			//m_pCommand->CommandText=(_bstr_t)strsql;
			//m_pCommand->CommandType=adCmdText;
			//m_pCommand->CommandTimeout=15;
			//m_pCommand->Execute(NULL,NULL,adCmdText);
			m_pFieldPtr=m_pFieldsPtr->Item["UserVisitedAddress"];
			m_pFieldPtr->Value=(_variant_t)str;
			m_pUserSet->Update();
			m_pUserSet->MoveNext();
		}
		//m_pUserSet->Update();
		m_pUserSet->Close();
		AfxMessageBox("修正成功!!");

	}
	catch(...)
	{
		AfxMessageBox("日期格式处理失败!!");
	}
    

}

void CLogInfoView::OnUserIdentify()
{
	 //TODO: 在此添加命令处理程序代码
	try
	{

		m_pUserSet1->Open("select * from TableUser",
			theApp.m_pConnection.GetInterfacePtr(),
			adOpenDynamic,
			adLockOptimistic,
			adCmdText);

		m_pUserSet->Open("select distinct(UserIP) from TableLog",
			theApp.m_pConnection.GetInterfacePtr(),
			adOpenDynamic,
			adLockOptimistic,
			adCmdText);
		


		m_pFieldsPtr=m_pUserSet->Fields;

		m_pFieldsPtr1=m_pUserSet1->Fields;
		
		m_pUserSet->MoveFirst();
		CString str;
		while(!m_pUserSet->adoEOF)
		{
			m_pUserSet1->AddNew();
			m_pFieldPtr=m_pFieldsPtr->Item["UserIP"];
			m_pFieldPtr1=m_pFieldsPtr1->Item["UserIP"];
			str=m_pFieldPtr->Value;


			m_pFieldPtr1->Value=(_variant_t)str;
			m_pUserSet1->Update();
			m_pUserSet->MoveNext();
		}
		//m_pUserSet->Update();
		m_pUserSet1->Close();
		AfxMessageBox("用户识别成功!!");

	}
	catch(...)
	{
		AfxMessageBox("用户识别失败!!");
	}
}

void CLogInfoView::OnDeletenuser()
{
	// TODO: 在此添加命令处理程序代码
	//不能删除

}

void CLogInfoView::OnSessionIdentify()
{
	// TODO: 在此添加命令处理程序代码
	try
	{
		m_pUserSet->Open("select UserIP from TableUser order by UserIP",
			theApp.m_pConnection.GetInterfacePtr(),
			adOpenDynamic,
			adLockOptimistic,
			adCmdText);
		
		//m_pUserSet1->Open("select * from TableLog",
		//	theApp.m_pConnection.GetInterfacePtr(),
		//	adOpenDynamic,
		//	adLockOptimistic,
		//	adCmdText);

		m_pFieldsPtr=m_pUserSet->Fields;

		//m_pFieldsPtr1=m_pUserSet1->Fields;
		m_pUserSet->MoveFirst();
		CString StrUserIP;
		CString StrSQL;
		int IntSessionIDNo;
		IntSessionIDNo=1;
		CString Str1;
		while(!m_pUserSet->adoEOF)
		{
			m_pFieldPtr=m_pFieldsPtr->Item["UserIP"];
			StrUserIP=m_pFieldPtr->Value;
		
			StrSQL="select * from TableLog where UserIP='" + StrUserIP + "'";
			m_pUserSet1->Open((_variant_t)StrSQL,
				theApp.m_pConnection.GetInterfacePtr(),
				adOpenDynamic,
				adLockOptimistic,
				adCmdText);
			if(m_pUserSet1->adoEOF && m_pUserSet1->BOF)
				break;
			m_pFieldsPtr1=m_pUserSet1->Fields;
			m_pUserSet1->MoveFirst();
			while(!m_pUserSet1->adoEOF)
			{
				//确定sessionIDNo,并写入session号

				m_pFieldPtr1=m_pFieldsPtr1->Item["UserVisitTime"];
				//StrTime1=(_variant_t)m_pFieldPtr1->Value;
				CTime Time1(m_pFieldPtr1->Value);
				m_pFieldPtr1=m_pFieldsPtr1->Item["UserSessionIDNo"];
				Str1.Format("%d",IntSessionIDNo);
				m_pFieldPtr1->Value=(_variant_t)Str1;
				m_pUserSet1->Update();

				m_pUserSet1->MoveNext();
				if(m_pUserSet1->adoEOF) {IntSessionIDNo++;break;}
				m_pFieldPtr1=m_pFieldsPtr1->Item["UserVisitTime"];
				CTime Time2(m_pFieldPtr1->Value);
				int ts;
				ts=(Time2.GetHour()-Time1.GetHour())*60+Time2.GetMinute()-Time1.GetMinute();
				if(ts>30)
					IntSessionIDNo++;

			}
			//m_pUserSet1->Update();
			m_pUserSet1->Close();
			m_pUserSet->MoveNext();
		}
		AfxMessageBox("会话识别完成!!");

	}
	catch(...)
	{
		AfxMessageBox("会话识别失败!!");
	}

}

void CLogInfoView::OnIdentifySameweb()
{
	// TODO: 在此添加命令处理程序代码
	try
	{
		m_pUserSet->Open("select * from TableLog where UserVisitAddress1 like '%/index.html'",
			theApp.m_pConnection.GetInterfacePtr(),
			adOpenDynamic,
			adLockOptimistic,
			adCmdText);
		m_pFieldsPtr=m_pUserSet->Fields;
		m_pFieldPtr=m_pFieldsPtr->Item["UserVisitAddress1"];
		m_pUserSet->MoveFirst();
		CString StrTemp;
		while(!m_pUserSet->adoEOF)
		{
			StrTemp=m_pFieldPtr->Value;
			StrTemp=StrTemp.Left(StrTemp.GetLength()-11);
			m_pFieldPtr->Value=(_variant_t)StrTemp;
			m_pUserSet->Update();
			m_pUserSet->MoveNext();
            
		}
		AfxMessageBox("相同网址识别成功!");
	}
	catch(...)
	{
		AfxMessageBox("相同网址识别失败!");
	}

	

}

⌨️ 快捷键说明

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