📄 stumdlg.cpp
字号:
// StuMdlg.cpp : implementation file
//
#include "stdafx.h"
#include "Student.h"
#include "StuMdlg.h"
#include "MyRecord.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CStuMdlg dialog
CStuMdlg::CStuMdlg(CWnd* pParent /*=NULL*/)
: CDialog(CStuMdlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CStuMdlg)
m_address = _T("");
m_content = _T("");
m_day = 0;
m_help = _T("");
m_month = 0;
m_name = _T("");
m_no = _T("");
m_phone = _T("");
m_score = 0;
m_sourse = _T("");
m_year = 0;
//}}AFX_DATA_INIT
}
void CStuMdlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CStuMdlg)
DDX_Control(pDX, IDC_COMBO_SEX, m_ComboSex);
DDX_Control(pDX, IDC_COMBO_POLITY, m_ComboPolity);
DDX_Control(pDX, IDC_COMBO_NATION, m_ComboNation);
DDX_Control(pDX, IDC_COMBO_DORM, m_ComboDorm);
DDX_Text(pDX, IDC_EDIT_ADDRESS, m_address);
DDV_MaxChars(pDX, m_address, 60);
DDX_Text(pDX, IDC_EDIT_CONTENT, m_content);
DDV_MaxChars(pDX, m_content, 1024);
DDX_Text(pDX, IDC_EDIT_DAY, m_day);
DDV_MinMaxInt(pDX, m_day, 1, 31);
DDX_Text(pDX, IDC_EDIT_MONTH, m_month);
DDV_MinMaxInt(pDX, m_month, 1, 12);
DDX_Text(pDX, IDC_EDIT_NAME, m_name);
DDV_MaxChars(pDX, m_name, 14);
DDX_Text(pDX, IDC_EDIT_NO, m_no);
DDV_MaxChars(pDX, m_no, 8);
DDX_Text(pDX, IDC_EDIT_PHONE, m_phone);
DDV_MaxChars(pDX, m_phone, 52);
DDX_Text(pDX, IDC_EDIT_SCORE, m_score);
DDX_Text(pDX, IDC_EDIT_SOURSE, m_sourse);
DDV_MaxChars(pDX, m_sourse, 6);
DDX_Text(pDX, IDC_EDIT_YEAR, m_year);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CStuMdlg, CDialog)
//{{AFX_MSG_MAP(CStuMdlg)
ON_BN_CLICKED(IDC_BTN_BOTTOM, OnBtnBottom)
ON_BN_CLICKED(IDC_BTN_DELETE, OnBtnDelete)
ON_BN_CLICKED(IDC_BTN_EDIT_CANCAL, OnBtnEditCancal)
ON_BN_CLICKED(IDC_BTN_FIRST, OnBtnFirst)
ON_BN_CLICKED(IDC_BTN_NEXT, OnBtnNext)
ON_BN_CLICKED(IDC_BTN_PREV, OnBtnPrev)
ON_BN_CLICKED(IDC_BTN_ADD_SAVE, OnBtnAddSave)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CStuMdlg message handlers
BOOL CStuMdlg::OnInitDialog()
{
CString strSQL;
BOOL Success;
CStudentSet rs;
CDialog::OnInitDialog();
// TODO: Add extra initialization here
try{
strSQL="select stu_no,name,sex,nation,polity,to_char(birthday,'yyyy-mm-dd') as birthday,";
strSQL+="score, home_phone,source,address,content from student";
Success=rs.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL);
if(!rs.IsOpen())
{
MessageBox("学生表打开失败!");
this->OnCancel();
return TRUE;
}
InitComboBox("001",&m_ComboSex);
InitComboBox("002",&m_ComboNation);
InitComboBox("003",&m_ComboPolity);
UpdateField(FALSE);
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 CStuMdlg::OnBtnBottom()
{
// TODO: Add your control notification handler code here
m_pStudent->MoveLast();
UpdateField(FALSE);
}
void CStuMdlg::OnBtnDelete()
{
// TODO: Add your control notification handler code here
}
void CStuMdlg::OnBtnEditCancal()
{
// TODO: Add your control notification handler code here
CString strCaption;
this->GetDlgItemText(IDC_BTN_EDIT_CANCAL,strCaption);
if (strCaption=="编辑")
{
this->GetDlgItem(IDC_BTN_FIRST)->EnableWindow(FALSE);
this->GetDlgItem(IDC_BTN_PREV )->EnableWindow(FALSE);
this->GetDlgItem(IDC_BTN_NEXT )->EnableWindow(FALSE);
this->GetDlgItem(IDC_BTN_BOTTOM)->EnableWindow(FALSE);
this->GetDlgItem(IDC_BTN_DELETE)->EnableWindow(FALSE);
this->GetDlgItem(IDCANCEL)->EnableWindow(FALSE);
this->SetDlgItemText(IDC_BTN_ADD_SAVE,"保存");
this->SetDlgItemText(IDC_BTN_EDIT_CANCAL,"还原");
EnableControl(TRUE);
}
else
{
this->GetDlgItem(IDC_BTN_FIRST)->EnableWindow(TRUE);
this->GetDlgItem(IDC_BTN_PREV )->EnableWindow(TRUE);
this->GetDlgItem(IDC_BTN_NEXT )->EnableWindow(TRUE);
this->GetDlgItem(IDC_BTN_BOTTOM)->EnableWindow(TRUE);
this->GetDlgItem(IDC_BTN_DELETE)->EnableWindow(TRUE);
this->GetDlgItem(IDCANCEL)->EnableWindow(TRUE);
UpdateField(FALSE);
this->SetDlgItemText(IDC_BTN_ADD_SAVE,"添加");
this->SetDlgItemText(IDC_BTN_EDIT_CANCAL,"编辑");
EnableControl(FALSE);
}
}
void CStuMdlg::OnBtnFirst()
{
// TODO: Add your control notification handler code here
m_pStudent->MoveFirst();
UpdateField(FALSE);
}
void CStuMdlg::OnBtnNext()
{
// TODO: Add your control notification handler code here
m_pStudent->MoveNext();
if(m_pStudent->IsEOF())
m_pStudent->MoveLast();
UpdateField(FALSE);
}
void CStuMdlg::OnBtnPrev()
{
// TODO: Add your control notification handler code here
m_pStudent->MovePrev();
UpdateField(FALSE);
}
void CStuMdlg::OnBtnAddSave() //**
{
// TODO: Add your control notification handler code here
CString strCaption;
this->GetDlgItemText(IDC_BTN_EDIT_CANCAL,strCaption);
if (strCaption=="添加")
{
this->GetDlgItem(IDC_BTN_FIRST)->EnableWindow(FALSE);
this->GetDlgItem(IDC_BTN_PREV )->EnableWindow(FALSE);
this->GetDlgItem(IDC_BTN_NEXT )->EnableWindow(FALSE);
this->GetDlgItem(IDC_BTN_BOTTOM)->EnableWindow(FALSE);
this->GetDlgItem(IDC_BTN_DELETE)->EnableWindow(FALSE);
this->GetDlgItem(IDCANCEL)->EnableWindow(FALSE);
this->SetDlgItemText(IDC_BTN_ADD_SAVE,"保存");
this->SetDlgItemText(IDC_BTN_EDIT_CANCAL,"还原");
EnableControl(TRUE);
}
else
{
this->GetDlgItem(IDC_BTN_FIRST)->EnableWindow(TRUE);
this->GetDlgItem(IDC_BTN_PREV )->EnableWindow(TRUE);
this->GetDlgItem(IDC_BTN_NEXT )->EnableWindow(TRUE);
this->GetDlgItem(IDC_BTN_BOTTOM)->EnableWindow(TRUE);
this->GetDlgItem(IDC_BTN_DELETE)->EnableWindow(TRUE);
this->GetDlgItem(IDCANCEL)->EnableWindow(TRUE);
CModifydlg modify;
int result=modify.DoModal();
if(result == IDCANCEL)
return;
else
UpdateField(TRUE);
this->SetDlgItemText(IDC_BTN_ADD_SAVE,"添加");
this->SetDlgItemText(IDC_BTN_EDIT_CANCAL,"编辑");
EnableControl(FALSE);
}
}
void CStuMdlg::OnCancel()
{
// TODO: Add extra cleanup here
CDialog::OnCancel();
}
void CStuMdlg::UpdateField(BOOL bSave)
{
CStudentSet rs;
CString strTemp;
CString strExpress,strSQL,strField;
if(bSave)
{
this->UpdateData(bSave);
m_name.TrimRight();
strExpress.Format("name=\'%s\'",m_name);
strSQL="update group1.student set "+strExpress;
strExpress.Format("sex=\'%d\'",m_ComboSex.GetCurSel()+1);
strSQL+=","+strExpress;
strExpress.Format("nation=\'%02d\'",m_ComboNation.GetCurSel()+1);
strSQL+=","+strExpress;
strExpress.Format("polity=\'%d\'",m_ComboPolity.GetCurSel()+1);
strSQL+=","+strExpress;
strExpress.Format("birthday=to_date(\'%4d-%02d-%02d\',\'yyyy-mm-dd\')",m_year,m_month,m_day);
strSQL+=","+strExpress;
strExpress.Format("score=%d",m_score);
strSQL+=","+strExpress;
strExpress.Format("home_phone=\'%s\'",m_phone);
strSQL+=","+strExpress;
strExpress.Format("scoure=\'%s\'",m_sourse);
strSQL+=","+strExpress;
strExpress.Format("address=\'%s\'",m_address);
strSQL+=","+strExpress;
strExpress.Format("content=\'%s\'",m_content);
strSQL+=","+strExpress;
strExpress.Format(" where stu_no=\'%s\'",m_no);
strSQL+=strExpress;
m_pDB->ExecuteSQL(strSQL);
rs.Requery();
UpdateField(FALSE);
}
else
{
m_pStudent->GetFieldValue("STU_NO",m_no);
m_pStudent->GetFieldValue("NAME",m_name);
m_name.TrimRight();
m_pStudent->GetFieldValue("SEX",strTemp);
m_ComboSex.SetCurSel(atoi(strTemp)-1);
m_pStudent->GetFieldValue("NATION",strTemp);
m_ComboNation.SetCurSel(atoi(strTemp)-1);
m_pStudent->GetFieldValue("POLITY",strTemp);
m_ComboPolity.SetCurSel(atoi(strTemp)-1);
m_pStudent->GetFieldValue("BIRTHDAY",strTemp);
m_year=atoi(strTemp.Left(4));
m_month=atoi(strTemp.Mid(5,2));
m_day=atoi(strTemp.Right(2));
m_pStudent->GetFieldValue("SCORE",strTemp);
m_score=atoi(strTemp);
m_pStudent->GetFieldValue("HOME_PHONE",m_phone);
m_pStudent->GetFieldValue("SOURCE",m_sourse);
m_pStudent->GetFieldValue("ADDRESS",m_address);
m_pStudent->GetFieldValue("CONTENT",m_content);
this->UpdateData(bSave);
}
}
void CStuMdlg::InitComboBox(CString tCategory, CComboBox *tBox)
{
CStudentSet 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->OnCancel();
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 group1.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->OnCancel();
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 CStuMdlg::EnableControl(BOOL bEnable)
{
CMyRecord mr;
CString strTemp;
m_pStudent->GetFieldValue("INPUTTIMT",strTemp);
int Inputyear=atoi(strTemp.Left(4));
int Inputmonth=atoi(strTemp.Mid(5,2));
int Inputday=atoi(strTemp.Right(2));
if(mr.IsDate(Inputyear,Inputmonth,Inputday,1) && m_kind == 1) //教师可修改,一周内可修改
{
this->GetDlgItem(IDC_COMBO_SEX)->EnableWindow(bEnable);
this->GetDlgItem(IDC_COMBO_NATION)->EnableWindow(bEnable);
this->GetDlgItem(IDC_EDIT_SOURSE)->EnableWindow(bEnable);
this->GetDlgItem(IDC_EDIT_SCORE)->EnableWindow(bEnable);
}
//学生,教师,管理员均可修改可修改
this->GetDlgItem(IDC_EDIT_NAME)->EnableWindow(bEnable);
this->GetDlgItem(IDC_EDIT_YEAR)->EnableWindow(bEnable);
this->GetDlgItem(IDC_EDIT_MONTH)->EnableWindow(bEnable);
this->GetDlgItem(IDC_EDIT_DAY)->EnableWindow(bEnable);
this->GetDlgItem(IDC_EDIT_PHONE)->EnableWindow(bEnable);
this->GetDlgItem(IDC_EDIT_ADDRESS)->EnableWindow(bEnable);
this->GetDlgItem(IDC_EDIT_CONTENT)->EnableWindow(bEnable);
if(m_kind == 0) //管理员可修改
{
this->GetDlgItem(IDC_COMBO_POLITY)->EnableWindow(bEnable);
this->GetDlgItem(IDC_COMBO_DORM)->EnableWindow(bEnable);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -