You are on page 1of 7

PROGRAM

// databaseDoc.h : interface of the CDatabaseDoc class

#if !defined(AFX_DATABASEDOC_H__6C43D46F_106D_40AE_8F64_358A1D70937C__INCLUDED_)
#define AFX_DATABASEDOC_H__6C43D46F_106D_40AE_8F64_358A1D70937C__INCLUDED_

#if _MSC_VER > 1000


#pragma once
#endif // _MSC_VER > 1000

#include "Db1set.h"

class CDatabaseDoc : public CDocument


{
protected: // create from serialization only
CDatabaseDoc();
DECLARE_DYNCREATE(CDatabaseDoc)

// Attributes
public:
CDb1set m_nset;

// Operations
public:
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CDatabaseDoc)
public:
virtual BOOL OnNewDocument();
virtual void Serialize(CArchive& ar);
//}}AFX_VIRTUAL

// Implementation
public:
virtual ~CDatabaseDoc();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif
protected:
//{{AFX_MSG(CDatabaseDoc)
// NOTE - the ClassWizard will add and remove member functions here.
// DO NOT EDIT what you see in these blocks of generated code !
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_DATABASEDOC_H__6C43D46F_106D_40AE_8F64_358A1D70937C__INCLUDED_)

// databaseView.h : interface of the CDatabaseView class

#if !defined(AFX_DATABASEVIEW_H__36D67C14_8C60_42AB_8C10_7AE35FBBB52F__INCLUDED_)
#define AFX_DATABASEVIEW_H__36D67C14_8C60_42AB_8C10_7AE35FBBB52F__INCLUDED_

#if _MSC_VER > 1000


#pragma once
#endif // _MSC_VER > 1000

class CDatabaseView : public CScrollView


{
protected: // create from serialization only
CDatabaseView();
DECLARE_DYNCREATE(CDatabaseView)

// Attributes
public:
CDatabaseDoc* GetDocument();
CDb1set *m_pset;

// Operations
public:

// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CDatabaseView)
public:
virtual void OnDraw(CDC* pDC); // overridden to draw this view
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
protected:
virtual void OnInitialUpdate(); // called first time after construct
virtual BOOL OnPreparePrinting(CPrintInfo* pInfo);
virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo);
virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo);
//}}AFX_VIRTUAL

// Implementation
public:
virtual ~CDatabaseView();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif

protected:

// Generated message map functions


protected:
//{{AFX_MSG(CDatabaseView)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};

#ifndef _DEBUG // debug version in databaseView.cpp


inline CDatabaseDoc* CDatabaseView::GetDocument()
{ return (CDatabaseDoc*)m_pDocument; }
#endif

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !
defined(AFX_DATABASEVIEW_H__36D67C14_8C60_42AB_8C10_7AE35FBBB52F__INCLUDED_)

// databaseView.cpp : implementation of the CDatabaseView class

#include "stdafx.h"
#include "database.h"
#include "Db1set.h"
#include "databaseDoc.h"
#include "databaseView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

// CDatabaseView

IMPLEMENT_DYNCREATE(CDatabaseView, CScrollView)

BEGIN_MESSAGE_MAP(CDatabaseView, CScrollView)
//{{AFX_MSG_MAP(CDatabaseView)
// 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, CScrollView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CScrollView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CScrollView::OnFilePrintPreview)
END_MESSAGE_MAP()

// CDatabaseView construction/destruction

CDatabaseView::CDatabaseView()
{}

CDatabaseView::~CDatabaseView()
{}

BOOL CDatabaseView::PreCreateWindow(CREATESTRUCT& cs)


{
return CScrollView::PreCreateWindow(cs);
}

// CDatabaseView drawing

void CDatabaseView::OnDraw(CDC* pDC)


{
CDatabaseDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
int x=100,y=100;
CString str;
if(m_pset->IsEOF())
{
return;
}
m_pset->MoveFirst();
while(!m_pset->IsEOF())
{
str.Format("%d",m_pset->m_Sid);
pDC->TextOut(x,y,str);
pDC->TextOut(x+150,y,m_pset->m_Sname);
str.Format("%d",m_pset->m_Syear);
pDC->TextOut(x+300,y,str);
m_pset->MoveNext();
y=y+20;
}

void CDatabaseView::OnInitialUpdate()
{
CScrollView::OnInitialUpdate();

CSize sizeTotal;
sizeTotal.cx = sizeTotal.cy = 100;
SetScrollSizes(MM_TEXT, sizeTotal);
m_pset=&GetDocument()->m_nset;
if(m_pset->IsOpen())
{
m_pset->Close();
}
m_pset->Open();
}

// CDatabaseView printing

BOOL CDatabaseView::OnPreparePrinting(CPrintInfo* pInfo)


{
return DoPreparePrinting(pInfo);
}
void CDatabaseView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{}

void CDatabaseView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)


{}

// CDatabaseView diagnostics

#ifdef _DEBUG
void CDatabaseView::AssertValid() const
{
CScrollView::AssertValid();
}

void CDatabaseView::Dump(CDumpContext& dc) const


{
CScrollView::Dump(dc);
}

CDatabaseDoc* CDatabaseView::GetDocument() // non-debug version is inline


{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CDatabaseDoc)));
return (CDatabaseDoc*)m_pDocument;
}
#endif //_DEBUG

// CDatabaseView message handlers


OUTPUT

You might also like