dt930仓库盘点源代码,编译可用
#include <stdio.h>
#include <string.h>
#include <math.h>
#include "itron.h"
#include "cmndef.h"
#include "bios1mac.h"
void ShowLogo( void );
void MainMenu(void);
void FNC_Init( void ); /* 1996.11.12 casio */
void Pd_input(char *filename,int type);
void SaveToFile(H file,B *barcode,B *number);
int ReadFromFile(H file,B *barcode);
int ReCreateFile(char *filename);
int Input_FileName(char *filename,int type);
unsigned char pd_file_in[11]="rk.txt";
unsigned char pd_file_cj[11]="cj.txt";
unsigned char pd_file_out[11];
/* 定义的功能键值*/
#define KEY_BS 8
#define KEY_CLR 12
#define KEY_ENT 13
#define MAX_BAR_LEN 20 /*条码长度*/
#define LineLen 28 /*每行文本记录字节数量*/
#define MAX_NUM_LEN 5 /*数量字符长度*/
#define split ","
#define line_end "\r\n"
/*LineLen=MAX_BAR_LEN + 1 + MAX_NUM_LEN + 2
unsigned char data[33];
0-19:条码 20:分隔符 21-25:数量 26-27
20字节 1字节 5字节 2字节 合计:28字节,*/
/*******************************************************************************/
void ap_start( void )
{
Wait2( 5L );
s_sound( 2250, 5 );
Wait2( 5L );
s_sound( 2250, 5 );
FNC_Init();
lcd_cls(); /* screen clear 1996.11.26.casio */
obr_change( 0 ); /* obr_change( OBR_ALL ) */
while(1)
{
ShowLogo(); /* display opening message */
if (getkey()==KEY_BS) break;
MainMenu();
}
exit( 0 ); /* application end */
}
/*******************************************************************************/
void FNC_Init( void )
{
KEYFORM kcode;
kcode.attr = 0x0;
kcode.code = 0x2d;
key_fnc( FNC_SET, FNC_1, &kcode);
kcode.attr = 0x0;
kcode.code = 0x1d;
key_fnc( FNC_SET, FNC_2, &kcode);
kcode.attr = 0x0;
kcode.code = 0x1c;
key_fnc( FNC_SET, FNC_3, &kcode);
kcode.attr = 0x0;
kcode.code = 0x10;
key_fnc( FNC_SET, FNC_4, &kcode);
kcode.attr = 0x0;
kcode.code = 0x20;
key_fnc( FNC_SET, FNC_5, &kcode);
kcode.attr = 0xff;
kcode.code = 0x0;
key_fnc( FNC_SET, FNC_6, &kcode);
kcode.attr = 0xff;
kcode.code = 0x1;
key_fnc( FNC_SET, FNC_7, &kcode);
kcode.attr = 0xff;
kcode.code = 0x02;
key_fnc( FNC_SET, FNC_8, &kcode);
}
/*******************************************************************************/
void ShowLogo( void )
{
unsigned char msg[][25]={
"欢迎使用",
"==温州新壹加壹软件==",
" 条码采集系统 V1.0",
" ",
" 2011 BY YJY"};
short cnt, x, y;
DAT_DSP_STR disp_set;
dat_system( SYSD_FNC_READ, SYSD_DSP, &disp_set );
disp_set.font_md = FONT6_SET;
dat_system( SYSD_FNC_WRITE, SYSD_DSP, &disp_set );
lcd_cls();
for( x=0,y=1,cnt=0; cnt<5; y+=2,cnt++ )
{
lcd_csr_put( y, x );
cputstr(LCD_ATTR_NORMAL,msg[cnt]);
}
}
int Input_FileName(char *filename,int type)
{
int i;
char str[11];
while(1)
{
lcd_cls();
Display("******客户编码******:",0,1,0);
Display(" (最长 7位字符)",0,3,0);
Display("编号: ",0,5,0);
if (type==1)
Display("发货出库操作中...",0,9,0);
if (type==3)
Display("按 ENT:上传入库数据",0,9,0);
if (type==4)
Display("按 ENT:清除入库文件",0,9,0);
memset(str,0x0,11);
i=read_str(0,7,0,str,11);
if(i==E_KEY_CLR) return i;
if( strlen(str)>7 )
{
SoundError();
continue;
}
if( (strlen(str)<8) && (strlen(str)>0) )
{
strcat(str,".csv");
strcpy(filename,str);
break;
}
if( (strlen(str)==0) && (i==0) && ((type==3) || (type==4)) )
{
strcpy(filename,pd_file_in);
break;
}
}
return i;
}
/*******************************************************************************/
void MainMenu()
{
short code;
int i;
int file;
char filename[20],str[MAX_BAR_LEN];
while (1)
{
key_clear();
lcd_cls();
/*
for( x=0,y=1,cnt=0; cnt<5; y+=2,cnt++ )
{
{
lcd_csr_put( y, x );
cputstr(LCD_ATTR_NORMAL,msg[cnt]);
}
}*/
Display("**温州新壹加壹软件**",0,1,0);
Display(" 1.数据采集",0,3,0);
Display(" 2.数据上传",0,5,0);
Display(" 3.删除数据",0,7,0);
code=getkey();
if(code==E_KEY_CLR)break;/*检测到推出按键*/
if(code >= '1' && code <= '3')
code -= 0x30;
switch (code)
{
case 1:
Pd_input(pd_file_cj,3);
break;
case 2:
{
i=Sendfile(pd_file_cj);
if (i==0)
{
lcd_cls();
Display("是否需要清理数据?",0,1,0);
Display(" 1.保留数据 ",0,3,0);
Display(" 2.清理数据",0,5,0);
if (getkey()=='2')
{
ReCreateFile(pd_file_cj);
lcd_cls();
Display(" 数据清理完成! ",0,3,0);
Display(" 任意键返回....",0,7,0);
Sound();
getkey();
}
}
}
break;
case 3:
{
lcd_cls();
Display("是否需要清理数据?",0,1,0);
Display(" 1.保留数据文件 ",0,3,0);
Display(" 2.删除数据文件",0,5,0);
if (getkey()=='2')
{
ReCreateFile(pd_file_cj);
lcd_cls();
Display("数据文件已经删除!",0,3,0);
Display(" 任意键返回 ....",0,7,0);
Sound();
getkey();
}
}
break;
case 6:
memset(filename,0x0,20);
while(Input_FileName(filename,1)!=E_KEY_CLR)
{
if( strlen(filename)>4)
{
Pd_input(filename,1);
break;
}
else
{
if( Input_FileName(filename,1)==E_KEY_CLR ) break;
SoundError();
}
}
break;
case 7:
Pd_input(pd_file_in,2);
break;
default:
break;/*这个break 只是跳出SWITCH 并未跳出while*/
}
}/*while end */
}
int ReCreateFile(char *filename)
{
int file;
char bar[MAX_BAR_LEN]="条码 ";
char num[MAX_NUM_LEN]="数量 ";
dat_fdel(filename);
file=open(filename,O_CREAT|O_RDWR);
if( file==E_LOWERR)
{
lcd_cls();
Display("文件创建错误! ",0,3,0);
SoundError();
getkey();
return 1;
}
lseek(file,0,0);
FormatLen(bar,MAX_BAR_LEN);
write(file,bar,MAX_BAR_LEN);
write(file,split,1);
FormatLen(num,MAX_NUM_LEN);
write(file,num,MAX_NUM_LEN);
write(file,line_end,2);
close(file);
return 0;
}
/*******************************************************************************/
void Pd_input(char *filename,int type)
{
char str[MAX_BAR_LEN+1],bar[MAX_BAR_LEN+1],oldbar[MAX_BAR_LEN+1],num[MAX_NUM_LEN+1];
int ret,number;
int file;
int old_num,sum_num;
int key;
str[0]=0x0;
number=1;
old_num=0;
file=open(filename,O_RDWR);
if( file==E_LOWERR )
{
if (ReCreateFile(filename)==0)
file=open(filename,O_RDWR);
}
if ( file==E_LOWERR)
{
lcd_cls();
if (type==3)
Display("------数据采集------",0,1,0);
if (type==2)
Display("----入库数据采集----",0,1,0);
if (type==1)
Display("----发货数据采集----",0,1,0);
Display("文件:",0,3,0);
Display(filename,7,3,0);
Display("打开错误!",0,5,0);
SoundError();
getkey();
return;
}
memset(bar,0x0,MAX_BAR_LEN);
memset(oldbar,0x0,MAX_BAR_LEN);
while(1)
{
lcd_cls();
sum_num=0;
sum_num=ReadFromFileSum(file);
Display("------数据采集------",0,1,0);
Display("条码:",0,3,0);
/*Display(oldbar,0,5,0);*/
sprintf(str,"数量:%d,总数:%d",old_num,sum_num);
Display(str,0,9,0);
/*memset(bar,0x0,MAX_BAR_LEN);*/
sprintf(bar,"%s",oldbar);
ret=read_str(0,5,0,bar,MAX_BAR_LEN);/*读取条码,最长20位,回显关闭状态*/
if(ret==E_KEY_CLR) break;
if (strlen(bar)==0) continue;
FormatLen(bar,MAX_BAR_LEN);
sprintf(oldbar,"%s",bar);
number=1;
old_num=ReadFromFile(file,bar);
old_num=old_num+number;
memset(str,0x0,MAX_BAR_LEN);
sprintf(str,"%d",old_num);
FormatLen(str,MAX_NUM_LEN);
SaveToFile(file,bar,str);
}
close(file);
}
int ReadFromFile(H file,B *barcode)
{
B *str;
ER err = 0;
int count=0;
char bar[MAX_BAR_LEN+1],split2[2],num[MAX_NUM_LEN+1],end[3];
err = lseek(file, LineLen, 0);
while(1)
{
err = read(file,bar,MAX_BAR_LEN);
if((err==E_LOWERR) || (err<20))
break;
FormatLen(bar,MAX_BAR_LEN);
err = read(file,split2,1);
split2[1]=0x0;
err = read(file,num,MAX_NUM_LEN);
num[MAX_NUM_LEN]=0x0;
err = read(file,end,2);
end[2]=0x0;
if (strcmp(bar,barcode)==0)
{
TrimRight(num,5);
count=atoi(num);
err = lseek(file, -LineLen, 1);
break;
}
}
return count;
}
int CheckRepeat(H file,B *barcode)
{
B *str;
ER err = 0;
int result=0;
char bar[MAX_BAR_LEN+1],split2[2],num[MAX_NUM_LEN+1],end[3];
err = lseek(file, LineLen, 0);
while(1)
{
err = read(file,bar,MAX_BAR_LEN);
if((err==E_LOWERR) || (err<20))
break;
FormatLen(bar,MAX_BAR_LEN);
err = read(file,split2,1);
split2[1]=0x0;
err = read(file,num,MAX_NUM_LEN);
num[MAX_NUM_LEN]=0x0;
err = read(file,end,2);
end[2]=0x0;
if (strcmp(bar,barcode)==0)
{
result=1;
err = lseek(file, -LineLen, 1);
break;
}
}
return result;
}
int ReadFromFileSum(H file)
{
B *str;
ER err = 0;
int count=0,sum=0;
char bar[MAX_BAR_LEN+1],split2[2],num[MAX_NUM_LEN+1],end[3];
err = lseek(file, LineLen, 0);
while(1)
{
err = read(file,bar,MAX_BAR_LEN);
if((err==E_LOWERR) || (err<20))
break;
bar[MAX_BAR_LEN]=0x0;
err = read(file,split2,1);
split2[1]=0x0;
err = read(file,num,MAX_NUM_LEN);
num[MAX_NUM_LEN]=0x0;
TrimRight(num,5);
count=atoi(num);
sum=sum+count;
err = read(file,end,2);
end[2]=0x0;
}
return sum;
}
void SaveToFile(H file,B *barcode,B *number)
{
write(file,barcode,MAX_BAR_LEN);
write(file,split,1);
write(file,number,MAX_NUM_LEN);
write(file,line_end,2);
}