📄 scoreadddlg.cpp
字号:
// ScoreAddDlg.cpp : implementation file
//
#include "stdafx.h"
#include "member.h"
#include "ScoreAddDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CScoreAddDlg dialog
CScoreAddDlg::CScoreAddDlg(CWnd* pParent /*=NULL*/)
: CDialog(CScoreAddDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CScoreAddDlg)
m_addcourseID = _T("");
m_addmemID = _T("");
m_addcoursename = _T("");
m_addscore = 0;
m_addcoursescore = 0;
//}}AFX_DATA_INIT
}
void CScoreAddDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CScoreAddDlg)
DDX_Control(pDX, IDC_LIST, m_list);
DDX_Text(pDX, IDC_ADD_COURSRID, m_addcourseID);
DDX_Text(pDX, IDC_ADD_MEMID, m_addmemID);
DDX_Text(pDX, IDC_ADD_COURSENAME, m_addcoursename);
DDX_Text(pDX, IDC_ADD_SCORE, m_addscore);
DDX_Text(pDX, IDC_ADD_COURSESCORE, m_addcoursescore);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CScoreAddDlg, CDialog)
//{{AFX_MSG_MAP(CScoreAddDlg)
ON_BN_CLICKED(IDDEL, OnDel)
ON_NOTIFY(NM_CLICK, IDC_LIST, OnClickList)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CScoreAddDlg message handlers
BOOL CScoreAddDlg::OnInitDialog()
{
CDialog::OnInitDialog();
//设置表格风格
m_list.SetExtendedStyle(m_list.GetExtendedStyle()|LVS_EX_GRIDLINES|LVS_EX_FULLROWSELECT);
//设置表头
m_list.InsertColumn(0,"学号",LVCFMT_LEFT,80);
m_list.InsertColumn(1,"课程编号",LVCFMT_LEFT,80);
m_list.InsertColumn(2,"课程名称",LVCFMT_LEFT,90);
m_list.InsertColumn(3,"学分",LVCFMT_LEFT,80);
m_list.InsertColumn(4,"成绩",LVCFMT_LEFT,80);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CScoreAddDlg::AddScore()
{
try
{
if(m_ScoreReSet.IsOpen())
m_ScoreReSet.Close();
//打开记录集
CString strsql;
strsql.Format("select * from score where MemID='%s' and CourseID='%s'",m_addmemID,m_addcourseID);
m_ScoreReSet.Open(CRecordset::snapshot,strsql,CRecordset::none);
if(m_ScoreReSet.IsOpen()&&!m_ScoreReSet.IsEOF())
{
AfxMessageBox("该记录已存在!");
return;
}
else
{
m_ScoreReSet.AddNew();
m_ScoreReSet.m_MemID=m_addmemID;
m_ScoreReSet.m_CourseID=m_addcourseID;
m_ScoreReSet.m_CourseName=m_addcoursename;
m_ScoreReSet.m_CourseScore=m_addcoursescore;
m_ScoreReSet.m_Score=m_addscore;
if(m_ScoreReSet.CanUpdate())
{
m_ScoreReSet.Update();
}
}
m_ScoreReSet.Close();
}
catch(CDBException *e)
{
e->Delete();
return;
}
//将记录集显示到CList中
CString strcoursescore,strscore;
m_list.InsertItem(0,m_addmemID);
m_list.SetItemText(0,1,m_addcourseID);
m_list.SetItemText(0,2,m_addcoursename);
strcoursescore.Format("%d",m_addcoursescore);
m_list.SetItemText(0,3,strcoursescore);
strscore.Format("%d",m_addscore);
m_list.SetItemText(0,4,strscore);
}
void CScoreAddDlg::DelScore()
{
int row=m_list.GetSelectionMark();
CString position1=m_list.GetItemText(row,0);
CString position2=m_list.GetItemText(row,1);
if(position1=="")
{
AfxMessageBox("请先选择一条信息!");
return;
}
if(MessageBox("确定删除成绩?","删除确认",MB_YESNO|MB_ICONQUESTION)==IDYES)
{
try
{
//删除个人信息
if(m_ScoreReSet.IsOpen())
m_ScoreReSet.Close();
CString strsql;
strsql.Format("select * from score where MemID='%s' and CourseID='%s'",position1,position2);
m_ScoreReSet.Open(CRecordset::snapshot,strsql,CRecordset::none);
//如果用户记录存在,则进行修改操作
if(m_ScoreReSet.IsOpen() && !m_ScoreReSet.IsEOF())
{
//设置编辑当前记录
m_ScoreReSet.Delete();
//更新完毕,关闭数据库
m_ScoreReSet.Close();
}
else //考虑特例,如果操作中用户信息不存在了
{
//关闭数据库
if(m_ScoreReSet.IsOpen())
m_ScoreReSet.Close();
//提示用户
AfxMessageBox("该记录不存在,无法删除!");
return;
}
}
catch(CDBException*e)
{
e->ReportError ();
return;
}
//在ListCtrl中删除当前用户信息
POSITION pos=m_list.GetFirstSelectedItemPosition();
int m_CurUser=m_list.GetNextSelectedItem(pos);
m_list.DeleteItem(m_CurUser);
}
}
void CScoreAddDlg::OnOK()
{
// TODO: Add extra validation here
UpdateData(TRUE);
if(m_addmemID.GetLength()<=0||m_addcourseID.GetLength()<=0)
{
AfxMessageBox("学号、课程编号不能为空");
return;
}
AddScore();
//清空编辑框
m_addmemID="";
m_addcourseID="";
m_addcoursename="";
m_addcoursescore=0;
m_addscore=0;
UpdateData(FALSE);
}
void CScoreAddDlg::OnDel()
{
// TODO: Add your control notification handler code here
DelScore();
}
void CScoreAddDlg::ShowScore()
{
int row=m_list.GetSelectionMark();
CString position1=m_list.GetItemText(row,0);
CString position2=m_list.GetItemText(row,1);
// AfxMessageBox(position);
try
{
if(m_ScoreReSet.IsOpen())
m_ScoreReSet.Close();
CString strSQL;
strSQL.Format("select * from score where MemID='%s' and CourseID='%s'",position1,position2);
// AfxMessageBox(strSQL);
m_ScoreReSet.Open(CRecordset::snapshot,strSQL,CRecordset::none);
m_addmemID=m_ScoreReSet.m_MemID;
m_addcourseID=m_ScoreReSet.m_CourseID;
m_addcoursename=m_ScoreReSet.m_CourseName;
m_addcoursescore=m_ScoreReSet.m_CourseScore;
m_addscore=m_ScoreReSet.m_Score;
UpdateData(FALSE);
}
catch(CDBException *e)
{
e->Delete();
return;
}
}
void CScoreAddDlg::OnClickList(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
ShowScore();
*pResult = 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -