⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qtsylib.c

📁 dos下pos机程序 连接sybase数据库 使用Microsoft c7 编译
💻 C
📖 第 1 页 / 共 5 页
字号:
  dbcmd(dbproc,"       etime=convert(char(11),etime,102)+convert(char(9),etime,8),yhl,\n");
  dbcmd(dbproc,"       srr,srtime=convert(char(11),srtime,102)+convert(char(9),srtime,8),qfr,\n");
  dbcmd(dbproc,"       qftime=convert(char(11),qftime,102)+convert(char(9),qftime,8),qfbz,dzlx\n");
  dbcmd(dbproc,"from jxc_sddzb\n");
  if(pWhere[0]!='\0')
   dbfcmd(dbproc,"where %s\n",pWhere);
  dbcmd(dbproc,"order by bm");
  dbsqlexec(dbproc);
  while((result_code=dbresults(dbproc))!= NO_MORE_RESULTS)
   if (result_code == SUCCEED)
    {
     fpt = fopen("temp.dat","wb+");
     dbbind(dbproc, 1, NTBSTRINGBIND, (DBINT)0,bm);
     dbbind(dbproc, 2, NTBSTRINGBIND, (DBINT)0,stime);
     dbbind(dbproc, 3, NTBSTRINGBIND, (DBINT)0,etime);
     dbbind(dbproc, 4, FLT8BIND, (DBINT) 0,(BYTE *) &yhl);
     dbbind(dbproc, 5, NTBSTRINGBIND, (DBINT)0,srr);
     dbbind(dbproc, 6, NTBSTRINGBIND, (DBINT)0,srtime);
     dbbind(dbproc, 7, NTBSTRINGBIND, (DBINT)0,qfr);
     dbbind(dbproc, 8, NTBSTRINGBIND, (DBINT)0,qftime);
     dbbind(dbproc, 9, NTBSTRINGBIND, (DBINT)0,qfbz);
     dbbind(dbproc,10, NTBSTRINGBIND, (DBINT)0,dzlx);
     while(dbnextrow(dbproc)!=NO_MORE_ROWS)
     {
      sprintf(tmpbuf,pFor,bm,stime,etime,yhl,srr,srtime,qfr,qftime,qfbz,dzlx);
      fwrite(&tmpbuf,rLen,1,fpt);
      RecordCount++;
     }
     fclose(fpt);
    }
  return RecordCount;
}
//分表从服务器下载数据到本地表中JXC_SYJB
long int GetSYJBFromServer(int rLen)
{
  FILE *fpt;
  long int RecordCount=0;
  char tmpbuf[500];
  DBCHAR syjh[4],mc[4],jrsj[21],jbsj[21],syy[4],bc[7],jbsyy[4],lx[2],lsdh[5],status[2];
  DBFLT8 dbsr,drsr,ljsr,dbbs,drbs,ljbs;
  char *pFor="%-3s%-3s%-20s%-20s%-3s%-6s%19.4f%19.4f%19.4f%19.4f%19.4f%19.4f%-3s%-1s%-4s%-1s";
  dbfreebuf(dbproc);
  dbcmd(dbproc,"select syjh,mc,jrsj=convert(char(11),jrsj,102)+convert(char(9),jrsj,8),\n");
  dbcmd(dbproc,"jbsj=convert(char(11),jbsj,102)+convert(char(9),jbsj,8),\n");
  dbcmd(dbproc,"       syy,bc,dbsr,drsr,ljsr,dbbs,drbs,ljbs,jbsyy,lx,lsdh,status\n");
  dbcmd(dbproc,"from jxc_syjb\n");
  dbcmd(dbproc,"order by syjh");
  dbsqlexec(dbproc);
  while((result_code=dbresults(dbproc))!= NO_MORE_RESULTS)
   if (result_code == SUCCEED)
    {
     fpt = fopen("temp.dat","wb+");
     dbbind(dbproc, 1, NTBSTRINGBIND, (DBINT)0,syjh);
     dbbind(dbproc, 2, NTBSTRINGBIND, (DBINT)0,mc);
     dbbind(dbproc, 3, NTBSTRINGBIND, (DBINT)0,jrsj);
     dbbind(dbproc, 4, NTBSTRINGBIND, (DBINT)0,jbsj);
     dbbind(dbproc, 5, NTBSTRINGBIND, (DBINT)0,syy);
     dbbind(dbproc, 6, NTBSTRINGBIND, (DBINT)0,bc);
     dbbind(dbproc, 7, FLT8BIND, (DBINT) 0,(BYTE *) &dbsr);
     dbbind(dbproc, 8, FLT8BIND, (DBINT) 0,(BYTE *) &drsr);
     dbbind(dbproc, 9, FLT8BIND, (DBINT) 0,(BYTE *) &ljsr);
     dbbind(dbproc,10, FLT8BIND, (DBINT) 0,(BYTE *) &dbbs);
     dbbind(dbproc,11, FLT8BIND, (DBINT) 0,(BYTE *) &drbs);
     dbbind(dbproc,12, FLT8BIND, (DBINT) 0,(BYTE *) &ljbs);
     dbbind(dbproc,13, NTBSTRINGBIND, (DBINT)0,jbsyy);
     dbbind(dbproc,14, NTBSTRINGBIND, (DBINT)0,lx);
     dbbind(dbproc,15, NTBSTRINGBIND, (DBINT)0,lsdh);
     dbbind(dbproc,16, NTBSTRINGBIND, (DBINT)0,status);
     while(dbnextrow(dbproc)!=NO_MORE_ROWS)
     {
      sprintf(tmpbuf,pFor,syjh,mc,jrsj,jbsj,syy,bc,dbsr,drsr,ljsr,dbbs,drbs,ljbs,jbsyy,lx,lsdh,status);
      fwrite(&tmpbuf,rLen,1,fpt);
      RecordCount++;
     }
     fclose(fpt);
    }
  return RecordCount;
}
//分表从服务器下载数据到本地表中JXC_SYYB
long int GetSYYBFromServer(int rLen)
{
  FILE *fpt;
  long int RecordCount=0;
  char tmpbuf[200];
  DBCHAR syybm[4],xm[9],mm[7],jrjh[4],bc[7],lsdh[5];
  DBFLT8 dbsr,drsr,ljsr,dbbs,dybs,ljbs;
  char *pFor="%-3s%-8s%-6s%-3s%-6s%19.4f%19.4f%19.4f%19.4f%19.4f%19.4f%-4s";
  dbfreebuf(dbproc);
  dbcmd(dbproc,"select syybm,xm,mm,jrjh,bc,dbsr,dysr,dbbs,dybs,ljsr,ljbs,lsdh\n");
  dbcmd(dbproc,"from jxc_syyb\n");
  dbcmd(dbproc,"order by syybm");
  dbsqlexec(dbproc);
  while((result_code=dbresults(dbproc))!= NO_MORE_RESULTS)
   if (result_code == SUCCEED)
    {
     fpt = fopen("temp.dat","wb+");
     dbbind(dbproc, 1, NTBSTRINGBIND, (DBINT)0,syybm);
     dbbind(dbproc, 2, NTBSTRINGBIND, (DBINT)0,xm);
     dbbind(dbproc, 3, NTBSTRINGBIND, (DBINT)0,mm);
     dbbind(dbproc, 4, NTBSTRINGBIND, (DBINT)0,jrjh);
     dbbind(dbproc, 5, NTBSTRINGBIND, (DBINT)0,bc);
     dbbind(dbproc, 6, FLT8BIND, (DBINT) 0,(BYTE *) &dbsr);
     dbbind(dbproc, 7, FLT8BIND, (DBINT) 0,(BYTE *) &drsr);
     dbbind(dbproc, 8, FLT8BIND, (DBINT) 0,(BYTE *) &ljsr);
     dbbind(dbproc, 9, FLT8BIND, (DBINT) 0,(BYTE *) &dbbs);
     dbbind(dbproc,10, FLT8BIND, (DBINT) 0,(BYTE *) &dybs);
     dbbind(dbproc,11, FLT8BIND, (DBINT) 0,(BYTE *) &ljbs);
     dbbind(dbproc,12, NTBSTRINGBIND, (DBINT)0,lsdh);
     while(dbnextrow(dbproc)!=NO_MORE_ROWS)
     {
      sprintf(tmpbuf,pFor,syybm,xm,mm,jrjh,bc,dbsr,drsr,ljsr,dbbs,dybs,ljbs,lsdh);
      fwrite(&tmpbuf,rLen,1,fpt);
      RecordCount++;
     }
     fclose(fpt);
    }
  return RecordCount;
}
//分表从服务器下载数据到本地表中JXC_DTMB
long int GetDTMBFromServer(char *pWhere,int rLen)
{
  FILE *fpt;
  long int RecordCount=0;
  char tmpbuf[120];
  DBCHAR spbm[9],tm[14],jc[2];
  DBFLT8 sl,sj,dyzs,yhj;
  char *pFor="%-8s%-13s%14.4f%14.4f%8.0f%14.4f%-3s";
  dbfreebuf(dbproc);
  dbcmd(dbproc,"select spbm,tm,sl,sj,dyzs,yhj,jc\n");
  dbcmd(dbproc,"from jxc_dtmb\n");
  if(pWhere[0]!='\0')
   dbfcmd(dbproc,"where %s\n",pWhere);
  dbcmd(dbproc,"order by tm");
  dbsqlexec(dbproc);
  while((result_code=dbresults(dbproc))!= NO_MORE_RESULTS)
   if (result_code == SUCCEED)
    {
     fpt = fopen("temp.dat","wb+");
     dbbind(dbproc, 1, NTBSTRINGBIND, (DBINT)0,spbm);
     dbbind(dbproc, 2, NTBSTRINGBIND, (DBINT)0,tm);
     dbbind(dbproc, 3, FLT8BIND, (DBINT) 0,(BYTE *) &sl);
     dbbind(dbproc, 4, FLT8BIND, (DBINT) 0,(BYTE *) &sj);
     dbbind(dbproc, 5, FLT8BIND, (DBINT) 0,(BYTE *) &dyzs);
     dbbind(dbproc, 6, FLT8BIND, (DBINT) 0,(BYTE *) &yhj);
     dbbind(dbproc, 7, NTBSTRINGBIND, (DBINT)0,jc);
     while(dbnextrow(dbproc)!=NO_MORE_ROWS)
     {
      sprintf(tmpbuf,pFor,spbm,tm,sl,sj,dyzs,yhj,jc);
      fwrite(&tmpbuf,rLen,1,fpt);
      RecordCount++;
     }
     fclose(fpt);
    }
  return RecordCount;
}
//分表从服务器下载数据到本地表中JXC_LBB
long int GetLBBFromServer(int rLen)
{
  FILE *fpt;
  long int RecordCount=0;
  char tmpbuf[100];
  DBCHAR lbbm[7],lbmc[21];
  DBFLT8 yhl;
  char *pFor="%-6s%-20s%6.2f";
  dbfreebuf(dbproc);
  dbcmd(dbproc,"select lbbm,lbmc,yhl\n");
  dbcmd(dbproc,"from jxc_lbb\n");
  dbcmd(dbproc,"order by lbbm");
  dbsqlexec(dbproc);
  while((result_code=dbresults(dbproc))!= NO_MORE_RESULTS)
   if (result_code == SUCCEED)
    {
     fpt = fopen("temp.dat","wb+");
     dbbind(dbproc, 1, NTBSTRINGBIND, (DBINT)0,lbbm);
     dbbind(dbproc, 2, NTBSTRINGBIND, (DBINT)0,lbmc);
     dbbind(dbproc, 3, FLT8BIND, (DBINT) 0,(BYTE *) &yhl);
     while(dbnextrow(dbproc)!=NO_MORE_ROWS)
     {
      sprintf(tmpbuf,pFor,lbbm,lbmc,yhl);
      fwrite(&tmpbuf,rLen,1,fpt);
      RecordCount++;
     }
     fclose(fpt);
    }
  return RecordCount;
}
//分表从服务器下载数据到本地表中JXC_TMCB
long int GetTMCBFromServer(char *pWhere,int rLen)
{
  FILE *fpt;
  long int RecordCount=0;
  char tmpbuf[200];
  DBCHAR tplu[7],spbm[9],spmc[33],dtime[21],sr[11],kjj[11],tm[11];
  DBFLT8 sj,ysj;
  char *pFor="%-6s%-8s%-32s%19.4f%19.4f%-20s%-10s%-10s%-10s";
  dbfreebuf(dbproc);
  dbcmd(dbproc,"select tplu,spbm,spmc,sj,ysj,\n");
  dbcmd(dbproc,"dtime=convert(char(11),dtime,102)+convert(char(9),dtime,8),sr,kjj,tm\n");
  dbcmd(dbproc,"from jxc_tmcb\n");
  if(pWhere[0]!='\0')
   dbfcmd(dbproc,"where %s\n",pWhere);
  dbcmd(dbproc,"order by tplu");
  dbsqlexec(dbproc);
  while((result_code=dbresults(dbproc))!= NO_MORE_RESULTS)
   if (result_code == SUCCEED)
    {
     fpt = fopen("temp.dat","wb+");
     dbbind(dbproc, 1, NTBSTRINGBIND, (DBINT)0,tplu);
     dbbind(dbproc, 2, NTBSTRINGBIND, (DBINT)0,spbm);
     dbbind(dbproc, 3, NTBSTRINGBIND, (DBINT)0,spmc);
     dbbind(dbproc, 4, FLT8BIND, (DBINT) 0,(BYTE *) &sj);
     dbbind(dbproc, 5, FLT8BIND, (DBINT) 0,(BYTE *) &ysj);
     dbbind(dbproc, 6, NTBSTRINGBIND, (DBINT)0,dtime);
     dbbind(dbproc, 7, NTBSTRINGBIND, (DBINT)0,sr);
     dbbind(dbproc, 8, NTBSTRINGBIND, (DBINT)0,kjj);
     dbbind(dbproc, 9, NTBSTRINGBIND, (DBINT)0,tm);
     while(dbnextrow(dbproc)!=NO_MORE_ROWS)
     {
      sprintf(tmpbuf,pFor,tplu,spbm,spmc,sj,ysj,dtime,sr,kjj,tm);
      fwrite(&tmpbuf,rLen,1,fpt);
      RecordCount++;
     }
     fclose(fpt);
    }
  return RecordCount;
}
//分表从服务器下载数据到本地表中SER_XSJB
long int GetXSJBFromServer(const char *pFrom,char *pWhere,int rLen)
{
  FILE *fpt;
  long int RecordCount=0;
  char tmpbuf[200];
  DBCHAR syjh[4],dtime[21],spbm[9],fkfs[2];
  DBFLT8 lsh,xh,sl,sj,je,bx;
  char *pFor="%-3s%8.0f%-21s%8.0f%-8s%14.4f%19.4f%19.4f%-1s%19.4f";
  dbfreebuf(dbproc);
  dbcmd(dbproc,"select syjh,lsh,dtime=convert(char(11),dtime,102)+convert(char(9),dtime,8),\n");
  dbcmd(dbproc,"       xh,spbm,sl,sj,je,fkfs,bx\n");
  dbfcmd(dbproc,"from %s\n",pFrom);
  if(pWhere[0]!='\0')
    dbfcmd(dbproc,"where %s\n",pWhere);
  dbcmd(dbproc,"order by dtime,xh");
  dbsqlexec(dbproc);
  while((result_code=dbresults(dbproc))!= NO_MORE_RESULTS)
   if (result_code == SUCCEED)
    {
     fpt = fopen("temp.dat","wb+");
     dbbind(dbproc, 1, NTBSTRINGBIND, (DBINT)0,syjh);
     dbbind(dbproc, 2, FLT8BIND, (DBINT) 0,(BYTE *) &lsh);
     dbbind(dbproc, 3, NTBSTRINGBIND, (DBINT)0,dtime);
     dbbind(dbproc, 4, FLT8BIND, (DBINT) 0,(BYTE *) &xh);
     dbbind(dbproc, 5, NTBSTRINGBIND, (DBINT)0,spbm);
     dbbind(dbproc, 6, FLT8BIND, (DBINT) 0,(BYTE *) &sl);
     dbbind(dbproc, 7, FLT8BIND, (DBINT) 0,(BYTE *) &sj);
     dbbind(dbproc, 8, FLT8BIND, (DBINT) 0,(BYTE *) &je);
     dbbind(dbproc, 9, NTBSTRINGBIND, (DBINT)0,fkfs);
     dbbind(dbproc,10, FLT8BIND, (DBINT) 0,(BYTE *) &bx);
     while(dbnextrow(dbproc)!=NO_MORE_ROWS)
     {
      sprintf(tmpbuf,pFor,syjh,lsh,dtime,xh,spbm,sl,sj,je,fkfs,bx);
      fwrite(&tmpbuf,rLen,1,fpt);
      RecordCount++;
     }
     fclose(fpt);
    }
  return RecordCount;
}


//从服务器读取数据到表TableName中
int GetDataFromServer(const char *TableName,const char *sTableName,
		      char *Where,int Att)
{
  FILE *fp,*fpt;
  int i,hLen,rLen,FieldCount=0;
  char _DbfHead[2048],buffer[2000];
  char _Size[2],_Dec[2];
  unsigned char a[4];
  long int m,n,RecordCount=0,RCount;
  TField TStr[30];

  if(dbproc==NULL||DBDEAD(dbproc)) return 0;

  //读取表的结构
  fp = fopen(TableName,"rb");
  if(fp)
  {
    fseek(fp,4,0);             //记录数
    fread(&a,4,1,fp);
    RCount = a[0]+(long int)a[1]*0x100+(long int)a[2]*0x100*0x100;

    fseek(fp,8,0);             //库结构说明长度
    fread(&a,2,1,fp);
    hLen = a[0]+a[1]*0x100+1;

    fseek(fp,10,0);             //记录长度
    fread(&a,2,1,fp);
    rLen = a[0]+a[1]*0x100;


    FieldCount = hLen/32-1; //字段数
    //printf("%d  %d\n",hLen,FieldCount);

    //读取库结构
    fseek(fp,0,0);
    fread(&_DbfHead,hLen,1,fp);

    for(i=0;i<FieldCount;i++)
    {
     fseek(fp,32+i*32,0);      //读取记录描述
     fread(&buffer,32,1,fp);
     CopyStr(TStr[i].FieldName,buffer,0,10,1);

     StrToLower(TStr[i].FieldName);

     CopyStr(TStr[i].DataType, buffer,11,1,1);
     CopyStr(_Size,buffer,16,1,0);
     CopyStr(_Dec,buffer,17,1,0);
     TStr[i].Size=(int)_Size[0];
     //printf("%10s,%2d ",TStr[i].FieldName,_Size[0]);
     TStr[i].Dec=(int)_Dec[0];
     if(i)
      TStr[i].xOff=TStr[i-1].xOff+TStr[i-1].Size;
     else
      TStr[i].xOff=0;
    }
   fclose(fp);
  }
  else
   return 0;
  switch(Att)
  {
   case 0:RecordCount=GetSPBFromServer(Where,rLen);
	  break;
   case 1:RecordCount=GetSYSFromServer(rLen);
	  break;
   case 2:RecordCount=GetSDDZFromServer(Where,rLen);
	  break;
   case 3:RecordCount=GetSYJBFromServer(rLen);
	  break;
   case 4:RecordCount=GetSYYBFromServer(rLen);
	  break;
   case 5:RecordCount=GetDTMBFromServer(Where,rLen);
	  break;
   case 6:RecordCount=GetLBBFromServer(rLen);
	  break;
   case 7:RecordCount=GetTMCBFromServer(Where,rLen);
	  break;
   case 8:RecordCount=GetXSJBFromServer(sTableName,Where,rLen);
	  break;
  }
  i=4;
  n=RecordCount;
  while(n&&i<8)
  {
   m=n%256;
   _DbfHead[i++]=(char)m;
   n/=256;
  }
  fpt = fopen("temp.dat","rb");
  fp = fopen(TableName,"wb+");
  fwrite(&_DbfHead,hLen,1,fp); //写入表头
  while(fread(&buffer,rLen,1,fpt))
   fwrite(&buffer,rLen,1,fp);
  fclose(fpt);
  fclose(fp);
  return 1;
}
/*
  从一个DataSet检索数据
  DataSet  - 数据集
  TStr[]   - 字段列表
  KeyField - 关键字段
  Value    - 匹配的值
  buffer   - 返回的结果
*/
int GetDataFromDbf(TDataSet *DataSet,TField TStr[],
			 const char *KeyField,const char *Value)
{
	FILE *fp;
	int hLen,rLen,FieldCount=0;
  char _buf[80];
  long int RCount,m,n;
  int xOff,fLen,k;
  hLen = DataSet->hLen;
  rLen = DataSet->rLen;
  FieldCount = DataSet->FieldCount;
  RCount = DataSet->RCount;
  xOff = DataSet->xOff;
  fLen = DataSet->fLen;
  //打开表
  fp = fopen(DataSet->TableName,"rb");
  if(fp)
   {
    n=0;
    RCount--;
    xOff+=hLen;
    k=1;
		while(n<=RCount)
		 {
			m = (n+RCount)/2;
			fseek(fp,m*rLen+xOff,0);
			fread(&_buf,fLen,1,fp);  //读取记录
			_buf[fLen]='\0';
			Trim(_buf);
			k = strcmp(Value,_buf);
			//printf("Value:%s _buf:%s\n",Value,_buf);
			//getch();
			if(k==0)
			 {
				fseek(fp,m*rLen+hLen,0);
				fread(DataSet->buffer,rLen,1,fp);  //读取记录
				break;
       }
      else if(k>0)
	  n=m+1;
	 else
	  RCount=m-1;
     }
    fclose(fp);
    if(!k)  //找到记录
     return 0;
   return 1;
  }
  return 2;
}
//取某个字段的值
int GetDataFromField(int FieldCount,TField TStr[],const char *FieldName,
		     char *svalue,double *fvalue)
{
  int i;
  for(i=0;i<FieldCount;i++)
   if(!strcmp(TStr[i].FieldName,FieldName))
    {
     CopyStr(svalue,_tbuffer,TStr[i].xOff,TStr[i].Size,1);
     if(TStr[i].DataType[0]=='N'&&fvalue) //数字
      *fvalue=atof(svalue);
    }
  return 1;
}
//获取本地时间
void GetlocalTime(char *DateTime,char *LocalDate,char *LocalTime)
{
  time_t timer;
  struct tm *tblock;
  int i;
  //求当前日期及时间
  timer = time(NULL);
  tblock = localtime(&timer);
  tblock->tm_mon++;
  sprintf(DateTime,"%4d.%2d.%2d %2d:%2d:%2d",
		   1900+tblock->tm_year,tblock->tm_mon,tblock->tm_mday,
		   tblock->tm_hour,tblock->tm_min,tblock->tm_sec);
  for(i=0;i<(int)strlen(DateTime);i++)
   if(DateTime[i]==' '&&i!=10)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -