#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include <conio.h>
#include <time.h>
#include <stddef.h>
#include <dos.h>
struct storeh{
char name[20]; /*存储仓库名*/
char ID[8]; /*存储仓库ID*/
long zrrNM; /*存储仓库责任人编号*/
struct date bt; /*责任人入库的时间*/
struct date rt; /*记录的时间*/
struct storeh * next; /*指向下一个信息节点*/
};
struct product{
int bn; /*记录该产品拿出仓库的次数*/
char productname[20]; /*产品名*/
long productid; /*产品编号*/
int amount; /*产品的数量*/
float price; /*产品的单价*/
float cost; /*总金额*/
int r_num; /*已出库总数目*/
struct date p_time; /*产品的入库日期*/
struct storeh * br; /*指向仓库信息*/
struct product * next;/*指向下一个产品*/
};
struct productsort{
char sort[5]; /*存储该分类号的名字*/
int b_num; /*该产品的数目*/
struct product * sd; /*指向产品信息链表*/
struct productsort * next; /*指向下一个分类信息节点*/
};
struct sortdata{
int s_num; /*产品中分类号的个数*/
int r_num; /*档案资料中仓库的个数*/
struct provide_pro_sh_data *readp; /*指向仓库档案文件链表*/
struct productsort * first; /*指向产品分类链表*/
};
struct provide_pro_sh_data{
int n; /*记录仓库提供产品的次数*/
char name[20]; /*存储提供产品仓库的名称*/
long zrrNM; /*存储提供产品仓库责任人编号*/
char ID[8]; /*存储提供产品仓库编号*/
struct provide_pro_sh_data *next; /*指向下一个仓库信息节点*/
};
struct top{
long num;
char name[20];
char sort[5];
int bn;
struct top *next;
};
char * file[]={ /*file菜单的选项*/
"Download",
"Inputnew",
"Filesave",
"Pro-stock",
"Withdraw"
};
char *mainmenu[]= { /*主菜单名*/
"Product", /*产品项目*/
"Storeh", /*仓库项目*/
"Search Product", /*查询产品*/
"Statistic", /*统计*/
"Withdraw", /*退出*/
};
char *product[]= { /*主菜单名*/
"Insert Product", /*新产品入库*/
"Modify Product", /*修改信息*/
"Delete Product", /*产品出库*/
"Withdraw",
};
char *sale[]={
"Sale", /*产品出库*/
"Store", /*销售记录*/
"Modify Data", /*修改仓库信息*/
"Withdraw",
};
char * search[]={ /*search菜单的选项*/
"All Sort",
"Sort Data",
"product",
"Storeh Data",
"Withdraw",
};
char * statistic[]={ /*count菜单的选项*/
"Amount",
"Value",
"Top10product",
"Top5storeh",
"Withdraw",
};
void showmenu(char **menu,int count,int sr,int sc);
int getchoice(char **menu,char *hotkeys,int r,int c,int count);
int t();
void readfile(struct sortdata *,FILE*); /*打开文件*/
void create(struct sortdata *); /* 新建文件*/
void writefile(struct sortdata *,FILE*); /* 保存文件*/
void insert_pro (struct sortdata *); /*新产品入库*/
void modify_pro (struct sortdata *); /*修改产品信息*/
void del_pro (struct sortdata *); /*产品出库*/
void insert_sh (struct sortdata *); /*销售产品*/
void del_sh (struct sortdata *); /*记录*/
void modify_sh (struct sortdata *); /*修改仓库信息*/
void sch_as (struct sortdata *); /*显示所有大类*/
void sch_s (struct sortdata *); /*查找指定大类*/
void sch_b (struct sortdata *); /*查找产品信息*/
void sch_r (struct sortdata *); /*查找仓库信息*/
void b_data (struct sortdata *); /*数量统计*/
void value (struct sortdata *); /*价格统计*/
void top10_pro (struct sortdata *); /*排名前十的产品*/
void top5_sh (struct sortdata *); /*排名前五的仓库*/
int difday (struct date*,struct date*);
void sortchain (struct top *);
struct date t;
struct sortdata head;
struct productsort *p1;
struct product *p2;
struct storeh *p3;
struct provide_pro_sh_data *rp,*p4;
FILE * fp;
char c,filename[13];
void main()
{
int ch,ch0,ch1,ch2,ch3,ch4,ch5,on_off=1;
char c;
textbackground(GREEN);
clrscr();
while(on_off)
{
inf:
showmenu(file,5,10,35);
ch=getchoice(file,"LNSEQ",10,35,5);
switch(ch)
{
case 1:
textbackground(GREEN);
clrscr();
gotoxy(25,10);
cprintf("Input the file name:");
scanf("%s",filename);
if((fp=fopen(filename,"rb"))==NULL)
{
clrscr( );
gotoxy(25,10);
cprintf("The file %s is not exist!",filename); /*所要打开的文件不存在*/
gotoxy(25,11);
cprintf("Please press any key to continue...");
getch();
clrscr( );
gotoxy(25,9);
cprintf("**************************");
gotoxy(25,10);
cprintf("* Create the file?(y/n) *");
gotoxy(25,11);
cprintf("**************************");
gotoxy(48,10);
while(isspace(c=getchar()));
if(c=='y'||c=='Y') goto innew;
if(c=='N'||c=='n') goto inf;
clrscr( );
break;
}
clrscr();
fread(&head,sizeof(struct sortdata),1,fp); /*所要打开的文件存在*/
head.first=NULL;
head.readp=NULL;
readfile(&head,fp); /*file菜单中的download选项*/
fclose(fp);
clrscr( );
goto inf;
case 2:
clrscr( );
gotoxy(25,9);
cprintf("******************************");
gotoxy(25,10);
cprintf("* Input the new file name: *");
gotoxy(25,11);
cprintf("******************************");
gotoxy(51,10);
scanf("%s",filename);
innew:
head.s_num=0;
head.r_num=0;
head.readp=NULL;
head.first=NULL;
create(&head); /* file菜单中的new选项*/
clrscr( );
goto inf;
case 3:
clrscr();
if((fp=fopen(filename,"wb"))==NULL)
{
gotoxy(25,10);
cprintf("error:can't create file!");
gotoxy(25,11);
cprintf("Please press any key to continue...");
getch();
goto inf;
}