// PictureSet.cpp : implementation file
//

#include "stdafx.h"
#include "ex30a.h"
#include "PictureSet.h"

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

/////////////////////////////////////////////////////////////////////////////
// CPictureSet

IMPLEMENT_DYNAMIC(CPictureSet, CDaoRecordset)

CPictureSet::CPictureSet(CDaoDatabase* pdb)
	: CDaoRecordset(pdb)
{
	//{{AFX_FIELD_INIT(CPictureSet)
	m_lBookID = 0;
	m_lPageNumber = 0;
	m_lPictureNumber = 0;
	m_strName = _T("");
	m_byType = 0;
	m_lSmallSize = 0;
	m_lLargeSize = 0;
	m_lSmallWidth = 0;
	m_lLargeWidth = 0;
	m_lSmallHeight = 0;
	m_lLargeHeight = 0;
	m_nFields = 15;
	//}}AFX_FIELD_INIT
	// m_nFields = 11 + 2 pictures fields

	m_nDefaultType = dbOpenDynaset;
	
	// m_nFields debe ser igual a la cantidad de
	// variables en true
	m_bKey			= true;		// = 3 fields
	m_bName			= true;
	m_bType			= true;
	m_nFields = 5;				// 3 + 2
	
	m_bSmallPicture	= false;
	m_bLargePicture = false;
	m_bSmallInfo	= false;	// = 3 fields
	m_bLargeInfo	= false;	// = 3 fields
}

CString CPictureSet::GetDefaultSQL()
{
	return _T("[Pictures]");
}

void CPictureSet::DoFieldExchange(CDaoFieldExchange* pFX)
{
	pFX->SetFieldType(CDaoFieldExchange::outputColumn);
	
	if (m_bKey) 
	{
		DFX_Long(pFX, _T("[BookID]"), m_lBookID);
		DFX_Long(pFX, _T("[PageNumber]"), m_lPageNumber);
		DFX_Long(pFX, _T("[PictureNumber]"), m_lPictureNumber);
	}
	if (m_bName)
		DFX_Text(pFX, _T("[Name]"), m_strName);
	if (m_bType)
		DFX_Byte(pFX, _T("[Type]"), m_byType);
	if (m_bSmallPicture)
		DFX_Binary(pFX, _T("[SmallPicture]"), m_smallPicture);
	if (m_bLargePicture)
		DFX_Binary(pFX, _T("[LargePicture]"), m_largePicture);
	if (m_bSmallInfo) 
	{
		DFX_Long(pFX, _T("[SmallSize]"), m_lSmallSize);
		DFX_Long(pFX, _T("[SmallWidth]"), m_lSmallWidth);
		DFX_Long(pFX, _T("[SmallHeight]"), m_lSmallHeight);
	}
	if (m_bLargeInfo) 
	{
		DFX_Long(pFX, _T("[LargeSize]"), m_lLargeSize);
		DFX_Long(pFX, _T("[LargeWidth]"), m_lLargeWidth);
		DFX_Long(pFX, _T("[LargeHeight]"), m_lLargeHeight);
	}

	/*
	//{{AFX_FIELD_MAP(CPictureSet)
	pFX->SetFieldType(CDaoFieldExchange::outputColumn);
	DFX_Long(pFX, _T("[ImageNumber]"), m_lImageNumber);
	DFX_Text(pFX, _T("[Name]"), m_strName);
	DFX_Byte(pFX, _T("[Type]"), m_byType);
	DFX_Text(pFX, _T("[Note]"), m_strNote);
	DFX_Binary(pFX, _T("[SmallImage]"), m_smallImage);
	DFX_Binary(pFX, _T("[LargeImage]"), m_largeImage);
	DFX_Bool(pFX, _T("[NoteFlag]"), m_fNoteFlag);
	//}}AFX_FIELD_MAP
	*/
}

/////////////////////////////////////////////////////////////////////////////
// CPictureSet diagnostics

#ifdef _DEBUG
void CPictureSet::AssertValid() const
{
	CDaoRecordset::AssertValid();
}

void CPictureSet::Dump(CDumpContext& dc) const
{
	CDaoRecordset::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CPictureSet

void CPictureSet::Open(unsigned int nFields, int nOpenType)
{
	// nFields siempre debe ser UINT para que no se 
	// confunda con Open de la clase base
	m_nFields = 0;
	if (m_bKey = (IMG_KEY & nFields) ? true:false)	
		m_nFields += 3;
	if (m_bName =  (IMG_NAME & nFields) ? true:false) 
		m_nFields++;
	if (m_bType = (IMG_TYPE & nFields) ? true:false)	
		m_nFields++;
	if (m_bSmallPicture = (IMG_SMALLPICTURE & nFields) ? true:false) 
		m_nFields++;
	if (m_bLargePicture = (IMG_LARGEPICTURE & nFields) ? true:false) 
		m_nFields++;
	if (m_bSmallInfo = (IMG_SMALLINFO & nFields) ? true:false) 
		m_nFields += 3;
	if (m_bLargeInfo = (IMG_LARGEINFO & nFields) ? true:false) 
		m_nFields += 3;

	CDaoRecordset::Open(nOpenType);
}

