    using System;
    using 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 : System.Web.UI.Page
        {
            protected System.Web.UI.WebControls.DataList ProjectList;
            protected System.Web.UI.WebControls.HyperLink BackLink;
            protected System.Web.UI.WebControls.HyperLink BackLink2;
            protected System.Web.UI.WebControls.Label NoData;

            protected string _pageIndex;

            private void Page_Load(object sender, System.EventArgs e)
            {
                // Ensure that the visiting user has access to view the current page
                if (TTSecurity.IsInRole(TTUser.UserRoleAdminPMgr) == false)
                {
                    Response.Redirect("AccessDenied.aspx?Index=-1", true);
                }

                string projectIDs;

                // Get input parameters from query string
                projectIDs = Request.QueryString["IDs"]==null? "0" : Request.QueryString["IDs"];
                _pageIndex = Request.QueryString["index"]==null? "0" : Request.QueryString["index"];

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

                if (!IsPostBack)
                    BindProject(projectIDs);
            }

            #region Web Form Designer generated code
            override protected void OnInit(EventArgs e)
            {
                //
                // CODEGEN: This call is required by the ASP.NET Web Form Designer.
                //
                InitializeComponent();
                base.OnInit(e);
            }

            ///
            /// Required method for Designer support - do not modify
            /// the contents of this method with the code editor.
            ///
            private void InitializeComponent()
            {
                this.Load += new System.EventHandler(this.Page_Load);

            }
            #endregion

            //*********************************************************************
            //
            //    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 void BindProject(string ids)
            {
                ProjectReportProjectCollection prjData = 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)
                {
                    NoData.Visible = true;
                    ProjectList.Visible = false;
                }
            }

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

            protected ProjectReportCategoryCollection ListCategory(int projectID)
            {
                ProjectReportCategoryCollection listCategory = ProjectReportCategory.GetCategorySummary(projectID);
                return listCategory.Count == 0? null : 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 ProjectReportEntryLogCollection ListTimeEntries(int categoryID)
            {
                ProjectReportEntryLogCollection entryLog = ProjectReportEntryLog.GetEntrySummary(categoryID);
                return entryLog.Count == 0? null : entryLog;
            }
        }
    }