ScoreInputDlg.cpp
资源名称:school.rar [点击查看]
上传用户:rs600066
上传日期:2017-10-16
资源大小:4788k
文件大小:7k
源码类别:
数据库系统
开发平台:
Visual C++
- // ScoreInputDlg.cpp : implementation file
- //
- #include "stdafx.h"
- #include "school.h"
- #include "ScoreInputDlg.h"
- #include "classset.h"
- #include "examtimeset.h"
- #include "examsubjectset.h"
- #include "examtypeset.h"
- #include "StudentSet.h"
- #include "scoredlg.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CScoreInputDlg dialog
- CScoreInputDlg::CScoreInputDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CScoreInputDlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CScoreInputDlg)
- m_strClass = _T("");
- m_strSubject = _T("");
- m_strTime = _T("");
- m_strType = _T("");
- //}}AFX_DATA_INIT
- }
- void CScoreInputDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CScoreInputDlg)
- DDX_Control(pDX, IDC_COMBO_TYPE, m_ctrType);
- DDX_Control(pDX, IDC_COMBO_TIME, m_ctrTime);
- DDX_Control(pDX, IDC_COMBO_SUBJECT, m_ctrSubject);
- DDX_Control(pDX, IDC_COMBO_CLASS, m_ctrClass);
- DDX_Control(pDX, IDC_LIST2, m_ctrList);
- DDX_CBString(pDX, IDC_COMBO_CLASS, m_strClass);
- DDX_CBString(pDX, IDC_COMBO_SUBJECT, m_strSubject);
- DDX_CBString(pDX, IDC_COMBO_TIME, m_strTime);
- DDX_CBString(pDX, IDC_COMBO_TYPE, m_strType);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CScoreInputDlg, CDialog)
- //{{AFX_MSG_MAP(CScoreInputDlg)
- ON_BN_CLICKED(IDC_BUTTON_INPUT, OnButtonInput)
- ON_NOTIFY(NM_DBLCLK, IDC_LIST2, OnDblclkList2)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CScoreInputDlg message handlers
- void CScoreInputDlg::OnButtonInput()
- {
- // TODO: Add your control notification handler code here
- UpdateData();
- if(m_strClass.IsEmpty())
- {
- AfxMessageBox("请选择班级");
- return;
- }
- if(m_strTime.IsEmpty())
- {
- AfxMessageBox("请选择考试时间段");
- return;
- }
- if(m_strType.IsEmpty())
- {
- AfxMessageBox("请选择考试类型");
- return;
- }
- if(m_strSubject.IsEmpty())
- {
- AfxMessageBox("请选择考试科目");
- return;
- }
- CString strSQL;
- strSQL.Format("select * from score
- where class = '%s' and time = '%s'
- and type = '%s' and subject = '%s'"
- ,m_strClass,m_strTime,m_strType,m_strSubject);
- if(!m_recordset.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL))
- {
- MessageBox("打开数据库失败!","数据库错误",MB_OK);
- return ;
- }
- if(m_recordset.GetRecordCount()==0)
- {
- m_recordset.Close();
- CreateScoreTable();
- }
- else
- {
- m_recordset.Close();
- }
- RefreshData(strSQL);
- }
- void CScoreInputDlg::CreateScoreTable()
- {
- CString strSQL;
- CStudentSet StudentSet;
- strSQL.Format("select * from student where class = '%s'",m_strClass);
- if(!StudentSet.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL))
- {
- MessageBox("打开数据库失败!","数据库错误",MB_OK);
- return ;
- }
- if(!m_recordset.Open(AFX_DB_USE_DEFAULT_TYPE))
- {
- MessageBox("打开数据库失败!","数据库错误",MB_OK);
- return ;
- }
- while(!StudentSet.IsEOF())
- {
- m_recordset.AddNew();
- m_recordset.m_code = StudentSet.m_code;
- m_recordset.m_class = m_strClass;
- m_recordset.m_name = StudentSet.m_name;
- m_recordset.m_subject = m_strSubject;
- m_recordset.m_time = m_strTime;
- m_recordset.m_type = m_strType;
- m_recordset.Update();
- StudentSet.MoveNext();
- }
- m_recordset.Close();
- StudentSet.Close();
- }
- void CScoreInputDlg::RefreshData(CString strSQL)
- {
- m_ctrList.DeleteAllItems();
- m_ctrList.SetRedraw(FALSE);
- UpdateData(TRUE);
- if(!m_recordset.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL))
- {
- MessageBox("打开数据库失败!","数据库错误",MB_OK);
- return ;
- }
- int i=0;
- char buffer[20];
- while(!m_recordset.IsEOF())
- {
- _ltoa(m_recordset.m_ID,buffer,10);
- m_ctrList.InsertItem(i,buffer);
- m_ctrList.SetItemText(i,1,m_recordset.m_code);
- m_ctrList.SetItemText(i,2,m_recordset.m_name);
- m_ctrList.SetItemText(i,3,m_recordset.m_subject);
- _ltoa(m_recordset.m_score,buffer,10);
- m_ctrList.SetItemText(i,4,buffer);
- _ltoa(m_recordset.m_makeup_score,buffer,10);
- m_ctrList.SetItemText(i,5,buffer);
- m_ctrList.SetItemText(i,6,m_recordset.m_absent);
- i++;
- m_recordset.MoveNext();
- }
- m_recordset.Close();
- m_ctrList.SetRedraw(TRUE);
- }
- BOOL CScoreInputDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
- CString strSQL;
- //初始化班级
- CClassSet ClassSet ;
- strSQL="select * from class";
- if(!ClassSet.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL))
- {
- AfxMessageBox("打开数据库失败!");
- }
- while(!ClassSet.IsEOF())
- {
- m_ctrClass.AddString(ClassSet.m_code);
- ClassSet.MoveNext();
- }
- ClassSet.Close();
- //初始化时间段
- CExamtimeSet TimeSet ;
- strSQL="select * from examtime";
- if(!TimeSet.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL))
- {
- AfxMessageBox("打开数据库失败!");
- }
- while(!TimeSet.IsEOF())
- {
- m_ctrTime.AddString(TimeSet.m_time);
- TimeSet.MoveNext();
- }
- TimeSet.Close();
- //初始化考试类型
- CExamtypeSet TypeSet ;
- strSQL="select * from examtype";
- if(!TypeSet.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL))
- {
- AfxMessageBox("打开数据库失败!");
- }
- while(!TypeSet.IsEOF())
- {
- m_ctrType.AddString(TypeSet.m_name);
- TypeSet.MoveNext();
- }
- TypeSet.Close();
- //初始化考试科目
- CExamSubjectSet SubjectSet ;
- strSQL="select * from examsubject";
- if(!SubjectSet.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL))
- {
- AfxMessageBox("打开数据库失败!");
- }
- while(!SubjectSet.IsEOF())
- {
- m_ctrSubject.AddString(SubjectSet.m_name);
- SubjectSet.MoveNext();
- }
- SubjectSet.Close();
- //初始化成绩列表
- m_ctrList.InsertColumn(0,"序号");
- m_ctrList.InsertColumn(1,"学号");
- m_ctrList.InsertColumn(2,"姓名");
- m_ctrList.InsertColumn(3,"科目");
- m_ctrList.InsertColumn(4,"成绩");
- m_ctrList.InsertColumn(5,"补考成绩");
- m_ctrList.InsertColumn(6,"缺考标志");
- m_ctrList.SetColumnWidth(0,60);
- m_ctrList.SetColumnWidth(1,80);
- m_ctrList.SetColumnWidth(2,80);
- m_ctrList.SetColumnWidth(3,100);
- m_ctrList.SetColumnWidth(4,80);
- m_ctrList.SetColumnWidth(5,80);
- m_ctrList.SetColumnWidth(6,60);
- m_ctrList.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);
- return TRUE; // return TRUE unless you set the focus to a control
- // EXCEPTION: OCX Property Pages should return FALSE
- }
- void CScoreInputDlg::OnDblclkList2(NMHDR* pNMHDR, LRESULT* pResult)
- {
- // TODO: Add your control notification handler code here
- CString strSQL;
- long score=0,makeup=0;
- CScoreDlg Dlg;
- UpdateData(TRUE);
- int i = m_ctrList.GetSelectionMark();
- if(i<0) return;
- if(IDOK!=Dlg.DoModal())
- {
- return;
- }
- if(!Dlg.m_strScore.IsEmpty())
- score = atol(Dlg.m_strScore);
- if(!Dlg.m_strMakeup.IsEmpty())
- makeup = atol(Dlg.m_strMakeup);
- strSQL.Format("select * from score where ID=%s",m_ctrList.GetItemText(i,0));
- if(!m_recordset.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL))
- {
- MessageBox("打开数据库失败!","数据库错误",MB_OK);
- return ;
- }
- m_recordset.Edit();
- if(Dlg.m_bAbsent)
- m_recordset.m_absent = "是";
- m_recordset.m_score = score;
- m_recordset.m_makeup_score = makeup;
- m_recordset.Update();
- char buffer[20];
- _ltoa(m_recordset.m_score,buffer,10);
- m_ctrList.SetItemText(i,4,buffer);
- _ltoa(m_recordset.m_makeup_score,buffer,10);
- m_ctrList.SetItemText(i,5,buffer);
- m_ctrList.SetItemText(i,6,m_recordset.m_absent);
- m_recordset.Close();
- *pResult = 0;
- }