📄 banjibaobiao.cpp
字号:
// banjibaobiao.cpp : implementation file
//
#include "stdafx.h"
#include "mark.h"
#include "banjibaobiao.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
/////////////////////////////////////////////////////////////////////////////
// Cbanjibaobiao
IMPLEMENT_DYNCREATE(Cbanjibaobiao, CFormView)
Cbanjibaobiao::Cbanjibaobiao()
: CFormView(Cbanjibaobiao::IDD)
{
//{{AFX_DATA_INIT(Cbanjibaobiao)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
ischoose=false;
}
Cbanjibaobiao::~Cbanjibaobiao()
{
}
void Cbanjibaobiao::DoDataExchange(CDataExchange* pDX)
{
CFormView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(Cbanjibaobiao)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(Cbanjibaobiao, CFormView)
//{{AFX_MSG_MAP(Cbanjibaobiao)
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// Cbanjibaobiao diagnostics
#ifdef _DEBUG
void Cbanjibaobiao::AssertValid() const
{
CFormView::AssertValid();
}
void Cbanjibaobiao::Dump(CDumpContext& dc) const
{
CFormView::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// Cbanjibaobiao message handlers
void Cbanjibaobiao::OnButton1()
{
CMainFrame *pframe=(CMainFrame *)AfxGetMainWnd();
CComboBox *banj=(CComboBox *)GetDlgItem(IDC_COMBO1);
CString temp,temp1;
banj->GetWindowText(temp);
if(temp==""){
pframe->Agenttalk("请选择班级");
return;
}
CEdit *xueh=(CEdit *)GetDlgItem(IDC_EDIT1);
xueh->GetWindowText(temp1);
if(temp1==""){
pframe->Agenttalk("请选择课程号");
return;
}
m_bj=temp;
m_kch=temp1;
CAdodc *ado=(CAdodc *)GetDlgItem(IDC_ADODC3);
ado->GetRecordset().MoveFirst();
bool isfound=false;
while(!ado->GetRecordset().GetEof()){
COleVariant v=ado->GetRecordset().GetFields().GetItem(COleVariant("课程号")).GetValue();
if(v==COleVariant(temp1)){
isfound=true;
v=ado->GetRecordset().GetFields().GetItem(COleVariant("课程名称")).GetValue();
m_kcm=v.bstrVal;
ischoose=true;
break;
}
ado->GetRecordset().MoveNext();
}
if(isfound){
CEdit *pedi=(CEdit *)GetDlgItem(IDC_EDIT2);
pedi->SetWindowText(m_kcm);
CAdodc *pad=(CAdodc *)GetDlgItem(IDC_ADODC2);
CString sql="Select 学生档案表.学号,学生档案表.姓名,学生档案表.性别,教师档案表.教师名,选课情况.成绩,选课情况.状态 from 学生档案表,选课情况,课程,授课,教师档案表 where 学生档案表.学号=选课情况.学号 and 选课情况.课程号=课程.课程号 and 选课情况.教师号=教师档案表.教师号 and 课程.课程号=授课.课程号 and 授课.教师号=教师档案表.教师号 and 学生档案表.班级='"+m_bj+"' and 课程.课程号="+m_kch;
pad->SetRecordSource(sql);
pad->Refresh();
}else{
pframe->Agenttalk("没有找到该门课程");
}
}
void Cbanjibaobiao::OnButton2()
{
CMainFrame *pframe=(CMainFrame *)AfxGetMainWnd();
CAdodc *ado=(CAdodc *)GetDlgItem(IDC_ADODC2);
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_bj+m_kcm+"课程成绩单";
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 + -