示例#1
0
        public override void CheckConstraints()
        {
            DateTime value = (DateTime)ValueDateTime;

            this._Value = value.ToDBDateTimeFormat();

            DateTime min = DateTime.Now;

            if (string.IsNullOrEmpty(Minimum))
            {
                goto CheckMax;
            }

            #region Checking Minimum

            if (!DateTime.TryParse(Minimum, out min))
            {
                min = DateTime.Now;
            }

            if (Minimum.ToUpper().Equals("CURRENTDATETIME+"))
            {
                if (value < min)
                {
                    this._ParseResult         = new IdpeMessage(IdpeMessageCodes.IDPE_TYPE_DATA_VALIDATION_FAILED_MINIMUM_DATETIME_SERVER);
                    this._ParseResult.Message = string.Format(this._ParseResult.Message, PrintRowColPosition(), Value, min);
                }
            }
            else if (Minimum.ToUpper().Equals("CURRENTDATETIME-"))
            {
                if (value > min)
                {
                    this._ParseResult         = new IdpeMessage(IdpeMessageCodes.IDPE_TYPE_DATA_VALIDATION_FAILED_MAXIMUM_DATETIME_SERVER);
                    this._ParseResult.Message = string.Format(this._ParseResult.Message, PrintRowColPosition(), Value, min);
                }
            }
            else if (Minimum.ToUpper().Equals("CURRENTDATE+"))
            {
                DateTime d1 = (DateTime)value.ToShortDateString().ParseDateTime();
                DateTime d2 = (DateTime)min.ToShortDateString().ParseDateTime();

                if (d1 < d2)
                {
                    this._ParseResult         = new IdpeMessage(IdpeMessageCodes.IDPE_TYPE_DATA_VALIDATION_FAILED_MINIMUM_DATE_SERVER);
                    this._ParseResult.Message = string.Format(this._ParseResult.Message, PrintRowColPosition(), Value, d2);
                }
            }
            else if (Minimum.ToUpper().Equals("CURRENTDATE-"))
            {
                DateTime d1 = (DateTime)value.ToShortDateString().ParseDateTime();
                DateTime d2 = (DateTime)min.ToShortDateString().ParseDateTime();

                if (d1 > d2)
                {
                    this._ParseResult         = new IdpeMessage(IdpeMessageCodes.IDPE_TYPE_DATA_VALIDATION_FAILED_MAXIMUM_DATE_SERVER);
                    this._ParseResult.Message = string.Format(this._ParseResult.Message, PrintRowColPosition(), Value, d2);
                }
            }
            #endregion Checking Minimum

CheckMax:
            if (string.IsNullOrEmpty(Maximum))
            {
                return;                                //no need to check further
            }
            #region Checking Maximum
            DateTime max = DateTime.Now;
            if (!DateTime.TryParse(Maximum, out max))
            {
                max = DateTime.Now;
            }

            //As we have both Minimum & Maximum, lets try a logical validation
            //logical validation starts
            if ((!string.IsNullOrEmpty(Minimum)) && (max <= min))
            {
                throw new Exception(string.Format("Attribute {0} has some invalid configuration. Please check Minimum and Maximum, else contact administrator or read manual for more details.", ColumnName));
            }
            //logical validation ends

            if (Maximum.ToUpper().Equals("CURRENTDATETIME+"))
            {
                if (value < max)
                {
                    this._ParseResult         = new IdpeMessage(IdpeMessageCodes.IDPE_TYPE_DATA_VALIDATION_FAILED_MINIMUM_DATETIME_SERVER);
                    this._ParseResult.Message = string.Format(this._ParseResult.Message, PrintRowColPosition(), Value, max);
                }
            }
            else if (Maximum.ToUpper().Equals("CURRENTDATETIME-"))
            {
                if (value > max)
                {
                    this._ParseResult         = new IdpeMessage(IdpeMessageCodes.IDPE_TYPE_DATA_VALIDATION_FAILED_MAXIMUM_DATETIME_SERVER);
                    this._ParseResult.Message = string.Format(this._ParseResult.Message, PrintRowColPosition(), Value, min);
                }
            }
            else if (Maximum.ToUpper().Equals("CURRENTDATE+"))
            {
                DateTime d1 = (DateTime)value.ToShortDateString().ParseDateTime();
                DateTime d2 = (DateTime)max.ToShortDateString().ParseDateTime();

                if (d1 < d2)
                {
                    this._ParseResult         = new IdpeMessage(IdpeMessageCodes.IDPE_TYPE_DATA_VALIDATION_FAILED_MINIMUM_DATE_SERVER);
                    this._ParseResult.Message = string.Format(this._ParseResult.Message, PrintRowColPosition(), Value, d2);
                }
            }
            else if (Maximum.ToUpper().Equals("CURRENTDATE-"))
            {
                DateTime d1 = (DateTime)value.ToShortDateString().ParseDateTime();
                DateTime d2 = (DateTime)max.ToShortDateString().ParseDateTime();

                if (d1 > d2)
                {
                    this._ParseResult         = new IdpeMessage(IdpeMessageCodes.IDPE_TYPE_DATA_VALIDATION_FAILED_MAXIMUM_DATE_SERVER);
                    this._ParseResult.Message = string.Format(this._ParseResult.Message, PrintRowColPosition(), Value, d2);
                }
            }
            #endregion Checking Maximum

            if (!((value >= min) && (value <= max)))
            {
                this._ParseResult         = new IdpeMessage(IdpeMessageCodes.IDPE_TYPE_DATA_VALIDATION_FAILED_MINIMUM_MAXIMUM_DATE);
                this._ParseResult.Message = string.Format(this._ParseResult.Message, PrintRowColPosition(), value, min, max);
            }
        }