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

📄 xuanxiuke.cpp

📁 本系统是vc开发的成绩管理系统,功能强大易于阅读.
💻 CPP
字号:
// xuanxiuke.cpp : implementation file
//

#include "stdafx.h"
#include "mark.h"
#include "xuanxiuke.h"
#include "MainFrm.h"
#include "adodc.h"
#include "_recordset.h"
#include "fields.h"
#include "field.h"


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

/////////////////////////////////////////////////////////////////////////////
// Cxuanxiuke

IMPLEMENT_DYNCREATE(Cxuanxiuke, CFormView)

Cxuanxiuke::Cxuanxiuke()
	: CFormView(Cxuanxiuke::IDD)
{
	//{{AFX_DATA_INIT(Cxuanxiuke)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}

Cxuanxiuke::~Cxuanxiuke()
{
}

void Cxuanxiuke::DoDataExchange(CDataExchange* pDX)
{
	CFormView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(Cxuanxiuke)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(Cxuanxiuke, CFormView)
	//{{AFX_MSG_MAP(Cxuanxiuke)
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	ON_CBN_SELCHANGE(IDC_COMBO1, OnSelchangeCombo1)
	ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
	ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// Cxuanxiuke diagnostics

#ifdef _DEBUG
void Cxuanxiuke::AssertValid() const
{
	CFormView::AssertValid();
}

void Cxuanxiuke::Dump(CDumpContext& dc) const
{
	CFormView::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// Cxuanxiuke message handlers

void Cxuanxiuke::OnButton1() 
{
	CMainFrame *pframe=(CMainFrame *)AfxGetMainWnd();
	CEdit *kech=(CEdit *)GetDlgItem(IDC_EDIT1);
	CString kch;
	kech->GetWindowText(kch);
	if(kch==""){
		pframe->Agenttalk("必须输入课程号!");
		return;
	}
	bool isfound=false;
	CAdodc *adodc1=(CAdodc *)GetDlgItem(IDC_ADODC1);
	CComboBox *jiaosh=(CComboBox *)GetDlgItem(IDC_COMBO1);
	jiaosh->ResetContent();
	CEdit *kcmc=(CEdit *)GetDlgItem(IDC_EDIT2);
	adodc1->GetRecordset().MoveFirst();
	while(!adodc1->GetRecordset().GetEof()){
		COleVariant kechenghao=adodc1->GetRecordset().GetFields().GetItem(COleVariant("课程号")).GetValue();
		if(COleVariant(kch)==kechenghao){
			isfound=true;
			COleVariant jsh=adodc1->GetRecordset().GetFields().GetItem(COleVariant("教师号")).GetValue();
			CString jiaoshihao;
			jiaoshihao=jsh.bstrVal;
			jiaosh->AddString(jiaoshihao);
			jsh=adodc1->GetRecordset().GetFields().GetItem(COleVariant("课程名称")).GetValue();
			jiaoshihao=jsh.bstrVal;
			kcmc->SetWindowText(jiaoshihao);
		}
		adodc1->GetRecordset().MoveNext();
	}
	if(!isfound){
		pframe->Agenttalk("找不到该课程!");
		kech->SetWindowText("");
		kech->SetFocus();
	}
	adodc1->GetRecordset().MoveFirst();	
}

void Cxuanxiuke::OnSelchangeCombo1() 
{
	CComboBox *combo=(CComboBox *)GetDlgItem(IDC_COMBO1);
	CAdodc *adodc=(CAdodc *)GetDlgItem(IDC_ADODC1);
	CEdit *kech=(CEdit *)GetDlgItem(IDC_EDIT1);
	CString kch;
	kech->GetWindowText(kch);
	CString str;
	int i=combo->GetCurSel();
	combo->GetLBText(i,str);
	adodc->GetRecordset().MoveFirst();
	bool isfound=false;
	while(!adodc->GetRecordset().GetEof()){
		COleVariant jsh=adodc->GetRecordset().GetFields().GetItem(COleVariant("教师号")).GetValue();
		if(jsh==COleVariant(str)){
			COleVariant k=adodc->GetRecordset().GetFields().GetItem(COleVariant("课程号")).GetValue();
			if(COleVariant(kch)==k){
				isfound=true;
				k=adodc->GetRecordset().GetFields().GetItem(COleVariant("教师名")).GetValue();
				CEdit *pedit=(CEdit *)GetDlgItem(IDC_EDIT3);
				CString temp=k.bstrVal;
				pedit->SetWindowText(temp);
				CEdit *detail=(CEdit *)GetDlgItem(IDC_EDIT4);
				COleVariant tem=adodc->GetRecordset().GetFields().GetItem(COleVariant("课程名称")).GetValue();
				CString tem1=tem.bstrVal;
				CString det="课程名:"+tem1;
				tem=adodc->GetRecordset().GetFields().GetItem(COleVariant("院系")).GetValue();
				tem1=tem.bstrVal;
				det+=",由"+tem1+"的"+temp+"老师任课,共";
				tem=adodc->GetRecordset().GetFields().GetItem(COleVariant("学时")).GetValue();
				tem1=tem.bstrVal;
				det+=tem1+"学时,";
				tem=adodc->GetRecordset().GetFields().GetItem(COleVariant("学分")).GetValue();
				tem1=tem.bstrVal;
				det+=tem1+"学分,该门课属于";
				tem=adodc->GetRecordset().GetFields().GetItem(COleVariant("课程类别")).GetValue();
				tem1=tem.bstrVal;
				det+=tem1;
				detail->SetWindowText(det);
				CString m_kch,m_jsh;
				kech->GetWindowText(m_kch);
				combo->GetLBText(i,m_jsh);
				CString sql="Select 学生档案表.班级,学生档案表.学号,学生档案表.姓名,学生档案表.性别,选课情况.成绩,选课情况.状态 from 学生档案表,选课情况,课程,授课,教师档案表 where 学生档案表.学号=选课情况.学号 and 选课情况.课程号=课程.课程号 and 课程.课程号=授课.课程号 and 授课.教师号=教师档案表.教师号 and 选课情况.教师号="+m_jsh+" and 教师档案表.教师号="+m_jsh+" and 课程.课程号="+m_kch;
				CAdodc *ado=(CAdodc *)GetDlgItem(IDC_ADODC2);
				ado->SetRecordSource(sql);
				ado->Refresh();
				break;
			}
		}
		adodc->GetRecordset().MoveNext();
	}
	if(!isfound){
		CMainFrame *pframe=(CMainFrame *)AfxGetMainWnd();
		pframe->Agenttalk("没有找到符合条件的信息!");
		adodc->GetRecordset().MoveFirst();
	}	
}

void Cxuanxiuke::OnButton2() 
{
	CEdit *pedit=(CEdit *)GetDlgItem(IDC_EDIT5);
	CMainFrame *pframe=(CMainFrame *)AfxGetMainWnd();
	CString find;
	pedit->GetWindowText(find);
	if(find==""){
		pframe->Agenttalk("增加的学号不能为空!");
		pedit->SetFocus();
		return;
	}
	CEdit *pkch=(CEdit *)GetDlgItem(IDC_EDIT1);
	CComboBox *combo=(CComboBox *)GetDlgItem(IDC_COMBO1);
	CString kch,jsh;
	pkch->GetWindowText(kch);
	combo->GetWindowText(jsh);
	if(kch==""){
		pframe->Agenttalk("课程号不能为空!");
		return;
	}
	if(jsh==""){
		pframe->Agenttalk("教师号不能为空!");
		return;
	}
	m_pConnection.CreateInstance(__uuidof(Connection));
	
	m_pConnection->Open("Provider=SQLOLEDB.1;Persist Security Info=False;User ID=hello;Pwd=panpan;Initial Catalog=student;Data Source=localhost","hello","panpan",0);

	// 使用ADO创建数据库记录集
	m_pRecordset.CreateInstance(__uuidof(Recordset));
	m_pRecordset->Open("SELECT * FROM 选课情况",              
							m_pConnection.GetInterfacePtr(),	 // 获取库接库的IDispatch指针
							adOpenDynamic,
							adLockOptimistic,
							adCmdText);

	m_pRecordset->AddNew();
	m_pRecordset->PutCollect("学号", _variant_t(find));
	m_pRecordset->PutCollect("课程号", _variant_t(kch));
	m_pRecordset->PutCollect("教师号",_variant_t(jsh));
	m_pRecordset->Update();
	m_pRecordset->Close();
	m_pRecordset = NULL;
	m_pConnection->Close();
	m_pConnection=NULL;
	CAdodc *pdc=(CAdodc *)GetDlgItem(IDC_ADODC2);
	pdc->Refresh();
	pframe->Agenttalk("为"+find+"同学添加了一门由"+jsh+"教师教授的"+kch+"课");
}

void Cxuanxiuke::OnButton3() 
{
	CEdit *pedit=(CEdit *)GetDlgItem(IDC_EDIT6);
	CMainFrame *pframe=(CMainFrame *)AfxGetMainWnd();
	CString find;
	pedit->GetWindowText(find);
	if(find==""){
		pframe->Agenttalk("删除课程的学号不能为空!");
		pedit->SetFocus();
		return;
	}
	CEdit *pkch=(CEdit *)GetDlgItem(IDC_EDIT1);
	CComboBox *combo=(CComboBox *)GetDlgItem(IDC_COMBO1);
	CString kch,jsh;
	pkch->GetWindowText(kch);
	combo->GetWindowText(jsh);
	if(kch==""){
		pframe->Agenttalk("课程号不能为空!");
		return;
	}
	if(jsh==""){
		pframe->Agenttalk("教师号不能为空!");
		return;
	}
	m_pConnection.CreateInstance(__uuidof(Connection));
	
	m_pConnection->Open("Provider=SQLOLEDB.1;Persist Security Info=False;User ID=hello;Pwd=panpan;Initial Catalog=student;Data Source=localhost","hello","panpan",0);

	// 使用ADO创建数据库记录集
	m_pRecordset.CreateInstance(__uuidof(Recordset));
	m_pRecordset->Open("SELECT * FROM 选课情况",              
							m_pConnection.GetInterfacePtr(),	 // 获取库接库的IDispatch指针
							adOpenDynamic,
							adLockOptimistic,
							adCmdText);

	m_pRecordset->MoveFirst();
	bool isfind=false;
	while(!m_pRecordset->GetadoEOF()){
		if(m_pRecordset->GetCollect("学号")==_variant_t(find)){
			if(m_pRecordset->GetCollect("课程号")==_variant_t(kch) && m_pRecordset->GetCollect("教师号")==_variant_t(jsh)){
				isfind=true;
				m_pRecordset->Delete(adAffectCurrent);
				m_pRecordset->Update();
				pframe->Agenttalk("删除成功!");
			}
		}
		m_pRecordset->MoveNext();
	}
	if(!isfind){
		pframe->Agenttalk("没有找到符合条件的记录!");
	}
	m_pRecordset->Close();
	m_pRecordset = NULL;
	m_pConnection->Close();
	m_pConnection=NULL;
	CAdodc *pdc=(CAdodc *)GetDlgItem(IDC_ADODC2);
	pdc->Refresh();
}

⌨️ 快捷键说明

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