195 lines
4.2 KiB
C++
195 lines
4.2 KiB
C++
#ifndef __DBF_TOOLS_H
|
||||
|
|
#define __DBF_TOOLS_H
|
|||
|
|
|
|||
|
|
#include "DBFRecordset.h "
|
|||
|
|
|
|||
|
|
//////////////////////////////////////////////////////////////////////////////
|
|||
|
|
// sg modify 090922,整体修改了DbfTool.h、DbfTool.cpp文件
|
|||
|
|
// 用新的头文件、库文件,替换掉CODE_BASE
|
|||
|
|
//////////////////////////////////////////////////////////////////////////////
|
|||
|
|
|
|||
|
|
#define CMP_SENSITIVE 0
|
|||
|
|
#define CMP_INSENSITIVE 1
|
|||
|
|
#define CMP_MATCH 2
|
|||
|
|
|
|||
|
|
void xh1cpy(char *to, const char *src);
|
|||
|
|
|
|||
|
|
class DbfTable;
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
// 表列信息(DBFField:name、type、len、dec)
|
|||
|
|
|
|||
|
|
class FieldInfo: public DBFField
|
|||
|
|
{
|
|||
|
|
public:
|
|||
|
|
FieldInfo(const TCHAR *n = NULL, int t = 0, int l = 0, int d = 0);
|
|||
|
|
FieldInfo(const FieldInfo &src) {
|
|||
|
|
InitClear();
|
|||
|
|
*this = src;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
~FieldInfo() {}
|
|||
|
|
|
|||
|
|
FieldInfo & operator= (const FieldInfo &src);
|
|||
|
|
|
|||
|
|
void InitClear();
|
|||
|
|
|
|||
|
|
int operator !() { return m_strName.IsEmpty(); }
|
|||
|
|
|
|||
|
|
static void ReleaseArray(FieldInfo *p);
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
// 单元格,结构+内容
|
|||
|
|
// 移植后,该类的部分内容,找不到完全对应的接口;不推荐使用
|
|||
|
|
class FieldContent: public FIELD_REC
|
|||
|
|
{
|
|||
|
|
private:
|
|||
|
|
static CString csValue;
|
|||
|
|
|
|||
|
|
public:
|
|||
|
|
FieldContent() {}
|
|||
|
|
|
|||
|
|
// 数据类型
|
|||
|
|
TCHAR GetFieldType() const;
|
|||
|
|
|
|||
|
|
operator int () const;
|
|||
|
|
operator float () const; // Add on 2002/9/20
|
|||
|
|
operator double () const;
|
|||
|
|
operator const TCHAR * () const;
|
|||
|
|
|
|||
|
|
FieldContent & operator = (int i);
|
|||
|
|
FieldContent & operator = (double d);
|
|||
|
|
FieldContent & operator = (const TCHAR *str);
|
|||
|
|
|
|||
|
|
int CompareTo(const FieldContent &otherOne) const;
|
|||
|
|
|
|||
|
|
#ifdef __AFXDISP_H__
|
|||
|
|
COleVariant AsVariant() const;
|
|||
|
|
FieldContent & operator = (const COleVariant &src);
|
|||
|
|
#endif
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
// 数据库
|
|||
|
|
class CodeBase
|
|||
|
|
{
|
|||
|
|
public:
|
|||
|
|
CodeBase();
|
|||
|
|
~CodeBase();
|
|||
|
|
|
|||
|
|
DbfTable *Open(const TCHAR *szFile);
|
|||
|
|
|
|||
|
|
DbfTable *Create(const TCHAR *szFile, const FieldInfo *pFieldArray,
|
|||
|
|
int nCount); // sg modify 090927,增加了数组长度的参数
|
|||
|
|
|
|||
|
|
public:
|
|||
|
|
DbfTable* m_pDbfTable; // sg add 090922,数据表指针
|
|||
|
|
int read_only; // sg add 091013,是否只读
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
// 数据表
|
|||
|
|
class DbfTable: public CDBFRecordset
|
|||
|
|
{
|
|||
|
|
public:
|
|||
|
|
DbfTable() : m_bIsAdd(false) {}
|
|||
|
|
|
|||
|
|
// 列数
|
|||
|
|
int GetFieldNum();
|
|||
|
|
// 获取列信息集合,调用FieldInfo::ReleaseArray释放
|
|||
|
|
FieldInfo* GetFieldInfo();
|
|||
|
|
|
|||
|
|
// 获取指定列,n=0,1,2,......
|
|||
|
|
FieldContent* GetFieldContent(int n);
|
|||
|
|
FieldContent* GetFieldContent(const TCHAR *szFieldName);
|
|||
|
|
|
|||
|
|
// 记录数,bSkipDeleted控制是否计算被删除的记录
|
|||
|
|
long GetRecordCount(int bSkipDeleted);
|
|||
|
|
long GetPosition();
|
|||
|
|
|
|||
|
|
// 判断记录是否被delete
|
|||
|
|
BOOL IsDeleted();
|
|||
|
|
|
|||
|
|
BOOL IsEOF();
|
|||
|
|
BOOL IsBOF();
|
|||
|
|
BOOL operator !() {
|
|||
|
|
return (IsEOF() || IsBOF());
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 增加记录,成对使用,中间设置单元格内容
|
|||
|
|
void AppendBegin();
|
|||
|
|
void AppendEnd();
|
|||
|
|
|
|||
|
|
// 首先增加EDIT标记,然后更新记录
|
|||
|
|
BOOL Pack();
|
|||
|
|
void Close();
|
|||
|
|
void Delete();
|
|||
|
|
// 未实现,无法找到对应的移植方法。应用层也未使用
|
|||
|
|
void Recall() {}
|
|||
|
|
|
|||
|
|
// Iteration
|
|||
|
|
BOOL MoveFirst(int bSkipDeleted = 1);
|
|||
|
|
BOOL MoveLast(int bSkipDeleted = 1);
|
|||
|
|
BOOL MoveNext(int bSkipDeleted = 1);
|
|||
|
|
BOOL MovePrev(int bSkipDeleted = 1);
|
|||
|
|
|
|||
|
|
// nRecNo=0,1,2,......
|
|||
|
|
BOOL MoveTo(long nRecNo);
|
|||
|
|
|
|||
|
|
BOOL MoveTo(const TCHAR *szKey, const TCHAR *szValue,
|
|||
|
|
int nMethod = CMP_SENSITIVE, int bSkipDeleted = 1);
|
|||
|
|
BOOL MoveFirst(const TCHAR *szKey, const TCHAR *szValue,
|
|||
|
|
int nMethod = CMP_SENSITIVE, int bSkipDeleted = 1);
|
|||
|
|
BOOL MoveNext(const TCHAR *szKey, const TCHAR *szValue,
|
|||
|
|
int nMethod = CMP_SENSITIVE, int bSkipDeleted = 1);
|
|||
|
|
void Move(long offset, int bSkipDeleted = 1);
|
|||
|
|
|
|||
|
|
void EditMode();
|
|||
|
|
void EditUpdate();
|
|||
|
|
private:
|
|||
|
|
bool m_bIsAdd; // 插入标记
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
#define GET_FIELD(table, fname, fvalue) (table)->GetFieldValue(fname, fvalue)
|
|||
|
|
#define SET_FIELD(table, fname, fvalue)\
|
|||
|
|
(table)->EditMode();\
|
|||
|
|
(table)->SetFieldValue(fname, fvalue);\
|
|||
|
|
(table)->EditUpdate()
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
//////////////////////////////////////////////////////////////////////////////
|
|||
|
|
/*
|
|||
|
|
#define FLAG_READ 0
|
|||
|
|
#define FLAG_WRITE 1
|
|||
|
|
#define FLAG_APPEND 2
|
|||
|
|
#define FLAG_DELETE 3
|
|||
|
|
#define FLAG_PACK 4
|
|||
|
|
|
|||
|
|
struct DbfAccess
|
|||
|
|
{
|
|||
|
|
TCHAR dbfname[256]; // 数据库名称
|
|||
|
|
int flag; // 读写标志
|
|||
|
|
int keynum; // 关键字段数
|
|||
|
|
char **keyFieldName; // 关键字的序号
|
|||
|
|
char **keyinfo; // 关键字段的内容
|
|||
|
|
int datanum; // 查询或更新的字段数
|
|||
|
|
char **dataFieldName; // 数据字段的名称(1,2,...)
|
|||
|
|
|
|||
|
|
union {
|
|||
|
|
char *resFileName; // 数据字段的内容 read result
|
|||
|
|
char **dataIn;
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
DbfAccess(const TCHAR *tabName, int isWrite, int kn, int dn);
|
|||
|
|
~DbfAccess();
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
int DBFFUN(DbfAccess &kz);*/
|
|||
|
|
|
|||
|
|
#endif
|