⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frmbookplace.vb

📁 The Management Information System of Library using .NET
💻 VB
📖 第 1 页 / 共 2 页
字号:
        Me.SqlSelectCommand1.Connection = Me.cn
        '
        'SqlInsertCommand1
        '
        Me.SqlInsertCommand1.CommandText = "INSERT INTO place(Book_place, Place_remarks) VALUES (@Book_place, @Place_remarks)" & _
        "; SELECT Book_place, Place_remarks FROM place WHERE (Book_place = @Book_place)"
        Me.SqlInsertCommand1.Connection = Me.cn
        Me.SqlInsertCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Book_place", System.Data.SqlDbType.NVarChar, 50, "Book_place"))
        Me.SqlInsertCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Place_remarks", System.Data.SqlDbType.NVarChar, 4000, "Place_remarks"))
        '
        'SqlUpdateCommand1
        '
        Me.SqlUpdateCommand1.CommandText = "UPDATE place SET Book_place = @Book_place, Place_remarks = @Place_remarks WHERE (" & _
        "Book_place = @Original_Book_place) AND (Place_remarks = @Original_Place_remarks " & _
        "OR @Original_Place_remarks IS NULL AND Place_remarks IS NULL); SELECT Book_place" & _
        ", Place_remarks FROM place WHERE (Book_place = @Book_place)"
        Me.SqlUpdateCommand1.Connection = Me.cn
        Me.SqlUpdateCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Book_place", System.Data.SqlDbType.NVarChar, 50, "Book_place"))
        Me.SqlUpdateCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Place_remarks", System.Data.SqlDbType.NVarChar, 4000, "Place_remarks"))
        Me.SqlUpdateCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Original_Book_place", System.Data.SqlDbType.NVarChar, 50, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "Book_place", System.Data.DataRowVersion.Original, Nothing))
        Me.SqlUpdateCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Original_Place_remarks", System.Data.SqlDbType.NVarChar, 4000, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "Place_remarks", System.Data.DataRowVersion.Original, Nothing))
        '
        'SqlDeleteCommand1
        '
        Me.SqlDeleteCommand1.CommandText = "DELETE FROM place WHERE (Book_place = @Original_Book_place) AND (Place_remarks = " & _
        "@Original_Place_remarks OR @Original_Place_remarks IS NULL AND Place_remarks IS " & _
        "NULL)"
        Me.SqlDeleteCommand1.Connection = Me.cn
        Me.SqlDeleteCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Original_Book_place", System.Data.SqlDbType.NVarChar, 50, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "Book_place", System.Data.DataRowVersion.Original, Nothing))
        Me.SqlDeleteCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Original_Place_remarks", System.Data.SqlDbType.NVarChar, 4000, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "Place_remarks", System.Data.DataRowVersion.Original, Nothing))
        '
        'da
        '
        Me.da.DeleteCommand = Me.SqlDeleteCommand1
        Me.da.InsertCommand = Me.SqlInsertCommand1
        Me.da.SelectCommand = Me.SqlSelectCommand1
        Me.da.TableMappings.AddRange(New System.Data.Common.DataTableMapping() {New System.Data.Common.DataTableMapping("Table", "place", New System.Data.Common.DataColumnMapping() {New System.Data.Common.DataColumnMapping("Book_place", "Book_place"), New System.Data.Common.DataColumnMapping("Place_remarks", "Place_remarks")})})
        Me.da.UpdateCommand = Me.SqlUpdateCommand1
        '
        'btnReset
        '
        Me.btnReset.Location = New System.Drawing.Point(180, 16)
        Me.btnReset.Name = "btnReset"
        Me.btnReset.Size = New System.Drawing.Size(56, 24)
        Me.btnReset.TabIndex = 3
        Me.btnReset.Text = "重置"
        '
        'frmBookPlace
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
        Me.ClientSize = New System.Drawing.Size(504, 245)
        Me.Controls.Add(Me.GroupBox3)
        Me.Controls.Add(Me.Panel1)
        Me.Controls.Add(Me.GroupBox2)
        Me.Controls.Add(Me.grp1)
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D
        Me.MaximizeBox = False
        Me.MinimizeBox = False
        Me.Name = "frmBookPlace"
        Me.ShowInTaskbar = False
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent
        Me.Text = "图书存放位置管理"
        Me.grp1.ResumeLayout(False)
        CType(Me.dbgBookPlace, System.ComponentModel.ISupportInitialize).EndInit()
        Me.GroupBox2.ResumeLayout(False)
        Me.GroupBox3.ResumeLayout(False)
        Me.Panel1.ResumeLayout(False)
        Me.ResumeLayout(False)

    End Sub

#End Region
    'Dim cn As New SqlConnection
    'Dim da As SqlDataAdapter
    Dim ds As DataSet
    Private Sub frmBookPlace_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        cn.ConnectionString = cnstr
        ds = New DataSet
        LoadData()
        clearMe()
    End Sub

    Private Sub LoadData()
        ds.Reset()
        Try
            da.Fill(ds)
            Me.dbgBookPlace.DataSource = ds.Tables(0)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        Finally
            cn.Close()
            If Not cn Is Nothing Then
                cn.Dispose()
            End If
        End Try
    End Sub

    Private Sub dbgBookPlace_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles dbgBookPlace.Click
        Dim currcnt As Int16
        currcnt = sender.CurrentRowIndex
        Me.txtBook_place.Text = ds.Tables(0).Rows(currcnt).Item(0)
        Me.txtPlace_remarks.Text = ds.Tables(0).Rows(currcnt).Item(1)

        Me.btnAdd.Enabled = False
        Me.btnEdit.Enabled = True
        Me.btnDelete.Enabled = True
    End Sub

    Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
        Dim rowValues(1) As String
        Dim DaRow As DataRow
        rowValues(0) = Me.txtBook_place.Text
        rowValues(1) = Me.txtPlace_remarks.Text
        DaRow = ds.Tables(0).NewRow
        DaRow.ItemArray = rowValues
        ds.Tables(0).Rows.Add(DaRow)
        If Me.Updatedata Then
            clearMe()
        End If

    End Sub

    Private Sub btnEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEdit.Click
        ds.Tables(0).Rows(dbgBookPlace.CurrentRowIndex).Item(0) = Me.txtBook_place.Text
        ds.Tables(0).Rows(dbgBookPlace.CurrentRowIndex).Item(1) = Me.txtPlace_remarks.Text
        Try
            Me.Updatedata()
        Catch ex As Exception
            'error
        End Try

    End Sub

    Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
        ds.Tables(0).Rows(dbgBookPlace.CurrentRowIndex).Delete()
        If Me.Updatedata Then
            clearMe()
        End If
    End Sub
    Private Function Updatedata() As Boolean
        If Not ds.GetChanges Is Nothing Then
            cn.ConnectionString = cnstr
            Try
                da.Update(ds)
                Return True
            Catch ex As Exception
                ds.RejectChanges()
                MessageBox.Show(ex.Message)
                Return False
                ' Throw ex
            Finally
                cn.Close()
                If Not cn Is Nothing Then
                    cn.Dispose()
                End If
            End Try
        End If
    End Function
    Sub clearMe()
        Me.txtBook_place.Clear()
        Me.txtPlace_remarks.Clear()
        Me.btnEdit.Enabled = False
        Me.btnDelete.Enabled = False
        Me.btnAdd.Enabled = True
    End Sub

    Private Sub btnReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReset.Click
        clearMe()
        Me.txtBook_place.Focus()
    End Sub

    Private Sub da_RowUpdated(ByVal sender As Object, ByVal e As System.Data.SqlClient.SqlRowUpdatedEventArgs) Handles da.RowUpdated
        If e.Status = UpdateStatus.SkipCurrentRow Then
            e.Row.RejectChanges()
        Else
            e.Row.AcceptChanges()
        End If
    End Sub
End Class

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -