📄 dormmdlg.cpp
字号:
// DormMdlg.cpp : implementation file
//
#include "stdafx.h"
#include "Student.h"
#include "DormMdlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDormMdlg dialog
CDormMdlg::CDormMdlg(CWnd* pParent /*=NULL*/)
: CDialog(CDormMdlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CDormMdlg)
m_apart = _T("");
m_build = _T("");
m_manager = _T("");
m_phone = _T("");
m_dorm = _T("");
//}}AFX_DATA_INIT
}
void CDormMdlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDormMdlg)
DDX_Control(pDX, IDC_COMBO_SEX, m_ComboSex);
DDX_Text(pDX, IDC_EDIT_APART, m_apart);
DDV_MaxChars(pDX, m_apart, 4);
DDX_Text(pDX, IDC_EDIT_BUILD_NO, m_build);
DDV_MaxChars(pDX, m_build, 2);
DDX_Text(pDX, IDC_EDIT_MANAGER, m_manager);
DDV_MaxChars(pDX, m_manager, 8);
DDX_Text(pDX, IDC_EDIT_PHONE, m_phone);
DDV_MaxChars(pDX, m_phone, 7);
DDX_Text(pDX, IDC_EDIT_DORM_NO, m_dorm);
DDV_MaxChars(pDX, m_dorm, 4);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDormMdlg, CDialog)
//{{AFX_MSG_MAP(CDormMdlg)
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()
/////////////////////////////////////////////////////////////////////////////
// CDormMdlg message handlers
void CDormMdlg::OnBtnNext()
{
// TODO: Add your control notification handler code here
m_pDorm->MoveNext();
if(m_pDorm->IsEOF())
m_pDorm->MoveLast();
UpdateField(FALSE);
}
void CDormMdlg::OnBtnPrev()
{
// TODO: Add your control notification handler code here
m_pDorm->MovePrev();
UpdateField(FALSE);
}
void CDormMdlg::OnBtnReturn()
{
// TODO: Add your control notification handler code here
UpdateField(FALSE);
}
void CDormMdlg::OnCancel()
{
// TODO: Add extra cleanup here
CDialog::OnCancel();
}
void CDormMdlg::OnOK()
{
// TODO: Add extra validation here
CModifydlg modify;
int result=modify.DoModal();
if(result == IDCANCEL)
return;
if(m_kind == 1)//教师
UpdateField(true);
else MessageBox("你无权修改数据!");
}
BOOL CDormMdlg::OnInitDialog() //**
{
CString strSQL;
BOOL Success;
CDormSet rs;
CDialog::OnInitDialog();
// TODO: Add extra initialization here
try{
strSQL="select dorm_no,apart_no,build_no,sex,manager,phone from Dormitory";
Success=rs.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL);MessageBox("lalalallala");
if(!Success)
{
MessageBox("住宿表打开失败!");
this->OnCancel();
return TRUE;
}
InitComboBox("001",&m_ComboSex);
UpdateField(FALSE);
EnableControl(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 CDormMdlg::UpdateField(BOOL bSave)
{
CString strTemp;
CString strExpress,strSQL,strField;
if(bSave)
{
this->UpdateData(bSave);
strExpress.Format("Dorm_no=\'%s\'",m_dorm);
strSQL="update group1.Dormitory set "+strExpress;
strExpress.Format("Apart_no=\'%s\'",m_apart);
strSQL+=","+strExpress;
strExpress.Format("Build_no=\'%s\'",m_build);
strSQL+=","+strExpress;
strExpress.Format("Sex=\'%d\'",m_ComboSex.GetCurSel()+1);
strSQL+=","+strExpress;
strExpress.Format("Manager=%s",m_manager);
strSQL+=","+strExpress;
strExpress.Format("Phone=\'%s\'",m_phone);
strSQL+=","+strExpress;
m_pDB->ExecuteSQL(strSQL);
m_pDorm->Requery();
UpdateField(FALSE);
}
else
{
m_pDorm->GetFieldValue("DORM_NO",m_dorm);
m_pDorm->GetFieldValue("APART_NO",m_apart);
m_pDorm->GetFieldValue("BUILD_NO",m_build);
m_pDorm->GetFieldValue("SEX",strTemp);
m_ComboSex.SetCurSel(atoi(strTemp)-1);
m_pDorm->GetFieldValue("MANAGER",m_manager);
m_pDorm->GetFieldValue("PHONE",m_phone);
this->UpdateData(bSave);
}
}
void CDormMdlg::InitComboBox(CString tCategory, CComboBox *tBox)
{
CDormSet rs;
CString strText,strCode0;
CString strSQL;
BOOL Success;
try{
strSQL.Format("select trim(min(ccode)) from userdict where category=\'%s\'",tCategory);
Success=rs.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL);
if (!Success)
{
MessageBox("住宿表打开失败!");
this->OnClose();
return;
}
if (rs.GetRecordCount()>0)
rs.GetFieldValue((short)0,strCode0);
else
Success=FALSE;
rs.Close();
if (!Success)
return;
strSQL.Format("select trim(ccode)||\'-\'||trim(ctext) from userdict where category=\'%s\' and ccode<>\'%s\' order by ccode",tCategory,strCode0);
Success=rs.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL);
if (!Success)
{
MessageBox("住宿表打开失败!");
this->OnClose();
return;
}
while(!rs.IsEOF())
{
rs.GetFieldValue((short)0,strText);
tBox->AddString(strText);
rs.MoveNext();
}
rs.Close();
}
catch(CDBException *pe){
AfxMessageBox(pe->m_strError);
pe->Delete();
}
}
void CDormMdlg::EnableControl(BOOL bEnable)
{
CMyRecord mr;
CString strTemp;
m_pDorm->GetFieldValue("INPUTTIMT",strTemp);
int Inputyear=atoi(strTemp.Left(4));
int Inputmonth=atoi(strTemp.Mid(5,2));
int Inputday=atoi(strTemp.Right(2));
if(m_kind == 1 && mr.IsDate(Inputyear,Inputmonth,Inputday,1))//只可教师可修改
{
this->GetDlgItem(IDC_EDIT_APART_NO)->EnableWindow(bEnable);
this->GetDlgItem(IDC_EDIT_BUILD_NO)->EnableWindow(bEnable);
}
this->GetDlgItem(IDC_COMBO_SEX)->EnableWindow(bEnable);
this->GetDlgItem(IDC_EDIT_MANAGER)->EnableWindow(bEnable);
this->GetDlgItem(IDC_EDIT_PHONE)->EnableWindow(bEnable);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -