using System;
using System.Collections.Generic;
using System.Text;
using Medivators.Common;
using Medivators.BusinessObjects;

namespace Medivators.Data.Queries
{
	internal struct sqlHelper
	{
		internal const string baseSQL =	" select CR.*, LR.* " +
										" from   CycleReports CR, CycleReportLogRecords CRLR, LogRecords LR";
		internal const string joinSQL = " and    CR.[Key] = CRLR.CycleReportKey" +
										" and    CRLR.LogRecordKey = LR.[Key]" + 
										" order by LR.LogNumber";
	}
	public class SelectCycleReportsByDay : AsynchronousExecute, ISelectQuery
	{
		public void Select(object Day)
		{
			DateTime dt = Convert.ToDateTime(Day).Date;
			string sql = sqlHelper.baseSQL +
						 " where  StartTimestamp >= " + Constants.DateDelimiter + dt.ToString() + Constants.DateDelimiter +
						 " and    EndTimestamp   <  " + Constants.DateDelimiter + dt.AddDays(1).ToString() + Constants.DateDelimiter +
						 sqlHelper.joinSQL;
			base.Select(sql, new CycleReportDataMapper());
		}
	}
	public class SelectCycleReportsByMachineStation : AsynchronousExecute, ISelectQuery
	{
		public void Select(object MachineIDStationString)
		{
			string Station = string.Empty;
			int MachineID = 0 ;

			//	 unpack parms
			if ( ((string)MachineIDStationString).EndsWith("B"))
				Station = "B";
			else
				Station = "A";
			string wrkString = ((string)MachineIDStationString).Substring(0,((string)MachineIDStationString).Length-1);
			MachineID = Convert.ToInt32(wrkString);

			string sql = sqlHelper.baseSQL +
						 " where  CR.MachineID = " + MachineID.ToString() +
						 " and    CR.Station   = " + Constants.DoubleQuote + Station + Constants.DoubleQuote +
						 sqlHelper.joinSQL;
			base.Select(sql, new CycleReportDataMapper());
		}
	}
	public class SelectCycleReportsByOperator : AsynchronousExecute, ISelectQuery
	{
		public void Select(object OperatorID)
		{
			string sql = sqlHelper.baseSQL +
						 " where  OperatorID = " + OperatorID.ToString() +
						 sqlHelper.joinSQL;
			base.Select(sql, new CycleReportDataMapper());
		}
	}
	public class SelectCycleReportsByPatient : AsynchronousExecute, ISelectQuery
	{
		public void Select(object PatientID)
		{
			string sql = sqlHelper.baseSQL +
						 " where  PatientID = " + PatientID.ToString() +
						 sqlHelper.joinSQL;
			base.Select(sql, new CycleReportDataMapper());
		}
	}
	public class SelectCycleReportsByPhysician : AsynchronousExecute, ISelectQuery
	{
		public void Select(object PhysicianID)
		{
			string sql = sqlHelper.baseSQL +
						 " where  PhysicianID = " + PhysicianID.ToString() +
						 sqlHelper.joinSQL;
			base.Select(sql, new CycleReportDataMapper());
		}
	}
	public class SelectCycleReportsByScope : AsynchronousExecute, ISelectQuery
	{
		public void Select(object ScopeID)
		{
			string sql = sqlHelper.baseSQL +
						 " where  ScopeID = " + ScopeID.ToString() +
						 sqlHelper.joinSQL;
			base.Select(sql, new CycleReportDataMapper());
		}
	}
}