📄 datamp.txt
字号:
/* 前台收银程序数据处理单元 */
#include <dos.h>
#include <bios.h>
#include <io.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
#include <math.h>
#include <fcntl.h>
#include <stdarg.h>
#include <memory.h>
#include <time.h>
#include <user.h>
#include <publ.h>
//fst
#include "fujistu.h"
#include "direct.h"
/* -------------------键盘输入处理函数----------------------*/
//把一个输入放入消息缓冲区
extern int MsgBoxEx(char *,int );
//
extern void InBuffer(int type,unsigned RetKey,int x,int y);
extern int sql_tm(_SPStruct *CurrSP,int Att);
extern int sql_insertspb(_SPStruct *rec,int lsh,char *time,
char *fkfs,double bx);
extern void dbf_insertspb(_SPStruct *rec,int lsh,char *time,
char *fkfs,double bx);
extern int sql_insertwqrb(_SPStruct *rec,int lsh,char *time,
char *fkfs,double bx);
extern int sql_insertyhk(YHK *yptr,char *time,double sps,
double ysje,double ssje);
extern int sql_insertthk(THK *yptr,char *time,double sps,
double ysje,double ssje);
extern int sql_insertxyk(char *km,char *kh,char *time,double je);
extern int sql_begin(void);
extern int sql_commit(void);
extern int sql_rollback(void);
extern int uf_strmid(char *dest,char *sour,int from,int count);
extern int uf_strmidEx(char *dest,char *sour);
extern int sql_yhk(YHK *rec);
extern int sql_thk(THK *rec);
extern void sql_thkclose(void);
extern int sql_checkthk(char *kh);
extern int InPutPassWord(char *PW);
extern int ShowTiHuoKa(THK *lpThk);//显示提货卡
extern int TiJiaoQueRen(int MaxLines,int Att);//显示销售凭证
extern int sql_xspz(char *_bc,int _lsh);
extern void DrawText(int x,int y,char *String,unsigned char Co,int MaxLine);
extern void __process(char *sour);
extern int sql_xykxx(void);
//lijing
extern TOption Param;
extern char g_customer[];
extern char g_VIPsw[];
extern char g_VIPyhl[];
extern int ShowTiHuoKaEx(THK *lpThk);
extern void ShowSyInf(void);
extern void rdxykfh(void);
extern int sql_insertgq(int xh,int gqbs,double ysje,double ssje);
extern int sql_removegq(int xh,int gqbs,double ysje,double ssje);
extern double uf_round(double num,double dig);
void Reset(_SPLists *lp);
//extern int g_hyxf;
//定义全局数据结构
//当前商品数据结构指针
_SPStruct OrigSP; //工作缓冲区
//商品销售数据集
_SPLists *SPLists;
short __WorkCount=1; //工作区数
short __WorkBuffer=8; //可以挂起的笔数
_GQStruct __GQList[8]; //挂起工作区
_SPLists __SPLists[1]; //
short _SPListCount=0; //当前挂起的笔数
short __guxianmark=0;
char __Preview[230][75];
//打印格式参数
int _nFormat=0;
int _nFormatx=0;
char p_Formats[31][61];
short _PortType=2; //打印端口类型
int _nFeedLine=5; //走纸行数
char _pFeedLine[65];
int _xsdws=0;
int _spmcws=15;
char _SpSplb[6][9]={"","","","","",""};
extern char g_now[11]; //时间
extern int g_lsh; //流水号
extern int g_xsbs; //销售笔数
extern int g_jycs;
extern double g_flhj[5]; //付款方式数组
extern char g_pos[]; //收银机类型
extern char g_scmc[];
extern char Syy_No[];
extern char g_bc[];
extern char g_gz_mode[];
extern char g_cashcode[];
extern int g_dyys;
extern char g_xyksy[];
extern CARDOUT xyk_fhxx;//zh
/*对销售商品数据的管理包含以下的功能
1-增加记录
2-删除记录
3-修改记录
4-移动记录
5-计算合计
6-保存数据到文件中
7-保存数据服务器
8-结帐管理
*/
//固显
//统计非空格字符串长度
int _StrlenEx(char *str)
{
int i,Result=0;
for(i=0;i<(int)strlen(str);i++)
if(str[i]!=' ') Result++;
return Result;
}
void Trim(char *s)
{
int i=0,j=0;
while(s[i])
{
if(s[i]!=' ')
s[j++] = s[i];
i++;
}
s[j] = '\0';
while(j>=0)
{
if(s[j]=='\0'||s[j]==' ')
s[j--] = '\0';
else
j = -1;
}
}
void LeftTrim(char *s,char c)
{
int l;
l = (int)strlen(s)-1;
while(l>=0&&(unsigned)s[l]<=32) s[l--]='\0';
l=l+1;
if(l>0)
{
s[l]=c;
s[l+1]='\0';
}
}
void FormatStr(char *str,int nlen) //格式化字符串
{
int i,nl,nBlank=0,j=0,k=0; //nBlank空格计数
char value[81];
nl=_StrlenEx(str); //不包括空格的字符串长度
nl=nlen-nl; //需要补的空格数
if(nl<=0) return;
for(i=0;i<(int)strlen(str);i++)
{
if(str[i]==' '&&k<nl)
while(k<nl) {value[j++]='~',k++;}
else value[j++]=str[i];
}
value[j]='\0';
strcpy(str,value);
}
//设置打印格式
int _Dyjg = 15;
void SetPrintFormat(void)
{
FILE *fp;
int i=1,k=0,c=32;
char value[4];
_nFormat = 0;
_nFormatx = 0;
fp = fopen(Param.ForFile,"r");
if(fp)
{
p_Formats[1][0]='\0';
while(c!=EOF&&_nFormat<=30)
{
c = fgetc(fp);
if(c==EOF||c=='\n')
{
p_Formats[i][k]='\0';
LeftTrim(p_Formats[i],'\n');
i++;
p_Formats[i][0]='\0';
_nFormat++;
_nFormatx++;
k = 0;
}
else p_Formats[i][k++]=(char)c;
}
fclose(fp);
}
//检查端口类型
uf_strmid(value,Param.Port,0,3);
if(strcmp(value,"COM")==0||strcmp(value,"LPT")==0||
strcmp(value,"PRN")==0)
_PortType = 0; //端口
else if(value[0]=='>')
{
_PortType = 1;
uf_strmid(value,Param.Port,1,4);
strcpy(Param.Port,value);
}
_nFeedLine = atoi(Param.PLine); //走纸行数
for(i=0;i<_nFeedLine;i++)
_pFeedLine[i]='\n';
_pFeedLine[i]='\0';
value[0] = Param.Slbhxs[0];
value[1] = '\0';
if(Param.Dyspbm[2]!='\0')
_spmcws=3+2*(Param.Dyspbm[2]-47);
_xsdws = atoi(value);
if(Param.Title[0]!='\0')
_Dyjg = atoi(Param.Title);
else
_Dyjg = 15;
for(i=0;i<8;i++)
__GQList[i].lsh = 0;
_SPListCount=0; //当前挂起的笔数
__guxianmark=0;
}
char _CustumDisp[2][31]={0};
void ShowGuXian(char *Caption,int Lines,int Att)
{
char valuex[51],value[121],value1[25];
int i,k;
__guxianmark=0;
switch(Att)
{
case 3:
case 0:if(Param.Gx[0]=='0'||Param.GxDisp[0]=='\0') return; //禁止顾显
__guxianmark=Att;
strcpy(valuex,Caption);
FormatStr(valuex,20); //补足~符号
switch(Param.Gx[0])
{
case '2':strcpy(_CustumDisp[Lines-1],valuex);
sprintf(value,"%s 1 %s %s",Param.GxDisp,
_CustumDisp[0],_CustumDisp[1]);
break;
case '9':if(Lines==2)
{
if(valuex[0]=='T') // 显示总计
Lines=2;
else Lines=4;
k=20;
while(k)
if(valuex[k]==' '||valuex[k]=='~')
{
k++;
break;
}
else k--;
for(i=k;i<=20;i++)
{
value1[i-k]=valuex[i];
if(value1[i-k]==':')
{
value1[i-k]='.';
Lines=3;
}
}
sprintf(value,Param.GxDisp,"COM",Lines,value1);
// printf("%s\n",value1);
}
else return;
break;
default: sprintf(value,Param.GxDisp,Lines,valuex);
break;
}
system(value);
break;
case 1:if(Param.Qx[0]=='0'||Param.QxOpen[0]=='\0') return; //禁止钱箱
system(Param.QxOpen);
break;
case 2:if(Param.Gx[0]=='0'||Param.GxInit[0]=='\0') return; //禁止固显
system(Param.GxInit);
break;
}
}
double GetRound(double value)
{
char buf[21];
sprintf(buf,"%.2f",value);
return atof(buf);
}
//设置小数位数
void GetDec(char *value,double dec,int ws,int Att)
{
char buf[21],_buf[21];
int k,mark=1;
if(ws<0) ws=_xsdws;
sprintf(buf,"%%%c.%df",Param.Dyspbm[4],(ws>3)? 3:ws);
sprintf(value,buf,dec);
if(ws>=4)
{
k = (int)strlen(value)-1;
value[k+1]='\0';
while(k>=0&&mark&&(value[k]=='0'||value[k]=='.'))
{
mark=value[k]!='.';
value[k--]='\0';
}
}
if(Att)
{
sprintf(buf,"%%%cs",Param.Dyspbm[4]);
sprintf(_buf,buf,value);
strcpy(value,_buf);
uf_strmid(buf,p_Formats[7],4,1);
if(buf[0]=='\n') buf[0]='\0';
strcat(value,buf);
}
// printf("%s\n",value);
}
//
void GetJE(char *value,double JE,char ws,char *_c,int Index)
{
int k;
char buf[21],buf2[11];
sprintf(buf,"%s%.2f",_c,JE);
k = ws-44+strlen(_c);
sprintf(buf2,"%%%ds",k);
sprintf(value,buf2,buf);
// printf("\n%s",value);
if(Index>=0)
{
uf_strmid(buf,p_Formats[7],Index,1);
strcat(value,buf);
}
}
//检查商品是否为联营
int CheckLysp(void)
{
int k;
if(!SPLists->RecordCount) return 0;
if(SPLists->RecNo>SPLists->RecordCount)
k = SPLists->RecordCount;
else
k = SPLists->RecNo;
switch(Param.Yxxgsj[0])
{
case '3':if(strcmp(SPLists->SPList[k].jyfs,"10")==0)
return 1;
break;
case '4':if(SPLists->SPList[k].sj==0)
return 1;
break;
case '5':if(strcmp(SPLists->SPList[k].jyfs,"10")==0||
SPLists->SPList[k].sj==0)
return 1;
break;
default:break;
}
return 0;
}
//初始化商品销售表,全部清为0
void InitCommodity(void)
{
SPLists->RecordCount=0;
SPLists->RecNo=0;
SPLists->spje=0;
SPLists->ysje=0;
InBuffer(-1,0x9904,1,0); // 产生显示金额的消息
}
//计算合计金额
void CalculateSum(void)
{
int i;
char value[31];
double Result=0,k=0,r,q,p,sl=0;
for(i=1;i<=SPLists->RecordCount;i++)
{
Result+=SPLists->SPList[i].je;
sl+=SPLists->SPList[i].sl;
if(Param.Sswr[0]=='3')
{
sprintf(value,"%.2f",SPLists->SPList[i].sjsj);
SPLists->SPList[i].sjsj = atof(value);
}
if(SPLists->SPList[i].state!=4)
r = SPLists->SPList[i].sjsj*SPLists->SPList[i].sl;
else
r = SPLists->SPList[i].ssje;
q = 0;
if(Param.Sswr[0]=='3')
{
p=10*r; //求整数部分
q=p-floor(p); //求小数部分
if(q>=0.5) q=1.0-q; //增加的付款分
else q=-q; //少收的钱
q=q/10; //转成分
r=r+q;
}
SPLists->SPList[i].sswr = q;
SPLists->SPList[i].ssje = r;
k+=SPLists->SPList[i].ssje;
}
SPLists->sl=sl;
SPLists->spje=Result;
//处理四舍五入
if(Param.Sswr[0]=='1'||Param.Sswr[0]=='2')
{
r=floor(10*k); //求整数部分
q=10*k-r; //求小数部分
if(q>=0.5) q=1.0-q; //增加的付款分
else q=-q; //少收的钱
q=q/10; //转成分
if(Param.Sswr[0]=='2')
SPLists->SPList[1].ssje+=q; //加到第一笔上
k+=q; //实收变化
}
sprintf(value,"%.2f",k);
SPLists->ysje=atof(value);
sprintf(value,"Total %.2f",SPLists->spje);
ShowGuXian(value,2,0);
}
//删除一条商品记录
void DeleteRecord(void)
{
int i;
if(Param.Yxscjl[0]=='0') return;
if(!SPLists->RecordCount||SPLists->RecNo>SPLists->RecordCount) return;
for(i=SPLists->RecNo+1;i<=SPLists->RecordCount;i++) //记录移动
{
SPLists->SPList[i].RecNo--;
memcpy(&(SPLists->SPList[i-1]),&(SPLists->SPList[i]),sizeof(_SPStruct));
}
SPLists->RecordCount--; //记录数减一
CalculateSum();//计算合计
InBuffer(-1,0x9904,1,0); //刷新数据显示
}
//
int CheckSpSplb(void)
{
int i,j;
for(i=0;i<6;i++)
{
if(_SpSplb[i][0]=='\0') return 0;
j = 0;
while(_SpSplb[i][j]&&OrigSP.splb[j])
{
if(_SpSplb[i][j]!=OrigSP.splb[j])
break;
j++;
}
if(_SpSplb[i][j]=='\0') return 1;
}
return 0;
}
//总是增加在最后
int InsertRecord(void)
{
int oldNo;
char value[41];
if(SPLists->RecordCount>=100)
{
MsgBoxEx("每次交易最大商品数不能大于100.",1);
return 0;//失败
}
if(!SPLists->RecNo) SPLists->RecNo=1; //如果无记录时
oldNo=SPLists->RecNo; //保存原来的记录号
OrigSP.RecNo=oldNo;
//检查是否能够修改售价及打折
OrigSP.bz = CheckSpSplb();
if(Param.Yxscjl[0]=='0'||(SPLists->RecNo<=SPLists->RecordCount&&
(!MsgBoxEx("覆盖当前的商品吗?",0))))
{
SPLists->RecNo=SPLists->RecordCount+1; //加在最后一条记录
OrigSP.RecNo=SPLists->RecNo;
InBuffer(-1,0x9904,3,SPLists->RecNo); //刷新数据显示
}
memcpy(&(SPLists->SPList[SPLists->RecNo]),&OrigSP,sizeof(_SPStruct));
sprintf(value,"%s %.2f",
SPLists->SPList[SPLists->RecNo].spbm,
SPLists->SPList[SPLists->RecNo].je);
ShowGuXian(value,1,0);
if(SPLists->RecNo>SPLists->RecordCount) //当前位置无数据,增加记录
SPLists->RecordCount++; //记录数加1
CalculateSum();//计算合计
InBuffer(-1,0x9904,3,oldNo);
//如果不是最后时,记录移动到最后
if(SPLists->RecNo<SPLists->RecordCount+1)
{
SPLists->RecNo=SPLists->RecordCount+1;
InBuffer(-1,0x9904,3,SPLists->RecNo); //刷新数据显示
}
}
//商品处理
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -