using System;
using System.Configuration;
using System.Data;
using ASPNET.StarterKit.TimeTracker.DataAccessLayer;

namespace ASPNET.StarterKit.TimeTracker.BusinessLogicLayer
{
	//*********************************************************************
	//
	//	ProjectReportProject Class
	//
	//	This class represents project item in Project Report page
	//
	//*********************************************************************

	public class ProjectReportProject
	{
		private decimal		_actualHours;
		private DateTime	_estCompletionDate;
		private decimal		_estHours;
		private int			_projectID;
		private string		_projectName;
		
		public ProjectReportProject()
		{
			_projectID = 0;
			_projectName = string.Empty;
			_estCompletionDate = DateTime.MinValue;
			_estHours = 0M;
			_actualHours = 0M;
		}

		public decimal ActualHours
		{
			get { return _actualHours; }
			set { _actualHours = value; }
		}

		public DateTime	EstCompletionDate 
		{
			get { return _estCompletionDate; }
			set { _estCompletionDate = value; }
		}

		public decimal EstHours
		{
			get { return _estHours; }
			set { _estHours = value; }
		}

		public int ProjectID 
		{
			get {return _projectID;}
			set { _projectID = value; }
		}

		public string ProjectName 
		{
			get { return _projectName; }
			set { _projectName = value; }
		}

		//*********************************************************************
		//
		//	GetProjectSummary returns multiple project summaries based on projectIdList parameter
		//	projectIdList is a comma delimited project IDs string (i.e. "1,2,3")
		//
		//*********************************************************************
 
		public static ProjectReportProjectCollection GetProjectSummary(string projectIdList, int userID)
		{
			DataSet dsProjects = SqlHelper.ExecuteDataset(ConfigurationSettings.AppSettings[Web.Global.CfgKeyConnString], 
															"TT_ListProjectsByIDs", projectIdList, userID);
			ProjectReportProjectCollection projectList = new ProjectReportProjectCollection();
			
			// Separate Data into a collection of ProjectReportProject
			foreach(DataRow row in dsProjects.Tables[0].Rows)
			{
				ProjectReportProject proj = new ProjectReportProject();
				proj.ProjectID = Convert.ToInt32(row["ProjectID"]);
				proj.ProjectName = row["ProjectName"].ToString();
				proj.EstCompletionDate = Convert.ToDateTime(row["EstCompletionDate"]);
				proj.EstHours = Convert.ToDecimal(row["EstHours"]);
				proj.ActualHours = Convert.ToDecimal(row["ActualHours"]);

				projectList.Add(proj);
			}
		
			return projectList;
		}
	}
}