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

📄 admin.vb

📁 数据库学习的绝好例子简单的数据库经典入门
💻 VB
📖 第 1 页 / 共 5 页
字号:
                    'Initialize a new instance of the business logic component
                    Using objUsers As New WroxBusinessLogic.WBLUsers( _
                        strCompany, strApplication)
                        'Delete the user
                        If Not objUsers.DeleteUser( _
                            New Guid(txtUserID.Text)) Then
                            Throw New Exception("Delete User Failed")
                        End If
                    End Using

                    'Clear the input fields
                    txtUserID.Text = String.Empty
                    txtLogin.Text = String.Empty
                    txtPassword.Text = String.Empty
                    txtFirstName.Text = String.Empty
                    txtLastName.Text = String.Empty
                    txtEmail.Text = String.Empty
                    txtPhone.Text = String.Empty
                    optStatusActive.Checked = True
                    txtUserUpdateDate.Text = String.Empty

                    'Reload the Managers combo box
                    Call LoadManagers()

                    'Reload the Users list
                    Call LoadUsers()
                    cboUserGroup.SelectedIndex = -1
                    cboUserRole.SelectedIndex = -1
                    cboUserManager.SelectedIndex = -1
            End Select

            'Display a message that the record was deleted
            ToolStripStatus.Text = "Record Deleted"
        Catch ExceptionErr As Exception
            MessageBox.Show(ExceptionErr.Message, strAppTitle)
        End Try
    End Sub
#End Region

#Region " Projects Procedures "
    Private Sub LoadProjects()
        'Declare variables
        Dim objListViewItem As ListViewItem

        'Initialize a new instance of the business logic component
        Using objProjects As New WroxBusinessLogic.WBLProjects( _
            strCompany, strApplication)

            Try
                'Clear previous bindings
                lstProjects.DataSource = Nothing
                lstProjects.DisplayMember = String.Empty
                lstProjects.ValueMember = String.Empty

                'Get all projects in a DataSet object
                objProjectsDS = objProjects.GetProjects()

                'Clear previous list
                lvwProjects.Items.Clear()

                'Process all rows
                For intIndex = 0 To objProjectsDS.Tables("Projects").Rows.Count - 1
                    'Create a new listview item
                    objListViewItem = New ListViewItem
                    'Add the data to the listview item
                    objListViewItem.Text = objProjectsDS.Tables( _
                        "Projects").Rows(intIndex).Item("ProjectName")
                    objListViewItem.Tag = objProjectsDS.Tables( _
                        "Projects").Rows(intIndex).Item("ProjectID")
                    'Add the sub items to the listview item
                    objListViewItem.SubItems.Add(objProjectsDS.Tables( _
                        "Projects").Rows(intIndex).Item("ProjectDescription"))
                    objListViewItem.SubItems.Add(objProjectsDS.Tables( _
                        "Projects").Rows(intIndex).Item("SequenceNumber"))
                    objListViewItem.SubItems.Add(Format(objProjectsDS.Tables( _
                        "Projects").Rows(intIndex).Item("LastUpdateDate"), "g"))
                    'Add the listview item to the listview control
                    lvwProjects.Items.Add(objListViewItem)
                Next

                'Rebind ListBox control
                lstProjects.DataSource = objProjectsDS.Tables("Projects")
                lstProjects.DisplayMember = "ProjectName"
                lstProjects.ValueMember = "ProjectID"
            Catch ExceptionErr As Exception
                MessageBox.Show(ExceptionErr.Message, strAppTitle)
            End Try
        End Using

        'Cleanup
        objListViewItem = Nothing

    End Sub

    Private Sub lvwProjects_Click(ByVal sender As Object, _
        ByVal e As System.EventArgs) Handles lvwProjects.Click

        'Initialize a new instance of the business logic component
        Using objProjects As New WroxBusinessLogic.WBLProjects( _
            strCompany, strApplication)

            Try
                'Get the specific project selected in the ListView control
                objDataSet = objProjects.GetProject( _
                    New Guid(lvwProjects.SelectedItems.Item(0).Tag.ToString))

                'Populate the Project Details section
                txtProjectID.Text = _
                    objDataSet.Tables("Project").Rows(0).Item( _
                    "ProjectID").ToString.ToUpper
                txtProjectName.Text = _
                    objDataSet.Tables("Project").Rows(0).Item("ProjectName")
                txtProjectDescription.Text = _
                    objDataSet.Tables("Project").Rows(0).Item( _
                    "ProjectDescription")
                txtSequenceNumber.Text = _
                    objDataSet.Tables("Project").Rows(0).Item("SequenceNumber")
                txtProjectUpdateDate.Text = _
                    objDataSet.Tables("Project").Rows(0).Item("LastUpdateDate")

            Catch ExceptionErr As Exception
                MessageBox.Show(ExceptionErr.Message, strAppTitle)
            End Try
        End Using
    End Sub

    Private Sub lstProjects_MouseDown(ByVal sender As Object, _
        ByVal e As System.Windows.Forms.MouseEventArgs) _
        Handles lstProjects.MouseDown

        If e.Button = MouseButtons.Left Then
            lstProjects.DoDragDrop(objProjectsDS.Tables("Projects").Rows( _
                lstProjects.SelectedIndex)("ProjectID").ToString, _
                DragDropEffects.Copy)
        End If
    End Sub

    Private Sub lstGroupProjects_DragEnter(ByVal sender As Object, _
        ByVal e As System.Windows.Forms.DragEventArgs) _
        Handles lstGroupProjects.DragEnter

        'Exit if nothing has been selected in the cboGroups ComboBox
        If cboGroups.SelectedIndex = -1 Then
            Exit Sub
        End If

        'Now ensure that the drag content is the correct type for this control
        If (e.Data.GetDataPresent(DataFormats.Text)) Then
            'If the item does not already exist then allow the copy
            Dim objDataView As Data.DataView = New _
                Data.DataView(objGroupProjectsDS.Tables("GroupProjects"))
            objDataView.Sort = "ProjectID"
            intIndex = objDataView.Find(e.Data.GetData(DataFormats.Text))
            If intIndex = -1 Then
                e.Effect = DragDropEffects.Copy
            Else
                e.Effect = DragDropEffects.None
            End If
        Else
            e.Effect = DragDropEffects.None
        End If
    End Sub

    Private Sub lstGroupProjects_DragDrop(ByVal sender As Object, _
        ByVal e As System.Windows.Forms.DragEventArgs) _
        Handles lstGroupProjects.DragDrop

        Dim objDataRow As Data.DataRow
        Dim objDataView As Data.DataView = New _
            Data.DataView(objProjectsDS.Tables("Projects"))
        objDataView.Sort = "ProjectID"
        intIndex = objDataView.Find(e.Data.GetData(DataFormats.Text))
        objDataRow = objGroupProjectsDS.Tables("GroupProjects").NewRow
        objDataRow.Item("ProjectID") = New _
            Guid(e.Data.GetData(DataFormats.Text).ToString)
        objDataRow.Item("ProjectName") = _
            objDataView.Item(intIndex).Item("ProjectName")
        objGroupProjectsDS.Tables("GroupProjects").Rows.Add(objDataRow)
        objGroupProjectsDS.AcceptChanges()
    End Sub

    Private Sub lstGroupProjects_KeyUp(ByVal sender As Object, _
        ByVal e As System.Windows.Forms.KeyEventArgs) _
        Handles lstGroupProjects.KeyUp

        If e.KeyCode = Keys.Delete Then
            objGroupProjectsDS.Tables("GroupProjects").Rows.RemoveAt( _
                lstGroupProjects.SelectedIndex)
            objGroupProjectsDS.AcceptChanges()
        End If
    End Sub
#End Region

#Region " Groups Procedures "
    Private Sub LoadGroups()
        'Declare variables
        Dim objListViewItem As ListViewItem

        'Turn the loading flag on so no items are processed
        blnLoading = True

        'Initialize a new instance of the business logic component
        Using objGroups As New WroxBusinessLogic.WBLGroups( _
            strCompany, strApplication)

            Try
                'Clear previous data bindings
                cboGroups.DataSource = Nothing
                cboGroups.DisplayMember = String.Empty
                cboGroups.ValueMember = String.Empty
                cboUserGroup.DataSource = Nothing
                cboUserGroup.DisplayMember = String.Empty
                cboUserGroup.ValueMember = String.Empty

                'Get all groups in a DataSet object
                objGroupsDS = objGroups.GetGroups()

                'Clear previous list
                lvwGroups.Items.Clear()

                'Process all rows
                For intIndex = 0 To objGroupsDS.Tables("Groups").Rows.Count - 1

                    'Create a new listview item
                    objListViewItem = New ListViewItem

                    'Add the data to the listview item
                    objListViewItem.Text = _
                        objGroupsDS.Tables("Groups").Rows(intIndex).Item( _
                        "GroupName")
                    objListViewItem.Tag = _
                        objGroupsDS.Tables("Groups").Rows(intIndex).Item( _
                        "GroupID")

                    'Add the sub items to the listview item
                    objListViewItem.SubItems.Add( _
                        objGroupsDS.Tables("Groups").Rows(intIndex).Item( _
                        "GroupDescription"))
                    objListViewItem.SubItems.Add( _
                        Format(objGroupsDS.Tables("Groups").Rows(intIndex).Item( _
                        "LastUpdateDate"), "g"))

                    'Add the listview item to the listview control
                    lvwGroups.Items.Add(objListViewItem)

                Next

                'Rebind ComboBox control
                cboGroups.DataSource = objGroupsDS.Tables("Groups")
                cboGroups.DisplayMember = "GroupName"
                cboGroups.ValueMember = "GroupID"
                cboUserGroup.DataSource = objGroupsDS.Tables("Groups")
                cboUserGroup.DisplayMember = "GroupName"
                cboUserGroup.ValueMember = "GroupID"

                'Reset the selected index
                cboGroups.SelectedIndex = -1
                cboUserGroup.SelectedIndex = -1
            Catch ExceptionErr As Exception
                MessageBox.Show(ExceptionErr.Message, strAppTitle)
            End Try
        End Using

        'Cleanup
        objListViewItem = Nothing

        'Turn off loading switch
        blnLoading = False
    End Sub

    Private Sub lvwGroups_Click(ByVal sender As Object, _
        ByVal e As System.EventArgs) Handles lvwGroups.Click

        'Initialize a new instance of the business logic component
        Using objGroups As New WroxBusinessLogic.WBLGroups( _
            strCompany, strApplication)

            Try
                'Get the specific Group selected in the ListView control
                objDataSet = objGroups.GetGroup( _
                    New Guid(lvwGroups.SelectedItems.Item(0).Tag.ToString))

                'Populate the Group Details section
                txtGroupID.Text = _
                    objDataSet.Tables("Group").Rows(0).Item( _
                    "GroupID").ToString.ToUpper
                txtGroupName.Text = _
                    objDat

⌨️ 快捷键说明

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