📄 ex_adoview.cpp
字号:
// Ex_ADOView.cpp : implementation of the CEx_ADOView class
//
#include "stdafx.h"
#include "Ex_ADO.h"
#include "Ex_ADODoc.h"
#include "Ex_ADOView.h"
#include "Employees.h"
#include "ADOConn.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CEx_ADOView
IMPLEMENT_DYNCREATE(CEx_ADOView, CListView)
BEGIN_MESSAGE_MAP(CEx_ADOView, CListView)
//{{AFX_MSG_MAP(CEx_ADOView)
// 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
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CListView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CListView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CListView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CEx_ADOView construction/destruction
CEx_ADOView::CEx_ADOView()
{
// TODO: add construction code here
}
CEx_ADOView::~CEx_ADOView()
{
}
BOOL CEx_ADOView::PreCreateWindow(CREATESTRUCT& cs)
{
//hua
cs.style |= LVS_REPORT; //报表风格
//hua
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CListView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CEx_ADOView drawing
void CEx_ADOView::OnDraw(CDC* pDC)
{
CEx_ADODoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
/*CString str("Hello");
pDC->TextOut(330,200,str);*/
}
void CEx_ADOView::OnInitialUpdate()
{
CListView::OnInitialUpdate();
//hua
CListCtrl& m_ListCtrl = GetListCtrl();
CString strHeader[]={"员工号","员工姓名","性别","职务","工资"};
int nLong[]={100,80,100,100,100};
for(int nCol=0;nCol<sizeof(strHeader)/sizeof(CString);nCol++)
m_ListCtrl.InsertColumn(nCol,strHeader[nCol],LVCFMT_CENTER,nLong[nCol]);
ResetListItem();
//hua
// TODO: You may populate your ListView with items by directly accessing
// its list control through a call to GetListCtrl().
}
/////////////////////////////////////////////////////////////////////////////
// CEx_ADOView printing
BOOL CEx_ADOView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CEx_ADOView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CEx_ADOView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
void CEx_ADOView::ResetListItem()
{
CListCtrl& m_ListCtrl=GetListCtrl();
m_ListCtrl.DeleteAllItems();
int nItem=0;
_bstr_t vSQL;
vSQL="SELECT * FROM Employees ORDER BY Emp_id DESC";
ADOConn m_AdoConn;
m_AdoConn.OnInitADOConn();
_RecordsetPtr m_pRecordset;
m_pRecordset=m_AdoConn.GetRecordSet(vSQL);
while(!m_pRecordset->adoEOF)
{
_variant_t value;
value=m_pRecordset->GetCollect("Emp_id");
m_ListCtrl.InsertItem(nItem,(char*)_bstr_t(value));
value=m_pRecordset->GetCollect("Emp_name");
m_ListCtrl.SetItemText(nItem,1,(char*)_bstr_t(value));
value=m_pRecordset->GetCollect("Sex");
m_ListCtrl.SetItemText(nItem,2,(char*)_bstr_t(value));
value=m_pRecordset->GetCollect("Title");
m_ListCtrl.SetItemText(nItem,3,(char*)_bstr_t(value));
value=m_pRecordset->GetCollect("Wage");
m_ListCtrl.SetItemText(nItem,4,(char*)_bstr_t(value));
m_pRecordset->MoveNext();
}
m_AdoConn.ExitConnect();
}
/////////////////////////////////////////////////////////////////////////////
// CEx_ADOView diagnostics
#ifdef _DEBUG
void CEx_ADOView::AssertValid() const
{
CListView::AssertValid();
}
void CEx_ADOView::Dump(CDumpContext& dc) const
{
CListView::Dump(dc);
}
CEx_ADODoc* CEx_ADOView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CEx_ADODoc)));
return (CEx_ADODoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CEx_ADOView message handlers
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -