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

📄 qtsylib.c

📁 dos下pos机程序 连接sybase数据库 使用Microsoft c7 编译
💻 C
📖 第 1 页 / 共 5 页
字号:
    DateTime[i]='0';

  if(LocalDate!=NULL)
   uf_strmid(LocalDate,DateTime,0,10);  //析取日期
  if(&LocalTime!=NULL)
   uf_strmid(LocalTime,DateTime,11,8);  //析取时间
}
//从时点打折本地表中读取数据
int Pos(char *sub,char *s)
{
  int k,i;
  k = 8;
  for(i=7;i>=0;i--)
   if(sub[i]==' ')
   {
    k--;
    sub[i]='\0';
   }
  for(i=0;i<k;i++)
   if(sub[i]!=s[i]) return 0;
  return 1;
}

double dbf_sddz(char *spbm,char *dzlx)
{
  FILE *fp;
  char tstime[9],tetime[9],NowDate[11],NowTime[9];
  int hLen,rLen,FieldCount=0;
  char _buf[30],stime[20],etime[20],dstime[11],detime[11];
  long int RCount,m;
  int xOff,fLen,k;
  double yhl=0;
  //设置查询查询
  hLen = _SDBDataSet.hLen;
  rLen = _SDBDataSet.rLen;
  FieldCount = _SDBDataSet.FieldCount;
  RCount = _SDBDataSet.RCount;
  xOff = _SDBDataSet.xOff;
  fLen = _SDBDataSet.fLen;
  //打开表
  fp = fopen(_SDBDataSet.TableName,"rb");
  if(fp)
  {
    xOff+=hLen;
    _buf[fLen]='\0';
    m=0;
    k=1;
    while(m<RCount)
     {
      fseek(fp,m*rLen+xOff,0);
      fread(&_buf,fLen,1,fp);  //读取关键字段
      k = Pos(_buf,spbm);
      //printf("hLen:%d xOff:%d %s-%s\n",hLen,xOff,_buf,spbm);
      //getchar();
      if(k)                    //读取整条记录
       {
	fseek(fp,m*rLen+hLen,0);
	fread(_tbuffer,rLen,1,fp);
	//读取stime和etime

	GetDataFromField(FieldCount,_SDBFields,"stime",stime,NULL);
	GetDataFromField(FieldCount,_SDBFields,"etime",etime,NULL);

	GetlocalTime(_buf,NowDate,NowTime);
	//分离stime和etime日期和时间
	uf_strmid(dstime,stime,0,10);
	uf_strmid(tstime,stime,11,8);
	uf_strmid(detime,etime,0,10);
	uf_strmid(tetime,etime,11,8);

	if(strcmp(NowDate,dstime)>=0&&strcmp(detime,NowDate)>=0&&
	   strcmp(NowTime,tstime)>=0&&strcmp(tetime,NowTime)>=0)
	 {
	  GetDataFromField(FieldCount,_SDBFields,"yhl",_buf,&yhl);
	  GetDataFromField(FieldCount,_SDBFields,"dzlx",dzlx,NULL);
	  break;
	 }
       }
      else if(k>0)
	    break;
      m++;
     }
    fclose(fp);
  }
  return yhl;
}
//交班写入本地表
void Dbf_jb(char *DateTime)
{
  FILE *fp;
  int i,xOff;
  char _buf[1000];
  fp = fopen("DATA\\JXC_SYJB.DBF","rb");
  if(fp)
  {
   fread(&_buf,_SYJDataSet.hLen+_SYJDataSet.rLen,1,fp);
   fclose(fp);
   for(i=0;i<_SYJDataSet.FieldCount;i++)
    if(!strcmp(_SYJFields[i].FieldName,"jbsj"))
     {
      xOff = _SYJFields[i].xOff+_SYJDataSet.hLen;
      break;
     }
   for(i=0;i<19;i++)
    _buf[xOff+i] = DateTime[i];

   fp = fopen("DATA\\JXC_SYJB.DBF","wb");
   fwrite(&_buf,_SYJDataSet.hLen+_SYJDataSet.rLen,1,fp);
   fclose(fp);
  }
}
//传送本地数据到服务器
void TranDataToServer(void)
{
  dbf_TranToServer(_jxc_xsdb,_OrigXsd,
		   _XSDDataSet.hLen,_XSDDataSet.rLen,
		   _XSBDataSet.hLen,_XSBDataSet.rLen);
  dbf_TranToServer("jxc_wqrb",_OrigWqb,
		   _XSDDataSet.hLen,_XSDDataSet.rLen,
		   _XSBDataSet.hLen,_XSBDataSet.rLen);
}
//求销售笔数及最大流水号
//
double cur_je[5],cur_bx[5];
double localje;
int localbs;

void GetMaxLshAndXsbs(int *xsbs,int *maxlsh)
{
  FILE *fp;
  char _syjh[4],_syy[4],_bc[7],_buf[30],_fkfs[2];
  int _lsh=0,_maxlsh=0,FCount,k,_xsbs=0;
  double je,bx,__lsh;
  DBINT   nxsbs=0,nmaxlsh=0;

  for(FCount=0;FCount<5;FCount++)
  {
   cur_je[FCount]=0;
   cur_bx[FCount]=0;
  }
  _xsbs = 0;
  _maxlsh = 0;
  localje = 0;
  localbs = 0;
  fp = fopen(_OrigXsd,"rb");
  if(fp)
  {
   FCount = _XSDDataSet.FieldCount;
   fseek(fp,_XSDDataSet.hLen,0);
   while(fread(&_tbuffer,_XSDDataSet.rLen,1,fp))  //读取一条记录
   {
    GetDataFromField(FCount,_XSDFields,"syjh",_syjh,NULL); //取收银机号
    GetDataFromField(FCount,_XSDFields,"syy",_syy,NULL);   //取收银员号
    GetDataFromField(FCount,_XSDFields,"bc",_bc,NULL);     //取班次
    GetDataFromField(FCount,_XSDFields,"lsh",_buf,&__lsh);  //流水号
    GetDataFromField(FCount,_XSDFields,"fkfs",_fkfs,NULL); //付款方式
    GetDataFromField(FCount,_XSDFields,"je",_buf,&je);   //金额
    GetDataFromField(FCount,_XSDFields,"bx",_buf,&bx);   //补现
    if(strcmp(_syjh,Param.SyjNo)==0&&strcmp(_syy,Syy_No)==0&&
       strcmp(_bc,g_bc)==0)
    {
      _xsbs++;                          //销售笔数加1
      _lsh=(int)__lsh;

      if(_maxlsh<_lsh) _maxlsh = _lsh;  //替换流水号
      k = atoi(_fkfs);
      localje+=je;
      localbs++;
      cur_je[k]+=je;                    //计算分类合计
      cur_bx[k]+=bx;
    }
   }
   fclose(fp);
  }
  if(*xsbs<_xsbs) *xsbs=_xsbs;
  if(*maxlsh<_maxlsh+1) *maxlsh = _maxlsh+1;

  if(!(dbproc==NULL||DBDEAD(dbproc)))
  {
   dbfreebuf(dbproc);
   dbfcmd(dbproc," select count(*),max(lsh) from %s",_jxc_xsdb);
   dbfcmd(dbproc," where syjh='%s' and syy='%s' and bc='%s' ",Param.SyjNo,Syy_No,g_bc);
   dbsqlexec(dbproc);
   while((result_code=dbresults(dbproc))!=NO_MORE_RESULTS)
   {
     if(result_code==SUCCEED)
     {
      dbbind(dbproc, 1, INTBIND, (DBINT) 0,(BYTE *) &nxsbs);
      dbbind(dbproc, 2, INTBIND, (DBINT) 0,(BYTE *) &nmaxlsh);
      while(dbnextrow(dbproc)!=NO_MORE_ROWS)
      {
	if(*xsbs<(int)nxsbs) *xsbs=(int)nxsbs;
	if(*maxlsh<(int)nmaxlsh+1) *maxlsh=(int)nmaxlsh+1;
      }
     }
     else break;
   }
  }
/*  for(FCount=0;FCount<5;FCount++)
  {
   printf("xh:%d je:%f  bx:%f\n",FCount,cur_je[FCount],cur_bx[FCount]);
  }
  getchar(); */
}

//单机收银系列函数结束
//  SQL的错误处理函数
int err_handler(DBPROCESS *dbproc_1,int severity,int dberr,int oserr,
		char *dberrstr,char *oserrstr)
{
  struct dosdate_t date;
  struct dostime_t time;
  FILE *f_errinfo;

  _dos_getdate(&date);
  _dos_gettime(&time);

  f_errinfo=fopen("errinfo.txt","a");
  fprintf(f_errinfo,"%d-%d-%d %02d:%02d\n",
	   date.year,date.month,date.day,time.hour,time.minute);
  if (dbproc_1 == NULL||DBDEAD(dbproc_1))
  {
   if(!__sqlerrormark)
   {
    MsgBoxEx("网络连接失败!",3);
    if(dbproc == NULL||DBDEAD(dbproc))
    {
      __sqlerrormark=1;
      __sqlok=0;
      __syfs=0;   //自动切换到单机收银方式
    }
    ShowBc_Name(); //显示收银状态
   }
   fclose(f_errinfo);
   return INT_CANCEL;  //INT_EXIT;
  }
  else
  { fprintf(f_errinfo,"DB-LIBRARY error:\n\t%s\n", dberrstr);
    if (oserr != DBNOERR)
	  fprintf(f_errinfo,"Operating-system error:\n\t%s\n", oserrstr);
    fclose(f_errinfo);
    return INT_CANCEL;
  }
  fclose(f_errinfo);
}

// SQL的消息处理函数
int msg_handler(DBPROCESS *dbproc,DBINT msgno,int msgstate, int severity,
		char *msgtext)
{
  char    cmd[300];
  struct dosdate_t date;
  struct dostime_t time;
  FILE *f_errinfo;

//  return 0;
  _dos_getdate(&date);
  _dos_gettime(&time);

  f_errinfo=fopen("errinfo.txt","a");
  fprintf(f_errinfo,"%d-%d-%d %02d:%02d\n",
	  date.year,date.month,date.day,time.hour,time.minute);
  fprintf(f_errinfo,"SQL Server message %ld, state %d, severity %d:\n\t%s\n",
	  msgno, msgstate, severity, msgtext);
  dbstrcpy(dbproc,0,-1,cmd);
  fprintf(f_errinfo,"%s\n",cmd);
  fclose(f_errinfo);
  return 0;
}

//联结SQL Server(用户名,密码,服务器名)
int sql_connectdb(char *user,char *pass,char *server,int flag)
{
  LOGINREC        *login;
  //安装错误处理程序
  dberrhandle(err_handler);
  dbmsghandle(msg_handler);

  login = dblogin();
  DBSETLUSER(login,user);
  DBSETLPWD(login,pass);
  DBSETLAPP(login,"QTSY");
  dbsetlogintime(10);

  if(!flag)
   {
    dbproc=dbopen(login, "Server_main");    //打开服务器
    if(dbproc==NULL) return 0;
   }
  else if(flag==1)
	{
	 dbproc_thk = dbopen(login, server);
	 if (dbproc_thk==NULL) return 0;
	 dbuse(dbproc_thk,"ytposdb");
	}
  __sqlerrormark = 0;
  return 1;
}
//收银员登录,成功-1,失败-0
int sql_login(void)
{
  DBCHAR  tmpmm[7],tmpxm[9];
  char    cmpmm[7];
  int Result=1;
  if(!__syfs||dbproc==NULL||DBDEAD(dbproc)) //实现单机登录
  {
   Result=GetDataFromDbf(&_SYYDataSet,_SYYFields,"syybm",Syy_No);
   if(!Result) //找到
    {
     GetDataFromField(_SYYDataSet.FieldCount,
		      _SYYFields,"xm",Syy_Name,NULL);
     GetDataFromField(_SYYDataSet.FieldCount,
		      _SYYFields,"mm",cmpmm,NULL);
    }
  }
  else
  {
   dbfreebuf(dbproc);
   dbcmd(dbproc," select mm,xm from jxc_syyb");
   dbfcmd(dbproc," where syybm='%s' ",Syy_No);
   dbsqlexec(dbproc);
   while((result_code=dbresults(dbproc))!=NO_MORE_RESULTS)
    if(result_code==SUCCEED)
    {
     dbbind(dbproc,1,NTBSTRINGBIND, (DBINT) 0, tmpmm);
     dbbind(dbproc, 2, NTBSTRINGBIND, (DBINT) 0, tmpxm);
     while(dbnextrow(dbproc)!=NO_MORE_ROWS)
     {
      strcpy(cmpmm,tmpmm);
      strcpy(Syy_Name,tmpxm);
     }
     if(!DBCOUNT(dbproc))
      Result = 1;
     else Result = 0;
     break;
    }
   else break;
  }
  if(!Result&&!strcmp(Syy_mm,cmpmm))
   return 1;
  else
   return 0;
}
//
void sql_close(void)
{
 dbexit();
}
//取服务器时间(返回串)
int sql_time(char *dest)
{
  DBCHAR  tmpdate[30];
  struct dosdate_t reset;
  struct dostime_t treset;

  char value[5];
  if(__syfs==0||dbproc==NULL||DBDEAD(dbproc)) //实现取单机时间
   GetlocalTime(dest,NULL,NULL);
  else
  {
   dbfreebuf(dbproc);
   dbcmd(dbproc," select convert(char(11),getdate(),102)+convert(char(8),getdate(),8)");
   dbsqlexec(dbproc);
   while((result_code=dbresults(dbproc))!= NO_MORE_RESULTS)
    if (result_code == SUCCEED)
     {
      dbbind(dbproc, 1, NTBSTRINGBIND, (DBINT) 0,tmpdate);
      while(dbnextrow(dbproc)!=NO_MORE_ROWS)
       strcpy(dest,tmpdate);
     }
    else break;
  }
  //较正本地日期
  uf_strmid(value,dest,0,4);
  reset.year  = (unsigned int)atoi(value);
  uf_strmid(value,dest,5,2);
  reset.month = (unsigned char)atoi(value);
  uf_strmid(value,dest,8,2);
  reset.day   = (unsigned char)atoi(value);
  _dos_setdate(&reset);
  //
  uf_strmid(value,dest,11,2);
  _hour=atoi(value);
  uf_strmid(value,dest,14,2);
  _minute=atoi(value);
  uf_strmid(value,dest,17,2);
  _second=atoi(value);
  __prostart=clock();
  //较正系统时间
  treset.hour    = (unsigned char)_hour;
  treset.minute  = (unsigned char)_minute;
  treset.second  = (unsigned char)_second;
  _dos_settime(&treset);
  return 1;
}
//取服务器时间的相对时间(返回串,相对的天数[可正可负])
int sql_anyday(char *dest)
{
  DBCHAR  tmpdate[30];
  time_t timer;
  struct tm *tblock;
  int i;
  if(__syfs==0||dbproc==NULL||DBDEAD(dbproc)) //从本地取时间
  {
   timer = time(NULL);
   tblock = localtime(&timer);
   tblock->tm_mon++;
   if(tblock->tm_mday==1)  // 1号
    switch(tblock->tm_mon)
    {
     case  1:tblock->tm_year--;
             tblock->tm_mon=12;
	     tblock->tm_mday=31;
	     break;
     case  3:tblock->tm_mon=2;
	     tblock->tm_mday=29;
	     break;
     case  5:
     case  7:
     case  8:
     case 10:
     case 12:tblock->tm_mday=30;
	     tblock->tm_mon--;
	     break;
     case  2:
     case  4:
     case  6:
     case  9:
     case 11:tblock->tm_mday=31;
	     tblock->tm_mon--;
	     break;
    }
   else
    tblock->tm_mday--;
   sprintf(dest,"%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(dest);i++)
    if(dest[i]==' '&&i!=10)
     dest[i]='0';
  }
  else
  {
   dbfreebuf(dbproc);
   dbcmd(dbproc,"select convert(char(10),dateadd(dd,-1,getdate()),102)+' '+convert(char(8),getdate(),8)");
   dbsqlexec(dbproc);
   while((result_code=dbresults(dbproc))!=NO_MORE_RESULTS)
    if(result_code==SUCCEED)
    {
     dbbind(dbproc, 1, NTBSTRINGBIND, (DBINT) 0,tmpdate);
     while(dbnextrow(dbproc)!=NO_MORE_ROWS)
      strcpy(dest,tmpdate);
    }
    else break;
  }

⌨️ 快捷键说明

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