/// <summary>
        /// Determines whether the specified attribute is required.
        /// </summary>
        /// <param name="attribute">The attribute.</param>
        /// <returns>
        ///     <c>true</c> if the specified attribute is required; otherwise, <c>false</c>.
        /// </returns>
        public static bool IsRequired(this ICrmAttributeMetadata attribute, bool checkForm)
        {
            if (checkForm)
            {
                return(attribute.IsRequired());
            }

            return(attribute.IsApplicable() && attribute.IsValidForCreate() && attribute.IsValidForAdvancedFind && attribute.IsApplicationRequiredLevel() && !attribute.IsStateAttribute() && !attribute.IsOwnerAttribute());
        }
        /// <summary>
        /// Determines whether the specified attribute is valid for update, create and read
        /// </summary>
        /// <param name="attribute">The attribute.</param>
        /// <returns>
        ///     <c>true</c> if the specified attribute is required; otherwise, <c>false</c>.
        /// </returns>
        public static bool IsAdditional(this ICrmAttributeMetadata attribute, bool checkForm)
        {
            if (checkForm)
            {
                return(attribute.IsAdditional());
            }

            return(attribute.IsApplicable() && attribute.IsValidForCreate() && (attribute.IsStateAttribute() || attribute.IsRecommendedLevel() || attribute.IsNoneLevel()));
        }
        /// <summary>
        /// The parse.
        /// </summary>
        /// <param name="metadata">
        /// The metadata.
        /// </param>
        /// <returns>
        /// </returns>
        internal static XCrmField Parse(ICrmAttributeMetadata metadata)
        {
            Assert.ArgumentNotNull(metadata, "metadata");
            XCrmField field = Parse("<f n='{0}' />".FormatWith(metadata.LogicalName ?? string.Empty));

            field.EditMode = "Always";
            field.Merge(metadata);

            return(field);
        }
        /// <summary>
        /// Gets the column.
        /// </summary>
        /// <param name="attribute">the attribute.</param>
        private GridColumn GetColumn(ICrmAttributeMetadata attribute)
        {
            bool isString = attribute.AttributeType == CrmAttributeType.String;

            return(new GridColumn
            {
                DataField = attribute.LogicalName,
                HeadingText = attribute.Title,
                AllowSorting = isString ? InheritBool.True : InheritBool.False,
                IsSearchable = isString
            });
        }
        /// <summary>
        /// Adds the specified attribute.
        /// </summary>
        /// <param name="attribute">The metadata.</param>
        public void Add(ICrmAttributeMetadata attribute)
        {
            var field = this[attribute.LogicalName];

            if (field != null)
            {
                field.Disabled = false;
                field.Merge(attribute);
            }
            else
            {
                xml.Root.Add(XElement.Parse(XCrmField.Parse(attribute).ToString()));
                fields = null;
            }
        }
        /// <summary>
        /// The merge.
        /// </summary>
        /// <param name="metadata">
        /// The metadata.
        /// </param>
        internal void Merge(ICrmAttributeMetadata metadata)
        {
            if (metadata != null && this.Name == (metadata.LogicalName ?? string.Empty))
            {
                this.Title    = metadata.Title;
                this.Required = metadata.IsRequired();

                string kind = string.Empty;
                switch (metadata.AttributeType)
                {
                case CrmAttributeType.Customer:
                case CrmAttributeType.Lookup:
                    kind = "1";
                    break;

                case CrmAttributeType.Picklist:
                    kind = "2";
                    break;

                case CrmAttributeType.State:
                    kind = "3";
                    break;

                case CrmAttributeType.Status:
                    kind = "4";
                    break;
                }

                if (!string.IsNullOrEmpty(kind))
                {
                    this.SetKind(kind);
                }

                this.DefaultValue  = string.Empty;
                this.AttributeType = metadata.AttributeType;

                if (string.IsNullOrEmpty(this.xml.GetAttributeValue("uvt")))
                {
                    this.UseValueType = this.IsRestricted ? 1 : 0;
                }
            }
        }
 /// <summary>
 /// Determines whether the specified attribute is required.
 /// </summary>
 /// <param name="attribute">The attribute.</param>
 /// <returns>
 ///     <c>true</c> if the specified attribute is required; otherwise, <c>false</c>.
 /// </returns>
 public static bool IsAdditional(this ICrmAttributeMetadata attribute)
 {
     return(attribute.IsSelectable() && (attribute.IsStateAttribute() || attribute.IsRecommendedLevel() || attribute.IsNoneLevel()));
 }
 /// <summary>
 /// Determines whether the attribute is system required.
 /// </summary>
 /// <param name="attribute">The attribute.</param>
 /// <returns>
 ///     <c>true</c> if the attribute is system required; otherwise, <c>false</c>.
 /// </returns>
 public static bool IsSystemRequredLevel(this ICrmAttributeMetadata attribute)
 {
     return(attribute.RequiredLevel == CrmAttributeRequiredLevel.SystemRequired);
 }
 /// <summary>
 /// Determines whether the specified attribute is required.
 /// </summary>
 /// <param name="attribute">The attribute.</param>
 /// <returns>
 ///     <c>true</c> if the specified attribute is required; otherwise, <c>false</c>.
 /// </returns>
 public static bool IsRequired(this ICrmAttributeMetadata attribute)
 {
     return(attribute.IsSelectable() &&
            (attribute.IsApplicationRequiredLevel() || attribute.IsSystemRequredLevel()) &&
            !attribute.IsStateAttribute() && !attribute.IsOwnerAttribute());
 }
Пример #10
0
 /// <summary>
 /// Determines whether [is already in tree] [the specified treeview].
 /// </summary>
 /// <param name="treeview">The treeview.</param>
 /// <param name="attribute">The attribute.</param>
 /// <returns>
 ///   <c>true</c> if [is already in tree] [the specified treeview]; otherwise, <c>false</c>.
 /// </returns>
 internal static bool IsAlreadyInTree(this TreeView treeview, ICrmAttributeMetadata attribute)
 {
     return(treeview.Nodes.Count < 2 || treeview.Nodes[1].Nodes.Contains(attribute.LogicalName));
 }
 /// <summary>
 /// Determines whether the attribute is a state attribute.
 /// </summary>
 /// <param name="attribute">The attribute.</param>
 /// <returns>
 ///     <c>true</c> if the attribute is a state attribute; otherwise, <c>false</c>.
 /// </returns>
 public static bool IsStateAttribute(this ICrmAttributeMetadata attribute)
 {
     return(attribute.AttributeType == CrmAttributeType.State);
 }
 /// <summary>
 /// Determines whether the attribute is a owner attribute.
 /// </summary>
 /// <param name="attribute">The attribute.</param>
 /// <returns>
 ///     <c>true</c> if the attribute is a owner attribute; otherwise, <c>false</c>.
 /// </returns>
 public static bool IsOwnerAttribute(this ICrmAttributeMetadata attribute)
 {
     return(attribute.AttributeType == CrmAttributeType.Owner);
 }
 /// <summary>
 /// Determines whether the specified attribute is unfit.
 /// </summary>
 /// <param name="attribute">The attribute.</param>
 /// <returns>
 /// <c>true</c> if the specified attribute is unfit; otherwise, <c>false</c>.
 /// </returns>
 public static bool IsApplicable(this ICrmAttributeMetadata attribute)
 {
     return(attribute.AttributeType != CrmAttributeType.UniqueIdentifier && attribute.AttributeType != CrmAttributeType.PrimaryKey);
 }
 /// <summary>
 /// Determines whether the attribute has a none level.
 /// </summary>
 /// <param name="attribute">The attribute.</param>
 /// <returns>
 ///     <c>true</c> if the attribute has a none level; otherwise, <c>false</c>.
 /// </returns>
 public static bool IsNoneLevel(this ICrmAttributeMetadata attribute)
 {
     return(attribute.RequiredLevel == CrmAttributeRequiredLevel.None);
 }
 /// <summary>
 /// Determines whether the specified attribute is valid for create and read
 /// </summary>
 /// <param name="attribute">The attribute.</param>
 /// <returns>
 ///     <c>true</c> if the specified attribute is valid; otherwise, <c>false</c>.
 /// </returns>
 public static bool IsValidForCreate(this ICrmAttributeMetadata attribute)
 {
     return(attribute.IsValidForCreate && attribute.IsValidForRead);
 }
 /// <summary>
 /// Determines whether the attribute has a required level.
 /// </summary>
 /// <param name="attribute">The attribute.</param>
 /// <returns>
 ///     <c>true</c> if the attribute has a required level; otherwise, <c>false</c>.
 /// </returns>
 public static bool IsApplicationRequiredLevel(this ICrmAttributeMetadata attribute)
 {
     return(attribute.RequiredLevel == CrmAttributeRequiredLevel.ApplicationRequired);
 }
 /// <summary>
 /// Determines whether the attribute is recommended.
 /// </summary>
 /// <param name="attribute">The attribute.</param>
 /// <returns>
 ///     <c>true</c> if the attribute is recommended; otherwise, <c>false</c>.
 /// </returns>
 public static bool IsRecommendedLevel(this ICrmAttributeMetadata attribute)
 {
     return(attribute.RequiredLevel == CrmAttributeRequiredLevel.Recommended);
 }
 /// <summary>
 /// Determines whether the specified attribute is valid for update
 /// </summary>
 /// <param name="attribute">The attribute.</param>
 /// <returns>
 ///     <c>true</c> if the specified attribute is valid; otherwise, <c>false</c>.
 /// </returns>
 public static bool IsValidForUpdate(this ICrmAttributeMetadata attribute)
 {
     return(attribute.IsValidForUpdate);
 }
 /// <summary>
 /// Determines whether the specified attribute is required.
 /// </summary>
 /// <param name="attribute">The attribute.</param>
 /// <returns>
 ///     <c>true</c> if the specified attribute is selectable; otherwise, <c>false</c>.
 /// </returns>
 public static bool IsSelectable(this ICrmAttributeMetadata attribute)
 {
     return(attribute.IsApplicable() && attribute.IsValidForAdvancedFind);
 }