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

📄 bixiuke.cpp

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

#include "stdafx.h"
#include "mark.h"
#include "bixiuke.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

/////////////////////////////////////////////////////////////////////////////
// Cbixiuke

IMPLEMENT_DYNCREATE(Cbixiuke, CFormView)

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

Cbixiuke::~Cbixiuke()
{
}

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


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

/////////////////////////////////////////////////////////////////////////////
// Cbixiuke diagnostics

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

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

/////////////////////////////////////////////////////////////////////////////
// Cbixiuke message handlers

void Cbixiuke::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 Cbixiuke::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 Cbixiuke::OnButton2() 
{
	CEdit *p=(CEdit *)GetDlgItem(IDC_EDIT1);
	CMainFrame *pframe=(CMainFrame *)AfxGetMainWnd();
	pframe->Agenttalk("需要几十秒的时间,请您等待一下!");
	CString temp,temp1,temp2;
	p->GetWindowText(temp);
	if(temp==""){
		pframe->Agenttalk("课程号不能为空!");
		return;
	}
	CComboBox *pcom1=(CComboBox *)GetDlgItem(IDC_COMBO1);
	pcom1->GetWindowText(temp1);
	if(temp1==""){
		pframe->Agenttalk("教师号不能为空!");
		return;
	}
	CComboBox *pcom2=(CComboBox *)GetDlgItem(IDC_COMBO2);
	pcom2->GetWindowText(temp2);
	if(temp2==""){
		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);
	m_pc.CreateInstance(__uuidof(Connection));
	
	m_pc->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_p.CreateInstance(__uuidof(Recordset));
	m_pRecordset->Open("SELECT * FROM 学生档案表",              
							m_pConnection.GetInterfacePtr(),	 // 获取库接库的IDispatch指针
							adOpenDynamic,
							adLockOptimistic,
							adCmdText);
	m_p->Open("SELECT * FROM 选课情况",              
							m_pc.GetInterfacePtr(),	 // 获取库接库的IDispatch指针
							adOpenDynamic,
							adLockOptimistic,
							adCmdText);
	m_pRecordset->MoveFirst();
	while(!m_pRecordset->GetadoEOF()){
		if(m_pRecordset->GetCollect("班级")==_variant_t(temp2)){
			_variant_t xh=m_pRecordset->GetCollect("学号");
			m_p->MoveFirst();
			bool isfound=false;
			while(!m_p->GetadoEOF()){
				if(m_p->GetCollect("学号")==xh){
					if(m_p->GetCollect("课程号")==_variant_t(temp) && m_p->GetCollect("教师号")==_variant_t(temp1)){
						isfound=true;
					}
				}
				m_p->MoveNext();
			}
			if(!isfound){
				m_p->AddNew();
				m_p->PutCollect("学号",xh);
				m_p->PutCollect("课程号",_variant_t(temp));
				m_p->PutCollect("教师号",_variant_t(temp1));
				m_p->Update();
			}
		}
		m_pRecordset->MoveNext();
	}
	m_p->Close();
	m_p=NULL;
	m_pRecordset->Close();
	m_pRecordset=NULL;
	m_pConnection->Close();
	m_pConnection=NULL;
	m_pc->Close();
	m_pc=NULL;
	CAdodc *pdc=(CAdodc *)GetDlgItem(IDC_ADODC2);
	pdc->Refresh();
	pframe->Agenttalk("添加成功");
}

⌨️ 快捷键说明

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