public static OverDue CalculateOverDueRate(DateTime CheckOutTime, long ReservationID, HotelBookingCalculate msg, HotelBookingObject hObject) { bool isWeekend = DateIsWeekend(CheckOutTime); string query = string.Format("Select {0} from CheckTime as a, RoomOverDueRate as b where a.ReservationID = @ReservationID and a.RoomTypeID = b.RoomTypeID", isWeekend ? "b.WeekendRate" : "b.WeekDayRate"); SQLClient sqlclient = new SQLClient(); double overDueRate = sqlclient.GetOverDueRate(query, ReservationID); DateTime expectedCheckIn = Convert.ToDateTime(hObject.ExpectedCheckInTime); DateTime expectedCheckOut = Convert.ToDateTime(hObject.ExpectedCheckOutTime); double expectedHours = expectedCheckOut.Subtract(expectedCheckIn).TotalHours; bool hoursStretched = ExpectedHoursStretched(expectedHours); int calculatedHours = Convert.ToInt32(Math.Ceiling(expectedHours)); WriteToFile(string.Format("Calculated Hours for ReservationID {0}: {1}", ReservationID, calculatedHours)); double initialAmount = Convert.ToDouble(hObject.HourlyRate) * calculatedHours; double overDueAmount = GetOverDueAmount(CheckOutTime, expectedCheckOut, hoursStretched, overDueRate, Convert.ToDouble(hObject.HourlyRate)); double totalAmount = initialAmount + overDueAmount; OverDue overdue = new OverDue { InitialAmount = initialAmount, OverDueAmount = overDueAmount, TotalAmount = totalAmount, WeekendRate = isWeekend }; return(overdue); }