SQL SERVER(47)图书管理系统之四图书管理的增删改查

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

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ngbshzhn

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值