BookAdminView.cpp
上传用户:weisheen
上传日期:2022-07-09
资源大小:19390k
文件大小:4k
源码类别:

ActiveX/DCOM/ATL

开发平台:

Visual C++

  1. // BookAdminView.cpp : implementation of the CBookAdminView class
  2. //
  3. #include "stdafx.h"
  4. #include "BookAdmin.h"
  5. #include "BookAdminDoc.h"
  6. #include "BookAdminView.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CBookAdminView
  14. IMPLEMENT_DYNCREATE(CBookAdminView, CListView)
  15. BEGIN_MESSAGE_MAP(CBookAdminView, CListView)
  16. //{{AFX_MSG_MAP(CBookAdminView)
  17. ON_COMMAND(ID_BUTTON32772, OnButton32772)
  18. //}}AFX_MSG_MAP
  19. // Standard printing commands
  20. ON_COMMAND(ID_FILE_PRINT, CListView::OnFilePrint)
  21. ON_COMMAND(ID_FILE_PRINT_DIRECT, CListView::OnFilePrint)
  22. ON_COMMAND(ID_FILE_PRINT_PREVIEW, CListView::OnFilePrintPreview)
  23. END_MESSAGE_MAP()
  24. /////////////////////////////////////////////////////////////////////////////
  25. // CBookAdminView construction/destruction
  26. CBookAdminView::CBookAdminView()
  27. {
  28. // TODO: add construction code here
  29. }
  30. CBookAdminView::~CBookAdminView()
  31. {
  32. }
  33. BOOL CBookAdminView::PreCreateWindow(CREATESTRUCT& cs)
  34. {
  35. // TODO: Modify the Window class or styles here by modifying
  36. //  the CREATESTRUCT cs
  37. return CListView::PreCreateWindow(cs);
  38. }
  39. /////////////////////////////////////////////////////////////////////////////
  40. // CBookAdminView drawing
  41. void CBookAdminView::OnDraw(CDC* pDC)
  42. {
  43. CBookAdminDoc* pDoc = GetDocument();
  44. ASSERT_VALID(pDoc);
  45. CListCtrl& refCtrl = GetListCtrl();
  46. refCtrl.InsertItem(0, "Item!");
  47. // TODO: add draw code for native data here
  48. }
  49. void CBookAdminView::OnInitialUpdate()
  50. {
  51. CListView::OnInitialUpdate();
  52. //创建列;
  53. this->GetListCtrl().InsertColumn(0,"BookName",LVCFMT_CENTER,200);
  54. this->GetListCtrl().InsertColumn(1,"BookAuther",LVCFMT_CENTER,200);
  55. //添加数据;
  56. POSITION ps;
  57. ps=this->GetDocument()->allBooks.GetHeadPosition();
  58. while(ps!=NULL)
  59. {
  60. BookEntity* be=this->GetDocument()->allBooks.GetNext(ps);
  61. this->GetListCtrl().InsertItem(0,be->BookName);
  62. this->GetListCtrl().SetItemText(0,1,be->BookAuthor);
  63. this->GetListCtrl().SetItemData(0,be->BookIsnb);
  64. }
  65. // TODO: You may populate your ListView with items by directly accessing
  66. //  its list control through a call to GetListCtrl().
  67. }
  68. /////////////////////////////////////////////////////////////////////////////
  69. // CBookAdminView printing
  70. BOOL CBookAdminView::OnPreparePrinting(CPrintInfo* pInfo)
  71. {
  72. // default preparation
  73. return DoPreparePrinting(pInfo);
  74. }
  75. void CBookAdminView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  76. {
  77. // TODO: add extra initialization before printing
  78. }
  79. void CBookAdminView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  80. {
  81. // TODO: add cleanup after printing
  82. }
  83. /////////////////////////////////////////////////////////////////////////////
  84. // CBookAdminView diagnostics
  85. #ifdef _DEBUG
  86. void CBookAdminView::AssertValid() const
  87. {
  88. CListView::AssertValid();
  89. }
  90. void CBookAdminView::Dump(CDumpContext& dc) const
  91. {
  92. CListView::Dump(dc);
  93. }
  94. CBookAdminDoc* CBookAdminView::GetDocument() // non-debug version is inline
  95. {
  96. ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CBookAdminDoc)));
  97. return (CBookAdminDoc*)m_pDocument;
  98. }
  99. #endif //_DEBUG
  100. /////////////////////////////////////////////////////////////////////////////
  101. // CBookAdminView message handlers
  102. void CBookAdminView::OnStyleChanged(int nStyleType, LPSTYLESTRUCT lpStyleStruct)
  103. {
  104. //TODO: add code to react to the user changing the view style of your window
  105. }
  106. void CBookAdminView::OnButton32772() 
  107. {
  108. // TODO: Add your command handler code here
  109. //找到被删除的记录ID;
  110. int index=this->GetListCtrl().GetNextItem(-1,LVNI_SELECTED|LVNI_ALL);
  111. if(index==-1)
  112. {
  113. MessageBox("请首先选中一条记录!");
  114. }
  115. else
  116. {
  117. UINT iOk=MessageBox("你真的要删除吗?","删除确认",MB_YESNO);
  118. //从当前的界面上删除;
  119. if(iOk==6)
  120. {
  121. this->GetListCtrl().DeleteItem(index);
  122. //DWORD为unsigned long的宏
  123. DWORD isbn=this->GetListCtrl().GetItemData(index);
  124. UINT iResult=0;
  125. this->GetDocument()->GetDbTools()->DeleteBookById((UINT)isbn,&iResult);
  126. }
  127. }
  128. }