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

📄 selcouresult.cpp

📁 分管理员和学生界面
💻 CPP
字号:
// SelCouResult.cpp : implementation file
//

#include "stdafx.h"
#include "教学管理系统.h"
#include "SelCouResult.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// SelCouResult dialog


SelCouResult::SelCouResult(CWnd* pParent /*=NULL*/)
	: CDialog(SelCouResult::IDD, pParent)
{
	//{{AFX_DATA_INIT(SelCouResult)
	number = _T("");
	coursenumber = _T("");
	//}}AFX_DATA_INIT
}


void SelCouResult::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(SelCouResult)
	DDX_Control(pDX, IDC_LIST1, resultlist);
	DDX_Text(pDX, IDC_SELCOURESULT_STUNO, number);
	DDX_Text(pDX, IDC_SELCOURESULT_COUNO, coursenumber);
	//}}AFX_DATA_MAP
}

BOOL SelCouResult::OnInitDialog()
{
	CDialog::OnInitDialog();
    DWORD dwExStyle=LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES | LVS_EX_HEADERDRAGDROP ;  
    resultlist.SetExtendedStyle(dwExStyle);     
    resultlist.InsertColumn(0,"课程号",LVCFMT_CENTER,175);
	resultlist.InsertColumn(0,"学号",LVCFMT_CENTER,175);
	// TODO:  在此添加额外的初始化
   flag=0;
	return TRUE;  // return TRUE unless you set the focus to a control
	// 异常: OCX 属性页应返回 FALSE
}

BEGIN_MESSAGE_MAP(SelCouResult, CDialog)
	//{{AFX_MSG_MAP(SelCouResult)
	ON_BN_CLICKED(IDC_SELCOURESULT_QUERY, OnSelcouresultQuery)
	ON_BN_CLICKED(IDC_SELCOURESULT_MODIFY, OnSelcouresultModify)
	ON_BN_CLICKED(IDC_SELCOURESULT_DELETE, OnSelcouresultDelete)
	ON_NOTIFY(NM_CLICK, IDC_LIST1, OnClickList1)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// SelCouResult message handlers

void SelCouResult::OnSelcouresultQuery() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	CString num,coursenum;
	if(number.IsEmpty()&&coursenumber.IsEmpty())
	{
		AfxMessageBox("请输入一个查询条件");
		return;
	}
	if(!number.IsEmpty()&&!coursenumber.IsEmpty())
	{
		AfxMessageBox("只输入一个查询条件");
		return;
	}
	resultlist.DeleteAllItems();
	connection.Initialize();
	CString student;
	if(coursenumber.IsEmpty())
	{
		student.Format("select * from 选修 where 学号='%s'order by 课程号 desc",number);
		connection.Connect(student);
		if(connection.m_pRecordset->adoEOF)
		{
			AfxMessageBox("没有该学生的资料");
			number="";
			coursenumber="";
			UpdateData(FALSE);
			connection.Unitialize();	
			return;
		}
	}
	if(number.IsEmpty())
	{
		student.Format("select * from 选修 where 课程号='%s'order by 学号 desc",coursenumber);
		connection.Connect(student);
		if(connection.m_pRecordset->adoEOF)
		{
			AfxMessageBox("没有该课程的资料");
			number="";
			coursenumber="";
			UpdateData(FALSE);
			connection.Unitialize();	
			return;
		}
	}
	connection.m_pRecordset->MoveFirst();
	while(!connection.m_pRecordset->adoEOF)
	{   
		_variant_t TheValue; 
		
        TheValue = connection.m_pRecordset->Fields->GetItem("学号")->Value;
		num=TheValue.bstrVal;
		
		TheValue = connection.m_pRecordset->Fields->GetItem("课程号")->Value;
		coursenum=TheValue.bstrVal;
		
        int nIndex= resultlist.InsertItem(0,num);
        resultlist.SetItemText(nIndex,1,coursenum );
        
		connection.m_pRecordset->MoveNext();
	}	
    connection.Unitialize();
}

void SelCouResult::OnSelcouresultModify() 
{
	// TODO: Add your control notification handler code here
	if(flag==0)
		mod1();
	else
		mod2(); 
}

void SelCouResult::mod1()
{
	UpdateData(TRUE);
	if(number.IsEmpty())
	{
		AfxMessageBox("请输入学号");
		return;
	}
	if(coursenumber.IsEmpty())
	{
		AfxMessageBox("请输入课程号");
		return;
	}
	copy1=number;
	copy2=coursenumber;
	number="";
	coursenumber="";
	UpdateData(FALSE);
	MessageBox("请输入修改后的值");
	flag=1;
}

void SelCouResult::mod2()
{
	UpdateData(TRUE);
	connection.Initialize();
	CString student;
	student.Format("select * from 选修 where 学号='%s'and 课程号='%s'",copy1,copy2);
	connection.Connect(student);
	if(connection.m_pRecordset->adoEOF)
	{
		AfxMessageBox("没有资料,修改失败");
		connection.Unitialize();flag=0;
		return;
	}
	connection.m_pRecordset->Fields->GetItem(_variant_t("学号"))->Value=_bstr_t(number);
	connection.m_pRecordset->Fields->GetItem(_variant_t("课程号"))->Value=_bstr_t(coursenumber);
	connection.m_pRecordset->Update();
	connection.Unitialize();
	connection.Initialize();
	student.Format("select * from 成绩 where 学号='%s'and 课程号='%s'",copy1,copy2);
	connection.Connect(student);
	connection.m_pRecordset->Fields->GetItem(_variant_t("学号"))->Value=_bstr_t(number);
	connection.m_pRecordset->Fields->GetItem(_variant_t("课程号"))->Value=_bstr_t(coursenumber);
	connection.m_pRecordset->Update();
	connection.Unitialize();
	MessageBox("资料修改成功");
	flag=0;
}

void SelCouResult::OnSelcouresultDelete() 
{
	// TODO: Add your control notification handler code here
	CString sSql; 
	UpdateData(TRUE);
	if(number.IsEmpty())
	{
		AfxMessageBox("请输入学号");
		return;
	}
	if(coursenumber.IsEmpty())
    {
		AfxMessageBox("请输入课程号");
		return;
	}
	connection.Initialize();
    sSql.Format("select * from 选修 where 学号='%s'and 课程号='%s'",number,coursenumber);
    connection.Connect(sSql);
	if((connection.m_pRecordset->adoEOF))
	{
		AfxMessageBox("没有资料");
		connection.Unitialize();	
		return;
	}
    if(AfxMessageBox("确定删除吗?",MB_YESNO) == IDYES)
	{
		connection.m_pRecordset->Delete(adAffectCurrent);///删除当前记录
		connection.m_pRecordset->Update();
		connection.Unitialize();
		number="";
		coursenumber="";
		UpdateData(FALSE);
	}
}

void SelCouResult::OnClickList1(NMHDR* pNMHDR, LRESULT* pResult) 
{
	int nItem=resultlist.GetNextItem(-1,LVNI_SELECTED);
	if (nItem!=-1)
	{
		number=resultlist.GetItemText(nItem,0);
		coursenumber=resultlist.GetItemText(nItem,1);
		UpdateData(FALSE);
	}
	*pResult = 0;
}

void SelCouResult::OnCancel() 
{
	// TODO: Add extra cleanup here
	EndDialog(0);
}

⌨️ 快捷键说明

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