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

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

	public class ProjectReportCategory
	{
		private decimal _actualHours;
		private int		_categoryID;
		private string	_categoryName;
		private string	_categoryShortName;
		private decimal _estDuration;

		public ProjectReportCategory()
		{
			_categoryID = 0;
			_categoryName = string.Empty;
			_categoryShortName = string.Empty;
			_estDuration = 0M;
			_actualHours = 0M;
		}

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

		public string CategoryName
		{
			get { return _categoryName; }
			set { _categoryName = value; }
		}

		public string CategoryShortName
		{
			get { return _categoryShortName; }
			set { _categoryShortName = value; }
		}

		public decimal EstDuration 
		{
			get { return _estDuration; }
			set { _estDuration = value; }
		}

		//*********************************************************************
		//
		//	GetCategorySummary returns project report category summary by each project.
		//
		//*********************************************************************

		public static ProjectReportCategoryCollection GetCategorySummary(int projectID)
		{
			DataSet dsCats = SqlHelper.ExecuteDataset(ConfigurationSettings.AppSettings[Web.Global.CfgKeyConnString], 
				"TT_ListCategoriesByProject", projectID); 
			ProjectReportCategoryCollection categoryList = new ProjectReportCategoryCollection();

			// Separate Data into a list of collections.
			foreach(DataRow row in dsCats.Tables[0].Rows)
			{
				ProjectReportCategory cat = new ProjectReportCategory();
				cat.CategoryID = Convert.ToInt32(row["CategoryID"]);
				cat.CategoryName = row["Name"].ToString();
				cat.CategoryShortName = row["CategoryShortName"].ToString();
				cat.EstDuration = Convert.ToDecimal(row["EstDuration"]);
				cat.ActualHours = Convert.ToDecimal(row["ActualHours"]);

				categoryList.Add(cat);
			}
		
			return categoryList;
		}
	}
}