Files
envi-code/SourceCode/Code2026/Dimension/DbfTools.h
T

195 lines
4.4 KiB
C++
Raw Normal View History

2026-10-04 00:04:20 +08:00
#ifndef __DBF_TOOLS_H
2026-09-28 15:28:50 +08:00
#define __DBF_TOOLS_H
#include "DBFRecordset.h "
//////////////////////////////////////////////////////////////////////////////
2026-10-04 00:04:20 +08:00
// sg modify 090922,整体修改了DbfTool.h、DbfTool.cpp文件
// 用新的头文件、库文件,替换掉CODE_BASE
2026-09-28 15:28:50 +08:00
//////////////////////////////////////////////////////////////////////////////
#define CMP_SENSITIVE 0
#define CMP_INSENSITIVE 1
#define CMP_MATCH 2
void xh1cpy(char *to, const char *src);
class DbfTable;
2026-10-04 00:04:20 +08:00
// 表列信息(DBFField:name、type、len、dec)
2026-09-28 15:28:50 +08:00
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);
};
2026-10-04 00:04:20 +08:00
// 单元格,结构+内容
// 移植后,该类的部分内容,找不到完全对应的接口;不推荐使用
2026-09-28 15:28:50 +08:00
class FieldContent: public FIELD_REC
{
private:
static CString csValue;
public:
FieldContent() {}
2026-10-04 00:04:20 +08:00
// 数据类型
2026-09-28 15:28:50 +08:00
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
};
2026-10-04 00:04:20 +08:00
// 数据库
2026-09-28 15:28:50 +08:00
class CodeBase
{
public:
CodeBase();
~CodeBase();
DbfTable *Open(const TCHAR *szFile);
DbfTable *Create(const TCHAR *szFile, const FieldInfo *pFieldArray,
2026-10-04 00:04:20 +08:00
int nCount); // sg modify 090927,增加了数组长度的参数
2026-09-28 15:28:50 +08:00
public:
2026-10-04 00:04:20 +08:00
DbfTable* m_pDbfTable; // sg add 090922,数据表指针
int read_only; // sg add 091013,是否只读
2026-09-28 15:28:50 +08:00
};
2026-10-04 00:04:20 +08:00
// 数据表
2026-09-28 15:28:50 +08:00
class DbfTable: public CDBFRecordset
{
public:
DbfTable() : m_bIsAdd(false) {}
2026-10-04 00:04:20 +08:00
// 列数
2026-09-28 15:28:50 +08:00
int GetFieldNum();
2026-10-04 00:04:20 +08:00
// 获取列信息集合,调用FieldInfo::ReleaseArray释放
2026-09-28 15:28:50 +08:00
FieldInfo* GetFieldInfo();
2026-10-04 00:04:20 +08:00
// 获取指定列,n=0,1,2,......
2026-09-28 15:28:50 +08:00
FieldContent* GetFieldContent(int n);
FieldContent* GetFieldContent(const TCHAR *szFieldName);
2026-10-04 00:04:20 +08:00
// 记录数,bSkipDeleted控制是否计算被删除的记录
2026-09-28 15:28:50 +08:00
long GetRecordCount(int bSkipDeleted);
long GetPosition();
2026-10-04 00:04:20 +08:00
// 判断记录是否被delete
2026-09-28 15:28:50 +08:00
BOOL IsDeleted();
BOOL IsEOF();
BOOL IsBOF();
BOOL operator !() {
return (IsEOF() || IsBOF());
}
2026-10-04 00:04:20 +08:00
// 增加记录,成对使用,中间设置单元格内容
2026-09-28 15:28:50 +08:00
void AppendBegin();
void AppendEnd();
2026-10-04 00:04:20 +08:00
// 首先增加EDIT标记,然后更新记录
2026-09-28 15:28:50 +08:00
BOOL Pack();
void Close();
void Delete();
2026-10-04 00:04:20 +08:00
// 未实现,无法找到对应的移植方法。应用层也未使用
2026-09-28 15:28:50 +08:00
void Recall() {}
// Iteration
BOOL MoveFirst(int bSkipDeleted = 1);
BOOL MoveLast(int bSkipDeleted = 1);
BOOL MoveNext(int bSkipDeleted = 1);
BOOL MovePrev(int bSkipDeleted = 1);
2026-10-04 00:04:20 +08:00
// nRecNo=0,1,2,......
2026-09-28 15:28:50 +08:00
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:
2026-10-04 00:04:20 +08:00
bool m_bIsAdd; // 插入标记
2026-09-28 15:28:50 +08:00
};
#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
{
2026-10-04 00:04:20 +08:00
TCHAR dbfname[256]; // 数据库名称
int flag; // 读写标志
int keynum; // 关键字段数
char **keyFieldName; // 关键字的序号
char **keyinfo; // 关键字段的内容
int datanum; // 查询或更新的字段数
char **dataFieldName; // 数据字段的名称(1,2,...)
2026-09-28 15:28:50 +08:00
union {
2026-10-04 00:04:20 +08:00
char *resFileName; // 数据字段的内容 read result
2026-09-28 15:28:50 +08:00
char **dataIn;
};
DbfAccess(const TCHAR *tabName, int isWrite, int kn, int dn);
~DbfAccess();
};
int DBFFUN(DbfAccess &kz);*/
#endif