📄 sample1view.cpp
字号:
// sample1View.cpp : implementation of the CSample1View class
//
#include "stdafx.h"
#include "sample1.h"
#include "sample1Set.h"
#include "sample1Doc.h"
#include "sample1View.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CSample1View
IMPLEMENT_DYNCREATE(CSample1View, CDaoRecordView)
BEGIN_MESSAGE_MAP(CSample1View, CDaoRecordView)
//{{AFX_MSG_MAP(CSample1View)
ON_BN_CLICKED(IDC_CLEAR, OnClear)
ON_BN_CLICKED(IDC_ADD, OnAdd)
ON_BN_CLICKED(IDC_DELETE, OnDelete)
ON_BN_CLICKED(IDC_EDIT, OnEdit)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CDaoRecordView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CDaoRecordView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CDaoRecordView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSample1View construction/destruction
CSample1View::CSample1View()
: CDaoRecordView(CSample1View::IDD)
{
//{{AFX_DATA_INIT(CSample1View)
m_pSet = NULL;
//}}AFX_DATA_INIT
// TODO: add construction code here
}
CSample1View::~CSample1View()
{
}
void CSample1View::DoDataExchange(CDataExchange* pDX)
{
CDaoRecordView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSample1View)
DDX_FieldText(pDX, IDC_ID, m_pSet->m_id, m_pSet);
DDX_FieldText(pDX, IDC_NAME, m_pSet->m_name, m_pSet);
DDX_FieldText(pDX, IDC_DEPARTMENT, m_pSet->m_department, m_pSet);
DDX_FieldText(pDX, IDC_AGE, m_pSet->m_age, m_pSet);
DDX_FieldText(pDX, IDC_COMMENT, m_pSet->m_comment, m_pSet);
//}}AFX_DATA_MAP
}
BOOL CSample1View::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CDaoRecordView::PreCreateWindow(cs);
}
void CSample1View::OnInitialUpdate()
{
m_pSet = &GetDocument()->m_sample1Set;
CDaoRecordView::OnInitialUpdate();
GetParentFrame()->RecalcLayout();
ResizeParentToFit();
}
/////////////////////////////////////////////////////////////////////////////
// CSample1View printing
BOOL CSample1View::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CSample1View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CSample1View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CSample1View diagnostics
#ifdef _DEBUG
void CSample1View::AssertValid() const
{
CDaoRecordView::AssertValid();
}
void CSample1View::Dump(CDumpContext& dc) const
{
CDaoRecordView::Dump(dc);
}
CSample1Doc* CSample1View::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CSample1Doc)));
return (CSample1Doc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CSample1View database support
CDaoRecordset* CSample1View::OnGetRecordset()
{
return m_pSet;
}
/////////////////////////////////////////////////////////////////////////////
// CSample1View message handlers
void CSample1View::OnClear()
{
// TODO: Add your control notification handler code here
CWnd* c1;
c1= CWnd::GetDlgItem(IDC_ID);
c1->SetWindowText("");
c1= CWnd::GetDlgItem(IDC_NAME);
c1->SetWindowText("");
c1= CWnd::GetDlgItem(IDC_DEPARTMENT);
c1->SetWindowText("");
c1= CWnd::GetDlgItem(IDC_AGE);
c1->SetWindowText("");
c1= CWnd::GetDlgItem(IDC_COMMENT);
c1->SetWindowText("");
}
void CSample1View::OnAdd()
{
// TODO: Add your control notification handler code here
//判断年龄是否合适
CString strAge;
GetDlgItem(IDC_AGE)->GetWindowText(strAge);
int nAge = atoi(strAge.GetBuffer(0));
if(nAge<0 || nAge>120)
{
AfxMessageBox("输入的年龄不符合实际!");
return;
}
//呈增加状态
m_pSet->AddNew();
UpdateData();
//更新数据库
m_pSet->Update();
//重新获得数据
m_pSet->Requery();
UpdateData(FALSE);
}
void CSample1View::OnDelete()
{
// TODO: Add your control notification handler code here
//发出删除命令
m_pSet->Delete();
//重新获得记录集
m_pSet->Requery();
UpdateData(FALSE);
}
void CSample1View::OnEdit()
{
// TODO: Add your control notification handler code here
//判断年龄是否合适
CString strAge;
GetDlgItem(IDC_AGE)->GetWindowText(strAge);
int nAge = atoi(strAge.GetBuffer(0));
if(nAge<0 || nAge>120)
{
AfxMessageBox("输入的年龄不符合实际!");
return;
}
//呈编辑状态
m_pSet->Edit();
UpdateData();
//更新数据库
m_pSet->Update();
//重新获得记录集
m_pSet->Requery();
UpdateData(FALSE);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -