|
|
#include<stdio.h>
|
|
|
#include<stdlib.h>
|
|
|
#include<windows.h>
|
|
|
#include<string.h>
|
|
|
#include <conio.h>
|
|
|
struct airstruct //*航班*//
|
|
|
{
|
|
|
int runway; //*跑道号*//
|
|
|
char airstatus[20]; //*状态*//
|
|
|
char start[20]; //*起点*//
|
|
|
char des[20]; //*目的地*//
|
|
|
char airname[20]; //*航班号*//
|
|
|
char time[20]; //*出发时间*//
|
|
|
int count; //机票数量//
|
|
|
struct airstruct *next; //航班信息链表//
|
|
|
};
|
|
|
struct userstruct
|
|
|
{
|
|
|
char username[20]; //用户名
|
|
|
char usermm[100]; //密码
|
|
|
char name[20]; //姓名
|
|
|
char sex[20]; //性别
|
|
|
char tele[20]; // 电话
|
|
|
char id[20]; //身份证
|
|
|
int aircount1; // 订购的机票数量
|
|
|
char uairname[20][20]; // 用户订购的航班编号( 二维数组储存信息 下同 )
|
|
|
char ustart[20][20]; //起点//
|
|
|
char udes[20][20]; //终点//
|
|
|
char utime[20][20]; //出发时间//
|
|
|
int urunway[20]; //跑道号//
|
|
|
struct userstruct *next; //用户信息链表//
|
|
|
|
|
|
};
|
|
|
struct adminstruct
|
|
|
{
|
|
|
char adminname[20]; //管理员用户名//
|
|
|
char adminmm[100]; //管理员密码//
|
|
|
struct adminstruct *next; //管理员身份链表
|
|
|
};
|
|
|
struct superstruct
|
|
|
{
|
|
|
char supername[20]; //同上
|
|
|
char supermm[100];
|
|
|
struct superstruct *next;
|
|
|
};
|
|
|
struct airstruct *airhead=NULL,*airend =NULL; //初始化头指针和尾指针为空(下同)
|
|
|
struct userstruct *userhead=NULL,*userend =NULL;
|
|
|
struct adminstruct *adminhead=NULL,*adminend =NULL;
|
|
|
struct superstruct *superhead =NULL,*superend =NULL;
|
|
|
int aircount,usercount,admincount,supercount; //*全局变量(航班,用户,管理员,超级管理员数量)*//
|
|
|
void airfile(); //航班文件
|
|
|
void userfile(); //用户文件
|
|
|
void adminfile(); //管理员
|
|
|
void superfile(); //超级管理员
|
|
|
void writefile(int flag); //写文件
|
|
|
void home(); //主界面
|
|
|
void dengru(); //登陆界面
|
|
|
void userlogin(); //用户登入界面
|
|
|
void userfunction(struct userstruct *p); // 用户功能界面
|
|
|
void u_search(); //用户查询航班信息界面
|
|
|
void u_book(struct userstruct *userp); //用户订票界面
|
|
|
void u_exit(struct userstruct *userp); //用户退票界面
|
|
|
void u_rivese(struct userstruct *userp); //用户修改个人信息界面
|
|
|
void adminlogin(); //管理员登陆界面
|
|
|
void adminfunction(); //管理员功能界面
|
|
|
void superlogin(); //超级管理员登陆界面
|
|
|
void superfunction(); //超级管理员登陆界面
|
|
|
void a_research1(); //管理员按航班编号查询航班信息
|
|
|
void a_research2(); //按跑道号查询航班信息
|
|
|
void a_research3(); //按用户真实姓名查询用户信息
|
|
|
void a_add(); //添加航班
|
|
|
void a_rivese1(); //管理员修改航班信息
|
|
|
void changeuser(char *s,char *s1,int a); //修改已订票的用户的航班信息 void a_rivese1()子函数 修改信息为char型
|
|
|
void changeuser1(char *s,int a); //修改已订票的用户的航班信息 void a_rivese1()子函数 修改信息为int型
|
|
|
void deleteair(); //管理员删除航班信息
|
|
|
void deleteuser(); //删除(管理员要删除的)已订票的用户的航班信息
|
|
|
void s_add(); //超级管理员添加管理员
|
|
|
void s_delete(); //超级管理员删除管理员
|
|
|
void zhuce();
|
|
|
void userrigester(); //用户注册
|
|
|
void superrigerster(); ////超级管理员注册(需要初始密码)
|
|
|
|
|
|
int main()
|
|
|
{
|
|
|
FILE *fp;
|
|
|
airhead = (struct airstruct *)malloc(sizeof(struct airstruct)); //给头指针分配内存(下同)
|
|
|
userhead = (struct userstruct *)malloc(sizeof(struct userstruct));
|
|
|
adminhead = (struct adminstruct *)malloc(sizeof(struct adminstruct));
|
|
|
superhead = (struct superstruct *)malloc(sizeof(struct superstruct)); //申请内存
|
|
|
fp=fopen("air","a+"); //第一次建立air文件,随后追加
|
|
|
aircount=fread(airhead,sizeof(struct airstruct),1,fp); //读取航班数量
|
|
|
fclose(fp); //关闭文件
|
|
|
airend=airhead;
|
|
|
airfile();
|
|
|
fp=fopen("user","a+");
|
|
|
usercount=fread(userhead,sizeof(struct userstruct),1,fp);
|
|
|
fclose(fp);
|
|
|
userend=userhead;
|
|
|
userfile();
|
|
|
fp=fopen("admin","a+");
|
|
|
admincount=fread(adminhead,sizeof(struct adminstruct),1,fp);
|
|
|
fclose(fp);
|
|
|
adminend=adminhead;
|
|
|
adminfile();
|
|
|
fp=fopen("super","a+");
|
|
|
supercount=fread(superhead,sizeof(struct superstruct),1,fp);
|
|
|
fclose(fp);
|
|
|
superend=superhead;
|
|
|
superfile();
|
|
|
home();
|
|
|
return 0;
|
|
|
}
|
|
|
int isexist(char *name,int flag) //是否存在//
|
|
|
{
|
|
|
|
|
|
if (flag == 0)
|
|
|
{
|
|
|
struct userstruct *p;
|
|
|
p = userhead;
|
|
|
while (p != NULL)
|
|
|
{
|
|
|
if (strcmp(name, p->username) == 0)
|
|
|
return 1;
|
|
|
p = p->next;
|
|
|
}
|
|
|
}
|
|
|
else if (flag == 1)
|
|
|
{
|
|
|
struct adminstruct *p;
|
|
|
p = adminhead;
|
|
|
while (p != NULL)
|
|
|
{
|
|
|
if (strcmp(name, p->adminname) == 0)
|
|
|
return 1;
|
|
|
p = p->next;
|
|
|
}
|
|
|
}
|
|
|
else if (flag == 2)
|
|
|
{
|
|
|
struct superstruct *p;
|
|
|
p = superhead;
|
|
|
while (p != NULL)
|
|
|
{
|
|
|
if (strcmp(name, p->supername) == 0)
|
|
|
return 1;
|
|
|
p = p->next;
|
|
|
}
|
|
|
}
|
|
|
else if(flag == 3)
|
|
|
{
|
|
|
struct airstruct *p;
|
|
|
p = airhead;
|
|
|
while (p != NULL)
|
|
|
{
|
|
|
if (strcmp(name, p->airname) == 0)
|
|
|
return 1;
|
|
|
p = p->next;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
void home()
|
|
|
{
|
|
|
int i;
|
|
|
int end=0;
|
|
|
while(1)
|
|
|
{
|
|
|
system("cls"); //清屏
|
|
|
system("color 0F");
|
|
|
printf("\n\n\n\n\n\n");
|
|
|
printf("\n\n ***********欢迎来到机场管理系统************ \n\n");
|
|
|
printf("~ 1 登陆 ~\n");
|
|
|
printf("~ 2 注册 ~\n");
|
|
|
printf("~ 0 退出 ~\n");
|
|
|
printf("\n\n 请输入你要进行的操作:");
|
|
|
scanf("%d",&i);
|
|
|
switch(i)
|
|
|
{
|
|
|
case 1:dengru();break;
|
|
|
case 2:zhuce();break;
|
|
|
case 0:end=1;break;
|
|
|
default:printf(" 错误输入!请重新输入:");
|
|
|
system("pause");
|
|
|
continue;
|
|
|
}
|
|
|
if(end==1) break;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
void dengru()
|
|
|
{
|
|
|
int i;
|
|
|
int end=0;
|
|
|
while(1)
|
|
|
{
|
|
|
system("cls");
|
|
|
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
|
|
|
SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | FOREGROUND_RED| FOREGROUND_GREEN); //颜色函数
|
|
|
printf("\n\n\n\n\n\n");
|
|
|
printf(" 1 用户登陆\n");
|
|
|
printf(" 2 管理员登陆\n");
|
|
|
printf(" 3 超级管理员登陆\n");
|
|
|
printf(" 0 返回上一层\n");
|
|
|
printf("\n\n\n");
|
|
|
printf(" 请输入你要进行的操作: ");
|
|
|
scanf("%d",&i);
|
|
|
switch(i)
|
|
|
{
|
|
|
case 1:userlogin();break;
|
|
|
case 2:adminlogin();break;
|
|
|
case 3:superlogin();break;
|
|
|
case 0:end=1;break;
|
|
|
default:printf(" 错误输入!请重新输入:\n ");
|
|
|
system("pause");
|
|
|
continue;
|
|
|
}
|
|
|
if(end==1)
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
void userlogin()
|
|
|
{
|
|
|
struct userstruct *p;
|
|
|
char username[20];
|
|
|
char usermm[100];
|
|
|
int exist=0;
|
|
|
FILE *fp;
|
|
|
int i;
|
|
|
p=userhead;
|
|
|
system("cls");
|
|
|
system("color 0A");
|
|
|
printf("\n\n\n\n\n\n\n");
|
|
|
printf("**************************************************************");
|
|
|
printf("\n输入您的用户信息: \n");
|
|
|
printf("输入用户名: ");
|
|
|
fflush(stdin);
|
|
|
gets(username);
|
|
|
fflush(stdin);
|
|
|
printf("输入密码: ");
|
|
|
for(i=0;i<100;i++)
|
|
|
{
|
|
|
usermm[i]=getch();
|
|
|
if(usermm[i]!=13&&usermm[i]!=8)
|
|
|
{
|
|
|
printf("*");
|
|
|
}
|
|
|
if(usermm[i]==8)
|
|
|
{
|
|
|
printf("\b");
|
|
|
i--;
|
|
|
printf(" ");
|
|
|
printf("\b");
|
|
|
i--;
|
|
|
}
|
|
|
if(usermm[i]==13)
|
|
|
{
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
usermm[i]='\0';
|
|
|
printf("\n**************************************************************");
|
|
|
printf("\n\n\n\n\n\n\n");
|
|
|
while (p != NULL)
|
|
|
{
|
|
|
if (strcmp(p->username, username) == 0)
|
|
|
{
|
|
|
exist=1;
|
|
|
while(strcmp(p->usermm,usermm) != 0)
|
|
|
{
|
|
|
printf("密码错误!请重新输入\n");
|
|
|
printf("输入密码: ");
|
|
|
gets(usermm);
|
|
|
}
|
|
|
printf("用户%s登陆成功!3秒后自动跳转至用户界面...", p->username);
|
|
|
Sleep(3000);
|
|
|
userfunction(p);
|
|
|
}
|
|
|
p = p->next;
|
|
|
}
|
|
|
if (!exist)
|
|
|
{
|
|
|
printf("不存在此用户名,请先前往注册...\n");
|
|
|
printf("3秒后自动跳转至注册界面...");
|
|
|
Sleep(3000);
|
|
|
zhuce();
|
|
|
}
|
|
|
}
|
|
|
void userfunction(struct userstruct *p) //对应用户功能 //
|
|
|
{
|
|
|
int i;
|
|
|
int end=0;
|
|
|
while(1)
|
|
|
{
|
|
|
system("cls");
|
|
|
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
|
|
|
SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | FOREGROUND_GREEN);
|
|
|
printf("\n\n\n\n\n\n");
|
|
|
printf(" 1 查询\n");
|
|
|
printf(" 2 买票\n");
|
|
|
printf(" 3 退票\n");
|
|
|
printf(" 4 修改个人信息\n");
|
|
|
printf(" 0 返回上一层\n");
|
|
|
printf("\n\n\n");
|
|
|
printf(" 请输入你要进行的操作: ");
|
|
|
scanf("%d",&i);
|
|
|
getchar();
|
|
|
switch(i)
|
|
|
{
|
|
|
case 1:u_search();break; //查询
|
|
|
case 2:u_book(p);break; //订票
|
|
|
case 3:u_exit(p);break; //退票
|
|
|
case 4:u_rivese(p);break; //修改个人信息
|
|
|
case 0:end=1;break;
|
|
|
default:printf(" 错误输入!请重新输入:");
|
|
|
system("pause");
|
|
|
continue;
|
|
|
}
|
|
|
if(end==1)
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
void u_search()
|
|
|
{
|
|
|
struct airstruct *p;
|
|
|
char airname[20];
|
|
|
char start[20];
|
|
|
char des[20];
|
|
|
int exist = 0;
|
|
|
system("c0");
|
|
|
system("cls");
|
|
|
printf("\n\n\n\n\n\n\n");
|
|
|
printf("\n请输入您需要查询的航班起点: ");
|
|
|
gets(start);
|
|
|
printf("\n");
|
|
|
printf("\n请输入您需要查询的航班终点: ");
|
|
|
gets(des);
|
|
|
p = airhead;
|
|
|
while (p != NULL)
|
|
|
{
|
|
|
if (strcmp(p->start, start) == 0)
|
|
|
{
|
|
|
if(strcmp(p->des ,des)==0)
|
|
|
{
|
|
|
printf("您查询的信息如下:\n");
|
|
|
printf("航班编号:%s\n",p->airname );
|
|
|
printf("起点:%s\n",p->start );
|
|
|
printf("终点:%s\n",p->des );
|
|
|
printf("起飞时间:%s\n",p->time );
|
|
|
printf("跑道号:%d\n",p->runway);
|
|
|
printf("余票量%d\n",p->count);
|
|
|
exist=1;
|
|
|
}
|
|
|
}
|
|
|
p = p->next;
|
|
|
}
|
|
|
if (exist == 0)
|
|
|
printf("该航班信息不存在...\n");
|
|
|
printf("\n输入0返回用户界面: ");
|
|
|
int n;
|
|
|
while (1)
|
|
|
{
|
|
|
scanf("%d", &n);
|
|
|
if (n == 0)
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
void u_book(struct userstruct *userp)
|
|
|
{
|
|
|
struct airstruct *p;
|
|
|
char start[20];
|
|
|
char des[20];
|
|
|
int exist = 0;
|
|
|
system("cls");
|
|
|
printf("输入您需要订票航班的起点: ");
|
|
|
gets(start);
|
|
|
printf("输入您需要订票航班的终点: ");
|
|
|
gets(des);
|
|
|
p = airhead;
|
|
|
while (p != NULL)
|
|
|
{
|
|
|
if (strcmp(start, p->start) == 0)
|
|
|
{
|
|
|
if(strcmp(des,p->des )==0)
|
|
|
{
|
|
|
printf("%s %d",p->des,p->count );
|
|
|
if (p->count == 0)
|
|
|
printf("该航班机票已售完...");
|
|
|
else
|
|
|
{
|
|
|
p->count -= 1;
|
|
|
userp->aircount1++;
|
|
|
strcpy(userp->uairname[userp->aircount1 -1] ,p->airname );
|
|
|
strcpy(userp->ustart[userp->aircount1 -1] ,p->start );
|
|
|
strcpy(userp->udes[userp->aircount1 -1],p->des );
|
|
|
strcpy(userp->utime[userp->aircount1 -1],p->time );
|
|
|
userp->urunway[userp->aircount1 -1]=p->runway ;
|
|
|
writefile(0);
|
|
|
writefile(3);
|
|
|
exist = 1;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
p = p->next;
|
|
|
}
|
|
|
if (exist == 0)
|
|
|
printf("\n航班不存在!");
|
|
|
else
|
|
|
printf("\n%s航班订票成功", p->airname);
|
|
|
printf("\n3秒后返回用户界面...");
|
|
|
Sleep(3000);
|
|
|
}
|
|
|
void u_exit(struct userstruct *userp)
|
|
|
{
|
|
|
struct airstruct *p;
|
|
|
char airname[20];
|
|
|
int count = userp->aircount1;
|
|
|
int exist;
|
|
|
int flag;
|
|
|
int end=0;
|
|
|
system("cls");
|
|
|
system("color 06");
|
|
|
p = airhead;
|
|
|
while (count--)
|
|
|
{
|
|
|
printf("已购买机票列表:\n");
|
|
|
printf("航班编号:%s ", userp->uairname[count]);
|
|
|
printf("航班起点:%s ", userp->ustart[count]);
|
|
|
printf("航班终点:%s ", userp->udes[count]);
|
|
|
printf("航班出发时间:%s ", userp->utime[count]);
|
|
|
printf("航班飞行跑道号:%d\n", userp->urunway[count]);
|
|
|
}
|
|
|
printf("\n\n\n\n\n");
|
|
|
printf("**************************************************************");
|
|
|
printf("\n输入你需要退票的航班号: ");
|
|
|
while (gets(airname))
|
|
|
{
|
|
|
exist = 0;
|
|
|
int i;
|
|
|
for (i = 0; i < userp->aircount1; i++)
|
|
|
{
|
|
|
if (strcmp(airname, userp->uairname[i])== 0)
|
|
|
{
|
|
|
flag = i;
|
|
|
exist = 1;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
if (!exist)
|
|
|
{
|
|
|
printf("你没有此机票...\n");
|
|
|
printf("请重新输入你需要名称退票的航班号: ");
|
|
|
}
|
|
|
else
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
printf("**************************************************************");
|
|
|
while (p != NULL)
|
|
|
{
|
|
|
if (strcmp(p->airname, airname) == 0)
|
|
|
{
|
|
|
p->count++;
|
|
|
break;
|
|
|
}
|
|
|
p = p->next;
|
|
|
}
|
|
|
int i;
|
|
|
for ( i = flag; i < userp->aircount1 - 1; i++)
|
|
|
{
|
|
|
strcpy(userp->uairname[i], userp->uairname[i + 1]);
|
|
|
strcpy(userp->ustart[i], userp->ustart[i + 1]);
|
|
|
strcpy(userp->udes[i], userp->udes[i + 1]);
|
|
|
strcpy(userp->utime[i], userp->utime[i + 1]);
|
|
|
userp->urunway[i]= userp->urunway[i + 1];
|
|
|
}
|
|
|
userp->aircount1--;
|
|
|
writefile(0);
|
|
|
writefile(3);
|
|
|
printf("\n%退票成功...", airname);
|
|
|
printf("3秒后自动跳转回用户界面...");
|
|
|
Sleep(3000);
|
|
|
}
|
|
|
void u_rivese(struct userstruct *userp)
|
|
|
{
|
|
|
char username[200];
|
|
|
char usermm[100];
|
|
|
char name[2-0];
|
|
|
char sex[20];
|
|
|
char tele[20];
|
|
|
char id[20];
|
|
|
system("cls");
|
|
|
system("color 09");
|
|
|
int i;
|
|
|
int end=0;
|
|
|
printf("\n\n\n\n\n\n");
|
|
|
printf("**************************************************************\n");
|
|
|
printf("\t\t1.修改用户名\n");
|
|
|
printf("\t\t2.修改密码\n");
|
|
|
printf("\t\t3.修改真实姓名\n");
|
|
|
printf("\t\t4.修改性别\n");
|
|
|
printf("\t\t5.修改电话号码\n");
|
|
|
printf("\t\t6.修改身份证号\n");
|
|
|
printf("\t\t0.退出");
|
|
|
printf("\n\n\n\n\n\n");
|
|
|
printf("**************************************************************\n");
|
|
|
while(1)
|
|
|
{
|
|
|
printf("\t\t请输入您需要进行的操作: ");
|
|
|
scanf("%d",&i);
|
|
|
printf("1");
|
|
|
getchar();
|
|
|
switch(i)
|
|
|
{
|
|
|
case 1:
|
|
|
{
|
|
|
printf("\t\t请输入您需要修改后的用户名: ");
|
|
|
gets(username);
|
|
|
while(isexist(username, 0))
|
|
|
{
|
|
|
printf("\t\t该用户名已经存在!\n");
|
|
|
printf("\t\t请重新输入: ");
|
|
|
gets(username);
|
|
|
}
|
|
|
strcpy(userp->username ,username);
|
|
|
break;
|
|
|
}
|
|
|
case 2:
|
|
|
{
|
|
|
printf("\n\n\t\t请输入您需要修改后的用户密码: ");
|
|
|
gets(usermm);
|
|
|
strcpy(userp->usermm ,usermm);
|
|
|
break;
|
|
|
}
|
|
|
case 3:
|
|
|
{
|
|
|
printf("\n\n\t\t请输入您需要修改后的真实姓名: ");
|
|
|
gets(name);
|
|
|
strcpy(userp->name ,name);
|
|
|
break;
|
|
|
}
|
|
|
case 4:
|
|
|
{
|
|
|
printf("\n\n请输入您需要修改后的性别: ");
|
|
|
gets(sex);
|
|
|
strcpy(userp->sex ,sex);
|
|
|
break;
|
|
|
}
|
|
|
case 5:
|
|
|
{
|
|
|
printf("\n\n\t\t请输入您需要修改后的电话号码: ");
|
|
|
gets(tele);
|
|
|
strcpy(userp->tele ,tele);
|
|
|
break;
|
|
|
}
|
|
|
case 6:
|
|
|
{
|
|
|
printf("\n\n\t\t请输入您需要修改后的身份证号:");
|
|
|
gets(id);
|
|
|
strcpy(userp->id ,id);
|
|
|
break;
|
|
|
}
|
|
|
case 0:
|
|
|
{
|
|
|
end=1;
|
|
|
break;
|
|
|
}
|
|
|
default:printf("\t\t错误输入!\n\n");
|
|
|
//system("pause");
|
|
|
continue;
|
|
|
}
|
|
|
if(end==1)
|
|
|
{
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
system("cls");
|
|
|
printf("\t\t修改成功!");
|
|
|
printf("\n\t\t您修改后的信息如下:");
|
|
|
printf("\n\t\t用户名:%s",userp->username );
|
|
|
printf("\n\t\t密码:%s",userp->usermm );
|
|
|
printf("\n\t\t真实姓名:%s",userp->name );
|
|
|
printf("\n\t\t性别:%s",userp->sex );
|
|
|
printf("\n\t\t电话号码:%s",userp->tele );
|
|
|
printf("\n\t\t身份证号:%s\n\t\t",userp->id );
|
|
|
system("pause");
|
|
|
printf("\n\t\t三秒后自动返回用户界面...");
|
|
|
writefile(0);
|
|
|
Sleep(3000);
|
|
|
}
|
|
|
void adminlogin()
|
|
|
{
|
|
|
int exit=0;
|
|
|
int i;
|
|
|
struct adminstruct *p;
|
|
|
char adminname[20];
|
|
|
char adminmm[100];
|
|
|
p = adminhead;
|
|
|
system("cls");
|
|
|
system("color 0B");
|
|
|
printf("\n\n\n\n\n\n\n");
|
|
|
printf("**************************************************************");
|
|
|
printf("\n输入您的管理员信息: \n");
|
|
|
printf("输入管理员账号: ");
|
|
|
fflush(stdin);
|
|
|
gets(adminname);
|
|
|
printf("\n输入密码: ");
|
|
|
fflush(stdin);
|
|
|
for(i=0;i<100;i++)
|
|
|
{
|
|
|
adminmm[i]=getch();
|
|
|
if(adminmm[i]!=13&&adminmm[i]!=8)
|
|
|
{
|
|
|
printf("*");
|
|
|
}
|
|
|
if(adminmm[i]==8)
|
|
|
{
|
|
|
printf("\b");
|
|
|
i--;
|
|
|
printf(" ");
|
|
|
printf("\b");
|
|
|
i--;
|
|
|
}
|
|
|
if(adminmm[i]==13)
|
|
|
{
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
adminmm[i]='\0';
|
|
|
printf("\n\n**************************************************************");
|
|
|
printf("\n\n\n\n\n\n\n");
|
|
|
while (p != NULL)
|
|
|
{
|
|
|
if (strcmp(p->adminname, adminname) == 0)
|
|
|
{
|
|
|
exit=1;
|
|
|
while (strcmp(p->adminmm, adminmm) != 0)
|
|
|
{
|
|
|
printf("\n密码错误!请重新输入\n");
|
|
|
printf("adminmm: ");
|
|
|
gets(adminmm);
|
|
|
}
|
|
|
printf("\n管理员%s登陆成功!3秒后自动跳转至管理员界面...", p->adminname);
|
|
|
Sleep(3000);
|
|
|
adminfunction();
|
|
|
}
|
|
|
p = p->next;
|
|
|
}
|
|
|
if(exit==0)
|
|
|
{
|
|
|
printf("\n该用户名不存在!");
|
|
|
printf("\n三秒后返回登录界面...");
|
|
|
Sleep(3000);
|
|
|
dengru();
|
|
|
}
|
|
|
}
|
|
|
void adminfunction() //管理员功能//
|
|
|
{
|
|
|
int i;
|
|
|
int end=0;
|
|
|
system("color 03");
|
|
|
while(1)
|
|
|
{
|
|
|
system("cls");
|
|
|
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
|
|
|
SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY| FOREGROUND_RED);
|
|
|
printf("\n\n\n\n\n\n");
|
|
|
printf("\t\t1 通过航班号查询\n");
|
|
|
printf("\t\t2 通过跑道号查询\n");
|
|
|
printf("\t\t3 通过姓名查询\n");
|
|
|
printf("\t\t4 添加航班\n");
|
|
|
printf("\t\t5 修改航班信息\n");
|
|
|
printf("\t\t6 删除航班信息\n");
|
|
|
printf("\t\t0 返回上一层\n");
|
|
|
printf("\n\n\n");
|
|
|
printf("\t\t请输入你要进行的操作: ");
|
|
|
scanf("%d",&i);
|
|
|
getchar();
|
|
|
switch(i)
|
|
|
{
|
|
|
case 1:a_research1();break;
|
|
|
case 2:a_research2();break;
|
|
|
case 3:a_research3();break;
|
|
|
case 4:a_add();break;
|
|
|
case 5:a_rivese1();break;
|
|
|
case 6:deleteair();break;
|
|
|
case 0:end=1;break;
|
|
|
default:printf("\t\t错误输入!请重新输入:\n\t\t");
|
|
|
system("pause");
|
|
|
continue;
|
|
|
}
|
|
|
if(end==1)
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
void superlogin()
|
|
|
{
|
|
|
struct superstruct *p;
|
|
|
char supername[20];
|
|
|
char supermm[100];
|
|
|
p = superhead;
|
|
|
int exist=0;
|
|
|
int i;
|
|
|
system("cls");
|
|
|
system("color 0C");
|
|
|
printf("\n\n\n\n\n\n\n");
|
|
|
printf("**************************************************************");
|
|
|
printf("\n输入您的超级管理员信息: \n");
|
|
|
printf("输入超级管理员账号: ");
|
|
|
fflush(stdin);
|
|
|
gets(supername);
|
|
|
printf("输入密码: ");
|
|
|
fflush(stdin);
|
|
|
for(i=0;i<100;i++)
|
|
|
{
|
|
|
supermm[i]=getch();
|
|
|
if(supermm[i]!=13&&supermm[i]!=8)
|
|
|
{
|
|
|
printf("*");
|
|
|
}
|
|
|
if(supermm[i]==8)
|
|
|
{
|
|
|
printf("\b");
|
|
|
i--;
|
|
|
printf(" ");
|
|
|
printf("\b");
|
|
|
i--;
|
|
|
}
|
|
|
if(supermm[i]==13)
|
|
|
{
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
supermm[i]='\0';
|
|
|
printf("\n**************************************************************");
|
|
|
printf("\n\n\n\n\n\n\n");
|
|
|
while (p != NULL)
|
|
|
{
|
|
|
if (strcmp(p->supername, supername) == 0)
|
|
|
{
|
|
|
exist = 1;
|
|
|
while(strcmp(p->supermm, supermm) != 0)
|
|
|
{
|
|
|
printf("\n密码错误!请重新输入\n");
|
|
|
printf("\n输入密码: ");
|
|
|
gets(supermm);
|
|
|
}
|
|
|
printf("\n超级管理员%s登陆成功!3秒后自动跳转至超级管理员界面...", p->supername);
|
|
|
Sleep(3000);
|
|
|
superfunction();
|
|
|
}
|
|
|
p = p->next;
|
|
|
}
|
|
|
if (!exist)
|
|
|
{
|
|
|
printf("不存在此用户名,请先前往注册...\n");
|
|
|
printf("3秒后自动跳转至注册...");
|
|
|
Sleep(3000);
|
|
|
zhuce();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void superfunction()
|
|
|
{
|
|
|
int i;
|
|
|
int end=0;
|
|
|
system("color 01");
|
|
|
while(1)
|
|
|
{
|
|
|
system("cls");
|
|
|
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
|
|
|
SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY| FOREGROUND_RED);
|
|
|
printf("\n\n\n\n\n\n");
|
|
|
printf("\t\t1 添加管理员\n");
|
|
|
printf("\t\t2 删除管理员\n");
|
|
|
printf("\t\t0 返回上一层\n");
|
|
|
printf("\n\n\n");
|
|
|
printf("\t\t请输入你要进行的操作: ");
|
|
|
scanf("%d",&i);
|
|
|
getchar();
|
|
|
switch(i)
|
|
|
{
|
|
|
case 1:s_add();
|
|
|
case 2:s_delete();
|
|
|
case 0:end=1;break;
|
|
|
default:printf("\t\t错误输入!请重新输入:");
|
|
|
system("pause");
|
|
|
continue;
|
|
|
}
|
|
|
if(end==1)
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
void a_research1()
|
|
|
{
|
|
|
struct airstruct *p;
|
|
|
char airname[20];
|
|
|
int exist = 0;
|
|
|
system("cls");
|
|
|
system("color 0b");
|
|
|
printf("\n\n\n\n\n\n\n");
|
|
|
printf("\n请输入您需要查询的航班号: ");
|
|
|
gets(airname);
|
|
|
p = airhead;
|
|
|
while (p != NULL)
|
|
|
{
|
|
|
if (strcmp(p->airname, airname) == 0)
|
|
|
{
|
|
|
printf("您查询的信息如下:\n");
|
|
|
printf("航班编号:%s\n",p->airname );
|
|
|
printf("起点:%s\n",p->start );
|
|
|
printf("终点:%s\n",p->des );
|
|
|
printf("起飞时间:%s\n",p->time );
|
|
|
printf("跑道号:%d\n",p->runway);
|
|
|
printf("余票量%d",p->count );
|
|
|
exist=1;
|
|
|
}
|
|
|
p = p->next;
|
|
|
}
|
|
|
if (exist == 0)
|
|
|
printf("该航班信息不存在...\n");
|
|
|
printf("\n输入0返回管路员界面: ");
|
|
|
int n;
|
|
|
while (1)
|
|
|
{
|
|
|
scanf("%d", &n);
|
|
|
if (n == 0)
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
void a_research2()
|
|
|
{
|
|
|
struct airstruct *p;
|
|
|
int runway;
|
|
|
int exist = 0;
|
|
|
system("color 0D");
|
|
|
system("cls");
|
|
|
printf("\n\n\n\n\n\n\n");
|
|
|
printf("\n请输入您需要查询的跑道号: ");
|
|
|
scanf("%d",&runway);
|
|
|
p = airhead;
|
|
|
while (p != NULL)
|
|
|
{
|
|
|
if (p->runway == runway)
|
|
|
{
|
|
|
printf("您查询的信息如下:\n");
|
|
|
printf("航班编号:%s\n",p->airname );
|
|
|
printf("起点:%s\n",p->start );
|
|
|
printf("终点:%s\n",p->des );
|
|
|
printf("起飞时间:%s\n",p->time );
|
|
|
printf("跑道号:%d\n",p->runway);
|
|
|
printf("余票量%d",p->count );
|
|
|
exist=1;
|
|
|
}
|
|
|
p = p->next;
|
|
|
}
|
|
|
if (exist == 0)
|
|
|
printf("\n该跑道暂无航班信息...\n");
|
|
|
printf("\n输入0返回管路员界面: ");
|
|
|
int n;
|
|
|
while (1)
|
|
|
{
|
|
|
scanf("%d", &n);
|
|
|
if (n == 0)
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
void a_research3()
|
|
|
{
|
|
|
struct userstruct *p;
|
|
|
char name[20];
|
|
|
int exist = 0;
|
|
|
system("color 04");
|
|
|
system("cls");
|
|
|
printf("\n\n\n\n\n\n\n");
|
|
|
printf("\n请输入您需要查询的乘客姓名: \n");
|
|
|
gets(name);
|
|
|
p = userhead;
|
|
|
while (p != NULL)
|
|
|
{
|
|
|
int count=p->aircount1 ;
|
|
|
if (strcmp(p->name, name) == 0)
|
|
|
{
|
|
|
printf("您查询的信息如下:\n");
|
|
|
printf("用户名:%s",p->username );
|
|
|
printf("姓名:%s\n",p->name );
|
|
|
printf("性别:%s\n",p->sex);
|
|
|
printf("电话:%s\n",p->tele );
|
|
|
printf("身份证号:%s\n",p->id );
|
|
|
while (count--)
|
|
|
{
|
|
|
printf("已购买机票列表:\n");
|
|
|
printf("%s ", p->uairname[count]);
|
|
|
printf("%s ", p->ustart[count]);
|
|
|
printf("%s ", p->udes[count]);
|
|
|
printf("%s ", p->utime[count]);
|
|
|
printf("%d\n", p->urunway[count]);
|
|
|
}
|
|
|
exist=1;
|
|
|
}
|
|
|
p = p->next;
|
|
|
}
|
|
|
if (exist == 0)
|
|
|
printf("\n该用户信息不存在...\n");
|
|
|
printf("\n输入0返回管路员界面: ");
|
|
|
int n;
|
|
|
while (1)
|
|
|
{
|
|
|
scanf("%d", &n);
|
|
|
if (n == 0)
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
void a_add()
|
|
|
{
|
|
|
struct airstruct *p;
|
|
|
FILE *fp;
|
|
|
system("cls");
|
|
|
system("color 03");
|
|
|
char airname[10];
|
|
|
if(aircount==0)
|
|
|
{
|
|
|
printf("请输入航班的编号:");
|
|
|
fflush(stdin);
|
|
|
gets(airname);
|
|
|
strcpy(airhead->airname ,airname);
|
|
|
printf("起点:");
|
|
|
fflush(stdin);
|
|
|
scanf("%s",airhead->start);
|
|
|
printf("终点:");
|
|
|
scanf("%s",airhead->des);
|
|
|
printf("出发时间:");
|
|
|
scanf("%s",airhead->time);
|
|
|
printf("跑道号:");
|
|
|
scanf("%d",&airhead->runway);
|
|
|
printf("状态:");
|
|
|
scanf("%s",airhead->airstatus);
|
|
|
printf("机票数量:");
|
|
|
scanf("%d",&airhead->count );
|
|
|
airend=airhead;
|
|
|
airend->next=NULL;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
|
|
|
p = (struct airstruct *)malloc(sizeof(struct airstruct));
|
|
|
printf("请输入航班的编号:");
|
|
|
fflush(stdin);
|
|
|
gets(airname);
|
|
|
if(isexist(airname,3))
|
|
|
{
|
|
|
printf("该航班已存在!");
|
|
|
system("pause");
|
|
|
getchar();
|
|
|
return;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
strcpy(p->airname ,airname);
|
|
|
printf("起点:");
|
|
|
fflush(stdin);
|
|
|
scanf("%s",p->start);
|
|
|
printf("终点:");
|
|
|
scanf("%s",p->des);
|
|
|
printf("出发时间:");
|
|
|
scanf("%s",p->time);
|
|
|
printf("跑道号:");
|
|
|
scanf("%d",&p->runway);
|
|
|
printf("状态:");
|
|
|
scanf("%s",p->airstatus);
|
|
|
printf("机票数量:");
|
|
|
scanf("%d",&p->count );
|
|
|
airend->next=p;
|
|
|
airend = p;
|
|
|
airend->next = NULL;
|
|
|
}
|
|
|
}
|
|
|
aircount++;
|
|
|
p = airhead;
|
|
|
fp = fopen("air", "w");
|
|
|
while (p != NULL)
|
|
|
{
|
|
|
fwrite(p, sizeof(struct airstruct), 1, fp);
|
|
|
p = p->next;
|
|
|
}
|
|
|
fclose(fp);
|
|
|
system("cls");
|
|
|
printf("航班添加成功\n");
|
|
|
printf("3秒后自动返回管理员界面....\n");
|
|
|
Sleep(3000);
|
|
|
}
|
|
|
void a_rivese1()
|
|
|
{
|
|
|
char airname[20];
|
|
|
char airname1[20];
|
|
|
struct airstruct *airp;
|
|
|
int exist=0;
|
|
|
int end=0;
|
|
|
char start[20];
|
|
|
char des[20];
|
|
|
char time[20];
|
|
|
char airstatus[20];
|
|
|
int runway;
|
|
|
int count;
|
|
|
airp=airhead;
|
|
|
system("cls");
|
|
|
while(airp!=NULL)
|
|
|
{
|
|
|
printf("%s ",airp->airname );
|
|
|
printf("%s ",airp->start );
|
|
|
printf("%s ",airp->des );
|
|
|
printf("%s ",airp->time );
|
|
|
printf("%d ",airp->runway);
|
|
|
printf("%d ",airp->count );
|
|
|
printf("%s\n",airp->airstatus );
|
|
|
airp = airp->next ;
|
|
|
}
|
|
|
airp = airhead;
|
|
|
printf("输入你需要修改的航班编号(按@退出): ");
|
|
|
while (gets(airname))
|
|
|
{
|
|
|
if (strcmp(airname, "@") == 0)
|
|
|
break;
|
|
|
while (airp != NULL)
|
|
|
{
|
|
|
if (strcmp(airp->airname, airname) == 0)
|
|
|
{
|
|
|
exist = 1;
|
|
|
break;
|
|
|
}
|
|
|
airp = airp->next;
|
|
|
}
|
|
|
if (!exist)
|
|
|
printf("不存在该航班,请重新输入: ");
|
|
|
else
|
|
|
break;
|
|
|
}
|
|
|
if (!exist)
|
|
|
return;
|
|
|
else
|
|
|
{
|
|
|
int cmd;
|
|
|
system("cls");
|
|
|
printf("\n\n\n\n\n\n\n");
|
|
|
printf("**************************************************************\n");
|
|
|
printf("1.修改航班编号\n");
|
|
|
printf("2.修改航班起点\n");
|
|
|
printf("3.修改航班终点\n");
|
|
|
printf("4.修改出发时间\n");
|
|
|
printf("5.修改该航班跑道号\n");
|
|
|
printf("6.修改该航班机票数目\n");
|
|
|
printf("7.修改该航班状态\n");
|
|
|
printf("0.退出\n");
|
|
|
printf("**************************************************************");
|
|
|
printf("\n\n\n\n\n\n\n");
|
|
|
while (1)
|
|
|
{
|
|
|
printf("输入您需要进行的操作: ");
|
|
|
scanf("%d", &cmd);
|
|
|
switch (cmd)
|
|
|
{
|
|
|
case 1:
|
|
|
{
|
|
|
printf("\n输入你修改后的航班编号: ");
|
|
|
scanf("%s", airname1);
|
|
|
changeuser(airname,airname1,1);
|
|
|
strcpy(airp->airname, airname1);
|
|
|
break;
|
|
|
}
|
|
|
case 2:
|
|
|
{
|
|
|
printf("\n输入你修改后的航班起点: ");
|
|
|
scanf("%s", &start);
|
|
|
changeuser(airname,start,2);
|
|
|
strcpy(airp->start, start);
|
|
|
break;
|
|
|
}
|
|
|
case 3:
|
|
|
{
|
|
|
printf("\n输入你修改后的航班终点: ");
|
|
|
scanf("%s", des);
|
|
|
changeuser(airname,des,3);
|
|
|
strcpy(airp->des, des);
|
|
|
break;
|
|
|
}
|
|
|
case 4:
|
|
|
{
|
|
|
printf("\n输入你修改后的出发时间: ");
|
|
|
scanf("%s",time);
|
|
|
changeuser(airname,time,4);
|
|
|
strcpy(airp->time, time);
|
|
|
break;
|
|
|
}
|
|
|
case 5:
|
|
|
{
|
|
|
printf("\n输入你修改后航班跑道号: ");
|
|
|
scanf("%d", &runway);
|
|
|
changeuser1(airname,runway);
|
|
|
airp->runway = runway;
|
|
|
break;
|
|
|
}
|
|
|
case 6:
|
|
|
{
|
|
|
printf("输入修改后的机票数目:");
|
|
|
scanf("%d",&count);
|
|
|
airp->count =count;
|
|
|
break;
|
|
|
}
|
|
|
case 7:
|
|
|
{
|
|
|
printf("输入该航班修改后的状态:");
|
|
|
scanf("%s", airstatus);
|
|
|
strcpy(airp->airstatus , airstatus);
|
|
|
break;
|
|
|
}
|
|
|
case 0:
|
|
|
{
|
|
|
end = 1;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
if (end == 1)
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
writefile(3);
|
|
|
}
|
|
|
void changeuser1(char *s,int a)
|
|
|
{
|
|
|
struct userstruct *userp;
|
|
|
userp = userhead;
|
|
|
while(userp!=NULL)
|
|
|
{
|
|
|
int i;
|
|
|
for (i = 0; i < userp->aircount1; i++)
|
|
|
{
|
|
|
if (strcmp(userp->uairname[i] , s) == 0)
|
|
|
{
|
|
|
userp->urunway [i]= a;
|
|
|
}
|
|
|
}
|
|
|
userp = userp->next;
|
|
|
}
|
|
|
writefile(0);
|
|
|
}
|
|
|
void deleteair()
|
|
|
{
|
|
|
struct airstruct *airp;
|
|
|
char airname[20];
|
|
|
int exist = 0;
|
|
|
int end=0;
|
|
|
airp = airhead;
|
|
|
printf("\t\t输入你需要删除的航班编号(输入@退出): ");
|
|
|
while (gets(airname))
|
|
|
{
|
|
|
if(strcmp(airname,"@")==0)
|
|
|
{
|
|
|
end=1;
|
|
|
break;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
while (airp != NULL)
|
|
|
{
|
|
|
if (strcmp(airname, airp->airname) == 0)
|
|
|
{
|
|
|
exist = 1;
|
|
|
break;
|
|
|
}
|
|
|
airp = airp->next;
|
|
|
}
|
|
|
if (!exist)
|
|
|
{
|
|
|
printf("\n\t\t该航班不存在...\n");
|
|
|
printf("\n\t\t请重新输入: ");
|
|
|
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
printf("\n\t\t删除成功!");
|
|
|
system("pause");
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
if(end)
|
|
|
{
|
|
|
return ;
|
|
|
}
|
|
|
deleteuser(airname);
|
|
|
airp = airhead;
|
|
|
if (strcmp(airhead->airname,airname) == 0)
|
|
|
airhead = airhead->next;
|
|
|
while (airp->next != NULL)
|
|
|
{
|
|
|
if (strcmp(airp->next->airname, airname) == 0)
|
|
|
{
|
|
|
airp->next = airp->next->next;
|
|
|
break;
|
|
|
}
|
|
|
airp = airp->next;
|
|
|
}
|
|
|
airp = NULL;
|
|
|
writefile(3);
|
|
|
/*printf("\n 输入0返回管理员界面界面: ");
|
|
|
int n;
|
|
|
while (1)
|
|
|
{
|
|
|
scanf("%d", &n);
|
|
|
if (n == 0)
|
|
|
break;
|
|
|
}*/
|
|
|
}
|
|
|
void changeuser(char *s,char *s1,int a)
|
|
|
{
|
|
|
struct userstruct *userp;
|
|
|
userp = userhead;
|
|
|
switch(a)
|
|
|
{
|
|
|
case 1:
|
|
|
{
|
|
|
while (userp != NULL)
|
|
|
{
|
|
|
int i;
|
|
|
for (i = 0; i < userp->aircount1; i++)
|
|
|
{
|
|
|
if (strcmp(userp->uairname[i] , s) == 0)
|
|
|
{
|
|
|
strcpy(userp->uairname[i] , s1);
|
|
|
}
|
|
|
}
|
|
|
userp = userp->next;
|
|
|
}
|
|
|
writefile(0);
|
|
|
}
|
|
|
case 2:
|
|
|
{
|
|
|
while (userp != NULL)
|
|
|
{
|
|
|
int i;
|
|
|
for (i = 0; i < userp->aircount1; i++)
|
|
|
{
|
|
|
if (strcmp(userp->ustart[i] , s) == 0)
|
|
|
{
|
|
|
strcpy(userp->ustart[i] , s1);
|
|
|
}
|
|
|
}
|
|
|
userp = userp->next;
|
|
|
}
|
|
|
writefile(0);
|
|
|
}
|
|
|
case 3:
|
|
|
{
|
|
|
while (userp != NULL)
|
|
|
{
|
|
|
int i;
|
|
|
for (i = 0; i < userp->aircount1; i++)
|
|
|
{
|
|
|
if (strcmp(userp->udes[i] , s) == 0)
|
|
|
{
|
|
|
strcpy(userp->udes[i] , s1);
|
|
|
}
|
|
|
}
|
|
|
userp = userp->next;
|
|
|
}
|
|
|
writefile(0);
|
|
|
}
|
|
|
case 4:
|
|
|
{
|
|
|
while (userp != NULL)
|
|
|
{
|
|
|
int i;
|
|
|
for (i = 0; i < userp->aircount1; i++)
|
|
|
{
|
|
|
if (strcmp(userp->utime[i] , s) == 0)
|
|
|
{
|
|
|
strcpy(userp->utime[i] , s1);
|
|
|
}
|
|
|
}
|
|
|
userp = userp->next;
|
|
|
}
|
|
|
writefile(0);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
void deleteuser(char *s) //传递字符串的位置
|
|
|
{
|
|
|
struct userstruct *userp;
|
|
|
int flag = -1;
|
|
|
userp = userhead;
|
|
|
while (userp != NULL)
|
|
|
{
|
|
|
flag = -1;
|
|
|
int i;
|
|
|
for (i = 0; i < userp->aircount1; i++)
|
|
|
{
|
|
|
if (strcmp(userp->uairname[i] , s) == 0)
|
|
|
{
|
|
|
flag = i;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
if (flag != -1)
|
|
|
{
|
|
|
int i;
|
|
|
for (i = flag; i < userp->aircount1 - 1; i++)
|
|
|
{
|
|
|
strcpy(userp->uairname[i], userp->uairname[i + 1]);
|
|
|
strcpy(userp->ustart[i], userp->ustart[i + 1]);
|
|
|
strcpy(userp->udes[i], userp->udes[i + 1]);
|
|
|
strcpy(userp->utime[i], userp->utime[i + 1]);
|
|
|
userp->urunway[i]= userp->urunway[i + 1];
|
|
|
}
|
|
|
userp->aircount1--;
|
|
|
}
|
|
|
userp = userp->next;
|
|
|
}
|
|
|
writefile(0);
|
|
|
}
|
|
|
void s_add()
|
|
|
{
|
|
|
struct adminstruct *p;
|
|
|
char adminname[20];
|
|
|
char adminmm[100];
|
|
|
FILE *fp;
|
|
|
system("cls");
|
|
|
if(admincount<=20)
|
|
|
{
|
|
|
if(admincount==0)
|
|
|
{
|
|
|
printf("\n\n\n\n\n\n\n");
|
|
|
printf("***************************************************************\n");
|
|
|
printf("\t\t请输入用户名:");
|
|
|
gets(adminname);
|
|
|
strcpy(adminhead->adminname, adminname);
|
|
|
printf("\n\t\t输入密码:");
|
|
|
gets(adminmm);
|
|
|
strcpy(adminhead->adminmm,adminmm);
|
|
|
adminend = adminhead;
|
|
|
adminend->next = NULL;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
printf("\n\n\n\n\n\n\n");
|
|
|
printf("***************************************************************\n");
|
|
|
p=(struct adminstruct *)malloc(sizeof(struct adminstruct));
|
|
|
printf("\t\t请输入用户名:");
|
|
|
gets(adminname);
|
|
|
while(1)
|
|
|
{
|
|
|
if(isexist(adminname,1))
|
|
|
{
|
|
|
printf("\t\t用户名已存在,请重新输入:");
|
|
|
gets(adminname);
|
|
|
}
|
|
|
else
|
|
|
break;
|
|
|
}
|
|
|
strcpy(p->adminname, adminname);
|
|
|
printf("\t\t请输入密码:");
|
|
|
gets(adminmm);
|
|
|
strcpy(p->adminmm, adminmm);
|
|
|
adminend->next = p;
|
|
|
adminend = p;
|
|
|
adminend->next = NULL;
|
|
|
}
|
|
|
admincount++;
|
|
|
fp = fopen("admin", "w");
|
|
|
p = adminhead;
|
|
|
while (p != NULL)
|
|
|
{
|
|
|
fwrite(p, sizeof(struct adminstruct), 1, fp);
|
|
|
p = p->next;
|
|
|
}
|
|
|
fclose(fp);
|
|
|
system("cls");
|
|
|
printf("管理员%s创建成功\n", adminend->adminname);
|
|
|
printf("3秒后自动进入登陆界面....\n");
|
|
|
Sleep(3000);
|
|
|
adminlogin();
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
printf("管理员人数已满!");
|
|
|
system("pause");
|
|
|
printf("按任意键返回上一层....");
|
|
|
}
|
|
|
}
|
|
|
void s_delete()
|
|
|
{
|
|
|
struct adminstruct *adminp;
|
|
|
char adminname[20];
|
|
|
int exist = 0;
|
|
|
int end=0;
|
|
|
adminp = adminhead;
|
|
|
printf("\t\t输入你需要删除的管理员用户名(按@退出): ");
|
|
|
while (gets(adminname))
|
|
|
{
|
|
|
if(strcmp(adminname,"@")==0)
|
|
|
{
|
|
|
end=1;
|
|
|
break;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
while (adminp != NULL)
|
|
|
{
|
|
|
if (strcmp(adminname, adminp->adminname) == 0)
|
|
|
{
|
|
|
exist = 1;
|
|
|
break;
|
|
|
}
|
|
|
adminp = adminp->next;
|
|
|
}
|
|
|
if (!exist)
|
|
|
{
|
|
|
printf("\t\t该管理员不存在!..\n");
|
|
|
printf("\t\t请重新输入: ");
|
|
|
}
|
|
|
else
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
adminp = adminhead;
|
|
|
if (strcmp(adminhead->adminname,adminname) == 0)
|
|
|
adminhead = adminhead->next;
|
|
|
while (adminp->next != NULL)
|
|
|
{
|
|
|
if (strcmp(adminp->next->adminname, adminname) == 0)
|
|
|
{
|
|
|
adminp->next = adminp->next->next;
|
|
|
break;
|
|
|
}
|
|
|
adminp = adminp->next;
|
|
|
}
|
|
|
adminp = NULL;
|
|
|
}
|
|
|
void zhuce()
|
|
|
{
|
|
|
int i;
|
|
|
int end=0;
|
|
|
while(1)
|
|
|
{
|
|
|
system("cls");
|
|
|
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
|
|
|
SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | FOREGROUND_RED);
|
|
|
printf("\n\n\n\n\n\n");
|
|
|
printf(" 1 用户注册\n");
|
|
|
printf(" 2 超级管理员注册\n");
|
|
|
printf(" 0 返回上一层\n");
|
|
|
printf("\n\n\n");
|
|
|
printf(" 请输入你要进行的操作: ");
|
|
|
scanf("%d",&i);
|
|
|
getchar();
|
|
|
switch(i)
|
|
|
{
|
|
|
case 1:userrigester();break;
|
|
|
case 2:superrigerster();break;
|
|
|
case 0:end=1;break;
|
|
|
default:printf(" 错误输入!请重新输入:");
|
|
|
system("pause"); //输出一行 请按任意键继续...
|
|
|
continue;
|
|
|
}
|
|
|
if(end==1)
|
|
|
break; //退出循环
|
|
|
}
|
|
|
}
|
|
|
void userrigester() //参考1402
|
|
|
{
|
|
|
struct userstruct *p;
|
|
|
char username[20];
|
|
|
char usermm[100];
|
|
|
char name[10];
|
|
|
char sex[10];
|
|
|
char tele[20];
|
|
|
char id[20];
|
|
|
FILE *fp;
|
|
|
system("cls");
|
|
|
if (usercount == 0) //第一次添加
|
|
|
{
|
|
|
userhead = (struct userstruct *)malloc(sizeof(struct userstruct));
|
|
|
printf("输入用户名: ");
|
|
|
fflush(stdin);
|
|
|
gets(username);
|
|
|
strcpy(userhead->username, username);
|
|
|
printf("输入密码: ");
|
|
|
fflush(stdin);
|
|
|
gets(usermm);
|
|
|
strcpy(userhead->usermm, usermm);
|
|
|
userhead->aircount1 = 0;
|
|
|
userend = userhead;
|
|
|
userend->next = NULL;
|
|
|
printf("您的真实姓名是: ");
|
|
|
gets(name);
|
|
|
strcpy(userhead->name ,name);
|
|
|
printf("您的性别是:");
|
|
|
gets(sex);
|
|
|
strcpy(userhead->sex ,sex);
|
|
|
printf("您的电话号码是:");
|
|
|
gets(tele);
|
|
|
strcpy(userhead->tele ,tele);
|
|
|
printf("您的身份证号是(必填):");
|
|
|
gets(id);
|
|
|
strcpy(userhead->id ,id);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
p = (struct userstruct *)malloc(sizeof(struct userstruct));
|
|
|
printf("输入用户名: ");
|
|
|
gets(username);
|
|
|
while(1)
|
|
|
{
|
|
|
if (isexist(username, 0))
|
|
|
{
|
|
|
printf("该用户名已经存在!\n");
|
|
|
printf("请重新输入: ");
|
|
|
gets(username);
|
|
|
}
|
|
|
else
|
|
|
break;
|
|
|
}
|
|
|
strcpy(p->username, username);
|
|
|
printf("输入密码: ");
|
|
|
gets(usermm);
|
|
|
strcpy(p->usermm, usermm);
|
|
|
p->aircount1 = 0;
|
|
|
userend->next = p;
|
|
|
userend = p;
|
|
|
userend->next = NULL;
|
|
|
printf("您的真实姓名是: ");
|
|
|
gets(name);
|
|
|
strcpy(p->name ,name);
|
|
|
printf("您的性别是:");
|
|
|
gets(sex);
|
|
|
strcpy(p->sex ,sex);
|
|
|
printf("您的电话号码是:");
|
|
|
gets(tele);
|
|
|
strcpy(p->tele ,tele);
|
|
|
printf("您的身份证号是(必填):");
|
|
|
gets(id);
|
|
|
strcpy(p->id ,id);
|
|
|
}
|
|
|
usercount++;
|
|
|
fp = fopen("user", "w");
|
|
|
p = userhead;
|
|
|
while (p != NULL)
|
|
|
{
|
|
|
fwrite(p, sizeof(struct userstruct), 1, fp);
|
|
|
p = p->next;
|
|
|
}
|
|
|
fclose(fp);
|
|
|
system("cls");
|
|
|
printf("用户%s创建成功\n", userend->username);
|
|
|
printf("3秒后自动返回登陆界面....\n");
|
|
|
Sleep(3000);
|
|
|
dengru();
|
|
|
}
|
|
|
void superrigerster()
|
|
|
{
|
|
|
struct superstruct *p;
|
|
|
char supername[20];
|
|
|
char supermm[100];
|
|
|
FILE *fp;
|
|
|
int i;
|
|
|
system("cls");
|
|
|
char str[100];
|
|
|
char mm[]="pangshou180125"; //初始密码
|
|
|
int j;
|
|
|
printf("请输入初始密码:");
|
|
|
for(j=0;j<100;j++)
|
|
|
{
|
|
|
str[j]=getch();
|
|
|
if(str[j]!=13&&str[j]!=8)
|
|
|
{
|
|
|
printf("*");
|
|
|
}
|
|
|
if(str[j]==8)
|
|
|
{
|
|
|
printf("\b");
|
|
|
j--;
|
|
|
printf(" ");
|
|
|
printf("\b");
|
|
|
j--;
|
|
|
}
|
|
|
if(str[j]==13)
|
|
|
{
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
str[j]='\0';
|
|
|
if(strcmp(mm,str)==0)
|
|
|
{
|
|
|
if(supercount<=5) //超级管理员数量不能多于五个
|
|
|
{
|
|
|
if(supercount==0)
|
|
|
{
|
|
|
superhead = (struct superstruct *)malloc(sizeof(struct superstruct));
|
|
|
printf("\n请输入用户名:");
|
|
|
fflush(stdin); //清空缓存
|
|
|
gets(supername);
|
|
|
strcpy(superhead->supername,supername);
|
|
|
printf("\n请输入密码:");
|
|
|
fflush(stdin); //清空缓存
|
|
|
gets(supermm);
|
|
|
strcpy(superhead->supermm ,supermm);
|
|
|
superend=superhead;
|
|
|
superend->next = NULL;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
p = (struct superstruct *)malloc(sizeof(struct superstruct));
|
|
|
printf("\n请输入用户名:");
|
|
|
gets(supername);
|
|
|
strcpy(superhead->supername,supername);
|
|
|
printf("\n请输入密码:");
|
|
|
gets(supermm);
|
|
|
strcpy(superhead->supermm ,supermm);
|
|
|
superend->next = p;
|
|
|
superend=p;
|
|
|
superend->next =NULL;
|
|
|
}
|
|
|
supercount++;
|
|
|
fp = fopen("super", "w"); //写入文件
|
|
|
p = superhead;
|
|
|
while (p != NULL)
|
|
|
{
|
|
|
fwrite(p, sizeof(struct superstruct), 1, fp); //从p读取数据写入fp指向的文件super中
|
|
|
p = p->next;
|
|
|
}
|
|
|
fclose(fp);
|
|
|
system("cls");
|
|
|
printf("超级管理员%s创建成功\n", superend->supername);
|
|
|
printf("3秒后进入登陆界面....\n");
|
|
|
Sleep(3000); //windows下函数延时,程序暂停3秒时间
|
|
|
dengru();
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
printf("密码错误!\n");
|
|
|
printf("继续输入密码或者退出\n");
|
|
|
printf("1 退出\n2 返回上一层\n");
|
|
|
printf("请输入您的选择:");
|
|
|
scanf("%d",&i);
|
|
|
if(i==1)
|
|
|
{
|
|
|
home();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
void superfile()
|
|
|
{
|
|
|
struct superstruct *p;
|
|
|
FILE *fp;
|
|
|
p = superhead;
|
|
|
fp = fopen("super", "ab+");
|
|
|
while (fread(p, sizeof(struct superstruct), 1, fp))
|
|
|
{
|
|
|
if (p->next != NULL)
|
|
|
{
|
|
|
p = (struct superstruct *)malloc(sizeof(struct superstruct));
|
|
|
superend->next = p;
|
|
|
superend = p;
|
|
|
superend->next = NULL;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
void airfile()
|
|
|
{
|
|
|
struct airstruct *p;
|
|
|
FILE *fp;
|
|
|
p = airhead;
|
|
|
fp = fopen("air", "ab+");
|
|
|
while (fread(p, sizeof(struct airstruct), 1, fp))
|
|
|
{
|
|
|
if (p->next != NULL)
|
|
|
{
|
|
|
p = (struct airstruct *)malloc(sizeof(struct airstruct));
|
|
|
airend->next = p;
|
|
|
airend = p;
|
|
|
airend->next = NULL;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
void userfile()//同下
|
|
|
{
|
|
|
struct userstruct *p;
|
|
|
FILE *fp;
|
|
|
p = userhead;
|
|
|
fp = fopen("user", "ab+");
|
|
|
while (fread(p,sizeof(struct userstruct),1,fp))
|
|
|
{
|
|
|
if (p->next != NULL)
|
|
|
{
|
|
|
p = (struct userstruct *)malloc(sizeof(struct userstruct));
|
|
|
userend->next = p;
|
|
|
userend = p;
|
|
|
userend->next = NULL;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
void adminfile() //读取数据 ,建立链表
|
|
|
{
|
|
|
struct adminstruct *p;
|
|
|
FILE *fp;
|
|
|
p = adminhead;
|
|
|
fp = fopen("admin", "ab+");
|
|
|
while (fread(p, sizeof(struct adminstruct), 1, fp))
|
|
|
{
|
|
|
if (p->next != NULL)
|
|
|
{
|
|
|
p = (struct adminstruct *)malloc(sizeof(struct adminstruct)); //为链表的建立分配内存
|
|
|
adminend->next = p;
|
|
|
adminend = p;
|
|
|
adminend->next = NULL;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
void writefile(int flag) //'写文件',修改数据时引用
|
|
|
{
|
|
|
FILE *fp;
|
|
|
struct userstruct *userp;
|
|
|
struct adminstruct *adminp;
|
|
|
struct superstruct *superp;
|
|
|
struct airstruct *airp;
|
|
|
userp = userhead;
|
|
|
adminp = adminhead;
|
|
|
superp = superhead;
|
|
|
airp = airhead;
|
|
|
if (flag == 0)
|
|
|
{
|
|
|
fp = fopen("user", "w");
|
|
|
while (userp != NULL)
|
|
|
{
|
|
|
fwrite(userp, sizeof(struct userstruct), 1, fp);
|
|
|
userp = userp->next;
|
|
|
}
|
|
|
}
|
|
|
else if (flag == 1)
|
|
|
{
|
|
|
fp = fopen("admin", "w");
|
|
|
|
|
|
while (adminp != NULL)
|
|
|
{
|
|
|
fwrite(adminp, sizeof(struct adminstruct), 1, fp);
|
|
|
adminp = adminp->next;
|
|
|
}
|
|
|
}
|
|
|
else if(flag==2)
|
|
|
{
|
|
|
fp = fopen("super", "w");
|
|
|
while (superp != NULL)
|
|
|
{
|
|
|
fwrite(superp, sizeof(struct superstruct), 1, fp);
|
|
|
superp = superp->next;
|
|
|
}
|
|
|
}
|
|
|
else if(flag==3)
|
|
|
{
|
|
|
fp = fopen("air","w");
|
|
|
while(airp!=NULL)
|
|
|
{
|
|
|
fwrite(airp, sizeof(struct airstruct), 1, fp);
|
|
|
airp = airp->next ;
|
|
|
}
|
|
|
}
|
|
|
fclose(fp);
|
|
|
}
|