?? departmdlg.cpp
字號:
// DepartMdlg.cpp : implementation file
//
#include "stdafx.h"
#include "Student.h"
#include "DepartMdlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDepartMdlg dialog
CDepartMdlg::CDepartMdlg(CWnd* pParent /*=NULL*/)
: CDialog(CDepartMdlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CDepartMdlg)
m_header = _T("");
m_intro = _T("");
m_name = _T("");
m_phone = _T("");
m_depart = _T("");
m_coll_no = _T("");
//}}AFX_DATA_INIT
}
void CDepartMdlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDepartMdlg)
DDX_Text(pDX, IDC_EDIT_HEADER, m_header);
DDV_MaxChars(pDX, m_header, 4);
DDX_Text(pDX, IDC_EDIT_INTRODC, m_intro);
DDV_MaxChars(pDX, m_intro, 1024);
DDX_Text(pDX, IDC_EDIT_NAME, m_name);
DDV_MaxChars(pDX, m_name, 40);
DDX_Text(pDX, IDC_EDIT_PHONE, m_phone);
DDV_MaxChars(pDX, m_phone, 7);
DDX_Text(pDX, IDC_EDIT_DEPART_NO, m_depart);
DDV_MaxChars(pDX, m_depart, 4);
DDX_Text(pDX, IDC_EDIT_COLL_NO, m_coll_no);
DDV_MaxChars(pDX, m_coll_no, 2);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDepartMdlg, CDialog)
//{{AFX_MSG_MAP(CDepartMdlg)
ON_BN_CLICKED(IDC_BTN_NEXT, OnBtnNext)
ON_BN_CLICKED(IDC_BTN_PREV, OnBtnPrev)
ON_BN_CLICKED(IDC_BTN_RETURN, OnBtnReturn)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDepartMdlg message handlers
void CDepartMdlg::OnBtnNext()
{
// TODO: Add your control notification handler code here
m_pDepart->MoveNext();
if(m_pDepart->IsEOF())
m_pDepart->MoveLast();
UpdateField(FALSE);
}
void CDepartMdlg::OnBtnPrev()
{
// TODO: Add your control notification handler code here
m_pDepart->MovePrev();
UpdateField(FALSE);
}
void CDepartMdlg::OnBtnReturn()
{
// TODO: Add your control notification handler code here
UpdateField(FALSE);
}
void CDepartMdlg::OnOK()
{
// TODO: Add extra validation here
// TODO: Add your control notification handler code here
CModifydlg modify;
int result=modify.DoModal();
if(result == IDCANCEL)
return;
if(m_kind == 1)//教師
UpdateField(true);
else MessageBox("你無權修改數據!");
CDialog::OnOK();
}
void CDepartMdlg::OnCancel()
{
// TODO: Add extra cleanup here
CDialog::OnCancel();
}
BOOL CDepartMdlg::OnInitDialog()
{
CString strSQL;
BOOL Success;
CDepartSet rs;
CDialog::OnInitDialog();
// TODO: Add extra initialization here
try{
strSQL="select Depart_no,Name,Phone,College_no,Depart_header,Introduction from Department";
Success=Success=rs.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL);
if(!Success)
{
MessageBox("系表打開失敗!");
this->OnCancel();
return TRUE;
}
UpdateField(FALSE);
if(m_kind == 1) //教師可以修改
{
this->GetDlgItem(IDC_EDIT_NAME)->EnableWindow(true);
this->GetDlgItem(IDC_EDIT_PHONE)->EnableWindow(true);
this->GetDlgItem(IDC_EDIT_HEADER)->EnableWindow(true);
this->GetDlgItem(IDC_EDIT_COLL_NO)->EnableWindow(true);
this->GetDlgItem(IDC_EDIT_INTRODC)->EnableWindow(true);
}
rs.Close();
}
catch(CDBException *pe){
AfxMessageBox(pe->m_strError);
pe->Delete();
}
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CDepartMdlg::UpdateField(BOOL bSave)
{
CString strTemp;
CString strExpress,strSQL,strField;
if(bSave)
{
this->UpdateData(true);
//m_name.TrimRight();
strExpress.Format("name=\'%s\'",m_name);
strSQL="update group1.Class set "+strExpress;
strExpress.Format("Phone=\'%s\'",m_phone);
strSQL+=","+strExpress;
strExpress.Format("DEPART_HEADER=\'%s\'",m_header);
strSQL+=","+strExpress;
strExpress.Format("Coll_no=\'%s\'",m_coll_no);
strSQL+=","+strExpress;
strExpress.Format("Introduction=\'%s\'",m_intro);
strSQL+=","+strExpress;
m_pDB->ExecuteSQL(strSQL);
m_pDepart->Requery();
UpdateField(FALSE);
}
else
{
m_pDepart->GetFieldValue("NAME",m_name);
m_pDepart->GetFieldValue("PHONE",m_phone);
m_pDepart->GetFieldValue("DEPART_HEADER",m_header);
m_pDepart->GetFieldValue("COLLEGE",m_coll_no);
m_pDepart->GetFieldValue("INTRODUCTION",m_intro);
this->UpdateData(bSave);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -