Click here to Skip to main content
15,886,199 members
Articles / Desktop Programming / MFC

The alxBase classes for work with DBF files

Rate me:
Please Sign up or sign in to vote.
5.00/5 (22 votes)
5 Nov 20021 min read 361.6K   3.8K   57  
The alxBase classes for work with dbf files.
// DBFTableDef.h : interface of the CDBFTableDef class
//
/////////////////////////////////////////////////////////////////////////////
/*
�����:              �������� �.�.
����������:         alxsoft@gazinter.net
*/
/////////////////////////////////////////////////////////////////////////////

#if !defined(ALX_DBFTABLEDEF_H__INCLUDED_)
#define ALX_DBFTABLEDEF_H__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "DBFDef.h"
#include "DBFFields.h"
#include "DBTMemoFile.h"
#include "FPTMemoFile.h"
#include "SMTMemoFile.h"
#include "DBFException.h"

// ����� ��������������� ������
enum TextConvertDirection
{
	GetText,
	SetText
};

// ������� ������ ���������� � ����� �����
CString alxChangeFileExt(CString& strFileName, CString strNewFileExt);

// ������� ������� � ���������� ��������� �� ����� ���� �����
CMemoFile* alxNewMemoFile(UINT nMemoType);

// ������� ���������� ���������� ��� ����� ���� �����
LPCTSTR alxMemoFileExt(UINT nMemoType);

// ������� ���������� �������� ���� � ����� ������
void alxSetFieldValue(DBF_CHAR* pRec, FIELD_REC* pFieldRec, const COleVariant& varValue,
					  void (FAR * lpfnTextConvert) (CString& strConvertText, TextConvertDirection enDirection));
// ������� ���������� �������� ���� �� ������ ������
long alxGetFieldValue(DBF_CHAR* pRec, FIELD_REC* pFieldRec, COleVariant& varValue,
					  void (FAR * lpfnTextConvert) (CString& strConvertText, TextConvertDirection enDirection));

////////////////////////////////////////////////////////////////////////
// CDBFTableDef - a DBF TableDef

class ALX_EXT_CLASS CDBFTableDef : public CObject
{

friend class CDBFRecordset;
friend class CDBFCursorset;
friend class CDBFMemCursorset;

	DECLARE_DYNAMIC(CDBFTableDef)

// Constructors
public:
	CDBFTableDef();

	void Open(LPCTSTR lpszName, UINT nOpenFlag = ALX_DBF_USE_EXCLUSIVE);
	void Close();

// Attributes
public:
	DBF_HEAD	m_DBFHead;	// ��������� �������

	BOOL IsOpen() const;	// ������ �� ����� �������

	CString GetName();		// ���������� ��� ������
	CString GetDBFilePath();// ���������� ������ ���� � DBF �������
	CString GetMemoName();	// ���������� ��� ���� �����
	CString GetMemoFilePath();// ���������� ������ ���� � ���� �����

	CTime GetDateCreated();		// ���� �������� �������
	CTime GetDateLastUpdated();	// ���� ��������� �����������

	long GetRecordCount();	// ���-�� ������� � �������

// Overridables
public:

// Operations
public:
	BOOL CreateTable(LPCTSTR lpszName);	// ������� �������
	void ModifyTable();					// ������������
	void UpdateTable();					// ��������� ���������
	void CancelUpdateTable();			// �����

	void AddField(FIELD_REC* pFieldRec);					// ��������� ����
	void InsertField(short nIndex, FIELD_REC* pFieldRec);	// ��������� ����
	void MoveField(short nIndex, short nNewIndex);			// ���������� ���� �� �������...
	void ModifyField(short nIndex, FIELD_REC* pFieldRec);	// �������� ����
	void DeleteField(short nIndex);							// ������� ����

	short GetFieldCount();	// ���-�� �����

// Implementation
public:
	~CDBFTableDef();

#ifdef _DEBUG
	virtual void AssertValid() const;
	virtual void Dump(CDumpContext& dc) const;
#endif

	CDBFFields m_DBFFields; // ��������� �����

protected:
	BOOL ChangeOpenFlag(UINT nNewFlag);
	BOOL m_bOpen;				// ������� �� �������
	BOOL m_bNew;				// ������� �� �������
	UINT m_nOpenFlag;			// ������ �������� �����

	CFile m_DBFile;				// DBF �������
	CMemoFile* m_pMemoFile;		// ���� � ���� ������

	enum EditMode
	{
		noMode,
		modify,
		create
	};
	UINT m_nEditMode;

	BOOL ReadHeader();	// ������ ���������
	void WriteHeader(); // ���������� ���������

	void ReadRecord(long lRecNumber, void* lpBuffer);	// ������ ������
	void WriteRecord(long lRecNumber, void* lpBuffer);	// ���������� ������

	// ������ ���� ����
	void ReadMemoRecord(DBF_ULONG lOffsetRec, DBF_LONG& nLen, CString& strMemo); 
	void ReadMemoRecord(DBF_ULONG lOffsetRec, DBF_LONG& nLen, unsigned char** pMemoData);
	// ���������� ���� ����
	void WriteMemoRecord(DBF_ULONG& lOffsetRec, DBF_LONG& nLen, CString& strMemo);

	// ���������� �������� ����
	long GetFieldValue(DBF_CHAR* pRec, FIELD_REC* pFieldRec, COleVariant& varValue,
					  void (FAR * lpfnTextConvert) (CString& strConvertText, TextConvertDirection enDirection));
	// ������� ��������� �������� ����
	void SetFieldValue(DBF_CHAR* pRec, FIELD_REC* pFieldRec, const COleVariant& varValue,
					  void (FAR * lpfnTextConvert) (CString& strConvertText, TextConvertDirection enDirection));
private:
	// ��������� ������������ ��� ����������� �������
	DBF_HEAD*	m_pOldDBFHead;		// ��������� �� ������ ��������� �������
	CDBFFields* m_pOldDBFFields;	// ��������� ��������� �����
	DBF_INT*	m_pSwapFld;			// ������ ����������� ������������ ������ � ����� �����

	DBF_UCHAR*	m_pData;	// ����� ��� �������� �������� ������ (���� Picture, Binary, General)
};

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

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

#endif // !defined(ALX_DBFTABLEDEF_H__INCLUDED_)

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
Year of birth - 1974.
Eeducation - was ended by Kaliningrad State University in 1997.
Now I work as the engineer-programmer in Kaliningrad (RUSSIA).

Comments and Discussions