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

📄 gerenbaobiao.cpp

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

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

/////////////////////////////////////////////////////////////////////////////
// Cgerenbaobiao

IMPLEMENT_DYNCREATE(Cgerenbaobiao, CFormView)

Cgerenbaobiao::Cgerenbaobiao()
	: CFormView(Cgerenbaobiao::IDD)
{
	//{{AFX_DATA_INIT(Cgerenbaobiao)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	ischoose=false;
}

Cgerenbaobiao::~Cgerenbaobiao()
{
}

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


BEGIN_MESSAGE_MAP(Cgerenbaobiao, CFormView)
	//{{AFX_MSG_MAP(Cgerenbaobiao)
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// Cgerenbaobiao diagnostics

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

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

/////////////////////////////////////////////////////////////////////////////
// Cgerenbaobiao message handlers

void Cgerenbaobiao::OnButton1() 
{
	CMainFrame *pframe=(CMainFrame *)AfxGetMainWnd();
	CEdit *xueh=(CEdit *)GetDlgItem(IDC_EDIT1);
	CString xh;
	xueh->GetWindowText(xh);
	m_xh=xh;
	if(xh==""){
		pframe->Agenttalk("学号不能为空");
		return;
	}
	CAdodc *ado=(CAdodc *)GetDlgItem(IDC_ADODC1);
	ado->GetRecordset().MoveFirst();
	bool isfound=false;
	while(!ado->GetRecordset().GetEof()){
		COleVariant v=ado->GetRecordset().GetFields().GetItem(COleVariant("学号")).GetValue();
		if(v==COleVariant(xh)){
			v=ado->GetRecordset().GetFields().GetItem(COleVariant("姓名")).GetValue();
			m_xm=v.bstrVal;
			v=ado->GetRecordset().GetFields().GetItem(COleVariant("性别")).GetValue();
			m_xb=v.bstrVal;
			v=ado->GetRecordset().GetFields().GetItem(COleVariant("院系")).GetValue();
			m_yx=v.bstrVal;
			v=ado->GetRecordset().GetFields().GetItem(COleVariant("班级")).GetValue();
			m_bj=v.bstrVal;
			CEdit *p=(CEdit *)GetDlgItem(IDC_EDIT2);
			CString temp=m_yx+" "+m_bj+" "+m_xm+" "+m_xb;
			p->SetWindowText(temp);
			isfound=true;
			break;
		}
		ado->GetRecordset().MoveNext();
	}
	if(!isfound){
		pframe->Agenttalk("没有找到该学生!");
	}else{
		ischoose=true;
		CString tmp="Select 课程.学年,课程.课程名称,课程.学时,课程.学分,选课情况.成绩,选课情况.状态 From 选课情况,课程 where 选课情况.课程号=课程.课程号 and 选课情况.学号="+m_xh;
		CAdodc *pado=(CAdodc *)GetDlgItem(IDC_ADODC3);
		pado->SetRecordSource(tmp);
		pado->Refresh();
	}
}

void Cgerenbaobiao::OnButton2() 
{
	CMainFrame *pframe=(CMainFrame *)AfxGetMainWnd();
	CAdodc *ado=(CAdodc *)GetDlgItem(IDC_ADODC3);
	long rows=ado->GetRecordset().GetRecordCount();
	if(!ischoose){
		pframe->Agenttalk("没有选择好输出内容");
		return;
	}
	COleVariant vOpt(DISP_E_PARAMNOTFOUND,VT_ERROR);
	_Application oApp;
	oApp.CreateDispatch("Excel.Application");
	if(!oApp){
		pframe->Agenttalk("不能启动Excel");
		return;
	}
	BeginWaitCursor();
	//添加工作表
	Workbooks oBooks=oApp.GetWorkbooks();
	_Workbook oBook=oBooks.Add(vOpt);
	Worksheets oSheets=oBook.GetWorksheets();
	_Worksheet oSheet=oSheets.GetItem(COleVariant((short)1));
	
	Range oRange;
	oRange=oSheet.GetRange(COleVariant("A2"),vOpt);
	oRange.CopyFromRecordset((LPUNKNOWN)ado->GetRecordset().m_lpDispatch,vOpt,vOpt);
	oRange=oSheet.GetRange(COleVariant("A1"),vOpt);
	oRange.SetValue(COleVariant("学年"));
	oRange=oSheet.GetRange(COleVariant("B1"),vOpt);
	oRange.SetValue(COleVariant("课程名称"));
	oRange=oSheet.GetRange(COleVariant("C1"),vOpt);
	oRange.SetValue(COleVariant("学时"));
	oRange=oSheet.GetRange(COleVariant("D1"),vOpt);
	oRange.SetValue(COleVariant("学分"));
	oRange=oSheet.GetRange(COleVariant("E1"),vOpt);
	oRange.SetValue(COleVariant("成绩"));
	oRange=oSheet.GetRange(COleVariant("F1"),vOpt);
	oRange.SetValue(COleVariant("状态"));
	//为每一行加上边框
	for(long i=1;i<rows+2;i++){
		CString tmp,tmp2;
		tmp.Format("A%d:F%d",i,i);
		tmp2+=tmp;
		oRange=oSheet.GetRange(COleVariant(tmp2),vOpt);
		Borders b=oRange.GetBorders();
		b.SetLineStyle(COleVariant((short)1));
	}

	//可以看到自动化的过程
	oApp.SetVisible(true);
	//允许用户进行控制
	oApp.SetUserControl(TRUE);
	
	
	//设置打印信息
	PageSetup PageInfo=oSheet.GetPageSetup();
	//描述页眉信息:楷体 26号字体
	CString HeaderFormat= "&";
	HeaderFormat+="\"楷体_GB2312,常规\"";
	HeaderFormat+="&24课程成绩单("+m_xm+")";
	PageInfo.SetCenterHeader(HeaderFormat);
	//设置页脚信息:楷体 12号字体
	CString FooterFormat= "&";
	FooterFormat+="\"楷体_GB2312,常规\"";
	FooterFormat+="&12第";
	//"&p":页码
	FooterFormat+="&p";
	FooterFormat+="页";
	//设置页脚
	PageInfo.SetCenterFooter(FooterFormat);
	
	//横向打印
	PageInfo.SetOrientation(1);
	//设置纸张大小为A4
	PageInfo.SetPaperSize(9);
	//第一页编号为默认值1
	PageInfo.SetFirstPageNumber(-4105);
	//设置标题行
	PageInfo.SetPrintTitleRows("$1:$1");
	
	//设置打印缩放比例100%
	PageInfo.SetZoom(COleVariant((short)100));
	//水平居中
	PageInfo.SetCenterHorizontally(1);
	//垂直居中
	PageInfo.SetCenterVertically(0);
	//进行打印预览,允许用户进行打印参数修改
	oSheet.PrintPreview(COleVariant((short)1));
	/*  如果想要直接打印输出,调用
	PrintOut(const VARIANT& From, const VARIANT& To, 
	const VARIANT& Copies, const VARIANT& Preview, 
	const VARIANT& ActivePrinter, 
	const VARIANT& PrintToFile, 
	const VARIANT& Collate)
		  */
	EndWaitCursor();	
}

⌨️ 快捷键说明

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