📄 inventory_project_2.c
字号:
gotopos(r+1,33);
cprintf("Name of the Item: %s",inv_stock.itemname);
gotopos(r+2,33);
cprintf("Price of each unit: %.2f"," ");
gotopos(r+2,33);
cprintf("Price of each unit: %.2f",inv_stock.itemrate);
gotopos(r+3,33);
cprintf("Quantity in Stock: %.4f"," ");
gotopos(r+3,33);
cprintf("Quantity in Stock: %.4f",inv_stock.itemqty);
gotopos(r+4,33);
cprintf("Reorder Level: %d"," ");
gotopos(r+4,33);
cprintf("Reorder Level: %d",inv_stock.minqty);
gotopos(r+5,33);
cprintf("\nPress Any Key...");fflush(stdin);getch();
textbackground(BROWN);
textcolor(BLUE);
return;
}
/*This function will return 0 if an item cannot issued, else issues the item*/
IssueItem()
{
float issueqnty;
DisplayItemInfo();
print2screen(15,33,"Enter Quantity: ",BROWN,BLUE,0);fflush(stdin);gotopos(15,49);
scanf("%f",&issueqnty);
/*If the stock of the item is greater than minimum stock*/
if((inv_stock.itemqty - issueqnty) >= inv_stock.minqty)
{
textcolor(BLUE);
textbackground(BROWN);
gotopos(18,33);
cprintf("%.4f Item(s) issued.",issueqnty);
gotopos(19,33);
cprintf("You should pay RS. %.2f",issueqnty*inv_stock.itemrate);getch();
textcolor(BLUE);
inv_stock.itemqty-=issueqnty; /*Updating quantity for the item in stock*/
fseek(dbfp,-stocksize,SEEK_CUR);
fwrite(&inv_stock,stocksize,1,dbfp);
return issueqnty;
}
/* If the stock of the item is less than minimum stock.ie Reorder level*/
else
{
messagebox(10,33,"Insufficient quantity in stock.","Insufficient Stock",' ',mboxbrdrclr,mboxbgclr,mboxfgclr,0);
gotopos(17,33);
textcolor(BLUE);
textbackground(BROWN);
cprintf("ONLY %.4f pieces of the Item can be issued.",inv_stock.itemqty-inv_stock.minqty);
gotopos(18,33);
cprintf("Press Any Key...");getch();
textcolor(BLUE);
textbackground(BROWN);
return 0;
}
}
/* Calculates the total investment amount for the stock available*/
float getInvestmentInfo(void)
{
tot_investment=0;
rewind(dbfp);
while(fread(&inv_stock,stocksize,1,dbfp)==1)
tot_investment+=(inv_stock.itemrate*inv_stock.itemqty);
return tot_investment;
}
/* Creates a backup file "Bakckup" of "inv_stock.dat"*/
BackupDatabase(void)
{
FILE *fback;
fback=fopen("d:/Backup.dat","w");
rewind(dbfp);
while(fread(&inv_stock,stocksize,1,dbfp)==1)
fwrite(&inv_stock,stocksize,1,fback);
fclose(fback);
return;
}
/*This structure is used color settings for the application*/
struct colors
{
char cfg_name[10];
int mboxbrdrclr;
int mboxbgclr;
int mboxfgclr;
int menutxtbgclr;
int menutxtfgclr;
int appframeclr;
int section1_symb;
int section1_bgclr;
int section1_fgclr;
int section2_symb;
int section2_bgclr;
int section2_fgclr;
}clr;
const long int clrsize=sizeof(clr);
/* Gets the display configuration for the application*/
getConfiguration()
{
FILE *flast;
flast=fopen("lastcfg","r+");
if(flast==NULL)
{
SetDefaultColor();
return 0;
}
rewind(flast);
/*Reads the first record.*/
fread(&clr,clrsize,1,flast);
#ifdef OKAY
if(strcmp(clr.cfg_name,"lastclr")!=0)
{
SetDefaultColor();
fclose(flast);
return 0;
}
#endif
mboxbrdrclr=clr.mboxbrdrclr;mboxbgclr=clr.mboxbgclr;mboxfgclr=clr.mboxfgclr;
menutxtbgclr=clr.menutxtbgclr;menutxtfgclr=clr.menutxtfgclr;appframeclr=clr.appframeclr;
section1_symb=clr.section1_symb;section1_bgclr=clr.section1_bgclr;section1_fgclr=clr.section1_fgclr;
section2_symb=clr.section2_symb;section2_bgclr=clr.section2_bgclr;section2_fgclr=clr.section2_fgclr;
fclose(flast);
return 1;
}
/* Sets the default color settings for the application*/
SetDefaultColor()
{
mboxbrdrclr=BLUE,mboxbgclr=GREEN,mboxfgclr=WHITE;
menutxtbgclr=BROWN,menutxtfgclr=BLUE,appframeclr=CYAN;
section1_symb=' ',section1_bgclr=BROWN,section1_fgclr=BLUE;
section2_symb=' ',section2_bgclr=BROWN,section2_fgclr=BLUE;
return 1;
}
/* Adds animation to a text */
BlinkText(const int r,const int c,char txt[],int bgclr,int fgclr,int BGCLR2,int FGCLR2,int blink,const int dly)
{
int len=strlen(txt);
BGCLR2=bgclr;FGCLR2=BLUE;
htskin(r,c,' ',len,bgclr,bgclr,0);
print2screen(r,c,txt,bgclr,fgclr,blink);
write2screen(r,c+animcounter+1,txt[animcounter],BGCLR2,FGCLR2,0);
write2screen(r,c+animcounter+2,txt[animcounter+1],BGCLR2,FGCLR2,0);
write2screen(r,c+animcounter+3,txt[animcounter+2],BGCLR2,FGCLR2,0);
write2screen(r,c+animcounter+4,txt[animcounter+3],BGCLR2,FGCLR2,0);
write2screen(r,c+animcounter+5,txt[animcounter+4],BGCLR2,FGCLR2,0);
write2screen(r,c+animcounter+6,txt[animcounter+5],BGCLR2,FGCLR2,0);
delay(dly*2);
write2screen(r,c+animcounter+1,txt[animcounter],bgclr,fgclr,0);
write2screen(r,c+animcounter+2,txt[animcounter+1],bgclr,fgclr,0);
write2screen(r,c+animcounter+3,txt[animcounter+2],bgclr,fgclr,0);
write2screen(r,c+animcounter+4,txt[animcounter+3],bgclr,fgclr,0);
write2screen(r,c+animcounter+5,txt[animcounter+4],bgclr,fgclr,0);
write2screen(r,c+animcounter+6,txt[animcounter+5],bgclr,fgclr,0);
animcounter+=1;
if(animcounter+5 >= len) animcounter=0;
return;
}
/* Displays a single charector with its attrribute*/
write2screen(int row,int col,char ch,int bg_color,int fg_color,int blink)
{
int attr;
char far *v;
char far *ptr=(char far*)0xB8000000;
if(blink!=0)
blink=128;
attr=bg_color+blink;
attr=attr<<4;
attr+=fg_color;
attr=attr|blink;
v=ptr+row*160+col*2; /*Calculates the video memory address corresponding to row & column*/
*v=ch;
v++;
*v=attr;
return 0;
}
/* Prints text with color attribute direct to the screen*/
print2screen(int row,int col,char string[],int bg_color,int fg_color,int blink)
{
int i=row,j=col,strno=0,len;
len=strlen(string);
while(j<80)
{
j++;
if(j==79)
{
j=0;
i+=1;
}
write2screen(i,j,string[strno],bg_color,fg_color,blink); /*See below function*/
strno+=1;
if(strno > len-1)
break;
}
return;
}
/* Prints text horizondally*/
htskin(int row,int column,char symb,int no,int bg_color,int fg_color,int blink)
{
int i;
for(i=0;i<no;i++)
write2screen(row,column++,symb,bg_color,fg_color,blink); /*Print one symbol*/
return;
}
/*Print text vertically*/
vtskin(int row,int column,char symb,int no,int bg_color,int fg_color,int blink)
{
int i;
for(i=0;i<no;i++)
write2screen(row++,column,symb,bg_color,fg_color,blink); /*Print one symbol*/
return;
}
/* Shows a message box*/
messagebox(int row,int column,char message[50],char heading[10],char symb,int borderclr,int bg_color,int fg_color,int blink)
{
int len;
char key,image[1000];
len=strlen(message);
capture_image(row,column,row+3,column+len+7,&image);
draw_mbox(row,column,row+3,column+len+7,symb,symb,borderclr,YELLOW,blink,borderclr,YELLOW,blink);
fillcolor(row+1,column+1,row+2,column+len+6,' ',bg_color,bg_color,0);
print2screen(row+1,column+2,message,bg_color,fg_color,blink);
print2screen(row+2,column+2,"Press Any Key... ",bg_color,fg_color,blink);
print2screen(row,column+1,heading,borderclr,fg_color,blink);
sound(400);
delay(200);
nosound();
fflush(stdin);
key=getch();
put_image(row,column,row+3,column+len+7,&image);
return key;
}
/* Fills color in a region*/
fillcolor(int top_row,int left_column,int bottom_row,int right_column,char symb,int bg_color,int fg_color,int blink)
{
int i,j;
for(i=top_row;i<=bottom_row;i++)
htskin(i,left_column,symb,right_column-left_column+1,bg_color,fg_color,blink);
return;
}
/* Prints a message box with an appropriate message*/
draw_mbox(int trow,int tcolumn,int brow,int bcolumn,char hsymb,char vsymb,int hbg_color,int hfg_color,int hblink,int vbg_color,int vfg_color,int vblink)
{
htskin(trow,tcolumn,hsymb,bcolumn-tcolumn,hbg_color,hfg_color,hblink);
htskin(brow,tcolumn,hsymb,bcolumn-tcolumn,hbg_color,hfg_color,hblink);
vtskin(trow,tcolumn,vsymb,brow-trow+1,vbg_color,vfg_color,vblink);
vtskin(trow,bcolumn,vsymb,brow-trow+1,vbg_color,vfg_color,vblink);
return;
}
/* Copies the txt mode image below the messagebox*/
capture_image(int toprow,int leftcolumn,int bottomrow,int rightcolumn,int *image)
{
char far *vidmem;
int i,j,count;
count=0;
for(i=toprow;i<=bottomrow;i++)
for(j=leftcolumn;j<=rightcolumn;j++)
{
vidmem=(char far*)0xB8000000+(i*160)+(j*2); /*Calculates the video memory address corresponding to row & column*/
image[count]=*vidmem;
image[count+1]=*(vidmem+1);
count+=2;
}
return;
}
/* Places an image on the screen*/
put_image(int toprow,int leftcolumn,int bottomrow,int rightcolumn,int image[])
{
char far *ptr=(char far*)0xB8000000;
char far *vid;
int i,j,count;
count=0;
for(i=toprow;i<=bottomrow;i++)
for(j=leftcolumn;j<=rightcolumn;j++)
{
vid=ptr+(i*160)+(j*2); /*Calculates the video memory address corresponding to row & column*/
*vid=image[count];
*(vid+1)=image[count+1];
count+=2;
}
return;
}
/* To move the curser position to derired position*/
gotopos(int r,int c)
{
union REGS i,o;
i.h.ah=2;
i.h.bh=0;
i.h.dh=r;
i.h.dl=c;
int86(16,&i,&o);
return 0;
}
union REGS i,o;
/* Initialize the mouse*/
initmouse()
{
i.x.ax=0;
int86(0x33,&i,&o);
return(o.x.ax);
}
/* Shows the mouse pointer*/
showmouseptr()
{
i.x.ax=1;
int86(0x33,&i,&o);
return;
}
/* Get the mouse position*/
getmousepos(int *button,int *x,int *y)
{
i.x.ax=3;
int86(0x33,&i,&o);
*button=o.x.bx;
*x=o.x.dx;
*y=o.x.cx;
return 0;
}
/* Restores the default text mode*/
setdefaultmode()
{
set25x80();
setdefaultcolor();
return;
}
/* Sets the default color and cursor of screen*/
setdefaultcolor()
{
int i;
char far *vidmem=(char far*)0xB8000000;
window(1,1,80,25);
clrscr();
for (i=1;i<4000;i+=2)
*(vidmem+i)=7;
_setcursortype(_NORMALCURSOR);
return;
}
/* Sets 25x80 Text mode*/
set25x80()
{
asm mov ax,0x0003;
asm int 0x10;
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -