private DateTime getMinProcessRequestDateTime(DateTime currentDateTime)
{
int min = 0, hr = 0, sec = 0;
int year = currentDateTime.Year;
int month = currentDateTime.Month;
int day = currentDateTime.Day;
DateTime minProcessRequestDateTime = DateTime.MinValue;
foreach (ProcessRequestTime ProcessRequestTime in _ProcessRequestTimes)
{
DateTime tempProcessRequestDateTime = DateTime.MaxValue;
switch (ProcessRequestTime.ClockType)
{
case ClockType._24Hr:
string[] time24Hr = ProcessRequestTime.Value.Split(Constants.SeperatorColon);
hr = Convert.ToInt32(time24Hr[0]);
min = Convert.ToInt32(time24Hr[1]);
tempProcessRequestDateTime = new DateTime(year, month, day, hr, min, 0);
if (!(currentDateTime > tempProcessRequestDateTime))
{
tempProcessRequestDateTime = tempProcessRequestDateTime.AddDays(-1);
}
break;
case ClockType._12Hr:
string[] time12Hr = ProcessRequestTime.Value.Split(Constants.SeperatorSingleSpace);
if (time12Hr[1].Equals(Constants.DateTimeMeridianPM, StringComparison.InvariantCultureIgnoreCase))
{
hr = Convert.ToInt32(time12Hr[0].Split(Constants.SeperatorColon)[0]);
}
else if (time12Hr[1].Equals(Constants.DateTimeMeridianAM, StringComparison.InvariantCultureIgnoreCase))
{
hr = Convert.ToInt32(time12Hr[0].Split(Constants.SeperatorColon)[0]);
if (hr >= 12) { hr -= 12; }
}
min = Convert.ToInt32(time12Hr[0].Split(Constants.SeperatorColon)[1]);
tempProcessRequestDateTime = new DateTime(year, month, day, hr, min, 0);
if (!(currentDateTime > tempProcessRequestDateTime))
{
tempProcessRequestDateTime = tempProcessRequestDateTime.AddDays(-1);
}
break;
case ClockType.Hr:
hr = Convert.ToInt32(ProcessRequestTime.Value);
tempProcessRequestDateTime = new DateTime(year, month, day);
tempProcessRequestDateTime = tempProcessRequestDateTime.AddHours(currentDateTime.Hour - hr).AddMinutes(currentDateTime.Minute);
break;
case ClockType.Min:
min = Convert.ToInt32(ProcessRequestTime.Value);
tempProcessRequestDateTime = new DateTime(year, month, day);
tempProcessRequestDateTime = tempProcessRequestDateTime.AddHours(currentDateTime.Hour).AddMinutes(currentDateTime.Minute - min);
break;
case ClockType.Sec:
sec = Convert.ToInt32(ProcessRequestTime.Value);
tempProcessRequestDateTime = new DateTime(year, month, day);
tempProcessRequestDateTime = tempProcessRequestDateTime.AddHours(currentDateTime.Hour).AddMinutes(currentDateTime.Minute).AddSeconds(currentDateTime.Second - sec);
break;
}
//Assigning the maximum datetime less than the current date
if (tempProcessRequestDateTime > minProcessRequestDateTime)
{ minProcessRequestDateTime = tempProcessRequestDateTime; _DataSource = ProcessRequestTime.DataSource; }
}
return minProcessRequestDateTime;
}