📄 admin_bookmanage.vb
字号:
If objDS.Tables(0).Rows(0)("display") = 0 Then
rbyes.Checked = True
Else
rbno.Checked = True
End If
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Me.Close()
End Sub
Private Sub btOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btOK.Click
can = True
bookname = filter(Trim(tbbookname.Text).ToString)
author = filter(Trim(tbauthor.Text).ToString)
classify = filter(Trim(cbclassify.Text).ToString)
bookconcern = filter(Trim(tbbookconcern.Text).ToString)
amount = filter(Trim(tbamount.Text).ToString)
If bookid = 0 Then
MessageBox.Show("没有选定图书", "错误", MessageBoxButtons.OK, MessageBoxIcon.Information)
can = False
ElseIf islock.Checked = True Then
MessageBox.Show("图书状态锁定", "错误", MessageBoxButtons.OK, MessageBoxIcon.Information)
islock.Focus()
can = False
ElseIf bookname = "" Then
MessageBox.Show("图书名不能为空", "错误", MessageBoxButtons.OK, MessageBoxIcon.Information)
tbbookname.Focus()
can = False
ElseIf author = "" Then
MessageBox.Show("图书作者名不能为空", "错误", MessageBoxButtons.OK, MessageBoxIcon.Information)
tbauthor.Focus()
can = False
ElseIf bookconcern = "" Then
MessageBox.Show("图书出版社不能为空", "错误", MessageBoxButtons.OK, MessageBoxIcon.Information)
tbbookconcern.Focus()
can = False
ElseIf amount = "" Then
MessageBox.Show("图书数量不能为空", "错误", MessageBoxButtons.OK, MessageBoxIcon.Information)
tbamount.Focus()
can = False
ElseIf cbclassify.Text = "" Then
MessageBox.Show("图书分类不能为空", "错误", MessageBoxButtons.OK, MessageBoxIcon.Information)
tbamount.Focus()
can = False
ElseIf Not isnum(amount) Then
MessageBox.Show("图书数量不是数字", "操作错误", MessageBoxButtons.OK, MessageBoxIcon.Information)
tbamount.Text = ""
tbamount.Focus()
can = False
End If
Try
Dim classifyid As Integer, display As Integer = 0
If rbno.Checked = True Then display = 1
sqlstr = "select * from classify where name = '" & classify & "'"
objDS = GetData(sqlstr)
If objDS.Tables(0).Rows.Count > 0 Then
classifyid = objDS.Tables(0).Rows(0)("id")
Else
classifyid = 0
End If
If can Then
sqlstr = "update bookinfo set name='" & bookname & "',author='" & author & "',bookconcern='" & bookconcern & "',amount=" & amount & ",classify=" & classifyid & ",display=" & display & " where id=" & bookid & ""
objDS = GetData(sqlstr)
islock.Checked = True
tbbookname.Text = ""
tbauthor.Text = ""
cbclassify.SelectedIndex = 0
dtpmoditime.Value = Now()
tbbookconcern.Text = ""
tbamount.Text = ""
rbyes.Checked = True
bookid = 0
objDS = GetData(sqlstr2)
LoadData()
MessageBox.Show("数据库更新成功", "操作成功", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
Catch
MessageBox.Show("数据库更新错误", "错误", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Try
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
can = True
If bookid = 0 Then
MessageBox.Show("没有选定图书", "错误", MessageBoxButtons.OK, MessageBoxIcon.Information)
can = False
ElseIf islock.Checked = True Then
MessageBox.Show("图书状态锁定", "错误", MessageBoxButtons.OK, MessageBoxIcon.Information)
islock.Focus()
can = False
End If
If can Then
If MsgBox("确定要删除该图书吗?", MsgBoxStyle.YesNo + MsgBoxStyle.Question, "查询") = MsgBoxResult.Yes Then
Try
sqlstr = "delete from bookinfo where id=" & bookid & ""
UpdateData(sqlstr)
islock.Checked = True
LabelID.Text = ""
tbbookname.Text = ""
tbauthor.Text = ""
tbauthor.Text = ""
tbbookconcern.Text = ""
dtpmoditime.Value = Now()
tbamount.Text = ""
Laberemain.Text = ""
Labelloandegree.Text = ""
bookid = 0
objDS = GetData(sqlstr2)
LoadData()
MessageBox.Show("删除成功", "操作成功", MessageBoxButtons.OK, MessageBoxIcon.Information)
Catch
MessageBox.Show("数据库更新错误", "错误", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Try
End If
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim keyword, bywhat As String, canlist As Boolean = True
keyword = filter(Trim(tbkeyword.Text).ToString)
bywhat = filter(Trim(cbby.Text).ToString)
tbkeyword.Text = keyword
If keyword = "" Then
MessageBox.Show("关键词不能为空", "错误", MessageBoxButtons.OK, MessageBoxIcon.Information)
tbkeyword.Focus()
canlist = False
ElseIf bywhat = "" Then
MessageBox.Show("根据条件不能为空", "错误", MessageBoxButtons.OK, MessageBoxIcon.Information)
cbby.Focus()
canlist = False
End If
If canlist Then '没有错误
bywhat = changewhat(bywhat)
If bywhat <> "classify" Then '不是按分类查询
sqlstr2 = "select * from bookinfo where " & bywhat & " LIKE '%" + keyword + "%'"
objDS = GetData(sqlstr2)
LoadData()
Else '是按分类查询
lblistbooks.Items.Clear()
sqlstr = "select * from classify where name LIKE '%" + keyword + "%'" '从classify表中读出与KEYWORD相符的ID
objDS2 = GetData(sqlstr)
Dim i As Integer
If objDS2.Tables(0).Rows.Count > 0 Then '有相符的ID
For i = 0 To objDS2.Tables(0).Rows.Count - 1
sqlstr2 = "select * from bookinfo where classify=" & objDS2.Tables(0).Rows(i)("id") & "" '从bookinfo表中读出书名
objDS = GetData(sqlstr2)
If objDS.Tables(0).Rows.Count > 0 Then '有相符的书名
LoadData()
End If
Next
End If
End If
End If
End Sub
Function changewhat(ByVal fstring) As String
If fstring.length > 0 Then
Select Case fstring
Case "编号"
fstring = "id"
Case "书名"
fstring = "name"
Case "分类"
fstring = "classify"
Case "作者"
fstring = "author"
Case "出版社"
fstring = "bookconcern"
Case "总数量"
fstring = "amount"
Case "剩余数量"
fstring = "remain"
Case "借阅次数"
fstring = "loandegree"
Case Else
fstring = ""
End Select
Return fstring
End If
End Function
Private Sub tball_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tball.SelectedIndexChanged
forall = tball.SelectedItem.ToString
If forall.Length > 0 Then
Select Case forall
Case "编号"
forall = "id"
Case "书名"
forall = "name"
Case "分类"
forall = "classify"
Case "作者"
forall = " author"
Case "出版社"
forall = "bookconcern"
Case "进馆时间"
forall = "addtime"
Case "总数量"
forall = "amount"
Case "剩余数量"
forall = "remain"
Case "借阅次数"
forall = "loandegree"
Case "所有隐藏的"
forall = "ishide"
Case Else
forall = "id"
End Select
If forall <> "ishide" Then
sqlstr2 = "select * from bookinfo order by " & forall & " " & isDESC & ""
Else
sqlstr2 = "select * from bookinfo where display=1 order by id " & isDESC & ""
End If
objDS = GetData(sqlstr2)
LoadData()
End If
End Sub
Private Sub cbDESC_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbDESC.SelectedIndexChanged
isDESC = cbDESC.SelectedItem.ToString
If isDESC.Length > 0 Then
Select Case isDESC
Case "正序"
isDESC = "DESC"
Case "倒序"
isDESC = ""
Case Else
isDESC = "DESC"
End Select
If forall <> "ishide" Then
sqlstr2 = "select * from bookinfo order by " & forall & " " & isDESC & ""
Else
sqlstr2 = "select * from bookinfo where display=1 order by id " & isDESC & ""
End If
objDS = GetData(sqlstr2)
LoadData()
End If
End Sub
Private Sub btadd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btadd.Click
can = True
bookname = filter(Trim(tbbookname.Text).ToString)
author = filter(Trim(tbauthor.Text).ToString)
classify = filter(Trim(cbclassify.Text).ToString)
bookconcern = filter(Trim(tbbookconcern.Text).ToString)
amount = filter(Trim(tbamount.Text).ToString)
If bookname = "" Then
MessageBox.Show("图书名不能为空", "错误", MessageBoxButtons.OK, MessageBoxIcon.Information)
tbbookname.Focus()
can = False
ElseIf author = "" Then
MessageBox.Show("图书作者名不能为空", "错误", MessageBoxButtons.OK, MessageBoxIcon.Information)
tbauthor.Focus()
can = False
ElseIf bookconcern = "" Then
MessageBox.Show("图书出版社不能为空", "错误", MessageBoxButtons.OK, MessageBoxIcon.Information)
tbbookconcern.Focus()
can = False
ElseIf amount = "" Then
MessageBox.Show("图书数量不能为空", "错误", MessageBoxButtons.OK, MessageBoxIcon.Information)
tbamount.Focus()
can = False
ElseIf cbclassify.Text = "" Then
MessageBox.Show("图书分类不能为空", "错误", MessageBoxButtons.OK, MessageBoxIcon.Information)
cbclassify.Focus()
can = False
ElseIf Not isnum(amount) Then
MessageBox.Show("图书数量不是数字", "操作错误", MessageBoxButtons.OK, MessageBoxIcon.Information)
tbamount.Text = ""
tbamount.Focus()
can = False
End If
Dim display As Integer
If rbyes.Checked = True Then
display = 1
Else
display = 0
End If
Try
If can Then
sqlstr = "insert into bookinfo(name,author,bookconcern,amount,remain,classify,display) values('" & bookname & "','" & author & "','" & bookconcern & "'," & amount & "," & amount & "," & cbclassify.SelectedIndex & "," & display & ")"
GetData(sqlstr)
islock.Checked = True
tbbookname.Text = ""
tbauthor.Text = ""
cbclassify.SelectedIndex = 0
tbbookconcern.Text = ""
tbamount.Text = ""
dtpmoditime.Value = Now()
rbyes.Checked = True
bookid = 0
objDS = GetData(sqlstr2)
LoadData()
MessageBox.Show("数据库更新成功", "操作成功", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
Catch
MessageBox.Show("数据库更新错误", "错误", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Try
End Sub
Private Sub btreset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btreset.Click
tbbookname.Text = ""
tbauthor.Text = ""
cbclassify.SelectedIndex = 0
tbbookconcern.Text = ""
tbamount.Text = ""
dtpmoditime.Value = Now()
rbyes.Checked = True
bookid = 0
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -