|
|
|
@ -146,6 +146,8 @@ void Save() //
|
|
|
|
|
Menu();
|
|
|
|
|
}
|
|
|
|
|
printf("数据保存中,请稍后\n");
|
|
|
|
|
fp2 = fopen("num.txt", "wb");
|
|
|
|
|
fp1 = fopen("sql.txt", "wb");
|
|
|
|
|
fwrite(&class_num, sizeof(int), 1, fp2); //写入文件信息
|
|
|
|
|
fwrite(records, sizeof(CLASS), class_num, fp1);
|
|
|
|
|
fclose(fp1);
|
|
|
|
@ -168,6 +170,8 @@ void Load() //
|
|
|
|
|
system("pause");
|
|
|
|
|
Menu();
|
|
|
|
|
}
|
|
|
|
|
fp1 = fopen("sql.txt", "rb");
|
|
|
|
|
fp2 = fopen("num.txt", "rb");
|
|
|
|
|
fread(&class_num, sizeof(int), 1, fp2); //读入信息
|
|
|
|
|
fread(records, sizeof(CLASS), class_num, fp1); //读入信息
|
|
|
|
|
fclose(fp1);
|
|
|
|
@ -176,7 +180,8 @@ void Load() //
|
|
|
|
|
int Judge(int i) //判断时间是否超出
|
|
|
|
|
{
|
|
|
|
|
struct tm *local; //时间结构体
|
|
|
|
|
time_t t; //把当前时间给t
|
|
|
|
|
time_t t;
|
|
|
|
|
time(&t);
|
|
|
|
|
local = localtime(&t); //获取当前系统时间
|
|
|
|
|
if (local->tm_hour < atoi(records[i].hour) || local->tm_hour == atoi(records[i].hour) && local->tm_min < atoi(records[i].min))
|
|
|
|
|
//atoi函数将字符串转换成一个整数值
|
|
|
|
@ -194,7 +199,7 @@ int FindCarByNum(char s1[]) //
|
|
|
|
|
{
|
|
|
|
|
printf("|----------|----------|----------|----------|--------|--------|--------|\n");
|
|
|
|
|
printf("|%10s|%5s:%-4s|%10s|%10s|%8.1f|%8d|%8d|", records[i].number, records[i].hour,
|
|
|
|
|
records[i].min, records[i].from, records[i].to, records[i].hours, records[i].max, records[i].bought);
|
|
|
|
|
records[i].min, records[i].from, records[i].to, records[i].hours, records[i].max, records[i].bought);
|
|
|
|
|
h += 2;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
@ -205,7 +210,6 @@ int FindCarByNum(char s1[]) //
|
|
|
|
|
void Import()
|
|
|
|
|
{
|
|
|
|
|
int i = 0, j = 5, h;
|
|
|
|
|
char s[5];
|
|
|
|
|
FILE *fp;
|
|
|
|
|
system("cls");
|
|
|
|
|
if ((fp = fopen("num.txt", "rb")) != NULL)
|
|
|
|
@ -231,7 +235,7 @@ void Import()
|
|
|
|
|
scanf("%s", records[i].number);
|
|
|
|
|
for (h = 0; h < i; h++)
|
|
|
|
|
if (strcmp(records[h].number, records[i].number) == 0)
|
|
|
|
|
//判断字符串是否相等
|
|
|
|
|
//判断字符串是否相等
|
|
|
|
|
{
|
|
|
|
|
printf("输入错误!该班次已存在!\n");
|
|
|
|
|
break; ///返回
|
|
|
|
@ -268,7 +272,7 @@ void Buy()
|
|
|
|
|
for (i = 0; i < class_num; i++)
|
|
|
|
|
if (strcmp(num, records[i].number) == 0)
|
|
|
|
|
if (records[i].max > records[i].bought && Judge(i) == 1)
|
|
|
|
|
//判断时间是否超出当前系统时间并且已售车票没超出最大客量
|
|
|
|
|
//判断时间是否超出当前系统时间并且已售车票没超出最大客量
|
|
|
|
|
{
|
|
|
|
|
records[i].bought++;
|
|
|
|
|
printf("通向%s班次为%s的票订票成功!\n", records[i].to, records[i].number);
|
|
|
|
@ -327,7 +331,7 @@ void Refund()
|
|
|
|
|
void Query()
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
char s1[10] = {'\0'}, s2[10] = {'\0'};
|
|
|
|
|
char s1[10] = { '\0' }, s2[10] = { '\0' };
|
|
|
|
|
system("cls");
|
|
|
|
|
printf("1. 按班次查询\n");
|
|
|
|
|
printf("2. 按终点站查询\n");
|
|
|
|
@ -368,7 +372,7 @@ void Find(char s1[], char s2[])
|
|
|
|
|
{
|
|
|
|
|
printf("\n|----------|----------|----------|----------|--------|--------|--------|\n");
|
|
|
|
|
printf("|%10s|%5s:%-4s|%10s|%10s|%8.1f|%8d|%8d|", records[i].number, records[i].hour, records[i].min,
|
|
|
|
|
records[i].from, records[i].to, records[i].hours, records[i].max, records[i].bought);
|
|
|
|
|
records[i].from, records[i].to, records[i].hours, records[i].max, records[i].bought);
|
|
|
|
|
h += 2;
|
|
|
|
|
if (m == 1)
|
|
|
|
|
break;
|
|
|
|
@ -393,7 +397,7 @@ void Insert()
|
|
|
|
|
scanf("%s", records[class_num].number);
|
|
|
|
|
for (i = 0; i < class_num; i++)
|
|
|
|
|
if (strcmp(records[class_num].number, records[i].number) == 0)
|
|
|
|
|
//判断车次是否重复
|
|
|
|
|
//判断车次是否重复
|
|
|
|
|
{
|
|
|
|
|
printf("输出车次已存在!\n");
|
|
|
|
|
system("pause");
|
|
|
|
@ -419,11 +423,11 @@ void Exploer() //
|
|
|
|
|
printf("\n|----------|----------|----------|----------|--------|--------|--------|\n");
|
|
|
|
|
if (Judge(i))
|
|
|
|
|
printf("|%10s|%5s:%-4s|%10s|%10s|%8.1f|%8d|%8d|", records[i].number, records[i].hour,
|
|
|
|
|
records[i].min, records[i].from, records[i].to, records[i].hours,
|
|
|
|
|
records[i].max, records[i].bought);
|
|
|
|
|
records[i].min, records[i].from, records[i].to, records[i].hours,
|
|
|
|
|
records[i].max, records[i].bought);
|
|
|
|
|
else
|
|
|
|
|
printf("|%10s| 已发车 |%10s|%10s|%8.1f|%8d|%8d|", records[i].number,
|
|
|
|
|
records[i].from, records[i].to, records[i].hours, records[i].max, records[i].bought);
|
|
|
|
|
records[i].from, records[i].to, records[i].hours, records[i].max, records[i].bought);
|
|
|
|
|
}
|
|
|
|
|
ShowTableFoot();
|
|
|
|
|
printf("\n");
|
|
|
|
|