AIM:
To write a Visual C++ Program for the Implementation of Database Modify using MFC(Microsoft Foundation Class) ODBC(Open DataBase Connectivity) Classes in CS1255 - Visual Programming Lab.
SOURCE CODE:
To write a Visual C++ Program for the Implementation of Database Modify using MFC(Microsoft Foundation Class) ODBC(Open DataBase Connectivity) Classes in CS1255 - Visual Programming Lab.
SOURCE CODE:
ODBCMODIFYView.cpp : implementation of the CODBCMODIFYView class
#include "stdafx.h"
#include "ODBCMODIFY.h"
#include "ODBCMODIFYSet.h"
#include "ODBCMODIFYDoc.h"
#include "ODBCMODIFYView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CODBCMODIFYView
IMPLEMENT_DYNCREATE(CODBCMODIFYView, CRecordView)
BEGIN_MESSAGE_MAP(CODBCMODIFYView, CRecordView)
//{{AFX_MSG_MAP(CODBCMODIFYView)
ON_BN_CLICKED(ID_RECORD_ADD, OnRecordAdd)
ON_BN_CLICKED(ID_RECORD_CLEAR_FIELDS, OnRecordClearFields)
ON_BN_CLICKED(ID_RECORD_DELETE, OnRecordDelete)
ON_BN_CLICKED(ID_RECORD_UPDATE, OnRecordUpdate)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CODBCMODIFYView construction/destruction
CODBCMODIFYView::CODBCMODIFYView()
: CRecordView(CODBCMODIFYView::IDD)
{
//{{AFX_DATA_INIT(CODBCMODIFYView)
m_pSet = NULL;
//}}AFX_DATA_INIT
// TODO: add construction code here
}
CODBCMODIFYView::~CODBCMODIFYView()
{
}
void CODBCMODIFYView::DoDataExchange(CDataExchange* pDX)
{
CRecordView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CODBCMODIFYView)
DDX_FieldText(pDX, IDC_NAME, m_pSet->m_sname, m_pSet);
DDX_FieldText(pDX, IDC_REGNO, m_pSet->m_sreg, m_pSet);
DDX_FieldText(pDX, IDC_MARK1, m_pSet->m_mark1, m_pSet);
DDX_FieldText(pDX, IDC_MARK2, m_pSet->m_mark2, m_pSet);
DDX_FieldText(pDX, IDC_MARK3, m_pSet->m_mark3, m_pSet);
DDX_FieldText(pDX, IDC_TOTAL, m_pSet->m_stotal, m_pSet);
DDX_FieldText(pDX, IDC_AVG, m_pSet->m_savg, m_pSet);
DDX_FieldText(pDX, IDC_RESULT, m_pSet->m_result, m_pSet);
//}}AFX_DATA_MAP
}
BOOL CODBCMODIFYView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CRecordView::PreCreateWindow(cs);
}
void CODBCMODIFYView::OnInitialUpdate()
{
m_pSet = &GetDocument()->m_ODBCMODIFYSet;
CRecordView::OnInitialUpdate();
GetParentFrame()->RecalcLayout();
ResizeParentToFit();
}
/////////////////////////////////////////////////////////////////////////////
// CODBCMODIFYView diagnostics
#ifdef _DEBUG
void CODBCMODIFYView::AssertValid() const
{
CRecordView::AssertValid();
}
void CODBCMODIFYView::Dump(CDumpContext& dc) const
{
CRecordView::Dump(dc);
}
CODBCMODIFYDoc* CODBCMODIFYView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CODBCMODIFYDoc)));
return (CODBCMODIFYDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CODBCMODIFYView database support
CRecordset* CODBCMODIFYView::OnGetRecordset()
{
return m_pSet;
}
/////////////////////////////////////////////////////////////////////////////
// CODBCMODIFYView message handlers
BOOL CODBCMODIFYView::OnMove(UINT nIDMoveCommand){switch (nIDMoveCommand){case ID_RECORD_PREV:m_pSet->MovePrev ();if(!m_pSet->IsBOF ())break;case ID_RECORD_FIRST:m_pSet->MoveFirst ();break;case ID_RECORD_NEXT:m_pSet->MoveNext ();if(!m_pSet->IsEOF ())break;case ID_RECORD_LAST:m_pSet->MoveLast ();break;default:ASSERT(false);}UpdateData(false);return true;//return CRecordView::OnMove(nIDMoveCommand);}void CODBCMODIFYView::OnRecordAdd(){m_pSet->AddNew ();UpdateData(true);if(m_pSet->CanUpdate ()){m_pSet->Update ();}if(!m_pSet->IsEOF ()){m_pSet->MoveLast ();}m_pSet->Requery ();UpdateData(false);}
void CODBCMODIFYView::OnRecordClearFields(){m_pSet->SetFieldNull (NULL);UpdateData(false);}
void CODBCMODIFYView::OnRecordDelete(){CRecordsetStatus status;try{m_pSet->Delete ();}catch(CDBException* e){AfxMessageBox(e->m_strError );e->Delete ();m_pSet->MoveFirst ();UpdateData(false);return;}m_pSet->GetStatus (status);if(status.m_lCurrentRecord ==0){m_pSet->MoveFirst ();}else{m_pSet->MoveNext ();}UpdateData(false);}void CODBCMODIFYView::OnRecordUpdate(){m_pSet->Edit ();UpdateData(true);if(m_pSet->CanUpdate ()){m_pSet->Update ();}}
OUTPUT:
EmoticonEmoticon