Public Class frmAddbook
Private Sub ClearText()
txtBookName.Text = ""
txtAuthor.Text = ""
txtISBN.Text = ""
txtPrice.Text = ""
txtPub.Text = ""
txtDate.Text = ""
txtContent.Text = ""
End Sub
Private Sub frmAddbook_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ClearText()
End Sub
Private Sub btnOk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOk.Click
Dim strSql As String = "Insert into " _
& "bookinfo(bookname,bookprice,bookpub,bookisbn,bookauthor,bookcontent,bookdate) " _
& "values('{0}','{1}','{2}','{3}','{4}','{5}','{6}')"
strSql = String.Format(strSql, txtBookName.Text, txtPrice.Text, txtPub.Text, txtISBN.Text, txtAuthor.Text, txtContent.Text, txtDate.Text)
'MsgBox(strSql)
Dim mypubfun As New PubFunction
If mypubfun.nonQuery(strSql) = 1 Then
MsgBox("添加图书信息成功!")
Else
MsgBox("添加图书信息失败!")
End If
ClearText()
End Sub
Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
Me.Close()
End Sub
End Class
Public Class frmModify
Dim id As Integer
Private Sub frmModify_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
DataGridView1.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells
Dim pubf As New PubFunction
pubf.Ref(DataGridView1)
End Sub
Private Sub DataGridView1_CellDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellDoubleClick
Dim intIndex As Integer = e.RowIndex
id = DataGridView1.Rows(intIndex).Cells(0).Value
txtBookName.Text = DataGridView1.Rows(intIndex).Cells(1).Value
txtPrice.Text = DataGridView1.Rows(intIndex).Cells(2).Value
txtPub.Text = DataGridView1.Rows(intIndex).Cells(3).Value
txtISBN.Text = DataGridView1.Rows(intIndex).Cells(4).Value
txtAuthor.Text = DataGridView1.Rows(intIndex).Cells(5).Value
txtContent.Text = DataGridView1.Rows(intIndex).Cells(6).Value
txtDate.Text = DataGridView1.Rows(intIndex).Cells(7).Value
End Sub
Private Sub btnOk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOk.Click
Dim strSql As String = "Update bookinfo set " _
& "bookname='{0}'," _
& "bookprice='{1}'," _
& "bookpub='{2}'," _
& "bookisbn='{3}'," _
& "bookauthor='{4}'," _
& "bookcontent='{5}'," _
& "bookdate='{6}' " _
& "where id={7}"
strSql = String.Format(strSql, txtBookName.Text, txtPrice.Text, txtPub.Text, txtISBN.Text, txtAuthor.Text, txtContent.Text, txtDate.Text, id)
MsgBox(strSql)
Dim pubf As New PubFunction
If pubf.nonQuery(strSql) >= 0 Then
MsgBox("修改成功!")
pubf.Ref(DataGridView1)
Else
MsgBox("修改失败")
End If
End Sub
Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
Me.Close()
End Sub
End Class
Public Class frmDelete
Private Sub frmDelete_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim pubf As New PubFunction
pubf.Ref(DataGridView1)
End Sub
Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click
Dim strSql As String = "Select " _
& "bookname as '书名'," _
& "bookprice as '价格'," _
& "bookisbn as '书号'," _
& "bookauthor as '作者'," _
& "bookcontent as '内容'," _
& "bookdate as '日期'," _
& "bookpub as '出版社' " _
& "from bookinfo " _
& "where bookname like '%{0}%'"
strSql = String.Format(strSql, txtName.Text)
Dim pubf As New PubFunction
Dim ds As New DataSet
ds = pubf.query(strSql)
DataGridView1.DataSource = ds.Tables(0)
End Sub
Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
Dim strSql As String = "Delete from bookinfo where id={0}"
strSql = String.Format(strSql, DataGridView1.SelectedRows(0).Cells(0).Value)
Dim pubf As New PubFunction
If pubf.nonQuery(strSql) = 1 Then
MsgBox("删除成功")
pubf.Ref(DataGridView1)
Else
MsgBox("删除失败")
End If
End Sub
End Class
Public Class frmQuery
Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click
Dim strSql As String = "Select " _
& "bookname as '书名'," _
& "bookprice as '价格'," _
& "bookisbn as '书号'," _
& "bookauthor as '作者'," _
& "bookcontent as '内容'," _
& "bookdate as '日期'," _
& "bookpub as '出版社' " _
& "from bookinfo " _
& "where bookname like '%{0}%'"
strSql = String.Format(strSql, txtName.Text)
Dim pubf As New PubFunction
Dim ds As New DataSet
ds = pubf.query(strSql)
DataGridView1.DataSource = ds.Tables(0)
End Sub
Private Sub frmQuery_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim pubf As New PubFunction
pubf.Ref(DataGridView1)
End Sub
End Class