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

📄 contentview.cpp

📁 学生信息管理系统,具体内容,用VC6.0,MFC,成绩管理系统
💻 CPP
字号:
// ContentView.cpp : implementation file
//

#include "stdafx.h"
#include "ERSDemo.h"
#include "ContentView.h"
#include "MainFrm.h"

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

/////////////////////////////////////////////////////////////////////////////
// CContentView

IMPLEMENT_DYNCREATE(CContentView, CTreeView)

CContentView::CContentView()
{
}

CContentView::~CContentView()
{
}


BEGIN_MESSAGE_MAP(CContentView, CTreeView)
	//{{AFX_MSG_MAP(CContentView)
	ON_WM_CREATE()
	ON_WM_LBUTTONDBLCLK()
	ON_NOTIFY_REFLECT(TVN_SELCHANGED, OnSelchanged)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CContentView drawing

void CContentView::OnDraw(CDC* pDC)
{
	CDocument* pDoc = GetDocument();
	// TODO: add draw code here
}

/////////////////////////////////////////////////////////////////////////////
// CContentView diagnostics

#ifdef _DEBUG
void CContentView::AssertValid() const
{
	CTreeView::AssertValid();
}

void CContentView::Dump(CDumpContext& dc) const
{
	CTreeView::Dump(dc);
}
#endif //_DEBUG


int CContentView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CTreeView::OnCreate(lpCreateStruct) == -1)
		return -1;

	return 0;
}

void CContentView::OnInitialUpdate() 
{
	CTreeView::OnInitialUpdate();
	
	CMainFrame * pMainFrame = (CMainFrame *)AfxGetMainWnd();

	pMainFrame->m_pContentView = this;
	
	CDepartmentDataSet dsDepartment;
	CEmployeeInfoDataSet dsEmployeeInfo;
	CMappingDataSet dsMapping;

	dsDepartment.m_cnn = pMainFrame->m_conn;
	dsEmployeeInfo.m_cnn = pMainFrame->m_conn;
	dsMapping.m_cnn = pMainFrame->m_conn;

	if (!dsDepartment.LoadData())
	{
		::AfxMessageBox("打开部门数据失败!");
	}	

	int DepartmentID;

	CTreeCtrl & tc = GetTreeCtrl();
	DWORD dwStyle;
	dwStyle = ::GetWindowLong(tc.m_hWnd, GWL_STYLE);
	dwStyle = dwStyle | TVS_HASLINES | TVS_HASBUTTONS | TVS_LINESATROOT;
	::SetWindowLong(tc.m_hWnd, GWL_STYLE, dwStyle);

	TVINSERTSTRUCT tvInsert;
	HTREEITEM hTreeItem;

	while (!dsDepartment.IsEOF())
	{
		tvInsert.hParent = TVI_ROOT;
		tvInsert.hInsertAfter = TVI_LAST;
		tvInsert.item.mask = TVIF_TEXT|TVIF_PARAM;
		CString strName = dsDepartment.GetName();
		tvInsert.item.pszText = strName.GetBuffer(strName.GetLength());
		strName.ReleaseBuffer();
		DepartmentID = dsDepartment.GetID();
		tvInsert.item.lParam = DepartmentID;

		hTreeItem = tc.InsertItem(&tvInsert);	
		
		dsMapping.LoadDataByDepartmentID(DepartmentID);
		while (!dsMapping.IsEOF())
		{
			dsEmployeeInfo.LoadByEmployeeID(dsMapping.GetEmployeeID());
			while (!dsEmployeeInfo.IsEOF())
			{
				tvInsert.hParent = hTreeItem;
				tvInsert.hInsertAfter = TVI_LAST;
				tvInsert.item.mask = TVIF_TEXT|TVIF_PARAM;
				CString strName = dsEmployeeInfo.GetName();
				tvInsert.item.pszText = strName.GetBuffer(strName.GetLength());
				strName.ReleaseBuffer();
				tvInsert.item.lParam = dsEmployeeInfo.GetID();	
				tc.InsertItem(&tvInsert);
				dsEmployeeInfo.MoveNext();
			}
			dsEmployeeInfo.Close();
			dsMapping.MoveNext();
		}
		dsMapping.Close();

		dsDepartment.MoveNext();
	}
	dsDepartment.Close();
}

void CContentView::OnSelchanged(NMHDR* pNMHDR, LRESULT* pResult) 
{
	NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
	// TODO: Add your control notification handler code here
	CMainFrame * pMainFrame = (CMainFrame *)AfxGetMainWnd();
	CTreeCtrl & tc = GetTreeCtrl();

	if (tc.GetParentItem(pNMTreeView->itemNew.hItem) == 0)
	{
		pMainFrame->ClearEmployeeInfo();
	}
	else
	{
		pMainFrame->EmployeeIDChanged(pNMTreeView->itemNew.lParam);
	}
	*pResult = 0;
}


void CContentView::NewDepartment(CString DepartmentName)
{
	CMainFrame * pMainFrame = (CMainFrame *)AfxGetMainWnd();

	CDepartmentCommand dCmd;
	dCmd.m_cnn = pMainFrame->m_conn;
	dCmd.InsertDepartment(DepartmentName);
		

	CDepartmentDataSet dsDepartment;
	dsDepartment.m_cnn = pMainFrame->m_conn;
	dsDepartment.LocateByName(DepartmentName);
	CTreeCtrl & tc = GetTreeCtrl();
	
	int DepartmentID;
	TVINSERTSTRUCT tvInsert;
	
	while (!dsDepartment.IsEOF())
	{
		tvInsert.hParent = TVI_ROOT;
		tvInsert.hInsertAfter = TVI_LAST;
		tvInsert.item.mask = TVIF_TEXT|TVIF_PARAM;
		CString strName = dsDepartment.GetName();
		tvInsert.item.pszText = strName.GetBuffer(strName.GetLength());
		strName.ReleaseBuffer();
		DepartmentID = dsDepartment.GetID();
		tvInsert.item.lParam = DepartmentID;

		tc.InsertItem(&tvInsert);	
		
		dsDepartment.MoveNext();
	}
	dsDepartment.Close();	
}

void CContentView::RenameDepartment(CString NewName)
{
	CTreeCtrl & tc = GetTreeCtrl();
	HTREEITEM hSelItem = tc.GetSelectedItem();
	ASSERT(tc.GetParentItem(hSelItem) == 0);

	TVITEM item;
	TCHAR szText[1024];
	item.hItem = hSelItem;
	item.mask = TVIF_TEXT|TVIF_PARAM;
	item.pszText = szText;
	item.cchTextMax = 1024;

	tc.GetItem(&item);

	CMainFrame * pMainFrame = (CMainFrame *)AfxGetMainWnd();

	CDepartmentCommand dCmd;
	dCmd.m_cnn = pMainFrame->m_conn;
	dCmd.RenameDepartment(NewName, item.lParam);

	tc.SetItemText(hSelItem, NewName);
}

⌨️ 快捷键说明

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