[c]代码库
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <gtk/gtk.h>
#include "myDataType.h"
#define BOOK_WINDOW_SIZE 320
#define MAXSTATIONS 100
#define MAXTRAINLINES 100
#define MAXPASSENGERS 100
/*file.c*/
extern int GetStation(struct station_tag myStations[]);
extern int GetTrainLine(struct trainline_tag myTrainLines[], struct station_tag stations[]);
extern double CalTicketPrice(int stationDif, int i_kindOfLine, int i_kindOfSeat);
extern struct station_tag *FindStation(const char *stationname, struct station_tag myStations[], int length);
extern void TurnTrainLineIntoString(char des[][20], struct trainline_tag *srcTrainLine);
extern void TurnTicketIntoString(char des[][20], struct trainline_tag *srcTrainLine);
extern int TurnSeatIntoKind(const char *text);
extern int GetStationDif(const struct trainline_tag *trainLine_ptr, const struct station_tag *startStation, const struct station_tag *endStation_ptr);
/**end file.c**/
/*list.c*/
extern struct head_tag *CreatList(void);
extern struct head_tag *InsertNode(struct head_tag *head_ptr, struct node_tag *node_ptr);
extern int FreeList(struct head_tag *head_ptr);
extern struct head_tag *FindStationInTrainLine(struct trainline_tag trainLines[], int length, const struct station_tag *startStation_ptr, const struct station_tag *endStation_ptr);
extern struct head_tag *FindTrainLine(struct trainline_tag trainLines[], int length, const struct trainline_tag *samTrainline_ptr, int timeMode);
extern void fft_ShowList(const struct head_tag *head);
/**end list.c**/
/*client.c*/
extern void ModifyPassenger(struct passenger_tag passengers[],int *length, struct pastemp_tag *pastemp_ptr);
extern struct passenger_tag *FindPassenger(struct passenger_tag passengers[], int length, struct pastemp_tag *pastemp_ptr);
extern int ReturnTicket(struct passenger_tag *passenger_ptr, int index);
extern struct trainline_tag *BookTickets(int kindofseat, struct trainline_tag *trainLine_ptr);
/**end client.c**/
/*my gtk*/
int quit(GtkButton *button, gpointer data);
int about(GtkButton *button, gpointer data);
int book(GtkButton *button, gpointer data);
int book_check_button_on_click(GtkWidget *button, gpointer data);
int book_clist_row_on_click(GtkWidget *clist, gint row, gint column, GdkEventButton *event, gpointer data);
int book_sure_buttn_clicked(GtkWidget *button, struct trainline_tag* data);
int book_final_button_clicked(GtkWidget *button, struct trainline_tag *data);
int check(GtkWidget *button, gpointer data);
int check_check_button_on_click(GtkWidget *button, gpointer data);
int check_return_button_on_click(GtkWidget *button, gpointer data);
/**end my gtk**/
/*global variable*/
GtkWidget *g_book_start_station_entry;
GtkWidget *g_book_end_station_entry;
GtkWidget *g_book_date_entry;
GtkWidget *g_book_clist;
GtkWidget *g_book_sure_name_entry;
GtkWidget *g_book_sure_id_entry;
GtkWidget *g_book_sure_tel_entry;
GtkWidget *g_book_sure_seat_combo;
GtkWidget *g_book_book_window;
GtkWidget *g_book_sure_window;
GtkWidget *g_check_name_entry;
GtkWidget *g_check_id_entry;
GtkWidget *g_check_tel_entry;
GtkWidget *g_check_check_window;
GtkWidget *g_check_return_notebook;
struct head_tag *g_book_check_button_head = NULL;
struct pastemp_tag g_pastemp;
struct passenger_tag *g_passenger_return_ticket;
struct station_tag g_myStations[MAXSTATIONS];
int g_slen = 0;
struct trainline_tag g_myTrainLines[MAXTRAINLINES];
int g_tlen = 0;
struct passenger_tag g_myPassengers[MAXPASSENGERS];
int g_plen = 0;
/**end global variable**/
int main(int argc, char *argv[])
{
GtkWidget *window;
GtkWidget *hello_window;
GtkWidget *main_menu_book_button;
GtkWidget *main_menu_check_button;
GtkWidget *main_menu_return_button;
GtkWidget *main_menu_about_button;
GtkWidget *main_menu_quit_button;
GtkWidget *button_box;
GtkWidget *down_box;
GtkWidget *whole_box;
GtkWidget *up_image_box;
GtkWidget *down_image_box;
GtkWidget *up_image;
GtkWidget *down_image;
int i;
gtk_init(&argc, &argv);
/*read file*/
g_slen = GetStation(g_myStations);
g_tlen = GetTrainLine(g_myTrainLines, g_myStations);
/**end read file**/
up_image = gtk_image_new_from_file("up.png");
up_image_box = gtk_hbox_new(FALSE, 0);
gtk_box_pack_start(GTK_BOX(up_image_box), up_image,FALSE, FALSE, 0);
down_image = gtk_image_new_from_file("side.png");
down_image_box = gtk_hbox_new(FALSE, 0);
gtk_box_pack_start(GTK_BOX(down_image_box), down_image,FALSE, FALSE, 0);
main_menu_book_button = gtk_button_new_with_mnemonic(g_convert("预订车票(_B)", -1, "UTF-8", "GB2312", NULL, NULL, NULL));
main_menu_check_button = gtk_button_new_with_mnemonic(g_convert("查询订票信息(_C)", -1, "UTF-8", "GB2312", NULL, NULL, NULL));
main_menu_return_button = gtk_button_new_with_mnemonic(g_convert("退票(_R)", -1, "UTF-8", "GB2312", NULL, NULL, NULL));
main_menu_about_button = gtk_button_new_with_mnemonic(g_convert("关于(_A)", -1, "UTF-8", "GB2312", NULL, NULL, NULL));
main_menu_quit_button = gtk_button_new_with_mnemonic(g_convert("退出(_Q)", -1, "UTF-8", "GB2312", NULL, NULL, NULL));
/*button_box init*/
button_box = gtk_vbox_new(TRUE, 21);
gtk_box_pack_start(GTK_BOX(button_box), main_menu_book_button, FALSE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(button_box), main_menu_check_button, FALSE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(button_box), main_menu_return_button, FALSE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(button_box), main_menu_about_button, FALSE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(button_box), main_menu_quit_button, FALSE, TRUE, 0);
/**end button_box init**/
/*down_box init*/
down_box = gtk_hbox_new(FALSE, 47);
gtk_box_pack_start(GTK_BOX(down_box), down_image_box, FALSE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(down_box), button_box, FALSE, TRUE, 0);
/**end down_box init**/
/*whole_box*/
whole_box = gtk_vbox_new(FALSE, 7);
gtk_box_pack_start(GTK_BOX(whole_box), up_image_box, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(whole_box), down_box, FALSE, FALSE, 0);
/**end whole_box**/
/*window init*/
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), g_convert("火车售票系统", -1, "UTF-8", "GB2312", NULL, NULL, NULL));
gtk_window_set_default_size(GTK_WINDOW(window), 600, 450);
g_signal_connect(G_OBJECT(window), "delete_event", G_CALLBACK(gtk_main_quit), NULL);
gtk_container_set_border_width(GTK_CONTAINER(window), 20);
gtk_container_add(GTK_CONTAINER(window), whole_box);
/**end window init**/
g_signal_connect(G_OBJECT(main_menu_about_button), "clicked", G_CALLBACK(about), NULL);
g_signal_connect(G_OBJECT(main_menu_quit_button), "clicked", G_CALLBACK(quit), NULL);
g_signal_connect(G_OBJECT(main_menu_book_button), "clicked", G_CALLBACK(book), NULL);
g_signal_connect(G_OBJECT(main_menu_check_button), "clicked", G_CALLBACK(check), NULL);
gtk_widget_show_all(window);
gtk_main();
return FALSE;
}
int quit(GtkButton *button, gpointer data)
{
GtkWidget *window;
GtkWidget *button1;
GtkWidget *button2;
GtkWidget *box1;
GtkWidget *box2;
GtkWidget *label;
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "");
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
gtk_container_set_border_width(GTK_CONTAINER(window), 30);
g_signal_connect(G_OBJECT(window), "delete_event", G_CALLBACK(gtk_widget_destroy), window);
box2 = gtk_vbox_new(TRUE, 0);
box1 = gtk_hbox_new(TRUE, 0);
gtk_container_add(GTK_CONTAINER(window), box2);
gtk_box_pack_end(GTK_BOX(box2), box1, TRUE, TRUE, 5);
label = gtk_label_new(NULL);
gtk_label_set_markup(GTK_LABEL(label), g_convert("<big><i>是否要退出售票系统?</i></big>", -1, "UTF-8", "GB2312", NULL, NULL, NULL));
gtk_box_pack_end(GTK_BOX(box2), label, FALSE, FALSE, 5);
button1 = gtk_button_new_from_stock(GTK_STOCK_OK);
gtk_box_pack_start(GTK_BOX(box1), button1, TRUE, TRUE, 5);
g_signal_connect(G_OBJECT(button1), "clicked", G_CALLBACK(gtk_main_quit), FALSE);
button2 = gtk_button_new_from_stock(GTK_STOCK_CANCEL);
gtk_box_pack_start(GTK_BOX(box1), button2, TRUE, TRUE, 5);
g_signal_connect_swapped(G_OBJECT(button2), "clicked", G_CALLBACK(gtk_widget_destroy), window);
gtk_widget_show_all(window);
return 0;
}
int about(GtkButton *button, gpointer data)
{
GtkWidget *window;
GtkWidget *notebook;
GtkWidget *label;
GtkWidget *page;
GtkWidget *fixed;
GtkWidget *image;
GtkWidget *vbox, *imagevbox, *hbox, *box;
GtkWidget *hsep;
GtkWidget *frame;
/**窗口**/
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), g_convert("关于", -1, "UTF-8", "GB2312", NULL, NULL, NULL));
g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(gtk_widget_destroy), NULL);
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
gtk_window_set_default_size(GTK_WINDOW(window), 300, 400);
gtk_container_border_width(GTK_CONTAINER(window), 5);
/**盒子**/
hbox = gtk_hbox_new(FALSE, 0);
gtk_container_add(GTK_CONTAINER(window), hbox);
vbox = gtk_vbox_new(FALSE, 0);
gtk_box_pack_start(GTK_BOX(hbox), vbox, FALSE, FALSE, 0);
imagevbox = gtk_vbox_new(FALSE, 0);
gtk_box_pack_start(GTK_BOX(vbox), imagevbox, FALSE, FALSE, 0);
box = gtk_vbox_new(FALSE, 0);
/**图片**/
image = gtk_image_new_from_file("about.png");
gtk_box_pack_start(GTK_BOX(imagevbox), image, FALSE, FALSE, 0);
/**分割线**/
hsep = gtk_hseparator_new();
gtk_box_pack_start(GTK_BOX(vbox), hsep, TRUE, TRUE, 8);
/**笔记本**/
notebook = gtk_notebook_new();
gtk_box_pack_start(GTK_BOX(vbox), notebook, TRUE, TRUE, 0);
/**框架**/
frame = gtk_frame_new(NULL);
gtk_box_pack_start(GTK_BOX(box), frame, TRUE, TRUE, 0);
/**笔记本-信息**/
page = gtk_vbox_new(FALSE, 0);
gtk_container_add(GTK_CONTAINER(frame), page);
/**自由布局**/
fixed = gtk_fixed_new();
gtk_fixed_set_has_window(GTK_FIXED(fixed), TRUE);
gtk_container_add(GTK_CONTAINER(page), fixed);
label = gtk_label_new(g_convert("软件名称:火车票预订系统", -1, "UTF-8", "GB2312", NULL, NULL, NULL));
gtk_fixed_put(GTK_FIXED(fixed), label, 10, 2);
label = gtk_label_new(g_convert("版本信息:1.0.0.0", -1, "UTF-8", "GB2312", NULL, NULL, NULL));
gtk_fixed_put(GTK_FIXED(fixed), label, 10, 22);
label = gtk_label_new(g_convert("开发团队:软工-1207-Item9", -1, "UTF-8", "GB2312", NULL, NULL, NULL));
gtk_fixed_put(GTK_FIXED(fixed), label, 10, 42);
label = gtk_label_new(g_convert("发布时间:20130323", -1, "UTF-8", "GB2312", NULL, NULL, NULL));
gtk_fixed_put(GTK_FIXED(fixed), label, 10, 96);
label = gtk_label_new(g_convert("联系方式:471766436", -1, "UTF-8", "GB2312", NULL, NULL, NULL));
gtk_fixed_put(GTK_FIXED(fixed), label, 10, 116);
label = gtk_label_new(g_convert("信息", -1, "UTF-8", "GB2312", NULL, NULL, NULL));
gtk_notebook_append_page(GTK_NOTEBOOK(notebook), box, label);
/**笔记本-描述**/
page = gtk_vbox_new(FALSE, 0);
label = gtk_label_new(NULL);
gtk_label_set_markup(GTK_LABEL(label), "<span><big>This is a programe!</big></span>");
gtk_box_pack_start(GTK_BOX(page), label, FALSE, FALSE, 0);
label = gtk_label_new(g_convert("描述", -1, "UTF-8", "GB2312", NULL, NULL, NULL));
gtk_notebook_append_page(GTK_NOTEBOOK(notebook), page, label);
gtk_widget_show_all(window);
return 0;
}
int book (GtkButton *button, gpointer data)
{
GtkWidget *window;
GtkWidget *start_station_label;
GtkWidget *end_station_label;
GtkWidget *date_label;
GtkWidget *check_button;
GtkWidget *start_station_box;
GtkWidget *end_station_box;
GtkWidget *date_box;
GtkWidget *se_box;
GtkWidget *dc_box;
GtkWidget *sedc_box;
GtkWidget *hwhole_box;
time_t rawtime;
struct tm *timeInfo;
char timeInfoArr[30];
const char *timeInfoPtr = timeInfoArr;
time(&rawtime);
timeInfo = localtime(&rawtime);
sprintf(timeInfoArr, "%d-%d-%d", 1900+timeInfo->tm_year, 1+timeInfo->tm_mon, timeInfo->tm_mday);
/*window init*/
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), g_convert("车票预订", -1, "UTF-8", "GB2312", NULL, NULL, NULL));
gtk_window_set_default_size(GTK_WINDOW(window), BOOK_WINDOW_SIZE, BOOK_WINDOW_SIZE);
gtk_container_border_width(GTK_CONTAINER(window), 10);
g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(gtk_widget_destroy), NULL);
/**end window init**/
/*start_station_label init*/
start_station_label = gtk_label_new(g_convert("*出发站点:", -1, "UTF-8", "GB2312", NULL, NULL, NULL));
gtk_label_set_justify (GTK_LABEL (start_station_label), GTK_JUSTIFY_LEFT);
/**end start_station_label init**/
/*start_station_entry init*/
g_book_start_station_entry = gtk_entry_new();
/**end start_station_entry init**/
/*start_station_box*/
start_station_box = gtk_hbox_new(FALSE, 0);
gtk_box_pack_start(GTK_BOX(start_station_box), start_station_label, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(start_station_box), g_book_start_station_entry, FALSE, FALSE, 0);
/**end start_station_box**/
/*end_station_label init*/
end_station_label = gtk_label_new(g_convert("*终到站点:", -1, "UTF-8", "GB2312", NULL, NULL, NULL));
gtk_label_set_justify (GTK_LABEL (end_station_label), GTK_JUSTIFY_LEFT);
/**end end_station_label init**/
/*end_station_entry init*/
g_book_end_station_entry = gtk_entry_new();
/**end end_station_entry init**/
/**end_station_box**/
end_station_box = gtk_hbox_new(FALSE, 0);
gtk_box_pack_start(GTK_BOX(end_station_box), end_station_label, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(end_station_box), g_book_end_station_entry, FALSE, FALSE, 0);
/**end end_station_box**/
/*date_label init*/
date_label = gtk_label_new(g_convert("*出发日期:", -1, "UTF-8", "GB2312", NULL, NULL, NULL));
gtk_label_set_justify (GTK_LABEL (date_label), GTK_JUSTIFY_LEFT);
/**end date_label init**/
/*date_entry init*/
g_book_date_entry = gtk_entry_new();
gtk_entry_set_text(GTK_ENTRY(g_book_date_entry), timeInfoPtr);
/**end date_entry init**/
/*date_box*/
date_box = gtk_hbox_new(FALSE, 0);
gtk_box_pack_start(GTK_BOX(date_box), date_label, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(date_box), g_book_date_entry, FALSE, FALSE, 0);
/**end date_box**/
/*check_button*/
check_button = gtk_button_new_with_mnemonic(g_convert("查询(_C)", -1, "UTF-8", "GB2312", NULL, NULL, NULL));
g_signal_connect(G_OBJECT(check_button), "clicked", G_CALLBACK(book_check_button_on_click), NULL);
/**end check_button**/
/*g_book_clist init*/
g_book_clist = gtk_clist_new(10);
/*set title*/
gtk_clist_set_column_title(GTK_CLIST(g_book_clist), 0, g_convert("车次", -1, "UTF-8", "GB2312", NULL, NULL, NULL));
gtk_clist_set_column_title(GTK_CLIST(g_book_clist), 1, g_convert("始发站(发车时间)", -1, "UTF-8", "GB2312", NULL, NULL, NULL));
gtk_clist_set_column_title(GTK_CLIST(g_book_clist), 2, g_convert("终点站", -1, "UTF-8", "GB2312", NULL, NULL, NULL));
gtk_clist_set_column_title(GTK_CLIST(g_book_clist), 3, g_convert("商务座", -1, "UTF-8", "GB2312", NULL, NULL, NULL));
gtk_clist_set_column_title(GTK_CLIST(g_book_clist), 4, g_convert("特等座", -1, "UTF-8", "GB2312", NULL, NULL, NULL));
gtk_clist_set_column_title(GTK_CLIST(g_book_clist), 5, g_convert("一等座", -1, "UTF-8", "GB2312", NULL, NULL, NULL));
gtk_clist_set_column_title(GTK_CLIST(g_book_clist), 6, g_convert("二等座", -1, "UTF-8", "GB2312", NULL, NULL, NULL));
gtk_clist_set_column_title(GTK_CLIST(g_book_clist), 7, g_convert("软卧", -1, "UTF-8", "GB2312", NULL, NULL, NULL));
gtk_clist_set_column_title(GTK_CLIST(g_book_clist), 8, g_convert("硬卧", -1, "UTF-8", "GB2312", NULL, NULL, NULL));
gtk_clist_set_column_title(GTK_CLIST(g_book_clist), 9, g_convert("无座", -1, "UTF-8", "GB2312", NULL, NULL, NULL));
/**end set title**/
gtk_clist_column_titles_show(GTK_CLIST(g_book_clist));
gtk_signal_connect(GTK_OBJECT(g_book_clist), "select_row", GTK_SIGNAL_FUNC(book_clist_row_on_click), NULL);
/**end g_book_clist init**/
/*put in box*/
/*start and end station box*/
se_box = gtk_hbox_new(FALSE, 0);
gtk_box_pack_start(GTK_BOX(se_box), start_station_box, FALSE, FALSE, 0);
gtk_box_pack_end(GTK_BOX(se_box), end_station_box, FALSE, FALSE, 0);
/**start and end station box**/
/*date box and check_button*/
dc_box = gtk_hbox_new(FALSE, 0);
gtk_box_pack_start(GTK_BOX(dc_box), date_box, FALSE, FALSE, 0);
gtk_box_pack_end(GTK_BOX(dc_box), check_button, FALSE, FALSE, 0);
/**end date box and check_button**/
/*se dc and clist box*/
sedc_box = gtk_vbox_new(FALSE, 0);
gtk_box_pack_start(GTK_BOX(sedc_box), se_box, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(sedc_box), dc_box, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(sedc_box), g_book_clist, FALSE, FALSE, 0);
/**end se dc and clist box**/
hwhole_box = gtk_hbox_new(FALSE, 0);
gtk_box_pack_start(GTK_BOX(hwhole_box), sedc_box, FALSE, FALSE, 0);
/**end put in box**/
gtk_container_add(GTK_CONTAINER(window), hwhole_box);
gtk_widget_show(g_book_clist);
gtk_widget_show_all(window);
return FALSE;
}
int book_check_button_on_click(GtkWidget *button, gpointer data)
{
int i;
const gchar *start_station_string = g_convert(gtk_entry_get_text(GTK_ENTRY(g_book_start_station_entry)), -1, "GB2312", "UTF-8", NULL, NULL, NULL);
const gchar *end_station_string = g_convert(gtk_entry_get_text(GTK_ENTRY(g_book_end_station_entry)), -1, "GB2312", "UTF-8", NULL, NULL, NULL);
struct station_tag *startStation = FindStation(start_station_string, g_myStations, g_slen);
struct station_tag *endStation = FindStation(end_station_string, g_myStations, g_slen);
struct head_tag *head = FindStationInTrainLine(g_myTrainLines, g_tlen, startStation, endStation);
struct node_tag *p;
char text[10][20];
char *text_ptr[10] = {text[0], text[1], text[2], text[3], text[4], text[5], text[6], text[7], text[8], text[9]};
gtk_clist_clear(GTK_CLIST(g_book_clist));
if (NULL == head) return 0;
if (NULL != g_book_check_button_head) FreeList(g_book_check_button_head);
g_pastemp.ticket.startStation_ptr = startStation;
g_pastemp.ticket.endStation_ptr = endStation;
g_book_check_button_head = head;
p = head->next_ptr;
for (i=0; i<head->numOfNode; i++)
{
if (i>7) break;
TurnTrainLineIntoString(text, p->trainLine_ptr);
gtk_clist_append(GTK_CLIST(g_book_clist), text_ptr);
p = p->next_ptr;
}
return 0;
}
int book_clist_row_on_click(GtkWidget *clist, gint row, gint column, GdkEventButton *event, gpointer data)
{
int i;
static int prerow = -1;
struct node_tag *p;
GtkWidget *name_label;
GtkWidget *name_box;
GtkWidget *id_label;
GtkWidget *id_box;
GtkWidget *tel_label;
GtkWidget *tel_box;
GtkWidget *seat_label;
GtkWidget *seat_box;
GtkWidget *sure_button;
GtkWidget *sure_box;
GtkWidget *whole_box;
GList *list = NULL;
gchar combo_text[7][20];
/*clicked*/
if (prerow != row)
{
prerow = row;
return 0;
}
else
{
prerow = -1;
}
/**end clicked**/
if (NULL == g_book_check_button_head) return -1;
p = g_book_check_button_head->next_ptr;
for (i=0; i<row; i++)
{
p = p->next_ptr;
}
//printf ("%s\n", p->trainLine_ptr->lineName);
g_pastemp.ticket.trainLine_ptr = p->trainLine_ptr;
/*name_box init*/
/*name_label init*/
name_label = gtk_label_new(g_convert("乘客姓名:", -1, "UTF-8", "GB2312", NULL, NULL, NULL));
/**end name_label init**/
/*g_book_sure_name_entry init*/
g_book_sure_name_entry = gtk_entry_new();
/**end g_book_sure_name_entry init**/
name_box = gtk_hbox_new(FALSE, 0);
gtk_box_pack_start(GTK_BOX(name_box), name_label, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(name_box), g_book_sure_name_entry, FALSE, FALSE, 0);
/**end name_box init**/
/*id_box init*/
/*id_label init*/
id_label = gtk_label_new(g_convert("身份证号:", -1, "UTF-8", "GB2312", NULL, NULL, NULL));
/**end id_label init**/
/*g_book_sure_id_entry init*/
g_book_sure_id_entry = gtk_entry_new();
/**end g_book_sure_id_entry init**/
id_box = gtk_hbox_new(FALSE, 0);
gtk_box_pack_start(GTK_BOX(id_box), id_label, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(id_box), g_book_sure_id_entry, FALSE, FALSE, 0);
/**end id_box init**/
/*tel_box init*/
/*tel_label init*/
tel_label = gtk_label_new(g_convert("电话号码:", -1, "UTF-8", "GB2312", NULL, NULL, NULL));
/**end tel_label init**/
/*g_book_sure_tel_entry init*/
g_book_sure_tel_entry = gtk_entry_new();
/**end g_book_sure_tel_entry init**/
tel_box = gtk_hbox_new(FALSE, 0);
gtk_box_pack_start(GTK_BOX(tel_box), tel_label, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(tel_box), g_book_sure_tel_entry, FALSE, FALSE, 0);
/**end tel_box init**/
/*seat_box init*/
/*seat_label*/
seat_label = gtk_label_new(g_convert("订票种类:", -1, "UTF-8", "GB2312", NULL, NULL, NULL));
/**end seat_label**/
/*g_book_sure_seat_combo init*/
g_book_sure_seat_combo = gtk_combo_new();
TurnTicketIntoString(combo_text, p->trainLine_ptr);
list = g_list_append(list, combo_text[0]);
list = g_list_append(list, combo_text[1]);
list = g_list_append(list, combo_text[2]);
list = g_list_append(list, combo_text[3]);
list = g_list_append(list, combo_text[4]);
list = g_list_append(list, combo_text[5]);
list = g_list_append(list, combo_text[6]);
gtk_combo_set_popdown_strings(GTK_COMBO(g_book_sure_seat_combo), list);
/*****************************************/
/*********** ADD EDITABLE! ***************/
/*****************************************/
g_list_free(list);
/**end g_book_sure_seat_combo init**/
seat_box = gtk_hbox_new(FALSE, 0);
gtk_box_pack_start(GTK_BOX(seat_box), seat_label, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(seat_box), g_book_sure_seat_combo, FALSE, FALSE, 0);
/**end seat_box init**/
/*sure_box init*/
/*sure_button*/
sure_button = gtk_button_new_with_mnemonic(g_convert("确认(_Y)", -1, "UTF-8", "GB2312", NULL, NULL, NULL));
g_signal_connect(G_OBJECT(sure_button), "clicked", G_CALLBACK(book_sure_buttn_clicked), p->trainLine_ptr);
/**end sure_button**/
sure_box = gtk_hbox_new(FALSE, 0);
gtk_box_pack_start(GTK_BOX(sure_box), sure_button, FALSE, FALSE, 80);
/**end sure_box init**/
/*whole_box init*/
whole_box = gtk_vbox_new(FALSE, 0);
gtk_box_pack_start(GTK_BOX(whole_box), name_box, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(whole_box), id_box, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(whole_box), tel_box, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(whole_box), seat_box, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(whole_box), sure_box, FALSE, FALSE, 0);
/**end whole_box init**/
/*g_book_book_window init*/
g_book_book_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(g_book_book_window), g_convert("预订", -1, "UTF-8", "GB2312", NULL, NULL, NULL));
gtk_window_set_default_size(GTK_WINDOW(g_book_book_window), 200, 200);
g_signal_connect(G_OBJECT(g_book_book_window), "destroy", G_CALLBACK(gtk_widget_destroy), g_book_book_window);
gtk_container_border_width(GTK_CONTAINER(g_book_book_window), 20);
gtk_container_add(GTK_CONTAINER(g_book_book_window), whole_box);
/**end g_book_book_window init**/
gtk_widget_show_all(g_book_book_window);
return 0;
}
int book_sure_buttn_clicked(GtkWidget *button, struct trainline_tag *data)
{
GtkWidget *sure_button;
GtkWidget *cancel_button;
GtkWidget *imfor_label;
GtkWidget *button_box;
GtkWidget *whole_box;
GtkWidget *hwhole_box;
GtkWidget *frame;
struct trainline_tag *p = data;
const gchar *passenger_name = g_convert(gtk_entry_get_text(GTK_ENTRY(g_book_sure_name_entry)), -1, "GB2312", "UTF-8", NULL, NULL, NULL);
const gchar *passenger_id = g_convert(gtk_entry_get_text(GTK_ENTRY(g_book_sure_id_entry)), -1, "GB2312", "UTF-8", NULL, NULL, NULL);
const gchar *passenger_tel = g_convert(gtk_entry_get_text(GTK_ENTRY(g_book_sure_tel_entry)), -1, "GB2312", "UTF-8", NULL, NULL, NULL);
const gchar *passenger_seat = g_convert(gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(g_book_sure_seat_combo)->entry)), -1, "GB2312", "UTF-8", NULL, NULL, NULL);
char passenger_imfor_string[100];
gtk_widget_destroy(g_book_book_window);
strcpy(g_pastemp.pasName, passenger_name);
strcpy(g_pastemp.idNum, passenger_id);
strcpy(g_pastemp.telNum, passenger_tel);
g_pastemp.ticket.kindOfSeat = (enum kindOfSeat_tag)TurnSeatIntoKind(passenger_seat);
g_pastemp.ticket.stationDif = GetStationDif(g_pastemp.ticket.trainLine_ptr, g_pastemp.ticket.startStation_ptr, g_pastemp.ticket.endStation_ptr);
g_pastemp.ticket.price = CalTicketPrice(g_pastemp.ticket.stationDif, p->kindOfLine, g_pastemp.ticket.kindOfSeat);
/*g_book_sure_window init*/
g_book_sure_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(g_book_sure_window), g_convert("确认预订", -1, "UTF-8", "GB2312", NULL, NULL, NULL));
//gtk_window_set_default_size(GTK_WINDOW(g_book_sure_window), 200, 200);
g_signal_connect(G_OBJECT(g_book_sure_window), "destroy", G_CALLBACK(gtk_widget_destroy), g_book_sure_window);
gtk_container_border_width(GTK_CONTAINER(g_book_sure_window), 20);
/**end g_book_sure_window init**/
/*sure_button init*/
sure_button = gtk_button_new_from_stock(GTK_STOCK_OK);
g_signal_connect(G_OBJECT(sure_button), "clicked", G_CALLBACK(book_final_button_clicked), data);
/**end sure_button init**/
/*cancel_button init*/
cancel_button = gtk_button_new_from_stock(GTK_STOCK_CANCEL);
g_signal_connect_swapped(G_OBJECT(cancel_button), "clicked", G_CALLBACK(gtk_widget_destroy), g_book_sure_window);
/**end cancel_button init**/
/*imfor_label init*/
sprintf(passenger_imfor_string, "乘客姓名:%s\n身份证号:%s\n电话号码:%s\n车票种类:%s\n车票价格:%d", passenger_name, passenger_id, passenger_tel, passenger_seat, (int)g_pastemp.ticket.price);
imfor_label = gtk_label_new(g_convert(passenger_imfor_string, -1, "UTF-8", "GB2312", NULL, NULL, NULL));
/**end imfor_label init**/
/*button_box init*/
button_box = gtk_hbox_new(FALSE, 0);
gtk_box_pack_start(GTK_BOX(button_box), sure_button, FALSE, FALSE, 0);
gtk_box_pack_end(GTK_BOX(button_box), cancel_button, FALSE, FALSE, 0);
/**end button_box init**/
/*frame init*/
frame = gtk_frame_new(g_convert("乘客信息:", -1, "UTF-8", "GB2312", NULL, NULL, NULL));
gtk_container_add(GTK_CONTAINER(frame), imfor_label);
/**end frame init**/
/*whole_box init*/
whole_box = gtk_vbox_new(FALSE, 0);
gtk_box_pack_start(GTK_BOX(whole_box), frame, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(whole_box), button_box, FALSE, FALSE, 0);
/**end whole_box init**/
/*hwhole_box init*/
hwhole_box = gtk_hbox_new(FALSE, 0);
gtk_box_pack_start(GTK_BOX(hwhole_box), whole_box, FALSE, FALSE, 0);
/**end hwhole_box init**/
gtk_container_add(GTK_CONTAINER(g_book_sure_window), hwhole_box);
gtk_widget_show_all(g_book_sure_window);
return 0;
}
int book_final_button_clicked(GtkWidget *button, struct trainline_tag *data)
{
GtkWidget *dialog;
gtk_widget_destroy(g_book_sure_window);
ModifyPassenger(g_myPassengers, &g_plen, &g_pastemp);
BookTickets(g_pastemp.ticket.kindOfSeat, data);
dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_INFO, GTK_BUTTONS_OK, g_convert("预订成功!", -1, "UTF-8", "GB2312", NULL, NULL, NULL));
gtk_dialog_run(GTK_DIALOG(dialog));
gtk_widget_destroy(dialog);
return 0;
}
int check(GtkWidget *button, gpointer data)
{
GtkWidget *window;
GtkWidget *name_label;
GtkWidget *name_box;
GtkWidget *id_label;
GtkWidget *id_box;
GtkWidget *tel_label;
GtkWidget *tel_box;
GtkWidget *check_button;
GtkWidget *check_box;
GtkWidget *whole_box;
/*name_box init*/
/*name_label init*/
name_label = gtk_label_new(g_convert("乘客姓名:", -1, "UTF-8", "GB2312", NULL, NULL, NULL));
/**end name_label init**/
/*g_check_name_entry init*/
g_check_name_entry = gtk_entry_new();
/**end g_check_name_entry init**/
name_box = gtk_hbox_new(FALSE, 0);
gtk_box_pack_start(GTK_BOX(name_box), name_label, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(name_box), g_check_name_entry, FALSE, FALSE, 0);
/**end name_box init**/
/*id_box init*/
/*id_label init*/
id_label = gtk_label_new(g_convert("身份证号:", -1, "UTF-8", "GB2312", NULL, NULL, NULL));
/**end id_label init**/
/*g_check_id_entry init*/
g_check_id_entry = gtk_entry_new();
/**end g_check_id_entry init**/
id_box = gtk_hbox_new(FALSE, 0);
gtk_box_pack_start(GTK_BOX(id_box), id_label, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(id_box), g_check_id_entry, FALSE, FALSE, 0);
/**end id_box init**/
/*tel_box init*/
/*tel_label init*/
tel_label = gtk_label_new(g_convert("电话号码:", -1, "UTF-8", "GB2312", NULL, NULL, NULL));
/**end tel_label init**/
/*g_check_tel_entry init*/
g_check_tel_entry = gtk_entry_new();
/**end g_check_tel_entry init**/
tel_box = gtk_hbox_new(FALSE, 0);
gtk_box_pack_start(GTK_BOX(tel_box), tel_label, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(tel_box), g_check_tel_entry, FALSE, FALSE, 0);
/**end tel_box init**/
/*check_button init*/
check_button = gtk_button_new_with_mnemonic(g_convert("查询(_C)", -1, "UTF-8", "GB2312", NULL, NULL, NULL));
g_signal_connect(G_OBJECT(check_button), "clicked", G_CALLBACK(check_check_button_on_click), NULL);
/**end check_button init**/
/*check_box init*/
check_box = gtk_hbox_new(FALSE, 0);
gtk_box_pack_start(GTK_BOX(check_box), check_button, FALSE, FALSE, 80);
/**end check_box init**/
/*whole_box init*/
whole_box = gtk_vbox_new(FALSE, 0);
gtk_box_pack_start(GTK_BOX(whole_box), name_box, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(whole_box), id_box, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(whole_box), tel_box, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(whole_box), check_box, FALSE, FALSE, 0);
/**end whole_box init**/
/*window init*/
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), g_convert("查询订票讯息", -1, "UTF-8", "GB2312", NULL, NULL, NULL));
//gtk_window_set_default_size(GTK_WINDOW(window), 200, 200);
g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(gtk_widget_destroy), window);
gtk_container_border_width(GTK_CONTAINER(window), 20);
gtk_container_add(GTK_CONTAINER(window), whole_box);
/**end window init**/
gtk_widget_show_all(window);
return 0;
}
int check_check_button_on_click(GtkWidget *button, gpointer data)
{
int i;
GtkWidget *page;
GtkWidget *page_name_label;
GtkWidget *info_label;
GtkWidget *return_button;
GtkWidget *return_button_box;
GtkWidget *whole_box;
GtkWidget *hwhole_box;
struct passenger_tag *passenger_ptr;
char info[100];
const gchar *passenger_name = g_convert(gtk_entry_get_text(GTK_ENTRY(g_check_name_entry)), -1, "GB2312", "UTF-8", NULL, NULL, NULL);
const gchar *passenger_id = g_convert(gtk_entry_get_text(GTK_ENTRY(g_check_id_entry)), -1, "GB2312", "UTF-8", NULL, NULL, NULL);
const gchar *passenger_tel = g_convert(gtk_entry_get_text(GTK_ENTRY(g_check_tel_entry)), -1, "GB2312", "UTF-8", NULL, NULL, NULL);
strcpy(g_pastemp.pasName, passenger_name);
strcpy(g_pastemp.idNum, passenger_id);
strcpy(g_pastemp.telNum, passenger_tel);
passenger_ptr = FindPassenger(g_myPassengers, g_plen, &g_pastemp);
if (NULL == passenger_ptr || 0 == passenger_ptr->numOfTickets)
{
g_check_check_window = gtk_message_dialog_new(NULL, GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_INFO, GTK_BUTTONS_OK, g_convert("您未订票!", -1, "UTF-8", "GB2312", NULL, NULL, NULL));
gtk_dialog_run(GTK_DIALOG(g_check_check_window));
gtk_widget_destroy(g_check_check_window);
return 0;
}
g_passenger_return_ticket = passenger_ptr;
/*g_check_return_notebook init*/
g_check_return_notebook = gtk_notebook_new();
/**end g_check_return_notebook init**/
/*pagr init*/
for (i=0; i<passenger_ptr->numOfTickets; i++)
{
sprintf(info, "车次:%s\n%s 到 %s\n乘车人:%s\n身份证号:%s\n票价:%d"
, passenger_ptr->tickets[i].trainLine_ptr->lineName
, passenger_ptr->tickets[i].startStation_ptr->stationName
, passenger_ptr->tickets[i].endStation_ptr->stationName
, passenger_ptr->pasName
, passenger_ptr->idNum
, (int)passenger_ptr->tickets[i].price);
info_label = gtk_label_new(g_convert(info, -1, "UTF-8", "GB2312", NULL, NULL, NULL));
sprintf(info, "车票%d", i+1);
page_name_label = gtk_label_new(g_convert(info, -1, "UTF-8", "GB2312", NULL, NULL, NULL));
page = gtk_vbox_new(FALSE, 0);
gtk_box_pack_start(GTK_BOX(page), info_label, FALSE, FALSE, 0);
gtk_notebook_append_page(GTK_NOTEBOOK(g_check_return_notebook), page, page_name_label);
}
/**end pagr init**/
/*return_button*/
return_button = gtk_button_new_with_mnemonic(g_convert("退票(_R)", -1, "UTF-8", "GB2312", NULL, NULL, NULL));
g_signal_connect(G_OBJECT(return_button), "clicked", G_CALLBACK(check_return_button_on_click), (gpointer)gtk_notebook_get_current_page(GTK_NOTEBOOK(g_check_return_notebook)));
return_button_box = gtk_hbox_new(FALSE, 0);
gtk_box_pack_start(GTK_BOX(return_button_box),return_button, FALSE, FALSE, 70);
/**end return_button**/
/*whole_box init*/
whole_box = gtk_vbox_new(FALSE, 0);
gtk_box_pack_start(GTK_BOX(whole_box), g_check_return_notebook, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(whole_box), return_button_box, FALSE, FALSE, 0);
gtk_container_border_width(GTK_CONTAINER(whole_box), 20);
/**end whole_box init**/
hwhole_box = gtk_hbox_new(FALSE, 0);
gtk_box_pack_start(GTK_BOX(hwhole_box), whole_box, FALSE, FALSE, 0);
/*g_check_check_window init*/
g_check_check_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(g_check_check_window), g_convert("查询结果", -1, "UTF-8", "GB2312", NULL, NULL, NULL));
g_signal_connect(G_OBJECT(g_check_check_window), "destroy", G_CALLBACK(gtk_widget_destroy), NULL);
gtk_window_set_position(GTK_WINDOW(g_check_check_window), GTK_WIN_POS_CENTER);
//gtk_g_check_check_window_set_default_size(GTK_WINDOW(g_check_check_window), 400, 300);
gtk_container_add(GTK_CONTAINER(g_check_check_window), hwhole_box);
gtk_container_border_width(GTK_CONTAINER(g_check_check_window), 5);
gtk_widget_show_all(g_check_check_window);
/**end g_check_check_window init**/
return 0;
}
int check_return_button_on_click(GtkWidget *button, gpointer data)
{
GtkWidget *dialog;
ReturnTicket(g_passenger_return_ticket, gtk_notebook_get_current_page(GTK_NOTEBOOK(g_check_return_notebook)));
gtk_widget_destroy(g_check_check_window);
dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_INFO, GTK_BUTTONS_OK, g_convert("退票成功!", -1, "UTF-8", "GB2312", NULL, NULL, NULL));
gtk_dialog_run(GTK_DIALOG(dialog));
gtk_widget_destroy(dialog);
return 0;
}
[代码运行效果截图]
[源代码打包下载]
中级程序员
by: 阿小 发表于:2013-08-22 19:04:55 顶(1) | 踩(0) 回复
这个程序是用gtk是实现的,需要linux环境,或者在windows下配置gtk的环境也可以运行,没有配置可以,我将dll文件加进去了,直接可以运行exe文件,需运行代码的话,可以自行配置环境。
回复评论