www.gusucode.com > VC++操作SqlServer数据库的参考源程序源码程序 > VC++操作SqlServer数据库的参考源程序源码程序/code/FrmMain.cpp

    // FrmMain.cpp : implementation file
// Download by http://www.NewXing.com

#include "stdafx.h"
#include "Student.h"
#include "FrmMain.h"
#include "studentdlg.h"
#include "istudent.h"
#include "class.h"
#include "course.h"
#include "choice.h"
#include "teach.h"
#include "teaching.h"
#include "query.h"
#include "htmlhelp.h"
#include "about.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern CStudentApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CFrmMain dialog


CFrmMain::CFrmMain(CWnd* pParent /*=NULL*/)
	: CDialog(CFrmMain::IDD, pParent)
{
	//{{AFX_DATA_INIT(CFrmMain)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


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


BEGIN_MESSAGE_MAP(CFrmMain, CDialog)
	//{{AFX_MSG_MAP(CFrmMain)
	ON_COMMAND(ID_ExpStudent, OnExpStudent)
	ON_COMMAND(ID_ExpClass, OnExpClass)
	ON_COMMAND(ID_ExpChoice, OnExpChoice)
	ON_COMMAND(ID_ExpCourse, OnExpCourse)
	ON_COMMAND(ID_ExpTeach, OnExpTeach)
	ON_COMMAND(ID_ExpTeaching, OnExpTeaching)
	ON_COMMAND(ID_ABOUT, OnAbout)
	ON_COMMAND(ID_CONTENT, OnContent)
	ON_COMMAND(ID_IChoice, OnIChoice)
	ON_COMMAND(ID_IClass, OnIClass)
	ON_COMMAND(ID_ICourse, OnICourse)
	ON_COMMAND(ID_IStudent, OnIStudent)
	ON_COMMAND(ID_ITeach, OnITeach)
	ON_COMMAND(ID_ITeaching, OnITeaching)
	ON_COMMAND(ID_QStudent, OnQStudent)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CFrmMain message handlers

BOOL CFrmMain::DestroyWindow() 
{
	// TODO: Add your specialized code here and/or call the base class
	CStudentDlg dlg;
	dlg.DestroyWindow();
	return CDialog::DestroyWindow();
}
void CFrmMain::OnExpStudent() 
{
	m_pRec->Open("select s_no as 学号,class_no as 班级号,s_name as 姓名,s_sex as 性别,s_birthday as 出生日期 from student",theApp.m_pConnect.GetInterfacePtr(),adOpenStatic,adLockOptimistic,adCmdText);
	theApp.m_opt.ExportToExcel(m_pRec);
	m_pRec->Close();
}

BOOL CFrmMain::OnInitDialog() 
{
	CDialog::OnInitDialog();
	m_pRec.CreateInstance("ADODB.Recordset");
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CFrmMain::OnExpClass() 
{
	m_pRec->Open("select class_no as 班级号,class_name as 班级名称,class_special as 所属专业,class_dept as 系别 from class",theApp.m_pConnect.GetInterfacePtr(),adOpenStatic,adLockOptimistic,adCmdText);
	theApp.m_opt.ExportToExcel(m_pRec);
	m_pRec->Close();
	
}

void CFrmMain::OnExpChoice() 
{
	m_pRec->Open("select s_no as 学号,course_no as 课程号,score as 成绩 from choice",theApp.m_pConnect.GetInterfacePtr(),adOpenStatic,adLockOptimistic,adCmdText);
	theApp.m_opt.ExportToExcel(m_pRec);
	m_pRec->Close();
	
	
}

void CFrmMain::OnExpCourse() 
{
	m_pRec->Open("select course_no 课程号,course_name as 课程名称,course_score as 学分 from course",theApp.m_pConnect.GetInterfacePtr(),adOpenStatic,adLockOptimistic,adCmdText);
	theApp.m_opt.ExportToExcel(m_pRec);
	m_pRec->Close();
	
	
}

void CFrmMain::OnExpTeach() 
{
	m_pRec->Open("select t_no as 教师号,t_name as 教师姓名,t_sex as 性别,t_birthday as 出生日期,t_title as 职称 from teacher",theApp.m_pConnect.GetInterfacePtr(),adOpenStatic,adLockOptimistic,adCmdText);
	theApp.m_opt.ExportToExcel(m_pRec);
	m_pRec->Close();
	
	
}

void CFrmMain::OnExpTeaching() 
{
	m_pRec->Open("select course_no as 课程号,t_no as 教师号 from teaching",theApp.m_pConnect.GetInterfacePtr(),adOpenStatic,adLockOptimistic,adCmdText);
	theApp.m_opt.ExportToExcel(m_pRec);
	m_pRec->Close();
	
	
}

void CFrmMain::OnAbout() 
{
	CAbout dlg;
	dlg.DoModal();
}

void CFrmMain::OnContent() 
{
	CString appPath;
	GetModuleFileName(NULL, appPath.GetBuffer(MAX_PATH), MAX_PATH);
	appPath.ReleaseBuffer();
	int n = appPath.ReverseFind('\\');
	CString helpFile;
	helpFile = appPath.Left(n);
	TCHAR c = helpFile.GetAt(n - 1);
	if(c == '\\')
		helpFile += "Help.chm";
	else
		helpFile += "\\Help.chm";
	HtmlHelp(NULL, (LPCSTR)helpFile, HH_DISPLAY_TOPIC, 0);
		
}

void CFrmMain::OnIChoice() 
{
	CChoice IDlg;
	IDlg.DoModal();
	
}

void CFrmMain::OnIClass() 
{
	CClass IDlg;
	IDlg.DoModal();
	
}

void CFrmMain::OnICourse() 
{
	CCourse IDlg;
	IDlg.DoModal();
	
}

void CFrmMain::OnIStudent() 
{
	CInput IDlg;
	theApp.m_opt.m_iOptStatus=1;//addnew
	theApp.m_opt.m_iTableFlag=1;//student
	IDlg.DoModal();
}

void CFrmMain::OnITeach() 
{
	CTeach IDlg;
	IDlg.DoModal();
	
}

void CFrmMain::OnITeaching() 
{
	CTeaching IDlg;
	IDlg.DoModal();
	
}

void CFrmMain::OnQStudent() 
{

	CQuery dlg;
	theApp.m_opt.m_iOptStatus=2;//update
	theApp.m_opt.m_iTableFlag=1;//student
	theApp.m_opt.m_sTableName="student";//student
	
	dlg.DoModal();
}