Visual C++ Program for the Implementation of Database Display using MFC(Microsoft Foundation Class) ODBC(Open DataBase Connectivity) Classes | CS1255 - Visual Programming Laboratory


AIM:
To write a Visual C++ Program for the Implementation of Database Display using MFC(Microsoft Foundation Class) ODBC(Open DataBase Connectivity) Classes in CS1255 - Visual Programming Lab.


SOURCE CODE:
ODBCDISPLAYView.cpp : Implementation of the CODBCDISPLAYView class
#include "stdafx.h"
#include "ODBCDISPLAY.h"
#include "ex31aSet.h"
#include "ODBCDISPLAYDoc.h"
#include "ODBCDISPLAYView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
// CODBCDISPLAYView
IMPLEMENT_DYNCREATE(CODBCDISPLAYView, CScrollView)
BEGIN_MESSAGE_MAP(CODBCDISPLAYView, CScrollView)
    //{{AFX_MSG_MAP(CODBCDISPLAYView)
        // 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
END_MESSAGE_MAP()

// CODBCDISPLAYView construction/destruction
CODBCDISPLAYView::CODBCDISPLAYView()

{    // TODO: add construction code here
}

CODBCDISPLAYView::~CODBCDISPLAYView()
{
}

BOOL CODBCDISPLAYView::PreCreateWindow(CREATESTRUCT& cs)
{    // TODO: Modify the Window class or styles here by modifying
    //  the CREATESTRUCT cs
    return CScrollView::PreCreateWindow(cs);
}

// CODBCDISPLAYView drawing
void CODBCDISPLAYView::OnDraw(CDC* pDC)
{
    CODBCDISPLAYDoc* pDoc = GetDocument();
    ASSERT_VALID(pDoc);
    // TODO: add draw code for native data here
    TEXTMETRIC tm;
pDC->GetTextMetrics(&tm);
int nLineHeight=tm.tmHeight+tm.tmExternalLeading;
CPoint pText(0,0);
int y=0;
CString str,str1,str2,str3,str4,str5;
if(a->IsBOF())
{
   return;
 }
a->MoveFirst();
while(!a->IsEOF())
   {
    pDC->TextOut(pText.x,pText.y,a->m_Name);
    str.Format("%d",a->m_Rollno);
    pDC->TextOut(pText.x+1000,pText.y,str);
    str1.Format("%d",a->m_mark1);
    pDC->TextOut(pText.x+2000,pText.y,str1);
    str2.Format("%d",a->m_mark2);
    pDC->TextOut(pText.x+3000,pText.y,str2);
           str3.Format("%d",a->m_mark3);
    pDC->TextOut(pText.x+4000,pText.y,str3);
    str4.Format("%d",a->m_total);
    pDC->TextOut(pText.x+5000,pText.y,str4);
    str5.Format("%d",a->m_average);
    pDC->TextOut(pText.x+6000,pText.y,str5);
    pDC->TextOut(pText.x+7000,pText.y,a->m_Result);
            a->MoveNext();
    pText.y-=nLineHeight;
   }
}

void CODBCDISPLAYView::OnInitialUpdate()
{
    CScrollView::OnInitialUpdate();  
    CSize sizeTotal(8000,10500);
    // TODO: calculate the total size of this view

    SetScrollSizes(MM_HIENGLISH, sizeTotal);
    a=&GetDocument()->m_ex31aSet;
    if(a->IsOpen())
    {
        a->Close();
    }
    a->Open();
}

/////////////////////////////////////////////////////////////////////////////
// CODBCDISPLAYView diagnostics

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

void CODBCDISPLAYView::Dump(CDumpContext& dc) const
{
    CScrollView::Dump(dc);
}

CODBCDISPLAYDoc* CODBCDISPLAYView::GetDocument() // non-debug version is inline
{
    ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CODBCDISPLAYDoc)));
    return (CODBCDISPLAYDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CODBCDISPLAYView message handlers
// ODBCDISPLAYView.h : interface of the CODBCDISPLAYView class
//
/////////////////////////////////////////////////////////////////////////////

#if !defined(AFX_ODBCDISPLAYVIEW_H__C60713E5_C40A_4F4F_88A1_6059F2C9B140__INCLUDED_)
#define AFX_ODBCDISPLAYVIEW_H__C60713E5_C40A_4F4F_88A1_6059F2C9B140__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
class CODBCDISPLAYView : public CScrollView
{
protected: // create from serialization only
    CODBCDISPLAYView();
    DECLARE_DYNCREATE(CODBCDISPLAYView)

// Attributes
public:
    CODBCDISPLAYDoc* GetDocument();

// Operations
private:
    Cex31aSet* a;
public:

// Overrides
    // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CODBCDISPLAYView)
    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
    //}}AFX_VIRTUAL

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

protected:
// Generated message map functions
protected:
    //{{AFX_MSG(CODBCDISPLAYView)
        // 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()
};

#ifndef _DEBUG  // debug version in ODBCDISPLAYView.cpp
inline CODBCDISPLAYDoc* CODBCDISPLAYView::GetDocument()
   { return (CODBCDISPLAYDoc*)m_pDocument; }
#endif

/////////////////////////////////////////////////////////////////////////////

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

#endif // !defined(AFX_ODBCDISPLAYVIEW_H__C60713E5_C40A_4F4F_88A1_6059F2C9B140__INCLUDED_)

// ODBCDISPLAYDoc.h : interface of the CODBCDISPLAYDoc class
//
/////////////////////////////////////////////////////////////////////////////

#if !defined(AFX_ODBCDISPLAYDOC_H__9C49AC86_8582_48F1_8409_988370D76690__INCLUDED_)
#define AFX_ODBCDISPLAYDOC_H__9C49AC86_8582_48F1_8409_988370D76690__INCLUDED_
#include "ex31aSet.h"
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
class CODBCDISPLAYDoc : public CDocument
{
protected: // create from serialization only
    CODBCDISPLAYDoc();
    DECLARE_DYNCREATE(CODBCDISPLAYDoc)
// Attributes
public:
// Operations
public:
    Cex31aSet m_ex31aSet;
public:
// Overrides
    // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CODBCDISPLAYDoc)
    public:
    virtual BOOL OnNewDocument();
    virtual void Serialize(CArchive& ar);
    //}}AFX_VIRTUAL
// Implementation
public:
    virtual ~CODBCDISPLAYDoc();
#ifdef _DEBUG
    virtual void AssertValid() const;
    virtual void Dump(CDumpContext& dc) const;
#endif
protected:
// Generated message map functions
protected:
    //{{AFX_MSG(CODBCDISPLAYDoc)
        // 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_ODBCDISPLAYDOC_H__9C49AC86_8582_48F1_8409_988370D76690__INCLUDED_)

OUTPUT:
Previous
Next Post »

Still not found what you are looking for? Try again here.