vb+sql2000图书管理系统.doc
Vb+sql2000图书管理代码及控件主要控件:Commandbutton,textbox,frame,label, Toolbar, ProgressBar, CommonDialog, Timer, StatusBar, ImageList, Adodc, DataGrid主界面模型图:图书管理主界面图书信息管理图书借阅管理读者信息管理添加修改删除图书信息图书所有信息查询图书信息添加修改删除借阅信息图书借阅查询添加删除修改读者信息查询读者信息1.登录界面设计过程:用于输入用户名和密码登录,若是用户输入用户名和密码错误则不能进入系统。界面是一个GIF图片。来自于第三方控件。代码:Private Sub cmdok_Click()Dim cn As New ADODB.ConnectionDim rs As New ADODB.RecordsetDim flag As BooleanDim cn_str As String, sql_str As Stringcn_str = "DRIVER=SQL SERVER;SERVER=QA2ONHYK7VWHRY2;DATABASE=library"cn.Open cn_strsql_str = "select username ,userp from user_info"rs.Open sql_str, cnWhile Not rs.EOFIf txtusername.Text = Trim(rs(0) And txtpassword.Text = Trim(rs(1) ThenMe.Hide form8.Showflag = TrueExit SubElsers.MoveNextflag = FalseEnd IfWendIf flag = False ThenMsgBox "输入的用户名或密码有误,请重新输入!", vbCritical + vbOKOnly, "错误"rs.CloseEnd IfEnd SubPrivate Sub Command1_Click()If MsgBox("你确定要退出?", vbYesNo) = vbNo Thenfrmlogin.ShowElseUnload MeEnd IfEnd SubPrivate Sub txtpassword_GotFocus()txtpassword = ""txtpassword.PasswordChar = "*"End SubPrivate Sub txtusername_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)Static Toogle As BooleanIf Toogle = False Thentxtusername = ""Toogle = TrueEnd If2图书管理主界面设计过程:所有功能都在菜单中打开来实现。设计代码:Private Sub adu_Click(Index As Integer) form3.ShowEnd SubPrivate Sub b_Click()DataReport1.ShowEnd SubPrivate Sub BEI_Click() form4.ShowEnd SubPrivate Sub Command1_Click()frmaduinfo.ShowEnd SubPrivate Sub Command2_Click()frmseekxs.ShowEnd SubPrivate Sub Command3_Click()frmaduclass_info.ShowEnd SubPrivate Sub Command4_Click()frmaduclass_info.ShowEnd SubPrivate Sub Command5_Click()frmadu_course.ShowEnd SubPrivate Sub Command6_Click()frminquire_course.ShowEnd SubPrivate Sub Command7_Click()frmmodify_result.ShowEnd SubPrivate Sub Command8_Click()frminquire_result.ShowEnd SubPrivate Sub MDIForm_Load()Me.Left = GetSetting(App.Title, "setting", "mainleft", 1000)Me.Top = GetSetting(App.Title, "setting", "maintop", 1000)Me.Width = GetSetting(App.Title, "setting", "mainwidth", 1000)Me.Height = GetSetting(App.Title, "setting", "mainheight", 1000)End SubPrivate Sub MDIForm_Unload(Cancel As Integer)If Me.WindowState <> vbMinimized ThenSaveSetting App.Title, "settings", "mainleft", Me.LeftSaveSetting App.Title, "settings", "maintop", Me.TopSaveSetting App.Title, "settings", "mainwidth", Me.WidthSaveSetting App.Title, "settings", "mainheight", Me.HeightEnd IfEnd SubPrivate Sub cxbj_Click(Index As Integer)frminquire_bj_info.ShowEnd SubPrivate Sub Command9_Click()DataReport1.ShowEnd SubPrivate Sub cxcj_Click(Index As Integer)frminquire_result.ShowEnd SubPrivate Sub c_Click()Form10.ShowEnd SubPrivate Sub cxkc_Click(Index As Integer) form6.ShowEnd SubPrivate Sub cxxs_Click(Index As Integer) form9.ShowEnd SubPrivate Sub Form_Load()StatusBar1.Panels(3).Text = Format(Now, "yyyy年mm月dd日 ")StatusBar1.Panels(4).Text = Format(Now, " hh点mm分ss秒")End SubPrivate Sub hai_Click() form5.ShowEnd SubPrivate Sub Label1_Click()Label1.ForeColor = RGB(Int(Rnd * 255), Int(Rnd * 255), Int(Rnd * 255)End SubPrivate Sub s_Click()Form11.ShowEnd SubPrivate Sub tc_Click()Unload MeEndEnd SubPrivate Sub Timer1_Timer()StatusBar1.Panels(3).Text = Format(Now, "yyyy年mm月dd日 ")StatusBar1.Panels(4).Text = Format(Now, " hh点mm分ss秒")Label1.ForeColor = RGB(Int(Rnd * 255), Int(Rnd * 255), Int(Rnd * 255)End SubPrivate Sub tjbj_Click(Index As Integer) form2.ShowEnd SubPrivate Sub tjcj_Click(Index As Integer)frmmodify_result.ShowEnd SubPrivate Sub tjkc_Click(Index As Integer)form1.ShowEnd SubPrivate Sub tjxs_Click()frmadd_s_info.ShowEnd SubPrivate Sub xgcj_Click(Index As Integer)frmmodify_result.ShowEnd SubPrivate Sub Toolbar1_ButtonClick(ByVal Button As MSComctlLib.Button) Select Case Button.key Case "tt" form3.ShowCase "ct" form9.Show Case "tj" form2.Show Case "xj" form2.Show Case "td" form1.Show Case "cd" form6.Show Case "exit" End End SelectEnd Sub3.2.1图书信息管理 3.2.1.1添加修改删除图书信息 添加修改删除图书信息设计过程:选择添加修改删除图书信息,在相应的栏目填入或选择相应的内容,点击相应的按钮可以实现添加修改删除图书信息。设计代码:Dim rs As New ADODB.RecordsetPrivate Sub Command1_Click()rs.Deleters.AddNewrs("图书号") = Trim(Text1.Text)rs("书籍名称") = Trim(Text2.Text)rs("作者") = Trim(Text3.Text)rs("出版社") = Trim(Text4.Text)rs("订购价格") = Trim(Text5.Text)rs("附件") = Trim(Text6.Text)rs("条码号") = Trim(Text7.Text)rs("规定天数") = Trim(Text8.Text)rs("书的状态") = Trim(Text9.Text)rs.UpdateMsgBox "修改信息成功!", vbExclamation + vbOKOnly, "提示"End SubPrivate Sub Command2_Click()rs.DeleteMsgBox "删除成功!", vbExclamation + vbOKOnly, "提示"End SubPrivate Sub Command3_Click(Index As Integer)Select Case IndexCase 0rs.MoveFirstFrame2.Caption = "当前位置" & rs.AbsolutePosition & "/" & rs.RecordCountCase 1rs.MovePreviousIf rs.BOF Thenrs.MoveFirstFrame2.Caption = "当前位置" & rs.AbsolutePosition & "/" & rs.RecordCountMsgBox "已经是第一条记录", vbExclamation, "提示"End IfCase 2rs.MoveNextFrame2.Caption = "当前位置" & rs.AbsolutePosition & "/" & rs.RecordCountIf rs.EOF Thenrs.MoveLastMsgBox "已经是最后一条记录!", vbExclamation, "提示"End IfCase 3rs.MoveLastFrame2.Caption = "当前位置" & rs.AbsolutePosition & "/" & rs.RecordCountEnd SelectText1.Text = rs(0)Text2.Text = rs(1)Text3.Text = rs(2)Text4.Text = rs(3)Text5.Text = rs(4)Text6.Text = rs(5)Text7.Text = rs(6)Text8.Text = rs(7)Text9.Text = rs(8)End SubPrivate Sub Command4_Click()If Text1.Text = "" ThenMsgBox "请输入图书号!", vbOKOnly + vbExclamation, "警告"Text1.SetFocusExit SubEnd IfIf Text2.Text = "" ThenMsgBox "请输入书籍名称!", vbOKOnly + vbExclamation, "警告"Text2.SetFocusExit SubEnd IfIf Text3.Text = "" ThenMsgBox "请输入作者!", vbOKOnly + vbExclamation, "警告"Combo1.SetFocusExit SubEnd IfIf Text4.Text = "" ThenMsgBox "请输入出版社!", vbOKOnly + vbExclamation, "警告"Text4.SetFocusExit SubEnd IfIf Text5.Text = "" ThenMsgBox "请输入订购价格!", vbOKOnly + vbExclamation, "警告"Text5.SetFocusExit SubEnd IfIf Text6.Text = "" ThenMsgBox "请输入附件!", vbOKOnly + vbExclamation, "警告"Text4.SetFocusExit SubEnd IfIf Text7.Text = "" ThenMsgBox "请输入条码号!", vbOKOnly + vbExclamation, "警告"Text7.SetFocusExit SubEnd IfIf Text8.Text = "" ThenMsgBox "请输入规定天数!", vbOKOnly + vbExclamation, "警告"Text8.SetFocusExit SubEnd IfIf Text9.Text = "" ThenMsgBox "请输入书的状态!", vbOKOnly + vbExclamation, "警告"Text9.SetFocusExit SubEnd IfDim cn As New ADODB.ConnectionDim rs As New ADODB.RecordsetDim flag As BooleanDim cn_str As String, sql_str As Stringcn_str = "DRIVER=SQL SERVER;SERVER=QA2ONHYK7VWHRY2;DATABASE=library"cn.Open cn_strsql_str = "select *from 图书基本信息表"rs.Open sql_str, cn, adOpenDynamic, adLockOptimisticrs.AddNewrs("图书号") = Trim(Text1.Text)rs("书籍名称") = Trim(Text2.Text)rs("作者") = Trim(Text3.Text)rs("出版社") = Trim(Text4.Text)rs("订购价格") = Trim(Text5.Text)rs("附件") = Trim(Text6.Text)rs("条码号") = Trim(Text7.Text)rs("规定天数") = Trim(Text8.Text)rs("书的状态") = Trim(Text9.Text)rs.Updaters.CloseMsgBox "添加信息成功!", vbExclamation + vbOKOnly, "提示"End SubPrivate Sub Form_Load()Dim cn As New ADODB.ConnectionDim cn_str As String, sql_str As Stringcn_str = "DRIVER=SQL SERVER;SERVER=QA2ONHYK7VWHRY2;DATABASE=library"cn.Open cn_strsql_str = "select * from 图书基本信息表"rs.CursorLocation = adUseClientrs.Open sql_str, cn_str, adOpenDynamic, adLockOptimisticText1.Text = rs(0)Text2.Text = rs(1)Text3.Text = rs(2)Text4.Text = rs(3)Text5.Text = rs(4)Text6.Text = rs(5)Text7.Text = rs(6)Text8.Text = rs(7)Text9.Text = rs(8)End SubPrivate Sub Form_Unload(Cancel As Integer)rs.CloseEnd Sub3.3.1.3查询图书信息查询图书信息图设计过程:选择查询图书信息,在相应的栏目输入要查询的图书号就能查询该图书的基本信息设计代码:Private Sub Command1_Click()Dim cn As New ADODB.ConnectionDim rs As New ADODB.RecordsetDim flag As BooleanDim cn_str As String, sql_str As Stringcn_str = "DRIVER=SQL SERVER;SERVER=QA2ONHYK7VWHRY2;DATABASE=library"cn.Open cn_strsql_str = "select * from 图书基本信息表"rs.Open sql_str, cnWhile Not rs.EOFIf Text10.Text = Trim(rs(0) ThenText1.Text = rs(0)Text2.Text = rs(1)Text3.Text = rs(2)Text4.Text = rs(3)Text5.Text = rs(4)Text6.Text = rs(5)Text7.Text = rs(6)Text8.Text = rs(7)Text9.Text = rs(8)flag = TrueExit SubElsers.MoveNextflag = FalseEnd IfWendIf flag = False ThenMsgBox "没有找到此图书的信息,请确认所输入正确的图书号!", vbCritical + vbOKOnly, "错误"rs.CloseEnd IfEnd Sub3.2.2图书借阅管理3.2.2.1添加修改删除借阅信息添加修改删除借阅信息图设计过程:选择添加修改删除借阅信息,在相应的栏目填入或选择相应的内容,点击相应的按钮可以实现添加修改删除借阅信息。设计代码:Dim rs As New ADODB.RecordsetPrivate Sub Command1_Click()rs.Deleters.AddNewrs("条码号") = Trim(Text1.Text)rs("读者编号") = Trim(Text2.Text)rs("书籍名称") = Trim(Text3.Text)rs("图书作者") = Trim(Text4.Text)rs("规定天数") = Trim(Text5.Text)rs("借出日期") = Trim(Text6.Text)rs("还书日期") = Trim(Text7.Text)rs("实还日期") = Trim(Text8.Text)rs("超出天数") = Trim(Text9.Text)rs.UpdateMsgBox "修改信息成功!", vbExclamation + vbOKOnly, "提示"End SubPrivate Sub Command2_Click()rs.Deleters.UpdateMsgBox "删除成功!", vbExclamation + vbOKOnly, "提示"End SubPrivate Sub Command3_Click(Index As Integer)Select Case IndexCase 0rs.MoveFirstCase 1rs.MovePreviousIf rs.BOF Thenrs.MoveFirstMsgBox "已经是第一条记录", vbExclamation, "提示"End IfCase 2rs.MoveNextIf rs.EOF Thenrs.MoveLastMsgBox "已经是最后一条记录!", vbExclamation, "提示"End IfCase 3rs.MoveLastEnd SelectText1.Text = rs(0)Text2.Text = rs(1)Text3.Text = rs(2)Text4.Text = rs(3)Text5.Text = rs(4)Text6.Text = rs(5)Text7.Text = rs(6)Text8.Text = rs(7)Text9.Text = rs(8)End SubPrivate Sub Command4_Click()If Text1.Text = "" ThenMsgBox "请输入条码号!", vbOKOnly + vbExclamation, "警告"Text1.SetFocusExit SubEnd IfIf Text2.Text = "" ThenMsgBox "请输入读者编号!", vbOKOnly + vbExclamation, "警告"Text2.SetFocusExit SubEnd IfIf Text3.Text = "" ThenMsgBox "请输入书籍名称!", vbOKOnly + vbExclamation, "警告"Text3.SetFocusExit SubEnd IfIf Text4.Text = "" ThenMsgBox "请输入图书作者!", vbOKOnly + vbExclamation, "警告"Text4.SetFocusExit SubEnd IfIf Text5.Text = "" ThenMsgBox "请输入规定天数!", vbOKOnly + vbExclamation, "警告"Text5.SetFocusExit SubEnd IfIf Text6.Text = "" ThenMsgBox "请输入借出日期!", vbOKOnly + vbExclamation, "警告"Text6.SetFocusExit SubEnd IfIf Text7.Text = "" ThenMsgBox "请输入还书日期!", vbOKOnly + vbExclamation, "警告"Text7.SetFocusExit SubEnd IfIf Text8.Text = "" ThenMsgBox "请输入实还日期!", vbOKOnly + vbExclamation, "警告"Text8.SetFocusExit SubEnd IfIf Text9.Text = "" ThenMsgBox "请输入超出天数!", vbOKOnly + vbExclamation, "警告"Text9.SetFocusExit SubEnd IfDim cn As New ADODB.ConnectionDim rs As New ADODB.RecordsetDim flag As BooleanDim cn_str As String, sql_str As Stringcn_str = "DRIVER=SQL SERVER;SERVER=QA2ONHYK7VWHRY2;DATABASE=library"cn.Open cn_strsql_str = "select * from 借阅信息表"rs.Open sql_str, cn, adOpenDynamic, adLockOptimisticrs.AddNewrs("条码号") = Trim(Text1.Text)rs("读者编号") = Trim(Text2.Text)rs("书籍名称") = Trim(Text3.Text)rs("图书作者") = Trim(Text4.Text)rs("规定天数") = Trim(Text5.Text)rs("借出日期") = Trim(Text6.Text)rs("还书日期") = Trim(Text7.Text)rs("实还日期") = Trim(Text8.Text)rs("超出天数") = Trim(Text9.Text)rs.Updaters.CloseMsgBox "添加信息成功!", vbExclamation + vbOKOnly, "提示"End SubPrivate Sub Form_Load()Dim cn As New ADODB.ConnectionDim cn_str As String, sql_str As Stringcn_str = "DRIVER=SQL SERVER;SERVER=QA2ONHYK7VWHRY2;DATABASE=library"cn.Open cn_strsql_str = "select * from 借阅信息表"rs.Open sql_str, cn_str, adOpenDynamic, adLockOptimisticText1.Text = rs(0)Text2.Text = rs(1)Text3.Text = rs(2)Text4.Text = rs(3)Text5.Text = rs(4)Text6.Text = rs(5)Text7.Text = rs(6)Text8.Text = rs(7)Text9.Text = rs(8)End Sub3.2.2.2图书借阅查询设计过程:选择图书借阅查询,在相应的栏目输入要查询的图书号就能查询该图书的借阅信息!设计代码:Private Sub Command1_Click()Dim cn As New ADODB.ConnectionDim rs As New ADODB.RecordsetDim flag As BooleanDim cn_str As String, sql_str As Stringcn_str = "DRIVER=SQL SERVER;SERVER=QA2ONHYK7VWHRY2;DATABASE=library"cn.Open cn_strsql_str = "select * from 借阅信息表"rs.Open sql_str, cnWhile Not rs.EOFIf Text10.Text = Trim(rs(0) ThenText1.Text = rs(0)Text2.Text = rs(1)Text3.Text = rs(2)Text4.Text = rs(3)Text5.Text = rs(4)Text6.Text = rs(5)Text7.Text = rs(6)Text8.Text = rs(7)Text9.Text = rs(8)flag = TrueExit SubElsers.MoveNextflag = FalseEnd IfWendIf flag = False ThenMsgBox "没有找到此图书的信息,请确认所输入正确的图书号!", vbCritical + vbOKOnly, "错误"rs.CloseEnd IfEnd SubPrivate Sub Command2_Click()Unload MeEnd Sub3.2.3读者信息管理 3.2.3.1添加删除修改读者信息 设计过程:选择添加删除修改读者信息,在相应的栏目填入或选择相应的内容,点击相应的按钮可以实现添加删除修改读者信息。设计代码:Dim rs As New ADODB.RecordsetPrivate Sub Command1_Click()rs.Deleters.AddNewrs("读者编号") = Trim(Text1.Text)rs("读者姓名") = Trim(Text2.Text)rs("性别") = Trim(Text3.Text)rs("出生日期") = Trim(Text4.Text)rs("单位") = Trim(Text5.Text)rs("家庭住址") = Trim(Text6.Text)rs("电话") = Trim(Text7.Text)rs("Email") = Trim(Text8.Text)rs("证件类型") = Trim(Text9.Text)rs("证件号码") = Trim(Text10.Text)rs("登记日期") = Trim(Text11.Text)rs("读者级别") = Trim(Text12.Text)rs.UpdateMsgBox "修改信息成功!", vbExclamation + vbOKOnly, "提示"End SubPrivate Sub Command2_Click()rs.DeleteMsgBox "删除成功!", vbExclamation + vbOKOnly, "提示"End SubPrivate Sub Command3_Click(Index As Integer)Select Case IndexCase 0rs.MoveFirstCase 1rs.MovePreviousIf rs.BOF Thenrs.MoveFirstMsgBox "已经是第一条记录", vbExclamation, "提示"End IfCase 2rs.MoveNextIf rs.EOF Thenrs.MoveLastMsgBox "已经是最后一条记录!", vbExclamation, "提示"End IfCase 3rs.MoveLastEnd SelectText1.Text = rs(0)Text2.Text = rs(1)Text3.Text = rs(2)Text4.Text = rs(3)Text5.Text = rs(4)Text6.Text = rs(5)Text7.Text = rs(6)Text8.Text = rs(7)Text9.Text = rs(8)Text10.Text = rs(9)Text11.Text = rs(10)Text12.Text = rs(11)End SubPrivate Sub Command4_Click()If Text1.Text = "" ThenMsgBox "请输入要添加的读者编号!", vbOKOnly + vbExclamation, "警告"Text1.SetFocusExit SubEnd IfIf Text2.Text = "" ThenMsgBox "请输入要添加的读者姓名!", vbOKOnly + vbExclamation, "警告"Text2.SetFocusExit SubEnd IfIf Text3.Text = "" ThenMsgBox "请输入要添加的性别!", vbOKOnly + vbExclamation, "警告"Text3.SetFocusExit SubEnd IfIf Text4.Text = "" ThenMsgBox "请输入出生日期!", vbOKOnly + vbExclamation, "警告"Text4.SetFocusExit SubEnd IfIf Text5.Text = "" ThenMsgBox "请输入单位!", vbOKOnly + vbExclamation, "警告"Text5.SetFocusExit SubEnd IfIf Text6.Text = "" ThenMsgBox "请输入家庭住址!", vbOKOnly + vbExclamation, "警告"Text6.SetFocusExit SubEnd IfIf Text7.Text = "" ThenMsgBox "请输入要添加电话!", vbOKOnly + vb