⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stuidlg.cpp

📁 这是一个学生管理系统 包含学生基本信息 选课信息 宿舍信息 教师信息 课程信息 班机信息 教师信息等录入 查询 修改删除等强大功能
💻 CPP
字号:
// StuIdlg.cpp : implementation file
//

#include "stdafx.h"
#include "Student.h"
#include "StuIdlg.h"
#include "StudentSet.h"
#include "myrecord.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CStuIdlg dialog


CStuIdlg::CStuIdlg(CWnd* pParent /*=NULL*/)
	: CDialog(CStuIdlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CStuIdlg)
	m_address = _T("");
	m_content = _T("");
	m_name = _T("");
	m_dorm = _T("");
	m_nation = _T("");
	m_no = _T("");
	m_phone = _T("");
	m_polity = _T("");
	m_score = 0;
	m_sex = _T("");
	m_help = _T("");
	m_birth_day = 0;
	m_birth_month = 0;
	m_birth_year = 0;
	m_source = _T("");
	//}}AFX_DATA_INIT
}


void CStuIdlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CStuIdlg)
	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_NAME, m_name);
	DDV_MaxChars(pDX, m_name, 14);
	DDX_Text(pDX, IDC_EDIT_DORM, m_dorm);
	DDX_Text(pDX, IDC_EDIT_NATION, m_nation);
	DDV_MaxChars(pDX, m_nation, 2);
	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_POLITY, m_polity);
	DDV_MaxChars(pDX, m_polity, 1);
	DDX_Text(pDX, IDC_EDIT_SCORE, m_score);
	DDX_Text(pDX, IDC_EDIT_SEX, m_sex);
	DDV_MaxChars(pDX, m_sex, 1);
	DDX_Text(pDX, IDC_EDIT1, m_help);
	DDV_MaxChars(pDX, m_help, 1024);
	DDX_Text(pDX, IDC_EDIT_DAY, m_birth_day);
	DDX_Text(pDX, IDC_EDIT_MONTH, m_birth_month);
	DDX_Text(pDX, IDC_EDIT_YEAR, m_birth_year);
	DDX_Text(pDX, IDC_EDIT_SOURSE, m_source);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CStuIdlg, CDialog)
	//{{AFX_MSG_MAP(CStuIdlg)
	ON_EN_SETFOCUS(IDC_EDIT_NAME, OnSetfocusEditName)
	ON_EN_SETFOCUS(IDC_EDIT_NATION, OnSetfocusEditNation)
	ON_EN_SETFOCUS(IDC_EDIT_PHONE, OnSetfocusEditPhone)
	ON_EN_SETFOCUS(IDC_EDIT_POLITY, OnSetfocusEditPolity)
	ON_EN_SETFOCUS(IDC_EDIT_SCORE, OnSetfocusEditScore)
	ON_EN_SETFOCUS(IDC_EDIT_SEX, OnSetfocusEditSex)
	ON_EN_SETFOCUS(IDC_EDIT_SOURSE, OnSetfocusEditSourse)
	ON_EN_SETFOCUS(IDC_EDIT_YEAR, OnSetfocusEditYear)
	ON_EN_SETFOCUS(IDC_EDIT_MONTH, OnSetfocusEditMonth)
	ON_EN_SETFOCUS(IDC_EDIT_DORM, OnSetfocusEditDorm)
	ON_EN_SETFOCUS(IDC_EDIT_DAY, OnSetfocusEditDay)
	ON_EN_SETFOCUS(IDC_EDIT_CONTENT, OnSetfocusEditContent)
	ON_EN_SETFOCUS(IDC_EDIT_ADDRESS, OnSetfocusEditAddress)
	ON_EN_KILLFOCUS(IDC_EDIT_POLITY, OnKillfocusEditPolity)
	ON_EN_KILLFOCUS(IDC_EDIT_SEX, OnKillfocusEditSex)
	ON_EN_KILLFOCUS(IDC_EDIT_NATION, OnKillfocusEditNation)
	ON_EN_KILLFOCUS(IDC_EDIT_DAY, OnKillfocusEditDay)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CStuIdlg message handlers

BOOL CStuIdlg::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 CStuIdlg::OnSetfocusEditName() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	m_help="请输入姓名信息:长度限制14个字符(7个汉字)";
	UpdateData(FALSE);
}

void CStuIdlg::OnSetfocusEditNation() 
{
	// TODO: Add your control notification handler code here
	UpdateData();
	m_nation=m_nationid;
	GenHelp("002");
	this->GetDlgItem(IDC_EDIT_NATION)->SendMessage(EM_SETSEL,0,2);
}

void CStuIdlg::OnSetfocusEditPhone() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	m_help="请输入联系电话信息:长度限制52个字符";
	UpdateData(FALSE);
}

void CStuIdlg::OnSetfocusEditPolity() 
{
	// TODO: Add your control notification handler code here
	UpdateData();
	m_polity=m_polityid;
	GenHelp("003");
	this->GetDlgItem(IDC_EDIT_POLITY)->SendMessage(EM_SETSEL,0,1);
}

void CStuIdlg::OnSetfocusEditScore() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	m_help="请输入入学成绩信息:最小500,最大600";
	UpdateData(FALSE);
}

void CStuIdlg::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 CStuIdlg::OnSetfocusEditSourse() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	m_help="请输入学生来源信息:长度限制60个字符(30个汉字)";
	UpdateData(FALSE);
}

void CStuIdlg::OnSetfocusEditYear() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	m_help="四位年:1900-2100";
	UpdateData(FALSE);
}

void CStuIdlg::OnSetfocusEditMonth() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	m_help="月份:1-12";
	UpdateData(FALSE);
}

void CStuIdlg::OnSetfocusEditDorm() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	m_help="请输入宿舍信息:";
	UpdateData(FALSE);
}

void CStuIdlg::OnSetfocusEditDay() 
{
	// TODO: Add your control notification handler code here
	int day=31;
	
	UpdateData(TRUE);
	switch(m_birth_month)
	{
	case 4:
	case 6:
	case 9:
	case 11:
		day=30;
		break;
	case 2:
		if(m_birth_year%400==0||(m_birth_year%4==0 && m_birth_year%100!=0))
			day=29;
		else
			day=28;
		
	}
	m_help.Format("日:1-%2d",day);
	UpdateData(FALSE);
	this->GetDlgItem(IDC_EDIT_POLITY)->SendMessage(EM_SETSEL,0,2);
}

void CStuIdlg::OnSetfocusEditContent() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	m_help="请输入备注信息:长度不限";
	UpdateData(FALSE);
}

void CStuIdlg::OnSetfocusEditAddress() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	m_help="请输入地址信息:长度限制60个字符(30个汉字)";
	UpdateData(FALSE);
}

void CStuIdlg::OnKillfocusEditPolity() 
{
	// TODO: Add your control notification handler code here
	m_polityid=KillFocus("003",m_polity,1);	
}

void CStuIdlg::OnKillfocusEditSex() 
{
	// TODO: Add your control notification handler code here
	m_sexid=KillFocus("001",m_sex,1);
}

void CStuIdlg::OnKillfocusEditNation() 
{
	// TODO: Add your control notification handler code here
	m_nationid=KillFocus("002",m_nation,2);	
}

void CStuIdlg::OnKillfocusEditDay() 
{
	// TODO: Add your control notification handler code here
	int day=31;
	
	UpdateData(TRUE);
	switch(m_birth_month)
	{
	case 4:
	case 6:
	case 9:
	case 11:
		day=30;
		break;
	case 2:
		if(m_birth_year%400==0||(m_birth_year%4==0 && m_birth_year%100!=0))
			day=29;
		else
			day=28;
		
	}
	if (m_birth_day>day)
	{
		m_birth_day=day;
		MessageBeep(MB_ICONEXCLAMATION);
	}
	UpdateData(FALSE);
}

void CStuIdlg::OnOK() 
{
	// TODO: Add extra validation 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();
	CDialog::OnOK();
}
CString CStuIdlg::GetNextNo()
{
	static int num=0;
	CStudentSet rs;
	CString strValue,strSQL;
	BOOL Success;
	
	if(num==0)
	{
		strSQL.Format("select max(substr(stu_no,5)) from student where substr(stu_no,1,4)=\'%02d%s\'",m_year%100,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("%02d%s%04d",m_year%100,m_CollegeNo,num);
	return strValue;
}

void CStuIdlg::GenNext()
{
	CStudentSet rs;
	BOOL Success;
	CString strValue;
	CString strSQL;
	//CString strFileName;
	
	//static HBITMAP hBitmap=NULL;
	// TODO: Add extra initialization here
	
	m_no=GetNextNo();
	
	m_name="";
	m_address="";
	m_phone="";
	m_score=0;
	m_source="";
	m_content="";
	m_birth_year=m_year-18;
	m_birth_month=1;
	m_birth_day=1;
	m_sex="";
	m_sexid="1";
	strSQL="select trim(ctext) from userdict where category=\'001\' 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();
	}
	m_nation="";
	m_nationid="01";
	strSQL="select trim(ctext) from userdict where category=\'002\' and ccode=\'01\'";
	Success=rs.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL);
	if (Success)
	{
		if(rs.GetRecordCount()>0)
			rs.GetFieldValue((short)0,m_nation);
		rs.Close();
	}
	m_polity="";
	m_polityid="1";
	strSQL="select trim(ctext) from userdict where category=\'003\' and ccode=\'1\'";
	Success=rs.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL);
	if (Success)
	{
		if(rs.GetRecordCount()>0)
			rs.GetFieldValue((short)0,m_polity);
		rs.Close();
	}
	
}
BOOL CStuIdlg::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 student(stu_no,name,nation,sex,polity,score,birthday";
	strValue="\'"+m_no+"\',\'"+m_name+"\',\'"+m_nationid+"\',\'"+m_sexid+"\',\'"+m_polityid+"\',"+strTemp;
	if (!m_source.IsEmpty())
	{
		strSQL+=",source";
		strValue+=",\'"+m_source+"\'";
	}
	if (!m_phone.IsEmpty())
	{
		strSQL+=",home_phone";
		strValue+=",\'"+m_phone+"\'";
	}
	if (!m_address.IsEmpty())
	{
		strSQL+=",address";
		strValue+=",\'"+m_address+"\'";
	}
	if (!m_content.IsEmpty())
	{
		strSQL+=",content";
		strValue+=",\'"+m_content+"\'";
	}
	strSQL+=") values("+strValue+")";
	//MessageBox(strSQL);
	m_pDB->ExecuteSQL(strSQL);
	return TRUE;
}

CString CStuIdlg::KillFocus(CString tCategory,CString & tCode, int tLen)
{
	CStudentSet 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 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 CStuIdlg::GenHelp(CString tCategory)
{
	CStudentSet 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 + -