?? train_booking_bookop.c
字號:
return FAIL;
}
}
// 仍有有效座位,執(zhí)行訂票操作
deal_sb_seat(&train_info_pt->sbed_info_list[i], ok_car_order, t_seat_order,
t_begin_order, t_end_order, 1); // 1為訂票
// 上面的函數(shù)不包括文件保存功能,需要自己更新文件
if (!(save_sbed_info_list(&train_info_pt->sbed_info_list, train_info_pt->master,
train_info_pt->time_id, SOFT_BED_CAR)))
{
message(ERROR, "執(zhí)行乘客訂票操作時更新文件失敗!", NULL);
message(WARN, "預(yù)訂軟臥車票失敗!", WC);
return FAIL;
}
// 回饋用戶信息
message(INFO, "您已成功訂票了!恭喜恭喜!", NULL);
message(INFO, "下面是您這次操作的訂票信息,請確認。", NULL);
printf("【信息】%s 車次 %d 趟車 %d 號(軟臥)車廂 %d 號座位",
train_info_pt->master, train_info_pt->time_id,
booked_car_order, t_seat_order);
message(INFO, "信息已添加至您的訂票清單(歷史記錄)中。按任意鍵返回。", WC);
return OK;
}
/////////////////////////////////////////////////////////////////////////////
// 函數(shù)功能: 查找用于執(zhí)行訂/退票操作的目標列車信息
//
// 函數(shù)參數(shù): target_train_pt:用于返回指向目標列車信息單元的指針變量(不能用地址!)
// system_info_pt:系統(tǒng)信息單元指針
//
/////////////////////////////////////////////////////////////////////////////
status search_target_train(train_info *target_train_pt, system_info *system_info_pt)
{
train_sq_info *train_sq_info_head;
train_info *train_info_head;
char t_re_sq[64], t_re_time_id[64];
int state;
train_sq_info_head = &system_info_pt->train_sq_list; // 取得頭結(jié)點指針
// 取得退票車次
printf("第一步:確定要退票的列車車次\n");
if (!(get_str("要退票的列車車次", t_re_sq, MIN_TRING_ID_LEN, MAX_TRAIN_ID_LEN)))
{
message(ERROR, "輸入退票車次失敗!", NULL);
message(WARN, "退訂軟臥車票失敗!", WC);
return OK;
}
// 取得退票列車時間標識
printf("第二步:確定要退票的列車時間標識\n");
message(TIP, "時間標識格式如下:如果是2006年9月12號的列車,則輸入 20060912", NULL);
message(TIP, "注意數(shù)字小于10時補一個0在前面", W);
if (!(get_str("要退票的列車時間標識", t_re_time_id, 8, 8)))
{
message(ERROR, "輸入退票列車時間標識失敗!", NULL);
message(WARN, "退訂軟臥車票失敗!", WC);
return OK;
}
// 在內(nèi)存中搜索列車信息
state = 0;
while (train_sq_info_head->next)
{
train_sq_info_head = train_sq_info_head->next;
if (!(strcmp(train_sq_info_head->train_sq_id, t_re_sq)))
{
train_info_head = &train_sq_info_head->train_list; // 取得列車信息頭結(jié)點指針
state = 1;
break;
}
}
// 如果沒有找到對應(yīng)車次
if (!state)
{
printf("【警告】沒有找到任何有關(guān)于車次(%s)的信息!請確認是否輸入錯誤,再重試。\n", t_re_sq);
WAIT;
CLS;
return FAIL;
}
// 在車次鏈上根據(jù)時間標識查找列車信息
state = 0;
while (train_info_head->next)
{
train_info_head = train_info_head->next;
if (!(strcmp(train_info_head->time_id, t_re_time_id)))
{
target_train_pt = train_info_head;
state = 1;
break;
}
}
// 如果沒有找到對應(yīng)列車
if (!state)
{
printf("【警告】沒有找到任何有關(guān)于列車(%s)的信息!請確認是否輸入錯誤,再重試。\n", t_re_time_id);
WAIT;
CLS;
return FAIL;
}
return OK;
}
/////////////////////////////////////////////////////////////////////////////
// 函數(shù)功能: 用戶軟臥票退票事務(wù)處理
//
// 函數(shù)參數(shù): op_psngr_pt:操作用戶信息結(jié)構(gòu)體指針
// system_info_pt:系統(tǒng)信息結(jié)構(gòu)體指針
// train_info_pt:要退票的列車信息結(jié)構(gòu)體指針
//
// 函數(shù)說明: 1、這里train_info_pt只是便于修改某些參數(shù)用,并不提供退票的信息
// 2、在使用此函數(shù)之前,應(yīng)已找到對應(yīng)列車及車次數(shù)據(jù),本程序?qū)⒁来?// 搜索該列車的所有要求類型的車廂,直到找到座位
//
/////////////////////////////////////////////////////////////////////////////
status re_sb_ticket(passenger_info *op_psngr_pt, system_info *system_info_pt,
train_info *train_info_pt)
{
int t_begin_order, t_end_order, t_car_order, t_seat_order;
char t_re_book_station_id[64];
int re_car_order, re_seat_order;
char t_begin_station[64], t_end_station[64];
char t_re_sq[64], t_re_time_id[64];
int this_cost, t_distance;
CLS;
if (0 == op_psngr_pt->total_booked_tickets)
{
message(ERROR, "您還沒有在此列車上訂過車票,不能退訂!", WC);
return FAIL;
}
actitle("退訂軟臥車票");
// 取得退票的起點
printf("第一步:確定要退票的始發(fā)站(當前站為 %s 站,回車直接確認)\n",
system_info_pt->location);
if (!(get_str("要退票的始發(fā)站", t_begin_station, MIN_STATION_ID_LEN, MAX_STATION_ID_LEN)))
{
message(INFO, "將當前站點設(shè)置為始發(fā)站!", NULL);
printf("【信息】您輸入的始發(fā)站為 %s 站!\n", system_info_pt->location);
WAIT;
}
// 取得訂票的終點
printf("第二步:確定要退票的終點站\n");
if (!(get_str("要退票的終點站", t_end_station, MIN_STATION_ID_LEN, MAX_STATION_ID_LEN)))
{
message(WARN, "退訂軟臥車票失敗!", WC);
return FAIL;
}
// 取得車票的車廂號(面向用戶式輸入)
printf("第三步:確定要退票的車票的車廂號\n");
if (!(get_int("要退票的車票的車廂號", &t_car_order, 1, DOT_PER_SB_CAR)))
{
message(WARN, "退訂軟臥車票失敗!", WC);
return FAIL;
}
// 取得車票的座位號
printf("第四步:確定要退票的車票的座位號\n");
if (!(get_int("要退票的車票的座位號", &t_seat_order, 1, DOT_PER_SB_CAR)))
{
message(WARN, "退訂軟臥車票失敗!", WC);
return FAIL;
}
message(INFO, "正在執(zhí)行退票操作,請稍候...", NULL);
// 取得站點在信息鏈中的區(qū)間序號
if (!(get_span_order(&train_info_pt->station_links, t_begin_station, t_end_station,
&t_begin_order, &t_end_order)))
{
message(WARN, "抱歉!退票失敗!", WC);
return FAIL;
}
// 檢測用戶提供退票信息的真實性:參數(shù)為面向用戶的車廂號,內(nèi)部自動轉(zhuǎn)換處理
if (!(check_hs_booked_ii(op_psngr_pt, t_re_sq, t_re_time_id, t_car_order, t_seat_order)))
{
message(ERROR, "您提供的退票信息有誤!請重試!", NULL);
message(WARN, "抱歉!退票失敗!", WC);
return FAIL;
}
// 取得錢款
get_distance(&t_distance, &train_info_pt->station_links,
t_begin_order, t_end_order); //計算路程
pay_bill(&this_cost, system_info_pt->price_sbed_per_km, t_distance);
//車廂訂票信息矩陣的更新
deal_sb_seat(&train_info_pt->sbed_info_list, t_car_order, t_seat_order,
t_begin_order, t_end_order, 0);
// 處理個人信息
op_psngr_pt->total_booked_tickets--;
op_psngr_pt->total_cost -= this_cost;
// 處理系統(tǒng)信息
system_info_pt->total_sold--;
system_info_pt->total_income -= this_cost;
if (!op_psngr_pt->total_cost) // 如果用戶把票退光
{
train_info_pt->total_passengers--;
}
// 通知其它用戶退票消息
// 返還用戶錢款
// 回饋用戶信息
message(INFO, "您已成功退票了!恭喜恭喜!", NULL);
message(INFO, "下面是您這次操作的退票信息,請確認。", NULL);
printf("【信息】%s 車次 %d 趟車 %d 號(軟臥)車廂 %d 號座位",
train_info_pt->master, train_info_pt->time_id,
re_car_order, t_seat_order);
message(INFO, "信息從您的訂票清單(歷史記錄)中銷毀。按任意鍵返回。", WC);
return OK;
}
/////////////////////////////////////////////////////////////////////////////
#endif
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -