mfc源程序选课系统源程序
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
// StudentAdd.cpp : implementation file
//
#include "stdafx.h"
#include "Student.h"
#include "StudentAdd.h"
#include "SCCourseDialog.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
///////////////////////////////////////////////////////////////////////////// // CStudentAdd dialog
CStudentAdd::CStudentAdd(CWnd* pParent /*=NULL*/)
: CDialog(CStudentAdd::IDD, pParent)
{
//{{AFX_DATA_INIT(CStudentAdd)
// NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT
}
void CStudentAdd::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CStudentAdd)
// NOTE: the ClassWizard will add DDX and DDV calls here //}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CStudentAdd, CDialog)
//{{AFX_MSG_MAP(CStudentAdd)
ON_BN_CLICKED(IDC_CHOICE, OnChoice)
ON_BN_CLICKED(IDC_STUCHOICE, OnStuchoice)
ON_BN_CLICKED(IDC_STUSEARCH, OnStusearch)
ON_BN_CLICKED(IDC_STUSEECOURCE, OnStuseecource)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CStudentAdd message handlers
void CStudentAdd::OnChoice()
{
// TODO: Add your control notification handler code here
CDatabase db;
db.OpenEx("DSN=Student");
CRecordset rs(&db);
CString strSQL;
CString temp;
GetDlgItemText(IDC_EDIT6,temp);
if(temp.IsEmpty())
{
AfxMessageBox("您没有选择任何课程!");
return;
}
strSQL.Format("select * from CS where Snum='%s' and Cnum='%s' and Snum in (select Snum,sum(CSCJ) from CS group by Snum having sum(CSCJ)>3",usernumber,temp);
rs.Open(CRecordset::snapshot,strSQL);
/*计算总分是否大于60满足学分上限?*/
//select sno,sum(grade) from sc group by sno having sum(grade)>200
if(rs.GetRecordCount()!=0)
{
AfxMessageBox("您已经选了该科!");
SetDlgItemText(IDC_EDIT1,"");
SetDlgItemText(IDC_EDIT6,"");
SetDlgItemText(IDC_EDIT7,"");
SetDlgItemText(IDC_EDIT8,"");
SetDlgItemText(IDC_EDIT9,"");
SetDlgItemText(IDC_EDIT10,"");
return;
}
int nOK=MessageBox("确认选择?","提示",MB_ICONWARNING+MB_OKCANCEL);
if(nOK==IDCANCEL)
return;
CString temp1,temp2;
GetDlgItemText(IDC_EDIT7,temp1); //课名
GetDlgItemText(IDC_EDIT8,temp2); //学分
strSQL.Format("insert into CS(Snum,Cnum,Sname,Cname,CSscore)
values('%s','%s','%s','%s','%s')",usernumber,temp,username,temp1,temp2);
db.ExecuteSQL(strSQL);
AfxMessageBox("学生选课成功!");
}
void CStudentAdd::OnStuchoice()
{
// TODO: Add your control notification handler code here
SendMessage(WM_CLOSE);
}
void CStudentAdd::OnStusearch()
{
// TODO: Add your control notification handler code here
CDatabase db;
db.OpenEx("DSN=Student");
CRecordset rs(&db);
CString temp;
GetDlgItemText(IDC_EDIT1,temp);
if(temp.IsEmpty())
{
AfxMessageBox("课程号不能为空");
return;
}
CString strSQL;
strSQL.Format("select courseName,courseScore,courseTime,courseTerm from Course where courseNum='%s'",temp);
rs.Open(CRecordset::snapshot,strSQL);
if(rs.GetRecordCount()==0)
{
AfxMessageBox("该课程号不存在!");
SetDlgItemText(IDC_EDIT1,"");
return;
}
CString temp1,temp2,temp3,temp4;
rs.GetFieldValue("courseName",temp1);
rs.GetFieldValue("courseScore",temp2);
rs.GetFieldValue("courseTime",temp3);
rs.GetFieldValue("courseTerm",temp4);
SetDlgItemText(IDC_EDIT6,temp);
SetDlgItemText(IDC_EDIT7,temp1);
SetDlgItemText(IDC_EDIT8,temp2);
SetDlgItemText(IDC_EDIT9,temp3);