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;
- 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);
- ::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;
- CString CSisbn;
- DTOBook* dto=new DTOBook;
- dto->BookIsnb=isbn;
- dto->BookName=name.AllocSysString();//转BSTR
- dto->BookAuthor=Author.AllocSysString();
- //将数据添加到数据库中;==>重复的代码
- 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"));
- //保存数据
- UINT iResult=0;
- mytools->SaveBook(dto,&iResult);
- //刷新界面上的数据==>显示到界面上;
- POSITION ps=this->GetFirstViewPosition();
- while(ps!=NULL)
- {
- CView* pview=this->GetNextView(ps);
- if(pview->GetRuntimeClass()->m_lpszClassName=="CBookAdminView")
- {
- CListView* plist=(CListView*)pview;
- plist->GetListCtrl().InsertItem(0,name);
- plist->GetListCtrl().SetItemText(0,1,Author);
- }
- }
- }
- }