inttm_mday;
};
*定义设备结构体*
#endif
structequipment{
intID;
charname[20];
}e[10];
*定义部门结构体*
structdepartment{
intnum;
charname[20];
}d[4];
*购买和报废信息结构体*
structinformation{
intID;*设备名称*
intnum;*部门编号*
chardate[11];*购买日期*
chardate1[11];*报废日期*
intstyle;*设备类型*
doubleprice;*单价*
intnumber;*购买数量*
intnumber1;*报废数量*
doublesum;*总价*
structinformation*next;
};
*函数的声明*
voidload(structinformation*_menu();*主菜单*
voidmenu_select(intsel,structinformation**(structinformation***(structinformation*(structinformation**_menu(structinformation**scanf_add(structinformation*();*显示购买和报废设备信息记录*
voidshow_menu(structinformation***(_menu(");
printf("*********谢谢使用!
**********\n");
****\n");
printf("****XXX****\n");
exit(0);
}
}
*显示主菜单界面*
intmain_menu()
{
inti;
printf("\1**********欢迎使用设备管理系统********************\1\n");
printf("\1***1.查询设备信息***\1\n");
printf("\1***2.查询部门信息***\1\n");
printf("\1***3.购买设备***\1\n");
printf("\1***4.报废设备***\1\n");
printf("\1***5.设备的购买历史查询***\1\n");
printf("\1***6.设备的报废历史查询***\1\n");
printf("\1***7.剩余使用次数***\1\n");
printf("\1***8.显示全部信息***\1\n");
printf("\1***9.设备信息报表***\1\n");
printf("\1***0.退出菜单***\1\n");
printf("\1**************************************************\1\n");
while
(1)
{
printf("请选择你所需要的操作序号(0~9):
");
do{
scanf("%d",&i);
if(i<0||i>9)
printf("输入有误,请重新输入(0~9):
");
rewind(stdin);
}while(i<0||i>9);
system("cls");
break;
}
returni;
}
*读取显示设备信息*
voidload_equipment()
{
FILE*fp;
structequipment*pt1=e;
system("cls");
if((fp=fopen("设备名称.txt","r"))==NULL)
{
printf("打开错误!
\n");
exit(0);
}
printf("**********************************设备信息界面*******************************");
printf("\n\t设备编号(1~10)设备名\n");
while(!
feof(fp))
{
fscanf(fp,"%d%s",&pt1->ID,&pt1->name);
printf("\n\t\t%d\t\t%s",pt1->ID,pt1->name);
pt1++;
}
if(fclose(fp))
{
printf("不能关闭文件!
!
!
\n");
exit(0);
}
printf("\n\n********************************导入成功*********************************\n");
printf("\n按Enter键返回");
getchar();
system("cls");
}
*读取显示部门信息*
voidload_department()
{
FILE*fp;
structdepartment*pt1=d;
system("cls");
if((fp=fopen("部门名称.txt","r"))==NULL)
{
printf("打开错误!
\n");
exit(0);
}
printf("*********************************部门信息界面**************************");
printf("\n\t\t部门编号(1~4)部门名称\n");
while(!
feof(fp))
{
fscanf(fp,"%d%s",&pt1->num,&pt1->name);
printf("\n\t\t%d\t\t%s",pt1->num,pt1->name);
pt1++;
}
if(fclose(fp))
{
printf("不能关闭文件!
!
!
\n");
exit(0);
}
printf("\n\n*******************************导入成功*****************************\n");
printf("\n按Enter键返回");
getchar();
system("cls");
}
*记录购买设备的信息*
voidsave_buy(structinformation**temp,*p=*)malloc(sizeof(structinformation));*开辟一个新单元*
while(p->next!
=NULL)
p=p->next;
printf("\n设备编号部门编号购买日期设备状态(1买-1废)设备数量报废数量单价总价\n");
printf("请输入设备编号(1~10):
");
do{
scanf("%d",&temp->ID);
if(temp->ID<=0||temp->ID>10)
printf("输入的设备编号有误,请重新输入(1~10):
");
rewind(stdin);
}while(temp->ID<=0||temp->ID>10);
printf("请输入部门编号(1~4):
");
do{
scanf("%d",&temp->num);
if(temp->num<=0||temp->num>4)
printf("输入的部门编号有误,请重新输入(1~4):
");
rewind(stdin);
}while(temp->num<=0||temp->num>4);
{
time_ttval;
structtm*data;
tval=time(NULL);
data=localtime(&tval);
printftime(p->date);
printf("\n当前时间(从系统调用)为:
%s\n",p->date);
temp->date[0]=(data->tm_year+1900)1000+'0';
temp->date[1]=(data->tm_year+1900)100%10+'0';
temp->date[2]=(data->tm_year+1900)10%100+'0';
temp->date[3]=(data->tm_year+1900)%10+'0';
temp->date[4]='-';
temp->date[5]=(data->tm_mon+1)10+'0';
temp->date[6]=(data->tm_mon+1)%10+'0';
temp->date[7]='-';
temp->date[8]=(data->tm_mday)10+'0';
temp->date[9]=(data->tm_mday)%10+'0';
temp->date[10]='\0';
}*将日期装换为字符型存入*
temp->style=1;
printf("请输入购买设备数量(整数):
");
do{
scanf("%d",&temp->number);
if(temp->number<=0)
printf("输入的购买设备数量有误,请重新输入购买设备数量(整数):
");
rewind(stdin);
}while(temp->number<=0);
temp->number1=0;
temp->price=1*temp->ID;
printf("请输入设备单价:
");
do{
scanf("%lf",&temp->price);
if(temp->price<=0)
printf("输入的设备单价有误,请重新输入设备单价:
");
rewind(stdin);
}while(temp->price<=0);
temp->sum=(temp->number)*(temp->price);
printf("设备需要总价:
%.2lf\n\n",temp->sum);
p->next=temp;
temp->next=NULL;
getchar();
load((structinformation*,s=0,o=0,g=0;
structinformation*temp,*p=*)malloc(sizeof(structinformation));
w=temp;
while(p->next!
=NULL)
p=p->next;
printf("\n设备编号部门编号购买日期设备状态(1买-1废)设备数量报废数量单价总价\n");
printf("请输入设备编号(1~10):
");
do{
scanf("%d",&m);
if(m<=0||m>10)
printf("输入的设备编号有误,请重新输入(1~10):
");
rewind(stdin);
}while(m<=0||m>10);
printf("请输入部门编号(1~4):
");
do{
scanf("%d",&n);
if(n<=0||n>4)
printf("输入的部门编号有误,请重新输入(1~4):
");
rewind(stdin);
}while(n<=0||n>4);printf("\n请输入报废日期,格式为(YYYY-MM-DD):
");
do{
address:
scanf("%s",date2);
if(judge_date(date2)==0)
printf("\n您输入的日期格式不正确,请重新输入(YYYY-MM-DD):
");
}while(judge_date(date2)==0);
if(strcmp(p->date,date2)>=0){
printf("\n>>>>>>>>提示:
输入时间不能小于购买时间!
请重新输入:
");
date2[0]='\0';
gotoaddress;
}
strcpy(p->date1,date2);
if((fp=fopen("购买报废记录.txt","r+"))==NULL)
{
printf("打开错误!
\n");
exit(0);
}
while(!
feof(fp))
{
fscanf(fp,"%d%d%s%d%d%d%lf%lf\n",&w->ID,&w->num,w->date,&w->style,&w->number,&w->number1,&w->price,&w->sum);
if(w->ID==m&&w->num==n)
{s=s+w->number;
o=o+w->number1;
g=s-o;}
}
printf("剩余使用数量:
%d",g);
q=g;
temp->ID=m;
temp->num=n;
{
time_ttval;
structtm*data;
tval=time(NULL);
data=localtime(&tval);
printftime(p->date);
printf("\n当前时间(从系统调用)为:
%s\n",p->date);
temp->date[0]=(data->tm_year+1900)1000+'0';
temp->date[1]=(data->tm_year+1900)100%10+'0';
temp->date[2]=(data->tm_year+1900)10%100+'0';
temp->date[3]=(data->tm_year+1900)%10+'0';
temp->date[4]='-';
temp->date[5]=(data->tm_mon+1)10+'0';
temp->date[6]=(data->tm_mon+1)%10+'0';
temp->date[7]='-';
temp->date[8]=(data->tm_mday)10+'0';
temp->date[9]=(data->tm_mday)%10+'0';
temp->date[10]='\0';
}*将日期装换为字符型存入*
temp->style=-1;
temp->number=0;
printf("请输入报废设备数量