示例#1
0
        /// <summary>
        /// This method is responsible for translanting between coded domain names
        /// and their values, setting into UnderlyingObject the correct value.
        /// </summary>
        /// <remarks>
        /// Imagine a ICodedDomain like:
        /// 1 = "Alphanumeric"
        /// 2 = "Geographic"
        ///
        /// This method will aways set the value to 1 when passed
        /// "Alphanumeric"
        /// </remarks>
        /// <exception cref="ActiveRecrdAttributeException"></exception>
        /// <param name="wrapper"></param>
        /// <param name="propertyName"></param>
        /// <param name="displayValue"></param>
        /// <returns></returns>
        private static void SetDisplayValue(this IActiveRecord wrapper, FieldAttribute fieldAtt, string displayValue)
        {
            if (wrapper.UnderlyingObject == null)
            {
                FetchUnderlyingObject(wrapper);
            }

            if (!(fieldAtt is DomainFieldAttribute))
            {
                throw new ActiveRecordAttributeException(wrapper.GetType(), "O atributo não é tipo domínio.");
            }

            DomainFieldAttribute domainField = fieldAtt as DomainFieldAttribute;
            ICodedValueDomain    domain      = wrapper.UnderlyingObject.Fields.get_Field(domainField.Index).Domain as ICodedValueDomain;

            if (domain == null)
            {
                throw new ActiveRecordAttributeException(wrapper.GetType(), "Não foi possível localizar o domínio.");
            }

            for (var i = 0; i <= domain.CodeCount - 1; i++)
            {
                if (domain.get_Name(i) == displayValue)
                {
                    object codedValue = domain.get_Value(i);
                    wrapper.UnderlyingObject.set_Value(domainField.Index, codedValue);
                }
            }
        }
示例#2
0
        /// <summary>
        /// This method is responsible for translating between coded domain values
        /// and their names, returning the correct name.
        /// </summary>
        /// Imagine a ICodedDomain like:
        /// 1 = "Alphanumeric"
        /// 2 = "Geographic"
        ///
        /// This method will always return "Alphanumeric" for the value 1,
        /// fetched from UnderlyingObject
        /// </remarks>
        /// <exception cref="ActiveRecrdAttributeException"></exception>
        /// <param name="wrapper">IActiveRecord</param>
        /// <param name="propertyName">string</param>
        /// <returns>string</returns>
        private static string GetDisplayValue(this IActiveRecord wrapper, FieldAttribute fieldAtt)
        {
            if (wrapper.UnderlyingObject == null)
            {
                FetchUnderlyingObject(wrapper);
            }

            if (!(fieldAtt is DomainFieldAttribute))
            {
                throw new ActiveRecordAttributeException(wrapper.GetType(), "Não é possível obter o atributo de domínio.");
            }

            DomainFieldAttribute domainField = fieldAtt as DomainFieldAttribute;
            ICodedValueDomain    domain      = wrapper.UnderlyingObject.Fields.get_Field(domainField.Index).Domain as ICodedValueDomain;

            if (domain == null)
            {
                throw new ActiveRecordAttributeException(wrapper.GetType(),
                                                         String.Format("Não foi possível localizar o domínio {0}.", domainField.DomainName));
            }

            string codedValue   = wrapper.UnderlyingObject.get_Value(domainField.Index).ToString();
            string displayValue = String.Empty;

            for (int i = 0; i <= domain.CodeCount - 1; i++)
            {
                if (domain.get_Value(i).ToString() == codedValue)
                {
                    displayValue = domain.get_Name(i);
                    break;
                }
            }

            if (displayValue == String.Empty)
            {
                return(codedValue);
            }
            else
            {
                return(displayValue);
            }
        }