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

📄 mydbdoc.cpp

📁 这个小例子可以查询雇员的平均工资和基本信息
💻 CPP
字号:
// mydbDoc.cpp : implementation of the CMydbDoc class
//

#include "stdafx.h"
#include "mydb.h"
#include "DepartNameList.h"
#include "mydbSet.h"
#include "mydbDoc.h"

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

/////////////////////////////////////////////////////////////////////////////
// CMydbDoc

IMPLEMENT_DYNCREATE(CMydbDoc, CDocument)

BEGIN_MESSAGE_MAP(CMydbDoc, CDocument)
	//{{AFX_MSG_MAP(CMydbDoc)
	ON_COMMAND(ID_RECORD_ADDNEW, OnRecordAddnew)
	ON_COMMAND(ID_RECORD_DELETE, OnRecordDelete)
	ON_COMMAND(ID_QUERY, OnQuery)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMydbDoc construction/destruction

CMydbDoc::CMydbDoc()
{
	// TODO: add one-time construction code here

}

CMydbDoc::~CMydbDoc()
{
}

BOOL CMydbDoc::OnNewDocument()
{
	if (!CDocument::OnNewDocument())
		return FALSE;
	m_SelectedDepartName="ALL";

	// TODO: add reinitialization code here
	// (SDI documents will reuse this document)

	m_bInAdding=FALSE;
	

	return TRUE;
}



/////////////////////////////////////////////////////////////////////////////
// CMydbDoc diagnostics

#ifdef _DEBUG
void CMydbDoc::AssertValid() const
{
	CDocument::AssertValid();
}

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

/////////////////////////////////////////////////////////////////////////////
// CMydbDoc commands

void CMydbDoc::OnRecordAddnew() 
{
	// TODO: Add your command handler code here
	
	CRecordView*pView;
	POSITION pos=GetFirstViewPosition();
	pView=(CRecordView*)GetNextView(pos);

	if(m_bInAdding)
		pView->OnMove(ID_RECORD_FIRST);
	if(!m_mydbSet.CanAppend()){
		AfxMessageBox("You can't add a newrecord tothis database!");
		return;
	}
	try{

		m_mydbSet.AddNew();
	}
	catch(CDBException*e){
			AfxMessageBox(e->m_strError);
	}
	m_bInAdding=TRUE;
	pView->UpdateData(FALSE);

}

void CMydbDoc::OnRecordDelete() 
{
	// TODO: Add your command handler code here

	CRecordView*pView;
	POSITION pos=GetFirstViewPosition();
	pView=(CRecordView*)GetNextView(pos);
	try{
		m_mydbSet.Delete();
	}
	catch(CDBException*e){
			AfxMessageBox(e->m_strError);
			return;
	}
	m_mydbSet.MoveNext();
		if(m_mydbSet.IsEOF())
		m_mydbSet.MoveLast();
		if(m_mydbSet.IsBOF())
		m_mydbSet.SetFieldNull(NULL);

	pView->UpdateData(FALSE);
	
}


void CMydbDoc::OnQuery() 
{
	// TODO: Add your command handler code here
	CDepartNameList dialog;
	if(dialog.DoModal()==IDCANCEL)
		return;
	m_SelectedDepartName=dialog.m_SelectedDepartName;
	UpdateAllViews(NULL,SELECT_NEW_DEPART);
	
}

⌨️ 快捷键说明

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