BookAdminDoc.cpp
上传用户:weisheen
上传日期:2022-07-09
资源大小:19390k
文件大小:3k
源码类别:
ActiveX/DCOM/ATL
开发平台:
Visual C++
- // BookAdminDoc.cpp : implementation of the CBookAdminDoc class
- //
- #include "stdafx.h"
- #include "BookAdmin.h"
- #include "BookAdminDoc.h"
- //添加的头文件
- #include <atlbase.h>
- #include "../BooksDAL/BooksDAL_i.c"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CBookAdminDoc
- IMPLEMENT_DYNCREATE(CBookAdminDoc, CDocument)
- BEGIN_MESSAGE_MAP(CBookAdminDoc, CDocument)
- //{{AFX_MSG_MAP(CBookAdminDoc)
- // NOTE - the ClassWizard will add and remove mapping macros here.
- // DO NOT EDIT what you see in these blocks of generated code!
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CBookAdminDoc construction/destruction
- CBookAdminDoc::CBookAdminDoc()
- {
- // TODO: add one-time construction code here
- }
- CBookAdminDoc::~CBookAdminDoc()
- {
- }
- BOOL CBookAdminDoc::OnNewDocument()
- {
- if (!CDocument::OnNewDocument())
- return FALSE;
- // TODO: add reinitialization code here
- // (SDI documents will reuse this document)
- CComPtr<IDALMyBools> mytools;//组件接口指针
- mytools.CoCreateInstance(CLSID_DALMyBools);//生成实例
- DTOBook* pAllBooks=NULL;//数据的结构
- UINT iSize=0;
- //设置连接数据库条件
- mytools->put_DataSource(::SysAllocString(L"tarena"));
- mytools->put_UID(::SysAllocString(L"scott"));
- mytools->put_PWD(::SysAllocString(L"tiger"));
- mytools->QueryAllBook(&pAllBooks,&iSize);//查询数据库
- for(int i=0;i<iSize;i++)
- {
- BookEntity* p1=new BookEntity;//
- p1->BookIsnb=(pAllBooks+i)->BookIsnb;
- p1->BookName=CString((pAllBooks+i)->BookName);
- p1->BookAuthor=CString((pAllBooks+i)->BookAuthor);
- //CString类型用完要释放掉
- ::SysFreeString((pAllBooks+i)->BookName);
- ::SysFreeString((pAllBooks+i)->BookAuthor);
- this->allBooks.AddTail(p1);
- }
- //释放栈中的结构体
- ::CoTaskMemFree(pAllBooks);
- return TRUE;
- }
- /////////////////////////////////////////////////////////////////////////////
- // CBookAdminDoc serialization
- void CBookAdminDoc::Serialize(CArchive& ar)
- {
- if (ar.IsStoring())
- {
- // TODO: add storing code here
- }
- else
- {
- // TODO: add loading code here
- }
- }
- /////////////////////////////////////////////////////////////////////////////
- // CBookAdminDoc diagnostics
- #ifdef _DEBUG
- void CBookAdminDoc::AssertValid() const
- {
- CDocument::AssertValid();
- }
- void CBookAdminDoc::Dump(CDumpContext& dc) const
- {
- CDocument::Dump(dc);
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // CBookAdminDoc commands