using System;
using System.Text;
using Medivators.BusinessObjects;
using Medivators.Common;
using Medivators.Common.Logging;

namespace Medivators.Data.Queries
{
	public class SelectCycleReports : AsynchronousExecute
	{
		private string baseSQL =	" select CR.*, LR.* " +
									" from   CycleReports CR, CycleReportLogRecords CRLR, LogRecords LR";
		private string joinSQL =	" and    CR.[Key] = CRLR.CycleReportKey" +
									" and    CRLR.LogRecordKey = LR.[Key]" + 
									" order by CR.[Key]";

		public void SelectByDates(DateTime StartDate, DateTime EndDate)
		{
			string sql = baseSQL +
						 " where  StartTimestamp >= " + Constants.DateDelimiter + StartDate + Constants.DateDelimiter +
						 " and    EndTimestamp   <= " + Constants.DateDelimiter + EndDate + Constants.DateDelimiter +
						 joinSQL;

			base.Select(sql, new CycleReportDataMapper());
		}
		public void SelectByKey(string CycleReportKey)
		{
			string sql = baseSQL +
						 " where  CR.[Key] = " + Constants.DoubleQuote + CycleReportKey + Constants.DoubleQuote + 
						 joinSQL;
			base.Select(sql, new CycleReportDataMapper());
		}
	}
}
