📄 bookmanage.vb
字号:
cmbType.Items.Add(DataReader.Item(0))
End While
DataReader.Close()
Else
MsgBox("查询图书类别表失败")
End If
If OleConn.SelectQuery("select * from 存放位置", DataReader) Then
While DataReader.Read
cmbLocation.Items.Add(DataReader.Item(0))
End While
DataReader.Close()
Else
MsgBox("查询存放位置表失败")
End If
Catch ex As Exception
OleConn.DisplayError(ex)
End Try
OleConn.Adapter.SelectCommand.CommandText = str
dr = bookDataSet.Tables(0).Rows(linenum)
SetControls()
End Sub
Private Sub SetControls()
Try
txtBookId.Text = dr.Item("图书编号")
If Not dr.IsNull("条形码") Then
txtBarCode.Text = dr.Item("条形码")
End If
If Not dr.IsNull("书名") Then
txtBookName.Text = dr.Item("书名")
End If
If Not dr.IsNull("作者") Then
txtAuthor.Text = dr.Item("作者")
End If
If Not dr.IsNull("出版社") Then
txtBookConcern.Text = dr.Item("出版社")
End If
If Not dr.IsNull("类别") Then
cmbType.SelectedItem = dr.Item("类别")
End If
If Not dr.IsNull("页数") Then
txtPage.Text = CStr(dr.Item("页数"))
End If
If Not dr.IsNull("出版时间") Then
cmbPublishTime.Text = CStr(dr.Item("出版时间"))
End If
If Not dr.IsNull("图书总数") Then
txtBookCount.Text = CStr(dr.Item("图书总数"))
End If
If Not dr.IsNull("现存数量") Then
txtExistCount.Text = CStr(dr.Item("现存数量"))
End If
If Not dr.IsNull("入馆时间") Then
cmbAddTime.Text = CStr(dr.Item("入馆时间"))
End If
If Not dr.IsNull("图书价格") Then
txtBookPrice.Text = CStr(dr.Item("图书价格"))
End If
If Not dr.IsNull("借出次数") Then
txtLendCount.Text = CStr(dr.Item("借出次数"))
End If
If Not dr.IsNull("存放位置") Then
cmbLocation.SelectedItem = dr.Item("存放位置")
End If
Catch ex As Exception
OleConn.DisplayError(ex)
End Try
End Sub
Private Sub btnUp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUp.Click
If linenum = 0 Then
linenum = bookDataSet.Tables(0).Rows.Count - 1
Else
linenum = linenum - 1
End If
If linenum >= 0 And bookDataSet.Tables(0).Rows.Count > 0 Then
dr = bookDataSet.Tables(0).Rows(linenum)
SetControls()
End If
End Sub
Private Sub btnFirst_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFirst.Click
linenum = 0
If bookDataSet.Tables(0).Rows.Count > 0 Then
dr = bookDataSet.Tables(0).Rows(linenum)
SetControls()
End If
End Sub
Private Sub btnDown_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDown.Click
If linenum = bookDataSet.Tables(0).Rows.Count - 1 Then
linenum = 0
Else
linenum = linenum + 1
End If
If linenum < bookDataSet.Tables(0).Rows.Count And bookDataSet.Tables(0).Rows.Count > 0 Then
dr = bookDataSet.Tables(0).Rows(linenum)
SetControls()
End If
End Sub
Private Sub btnEnd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEnd.Click
linenum = bookDataSet.Tables(0).Rows.Count - 1
If bookDataSet.Tables(0).Rows.Count > 0 Then
dr = bookDataSet.Tables(0).Rows(linenum)
SetControls()
End If
End Sub
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
Try
OleConn.UpDate(bookDataSet)
bookDataSet.AcceptChanges()
Catch ex As Exception
OleConn.DisplayError(ex)
End Try
End Sub
Private Sub btnModify_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnModify.Click
If bookDataSet.Tables(0).Rows.Count > 0 Then
If txtBookId.Text = "" Then
MsgBox("请输入图书编号")
txtBookId.Focus()
ElseIf txtBarCode.Text = "" Then
MsgBox("请输入条形码")
txtBarCode.Focus()
ElseIf txtBookName.Text = "" Then
MsgBox("请输入书名")
txtBookName.Focus()
ElseIf txtAuthor.Text = "" Then
MsgBox("请输入作者")
txtAuthor.Focus()
ElseIf txtBookConcern.Text = "" Then
MsgBox("请输入出版社")
txtBookConcern.Focus()
ElseIf cmbType.SelectedIndex < 0 Then
MsgBox("请选择图书类别")
cmbType.Focus()
ElseIf txtPage.Text = "" Then
MsgBox("请输入页数")
txtPage.Focus()
ElseIf cmbPublishTime.Text = "" Then
MsgBox("请输入出版时间")
cmbPublishTime.Focus()
ElseIf txtBookCount.Text = "" Then
MsgBox("请输入图书总数")
txtBookCount.Focus()
ElseIf txtExistCount.Text = "" Then
MsgBox("请输入现存数量")
txtExistCount.Focus()
ElseIf cmbAddTime.Text = "" Then
MsgBox("请输入入馆时间")
cmbAddTime.Focus()
ElseIf txtBookPrice.Text = "" Then
MsgBox("请输入图书价格")
txtBookPrice.Focus()
ElseIf txtLendCount.Text = "" Then
MsgBox("请输入借出次数")
txtLendCount.Focus()
ElseIf cmbLocation.SelectedIndex < 0 Then
MsgBox("请指定存放位置")
cmbLocation.Focus()
Else
Try
dr.BeginEdit()
dr.Item("图书编号") = txtBookId.Text
dr.Item("条形码") = txtBarCode.Text
dr.Item("书名") = txtBookName.Text
dr.Item("作者") = txtAuthor.Text
dr.Item("出版社") = txtBookConcern.Text
dr.Item("类别") = cmbType.SelectedItem
dr.Item("页数") = CInt(txtPage.Text)
dr.Item("出版时间") = CDate(cmbPublishTime.Text)
dr.Item("图书总数") = CInt(txtBookCount.Text)
dr.Item("现存数量") = CInt(txtExistCount.Text)
dr.Item("入馆时间") = CDate(cmbAddTime.Text)
dr.Item("图书价格") = txtBookPrice.Text
dr.Item("借出次数") = CInt(txtLendCount.Text)
dr.Item("存放位置") = cmbLocation.SelectedItem
dr.EndEdit()
Catch ex As Exception
OleConn.DisplayError(ex)
End Try
End If
End If
End Sub
Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
If bookDataSet.Tables(0).Rows.Count > 0 Then
Dim str As String = "确定要删除《" & dr.Item("书名") & "》吗?"
If MessageBox.Show(str, "删除", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) = DialogResult.OK Then
Try
bookDataSet.Tables(0).Rows(linenum).Delete()
OleConn.UpDate(bookDataSet)
bookDataSet.AcceptChanges()
If linenum = bookDataSet.Tables(0).Rows.Count - 1 Then
linenum = 0
Else
linenum = linenum + 1
End If
If linenum < bookDataSet.Tables(0).Rows.Count And bookDataSet.Tables(0).Rows.Count > 0 Then
dr = bookDataSet.Tables(0).Rows(linenum)
SetControls()
End If
Catch ex As Exception
OleConn.DisplayError(ex)
End Try
End If
End If
End Sub
Private Sub cmbPublishTime_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmbPublishTime.MouseEnter
mcdPublishTime.SelectionStart = cmbPublishTime.Text
mcdPublishTime.SelectionEnd = cmbPublishTime.Text
mcdPublishTime.Visible = True
End Sub
Private Sub mcdPublishTime_DateSelected(ByVal sender As Object, ByVal e As System.Windows.Forms.DateRangeEventArgs) Handles mcdPublishTime.DateSelected
cmbPublishTime.Text = e.Start.ToShortDateString
mcdPublishTime.Visible = False
End Sub
Private Sub mcdPublishTime_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles mcdPublishTime.MouseLeave
mcdPublishTime.Visible = False
End Sub
Private Sub cmbAddTime_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmbAddTime.MouseEnter
mcdAddTime.SelectionStart = cmbAddTime.Text
mcdAddTime.SelectionEnd = cmbAddTime.Text
mcdAddTime.Visible = True
End Sub
Private Sub mcdAddTime_DateSelected(ByVal sender As Object, ByVal e As System.Windows.Forms.DateRangeEventArgs) Handles mcdAddTime.DateSelected
cmbAddTime.Text = e.Start.ToShortDateString
mcdAddTime.Visible = False
End Sub
Private Sub mcdAddTime_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles mcdAddTime.MouseLeave
mcdAddTime.Visible = False
End Sub
Private Sub frmBookManage_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
Dim str As String = "要保存你的工作吗吗?"
If MessageBox.Show(str, "保存", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.Yes Then
Try
OleConn.UpDate(bookDataSet)
bookDataSet.AcceptChanges()
Catch ex As Exception
OleConn.DisplayError(ex)
End Try
Else
bookDataSet.RejectChanges()
End If
End Sub
Private Sub txtBookId2_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtBookId2.KeyDown
If e.KeyCode = Keys.Return Then
If txtBookId2.Text <> "" Then
Dim str As String = "图书编号='" & txtBookId2.Text & "'"
Dim dr0 As DataRow() = bookDataSet.Tables(0).Select(str)
If dr0.Length() > 0 Then
dr = dr0(0)
SetControls()
End If
End If
End If
End Sub
Private Sub txtBarCode2_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtBarCode2.KeyDown
If e.KeyCode = Keys.Return Then
If txtBarCode2.Text <> "" Then
Dim str As String = "条形码='" & txtBarCode2.Text & "'"
Dim dr0 As DataRow() = bookDataSet.Tables(0).Select(str)
If dr0.Length() > 0 Then
dr = dr0(0)
SetControls()
End If
End If
End If
End Sub
Private Sub txtBookName2_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtBookName2.KeyDown
If e.KeyCode = Keys.Return Then
If txtBookName2.Text <> "" Then
Dim str As String = "条形码='" & txtBookName2.Text & "'"
Dim dr0 As DataRow() = bookDataSet.Tables(0).Select(str)
If dr0.Length() > 0 Then
dr = dr0(0)
SetControls()
End If
End If
End If
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -