1、1.1 程序设计代码登录模块if(username.Text.Trim()=|password.Text.Trim()=)MessageBox.Show(请输入用户名和密码,提醒);else if (radioManage.Checked = true) string strcon = Data Source=SIMON-VAIO;Initial Catalog=lkl2;Integrated Security=True; /连接数据库字符串,用于指定数据库地址,名称,账号,密码,连接方法 SqlConnection sqlCon = new SqlConnection(strcon); /实
2、例化并定义一个数据库连接 sqlCon.Open(); /打开数据库连接 string sql = select * from login where usernum=usernum and userpassword=suerpassword; /定义要查询sql语句 SqlCommand cmd = new SqlCommand(sql, sqlCon); /实例化并定义sql语句和数据库路径 cmd.Parameters.Add(usernum, SqlDbType.NChar, 20); /定义cmd查询命令字段属性,loginname sqldbtype nchar(20) cmd.P
3、arameters.Add(suerpassword, SqlDbType.NChar, 20); /同上 cmd.Parametersusernum.Value = username.Text; /将username中text保留到变量loginname cmd.Parameterssuerpassword.Value = password.Text; /同上 SqlDataReader dr = cmd.ExecuteReader(); if (dr.Read() this.Visible=false; Form2 Formmain = new Form2(); /应该是实例化一个主窗体
4、this.Hide(); /应该是切换到主窗口或关闭自己 Formmain.Show(); /应该是打开一个主窗体 dr.Close();/关闭dr数据库连接 else / if (dr.Read()读取失败则实施以下代码 MessageBox.Show(密码错误,请重新输入!); /显示提醒信息 else if (radioPerson.Checked=true) string strcon = Data Source=SIMON-VAIO;Initial Catalog=lkl2;Integrated Security=True; /连接数据库字符串,用于指定数据库地址,名称,账号,密码,
5、连接方法 SqlConnection sqlCon = new SqlConnection(strcon); /实例化并定义一个数据库连接 sqlCon.Open(); /打开数据库连接 string sql1 = select * from reader where usernum=usernum and userpassword=suerpassword; /定义要查询sql语句 SqlCommand cmd1 = new SqlCommand(sql1, sqlCon); /实例化并定义sql语句和数据库路径 cmd1.Parameters.Add(usernum, SqlDbType.
6、NChar, 20); /定义cmd查询命令字段属性,loginname sqldbtype nchar(20) cmd1.Parameters.Add(suerpassword, SqlDbType.NChar, 20); /同上 cmd1.Parametersusernum.Value = username.Text; /将username中text保留到变量loginname cmd1.Parameterssuerpassword.Value = password.Text; /同上 cmd1.CommandText=sql1; SqlDataReader dr = cmd1.Execu
7、teReader(); if (dr.Read() this.Visible=false; Form9 Formmain = new Form9(); /应该是实例化一个主窗体 this.Hide(); /应该是切换到主窗口或关闭自己 dr.Close();/关闭dr数据库连接 Formmain.Show(); /应该是打开一个主窗体 elseMessageBox.Show(用户名或密码错误,警告); else MessageBox.Show(没有选择角色, 提醒); 添加图书代码SqlConnection sqlcon = new SqlConnection(Data Source=SIMO
8、N-VAIO;Initial Catalog=lkl2;Integrated Security=True;); string str = insert into dbo.book values(bnum,bname,bauthor,bpublic,bclasses,benshu); sqlcon.Open(); SqlCommand cmd = new SqlCommand(str, sqlcon); cmd.Parameters.Add(bnum, SqlDbType.NChar, 20); cmd.Parameters.Add(bname, SqlDbType.NChar, 20); cm
9、d.Parameters.Add(bauthor, SqlDbType.NChar, 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.Text; cmd.Parametersbname.Value = bname.Text; cmd.Parametersbauthor.Valu
10、e = bauthor.Text; cmd.Parametersbpublic.Value = bpublic.Text; cmd.Parametersbclasses.Value = bclasses.Text; cmd.Parametersbenshu.Value = benshu.Text; cmd.ExecuteNonQuery(); sqlcon.Close(); this.bnum.Clear(); this.bname.Clear(); this.bauthor.Clear(); this.bpublic.Clear(); this.benshu.Clear(); this.bc
11、lasses.Clear(); MessageBox.Show(添加成功!);删除图书代码SqlConnection sqlcon = new SqlConnection(Data Source=SIMON-VAIO;Initial Catalog=lkl2;Integrated Security=True); sqlcon.Open(); string str = delete from book where bnum=bnum; SqlCommand cmd = new SqlCommand(str, sqlcon); cmd.Parameters.Add(bnum, SqlDbType.
12、NChar, 20); cmd.Parametersbnum.Value = this.tnum.Text; cmd.ExecuteNonQuery(); sqlcon.Close(); this.tnum.Clear(); this.tno.Clear(); this.tname.Clear(); this.tpublisher.Clear(); this.tauthor.Clear(); this.tclasses.Clear(); this.tbenshu.Clear(); MessageBox.Show(删除成功!)查询图书代码SqlConnection con = new SqlCo
13、nnection();/建立数据库连接 con.ConnectionString = Data Source=SIMON-VAIO;Initial Catalog=lkl2;Integrated Security=True; con.Open();/打开连接 SqlCommand cmd = new SqlCommand(select * from book where bname=bname, con); cmd.Parameters.Add(bname, SqlDbType.NChar, 20); cmd.Parametersbname.Value = bookname.Text; Sql
14、DataAdapter da = new SqlDataAdapter(cmd); DataTable dt = new DataTable(图书统计表); da.TableMappings.Add(BorrowRecord, 借阅统计表); da.TableMappings0.ColumnMappings.Add(bnum, 图书号); da.TableMappings0.ColumnMappings.Add(bname, 图书名); da.TableMappings0.ColumnMappings.Add(bauthor, 作者); da.TableMappings0.ColumnMapp
15、ings.Add(bpublic, 出版社); da.TableMappings0.ColumnMappings.Add(bclasses, 类别); da.TableMappings0.ColumnMappings.Add(benshu, 本数); da.Fill(dt); dataGridView1.DataSource = dt; con.Close();图书更新代码SqlConnection con1 = new SqlConnection(Data Source=SIMON-VAIO;Initial Catalog=lkl2;Integrated Security=True;); c
16、on1.Open(); SqlCommand cmd1 = new SqlCommand(update book set bname=bname,bauthor=bauthor,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.NC
17、har, 20); cmd1.Parameters.Add(bpublic, SqlDbType.NChar, 20); cmd1.Parameters.Add(bclasses, SqlDbType.NChar, 20); cmd1.Parameters.Add(benshu, SqlDbType.NChar, 20); cmd1.Parametersbnum.Value = cnum.Text; cmd1.Parametersbname.Value = cname.Text; cmd1.Parametersbauthor.Value = cauthor.Text; cmd1.Paramet
18、ersbpublic.Value = cpublic.Text; cmd1.Parametersbclasses.Value = cclasses.Text; cmd1.Parametersbenshu.Value = cbenshu.Text; cmd1.ExecuteNonQuery(); con1.Close(); um.Clear(); ame.Clear(); this.cauthor.Clear(); this.cpublic.Clear(); this.cclasses.Clear(); this.cbenshu.Clear(); MessageBox.Show(更新成功!);添
19、加用户代码SqlConnection sqlcon = new SqlConnection(Data Source=SIMON-VAIO;Initial Catalog=lkl2;Integrated Security=True;); string str = insert into dbo.reader values(usernum,username,userpassword,usertype); sqlcon.Open(); SqlCommand cmd = new SqlCommand(str, sqlcon); cmd.Parameters.Add(usernum, SqlDbType
20、.NChar, 20); cmd.Parameters.Add(username, SqlDbType.NChar, 20); cmd.Parameters.Add(userpassword, SqlDbType.NChar, 20); cmd.Parameters.Add(usertype, SqlDbType.NChar, 20); cmd.Parametersusernum.Value =usernum.Text; cmd.Parametersusername.Value = username.Text; cmd.Parametersuserpassword.Value = userpa
21、ssword.Text; cmd.Parametersusertype.Value = usertype.Text; cmd.ExecuteNonQuery(); sqlcon.Close(); this.usernum.Clear(); this.username.Clear(); this.userpassword.Clear(); this.usertype.Clear(); MessageBox.Show(用户添加成功!删除用户代码SqlConnection sqlcon = new SqlConnection(Data Source=SIMON-VAIO;Initial Catalo
22、g=lkl2;Integrated Security=True); sqlcon.Open(); string str = delete from reader where usernum=usernum; SqlCommand cmd = new SqlCommand(str, sqlcon); cmd.Parameters.Add(usernum, SqlDbType.NChar, 20); cmd.Parametersusernum.Value = this.num.Text; cmd.ExecuteNonQuery(); sqlcon.Close(); MessageBox.Show(
23、删除成功!);修改密码代码 SqlConnection con1 = new SqlConnection(Data Source=SIMON-VAIO;Initial Catalog=lkl2;Integrated Security=True;); con1.Open(); SqlCommand cmd1 = new SqlCommand(update reader set userpassword=userpassword where usernum=usernum;, con1); cmd1.Parameters.Add(usernum, SqlDbType.NChar, 20); cmd
24、1.Parameters.Add(userpassword, SqlDbType.NChar, 20); cmd1.Parametersusernum.Value = cusernum.Text; cmd1.Parametersuserpassword.Value = cuserpassword.Text; cmd1.ExecuteNonQuery(); con1.Close(); this.cusernum.Clear(); this.cuserpassword.Clear(); MessageBox.Show(修改成功请从新登陆!);完善读者信息代码SqlConnection sqlcon
25、 = new SqlConnection(Data Source=SIMON-VAIO;Initial Catalog=lkl2;Integrated Security=True;); string str = insert into dbo.readerifo values(usernum,username,usersex,usergrade,telephone); sqlcon.Open(); SqlCommand cmd = new SqlCommand(str, sqlcon); cmd.Parameters.Add(usernum, SqlDbType.NChar, 20); cmd
26、.Parameters.Add(username, SqlDbType.NChar, 20); cmd.Parameters.Add(usersex, SqlDbType.NChar, 20); cmd.Parameters.Add(usergrade, SqlDbType.NChar, 20); cmd.Parameters.Add(telephone, SqlDbType.NChar, 20); cmd.Parametersusernum.Value = usernum.Text; cmd.Parametersusername.Value = username.Text; cmd.Para
27、metersusersex.Value = usersex.Text; cmd.Parametersusergrade.Value = usergrade.Text; cmd.Parameterstelephone.Value =telephone.Text; cmd.ExecuteNonQuery(); sqlcon.Close(); this.usernum.Clear(); this.username.Clear(); this.userpassword.Clear(); this.usertype.Clear(); this.usersex.Clear(); this.usergrad
28、e.Clear(); this.telephone.Clear(); MessageBox.Show(添加信息成功!);检索用户信息代码if (num.Text = ) MessageBox.Show(请输入学生学号!); else string strcon = Data Source=SIMON-VAIO;Initial Catalog=lkl2;Integrated Security=True; SqlConnection sqlCon = new SqlConnection(strcon); sqlCon.Open(); string sql = select * from reade
29、rifo where usernum=usernum ; SqlCommand cmd = new SqlCommand(sql, sqlCon); cmd.Parameters.Add(usernum, SqlDbType.NChar, 20); cmd.Parametersusernum.Value = num.Text; /创建 SqlDataReader,必需调用 SqlCommand 对象 ExecuteReader 方法,而不要直接使用结构函数。 SqlDataReader dr = cmd.ExecuteReader(); if (dr.Read() this.usernum.T
30、ext = drusernum.ToString().Trim(); this.username.Text = drusername.ToString().Trim(); this.usersex.Text = drusersex.ToString().Trim(); this.usergrade.Text = drusergrade.ToString().Trim(); this.telephone.Text = drtelephone.ToString().Trim(); MessageBox.Show(欢迎光临本图书馆来借书!); sqlCon.Close();借阅图书代码SqlConn
31、ection sqlcon = new SqlConnection(Data Source=SIMON-VAIO;Initial Catalog=lkl2;Integrated Security=True;); string str = insert into dbo.borrowifo values(bnum,bname,bauthor,bpublic,bclasses,benshu,btime,usernum,username,usersex,usergrade,telephone); sqlcon.Open(); SqlCommand cmd = new SqlCommand(str,
32、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(bpublic, SqlDbType.NChar, 20); cmd.Parameters.Add(bclasses, SqlDbType.NChar, 20); cmd.Parameters.Add(benshu, SqlDbType.TinyInt)
33、; cmd.Parameters.Add(btime, SqlDbType.Date); cmd.Parameters.Add(usernum, SqlDbType.NChar, 20); cmd.Parameters.Add(username, SqlDbType.NChar, 20); cmd.Parameters.Add(usersex, SqlDbType.NChar, 20); cmd.Parameters.Add(usergrade, SqlDbType.NChar, 20); cmd.Parameters.Add(telephone, SqlDbType.NChar, 20);
34、cmd.Parametersbnum.Value = tno.Text; cmd.Parametersbname.Value = tname.Text; cmd.Parametersbauthor.Value = tauthor.Text; cmd.Parametersbpublic.Value = tpublisher.Text; cmd.Parametersbclasses.Value = tclasses.Text; cmd.Parametersbenshu.Value = 1; cmd.Parametersbtime.Value = System.DateTime.Now; cmd.P
35、arametersusernum.Value = usernum.Text; cmd.Parametersusername.Value = username.Text; cmd.Parametersusersex.Value = usersex.Text; cmd.Parametersusergrade.Value = usergrade.Text; cmd.Parameters.Add(new SqlParameter(borrowtime, DateTime.Now); cmd.Parameterstelephone.Value = telephone.Text; cmd.ExecuteNonQuery(); sqlcon.Close(); SqlConnection con1 = new SqlConnection(Data Source=SIMON-VAIO;Initial Catalog=lkl2;Integrated Security=True;); con1.Open(); SqlCo
©2010-2024 宁波自信网络信息技术有限公司 版权所有
客服电话:4008-655-100 投诉/维权电话:4009-655-100