Пример #1
0
 /// <summary>
 /// 更新实体数据到数据库中
 /// </summary>
 /// <param name="ConditionForUpdate">自定义条件</param>
 public bool DB_UpdateEntity(SQLCondition ConditionForUpdate, params string[] Propertys)
 {
     try
     {
         EntityStruct es = EntityStructManager.GetEntityStruct(this.GetType());
         IsCreated = es.DoUpdate(this, ConditionForUpdate, Propertys) > 0 ? true : false;
         return(IsCreated);;
     }
     catch (Exception exp)
     {
         if (ThrowException)
         {
             throw exp;
         }
         return(false);
     }
 }
Пример #2
0
 /// <summary>
 /// 从数据库删除指定条件的实体数据
 /// </summary>
 ///  <param name="ConditionForDelete">自定义条件</param>
 public bool DB_DeleteEntity(SQLCondition ConditionForDelete)
 {
     try
     {
         this.IsCreated = false;
         EntityStruct es = EntityStructManager.GetEntityStruct(this.GetType());
         return(es.DoDelete(this, ConditionForDelete) > 0 ? true : false);
     }
     catch (Exception exp)
     {
         if (ThrowException)
         {
             throw exp;
         }
         return(false);
     }
 }
Пример #3
0
 /// <summary>
 /// 将实体对象插入数据库
 /// </summary>
 /// <param name="Propertys">自定义字段</param>
 public bool DB_InsertEntity(params string[] Propertys)
 {
     try
     {
         IsCreated = true;
         EntityStruct es = EntityStructManager.GetEntityStruct(this.GetType());
         IsCreated = es.DoInsert(this, Propertys) > 0 ? true : false;
         return(IsCreated);
     }
     catch (Exception exp)
     {
         if (ThrowException)
         {
             throw exp;
         }
         return(false);
     }
 }
Пример #4
0
        public bool FillSelf(SQLCondition Condition)
        {
            EntityStruct es = EntityStructManager.GetEntityStruct(this.GetType());

            return(es.DoFillSelf(this, Condition));
        }
Пример #5
0
        public bool FillSelf <T>(T ID, params string[] FieldNames)
        {
            EntityStruct es = EntityStructManager.GetEntityStruct(this.GetType());

            return(es.DoFillSelf(this, ID, FieldNames));
        }
Пример #6
0
        /// <summary>
        /// 判断指定字段值是否存在
        /// </summary>
        /// <param name="FieldName">字段名</param>
        /// <param name="FieldValue">值</param>
        /// <param name="ConditionForCheckExist">自定义条件</param>
        /// <returns></returns>
        public bool IsExist(string ConditionForCheckExist)
        {
            EntityStruct es = EntityStructManager.GetEntityStruct(this.GetType());

            return(es.DoCheckExist(ConditionForCheckExist) > 0 ? true : false);
        }
Пример #7
0
        /// <summary>
        /// 判断指定字段值是否存在
        /// </summary>
        /// <param name="FieldName">字段名</param>
        /// <param name="FieldValue">值</param>
        /// <param name="ConditionForCheckExist">自定义条件</param>
        /// <returns></returns>
        public bool IsExist(string FieldName, object FieldValue)
        {
            EntityStruct es = EntityStructManager.GetEntityStruct(this.GetType());

            return(es.DoCheckExist(FieldName, FieldValue) > 0 ? true : false);
        }
Пример #8
0
        /// <summary>
        /// 注册实体结构到缓存管理器
        /// </summary>
        /// <param name="EntityType"></param>
        public static void RegisterEntityStruct(Type EntityType)
        {
            if (!CheckExist(EntityType))
            {
                EntityStruct Struct = new EntityStruct();

                #region Fill DataTable
                ORMDataTable[] dbTable = (ORMDataTable[])EntityType.GetCustomAttributes(typeof(ORMDataTable), true);


                if (dbTable.Length > 0)
                {
                    Struct.Table = dbTable[0];
                }
                #endregion

                #region Fill Field

                #region 获取当前类的隐射信息

                #region 取字段信息
                foreach (FieldInfo fi in EntityType.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly))
                {
                    #region 获取主键信息
                    KeyField[] dbKeyFieldSet = (KeyField[])fi.GetCustomAttributes(typeof(KeyField), true);
                    foreach (KeyField key in dbKeyFieldSet)
                    {
                        key.FieldType    = fi.FieldType;
                        key.PropertyName = fi.Name;

                        if (key.FieldName == string.Empty)
                        {
                            key.FieldName = key.PropertyName;                               //如果字段隐射为空就等于属性名称
                        }
                        if (key.KeyType == EKeyType.PRIMARY)
                        {
                            if (!Struct.PKeyList.ContainsKey(key.FieldName.ToUpper()))
                            {
                                Struct.PKeyList.Add(key.FieldName.ToUpper(), key);
                            }
                        }
                        else
                        {
                            if (!Struct.FKeyList.ContainsKey(key.FieldName.ToUpper()))
                            {
                                Struct.FKeyList.Add(key.FieldName.ToUpper(), key);
                            }
                        }
                    }
                    #endregion

                    #region 获取其他字段信息
                    DataField[] dbDataFieldSet = (DataField[])fi.GetCustomAttributes(typeof(DataField), true);
                    foreach (DataField key in dbDataFieldSet)
                    {
                        key.FieldType    = fi.FieldType;
                        key.PropertyName = fi.Name;

                        if (key.FieldName == string.Empty)
                        {
                            key.FieldName = key.PropertyName;                               //如果字段隐射为空就等于属性名称
                        }
                        if (!Struct.FKeyList.ContainsKey(key.FieldName.ToUpper()))
                        {
                            key.FieldType    = fi.FieldType;
                            key.PropertyName = fi.Name;

                            if (key.FieldName == string.Empty)
                            {
                                key.FieldName = key.PropertyName;                               //如果字段隐射为空就等于属性名称
                            }
                            Struct.FieldList.Add(key.FieldName.ToUpper(), key);
                        }
                    }
                    #endregion
                }
                #endregion

                #region 取属性信息
                foreach (PropertyInfo fi in EntityType.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly))
                {
                    #region 获取主键信息
                    KeyField[] dbKeyFieldSet = (KeyField[])fi.GetCustomAttributes(typeof(KeyField), true);
                    foreach (KeyField key in dbKeyFieldSet)
                    {
                        key.FieldType    = fi.PropertyType;
                        key.PropertyName = fi.Name;

                        if (key.FieldName == string.Empty)
                        {
                            key.FieldName = key.PropertyName;                               //如果字段隐射为空就等于属性名称
                        }
                        if (key.KeyType == EKeyType.PRIMARY)
                        {
                            if (!Struct.PKeyList.ContainsKey(key.FieldName.ToUpper()))
                            {
                                Struct.PKeyList.Add(key.FieldName.ToUpper(), key);
                            }
                        }
                        else
                        {
                            if (!Struct.FKeyList.ContainsKey(key.FieldName.ToUpper()))
                            {
                                Struct.FKeyList.Add(key.FieldName.ToUpper(), key);
                            }
                        }
                    }
                    #endregion

                    #region 获取其他字段信息
                    DataField[] dbDataFieldSet = (DataField[])fi.GetCustomAttributes(typeof(DataField), true);
                    foreach (DataField key in dbDataFieldSet)
                    {
                        key.FieldType    = fi.PropertyType;
                        key.PropertyName = fi.Name;

                        if (key.FieldName == string.Empty)
                        {
                            key.FieldName = key.PropertyName;                               //如果字段隐射为空就等于属性名称
                        }
                        if (!Struct.FieldList.ContainsKey(key.FieldName.ToUpper()))
                        {
                            key.FieldType    = fi.PropertyType;
                            key.PropertyName = fi.Name;

                            if (key.FieldName == string.Empty)
                            {
                                key.FieldName = key.PropertyName;                               //如果字段隐射为空就等于属性名称
                            }
                            Struct.FieldList.Add(key.FieldName.ToUpper(), key);
                        }
                    }
                    #endregion
                }
                #endregion
                #endregion


                #region 获取继承的隐射信息

                #region 取字段信息
                foreach (FieldInfo fi in EntityType.GetFields())
                {
                    #region 获取主键信息
                    KeyField[] dbKeyFieldSet = (KeyField[])fi.GetCustomAttributes(typeof(KeyField), true);
                    foreach (KeyField key in dbKeyFieldSet)
                    {
                        key.FieldType    = fi.FieldType;
                        key.PropertyName = fi.Name;

                        if (key.FieldName == string.Empty)
                        {
                            key.FieldName = key.PropertyName;                               //如果字段隐射为空就等于属性名称
                        }
                        if (key.KeyType == EKeyType.PRIMARY)
                        {
                            if (!Struct.PKeyList.ContainsKey(key.FieldName.ToUpper()))
                            {
                                key.KeyType  = EKeyType.FOREIGN;
                                key.Sequence = string.Empty;
                                key.IsBase   = true;
                                Struct.FKeyList.Add(key.FieldName.ToUpper(), key);
                            }
                        }
                        else
                        {
                            if (!Struct.FKeyList.ContainsKey(key.FieldName.ToUpper()))
                            {
                                key.IsBase = true;
                                Struct.FKeyList.Add(key.FieldName.ToUpper(), key);
                            }
                        }
                    }
                    #endregion

                    #region 获取其他字段信息
                    DataField[] dbDataFieldSet = (DataField[])fi.GetCustomAttributes(typeof(DataField), true);
                    foreach (DataField key in dbDataFieldSet)
                    {
                        key.FieldType    = fi.FieldType;
                        key.PropertyName = fi.Name;

                        if (key.FieldName == string.Empty)
                        {
                            key.FieldName = key.PropertyName;                               //如果字段隐射为空就等于属性名称
                        }
                        if (!Struct.FieldList.ContainsKey(key.FieldName.ToUpper()))
                        {
                            key.FieldType    = fi.FieldType;
                            key.PropertyName = fi.Name;
                            key.IsBase       = true;
                            if (key.FieldName == string.Empty)
                            {
                                key.FieldName = key.PropertyName;                               //如果字段隐射为空就等于属性名称
                            }
                            Struct.FieldList.Add(key.FieldName.ToUpper(), key);
                        }
                    }
                    #endregion
                }
                #endregion

                #region 取属性信息
                foreach (PropertyInfo fi in EntityType.GetProperties())
                {
                    #region 获取主键信息
                    KeyField[] dbKeyFieldSet = (KeyField[])fi.GetCustomAttributes(typeof(KeyField), true);
                    foreach (KeyField key in dbKeyFieldSet)
                    {
                        key.FieldType    = fi.PropertyType;
                        key.PropertyName = fi.Name;

                        if (key.FieldName == string.Empty)
                        {
                            key.FieldName = key.PropertyName;                               //如果字段隐射为空就等于属性名称
                        }
                        if (key.KeyType == EKeyType.PRIMARY)
                        {
                            if (!Struct.PKeyList.ContainsKey(key.FieldName.ToUpper()))
                            {
                                key.KeyType  = EKeyType.FOREIGN;
                                key.Sequence = string.Empty;
                                key.IsBase   = true;
                                Struct.FKeyList.Add(key.FieldName.ToUpper(), key);
                            }
                        }
                        else
                        {
                            if (!Struct.FKeyList.ContainsKey(key.FieldName.ToUpper()))
                            {
                                key.IsBase = true;
                                Struct.FKeyList.Add(key.FieldName.ToUpper(), key);
                            }
                        }
                    }
                    #endregion

                    #region 获取其他字段信息
                    DataField[] dbDataFieldSet = (DataField[])fi.GetCustomAttributes(typeof(DataField), true);
                    foreach (DataField key in dbDataFieldSet)
                    {
                        key.FieldType    = fi.PropertyType;
                        key.PropertyName = fi.Name;

                        if (key.FieldName == string.Empty)
                        {
                            key.FieldName = key.PropertyName;                               //如果字段隐射为空就等于属性名称
                        }
                        if (!Struct.FieldList.ContainsKey(key.FieldName.ToUpper()))
                        {
                            key.FieldType    = fi.PropertyType;
                            key.PropertyName = fi.Name;
                            key.IsBase       = true;
                            if (key.FieldName == string.Empty)
                            {
                                key.FieldName = key.PropertyName;                               //如果字段隐射为空就等于属性名称
                            }
                            Struct.FieldList.Add(key.FieldName.ToUpper().ToUpper(), key);
                        }
                    }
                    #endregion
                }
                #endregion
                #endregion

                #endregion

                innerCacheManager.Add(EntityType.ToString(), Struct);
            }
        }