/*头文件*/
#include <stdio.h>
#include <conio.h>
#include <ctype.h>
#include <string.h>
#include <dos.h>
#include <math.h>
#include <time.h>
#include <stdlib.h>
#include <bios.h>
/*所有函数声明*/
int t();
void design();
void show_mouse();
void entry();
void ventry(char t[],int);
void search();
void search_date();
void search_name();
void display();
void del();
void deletion_name();
void deletion_date();
int delete_file();
void graph();
void graph1();
void graph2();
void bar1(int inscor1);
void bar2(int inscore2);
struct shop
{
char name[20];
int quantity;
float sale;
char id[10];
float total;
};
struct shop temp;
struct shop x[20];
FILE *ptr;
char a[10];
/*显示当前时间函数*/
int t(void)
{
time_t t;
time(&t);
gotoxy(24,21);
printf("Date: %s\n", ctime(&t));
return 0;
}
/*显示光标位置函数*/
void show_mouse(void)
{
union REGS in, out;
in.x.ax = 0x1;
int86(0x33, &in, &out);
}
/*程序框架函数*/
void design()
{
int i;
clrscr();
textcolor(14);
gotoxy(2,2);
cprintf("\xC9");
gotoxy(3,2);
for(i=1;i<=74;i++)
cprintf("\xCD");
gotoxy(77,2);
cprintf("\xBB");
gotoxy(2,3);
cprintf("\xBA");gotoxy(2,4);cprintf("\xBA");gotoxy(2,5);cprintf("\xBA");
gotoxy(2,6);cprintf("\xBA");gotoxy(2,7);cprintf("\xBA");gotoxy(2,8);cprintf("\xBA");
gotoxy(2,9);cprintf("\xBA");gotoxy(2,10);cprintf("\xBA");gotoxy(2,11);cprintf("\xBA");gotoxy(2,12);cprintf("\xBA");
gotoxy(2,13);cprintf("\xBA");gotoxy(2,14);cprintf("\xBA");gotoxy(2,15);cprintf("\xBA");gotoxy(2,16);cprintf("\xBA");
gotoxy(2,17);cprintf("\xBA");gotoxy(2,18);cprintf("\xBA");gotoxy(2,22);cprintf("\xCC");
gotoxy(2,19);cprintf("\xBA");gotoxy(2,20);cprintf("\xBA");gotoxy(2,21);cprintf("\xBA");gotoxy(2,24);cprintf("\xC8");
gotoxy(2,23);cprintf("\xBA");
gotoxy(3,24);
for(i=1;i<=74;i++)
cprintf("\xCD");
gotoxy(77,18);cprintf("\xBA");gotoxy(77,19);cprintf("\xBA");gotoxy(77,20);cprintf("\xBA");gotoxy(77,21);cprintf("\xBA");gotoxy(77,24);cprintf("\xBC");
gotoxy(77,23);
cprintf("\xBA");
gotoxy(3,22);
for(i=1;i<=74;i++)
cprintf("\xCD");
gotoxy(77,22);
cprintf("\xB9");
gotoxy(77,3);
cprintf("\xBA");gotoxy(77,4);cprintf("\xBA");gotoxy(77,5);cprintf("\xBA");
gotoxy(77,6);cprintf("\xBA");gotoxy(77,7);cprintf("\xBA");gotoxy(77,8);cprintf("\xBA");
gotoxy(77,9);cprintf("\xBA");gotoxy(77,10);cprintf("\xBA");gotoxy(77,11);cprintf("\xBA");gotoxy(77,12);cprintf("\xBA");
gotoxy(77,13);cprintf("\xBA");gotoxy(77,14);cprintf("\xBA");gotoxy(77,15);cprintf("\xBA");gotoxy(77,16);cprintf("\xBA");
gotoxy(77,17);cprintf("\xBA");
textcolor(4);
}
/*=================把接受的字符串类型转换整型或浮点型=================*/
void ventry(char t[],int code)
{
int i=0;
if(code==0)
{
while((t[i]=getch())!='\r' && i<30)
if((t[i]>=97 && t[i]<=122) || (t[i]>=65 && t[i]<=90) || t[i]==32 || t[i]==8)
{ printf("%c",t[i]);
i++;
}
}
else if(code==1)
{
while((t[i]=getch())!='\r' && i<10)
if((t[i]>=48 && t[i]<=57) || t[i]==46 || t[i]==8 )
{ printf("%c",t[i]);
i++;
}
}
t[i]='\0';
}
/*============1.增加记录函数===================*/
void entry()
{
char ch;
clrscr();
ptr=fopen("shop.dat","a+b");/*运行程序时就建立shop.dat文件*/
ch='y';
while(ch=='y')
{
clrscr();
design();
textcolor(14);
t();
gotoxy(14,3);
cprintf("\xDB\xDB\xDB\xDB\xDB\xB2 Product Infomation \xB2\xDB\xDB\xDB\xDB\xDB ");
{
gotoxy(7,5);
cprintf("\xDB\xDB\xB2 Enter Date: ");
ventry(temp.id,1);
flushall();
gotoxy(7,8);
cprintf("\xDB\xDB\xB2 Enter Name: ");
ventry(temp.name,0);
flushall();
gotoxy(7,11);
cprintf("\xDB\xDB\xB2 Enter Price(RMB): ");
ventry(a,1);
temp.sale= atof(a);
flushall();
gotoxy(7,14);
cprintf("\xDB\xDB\xB2 Enter Quantity: ");
ventry(a,1);
temp.quantity= atoi(a);
flushall();
gotoxy(7,16);
cprintf("=====================================");
temp.total=temp.quantity*temp.sale;
textcolor(10);
gotoxy(10,18);
cprintf("\xB2\xDB\xB2 Total Money = %.2f RMB",temp.total);
}
fwrite(&temp,sizeof(temp),1,ptr);
textcolor(10);
gotoxy(10,23);
cprintf("More entries [Y/N]");
ch=getche();
}
fclose(ptr);
}
/*===================2.查找主函数================*/
void search()
{
int sh;
clrscr();
design();
gotoxy(17,6);
printf("\xDB\xDB\xB2 Two options available to search \xB2\xDB\xDB");
gotoxy(15,9);
printf("[ 1 ] - Search by Date.");
gotoxy(15,11);
printf("[ 2 ] - Search by Name.");
gotoxy(17,15);
printf("Enter your choice:");
sh=toupper(getch());
switch(sh)
{
case '1':
search_date();
break;
case '2':
search_name();
break;
default:
gotoxy(18,18);
printf("\a\xDB\xDB Please try again");
getch();
}
getche();
}
/*=================2_1按日期查找=====================*/
void search_date()
{
int flag=0;
char lkf[20];
clrscr();
ptr=fopen("shop.dat","rb");
design();
gotoxy(13,4);
printf("\xDB\xDB\xB2 Enter date to be searched:");
scanf("%s",&lkf);
while((!flag)&&(fread(&temp,sizeof(temp),1,ptr))==1)
{
if(strcmp(temp.id,lkf)==0)
flag=1;
}
if(flag)
{
gotoxy(18,6);
printf("Date :%s",temp.id);
gotoxy(18,9);
printf("Name :%s",temp.name);
gotoxy(18,12);
printf("Price :%.2f",temp.sale);
gotoxy(18,15);
printf("Quantity:%d",temp.quantity);
gotoxy(16,17);
printf("============================");
gotoxy(18,19);
printf(" Total :%.2f",temp.total);
}
else
printf("Record not found!");
fclose(ptr);
}
/*==============2_2按名字查找==================*/
void search_name()
{
int flag=0;
char lkf[20];
clrscr();
ptr=fopen("shop.dat","rb");
design();
gotoxy(13,4);
printf("\xDB\xDB\xB2 Enter name to be searched:");
scanf("%s",&lkf);
while((!flag)&&(fread(&temp,sizeof(temp),1,ptr))==1)
{
if(strcmp(temp.name,lkf)==0)
flag=1;
}
if(flag)
{
gotoxy(18,6);
printf("Date :%s",temp.id);
gotoxy(18,9);
printf("Name :%s",temp.name);
gotoxy(18,12);
printf("Price :%.2f",temp.sale);
gotoxy(18,15);
printf("Quantity:%d",temp.quantity);
gotoxy(16,17);
printf("============================");
gotoxy(18,19);
printf(" Total :%.2f",temp.total);
}
else
printf("Record not found!");
fclose(ptr);
}
/*=================3.显示记录函数======================*/
void display()
{
char ch;
clrscr();
design();
gotoxy(20,23);
printf("Press Enter to go to Main Menu");
textcolor(GREEN);
gotoxy(25,4);
cprintf("\xDB\xDB\xDB\xDB\xDB\xB2 Display the Records \xB2\xDB\xDB\xDB\xDB\xDB");
textcolor(RED);
gotoxy(4,7);
cprintf(" Date Name Price Quantity Total");
gotoxy(4,9);
printf("========================================================================");
ptr=fopen("shop.dat","rb");
while((fread(&temp,sizeof(temp),1,ptr))==1)
{
printf("\n \xBA %s",temp.id);
printf("\t%10s",temp.name);
printf("\t%.2f",temp.sale);
printf("\t\t%d",temp.quantity);
printf("\t%.2f\n",temp.total);
}
getche();
}
/*====================4.删除主函数====================*/
void del()
{
int sh;
clrscr();
design();
gotoxy(17,6);
printf("\xDB\xDB\xB2 Two options available to delete \xB2\xDB\xDB");
gotoxy(16,9);
printf("[ 1 ] -Delete by Date");
gotoxy(16,11);
printf("[ 2 ] -Delete by Name");
gotoxy(18,15);
printf("Enter your choice:");
sh=toupper(getch());
switch(sh)
{
case '1':
deletion_date();
break;
case '2':
d