#include <stdio.h>
#include <conio.h>
#include <bios.h>
#include <dos.h>
#include <malloc.h>
#define NULL 0
#define LEN sizeof(struct mcd)
struct data /*声明一个日期的结构体类型*/
{
int year;
int month;
int day;
};
struct mcd
{
int code;
char name[12];
long price;
int num;
char place[20];
struct data putdate;
struct data selldate;
struct mcd * next;
};
int n;
struct mcd *head;
creat()
{
struct mcd *p1,*p2;
n=0;
p1=p2=(struct mcd *)malloc(LEN);
head=p1;
loop: {
clrscr();
printf("shangpinluruxitong\n");
printf("luruhao:%d\n",n+1);
printf("bianma:");
scanf("%d",&p1->code);
printf("pinming:");
scanf("%s",&p1->name);
printf("danjia:");
scanf("%ld",&p1->price);
printf("shuliang:");
scanf("%d",&p1->num);
printf("chandi:");
scanf("%s",&p1->place);
printf("rukushijian:");
scanf("%d-%d-%d",&p1->putdate.year,&p1->putdate.month,&p1->putdate.day);
}
while(p1->num!=0)
{
n=n+1;
if(n==1)head=p1;
else p2->next=p1;
p2=p1;
p1=(struct mcd *)malloc(LEN);
goto loop;
}
p2->next=NULL;
main();
}
print()
{
int m=0;
struct mcd *p;
clrscr();
printf("bianhao||pinming||danjia||shuliang||chandi ||rukushijian\n");
p=head;
if(head!=NULL)
do
{
printf("%-10d%-14s%-12ld%-10d%-22s%-4d-%-2d-%-2d\n",p->code,p->name,p->price,p->num,p->place,p->putdate.year,p->putdate.month,p->putdate.day);
p=p->next;
m=m+1;
if(m%23==0){gotoxy(10,25);printf("anrenyijianjixu.");getch();}
}while(p!=NULL);
getch();
main();
}
sell()
{
int code,m=3,ch;
long sum=0;
struct mcd *p1;
struct date today;
getdate(&today);
clrscr();
printf("shangpinxiaoshouxitong\n");
printf("bianhao||||pinming||||chandi ||||danjia(yuan)||||chushoushijian\n");
loop:
do{
gotoxy(23,25);
printf("anrenyijianjixu,F2jiezhang,ESCjiantuichu");
ch=bioskey(0);
}while(0);
switch(ch)
{
case 15360:{
if(sum==0)
{
gotoxy(1,m);printf("haimeigoumeishangpin!");
getch();
sell();
break;
}
else {
gotoxy(1,m);
printf("------------------------------------------------------------------------------");
gotoxy(47,m+1);
printf("zongjia: %-12ldyuan",sum);
getch();
main();
break;
}
}
case 283:{main();break;}
default:
{
gotoxy(23,25);
printf("qingshueushangpinbianma,huixiangshishangpinxinxi");
gotoxy(1,m);
scanf("%d",&code);
if(head==NULL)
{
printf("nihaimeiyoujinhuo.");
getch();
main();
break;
}
p1=head;
while(code!=p1->code&&p1->next!=NULL)
{p1=p1->next;}
if(code==p1->code)
{
gotoxy(13,m);
printf("%-16s%-24s%-16ld%4d-%2d-%2d",p1->name,p1->place,p1->price,today.da_year,today.da_mon,today.da_day);
m=m+1;
p1->num=p1->num-1;
sum=sum+p1->price;
}
}
goto loop;
}
n=n+1;
print();
}
del()
{
int code;
struct mcd *p1,*p2;
clrscr();
printf("qingshuruyaoshanchushangpindebianhao:");
scanf("%d",&code);
if(head==NULL)
{
printf("nihaimeiyoujinhuo.");
getch();
main();
}
p1=head;
while(code!=p1->code&&p1->next!=NULL)
{
p2=p1;
p1=p1->next;
}
if(code==p1->code)
{
if(code==head)head=p1->next;
else p2->next=p1->next;
n=n-1;
print();
}
else
{
printf("zhaobudaozhetiaoshangpinxinxi.");
getch();
print();
}
}
main()
{
do{
clrscr();
printf(" . : : \n");
printf(" '. :'''''''': : : :'''':'''':\n");
printf(" '. : : :'''''' :'''''' : : :\n");
printf(" ................ : : :', :', ''''':''''': : :\n");
printf(" '. .' : : : ', : ', : :....:....:\n");
printf(" '. .' : : ,' ,' : : : :\n");
printf(" '.' : : ', : : : :\n");
printf(".........:........... :........: : ', : :....:....:\n");
printf(" ............... :''''''''''''''': '''':'''' : \n");
printf(" : , , : :'''''': :'''''': ,' : : \n");
printf(" : , , : : : : : :''''''''': : ,' : \n");
printf(" : , , : : : : : : : : ,' ....:.... \n");
printf(" :, :''''''': : : : : : : : :,' : \n");
printf(" : : : : : : : : :'''''''''' ,' : \n");
printf(" : : : : : : : : :.......... ,' : \n");
printf(" : :.......: : : : : : : : ' : \n");
printf(" : : : : : : : : ......:.....\n");
printf(" : ..: :......: :......: :.........: \n");
gotoxy(60,19);
printf("zhaofeiyuzhizhao V1.0");
gotoxy(10,21);
printf("1,xiaoshouxitong;2,jinhuoxitong;3,chakanliebiao;4,charushanchu;5,xiaoshouyingkui;6,bangzhuwendang");
gotoxy(32,24);
printf("anESCjiantuichu");
key();
}while(0);
}
key()
{
int ch;
loop:
do{
ch=bioskey(0);
}while(0);
switch(ch)
{
case 561:sell();break;
case 818:creat();break;
case 1075:print();break;
case 283:break;
default:
{
gotoxy(30,22);
printf("qinganshuzijianxuanzhe!");
goto loop;
}
}
}