圖書館管理系統(tǒng)程序設計代碼_第1頁
圖書館管理系統(tǒng)程序設計代碼_第2頁
圖書館管理系統(tǒng)程序設計代碼_第3頁
圖書館管理系統(tǒng)程序設計代碼_第4頁
圖書館管理系統(tǒng)程序設計代碼_第5頁
已閱讀5頁,還剩5頁未讀 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

1、精選優(yōu)質文檔-傾情為你奉上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;" /連接數據庫的字符串,用于

2、指定數據庫地址,名稱,賬號,密碼,連接方式 SqlConnection sqlCon = new SqlConnection(strcon); /實例化并定義一個數據庫連接 sqlCon.Open(); /打開數據庫連接 string sql = "select * from login where usernum=usernum and userpassword=suerpassword" /定義要查詢sql語句 SqlCommand cmd = new SqlCommand(sql, sqlCon); /實例化并定義sql語句和數據庫路徑 cmd.Parameters.

3、Add("usernum", SqlDbType.NChar, 20); /定義cmd查詢命令的字段屬性,loginname sqldbtype nchar(20) cmd.Parameters.Add("suerpassword", SqlDbType.NChar, 20); /同上 cmd.Parameters"usernum".Value = username.Text; /將username中的text保存到變量loginname cmd.Parameters"suerpassword".Value = p

4、assword.Text; /同上 SqlDataReader dr = cmd.ExecuteReader(); if (dr.Read() this.Visible=false; Form2 Formmain = new Form2(); /應該是實例化一個主窗體的 this.Hide(); /應該是切換到主窗口的或關閉自己的 Formmain.Show(); /應該是打開一個主窗體的 dr.Close();/關閉dr的數據庫連接 else / if (dr.Read()讀取失敗則執(zhí)行如下代碼 MessageBox.Show("密碼錯誤,請重新輸入!"); /顯示提示信

5、息 else if (radioPerson.Checked=true) string strcon = "Data Source=SIMON-VAIO;Initial Catalog=lkl2;Integrated Security=True;" /連接數據庫的字符串,用于指定數據庫地址,名稱,賬號,密碼,連接方式 SqlConnection sqlCon = new SqlConnection(strcon); /實例化并定義一個數據庫連接 sqlCon.Open(); /打開數據庫連接 string sql1 = "select * from reader

6、where usernum=usernum and userpassword=suerpassword" /定義要查詢sql語句 SqlCommand cmd1 = new SqlCommand(sql1, sqlCon); /實例化并定義sql語句和數據庫路徑 cmd1.Parameters.Add("usernum", SqlDbType.NChar, 20); /定義cmd查詢命令的字段屬性,loginname sqldbtype nchar(20) cmd1.Parameters.Add("suerpassword", SqlDbTyp

7、e.NChar, 20); /同上 cmd1.Parameters"usernum".Value = username.Text; /將username中的text保存到變量loginname cmd1.Parameters"suerpassword".Value = password.Text; /同上 cmd1.CommandText=sql1; SqlDataReader dr = cmd1.ExecuteReader(); if (dr.Read() this.Visible=false; Form9 Formmain = new Form9()

8、; /應該是實例化一個主窗體的 this.Hide(); /應該是切換到主窗口的或關閉自己的 dr.Close();/關閉dr的數據庫連接 Formmain.Show(); /應該是打開一個主窗體的 elseMessageBox.Show("用戶名或密碼錯ª誤","警告"); else MessageBox.Show("沒有選擇角色", "提示"); 添加圖書代碼SqlConnection sqlcon = new SqlConnection("Data Source=SIMON-VAIO;In

9、itial 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

10、", 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); cmd.Parameters"bnum

11、".Value = bnum.Text; cmd.Parameters"bname".Value = bname.Text; cmd.Parameters"bauthor".Value = bauthor.Text; cmd.Parameters"bpublic".Value = bpublic.Text; cmd.Parameters"bclasses".Value = bclasses.Text; cmd.Parameters"benshu".Value = benshu.Text

12、; cmd.ExecuteNonQuery(); sqlcon.Close(); this.bnum.Clear(); this.bname.Clear(); this.bauthor.Clear(); this.bpublic.Clear(); this.benshu.Clear(); this.bclasses.Clear(); MessageBox.Show("添加成功!");刪除圖書代碼SqlConnection sqlcon = new SqlConnection("Data Source=SIMON-VAIO;Initial Catalog=lkl2;

13、Integrated Security=True"); sqlcon.Open(); string str = "delete from book where bnum=bnum" SqlCommand cmd = new SqlCommand(str, sqlcon); cmd.Parameters.Add("bnum", SqlDbType.NChar, 20); cmd.Parameters"bnum".Value = this.tnum.Text; cmd.ExecuteNonQuery(); sqlcon.Clos

14、e(); 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 SqlConnection();/建立數據庫連接 con.ConnectionString = "Data Source=SIMON-VAIO;Initi

15、al 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.Parameters"bname".Value = bookname.Text; SqlDataAdapter da = new SqlDataA

16、dapter(cmd); DataTable dt = new DataTable("圖書記錄表"); da.TableMappings.Add("BorrowRecord", "借閱記錄表"); da.TableMappings0.ColumnMappings.Add("bnum", "圖書號"); da.TableMappings0.ColumnMappings.Add("bname", "圖書名"); da.TableMappings0.Column

17、Mappings.Add("bauthor", "作者"); da.TableMappings0.ColumnMappings.Add("bpublic", "出版社"); da.TableMappings0.ColumnMappings.Add("bclasses", "類別"); da.TableMappings0.ColumnMappings.Add("benshu", "本數"); da.Fill(dt); dataGridVi

18、ew1.DataSource = dt; con.Close();圖書更新代碼SqlConnection con1 = new SqlConnection("Data Source=SIMON-VAIO;Initial Catalog=lkl2;Integrated Security=True;"); con1.Open(); SqlCommand cmd1 = new SqlCommand("update book set bname=bname,bauthor=bauthor,bpublic=bpublic,bclasses=bclasses,benshu=b

19、enshu 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.

20、Add("bclasses", SqlDbType.NChar, 20); cmd1.Parameters.Add("benshu", SqlDbType.NChar, 20); cmd1.Parameters"bnum".Value = cnum.Text; cmd1.Parameters"bname".Value = cname.Text; cmd1.Parameters"bauthor".Value = cauthor.Text; cmd1.Parameters"bpublic&

21、quot;.Value = cpublic.Text; cmd1.Parameters"bclasses".Value = cclasses.Text; cmd1.Parameters"benshu".Value = cbenshu.Text; cmd1.ExecuteNonQuery(); con1.Close(); um.Clear(); ame.Clear(); this.cauthor.Clear(); this.cpublic.Clear(); this.cclasses.Clear(); this.cbenshu.Clear(); Messa

22、geBox.Show("更新成功!");添加用戶代碼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 SqlComma

23、nd(str, sqlcon); cmd.Parameters.Add("usernum", SqlDbType.NChar, 20); cmd.Parameters.Add("username", SqlDbType.NChar, 20); cmd.Parameters.Add("userpassword", SqlDbType.NChar, 20); cmd.Parameters.Add("usertype", SqlDbType.NChar, 20); cmd.Parameters"usernum&

24、quot;.Value =usernum.Text; cmd.Parameters"username".Value = username.Text; cmd.Parameters"userpassword".Value = userpassword.Text; cmd.Parameters"usertype".Value = usertype.Text; cmd.ExecuteNonQuery(); sqlcon.Close(); this.usernum.Clear(); this.username.Clear(); this.us

25、erpassword.Clear(); this.usertype.Clear(); MessageBox.Show("用戶添加成功!"刪除用戶代碼SqlConnection sqlcon = new SqlConnection("Data Source=SIMON-VAIO;Initial Catalog=lkl2;Integrated Security=True"); sqlcon.Open(); string str = "delete from reader where usernum=usernum" SqlCommand

26、cmd = new SqlCommand(str, sqlcon); cmd.Parameters.Add("usernum", SqlDbType.NChar, 20); cmd.Parameters"usernum".Value = this.num.Text; cmd.ExecuteNonQuery(); sqlcon.Close(); MessageBox.Show("刪除成功!");修改密碼代碼 SqlConnection con1 = new SqlConnection("Data Source=SIMON-VA

27、IO;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); cmd1.Parameters.Add("userpassword",

28、SqlDbType.NChar, 20); cmd1.Parameters"usernum".Value = cusernum.Text; cmd1.Parameters"userpassword".Value = cuserpassword.Text; cmd1.ExecuteNonQuery(); con1.Close(); this.cusernum.Clear(); this.cuserpassword.Clear(); MessageBox.Show("修改成功請從新登陸!");完善讀者信息代碼SqlConnection s

29、qlcon = 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("

30、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); cmd.Parame

31、ters"usernum".Value = usernum.Text; cmd.Parameters"username".Value = username.Text; cmd.Parameters"usersex".Value = usersex.Text; cmd.Parameters"usergrade".Value = usergrade.Text; cmd.Parameters"telephone".Value =telephone.Text; cmd.ExecuteNonQuery()

32、; sqlcon.Close(); this.usernum.Clear(); this.username.Clear(); this.userpassword.Clear(); this.usertype.Clear(); this.usersex.Clear(); this.usergrade.Clear(); this.telephone.Clear(); MessageBox.Show("添加信息成功!");檢索用戶信息代碼if (num.Text = "") MessageBox.Show("請輸入學生學號!"); else

33、 string strcon = "Data Source=SIMON-VAIO;Initial Catalog=lkl2;Integrated Security=True" SqlConnection sqlCon = new SqlConnection(strcon); sqlCon.Open(); string sql = "select * from readerifo where usernum=usernum " SqlCommand cmd = new SqlCommand(sql, sqlCon); cmd.Parameters.Add(

34、"usernum", SqlDbType.NChar, 20); cmd.Parameters"usernum".Value = num.Text; /創(chuàng)建 SqlDataReader,必須調用 SqlCommand 對象的 ExecuteReader 方法,而不要直接使用構造函數。 SqlDataReader dr = cmd.ExecuteReader(); if (dr.Read() this.usernum.Text = dr"usernum".ToString().Trim(); this.username.Text = d

35、r"username".ToString().Trim(); this.usersex.Text = dr"usersex".ToString().Trim(); this.usergrade.Text = dr"usergrade".ToString().Trim(); this.telephone.Text = dr"telephone".ToString().Trim(); MessageBox.Show("歡迎光臨本圖書館來借書!"); sqlCon.Close();借閱圖書代碼SqlC

36、onnection 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

37、cmd = new SqlCommand(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("bpublic", SqlDbType.NChar, 20); cmd.Parameters.Add(&qu

38、ot;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(&

39、quot;usersex", SqlDbType.NChar, 20); cmd.Parameters.Add("usergrade", SqlDbType.NChar, 20); cmd.Parameters.Add("telephone", SqlDbType.NChar, 20); cmd.Parameters"bnum".Value = tno.Text; cmd.Parameters"bname".Value = tname.Text; cmd.Parameters"bauthor&q

40、uot;.Value = tauthor.Text; cmd.Parameters"bpublic".Value = tpublisher.Text; cmd.Parameters"bclasses".Value = tclasses.Text; cmd.Parameters"benshu".Value = "1" cmd.Parameters"btime".Value = System.DateTime.Now; cmd.Parameters"usernum".Value

41、= usernum.Text; cmd.Parameters"username".Value = username.Text; cmd.Parameters"usersex".Value = usersex.Text; cmd.Parameters"usergrade".Value = usergrade.Text; cmd.Parameters.Add(new SqlParameter("borrowtime", DateTime.Now); cmd.Parameters"telephone"

42、.Value = telephone.Text; cmd.ExecuteNonQuery(); sqlcon.Close(); SqlConnection con1 = new SqlConnection("Data Source=SIMON-VAIO;Initial Catalog=lkl2;Integrated Security=True;"); con1.Open(); SqlCommand cmd1 = new SqlCommand("update book set benshu=benshu-1 where bnum=bnum", con1);

43、 cmd1.Parameters.Add("bnum", SqlDbType.NChar, 20); cmd1.Parameters"bnum".Value = tnum.Text; cmd1.ExecuteNonQuery(); con1.Close(); this.tnum.Clear(); this.tno.Clear(); this.tname.Clear(); this.tauthor.Clear(); this.tpublisher.Clear(); this.tclasses.Clear(); this.num.Clear(); this.

44、usernum.Clear(); this.username.Clear(); this.usersex.Clear(); this.usergrade.Clear(); this.tbenshu.Clear(); this.telephone.Clear(); MessageBox.Show("借閱成功!");歸還圖書代碼 SqlConnection sqlcon = new SqlConnection("Data Source=SIMON-VAIO;Initial Catalog=lkl2;Integrated Security=True;"); s

45、tring str = "insert into dbo.returnifo values(bnum,bname,bauthor,bpublic,bclasses,benshu,rtime,usernum,username,usersex,usergrade,telephone)" sqlcon.Open(); SqlCommand cmd = new SqlCommand(str, sqlcon); cmd.Parameters.Add("bnum", SqlDbType.NChar, 20); cmd.Parameters.Add("bna

46、me", 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); cmd.Parameters.Add(&qu

47、ot;rtime", 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.A

48、dd("telephone", SqlDbType.NChar, 20); cmd.Parameters"bnum".Value = sno.Text; cmd.Parameters"bname".Value = sname.Text; cmd.Parameters"bauthor".Value = sauthor.Text; cmd.Parameters"bpublic".Value = spublisher.Text; cmd.Parameters"bclasses".V

49、alue = sclasses.Text; cmd.Parameters"benshu".Value = sbenshu.Text; cmd.Parameters"rtime".Value = System.DateTime.Now; cmd.Parameters"usernum".Value =usernum.Text; cmd.Parameters"username".Value = username.Text; cmd.Parameters"usersex".Value = usersex

50、.Text; cmd.Parameters"usergrade".Value = usergrade.Text; cmd.Parameters.Add(new SqlParameter("returntime", DateTime.Now); cmd.Parameters"telephone".Value = telephone.Text; cmd.ExecuteNonQuery(); sqlcon.Close(); SqlConnection con1 = new SqlConnection("Data Source=SIMON-VAIO;Initia

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
  • 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論