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

📄 frmbooksort.vb

📁 The Management Information System of Library using .NET
💻 VB
📖 第 1 页 / 共 2 页
字号:
        Me.GroupBox3.Location = New System.Drawing.Point(256, 56)
        Me.GroupBox3.Name = "GroupBox3"
        Me.GroupBox3.Size = New System.Drawing.Size(184, 160)
        Me.GroupBox3.TabIndex = 8
        Me.GroupBox3.TabStop = False
        Me.GroupBox3.Text = "分类具体说明"
        '
        'btnDelete
        '
        Me.btnDelete.Location = New System.Drawing.Point(320, 224)
        Me.btnDelete.Name = "btnDelete"
        Me.btnDelete.Size = New System.Drawing.Size(56, 23)
        Me.btnDelete.TabIndex = 3
        Me.btnDelete.Text = "删除"
        '
        'btnReset
        '
        Me.btnReset.Location = New System.Drawing.Point(384, 224)
        Me.btnReset.Name = "btnReset"
        Me.btnReset.Size = New System.Drawing.Size(56, 23)
        Me.btnReset.TabIndex = 4
        Me.btnReset.Text = "重置"
        '
        'frmbooksort
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
        Me.ClientSize = New System.Drawing.Size(448, 253)
        Me.Controls.Add(Me.btnReset)
        Me.Controls.Add(Me.btnDelete)
        Me.Controls.Add(Me.GroupBox3)
        Me.Controls.Add(Me.GroupBox2)
        Me.Controls.Add(Me.GroupBox1)
        Me.Controls.Add(Me.btnSave2)
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D
        Me.MaximizeBox = False
        Me.MinimizeBox = False
        Me.Name = "frmbooksort"
        Me.ShowInTaskbar = False
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent
        Me.Text = "图书分类信息管理"
        CType(Me.dbgbooksort, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.Dsbooksort1, System.ComponentModel.ISupportInitialize).EndInit()
        Me.GroupBox1.ResumeLayout(False)
        Me.GroupBox2.ResumeLayout(False)
        Me.GroupBox3.ResumeLayout(False)
        Me.ResumeLayout(False)

    End Sub

#End Region
    Dim currCnt As Int16
    Dim IsEdit As Boolean
    Private Sub test_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.cnlib2004.ConnectionString = cnstr
        databind()
        IsEdit = False
        DisableControl()
        'Me.txtBooksort.Focus()
    End Sub

#Region "自定义函数 数据绑定"
    Function databind()
        Me.Dsbooksort1.Clear()
        Me.dabooksort.Fill(Me.Dsbooksort1)
    End Function
    Function updateData()
        'Me.Dsbooksort1.AcceptChanges()
        Me.dabooksort.Update(Dsbooksort1)
    End Function

    Function DisableControl()
        IsEdit = False
        Me.txtBookmark.Text = ""
        Me.txtBooksort.Text = ""
        Me.btnSave2.Enabled = False
        Me.btnDelete.Enabled = False
        Me.txtBooksort.Focus()
    End Function
    Function CheckExist(ByVal strBooksort As String) As Boolean
        Dim mycount As Int16
        With Me.Dsbooksort1.Tables(0)
            For mycount = 0 To .Rows.Count - 1
                If CType(.Rows(mycount).Item(0), String) = strBooksort Then
                    Return True
                End If
            Next
        End With

        Return False
    End Function
#End Region

    Private Sub dbgbooksort_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles dbgbooksort.Click
        currCnt = dbgbooksort.CurrentRowIndex
        Me.txtBooksort.Text = Me.Dsbooksort1.Tables(0).Rows(currCnt).Item(0)
        Me.txtBookmark.Text = Me.Dsbooksort1.Tables(0).Rows(currCnt).Item(1)

        IsEdit = True
        Me.btnSave2.Text = "修改"
        Me.btnSave2.Enabled = True
        Me.btnDelete.Enabled = True
        Me.txtBooksort.Focus()
    End Sub
    '添加 修改 代码
    Private Sub btnSave2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave2.Click
        Dim strBooksort As String = txtBooksort.Text.Trim
        Dim strBookmark As String = txtBookmark.Text.Trim
        '    
        If IsEdit = True Then
            With Me.Dsbooksort1.Tables(0).Rows(currCnt)
                '如果改变了主关键字(分类号),则检查是否重复
                If strBooksort <> .Item(0) Then
                    If CheckExist(strBooksort) = True Then
                        MessageBox.Show("该分类已经存在", "错误", _
                        MessageBoxButtons.OK, MessageBoxIcon.Stop)
                        Me.DisableControl()
                        Exit Sub
                    End If
                End If
                .Item(0) = strBooksort
                .Item(1) = strBookmark
                'MessageBox.Show("修改成功!", "提示")
                IsEdit = False
                DisableControl()
            End With
        Else
            '检查是否重复出现分类号
            If CheckExist(strBooksort) = True Then
                MessageBox.Show("该分类已经存在", "错误", _
                MessageBoxButtons.OK, MessageBoxIcon.Stop)
                Me.DisableControl()
                Exit Sub
            End If



            Dim rowValue(1) As Object
            Dim mydatarow As DataRow
            rowValue(0) = strBooksort
            rowValue(1) = strBookmark

            mydatarow = Dsbooksort1.Tables(0).NewRow
            mydatarow.ItemArray = rowValue
            Me.Dsbooksort1.Tables(0).Rows.Add(rowValue)
            Me.DisableControl()
        End If

        Try
            Me.updateData()
        Catch ex As Exception
            Me.Dsbooksort1.RejectChanges()
            MessageBox.Show("更新失败--" + ex.Message)
            Me.DisableControl()
            Me.dbgbooksort.Refresh()
        End Try
    End Sub
    '删除代码
    Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
        Dim DiaResult As System.Windows.Forms.DialogResult
        DiaResult = MessageBox.Show("是否删除该记录?", _
        "警告", MessageBoxButtons.YesNo, _
        MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2)
        If DiaResult = DialogResult.Yes Then
            Me.Dsbooksort1.Tables(0).Rows(currCnt).Delete()
            Try
                updateData()
                MessageBox.Show("删除成功")
            Catch ex As Exception
                Me.Dsbooksort1.RejectChanges()
                MessageBox.Show(ex.Message)
            End Try
            Me.DisableControl()
        End If
    End Sub
    'txtchange
    Private Sub txtBooksort_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtBooksort.TextChanged
        If IsEdit = False Then
            Me.btnSave2.Text = "添加"
            Me.btnSave2.Enabled = True
        End If
    End Sub
    '重置代码
    Private Sub btnReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReset.Click
        Me.DisableControl()
    End Sub
End Class

⌨️ 快捷键说明

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