Esempio n. 1
0
        /// <summary>
        /// Verifies the Date value.
        /// </summary>
        /// <param name="AValueText">the new value of the textbox</param>
        /// <param name="AShowVerificationError">Set to true to show errors if verification
        /// failed, or to false to suppress error messages</param>
        /// <returns>true if the Control has a valid date</returns>
        private Boolean VerifyDate(string AValueText, Boolean AShowVerificationError)
        {
            TVerificationResult DateVerificationResult = null;

            if (!FAllowVerification)
            {
                return(true);
            }

            if (CountVerifyDateRunningInstances > 0)
            {
                // the LostFocus and the DateValidated events overlap, and would display too messageboxes if the text can not be parsed for a date
                return(false);
            }

            CountVerifyDateRunningInstances++;

            try
            {
                // Convert TextBox's Text to Date
                DateTime Text2Date = DataBinding.LongDateStringToDateTime2(
                    AValueText,
                    FDateDescription,
                    out DateVerificationResult,
                    AShowVerificationError, null);

                if (DateVerificationResult != null)
                {
                    // Date conversion was NOT successful
                    return(false);
                }
                else
                {
                    // Conversion was successful
                    if (!AllowFutureDate)
                    {
                        DateVerificationResult = TDateChecks.IsCurrentOrPastDate(Text2Date, FDateDescription);

                        if (DateVerificationResult != null)
                        {
                            if (AShowVerificationError)
                            {
                                // Show appropriate Error Message to the user
                                TMessages.MsgGeneralError(DateVerificationResult, this.FindForm().GetType());
                            }

                            return(false);
                        }
                    }

                    if (!AllowPastDate)
                    {
                        DateVerificationResult = TDateChecks.IsCurrentOrFutureDate(Text2Date, FDateDescription);

                        if (DateVerificationResult != null)
                        {
                            if (AShowVerificationError)
                            {
                                // Show appropriate Error Message to the user
                                TMessages.MsgGeneralError(DateVerificationResult, this.FindForm().GetType());
                            }

                            return(false);
                        }
                    }

                    if (!FAllowEmpty)
                    {
                        DateVerificationResult = TDateChecks.IsNotUndefinedDateTime(Text2Date, FDateDescription);

                        if (DateVerificationResult != null)
                        {
                            if (AShowVerificationError)
                            {
                                // Show appropriate Error Message to the user
                                TMessages.MsgGeneralError(DateVerificationResult, this.FindForm().GetType());
                            }

                            return(false);
                        }
                    }

                    // Store the Date for later use
                    if (Text2Date != DateTime.MinValue)
                    {
                        FDate = Text2Date;
                    }
                    else
                    {
                        FDate = null;
                    }

                    // set tag to "SuppressChangeDetection" so text change is not detected by TFrmPetraEditUtils.MultiEventHandler
                    object OriginalTag = this.Tag;
                    this.Tag = MCommonResourcestrings.StrCtrlSuppressChangeDetection;
                    FSuppressTextChangeEvent = true;

                    // Now update the TextBox's Text with the newly formatted date
                    if (FDate != null)
                    {
                        if (DateTime.Compare(minimalDateValue, FDate.Value) > 0)
                        {
                            TMessages.DateValueMessageMinUnderrun(minimalDateValue);
                        }

                        if (DateTime.Compare(FDate.Value, maximalDateValue) > 0)
                        {
                            TMessages.DateValueMessageMaxOverrun(maximalDateValue);
                        }

                        String NewText = DataBinding.DateTimeToLongDateString2(FDate.Value);

                        if (this.Text != NewText) // Don't set anything that's unchanged
                        {
                            base.Text = NewText;  // I'm not calling my own Text Property, because I don't want to end up back here...
                        }
                    }
                    else
                    {
                        if (this.Text != "") // Don't set anything that's unchaged
                        {
                            base.Text = "";  // I'm not calling my own Text Property, because I don't want to end up back here...
                        }
                    }

                    // reset tag to original state
                    this.Tag = OriginalTag;
                    FSuppressTextChangeEvent = false;
                    return(true);
                }
            }
            finally
            {
                FDateVerificationResult = DateVerificationResult;

                CountVerifyDateRunningInstances--;
            }
        }