linux下用C语言编写带图形界面的成绩管理系统附带源代码:(下面内容请配合源代码看)
源代码下载地址: 点击打开链接
或留下联系方式,发给你
一、题目内容
嵌入式Linux数据库编程,用C实现成绩管理系统,通过图形化界面查询。
二、设计框架
(一)登陆界面
输入账号,密码后,如果账号密码匹配则进入系统,否则弹出错误提示框,提醒登陆用户账户或密码错误,请重新输入。
(二)功能界面
用户可选择相应的功能进行操作。功能界面分为学生基本信息查询,学生信息添加,学生信息修改和按条件查询。
(三)学生基本信息查询
在学学号处输入学号,即可查看学生个人信息。括学生姓名,性别,各科成绩等。
(四)学生个人信息添加
在学生个人信息添加模块中,我们先在每个选项中输入相应的值,最后按确认即可完成添加。
(五)学生个人信息修改
我们通过此模块,我们可以对已存在的学生信息进行更改,只需在相应的选项中按要求输入,即可完成更改。
(六)按条件查询信息
我们按要求输入我们需要查询对象满足的条件,最后按开始,即可查看满足要求的信息。
三、设计详细过程
(一)登陆界面
1.实现功能
输入账号,密码后,如果账号密码匹配则进入系统,否则弹出错误提示框,提醒登陆用户账户或密码错误,请重新输入。
2.设计思路
main()函数主要是画出用户文本框的和密码输入文本框,和一个“登陆”按钮,当用户按下确认是,就会触发按钮时间,调用callback_buttton()函数对按钮事件进行响应。初始设置用户名为:cyp,密码为:123。
3.成果展示
(一)功能界面
1.实现功能
用户可选择相应的功能进行操作。功能界面分为学生基本信息查询,学生信息添加,学生信息修改和按条件查询。
2.设计思路
calllback_button()函数主要是对输入界面的响应。获取用户输入的账号和密码,并进行判断,如果匹配则进入功能界面,否则弹出提示框,提示用户密码或账号错误。功能界面主要是四个按钮,按钮被绑定相应的函数。
3.成果展示
(三)学生基本信息查询
1.实现功能
输在学学号处输入学号,即可查看学生个人信息。括学生姓名,性别,各科成绩等。
2.设计思路
callback_button1()是对查看个人信息按钮事件的响应,画出成绩按输入学号查询的界面,包括个人所有信息。在这个界面中的“确定”按钮绑定函数lookfor(),并作出相应的处理。
lookfor()函数主要是打开学生成绩管理数据库,并按照用户输入的学号,并根据学号信息生成相应的sql语句,通过数据库查询成绩,如果没有查找到相关信息,则输出提示框提示用户查询失败,否则就将查询到的信息显示到界面中。
3.成果展示
(四)学生个人信息添加
1.实现功能
输在学生个人信息添加模块中,我们先在每个选项中输入相应的值,最后按确认即可完成添加。
2.设计思路
callback_button2()是对查看个人信息添加按钮的事件响应,画出成绩插入的界面,包括个人所有信息。在这个界面中的“确定”按钮绑定函数lookfor1(),并作出相应的处理。
lookfor1()函数主要获取用户的输入的个人信息,如果某些选项没有输入,则表示此项为默认值,根据用户的输入信息处理成的数据库插入语句,用sqlite3_exec()执行sql语句,根据插入情况,弹出插入失败或成功的提示框。
3.成果展示
(五)学生个人信息更改
1.实现功能
我们通过此模块,我们可以对已存在的学生信息进行更改,只需在相应的选项中按要求输入,即可完成更改。
2.设计思路
calllback_button3()函数主要是对输入界面的个人信息修改按钮响应。画出用户的个人信息输入界面,具体的修改过程由本界面中“确认”按钮绑定函数lookfor2()完成。
lookfor2()函数的先根据输入的学号,查找相应的信息。在将从界面用户输入将要修改的信息,如果某项输入为空,则有查找出原来的信息项代替,根据这些信息形成sql插入语句,先把此学号的个人信息删除,再将我们得到的sql语句用sqlite3_exec()完成插入,即可完成用户的信息修改。
3.成果展示
(六)按条件查询个人信息
1.实现功能
我们按要求输入我们需要查询对象满足的条件,最后按开始,即可查看满足要求的信息。
2.设计思路
calllback_button4()函数主要是对功能界面的按条件查询个人信息按钮响应。主要是画出界面,包括用户条件选择组成部分,选择显示选项部分,和显示部分组成。按下“开始匹配”按钮后,就开始打开数据库,按条件查询,并作出将查询的结果显示到界面上,显示界面是滚动类型界面。
lookfor4()函数主要是从界面获取用户需要显示的条件信息,并根据条件形成sql语句,从数据库中查询信息,并将获得信息显示到界面中。
3.成果展示
附录:
1.参考文献
[1]杜华 《Linux编程技术详解》人民邮电出版社 2007.11
[2]赵廷涛《Linux下的MySQL数据库编程》清华大学出版社 2010.6.
[3] http://blog.csdn.net/tianyou121/article/details/6104317
[4]http://www.sqlite.org/download.html
[5]http://linger-yan.iteye.com/blog/1571895
2.部分源代码:
/*************************************************************************
> File Name: student_gtk.c
> Author: maple
> Mail: [email protected]
> Created Time: 2015骞?4鏈?2鏃?鏄熸湡鏃?14鏃?4鍒?2绉?************************************************************************/
#include
#include
#include
#include
#include
void callback_button(GtkWidget*btn,GtkWidget *entry[3]);
char * str_str(char *A,char *B);
char *str_filled(char *str);
void callback_button1(GtkWidget *btn);
void callback_button2(GtkWidget *btn);
void callback_button3(GtkWidget *btn);
void callback_button4(GtkWidget *btn);
static gboolean release_resourse(GtkWidget*widget,GdkEvent *event,gpointer data);
void lookfor(GtkWidget *btn,GtkWidget*shuzu[7]);
void lookfor1(GtkWidget *btn,GtkWidget*shuzu[7]);
void lookfor2(GtkWidget *btn,GtkWidget*shuzu[7]);
void lookfor3(GtkWidget *btn,int n);
void lookfor4(GtkWidget *btn,GtkWidget*shuzu[7]);
char*table[7]={"","","","","","",""};
int xuanzhong[6]={0,0,0,0,0,0};
GtkWidget *shuzu[7];
char *temp="";
GtkTextBuffer *buffer;
int main(int argc,char* argv[])
{
GtkWidget *wnd;
GtkWidget *label;
GtkWidget *label1;
GtkWidget *btn1;
GtkWidget *fixed;
GtkWidget *entry1;
GtkWidget *entry2;
GtkWidget *entry[3];
gtk_init(&argc,&argv);
wnd= gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title((GtkWindow*)wnd,"鎴愮哗绠$悊绯荤粺鐧诲綍");
gtk_widget_set_usize(wnd,500,200);
gtk_container_set_border_width(GTK_CONTAINER(wnd),15);
fixed = gtk_fixed_new();
gtk_container_add(GTK_CONTAINER(wnd),fixed);
label = gtk_label_new("鐢ㄦ埛");
label1 = gtk_label_new("瀵嗙爜");
btn1 = gtk_button_new_with_label("鐧诲綍");
entry1 = gtk_entry_new_with_max_length(20);
entry2 = gtk_entry_new_with_max_length(20);
gtk_fixed_put(GTK_FIXED(fixed),label,80,40);
gtk_fixed_put(GTK_FIXED(fixed),label1,80,80);
gtk_fixed_put(GTK_FIXED(fixed),btn1,265,120);
gtk_fixed_put(GTK_FIXED(fixed),entry1,150,40);
gtk_fixed_put(GTK_FIXED(fixed),entry2,150,80);
gtk_entry_set_visibility(entry2,FALSE);
entry[0] = entry1;
entry[1] = entry2;
entry[2] = wnd;
g_signal_connect(G_OBJECT(btn1),"pressed",G_CALLBACK(callback_button),&entry);
g_signal_connect(G_OBJECT(wnd),"delete_event",G_CALLBACK(release_resourse),NULL);
gtk_widget_show_all(wnd);
gtk_main();
return 0;
}
//鐧诲綍鎴愬姛鍑芥暟//////////////////////////////////////////////////
void callback_button(GtkWidget*btn,GtkWidget *entry[3])
{
char *login = NULL;
char *password = NULL;
gboolean btn_state;
login = gtk_entry_get_text((GtkEntry *)entry[0]);
password = gtk_entry_get_text((GtkEntry *)entry[1]);
if(strcmp(login,"cyp")==0&&strcmp(password,"123")==0)
{
GtkWidget *wnd;
GtkWidget *label;
GtkWidget *btn1;
GtkWidget *btn2;
GtkWidget *btn3;
GtkWidget *btn4;
GtkWidget *fixed;
wnd = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title((GtkWindow*)wnd," 鐧诲綍鎴愬姛");
gtk_widget_set_usize(wnd,500,400);
gtk_container_set_border_width(GTK_CONTAINER(wnd),15);
fixed = gtk_fixed_new();
gtk_container_add(GTK_CONTAINER(wnd),fixed);
btn1 = gtk_button_new_with_label("鏌ョ湅涓汉淇℃伅");
btn2 = gtk_button_new_with_label("娣诲姞涓汉淇℃伅");
btn3 = gtk_button_new_with_label("淇敼涓汉淇℃伅");
btn4 = gtk_button_new_with_label("鏉′欢鏌ヨ淇℃伅");
label = gtk_label_new("娆㈣繋浣跨敤瀛︾敓鎴愮哗鏌ヨ绯荤粺");
gtk_fixed_put(GTK_FIXED(fixed),label,40,20);
gtk_fixed_put(GTK_FIXED(fixed),btn1,60,100);
gtk_fixed_put(GTK_FIXED(fixed),btn2,300,100);
gtk_fixed_put(GTK_FIXED(fixed),btn3,60,200);
gtk_fixed_put(GTK_FIXED(fixed),btn4,300,200);
release_resourse(entry[2],NULL,NULL);
g_signal_connect(G_OBJECT(wnd),"delete_event",G_CALLBACK(release_resourse),NULL);
g_signal_connect(G_OBJECT(btn1),"pressed",G_CALLBACK(callback_button1),NULL);
g_signal_connect(G_OBJECT(btn2),"pressed",G_CALLBACK(callback_button2),NULL);
g_signal_connect(G_OBJECT(btn3),"pressed",G_CALLBACK(callback_button3),NULL);
g_signal_connect(G_OBJECT(btn4),"pressed",G_CALLBACK(callback_button4),NULL);
gtk_widget_show_all(wnd);
gtk_main();
}
else
{
GtkWidget *dialog;
GtkWidget *label;
dialog = gtk_dialog_new();
gtk_window_set_title(GTK_WINDOW(dialog),"閿欒鎻愮ず");
gtk_widget_set_usize(dialog,300,100);
label = gtk_label_new("鐢ㄦ埛鍚嶆垨瀵嗙爜閿欒锛佽閲嶆柊杈撳叆");
gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox),label,TRUE,TRUE,0);
g_signal_connect(G_OBJECT(dialog),"delete_event",G_CALLBACK(release_resourse),NULL);
gtk_widget_show_all(dialog);
gtk_main();
}
}
////////////绐楀彛鍏抽棴鍑芥暟/////////////////////////////////
static gboolean release_resourse(GtkWidget*widget,GdkEvent *event,gpointer data)
{
gtk_main_quit();
returnFALSE;
}
//////////涓汉淇℃伅鏌ョ湅////////////////////////////////////////
void callback_button1(GtkWidget *btn)
{
GtkWidget *wnd;
GtkWidget *label;
GtkWidget *label1;
GtkWidget *label2;
GtkWidget *label3;
GtkWidget *label4;
GtkWidget *label5;
GtkWidget *label6;
char *label_table[6];
GtkWidget *btn1;
GtkWidget *btn2;
GtkWidget *btn3;
GtkWidget *entry;
GtkWidget *fixed;
GtkWidget *shuzu[8];
wnd= gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title((GtkWindow*)wnd,"涓汉淇℃伅鏌ョ湅");
gtk_widget_set_usize(wnd,400,600);
gtk_container_set_border_width(GTK_CONTAINER(wnd),15);
fixed = gtk_fixed_new();
gtk_container_add(GTK_CONTAINER(wnd),fixed);
entry = gtk_entry_new_with_max_length(20);
btn1 = gtk_button_new_with_label("纭畾");
// btn2 = gtk_button_new_with_label("涓婁竴涓?);
//btn3 = gtk_button_new_with_label("涓嬩竴涓?);
label = gtk_label_new("瀛﹀彿");
label1 = gtk_label_new("瀛﹀彿");
label2 = gtk_label_new("濮撳悕");
label3 = gtk_label_new("鎬у埆");
label4 = gtk_label_new("璇枃");
label5 = gtk_label_new("鏁板");
label6 = gtk_label_new("澶栬");
gtk_fixed_put(GTK_FIXED(fixed),label,40,40);
gtk_fixed_put(GTK_FIXED(fixed),btn1,300,40);
//gtk_fixed_put(GTK_FIXED(fixed),btn2,40,340);
gtk_fixed_put(GTK_FIXED(fixed),entry,100,40);
//gtk_fixed_put(GTK_FIXED(fixed),btn3,300,340);
gtk_fixed_put(GTK_FIXED(fixed),label1,60,100);
gtk_fixed_put(GTK_FIXED(fixed),label2,60,140);
gtk_fixed_put(GTK_FIXED(fixed),label3,60,180);
gtk_fixed_put(GTK_FIXED(fixed),label4,60,220);
gtk_fixed_put(GTK_FIXED(fixed),label5,60,260);
gtk_fixed_put(GTK_FIXED(fixed),label6,60,300);
shuzu[0]=entry;
shuzu[1]=label1;
shuzu[2]=label2;
shuzu[3]=label3;
shuzu[4]=label4;
shuzu[5]=label5;
shuzu[6]=label6;
shuzu[7]=wnd;
g_signal_connect(G_OBJECT(btn1),"pressed",G_CALLBACK(lookfor),&shuzu);
g_signal_connect(G_OBJECT(wnd),"delete_event",G_CALLBACK(release_resourse),NULL);
gtk_widget_show_all(wnd);
gtk_main();
}
//////////鏁版嵁搴撲釜浜轰俊鎭煡璇㈠嚱鏁?////////////////////////
void lookfor(GtkWidget *btn,GtkWidget *shuzu[8])
{
int k;
char*temp=NULL;
sqlite3*pdb = NULL;
sqlite3_open("student_base",&pdb);
char*sql = "select * from student where id ='2012211564'";
char*ErrMsg = 0;
intresult,i,j;
char**dbResult=NULL;
intnRow=0,nCloumn;
GtkEntry*entry = (GtkEntry*)shuzu[0] ;
const gchar *id = gtk_entry_get_text(entry);
sql=str_str("select * from student where id ='",id);
sql=str_str(sql,"'");
printf("%s\n",sql);
result= sqlite3_get_table(pdb,sql,&dbResult,&nRow,&nCloumn,&ErrMsg);
if(nRow==0)
{
GtkWidget *dialog;
GtkWidget *label;
dialog = gtk_dialog_new();
gtk_window_set_title(GTK_WINDOW(dialog),"閿欒鎻愮ず");
gtk_widget_set_usize(dialog,200,200);
label = gtk_label_new("鏌ヨ澶辫触锛?);
gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox),label,TRUE,TRUE,0);
g_signal_connect(G_OBJECT(dialog),"delete_event",G_CALLBACK(release_resourse),NULL);
gtk_widget_show_all(dialog);
gtk_main();
}
else
{
for(i = 0;i < nRow;i++)
for(j = 0;j < nCloumn;j++)
{
if(j==0)
table[j]=str_str("瀛﹀彿锛?",dbResult[(i+1)*nCloumn+j]);
if(j==1)
table[j]=str_str("濮撳悕锛?",dbResult[(i+1)*nCloumn+j]);
if(j==2)
table[j]=str_str("鎬у埆锛?",dbResult[(i+1)*nCloumn+j]);
if(j==3)
table[j]=str_str("璇枃锛?",dbResult[(i+1)*nCloumn+j]);
if(j==4)
table[j]=str_str("鏁板锛?",dbResult[(i+1)*nCloumn+j]);
if(j==5)
table[j]=str_str("澶栬锛?",dbResult[(i+1)*nCloumn+j]);
}
}
for (k=1;k<7;k++)
gtk_label_set_text(GTK_LABEL(shuzu[k]),table[k-1]);
gtk_widget_show_all(shuzu[7]);
sqlite3_free_table(dbResult);
sqlite3_close(pdb);
}
//////////瀛楃娴嬭繛鎺?//////////////////////////////////////////////////////
char *str_str(char *A,char *B)
{
int i = 0,j=0;
int a=strlen(A);
int b=strlen(B);
char *ptr = NULL;
ptr = malloc((a+b+1)*sizeof(char));
while(A[i]!='\0')
{
ptr[i] = A[i];
i++;
}
while(B[j]!='\0')
{
ptr[i]=B[j];
i++;j++;
}
ptr[i]='\0';
returnptr;
}
////////////////////涓汉淇℃伅鎻掑叆//////////////////////////////////////////
void lookfor1(GtkWidget *btn,GtkWidget *shuzu[7])
{
int k;
char *temp=NULL;
sqlite3*pdb = NULL;
sqlite3_open("student_base",&pdb);
char*sql = "insert into student values('";
char*ErrMsg = 0;
intresult,i,j;
intsign = 1;
char*szErrMsg;
char**dbResult=NULL;
GtkEntry*entry = (GtkEntry*)shuzu[1] ;
const gchar *id = gtk_entry_get_text(entry);
if(strlen(id)==0)
sign = 0;
else
{
sql=str_str(sql,id);
sql=str_str(sql,"','");
}
entry= (GtkEntry*)shuzu[2] ;
id = gtk_entry_get_text(entry);
if(strlen(id)==0)
sign = 0;
else
{
sql=str_str(sql,id);
sql=str_str(sql,"','");
}
if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(shuzu[3])))
{
sql=str_str(sql,"鐢?);
sql=str_str(sql,"',");
}
else
{
sql=str_str(sql,"濂?);
sql=str_str(sql,"',");
}
entry= (GtkEntry*)shuzu[4] ;
id = gtk_entry_get_text(entry);
if(strlen(id)==0)
id= "0";
sql=str_str(sql,id);
sql=str_str(sql,",");
entry= (GtkEntry*)shuzu[5] ;
id= gtk_entry_get_text(entry);
if(strlen(id)==0)
id= "0";
sql=str_str(sql,id);
sql=str_str(sql,",");
entry= (GtkEntry*)shuzu[6] ;
id = gtk_entry_get_text(entry);
if(strlen(id)==0)
id= "0";
sql=str_str(sql,id);
sql=str_str(sql,")");
//printf("%s\n",sql);
if(sign==0)
{
GtkWidget *dialog;
GtkWidget *label;
dialog = gtk_dialog_new();
gtk_window_set_title(GTK_WINDOW(dialog),"閿欒鎻愮ず");
gtk_widget_set_usize(dialog,200,200);
label = gtk_label_new("鍩烘湰淇℃伅涓嶅叏锛屾棤娉曟彃鍏ワ紒");
gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox),label,TRUE,TRUE,0);
g_signal_connect(G_OBJECT(dialog),"delete_event",G_CALLBACK(release_resourse),NULL);
gtk_widget_show_all(dialog);
gtk_main();
}
else
{
sqlite3_exec(pdb,sql,0,0,&szErrMsg);
GtkWidget *dialog;
GtkWidget *label;
dialog = gtk_dialog_new();
gtk_window_set_title(GTK_WINDOW(dialog),"鎿嶄綔鎻愮ず");
gtk_widget_set_usize(dialog,200,200);
label = gtk_label_new("鎻掑叆鎴愬姛锛?);
gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox),label,TRUE,TRUE,0);
g_signal_connect(G_OBJECT(dialog),"delete_event",G_CALLBACK(release_resourse),NULL);
gtk_widget_show_all(dialog);
gtk_main();
}
sqlite3_free_table(dbResult);
sqlite3_close(pdb);
}
/////////////// 鎻掑叆涓汉淇℃伅锛?/////////////////////////////////////////////////////////////
void callback_button2(GtkWidget *btn)
{
GtkWidget *wnd;
GtkWidget *label1;
GtkWidget *label2;
GtkWidget *label3;
GtkWidget *label4;
GtkWidget *label5;
GtkWidget *label6;
GtkWidget *btn1;
GtkWidget *btn2;
GtkWidget *btn3;
GtkWidget *box;
GtkWidget *entry1;
GtkWidget *entry2;
GtkWidget *entry3;
GtkWidget *entry4;
GtkWidget *entry5;
GtkWidget *entry6;
GtkWidget *fixed;
GtkWidget *shuzu[7];
GSList *group;
wnd= gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title((GtkWindow*)wnd,"娣诲姞涓汉淇℃伅");
gtk_widget_set_usize(wnd,400,600);
gtk_container_set_border_width(GTK_CONTAINER(wnd),15);
fixed = gtk_fixed_new();
gtk_container_add(GTK_CONTAINER(wnd),fixed);
box = gtk_hbox_new(TRUE,5);
// entry = gtk_entry_new_with_max_length(20);
entry1 = gtk_entry_new_with_max_length(20);
entry2 = gtk_entry_new_with_max_length(20);
entry3 = gtk_entry_new_with_max_length(20);
entry4 = gtk_entry_new_with_max_length(20);
entry5 = gtk_entry_new_with_max_length(20);
entry6 = gtk_entry_new_with_max_length(20);
btn1 = gtk_button_new_with_label("纭畾");
// label = gtk_label_new("瀛﹀彿");
label1 = gtk_label_new("瀛﹀彿");
label2 = gtk_label_new("濮撳悕");
label3 = gtk_label_new("鎬у埆");
label4 = gtk_label_new("璇枃");
label5 = gtk_label_new("鏁板");
label6 = gtk_label_new("澶栬");
//gtk_fixed_put(GTK_FIXED(fixed),label,40,40);
//gtk_fixed_put(GTK_FIXED(fixed),btn1,300,40);
//gtk_fixed_put(GTK_FIXED(fixed),btn2,40,340);
//gtk_fixed_put(GTK_FIXED(fixed),entry,100,40);
gtk_fixed_put(GTK_FIXED(fixed),btn1,240,340);
gtk_fixed_put(GTK_FIXED(fixed),label1,60,100);
gtk_fixed_put(GTK_FIXED(fixed),label2,60,140);
gtk_fixed_put(GTK_FIXED(fixed),label3,60,180);
gtk_fixed_put(GTK_FIXED(fixed),label4,60,220);
gtk_fixed_put(GTK_FIXED(fixed),label5,60,260);
gtk_fixed_put(GTK_FIXED(fixed),label6,60,300);
gtk_fixed_put(GTK_FIXED(fixed),entry1,120,100);
gtk_fixed_put(GTK_FIXED(fixed),entry2,120,140);
gtk_fixed_put(GTK_FIXED(fixed),box,120,180);
gtk_fixed_put(GTK_FIXED(fixed),entry4,120,220);
gtk_fixed_put(GTK_FIXED(fixed),entry5,120,260);
gtk_fixed_put(GTK_FIXED(fixed),entry6,120,300);
btn2 =gtk_radio_button_new_with_label(NULL,"鐢?);
gtk_box_pack_start(GTK_BOX(box),btn2,TRUE,TRUE,0);
group = gtk_radio_button_get_group(GTK_RADIO_BUTTON(btn2));
btn3 = gtk_radio_button_new_with_label(group,"濂?);
gtk_box_pack_start(GTK_BOX(box),btn3,TRUE,TRUE,0);
shuzu[0]=wnd;
shuzu[1]=entry1;
shuzu[2]=entry2;
shuzu[3]=btn2;
shuzu[4]=entry4;
shuzu[5]=entry5;
shuzu[6]=entry6;
g_signal_connect(G_OBJECT(btn1),"pressed",G_CALLBACK(lookfor1),&shuzu);
g_signal_connect(G_OBJECT(wnd),"delete_event",G_CALLBACK(release_resourse),NULL);
gtk_widget_show_all(wnd);
gtk_main();
}
///////////////////淇敼涓汉淇℃伅/////////////////////////////////
void callback_button3(GtkWidget *btn)
{
GtkWidget *wnd;
GtkWidget *label1;
GtkWidget *label2;
GtkWidget *label3;
GtkWidget *label4;
GtkWidget *label5;
GtkWidget *label6;
GtkWidget *btn1;
GtkWidget *btn2;
GtkWidget *btn3;
GtkWidget *btn4;
GtkWidget *box;
GtkWidget *entry1;
GtkWidget *entry2;
GtkWidget *entry3;
GtkWidget *entry4;
GtkWidget *entry5;
GtkWidget *entry6;
GtkWidget *fixed;
GtkWidget *shuzu[7];
GSList *group;
wnd= gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title((GtkWindow*)wnd,"鎸夊鍙蜂慨鏀逛釜浜轰俊鎭?);
gtk_widget_set_usize(wnd,400,600);
gtk_container_set_border_width(GTK_CONTAINER(wnd),15);
fixed = gtk_fixed_new();
gtk_container_add(GTK_CONTAINER(wnd),fixed);
box = gtk_hbox_new(TRUE,5);
// entry = gtk_entry_new_with_max_length(20);
entry1 = gtk_entry_new_with_max_length(20);
entry2 = gtk_entry_new_with_max_length(20);
entry3 = gtk_entry_new_with_max_length(20);
entry4 = gtk_entry_new_with_max_length(20);
entry5 = gtk_entry_new_with_max_length(20);
entry6 = gtk_entry_new_with_max_length(20);
btn1 = gtk_button_new_with_label("纭畾");
// label = gtk_label_new("瀛﹀彿");
label1 = gtk_label_new("瀛﹀彿");
label2 = gtk_label_new("濮撳悕");
label3 = gtk_label_new("鎬у埆");
label4 = gtk_label_new("璇枃");
label5 = gtk_label_new("鏁板");
label6 = gtk_label_new("澶栬");
//gtk_fixed_put(GTK_FIXED(fixed),label,40,40);
//gtk_fixed_put(GTK_FIXED(fixed),btn1,300,40);
//gtk_fixed_put(GTK_FIXED(fixed),btn2,40,340);
//gtk_fixed_put(GTK_FIXED(fixed),entry,100,40);
gtk_fixed_put(GTK_FIXED(fixed),btn1,240,340);
gtk_fixed_put(GTK_FIXED(fixed),label1,60,100);
gtk_fixed_put(GTK_FIXED(fixed),label2,60,140);
gtk_fixed_put(GTK_FIXED(fixed),label3,60,180);
gtk_fixed_put(GTK_FIXED(fixed),label4,60,220);
gtk_fixed_put(GTK_FIXED(fixed),label5,60,260);
gtk_fixed_put(GTK_FIXED(fixed),label6,60,300);
gtk_fixed_put(GTK_FIXED(fixed),entry1,120,100);
gtk_fixed_put(GTK_FIXED(fixed),entry2,120,140);
gtk_fixed_put(GTK_FIXED(fixed),box,120,180);
gtk_fixed_put(GTK_FIXED(fixed),entry4,120,220);
gtk_fixed_put(GTK_FIXED(fixed),entry5,120,260);
gtk_fixed_put(GTK_FIXED(fixed),entry6,120,300);
btn2 = gtk_radio_button_new_with_label(NULL,"榛樿");
gtk_box_pack_start(GTK_BOX(box),btn2,TRUE,TRUE,0);
group = gtk_radio_button_get_group(GTK_RADIO_BUTTON(btn2));
btn3 =gtk_radio_button_new_with_label(group,"鐢?);
gtk_box_pack_start(GTK_BOX(box),btn3,TRUE,TRUE,0);
group = gtk_radio_button_get_group(GTK_RADIO_BUTTON(btn3));
btn4 =gtk_radio_button_new_with_label(group,"濂?);
gtk_box_pack_start(GTK_BOX(box),btn4,TRUE,TRUE,0);
shuzu[0]=btn3;
shuzu[1]=entry1;
shuzu[2]=entry2;
shuzu[3]=btn2;
shuzu[4]=entry4;
shuzu[5]=entry5;
shuzu[6]=entry6;
g_signal_connect(G_OBJECT(btn1),"pressed",G_CALLBACK(lookfor2),&shuzu);
g_signal_connect(G_OBJECT(wnd),"delete_event",G_CALLBACK(release_resourse),NULL);
gtk_widget_show_all(wnd);
gtk_main();
}
/////////////////////////////////////////////////
//
void lookfor2(GtkWidget *btn,GtkWidget *shuzu[7])
{
int k;
char *temp=NULL;
sqlite3*pdb = NULL;
sqlite3_open("student_base",&pdb);
char*sql = "insert into student values('";
char*ErrMsg = 0;
intresult,i,j;
intsign = 1;
char*szErrMsg;
char**dbResult=NULL;
char*sql1 = "select * from student where id ='2012211564'";
char*ErrMsg1 = 0;
intnRow=0,nCloumn;
GtkEntry*entry = (GtkEntry*)shuzu[1] ;
const gchar *id = gtk_entry_get_text(entry);
const gchar *id1 = gtk_entry_get_text(entry);
sql1=str_str("select * from student where id ='",id1);
sql1=str_str(sql1,"'");
// printf("%s\n",sql1);
sqlite3_get_table(pdb,sql1,&dbResult,&nRow,&nCloumn,&ErrMsg1);
//temp1=str_filled(dbResult[(i+1)*nCloumn+j]);
// GtkEntry*entry = (GtkEntry*)shuzu[1] ;
// const gchar *id = gtk_entry_get_text(entry);
// const gchar *id1 = gtk_entry_get_text(entry);i
//
if(nRow==1)
{
if(strlen(id)==0)
sign = 0;
else
{
sql=str_str(sql,id);
sql=str_str(sql,"','");
}
entry= (GtkEntry*)shuzu[2] ;
id = gtk_entry_get_text(entry);
if(strlen(id)==0)
// sign = 0;
{
sql=str_str(sql,dbResult[nCloumn+1]);
sql=str_str(sql,"','");
}
else
{
sql=str_str(sql,id);
sql=str_str(sql,"','");
}
if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(shuzu[3])))
{
sql=str_str(sql,dbResult[nCloumn+2]);
sql=str_str(sql,"',");
}
elseif(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(shuzu[0])))
{
sql=str_str(sql,"鐢?);
sql=str_str(sql,"',");
}
else
{
sql=str_str(sql,"濂?);
sql=str_str(sql,"',");
}
entry= (GtkEntry*)shuzu[4] ;
id = gtk_entry_get_text(entry);
if(strlen(id)==0)
id= dbResult[nCloumn+3];
sql=str_str(sql,id);
sql=str_str(sql,",");
entry= (GtkEntry*)shuzu[5] ;
id = gtk_entry_get_text(entry);
if(strlen(id)==0)
id= dbResult[nCloumn+4];
sql=str_str(sql,id);
sql=str_str(sql,",");
entry= (GtkEntry*)shuzu[6] ;
id = gtk_entry_get_text(entry);
if(strlen(id)==0)
id= dbResult[nCloumn+5];
sql=str_str(sql,id);
sql=str_str(sql,")");
// printf("%s\n",sql);
//printf("nRow = %s\nsign=%s\n",nRow,sign);
}
//char*sql1 = "select * from student where id ='2012211564'";
//char*ErrMsg1 = 0;
// intnRow=0,nCloumn;
// sql1=str_str("select * from student where id ='",id1);
// sql1=str_str(sql1,"'");
// printf("%s\n",sql1);
//sqlite3_get_table(pdb,sql1,&dbResult,&nRow,&nCloumn,&ErrMsg1);
//printf("nRow =%s\nsign=%s\n",nRow,sign);
if(nRow==0|sign==0)
{
GtkWidget *dialog;
GtkWidget *label;
dialog = gtk_dialog_new();
gtk_window_set_title(GTK_WINDOW(dialog)," 鎿嶄綔鎻愮ず");
gtk_widget_set_usize(dialog,200,200);
label = gtk_label_new("鏃犳硶淇敼锛?);
gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox),label,TRUE,TRUE,0);
g_signal_connect(G_OBJECT(dialog),"delete_event",G_CALLBACK(release_resourse),NULL);
gtk_widget_show_all(dialog);
gtk_main();
}
else
{
sql1="delete from student where id = '";
sql1=str_str(sql1,id1);
sql1=str_str(sql1,"'");
sqlite3_exec(pdb,sql1,0,0,&szErrMsg);
sqlite3_exec(pdb,sql,0,0,&szErrMsg);
GtkWidget *dialog;
GtkWidget *label;
dialog = gtk_dialog_new();
gtk_window_set_title(GTK_WINDOW(dialog),"鎿嶄綔鎻愮ず");
gtk_widget_set_usize(dialog,200,200);
label = gtk_label_new("淇敼鎴愬姛锛?);
gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox),label,TRUE,TRUE,0);
g_signal_connect(G_OBJECT(dialog),"delete_event",G_CALLBACK(release_resourse),NULL);
gtk_widget_show_all(dialog);
gtk_main();
}
sqlite3_free_table(dbResult);
sqlite3_close(pdb);
}
/////////////// 鎸夋潯浠舵煡璇紒//////////////////////////////////////////////////////////////
void callback_button4(GtkWidget *btn)
{
GtkWidget *wnd;
GtkWidget *label1;
GtkWidget *label11;
GtkWidget *label2;
GtkWidget *label3;
GtkWidget *label4;
GtkWidget *label5;
GtkWidget *label6;
GtkWidget *label44;
GtkWidget *label55;
GtkWidget *label66;
GtkWidget *btn1;
GtkWidget *btn2;
GtkWidget *btn3;
GtkWidget *btn4;
GtkWidget *btn11;
GtkWidget *btn22;
GtkWidget *btn33;
GtkWidget *btn44;
GtkWidget *btn55;
GtkWidget *btn66;
GtkWidget *box;
GtkWidget *box1;
GtkWidget *box2;
GtkWidget *entry1;
GtkWidget *entry2;
GtkWidget *entry3;
GtkWidget *entry4;
GtkWidget *entry5;
GtkWidget *entry6;
GtkWidget *fixed;
GtkWidget *entry44;
GtkWidget *entry55;
GtkWidget *entry66;
GtkWidget *scrolled;
GtkWidget *text;
//GtkTextBuffer *buffer;
GtkWidget *shuzu[9];
GSList *group;
xuanzhong[0]=0;
xuanzhong[1]=0;
xuanzhong[2]=0;
xuanzhong[3]=0;
xuanzhong[4]=0;
xuanzhong[5]=0;
char *strx="cyp";
char *strx1="lj";
wnd= gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title((GtkWindow*)wnd,"鎸夋潯浠舵煡璇釜浜轰俊鎭?);
gtk_widget_set_usize(wnd,1000,700);
gtk_container_set_border_width(GTK_CONTAINER(wnd),15);
fixed = gtk_fixed_new();
gtk_container_add(GTK_CONTAINER(wnd),fixed);
box = gtk_hbox_new(TRUE,5);
box1 = gtk_hbox_new(TRUE,15);
box2 = gtk_hbox_new(TRUE,6);
gtk_widget_set_size_request(box2,420,160);
// entry = gtk_entry_new_with_max_length(20);
entry1 = gtk_entry_new_with_max_length(20);
entry2 = gtk_entry_new_with_max_length(20);
entry3 = gtk_entry_new_with_max_length(20);
entry4 = gtk_entry_new_with_max_length(20);
entry5 = gtk_entry_new_with_max_length(20);
entry6 = gtk_entry_new_with_max_length(20);
gtk_widget_set_size_request(entry4,60,25);
gtk_widget_set_size_request(entry5,60,25);
gtk_widget_set_size_request(entry6,60,25);
entry44 = gtk_entry_new_with_max_length(20);
entry55 = gtk_entry_new_with_max_length(20);
entry66 = gtk_entry_new_with_max_length(20);
gtk_widget_set_size_request(entry44,60,25);
gtk_widget_set_size_request(entry55,60,25);
gtk_widget_set_size_request(entry66,60,25);
btn1 = gtk_button_new_with_label("寮€濮嬪尮閰?);
// label = gtk_label_new("瀛﹀彿");
label1 = gtk_label_new("鏉′欢鍖归厤");
label11 = gtk_label_new("鏄剧ず閫夐」");
label2 = gtk_label_new("濮撳悕");
label3 = gtk_label_new("鎬у埆");
label4 = gtk_label_new("璇枃");
label5 = gtk_label_new("鏁板");
label6 = gtk_label_new("澶栬");
label44 = gtk_label_new("鍒?);
label55 = gtk_label_new("鍒?);
label66 = gtk_label_new("鍒?);
scrolled =gtk_scrolled_window_new(NULL,NULL);
gtk_widget_show(scrolled);
text = gtk_text_view_new();
//strx=str_filled(strx);
//strx=str_str(strx,"\n");
// strx1=str_filled(strx1);
strx1="";
buffer =gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
gtk_text_buffer_set_text(buffer,strx1,-1);
//gtk_text_buffer_set_text(GTK_TEXT_BUFFER(buffer),"HelloWorld!",-1);
gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrolled),text);
//frame = gtk_frame_new("dut");
//gtk_frame_set_label_align(GTK_FRAME(frame),0.5,0);
//gtk_fixed_put(GTK_FIXED(fixed),frame,300,100);
//gtk_fixed_put(GTK_FIXED(fixed),btn1,300,40);
//gtk_fixed_put(GTK_FIXED(fixed),btn2,40,340);
//gtk_fixed_put(GTK_FIXED(fixed),entry,100,40);
gtk_fixed_put(GTK_FIXED(fixed),btn1,230,350);
gtk_fixed_put(GTK_FIXED(fixed),label1,60,100);
gtk_fixed_put(GTK_FIXED(fixed),label2,60,140);
gtk_fixed_put(GTK_FIXED(fixed),label3,60,180);
gtk_fixed_put(GTK_FIXED(fixed),label4,60,220);
gtk_fixed_put(GTK_FIXED(fixed),label5,60,260);
gtk_fixed_put(GTK_FIXED(fixed),label6,60,300);
gtk_fixed_put(GTK_FIXED(fixed),label44,200,220);
gtk_fixed_put(GTK_FIXED(fixed),label55,200,260);
gtk_fixed_put(GTK_FIXED(fixed),label66,200,300);
gtk_fixed_put(GTK_FIXED(fixed),label11,360,100);
//gtk_fixed_put(GTK_FIXED(fixed),entry1,120,100);
gtk_fixed_put(GTK_FIXED(fixed),entry2,120,140);
gtk_fixed_put(GTK_FIXED(fixed),box,120,180);
gtk_fixed_put(GTK_FIXED(fixed),entry4,120,220);
gtk_fixed_put(GTK_FIXED(fixed),entry5,120,260);
gtk_fixed_put(GTK_FIXED(fixed),entry6,120,300);
gtk_fixed_put(GTK_FIXED(fixed),entry44,250,220);
gtk_fixed_put(GTK_FIXED(fixed),entry55,250,260);
gtk_fixed_put(GTK_FIXED(fixed),entry66,250,300);
gtk_fixed_put(GTK_FIXED(fixed),box1,360,140);
gtk_fixed_put(GTK_FIXED(fixed),box2,360,160);
gtk_box_pack_start(GTK_BOX(box2),scrolled,TRUE,TRUE,0);
btn2 =gtk_radio_button_new_with_label(NULL,"鐢?);
gtk_box_pack_start(GTK_BOX(box),btn2,TRUE,TRUE,0);
group = gtk_radio_button_get_group(GTK_RADIO_BUTTON(btn2));
btn3 =gtk_radio_button_new_with_label(group,"濂?);
gtk_box_pack_start(GTK_BOX(box),btn3,TRUE,TRUE,0);
group = gtk_radio_button_get_group(GTK_RADIO_BUTTON(btn3));
btn4 =gtk_radio_button_new_with_label(group,"鐢峰コ");
gtk_box_pack_start(GTK_BOX(box),btn4,TRUE,TRUE,0);
btn11 =gtk_check_button_new_with_label("瀛﹀彿");
gtk_container_add(GTK_CONTAINER(box1),btn11);
btn22 = gtk_check_button_new_with_label("濮撳悕");
gtk_container_add(GTK_CONTAINER(box1),btn22);
btn33 =gtk_check_button_new_with_label("鎬у埆");
gtk_container_add(GTK_CONTAINER(box1),btn33);
btn44 =gtk_check_button_new_with_label("璇枃");
gtk_container_add(GTK_CONTAINER(box1),btn44);
btn55 =gtk_check_button_new_with_label("鏁板");
gtk_container_add(GTK_CONTAINER(box1),btn55);
btn66 =gtk_check_button_new_with_label("澶栬");
gtk_container_add(GTK_CONTAINER(box1),btn66);
shuzu[0]=entry4;
shuzu[1]=entry5;
shuzu[2]=entry6;
shuzu[3]=entry44;
shuzu[4]=entry55;
shuzu[5]=entry66;
shuzu[6]=entry2;
shuzu[7]=btn2;
shuzu[8]=btn3;
//g_signal_connect(G_OBJECT(btn1),"pressed",G_CALLBACK(lookfor2),&shuzu);
g_signal_connect(G_OBJECT(wnd),"delete_event",G_CALLBACK(release_resourse),NULL);
g_signal_connect(G_OBJECT(btn11),"pressed",G_CALLBACK(lookfor3),0);
g_signal_connect(G_OBJECT(btn22),"pressed",G_CALLBACK(lookfor3),1);
g_signal_connect(G_OBJECT(btn33),"pressed",G_CALLBACK(lookfor3),2);
g_signal_connect(G_OBJECT(btn44),"pressed",G_CALLBACK(lookfor3),3);
g_signal_connect(G_OBJECT(btn55),"pressed",G_CALLBACK(lookfor3),4);
g_signal_connect(G_OBJECT(btn66),"pressed",G_CALLBACK(lookfor3),5);
g_signal_connect(G_OBJECT(btn1),"pressed",G_CALLBACK(lookfor4),&shuzu);
gtk_widget_show_all(wnd);
gtk_main();
}
/////////////////////////////////////////////////////
char*str_filled(char *str1)
{
int n = strlen(str1);
int i=0;
char *ptr=malloc(10*sizeof(char));
while(i<10&&i { ptr[i]=str1[i]; i++; } while(i<20) { ptr[i]=' '; i++; } ptr[i]='\0'; return ptr; } /////////////////////////////////////////////////////////////////////////////////// void lookfor3(GtkWidget *btn,int n) { xuanzhong[n]=xuanzhong[n]+1; xuanzhong[n]=xuanzhong[n]%2; } ////////////////////////////////////////////////////////////////////////////////// void lookfor4(GtkWidget *btn,GtkWidget *shuzu[8]) { int k; //char *temp=" "; char *temp1=NULL; sqlite3*pdb = NULL; sqlite3_open("student_base",&pdb); char*sql =NULL; char*ErrMsg = 0; intresult,i,j; char**dbResult=NULL; intnRow=0,nCloumn,sex_sign=0,name_sign=0; intfanwei[3][2]; char*ptr[7]; GtkEntry*entry = (GtkEntry*)shuzu[0] ; const gchar *shu = gtk_entry_get_text(entry); fanwei[0][0] = atoi(shu); ptr[0]=shu; if(strlen(shu)==0) ptr[0]="0"; entry= (GtkEntry*)shuzu[1] ; shu = gtk_entry_get_text(entry); fanwei[1][0] = atoi(shu); ptr[1]=shu; if(strlen(shu)==0) ptr[1]="0"; entry= (GtkEntry*)shuzu[2] ; shu = gtk_entry_get_text(entry); fanwei[2][0] = atoi(shu); ptr[2]=shu; if(strlen(shu)==0) ptr[2]="0"; entry= (GtkEntry*)shuzu[3] ; shu = gtk_entry_get_text(entry); fanwei[0][1] = atoi(shu); ptr[3]=shu; if(strlen(shu)==0) ptr[3]="100"; entry= (GtkEntry*)shuzu[4] ; shu = gtk_entry_get_text(entry); fanwei[1][1] = atoi(shu); ptr[4]=shu; if(strlen(shu)==0) ptr[4]="100"; entry= (GtkEntry*)shuzu[5] ; shu = gtk_entry_get_text(entry); fanwei[2][1] = atoi(shu); ptr[5]=shu; if(strlen(shu)==0) ptr[5]="100"; entry= (GtkEntry*)shuzu[6] ; const gchar *name = gtk_entry_get_text(entry); if(strlen(name)==0) name_sign=0; else name_sign=1; if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(shuzu[7]))) sex_sign=0; else if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(shuzu[8]))) sex_sign=1; else sex_sign=2; intii,jj; for(ii=0;ii<3;ii++) for(jj=0;jj<2;jj++) /// printf("fanwei[%d][%d]= %d\n",ii,jj,fanwei[ii][jj]); //printf("name=%s\n",name); //printf("sex_sign= %d\n",sex_sign); //printf("shu= %S\n",ptr[0]); sql="select * from student where "; if(name_sign==1) { sql=str_str(sql,"name = '"); sql=str_str(sql,name); sql=str_str(sql,"' and "); } else {} sql=str_str(sql," Chinese >"); sql =str_str(sql,ptr[0]); sql=str_str(sql," and Chinese <"); sql=str_str(sql,ptr[3]); sql=str_str(sql," and Math >"); sql =str_str(sql,ptr[1]); sql=str_str(sql," and Math <"); sql=str_str(sql,ptr[4]); sql=str_str(sql," and English >"); sql =str_str(sql,ptr[2]); sql=str_str(sql," and English <"); sql=str_str(sql,ptr[5]); if(sex_sign==0) sql=str_str(sql," and sex='鐢?"); else if(sex_sign==1) sql=str_str(sql," and sex='濂?"); else {}; //printf("%s\n",sql); result =sqlite3_get_table(pdb,sql,&dbResult,&nRow,&nCloumn,&ErrMsg); //printf("n = %d\n",nRow); if(nRow==0) { GtkWidget *dialog; GtkWidget *label; dialog = gtk_dialog_new(); gtk_window_set_title(GTK_WINDOW(dialog),"閿欒鎻愮ず"); gtk_widget_set_usize(dialog,100,100); label = gtk_label_new("鏌ヨ澶辫触锛?); gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox),label,TRUE,TRUE,0); g_signal_connect(G_OBJECT(dialog),"delete_event",G_CALLBACK(release_resourse),NULL); gtk_widget_show_all(dialog); gtk_main(); } else { temp=""; for(i = 0;i < nRow;i++) { for(j = 0;j < nCloumn;j++) { //printf("%s--->%s\n",dbResult[j],dbResult[(i+1)*nCloumn+j]); if(xuanzhong[j]==1) temp1=str_filled(dbResult[(i+1)*nCloumn+j]); else temp1=" "; temp=str_str(temp,temp1); } if(i<(nRow-1)) temp = str_str(temp,"\n"); } } // printf("temp = %s\n",temp); gtk_text_buffer_set_text(buffer,temp,-1); sqlite3_free_table(dbResult); sqlite3_close(pdb); }