⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 scoredlg.cpp

📁 本源码非常详细的实现了一个运动员信息管理系统 其中包括管理员
💻 CPP
字号:
// ScoreDlg.cpp : implementation file
//

#include "stdafx.h"
#include "AthleteInfo.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_SCORE_EDIT, m_bEdit);
	DDX_Control(pDX, IDC_SCORE_DEL, m_bDel);
	DDX_Control(pDX, IDC_SCORE_ADD, m_bAdd);
	DDX_Control(pDX, IDC_SCORE, m_strScore);
	DDX_Control(pDX, IDC_LIST_SCORE, m_list);
	DDX_Control(pDX, IDC_ITEM_NAME, m_strItemName);
	DDX_Control(pDX, IDC_ATHLETE_NAME, m_strAthleteName);
	DDX_Control(pDX, ID_SCORE_CONFIRM, m_bConfirm);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CScoreDlg, CDialog)
	//{{AFX_MSG_MAP(CScoreDlg)
	ON_BN_CLICKED(IDC_SCORE_ADD, OnScoreAdd)
	ON_BN_CLICKED(IDC_SCORE_EDIT, OnScoreEdit)
	ON_BN_CLICKED(IDC_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("athleteinfo"));
		m_recordSet.m_pDatabase=&m_database;
	}
	m_list.InsertColumn(0,"成绩编号");
	m_list.InsertColumn(1,"运动员名");
	m_list.InsertColumn(2,"参加项目");
	m_list.InsertColumn(3,"比赛成绩");

    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();
	for(int j=1;j<50;j++){
		CString s;
		s.Format("%d",j);
		m_strScore.AddString(s);
	}
	m_strScore.SelectString(0,"3");
	RefreshList();
	return true;
	

}

void CScoreDlg::RefreshList()
{
	m_list.DeleteAllItems();
	CString strSQL;
	strSQL.Format("select * from score,athlete,item where athlete.athlete_no=score.athlete_no and item.item_no=score.item_no and score.active_status='Y'");
	m_recordSet.Open(CRecordset::forwardOnly,strSQL);
	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("athlete_name",temp);
		m_list.SetItemText(i,1,temp);
		m_recordSet.GetFieldValue("item_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() 
{
	// TODO: Add your control notification handler code here
	CScoreAddDlg scoreAdd;
	//设置0表示为添加记录状态
	scoreAdd.id="0";
	//显示对话框
	scoreAdd.DoModal();
    RefreshList();
	
}

void CScoreDlg::OnScoreEdit() 
{
	// TODO: Add your control notification handler code here
	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() 
{
	// TODO: Add your control notification handler code here
	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 + -