BookAdminDoc.cpp
上传用户:weisheen
上传日期:2022-07-09
资源大小:19390k
文件大小:4k
源码类别:
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"
- #include "DlgBookAdd.h"
- #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)
- ON_COMMAND(ID_BUTTON32771, OnButton32771)
- //}}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=this->GetDbTools();
- DTOBook* pAllBooks=NULL;
- UINT iSize=0;
- 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);
- ::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
- void CBookAdminDoc::OnButton32771()
- {
- // TODO: Add your command handler code here
- DlgBookAdd mydlg;
- mydlg.DoModal();
- if(mydlg.m_bIsOk)
- {
- UINT isbn=mydlg.m_bookisbn;
- CString name=mydlg.m_bookname;
- CString Author=mydlg.m_bookauthor;
- DTOBook* dto=new DTOBook;
- dto->BookIsnb=isbn;
- dto->BookName=name.AllocSysString();
- dto->BookAuthor=Author.AllocSysString();
- //将数据添加到数据库中;
- CComPtr<IDALMyBools> mytools=this->GetDbTools();
- UINT iResult=0;
- mytools->SaveBook(dto,&iResult);
- //刷新界面上的数据;
- CListView* plist=this->GetListView1();
- plist->GetListCtrl().InsertItem(0,name);
- plist->GetListCtrl().SetItemText(0,1,Author);
- }
- }
- CComPtr<IDALMyBools> CBookAdminDoc::GetDbTools()
- {
- 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"));
- return mytools;
- }
- CListView* CBookAdminDoc::GetListView1()
- {
- CListView* plist=NULL;
- POSITION ps=this->GetFirstViewPosition();
- while(ps!=NULL)
- {
- CView* pview=this->GetNextView(ps);
- if(pview->GetRuntimeClass()->m_lpszClassName=="CBookAdminView")
- {
- plist=(CListView*)pview;
- break;
- }
- }
- return plist;
- }