コード例 #1
0
        /// <summary>
        /// Checks whether a Partner with a certain PartnerKey and a range of valid PartnerClasses exists.
        /// </summary>
        /// <param name="APartnerKey">PartnerKey.</param>
        /// <param name="AValidPartnerClasses">An array of PartnerClasses. If the Partner exists, but its
        /// PartnerClass isn't in the array, a TVerificationResult is still returned.</param>
        /// <param name="AZeroPartnerKeyIsValid">Set to true if <paramref name="APartnerKey" /> 0 should be considered
        /// as valid (Default: false)</param>
        /// <param name="AErrorMessageText">Text that should be prepended to the ResultText. (Default: empty string)</param>
        /// <param name="AResultContext">ResultContext (Default: null).</param>
        /// <param name="AResultColumn">Which <see cref="System.Data.DataColumn" /> failed (can be null). (Default: null).</param>
        /// <param name="AResultControl">Which <see cref="System.Windows.Forms.Control" /> is involved (can be null). (Default: null).</param>
        /// <returns>Null if the Partner exists and its PartnerClass is in the <paramref name="AValidPartnerClasses" />
        /// array. If the Partner exists, but its PartnerClass isn't in the array, a TVerificationResult
        /// with details about the error is returned. This is also the case if the Partner doesn't exist at all
        /// or got merged into another Partner, or if <paramref name="APartnerKey" /> is 0 and <paramref name="AZeroPartnerKeyIsValid" />
        /// is false.
        /// </returns>
        public static TVerificationResult IsValidPartner(Int64 APartnerKey, TPartnerClass[] AValidPartnerClasses,
            bool AZeroPartnerKeyIsValid = false, string AErrorMessageText = "", object AResultContext = null,
            System.Data.DataColumn AResultColumn = null, System.Windows.Forms.Control AResultControl = null)
        {
            TVerificationResult ReturnValue = null;
            string ShortName;
            TPartnerClass PartnerClass;
            bool PartnerExists;
            bool IsMergedPartner;
            string ValidPartnerClassesStr = String.Empty;
            bool PartnerClassValid = false;
            string PartnerClassInvalidMessageStr = Catalog.GetString("The Partner Class of the Partner needs to be '{0}', but it is '{1}'.");
            string PartnerClassConcatStr = Catalog.GetString(" or ");

            if ((AZeroPartnerKeyIsValid)
                && (APartnerKey == 0))
            {
                return null;
            }
            else if ((!AZeroPartnerKeyIsValid)
                     && (APartnerKey == 0))
            {
                if (AErrorMessageText == String.Empty)
                {
                    ReturnValue = new TVerificationResult(AResultContext, ErrorCodes.GetErrorInfo(
                            PetraErrorCodes.ERR_PARTNERKEY_INVALID_NOZERO, new string[] { APartnerKey.ToString("0000000000") }));
                }
                else
                {
                    ReturnValue = new TVerificationResult(AResultContext, ErrorCodes.GetErrorInfo(
                            PetraErrorCodes.ERR_PARTNERKEY_INVALID_NOZERO));
                    ReturnValue.OverrideResultText(AErrorMessageText + Environment.NewLine + ReturnValue.ResultText);
                }
            }
            else
            {
                bool VerificationOK = TSharedPartnerValidationHelper.VerifyPartner(APartnerKey, AValidPartnerClasses, out PartnerExists,
                    out ShortName, out PartnerClass, out IsMergedPartner);

                if ((!VerificationOK)
                    || (IsMergedPartner))
                {
                    if (AErrorMessageText == String.Empty)
                    {
                        ReturnValue = new TVerificationResult(AResultContext, ErrorCodes.GetErrorInfo(
                                PetraErrorCodes.ERR_PARTNERKEY_INVALID, new string[] { APartnerKey.ToString("0000000000") }));
                    }
                    else
                    {
                        ReturnValue = new TVerificationResult(AResultContext, ErrorCodes.GetErrorInfo(
                                PetraErrorCodes.ERR_PARTNERKEY_INVALID, new string[] { APartnerKey.ToString("0000000000") }));
                        ReturnValue.OverrideResultText(AErrorMessageText + Environment.NewLine + ReturnValue.ResultText);
                    }

                    if ((PartnerExists)
                        && (!IsMergedPartner))
                    {
                        if ((AValidPartnerClasses.Length == 1)
                            && (AValidPartnerClasses[0] != PartnerClass))
                        {
                            ReturnValue.OverrideResultText(ReturnValue.ResultText + " " +
                                String.Format(PartnerClassInvalidMessageStr, AValidPartnerClasses[0], PartnerClass));
                        }
                        else if (AValidPartnerClasses.Length > 1)
                        {
                            for (int Counter = 0; Counter < AValidPartnerClasses.Length; Counter++)
                            {
                                ValidPartnerClassesStr += "'" + AValidPartnerClasses[Counter] + "'" + PartnerClassConcatStr;

                                if (AValidPartnerClasses[Counter] == PartnerClass)
                                {
                                    PartnerClassValid = true;
                                }
                            }

                            if (!PartnerClassValid)
                            {
                                ValidPartnerClassesStr = ValidPartnerClassesStr.Substring(0,
                                    ValidPartnerClassesStr.Length - PartnerClassConcatStr.Length - 1);      // strip off "' or "
                                ReturnValue.OverrideResultText(ReturnValue.ResultText + " " +
                                    String.Format(PartnerClassInvalidMessageStr, ValidPartnerClassesStr, PartnerClass));
                            }
                        }
                    }
                }
            }

            if ((ReturnValue != null)
                && (AResultColumn != null))
            {
                ReturnValue = new TScreenVerificationResult(ReturnValue, AResultColumn, AResultControl);
            }

            return ReturnValue;
        }
コード例 #2
0
ファイル: Main.cs プロジェクト: js1987/openpetragit
        /// <summary>
        /// Checks whether two <see cref="TVerificationResult" />s are completely identical. The comparison
        /// takes all the data they hold into consideration.
        /// </summary>
        /// <param name="AVerificationResult1">First <see cref="TVerificationResult" />.</param>
        /// <param name="AVerificationResult2">Second <see cref="TVerificationResult" />.</param>
        /// <param name="ACompareResultContextsAsStrings">Set to true to compare the ResultContexts not as objects, but
        /// compare what a call of the .ToString() Method on the two object yields. (Default: false.)</param>
        /// <param name="ATreatUserControlAndFormContextsAsIdentical">Set to true to treat a UserControl and the Form
        /// where it is placed on as identical ResultContexts. (Default: false.)</param>
        /// <returns>True if the two <see cref="TVerificationResult" />s are completely identical,
        /// otherwise false.</returns>
        public static bool AreVerificationResultsIdentical(TVerificationResult AVerificationResult1, TVerificationResult AVerificationResult2,
            bool ACompareResultContextsAsStrings = false, bool ATreatUserControlAndFormContextsAsIdentical = false)
        {
            if ((AVerificationResult1 == null)
                || (AVerificationResult2 == null))
            {
                if ((AVerificationResult1 == null)
                    && (AVerificationResult2 == null))
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            else
            {
                if (AVerificationResult1.ResultCode != AVerificationResult2.ResultCode)
                {
                    return false;
                }

                if (!ACompareResultContextsAsStrings)
                {
                    if (ATreatUserControlAndFormContextsAsIdentical)
                    {
                        if ((AVerificationResult1.ResultContext is UserControl)
                            || (AVerificationResult2.ResultContext is UserControl))
                        {
                            if ((AVerificationResult1.ResultContext is UserControl)
                                && (AVerificationResult2.ResultContext is Form))
                            {
                                if (((UserControl)AVerificationResult1.ResultContext)
                                    != AVerificationResult2.ResultContext)
                                {
                                    return false;
                                }
                            }
                            else if ((AVerificationResult2.ResultContext is UserControl)
                                     && (AVerificationResult1.ResultContext is Form))
                            {
                                if (((UserControl)AVerificationResult2.ResultContext).ParentForm
                                    != AVerificationResult1.ResultContext)
                                {
                                    return false;
                                }
                            }
                        }
                        else if (AVerificationResult1.ResultContext != AVerificationResult2.ResultContext)
                        {
                            return false;
                        }
                    }
                    else if (AVerificationResult1.ResultContext != AVerificationResult2.ResultContext)
                    {
                        return false;
                    }
                }
                else
                {
                    if (ATreatUserControlAndFormContextsAsIdentical)
                    {
                        if ((AVerificationResult1.ResultContext is UserControl)
                            || (AVerificationResult2.ResultContext is UserControl))
                        {
                            if ((AVerificationResult1.ResultContext is UserControl)
                                && (AVerificationResult2.ResultContext is Form))
                            {
                                if (((UserControl)AVerificationResult1.ResultContext).ParentForm.ToString()
                                    != AVerificationResult2.ResultContext.ToString())
                                {
                                    return false;
                                }
                            }
                            else if ((AVerificationResult2.ResultContext is UserControl)
                                     && (AVerificationResult1.ResultContext is Form))
                            {
                                if (((UserControl)AVerificationResult2.ResultContext).ParentForm.ToString()
                                    != AVerificationResult1.ResultContext.ToString())
                                {
                                    return false;
                                }
                            }
                        }
                        else if (AVerificationResult1.ResultContext.ToString() != AVerificationResult2.ResultContext.ToString())
                        {
                            return false;
                        }
                    }
                    else if (AVerificationResult1.ResultContext.ToString() != AVerificationResult2.ResultContext.ToString())
                    {
                        return false;
                    }
                }

                if (AVerificationResult1.ResultSeverity != AVerificationResult2.ResultSeverity)
                {
                    return false;
                }

                if (AVerificationResult1.ResultText != AVerificationResult2.ResultText)
                {
                    // There may be some specific result codes that can allow the result text to differ so long as everything else is ok.
                    // This will happen when the result text changes with the user's INPUT (examples of this are rare!)
                    // Normally result text is either constant or depends on the current database content which will be constant during a verification run.
                    // But, for example, the result text for a duplicate record contains a hint indicating the entered data that might be wrong.
                    // So if the user makes the same error twice but with two different attempts at making a non-duplicate, we need to accept the result
                    //    as the same but update the old text, replacing it with the latest.
                    // Other examples of this behaviour may be created in the future, and can be OR'd with the ERR_DUPLICATE_RECORD case
                    if (AVerificationResult1.ResultCode == CommonErrorCodes.ERR_DUPLICATE_RECORD)
                    {
                        // ensure that the ResultText is the most recent instance
                        AVerificationResult1.OverrideResultText(AVerificationResult2.ResultText);
                    }
                    else
                    {
                        return false;
                    }
                }

                if (AVerificationResult1.ResultTextCaption != AVerificationResult2.ResultTextCaption)
                {
                    return false;
                }
            }

            return true;
        }
コード例 #3
0
        /// <summary>
        /// Checks whether a Partner with Field 0 has a non-gift Motivation Group code.
        /// </summary>
        /// <param name="APartnerKey">PartnerKey.</param>
        /// <param name="APartnerField">The field associated with the partner key</param>
        /// <param name="AMotivationGroup">The current motivation group</param>
        /// <param name="AErrorMessageText">Text that should be prepended to the ResultText. (Default: empty string)</param>
        /// <param name="AResultContext">ResultContext (Default: null).</param>
        /// <param name="AResultColumn">Which <see cref="System.Data.DataColumn" /> failed (can be null). (Default: null).</param>
        /// <param name="AResultControl">Which <see cref="System.Windows.Forms.Control" /> is involved (can be null). (Default: null).</param>
        /// <returns>Null if the Partner Field is non-zero or Motivation Group code is not Gift.
        ///   If the Partner Field is zero and Motivation Group is Gift, a TVerificationResult
        ///   with details about the error is returned.
        /// </returns>
        public static TVerificationResult IsValidRecipientFieldForMotivationGroup(Int64 APartnerKey, Int64 APartnerField,
            string AMotivationGroup, string AErrorMessageText = "", object AResultContext = null,
            System.Data.DataColumn AResultColumn = null, System.Windows.Forms.Control AResultControl = null)
        {
            TVerificationResult ReturnValue = null;

            if ((APartnerField == 0) && (AMotivationGroup == MFinanceConstants.MOTIVATION_GROUP_GIFT))
            {
                if (AErrorMessageText == String.Empty)
                {
                    ReturnValue = new TVerificationResult(AResultContext, ErrorCodes.GetErrorInfo(
                            PetraErrorCodes.ERR_RECIPIENT_FIELD_MOTIVATION_GROUP, new string[] { APartnerKey.ToString() }));
                }
                else
                {
                    ReturnValue = new TVerificationResult(AResultContext, ErrorCodes.GetErrorInfo(
                            PetraErrorCodes.ERR_RECIPIENT_FIELD_MOTIVATION_GROUP));
                    ReturnValue.OverrideResultText(AErrorMessageText + Environment.NewLine + ReturnValue.ResultText);
                }
            }
            else
            {
                return null;
            }

            if ((ReturnValue != null)
                && (AResultColumn != null))
            {
                ReturnValue = new TScreenVerificationResult(ReturnValue, AResultColumn, AResultControl);
            }

            return ReturnValue;
        }