📄 train_booking_trainop.c
字号:
// 如果出现开始站、结束站顺序相反的情况
if (*end_order < *begin_order)
{
printf("【错误】您要查找的结束站 %s 应该在起始站 %s 的前面!\n",
begin_station, end_station);
message(TIP, "想要更正吗(按Y更正,其它键放弃)?", W);
ch = getch();
if ('y' == ch) // 进行序号更正
{
tmp = *end_order;
*end_order = *begin_order;
*begin_order = tmp;
message(INFO, "已经成功更正站点信息!", NULL);
printf("【信息】您的车票的起点站为 %s , 结束站为 %s !\n",
end_station, begin_station);
return OK;
}
else
{
message(WARN, "确定列车行程起始结束号失败!", WC);
return FAIL;
}
}
return OK;
}
/////////////////////////////////////////////////////////////////////////////
// 函数功能: 求两车站之间的距离
//
// 函数参数: ok_distance:反回所求值
// station_info_head:车站信息链表头结点指针
// begin_order:开始站点编号
// end_order:结束站点编号
//
/////////////////////////////////////////////////////////////////////////////
status get_distance(int *ok_distance, station_info *station_info_head,
int begin_order, int end_order)
{
int i, begin_dis, end_dis;
// 取得开始站点距始发站的距离
for (i = 0; i < begin_order; i++)
{
station_info_head = station_info_head->next;
}
begin_dis = station_info_head->distance;
// 取得结束站点距始发站距离
for (i = begin_order; i < end_order; i++)
{
station_info_head = station_info_head->next;
}
end_dis = station_info_head->distance;
// 求出差值
*ok_distance = end_dis - begin_dis;
return OK;
}
/////////////////////////////////////////////////////////////////////////////
// 函数功能: 通过订票信息的起点站、终点站名称求得两站对应序号
//
// 函数参数: begin_order:返回起始站点序号
// end_order:返回结束站点序号
// begin_station:起始站点名
// end_station:结束站点名
// train_info_head:列车信息链头结点指针
//
/////////////////////////////////////////////////////////////////////////////
status station_to_order(int *begin_order, int *end_order, char *begin_station,
char *end_station, train_info *train_info_head)
{
int i = 0;
if (!(train_info_head->next))
{
message(ERROR, "该站点没有车站信息!", NULL);
message(WARN, "求车站信息序号失败!", WC);
return FAIL;
}
while (train_info_head->next)
{
train_info_head = train_info_head->next;
if (!(strcmp(train_info_head->station_links.station_id, begin_station)))
{
*begin_station = i;
}
if (!(strcmp(train_info_head->station_links.station_id, end_station)))
{
*end_station = i;
}
i++;
}
return OK;
}
/////////////////////////////////////////////////////////////////////////////
// 函数功能: 根据指定信息检测用户是否已订过软卧票
//
// 函数参数: op_psngr_pt:操作用户信息体指针
// sq_id:车票所属列车车次编号
// time_id:车票所属列车时间标识
// begin_station:车票起始站名称
// end_station:车票结束站名称
//
// 函数说明: 如是,返回OK,否则返回FAIL
// 检测方法:匹配站点名称法
//
/////////////////////////////////////////////////////////////////////////////
status check_sb_booked(passenger_info *op_psngr_pt, char *sq_id, char *time_id,
char *begin_station, char *end_station)
{
booked_info *booked_info_head;
char t_station_str[64];
int state = 0, i;
booked_info_head = &op_psngr_pt->booked_links;
if (!(booked_info_head->next))
{
message(ERROR, "该用户并没有订过车票!", WC);
return FAIL;
}
while (booked_info_head->next)
{
booked_info_head = booked_info_head->next;
if ((!(strcmp(sq_id, booked_info_head->booked_train_sq_id))) ||
(!(strcmp(time_id, booked_info_head->booked_train_time_id))))
{
// 找到对应列车,再找对应已订票信息,首先创建车站名串
strcpy(t_station_str, "");
strcpy(t_station_str, begin_station);
strcat(t_station_str, "#");
strcat(t_station_str, end_station);
for (i = 0; i < MAX_BOOK_PER_PSNGR; i++)
{
if (!(strcmp(t_station_str, booked_info_head->soft_bed_st[i])))
{
state = 1; // 置状态值
return OK;
}
}
}
}
if (!state) // 如果检测不到已订票信息
{
message(ERROR, "该用户并没有订过软卧车票!", WC);
return FAIL;
}
return OK;
}
/////////////////////////////////////////////////////////////////////////////
// 函数功能: 根据指定信息检测用户是否已订过硬卧票
//
// 函数参数: op_psngr_pt:操作用户信息体指针
// sq_id:车票所属列车车次编号
// time_id:车票所属列车时间标识
// begin_station:车票起始站名称
// end_station:车票结束站名称
//
// 函数说明: 如是,返回OK,否则返回FAIL
// 检测方法:匹配站点名称法
//
/////////////////////////////////////////////////////////////////////////////
status check_hb_booked(passenger_info *op_psngr_pt, char *sq_id, char *time_id,
char *begin_station, char *end_station)
{
booked_info *booked_info_head;
char t_station_str[64];
int state = 0, i;
booked_info_head = &op_psngr_pt->booked_links;
if (!(booked_info_head->next))
{
message(ERROR, "该用户并没有订过车票!", WC);
return FAIL;
}
while (booked_info_head->next)
{
booked_info_head = booked_info_head->next;
if ((!(strcmp(sq_id, booked_info_head->booked_train_sq_id))) ||
(!(strcmp(time_id, booked_info_head->booked_train_time_id))))
{
// 找到对应列车,再找对应已订票信息,首先创建车站名串
strcpy(t_station_str, "");
strcpy(t_station_str, begin_station);
strcat(t_station_str, "#");
strcat(t_station_str, end_station);
for (i = 0; i < MAX_BOOK_PER_PSNGR; i++)
{
if (!(strcmp(t_station_str, booked_info_head->hard_bed_st[i])))
{
state = 1; // 置状态值
return OK;
}
}
}
}
if (!state) // 如果检测不到已订票信息
{
message(ERROR, "该用户并没有订过硬卧车票!", WC);
return FAIL;
}
return OK;
}
/////////////////////////////////////////////////////////////////////////////
// 函数功能: 根据指定信息检测用户是否已订过硬座票
//
// 函数参数: op_psngr_pt:操作用户信息体指针
// sq_id:车票所属列车车次编号
// time_id:车票所属列车时间标识
// begin_station:车票起始站名称
// end_station:车票结束站名称
//
// 函数说明: 如是,返回OK,否则返回FAIL
// 检测方法:匹配站点名称法
//
/////////////////////////////////////////////////////////////////////////////
status check_hs_booked(passenger_info *op_psngr_pt, char *sq_id, char *time_id,
char *begin_station, char *end_station)
{
booked_info *booked_info_head;
char t_station_str[64];
int state = 0, i;
booked_info_head = &op_psngr_pt->booked_links;
if (!(booked_info_head->next))
{
message(ERROR, "该用户并没有订过车票!", WC);
return FAIL;
}
while (booked_info_head->next)
{
booked_info_head = booked_info_head->next;
if ((!(strcmp(sq_id, booked_info_head->booked_train_sq_id))) ||
(!(strcmp(time_id, booked_info_head->booked_train_time_id))))
{
// 找到对应列车,再找对应已订票信息,首先创建车站名串
strcpy(t_station_str, "");
strcpy(t_station_str, begin_station);
strcat(t_station_str, "#");
strcat(t_station_str, end_station);
for (i = 0; i < MAX_BOOK_PER_PSNGR; i++)
{
if (!(strcmp(t_station_str, booked_info_head->hard_seat_st[i])))
{
state = 1; // 置状态值
return OK;
}
}
}
}
if (!state) // 如果检测不到已订票信息
{
message(ERROR, "该用户并没有订过硬座车票!", WC);
return FAIL;
}
return OK;
}
/////////////////////////////////////////////////////////////////////////////
// 函数功能: 根据指定信息检测用户是否已订过硬座票
//
// 函数参数: op_psngr_pt:操作用户信息体指针
// sq_id:列车车次编号
// time_id:列车时间标识
// car_order:(面向用户的)车厢序号
// seat_order:座位号
// 函数说明: 如是,返回OK,否则返回FAIL
// 检测方法:匹配座位票号法
//
/////////////////////////////////////////////////////////////////////////////
status check_hs_booked_ii(passenger_info *op_psngr_pt, char *sq_id, char *time_id,
int car_order, int seat_order)
{
booked_info *booked_info_head;
int inner_seat_order;
int i;
booked_info_head = &op_psngr_pt->booked_links;
if (!(booked_info_head->next))
{
message(ERROR, "该用户并没有订过车票!", WC);
return FAIL;
}
inner_seat_order = car_order - 1; // 转换为内部车厢序号
while (booked_info_head->next)
{
booked_info_head = booked_info_head->next;
// 寻找到匹配车次订票信息
if ((!(strcmp(booked_info_head->booked_train_sq_id, sq_id))) &&
(!(strcmp(booked_info_head->booked_train_time_id, time_id))))
{
for (i = 0; i < MAX_BOOK_PER_PSNGR; i++)
{
// 如果查找到确实订过票
if (seat_order == booked_info_head->soft_bed_sq[car_order][i])
{
return OK;
}
}
}
}
return FAIL;
}
/////////////////////////////////////////////////////////////////////////////
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -