东北大学20级计算机C语言课设-航空订票系统

航空订票系统

开发人员:东北大学20级计算机系学生
开发团队:三人小组
开发语言:C语言
开发工具:vs2015
有疑问欢迎进行讨论
总代码数量大概在三千五百行左右
耗时近一个月的时间完成了该次课设,写此博客作为分享同时也纪念第一个开发一个大的项目
主要添加了eazyx,实现了可视化的操作
整个程序分为两大块,员工界面和顾客界面
员工界面可进行个人信息的查询和修改,查看某一天某趟航班的座位情况以及乘客的具体信息
顾客界面可进行个人信息的查询和修改,进行机票的购买,对已购买机票的查询
主要的特色:实现了程序的可长久发展,不仅仅局限于固定的时间期内
注:以下代码并不完整,有些自定义的函数并未贴出,详情可私信我要源码

一、基本信息

1、主函数

主要通过一个全局变量i进行页面的控制

//界面的控制
int main()
{
	initgraph(1280, 800);
	SetWindowText(hWnd, "XXX航空机票预订系统");// 使用 Windows API 修改窗口名称

	setbkcolor(WHITE);
	cleardevice();

	CreateThread(NULL, 0, showtime, NULL, 0, NULL);

	canfnowtime();//可支持查询的时间

	weainformation();//生成十天内的天气信息
	loadweather();//加载天气

	loadimage(&bk, "背景.jfif", 1280, 750);

	while (1)
	{
		while (i == 0)
		{
			BeginBatchDraw();
			star();
			nowload();
			EndBatchDraw();

			getchar();
			i++;
		}

		MOUSEMSG m;//定义鼠标信息

		while (i == 1)//登陆界面
		{
			BeginBatchDraw();

			regist();
			loadbottom(&work);
			loadbottom(&customer);
			loadbottom(&post);
			loadbottom(&recode);

			m = GetMouseMsg();

			if (mousebottom(&work, m))//鼠标在员工登录按钮里
			{
				if (m.mkLButton)
				{
					man = 1;
					loadwork();//若账户密码正确则进入员工界面	
					i++;
				}
			}
			if (mousebottom(&customer, m))//鼠标在顾客登录按钮里
			{
				if (m.mkLButton)
				{
					man = 2;
					loadcustomer();//若账户密码正确则进入顾客界面
					i++;
				}
			}
			if (mousebottom(&post, m))//鼠标在注册账号按钮里
			{
				if (m.mkLButton)
				{
					poster();
				}
			}
			if (mousebottom(&recode, m))//鼠标在忘记密码按钮里
			{
				if (m.mkLButton)
				{
					repass();
				}
			}
			EndBatchDraw();

			FlushMouseMsgBuffer();
		}

		while (i == 2)//员工或顾客界面
		{
			BeginBatchDraw();

			nowload();

			putimage(0, 50, &bk);
			if (man == 1)
			{
				loadbottom(&maindata1);
				loadbottom(&planedata1);
				loadbottom(&quit1);//按钮设置

				m = GetMouseMsg();

				if (mousebottom(&maindata1, m))//查看个人信息
				{
					if (m.mkLButton)
					{
						i++;
						loaddate();
					}
				}
				if (mousebottom(&planedata1, m))//查看航班信息
				{
					if (m.mkLButton)
					{
						i++;
						InputBox(iptime, 9, "可支持查询现在至十天后的航班信息(格式如20210101)");
						if ((strlen(iptime) != 8))
						{
							MessageBoxA(hWnd, "格式不正确请重试", "提示", MB_OK);
							i--;
						}
						else if (!checkuptime())
						{
							MessageBoxA(hWnd, "仅支持查询十天内的航班", "提示", MB_OK);
							i--;
						}
						else
						{
							flightdata();
						}
					}
				}
				if (mousebottom(&quit1, m))//退出当前登录
				{
					if (m.mkLButton)
					{
						Sleep(500);
						i = 0;
						man = 0;
					}
				}
			}
			else
			{
				loadbottom(&maindata2);
				loadbottom(&planedata2);
				loadbottom(&bugtick2);
				loadbottom(&quit2);//按钮设置

				m = GetMouseMsg();

				if (mousebottom(&maindata2, m))//查看个人信息
				{
					if (m.mkLButton)
					{
						i++;
						loaddate();
					}
				}
				if (mousebottom(&planedata2, m))//查看航班信息
				{
					if (m.mkLButton)
					{
						i++;
						InputBox(iptime, 9, "可支持查询现在至十天后的航班信息(格式如20210101)");
						if ((strlen(iptime) != 8))
						{
							MessageBoxA(hWnd, "格式不正确请重试", "提示", MB_OK);
							i--;
						}
						else if (!checkuptime())
						{
							MessageBoxA(hWnd, "仅支持查询十天内的航班", "提示", MB_OK);
							i--;
						}
						else
						{
							flightdata();
						}
					}
				}
				if (mousebottom(&bugtick2, m))//查看购票信息
				{
					if (m.mkLButton)
					{
						i++;
						bugdata();
					}
				}
				if (mousebottom(&quit2, m))//退出当前登录
				{
					if (m.mkLButton)
					{
						Sleep(500);
						i = 0;
						man = 0;
					}
				}

			}
			EndBatchDraw();

			FlushMouseMsgBuffer();
		}
	}

	closegraph();
}

2、全局变量和结构体

整个程序中会用到的结构体和链表

//定义结构体

struct bottom//定义按钮
{
	int x1;//按钮左上角坐标
	int y1;
	int x2;//按钮右下角坐标
	int y2;
	COLORREF color;
	char text[100];
	int page;//按钮的页码
};
struct workman//员工信息
{
	char num[5];//员工编号,四位
	char code[9];//八位密码
	char name[5];//员工姓名
	char idnumber[19];//身份证号
	char phonum[12];//手机号
	char sex[10];//性别
};
struct cusman//顾客信息
{
	char phonum[12];//手机号
	char code[9];//密码
	char name[10];//顾客姓名
	char idnumber[19];//身份证号
	char num[5];//顾客编号
	char sex[10];//性别
	char flytime[4];//已经乘坐过航班的次数
};
struct weather//天气信息
{
	int num;
	int weatype;//1代表晴,2代表多云,3代表少云,4代表雨,5代表阴,6代表多风
};
struct lover//伴侣信息
{
	char man[5];
	char woman[5];
	char start[10];
	char final[10];
};
struct seat
{
	char seatnum[4];
	struct cusman data;
	struct seat* next;
};
struct Flight
{
	char pdeparture[10];//出发地
	char pdestination[10];//目的地
	char tdaparture[10];//出发时间
	char tdestination[10];//落地时间
	char number[10];//航班编号
	char tnumber[9];//总
	char rnumber[9];//剩余
	char price[9];//价格
};

//定义链表
struct cuslist
{
	struct cusman data;
	struct cuslist *next;
};
struct worklist
{
	struct workman data;
	struct worklist *next;
};
struct weatherlist
{
	struct weather data;
	struct weatherlist *next;
};
struct loverlist
{
	struct lover data;
	struct loverlist *next;
};
struct Flightlist
{
	struct Flight data;
	char time[9];
	char seatnum[4];
	struct Flightlist *next;
};

所用到的全局变量

extern int n;
extern IMAGE bk;//设置背景图片
extern HWND hWnd;// 获得窗口句柄
extern int man;//用于判断登录类型,1代表员工登录,2代表顾客登录
extern int i;//用于控制页面
extern int k;//控制按键
extern int m;//已购买的座位
extern char iptime[9];//用户输入时间

//按钮的定义
extern struct bottom work;
extern struct bottom customer;
extern struct bottom post;
extern struct bottom recode;
extern struct bottom re;
extern struct bottom maindata1;
extern struct bottom planedata1;
extern struct bottom quit1;
extern struct bottom maindata2;
extern struct bottom planedata2;
extern struct bottom bugtick2;
extern struct bottom quit2;
extern struct bottom correct;

//航班的定义
extern struct Flight one;
extern struct Flight two;
extern struct Flight three;
extern struct Flight four;
extern struct Flight five;

//当前登录账户信息
extern struct workman *worker;
extern struct cusman *cuser;
extern struct lover *cuslover;

//可支持查询的时间
extern struct tm *pt;
extern struct tm nowtime;
extern struct tm futuretime;

//用户查询的时间
extern struct tm inputtime;

3、头文件和cpp文件

在这里插入图片描述

4、开始界面

在这里插入图片描述

二、时间系统

主要是同步系统时间,然后判断查询航班时的时间是否正确

1、同步系统时间

采用了多线程的方式,可以独立的刷新时间
该系统也是本程序能够实现长久运行的基础

//多线程程序与系统时间同步显示
DWORD WINAPI showtime(LPVOID lpParamter)
{
	char str[50];

	while (1)
	{
		BeginBatchDraw();

		function1(str);//初始化字符串数组

		time_t timep;
		struct tm *p;
		time(&timep);
		p = localtime(&timep);

		sprintf(str, "%d.%2d.%2d %d:%02d", 1900 + p->tm_year, 1 + p->tm_mon, p->tm_mday, p->tm_hour, p->tm_min);

		RECT r = { 1080,0,1280,50 };//字符串输出的矩形区域

		setfillcolor(WHITE);
		fillrectangle(1080, 0, 1280, 50);
		fillrectangle(0, 0, 200, 50);

		settextstyle(10, 10, "行楷");
		settextcolor(RED);
		setbkmode(TRANSPARENT);
		drawtext(str, &r, DT_CENTER | DT_VCENTER | DT_SINGLELINE);//将字符居中显示

		EndBatchDraw();
		Sleep(60000);
	}

	return 0L;
}

2、判断查询时间是否正确

//判断输入的时间格式是否正确
int checkuptime()
{
	int k = 0;
	long s = atoi(iptime);
	int year, day, mouth;
	day = s % 100;
	mouth = (s % 10000 - day) / 100;
	year = ((s - day) / 100 - mouth) / 100;

	inputtime.tm_year = year;
	inputtime.tm_mon = mouth;
	inputtime.tm_mday = day;

	if (futuretime.tm_year > nowtime.tm_year)
	{
		if ((year == futuretime.tm_year || year == nowtime.tm_year) && (mouth == 12 || mouth == 1) && ((day <= 31 && day >= nowtime.tm_mday) || (day >= 1 && day <= futuretime.tm_mday)))
		{
			return 1;
		}
		else
			return 0;
	}
	else
	{
		if (year == futuretime.tm_year)
		{
			if (futuretime.tm_mon > nowtime.tm_mon)
			{
				if ((mouth == futuretime.tm_mon || mouth == nowtime.tm_mon) && ((day <= 31 && day >= nowtime.tm_mday) || (day >= 1 && day <= futuretime.tm_mday)))
				{
					return 1;
				}
				else
				{
					return 0;
				}
			}
			else
			{
				if (mouth == futuretime.tm_mon && (day <= futuretime.tm_mday && day >= nowtime.tm_mday))
				{
					return 1;
				}
				else
				{
					return 0;
				}
			}
		}
		else
		{
			return 0;
		}
	}
}

3、加载可支持查询的时间

计算出可支持查询时间,赋给全局变量
使用了time.h里的函数

//加载可支持查询的时间
void canfnowtime()
{
	time_t ntsec;
	time(&ntsec);
	pt = localtime(&ntsec);
	nowtime.tm_year = pt->tm_year + 1900;
	nowtime.tm_mon = pt->tm_mon + 1;
	nowtime.tm_mday = pt->tm_mday;
	ntsec += 864000;
	pt = localtime(&ntsec);
	futuretime.tm_year = pt->tm_year + 1900;
	futuretime.tm_mon = pt->tm_mon + 1;
	futuretime.tm_mday = pt->tm_mday;
}

三、天气系统

1、天气信息读取插入保存

先读入文本里存的天气信息

struct weatherlist *inputwth()
{
	FILE *fp = fopen("天气信息.txt", "r+");
	int m = daydiff(nowtime.tm_year, nowtime.tm_mon, nowtime.tm_mday);
	int n = 1;
	struct weatherlist *head = NULL;
	struct weatherlist *p1, *p2;
	p1 = (struct weatherlist *)malloc(sizeof(struct weatherlist));
	p2 = (struct weatherlist *)malloc(sizeof(struct weatherlist));
	if (yncontent("天气信息.txt"))
	{
		while (!feof(fp))
		{
			fscanf(fp, "%d %d\n", &p1->data.num, &p1->data.weatype);
			if (n == 1)
			{
				head = p1;
				n++;
			}
			else
			{
				p2->next = p1;
				n++;
			}
			p2 = p1;
			p1 = (struct weatherlist *)malloc(sizeof(struct weatherlist));
		}
		p2->next = NULL;
	}
	fclose(fp);
	return head;
}

对新的天气进行创建,目前设置为创建到当天时间往后十天的天气

struct weatherlist *newweather(struct weatherlist *head)
{
	int j = daydiff(futuretime.tm_year, futuretime.tm_mon, futuretime.tm_mday);
	struct weatherlist *p1, *p2, *p3;
	int m = 0, n = 1;
	p1 = (struct weatherlist *)malloc(sizeof(struct weatherlist));
	p2 = inputwth();
	p3 = head;
	while (p2 != NULL)
	{
		m = p2->data.num + 1;
		p2 = p2->next;
	}
	while (p3 != NULL  && p3->data.num != m - 1)
	{
		p3 = p3->next;
	}
	while (m <= j)
	{
		p1->data.num = m;
		m++;
		p1->data.weatype = random(6, 1);
		if (m == 1)head = p1;
		else p3->next = p1;
		p3 = p1;
		n++;
		p1 = (struct weatherlist *)malloc(sizeof(struct weatherlist));
	}
	p3->next = NULL;
	return head;
}

查找到当天的天气

struct weatherlist *findweather(struct weatherlist *head, int m)
{
	while (head != NULL)//找到当天的天气信息
	{
		if (head->data.num == m)
		{
			break;
		}
		head = head->next;
	}
	return head;
}

保存至文本

void keepdata(struct weatherlist *head)
{
	FILE *fp = fopen("天气信息.txt", "w");
	while (head != NULL)
	{
		fprintf(fp, "%d %d\n", head->data.num, head->data.weatype);
		head = head->next;
	}
	fclose(fp);
}

2、创建天气信息

在程序运行界面加载出来前,进行天气信息的创建
采用随机数种子,伪随机的创建天气

//创建天气信息
void weainformation()
{
	struct weatherlist *head;
	srand((unsigned int)time(0));//修改种子
	head = inputwth();
	head = newweather(head);
	keepdata(head);
}

3、加载天气情况

设置了6种天气

//加载天气情况
void showweather(struct weather *p, RECT r)
{
	char str[20];
	switch (p->weatype)
	{
	case 1:sprintf(str, "天气:晴"); break;
	case 2:sprintf(str, "天气:多云"); break;
	case 3:sprintf(str, "天气:少云"); break;
	case 4:sprintf(str, "天气:雨"); break;
	case 5:sprintf(str, "天气:阴"); break;
	case 6:sprintf(str, "天气:多风"); break;
	default:
		break;
	}
	drawtext(str, &r, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
}

4、显示当天的天气

//显示当前天气情况
void loadweather()
{
	RECT r = { 540,0,740,50 };//显示天气信息的区域

	setfillcolor(WHITE);
	fillrectangle(0, 0, 200, 50);
	settextstyle(10, 10, "行楷");
	settextcolor(RED);
	setbkmode(TRANSPARENT);
	int m = daydiff(nowtime.tm_year, nowtime.tm_mon, nowtime.tm_mday);
	struct weatherlist *head;
	head = inputwth();
	head = findweather(head, m);
	showweather(&head->data, r);
}

5、显示查询的天气

在航班查询时,进行查询当天天气信息的显示

//显示选择查询时间的天气情况
void inquireweather(struct weatherlist *head)
{
	RECT r = { 1080,50,1280,100 };
	setfillcolor(RGB(137, 145, 255));
	solidroundrect(1080, 50, 1280, 100, 15, 15);

	int m = daydiff(inputtime.tm_year, inputtime.tm_mon, inputtime.tm_mday);
	head = findweather(head, m);
	showweather(&head->data, r);
}

四、伴侣系统

这也是我选择此项目作为本次课设的原因
也是我最想要完成的一个系统,也算是我们此次课设的特色之一吧
每个用户可以进行伴侣的绑定,并选择一趟优惠航班
(最初是打算给每个用户一个地址,然后选择该地址到伴侣地址的航班时进行优惠,后面采取了简化)
若选择优惠航班,则会对机票价格减半
但绑定后将无法更改

1、进行绑定

//账号进行绑定
int bind()
{
	char str[4][10];
	InputBox(str[0], 5, "请输入用户的姓名:");
	if (strlen(str[0]))
	{
		InputBox(str[1], 10, "请输入一个地点:");
		if (strlen(str[1]))
		{
			InputBox(str[2], 10, "请输入另一个地点:");
			if (strlen(str[2]))
			{
				int a = checkupsex(str[0]);
				int j = checkupplane(str[1], str[2]);
				if (j == 1)//存在该趟航班
				{
					if (a == 1)
					{
						strcpy(cuslover->start, str[1]);
						strcpy(cuslover->final, str[2]);
						if (strcmp(cuser->sex, "man") == 0)
						{
							strcpy(cuslover->man, cuser->name);
							strcpy(cuslover->woman, str[0]);
						}
						else if (strcmp(cuser->sex, "woman") == 0)
						{
							strcpy(cuslover->man, str[0]);
							strcpy(cuslover->woman, cuser->name);
						}
						MessageBox(hWnd, "绑定成功", "提示", MB_OK);
						return 1;
					}
					else if (a == 2)
					{
						MessageBox(hWnd, "暂不支持同性进行绑定", "提示", MB_OK);
					}
					else if (a == 3)
					{
						MessageBox(hWnd, "该用户已绑定请重试", "提示", MB_OK);
					}
					else
					{
						MessageBox(hWnd, "该账户未注册", "提示", MB_OK);
					}
				}
				else
				{
					MessageBox(hWnd, "不存在该趟航班请重试", "提示", MB_OK);
				}
			}
			else
			{
				MessageBox(hWnd, "格式错误", "提示", MB_OK);
			}
		}
		else
		{
			MessageBox(hWnd, "格式错误", "提示", MB_OK);
		}
	}
	else
	{
		MessageBox(hWnd, "格式错误", "提示", MB_OK);
	}
	return 0;
}

2、查询航班是否存在

//查找是否存在该趟航班
int checkupplane(char *start, char *final)
{
	if ((strcmp(start, one.pdeparture) == 0 && strcmp(final, one.pdestination) == 0) || (strcmp(final, one.pdeparture) == 0 && strcmp(start, one.pdestination) == 0))
	{
		return 1;
	}
	else if ((strcmp(start, two.pdeparture) == 0 && strcmp(final, two.pdestination) == 0) || (strcmp(final, two.pdeparture) == 0 && strcmp(start, two.pdestination) == 0))
	{
		return 1;
	}
	else if ((strcmp(start, three.pdeparture) == 0 && strcmp(final, three.pdestination) == 0) || (strcmp(final, three.pdeparture) == 0 && strcmp(start, three.pdestination) == 0))
	{
		return 1;
	}
	else if ((strcmp(start, four.pdeparture) == 0 && strcmp(final, four.pdestination) == 0) || (strcmp(final, four.pdeparture) == 0 && strcmp(start, four.pdestination) == 0))
	{
		return 1;
	}
	else if ((strcmp(start, five.pdeparture) == 0 && strcmp(final, five.pdestination) == 0) || (strcmp(final, five.pdeparture) == 0 && strcmp(start, five.pdestination) == 0))
	{
		return 1;
	}
	else
	{
		return 0;
	}
}

3、判断性别是否为异性,以及用户是否存在和是否绑定

//查找绑定账号是否存在并且是否为异性且该账户未被绑定
int checkupsex(char *name)
{
	int a;
	//判断账号是否存在并且是否为异性
	struct cuslist *head = inputcus();
	while (head != NULL)
	{
		if (strcmp(head->data.name, name) == 0)
		{
			if (strcmp(head->data.sex, cuser->sex) != 0)
				a = 1;//存在且为异性
			else
				a = 2;//存在为同性
			break;
		}
		head = head->next;
		a = 0;//账号不存在
	}
	//判断该账号是否绑定
	if (a == 1)
	{
		struct loverlist *p = inputlove();
		while (p != NULL)
		{
			if (strcmp(p->data.man, name) == 0 || strcmp(p->data.woman, name) == 0)
			{
				a = 3;//账号已被绑定
			}
			p = p->next;
		}
	}

	return a;
}

4、加载绑定信息

//查找绑定账号是否存在并且是否为异性且该账户未被绑定
int checkupsex(char *name)
{
	int a;
	//判断账号是否存在并且是否为异性
	struct cuslist *head = inputcus();
	while (head != NULL)
	{
		if (strcmp(head->data.name, name) == 0)
		{
			if (strcmp(head->data.sex, cuser->sex) != 0)
				a = 1;//存在且为异性
			else
				a = 2;//存在为同性
			break;
		}
		head = head->next;
		a = 0;//账号不存在
	}
	//判断该账号是否绑定
	if (a == 1)
	{
		struct loverlist *p = inputlove();
		while (p != NULL)
		{
			if (strcmp(p->data.man, name) == 0 || strcmp(p->data.woman, name) == 0)
			{
				a = 3;//账号已被绑定
			}
			p = p->next;
		}
	}

	return a;
}

五、注册和忘记账号

1、注册账号

//注册账号
void poster()
{
	MOUSEMSG m;

	struct bottom workpost = { 200, 500, 600, 700, YELLOW, "员工注册" ,1 };
	struct bottom cuspost = { 680, 500, 1080, 700, YELLOW, "顾客注册" ,1 };

	while (i == 1)
	{
		BeginBatchDraw();
		putimage(0, 50, &bk);

		loadbottom(&re);
		loadbottom(&workpost);
		loadbottom(&cuspost);

		RECT r = { 240, 200, 1040, 400 };
		settextcolor(RGB(85, 117, 246));
		settextstyle(30, 30, "行楷");
		setbkmode(TRANSPARENT);
		drawtext("请选择账号注册类型", &r, DT_CENTER | DT_VCENTER | DT_SINGLELINE);

		m = GetMouseMsg();

		if (mousebottom(&re, m))//返回
		{
			if (m.mkLButton)
			{
				break;
			}
		}
		if (mousebottom(&workpost, m))//员工注册
		{
			if (m.mkLButton)
			{
				FILE *fp = fopen("员工信息.txt", "r");
				if (fp == NULL)
				{
					fp = fopen("员工信息.txt", "w");
				}//判断文本文件是否存在,若不存在则创建
				fclose(fp);
				man = 1;
				inputdatawork();//填写注册信息并写入文件夹
			}

		}
		if (mousebottom(&cuspost, m))//顾客注册
		{

			if (m.mkLButton)
			{
				FILE *fp = fopen("顾客信息.txt", "r");
				if (fp == NULL)
				{
					fp = fopen("顾客信息.txt", "w");
				}//判断文本文件是否存在,若不存在则创建
				fclose(fp);
				man = 2;
				inputdatacus();
			}

		}

		EndBatchDraw();
		FlushMouseMsgBuffer();
	}

}

2、判断账户是否存在

一个身份证号或者电话号码仅能绑定一个账号

//检查当前注册账号信息是否已存在,保证一身份证号或者一手机号绑定一个账号
int checkup(struct workman *p)
{
	struct worklist *head = inputwork();
	while (head != NULL)
	{
		if (strcpy(head->data.phonum, p->phonum) == 0 || strcpy(head->data.idnumber, p->idnumber) == 0)
		{
			return 0;
		}
		head = head->next;
	}
	return 1;
}
int checkup(struct cusman *p)
{
	struct cuslist *head = inputcus();
	while (head != NULL)
	{
		if (strcpy(head->data.phonum, p->phonum) == 0 || strcpy(head->data.idnumber, p->idnumber) == 0)
		{
			return 0;
		}
		head = head->next;
	}
	return 1;
}

3、存入注册信息

//存入注册员工信息
void inputdatawork()
{
	struct worklist *head = (struct worklist *)malloc(sizeof(struct worklist));
	struct workman *p = (struct workman*)malloc(sizeof(struct workman));
	head = inputwork();//存入数据
	InputBox(p->name, 5, "请输入你的名字");
	if (strlen(p->name) == 0)
	{
		MessageBoxA(hWnd, "格式不正确请重试", "提示", MB_OK);
		man = 0;
	}
	else
	{
		InputBox(p->code, 9, "请输入八位密码");
		if (strlen(p->code) != 8)
		{
			MessageBoxA(hWnd, "格式不正确请重试", "提示", MB_OK);
			man = 0;
		}
		else
		{
			InputBox(p->idnumber, 19, "请输入你的身份证号");
			if (strlen(p->idnumber) != 18)
			{
				MessageBoxA(hWnd, "格式不正确请重试", "提示", MB_OK);
				man = 0;
			}
			else
			{
				InputBox(p->phonum, 12, "请输入你的电话号码");
				if (strlen(p->phonum) != 11)
				{
					MessageBoxA(hWnd, "格式不正确请重试", "提示", MB_OK);
					man = 0;
				}
				else
				{
					InputBox(p->sex, 6, "请输入你的性别(woman or man)");
					if (strncmp(p->sex, "woman", 5) == 0 || strncmp(p->sex, "man", 3) == 0)
					{
						if (!checkup(p))//已存在用户信息,重新注册
						{
							MessageBoxA(hWnd, "已存在该用户信息,请重新进行注册", "提示", MB_OK);
							man = 0;
						}
						else
						{
							head = newwork(head, p);
							keepdata(head);
							worker = p;//输入正确则将注册信息传递给当前登录用户
							i++;//进入下一界面
						}
					}
					else
					{
						MessageBoxA(hWnd, "格式不正确请重试", "提示", MB_OK);
						man = 0;
					}
				}
			}
		}
	}
}
//存入注册顾客信息
void inputdatacus()
{
	struct cuslist *head = (struct cuslist *)malloc(sizeof(struct cuslist));
	struct cusman *p = (struct cusman *)malloc(sizeof(struct cusman));
	head = inputcus();
	InputBox(p->name, 5, "请输入你的名字");
	if (strlen(p->name) == 0)
	{
		MessageBoxA(hWnd, "格式不正确请重试", "提示", MB_OK);
		man = 0;
	}
	else
	{
		InputBox(p->code, 9, "请输入八位密码");
		if (strlen(p->code) != 8)
		{
			MessageBoxA(hWnd, "格式不正确请重试", "提示", MB_OK);
			man = 0;
		}
		else
		{
			InputBox(p->idnumber, 19, "请输入你的身份证号");
			if (strlen(p->idnumber) != 18)
			{
				MessageBoxA(hWnd, "格式不正确请重试", "提示", MB_OK);
				man = 0;
			}
			else
			{
				InputBox(p->phonum, 12, "请输入你的电话号码");
				if (strlen(p->phonum) != 11)
				{
					MessageBoxA(hWnd, "格式不正确请重试", "提示", MB_OK);
					man = 0;
				}
				else
				{
					InputBox(p->sex, 6, "请输入你的性别(woman or man)");
					if (strncmp(p->sex, "woman", 5) == 0 || strncmp(p->sex, "man", 3) == 0)
					{
						if (!checkup(p))//已存在用户信息,重新注册
						{
							MessageBoxA(hWnd, "已存在该用户信息,请重新进行注册", "提示", MB_OK);
							man = 0;
						}
						else
						{
							head = newcus(head, p);
							keepdata(head);
							cuser = p;//输入正确则将注册信息传递给当前登录用户
							i++;//进入下一界面
						}
					}
					else
					{
						MessageBoxA(hWnd, "格式不正确请重试", "提示", MB_OK);
						man = 0;
					}
				}
			}
		}
	}
}

4、忘记密码

//忘记密码
void repass()
{
	MOUSEMSG m;

	struct bottom workpost = { 200, 500, 600, 700, YELLOW, "员工" ,1 };
	struct bottom cuspost = { 680, 500, 1080, 700, YELLOW, "顾客" ,1 };

	while (i == 1)
	{
		BeginBatchDraw();
		putimage(0, 50, &bk);

		loadbottom(&re);
		loadbottom(&workpost);
		loadbottom(&cuspost);

		RECT r = { 240, 200, 1040, 400 };
		settextcolor(RGB(85, 117, 246));
		settextstyle(30, 30, "行楷");
		setbkmode(TRANSPARENT);
		drawtext("请选择账号类型", &r, DT_CENTER | DT_VCENTER | DT_SINGLELINE);

		m = GetMouseMsg();

		if (mousebottom(&re, m))
		{
			if (m.mkLButton)
			{
				break;
			}
		}
		if (mousebottom(&workpost, m))
		{
			if (m.mkLButton)
			{
				char data1[12];
				char data2[9];

				InputBox(data1, 12, "请输入账户绑定的电话号码");
				if (strlen(data1) != 11)
				{
					MessageBoxA(hWnd, "格式不正确请重试", "提示", MB_OK);
				}
				else
				{
					InputBox(data2, 9, "请输入修改后的密码");
					if (strlen(data2) != 8)
					{
						MessageBoxA(hWnd, "格式不正确请重试", "提示", MB_OK);
					}
					else
					{
						int m = 0;
						FILE *fp = fopen("员工信息.txt", "r+");
						if (fp == NULL || yncontent("员工信息.txt"))
						{
							MessageBoxA(hWnd, "还未注册请先注册", "提示", MB_OK);
							break;
						}
						else
						{
							struct workman *p1, *p2;
							p1 = (struct workman*)malloc(sizeof(struct workman));
							p2 = (struct workman*)malloc(sizeof(struct workman));

							char str[5];
							while (!feof(fp))
							{
								fscanf(fp, "%s %s %s %s %s %s", p1->num, p1->code, p1->name, p1->idnumber, p1->phonum, p1->sex);
								if (strcmp(p1->phonum, data1) == 0)//找到该账号,m=1
								{
									m = 1;
									break;
								}
							}
							if (m == 1)//该账户存在
							{
								sprintf(str, "%d", atoi(p1->num) - 1);
								rewind(fp);
								while (!feof(fp))
								{
									fscanf(fp, "%s %s %s %s %s %s", p2->num, p2->code, p2->name, p2->idnumber, p2->phonum, p2->sex);
									if (strcmp(p2->num, str) == 0)
									{
										strcpy(p1->code, data2);
										break;
									}
								}
								fseek(fp, 0l, 1);
								worker = p1;
								fprintf(fp, "\n%s %s %s %s %s %s", worker->num, worker->code, worker->name, worker->idnumber, worker->phonum, worker->sex);
								MessageBoxA(hWnd, "密码修改成功", "提示", MB_OK);
								man = 1;
								i++;
							}
							else//该账户不存在
							{
								MessageBoxA(hWnd, "不存在该账户请重试", "提示", MB_OK);
							}
							free(p1);
							free(p2);
							fclose(fp);
						}
					}
				}
			}
		}
		if (mousebottom(&cuspost, m))
		{
			if (m.mkLButton)
			{
				char data1[12];
				char data2[9];

				InputBox(data1, 12, "请输入账户绑定的电话号码");
				if (strlen(data1) != 11)
				{
					MessageBoxA(hWnd, "格式不正确请重试", "提示", MB_OK);
				}
				else
				{
					InputBox(data2, 9, "请输入修改后的密码");
					if (strlen(data2) != 8)
					{
						MessageBoxA(hWnd, "格式不正确请重试", "提示", MB_OK);
					}
					else
					{
						int m = 0;
						FILE *fp = fopen("顾客信息.txt", "r+");
						if (fp == NULL || !yncontent("顾客信息.txt"))
						{
							MessageBoxA(hWnd, "还未注册请先注册", "提示", MB_OK);
							break;
						}
						else
						{
							struct cusman *p1, *p2;
							p1 = (struct cusman *)malloc(sizeof(struct cusman));
							p2 = (struct cusman *)malloc(sizeof(struct cusman));

							char str[5];
							while (!feof(fp))
							{
								fscanf(fp, "%s %s %s %s %s %s %s", p1->phonum, p1->code, p1->name, p1->idnumber, p1->num, p1->sex, p1->flytime);
								if (strcmp(data1, p1->phonum) == 0)//找到账户信息
								{
									m = 1;
									break;
								}
							}
							if (m == 1)
							{
								rewind(fp);
								sprintf(str, "%d", atoi(p1->num) - 1);
								while (!feof(fp))
								{
									fscanf(fp, "%s %s %s %s %s %s %s", p2->phonum, p2->code, p2->name, p2->idnumber, p2->num, p2->sex, p2->flytime);
									if (strcmp(str, p2->num) == 0)
									{
										strcpy(p1->code, data2);
										break;
									}
								}
								fseek(fp, 0l, 1);
								cuser = p1;
								fprintf(fp, "\n%s %s %s %s %s %s %s", cuser->phonum, cuser->code, cuser->name, cuser->idnumber, cuser->num, cuser->sex, cuser->flytime);
								MessageBoxA(hWnd, "密码修改成功", "提示", MB_OK);
								man = 2;
								i++;
							}
							else//该账户不存在
							{
								MessageBoxA(hWnd, "不存在该账户请重试", "提示", MB_OK);
							}
							free(p1);
							free(p2);
							fclose(fp);
						}
					}
				}
			}
		}

		EndBatchDraw();
		FlushMouseMsgBuffer();
	}

}

六、员工界面

1、员工信息读取查找修改保存插入(链表)

从指定的文本文档里读取员工的信息到链表中

//读取信息
struct worklist *inputwork()
{
	FILE *fp = fopen("员工信息.txt", "r+");
	int n = 1;//定义结点数
	struct worklist *head = NULL;
	struct worklist *p1 = (struct worklist *)malloc(sizeof(struct worklist));
	struct worklist *p2 = (struct worklist *)malloc(sizeof(struct worklist));
	if (yncontent("员工信息.txt"))
	{
		while (!feof(fp))
		{
			fscanf(fp, "%s %s %s %s %s %s\n", p1->data.num, p1->data.code, p1->data.name, p1->data.idnumber, p1->data.phonum, p1->data.sex);
			if (n == 1)
			{
				head = p1;
				n++;
			}
			else
			{
				p2->next = p1;
			}
			p2 = p1;
			p1 = (struct worklist *)malloc(sizeof(struct worklist));
		}
		p2->next = NULL;

	}
	fclose(fp);
	return head;
}
struct worklist *findwork(struct worklist *head)
{
	while (head != NULL)
	{
		if (strcmp(head->data.num, worker->num) == 0)
		{
			break;
		}
		head = head->next;
	}
	return head;
}
//修改数据
struct worklist *crtwork(struct worklist *head, int m, char *str)
{
	struct worklist *p1 = head;
	p1 = findwork(p1);
	switch (m)
	{
	case 1:strcpy(p1->data.name, str); break;
	case 2:strcpy(p1->data.code, str); break;
	case 3:strcpy(p1->data.idnumber, str); break;
	case 4:strcpy(p1->data.phonum, str); break;
	default:
		break;
	}
	return head;
}
//插入数据
struct worklist * newwork(struct worklist *head, struct workman *p)
{
	int n = 1;
	char str[5];
	struct worklist *p1 = head;
	struct worklist *p2;
	while (p1->next != NULL)
	{
		p1 = p1->next;
		n++;
	}
	p2 = (struct worklist*)malloc(sizeof(struct worklist));
	sprintf(str, "%d", atoi(p1->data.num) + 1);
	strcpy(p->num, str);
	p2->data = *p;
	p2->next = NULL;
	if (n == 1)
		head = p2;
	else
		p1->next = p2;
	return head;
}
//将数据存入文本
void keepdata(struct worklist *head)
{
	FILE *fp = fopen("员工信息.txt", "w");//创建一个文本作为过渡
	while (head != NULL)
	{
		fprintf(fp, "%s %s %s %s %s %s\n", head->data.num, head->data.code, head->data.name, head->data.idnumber, head->data.phonum, head->data.sex);
		head = head->next;
	}
	fclose(fp);
}

2、员工登录

通过链表里的数据对输入的员工编号和密码进行对比(对比的函数并未贴出)

//员工进行登录
void loadwork()
{
	struct workman *p = (struct workman *)malloc(sizeof(struct workman));
	InputBox(p->num, 5, "请输入员工编号");
	if (strlen(p->num) == 0)
	{
		MessageBoxA(hWnd, "格式不正确请重试", "提示", MB_OK);
		man = 0;
		i--;
	}
	else
	{
		InputBox(p->code, 9, "请输入密码");
		if (strlen(p->code) != 8)
		{
			MessageBoxA(hWnd, "格式不正确请重试", "提示", MB_OK);
			man = 0;
			i--;
		}
		else
		{
			//验证账号密码是否正确
			int c = checking(p->num, p->code);
			if (c == 0)
			{
				MessageBoxA(hWnd, "密码错误请重试", "提示", MB_OK);
				man = 0;
				i--;
			}
			else if (c == 2)
			{
				MessageBoxA(hWnd, "还未进行注册,请先注册", "提示", MB_OK);
				man = 0;
				i--;
			}
		}
	}
	free(p);
}

登录成功后i++,进入员工界面

3、个人信息的加载

//加载个人信息
void loaddate()
{
	
	struct loverlist *head = inputlove();
	while (i == 3)
	{
		BeginBatchDraw();
		nowload();
		putimage(0, 50, &bk);
		loadbottom(&re);
		loadbottom(&correct);

		setfillcolor(RGB(166, 171, 248));
		fillroundrect(340, 100, 940, 700, 15, 15);

		if (man == 1)
		{
			char str[5][50];
			RECT r1 = { 340,120,940,200 };//用户编号
			RECT r2 = { 340,240,940,320 };//姓名
			RECT r3 = { 340,360,940,440 };//身份证号
			RECT r4 = { 340,480,940,560 };//性别
			RECT r5 = { 340,600,940,680 };//电话

										  //基本信息输出
			sprintf(str[0], "用户编号:%s", worker->num);
			sprintf(str[1], "姓名;%s", worker->name);
			sprintf(str[2], "身份证号:%s", worker->idnumber);
			sprintf(str[3], "性别:%s", worker->sex);
			sprintf(str[4], "电话:%s", worker->phonum);

			settextcolor(RGB(45, 49, 56));
			settextstyle(20, 20, "行楷");
			drawtext(str[0], &r1, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
			drawtext(str[1], &r2, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
			drawtext(str[2], &r3, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
			drawtext(str[3], &r4, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
			drawtext(str[4], &r5, DT_CENTER | DT_VCENTER | DT_SINGLELINE);

			MOUSEMSG m;
			m = GetMouseMsg();

			if (mousebottom(&re, m))
			{
				if (m.mkLButton)
				{
					i--;
					Sleep(500);
				}
			}
			if (mousebottom(&correct, m))
			{
				if (m.mkLButton)
				{
					i++;
					correctdata();
				}
			}
		}
		else if (man == 2)
		{
			char str[6][50];

			struct loverlist *p = head;
			p = loadlover(p);

			RECT r1 = { 340,100,940,200 };//用户编号
			RECT r2 = { 340,200,940,300 };//姓名
			RECT r3 = { 340,300,940,400 };//身份证号
			RECT r4 = { 340,400,940, 500 };//性别
			RECT r5 = { 340,500,940, 600 };//电话
			RECT r6 = { 340,600, 940,700 };//飞行次数

										   //基本信息输出
			sprintf(str[0], "用户编号:%s", cuser->num);
			sprintf(str[1], "姓名;%s", cuser->name);
			sprintf(str[2], "身份证号:%s", cuser->idnumber);
			sprintf(str[3], "性别:%s", cuser->sex);
			sprintf(str[4], "电话:%s", cuser->phonum);
			sprintf(str[5], "飞行次数:%s", cuser->flytime);

			settextcolor(RGB(45, 49, 56));
			settextstyle(20, 20, "行楷");
			drawtext(str[0], &r1, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
			drawtext(str[1], &r2, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
			drawtext(str[2], &r3, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
			drawtext(str[3], &r4, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
			drawtext(str[4], &r5, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
			drawtext(str[5], &r6, DT_CENTER | DT_VCENTER | DT_SINGLELINE);

			MOUSEMSG m;
			m = GetMouseMsg();

			if (p == NULL)
			{
				if (m.x >= 200 && m.x <= 1080 && m.y >= 725 && m.y <= 775)
				{
					RECT r = { 800, 625, 1180, 725 };
					char xx[] = "可点击进行绑定,与一名异性已注册账户进行绑定,并填写两人所在地,当购买该趟航班时,将进行优惠,但绑定后无法再更改";
					setfillcolor(RGB(239, 214, 178));
					solidroundrect(800, 625, 1180, 725, 15, 15);
					setbkmode(TRANSPARENT);//字符背景透明
					settextstyle(20, 15, "微软雅黑");
					drawtext(xx, &r, DT_WORDBREAK);

					if (m.mkLButton)
					{
						int a;
						a = MessageBox(hWnd, "是否进行绑定", "提示", MB_OKCANCEL);
						if (a == 1)
						{
							if (bind())
							{
								storedata();
								head = inputlove();
							}
						}
						FlushMouseMsgBuffer();
					}
				}
			}
			if (mousebottom(&re, m))
			{
				if (m.mkLButton)
				{
					i--;
					Sleep(500);
				}
			}
			if (mousebottom(&correct, m))
			{
				if (m.mkLButton)
				{
					i++;
					correctdata();
				}
			}
		}
		EndBatchDraw();
	}
}

4、个人信息的修改

//更改信息
void correctdata()
{
	struct worklist *workhead = inputwork();//写入数据
	struct cuslist *cushead = inputcus();
	while (i == 4)
	{
		BeginBatchDraw();
		putimage(0, 50, &bk);

		MOUSEMSG m = GetMouseMsg();
		loadbottom(&re);

		RECT r = { 0,100,1280,200 };
		drawtext("请选择需要更改的信息", &r, DT_CENTER | DT_VCENTER | DT_SINGLELINE);

		struct bottom name = { 340,325,540,425,RGB(166, 171, 248),"姓名" ,4 };
		struct bottom code = { 740,325,940,425,RGB(166, 171, 248) ,"密码" ,4 };
		struct bottom idnumber = { 340,475,540,575,RGB(166, 171, 248) ,"身份证号",4 };
		struct bottom phonum = { 740,475,940,575,RGB(166, 171, 248) ,"手机号",4 };
		loadbottom(&name);
		loadbottom(&code);
		loadbottom(&idnumber);
		loadbottom(&phonum);

		if (man == 1)
		{
			char data[20];

			if (mousebottom(&re, m))
			{
				if (m.mkLButton)
				{
					i--;
					Sleep(500);
				}
			}
			if (mousebottom(&name, m))//更改姓名
			{
				if (m.mkLButton)
				{
					InputBox(data, 5, "请输入更改的姓名");
					if (strlen(data) == 0)
					{
						MessageBoxA(hWnd, "格式不正确请重试", "提示", MB_OK);
					}
					else
					{
						strcpy(worker->name, data);
						workhead = crtwork(workhead, 1, data);
						keepdata(workhead);
					}
				}
			}
			if (mousebottom(&code, m))//更改密码
			{
				if (m.mkLButton)
				{
					InputBox(data, 9, "请输入更改的密码");
					if (strlen(data) != 8)
					{
						MessageBoxA(hWnd, "格式不正确请重试", "提示", MB_OK);
					}
					else
					{
						strcpy(worker->code, data);
						workhead = crtwork(workhead, 2, data);
						keepdata(workhead);
					}
				}
			}
			if (mousebottom(&idnumber, m))
			{
				if (m.mkLButton)
				{
					InputBox(data, 19, "请输入更改的身份证号");
					if (strlen(data) != 18)
					{
						MessageBoxA(hWnd, "格式不正确请重试", "提示", MB_OK);
					}
					else
					{
						strcpy(worker->idnumber, data);
						workhead = crtwork(workhead, 3, data);
						keepdata(workhead);
					}
				}
			}
			if (mousebottom(&phonum, m))
			{
				if (m.mkLButton)
				{
					InputBox(data, 12, "请输入更改的手机号");
					if (strlen(data) != 11)
					{
						MessageBoxA(hWnd, "格式不正确请重试", "提示", MB_OK);
					}
					else
					{
						strcpy(worker->phonum, data);
						workhead = crtwork(workhead, 4, data);
						keepdata(workhead);
					}
				}
			}
		}
		else if (man == 2)
		{
			char data[20];
			if (mousebottom(&re, m))
			{
				if (m.mkLButton)
				{
					i--;
					Sleep(500);
				}
			}
			if (mousebottom(&name, m))//更改姓名
			{
				if (m.mkLButton)
				{
					InputBox(data, 5, "请输入更改的姓名");
					if (strlen(data) == 0)
					{
						MessageBoxA(hWnd, "格式不正确请重试", "提示", MB_OK);
					}
					else
					{
						strcpy(cuser->name, data);
						cushead = crtcus(cushead, 1, data);
						keepdata(cushead);
					}
				}
			}
			if (mousebottom(&code, m))//更改密码
			{
				if (m.mkLButton)
				{
					InputBox(data, 9, "请输入更改的密码");
					if (strlen(data) != 8)
					{
						MessageBoxA(hWnd, "格式不正确请重试", "提示", MB_OK);
					}
					else
					{
						strcpy(cuser->code, data);
						cushead = crtcus(cushead, 2, data);
						keepdata(cushead);
					}
				}
			}
			if (mousebottom(&idnumber, m))
			{
				if (m.mkLButton)
				{
					InputBox(data, 19, "请输入更改的身份证号");
					if (strlen(data) != 18)
					{
						MessageBoxA(hWnd, "格式不正确请重试", "提示", MB_OK);
					}
					else
					{
						strcpy(cuser->idnumber, data);
						cushead = crtcus(cushead, 3, data);
						keepdata(cushead);
					}
				}

			}
			if (mousebottom(&phonum, m))
			{
				if (m.mkLButton)
				{
					InputBox(data, 12, "请输入更改的手机号");
					if (strlen(data) != 11)
					{
						MessageBoxA(hWnd, "格式不正确请重试", "提示", MB_OK);
					}
					else
					{
						strcpy(cuser->phonum, data);
						cushead = crtcus(cushead, 4, data);
						keepdata(cushead);
					}
				}
			}
		}
		FlushMouseMsgBuffer();
		nowload();
		EndBatchDraw();
	}
}

5、查询航班

通过MessageBoxA函数的返回值确定所需查询的时间(具体见main函数),然后进入航班选择界面

void pageone()
{
	struct button* p1 = cbutton(450, 150, 350, 50, YELLOW, "001航班 重庆-郑州");
	struct button* p2 = cbutton(450, 205, 350, 50, YELLOW, "002航班 广州-天津");
	struct button* p3 = cbutton(450, 260, 350, 50, YELLOW, "003航班 沈阳-上海");
	struct button* p4 = cbutton(450, 315, 350, 50, YELLOW, "004航班 青岛-武汉");
	struct button* p5 = cbutton(450, 370, 350, 50, YELLOW, "005航班 北京-杭州");
	struct button* re = cbutton(0, 50, 100, 50, YELLOW, "返回");
	struct weatherlist *head = inputwth();

	while (i == 3)
	{
		BeginBatchDraw();
		putimage(0, 50, &bk);
		//显示查询的时间
		inquiretime();
		//显示查询的天气
		inquireweather(head);
		drawbutton(p1);   //加按钮
		drawbutton(p2);
		drawbutton(p3);
		drawbutton(p4);
		drawbutton(p5);
		drawbutton(re);
		MOUSEMSG m = GetMouseMsg();
		if (clickbutton(re, m))
		{
			i--;
		}
		if (clickbutton(p1, m))
		{
			i++;
			k = 1;
		}

		if (clickbutton(p2, m))
		{

			i++;
			k = 2;
		}
		if (clickbutton(p3, m))
		{
			i++;
			k = 3;
		}
		if (clickbutton(p4, m))
		{
			i++;
			k = 4;
		}
		if (clickbutton(p5, m))
		{
			i++;
			k = 5;
		}
		EndBatchDraw();
	}
}

如果点击某趟航班则i++,通过全局变量k控制所选择的航班

6、航班信息的加载

只贴出一趟航班的代码,其余航班基本类似
可以通过该界面查询具体的座位情况

void pagetwo()
{
	int u = pricechange();
	char str[50];
	sprintf(str, "出发时间:%s", one.tdaparture);
	char rtr[50];
	sprintf(rtr, "落地时间:%s", one.tdestination);
	char qtr[50];
	sprintf(qtr, "剩余座位:%d", atoi(one.rnumber)-m);
	char p[50];
	sprintf(p, "价格:%.2f", atoi(one.price)*(1 - 0.09*u));
	struct button* p0 = cbutton(450, 95, 350, 50, YELLOW, p);
	struct button* p1 = cbutton(450, 150, 350, 50, YELLOW, "出发地:重庆");
	struct button* p2 = cbutton(450, 205, 350, 50, YELLOW, "目的地:郑州");
	struct button* p3 = cbutton(450, 260, 350, 50, YELLOW, str);
	struct button* p4 = cbutton(450, 315, 350, 50, YELLOW, rtr);
	struct button* p5 = cbutton(450, 370, 350, 50, YELLOW, "航班编号:001航班");
	struct button* p6 = cbutton(450, 425, 350, 50, YELLOW, "总座位:100");
	struct button* p7 = cbutton(450, 480, 350, 50, YELLOW, qtr);
	struct button* p8 = cbutton(450, 535, 170, 50, YELLOW, "确认");
	struct button* p9 = cbutton(630, 535, 170, 50, YELLOW, "返回");
	while (i == 4)
	{
		char str[50];
		sprintf(str, "出发时间:%s", one.tdaparture);
		char rtr[50];
		sprintf(rtr, "落地时间:%s", one.tdestination);
		char qtr[50];
		sprintf(qtr, "剩余座位:%s", one.rnumber);
		BeginBatchDraw();
		drawbutton(p0);
		drawbutton(p1);   //加按钮
		drawbutton(p2);
		drawbutton(p3);
		drawbutton(p4);
		drawbutton(p5);
		drawbutton(p6);
		drawbutton(p7);
		drawbutton(p8);
		drawbutton(p9);
		MOUSEMSG m = GetMouseMsg();
		if (clickbutton(p8, m))
		{
			i++;
		}
		if (clickbutton(p9, m))
		{
			i--;
			Sleep(500);
			FlushMouseMsgBuffer();
		}
		EndBatchDraw();
	}
}

7、乘客信息的查询

先选择所要查询的乘客

int pageseven(struct seat* head)
{
	int a, j;
	int l, w;
	struct seat *p;
	struct button* m[12][8];
	struct button* p0 = cbutton(5, 720, 100, 50, YELLOW, "返回");
	p = head;
	for (a = 0, l = 0; a < 12; a++)
	{
		for (j = 0; j < 8; j++)
		{
			if (p == NULL)
			{
				break;
			}
			(struct button*) m[a][j] = cbutton(5 + j * 155, 60 + a * 55, 150, 50, YELLOW, p->data.name);
			p = p->next;
			l++;
		}
		if (p == NULL)
		{
			break;
		}
	}
	while (i == 5)
	{
		BeginBatchDraw();
		MOUSEMSG o = GetMouseMsg();
		for (a = 0, w = 0; a < 12; a++)
		{
			for (j = 0; j < 8; j++)
			{
				if (w == l)
				{
					break;
				}
				drawbutton(m[a][j]);
				w++;
				if (clickbutton(m[a][j], o))
				{
					i++;
					return w;
				}
			}
		}
		if (clickbutton(p0, o))
		{
			i--;
			Sleep(500);
			FlushMouseMsgBuffer();
		}
		drawbutton(p0);
		EndBatchDraw();
	}
}

然后在对乘客的具体信息进行展示

void cusinformation(struct seat* head, int q)
{
	int b;
	struct seat *p = head;
	for (b = 1; ; b++)
	{
		if (b == q)break;
		p = p->next;
	}
	struct button* p1 = cbutton(450, 150, 350, 50, YELLOW, p->data.phonum);
	struct button* p2 = cbutton(450, 205, 350, 50, YELLOW, p->data.code);
	struct button* p3 = cbutton(450, 260, 350, 50, YELLOW, p->data.name);
	struct button* p4 = cbutton(450, 315, 350, 50, YELLOW, p->data.idnumber);
	struct button* p5 = cbutton(450, 370, 350, 50, YELLOW, p->data.num);
	struct button* p6 = cbutton(450, 425, 350, 50, YELLOW, p->data.sex);
	struct button* p7 = cbutton(450, 480, 350, 50, YELLOW, p->data.flytime);
	struct button* p8 = cbutton(450, 535, 350, 50, YELLOW, "返回");
	struct button* p9 = cbutton(255, 150, 200, 50, YELLOW, "手机号码");
	struct button* p10 = cbutton(255, 205, 200, 50, YELLOW, "用户密码");
	struct button* p11 = cbutton(255, 260, 200, 50, YELLOW, "用户姓名");
	struct button* p12 = cbutton(255, 315, 200, 50, YELLOW, "身份证号码");
	struct button* p13 = cbutton(255, 370, 200, 50, YELLOW, "用户编号");
	struct button* p14 = cbutton(255, 425, 200, 50, YELLOW, "用户性别");
	struct button* p15 = cbutton(255, 480, 200, 50, YELLOW, "飞行次数");
	while (i == 6)
	{
		BeginBatchDraw();
		drawbutton(p1);   //加按钮
		drawbutton(p2);
		drawbutton(p3);
		drawbutton(p4);
		drawbutton(p5);
		drawbutton(p6);
		drawbutton(p7);
		drawbutton(p8);
		drawbutton(p9);   //加按钮
		drawbutton(p10);
		drawbutton(p11);
		drawbutton(p12);
		drawbutton(p13);
		drawbutton(p14);
		drawbutton(p15);
		MOUSEMSG m = GetMouseMsg();
		if (clickbutton(p8, m))
		{
			i--;
		}
		EndBatchDraw();

	}
}

七、顾客界面

1、顾客信息读取查找修改保存插入(链表)

//读取数据
struct cuslist *inputcus()
{
	FILE *fp = fopen("顾客信息.txt", "r+");
	int n = 1;
	struct cuslist *head = NULL;
	struct cuslist *p1 = (struct cuslist *)malloc(sizeof(struct cuslist));
	struct cuslist *p2 = (struct cuslist *)malloc(sizeof(struct cuslist));
	if (yncontent("顾客信息.txt"))
	{
		while (!feof(fp))
		{
			fscanf(fp, "%s %s %s %s %s %s %s\n", p1->data.phonum, p1->data.code, p1->data.name, p1->data.idnumber, p1->data.num, p1->data.sex, p1->data.flytime);
			if (n == 1)
			{
				head = p1;
				n++;
			}
			else
			{
				p2->next = p1;
			}
			p2 = p1;
			p1 = (struct cuslist *)malloc(sizeof(struct cuslist));
		}
		p2->next = NULL;
	}
	fclose(fp);
	return head;
}
//查找数据
struct cuslist *findcus(struct cuslist *head)
{
	while (head != NULL)
	{
		if (strcmp(head->data.num, cuser->num) == 0)
		{
			break;
		}
		head = head->next;
	}
	return head;
}
//修改数据
struct cuslist *crtcus(struct cuslist *head, int m, char *str)
{
	struct cuslist *p1 = head;
	p1 = findcus(p1);
	switch (m)
	{
	case 1:strcpy(p1->data.name, str); break;
	case 2:strcpy(p1->data.code, str); break;
	case 3:strcpy(p1->data.idnumber, str); break;
	case 4:strcpy(p1->data.phonum, str); break;
	default:
		break;
	}
	return head;
}
//插入数据
struct cuslist * newcus(struct cuslist *head, struct cusman *p)
{
	int n = 1;
	char str[5];
	struct cuslist *p1 = head;
	struct cuslist *p2;
	while (p1->next != NULL)
	{
		p1 = p1->next;
		n++;
	}
	p2 = (struct cuslist*)malloc(sizeof(struct cuslist));
	sprintf(str, "%d", atoi(p1->data.num) + 1);
	strcpy(p->num, str);
	strcpy(p->flytime, "0");
	p2->data = *p;
	p2->next = NULL;
	p1->next = p2;
	return head;
}
//保存输据
void keepdata(struct cuslist *head)
{
	FILE *fp = fopen("顾客信息.txt", "w");
	while (head != NULL)
	{
		fprintf(fp, "%s %s %s %s %s %s %s\n", head->data.phonum, head->data.code, head->data.name, head->data.idnumber, head->data.num, head->data.sex, head->data.flytime);
		head = head->next;
	}
	fclose(fp);
}

2、顾客登录和个人信息加载和修改以及航班的查询

由于与员工界面类似,就不单独贴出,详见请看员工部分

3、剩余座位的判断

若等于0的话将无法进行购买

//找出该趟航班剩余座位
void findrest()
{
	struct seat *head = createlist();
	if (head != NULL)
	{
		while (head->next != NULL)
		{
			head = head->next;
		}
		m = atoi(head->seatnum);
	}
	else
	{
		m = 0;
	}
}

3、机票的购买

点击购票后会显示顾客的详细信息

//购票
void screenshuchu()
{
	checkuppre();
	struct seat *head = Createlist();
	head = insert(head);
	save(head);
	struct Zbutton* p = creatButton(0, 50, 100, 50, YELLOW, "返回");
	while (i == 6)
	{
		BeginBatchDraw();

		putimage(0, 50, &bk);

		setfillcolor(RGB(166, 171, 248));
		fillroundrect(340, 100, 940, 700, 15, 15);

		char str[5][50];
		RECT p1 = { 340,120,940,200 };//用户电话
		RECT p2 = { 340,240,940,320 };//用户密码
		RECT p3 = { 340,360,940,440 };//用户姓名
		RECT p4 = { 340,480,940,560 };//用户身份证号
		RECT p5 = { 340,600,940,680 };//用户性别
		sprintf(str[0], "电话:%s", cuser->phonum);
		sprintf(str[1], "用户密码:%s", cuser->code);
		sprintf(str[2], "姓名:%s", cuser->name);
		sprintf(str[3], "身份证号:%s", cuser->idnumber);
		sprintf(str[4], "性别:%s", cuser->sex);

		settextcolor(RGB(45, 49, 56));
		settextstyle(30, 20, "楷体");
		drawtext(str[0], &p1, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
		drawtext(str[1], &p2, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
		drawtext(str[2], &p3, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
		drawtext(str[3], &p4, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
		drawtext(str[4], &p5, DT_CENTER | DT_VCENTER | DT_SINGLELINE);

		drawButton(p);

		MOUSEMSG m = GetMouseMsg();

		if (clickButton(p, m))
		{
			i -= 3;
			Sleep(500);
			FlushMouseMsgBuffer();
		}

		EndBatchDraw();
	}
}

4、已购买机票的查询

使用链表先在文本里查找用户购买的机票信息,然后存入链表

struct Flightlist *inputflight()
{
	struct Flightlist *head = NULL;
	struct Flightlist *p1, *p2;
	struct seat *p;
	int n = 0;
	int c = daydiff(futuretime.tm_year, futuretime.tm_mon, futuretime.tm_mday);
	p = (struct seat *)malloc(sizeof(struct seat));
	p1 = (struct Flightlist*)malloc(sizeof(struct Flightlist));
	p2 = (struct Flightlist*)malloc(sizeof(struct Flightlist));
	for (int a = 1; a <= 5; a++)
	{
		for (int b = 0;b <= c; b++)
		{
			char str[40];
			sprintf(str, "航班信息\\00%d\\%d.txt", a, b);
			FILE *fp = fopen(str, "r");
			if (fp == NULL || !yncontent(str))
			{
				continue;
			}
			else
			{
				while (!feof(fp))
				{
					fscanf(fp, "%s %s %s %s %s %s %s %s\n", p->data.phonum, p->data.code, p->data.name, p->data.idnumber, p->data.num, p->data.sex, p->data.flytime, p->seatnum);
					if (strcmp(p->data.num, cuser->num) == 0)
					{
						switch (a)
						{
						case 1:p1->data = one; break;
						case 2:p1->data = two; break;
						case 3:p1->data = three; break;
						case 4:p1->data = four; break;
						case 5:p1->data = five; break;
						default:
							break;
						}
						strcpy(p1->seatnum, p->seatnum);
						strcpy(p1->time, plusdata(b));
						if (n == 0)head = p1;
						else p2->next = p1;
						p2 = p1;
						n++;
					}
					p1 = (struct Flightlist*)malloc(sizeof(struct Flightlist));
				}
				p2->next = NULL;
			}
			fclose(fp);
		}
	}
	return head;
}

展示出已购买的机票基本信息(这一块做得并不是很好,比较暴力的展示,运行速率会有点慢)

//查询所购票
void bugdata()
{
	struct Flightlist *head = inputflight();
	struct Flightlist *p = head;
	struct bottom f;
	struct bottom prev = { 240,725,540,775,RGB(166, 171, 248),"上一页",3 };
	struct bottom next = { 740,725,1040,775,RGB(166, 171, 248) ,"下一页",3 };
	while (i == 3)
	{
		int x = 0;
		int a;
		a = 0;
		while (p != NULL)//统计结点数
		{
			p = p->next;
			x++;
		}
		free(p);
		x = x / 6;
		
		while (a >= 0 && a <= x)//控制页数
		{
			BeginBatchDraw();
			putimage(0, 50, &bk);

			p = speed(head,a);

			MOUSEMSG m = GetMouseMsg();
			
			loadbottom(&re);
			if (a != 0)
			{
				loadbottom(&prev);
			}
			if (a != x)
			{
				loadbottom(&next);
			}
			for (int c = 0; c < 6 && p != NULL; c++, p = p->next)
			{
				char str[50];
				RECT r;
				sprintf(str, "%s %s %s %s", p->time, p->data.pdeparture, p->data.pdestination, p->seatnum);
				switch (c)
				{
				case 0:r = { 20,215,620,315 };
					   f = { 20,215,620,315,RGB(166, 171, 248) ,"",3 }; break;
				case 1:r = { 660,215,1260,315 };
					   f = { 660,215,1260,315 ,RGB(166, 171, 248) ,"",3 }; break;
				case 2:r = { 20,375,620,475 };
					   f = { 20,375,620,475,RGB(166, 171, 248) ,"",3 }; break;
				case 3:r = { 660,375,1260,475 };
					   f = { 660,375,1260,475,RGB(166, 171, 248) ,"",3 }; break;
				case 4:r = { 20,555,620,655 };
					   f = { 20,555,620,655,RGB(166, 171, 248) ,"",3 }; break;
				case 5:r = { 660,555,1260,655 };
					   f = { 660,555,1260,655,RGB(166, 171, 248) ,"",3 }; break;
				default:
					break;
				}
				strcpy(f.text, str);
				loadbottom(&f);
				if (mousebottom(&f, m))
				{
					if (m.mkLButton)
					{
						i++;
						showbugflight(p);
						FlushMouseMsgBuffer();
					}
				}
			}
			if (a != 0)
			{
				if (mousebottom(&prev, m))
				{
					if (m.mkLButton)
					{
						a--;
						Sleep(500);
					}
				}
			}
			if (a != x)
			{
				if (mousebottom(&next, m))
				{
					if (m.mkLButton)
					{
						a++;
						Sleep(500);
					}
				}
			}
			if (mousebottom(&re, m))
			{
				if (m.mkLButton)
				{
					a--;
					if (a < 0)
					{
						i--;
					}
					Sleep(500);
				}
			}
			EndBatchDraw();
		}
	}
}

点击航班后进入下一界面,进行详细信息的展示

/展示具体航班信息
void showbugflight(struct Flightlist *p)
{
	//存储信息到字符串数组
	char str[8][50];
	sprintf(str[0], "%s", p->time);
	sprintf(str[1], "起点:%s", p->data.pdeparture);
	sprintf(str[2], "终点:%s", p->data.pdestination);
	sprintf(str[3], "起飞时间:%s", p->data.tdaparture);
	sprintf(str[4], "落地时间:%s", p->data.tdestination);
	sprintf(str[5], "座位号:%s", p->seatnum);
	RECT r1 = { 340,125,940,225 };
	RECT r2 = { 340,275,640,375 };
	RECT r3 = { 640,275,940,375 };
	RECT r4 = { 340,425,640,525 };
	RECT r5 = { 640,425,940,525 };
	RECT r6 = { 340,575,940,675 };

	while (i == 4)
	{
		BeginBatchDraw();
		putimage(0, 50, &bk);
		loadbottom(&re);
		MOUSEMSG m = GetMouseMsg();
		//背景框
		setfillcolor(RGB(166, 171, 248));
		fillroundrect(340, 100, 940, 700, 15, 15);
		//展示信息
		settextcolor(BLACK);
		drawtext(str[0], &r1, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
		drawtext(str[1], &r2, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
		drawtext(str[2], &r3, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
		drawtext(str[3], &r4, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
		drawtext(str[4], &r5, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
		drawtext(str[5], &r6, DT_CENTER | DT_VCENTER | DT_SINGLELINE);

		if (mousebottom(&re, m))
		{
			if (m.mkLButton)
			{
				i--;
				Sleep(500);
			}
		}
		EndBatchDraw();
	}
}
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值