
Partial Class Folders
    Inherits System.Web.UI.UserControl

    Public Event AddFolder()
    Public Event FolderDeleted()
    Public Event FolderSelected(ByVal folderID As Integer)

    Public Property SelectedFolder() As Integer

        Get
            Return foldersListBox.SelectedValue
        End Get

        Set(ByVal value As Integer)
            foldersListBox.SelectedValue = value
        End Set

    End Property

    Public Sub LoadFolders()

        Dim documentManager As New DMSAdmin.DocumentManagerBL
        documentManager.Credentials = Net.CredentialCache.DefaultNetworkCredentials

        Dim folders() As DMSAdmin.DocumentFolder = documentManager.GetDocumentFolders()

        With foldersListBox
            .DataSource = folders
            .DataTextField = "Name"
            .DataValueField = "ID"
            .DataBind()
        End With

        deleteButton.Enabled = False

    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Try
            If Not IsPostBack Then

                Me.LoadFolders()
            End If
        Catch ex As Exception


      Throw
    End Try

  End Sub

  Protected Sub deleteButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles deleteButton.Click

    Try
      Dim folderID As Integer = foldersListBox.SelectedValue

      If folderID <> Global.Constants.Folders.Unassigned Then

                Dim documentManager As New DMSAdmin.DocumentManagerBL
                documentManager.Credentials = Net.CredentialCache.DefaultNetworkCredentials
                Dim page As AdminPage = CType(Me.Page, AdminPage)
                documentManager.DeleteFolder(folderID, page.CurrentUserID)

        RaiseEvent FolderDeleted()
      End If
    Catch ex As Exception


      Throw
    End Try

  End Sub

  Protected Sub foldersListBox_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles foldersListBox.SelectedIndexChanged

    Try
      Dim selectedValue As Integer = foldersListBox.SelectedValue
      RaiseEvent FolderSelected(selectedValue)

      deleteButton.Enabled = (selectedValue <> Constants.Folders.Unassigned)
    Catch ex As Exception


      Throw
    End Try

  End Sub

  Protected Sub newButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles newButton.Click

    Try
      RaiseEvent AddFolder()
    Catch ex As Exception


      Throw
    End Try

  End Sub

End Class
