📄 dormidlg.cpp
字号:
// DormIdlg.cpp : implementation file
//
#include "stdafx.h"
#include "Student.h"
#include "DormIdlg.h"
#include "DormSet.h"
#include "myrecord.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDormIdlg dialog
CDormIdlg::CDormIdlg(CWnd* pParent /*=NULL*/)
: CDialog(CDormIdlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CDormIdlg)
m_stu_num = 0;
m_manager = _T("");
m_phone = _T("");
m_sex = _T("");
m_help = _T("");
m_dorm_no = _T("");
m_build_no = _T("");
m_apartment_no = _T("");
m_class_no = _T("");
//}}AFX_DATA_INIT
}
void CDormIdlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDormIdlg)
DDX_Text(pDX, IDC_EDIT_NUM, m_stu_num);
DDX_Text(pDX, IDC_EDIT_MANAGER, m_manager);
DDX_Text(pDX, IDC_EDIT_PHONE, m_phone);
DDX_Text(pDX, IDC_EDIT_SEX, m_sex);
DDX_Text(pDX, IDC_EDIT_HELP, m_help);
DDX_Text(pDX, IDC_EDIT_DORM_NO, m_dorm_no);
DDX_Text(pDX, IDC_EDIT_BUILD_NO, m_build_no);
DDX_Text(pDX, IDC_EDIT_APART_NO, m_apartment_no);
DDX_Text(pDX, IDC_EDIT_CLASSNO, m_class_no);
DDV_MaxChars(pDX, m_class_no, 4);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDormIdlg, CDialog)
//{{AFX_MSG_MAP(CDormIdlg)
ON_BN_CLICKED(IDC_BTN_OK, OnBtnOk)
ON_EN_SETFOCUS(IDC_EDIT_BUILD_NO, OnSetfocusEditBuildNo)
ON_EN_SETFOCUS(IDC_EDIT_CLASSNO, OnSetfocusEditClassno)
ON_EN_SETFOCUS(IDC_EDIT_MANAGER, OnSetfocusEditManager)
ON_EN_SETFOCUS(IDC_EDIT_NUM, OnSetfocusEditNum)
ON_EN_SETFOCUS(IDC_EDIT_PHONE, OnSetfocusEditPhone)
ON_EN_SETFOCUS(IDC_EDIT_SEX, OnSetfocusEditSex)
ON_EN_KILLFOCUS(IDC_EDIT_SEX, OnKillfocusEditSex)
ON_EN_SETFOCUS(IDC_EDIT_APART_NO, OnSetfocusEditApartNo)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDormIdlg message handlers
BOOL CDormIdlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
GenNext();
UpdateData(FALSE);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CDormIdlg::OnBtnOk()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
if(m_build_no.IsEmpty())
{
//MessageBeep(MB_ICONEXCLAMATION);
this->GetDlgItem(IDC_EDIT_BUILD_NO)->SetFocus();
return;
}
if(m_class_no.IsEmpty())
{
//MessageBeep(MB_ICONEXCLAMATION);
this->GetDlgItem(IDC_EDIT_CLASS_NO)->SetFocus();
return;
}
if(m_apartment_no.IsEmpty())
{
//MessageBeep(MB_ICONEXCLAMATION);
this->GetDlgItem(IDC_EDIT_APART_NO)->SetFocus();
return;
}
if(m_stu_num==0)
{
//MessageBeep(MB_ICONEXCLAMATION);
this->GetDlgItem(IDC_EDIT_NUM)->SetFocus();
return;
}
if(!UpdateDB())
return;
GenNext();
UpdateData(FALSE);
this->GetDlgItem(IDC_EDIT_BUILD_NO)->SetFocus();
}
void CDormIdlg::OnCancel()
{
// TODO: Add extra cleanup here
CDialog::OnCancel();
}
void CDormIdlg::OnSetfocusEditBuildNo()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
m_help="请输入宿舍楼信息:最小500,最大600";
UpdateData(FALSE);
}
void CDormIdlg::OnSetfocusEditClassno()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
m_help="请输入所在班级信息:长度限制60个字符(30个汉字)";
UpdateData(FALSE);
}
void CDormIdlg::OnSetfocusEditManager()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
m_help="请输入宿舍室长信息:长度限制60个字符(30个汉字)";
UpdateData(FALSE);
}
void CDormIdlg::OnSetfocusEditNum()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
m_help="请输入学生数量信息:最小500,最大600";
UpdateData(FALSE);
}
void CDormIdlg::OnSetfocusEditPhone()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
m_help="请输入电话信息:长度限制60个字符(30个汉字)";
UpdateData(FALSE);
}
void CDormIdlg::OnSetfocusEditSex()
{
// TODO: Add your control notification handler code here
UpdateData();
m_sex=m_sexid;
GenHelp("001");
this->GetDlgItem(IDC_EDIT_SEX)->SendMessage(EM_SETSEL,0,1);
}
void CDormIdlg::OnKillfocusEditSex()
{
// TODO: Add your control notification handler code here
m_sexid=KillFocus("001",m_sex,1);
}
void CDormIdlg::OnSetfocusEditApartNo()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
m_help="请输入系信息:最小500,最大600";
UpdateData(FALSE);
}
CString CDormIdlg::GetNextNo()
{
static int num=0;
CDormSet rs;
CString strValue,strSQL;
BOOL Success;
if(num==0)
{
strSQL.Format("select max(substr(stu_no,5)) from Dormitory where substr(dorm_no,1,4)=\'%02d%s\'",m_CollegeNo);
Success=rs.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL);
if (Success && rs.GetRecordCount()>0)
rs.GetFieldValue((short)0,strValue);
else
strValue="0";
num=atoi(strValue);
}
num++;
strValue.Format("%s%04d",m_CollegeNo,num);
return strValue;
}
void CDormIdlg::GenNext()
{
CDormSet rs;
BOOL Success;
CString strValue;
CString strFileName;
CString strSQL;
static HBITMAP hBitmap=NULL;
// TODO: Add extra initialization here
m_dorm_no=GetNextNo();
m_build_no ="";
m_apartment_no ="";
m_manager ="";
m_phone ="";
m_class_no="";
m_sex ="";
m_sexid="1";
m_stu_num = 0;
strSQL="select trim(ctext) from userdict where category=\'0\' and ccode=\'1\'","数据字典";
Success=rs.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL);
if (Success)
{
if(rs.GetRecordCount()>0)
rs.GetFieldValue((short)0,m_sex);
rs.Close();
}
}
BOOL CDormIdlg::UpdateDB()
{
CString strSQL,strValue,strTemp;
strTemp.Format(m_stu_num);
strSQL="insert into dormitory(dorm_no,build_no,department_no,sex";
strValue="\'"+m_dorm_no+"\',\'"+m_build_no+"\',\'"+m_apartment_no+"\',\'"+m_sexid+"\',\'"+m_class_no+"\',\'"+strTemp;
if (!m_phone.IsEmpty())
{
strSQL+=",phone";
strValue+=",\'"+m_phone+"\'";
}
if (!m_manager.IsEmpty())
{
strSQL+=",manager";
strValue+=",\'"+m_manager+"\'";
}
strSQL+=") values("+strValue+")";
//MessageBox(strSQL);
m_pDB->ExecuteSQL(strSQL);
return TRUE;
}
CString CDormIdlg::KillFocus(CString tCategory,CString & tCode, int tLen)
{
CDormSet rs;
CString strCode,strText,strValue,strSQL,strFormat;
int nCode;
UpdateData();
nCode=atoi(tCode);
strFormat.Format("%%0%dd",tLen);
strCode.Format(strFormat,nCode);
strText="";
strSQL.Format("select trim(ctext) from userdict where category=\'%s\' and trim(ccode)=\'%s\'",tCategory,strCode);
if(rs.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL))
{
if (rs.GetRecordCount()>0)
{
rs.GetFieldValue((short)0,strText);
}
else
{
strText="";
}
rs.Close();
}
else
strText="";
if(strText.IsEmpty())
{
MessageBeep(MB_ICONEXCLAMATION);
strFormat.Format("select trim(ctext) from group1.userdict where category=\'%%s\' and trim(ccode)=\'%%0%dd\'",tLen);
strSQL.Format(strFormat,tCategory,1);
if(rs.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL))
{
if (rs.GetRecordCount()>0)
{
rs.GetFieldValue((short)0,strText);
strCode="1";
nCode=atoi(strCode);
strFormat.Format("%%0%dd",tLen);
strCode.Format(strFormat,nCode);
}
rs.Close();
}
}
tCode=strText;
UpdateData(FALSE);
return strCode;
}
// genhelp
void CDormIdlg::GenHelp(CString tCategory)
{
CDormSet rs;
CString strSQL,strValue,strZero;
BOOL Success;
int nLen;
//UpdateData();
strSQL.Format("select length(trim(ccode)) from userdict where category=\'%s\' and rownum<2",tCategory);
Success=rs.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL);
if(!Success)
return ;
rs.GetFieldValue((short)0,strValue);
nLen=atoi(strValue);
rs.Close();
strSQL.Format("select trim(ccode)||\'-\'||trim(ctext) from userdict where category=\'%s\'",tCategory);
Success=rs.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL);
if(Success)
{
strZero="";
for(int i=0;i<nLen;i++)
strZero+="0";
while (!rs.IsEOF())
{
rs.GetFieldValue((short)0,strValue);
if (strValue.Left(nLen)==strZero)
m_help=" "+strValue.Mid(nLen+1);
else
m_help+="\r\n\t"+strValue;
rs.MoveNext();
}
rs.Close();
}
UpdateData(FALSE);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -