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

📄 recorddlg.cpp

📁 本程序使用Visual C++6.0编写
💻 CPP
📖 第 1 页 / 共 2 页
字号:
								   adLockOptimistic,
								   adCmdText);	
			
			CString maxindex="";
			while(!pDeviceRecordset->adoEOF)
			{
				var = pDeviceRecordset->GetCollect("MaxID");
				if(var.vt != VT_NULL)maxindex=(LPCSTR)_bstr_t(var);
				DeviceRecordIndex=atoi(maxindex);
				break;
			}
			pDeviceRecordset->Close();
	}
	catch(_com_error *e)
	{
		AfxMessageBox(e->ErrorMessage());
	}
    
	 
	//设置列表视图的风格
	m_tree.Expand(item_root,TVE_EXPAND);
	DWORD dwStyle=GetWindowLong(m_tree.m_hWnd ,GWL_STYLE);
	dwStyle|=TVS_HASBUTTONS|TVS_HASLINES|TVS_LINESATROOT;
	::SetWindowLong (m_tree.m_hWnd ,GWL_STYLE,dwStyle);
  //AfxMessageBox("here!");

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

void CRecordDLg::OnClickTree1(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
    HWND hwnd=(HWND)pNMHDR->hwndFrom;
    CTreeCtrl* m_TreeJoint;
     m_TreeJoint=(CTreeCtrl*)FromHandle(hwnd);
	 //找到当前选中的树项
     CPoint   pt;   
     GetCursorPos(&pt);   
     m_TreeJoint->ScreenToClient(&pt);   
     HTREEITEM   item=m_TreeJoint->HitTest(pt);
     CString s=m_TreeJoint->GetItemText(item);

     m_Prop1.m_deviceid=s;
	 m_Prop2.m_deviceid=s;
	 m_Prop1.m_deviceid=s;
	 m_Prop2.m_deviceid=s;
	 m_Prop1.m_deviceid=s;
	 m_Prop2.m_deviceid=s;
     m_Prop1.CProperty1::OnSetActive();
	*pResult = 0;
}

void CRecordDLg::OnInquire() 
{
	// TODO: Add your control notification handler code here
	CInquireDlg  dlg;
    BOOL m_checkstate;
	CString begintime,endtime;
	CString strSQL;
    strSQL="select * from Netconnectdetail ";//构造查询语句
	int index=m_sheet.GetActiveIndex();
	if(IDOK==dlg.DoModal())
	{
		m_checkstate=dlg.m_checkstate;
		if(m_checkstate)
		{
	    	switch(dlg.m_radiostate)
			{
			case 0:
				strSQL="select * from Netconnectdetail where datediff(day,Datetime,getdate())=0";
				break;
			case 1:
				strSQL="select * from Netconnectdetail where datediff(day,Datetime,getdate())<=2 and datediff(day,Datetime,getdate())>=0 ";
				break;
			case 2:
				strSQL="select * from Netconnectdetail where datediff(day,Datetime,getdate())<=6 and datediff(day,Datetime,getdate())>=0 ";
				break;
			case 3:
				strSQL="select * from Netconnectdetail where datediff(day,Datetime,getdate())<=30 and datediff(day,Datetime,getdate())>=0 ";
				break;
			}
		}
		else
		{
          begintime=TimeToString(dlg.m_BeginMonth);
		  begintime+=dlg.m_BeginH;
		  endtime=TimeToString(dlg.m_EndMonth);
		  endtime+=dlg.m_EndH;
		  strSQL.Format("select * from Netconnectdetail where Datetime>='%s' and Datetime<'%s'",begintime,endtime);
		}
	}
	else
		return;

   switch(index)
	{
	case 0:
		strSQL+="and Name='浏览网页'";
		m_Prop1.m_list.DeleteAllItems();//清空列表框
		break;
	case 1:
		strSQL+="and (Name='发邮件' or Name='发邮件')";
		m_Prop2.m_list.DeleteAllItems();//清空列表框
		break;
    case 2:
		strSQL+="and Name='Telnet'";
		m_Prop3.m_list.DeleteAllItems();//清空列表框
		break;
	case 3:
		strSQL+="and Name='FTP下载'";
		m_Prop4.m_list.DeleteAllItems();//清空列表框
		break;
	case 4:
		strSQL+="and Name='聊天'";
		m_Prop5.m_list.DeleteAllItems();//清空列表框
		break;
	case 5:
		strSQL+="and Name='游戏'";
		m_Prop6.m_list.DeleteAllItems();//清空列表框
		break;
	default:
		break;
	}
	HRESULT hTRes;
	CString str;
	try
	{
		hTRes = m_pRecordset.CreateInstance(_T("ADODB.Recordset"));
		if (SUCCEEDED(hTRes))
		{
			hTRes = m_pRecordset->Open((LPTSTR)strSQL.GetBuffer(130),
			((CSjsysApp*)AfxGetApp())->pConnection.GetInterfacePtr(),
					adOpenDynamic,adLockPessimistic,adCmdText);//打开查询结果记录集
			if(SUCCEEDED(hTRes))
			{
				//将查询结果插入列表框控件中
				int i=0;
	        	int nItem=0;
		//		
			//	m_Prop2.m_list.DeleteAllItems();//清空列表框
			//	m_Prop3.m_list.DeleteAllItems();//清空列表框
			//	m_Prop4.m_list.DeleteAllItems();//清空列表框
			//	m_Prop5.m_list.DeleteAllItems();//清空列表框
			//	m_Prop6.m_list.DeleteAllItems();//清空列表框
				while(!(m_pRecordset->adoEOF))
				{
			    	switch(index)
					{
						case 0:
							nItem=m_Prop1.m_list.InsertItem(i,(LPCSTR)_bstr_t(m_pRecordset->GetCollect("ID")));//
							m_Prop1.m_list.SetItemText(nItem,1,(LPCSTR)_bstr_t(m_pRecordset->GetCollect("Datetime")));
							m_Prop1.m_list.SetItemText(nItem,2,(LPCSTR)_bstr_t(m_pRecordset->GetCollect("Deviceid")));
							str=(LPCSTR)_bstr_t(m_pRecordset->GetCollect("Status"));
							if(str=="1")
								str="放行";
							else
								str="禁止";
							m_Prop1.m_list.SetItemText(nItem,3,str); //
							m_Prop1.m_list.SetItemText(nItem,4,(LPCSTR)_bstr_t(m_pRecordset->GetCollect("Descr"))); 
							break;
						case 1:
							nItem=m_Prop2.m_list.InsertItem(i,(LPCSTR)_bstr_t(m_pRecordset->GetCollect("ID")));//
							m_Prop2.m_list.SetItemText(nItem,1,(LPCSTR)_bstr_t(m_pRecordset->GetCollect("Datetime")));
							m_Prop2.m_list.SetItemText(nItem,2,(LPCSTR)_bstr_t(m_pRecordset->GetCollect("Deviceid")));
							m_Prop2.m_list.SetItemText(nItem,3,str);
							str=(LPCSTR)_bstr_t(m_pRecordset->GetCollect("Status"));
							if(str=="1")
								str="放行";
							else
								str="禁止";
							m_Prop2.m_list.SetItemText(nItem,4,str); //
							m_Prop2.m_list.SetItemText(nItem,5,(LPCSTR)_bstr_t(m_pRecordset->GetCollect("Descr"))); 
							break;
						case 2:
							nItem=m_Prop3.m_list.InsertItem(i,(LPCSTR)_bstr_t(m_pRecordset->GetCollect("ID")));//
							m_Prop3.m_list.SetItemText(nItem,1,(LPCSTR)_bstr_t(m_pRecordset->GetCollect("Datetime")));
							m_Prop3.m_list.SetItemText(nItem,2,(LPCSTR)_bstr_t(m_pRecordset->GetCollect("Deviceid")));
							str=(LPCSTR)_bstr_t(m_pRecordset->GetCollect("Status"));
							if(str=="1")
								str="放行";
							else
								str="禁止";
							m_Prop3.m_list.SetItemText(nItem,3,str); //
							m_Prop3.m_list.SetItemText(nItem,4,(LPCSTR)_bstr_t(m_pRecordset->GetCollect("Descr"))); 
							break;
						case 3:
							nItem=m_Prop4.m_list.InsertItem(i,(LPCSTR)_bstr_t(m_pRecordset->GetCollect("ID")));//
							m_Prop4.m_list.SetItemText(nItem,1,(LPCSTR)_bstr_t(m_pRecordset->GetCollect("Datetime")));
							m_Prop4.m_list.SetItemText(nItem,2,(LPCSTR)_bstr_t(m_pRecordset->GetCollect("Deviceid")));
							str=(LPCSTR)_bstr_t(m_pRecordset->GetCollect("Status"));
							if(str=="1")
								str="放行";
							else
								str="禁止";
							m_Prop4.m_list.SetItemText(nItem,3,str); //
							m_Prop4.m_list.SetItemText(nItem,4,(LPCSTR)_bstr_t(m_pRecordset->GetCollect("Descr"))); 
							break;
						case 4:
							nItem=m_Prop5.m_list.InsertItem(i,(LPCSTR)_bstr_t(m_pRecordset->GetCollect("ID")));//
							m_Prop5.m_list.SetItemText(nItem,1,(LPCSTR)_bstr_t(m_pRecordset->GetCollect("Datetime")));
							m_Prop5.m_list.SetItemText(nItem,2,(LPCSTR)_bstr_t(m_pRecordset->GetCollect("Deviceid")));
							str=(LPCSTR)_bstr_t(m_pRecordset->GetCollect("Status"));
							if(str=="1")
								str="放行";
							else
								str="禁止";
							m_Prop5.m_list.SetItemText(nItem,3,str); //
							m_Prop5.m_list.SetItemText(nItem,4,(LPCSTR)_bstr_t(m_pRecordset->GetCollect("Descr"))); 
							break;
						case 5:
							nItem=m_Prop6.m_list.InsertItem(i,(LPCSTR)_bstr_t(m_pRecordset->GetCollect("ID")));//
							m_Prop6.m_list.SetItemText(nItem,1,(LPCSTR)_bstr_t(m_pRecordset->GetCollect("Datetime")));
							m_Prop6.m_list.SetItemText(nItem,2,(LPCSTR)_bstr_t(m_pRecordset->GetCollect("Deviceid")));
							str=(LPCSTR)_bstr_t(m_pRecordset->GetCollect("Status"));
							if(str=="1")
								str="放行";
							else
								str="禁止";
							m_Prop6.m_list.SetItemText(nItem,3,str); //
							m_Prop6.m_list.SetItemText(nItem,4,(LPCSTR)_bstr_t(m_pRecordset->GetCollect("Descr"))); 
							break;
						default:
							break;
					}
					m_pRecordset->MoveNext();
					i++;
				}
			}
		}
	}	
	catch(_com_error e)///捕捉异常
	{
		CString errormessage;
		MessageBox("创建记录集失败!","错误");
	}
	m_pRecordset->Close();
	UpdateData(false);//更新对话框数据
}

void CRecordDLg::OnRefresh() 
{
	// TODO: Add your control notification handler code here
	int index=m_sheet.GetActiveIndex();
	switch(index)
	{
	case 0:
		m_Prop1.RefreshData();
		break;
	case 1:
		m_Prop2.RefreshData();
		break;
    case 2:
		m_Prop3.RefreshData();
		break;
	case 3:
		m_Prop4.RefreshData();
		break;
	case 4:
		m_Prop5.RefreshData();
		break;
	case 5:
		m_Prop6.RefreshData();
		break;
	default:
		break;
	}
}

void CRecordDLg::OnDelete() 
{
	// TODO: Add your control notification handler code here
	int index=m_sheet.GetActiveIndex();
	int i;
	CString str;
	switch(index)
		{
		case 0:
			i=m_Prop1.GetIndex();
			if(i==-1)
			{
				MessageBox("请选择一项在修改!","提示",MB_ICONINFORMATION);
				return ;
			}
			str=m_Prop1.m_list.GetItemText(i,0);
			m_Prop1.m_list.DeleteItem(i);
			break;
		case 1:
			i=m_Prop2.GetIndex();
			if(i==-1)
			{
				MessageBox("请选择一项在修改!","提示",MB_ICONINFORMATION);
				return ;
			}
			str=m_Prop2.m_list.GetItemText(i,0);
			m_Prop2.m_list.DeleteItem(i);
			break;
		case 2:
			i=m_Prop3.GetIndex();
			if(i==-1)
			{
				MessageBox("请选择一项在修改!","提示",MB_ICONINFORMATION);
				return ;
			}
			str=m_Prop3.m_list.GetItemText(i,0);
			m_Prop3.m_list.DeleteItem(i);
			break;
		case 3:
			i=m_Prop4.GetIndex();
			if(i==-1)
			{
				MessageBox("请选择一项在修改!","提示",MB_ICONINFORMATION);
				return ;
			}
			str=m_Prop4.m_list.GetItemText(i,0);
			m_Prop4.m_list.DeleteItem(i);
			break;
		case 4:
			i=m_Prop5.GetIndex();
			if(i==-1)
			{
				MessageBox("请选择一项在修改!","提示",MB_ICONINFORMATION);
				return ;
			}
			str=m_Prop5.m_list.GetItemText(i,0);
			m_Prop5.m_list.DeleteItem(i);
			break;
		case 5:
			i=m_Prop6.GetIndex();
			if(i==-1)
			{
				MessageBox("请选择一项在修改!","提示",MB_ICONINFORMATION);
				return ;
			}
			str=m_Prop6.m_list.GetItemText(i,0);
			m_Prop6.m_list.DeleteItem(i);
			break;
		default:
			break;
		}
	    _variant_t RecordsAffected;
		CString strSQL;//构造删除记录的sql语句
    	strSQL.Format("DELETE FROM Netconnectdetail WHERE ID='%s'",str);
   		(((CSjsysApp*)AfxGetApp())->pConnection)->Execute((_bstr_t)strSQL,&RecordsAffected,adCmdText);
		MessageBox("删除成功!","提示");
}

void CRecordDLg::OnClear() 
{
	// TODO: Add your control notification handler code here
	int index=m_sheet.GetActiveIndex();
	if(IDYES==AfxMessageBox("此项操作将删除存盘中的全部数据,是否继续?", MB_YESNO|MB_ICONQUESTION ))
	{
		switch(index)
		{
		case 0:
			m_Prop1.m_list.DeleteAllItems();
			break;
		case 1:
			m_Prop2.m_list.DeleteAllItems();
			break;
		case 2:
			m_Prop3.m_list.DeleteAllItems();
			break;
		case 3:
			m_Prop4.m_list.DeleteAllItems();
			break;
		case 4:
			m_Prop5.m_list.DeleteAllItems();
			break;
		case 5:
			m_Prop6.m_list.DeleteAllItems();
			break;
		default:
			break;
		}
		_variant_t RecordsAffected;
		CString strSQL="TRUNCATE TABLE Netconnectdetail";//构造删除记录的sql语句
   		(((CSjsysApp*)AfxGetApp())->pConnection)->Execute((_bstr_t)strSQL,&RecordsAffected,adCmdText);
		MessageBox("删除成功!","提示");
	}
}
CString CRecordDLg::TimeToString(COleDateTime ct)
{
    CString str;
	str.Format("%d-%d-%d ",ct.GetYear(),ct.GetMonth(),ct.GetDay());
	return str;
}

⌨️ 快捷键说明

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