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

📄 mainfrm.cpp

📁 本程序使用Visual C++6.0编写
💻 CPP
字号:
// MainFrm.cpp : implementation of the CMainFrame class
//

#include "stdafx.h"
#include "Sjsys.h"
#include "PassModifyDlg.h"
#include "EmployeeAddim.h"
#include "NetStrategyDlg.h"
#include "RecordDLg.h"
#include "DeviceManagermentDlg.h"
#include "ReportDlg.h"
#include "NetFlow.h"
#include "FlowReport.h"
#include "UserAddin.h"
#include "LoginDlg.h"
#include "MyCrypt.h"


#include "MainFrm.h"

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

/////////////////////////////////////////////////////////////////////////////
// CMainFrame

IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)

BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
	//{{AFX_MSG_MAP(CMainFrame)
	ON_WM_CREATE()
	ON_COMMAND(IDM_SYS_PASSWMODIFY, OnSysPasswmodify)
	ON_COMMAND(IDM_SYS_ENPLOYEEMANA, OnSysEnployeemana)
	ON_COMMAND(IDM_SYS_LOGOUT, OnSysLogout)
	ON_COMMAND(IDM_SET_SYSPARA, OnSetSyspara)
	ON_COMMAND(IDM_SET_MONITOR, OnNetStrategySet)
	ON_WM_CLOSE()
	ON_COMMAND(IDM_SET_RECORD, OnSetRecord)
	ON_WM_CONTEXTMENU()
	ON_COMMAND(IDM_SCAN_LIULIANG, OnScanLiuliang)
	ON_COMMAND(IDM_SCAN_BAOBIAO, OnScanBaobiao)
	ON_COMMAND(IDM_SCAN_LIULIANGBAOBIAO, OnScanLiuliangbaobiao)
	ON_COMMAND(IDM_SET_SAVE, OnSetSave)
	ON_COMMAND(IDM_SYS_USER, OnSysUser)
	ON_COMMAND(ID_FILE_NEW, OnFileNew)
	ON_WM_INITMENU()
	ON_WM_DRAWITEM()
	ON_WM_MEASUREITEM()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

static UINT indicators[] =
{
	ID_SEPARATOR,           // status line indicator
	//ID_INDICATOR_CAPS,
	ID_INDICATOR_FLOW,      //显示用户上网流量
	//ID_INDICATOR_NUM,
	//ID_INDICATOR_SCRL,
};

/////////////////////////////////////////////////////////////////////////////
// CMainFrame construction/destruction

CMainFrame::CMainFrame()
{
	// TODO: add member initialization code here
	
}

CMainFrame::~CMainFrame()
{
}


int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
		| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
		!m_wndToolBar.LoadToolBar(IDR_TOOLBAR1))
	{
		TRACE0("Failed to create toolbar\n");
		return -1;      // fail to create
	}

	if (!m_wndStatusBar.Create(this) ||
		!m_wndStatusBar.SetIndicators(indicators,
		  sizeof(indicators)/sizeof(UINT)))
	{
		TRACE0("Failed to create status bar\n");
		return -1;      // fail to create
	}

	// TODO: Delete these three lines if you don't want the toolbar to
	//  be dockable
	m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
	EnableDocking(CBRS_ALIGN_ANY);
	DockControlBar(&m_wndToolBar);

	m_menu.SetImageLeft(IDB_MENUBITMAP);
	m_menu.SetHighLightColor(RGB(0,0,127));
	m_menu.SetTextColor(RGB(0,0,225));
	m_menu.SetBackColor(RGB(110,123,150));

	SetClassLong(m_hWnd,GCL_HICON,(LONG)LoadIcon(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDI_MAINFRAMEICON)));
	//SetClassLong(m_hWnd,GCL_HBRBACKGROUND,(LONG)GetStockObject(BLACK_BRUSH));
	return 0;
}

BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
	if( !CFrameWnd::PreCreateWindow(cs) )
		return FALSE;
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs
    cs.style&=~FWS_ADDTOTITLE;
	cs.lpszName="网络审计系统";
	return TRUE;
}

/////////////////////////////////////////////////////////////////////////////
// CMainFrame diagnostics

#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
	CFrameWnd::AssertValid();
}

void CMainFrame::Dump(CDumpContext& dc) const
{
	CFrameWnd::Dump(dc);
}

#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CMainFrame message handlers


BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext) 
{
	// TODO: Add your specialized code here and/or call the base class
	if(m_wndSplitter.CreateStatic(this,1,2)==NULL) 
              return FALSE; 
     //将CLeftTreeView连接到0行0列窗格上 
     m_wndSplitter.CreateView(0,0,RUNTIME_CLASS(CLeftTreeView),CSize(220,200), pContext); 

     //将CSjsysView连接到0行1列
     m_wndSplitter.CreateView(0,1,RUNTIME_CLASS(CSjsysView),CSize(100,100),pContext); 
     
	
/*	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000); 
	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}*/
     return TRUE; 
//	return CFrameWnd::OnCreateClient(lpcs, pContext);
}



void CMainFrame::OnSysPasswmodify() 
{
	// TODO: Add your command handler code here
	CPassModifyDlg passmodify;
	passmodify.DoModal();
}


void CMainFrame::OnSysEnployeemana() 
{
	// TODO: Add your command handler code here
	CEmployeeAddim employee;
	employee.DoModal();
}

void CMainFrame::OnSysLogout() 
{
	// TODO: Add your command handler code here
	CFrameWnd::ShowWindow(SW_HIDE);
    //if(MessageBox("请注意:用户名或者用户密码为空!")==IDOK)
	CLoginDlg login; //CLoginDialog为登陆对话框
	int nLogin; 
    bool IsPass=false;
	login.m_sUser=""; 
	login.m_sPass="";	
	UpdateData(true);
	nLogin=login.DoModal(); //显示 
	if(nLogin==IDOK) 
	{ 
			
		//CString tUser=login.m_sUser; //这里获得输入的帐号和密码 
		  CString tPass; 
		  CString SQLStr;
		  if((login.m_sUser!="") && (login.m_sPass!=""))
          {
			tPass=CMyCrypt::MyEncrypt(login.m_sPass,123);  //解密
			SQLStr.Format("select * from user1 where Name='%s' and Password='%s'",login.m_sUser,tPass);
		    pDetailRecordset.CreateInstance(__uuidof(Recordset));
			// AfxMessageBox(SQLStr); 
			try
			{
				//从数据库中寻找用户名和密码
			        //打开数据集,按照用户名和密码到数据库的对应表中查找
			
 		        	pDetailRecordset->Open(_bstr_t(SQLStr),
						                ((CSjsysApp*)AfxGetApp())->pConnection.GetInterfacePtr(),
										   adOpenDynamic, 
										   adLockOptimistic,
										   adCmdText); 
					if (!pDetailRecordset->adoEOF) 	
					{
				      // 若登陆认证成功,重新显示主窗口。
					  IsPass=true;
				      CFrameWnd::ShowWindow(SW_SHOW);
					}
			}
			
	        catch(_com_error *e)
			{
		        CString  errormessage;
		        errormessage.Format("打开记录集失败!\r\n错误信息:%s",e->ErrorMessage());
	            AfxMessageBox(errormessage);
		        return;
			} 
			pDetailRecordset->Close();

         }
		else  
			AfxMessageBox("请注意:用户名或者用户密码为空!");
		}
	if(!IsPass)
	{
	  AfxMessageBox("认证失败,系统即将退出!");
	  CFrameWnd::OnClose(); //如果取消登陆,则登陆失败,关闭主窗体 
	}
}

void CMainFrame::OnSetSyspara() 
{
	// TODO: Add your command handler code here
	CDeviceManagermentDlg dlg;
	dlg.DoModal();
}

void CMainFrame::OnNetStrategySet() 
{
	// TODO: Add your command handler code here
	CNetStrategyDlg dlg;
	dlg.DoModal();
}

CLeftTreeView * CMainFrame::GetLeftPane()
{
	CWnd *pWnd = m_wndSplitter.GetPane(0,0);
    CLeftTreeView *pView=DYNAMIC_DOWNCAST(CLeftTreeView,pWnd);
	return pView;
}

CSjsysView * CMainFrame::GetRightPane()
{
	CWnd *pWnd = m_wndSplitter.GetPane(0,1);
    CSjsysView *pView=DYNAMIC_DOWNCAST(CSjsysView,pWnd);
	return pView;
}

void CMainFrame::OnClose() 
{
	// TODO: Add your message handler code here and/or call default
	int i=MessageBox("确定要离开吗?","离开确认对话框", MB_YESNO|MB_ICONQUESTION );
	if(IDNO ==i)
		return;
	CFrameWnd::OnClose();
}

void CMainFrame::OnSetRecord() 
{
	// TODO: Add your command handler code here
	CRecordDLg dlg;
	dlg.DoModal();
}

void CMainFrame::OnContextMenu(CWnd* pWnd, CPoint point) 
{
	// TODO: Add your message handler code her
	RECT  m_Rect;
	RECT  m_wndRect;
    CLeftTreeView *pLeftView = GetLeftPane();
	CTreeCtrl &m_TreeCtrl= pLeftView->GetTreeCtrl();
	//获取树控件窗口的位置和大小
    m_TreeCtrl.GetWindowRect(&m_wndRect);
	HTREEITEM CurItem = m_TreeCtrl.GetFirstVisibleItem();
	while (CurItem!=NULL)
	{
		//获取当前结点的矩形位置
        m_TreeCtrl.GetItemRect(CurItem,&m_Rect,1);
		//如果当前鼠标点位于该节点的举行区域内,则执行以下代码
		if((point.x > m_wndRect.left+m_Rect.left-25)
			&&(point.x < m_wndRect.left+m_Rect.right)
			&&(point.x < m_wndRect.right)
			&&(point.y > m_wndRect.top+m_Rect.top)
			&&(point.y < m_wndRect.top+m_Rect.bottom))
		{
           m_TreeCtrl.SelectItem(CurItem);
		   //MessageBox(m_TreeCtrl.GetItemText(CurItem));
		   HTREEITEM NowRoot=m_TreeCtrl.GetParentItem(CurItem);   //取得父项句柄
           
		   //i=0代表选中为公司
		   //i=1代表选中为部门
		   //i=2代表选中为部室
		   //i=3代表选中为设备
		   int i=0; 
           while (NowRoot!=NULL)
		   {
	          i++;
              NowRoot=m_TreeCtrl.GetParentItem(NowRoot);
		   }
		   if(m_TreeCtrl.GetItemText(m_TreeCtrl.GetParentItem(CurItem))=="未分类")
			   i=3;
		   if(m_TreeCtrl.GetItemText(CurItem)=="未分类")
			   i=0;
		  CMenu MyTreeMenu;
          if(MyTreeMenu.LoadMenu(IDR_POPMENU))
		  {
			  
			  CMenu *pPopup=MyTreeMenu.GetSubMenu(0);
			  if(i==0)
			  {
                 pPopup->ModifyMenu(0,MF_BYPOSITION,ID_PopUp_New,"新建部门");
                 pPopup->RemoveMenu(2,MF_BYPOSITION);  //隐藏删除项
				 pPopup->RemoveMenu(4,MF_BYPOSITION);  //隐藏分隔符项

				 pPopup->RemoveMenu(ID_PopUp_Properties,MF_BYCOMMAND);  //隐藏属性项
			  }

			  if(i==1)
			  {
                pPopup->ModifyMenu(0,MF_BYPOSITION,ID_PopUp_New,"新建部室");
				 pPopup->RemoveMenu(3,MF_BYPOSITION);  //隐藏分隔符项
				 pPopup->RemoveMenu(4,MF_BYPOSITION);  //隐藏分隔符项
				 pPopup->RemoveMenu(ID_PopUp_Properties,MF_BYCOMMAND);  //隐藏属性项
			     pPopup->RemoveMenu(ID_PopUp_Refresh,MF_BYCOMMAND);    //隐藏刷新项
			  }
			  if(i==2)
			  {
				 pPopup->RemoveMenu(0,MF_BYPOSITION);  //隐藏新建符项
				 pPopup->RemoveMenu(4,MF_BYPOSITION);  //隐藏分隔符项
				 pPopup->RemoveMenu(5,MF_BYPOSITION);  //隐藏分隔符项
				 pPopup->RemoveMenu(ID_PopUp_Properties,MF_BYCOMMAND);  //隐藏属性项
			     pPopup->RemoveMenu(ID_PopUp_Refresh,MF_BYCOMMAND);    //隐藏刷新项
			  }
			  if(i==3)
			  {
				 pPopup->RemoveMenu(0,MF_BYPOSITION);  //隐藏新建符项
				 //pPopup->RemoveMenu(3,MF_BYPOSITION);  //隐藏分隔符项
				 //pPopup->RemoveMenu(4,MF_BYPOSITION);  //隐藏分隔符项
				 //pPopup->RemoveMenu(ID_PopUp_Properties,MF_BYCOMMAND);  //隐藏属性项
			     pPopup->RemoveMenu(ID_PopUp_Refresh,MF_BYCOMMAND);    //隐藏刷新项
			  }

              pPopup->TrackPopupMenu(TPM_LEFTALIGN|TPM_RIGHTBUTTON,
				                     point.x,point.y,this);
			  return;
		  }
		}
		CurItem=m_TreeCtrl.GetNextVisibleItem(CurItem);
	}
	
}

void CMainFrame::OnScanLiuliang() 
{
	// TODO: Add your command handler code here
	CNetFlow  dlg;
	dlg.DoModal();
}

void CMainFrame::OnScanBaobiao() 
{
	// TODO: Add your command handler code here
	CReportDlg dlg;
	dlg.DoModal();
}

void CMainFrame::OnScanLiuliangbaobiao() 
{
	// TODO: Add your command handler code here
	CFlowReport dlg;
	dlg.DoModal();
}

 void CMainFrame::OnSetSave() 
{
	// TODO: Add your command handler code here
	CString strSQL;
	strSQL="SELECT * FROM SysFlag" ;//构造sql语句
	_RecordsetPtr m_pRecordset;
	try
		{
			HRESULT hTRes;
			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))
				{
					TRACE(_T("连接成功!\n"));
			     //	m_pRecordset->AddNew();//添加新的记录
					m_pRecordset->PutCollect("IsUpdate",_variant_t("1"));
					m_pRecordset->Update(); //更新数据库
				   MessageBox("保存配置成功!","保存确认");  //提示信息
				}
				m_pRecordset->Close();
			}
		}
		catch(_com_error e)///捕捉异常
		{
			CString errormessage;
			MessageBox("创建记录集失败!","错误");
		}
}

void CMainFrame::OnSysUser() 
{
	// TODO: Add your command handler code here
	CUserAddin dlg;
	dlg.DoModal();
}

void CMainFrame::OnFileNew() 
{
	// TODO: Add your command handler code here
	
}

void CMainFrame::OnInitMenu(CMenu* pMenu) 
{
	CFrameWnd::OnInitMenu(pMenu);
	
	// TODO: Add your message handler code here
	m_menu.InitMenu(pMenu,IDR_TOOLBAR1,&m_wndToolBar);
}

void CMainFrame::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct) 
{
	// TODO: Add your message handler code here and/or call default
	if(!nIDCtl) m_menu.DrawItem(lpDrawItemStruct);
	CFrameWnd::OnDrawItem(nIDCtl, lpDrawItemStruct);
}

void CMainFrame::OnMeasureItem(int nIDCtl, LPMEASUREITEMSTRUCT lpMeasureItemStruct) 
{
	// TODO: Add your message handler code here and/or call default
	if(!nIDCtl) m_menu.MeasureItem(lpMeasureItemStruct);
	CFrameWnd::OnMeasureItem(nIDCtl, lpMeasureItemStruct);
}




⌨️ 快捷键说明

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