?? borrow.frm
字號:
If Text10 = "" Then
MsgBox "請輸入書號!", 16
Exit Sub
End If
If Text9 = "" Then
MsgBox "請輸入學號", 16
Exit Sub
End If
ssql = "select * from S_no where 學號='" & Text9.Text & "'" '查詢學號是否存在,不存在則退出過程
Set user_me = cn.Execute(ssql)
If user_me.EOF Then
MsgBox "學號不存在,無借書權限", 16
Exit Sub
End If
ssql = "select * from libary where 書號='" & Text10.Text & "'" '查詢書是否已借出
Set user_me = cn.Execute(ssql)
If Not user_me.EOF Then
MsgBox "此書已借出,請確認輸入是否正確", 16
Exit Sub
End If
ssql = "select * from S_book where 書號='" & Text10.Text & "'" '查詢書號是否存在
Set user_me = cn.Execute(ssql) '用行集判斷書號是否存在,沒有用recordset記錄集
If user_me.EOF Then
MsgBox "書號不存在,請確認是否輸入正確!", 16
Exit Sub
End If
Data1.Recordset.AddNew
bflag = True
'把借書操作寫入數據庫
Text1.Text = Text9.Text
Text2.Text = Text10.Text
Text3.Text = Text11.Text
Text4.Text = Text12.Text
Text5.Text = Text14.Text
Text6.Text = Text15.Text
'借書成功后修改該書的在館狀態{
ssql = "update S_book set 狀態='借出' where 書號='" & Text10.Text & "'" '刪除一列把 add 換成 drop
cn.Execute (ssql) '}
Dim itmx As ListItem
Form1.ListView1.ListItems.Clear
Data1.Recordset.FindFirst "學號='" & Text1.Text & "'" '通過text7,text8來傳遞查詢值
Do While Not Data1.Recordset.NoMatch
'Do While Not user_me.EOF
Set itmx = Form1.ListView1.ListItems.Add(, , Text1) '顯示該學號以往所借書籍
itmx.SubItems(1) = Text2
itmx.SubItems(2) = Text3
itmx.SubItems(3) = Text4
itmx.SubItems(4) = Text5
itmx.SubItems(5) = Text6
itmx.SubItems(6) = "已借"
Data1.Recordset.FindNext "學號='" & Text1.Text & "'"
Loop
If backup = True Then
Label3.Caption = "學號:"
Label4.Caption = "書號:"
Text14.Visible = False
Text15.Visible = False
Text9.Visible = True
Text10.Visible = True
Command3.Caption = "備注"
backup = False
End If
Exit Sub
wrong:
MsgBox Err.Description, 16
End Sub
Private Sub Command1_Click()
rc = MsgBox("確定要取消借書操作嗎?", 49)
If rc = vbOK Then
If bflag = True Then
Data1.Recordset.CancelUpdate
End If
Else
Exit Sub
End If
Unload Me
End Sub
Private Sub Bak_Click()
Dim Accessday As Boolean
Accessday = False
If Text7 = "" Then
MsgBox "請輸入書號", 16
Exit Sub
End If
If Text7 = "" Then
MsgBox "請確認書號", 16
Exit Sub
End If
If Text7.Text = Text8.Text Then
ssql = "select * from S_book where 書號='" & Text7.Text & "'" '查詢書號是否存在
Set user_me = cn.Execute(ssql)
If Not user_me.EOF Then
Data1.Recordset.FindFirst "書號='" & Text7.Text & "'" '查詢是否存在借書記錄
If Not Data1.Recordset.NoMatch Then
Text13 = Text1
'判斷還書是否逾期!{
Dim de As Date
de = Text3
If Year(Now()) = Year(de) Then
If Month(Now()) - Month(de) > 2 Then
MsgBox "已超過還書日期期" & Month(Now()) - Month(de) & "個月!", 48
Accessday = True
End If
If Month(Now()) - Month(de) = 2 And Day(Now()) > Day(de) Then
MsgBox "已超過還書日期" & Day(Now()) - Day(de) & "天!", 48
Accessday = True
End If
Else
If Year(Now()) > Year(de) Then
If Month(Now()) + 12 - Month(de) > 2 Then
MsgBox "已超過還書日期" & Month(Now()) + 12 - Month(de) & "個月!", 48
Accessday = True
End If
If Month(Now()) + 12 - Month(de) = 2 And Day(Now()) > Day(de) Then
MsgBox "已超過還書日期" & Day(Now()) - Day(de) & "天!", 48
Accessday = True
End If
Else
MsgBox "請確認系統時間是否正確!"
End If
End If '}
If Not Accessday Then
Data1.Recordset.Delete '找到后若沒有逾期便刪除借書記錄
ssql = "update S_book set 狀態='在館' where 書號='" & Text7.Text & "'" '刪除一列把 add 換成 drop
cn.Execute (ssql) '刪除成功后修改該書的在館狀態
Else
rc = MsgBox("確定要歸還已逾期的書籍嗎?", 49)
If rc = vbOK Then
Data1.Recordset.Delete
ssql = "update S_book set 狀態='在館' where 書號='" & Text7.Text & "'" '刪除一列把 add 換成 drop
cn.Execute (ssql) '刪除成功后修改該書的在館狀態
End If
End If
Else
MsgBox "無當前記錄", 16 '借書記錄不存在退出該過程
Exit Sub
End If
Else
MsgBox "書號不存在,請確認是否輸入正確!"
Exit Sub
End If
Else
MsgBox "書號不一致,請重試!", 48
Exit Sub
End If
'在listview1中顯示該學號以往的借書記錄
Form1.ListView1.ListItems.Clear
Data1.Recordset.FindFirst "學號='" & Text13.Text & "'" '查詢還書者所借的所有書并予以顯示{
Dim itmx As ListItem
Do While Not Data1.Recordset.NoMatch
Set itmx = Form1.ListView1.ListItems.Add(, , Text1)
itmx.SubItems(1) = Text2
itmx.SubItems(2) = Text3
itmx.SubItems(3) = Text4
itmx.SubItems(4) = Text5
itmx.SubItems(5) = Text6
itmx.SubItems(6) = "已借"
Data1.Recordset.FindNext "學號='" & Text13.Text & "'"
Loop '}
End Sub
'續借其實是跟還書的過程很相似,還書是刪除數據,而續借只是修改還書日期
Private Sub Command2_Click()
Dim Accessday As Boolean
Accessday = False
If Text7 = "" Then
MsgBox "請輸入書號", 16
Exit Sub
End If
If Text7 = "" Then
MsgBox "請確認書號", 16
Exit Sub
End If
If Text7.Text = Text8.Text Then
ssql = "select * from S_book where 書號='" & Text7.Text & "'" '查詢書號是否存在
Set user_me = cn.Execute(ssql)
If Not user_me.EOF Then
Data1.Recordset.FindFirst "書號='" & Text7.Text & "'" '查詢是否存在借書記錄
If Not Data1.Recordset.NoMatch Then
Text13 = Text1
'判斷還書是否逾期!{
Dim de As Date
de = Text3
If Year(Now()) = Year(de) Then
If Month(Now()) - Month(de) > 2 Then
MsgBox "已超過還書日期期" & Month(Now()) - Month(de) & "個月!", 48
Accessday = True
End If
If Month(Now()) - Month(de) = 2 And Day(Now()) > Day(de) Then
MsgBox "已超過還書日期" & Day(Now()) - Day(de) & "天!", 48
Accessday = True
End If
Else
If Year(Now()) > Year(de) Then
If Month(Now()) + 12 - Month(de) > 2 Then
MsgBox "已超過還書日期" & Month(Now()) + 12 - Month(de) & "個月!", 48
Accessday = True
End If
If Month(Now()) + 12 - Month(de) = 2 And Day(Now()) > Day(de) Then
MsgBox "已超過還書日期" & Day(Now()) - Day(de) & "天!", 48
Accessday = True
End If
Else
MsgBox "請確認系統時間是否正確!"
End If
End If '}
If Not Accessday Then
'找到后若沒有逾期便刪除借書記錄
ssql = "update libary set 還書日期='" & Text12 & "' where 書號='" & Text7.Text & "'" '刪除一列把 add 換成 drop
cn.Execute (ssql) '刪除成功后修改該書的在館狀態
Else
rc = MsgBox("確定要歸還已逾期的書籍嗎?", 49)
If rc = vbOK Then
Data1.Recordset.Delete
ssql = "update S_book set 狀態='在館' where 書號='" & Text7.Text & "'" '刪除一列把 add 換成 drop
cn.Execute (ssql) '刪除成功后修改該書的在館狀態
End If
End If
Else
MsgBox "無當前記錄", 16 '借書記錄不存在退出該過程
Exit Sub
End If
Else
MsgBox "書號不存在,請確認是否輸入正確!"
Exit Sub
End If
Else
MsgBox "書號不一致,請重試!", 48
Exit Sub
End If
'在listview1中顯示該學號以往的借書記錄
Form1.ListView1.ListItems.Clear
Data1.Recordset.FindFirst "學號='" & Text13.Text & "'" '查詢還書者所借的所有書并予以顯示{
Dim itmx As ListItem
Do While Not Data1.Recordset.NoMatch
Set itmx = Form1.ListView1.ListItems.Add(, , Text1)
itmx.SubItems(1) = Text2
itmx.SubItems(2) = Text3
itmx.SubItems(3) = Text4
itmx.SubItems(4) = Text5
itmx.SubItems(5) = Text6
itmx.SubItems(6) = "已借"
Data1.Recordset.FindNext "學號='" & Text13.Text & "'"
Loop '}
End Sub
Private Sub Command3_Click()
'判斷是否輸入備注
If Command3.Caption = "備注" Then
Label3.Caption = "書名:"
Label4.Caption = "介紹:"
Text9.Visible = False
Text10.Visible = False
Text14.Visible = True
Text15.Visible = True
Command3.Caption = "返回"
backup = True
Else
Label3.Caption = "學號:"
Label4.Caption = "書號:"
Text14.Visible = False
Text15.Visible = False
Text9.Visible = True
Text10.Visible = True
Command3.Caption = "備注"
backup = False
End If
End Sub
Private Sub Command4_Click()
Unload Me
End Sub
Private Sub Form_Load()
Me.Icon = Form1.Icon
Left = (Screen.Width - Width) \ 2
Top = (Screen.Height - Height) \ 2
cn.Open "Provider=Microsoft.Jet.OLEDB.3.51;Persist Security Info=False;Data Source=libary.mdb" '打開數據庫
bflag = False
backup = False
End Sub
Private Sub Form_Unload(cancel As Integer)
cn.Close
End Sub
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -