《图书馆管理系统程序设计代码.doc》由会员分享,可在线阅读,更多相关《图书馆管理系统程序设计代码.doc(10页珍藏版)》请在课桌文档上搜索。
1、1.1 程序设计代码登录模块if(username.Te*t.Trim()=|password.Te*t.Trim()=)MessageBo*.Show(请输入用户名和密码,提示);elseif (radioManage.Checked = true) string strcon = Data Source=SIMON-VAIO;Initial Catalog=lkl2;Integrated Security=True; /连接数据库的字符串,用于指定数据库地址,名称,账号,密码,连接方式SqlConnection sqlCon = newSqlConnection(strcon); /实例化
2、并定义一个数据库连接 sqlCon.Open(); /翻开数据库连接string sql = select * from login where usernum=usernum and userpassword=suerpassword; /定义要查询sql语句Sqlmand cmd = newSqlmand(sql, sqlCon); /实例化并定义sql语句和数据库路径 cmd.Parameters.Add(usernum, SqlDbType.NChar, 20); /定义cmd查询命令的字段属性,loginname sqldbtype nchar20 cmd.Parameters.Ad
3、d(suerpassword, SqlDbType.NChar, 20); /同上 cmd.Parametersusernum.Value = username.Te*t; /将username中的te*t保存到变量loginname cmd.Parameterssuerpassword.Value = password.Te*t; /同上SqlDataReader dr = cmd.E*ecuteReader();if (dr.Read() this.Visible=false; Form2 Formmain = newForm2(); /应该是实例化一个主窗体的this.Hide(); /
4、应该是切换到主窗口的或关闭自己的 Formmain.Show(); /应该是翻开一个主窗体的 dr.Close();/关闭dr的数据库连接 else/ if (dr.Read()读取失败则执行如下代码MessageBo*.Show(密码错误,请重新输入!); /显示提示信息 elseif (radioPerson.Checked=true) string strcon = Data Source=SIMON-VAIO;Initial Catalog=lkl2;Integrated Security=True; /连接数据库的字符串,用于指定数据库地址,名称,账号,密码,连接方式SqlConne
5、ction sqlCon = newSqlConnection(strcon); /实例化并定义一个数据库连接 sqlCon.Open(); /翻开数据库连接string sql1 = select * from reader where usernum=usernum and userpassword=suerpassword; /定义要查询sql语句Sqlmand cmd1 = newSqlmand(sql1, sqlCon); /实例化并定义sql语句和数据库路径 cmd1.Parameters.Add(usernum, SqlDbType.NChar, 20); /定义cmd查询命令的
6、字段属性,loginname sqldbtype nchar20 cmd1.Parameters.Add(suerpassword, SqlDbType.NChar, 20); /同上 cmd1.Parametersusernum.Value = username.Te*t; /将username中的te*t保存到变量loginname cmd1.Parameterssuerpassword.Value = password.Te*t; /同上 cmd1.mandTe*t=sql1;SqlDataReader dr = cmd1.E*ecuteReader();if (dr.Read() th
7、is.Visible=false;Form9 Formmain = newForm9(); /应该是实例化一个主窗体的this.Hide(); /应该是切换到主窗口的或关闭自己的 dr.Close();/关闭dr的数据库连接 Formmain.Show(); /应该是翻开一个主窗体的 elseMessageBo*.Show(用户名或密码错误,警告); elseMessageBo*.Show(没有选择角色, 提示); 添加图书代码SqlConnection sqlcon = newSqlConnection(Data Source=SIMON-VAIO;Initial Catalog=lkl2;
8、Integrated Security=True;);string str = insert into dbo.book values(bnum,bname,bauthor,bpublic,bclasses,benshu); sqlcon.Open();Sqlmand cmd = newSqlmand(str, sqlcon); cmd.Parameters.Add(bnum, SqlDbType.NChar, 20); cmd.Parameters.Add(bname, SqlDbType.NChar, 20); cmd.Parameters.Add(bauthor, SqlDbType.N
9、Char, 20); cmd.Parameters.Add(bpublic, SqlDbType.NChar, 20); cmd.Parameters.Add(bclasses, SqlDbType.NChar, 20); cmd.Parameters.Add(benshu, SqlDbType.TinyInt); cmd.Parametersbnum.Value = bnum.Te*t; cmd.Parametersbname.Value = bname.Te*t; cmd.Parametersbauthor.Value = bauthor.Te*t; cmd.Parametersbpubl
10、ic.Value = bpublic.Te*t; cmd.Parametersbclasses.Value = bclasses.Te*t; cmd.Parametersbenshu.Value = benshu.Te*t; cmd.E*ecuteNonQuery(); sqlcon.Close();this.bnum.Clear();this.bname.Clear();this.bauthor.Clear();this.bpublic.Clear();this.benshu.Clear();this.bclasses.Clear();MessageBo*.Show(添加成功!);删除图书代
11、码SqlConnection sqlcon = newSqlConnection(Data Source=SIMON-VAIO;Initial Catalog=lkl2;Integrated Security=True); sqlcon.Open();string str = delete from book where bnum=bnum; Sqlmand cmd = newSqlmand(str, sqlcon); cmd.Parameters.Add(bnum, SqlDbType.NChar, 20); cmd.Parametersbnum.Value = this.tnum.Te*t
12、; cmd.E*ecuteNonQuery(); sqlcon.Close();this.tnum.Clear();this.tno.Clear();this.tname.Clear();this.tpublisher.Clear();this.tauthor.Clear();this.tclasses.Clear();this.tbenshu.Clear();MessageBo*.Show(删除成功!)查询图书代码SqlConnection con = newSqlConnection();/建立数据库连接 con.ConnectionString = Data Source=SIMON-V
13、AIO;Initial Catalog=lkl2;Integrated Security=True; con.Open();/翻开连接Sqlmand cmd = newSqlmand(select * from book where bname=bname, con); cmd.Parameters.Add(bname, SqlDbType.NChar, 20); cmd.Parametersbname.Value = bookname.Te*t;SqlDataAdapter da = newSqlDataAdapter(cmd);DataTable dt = newDataTable(图书记
14、录表); da.TableMappings.Add(BorrowRecord, 借阅记录表); da.TableMappings0.ColumnMappings.Add(bnum, 图书号); da.TableMappings0.ColumnMappings.Add(bname, 图书名); da.TableMappings0.ColumnMappings.Add(bauthor, 作者); da.TableMappings0.ColumnMappings.Add(bpublic, ); da.TableMappings0.ColumnMappings.Add(bclasses, 类别); d
15、a.TableMappings0.ColumnMappings.Add(benshu, 本数); da.Fill(dt); dataGridView1.DataSource = dt; con.Close();图书更新代码SqlConnection con1 = newSqlConnection(Data Source=SIMON-VAIO;Initial Catalog=lkl2;Integrated Security=True;); con1.Open();Sqlmand cmd1 = newSqlmand(update book set bname=bname,bauthor=bauth
16、or,bpublic=bpublic,bclasses=bclasses,benshu=benshu where bnum=bnum;, con1); cmd1.Parameters.Add(bnum, SqlDbType.NChar, 20); cmd1.Parameters.Add(bname, SqlDbType.NChar, 20); cmd1.Parameters.Add(bauthor, SqlDbType.NChar, 20); cmd1.Parameters.Add(bpublic, SqlDbType.NChar, 20); cmd1.Parameters.Add(bclas
17、ses, SqlDbType.NChar, 20); cmd1.Parameters.Add(benshu, SqlDbType.NChar, 20); cmd1.Parametersbnum.Value = um.Te*t; cmd1.Parametersbname.Value = ame.Te*t; cmd1.Parametersbauthor.Value = cauthor.Te*t; cmd1.Parametersbpublic.Value = cpublic.Te*t; cmd1.Parametersbclasses.Value = cclasses.Te*t; cmd1.Param
18、etersbenshu.Value = cbenshu.Te*t; cmd1.E*ecuteNonQuery(); con1.Close();this.um.Clear();this.ame.Clear();this.cauthor.Clear();this.cpublic.Clear();this.cclasses.Clear();this.cbenshu.Clear();MessageBo*.Show(更新成功!);添加用户代码SqlConnection sqlcon = newSqlConnection(Data Source=SIMON-VAIO;Initial Catalog=lkl
19、2;Integrated Security=True;);string str = insert into dbo.reader values(usernum,username,userpassword,usertype); sqlcon.Open();Sqlmand cmd = newSqlmand(str, sqlcon); cmd.Parameters.Add(usernum, SqlDbType.NChar, 20); cmd.Parameters.Add(username, SqlDbType.NChar, 20); cmd.Parameters.Add(userpassword,
20、SqlDbType.NChar, 20); cmd.Parameters.Add(usertype, SqlDbType.NChar, 20); cmd.Parametersusernum.Value =usernum.Te*t; cmd.Parametersusername.Value = username.Te*t; cmd.Parametersuserpassword.Value = userpassword.Te*t; cmd.Parametersusertype.Value = usertype.Te*t; cmd.E*ecuteNonQuery(); sqlcon.Close();
21、this.usernum.Clear();this.username.Clear();this.userpassword.Clear();this.usertype.Clear();MessageBo*.Show(用户添加成功!删除用户代码SqlConnection sqlcon = newSqlConnection(Data Source=SIMON-VAIO;Initial Catalog=lkl2;Integrated Security=True); sqlcon.Open();string str = delete from reader where usernum=usernum;S
22、qlmand cmd = newSqlmand(str, sqlcon); cmd.Parameters.Add(usernum, SqlDbType.NChar, 20); cmd.Parametersusernum.Value = this.num.Te*t; cmd.E*ecuteNonQuery(); sqlcon.Close();MessageBo*.Show(删除成功!);修改密码代码SqlConnection con1 = newSqlConnection(Data Source=SIMON-VAIO;Initial Catalog=lkl2;Integrated Securit
23、y=True;); con1.Open();Sqlmand cmd1 = newSqlmand(update reader set userpassword=userpassword where usernum=usernum;, con1); cmd1.Parameters.Add(usernum, SqlDbType.NChar, 20); cmd1.Parameters.Add(userpassword, SqlDbType.NChar, 20); cmd1.Parametersusernum.Value = cusernum.Te*t; cmd1.Parametersuserpassw
24、ord.Value = cuserpassword.Te*t; cmd1.E*ecuteNonQuery(); con1.Close();this.cusernum.Clear();this.cuserpassword.Clear();MessageBo*.Show(修改成功请从新登陆!);完善读者信息代码SqlConnection sqlcon = newSqlConnection(Data Source=SIMON-VAIO;Initial Catalog=lkl2;Integrated Security=True;);string str = insert into dbo.reader
25、ifo values(usernum,username,userse*,usergrade,telephone); sqlcon.Open();Sqlmand cmd = newSqlmand(str, sqlcon); cmd.Parameters.Add(usernum, SqlDbType.NChar, 20); cmd.Parameters.Add(username, SqlDbType.NChar, 20); cmd.Parameters.Add(userse*, SqlDbType.NChar, 20); cmd.Parameters.Add(usergrade, SqlDbTyp
26、e.NChar, 20); cmd.Parameters.Add(telephone, SqlDbType.NChar, 20); cmd.Parametersusernum.Value = usernum.Te*t; cmd.Parametersusername.Value = username.Te*t; cmd.Parametersuserse*.Value = userse*.Te*t; cmd.Parametersusergrade.Value = usergrade.Te*t; cmd.Parameterstelephone.Value =telephone.Te*t; cmd.E
27、*ecuteNonQuery(); sqlcon.Close();this.usernum.Clear();this.username.Clear();this.userpassword.Clear();this.usertype.Clear();this.userse*.Clear();this.usergrade.Clear();this.telephone.Clear();MessageBo*.Show(添加信息成功!);检索用户信息代码if (num.Te*t = ) MessageBo*.Show(请输入学生*!); else string strcon = Data Source=
28、SIMON-VAIO;Initial Catalog=lkl2;Integrated Security=True;SqlConnection sqlCon = newSqlConnection(strcon); sqlCon.Open();string sql = select * from readerifo where usernum=usernum ;Sqlmand cmd = newSqlmand(sql, sqlCon); cmd.Parameters.Add(usernum, SqlDbType.NChar, 20); cmd.Parametersusernum.Value = n
29、um.Te*t;/创立 SqlDataReader,必须调用 Sqlmand 对象的 E*ecuteReader 方法,而不要直接使用构造函数。SqlDataReader dr = cmd.E*ecuteReader();if (dr.Read() this.usernum.Te*t = drusernum.ToString().Trim();this.username.Te*t = drusername.ToString().Trim();this.userse*.Te*t = druserse*.ToString().Trim();this.usergrade.Te*t = druserg
30、rade.ToString().Trim();this.telephone.Te*t = drtelephone.ToString().Trim();MessageBo*.Show(欢送光临本图书馆来借书!); sqlCon.Close();借阅图书代码SqlConnection sqlcon = newSqlConnection(Data Source=SIMON-VAIO;Initial Catalog=lkl2;Integrated Security=True;);string str = insert into dbo.borrowifo values(bnum,bname,bauth
31、or,bpublic,bclasses,benshu,btime,usernum,username,userse*,usergrade,telephone); sqlcon.Open();Sqlmand cmd = newSqlmand(str, sqlcon); cmd.Parameters.Add(bnum, SqlDbType.NChar, 20); cmd.Parameters.Add(bname, SqlDbType.NChar, 20); cmd.Parameters.Add(bauthor, SqlDbType.NChar, 20); cmd.Parameters.Add(bpu
32、blic, SqlDbType.NChar, 20); cmd.Parameters.Add(bclasses, SqlDbType.NChar, 20); cmd.Parameters.Add(benshu, SqlDbType.TinyInt); cmd.Parameters.Add(btime, SqlDbType.Date); cmd.Parameters.Add(usernum, SqlDbType.NChar, 20); cmd.Parameters.Add(username, SqlDbType.NChar, 20); cmd.Parameters.Add(userse*, Sq
33、lDbType.NChar, 20); cmd.Parameters.Add(usergrade, SqlDbType.NChar, 20); cmd.Parameters.Add(telephone, SqlDbType.NChar, 20); cmd.Parametersbnum.Value = tno.Te*t; cmd.Parametersbname.Value = tname.Te*t; cmd.Parametersbauthor.Value = tauthor.Te*t; cmd.Parametersbpublic.Value = tpublisher.Te*t; cmd.Para
34、metersbclasses.Value = tclasses.Te*t; cmd.Parametersbenshu.Value = 1; cmd.Parametersbtime.Value = System.DateTime.Now; cmd.Parametersusernum.Value = usernum.Te*t; cmd.Parametersusername.Value = username.Te*t; cmd.Parametersuserse*.Value = userse*.Te*t; cmd.Parametersusergrade.Value = usergrade.Te*t;
35、 cmd.Parameters.Add(newSqlParameter(borrowtime, DateTime.Now); cmd.Parameterstelephone.Value = telephone.Te*t; cmd.E*ecuteNonQuery(); sqlcon.Close();SqlConnection con1 = newSqlConnection(Data Source=SIMON-VAIO;Initial Catalog=lkl2;Integrated Security=True;); con1.Open();Sqlmand cmd1 = newSqlmand(upd
36、ate book set benshu=benshu-1 where bnum=bnum, con1); cmd1.Parameters.Add(bnum, SqlDbType.NChar, 20); cmd1.Parametersbnum.Value = tnum.Te*t; cmd1.E*ecuteNonQuery(); con1.Close();this.tnum.Clear();this.tno.Clear();this.tname.Clear();this.tauthor.Clear();this.tpublisher.Clear();this.tclasses.Clear();th
37、is.num.Clear();this.usernum.Clear();this.username.Clear();this.userse*.Clear();this.usergrade.Clear();this.tbenshu.Clear();this.telephone.Clear();MessageBo*.Show(借阅成功!);归还图书代码SqlConnection sqlcon = newSqlConnection(Data Source=SIMON-VAIO;Initial Catalog=lkl2;Integrated Security=True;);string str = i
38、nsert into dbo.returnifo values(bnum,bname,bauthor,bpublic,bclasses,benshu,rtime,usernum,username,userse*,usergrade,telephone); sqlcon.Open();Sqlmand cmd = newSqlmand(str, sqlcon); cmd.Parameters.Add(bnum, SqlDbType.NChar, 20); cmd.Parameters.Add(bname, SqlDbType.NChar, 20); cmd.Parameters.Add(bauth
39、or, SqlDbType.NChar, 20); cmd.Parameters.Add(bpublic, SqlDbType.NChar, 20); cmd.Parameters.Add(bclasses, SqlDbType.NChar, 20); cmd.Parameters.Add(benshu, SqlDbType.TinyInt); cmd.Parameters.Add(rtime, SqlDbType.Date); cmd.Parameters.Add(usernum, SqlDbType.NChar, 20); cmd.Parameters.Add(username, SqlDbType.NChar, 20); cmd.Parameters.Add(userse*, SqlDbType.NChar, 20); cmd.Parameters.Add(usergrade, SqlDbType.NChar, 20); cmd.Parameters.Add(telephone, SqlDbType.NChar, 20); cmd.Parametersbnum.Value = sno.Te*t; cmd.Param
链接地址:https://www.desk33.com/p-22968.html