📄 departidlg.cpp
字号:
// DepartIdlg.cpp : implementation file
//
#include "stdafx.h"
#include "Student.h"
#include "DepartIdlg.h"
#include "DepartSet.h"
#include "myrecord.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDepartIdlg dialog
CDepartIdlg::CDepartIdlg(CWnd* pParent /*=NULL*/)
: CDialog(CDepartIdlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CDepartIdlg)
m_depart_no = _T("");
m_depart_header = _T("");
m_help = _T("");
m_introduction = _T("");
m_name = _T("");
m_phone = _T("");
m_college_no = _T("");
//}}AFX_DATA_INIT
}
void CDepartIdlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDepartIdlg)
DDX_Text(pDX, IDC_EDIT_DEPART_NO, m_depart_no);
DDX_Text(pDX, IDC_EDIT_HEADER, m_depart_header);
DDX_Text(pDX, IDC_EDIT_HELP, m_help);
DDX_Text(pDX, IDC_EDIT_INTRODC, m_introduction);
DDX_Text(pDX, IDC_EDIT_NAME, m_name);
DDX_Text(pDX, IDC_EDIT_PHONE, m_phone);
DDX_Text(pDX, IDC_EDIT_COLL_NO, m_college_no);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDepartIdlg, CDialog)
//{{AFX_MSG_MAP(CDepartIdlg)
ON_BN_CLICKED(IDC_BTN_OK, OnBtnOk)
ON_EN_SETFOCUS(IDC_EDIT_INTRODC, OnSetfocusEditIntrodc)
ON_EN_SETFOCUS(IDC_EDIT_PHONE, OnSetfocusEditPhone)
ON_EN_SETFOCUS(IDC_EDIT_NAME, OnSetfocusEditName)
ON_EN_SETFOCUS(IDC_EDIT_HEADER, OnSetfocusEditHeader)
ON_EN_SETFOCUS(IDC_EDIT_COLL_NO, OnSetfocusEditCollNo)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDepartIdlg message handlers
BOOL CDepartIdlg::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 CDepartIdlg::OnCancel()
{
// TODO: Add extra cleanup here
CDialog::OnCancel();
}
void CDepartIdlg::OnBtnOk()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
if(m_name.IsEmpty())
{
//MessageBeep(MB_ICONEXCLAMATION);
this->GetDlgItem(IDC_EDIT_NAME)->SetFocus();
return;
}
if(m_phone.IsEmpty())
{
//MessageBeep(MB_ICONEXCLAMATION);
this->GetDlgItem(IDC_EDIT_PHONE)->SetFocus();
return;
}
if(m_college_no.IsEmpty())
{
//MessageBeep(MB_ICONEXCLAMATION);
this->GetDlgItem(IDC_EDIT_COLLEGE_NO)->SetFocus();
return;
}
if(m_depart_header.IsEmpty())
{
//MessageBeep(MB_ICONEXCLAMATION);
this->GetDlgItem(IDC_EDIT_HEADER)->SetFocus();
return;
}
if(!UpdateDB())
return;
GenNext();
UpdateData(FALSE);
this->GetDlgItem(IDC_EDIT_NAME)->SetFocus();
}
void CDepartIdlg::OnSetfocusEditIntrodc()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
m_help="请输入简介信息:最小500,最大600";
UpdateData(FALSE);
}
void CDepartIdlg::OnSetfocusEditPhone()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
m_help="请输入电话信息:长度限制60个字符(30个汉字)";
UpdateData(FALSE);
}
void CDepartIdlg::OnSetfocusEditName()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
m_help="请输入系名信息:长度限制14个字符(7个汉字)";
UpdateData(FALSE);
}
void CDepartIdlg::OnSetfocusEditHeader()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
m_help="请输入系长信息:最小500,最大600";
UpdateData(FALSE);
}
void CDepartIdlg::OnSetfocusEditCollNo()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
m_help="请选择学院编号信息:最小500,最大600";
m_college_no=m_CollegeNo;
UpdateData(FALSE);
}
BOOL CDepartIdlg::UpdateDB()
{
CString strSQL,strValue,strTemp;
//strTemp.Format("%d,to_date(\'%4d-%2d-%2d\',\'yyyy-mm-dd\')",m_score,m_birth_year,m_birth_month,m_birth_day);
strSQL="insert into Department(depart_no,name,phone,depart_header,CollegeNo";
strValue="\'"+m_depart_no+"\',\'"+m_name+"\',\'"+m_phone+"\',\'"+m_depart_header+"\',\'"+m_CollegeNo;
if (!m_introduction.IsEmpty())
{
strSQL+=",introduction";
strValue+=",\'"+m_introduction+"\'";
}
strSQL+=") values("+strValue+")";
//MessageBox(strSQL);
m_pDB->ExecuteSQL(strSQL);
return TRUE;
}
void CDepartIdlg::GenNext()
{
CDepartSet rs;
CString strValue;
CString strFileName;
static HBITMAP hBitmap=NULL;
// TODO: Add extra initialization here
m_depart_no=GetNextNo();
m_name ="";
m_phone ="";
m_depart_header ="";
m_introduction ="";
m_CollegeNo ="";
}
CString CDepartIdlg::GetNextNo()
{
static int num=0;
CDepartSet rs;
CString strValue,strSQL;
BOOL Success;
if(num==0)
{
strSQL.Format("select max(substr(stu_no,5)) from group1.class where substr(class_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 CDepartIdlg::GenHelp(CString tCategory)
{
CDepartSet 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 + -