Imports System.Data
Imports System.Data.Common
Imports System.Web.HttpUtility 
Imports RemotingClient
Imports CommonBLEntities
Imports System.Collections.Generic
Imports System.Collections

Public Class DocumentManagerDA
 

    Sub New()
 

    End Sub


    Public Function GetRelatedDocuments(ByVal ID As Integer) As BLHTMLDocument()
        Dim result As DocumentFolder = AdminSiteManager.Instance.GetRelatedDocuments(ID)

        If result.ChildDocuments Is Nothing Then Return Nothing

        Return result.ChildDocuments

    End Function

    Public Sub RemoveDocumentRelation(ByVal ID As Integer, ByVal IDtoRemove As Integer)
        AdminSiteManager.Instance.RemoveDocumentRelation(ID, IDtoRemove)
    End Sub

    Public Function GetAllDocuments() As BLHTMLDocument()
        Dim result As DocumentFolder = AdminSiteManager.Instance.GetAllDocuments()

        Dim lOut As New ArrayList
        If result.ChildDocuments Is Nothing Then Return Nothing
   
        Return result.ChildDocuments


    End Function

    Public Sub RelateDocument(ByVal ID As Integer, ByVal IDtoRelate As Integer)
        AdminSiteManager.Instance.RelateDocument(ID, IDtoRelate)
    End Sub

    Public Function AddDocument(ByVal folderID As Integer, ByVal document As IHTMLDocument) As Integer
        Dim ArticleID As Integer = AdminSiteManager.Instance.AddDocument(folderID, document)
        Return ArticleID
    End Function

    Public Function AddFolder(ByVal folder As DocumentFolder) As Integer
        Dim FolderID As Integer = AdminSiteManager.Instance.AddFolder(folder)
        Return FolderID

    End Function

    Public Sub DeleteDocument(ByVal documentID As Integer)
    AdminSiteManager.Instance.DeleteDocument(documentID)
    End Sub

    Public Sub DeleteFolder(ByVal folderID As Integer)
        ' cannot delete the "Unassigned" folder
        If folderID <> Global.Constants.Folders.Unassigned Then
      AdminSiteManager.Instance.DeleteFolder(folderID)
        End If

    End Sub

    Public Function GetDistinctKeyWords() As ArrayList
        Dim keyWords As New ArrayList ' = SiteManager.Instance.GetDistinctKeyWords()

        Return keyWords
    End Function

    Public Function GetDocument(ByVal documentID As Integer) As iHTMLDocument
    Dim result As IHTMLDocument = AdminSiteManager.Instance.GetDocument(documentID)

        Return result
    End Function

    Public Function GetDocumentFolders() As DocumentFolder()
        Dim result As DocumentFolder = AdminSiteManager.Instance.GetDocumentFolders()
        Return result.ChildFolders

        'Return results

    End Function

    Public Function GetDocumentFolders(ByVal parentFolderID As Integer) As DocumentFolder()
        Try
            Dim result As DocumentFolder = AdminSiteManager.Instance.GetDocumentFolders(parentFolderID)
            Return result.ChildFolders

        Catch ex As Exception
            Throw ex
        End Try


    End Function

    Public Function GetFolder(ByVal folderID As Integer) As DocumentFolder
        Dim result As DocumentFolder = AdminSiteManager.Instance.GetFolder(folderID)

        Return result

    End Function

    Public Function GetFolderDocuments(ByVal folderID As Integer) As BLHTMLDocument()
        Dim result As DocumentFolder = AdminSiteManager.Instance.GetFolderDocuments(folderID)
        If result.ChildDocuments Is Nothing Then Return Nothing

        Return result.ChildDocuments

    End Function

    Public Sub MoveDocument(ByVal documentID As Integer, ByVal newFolderID As Integer)
    AdminSiteManager.Instance.MoveDocument(documentID, newFolderID)
    End Sub

    Public Sub UpdateDocument(ByVal document As IHTMLDocument)
        AdminSiteManager.Instance.UpdateDocument(document)
    End Sub

    Public Sub UpdateFolder(ByVal folder As DocumentFolder)
        AdminSiteManager.Instance.UpdateFolder(folder)

    End Sub

    Private Sub DeleteKeyWords(ByVal documentID As Integer)

    End Sub

    Private Sub AddKeyWords(ByVal documentID As Integer, ByRef keyWords As ArrayList)

    End Sub

End Class


Public Class DocumentFolder

    Sub New()

    End Sub
    Public ID As Integer
    Public NumberOfChildren As Integer
    Public Name As String
    Public ParentFolderID As Integer

    Public ChildFolders() As DocumentFolder

    Public ChildDocuments() As BLHTMLDocument
End Class

