📄 mayan20032168view.cpp
字号:
// mayan20032168View.cpp : Cmayan20032168View 类的实现
//
#include "stdafx.h"
#include "mayan20032168.h"
#include "mayan20032168Set.h"
#include "mayan20032168Doc.h"
#include "mayan20032168View.h"
#include ".\mayan20032168view.h"
#include "Deldialog.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// Cmayan20032168View
IMPLEMENT_DYNCREATE(Cmayan20032168View, CRecordView)
BEGIN_MESSAGE_MAP(Cmayan20032168View, CRecordView)
// 标准打印命令
ON_COMMAND(ID_FILE_PRINT, CRecordView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CRecordView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CRecordView::OnFilePrintPreview)
ON_BN_CLICKED(IDC_BUTTON1, OnBnClickedButton1)
ON_BN_CLICKED(IDC_BUTTON2, OnBnClickedButton2)
ON_BN_CLICKED(IDC_BUTTON4, OnBnClickedButton4)
ON_BN_CLICKED(IDC_BUTTON3, OnBnClickedButton3)
END_MESSAGE_MAP()
// Cmayan20032168View 构造/析构
Cmayan20032168View::Cmayan20032168View()
: CRecordView(Cmayan20032168View::IDD)
{
m_pSet = NULL;
// TODO: 在此处添加构造代码
}
Cmayan20032168View::~Cmayan20032168View()
{
}
void Cmayan20032168View::DoDataExchange(CDataExchange* pDX)
{
CRecordView::DoDataExchange(pDX);
// 可以在此处插入 DDX_Field* 函数以将控件“连接”到数据库字段,例如
// DDX_FieldText(pDX, IDC_MYEDITBOX, m_pSet->m_szColumn1, m_pSet)
// DDX_FieldCheck(pDX, IDC_MYCHECKBOX, m_pSet->m_bColumn2, m_pSet);
// 有关更多信息,请参阅 MSDN 和 ODBC 示例
DDX_FieldText(pDX, IDC_EDIT1, m_pSet->m_name,m_pSet);
DDX_FieldText(pDX, IDC_EDIT2, m_pSet->m_num,m_pSet);
DDX_FieldText(pDX, IDC_EDIT3, m_pSet->m_sex,m_pSet);
DDX_FieldText(pDX, IDC_EDIT4, m_pSet->m_age,m_pSet);
DDX_FieldText(pDX, IDC_EDIT6, m_pSet->m_grade,m_pSet);
DDX_FieldText(pDX, IDC_EDIT5, m_pSet->m_money,m_pSet);
DDX_Control(pDX, IDC_EDIT7, m_zhao);
DDX_Control(pDX, IDC_EDIT8, m_shan);
DDX_Control(pDX, IDC_EDIT1, m_name1);
DDX_Control(pDX, IDC_EDIT2, m_num1);
DDX_Control(pDX, IDC_EDIT3, m_sex1);
DDX_Control(pDX, IDC_EDIT4, m_age1);
DDX_Control(pDX, IDC_EDIT6, m_grade1);
DDX_Control(pDX, IDC_EDIT5, m_money1);
}
BOOL Cmayan20032168View::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: 在此处通过修改 CREATESTRUCT cs 来修改窗口类或
// 样式
return CRecordView::PreCreateWindow(cs);
}
void Cmayan20032168View::OnInitialUpdate()
{
m_pSet = &GetDocument()->m_mayan20032168Set;
CRecordView::OnInitialUpdate();
}
// Cmayan20032168View 打印
BOOL Cmayan20032168View::OnPreparePrinting(CPrintInfo* pInfo)
{
// 默认准备
return DoPreparePrinting(pInfo);
}
void Cmayan20032168View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: 打印前添加额外的初始化
}
void Cmayan20032168View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: 打印后添加清除过程
}
// Cmayan20032168View 诊断
#ifdef _DEBUG
void Cmayan20032168View::AssertValid() const
{
CRecordView::AssertValid();
}
void Cmayan20032168View::Dump(CDumpContext& dc) const
{
CRecordView::Dump(dc);
}
Cmayan20032168Doc* Cmayan20032168View::GetDocument() const // 非调试版本是内联的
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(Cmayan20032168Doc)));
return (Cmayan20032168Doc*)m_pDocument;
}
#endif //_DEBUG
// Cmayan20032168View 数据库支持
CRecordset* Cmayan20032168View::OnGetRecordset()
{
return m_pSet;
}
// Cmayan20032168View 消息处理程序
void Cmayan20032168View::OnBnClickedButton1()
{
// TODO: 在此添加控件通知处理程序代码
BOOL lFound = FALSE; //Use it to judge wheather we have find
//a match record.
CDBVariant varBookMark; //Postioning bookmark.
CString Value;
CString str;
m_pSet->MoveFirst();
while(!m_pSet->IsEOF() &&!lFound)
{
//Check if the value is equal.
m_zhao.GetWindowText(Value);
if(m_pSet->m_name==Value)
{
lFound=TRUE;
}
else
{
m_pSet->MoveNext();
}
}
if(!lFound)
{
//Display an error message if we didn't find the record.
MessageBox("无此记录","Database Error",MB_OK|MB_ICONERROR);
if(m_pSet->CanBookmark())
//Restore the current position if
//the database supports bookmarks.
m_pSet->SetBookmark(varBookMark);
else
//Otherwise,move to the first record.
m_pSet->MoveFirst();
}
else
{
char temp[10];
Value=m_pSet->m_name;
itoa(m_pSet->m_num,temp,10);
Value=Value+"同学,学号:"+temp+",";
str=m_pSet->m_sex;
Value=Value+"性别:"+str+",";
itoa(m_pSet->m_age,temp,10);
Value=Value+"年龄:"+temp+",";
str=m_pSet->m_grade;
Value=Value+"年级:"+str+",";
str=m_pSet->m_money;
Value=Value+"交费信息:"+str+".";
MessageBox(Value);
}
m_zhao.SetWindowText("");
UpdateData(TRUE);
}
void Cmayan20032168View::OnBnClickedButton2()
{
// TODO: 在此添加控件通知处理程序代码
CDeldialog dlg1;
CString Value;
if(dlg1.DoModal()==IDOK)
{
m_shan.GetWindowText(Value);
m_pSet->MoveFirst();
while(!m_pSet->IsEOF() && m_pSet->m_name!=Value)
{
m_pSet->MoveNext();
}
m_pSet->Delete();
m_pSet->MoveNext();
if(m_pSet->IsEOF())
m_pSet->MoveLast();
if(m_pSet->IsBOF())
m_pSet->SetFieldNull(NULL);
UpdateData(FALSE);
m_shan.SetWindowText("");
UpdateData(TRUE);
UpdateData(FALSE);
}
}
void Cmayan20032168View::OnBnClickedButton4()
{
// TODO: 在此添加控件通知处理程序代码
CString Value;
m_pSet->Edit();
m_name1.GetWindowText(Value);
m_pSet->m_name=Value;
m_num1.GetWindowText(Value);
m_pSet->m_num=atoi((const char *)Value);
m_sex1.GetWindowText(Value);
m_pSet->m_age=atoi((const char *)Value);
m_grade1.GetWindowText(Value);
m_pSet->m_grade=Value;
m_money1.GetWindowText(Value);
m_pSet->m_money=Value;
m_pSet->Update();
UpdateData(TRUE);
UpdateData(FALSE);
}
void Cmayan20032168View::OnBnClickedButton3()
{
// TODO: 在此添加控件通知处理程序代码
CString Value;
BOOL lNew = TRUE;//用此变量来判断是否是新记录。
char temp[10];
m_num1.GetWindowText(Value);
m_pSet->MoveFirst();
while(!m_pSet->IsEOF())
{
itoa(m_pSet->m_num,temp,10);
if(strcmp(Value,temp)==0)
{
MessageBox("记录重复!","Database Error",MB_OK|MB_ICONERROR);
lNew=FALSE;
}
m_pSet->MoveNext();
}
if(lNew)
{
m_pSet->AddNew();
m_name1.GetWindowText(Value);
m_pSet->m_name=Value;
m_num1.GetWindowText(Value);
m_pSet->m_num=atoi((const char *)Value);
m_sex1.GetWindowText(Value);
m_pSet->m_sex=Value;
m_age1.GetWindowText(Value);
m_pSet->m_age=atoi((const char *)Value);
m_grade1.GetWindowText(Value);
m_pSet->m_grade=Value;
m_money1.GetWindowText(Value);
m_pSet->m_money=Value;
m_pSet->Update();
m_pSet->MoveLast();
UpdateData(TRUE);
UpdateData(FALSE);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -