(一)借阅管理窗体模块
P260页
1)public g_ws As Workspace
public g_db As Datebase
public g_rs As Recordset
public g_strSql As String
2)Private Sub Form_Load()
dtpLendDate.Value=Date
dtpLendDateChange.Value=Date
Set g_ws=DBEngine.Workspaces(0)
Set g_db=g_ws.OpenDatabase(App.Path+"\图书馆查询管理系统.mdb")
End Sub
3)Private Sub txtReaderID_KeyPress(KeyAscii As Integer)
If KeyAscii="13"And txtReaderID.Text<>""Then
g_strSql="select*from readerInfo where 读者编号=""&txtReaderID.Text&""
Set g_rs=g_db.OpenRecordset(g_strSql)
If Not g_rs.EOF Then
txtReaderName.Text=g_rs!读者姓名
InitDataGrid(False)
Else
MsgBox"没有该读者信息!",vbOKOnly,"提示"
txtReaderName.text=""
End if
Set g_rs=Nothing
else if KeyAscii="13"And txtReaderID.Text=""Then
MsgBox"请先输入读者编号!",vbOKOnly,"提示"
End if
End Sub
4)Public Function InitDataGrid(bInRenew As Boolean)
Dim strDataSource As String
Dim intCount As Integer
Dim strReaderID As String
If bInRenew=False Then
strReaderID=txtReaderID.Text
Else
strReaderID=txtReaderIDRenew.Text
end if
strDataSource="select lentInfo.读者编号,readerInfo.读者姓名,"_
&"lentInfo.书籍编号,bookInfo.书籍名称,bookType.书籍类别,"_
&"bookInfo.出版社,bookInfo.书籍页码,lentInfo.借书日期,"_
&"lentInfo.还书日期,lentInfo.超出天数,lentInfo.罚款金额,"_
&"from readerInfo,bookInfo,lentInfo,bookType"_
&"where readerInfo.读者编号=lendInfo.读者编号 and"_
&"bookInfo.书籍编号=lendInfo.书籍编号 and lentInfo.读者编号"_
&"='"&strReaderID &"'and bookType.类别代码=bookInfo.类别代码"_
&"and lentInfo.还书日期 is null"
Adoc1.ConnectionString="Provider =Microsoft.Jet.OLEDB.4.0;Data Source"_
&"="App.Path&"\图书馆查询管理系统.mdb;Persist Security Info= False"
Adoc1.CursorLocation=adUseClient
Adoc1.CommandType=adCmdText
Adoc1.RecordSource=strDataSource
Adoc1.Refresh
if bInRenew=False Then
Set dtgrdLendBook.DataSource=Adoc1
dtgrdLendBook.Refresh
lblLendCount.Caption="所借图书:"+CStr(Adoc1.Recordset.RecordCount)
g_strSql="select*from basicSet"
Set g_rs=g_db.OpenRecordset(g_strSql)
intCount=g_rs!借出册数-Adoc1.Recordset.RecordCount
lblRemain.Caption=CStr(intCount)
Else
Set dtgrdLendBookRenew.DataSource=Adoc1
dtgrdLendBookRenew.Refresh
End if
End Function
5)Private Sub txtBookID_KeyPress(KeyAscii As Integer)
If KeyAscii="13"And txtReaderID.Text<>""And txtBookID.Text<>""Then
g_strSql="select bookInfo.书籍名称,bookInfo.书籍价格,"_
&"bookInfo.出版社,bookInfo.书籍页码,"_
&"bookInfo.是否借出,bookType.书籍类别 from bookInfo,"_
&"bookType where 书籍编号=""&txtBookID.Text&""_
&"and bookInfo.类别代码=bookType.类别代码"_
Set g_rs=g_db.OpenRecordset(g_strSql)
If Not g_rs.EOF Then
txtBookName.Text=g_rs!书籍名称
txtBookPrice.Text=g_rs!书籍价格
txtBookLeibie.Text=g_rs!书籍类别
txtBookConcern.Text=g_rs!出版社
txtBookPage.Text=g_rs!书籍页码
If g_rs!是否借出=True Then
MsgBox"该书已借出,请选择其他图书!",vbOKOnly,"提示"
CmdLendBook.Enabled=False
Else
CmdLendBook.Enabled=True
End if
Else
MsgBox"没有该书的信息!",vbOKOnly,"提示"
txtBookName.Text=""
txtBookPrice.Text=""
txtBookLeibie.Text=""
txtBookConcern.Text=""
txtBookPage.Text=""
End if
Set g_rs= Nothing
Else If KeyAscii="13"And txtReaderID.Text=""Then
MsgBox"请输入读者编号!",vbOKOnly,"提示"
Else If KeyAscii="13"And txtReaderID.Text<>""And txtBookID.Text=""Then
MsgBox"请先输入书籍编号!",vbOKOnly,"提示"
End if
End Sub
6)Private Sub cmdLendBook_Click()
if txtReaderID.Text<>""Then
if lblRemain.Caption<>"0" Then
Set g_rs=g_db.OpenRecordset("lentInfo",dbOpenTable)
With g_rs
.AddNew
.Fields("读者编号")=txtReaderID.text
.Fields("书籍编号")=txtBookID.text
.Fields("借书日期")=dtpLendDate.Value
.Update
End with
Set g_rs= Nothing
g_strSql="select*from bookInfo where 书籍编号=""&txtBookID.Text&"""
Set g_rs=g_db.OpenRecordset(g_strSql)
g_rs.Edit
g_rs.Fields("是否借出").Value=True
g_rs.Update
Set g_rs= Nothing
MsgBox"借出完毕!",vbOKOnly,"提示"
txtBookID.Text=""
txtBookName.Text=""
txtBookPrice.Text=""
txtBookLeibie.Text=""
txtBookConcern.Text=""
txtBookPage.Text=""
InitDataGrid(False)
Else
MsgBox"您的书已经借满,不能再借!",vbOKOnly,"提示"
End if
Else
MsgBox"请先输入读者编号!",vbOKOnly,"提示"
End if
End Sub
=======================================================================================================================
7)Private Sub txtReaderIDRenew_KeyPress(KeyAscii As Integer)
If KeyAscii="13"And txtReaderIDRenew.Text<>""Then
g_strSql="select*from readerInfo where 读者编号=""&txtReaderIDRenew.Text&"""
Set g_rs=g_db.OpenRecordset(g_strSql)
If Not g_rs.EOF Then
txtReaderIDRenew.Text=g_rs!读者姓名
InitDataGrid(True)
cmdOK.Enabled=True
Else
MsgBox"没有该读者信息!",vbOKOnly,"提示"
txtReaderNameRenew.Text=""
cmdOK.Enabled=False
End if
Set g_rs= Nothing
Else If KeyAscii="13"And txtReaderIDRenew.Text=""Then
MsgBox"请输入读者编号!",vbOKOnly,"提示"
cmdOK.Enabled=False
End if
End Sub
8)Private Sub cmdOK_Click()
g_strSql="select*from LendInfo where 书籍编号='"&txtBookIDRenew.Text&"'"_
& "and 读者编号="'&txtReaderIDRenew.Text&'"and 借书日期=#"&txtLendDate.Text&"#"
Set g_rs=g_db.OpenRecordset(g_strSql)
g_rs.Edit
g_rs.Fields("借书日期").value=dtpLendDateChange.Value
g_rs.Update
Set g_rs= Nothing
Adoc1.Recordset.Update
MsgBox"续借完毕!",vbOKOnly,"提示"
End Sub
=====================================================================================================================
9)Private Sub txtBookIDReturn_KeyPress(KeyAscii As Integer)
Dim strSQL As String
If KeyAscii="13" And txtBookIDReturn.Text<>""Then
strSQL="select LendInfo.读者编号,ReaderInfo.读者姓名,"_
&"lentInfo.书籍编号,bookInfo.书籍价格,"_
&"bookInfo.书籍名称,bookInfo.书籍页码,lentInfo.借书日期,"_
&"bookType.书籍类别,bookType.借出天数"_
&"from readerInfo,bookInfo,lentInfo,bookType where"_
&"readerInfo.读者编号=lendInfo.读者编号"_
&"and bookInfo.书籍编号=lendInfo.书籍编号 and"_
&"bookInfo.书籍编号='" &txtBookIDReturn.Text&"'"_
&"and bookInfo.类别代码=bookType.类别代码"_
g_strSql=strSQL
Set g_rs=g_db.OpenRecordset(g_strSql)
If Not g_rs.EOF Then
cmdLendBook.Enabled=True
txtBookNameReturn.Text=g_rs!书籍名称
txtBookPriceReturn.Text=g_rs!书籍价格
txtBookLeibieReturn.Text=g_rs!书籍类别
txtBookPageReturn.Text=g_rs!书籍页码
txtReaderIDReturn.Text=g_rs!读者编号
txtReaderNameReturn.Text=g_rs!读者姓名
txtLendDateReturn.Text=g_rs!借书日期
txtDay.Text=g_rs!借书天数
txtReturnDate.Text=Date
txtDate.Text=Date
txtFactDay.Text=CStr(Date-g_rs!借书日期)
If CInt(txtFactDay.Text)-CInt(txtDay.Text)>0 Then
txtDayCount.Text=CStr(CInt(txtFactDay.Text)-CInt(txtReturnDate.Text))
Else
txtDayCount.Text="0"
End if
Set g_rs= Nothing
g_strSql=strSQL
Set g_rs=g_db.OpenRecordset("select*from basicSet")
txtFakuan.Text=g_rs!罚款*CInt(txtDayCount.Text)
Set g_rs= Nothing
cmdReturn.Enable=True
Else
Set g_rs= Nothing
MsgBox"没有该书信息!",vbOKOnly,"提示"
txtBookNameReturn.Text=""
txtBookPriceReturn.Text=""
txtBookLeibieReturn.
评论1