标签:
answer.c
#include <gtk/gtk.h> #include "vipLogin.h" #include "callinfo.h" #include "stdlib.h" #include <string.h> void answer_user( GtkWidget *widget,gpointer data ) { callinfo(); } void answer_VIP( GtkWidget *widget,gpointer data ) { vipLogin( ); } void staffSkip() { char buf[BUFSIZ]="staffSkip#X#X"; strcpy(buf,sendMsg(buf)); int num=atoi(buf); /////////////to do : hu jiao num hao ke hu ! } int answer( ) { GtkWidget *window1; GtkWidget *button2; GtkWidget *button3; GtkWidget *label6; GtkWidget *label7; GtkWidget *table; window1 = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_title (GTK_WINDOW (window1), "VIP登陆"); gtk_window_set_default_size(GTK_WINDOW(window1), 500, 500); gtk_window_set_position(GTK_WINDOW(window1),GTK_WIN_POS_CENTER_ALWAYS ); gtk_container_set_border_width (GTK_CONTAINER (window1), 30); table = gtk_table_new (9, 9, TRUE); gtk_container_add (GTK_CONTAINER (window1), table); button2 = gtk_button_new_with_label ("普通用户叫号"); button3 = gtk_button_new_with_label ("VIP用户登陆叫号"); label6 = gtk_label_new ("预计等待时间"); label7 = gtk_label_new ("预计等待时间,已为您节省**"); gtk_table_attach_defaults (GTK_TABLE (table), button2, 0, 4, 2, 6); gtk_table_attach_defaults (GTK_TABLE (table), button3, 5, 9, 2, 6); gtk_table_attach_defaults (GTK_TABLE (table), label6, 0, 4, 6, 7); gtk_table_attach_defaults (GTK_TABLE (table), label7, 5, 9, 6, 7); g_signal_connect (G_OBJECT (button2), "clicked",G_CALLBACK (answer_user), (gpointer) window1); g_signal_connect (G_OBJECT (button3), "clicked",G_CALLBACK (answer_VIP), (gpointer) window1); gtk_widget_show_all(window1); gtk_main (); return 0; }
call.c
#include <gtk/gtk.h> #include "answer.h" void do_button3(GtkWidget *widget,gpointer data ) { GtkWidget* dialog ; dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_INFO,GTK_BUTTONS_OK,"\n点击叫号按钮 "); gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy(dialog); } void do_button4(GtkWidget *widget,gpointer data ) { answer(); } void call() { GtkWidget *window; GtkWidget *button1; GtkWidget *button2; GtkWidget *fixed = gtk_fixed_new(); 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_ALWAYS ); gtk_window_set_default_size(GTK_WINDOW(window),420,470); g_signal_connect (G_OBJECT (window), "destroy", G_CALLBACK (gtk_main_quit), NULL); g_signal_connect_swapped (G_OBJECT (window), "delete_event", G_CALLBACK (gtk_widget_destroy), window); button1= gtk_button_new_with_label("说明"); gtk_widget_set_size_request(button1,250,50); button2= gtk_button_new_with_label("欢迎来到叫号系统"); gtk_widget_set_size_request(button2,250,305); g_signal_connect (G_OBJECT(button1),"clicked",G_CALLBACK(do_button3),(gpointer)window); g_signal_connect (G_OBJECT(button2),"clicked",G_CALLBACK(do_button4),(gpointer)window); gtk_fixed_put(GTK_FIXED(fixed),button1,85, 25); gtk_fixed_put(GTK_FIXED(fixed),button2,85, 110); gtk_container_add(GTK_CONTAINER(window),fixed); gtk_widget_show_all(window); gtk_main (); }
callinfo.c
#include <gtk/gtk.h> #include <string.h> void callinfo() { GtkWidget *dialog; //提示框 gchar* msg="\n\n叫号成功! \n\n您当前的号数是:0101\n\n您前面的普通用户人数是:26 \n\n您前面的VIP用户人数是:54 "; GtkMessageType type = GTK_MESSAGE_INFO; //信息消息 //GTK_DIALOG_MODAL 对话框模式 GTK_BUTTONS_OK 只有一个‘OK‘按钮 dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, type, GTK_BUTTONS_OK,msg ); gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy(dialog); //销毁dialog }
client.c
#include <stdio.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <string.h> #include <arpa/inet.h> char* sendMsg(char buf[BUFSIZ]) { int client_sockfd; int len; struct sockaddr_in remote_addr; //服务器端网络地址结构体 //char buf[BUFSIZ]; //数据传送的缓冲区 memset(&remote_addr,0,sizeof(remote_addr)); //数据初始化--清零 remote_addr.sin_family=AF_INET; //设置为IP通信 remote_addr.sin_addr.s_addr=inet_addr("127.0.0.1");//服务器IP地址 remote_addr.sin_port=htons(8000); //服务器端口号 /*创建客户端套接字--IPv4协议,面向连接通信,TCP协议*/ if((client_sockfd=socket(PF_INET,SOCK_STREAM,0))<0) { perror("socket"); return NULL; } /*将套接字绑定到服务器的网络地址上*/ if(connect(client_sockfd,(struct sockaddr *)&remote_addr,sizeof(struct sockaddr))<0) { perror("connect"); return NULL; } /*发送接收信息并打印接收信息--recv返回接收到的字节数,send返回发送的字节数*/ len=send(client_sockfd,buf,strlen(buf),0); len=recv(client_sockfd,buf,BUFSIZ,0); close(client_sockfd);//关闭套接字 return buf; }
client.c
#include <gtk/gtk.h> #include "call.h" int main(int argc,char *argv[]) { gtk_init(&argc,&argv); /*初始化GTK+工具库*/ call(); return 0; }
info.h
#include <stdio.h> #include <string.h> #include <malloc.h> struct notice { char content[BUFSIZ]; struct notice* next; } struct notice* get_notice() { struct notice* n,*new,*old; char filename[]="notice.txt"; FILE* fp; char str[BUFSIZ]; if((fp=fopen(filename,"rt"))==NULL) { printf("error!\n"); return NULL; } n=new=(struct notice*)malloc(sizeof(struct notice)); while(!fefo(fp)) { if(fread(new,sizeof(struct notice),1,fp)!=1) break; new->next=(struct notice*)malloc(sizeof(struct notice)); old=new; new=new->next; } old->next=NULL; fclose(fp); return n; } void set_notice(struct stu *notice,char* s) //s : "at" or "wt" { char filename[]="notice.txt"; FILE *fp; if ((fp=fopen(filename,s))==NULL) printf ("error!\n"); while (head!=NULL) { fwrite(head,sizeof (struct stu ),1,fp); notice=notice->next ; } fclose (fp); }
Manager_Login.c
#include <gtk/gtk.h> void login2( GtkWidget *widget,gpointer data ) { gtk_widget_hide(data); Manager_Work(); } void end_Login2( GtkWidget *widget,gpointer data ) { gtk_widget_hide(data); Manager_Login( ); } gint delete_event( GtkWidget *widget,GdkEvent *event,gpointer data ) { g_print ("delete event occurred\n"); return TRUE; } void destroy( GtkWidget *widget,gpointer data ) { gtk_main_quit (); } int Manager_Login( ) { GtkWidget *window2; GtkWidget *label8; GtkWidget *label9; GtkWidget *label10; GtkWidget *label11; GtkWidget *button4; GtkWidget *button5; GtkWidget *table; window2 = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_title (GTK_WINDOW (window2), "经理登陆"); gtk_window_set_default_size(GTK_WINDOW(window2), 400, 400); gtk_container_set_border_width (GTK_CONTAINER (window2), 30); table = gtk_table_new (12, 9, TRUE); gtk_container_add (GTK_CONTAINER (window2), table); label8 = gtk_label_new ("用户名:"); label9= gtk_entry_new (); label10 = gtk_label_new ("密码:"); label11 = gtk_entry_new (); button4 = gtk_button_new_with_label ("登陆"); button5 = gtk_button_new_with_label ("取消"); g_signal_connect (G_OBJECT (button4), "clicked",G_CALLBACK (login2), (gpointer) window2); g_signal_connect (G_OBJECT (button5), "clicked",G_CALLBACK (end_Login2), (gpointer) window2); gtk_table_attach_defaults (GTK_TABLE (table), label8, 1, 4, 3, 4); gtk_table_attach_defaults (GTK_TABLE (table), label9, 4, 8, 3, 4); gtk_table_attach_defaults (GTK_TABLE (table), label10, 1, 4, 5, 6); gtk_table_attach_defaults (GTK_TABLE (table), label11, 4, 8, 5, 6); gtk_table_attach_defaults (GTK_TABLE (table), button5, 2, 3, 7, 8); gtk_table_attach_defaults (GTK_TABLE (table), button4, 6, 7, 7, 8); gtk_widget_show_all(window2); gtk_main (); return 0; }
manager_test.c
#include <gtk/gtk.h> #include "Manager_Login.h" #include "Manager_Work.h" int main( int argc,char *argv[] ) { gtk_init(&argc,&argv); Manager_Login(); return 0; }
Manager_Work.c
#include <gtk/gtk.h> void f1( GtkWidget *widget,gpointer data ) { } void f2( GtkWidget *widget,gpointer data ) { } void f3( GtkWidget *widget,gpointer data ) { } void f4( GtkWidget *widget,gpointer data ) { } void f( GtkWidget *widget,gpointer data ) { gtk_widget_hide(data); Manager_Login( ); } int Manager_Work( ) { GtkWidget *window2; GtkWidget *label1; GtkWidget *label2; GtkWidget *label3; GtkWidget *label4; GtkWidget *button1; GtkWidget *button2; GtkWidget *button3; GtkWidget *button4; GtkWidget *button; GtkWidget *table; window2 = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_title (GTK_WINDOW (window2), "查询页面"); gtk_window_set_default_size(GTK_WINDOW(window2), 400, 400); gtk_container_set_border_width (GTK_CONTAINER (window2), 30); table = gtk_table_new (12, 10, TRUE); gtk_container_add (GTK_CONTAINER (window2), table); label1 = gtk_label_new ("经理VIP操作区:"); label2 = gtk_label_new ("经理业务查询区:"); label3 = gtk_label_new (""); label4 = gtk_label_new (""); button1 = gtk_button_new_with_label ("VIP查询"); button2 = gtk_button_new_with_label ("VIP添加"); button3 = gtk_button_new_with_label ("VIP删除"); button4 = gtk_button_new_with_label ("业务办理查询"); button = gtk_button_new_with_label ("经理退出"); g_signal_connect (G_OBJECT (button4), "clicked",G_CALLBACK (f4), (gpointer) window2); g_signal_connect (G_OBJECT (button3), "clicked",G_CALLBACK (f3), (gpointer) window2); g_signal_connect (G_OBJECT (button2), "clicked",G_CALLBACK (f2), (gpointer) window2); g_signal_connect (G_OBJECT (button1), "clicked",G_CALLBACK (f1), (gpointer) window2); g_signal_connect (G_OBJECT (button), "clicked",G_CALLBACK (f), (gpointer) window2); gtk_table_attach_defaults (GTK_TABLE (table), label1, 0, 3, 1, 2); gtk_table_attach_defaults (GTK_TABLE (table), button1, 0, 3, 2, 3); gtk_table_attach_defaults (GTK_TABLE (table), button2, 0, 3, 3, 4); gtk_table_attach_defaults (GTK_TABLE (table), button3, 0, 3, 4, 5); gtk_table_attach_defaults (GTK_TABLE (table), label2, 0, 3, 6, 7); gtk_table_attach_defaults (GTK_TABLE (table), button4, 0, 3, 7, 8); gtk_table_attach_defaults (GTK_TABLE (table), button, 0, 3, 11, 12); gtk_widget_show_all(window2); gtk_main (); return 0; }
request.c
#include <gtk/gtk.h> #include "answer.h" void answers( GtkWidget *widget,gpointer data ) { gtk_widget_hide(data); answer(); } int request( ) { GtkWidget *window; GtkWidget *button; GtkWidget *label1; GtkWidget *label2; GtkWidget *label3; GtkWidget *label4; GtkWidget *label5; GtkWidget *button1; GtkWidget *table; window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_title (GTK_WINDOW (window), "叫号系统"); gtk_window_set_default_size(GTK_WINDOW(window), 500, 500); gtk_window_set_position(GTK_WINDOW(window),GTK_WIN_POS_CENTER_ALWAYS ); gtk_container_set_border_width (GTK_CONTAINER (window), 30); table = gtk_table_new (8, 3, TRUE); gtk_container_add (GTK_CONTAINER (window), table); label1 = gtk_label_new ("柜台1服务情况"); label2= gtk_label_new ("柜台2服务情况"); label3 = gtk_label_new ("柜台3服务情况"); label4 = gtk_label_new ("柜台4服务情况"); label5 = gtk_label_new ("目前排队人数"); //Button = gtk_button_new_with_label ("welcome!"); button1 = gtk_button_new_with_label ("叫号"); g_signal_connect (G_OBJECT (button1), "clicked",G_CALLBACK (answers), (gpointer) window); //gtk_table_attach_defaults (GTK_TABLE (table), button, 0, 1, 0, 4); gtk_table_attach_defaults (GTK_TABLE (table), label1, 0, 1, 3, 4); gtk_table_attach_defaults (GTK_TABLE (table), label2, 0, 1, 4, 5); gtk_table_attach_defaults (GTK_TABLE (table), label3, 0, 1, 5, 6); gtk_table_attach_defaults (GTK_TABLE (table), label4, 0, 1, 6, 7); gtk_table_attach_defaults (GTK_TABLE (table), button1, 1, 3, 1, 6); gtk_table_attach_defaults (GTK_TABLE (table), label5, 1, 3, 6, 7); gtk_widget_show_all(window); gtk_main (); return 0; }
service.c
#include <stdio.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <string.h> #include <arpa/inet.h> struct user { int num; struct* next; } //int user_num=0; //普通用户数量 //int vip_num=0; //VIP用户数量 int all[3]; int finish[3]; int counter[2]; int callnum; int dealnum; struct user* userhead,* usernow=NULL; userhead=usernow=(struct user*)malloc(sizeof(struct user)); struct user* viphead,* vipnow=NULL; viphead=vipnow=(struct user*)malloc(sizeof(struct user)); char* buf1; //哪种请求 char* buf2; //字段1,如用户名 char* buf3; //字段2,如密码 int len; char buf[BUFSIZ]; //数据传送的缓冲区 int client_sockfd; //客户端套接字 void parseBuf(char buf[]); void doService(); int main(int argc, char *argv[]) { int server_sockfd; //服务器端套接字 struct sockaddr_in my_addr; //服务器网络地址结构体 struct sockaddr_in remote_addr; //客户端网络地址结构体 int sin_size; memset(&my_addr,0,sizeof(my_addr)); //数据初始化--清零 my_addr.sin_family=AF_INET; //设置为IP通信 my_addr.sin_addr.s_addr=INADDR_ANY;//服务器IP地址--允许连接到所有本地地址上 my_addr.sin_port=htons(8000); //服务器端口号 /*创建服务器端套接字--IPv4协议,面向连接通信,TCP协议*/ if((server_sockfd=socket(PF_INET,SOCK_STREAM,0))<0) { perror("socket"); return 1; } /*将套接字绑定到服务器的网络地址上*/ if (bind(server_sockfd,(struct sockaddr *)&my_addr,sizeof(struct sockaddr))<0) { perror("bind"); return 1; } /*监听连接请求--监听队列长度为5*/ listen(server_sockfd,5); sin_size=sizeof(struct sockaddr_in); while(1) { /*等待客户端连接请求到达*/ if((client_sockfd=accept(server_sockfd,(struct sockaddr *)&remote_addr,&sin_size))<0) { perror("accept"); return 1; } //printf("\n\n\naccept client %s\n",inet_ntoa(remote_addr.sin_addr)); //len=send(client_sockfd,"Welcome to my server",21,0);//发送欢迎信息 /*接收客户端的数据并将其发送给客户端--recv返回接收到的字节数,send返回发送的字节数*/ while((len=recv(client_sockfd,buf,BUFSIZ,0))>0) { buf1=buf2=buf3=NULL; parseBuf(buf); doService(); } close(client_sockfd); } close(server_sockfd); return 0; } void parseBuf(char buf[]) { char delims[] = "#"; char *result = NULL; result = strtok(buf,delims); buf1=result; result = strtok( NULL, delims ); buf2=result; result = strtok( NULL, delims ); buf3=result; } void doService() { if(strstr(buf1,"vipLogin")!=NULL) { char res[BUFSIZ]; if(strcmp(buf2,"aaa")&&strcmp(buf2,"bbb")) strcpy(res,"2"); else if(strcmp(buf3,"123")) strcpy(res,"3"); else strcpy(res,"1"); len=send(client_sockfd,res,BUFSIZ,0); } else if(strstr(buf1,"staffLogin")!=NULL) { char res[BUFSIZ]; if(strcmp(buf2,"lmx")&&strcmp(buf2,"lwc")) strcpy(res,"2"); else if(strcmp(buf3,"123")) strcpy(res,"3"); else strcpy(res,"1"); len=send(client_sockfd,res,BUFSIZ,0); } else if(strstr(buf1,"staffCall")!=NULL) //staffCall#[guitai]#[vip] { char res[BUFSIZ]; } else if(strstr(buf1,"staffSkip")!=NULL) //staffSkip#[]#[] { char res[BUFSIZ]; dealnum++; all[0]--; if(userhead->num==dealnum) { userhead=userhead->next; all[1]--;} else { viphead=viphead->next; all[2]--;} itoa(dealnum+1,res,10); len=send(client_sockfd,res,BUFSIZ,0); //fan hui xia yi ge yao shou li de } else if(strstr(buf1,"userCall")!=NULL) //userCall#[vip]#[] { char res[BUFSIZ]; callnum++; all[0]++; if(!strcmp(buf2,"1")) //common user { usernow->num=callnum; usernow->next=(struct user*)malloc(sizeof(struct user)); usernow=usernow->next; all[1]++; } else { vipnow->num=callnum; vipnow->next=(struct user*)malloc(sizeof(struct user)); vipnow=vipnow->next; all[2]++; } itoa(callnum,res,10); len=send(client_sockfd,res,BUFSIZ,0); //fan hui piao hao } else { printf("\n%s\n",buf1); printf("\n%s\n",buf2); printf("\n%s\n",buf3); } }
show.c
#include <gtk/gtk.h> void do_button(GtkWidget *widget,gpointer data ) { } void show(gchar* text){ GtkWidget *window; GtkWidget *button; GtkWidget *entry; GtkWidget *fixed = gtk_fixed_new(); 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_ALWAYS ); gtk_window_set_default_size(GTK_WINDOW(window),300,120); g_signal_connect (G_OBJECT (window), "destroy", G_CALLBACK (gtk_main_quit), NULL); g_signal_connect_swapped (G_OBJECT (window), "delete_event", G_CALLBACK (gtk_widget_destroy), window); entry = gtk_entry_new (); gtk_widget_set_size_request(entry ,250,33); gtk_entry_set_text(entry,text); button= gtk_button_new_with_label("查询"); gtk_widget_set_size_request(button,66,33); g_signal_connect (G_OBJECT(button),"clicked",G_CALLBACK(do_button),(gpointer)window); gtk_fixed_put(GTK_FIXED(fixed),entry,25, 20); gtk_fixed_put(GTK_FIXED(fixed),button,120,80); gtk_container_add(GTK_CONTAINER(window),fixed); gtk_widget_show_all(window); gtk_main (); }
Staff_Login.c
#include <gtk/gtk.h> #include <string.h> #include "stdlib.h" #include "client.h" #include "callinfo.h" GtkWidget* name; GtkWidget* password; void login( GtkWidget *widget,gpointer data ) { char Buf1[BUFSIZ]; char Buf2[BUFSIZ]; strcpy(Buf1,gtk_entry_get_text(GTK_ENTRY(name))); strcpy(Buf2,gtk_entry_get_text(GTK_ENTRY(password))); char Buf[BUFSIZ]={‘\0‘}; strcat(Buf,"staffLogin#"); strcat(Buf,Buf1); strcat(Buf,"#"); strcat(Buf,Buf2); char res[BUFSIZ]; strcpy(res,sendMsg(Buf)); if(res[0]==‘1‘){ Staff_Work1(); }else if(res[0]==‘2‘){ GtkWidget *dialog; //提示框 gchar* msg="\n\n用户名错误! "; GtkMessageType type = type = GTK_MESSAGE_ERROR; //信息消息 dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, type, GTK_BUTTONS_OK,msg ); gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy(dialog); //销毁dialog }else if(res[0]==‘3‘){ GtkWidget *dialog; //提示框 gchar* msg="\n\n密码错误! "; GtkMessageType type = type = GTK_MESSAGE_ERROR; //信息消息 dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, type, GTK_BUTTONS_OK,msg ); gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy(dialog); //销毁dialog }else{ GtkWidget *dialog; //提示框 gchar* msg="\n\n用户不存在! "; GtkMessageType type = type = GTK_MESSAGE_ERROR; //信息消息 dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, type, GTK_BUTTONS_OK,msg ); gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy(dialog); //销毁dialog } } void end_Login( GtkWidget *widget,gpointer data ) { gtk_widget_hide(data); } gint delete_event( GtkWidget *widget,GdkEvent *event,gpointer data ) { g_print ("delete event occurred\n"); return TRUE; } void destroy( GtkWidget *widget,gpointer data ) { gtk_main_quit (); } int Staff_Login( ) { GtkWidget *window2; GtkWidget *label8; GtkWidget *label10; GtkWidget *button4; GtkWidget *button5; GtkWidget *table; window2 = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_title (GTK_WINDOW (window2), "柜员登陆"); gtk_window_set_default_size(GTK_WINDOW(window2), 400, 400); gtk_container_set_border_width (GTK_CONTAINER (window2), 30); table = gtk_table_new (12, 9, TRUE); gtk_container_add (GTK_CONTAINER (window2), table); label8 = gtk_label_new ("用户名:"); name = gtk_entry_new (); label10 = gtk_label_new ("密码:"); password = gtk_entry_new (); button4 = gtk_button_new_with_label ("登陆"); button5 = gtk_button_new_with_label ("取消"); g_signal_connect (G_OBJECT (button4), "clicked",G_CALLBACK (login), (gpointer) window2); g_signal_connect (G_OBJECT (button5), "clicked",G_CALLBACK (end_Login), (gpointer) window2); gtk_table_attach_defaults (GTK_TABLE (table), label8, 1, 4, 3, 4); gtk_table_attach_defaults (GTK_TABLE (table), name, 4, 8, 3, 4); gtk_table_attach_defaults (GTK_TABLE (table), label10, 1, 4, 5, 6); gtk_table_attach_defaults (GTK_TABLE (table), password, 4, 8, 5, 6); gtk_table_attach_defaults (GTK_TABLE (table), button5, 2, 3, 7, 8); gtk_table_attach_defaults (GTK_TABLE (table), button4, 6, 7, 7, 8); gtk_widget_show_all(window2); gtk_main (); return 0; }
staff_test.c
#include <gtk/gtk.h> #include "Staff_Login.h" #include "Staff_Work1.h" #include "Staff_Work2.h" int main( int argc,char *argv[] ) { //初始化GTK+工具库 gtk_init(&argc,&argv); Staff_Login(); return 0; }
Staff_Work1.c
#include <gtk/gtk.h> void call( GtkWidget *widget,gpointer data ) { gtk_widget_hide(data); Staff_Work2( ); } void stop_Work( GtkWidget *widget,gpointer data ) { gtk_widget_hide(data); Staff_Login(); } int Staff_Work1( ) { GtkWidget *window2; GtkWidget *label8; GtkWidget *label9; GtkWidget *label10; GtkWidget *label11; GtkWidget *button4; GtkWidget *button5; GtkWidget *table; window2 = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_title (GTK_WINDOW (window2), "柜员服务页面"); gtk_window_set_default_size(GTK_WINDOW(window2), 400, 400); gtk_container_set_border_width (GTK_CONTAINER (window2), 30); table = gtk_table_new (12, 9, TRUE); gtk_container_add (GTK_CONTAINER (window2), table); label8 = gtk_label_new ("公告栏:"); button4 = gtk_button_new_with_label ("暂停服务(退出)"); button5 = gtk_button_new_with_label ("呼叫客户"); g_signal_connect (G_OBJECT (button5), "clicked",G_CALLBACK (call), (gpointer) window2); g_signal_connect (G_OBJECT (button4), "clicked",G_CALLBACK (stop_Work), (gpointer) window2); gtk_table_attach_defaults (GTK_TABLE (table), label8, 0, 3, 1, 10); gtk_table_attach_defaults (GTK_TABLE (table), button5, 4, 9, 1, 5); gtk_table_attach_defaults (GTK_TABLE (table), button4, 4, 9, 6, 10); gtk_widget_show_all(window2); gtk_main (); return 0; }
Staff_Work2.c
#include <gtk/gtk.h> #include "client.h" #include <string.h> int times = 1; void calls( GtkWidget *widget,gpointer data ) { times++; g_print("%d\n",times); if(times == 3){ times = 1; gtk_widget_hide(data); Staff_Work1(); } } void working( GtkWidget *widget,gpointer data ) { gtk_widget_hide(data); Staff_Work1(); } int Staff_Work2( ) { GtkWidget *window2; GtkWidget *label8; GtkWidget *label10; GtkWidget *label11; GtkWidget *button4; GtkWidget *button5; GtkWidget *table; window2 = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_title (GTK_WINDOW (window2), "柜员服务页面"); gtk_window_set_default_size(GTK_WINDOW(window2), 400, 400); gtk_container_set_border_width (GTK_CONTAINER (window2), 30); table = gtk_table_new (9, 9, TRUE); gtk_container_add (GTK_CONTAINER (window2), table); label8 = gtk_label_new ("最多提供三次呼叫"); label10 = gtk_label_new ("是否应答"); label11 = gtk_label_new ("内容"); button4 = gtk_button_new_with_label ("继续呼叫"); button5 = gtk_button_new_with_label ("受理业务中"); g_signal_connect (G_OBJECT (button4), "clicked",G_CALLBACK (calls), (gpointer) window2); g_signal_connect (G_OBJECT (button5), "clicked",G_CALLBACK (working), (gpointer) window2); //创建标签后,要改变标签你的文本,用以下函数: //void gtk_label_set_text( GtkLabel *label,const char *str ); gtk_table_attach_defaults (GTK_TABLE (table), label8, 0, 4, 6, 7); gtk_table_attach_defaults (GTK_TABLE (table), label10, 5, 9, 6, 7); gtk_table_attach_defaults (GTK_TABLE (table), button5, 5, 9, 1, 5); gtk_table_attach_defaults (GTK_TABLE (table), button4, 0, 4, 1, 5); gtk_widget_show_all(window2); gtk_main (); return 0; }
test.c
#include <stdio.h> #include <string.h> #include "client.h" int main() { char buf[BUFSIZ]; char* s="staffLogin#lmx#123"; strcpy(buf,s); strcpy(buf,sendMsg(buf)); if(buf[0]==‘1‘) printf("sucessful!\n"); else if(buf[0]==‘2‘) printf("wrong username !\n"); else if(buf[0]==‘3‘) printf("wrong code !\n"); else printf("other wrong !\n"); return 0; }
vipLogin.c
#include <gtk/gtk.h> #include <string.h> #include "stdlib.h" #include "request.h" #include "callinfo.h" #include "client.h" GtkWidget *name; GtkWidget *password; void do_button( GtkWidget *widget,gpointer data ) { char Buf1[BUFSIZ]; char Buf2[BUFSIZ]; strcpy(Buf1,(char*)gtk_entry_get_text(GTK_ENTRY(name))); strcpy(Buf2,(char*)gtk_entry_get_text(GTK_ENTRY(password))); char Buf[BUFSIZ]; strcat(Buf,"vipLogin#"); strcat(Buf,Buf1); strcat(Buf,"#"); strcat(Buf,Buf2); char res[BUFSIZ]; strcpy(res,sendMsg(Buf)); if(res[0]==‘1‘){ callinfo(); }else if(res[0]==‘2‘){ GtkWidget *dialog; //提示框 gchar* msg="\n\n用户名错误! "; GtkMessageType type = type = GTK_MESSAGE_ERROR; //信息消息 dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, type, GTK_BUTTONS_OK,msg ); gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy(dialog); //销毁dialog }else if(res[0]==‘3‘){ GtkWidget *dialog; //提示框 gchar* msg="\n\n密码错误! "; GtkMessageType type = type = GTK_MESSAGE_ERROR; //信息消息 dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, type, GTK_BUTTONS_OK,msg ); gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy(dialog); //销毁dialog }else{ GtkWidget *dialog; //提示框 gchar* msg="\n\n用户不存在! "; GtkMessageType type = type = GTK_MESSAGE_ERROR; //信息消息 dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, type, GTK_BUTTONS_OK,msg ); gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy(dialog); //销毁dialog } } int vipLogin( ) { GtkWidget *window; GtkWidget *label1; GtkWidget *label2; GtkWidget *button1; GtkWidget *button2; GtkWidget *fixed = gtk_fixed_new(); //GtkWidget *image = gtk_image_new_from_file("managerLogin.png"); window=gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_title (GTK_WINDOW (window),"VIP登录"); gtk_window_set_position(GTK_WINDOW(window),GTK_WIN_POS_CENTER_ALWAYS ); //窗体居中 gtk_window_set_default_size(GTK_WINDOW(window),370,250); g_signal_connect (G_OBJECT (window), "destroy", G_CALLBACK (gtk_main_quit), NULL); g_signal_connect_swapped (G_OBJECT (window), "delete_event", G_CALLBACK (gtk_widget_destroy), window); label1=gtk_label_new("VIP"); gtk_widget_set_size_request(label1,66,33); name= gtk_entry_new(); gtk_widget_set_size_request(name,165,33); label2=gtk_label_new("密 码"); gtk_widget_set_size_request(label2,66,33); password= gtk_entry_new(); gtk_widget_set_size_request(password,165,33); gtk_entry_set_visibility(GTK_ENTRY(password),FALSE); //密码不可见 button1= gtk_button_new_with_label("登陆"); //登录 gtk_widget_set_size_request(button1,66,33); button2= gtk_button_new_with_label("取消"); //取消 gtk_widget_set_size_request(button2,66,33); g_signal_connect (G_OBJECT(button1),"clicked",G_CALLBACK(do_button),(gpointer)window); g_signal_connect_swapped (G_OBJECT (button2), "clicked", G_CALLBACK (gtk_widget_destroy), window); //gtk_fixed_put(GTK_FIXED(fixed),image, 0, 0); //添加窗体背景图片 gtk_fixed_put(GTK_FIXED(fixed),label1, 54,41); gtk_fixed_put(GTK_FIXED(fixed),name,142,41); gtk_fixed_put(GTK_FIXED(fixed),label2,54,90); gtk_fixed_put(GTK_FIXED(fixed),password,142,90); gtk_fixed_put(GTK_FIXED(fixed),button1,85, 154); gtk_fixed_put(GTK_FIXED(fixed),button2,202, 154); gtk_container_add(GTK_CONTAINER(window),fixed); gtk_widget_show_all(window); gtk_main (); return 0; }
min ling
gcc staff_test.c Staff_Login.c Staff_Work1.c Staff_Work2.c callinfo.c client.c -o Staff `pkg-config --cflags --libs gtk+-2.0` gcc manager_test.c Manager_Login.c Manager_Work.c -o manager `pkg-config --cflags --libs gtk+-2.0` gcc call.c callinfo.c client.c client_test.c request.c answer.c vipLogin.c -o user `pkg-config --cflags --libs gtk+-2.0` gcc service.c -o service
suo you .h wen jian
#ifndef MANAGERLOGIN_H #define MANAGERLOGIN_H void answer_user( GtkWidget *widget,gpointer data ); void answer_VIP( GtkWidget *widget,gpointer data ); int answer( ); #endif #ifndef CALL_H #define CALL_H void do_button3(GtkWidget *widget,gpointer data ); void do_button4(GtkWidget *widget,gpointer data ); void call(); #endif #ifndef CALLINFO_H #define CALLINFO_H void callinfo(); #endif #ifndef CLIENT_H #define CLIENT_H char* sendMsg(char buf[BUFSIZ]); #endif #ifndef MANAGER_LOGIC_H #define MANAGER_LOGIC_H void login2( GtkWidget *widget,gpointer data ); void end_Login2( GtkWidget *widget,gpointer data ); gint delete_event( GtkWidget *widget,GdkEvent *event,gpointer data ); void destroy( GtkWidget *widget,gpointer data ); int Manager_Login( ); #endif #ifndef MANAGER_WORK_H #define MANAGER_WORK_H void f1( GtkWidget *widget,gpointer data ); void f2( GtkWidget *widget,gpointer data ); void f3( GtkWidget *widget,gpointer data ); void f4( GtkWidget *widget,gpointer data ); void f( GtkWidget *widget,gpointer data ); int Manager_Work( ); #endif #ifndef REQUEST_H #define REQUEST_H void answers( GtkWidget *widget,gpointer data ); int request( ); #endif #ifndef SHOW_H #define SHOW_H void do_button(GtkWidget *widget,gpointer data ); void show(gchar* text); #endif #ifndef STAFF_LOGIN_H #define STAFF_LOGIN_H void login( GtkWidget *widget,gpointer data ); void end_Login( GtkWidget *widget,gpointer data ); gint delete_event( GtkWidget *widget,GdkEvent *event,gpointer data ); void destroy( GtkWidget *widget,gpointer data ); int Staff_Login( ); #endif #ifndef STAFF_WORK1_H #define STAFF_WORK1_H void call( GtkWidget *widget,gpointer data ); void stop_Work( GtkWidget *widget,gpointer data ); int Staff_Work1( ); #endif #ifndef STAFF_WORK2_H #define STAFF_WORK2_H void calls( GtkWidget *widget,gpointer data ); void working( GtkWidget *widget,gpointer data ); int Staff_Work2( ); #endif #ifndef MANAGERLOGIN_H #define MANAGERLOGIN_H void callback( GtkWidget *widget,gpointer data ); gint delete_event( GtkWidget *widget,GdkEvent *event,gpointer data ); void destroy( GtkWidget *widget,gpointer data ); int vipLogin( ); #endif
标签:
原文地址:http://www.cnblogs.com/chaosi/p/4237867.html