?? scoredlg.cpp
字號:
// ScoreDlg.cpp : implementation file
//
#include "stdafx.h"
#include "StudentScore.h"
#include "ScoreDlg.h"
#include "ScoreAddDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CScoreDlg dialog
CScoreDlg::CScoreDlg(CWnd* pParent /*=NULL*/)
: CDialog(CScoreDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CScoreDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
void CScoreDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CScoreDlg)
DDX_Control(pDX, IDC_LIST_SCORE, m_list);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CScoreDlg, CDialog)
//{{AFX_MSG_MAP(CScoreDlg)
ON_BN_CLICKED(ID_SCORE_ADD, OnScoreAdd)
ON_BN_CLICKED(ID_SCORE_EDIT, OnScoreEdit)
ON_BN_CLICKED(ID_SCORE_DEL, OnScoreDel)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CScoreDlg message handlers
BOOL CScoreDlg::OnInitDialog()
{
CDialog::OnInitDialog();
//如果沒有打開數據庫,則打開數據庫
if(!m_database.IsOpen())
{
m_database.Open(_T("studentscore"));
m_recordSet.m_pDatabase=&m_database;
}
//初始化里CList 控件的和header
m_list.InsertColumn(0,"成績編號");
m_list.InsertColumn(1,"學生名");
m_list.InsertColumn(2,"課程名");
m_list.InsertColumn(3,"分數");
//設置header的寬度
RECT rectList;
m_list.GetWindowRect(&rectList);
int wid=rectList.right-rectList.left-4;
for(int i=0;i<4;i++)
m_list.SetColumnWidth(i,wid/4);
m_list.SetExtendedStyle(LVS_EX_FULLROWSELECT);
//調用refreshList()初始化CList中的數據
RefreshList();
return true;
}
void CScoreDlg::RefreshList()
{
//刪除CList的所有內容
m_list.DeleteAllItems();
//打開記錄集
CString strSQL;
strSQL.Format("select * from score,student,course where student.student_no=score.student_no and course.course_no=score.course_no and score.active_status='Y'");
m_recordSet.Open(CRecordset::forwardOnly,strSQL);
//將記錄集顯示到 CList中
for(int i=0;i<m_recordSet.GetRecordCount();i++){
CString temp;
m_recordSet.GetFieldValue("score_id",temp);
m_list.InsertItem(i,temp);
m_recordSet.GetFieldValue("student_name",temp);
m_list.SetItemText(i,1,temp);
m_recordSet.GetFieldValue("course_name",temp);
m_list.SetItemText(i,2,temp);
m_recordSet.GetFieldValue("score",temp);
m_list.SetItemText(i,3,temp);
m_recordSet.MoveNext();
}
//關閉數據庫
m_recordSet.Close();
}
void CScoreDlg::OnScoreAdd() //添加按鈕事件
{
//建立一個CScoreAddDlg對象
CScoreAddDlg scoreAdd;
//設置0表示為添加記錄狀態
scoreAdd.id="0";
//顯示對話框
scoreAdd.DoModal();
RefreshList();
}
void CScoreDlg::OnScoreEdit()//修改按鈕事件
{
//建立一個CScoreAddDlg對象
CScoreAddDlg scoreAdd;
//獲得當前所中的行
int row=m_list.GetSelectionMark();
//將id號賦值給scoreAdd對象
scoreAdd.id=m_list.GetItemText(row,0);
if(scoreAdd.id=="")//如果沒有選中行,提示選中信息
MessageBox("請選擇所需要修改的記錄!");
else
{
scoreAdd.DoModal();
RefreshList();
}
}
void CScoreDlg::OnScoreDel() //刪除按鈕事件
{
//獲得當前所中的行
int row=m_list.GetSelectionMark();
//得到當前行的id
CString id=m_list.GetItemText(row,0);
if(id=="")//如果id為空,提示選中信息
MessageBox("請選擇所需要刪除的記錄!");
else
{
CString strSQL;
//刪除語句
strSQL.Format("update score set active_status='N' where score_id=%s",id);
//執行刪除操作
m_database.ExecuteSQL(strSQL);
}
RefreshList();
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -