/*----- 公用函数文件 ALL_DBF.C ------*/
#define ALL_DBF
#include "all_dbf.h"
void lh_tjwk( char *bt, char *hlp, int fx, int fy, int ex, int ey )
{ struct viewporttype info;
getviewsettings(&info);
setviewport( (fx-1)*8, (fy-3)*18, (ex+1)*8, (ey+3)*18, 1 );
hlp_wk( "", bt, hlp, fx, fy, (ex-fx+2)*8-1, (ey-fy+6)*18-1 );
setviewport(info.left,info.top,info.right,info.bottom,1);
}
void tjwk_hlp( char *hlp, int fx, int ex, int ey )
{ power_prt( hlp, fx, ex, ey+2 );
}
long int tj_cx( int begin, int len, int gn_bz ) /* gn_bz = 0-顺序 1-快速 */
{
register i, old_hlp_bz;
int retu_code, jesc = 0, rec_len;
int fx = 20, fy = 12, ex = 39, ey = 15; /* 窗口高度 */
long int numb;
char tj[61];
void far *buff;
unsigned long size;
FILE *fp;
struct viewporttype info;
struct input word={
/* x y lengh colo b_colo lable string srbz*/
30, 13, 9, 15, 0, "查询条件 ", NULL, "B",
};
word.lengh = len;
if( (ex += len) < 45 ) ex = 45;
getviewsettings( &info );
setviewport( (fx-1)*8, (fy-3)*18, (ex+1)*8, (ey+3)*18, 1 );
size = imagesize( 0, 0, (ex-fx+2)*8-1, (ey-fy+6)*18-1 );
if((buff=(void far *)farmalloc(size))==NULL) error("内存不够 IN TJ_CX() !!");
getimage( 0, 0, (ex-fx+2)*8-1, (ey-fy+6)*18-1, buff );
hlp_wk( "", "查询条件", "ESC/返回 Enter/正确", fx, fy, (ex-fx+2)*8-1, (ey-fy+6)*18-1 );
setviewport( 0, 0, 639, 479, 1 );
word.string = (char *)malloc( (word.lengh+1)*sizeof(char) );
if( word.string == NULL ) error("内存不够 IN TJ_CX() !!");
strn_copy( word.string, cx_hlp, word.lengh );
put_string( word.lable, 0, 7, word.x-strlen(word.lable), word.y, 1 );
draw( (word.x+1)*8-1, word.y*18-1, (word.x+word.lengh+1)*8+1, (word.y+1)*18+1, 0 );
old_hlp_bz = hlp.bz;
hlp.bz = 0;
do
{ retu_code = lh_input( word );
switch( retu_code )
{ case CR:
for( i = 0; i < word.lengh; i++ ) if( word.string[i] == ' ' ) break;
if( !i ) { end( "条件未输入!", 1 ); continue; }
word.string[i] = 0;
if( gn_bz ) { if( (numb = seach(KM_CX_FILE, word.string, begin, i, -1)) != -1 ) jesc = 1; }
else /* 顺序查询 */
{ numb = 0;
fp = lh_use( (int *)&rec_len, KM_CX_FILE, 'r' );
fseek( fp, (long)begin+1l, SEEK_CUR );
while( fread(tj, sizeof(char)*len, 1, fp) != NULL )
{ if( !strncmp(tj, word.string, i) ) { jesc = 1; break; }
else numb++;
fseek( fp, (long)rec_len-len, SEEK_CUR );
}
fclose( fp );
}
if( !jesc )
{ end( "无此条件的记录!", 1 );
numb = -1;
}
break;
case ESC: jesc = 1; break;
}
} while( !jesc );
strcpy( cx_hlp, word.string );
free(word.string);
setviewport( (fx-1)*8, (fy-3)*18, (ex+1)*8, (ey+3)*18, 1 );
putimage( 0, 0, buff, COPY_PUT );
farfree(buff);
setviewport( info.left, info.top, info.right, info.bottom, 1 );
hlp.bz = old_hlp_bz;
if( retu_code == ESC ) return(-1);
else return( numb );
}
void move(int fx,int fy,int ex,int ey,int no,int colo,int move_fx)
{ union REGS reg;
if(move_fx==0) reg.h.ah=7; /* 向下滚动 */
else reg.h.ah=6;
reg.h.al=no;
reg.h.bh=colo;
reg.h.cl=fx;
reg.h.ch=fy;
reg.h.dl=ex-1;
reg.h.dh=ey;
int86(0x10,®,®);
}
void soud( void )
{ register i;
for( i = 0; i < 24400; i++ ) sound(1100); /* 延时 */
nosound();
}
int puthz16(int x,int y,int z,int color,char *p)
{ unsigned int i,c1,c2,f=0;
int i1,i2,i3,rec;
long l;
char by[32], text[2];
setcolor( color );
while( (i = *p++) != 0 )
{ if( i > 0xa1 ) if( !f )
{ c1 = (i-0xa1)&0x07f;
f = 1;
}
else
{ c2 = (i-0xa1) & 0x07f;
f = 0;
rec = c1*94+c2;
l = rec*32L;
lseek( handle, l, SEEK_SET );
read( handle, by, 32 );
for( i1 = 0; i1 < 16; i1++ )
for( i2 = 0; i2 < 2; i2++ )
for( i3 = 0; i3 < 8; i3++ )
if( (by[i1*2+i2] >> (7-i3)) & 1 ) putpixel(x+i2*8+i3,y+i1,color);
x = x+16+z;
}
else
{ text[0] = i; text[1] = 0;
outtextxy( x, y+4, text );
x = x+8+z;
}
}
return( x );
}
void put_string( char *s, int color, int b_color, int x, int y, int prt_bz )
{
textattr( color|b_color*16 );
if( prt_bz ) { gotoxy( x+1, y+1 ); cprintf( " " ); }
else gotoxy( x+2, y+1 );
cprintf( s );
}
void cursor(int x,int y,int bz)
{ register old_x,old_y;
void far *buff;
unsigned long size;
struct viewporttype info;
getviewsettings(&info);
if( bz == 3 ) { gotoxy(x+1, y ); return; }
if( bz == 1 || !bz )
{ old_x=wherex()*8-info.left-8;
old_y=wherey()*18-info.top;
size=imagesize(old_x,old_y-17,old_x+7,old_y-1);
if((buff=(void far *)farmalloc(size))==NULL) error("内存不够 IN CURSOR() !!");
getimage(old_x,old_y-17,old_x+7,old_y-1,buff);
putimage(old_x,old_y-17,buff,NOT_PUT);
farfree(buff);
}
if( bz == 1 || bz == 2 )
{ gotoxy(x+1,y);
old_x=x*8-info.left;
old_y=y*18-info.top;
size=imagesize(old_x,old_y-17,old_x+7,old_y-1);
if((buff=(void far *)farmalloc(size))==NULL) error("内存不够 IN CURSOR() !!");
getimage(old_x,old_y-17,old_x+7,old_y-1,buff);
putimage(old_x,old_y-17,buff,NOT_PUT);
farfree(buff);
}
}
void draw(int fx,int fy,int ex,int ey,int tu_o) /* tu_o: 0 - 凹 1 - 凸 */
{
tu_o = tu_o ? 0 : 15;
setcolor( tu_o );
rectangle(fx,fy,ex,ey);
tu_o = tu_o ? 0 : 15;
setcolor( tu_o );
line(fx,fy,fx,ey);
line(fx,fy,ex,fy);
}
FILE *use_check( char *filename, int r_bz )
{ int hand;
char use_error[61];
FILE *fp;
while( (hand = open(filename, r_bz == 'r' ? O_RDONLY|O_BINARY|O_DENYNONE : O_RDWR|O_BINARY|O_DENYALL)) == -1 )
if( errno == ENOENT )
{ strcpy( use_error, filename );
strcat( use_error, "找不到…" );
soud();soud();soud();
error( use_error );
}
while( (fp = fdopen(hand, r_bz == 'r' ? "rb" : "rb+")) == NULL );
return( fp );
}
FILE *lh_use( int *len, char *filename, int r_bz )
{ register i;
FILE *fp;
fp = use_check( filename, r_bz );
fseek( fp, 8l, SEEK_SET ); /* 定位于第八字节 */
i = fgetc( fp ) + 256*fgetc( fp ); /* 取结构描束长度 */
len[0] = fgetc( fp ) + 256*fgetc( fp ); /* 取记录长度 */
fseek( fp, (long)i, SEEK_SET ); /* 定位第一条记录 */
return( fp );
}
void lh_edit(char *DBF_NAME,char *record,long int N)
{ int i1,i2;
FILE *fp;
fp = use_check( DBF_NAME, 'w' );
fseek(fp,8l,SEEK_SET); /* 定位第八字节 */
i1=fgetc(fp)+256*fgetc(fp); /* 取结构描述长度 */
i2=fgetc(fp)+256*fgetc(fp); /* 取记录长度 */
fseek(fp,(long)i1+1l+(long)i2*N,SEEK_SET); /* 定位修改记录处 */
fputs(record,fp); /* 存修改记录 */
fclose(fp);
}
int lh_dbfnull(char *filename)
{ unsigned long i;
FILE *fp;
fp = use_check( filename, 'r' );
fseek(fp,4l,SEEK_SET); /* 定位于第八字节 */
fread(&i,sizeof(unsigned long),1,fp);
fclose(fp);
return( i );
}
long int rec_num(char *DBF_NAME)
{ FILE *fp;
unsigned long int i;
fp = use_check( DBF_NAME, 'r' );
fseek(fp,4l,SEEK_SET); /* 定位第四字节 */
fread(&i,sizeof(long),1,fp);
fclose(fp);
return(i);
}
void hlp_ts(char *string) /* 功能提示 */
{ power_prt( string, 1, 79, 24 );
}
void power_prt( char *string, int x, int ex, int y )
{ register i, xx;
int len, color = 0;
char p[2];
struct viewporttype info;
getviewsettings(&info);
setviewport( x*8, y*18, ex*8, (y+1)*18, 1 );
setfillstyle(1,7);
bar( 0, 0, (ex-x)*8-1, 17 ); /* 画帮助栏 */
len = strlen( string );
put_string( "[功能]", 0, 7, x, y, 0 );
for( i = 0, xx = 7; i < len;