Esempio n. 1
0
        public static void FetchREFEntity(object objEntity, REFAttribute refAtt, DataTable table)
        {
            int rindex = -1;//根据objEntity的Id属性,在table中找到对应的行数

            for (int i = 0; i < table.Rows.Count; i++)
            {
                if (((BaseEntity)objEntity).Id == Convert.ToInt64(table.Rows[i]["E_" + objEntity.GetType().Name + "Id"]))
                {
                    rindex = i;
                    break;
                }
            }
            //对象的该引用属性为空值
            if (table.Rows[rindex]["E_" + refAtt.REFEntityName + "Id"] == DBNull.Value)
            {
                return;
            }

            object objRef = DLLAnalysis.GetEntityInstance(refAtt.REFEntityName);

            ((BaseEntity)objRef).Id = Convert.ToInt64(table.Rows[rindex]["E_" + refAtt.REFEntityName + "Id"]);
            EntityInfo refeinfo = DLLAnalysis.GetEntityInfoByType(objRef.GetType());

            foreach (FieldAttribute fieldAtt in refeinfo.Properties)
            {
                FetchPropertyValue(objRef, fieldAtt, table, rindex);
            }
            objEntity.GetType().GetProperty(refAtt.PropertyName).SetValue(objEntity, objRef, null);
        }
Esempio n. 2
0
        /// <summary>
        /// 获取实体的父对象
        /// </summary>
        /// <param name="objEntity">宿主实体</param>
        /// <param name="table">数据集</param>
        /// <param name="rIndex">取数据集的行数</param>
        public static void FetchParent(object objEntity, DataTable table, int rIndex)
        {
            EntityInfo einfo = DLLAnalysis.GetEntityInfoByType(objEntity.GetType());
            object     pid   = table.Rows[rIndex]["PTId"];

            if (pid == DBNull.Value || string.IsNullOrEmpty(pid.ToString()))
            {
                return;
            }
            BaseEntity pEntity = (BaseEntity)DLLAnalysis.GetEntityInstance(einfo.EntityName);

            pEntity.Id = Convert.ToInt64(pid);
            try
            {
                pEntity.GetType().GetProperty(einfo.Properties[0].FieldName).SetValue(pEntity, table.Rows[rIndex]["PTC"], null);
                objEntity.GetType().GetProperty("Parent" + einfo.EntityName).SetValue(objEntity, pEntity, null);
            }
            catch (Exception ex) { }
            return;
        }
Esempio n. 3
0
        /// <summary>
        /// 将字符串类型的数据经转换后付给指定的实体对象
        /// </summary>
        /// <param name="objEntity">实体对象</param>
        /// <param name="pinfo">需要赋值的属性名称</param>
        /// <param name="table">字符串值</param>
        public static void FetchPropertyValue(object objEntity, string fieldName, string propValue)
        {
            if (string.IsNullOrEmpty(propValue))
            {
                return;
            }
            EntityInfo     einfo    = DLLAnalysis.GetEntityInfoByType(objEntity.GetType());
            FieldAttribute fieldAtt = null;

            foreach (FieldAttribute fatt in einfo.Properties)
            {
                if (fatt.FieldName.Equals(fieldName))
                {
                    fieldAtt = fatt;
                    break;
                }
            }
            if (fieldAtt.DataType.StartsWith("string") || fieldAtt.DataType.IndexOf("text") > -1)
            {
                objEntity.GetType().GetProperty(fieldName).SetValue(objEntity, propValue, null);
            }
            else
            {
                switch (fieldAtt.DataType)
                {
                case "int": objEntity.GetType().GetProperty(fieldName).SetValue(objEntity, Convert.ToInt32(propValue), null); break;

                case "long": objEntity.GetType().GetProperty(fieldName).SetValue(objEntity, Convert.ToInt64(propValue), null); break;

                case "float": objEntity.GetType().GetProperty(fieldName).SetValue(objEntity, Convert.ToSingle(propValue), null); break;

                case "decimal": objEntity.GetType().GetProperty(fieldName).SetValue(objEntity, Convert.ToDecimal(propValue), null); break;

                case "Date":
                case "SmallDate": objEntity.GetType().GetProperty(fieldName).SetValue(objEntity, Convert.ToDateTime(propValue), null); break;
                }
            }
        }
Esempio n. 4
0
        public static void FetchChildren(object objEntity, DataTable table)
        {
            EntityInfo einfo = DLLAnalysis.GetEntityInfoByType(objEntity.GetType());
            ArrayList  list  = new ArrayList();

            for (int i = 0; i < table.Rows.Count; i++)
            {
                //如果该实体的此集合属性为空
                if (table.Rows[i]["CTId"] == DBNull.Value || table.Rows[i]["CTPId"] == DBNull.Value)
                {
                    continue;
                }
                if (((BaseEntity)objEntity).Id == Convert.ToInt64(table.Rows[i]["CTPId"]))
                {
                    object objElement = DLLAnalysis.GetEntityInstance(einfo.EntityName);
                    //取自身引用子集合时,每个子对象只有Id是载入的,其他属性都没获取
                    ((BaseEntity)objElement).Id = Convert.ToInt64(table.Rows[i]["CTId"]);
                    //objElement.GetType().GetProperty(einfo.Properties[0].FieldName).SetValue(objElement, table.Rows[i]["CTC"], null);
                    list.Add(objElement);
                }
            }
            objEntity.GetType().GetProperty("Child" + einfo.EntityName + "s").SetValue(objEntity, list, null);
        }
Esempio n. 5
0
        public static void FetchSet(object objEntity, SETAttribute setAtt, DataTable table)
        {
            ArrayList list = new ArrayList();

            for (int i = 0; i < table.Rows.Count; i++)
            {
                //如果该实体的此集合属性为空
                if (table.Rows[i][setAtt.ElementEntityId] == DBNull.Value)
                {
                    continue;
                }
                if (((BaseEntity)objEntity).Id == Convert.ToInt64(table.Rows[i][setAtt.ElementEntityId]))
                {
                    object objElement = DLLAnalysis.GetEntityInstance(setAtt.ElementEntityName);
                    if (Convert.IsDBNull(table.Rows[i]["E_" + setAtt.ElementEntityName + "Id"]))
                    {
                        continue;
                    }
                    ((BaseEntity)objElement).Id = Convert.ToInt64(table.Rows[i]["E_" + setAtt.ElementEntityName + "Id"]);
                    EntityInfo elementEinfo = DLLAnalysis.GetEntityInfoByType(objElement.GetType());
                    foreach (FieldAttribute fieldAtt in elementEinfo.Properties)
                    {
                        FetchPropertyValue(objElement, fieldAtt, table, i);
                    }
                    foreach (REFAttribute refAtt in elementEinfo.References)
                    {
                        if (refAtt.REFEntityName.Equals(objEntity.GetType().Name))
                        {
                            objElement.GetType().GetProperty(refAtt.PropertyName).SetValue(objElement, objEntity, null);
                        }
                    }
                    list.Add(objElement);
                }
            }
            objEntity.GetType().GetProperty(setAtt.PropertyName).SetValue(objEntity, list, null);
        }