📄 frm_books.frm
字号:
ElseIf IsNumeric(txt_author3.Text) Then
MsgBox ("Enter the valid author name."), vbInformation, "Invalid information"
ElseIf Not IsNumeric(txt_bookid.Text) Then
MsgBox ("Bookid must be numeric."), vbInformation, "Invalid information"
ElseIf Not IsNumeric(txt_pages.Text) Then
MsgBox ("Enter page as in form of string of digits."), vbInformation, "Invalid information"
ElseIf Not IsNumeric(txt_price.Text) Then
MsgBox ("Price must be digit form,enter valid price."), vbInformation, "Invalid information"
ElseIf IsNumeric(txt_edition.Text) Then
MsgBox ("Enter the valid string for edition."), vbInformation, "Invalid information"
ElseIf IsNumeric(txt_subject.Text) Then
MsgBox ("Subject name can not be Numeric."), vbInformation, "Invalid information"
ElseIf Not IsNumeric(txt_totalno.Text) Then
MsgBox ("Total no of copy must be Numeric."), vbInformation, "Invalid information"
ElseIf Not IsNumeric(txt_avano.Text) Then
MsgBox ("Available no of copy must be Numeric."), vbInformation, "Invalid information"
ElseIf Not IsNumeric(txt_issue.Text) Then
MsgBox ("Issue no of copy must be Numeric."), vbInformation, "Invalid information"
ElseIf Not (CDbl(txt_totalno.Text) = (CDbl(txt_avano.Text) + CDbl(txt_issue.Text))) Then
MsgBox ("Possibly incorrect data in copy info. frame."), vbInformation, "Invalid information"
Else
status = True
End If
cheak = status
End Function
'subroutin for setting text box mode
Private Sub setlock(val As Boolean)
txt_title.Locked = val
txt_publication.Locked = val
txt_author1.Locked = val
txt_author2.Locked = val
txt_author3.Locked = val
txt_price.Locked = val
txt_pages.Locked = val
txt_subject.Locked = val
txt_isbn.Locked = val
txt_totalno.Locked = val
txt_edition.Locked = val
txt_bookid.Locked = val
txt_issue.Locked = val
txt_avano.Locked = val
End Sub
'make blank the text box
Private Sub clear()
txt_title.Text = ""
txt_publication.Text = ""
txt_author1.Text = ""
txt_author2.Text = ""
txt_author3.Text = ""
txt_price.Text = ""
txt_subject.Text = ""
txt_isbn.Text = ""
txt_pages.Text = ""
txt_totalno.Text = ""
txt_avano.Text = ""
txt_issue.Text = ""
txt_edition.Text = ""
txt_bookid.Text = ""
'set focus to fiRSt textbox
txt_title.SetFocus
End Sub
Private Sub showdata()
If Bookrecord.EOF = False And Bookrecord.BOF = False Then
txt_author1.Text = Bookrecord.Fields(0)
txt_author2.Text = Bookrecord.Fields(1)
txt_author3.Text = Bookrecord.Fields(2)
txt_avano.Text = Bookrecord.Fields(3)
txt_bookid.Text = Bookrecord.Fields(4)
txt_edition.Text = Bookrecord.Fields(5)
txt_isbn.Text = Bookrecord.Fields(6)
txt_issue.Text = Bookrecord.Fields(7)
txt_pages.Text = Bookrecord.Fields(8)
txt_price.Text = Bookrecord.Fields(9)
txt_publication.Text = Bookrecord.Fields(10)
txt_subject.Text = Bookrecord.Fields(11)
txt_title.Text = Bookrecord.Fields(12)
txt_totalno.Text = Bookrecord.Fields(13)
End If
End Sub
Private Sub setbutton(val As Boolean)
cmdFirst.Enabled = val
cmdPrevious.Enabled = val
cmdNext.Enabled = val
cmdLast.Enabled = val
cmd_delete.Enabled = val
cmd_edit.Enabled = val
cmd_new.Enabled = val
cmd_reset.Enabled = Not val
cmd_save.Enabled = Not val
cmdCancel.Enabled = Not val
End Sub
Private Sub cmd_close_Click()
Unload Me
'Load Frm_welcome
'Frm_welcome.Show
End Sub
Private Sub cmd_detail_Click()
Load Frm_bookd
Frm_bookd.Show
Unload Me
End Sub
Private Sub cmdCancel_Click()
On erro GoTo cancelerr
'disablink control
setlock (True)
lblStatus.Caption = " Cancel."
If Bookrecord.BOF And Bookrecord.EOF Then
GoTo newproc
Else
Bookrecord.MoveFirst
Call showdata
End If
newproc:
txt_title.SetFocus
Call setbutton(True)
Exit Sub
cancelerr:
MsgBox Err.Description
End Sub
Private Sub cmdFirst_Click()
On Error GoTo GoFirstError
Bookrecord.MoveFirst
lblStatus.Caption = " << Move"
'show thw current data record
Call showdata
Exit Sub
GoFirstError:
MsgBox Err.Description
End Sub
Private Sub cmdLast_Click()
On Error GoTo GoLastError
lblStatus.Caption = " Move >>"
Bookrecord.MoveLast
'show thw current data record
Call showdata
Exit Sub
GoLastError:
MsgBox Err.Description
End Sub
Private Sub cmdNext_Click()
On Error GoTo GoNextError
lblStatus.Caption = " Move >"
If Not Bookrecord.EOF Then Bookrecord.MoveNext
If Bookrecord.EOF And Bookrecord.RecordCount > 0 Then
Beep
'moved off the end so go back
Bookrecord.MoveLast
End If
'show thw current data record
Call showdata
Exit Sub
GoNextError:
MsgBox Err.Description
End Sub
Private Sub cmdPrevious_Click()
On Error GoTo GoPrevError
lblStatus.Caption = " < Move"
If Not Bookrecord.BOF Then Bookrecord.MovePrevious
If Bookrecord.BOF And Bookrecord.RecordCount > 0 Then
Beep
'moved off the end so go back
Bookrecord.MovePrevious
End If
'show thw current data record
Call showdata
Exit Sub
GoPrevError:
If Err.Number = 3021 Then
MsgBox ("This is first Record."), vbInformation, "First record"
ElseIf Err.Number <> 0 Then
MsgBox Err.Number & Err.Description
End If
End Sub
Private Sub Form_Load()
On Error GoTo errlable
If (view = 1) Then
Me.Top = 50
Me.Left = 50
ElseIf (view = 2) Then
Me.Top = 700
Me.Left = (Screen.Width - Me.Width) / 2
End If
Set Bookconnection = New ADODB.Connection
Bookconnection.CursorLocation = adUseClient
Bookconnection.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & App.Path & "\Database\Library.mdb;Jet OLEDB:Database Password=Library;"
slct = "select Author1,Author2,Author3,Avano,Bookid,Edition,ISBNNumber,Issno,Pages,Price,Publication,Subject,Title,Totalno from Book Order by Bookid"
Set Bookrecord = New ADODB.Recordset
Bookrecord.Open slct, Bookconnection, adOpenStatic, adLockOptimistic
'show current record
Call showdata
'disable buttons
pos = Bookrecord.AbsolutePosition
cmd_reset.Enabled = False
cmd_save.Enabled = False
cmdCancel.Enabled = False
Exit Sub
errlable:
MsgBox Err.Number & Err.Description
End Sub
Private Sub cmd_delete_Click()
On erro GoTo lable
Beep
If MsgBox("Execution of command will delete current Datarecord,Are you sure you wan't to delete Datarecord ?", vbYesNo + vbExclamation, "Confirm Delete") = vbYes Then
str = "DELETE FROM Book WHERE "
str = str & "Bookid = "
str = str & CDbl(txt_bookid.Text)
Bookconnection.Execute str
Bookrecord.Requery
MsgBox "Record deleted sucessfully.", vbinformayion, "Delete"
If Bookrecord.BOF And Bookrecord.EOF Then
Call clear
MsgBox ("The previous record was last record,Now no record left."), vbInformation, "Last record"
cmd_delete.Enabled = False
Else
Bookrecord.MoveNext
If Bookrecord.EOF Then
Bookrecord.MoveLast
End If
Call showdata
End If
'message for status of mode
lblStatus.Caption = "Record deleted."
End If
Exit Sub
lable:
MsgBox Err.Number & Err.Description
End Sub
Private Sub cmd_edit_Click()
On Error GoTo lable
'Make all entries in input mode
Call setlock(False)
saveflag = False
'message for status of mode
lblStatus.Caption = " Edit record"
Call setbutton(False)
' cmdcancel.Enabled = False
'set focus
txt_title.SetFocus
Exit Sub
lable:
MsgBox Err.Description
End Sub
Private Sub cmd_new_Click()
On Error GoTo lable
'Make all entries in input mode enable
Call setlock(False)
'clear the text field
Call clear
saveflag = True
lblStatus.Caption = " Add new record."
Call setbutton(False)
Exit Sub
lable:
'Error handling statement
MsgBox Err.Description
End Sub
Private Sub cmd_reset_Click()
'make all to input mode enable
Call setlock(False)
Call clear
End Sub
Private Sub cmd_save_Click()
On Error GoTo lable
'Make all entries in input mode enable
Call setlock(False)
'cheaking for validity condition
If cheak = True Then
If txt_author2.Text = "" Then
txt_author2.Text = "None"
End If
If txt_author3.Text = "" Then
txt_author3.Text = "None"
End If
pos = Bookrecord.AbsolutePosition
'saving new record
If saveflag = True Then
str = "INSERT INTO Book"
str = str & "(Author1, Author2, Author3, Avano, Bookid, Edition, ISBNNumber, Issno, Pages, Price, Publication, Subject, Title, Totalno) "
str = str & "VALUES('" & Trim(txt_author1.Text) & "', "
str = str & "'" & Trim(txt_author2.Text) & "', "
str = str & "'" & Trim(txt_author3.Text) & "', "
str = str & CDbl(txt_avano.Text) & ", "
str = str & CDbl(txt_bookid.Text) & ", "
str = str & "'" & Trim(txt_edition.Text) & "', "
str = str & "'" & Trim(txt_isbn.Text) & "', "
str = str & CDbl(txt_issue.Text) & ", "
str = str & CDbl(txt_pages.Text) & ", "
str = str & CDbl(txt_price.Text) & ", "
str = str & "'" & Trim(txt_publication.Text) & "', "
str = str & "'" & Trim(txt_subject.Text) & "', "
str = str & "'" & Trim(txt_title.Text) & "', "
str = str & CDbl(txt_totalno.Text) & ")"
Bookconnection.Execute str
Else 'for editing the record
str = "UPDATE Book SET "
str = str & "Author1='" & Trim(txt_author1.Text) & "',"
str = str & "Author2='" & Trim(txt_author2.Text) & "',"
str = str & "Author3='" & Trim(txt_author3.Text) & "',"
str = str & "Avano=" & CDbl(txt_avano.Text) & ","
str = str & "Bookid=" & CDbl(txt_bookid.Text) & ","
str = str & "Edition='" & Trim(txt_edition.Text) & "',"
str = str & "ISBNNumber='" & Trim(txt_isbn.Text) & "',"
str = str & "Issno=" & CDbl(txt_issue.Text) & ","
str = str & "Pages=" & CDbl(txt_pages.Text) & ","
str = str & "Price=" & CDbl(txt_price.Text) & ","
str = str & "Publication='" & Trim(txt_publication.Text) & "',"
str = str & "Subject='" & Trim(txt_subject.Text) & "',"
str = str & "Title='" & Trim(txt_title.Text) & "',"
str = str & "Totalno=" & CDbl(txt_totalno.Text)
str = str & " WHERE Bookid=" & CDbl(txt_bookid.Text)
Bookconnection.Execute str
End If
'Make all entries input mode disable
Call setlock(True)
Bookrecord.Requery
Bookrecord.Move (pos - 1)
'show thw current data record
Call showdata
'message for status of mode
lblStatus.Caption = " New record Saved."
MsgBox ("Record has been suceefully saved."), vbInformation, "Saving Record"
Call setbutton(True)
End If
Exit Sub
lable:
If Err.Number = -2147467259 Then
MsgBox ("BookID already exist,please enter anothe ID."), vbCritical, "BookID exist"
txt_bookid.SetFocus
ElseIf Err.Number <> 0 Then
MsgBox Err.Number & Err.Description
End If
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -