/// <summary> /// Checks whether the date is within a specified date range. Null values are accepted. /// </summary> /// <remarks>This Method is capable of returning varying<see cref="TVerificationResult" /> objects! The objects /// returned are determined by the values specified for <paramref name="ALowerRangeCheckType" /> and /// <paramref name="AUpperRangeCheckType" />!</remarks> /// <param name="ADate">Date to check.</param> /// <param name="ALowerDateRangeEnd">Lower end of the valid Date Range.</param> /// <param name="AUpperDateRangeEnd">Upper end of the valid Date Range.</param> /// <param name="ADescription">Name of the date value.</param> /// <param name="ALowerRangeCheckType">Type of Date Check: lower end of the valid Date Range (defaults to <see cref="TDateBetweenDatesCheckType.dbdctUnspecific" />).</param> /// <param name="AUpperRangeCheckType">Type of Date Check: upper end of the valid Date Range (defaults to <see cref="TDateBetweenDatesCheckType.dbdctUnspecific" />).</param> /// <param name="AResultContext">Context of verification (can be null).</param> /// <param name="AResultColumn">Which <see cref="System.Data.DataColumn" /> failed (can be null).</param> /// <param name="AResultControl">Which <see cref="System.Windows.Forms.Control" /> is involved (can be null).</param> /// <returns>Null if the date <paramref name="ADate" /> is between the lower and the upper end of the Date Range specified /// (lower and upper end dates are included), otherwise a verification result with a message that uses /// <paramref name="ADescription" />. /// </returns> public static TVerificationResult IsDateBetweenDates(DateTime? ADate, DateTime? ALowerDateRangeEnd, DateTime? AUpperDateRangeEnd, String ADescription, TDateBetweenDatesCheckType ALowerRangeCheckType = TDateBetweenDatesCheckType.dbdctUnspecific, TDateBetweenDatesCheckType AUpperRangeCheckType = TDateBetweenDatesCheckType.dbdctUnspecific, object AResultContext = null, System.Data.DataColumn AResultColumn = null, System.Windows.Forms.Control AResultControl = null) { TVerificationResult ReturnValue = null; DateTime TheDate = TSaveConvert.ObjectToDate(ADate); DateTime LowerDateRangeEndDate = TSaveConvert.ObjectToDate(ALowerDateRangeEnd); DateTime UpperDateRangeEndDate = TSaveConvert.ObjectToDate(AUpperDateRangeEnd); String Description = THelper.NiceValueDescription(ADescription); if ((!ADate.HasValue) || (!ALowerDateRangeEnd.HasValue) || (!AUpperDateRangeEnd.HasValue)) { return null; } // Check if ((TheDate < LowerDateRangeEndDate) || (TheDate > UpperDateRangeEndDate)) { if ((ALowerRangeCheckType == TDateBetweenDatesCheckType.dbdctUnspecific) && (AUpperRangeCheckType == TDateBetweenDatesCheckType.dbdctUnspecific)) { ReturnValue = GetUnspecificDateRangeCheckVerificationResult(LowerDateRangeEndDate, UpperDateRangeEndDate, Description, AResultContext); } else if (TheDate < LowerDateRangeEndDate) { if (ALowerRangeCheckType == TDateBetweenDatesCheckType.dbdctNoPastDate) { ReturnValue = new TVerificationResult(AResultContext, ErrorCodes.GetErrorInfo(CommonErrorCodes.ERR_NOPASTDATE, CommonResourcestrings.StrInvalidDateEntered + Environment.NewLine + StrDateMustNotBePastDate, new string[] { Description })); } else if (ALowerRangeCheckType == TDateBetweenDatesCheckType.dbdctUnrealisticDate) { ReturnValue = new TVerificationResult(AResultContext, ErrorCodes.GetErrorInfo(CommonErrorCodes.ERR_UNREALISTICDATE_ERROR, CommonResourcestrings.StrInvalidDateEntered + Environment.NewLine + StrDateNotSensible, new string[] { Description })); } else { ReturnValue = GetUnspecificDateRangeCheckVerificationResult(LowerDateRangeEndDate, UpperDateRangeEndDate, Description, AResultContext); } } else if (TheDate > UpperDateRangeEndDate) { if (AUpperRangeCheckType == TDateBetweenDatesCheckType.dbdctNoFutureDate) { ReturnValue = new TVerificationResult(AResultContext, ErrorCodes.GetErrorInfo(CommonErrorCodes.ERR_NOFUTUREDATE, CommonResourcestrings.StrInvalidDateEntered + Environment.NewLine + StrDateMustNotBeFutureDate, new string[] { Description })); } else if (AUpperRangeCheckType == TDateBetweenDatesCheckType.dbdctUnrealisticDate) { ReturnValue = new TVerificationResult(AResultContext, ErrorCodes.GetErrorInfo(CommonErrorCodes.ERR_UNREALISTICDATE_ERROR, CommonResourcestrings.StrInvalidDateEntered + Environment.NewLine + StrDateNotSensible, new string[] { Description })); } else { ReturnValue = GetUnspecificDateRangeCheckVerificationResult(LowerDateRangeEndDate, UpperDateRangeEndDate, Description, AResultContext); } } if (AResultColumn != null) { ReturnValue = new TScreenVerificationResult(ReturnValue, AResultColumn, AResultControl); } } else { ReturnValue = null; } return ReturnValue; }
/// <summary> /// Checks whether the date is within a specified date range. Null values are accepted. /// </summary> /// <remarks>This Method is capable of returning varying<see cref="TVerificationResult" /> objects! The objects /// returned are determined by the values specified for <paramref name="ALowerRangeCheckType" /> and /// <paramref name="AUpperRangeCheckType" />!</remarks> /// <param name="ADate">Date to check.</param> /// <param name="ALowerDateRangeEnd">Lower end of the valid Date Range.</param> /// <param name="AUpperDateRangeEnd">Upper end of the valid Date Range.</param> /// <param name="ADescription">Name of the date value.</param> /// <param name="ALowerRangeCheckType">Type of Date Check: lower end of the valid Date Range (defaults to <see cref="TDateBetweenDatesCheckType.dbdctUnspecific" />).</param> /// <param name="AUpperRangeCheckType">Type of Date Check: upper end of the valid Date Range (defaults to <see cref="TDateBetweenDatesCheckType.dbdctUnspecific" />).</param> /// <param name="AResultContext">Context of verification (can be null).</param> /// <param name="AResultColumn">Which <see cref="System.Data.DataColumn" /> failed (can be null).</param> /// <returns>Null if the date <paramref name="ADate" /> is between the lower and the upper end of the Date Range specified /// (lower and upper end dates are included), otherwise a verification result with a message that uses /// <paramref name="ADescription" />. /// </returns> public static TVerificationResult IsDateBetweenDates(DateTime?ADate, DateTime?ALowerDateRangeEnd, DateTime?AUpperDateRangeEnd, String ADescription, TDateBetweenDatesCheckType ALowerRangeCheckType = TDateBetweenDatesCheckType.dbdctUnspecific, TDateBetweenDatesCheckType AUpperRangeCheckType = TDateBetweenDatesCheckType.dbdctUnspecific, object AResultContext = null, System.Data.DataColumn AResultColumn = null) { TVerificationResult ReturnValue = null; DateTime TheDate = TSaveConvert.ObjectToDate(ADate); DateTime LowerDateRangeEndDate = TSaveConvert.ObjectToDate(ALowerDateRangeEnd); DateTime UpperDateRangeEndDate = TSaveConvert.ObjectToDate(AUpperDateRangeEnd); String Description = THelper.NiceValueDescription(ADescription); if ((!ADate.HasValue) || (!ALowerDateRangeEnd.HasValue) || (!AUpperDateRangeEnd.HasValue)) { return(null); } // Check if ((TheDate < LowerDateRangeEndDate) || (TheDate > UpperDateRangeEndDate)) { if ((ALowerRangeCheckType == TDateBetweenDatesCheckType.dbdctUnspecific) && (AUpperRangeCheckType == TDateBetweenDatesCheckType.dbdctUnspecific)) { ReturnValue = GetUnspecificDateRangeCheckVerificationResult(LowerDateRangeEndDate, UpperDateRangeEndDate, Description, AResultContext); } else if (TheDate < LowerDateRangeEndDate) { if (ALowerRangeCheckType == TDateBetweenDatesCheckType.dbdctNoPastDate) { ReturnValue = new TVerificationResult(AResultContext, ErrorCodes.GetErrorInfo(CommonErrorCodes.ERR_NOPASTDATE, CommonResourcestrings.StrInvalidDateEntered + Environment.NewLine + StrDateMustNotBePastDate, new string[] { Description })); } else if (ALowerRangeCheckType == TDateBetweenDatesCheckType.dbdctUnrealisticDate) { ReturnValue = new TVerificationResult(AResultContext, ErrorCodes.GetErrorInfo(CommonErrorCodes.ERR_UNREALISTICDATE_ERROR, CommonResourcestrings.StrInvalidDateEntered + Environment.NewLine + StrDateNotSensible, new string[] { Description })); } else { ReturnValue = GetUnspecificDateRangeCheckVerificationResult(LowerDateRangeEndDate, UpperDateRangeEndDate, Description, AResultContext); } } else if (TheDate > UpperDateRangeEndDate) { if (AUpperRangeCheckType == TDateBetweenDatesCheckType.dbdctNoFutureDate) { ReturnValue = new TVerificationResult(AResultContext, ErrorCodes.GetErrorInfo(CommonErrorCodes.ERR_NOFUTUREDATE, CommonResourcestrings.StrInvalidDateEntered + Environment.NewLine + StrDateMustNotBeFutureDate, new string[] { Description })); } else if (AUpperRangeCheckType == TDateBetweenDatesCheckType.dbdctUnrealisticDate) { ReturnValue = new TVerificationResult(AResultContext, ErrorCodes.GetErrorInfo(CommonErrorCodes.ERR_UNREALISTICDATE_ERROR, CommonResourcestrings.StrInvalidDateEntered + Environment.NewLine + StrDateNotSensible, new string[] { Description })); } else { ReturnValue = GetUnspecificDateRangeCheckVerificationResult(LowerDateRangeEndDate, UpperDateRangeEndDate, Description, AResultContext); } } if (AResultColumn != null) { ReturnValue = new TScreenVerificationResult(ReturnValue, AResultColumn); } } else { ReturnValue = null; } return(ReturnValue); }