📄 example_4doc.cpp
字号:
// Example_4Doc.cpp : implementation of the CExample_4Doc class
//
#include "stdafx.h"
#include "Example_4.h"
#include "Example_4Doc.h"
#include "ExaDg_4.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CExample_4Doc
IMPLEMENT_DYNCREATE(CExample_4Doc, CDocument)
BEGIN_MESSAGE_MAP(CExample_4Doc, CDocument)
//{{AFX_MSG_MAP(CExample_4Doc)
ON_COMMAND(ID_DATA_E4, OnDataE4)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CExample_4Doc construction/destruction
CExample_4Doc::CExample_4Doc()
{
// TODO: add one-time construction code here
}
CExample_4Doc::~CExample_4Doc()
{
}
BOOL CExample_4Doc::OnNewDocument()
{
if (!CDocument::OnNewDocument())
return FALSE;
m_strCnt=_T("Provider=SQLOLEDB;"
"Data Source=OFFICE-WXF;"
"Uid=sa;"
"Password=16676175;"
"database=Exa_3");
m_strCTt=_T("Select * from Exat_3");
m_pRs=NULL;
m_piAdoRecordBinding=NULL;
::CoInitialize(NULL);
// TODO: add reinitialization code here
// (SDI documents will reuse this document)
try
{
m_pRs.CreateInstance(__uuidof(Recordset));
m_pRs->Open((LPCTSTR)m_strCTt,(LPCTSTR)m_strCnt,adOpenDynamic,adLockOptimistic,
adCmdUnknown);
if(FAILED(m_pRs->QueryInterface(__uuidof(IADORecordBinding),
(LPVOID*)&m_piAdoRecordBinding)))
_com_issue_error(E_NOINTERFACE);
m_piAdoRecordBinding->BindToRecordset(&m_rsRecSet);
}
catch (_com_error &e)
{
GError(e.Error(),e.Description());
}
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CExample_4Doc serialization
void CExample_4Doc::Serialize(CArchive& ar)
{
if (ar.IsStoring())
{
// TODO: add storing code here
}
else
{
// TODO: add loading code here
}
}
/////////////////////////////////////////////////////////////////////////////
// CExample_4Doc diagnostics
#ifdef _DEBUG
void CExample_4Doc::AssertValid() const
{
CDocument::AssertValid();
}
void CExample_4Doc::Dump(CDumpContext& dc) const
{
CDocument::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CExample_4Doc commands
void CExample_4Doc::OnDataE4()
{
// TODO: Add your command handler code here
ExaDg_4 m_Dg;
m_Dg.DoModal();
}
ExaCI_4* CExample_4Doc::GetRecSet()
{
return &m_rsRecSet;
}
void CExample_4Doc::GError(HRESULT hr, PWSTR pwszDescription)
{
CString strError;
strError.Format("Run-time error'%(&x)'",hr,hr);
strError+="\n\n";
strError+=pwszDescription;
AfxMessageBox(strError);
}
void CExample_4Doc::DeleteContents()
{
// TODO: Add your specialized code here and/or call the base class
if(m_pRs)
m_pRs->Close();
if(m_piAdoRecordBinding)
m_pRs=NULL;
CoUninitialize();
CDocument::DeleteContents();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -