【VC开源代码栏目提醒】:本文主要为网学会员提供ContentView.cpp,希望对需要ContentView.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);
}
上一篇:
CONTENTMENU.CPP
下一篇:
大学生汉语写作水平与英语水平相关性研究