📄 dialognewstudent.cpp
字号:
//
/****************************************/
/* SchoolManageSystem */
/*设计者:全佳营 */
/*时间:2004.5.9-2004-5.18 */
/*Email:ghostman@tzc.edu.cn */
/****************************************/
// DialogNewStudent.cpp : 实现文件
//
#include "stdafx.h"
#include "SchoolManageSys_2.h"
#include "DialogNewStudent.h"
#include ".\dialognewstudent.h"
#include "SchoolManageSys_2Dlg.h"
#include <math.h>
// CDialogNewStudent 对话框
IMPLEMENT_DYNAMIC(CDialogNewStudent, CDialog)
CDialogNewStudent::CDialogNewStudent(CWnd* pParent /*=NULL*/)
: CDialog(CDialogNewStudent::IDD, pParent)
, m_newname(_T(""))
, m_studynum(_T(""))
, m_newage(20)
, m_newroom(_T(""))
, m_newqq(_T(""))
, m_newemail(_T(""))
, m_newaddr(_T(""))
, m_newphone(_T(""))
, m_newyear(4)
, m_newlessons(_T("增加的课程"))
, m_newlessonmark(100)
, m_newteacher(_T(""))
{
m_strpathname="";
}
CDialogNewStudent::~CDialogNewStudent()
{
}
void CDialogNewStudent::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Text(pDX, IDC_EDIT_NEWNAME, m_newname);
DDX_Text(pDX, IDC_EDIT_NEWNUM, m_studynum);
DDX_Control(pDX, IDC_COMBO_NEWSEX, m_NewSex);
DDX_Text(pDX, IDC_EDIT_NEWAGE, m_newage);
DDX_Control(pDX, IDC_COMBO_NEWCLASSID, m_newclassid);
DDX_Text(pDX, IDC_EDIT_NEWROOM, m_newroom);
DDX_Text(pDX, IDC_EDIT_NEWQQ, m_newqq);
DDX_Text(pDX, IDC_EDIT_NEWEMAIL, m_newemail);
DDX_Text(pDX, IDC_EDIT_NEWADDR, m_newaddr);
DDX_Text(pDX, IDC_EDIT_NEWPHONE, m_newphone);
DDX_Text(pDX, IDC_EDIT_NEWYEAR, m_newyear);
DDX_Text(pDX, IDC_EDIT_NEWLESSON, m_newlessons);
DDX_Text(pDX, IDC_EDIT_NEWMARK, m_newlessonmark);
DDX_Control(pDX, IDC_DATETIMEPICKER1, m_newdatain);
DDX_Control(pDX, IDC_EDIT_NEWNAME, m_newnamed);
DDX_Control(pDX, IDC_EDIT_NEWNUM, m_newnumd);
DDX_Control(pDX, IDC_EDIT_NEWAGE, m_newaged);
DDX_Control(pDX, IDC_EDIT_NEWROOM, m_newroomd);
DDX_Control(pDX, IDC_EDIT_NEWQQ, m_newqqd);
DDX_Control(pDX, IDC_EDIT_NEWEMAIL, m_newemaild);
DDX_Control(pDX, IDC_EDIT_NEWADDR, m_newaddrd);
DDX_Control(pDX, IDC_EDIT_NEWPHONE, m_newphoned);
DDX_Control(pDX, IDC_EDIT_NEWYEAR, m_newyeard);
DDX_Control(pDX, IDC_EDIT_NEWLESSON, m_newlessond);
DDX_Control(pDX, IDC_EDIT_NEWMARK, m_newmarkd);
DDX_Control(pDX, IDC_LIST_LESSON, m_listlesson);
DDX_Control(pDX, IDC_LIST_LESSON, m_listlesson);
DDX_Text(pDX, IDC_EDIT_TEACHER, m_newteacher);
DDX_Control(pDX, IDC_EDIT_TEACHER, m_newteacherd);
}
BEGIN_MESSAGE_MAP(CDialogNewStudent, CDialog)
ON_BN_CLICKED(IDOK, OnBnClickedOk)
ON_BN_CLICKED(IDCANCEL, OnBnClickedCancel)
ON_BN_CLICKED(IDC_BUTTON_NEWPHOTO, OnBnClickedButtonNewphoto)
ON_BN_CLICKED(IDC_BUTTON_NEWCLASS, OnBnClickedButtonNewclass)
ON_CBN_SELCHANGE(IDC_COMBO_NEWSEX, OnCbnSelchangeComboNewsex)
ON_CBN_SELCHANGE(IDC_COMBO_NEWCLASSID, OnCbnSelchangeComboNewclassid)
ON_EN_SETFOCUS(IDC_EDIT_NEWNAME, OnEnSetfocusEditNewname)
ON_EN_KILLFOCUS(IDC_EDIT_NEWNAME, OnEnKillfocusEditNewname)
ON_EN_KILLFOCUS(IDC_EDIT_NEWNUM, OnEnKillfocusEditNewnum)
ON_EN_SETFOCUS(IDC_EDIT_NEWNUM, OnEnSetfocusEditNewnum)
ON_EN_KILLFOCUS(IDC_EDIT_NEWAGE, OnEnKillfocusEditNewage)
ON_EN_SETFOCUS(IDC_EDIT_NEWAGE, OnEnSetfocusEditNewage)
ON_EN_KILLFOCUS(IDC_EDIT_NEWROOM, OnEnKillfocusEditNewroom)
ON_EN_SETFOCUS(IDC_EDIT_NEWROOM, OnEnSetfocusEditNewroom)
ON_EN_KILLFOCUS(IDC_EDIT_NEWQQ, OnEnKillfocusEditNewqq)
ON_EN_SETFOCUS(IDC_EDIT_NEWQQ, OnEnSetfocusEditNewqq)
ON_EN_KILLFOCUS(IDC_EDIT_NEWEMAIL, OnEnKillfocusEditNewemail)
ON_EN_SETFOCUS(IDC_EDIT_NEWEMAIL, OnEnSetfocusEditNewemail)
ON_EN_KILLFOCUS(IDC_EDIT_NEWADDR, OnEnKillfocusEditNewaddr)
ON_EN_SETFOCUS(IDC_EDIT_NEWADDR, OnEnSetfocusEditNewaddr)
ON_EN_KILLFOCUS(IDC_EDIT_NEWPHONE, OnEnKillfocusEditNewphone)
ON_EN_SETFOCUS(IDC_EDIT_NEWPHONE, OnEnSetfocusEditNewphone)
ON_EN_KILLFOCUS(IDC_EDIT_NEWYEAR, OnEnKillfocusEditNewyear)
ON_EN_SETFOCUS(IDC_EDIT_NEWYEAR, OnEnSetfocusEditNewyear)
ON_EN_KILLFOCUS(IDC_EDIT_NEWLESSON, OnEnKillfocusEditNewlesson)
ON_EN_SETFOCUS(IDC_EDIT_NEWLESSON, OnEnSetfocusEditNewlesson)
ON_EN_KILLFOCUS(IDC_EDIT_NEWMARK, OnEnKillfocusEditNewmark)
ON_EN_SETFOCUS(IDC_EDIT_NEWMARK, OnEnSetfocusEditNewmark)
ON_NOTIFY(DTN_DATETIMECHANGE, IDC_DATETIMEPICKER1, OnDtnDatetimechangeDatetimepicker1)
ON_EN_KILLFOCUS(IDC_EDIT_TEACHER, OnEnKillfocusEditTeacher)
ON_EN_SETFOCUS(IDC_EDIT_TEACHER, OnEnSetfocusEditTeacher)
END_MESSAGE_MAP()
// CDialogNewStudent 消息处理程序
BOOL CDialogNewStudent::OnInitDialog(){
CDialog::OnInitDialog();
theApp.m_pSkin->ApplySkin((long)m_hWnd);
CWnd *m_pWnd=CWnd::FindWindow(NULL,"校人事信息管理系统");
m_adoconnection=((CSchoolManageSys_2Dlg*) m_pWnd)->m_AdoConnection;
if(m_adoconnection.IsOpen()){
//打开记录集
m_adorecordset_studentinfo.SetAdoConnection(&m_adoconnection);
m_adorecordset_studentinfo.SetCursorLocation();
m_adorecordset_studentinfo.Open("studentrecord",adCmdTable);
m_adorecordset_lessoninfo.SetAdoConnection(&m_adoconnection);
m_adorecordset_lessoninfo.SetCursorLocation();
m_adorecordset_lessoninfo.Open("lessonrecord",adCmdTable);
}
int classnum=((CSchoolManageSys_2Dlg*) m_pWnd)->classnum;
m_NewSex.AddString("男");
m_NewSex.AddString("女");
m_NewSex.SetCurSel(0);
CString tmp;
for(int i=1;i<classnum+1;i++){
tmp.Format("%d",i);
m_newclassid.AddString(tmp);
}
m_newclassid.SetCurSel(0);
//设置编辑控件初始只读
m_newnamed.SetReadOnly();
m_newnumd.SetReadOnly();
m_newaged.SetReadOnly();
m_newroomd.SetReadOnly();
m_newqqd.SetReadOnly();
m_newemaild.SetReadOnly();
m_newaddrd.SetReadOnly();
m_newphoned.SetReadOnly();
m_newyeard.SetReadOnly();
m_newlessond.SetReadOnly();
m_newmarkd.SetReadOnly();
m_newteacherd.SetReadOnly();
m_Datein=COleDateTime::GetCurrentTime();
m_listlesson.DeleteAllItems();
DWORD dwExStyle = LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES | /*LVS_EX_SUBITEMIMAGES |*/
m_listlesson.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES); LVS_EX_HEADERDRAGDROP | LVS_EX_TRACKSELECT;
LV_COLUMN lvColumn;
lvColumn.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
lvColumn.fmt = LVCFMT_LEFT; lvColumn.cx = 67;
CString tmp1;
tmp1="课程";
int len=tmp1.GetLength();
TCHAR* szBuffer = new TCHAR[len + 1];
strcpy(szBuffer, tmp1.GetBuffer(len));
tmp.ReleaseBuffer();
lvColumn.pszText = szBuffer;
m_listlesson.InsertColumn(0,&lvColumn);
tmp1="分数";
strcpy(szBuffer,tmp1.GetBuffer(len));
tmp.ReleaseBuffer();
lvColumn.pszText=szBuffer;
m_listlesson.InsertColumn(1,&lvColumn);
tmp1="教师";
strcpy(szBuffer,tmp1.GetBuffer(len));
tmp.ReleaseBuffer();
lvColumn.pszText=szBuffer;
m_listlesson.InsertColumn(2,&lvColumn);
countoflesson=0;
return TRUE;
}
void CDialogNewStudent::OnBnClickedOk()
{
// TODO: 在此添加控件通知处理程序代码
UpdateData();
if(m_newname==""||m_studynum==""||m_newyear==0) {
AfxMessageBox("请填写完整姓名,学号,和学年制");
return;
}
if(!m_adorecordset_studentinfo.IsOpen()){
AfxMessageBox("student记录集未打开");
return;
}
m_adorecordset_studentinfo.AddNew();
if(!m_adorecordset_studentinfo.PutCollect("姓名",m_newname)||
!m_adorecordset_studentinfo.PutCollect("studynum",m_studynum)||
!m_adorecordset_studentinfo.PutCollect("性别",m_selectsex)||
!m_adorecordset_studentinfo.PutCollect("age",m_newage)||
!m_adorecordset_studentinfo.PutCollect("classid",m_selectcid)||
!m_adorecordset_studentinfo.PutCollect("寝室",m_newroom)||
!m_adorecordset_studentinfo.PutCollect("QQ",m_newqq)||
!m_adorecordset_studentinfo.PutCollect("email",m_newemail)||
!m_adorecordset_studentinfo.PutCollect("地址",m_newaddr)||
!m_adorecordset_studentinfo.PutCollect("电话号码",m_newphone)||
!m_adorecordset_studentinfo.PutCollect("入学时间",m_Datein)||
!m_adorecordset_studentinfo.PutCollect("学年制",m_newyear)/*||
!*/){
AfxMessageBox("添加学生记录失败");
}
if(m_strpathname!=""){
if(!m_adorecordset_studentinfo.AppendChunk("photo",LPCTSTR(m_strpathname))){
AfxMessageBox("添加照片失败");
}
}
int lcount=m_listlesson.GetItemCount();
if(!m_adorecordset_lessoninfo.IsOpen()){
AfxMessageBox("lesson记录集未打开");
return;
}
for(int i=0;i<lcount;i++){
int mark=0;
CString tmp,tmp1;
tmp=m_listlesson.GetItemText(i,1);
int l=tmp.GetLength();
for(int j=0;j<l;j++){
mark=mark+((int)(tmp[l-j-1]-48))*pow(10,j);
}
if(!m_adorecordset_lessoninfo.PutCollect("studynum",m_studynum)||
!m_adorecordset_lessoninfo.PutCollect("课程",m_listlesson.GetItemText(i,0))||
!m_adorecordset_lessoninfo.PutCollect("教师",m_listlesson.GetItemText(i,2))||
!m_adorecordset_lessoninfo.PutCollect("分数",mark)){
AfxMessageBox("添加课程记录失败");
return;
}
}
if(!m_adoconnection.CommitTrans()){
AfxMessageBox("添加失败");
}else AfxMessageBox("添加成功");
}
void CDialogNewStudent::OnBnClickedCancel()
{
// TODO: 在此添加控件通知处理程序代码
OnCancel();
}
void CDialogNewStudent::OnBnClickedButtonNewphoto()
{
// TODO: 在此添加控件通知处理程序代码
static char BASED_CODE szFilter[] = "BMP Files (*.bmp)|*.bmp|All Files (*.*)|*.*||";
CFileDialog dlg(TRUE,"BMP",NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,szFilter);
if(dlg.DoModal()==IDOK){
m_strpathname=dlg.GetPathName();
}
if(m_strpathname=="") {
AfxMessageBox("路径名为空,请重新选择");
return;
}
}
void CDialogNewStudent::OnBnClickedButtonNewclass()
{
// TODO: 在此添加控件通知处理程序代码
//添加课程
UpdateData();
CString tmp;
tmp.Format(TEXT("%s"),m_newlessons);
m_listlesson.InsertItem(countoflesson,tmp,0);
m_listlesson.SetTextColor(RGB(128,0,200));
tmp.Format(TEXT("%d"),m_newlessonmark);
m_listlesson.SetItemText(countoflesson,1,tmp);
tmp.Format(TEXT("%s"),m_newteacher);
m_listlesson.SetItemText(countoflesson,2,tmp);
countoflesson++;
}
void CDialogNewStudent::OnCbnSelchangeComboNewsex()
{
// TODO: 在此添加控件通知处理程序代码
UpdateData();
m_NewSex.GetLBText(m_NewSex.GetCurSel(),m_selectsex);
}
void CDialogNewStudent::OnCbnSelchangeComboNewclassid()
{
// TODO: 在此添加控件通知处理程序代码
UpdateData();
m_newclassid.GetLBText(m_newclassid.GetCurSel(),m_selectcid);
}
void CDialogNewStudent::OnEnSetfocusEditNewname()
{
// TODO: 在此添加控件通知处理程序代码
m_newnamed.SetReadOnly(FALSE);
}
void CDialogNewStudent::OnEnKillfocusEditNewname()
{
// TODO: 在此添加控件通知处理程序代码
m_newnamed.SetReadOnly();
}
void CDialogNewStudent::OnOK(){
if(MessageBox("确定增加?","确定",MB_OKCANCEL|MB_ICONQUESTION)==IDOK){
m_adoconnection.CommitTrans();
}
}
void CDialogNewStudent::OnCancel(){
if(MessageBox("退出窗口?","确定退出",MB_OKCANCEL|MB_ICONQUESTION)==IDOK){
CDialog::OnCancel();
}
}
void CDialogNewStudent::OnEnKillfocusEditNewnum()
{
// TODO: 在此添加控件通知处理程序代码
m_newnumd.SetReadOnly();
}
void CDialogNewStudent::OnEnSetfocusEditNewnum()
{
// TODO: 在此添加控件通知处理程序代码
m_newnumd.SetReadOnly(FALSE);
}
void CDialogNewStudent::OnEnKillfocusEditNewage()
{
// TODO: 在此添加控件通知处理程序代码
m_newaged.SetReadOnly();
}
void CDialogNewStudent::OnEnSetfocusEditNewage()
{
// TODO: 在此添加控件通知处理程序代码
m_newaged.SetReadOnly(FALSE);
}
void CDialogNewStudent::OnEnKillfocusEditNewroom()
{
// TODO: 在此添加控件通知处理程序代码
m_newroomd.SetReadOnly();
}
void CDialogNewStudent::OnEnSetfocusEditNewroom()
{
// TODO: 在此添加控件通知处理程序代码
m_newroomd.SetReadOnly(FALSE);
}
void CDialogNewStudent::OnEnKillfocusEditNewqq()
{
// TODO: 在此添加控件通知处理程序代码
m_newqqd.SetReadOnly();
}
void CDialogNewStudent::OnEnSetfocusEditNewqq()
{
// TODO: 在此添加控件通知处理程序代码
m_newqqd.SetReadOnly(FALSE);
}
void CDialogNewStudent::OnEnKillfocusEditNewemail()
{
// TODO: 在此添加控件通知处理程序代码
m_newemaild.SetReadOnly();
}
void CDialogNewStudent::OnEnSetfocusEditNewemail()
{
// TODO: 在此添加控件通知处理程序代码
m_newemaild.SetReadOnly(FALSE);
}
void CDialogNewStudent::OnEnKillfocusEditNewaddr()
{
// TODO: 在此添加控件通知处理程序代码
m_newaddrd.SetReadOnly();
}
void CDialogNewStudent::OnEnSetfocusEditNewaddr()
{
// TODO: 在此添加控件通知处理程序代码
m_newaddrd.SetReadOnly(FALSE);
}
void CDialogNewStudent::OnEnKillfocusEditNewphone()
{
// TODO: 在此添加控件通知处理程序代码
m_newphoned.SetReadOnly();
}
void CDialogNewStudent::OnEnSetfocusEditNewphone()
{
// TODO: 在此添加控件通知处理程序代码
m_newphoned.SetReadOnly(FALSE);
}
void CDialogNewStudent::OnEnKillfocusEditNewyear()
{
// TODO: 在此添加控件通知处理程序代码
m_newyeard.SetReadOnly();
}
void CDialogNewStudent::OnEnSetfocusEditNewyear()
{
// TODO: 在此添加控件通知处理程序代码
m_newyeard.SetReadOnly(FALSE);
}
void CDialogNewStudent::OnEnKillfocusEditNewlesson()
{
// TODO: 在此添加控件通知处理程序代码
m_newlessond.SetReadOnly();
}
void CDialogNewStudent::OnEnSetfocusEditNewlesson()
{
// TODO: 在此添加控件通知处理程序代码
m_newlessond.SetReadOnly(FALSE);
}
void CDialogNewStudent::OnEnKillfocusEditNewmark()
{
// TODO: 在此添加控件通知处理程序代码
m_newmarkd.SetReadOnly();
}
void CDialogNewStudent::OnEnSetfocusEditNewmark()
{
// TODO: 在此添加控件通知处理程序代码
m_newmarkd.SetReadOnly(FALSE);
}
void CDialogNewStudent::OnDtnDatetimechangeDatetimepicker1(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMDATETIMECHANGE pDTChange = reinterpret_cast<LPNMDATETIMECHANGE>(pNMHDR);
// TODO: 在此添加控件通知处理程序代码
*pResult = 0;
BOOL t=m_newdatain.GetTime( m_Datein);
if(!t){
AfxMessageBox("选择日期错误");
}
}
void CDialogNewStudent::OnEnKillfocusEditTeacher()
{
// TODO: 在此添加控件通知处理程序代码
m_newteacherd.SetReadOnly();
}
void CDialogNewStudent::OnEnSetfocusEditTeacher()
{
// TODO: 在此添加控件通知处理程序代码
m_newteacherd.SetReadOnly(FALSE);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -