📄 studentdlg.cpp
字号:
// StudentDlg.cpp : implementation file
//
#include "stdafx.h"
#include "DataBase.h"
#include "StudentDlg.h"
#include "StudentSet.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CStudentDlg dialog
CStudentDlg::CStudentDlg(CWnd* pParent /*=NULL*/)
: CDialog(CStudentDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CStudentDlg)
m_sex = _T("");
m_dept = _T("");
m_age = 0;
m_name = _T("");
m_no = 0;
//}}AFX_DATA_INIT
}
void CStudentDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CStudentDlg)
DDX_CBString(pDX, IDC_COMBO_SEX, m_sex);
DDX_Text(pDX, IDC_EDIT_DEPT, m_dept);
DDX_Text(pDX, IDC_EDIT_AGE, m_age);
DDV_MinMaxInt(pDX, m_age, 18, 100);
DDX_Text(pDX, IDC_EDIT_NAME, m_name);
DDX_Text(pDX, IDC_EDIT_NO, m_no);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CStudentDlg, CDialog)
//{{AFX_MSG_MAP(CStudentDlg)
ON_BN_CLICKED(IDC_RESTART, OnRestart)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CStudentDlg message handlers
void CStudentDlg::OnOK()
{
// TODO: Add extra validation here
UpdateData(TRUE);
CString strSQL;
int flag=0;
while(!flag){
CStudentSet m_recordset(&m_database);
strSQL.Format("select * from Student where Sno=%d",m_no);
m_recordset.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL);
if(m_recordset.GetRecordCount()==0)
{
strSQL.Format("insert into Student values(%d,\'%s\',\'%s\',%d,\'%s\')",
m_no,m_name,m_sex,m_age,m_dept);
m_database.ExecuteSQL(strSQL);
m_database.Close();
CDialog::OnOK();
flag=1;
}
m_no++;
}
CDialog::OnOK();
}
void CStudentDlg::OnRestart()
{
// TODO: Add your control notification handler code here
m_no=0;
m_name.Empty();
m_sex.Empty();
m_age=0;
m_dept.Empty();
UpdateData(FALSE);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -