Imports System
Imports ASPNET.StarterKit.TimeTracker.BusinessLogicLayer

Namespace ASPNET.StarterKit.TimeTracker.Web

    '*********************************************************************
    '
    '	ProjectReport.aspx
    '
    '	This page is used by Administrator or Project Manager to quickly assessed
    '	how projects are progressing.  The information is summarized at the Category
    '	level where total hours for each consultant are shown.
    '
    '	Additionally, project managers can only see the information related to the
    '	projects they are managing, and administrators have no restriction on what 
    '	they can view.
    '
    '*********************************************************************

    Public Class ProjectReport
        Inherits System.Web.UI.Page
        Protected ProjectList As System.Web.UI.WebControls.DataList
        Protected BackLink As System.Web.UI.WebControls.HyperLink
        Protected BackLink2 As System.Web.UI.WebControls.HyperLink
        Protected NoData As System.Web.UI.WebControls.Label

        Protected _pageIndex As String

        Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
            ' Ensure that the visiting user has access to view the current page
            If TTSecurity.IsInRole(TTUser.UserRoleAdminPMgr) = False Then
                Response.Redirect("AccessDenied.aspx?Index=-1", True)
            End If

            Dim projectIDs As String

            ' Get input parameters from query string
            projectIDs = IIf(Request.QueryString("IDs") Is Nothing, "0", Request.QueryString("IDs"))
            _pageIndex = IIf(Request.QueryString("index") Is Nothing, "0", Request.QueryString("index"))

            BackLink.NavigateUrl = "Reports.aspx?index=" + _pageIndex
            BackLink2.NavigateUrl = "Reports.aspx?index=" + _pageIndex

            If Not IsPostBack Then
                BindProject(projectIDs)
            End If
        End Sub 'Page_Load

        '*********************************************************************
        '
        '	BindProject method retrieves all related projects information based on
        '	Project IDs passed into the function.  The resulting collection is then binded
        '	to ProjectList web control.  This method also display a friendly description
        '	when there is no data retrieved from the database.
        '
        '	Notice that Project IDs are passed in as a comma delimited string.
        '
        '*********************************************************************

        Private Sub BindProject(ByVal ids As String)
            Dim prjData As ProjectReportProjectCollection = ProjectReportProject.GetProjectSummary(ids, TTSecurity.GetUserID())
            ProjectList.DataSource = prjData
            ProjectList.DataBind()

            ' If there is no data, then display no data notification label.
            If prjData.Count = 0 Then
                NoData.Visible = True
                ProjectList.Visible = False
            End If
        End Sub 'BindProject

        '*********************************************************************
        '
        '	ListCategory returns a collection of category summaries based on a Project ID.
        '	This method is used directly in DataSource attribute for CategoryList control.
        '
        '*********************************************************************

        Protected Function ListCategory(ByVal projectID As Integer) As ProjectReportCategoryCollection
            Dim lstCategory As ProjectReportCategoryCollection = ProjectReportCategory.GetCategorySummary(projectID)
            Return IIf(lstCategory.Count = 0, Nothing, lstCategory)
        End Function 'ListCategory

        '*********************************************************************
        '
        '	ListTimeEntries returns a collection of time entry summaries based on a Category ID.
        '	This method is used directly in DataSource attribute for EntryList control.
        '
        '*********************************************************************

        Protected Function ListTimeEntries(ByVal categoryID As Integer) As ProjectReportEntryLogCollection
            Dim entryLog As ProjectReportEntryLogCollection = ProjectReportEntryLog.GetEntrySummary(categoryID)
            Return IIf(entryLog.Count = 0, Nothing, entryLog)
        End Function 'ListTimeEntries

        Private Sub InitializeComponent()

        End Sub
    End Class 'ProjectReport
End Namespace 'ASPNET.StarterKit.TimeTracker.Web
