中国DOS联盟论坛

中国DOS联盟

-- 联合DOS 推动DOS 发展DOS --

联盟域名:www.cn-dos.net  论坛域名:www.cn-dos.net/forum
DOS,代表着自由开放与发展,我们努力起来,学习FreeDOS和Linux的自由开放与GNU精神,共同创造和发展美好的自由与GNU GPL世界吧!

游客:  注册 | 登录 | 命令行 | 会员 | 搜索 | 上传 | 帮助 »
« [11] [12] [13] [14] [15] [16] [17] [18] [19] [20] »
作者:
标题: DOS的界面开发终结者 上一主题 | 下一主题
firstsail
高级用户





积分 668
发帖 295
注册 2005-7-26
来自 广东深圳
状态 离线
『第 286 楼』:  

//下面文件是Foxpro.h文件

#ifndef _FOXPRO_20110811_H_
#define _FOXPRO_20110811_H_

//数据库头
struct FOXPRO_HEAD
{
        BYTE        byFlags;
        BYTE    byYear;
        BYTE    byMonth;
        BYTE    byDay;

        DWORD   dwRecordCount;
        WORD    wRecordAddress;
        WORD    wRecordLength;
        DWORD   dwReserve1;
        DWORD   dwReserve2;
        DWORD   dwReserve3;
        DWORD   dwReserve4;
        DWORD   dwReserve5;
};

//数据库“域”属性
struct FOXPRO_FIELDS
{
        BYTE    strName[10];
        BYTE    byFill;
        BYTE    byStyle;
        DWORD   dwDataAddress;
        BYTE    byLength;
        BYTE    byDotCount;
        WORD    wReserve1;
        BYTE    byFlags;
        BYTE    wsReserve[11];

};

//数据库“类”定义
class CFoxpro
{
private:
        BOOL           m_bNew;
        long           m_lRecordPoint;
        char           m_strFile[256];
        FOXPRO_HEAD    m_FoxproHead;
        FOXPRO_FIELDS  m_FoxproFields;
        FILE*          m_pFile;
        BYTE*          m_pRecordBuf;
        FOXPRO_FIELDS* m_pFoxproFields;
public:
        //建立新的数据库
        BOOL  CreateFoxpro(const char*pStr);
        //打开已存在的数据库
        BOOL  OpenFoxpro(const char*pStr);
        //关闭数据库
        BOOL  CloseFoxpro();
        //增加一域
        BOOL  AddFields(const char* strName,BYTE byStyle,int nLength,int nDot);
        //获得指定列的“域”属性
        FOXPRO_FIELDS*  GetFoxproFields(int nIndex);
public:
        //获得列的数量
        int   GetFieldsCount() {return(m_FoxproHead.wRecordAddress-sizeof(FOXPRO_HEAD))/sizeof(FOXPRO_FIELDS);}
        //获得纪录总数
        long  GetRecordCount() {return(m_FoxproHead.dwRecordCount);}
        //获得纪录地址
        long  GetRecordAddress() {return((DWORD)m_FoxproHead.wRecordAddress);}
        //获得数据库的最后修改日期-“有”
        int   GetMonth()       {return((int)m_FoxproHead.byMonth);}
        //获得数据库的最后修改日期-“日”
        int   GetDay()         {return((int)m_FoxproHead.byDay);}
        //获得数据库的最后修改日期-“年”
        int   GetYear()        {return((int)1900+(DWORD)m_FoxproHead.byYear);}
        //获得纪录的长度
        int   GetRecordLength(){return((int)(DWORD)m_FoxproHead.wRecordLength);}
        //显示数据库调试信息
        void  Debug();
public:
        //修剪指定字符串的前导空格
        static char*  TrimLeft(char  *pStr);
        //修剪指定字符串的后导空格
        static char*  TrimRight(char *pStr);

public:
        //设置串类型“域”的字符串
        BOOL  SetFieldsString(int nIndex, const char* pStr);
        //设置数字类型“域”的数字值
        BOOL  SetFieldsNumber(int nIndex,float fValue);
        //设置日期类型“域”的日期值
        BOOL  SetFieldsDate(int nIndex,int nYear,int nMonth,int nDay);
        //设置逻辑类型“域”的逻辑值
        BOOL  SetFieldsLogic(int nIndex,BOOL bLogic);
        //设置备注类型“域”的备注值
        BOOL  SetFieldsMemo(int nIndex, const char* pStr);

        //获得串类型“域”的字符串
        BOOL  GetFieldsString(int nIndex,char* pStr);
        //获得数字类型“域”的数字值
        float GetFieldsNumber(int nIndex);
        //获得日期类型“域”的日期值
        BOOL  GetFieldsDate(int nIndex,int* pnYear,int* pnMonth,int* pnDay);
        //获得逻辑类型“域”的逻辑值
        BOOL  GetFieldsLogic(int nIndex);
        //获得备注类型“域”的备注值
        BOOL  GetFieldsMemo(int nIndex,char* pStr);

        //定位纪录
        BOOL  Seek(long nIndex,int nMode);       
        //判断数据库是否已经打开
        BOOL  IsOpen();
        //刷新数据库到磁盘
        BOOL  Flush();
        //增加一新纪录
        BOOL  AddNew();
        //准备修改当前纪录
        BOOL  Edit();
        //使当前的更改有效
        BOOL  Update();
        //在当前纪录中插入一条纪录
        BOOL  Insert();
        //删除当前纪录(带上删除标记)
        BOOL  Delete();
        //删除当前纪录
        BOOL  DeleteEx();
        //将带有删除标准的纪录删除
        BOOL  Zap();
public:
        void CoFoxpro();//构造函数调用
        //构造函数
        CFoxpro();
        //构造函数(打开指定的数据库)
        CFoxpro(char* strFile);
        //析构函数
        ~CFoxpro();
};



#endif

2018-7-14 12:10
查看资料  访问主页  发短消息 网志   编辑帖子  回复  引用回复
firstsail
高级用户





积分 668
发帖 295
注册 2005-7-26
来自 广东深圳
状态 离线
『第 287 楼』:  

//下面文件是Foxpro.Cpp文件
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include <dos.h>
#include <bios.h>
#include <dir.h>
#include <conio.h>
#include <string.h>
#include <sys\\stat.h>
#include <io.h>

#include "symbol2.h"
#include "Foxpro.h"


//#include <Myframe.h>

void CFoxpro::CoFoxpro()
{
        m_bNew          = FALSE;
        m_lRecordPoint  = 0;
        m_pRecordBuf    = NULL;
        m_pFile         = NULL;
        m_pFoxproFields = NULL;
        _fmemset(&m_FoxproHead  ,0,sizeof(FOXPRO_HEAD));
        _fmemset(&m_FoxproFields,0,sizeof(FOXPRO_FIELDS));
        _fmemset(&m_strFile,0,256);
}

CFoxpro::CFoxpro()
{
        this->CoFoxpro();
}

CFoxpro::CFoxpro(char* strFile)
{

        this->CoFoxpro();
        this->OpenFoxpro(strFile);
}

CFoxpro::~CFoxpro()
{
        if (m_pFile != NULL)
        {
                fclose(m_pFile);
        }
        m_pFile = NULL;

        DELETE(m_pRecordBuf);
        DELETE(m_pFoxproFields);

}

void CFoxpro::Debug()
{
        char buf[512];
        if(!m_pRecordBuf) return;

        int nFields = this->GetFieldsCount();
        printf("\n-------------------------------------------------");
        for(int i=0;i<nFields;i++)
        {
                m_FoxproFields = *(this->GetFoxproFields(i));

                printf("\n%10s--",m_FoxproFields.strName);
                if(m_FoxproFields.byStyle=='C')
                {
                        this->GetFieldsString(i,buf);
                        this->TrimLeft(buf);
                        this->TrimRight(buf);
                        printf("%s",buf);
                }
                else if(m_FoxproFields.byStyle=='L')
                {
                        BOOL bLogic = this->GetFieldsLogic(i);
                        printf("%d",bLogic);
                }
                else if(m_FoxproFields.byStyle=='D')
                {
                        int nYear,nMonth,nDay;
                        this->GetFieldsDate(i,&nYear,&nMonth,&nDay);
                        printf("%04d-%02d-%02d",nYear,nMonth,nDay);
                }
                else if(m_FoxproFields.byStyle=='N')
                {
                        float fValue = this->GetFieldsNumber(i);
                        if(m_FoxproFields.byDotCount==0)      printf("%.0f",fValue);
                        else if(m_FoxproFields.byDotCount==1) printf("%.1f",fValue);
                        else if(m_FoxproFields.byDotCount==2) printf("%.2f",fValue);
                        else if(m_FoxproFields.byDotCount==3) printf("%.3f",fValue);
                        else if(m_FoxproFields.byDotCount==4) printf("%.4f",fValue);
                        else if(m_FoxproFields.byDotCount==5) printf("%.5f",fValue);
                        else                                  printf("%.6f",fValue);

                }
                else if(m_FoxproFields.byStyle=='M')
                {
                }
                if(i&& !(i%24))
                {
                        getch();
                }

        }
}

BOOL  CFoxpro::CreateFoxpro(const char *pStr)
{
        if(m_pFile) return(FALSE);

        m_pFile = NULL;

        CoFoxpro();

        int nFields = 0;

        date mDate;
        ::getdate(&mDate);

        m_FoxproHead.byFlags        = 0x03;
        m_FoxproHead.byDay          = (BYTE)mDate.da_day;
        m_FoxproHead.byMonth        = (BYTE)mDate.da_mon;
        m_FoxproHead.byYear         = (BYTE)(WORD)(mDate.da_year-1900);
        m_FoxproHead.dwRecordCount  = 0x00;
        m_FoxproHead.wRecordAddress = sizeof(FOXPRO_HEAD)+1;
        m_FoxproHead.wRecordLength  = 0x01;
        m_FoxproHead.dwReserve1     = 0x00;
        m_FoxproHead.dwReserve2     = 0x00;
        m_FoxproHead.dwReserve3     = 0x00;
        m_FoxproHead.dwReserve4     = 0x00;
        m_FoxproHead.dwReserve5     = 0x00;

        _fmemset(&m_FoxproFields.strName,0,10);
        m_FoxproFields.byFill        = 0;
        m_FoxproFields.byStyle       = (BYTE)'C';
        m_FoxproFields.dwDataAddress = 0;
        m_FoxproFields.byLength      = 0;
        m_FoxproFields.byDotCount    = 0;
        m_FoxproFields.wReserve1     = 0;
        m_FoxproFields.byFlags       = 0;
        _fmemset(&m_FoxproFields.wsReserve,0,11);

        if(!(m_pFile=fopen(pStr,"w+b")))
        {
                return(FALSE);
        }

        fwrite(&m_FoxproHead  ,sizeof(FOXPRO_HEAD)  ,1,m_pFile);
        fwrite(&m_FoxproFields,sizeof(FOXPRO_FIELDS),nFields,m_pFile);
        fwrite("\x0D",1,1,m_pFile);
        fwrite("\x1A",1,1,m_pFile);

        //File Name
        _fstrcpy(m_strFile,pStr);
        //Malloc RecordBuf
        m_pRecordBuf = new BYTE[this->GetRecordLength()+1024];
        _fmemset(m_pRecordBuf,0,this->GetRecordLength()+1024);
        //Malloc  Foxpro_Fields
        m_pFoxproFields = new FOXPRO_FIELDS[1+this->GetFieldsCount()];
        _fmemset(m_pFoxproFields,0,sizeof(FOXPRO_FIELDS)*(1+this->GetFieldsCount()));
        //Fill FoxproFields
        ::fseek(m_pFile,sizeof(FOXPRO_HEAD),SEEK_SET);
        nFields = this->GetFieldsCount();
        for(int i=0;i<nFields;i++)
        {
                ::fread(&m_pFoxproFields,sizeof(FOXPRO_FIELDS),1,m_pFile);
        }
        return(TRUE);
}


BOOL  CFoxpro::OpenFoxpro(const char* pStr)
{
        if (m_pFile != NULL)
    {
        return(FALSE);
    }

        CoFoxpro();

        if (!(m_pFile = fopen(pStr,"r+b")))
    {
        return(FALSE);
    }

        long  lFileLength = filelength(fileno(m_pFile));
        if(lFileLength<1L*sizeof(FOXPRO_HEAD)+2)
        {
                ::fclose(m_pFile);
                m_pFile=NULL;
                return(FALSE);
        }

        rewind(m_pFile);
        fread(&m_FoxproHead  ,sizeof(FOXPRO_HEAD)  ,1,m_pFile);
        //Flags
        if(m_FoxproHead.byFlags!=0x03 && m_FoxproHead.byFlags!=0xF5)
        {
                ::fclose(m_pFile);
                m_pFile=NULL;
                return(FALSE);
        }

        BYTE nCh=0;
        fseek(m_pFile,-1,SEEK_END);
        fread(&nCh,1,1,m_pFile);
        // End Is 0x1A?
        if(nCh!=0x1A)
        {
                fclose(m_pFile);
                m_pFile=NULL;
                return(FALSE);
        }
        //---------------------------
        //File Name
        _fstrcpy(m_strFile,pStr);
        //Malloc Record Buffer
        m_pRecordBuf = new BYTE[this->GetRecordLength()+1024];
    if (m_pRecordBuf == NULL)
    {
                fclose(m_pFile);
                m_pFile=NULL;

        return (FALSE);
    }
        _fmemset(m_pRecordBuf,0,this->GetRecordLength()+1024);
        //Malloc  Foxpro_Fields
        m_pFoxproFields = new FOXPRO_FIELDS[1+this->GetFieldsCount()];
    if (m_pFoxproFields == NULL)
    {
        delete m_pRecordBuf;
        m_pRecordBuf = NULL;

                fclose(m_pFile);
                m_pFile=NULL;

        return (FALSE);
    }

        _fmemset(m_pFoxproFields,0,sizeof(FOXPRO_FIELDS)*(1+this->GetFieldsCount()));
        //Fill FoxproFields
        ::fseek(m_pFile,sizeof(FOXPRO_HEAD),SEEK_SET);
        int nFields = this->GetFieldsCount();
        for(int i=0;i<nFields;i++)
        {
                ::fread(&m_pFoxproFields,sizeof(FOXPRO_FIELDS),1,m_pFile);
        }
        return(TRUE);
}

BOOL  CFoxpro::CloseFoxpro()
{
        if (NULL != m_pFile)
        {
                fclose(m_pFile);
    }
        m_pFile = NULL;

        DELETE(m_pRecordBuf);
        DELETE(m_pFoxproFields);

        return(TRUE);
}

BOOL  CFoxpro::AddFields(const char* strName,BYTE byStyle,int nLength,int nDot)
{
        if(!m_pFile) return(FALSE);

        if(byStyle=='C')      {nDot = 0;}
        else if(byStyle=='N') {}
        else if(byStyle=='D') {nLength = 8;nDot    = 0;}
        else if(byStyle=='L') {nLength=1;nDot   =0;}
        else if(byStyle=='M') {nLength = 10;nDot    = 0;}
        else {return(0);}

        _fmemset(&m_FoxproFields,0,sizeof(FOXPRO_FIELDS));
        //----------------------------------------------------
        if(byStyle=='M')
        {
                m_FoxproHead.byFlags=0xF5;
                fseek(m_pFile,0,SEEK_SET);
                fwrite(&m_FoxproHead  ,sizeof(FOXPRO_HEAD)  ,1,m_pFile);
        }
        //Calc Fields
        int nFields=(m_FoxproHead.wRecordAddress-sizeof(FOXPRO_HEAD))/sizeof(FOXPRO_FIELDS);
        //Modify Head
        date mDate;
        ::getdate(&mDate);
        m_FoxproHead.byDay          = (BYTE)mDate.da_day;
        m_FoxproHead.byMonth        = (BYTE)mDate.da_mon;
        m_FoxproHead.byYear         = (BYTE)(WORD)(mDate.da_year-1900);
        m_FoxproHead.wRecordAddress+= sizeof(FOXPRO_FIELDS);
        m_FoxproHead.wRecordLength += (WORD)nLength;
        //Write Head Again
        fseek(m_pFile,0,SEEK_SET);
        fwrite(&m_FoxproHead,sizeof(FOXPRO_HEAD),1,m_pFile);
        //
        int nFieldsAddress = 1;
        fseek(m_pFile,sizeof(FOXPRO_HEAD),SEEK_SET);
        for(int i=0;i<nFields;i++)
        {
                ::fread(&m_FoxproFields,sizeof(FOXPRO_FIELDS),1,m_pFile);
                nFieldsAddress+=m_FoxproFields.byLength;
        }
        //Fill in Field
        if (::_fstrlen(strName) < 10)
        {
                ::_fstrcpy((char*)&m_FoxproFields.strName,(char*)strName);
        }
        else
        {
                ::_fmemcpy((BYTE*)&m_FoxproFields.strName, (char*)strName, 10);
        }

        m_FoxproFields.byStyle       = (BYTE)byStyle;
        m_FoxproFields.dwDataAddress = nFieldsAddress;
        m_FoxproFields.byLength      = (BYTE)nLength;
        m_FoxproFields.byDotCount    = nDot;
       //Write Field
        ::fseek(m_pFile,sizeof(FOXPRO_HEAD)+nFields*sizeof(FOXPRO_FIELDS),SEEK_SET);
        ::fwrite(&m_FoxproFields,sizeof(FOXPRO_FIELDS),1,m_pFile);
        //Write End
        fwrite("\x0D",1,1,m_pFile);
        fwrite("\x1A",1,1,m_pFile);

        //Malloc Record BUf
        DELETE(m_pRecordBuf);
        m_pRecordBuf = new BYTE[this->GetRecordLength()+1024];
        _fmemset(m_pRecordBuf,' ',this->GetRecordLength()+1024);
        m_pRecordBuf[GetRecordLength()]='\0';
        //Reset Record Point
        m_lRecordPoint=0;
        //Malloc Foxpro Fields
        DELETE(m_pFoxproFields);
        m_pFoxproFields = new FOXPRO_FIELDS[1+this->GetFieldsCount()];
        _fmemset(m_pFoxproFields,0,sizeof(FOXPRO_FIELDS)*(1+this->GetFieldsCount()));
        //Fill FoxproFields
        ::fseek(m_pFile,sizeof(FOXPRO_HEAD),SEEK_SET);
        nFields = this->GetFieldsCount();
        for(i=0;i<nFields;i++)
        {
                ::fread(&m_pFoxproFields,sizeof(FOXPRO_FIELDS),1,m_pFile);
        }

        return(TRUE);
}

char*  CFoxpro::TrimLeft(char  *pStr)
{
        //if(_fstrlen(pStr)>=256) return(pStr);
        while(pStr[0]==' '||pStr[0]=='\x9')
        {
                int nLength=_fstrlen(pStr);
                if(!nLength) break;
                if(nLength) _fmemcpy(&pStr[0],&pStr[1],nLength);
        }
        return(pStr);
}

char*  CFoxpro::TrimRight(char *pStr)
{
        //if(_fstrlen(pStr)>=256) return(pStr);
        int nLength=_fstrlen(pStr);
        if(!nLength) return(pStr);
        for(int i=nLength-1;i>=0;i--)
        {
                if(pStr!=' '&&pStr!='\x9') break;
                pStr='\0';
        }

        return(pStr);
}

FOXPRO_FIELDS*  CFoxpro::GetFoxproFields(int nIndex)
{
        ::_fmemset(&m_FoxproFields,0,sizeof(FOXPRO_FIELDS));
        //----------------------------------------------------
        //Calc Fields
        int nFields=this->GetFieldsCount();
        if(nIndex>=nFields||nFields<0) return(&m_FoxproFields);
        return(&m_pFoxproFields[nIndex]);
}

BOOL  CFoxpro::GetFieldsString(int nIndex,char* pStr)
{
        int nFields=this->GetFieldsCount();
        if(nIndex<0||nIndex>=nFields||nFields<0) return(FALSE);

        m_FoxproFields = *(this->GetFoxproFields(nIndex));
        if(m_FoxproFields.byStyle!='C') return(FALSE);
        if(!m_pRecordBuf) return(FALSE);

        int nAddress = (WORD)m_FoxproFields.dwDataAddress;
        _fmemcpy(pStr,&m_pRecordBuf[nAddress],m_FoxproFields.byLength);
        if(m_FoxproFields.byLength)
        {
                pStr[m_FoxproFields.byLength] = '\0';
        }
        this->TrimRight(pStr);

        return(TRUE);
}

float  CFoxpro::GetFieldsNumber(int nIndex)
{
        char buf[120];
        int nFields=this->GetFieldsCount();
        if(nIndex<0||nIndex>=nFields||nFields<0) return(FALSE);

        m_FoxproFields = *(this->GetFoxproFields(nIndex));

        if(m_FoxproFields.byStyle!='N') return(FALSE);
        if(!m_pRecordBuf) return(FALSE);

        int nAddress = (WORD)m_FoxproFields.dwDataAddress;
        _fmemcpy(buf,&m_pRecordBuf[nAddress],m_FoxproFields.byLength);
        buf[m_FoxproFields.byLength] = '\0';
        return(atof(buf));
}

BOOL  CFoxpro::GetFieldsDate(int nIndex,int* pnYear,int* pnMonth,int* pnDay)
{
        char buf1[20],buf2[20];
        int nFields=this->GetFieldsCount();
        if(nIndex<0||nIndex>=nFields||nFields<0) return(FALSE);

        m_FoxproFields = *(this->GetFoxproFields(nIndex));

        if(m_FoxproFields.byStyle!='D') return(FALSE);
        if(!m_pRecordBuf) return(FALSE);

        int nAddress = (WORD)m_FoxproFields.dwDataAddress;
        _fmemcpy(buf1,&m_pRecordBuf[nAddress],m_FoxproFields.byLength);
        buf1[m_FoxproFields.byLength] = '\0';

        buf2[0]=buf1[0];
        buf2[1]=buf1[1];
        buf2[2]=buf1[2];
        buf2[3]=buf1[3];
        buf2[4]='\0';
        *pnYear =(int)(atof(buf2)+0.5f);

        buf2[0]=buf1[4];
        buf2[1]=buf1[5];
        buf2[2]='\0';
        *pnMonth =(int)(atof(buf2)+0.5f);

        buf2[0]=buf1[6];
        buf2[1]=buf1[7];
        buf2[2]='\0';
        *pnDay =(int)(atof(buf2)+0.5f);

        return(TRUE);
}

BOOL  CFoxpro::GetFieldsLogic(int nIndex)
{
        char buf[10];
        int nFields=this->GetFieldsCount();
        if(nIndex<0||nIndex>=nFields||nFields<0) return(FALSE);

        m_FoxproFields = *(this->GetFoxproFields(nIndex));

        if(m_FoxproFields.byStyle!='L') return(FALSE);
        if(!m_pRecordBuf) return(FALSE);

        int nAddress = (WORD)m_FoxproFields.dwDataAddress;
        _fmemcpy(buf,&m_pRecordBuf[nAddress],m_FoxproFields.byLength);
        buf[m_FoxproFields.byLength] = '\0';
        if(buf[0]=='T')  return(TRUE);
        return(FALSE);
}

BOOL  CFoxpro::GetFieldsMemo(int /*nIndex*/,char* /*pStr*/)
{
        return(TRUE);
}

BOOL  CFoxpro::SetFieldsString(int nIndex, const char* pStr)
{
        int nFields=this->GetFieldsCount();
        if(nIndex<0||nIndex>=nFields||nFields<0) return(FALSE);

        m_FoxproFields = *(this->GetFoxproFields(nIndex));

        if(m_FoxproFields.byStyle!='C') return(FALSE);
        if(!m_pRecordBuf) return(FALSE);

        int nAddress = (WORD)m_FoxproFields.dwDataAddress;
        int nLength1 = _fstrlen(pStr);
        int nLength2 = (WORD)m_FoxproFields.byLength;
        for(int i=0;i<nLength2;i++)
        {
                if(i>=nLength1)
                {
                        m_pRecordBuf[nAddress+i]=' ';
                }
                else
                {
                        m_pRecordBuf[nAddress+i]=*(pStr+i);
                }
        }


        //::fseek(m_pFile,this->GetRecordAddress(),SEEK_SET);
        //::fseek(m_pFile,m_lRecordPoint*GetRecordLength(),SEEK_CUR);
        //::fseek(m_pFile,nAddress,SEEK_CUR);
        return(TRUE);
}
BOOL  CFoxpro::SetFieldsNumber(int nIndex,float fValue)
{
        char buf[100];
        int nFields=this->GetFieldsCount();
        if(nIndex<0||nIndex>=nFields||nFields<0) return(FALSE);

        m_FoxproFields = *(this->GetFoxproFields(nIndex));

        if(m_FoxproFields.byStyle!='N') return(FALSE);
        if(!m_pRecordBuf) return(FALSE);


        if(m_FoxproFields.byDotCount==0) sprintf(buf,"%.0f",fValue);
        else if(m_FoxproFields.byDotCount==1) sprintf(buf,"%.1f",fValue);
        else if(m_FoxproFields.byDotCount==2) sprintf(buf,"%.2f",fValue);
        else if(m_FoxproFields.byDotCount==3) sprintf(buf,"%.3f",fValue);
        else if(m_FoxproFields.byDotCount==4) sprintf(buf,"%.4f",fValue);
        else if(m_FoxproFields.byDotCount==5) sprintf(buf,"%.5f",fValue);
        else  sprintf(buf,"%.6f",fValue);

        int nAddress = (WORD)m_FoxproFields.dwDataAddress;
        int nLength1 = _fstrlen(buf);
        int nLength2 = (WORD)m_FoxproFields.byLength;
        for(int i=0;i<nLength2;i++)
        {
                if(i>=nLength1)
                {
                        m_pRecordBuf[nAddress+i]=' ';
                }
                else
                {
                        m_pRecordBuf[nAddress+i]=buf;
                }
        }

        return(TRUE);
}
BOOL  CFoxpro::SetFieldsDate(int nIndex,int nYear,int nMonth,int nDay)
{
        int nFields=this->GetFieldsCount();
        if(nIndex<0||nIndex>=nFields||nFields<0) return(FALSE);

        m_FoxproFields = *(this->GetFoxproFields(nIndex));

        if(m_FoxproFields.byStyle!='D') return(FALSE);
        if(!m_pRecordBuf) return(FALSE);

        int nAddress = (WORD)m_FoxproFields.dwDataAddress;
        //sprintf((char *)&m_pRecordBuf[nAddress],"%4d%2d%2d%",nYear,nMonth,nDay);
        //m_pRecordBuf[nAddress+8]=' ';
        char buf[40];
        sprintf(buf,"%4d%2d%2d",nYear,nMonth,nDay);
        for(int i=0;i<8;i++)
        {       
                m_pRecordBuf[nAddress+i] = buf;
        }


        return(TRUE);
}
BOOL  CFoxpro::SetFieldsLogic(int nIndex,BOOL bLogic)
{
        int nFields=this->GetFieldsCount();
        if(nIndex<0||nIndex>=nFields||nFields<0) return(FALSE);

        m_FoxproFields = *(this->GetFoxproFields(nIndex));

        if(m_FoxproFields.byStyle!='L') return(FALSE);
        if(!m_pRecordBuf) return(FALSE);

        int nAddress = (WORD)m_FoxproFields.dwDataAddress;
        if(bLogic) m_pRecordBuf[nAddress]='T';
        else m_pRecordBuf[nAddress]='F';

        return(TRUE);
}
BOOL  CFoxpro::SetFieldsMemo(int nIndex, const char* /*pStr*/)
{
        int nFields=this->GetFieldsCount();
        if(nIndex<0||nIndex>=nFields||nFields<0) return(FALSE);

        m_FoxproFields = *(this->GetFoxproFields(nIndex));

        if(m_FoxproFields.byStyle!='M') return(FALSE);
        if(!m_pRecordBuf) return(FALSE);

        //int nAddress = (WORD)m_FoxproFields.dwDataAddress;
        //((DWORD *)&m_pRecordBuf[nAddress])=(BYTE)chLogic;

        return(TRUE);
}

BOOL  CFoxpro::Seek(long nIndex,int nMode)
{
        if(!m_pFile) return(FALSE);

        if(nMode==SEEK_SET)      m_lRecordPoint = nIndex;
        else if(nMode==SEEK_CUR) m_lRecordPoint+= nIndex;
        else if(nMode==SEEK_END)
        {
                m_lRecordPoint = GetRecordCount();
                m_lRecordPoint+= nIndex;
        }
        ::fseek(m_pFile,this->GetRecordAddress(),SEEK_SET);
        ::fseek(m_pFile,m_lRecordPoint*GetRecordLength(),SEEK_CUR);

        if(m_lRecordPoint<this->GetRecordCount())
        {
                ::fread(m_pRecordBuf,this->GetRecordLength(),1,m_pFile);
                m_pRecordBuf[GetRecordLength()]='\0';
                ::fseek(m_pFile,0L-GetRecordLength(),SEEK_CUR);
        }

        return(TRUE);
}

BOOL  CFoxpro::Delete()
{
        if(!m_pFile) return(FALSE);
        if(!m_pRecordBuf) return(FALSE);

        if(m_lRecordPoint>=this->GetRecordCount()) return(FALSE);

        this->Edit();
        m_pRecordBuf[0]='*';
        this->Update();

        return(TRUE);
}

BOOL  CFoxpro::Zap()
{
        if(!m_pFile) return(FALSE);
        if(!this->GetRecordCount()) return(TRUE);


        long lRecordCount  = this->GetRecordCount();
        long lRecordLength = this->GetRecordLength();

        long lLocation=0;
        for(long i=0;i<lRecordCount;i++)
        {
                ::fseek(m_pFile,this->GetRecordAddress(),SEEK_SET);
                ::fseek(m_pFile,i*lRecordLength,SEEK_CUR);

                ::fread(m_pRecordBuf,lRecordLength,1,m_pFile);
                if(m_pRecordBuf[0] != '*')
                {
                        ::fseek(m_pFile,this->GetRecordAddress(),SEEK_SET);
                        ::fseek(m_pFile,lLocation*lRecordLength,SEEK_CUR);
                        ::fwrite(m_pRecordBuf,lRecordLength,1,m_pFile);
                        lLocation++;
                }
        }
        this->m_FoxproHead.dwRecordCount=lLocation;

        ::fseek(m_pFile,0,SEEK_SET);
        ::fwrite(&m_FoxproHead,sizeof(FOXPRO_HEAD),1,m_pFile);

        long lFileLength = sizeof(FOXPRO_HEAD)+
                1L*sizeof(FOXPRO_FIELDS)*this->GetFieldsCount()+
                1L+
                1L*this->m_FoxproHead.dwRecordCount*lRecordLength;


        ::chsize(fileno(m_pFile),lFileLength);
        ::fseek(m_pFile,0,SEEK_END);
        ::fwrite("\x1A",1,1,m_pFile);

        m_lRecordPoint=0L;

        this->Seek(m_lRecordPoint,SEEK_SET);
        this->Edit();
        return(TRUE);
}

BOOL  CFoxpro::DeleteEx()
{
        if(!m_pFile) return(FALSE);

        if(m_lRecordPoint>=this->GetRecordCount()) return(FALSE);


        long lRecordCount  = this->GetRecordCount();
        long lRecordLength = this->GetRecordLength();

        for(long i=m_lRecordPoint+1;i<lRecordCount;i++)
        {
                ::fseek(m_pFile,this->GetRecordAddress(),SEEK_SET);
                ::fseek(m_pFile,i*lRecordLength,SEEK_CUR);

                ::fread(m_pRecordBuf,lRecordLength,1,m_pFile);

                ::fseek(m_pFile,-2L*lRecordLength,SEEK_CUR);
                ::fwrite(m_pRecordBuf,lRecordLength,1,m_pFile);
        }

        this->m_FoxproHead.dwRecordCount-=1;
        ::fseek(m_pFile,0,SEEK_SET);
        ::fwrite(&m_FoxproHead,sizeof(FOXPRO_HEAD),1,m_pFile);
        long lFileLength = sizeof(FOXPRO_HEAD)+
                1L*sizeof(FOXPRO_FIELDS)*this->GetFieldsCount()+
                1L+
                1L*this->m_FoxproHead.dwRecordCount*lRecordLength;


        ::chsize(fileno(m_pFile),lFileLength);
        ::fseek(m_pFile,0,SEEK_END);
        ::fwrite("\x1A",1,1,m_pFile);

        if(m_lRecordPoint && m_lRecordPoint==this->GetRecordCount())
        {
                m_lRecordPoint-=1;
        }
        //------------------------------------------------------------
        this->Seek(m_lRecordPoint,SEEK_SET);
        this->Edit();
        return(TRUE);
}

BOOL  CFoxpro::Insert()
{
        return(TRUE);
}

BOOL  CFoxpro::AddNew()
{
        if (NULL == m_pFile)
        {
                return(FALSE);
        }
        m_lRecordPoint = this->GetRecordCount();
        _fmemset(m_pRecordBuf,' ',this->GetRecordLength()+1024);
        this->Seek(0,SEEK_END);
        m_bNew = TRUE;

        return(TRUE);
}

BOOL  CFoxpro::Edit()
{
        if(NULL == m_pFile)
        {
                return(FALSE);
        }
        if (m_bNew)
        {
                return(TRUE);
        }

        this->Seek(m_lRecordPoint,SEEK_SET);
        ::fread(m_pRecordBuf,this->GetRecordLength(),1,m_pFile);
        m_pRecordBuf[GetRecordLength()]='\0';

        return(TRUE);
}
BOOL  CFoxpro::Update()
{
        if (NULL == m_pFile) return(FALSE);

        if(m_bNew)
        {
                m_lRecordPoint = this->GetRecordCount();
        }

        ::fseek(m_pFile,this->GetRecordAddress(),SEEK_SET);
        ::fseek(m_pFile,m_lRecordPoint*GetRecordLength(),SEEK_CUR);
        ::fwrite(m_pRecordBuf,this->GetRecordLength(),1,m_pFile);

        if (m_bNew)
        {
                //::fseek(m_pFile, 0, SEEK_END);
                fwrite("\x1A",1,1,m_pFile);

                rewind(m_pFile);
                m_FoxproHead.dwRecordCount += 1;
                ::fwrite(&m_FoxproHead,sizeof(FOXPRO_HEAD),1,m_pFile);
        }
        m_bNew = FALSE;
        return(TRUE);
}

BOOL  CFoxpro::IsOpen()
{
        return(((m_pFile)?TRUE:FALSE));
}

BOOL CFoxpro::Flush()
{
        if (NULL == m_pFile)
        {
                return(FALSE);
        }
        ::fflush(m_pFile);

        int duphandle = ::dup(fileno(m_pFile));

        ::close(duphandle);

        return(TRUE);
}

[ Last edited by firstsail on 2018-7-14 at 12:38 ]

2018-7-14 12:13
查看资料  访问主页  发短消息 网志   编辑帖子  回复  引用回复
firstsail
高级用户





积分 668
发帖 295
注册 2005-7-26
来自 广东深圳
状态 离线
『第 288 楼』:  

//下面是Symbol2.h文件



#ifndef  _SYMBOL2_H_
#define  _SYMBOL2_H_

#ifndef                TRUE
#define                TRUE        1
#endif
#ifndef                FALSE
#define                FALSE        0
#endif
#ifndef         NULL
#define         NULL 0
#endif



        #define _fmemcpy memcpy
        #define _fstrcpy strcpy
        #define _fstricmp stricmp
        #define _fstrcmp  strcmp
        #define _fstrlen  strlen
        #define _fmemset  memset

        #define farmalloc malloc
        #define farfree   free

#define  pi 3.1415926
#define CONST_SINGLE_T    3.14159f
#define CONST_DOUBLE_T    3.14159265359

typedef     char*   LPCTSTR;
typedef     void*   LPVOID;
typedef                int                COLOR;
typedef                int                HANDLE;
typedef                unsigned int        WORD;
typedef                unsigned char        BYTE;
typedef                int                BOOL;
typedef     unsigned long        DWORD;
typedef         DWORD           SORT;
typedef         int                 BOOL;
typedef         unsigned int    BOOLEN;
typedef           int                HWND;
typedef                DWORD                WPARAM;
typedef DWORD                LPARAM;
typedef long                LONG;
typedef long*       LPLONG;
typedef void        VOID;
typedef        DWORD        ULONG;
typedef         float                FLOAT;
typedef         int                INT;
typedef signed   short  SHORT;
typedef unsigned short  USHORT;
typedef unsigned short  WCHAR;



#define DELETE(a) {if ((a) != NULL) delete (a); (a) = NULL;}



#define  MAX(a,b)  ((a>b)?a:b)
#define  MIN(a,b)  ((a<b)?a:b)

#define SHIFT8(a)   ((a)<<8)
#define SHIFT16(a)  ((a)<<16)
#define LOBYTE(a)   ((BYTE)((a)&0xFF))
#define HIBYTE(a)   ((((DWORD)(a))>>8)&0xFF)
#define LOWORD(a)   ((WORD)((WORD)(((DWORD)(a))&0xFFFFL)))
#define HIWORD(a)   ((WORD)((((DWORD)(a))>>16)&0xFFFFL))


#endif

[ Last edited by firstsail on 2018-7-14 at 12:37 ]

2018-7-14 12:15
查看资料  访问主页  发短消息 网志   编辑帖子  回复  引用回复
firstsail
高级用户





积分 668
发帖 295
注册 2005-7-26
来自 广东深圳
状态 离线
『第 289 楼』:  

近期美国政府打压并插手谷歌、高通公司与华为及大僵等科技公司的合作事件,在嵌入式场合的中国企业,突然被外国企业和外国政府掐住了脖子,国人这才逐渐意识到:掌握中国人自主研发的嵌入式系统有多么的重要和紧迫。

现在的WinSail实时嵌入式系统,目前是一款免费可供下载的软件系统,可在http://www.firstsail.com.cn/Software.html网页中下载,其于2004年推向市场,至今已经过15年的市场考验,成功运用到各种嵌入式领域中,并被各行各业广泛大量的下载使用。

2019-5-24 11:57
查看资料  访问主页  发短消息 网志   编辑帖子  回复  引用回复
firstsail
高级用户





积分 668
发帖 295
注册 2005-7-26
来自 广东深圳
状态 离线
『第 290 楼』:  

谢天谢地,自己忘了密码后,多谢论坛坛主wengierwu先生,帮我把和密码恢复回来了。老用户忘了密码,可找wengierwu@hotmail.com请求恢复

[ Last edited by firstsail on 2019-12-13 at 09:15 ]

2019-12-13 09:13
查看资料  访问主页  发短消息 网志   编辑帖子  回复  引用回复
firstsail
高级用户





积分 668
发帖 295
注册 2005-7-26
来自 广东深圳
状态 离线
『第 291 楼』:  

7年后,更新了下载版本

http://www.firstsail.com.cn/Software.html

2020-2-17 12:02
查看资料  访问主页  发短消息 网志   编辑帖子  回复  引用回复
« [11] [12] [13] [14] [15] [16] [17] [18] [19] [20] »
请注意:您目前尚未注册或登录,请您注册登录以使用论坛的各项功能,例如发表和回复帖子等。


可打印版本 | 推荐给朋友 | 订阅主题 | 收藏主题



论坛跳转: