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

📄 scoreadddlg.cpp

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

#include "stdafx.h"
#include "AthleteInfo.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)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


void CScoreAddDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CScoreAddDlg)
	DDX_Control(pDX, IDC_SCORE_SCORE, m_cScore);
	DDX_Control(pDX, IDC_SCORE_ITEM, m_cItem);
	DDX_Control(pDX, IDC_SCORE_ATHLETE, m_cAthlete);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CScoreAddDlg, CDialog)
	//{{AFX_MSG_MAP(CScoreAddDlg)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CScoreAddDlg message handlers

BOOL CScoreAddDlg::OnInitDialog()
{
	CDialog::OnInitDialog();
	//如果没有打开数据库,则打开数据库
	CRecordset m_recordSet;
	if(!m_database.IsOpen())
	{
		m_database.Open(_T("athleteinfo"));
	    m_recordSet.m_pDatabase=&m_database;
	}
    //初始化项目下拉列表数据
	CString strSQL;
	strSQL.Format("select item_name from item where active_status='Y'");
    m_recordSet.Open(CRecordset::forwardOnly,strSQL);
	for(int i=0;i<m_recordSet.GetRecordCount();i++){
		CString temp;
		m_recordSet.GetFieldValue("item_name",temp);
		m_cItem.AddString(temp);
        m_recordSet.MoveNext();
	}
	m_recordSet.Close();
    m_cItem.SetCurSel(1);
    //初始化运动员下拉列表
	strSQL.Format("select athlete_name from athlete where active_status='Y'");
    m_recordSet.Open(CRecordset::forwardOnly,strSQL);
	for(int j=0;j<m_recordSet.GetRecordCount();j++){
		CString temp;
		m_recordSet.GetFieldValue("athlete_name",temp);
		m_cAthlete.AddString(temp);
        m_recordSet.MoveNext();
	}
	m_recordSet.Close();
    m_cAthlete.SetCurSel(1);
	//如果为修改状态
	if(id!="0")
	{
		this->SetWindowText("修改成绩窗口");//设置窗口标题为修改成绩窗口
		//并初始化控件中的值
		strSQL.Format("select item.item_name,athlete.athlete_name,score.score from athlete,item,score where score.active_status='Y' and score.athlete_no=athlete.athlete_no and item.item_no=score.item_no and score_id=%s",id);
        m_recordSet.Open(CRecordset::forwardOnly,strSQL);
		CString temp;
		m_recordSet.GetFieldValue("athlete_name",temp);
		m_cAthlete.SelectString(0,temp);
        m_recordSet.GetFieldValue("item_name",temp);
        m_cItem.SelectString(0,temp);
		m_recordSet.GetFieldValue("score",temp);
		m_cScore.SetWindowText(temp);
	}
	else//如果为添加状态
	{
		//设置窗口标题为添加窗口状态
		this->SetWindowText("添加成绩窗口");
	}
	return true;

}

void CScoreAddDlg::OnOK() 
{
	// TODO: Add extra validation here
	CString athlete,item,score,athlete_no,item_no;
	//分别获得控件中的值
	m_cAthlete.GetWindowText(athlete);
	m_cItem.GetWindowText(item);
    m_cScore.GetWindowText(score);
	if(score=="")//如果输入的成绩为空,怎提示输入成绩
	{
		MessageBox("请输入成绩!");
	}
	else//成绩不为空
	{
		CString strSQL;
		//查出该运动员的号码
		strSQL.Format("select * from athlete where active_status='Y' and athlete_name='%s'",athlete);
		CRecordset m_recordSet=&m_database;
		m_recordSet.Open(CRecordset::forwardOnly,strSQL);
        m_recordSet.GetFieldValue("athlete_no",athlete_no);
		m_recordSet.Close();
		//查出该项目的项目号 
        strSQL.Format("select * from item where active_status='Y' and item_name='%s'",item);
		m_recordSet.Open(CRecordset::forwardOnly,strSQL);
        m_recordSet.GetFieldValue("item_no",item_no);;
		m_recordSet.Close();
		//如果id为0,则认为是添加记录
		if(this->id=="0")
		{
			//添加SQL语句
			strSQL.Format("insert into score(athlete_no,item_no,score,active_status) values('%s','%s',%s,'Y')",athlete_no,item_no,score);
			//执行添加操作
			m_database.ExecuteSQL(strSQL);
		}
		else//否则为修改记录
		{
			//修改SQL语句
			strSQL.Format("update score set athlete_no='%s',item_no='%s',score=%s where score_id=%s",athlete_no,item_no,score,id);
			//执行修改操作
			m_database.ExecuteSQL(strSQL);
		}
	
	CDialog::OnOK();
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -