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

📄 databaseview.cpp

📁 一个数据库搜索源代码
💻 CPP
字号:
// DatabaseView.cpp : implementation of the CDatabaseView class
//

#include "stdafx.h"
#include "Database.h"

#include "DatabaseDoc.h"
#include "DatabaseView.h"
#include "DialogData.h"

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

/////////////////////////////////////////////////////////////////////////////
// CDatabaseView

IMPLEMENT_DYNCREATE(CDatabaseView, CFormView)

BEGIN_MESSAGE_MAP(CDatabaseView, CFormView)
	//{{AFX_MSG_MAP(CDatabaseView)
	ON_BN_CLICKED(IDC_BUTTON_FIND, OnButtonFind)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDatabaseView construction/destruction

CDatabaseView::CDatabaseView()
	: CFormView(CDatabaseView::IDD)
{
	//{{AFX_DATA_INIT(CDatabaseView)
	m_ssn = 0.0;
	//}}AFX_DATA_INIT
	// TODO: add construction code here

}

CDatabaseView::~CDatabaseView()
{
}

void CDatabaseView::DoDataExchange(CDataExchange* pDX)
{
	CFormView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDatabaseView)
	DDX_Text(pDX, IDC_EDIT_SSN, m_ssn);
	//}}AFX_DATA_MAP
}

BOOL CDatabaseView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CFormView::PreCreateWindow(cs);
}

void CDatabaseView::OnInitialUpdate()
{
	CFormView::OnInitialUpdate();
	GetParentFrame()->RecalcLayout();
	ResizeParentToFit();

}

/////////////////////////////////////////////////////////////////////////////
// CDatabaseView diagnostics

#ifdef _DEBUG
void CDatabaseView::AssertValid() const
{
	CFormView::AssertValid();
}

void CDatabaseView::Dump(CDumpContext& dc) const
{
	CFormView::Dump(dc);
}

CDatabaseDoc* CDatabaseView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CDatabaseDoc)));
	return (CDatabaseDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CDatabaseView message handlers

void CDatabaseView::OnButtonFind() 
{
	CDatabaseDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);

	//如果数据已打开,则显示数据窗口
	if ( pDoc->IsFileOpen() )
	{
		//将用户输入保存到m_ssn
		UpdateData(TRUE);  

		//创建显示窗口
		CDialogData dlg;
		ASSERT(&dlg != NULL);

		//将数据窗口中Dataset指针设为文档中的Dataset指针
		dlg.m_pSet = pDoc->GetRecSet();

		// 建立过滤字符串
		dlg.m_pSet->m_strFilter.Format("[SSN] = %9.0f", m_ssn);

		// 过滤数据表
		dlg.m_pSet->Requery();

		// 允许数据字段被修改
		dlg.m_pSet->Edit();

		// 如用户单击<保存>,则Update数据表
		if (dlg.DoModal() == IDOK)
			dlg.m_pSet->Update();
	}
	else
		AfxMessageBox("Please open the database file first",
			MB_OK | MB_ICONEXCLAMATION);
}

⌨️ 快捷键说明

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