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

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、精選優(yōu)質(zhì)文檔-傾情為你奉上1.1 程序設(shè)計(jì)代碼登錄模塊if(username.Text.Trim()=""|password.Text.Trim()="")MessageBox.Show("請(qǐng)輸入用戶名和密碼","提示");else if (radioManage.Checked = true) string strcon = "Data Source=SIMON-VAIO;Initial Catalog=lkl2;Integrated Security=True;" /連接數(shù)據(jù)庫的字符串,用于

2、指定數(shù)據(jù)庫地址,名稱,賬號(hào),密碼,連接方式 SqlConnection sqlCon = new SqlConnection(strcon); /實(shí)例化并定義一個(gè)數(shù)據(jù)庫連接 sqlCon.Open(); /打開數(shù)據(jù)庫連接 string sql = "select * from login where usernum=usernum and userpassword=suerpassword" /定義要查詢sql語句 SqlCommand cmd = new SqlCommand(sql, sqlCon); /實(shí)例化并定義sql語句和數(shù)據(jù)庫路徑 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(); /應(yīng)該是實(shí)例化一個(gè)主窗體的 this.Hide(); /應(yīng)該是切換到主窗口的或關(guān)閉自己的 Formmain.Show(); /應(yīng)該是打開一個(gè)主窗體的 dr.Close();/關(guān)閉dr的數(shù)據(jù)庫連接 else / if (dr.Read()讀取失敗則執(zhí)行如下代碼 MessageBox.Show("密碼錯(cuò)誤,請(qǐng)重新輸入!"); /顯示提示信

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

6、where usernum=usernum and userpassword=suerpassword" /定義要查詢sql語句 SqlCommand cmd1 = new SqlCommand(sql1, sqlCon); /實(shí)例化并定義sql語句和數(shù)據(jù)庫路徑 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、; /應(yīng)該是實(shí)例化一個(gè)主窗體的 this.Hide(); /應(yīng)該是切換到主窗口的或關(guān)閉自己的 dr.Close();/關(guān)閉dr的數(shù)據(jù)庫連接 Formmain.Show(); /應(yīng)該是打開一個(gè)主窗體的 elseMessageBox.Show("用戶名或密碼錯(cuò)ª誤","警告"); 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();/建立數(shù)據(jù)庫連接 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", "圖書號(hào)"); 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", "本數(shù)"); 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("修改成功請(qǐng)從新登陸!");完善讀者信息代碼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("請(qǐng)輸入學(xué)生學(xué)號(hào)!"); 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,必須調(diào)用 SqlCommand 對(duì)象的 ExecuteReader 方法,而不要直接使用構(gòu)造函數(shù)。 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等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論