圖書館管理系統(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),請進(jìn)行舉報或認(rèn)領(lǐng)

文檔簡介

1、1.1 程序設(shè)計(jì)代碼登錄模塊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;" /連接數(shù)據(jù)庫的字符串,用于指定數(shù)據(jù)庫地址,名稱,賬號

2、,密碼,連接方式 SqlConnection sqlCon = new SqlConnection(strcon); /實(shí)例化并定義一個數(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.Add("use

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

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

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

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

7、 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(); /應(yīng)該是實(shí)例化一個主窗體的 t

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

9、2;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

10、.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".Value = bn

11、um.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; cmd.ExecuteNonQ

12、uery(); 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;Integrated Securi

13、ty=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.Close(); this.tnum.Cl

14、ear(); 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;Initial Catalog=lkl2;I

15、ntegrated 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 SqlDataAdapter(cmd); Data

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

17、t;bauthor", "作者"); da.TableMappings0.ColumnMappings.Add("bpublic", "出版社"); da.TableMappings0.ColumnMappings.Add("bclasses", "類別"); da.TableMappings0.ColumnMappings.Add("benshu", "本數(shù)"); da.Fill(dt); dataGridView1.DataSource =

18、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=benshu where bnum=

19、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("bclasse

20、s", 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".Value = cpu

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

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

23、 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".V

24、alue =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.userpassw

25、ord.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 cmd = n

26、ew 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-VAIO;Init

27、ial 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", SqlDbTy

28、pe.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 sqlcon =

29、 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

30、", 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.Parameters&qu

31、ot;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(); sqlco

32、n.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("請輸入學(xué)生學(xué)號!"); else string

33、 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("u

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

35、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();借閱圖書代碼SqlConnecti

36、on 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 = n

37、ew 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("bcla

38、sses", 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("us

39、ersex", 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".Va

40、lue = 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 = usern

41、um.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".Value

42、= 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); cmd1.P

43、arameters.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.usernum

44、.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;"); string s

45、tr = "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("bname"

46、;, 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("rtim

47、e", 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(&quo

48、t;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".Value =

49、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.Text;

50、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;Initial Catalog=lkl2;Integrate

溫馨提示

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

評論

0/150

提交評論