📄 dankebaobiao.cpp
字号:
// dankebaobiao.cpp : implementation file
//
#include "stdafx.h"
#include "mark.h"
#include "dankebaobiao.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
/////////////////////////////////////////////////////////////////////////////
// Cdankebaobiao
IMPLEMENT_DYNCREATE(Cdankebaobiao, CFormView)
Cdankebaobiao::Cdankebaobiao()
: CFormView(Cdankebaobiao::IDD)
{
//{{AFX_DATA_INIT(Cdankebaobiao)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
ischoose=false;
}
Cdankebaobiao::~Cdankebaobiao()
{
}
void Cdankebaobiao::DoDataExchange(CDataExchange* pDX)
{
CFormView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(Cdankebaobiao)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(Cdankebaobiao, CFormView)
//{{AFX_MSG_MAP(Cdankebaobiao)
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_CBN_SELCHANGE(IDC_COMBO1, OnSelchangeCombo1)
ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// Cdankebaobiao diagnostics
#ifdef _DEBUG
void Cdankebaobiao::AssertValid() const
{
CFormView::AssertValid();
}
void Cdankebaobiao::Dump(CDumpContext& dc) const
{
CFormView::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// Cdankebaobiao message handlers
void Cdankebaobiao::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 Cdankebaobiao::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;
ischoose=true;
m_strjsh=str;
m_strkch=kch;
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;
m_strjsm=temp;
pedit->SetWindowText(temp);
CEdit *detail=(CEdit *)GetDlgItem(IDC_EDIT4);
COleVariant tem=adodc->GetRecordset().GetFields().GetItem(COleVariant("课程名称")).GetValue();
CString tem1=tem.bstrVal;
m_strkcm=tem1;
CString det="课程名:"+tem1;
tem=adodc->GetRecordset().GetFields().GetItem(COleVariant("院系")).GetValue();
tem1=tem.bstrVal;
m_stryx=tem1;
det+=",由"+tem1+"的"+temp+"老师任课,共";
tem=adodc->GetRecordset().GetFields().GetItem(COleVariant("学时")).GetValue();
tem1=tem.bstrVal;
m_strxs=tem1;
det+=tem1+"学时,";
tem=adodc->GetRecordset().GetFields().GetItem(COleVariant("学分")).GetValue();
tem1=tem.bstrVal;
m_strxf=tem1;
det+=tem1+"学分,该门课属于";
tem=adodc->GetRecordset().GetFields().GetItem(COleVariant("课程类别")).GetValue();
tem1=tem.bstrVal;
m_strkclb=tem1;
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 Cdankebaobiao::OnButton3()
{
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_strkcm+"课程成绩("+m_strjsm+")";
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 + -