classidlg.cpp

来自「这是一个学生管理系统 包含学生基本信息 选课信息 宿舍信息 教师信息 课程信息 」· C++ 代码 · 共 216 行

CPP
216
字号
// ClassIdlg.cpp : implementation file
//

#include "stdafx.h"
#include "Student.h"
#include "ClassIdlg.h"
#include "ClassSet.h"

#include "MyRecord.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CClassIdlg dialog


CClassIdlg::CClassIdlg(CWnd* pParent /*=NULL*/)
	: CDialog(CClassIdlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CClassIdlg)
	m_class_no = _T("");
	m_help = _T("");
	m_manager = _T("");
	m_name = _T("");
	m_monitor = _T("");
	//}}AFX_DATA_INIT
}


void CClassIdlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CClassIdlg)
	DDX_Text(pDX, IDC_EDIT_CLASSNO, m_class_no);
	DDV_MaxChars(pDX, m_class_no, 4);
	DDX_Text(pDX, IDC_EDIT_HELP, m_help);
	DDX_Text(pDX, IDC_EDIT_TEACHER_NO, m_manager);
	DDX_Text(pDX, IDC_EDIT_NAME, m_name);
	DDX_Text(pDX, IDC_EDIT_MONITOR_NO, m_monitor);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CClassIdlg, CDialog)
	//{{AFX_MSG_MAP(CClassIdlg)
	ON_BN_CLICKED(IDC_BTN_OK, OnBtnOk)
	ON_EN_SETFOCUS(IDC_EDIT_MONITOR_NO, OnSetfocusEditMonitorNo)
	ON_EN_SETFOCUS(IDC_EDIT_NAME, OnSetfocusEditName)
	ON_EN_SETFOCUS(IDC_EDIT_TEACHER_NO, OnSetfocusEditTeacherNo)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CClassIdlg message handlers

void CClassIdlg::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(!UpdateDB())
		return;
	GenNext();
	UpdateData(FALSE);
	this->GetDlgItem(IDC_EDIT_NAME)->SetFocus();
}

void CClassIdlg::OnCancel() 
{
	// TODO: Add extra cleanup here
	
	CDialog::OnCancel();
}

BOOL CClassIdlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	GenNext();
	UpdateData(FALSE);
	// TODO: Add extra initialization here
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CClassIdlg::OnSetfocusEditMonitorNo() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	m_help="请输入班长信息:最小500,最大600";
	UpdateData(FALSE);
}

void CClassIdlg::OnSetfocusEditName() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	m_help="请输入姓名信息:长度限制14个字符(7个汉字)";
	UpdateData(FALSE);
}

void CClassIdlg::OnSetfocusEditTeacherNo() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	m_help="请输入负责人信息:长度限制60个字符(30个汉字)";
	UpdateData(FALSE);
}
BOOL CClassIdlg::UpdateDB()
{
	CString strSQL,strValue,strTemp;
	strSQL="insert into class(class_no,name";
	strValue="\'"+m_class_no+"\',\'"+m_name;
	if (!m_monitor.IsEmpty())
	{
		strSQL+=",monitor";
		strValue+=",\'"+m_monitor+"\'";
	}
	if (!m_manager.IsEmpty())
	{
		strSQL+=",manager";
		strValue+=",\'"+m_manager+"\'";
	}
	
	strSQL+=") values("+strValue+")";
	//MessageBox(strSQL);
	m_pDB->ExecuteSQL(strSQL);
	return TRUE;
}

void CClassIdlg::GenHelp(CString tCategory)
{
	CClassSet 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);
	
}
void CClassIdlg::GenNext()
{
	CClassSet rs;
	CString strValue;
	CString strFileName;
	
	static HBITMAP hBitmap=NULL;
	// TODO: Add extra initialization here
	
	m_class_no=GetNextNo();
	
	m_name ="";
	m_manager ="";
	m_monitor ="";
	
}

CString CClassIdlg::GetNextNo()
{
	static int num=0;
	CClassSet rs;
	CString strValue,strSQL;
	BOOL Success;
	
	if(num==0)
	{
		strSQL.Format("select max(substr(stu_no,5)) from 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;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?