Click here to Skip to main content
15,892,575 members
Articles / Desktop Programming / MFC

MFC DataGrid

Rate me:
Please Sign up or sign in to vote.
5.00/5 (17 votes)
24 Feb 20022 min read 255.3K   7.5K   88  
CDataGrid which was derived from CGridCtrl and used ADO for access to database.
// DDXFields.cpp: implementation of the CDDXFields class.
//
// CDDXFields class for editing fields
// Written by Kirill Panov <cpanov@yahoo.com>
// Copyright (c) 2000-2002. All Rights Reserved.
//
// This file is provided "as is" with no expressed or implied warranty.
// The author accepts no liability for any damage/loss of business that
// this product may cause.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
//??
#include "DataGrid_Demo.h"
//#include "invent.h"


#include "DDXFields.h"

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

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////


void CDDXFields::DDX(CDataExchange *pDX)
{
  int n=GetSize();
  for(m_iCurField=0;m_iCurField<n;m_iCurField++)
  {
    if( (GetAt(m_iCurField).m_IDC!=-1)&& (GetAt(m_iCurField).m_name!="") )
    {
      DDX_Text(pDX, GetAt(m_iCurField).m_IDC, ElementAt(m_iCurField).m_value );
    }
  }
}

void CDDXFields::ReadData(  _RecordsetPtr pSet)
{
  int n=GetSize();
  for(m_iCurField=0;m_iCurField<n;m_iCurField++)
  {
    if(GetAt(m_iCurField).m_name!="")
    {
      ElementAt(m_iCurField).m_value = pSet->Fields->GetItem(GetAt(m_iCurField).m_name.Variant())->Value;
    }
  }
}

int CDDXFields::WriteData(_RecordsetPtr pSet)
{
  int n=GetSize();

  try
  {

    for(m_iCurField=0;m_iCurField<n;m_iCurField++)
    {
      if(GetAt(m_iCurField).m_name!="")
      {
        if(GetAt(m_iCurField).m_upper)
        {
          ElementAt(m_iCurField).m_value.MakeUpper();
        }
        if( GetAt(m_iCurField).m_float)
        {
          ElementAt(m_iCurField).m_value.Replace(".",",");
          ElementAt(m_iCurField).m_value.Replace("-",",");
          ElementAt(m_iCurField).m_value.Replace(" ","");
        }
        pSet->Fields->GetItem(GetAt(m_iCurField).m_name.Variant())->Value= GetAt(m_iCurField).m_value.Variant();
      }//if
    }//for
  }//try
/*
  catch( _com_error &e )
  {
  }
*/
  catch(...)
  {
    m_pWnd->MessageBox(_T("Invalid field ")+GetAt(m_iCurField).m_description,_T("������ ���� "),MB_ICONERROR);

    int id=GetAt(m_iCurField).m_IDC;

    if(id!=-1)
    {
      CWnd *pWnd =m_pWnd->GetDlgItem( id );
      pWnd->SetFocus();
    }

    return(-1);
  }
  return(0);
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Russian Federation Russian Federation
He is a Visual C++ developer,an MCSD and an MCDBA

He has been programming in C/C++ for 6 years, Visual C++ with MFC for 4 years and RDBMS: Oracle, MS SQL for 3 years

Comments and Discussions