📄 frmutterbook.vb
字号:
Me.GroupBox1.ResumeLayout(False)
Me.GroupBox3.ResumeLayout(False)
CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).EndInit()
Me.GroupBox2.ResumeLayout(False)
Me.GroupBox4.ResumeLayout(False)
Me.TabPage2.ResumeLayout(False)
Me.GroupBox5.ResumeLayout(False)
Me.GroupBox7.ResumeLayout(False)
CType(Me.DataGrid2, System.ComponentModel.ISupportInitialize).EndInit()
Me.TabPage3.ResumeLayout(False)
Me.GroupBox6.ResumeLayout(False)
Me.GroupBox8.ResumeLayout(False)
CType(Me.DataGrid3, System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)
End Sub
#End Region
Public sqlstr As String
Public MyDS As DataSet
Public num As Double
Private Sub TextBox1_KeyPress(ByVal sender As Object, _
ByVal e As System.Windows.Forms.KeyPressEventArgs) _
Handles TextBox1.KeyPress
If e.KeyChar = Chr(13) Then
If Trim(Me.TextBox1.Text) <> "" Then
Dim type As String
sqlstr = "SELECT Name,Authors,Publisher FROM BookInfo" & _
" WHERE ISBN='" & Trim(Me.TextBox1.Text) & "'"
MyDS = New DataSet()
MyDS.Clear()
MyDS = GetDataFromDB(sqlstr)
If Not MyDS Is Nothing Then
lbBookName.Text = MyDS.Tables(0).Rows(0)("Name")
lbAuthors.Text = MyDS.Tables(0).Rows(0)("Authors")
lbPublisher.Text = MyDS.Tables(0).Rows(0)("Publisher")
type = BorrowType(Me.TextBox1.Text).Trim
num = BorrowDates(type)
lbReturnDates.Text = CDate(Now.AddDays(num)).ToLongDateString
btnBorrow.Enabled = True
Else
MsgBox("没有该图书,请重新输入图书的ISBN。", _
MsgBoxStyle.OKOnly + MsgBoxStyle.Critical, "查无此书")
Exit Sub
End If
End If
End If
End Sub
Private Sub btnBorrow_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnBorrow.Click
If Trim(Me.TextBox2.Text) <> "" Then
Dim Regedited, Logout As Boolean
Dim finesum As Double
sqlstr = "SELECT Regedit,Logout,FineSum FROM StudentInfo " & _
"WHERE ID='" & Trim(Me.TextBox2.Text) & "'"
MyDS = New DataSet()
MyDS.Clear()
MyDS = GetDataFromDB(sqlstr)
If Not MyDS Is Nothing Then
Regedited = CBool(MyDS.Tables(0).Rows(0)("Regedit"))
Logout = CBool(MyDS.Tables(0).Rows(0)("LogOut"))
finesum = Val(MyDS.Tables(0).Rows(0)("FineSum"))
If Regedited = False Then
MsgBox("还没有注册,不能借阅图书,请先注册。", _
MsgBoxStyle.OKOnly + MsgBoxStyle.Critical, "借阅失败")
Exit Sub
End If
If Logout = True Then
MsgBox("被暂时取消借阅资格。", _
MsgBoxStyle.OKOnly + MsgBoxStyle.Critical, "借阅失败")
Exit Sub
End If
If finesum > 0 Then
MsgBox("尚有罚款未交,请先交纳罚款。", _
MsgBoxStyle.OKOnly + MsgBoxStyle.Critical, "借阅失败")
Exit Sub
End If
Dim rd As Date
rd = CDate(lbReturnDates.Text)
Dim name As String = Trim(lbBookName.Text)
Dim num As Integer, HasBorrowed As Boolean
Dim tempDS As New DataSet()
sqlstr = "SELECT Numbers FROM LendInfo WHERE " & _
"ISBN='" & TextBox1.Text.Trim & "' AND ID='" & TextBox2.Text.Trim & "'"
tempDS.Clear()
tempDS = GetDataFromDB(sqlstr)
If Not tempDS Is Nothing Then
HasBorrowed = True
num = CInt(tempDS.Tables(0).Rows(0)("Numbers"))
sqlstr = "UPDATE LendInfo SET Numbers='" & num + 1 & "'" & _
"WHERE ISBN='" & TextBox1.Text.Trim & "' AND ID='" & TextBox2.Text.Trim & "'"
Else
HasBorrowed = False
sqlstr = "INSERT INTO LendInfo (ID,ISBN,Name,LendDate," & _
"ReturnDate,Status,ReNew,Numbers ) VALUES " & _
"('" & Trim(Me.TextBox2.Text) & "','" & Trim(Me.TextBox1.Text) & "'," & _
"'" & name & "','" & Trim(Now.ToShortDateString) & "'," & _
"'" & rd & "','正常借阅',0,1)"
End If
UpdateDataBase(sqlstr)
LstBorrowInfo(Me.TextBox2.Text.Trim, Me.DataGrid1)
btnBorrow.Enabled = False
Dim num1, num2 As Integer
sqlstr = "SELECT LendTimes ,LendBooks FROM StudentInfo " & _
"WHERE ID='" & Trim(Me.TextBox2.Text) & "'"
MyDS = New DataSet()
MyDS.Clear()
MyDS = GetDataFromDB(sqlstr)
If MyDS.Tables(0).Rows.Count > 0 Then
num1 = CInt(Val(MyDS.Tables(0).Rows(0)("LendTimes"))) + 1
num2 = CInt(Val(MyDS.Tables(0).Rows(0)("LendBooks"))) + 1
End If
sqlstr = "UPDATE StudentInfo SET LendTimes=" & _
" '" & num1 & "',LendBooks='" & num2 & "' WHERE ID='" & _
Trim(Me.TextBox2.Text) & "'"
UpdateDataBase(sqlstr)
End If
Else
MsgBox("没有该图书,请重新输入图书的ISBN。", _
MsgBoxStyle.OKOnly + MsgBoxStyle.Critical, "查无此书")
End If
End Sub
Public Sub LstBorrowInfo(ByVal id As String, ByVal dg As DataGrid)
sqlstr = "SELECT ID AS 学号,ISBN AS ISBN, Name AS 书名, " & _
"LendDate AS 借书日期,ReturnDate AS 还书日期,Status AS " & _
"当前状态,ReNew AS 续借 ,Numbers AS 借阅数量 FROM LendInfo WHERE ID='" & Trim(id) & "'"
MyDS = New DataSet()
MyDS = GetDataFromDB(sqlstr)
If MyDS Is Nothing Then
dg.CaptionText = "没有借阅记录"
Exit Sub
End If
dg.DataSource = MyDS.Tables(0).DefaultView
dg.CaptionText = "共有 " & MyDS.Tables(0).Rows.Count & " 条记录"
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Dim isbn, id As String
id = Trim(Me.TextBox3.Text)
isbn = Trim(Me.TextBox4.Text)
If id = "" And isbn = "" Then
Exit Sub
End If
Dim rn As Boolean
Dim Rt As Date
sqlstr = "SELECT ReNew,ReturnDate FROM LendInfo " & _
" WHERE ID='" & id & "' AND ISBN='" & isbn & "'"
MyDS = New DataSet()
MyDS.Clear()
MyDS = GetDataFromDB(sqlstr)
If Not MyDS Is Nothing Then
rn = CBool(MyDS.Tables(0).Rows(0)("ReNew"))
Rt = CDate(MyDS.Tables(0).Rows(0)("ReturnDate"))
End If
If rn = True Then
MsgBox("该书已经续借了。此次续借失败。", MsgBoxStyle.OKOnly + _
MsgBoxStyle.Critical, "续借失败")
Exit Sub
End If
If DateDiff(DateInterval.Day, Now.Today, Rt) < 0 Then
MsgBox("该书已经过期了,不能续借,此次续借失败。", _
MsgBoxStyle.OKOnly + MsgBoxStyle.Critical, "续借失败")
Exit Sub
End If
If DateDiff(DateInterval.Day, Rt, Now.Today) < 10 Then
MsgBox("借阅时间太短,还不能续借,此次续借失败。", _
MsgBoxStyle.OKOnly + MsgBoxStyle.Critical, "续借失败")
Exit Sub
End If
Dim type As String
Dim num As Integer
type = BorrowType(Me.TextBox4.Text).Trim
num = BorrowDates(type)
sqlstr = "UPDATE LendInfo SET ReNew=1,ReturnDate=" & _
"'" & CDate(Now.AddDays(num).ToLongDateString) & "' " & _
"WHERE ID='" & id & "' AND ISBN='" & isbn & "'"
UpdateDataBase(sqlstr)
LstBorrowInfo(Me.TextBox3.Text, Me.DataGrid2)
End Sub
Public Function BorrowDates(ByVal type As String) As Integer
sqlstr = "SELECT BorrowDays FROM BorrowType WHERE Type='" & type & "'"
MyDS = Nothing
MyDS = New DataSet()
MyDS.Clear()
MyDS = GetDataFromDB(sqlstr)
If Not MyDS Is Nothing Then
num = CInt(MyDS.Tables(0).Rows(0)("BorrowDays"))
Return num
Else
Exit Function
End If
End Function
Public Function BorrowType(ByVal isbn As String) As String
sqlstr = "SELECT Type FROM BookInfo WHERE ISBN='" & isbn.Trim & "'"
MyDS = New DataSet()
MyDS.Clear()
MyDS = GetDataFromDB(sqlstr)
If MyDS.Tables(0).Rows.Count > 0 Then
Return Trim(MyDS.Tables(0).Rows(0)("Type"))
End If
End Function
Private Sub TextBox5_KeyPress(ByVal sender As Object, _
ByVal e As System.Windows.Forms.KeyPressEventArgs) _
Handles TextBox5.KeyPress
If e.KeyChar = Chr(13) Then
If Trim(Me.TextBox5.Text) <> "" Then
Dim type As String
sqlstr = "SELECT * FROM LendInfo WHERE ISBN='" & Trim(Me.TextBox5.Text) & "'"
MyDS = New DataSet()
MyDS.Clear()
MyDS = GetDataFromDB(sqlstr)
Me.DataGrid3.DataSource = MyDS.Tables(0).DefaultView
If MyDS.Tables(0).Rows.Count > 0 Then
lbsID.Text = MyDS.Tables(0).Rows(0)("ID")
lbBDate.Text = MyDS.Tables(0).Rows(0)("LendDate")
lbReDate.Text = MyDS.Tables(0).Rows(0)("ReturnDate")
lbBName.Text = MyDS.Tables(0).Rows(0)("Name")
num = DateDiff(DateInterval.Day, CDate(lbReDate.Text), Now.Today)
If num > 0 Then
lbDays.Text = num
sqlstr = "SELECT FineBase,FineMulti,FineFactor FROM BookInfo " & _
"WHERE ISBN='" & Trim(Me.TextBox5.Text) & "'"
Dim ds As New DataSet()
ds.Clear()
ds = GetDataFromDB(sqlstr)
lbFBase.Text = ds.Tables(0).Rows(0)("FineBase")
lbFMulti.Text = ds.Tables(0).Rows(0)("FineMulti")
lbFFactor.Text = ds.Tables(0).Rows(0)("FineFactor")
num = Val(lbFBase.Text) + Val(lbFMulti.Text) * Val(lbFFactor.Text) * num
lbSum.Text = num
End If
Else
Exit Sub
End If
End If
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button2.Click
If lbSum.Text <> "" Then
Dim fnum As Double
sqlstr = "SELECT FineSum FROM StudentInfo WHERE ID='" & Trim(lbsID.Text) & ""
Dim ds As New DataSet()
ds.Clear()
ds = GetDataFromDB(sqlstr)
fnum = Val(ds.Tables(0).Rows(0)("FineSum"))
fnum += Val(lbSum.Text)
sqlstr = "UPDATE StudentInfo SET FineSum='" & fnum & "'" & _
"WHERE ID='" & Trim(lbsID.Text) & "'"
UpdateDataBase(sqlstr)
End If
sqlstr = "DELETE FROM LendInfo WHERE ISBN = '" & TextBox5.Text.Trim & "' AND ID= '" & lbsID.Text.Trim & " '"
If UpdateDataBase(sqlstr) = True Then
MsgBox("恭喜您,您已经成功的还掉了所借阅的书籍,欢迎下次光临!", _
MsgBoxStyle.OKOnly + MsgBoxStyle.Exclamation, "还书成功")
Else
Return
End If
End Sub
Private Sub TextBox3_KeyPress(ByVal sender As Object, _
ByVal e As System.Windows.Forms.KeyPressEventArgs) _
Handles TextBox3.KeyPress
If e.KeyChar = Chr(13) Then
If Trim(Me.TextBox3.Text) <> "" Then
LstBorrowInfo(Me.TextBox3.Text, Me.DataGrid2)
End If
End If
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -