Exemplo n.º 1
0
        private static Hashtable GetAttributeMemberInfos(ArrayList memberInfos)
        {
            Hashtable hs = new Hashtable();

            foreach (MemberInfo info1 in memberInfos)
            {
                FieldMapAttribute attribute = (FieldMapAttribute)System.Attribute.GetCustomAttribute(info1, typeof(FieldMapAttribute));
                hs.Add(attribute, info1);
            }
            return(hs);
        }
Exemplo n.º 2
0
        public static Hashtable GetFieldNameMemberInfoMap(Type type)
        {
            Hashtable returnValue = new Hashtable();

            foreach (MemberInfo info in type.GetMembers())
            {
                FieldMapAttribute attribute = (FieldMapAttribute)System.Attribute.GetCustomAttribute(info, typeof(FieldMapAttribute));

                if (attribute != null)
                {
                    returnValue.Add(attribute.FieldName.Trim().ToLower(), info);
                }
            }

            return(returnValue);
        }
Exemplo n.º 3
0
        public static Hashtable GetNonKeyAttributeMemberInfos(TableMapAttribute tableMapAttribute, ArrayList memberInfos)
        {
            StringCollection keyFields = new StringCollection();

            keyFields.AddRange(tableMapAttribute.GetKeyFields());
            Hashtable hs = new Hashtable();

            foreach (MemberInfo info1 in memberInfos)
            {
                FieldMapAttribute attribute = (FieldMapAttribute)System.Attribute.GetCustomAttribute(info1, typeof(FieldMapAttribute));
                if (keyFields.IndexOf(attribute.FieldName) == -1)
                {
                    hs.Add(attribute, info1);
                }
            }
            return(hs);
        }
Exemplo n.º 4
0
        public virtual string GetDisplayText(string fieldName)
        {
            string returnValue = string.Empty;

            FieldInfo info = this.GetType().GetField(fieldName);

            if (info != null)
            {
                returnValue = info.GetValue(this).ToString();

                if (info.IsDefined(typeof(FieldDisplayAttribute), true))
                {
                    object[] fieldDisplayList = info.GetCustomAttributes(typeof(FieldDisplayAttribute), true);
                    foreach (FieldDisplayAttribute fieldDisplay in fieldDisplayList)
                    {
                        string descString = string.Empty;

                        if (fieldDisplay.RemoteTable.Trim().Length <= 0 &&
                            fieldDisplay.RemoteField.Trim().Length > 0)
                        {
                            FieldInfo[] fieldInfoList = this.GetType().GetFields();
                            if (fieldInfoList != null)
                            {
                                foreach (FieldInfo fieldInfo in fieldInfoList)
                                {
                                    if (fieldInfo.IsDefined(typeof(FieldMapAttribute), true))
                                    {
                                        FieldMapAttribute fieldMap = (FieldMapAttribute)Attribute.GetCustomAttribute(fieldInfo, typeof(FieldMapAttribute));
                                        if (string.Compare(fieldMap.FieldName.Trim(), fieldDisplay.RemoteField.Trim(), true) == 0)
                                        {
                                            descString = fieldInfo.GetValue(this).ToString();
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                        else
                        {
                            string sql = "SELECT {0} FROM {1} WHERE {2} = '{3}' ";
                            sql = string.Format(sql, fieldDisplay.RemoteField, fieldDisplay.RemoteTable, fieldDisplay.RemoteKey, info.GetValue(this).ToString());

                            IPersistBroker persistBroker = PersistBrokerManager.PersistBroker(true);
                            DataSet        result        = persistBroker.Query(sql);
                            if (result != null && result.Tables.Count > 0 && result.Tables[0].Rows.Count > 0)
                            {
                                descString = result.Tables[0].Rows[0][0].ToString();
                            }
                        }

                        if (descString.Trim().Length > 0)
                        {
                            if (fieldDisplay.ModifyType == FieldDisplayModifyType.Append)
                            {
                                returnValue += " - " + descString;
                            }
                            else if (fieldDisplay.ModifyType == FieldDisplayModifyType.Replace)
                            {
                                returnValue = descString;
                            }
                        }
                    }
                }
            }

            return(returnValue);
        }
Exemplo n.º 5
0
        private static void SetValue(object domainObject, MemberInfo info, object value)
        {
            if (info == null)
            {
                return;
            }

            FieldMapAttribute fa = (FieldMapAttribute)System.Attribute.GetCustomAttribute(info, typeof(FieldMapAttribute));

            if (fa == null)
            {
                return;
            }

            Type type1 = (info is FieldInfo) ? ((FieldInfo)info).FieldType : ((PropertyInfo)info).PropertyType;

            if (fa.BlobType == BlobTypes.Binary)
            {
                if (!((DomainObject)domainObject).IsBlobIgnored)
                {
                    DomainObjectUtility.SetValue(domainObject, info, value, null);
                    return;
                }
            }

            if (type1 == typeof(int))
            {
                if (value is System.DBNull)
                {
                    return;
                }
                else
                {
                    DomainObjectUtility.SetValue(domainObject, info, System.Int32.Parse(value.ToString()), null);
                    return;
                }
            }

            if (type1 == typeof(long))
            {
                if (value is System.DBNull)
                {
                    return;
                }

                DomainObjectUtility.SetValue(domainObject, info, System.Int64.Parse(value.ToString()), null);
                return;
            }

            if (type1 == typeof(double))
            {
                if (value is System.DBNull)
                {
                    return;
                }

                DomainObjectUtility.SetValue(domainObject, info, System.Double.Parse(value.ToString()), null);
                return;
            }

            if (type1 == typeof(float))
            {
                if (value is System.DBNull)
                {
                    return;
                }

                DomainObjectUtility.SetValue(domainObject, info, System.Single.Parse(value.ToString()), null);
                return;
            }

            if (type1 == typeof(decimal))
            {
                if (value is System.DBNull)
                {
                    return;
                }

                //DomainObjectUtility.SetValue(domainObject, info, System.Decimal.Parse(DomainObjectUtility.GetValueString(value)), null);
                //说明: 以前的方法在高精度的double数据转换成decimal数据的时候,报参数类型不对的错误,原因是高精度的double的数据在ToString之后会编程科学记数法,因此decimal.parse的时候会出错
                //解决方法: 私有方法专门对
                DomainObjectUtility.SetValue(domainObject, info, DomainObjectUtility.Getdecimal(value), null);
                return;
            }

            if (type1 == typeof(bool))
            {
                DomainObjectUtility.SetValue(domainObject, info, value.ToString() == "Y", null);
                return;
            }
            if (type1 == typeof(string))
            {
                DomainObjectUtility.SetValue(domainObject, info, value.ToString(), null);
                return;
            }

            if (type1 == typeof(DateTime))
            {
                DateTime result;
                DateTime.TryParse(value.ToString(), out result);
                DomainObjectUtility.SetValue(domainObject, info, result, null);

                return;
            }

            if (type1.IsEnum)
            {
                DomainObjectUtility.SetValue(domainObject, info, Enum.Parse(type1, value.ToString()), null);
                return;
            }

            DomainObjectUtility.SetValue(domainObject, info, value, null);
        }