Beispiel #1
0
 /// <summary>
 /// 添加, 这里可以人工干预,提高程序的性能
 /// </summary>
 /// <param name="entity">实体</param>
 /// <param name="identity">自增量方式,表主键是否采用自增的策略</param>
 /// <param name="returnId">返回主键,不返回程序允许速度会快,主要是为了主细表批量插入数据优化用的</param>
 /// <returns>主键</returns>
 public string Add(BaseUserRoleEntity entity, bool identity = true, bool returnId = true)
 {
     Identity  = identity;
     ReturnId  = returnId;
     entity.Id = AddEntity(entity).ToInt();
     return(entity.Id.ToString());
 }
Beispiel #2
0
        /// <summary>
        /// 添加(判断数据是否重复,防止垃圾数据产生)
        /// </summary>
        /// <param name="entity">实体</param>
        /// <returns>主键</returns>
        public string Add(BaseUserRoleEntity entity)
        {
            var result = string.Empty;

            // 判断是否数据重复
            var whereParameters = new List <KeyValuePair <string, object> >
            {
                new KeyValuePair <string, object>(BaseUserRoleEntity.FieldEnabled, 1),
                new KeyValuePair <string, object>(BaseUserRoleEntity.FieldDeleted, 0),
                new KeyValuePair <string, object>(BaseUserRoleEntity.FieldRoleId, entity.RoleId),
                new KeyValuePair <string, object>(BaseUserRoleEntity.FieldUserId, entity.UserId)
            };

            if (!Exists(whereParameters))
            {
                result = AddEntity(entity);
            }
            else
            {
                var parameters = new List <KeyValuePair <string, object> >
                {
                    new KeyValuePair <string, object>(BaseUserRoleEntity.FieldEnabled, 1),
                    new KeyValuePair <string, object>(BaseUserRoleEntity.FieldDeleted, 0)
                };
                UpdateProperty(whereParameters, parameters);
            }

            return(result);
        }
 /// <summary>
 /// 设置实体
 /// </summary>
 /// <param name="userRoleEntity">实体</param>
 private void SetEntity(SQLBuilder sqlBuilder, BaseUserRoleEntity userRoleEntity)
 {
     sqlBuilder.SetValue(BaseUserRoleEntity.FieldUserId, userRoleEntity.UserId);
     sqlBuilder.SetValue(BaseUserRoleEntity.FieldRoleId, userRoleEntity.RoleId);
     sqlBuilder.SetValue(BaseUserRoleEntity.FieldEnabled, userRoleEntity.Enabled);
     sqlBuilder.SetValue(BaseUserRoleEntity.FieldDescription, userRoleEntity.Description);
     sqlBuilder.SetValue(BaseUserRoleEntity.FieldDeletionStateCode, userRoleEntity.DeletionStateCode);
     SetEntityExpand(sqlBuilder, userRoleEntity);
 }
Beispiel #4
0
 /// <summary>
 /// 设置实体
 /// </summary>
 /// <param name="sqlBuilder">Sql语句生成器</param>
 /// <param name="entity">实体</param>
 private void SetEntity(SqlBuilder sqlBuilder, BaseUserRoleEntity entity)
 {
     SetEntityExtend(sqlBuilder, entity);
     sqlBuilder.SetValue(BaseUserRoleEntity.FieldSystemCode, entity.SystemCode);
     sqlBuilder.SetValue(BaseUserRoleEntity.FieldUserId, entity.UserId);
     sqlBuilder.SetValue(BaseUserRoleEntity.FieldRoleId, entity.RoleId);
     sqlBuilder.SetValue(BaseUserRoleEntity.FieldDescription, entity.Description);
     sqlBuilder.SetValue(BaseUserRoleEntity.FieldSortCode, entity.SortCode);
     sqlBuilder.SetValue(BaseUserRoleEntity.FieldDeleted, entity.Deleted);
     sqlBuilder.SetValue(BaseUserRoleEntity.FieldEnabled, entity.Enabled);
 }
Beispiel #5
0
 /// <summary>
 /// 设置实体
 /// </summary>
 /// <param name="entity">实体</param>
 private void SetObject(SQLBuilder sqlBuilder, BaseUserRoleEntity entity)
 {
     sqlBuilder.SetValue(BaseUserRoleEntity.FieldUserId, entity.UserId);
     sqlBuilder.SetValue(BaseUserRoleEntity.FieldRoleId, entity.RoleId);
     if (!string.IsNullOrEmpty(entity.CompanyId))
     {
         sqlBuilder.SetValue(BaseUserRoleEntity.FieldCompanyId, entity.CompanyId);
     }
     sqlBuilder.SetValue(BaseUserRoleEntity.FieldEnabled, entity.Enabled);
     sqlBuilder.SetValue(BaseUserRoleEntity.FieldDescription, entity.Description);
     sqlBuilder.SetValue(BaseUserRoleEntity.FieldDeletionStateCode, entity.DeletionStateCode);
     SetObjectExpand(sqlBuilder, entity);
 }
Beispiel #6
0
 /// <summary>
 /// 添加或更新(主键是否为0)
 /// </summary>
 /// <param name="entity">实体</param>
 /// <param name="identity">自增量方式,表主键是否采用自增的策略</param>
 /// <param name="returnId">返回主键,不返回程序允许速度会快,主要是为了主细表批量插入数据优化用的</param>
 /// <returns>主键</returns>
 public string AddOrUpdate(BaseUserRoleEntity entity, bool identity = true, bool returnId = true)
 {
     Identity = identity;
     ReturnId = returnId;
     if (entity.Id == 0)
     {
         entity.Id = AddEntity(entity).ToInt();
         return(entity.Id.ToString());
     }
     else
     {
         return(UpdateEntity(entity) > 0 ? entity.Id.ToString() : string.Empty);
     }
 }
Beispiel #7
0
        /// <summary>
        /// 更新实体
        /// </summary>
        /// <param name="entity">实体</param>
        public int UpdateObject(BaseUserRoleEntity entity)
        {
            SQLBuilder sqlBuilder = new SQLBuilder(DbHelper);

            sqlBuilder.BeginUpdate(this.CurrentTableName);
            this.SetObject(sqlBuilder, entity);
            if (UserInfo != null)
            {
                sqlBuilder.SetValue(BaseUserRoleEntity.FieldModifiedUserId, UserInfo.Id);
                sqlBuilder.SetValue(BaseUserRoleEntity.FieldModifiedBy, UserInfo.RealName);
            }
            sqlBuilder.SetDBNow(BaseUserRoleEntity.FieldModifiedOn);
            sqlBuilder.SetWhere(BaseUserRoleEntity.FieldId, entity.Id);
            return(sqlBuilder.EndUpdate());
        }
        //
        // 加入到角色
        //


        #region public string AddToRole(string userId, string roleId) 为了提高授权的运行速度
        /// <summary>
        /// 为了提高授权的运行速度
        /// </summary>
        /// <param name="Id">主键</param>
        /// <param name="userId">用户主键</param>
        /// <param name="roleId">角色主键</param>
        /// <returns>主键</returns>
        public string AddToRole(string userId, string roleId)
        {
            string             returnValue    = string.Empty;
            BaseUserRoleEntity userRoleEntity = new BaseUserRoleEntity();

            userRoleEntity.UserId            = int.Parse(userId);
            userRoleEntity.RoleId            = int.Parse(roleId);
            userRoleEntity.Enabled           = 1;
            userRoleEntity.DeletionStateCode = 0;
            string tableName = BaseUserRoleEntity.TableName;

            if (!string.IsNullOrEmpty(BaseSystemInfo.SystemCode))
            {
                tableName = BaseSystemInfo.SystemCode + "UserRole";
            }
            BaseUserRoleManager userRoleManager = new BaseUserRoleManager(this.DbHelper, this.UserInfo, tableName);

            return(userRoleManager.Add(userRoleEntity));
        }
Beispiel #9
0
        /// <summary>
        /// 为了提高授权的运行速度
        /// </summary>
        /// <param name="systemCode">系统编号</param>
        /// <param name="userId">用户主键</param>
        /// <param name="roleId">角色主键</param>
        /// <param name="enabled">有效状态</param>
        /// <returns>主键</returns>
        public string AddToRoleById(string systemCode, string userId, string roleId, bool enabled = true)
        {
            string result = string.Empty;

            if (string.IsNullOrEmpty(systemCode))
            {
                systemCode = "Base";
            }
            string tableName = string.Empty;

            if (!string.IsNullOrEmpty(userId) && !string.IsNullOrEmpty(roleId))
            {
                BaseUserRoleEntity entity = new BaseUserRoleEntity();
                entity.UserId            = userId;
                entity.RoleId            = roleId;
                entity.Enabled           = enabled ? 1 : 0;
                entity.DeletionStateCode = 0;
                // 2016-03-02 吉日嘎拉 增加按公司可以区别数据的功能。
                if (this.DbHelper.CurrentDbType == CurrentDbType.MySql)
                {
                    entity.CompanyId = BaseUserManager.GetCompanyIdByCache(userId);
                }
                // 2015-12-05 吉日嘎拉 把修改人记录起来,若是新增加的
                if (this.UserInfo != null)
                {
                    entity.CreateUserId   = this.UserInfo.Id;
                    entity.CreateBy       = this.UserInfo.RealName;
                    entity.CreateOn       = System.DateTime.Now;
                    entity.ModifiedUserId = this.UserInfo.Id;
                    entity.ModifiedBy     = this.UserInfo.RealName;
                    entity.ModifiedOn     = System.DateTime.Now;
                }
                tableName = systemCode + "UserRole";
                BaseUserRoleManager manager = new BaseUserRoleManager(this.DbHelper, this.UserInfo, tableName);
                result = manager.Add(entity);
            }

            return(result);
        }
Beispiel #10
0
        /// <summary>
        /// 新增或激活
        /// </summary>
        /// <param name="entity">实体</param>
        /// <returns></returns>
        public string AddOrActive(BaseUserRoleEntity entity)
        {
            var result          = string.Empty;
            var whereParameters = new List <KeyValuePair <string, object> >
            {
                new KeyValuePair <string, object>(BaseUserRoleEntity.FieldRoleId, entity.RoleId),
                new KeyValuePair <string, object>(BaseUserRoleEntity.FieldUserId, entity.UserId)
            };
            var entityOld = GetEntity(whereParameters);

            if (entityOld != null)
            {
                result         = entityOld.Id.ToString();
                entity.Id      = entityOld.Id;
                entity.Enabled = 1;
                entity.Deleted = 0;
                //激活
                UpdateEntity(entity);
            }
            else
            {
                result = AddEntity(entity);
                if (!string.IsNullOrEmpty(result))
                {
                    //运行成功
                    StatusCode    = Status.OkAdd.ToString();
                    StatusMessage = Status.OkAdd.ToDescription();
                }
                else
                {
                    //保存失败
                    StatusCode    = Status.DbError.ToString();
                    StatusMessage = Status.DbError.ToDescription();
                }
            }

            return(result);
        }
Beispiel #11
0
        /// <summary>
        /// 为了提高授权的运行速度
        /// </summary>
        /// <param name="systemCode">系统编号</param>
        /// <param name="userId">用户主键</param>
        /// <param name="roleId">角色主键</param>
        /// <param name="enabled">有效状态</param>
        /// <returns>主键</returns>
        public string AddToRoleById(string systemCode, string userId, string roleId, bool enabled = true)
        {
            var result = string.Empty;

            if (string.IsNullOrEmpty(systemCode))
            {
                systemCode = "Base";
            }
            if (ValidateUtil.IsInt(userId) && ValidateUtil.IsInt(roleId))
            {
                var entity = new BaseUserRoleEntity
                {
                    UserId  = userId.ToInt(),
                    RoleId  = roleId.ToInt(),
                    Enabled = enabled ? 1 : 0
                };
                var tableName = systemCode + "UserRole";
                //新增或激活
                result = new BaseUserRoleManager(DbHelper, UserInfo, tableName).AddOrActive(entity);
            }

            return(result);
        }
Beispiel #12
0
        /// <summary>
        /// 添加(判断数据是否重复,防止垃圾数据产生)
        /// </summary>
        /// <param name="entity">实体</param>
        /// <returns>主键</returns>
        public string Add(BaseUserRoleEntity entity)
        {
            string result = string.Empty;

            // 判断是否数据重复
            List <KeyValuePair <string, object> > whereParameters = new List <KeyValuePair <string, object> >();

            // parameters.Add(new KeyValuePair<string, object>(BaseUserRoleEntity.FieldEnabled, 1));
            whereParameters.Add(new KeyValuePair <string, object>(BaseUserRoleEntity.FieldDeletionStateCode, 0));
            whereParameters.Add(new KeyValuePair <string, object>(BaseUserRoleEntity.FieldRoleId, entity.RoleId));
            whereParameters.Add(new KeyValuePair <string, object>(BaseUserRoleEntity.FieldUserId, entity.UserId));
            if (!this.Exists(whereParameters))
            {
                result = this.AddObject(entity);
            }
            else
            {
                // 2015-12-04 吉日嘎拉 这里有严重错误,重复申请就会变成自己审核了
                List <KeyValuePair <string, object> > parameters = new List <KeyValuePair <string, object> >();
                if (this.UserInfo != null)
                {
                    parameters.Add(new KeyValuePair <string, object>(BaseUserRoleEntity.FieldModifiedUserId, this.UserInfo.Id));
                    parameters.Add(new KeyValuePair <string, object>(BaseUserRoleEntity.FieldModifiedBy, this.UserInfo.RealName));
                    parameters.Add(new KeyValuePair <string, object>(BaseUserRoleEntity.FieldModifiedOn, System.DateTime.Now));
                }
                else
                {
                    parameters.Add(new KeyValuePair <string, object>(BaseUserRoleEntity.FieldModifiedUserId, entity.ModifiedUserId));
                    parameters.Add(new KeyValuePair <string, object>(BaseUserRoleEntity.FieldModifiedBy, entity.ModifiedBy));
                    parameters.Add(new KeyValuePair <string, object>(BaseUserRoleEntity.FieldModifiedOn, System.DateTime.Now));
                }
                parameters.Add(new KeyValuePair <string, object>(BaseUserRoleEntity.FieldEnabled, entity.Enabled));
                this.SetProperty(whereParameters, parameters);
            }

            return(result);
        }
Beispiel #13
0
        /// <summary>
        /// 更新实体
        /// </summary>
        /// <param name="entity">实体</param>
        public int UpdateEntity(BaseUserRoleEntity entity)
        {
            var sqlBuilder = new SqlBuilder(DbHelper);

            sqlBuilder.BeginUpdate(CurrentTableName);
            SetEntity(sqlBuilder, entity);
            if (UserInfo != null)
            {
                sqlBuilder.SetValue(BaseUserRoleEntity.FieldUpdateUserId, UserInfo.UserId);
                sqlBuilder.SetValue(BaseUserRoleEntity.FieldUpdateUserName, UserInfo.UserName);
                sqlBuilder.SetValue(BaseUserRoleEntity.FieldUpdateBy, UserInfo.RealName);
            }
            sqlBuilder.SetDbNow(BaseUserRoleEntity.FieldUpdateTime);
            sqlBuilder.SetValue(BaseUserRoleEntity.FieldUpdateIp, Utils.GetIp());
            sqlBuilder.SetWhere(PrimaryKey, entity.Id);
            //return sqlBuilder.EndUpdate();
            var result = sqlBuilder.EndUpdate();

            if (result > 0)
            {
                RemoveCache(entity.Id);
            }
            return(result);
        }
 partial void SetEntityExpand(SQLBuilder sqlBuilder, BaseUserRoleEntity userRoleEntity);
Beispiel #15
0
 // 这个是声明扩展方法
 partial void SetEntityExtend(SqlBuilder sqlBuilder, BaseUserRoleEntity entity);
Beispiel #16
0
        /// <summary>
        /// 添加实体
        /// </summary>
        /// <param name="entity">实体</param>
        public string AddEntity(BaseUserRoleEntity entity)
        {
            var key = string.Empty;

            if (entity.SortCode == 0)
            {
                var managerSequence = new BaseSequenceManager(DbHelper, Identity);
                if (DbHelper.CurrentDbType == CurrentDbType.Oracle || DbHelper.CurrentDbType == CurrentDbType.Db2)
                {
                    key = managerSequence.Increment($"SC_{CurrentTableName}_SEQ");
                }
                else
                {
                    key = managerSequence.Increment(CurrentTableName);
                }
                entity.SortCode = key.ToInt();
            }
            var sqlBuilder = new SqlBuilder(DbHelper, Identity, ReturnId);

            sqlBuilder.BeginInsert(CurrentTableName, PrimaryKey);
            if (!Identity)
            {
                // 这里已经是指定了主键了,所以不需要返回主键了
                sqlBuilder.ReturnId = false;
                sqlBuilder.SetValue(PrimaryKey, entity.Id);
            }
            else
            {
                if (!ReturnId && (DbHelper.CurrentDbType == CurrentDbType.Oracle || DbHelper.CurrentDbType == CurrentDbType.Db2))
                {
                    if (DbHelper.CurrentDbType == CurrentDbType.Oracle)
                    {
                        sqlBuilder.SetFormula(PrimaryKey, $"{CurrentTableName}_SEQ.NEXTVAL");
                    }
                    if (DbHelper.CurrentDbType == CurrentDbType.Db2)
                    {
                        sqlBuilder.SetFormula(PrimaryKey, $"NEXT VALUE FOR {CurrentTableName}_SEQ");
                    }
                }
                else
                {
                    if (Identity && (DbHelper.CurrentDbType == CurrentDbType.Oracle || DbHelper.CurrentDbType == CurrentDbType.Db2))
                    {
                        var managerSequence = new BaseSequenceManager(DbHelper);
                        entity.Id = managerSequence.Increment($"{CurrentTableName}_SEQ").ToInt();
                        sqlBuilder.SetValue(PrimaryKey, entity.Id);
                    }
                }
            }
            SetEntity(sqlBuilder, entity);
            if (UserInfo != null)
            {
                sqlBuilder.SetValue(BaseUserRoleEntity.FieldCreateUserId, UserInfo.UserId);
                sqlBuilder.SetValue(BaseUserRoleEntity.FieldCreateUserName, UserInfo.UserName);
                sqlBuilder.SetValue(BaseUserRoleEntity.FieldCreateBy, UserInfo.RealName);
            }
            else
            {
                sqlBuilder.SetValue(BaseUserRoleEntity.FieldCreateBy, entity.CreateBy);
                sqlBuilder.SetValue(BaseUserRoleEntity.FieldCreateUserName, entity.CreateUserName);
            }
            sqlBuilder.SetDbNow(BaseUserRoleEntity.FieldCreateTime);
            sqlBuilder.SetValue(BaseUserRoleEntity.FieldCreateIp, Utils.GetIp());
            if (UserInfo != null)
            {
                sqlBuilder.SetValue(BaseUserRoleEntity.FieldUpdateUserId, UserInfo.UserId);
                sqlBuilder.SetValue(BaseUserRoleEntity.FieldUpdateUserName, UserInfo.UserName);
                sqlBuilder.SetValue(BaseUserRoleEntity.FieldUpdateBy, UserInfo.RealName);
            }
            sqlBuilder.SetDbNow(BaseUserRoleEntity.FieldUpdateTime);
            sqlBuilder.SetValue(BaseUserRoleEntity.FieldUpdateIp, Utils.GetIp());
            if (Identity && (DbHelper.CurrentDbType == CurrentDbType.SqlServer || DbHelper.CurrentDbType == CurrentDbType.Access))
            {
                key = sqlBuilder.EndInsert().ToString();
            }
            else
            {
                sqlBuilder.EndInsert();
            }
            if (Identity && (DbHelper.CurrentDbType == CurrentDbType.Oracle || DbHelper.CurrentDbType == CurrentDbType.Db2))
            {
                key = entity.Id.ToString();
            }
            if (!string.IsNullOrWhiteSpace(key))
            {
                RemoveCache();
            }
            return(key);
        }
Beispiel #17
0
 /// <summary>
 /// 更新
 /// </summary>
 /// <param name="entity">实体</param>
 public int Update(BaseUserRoleEntity entity)
 {
     return(UpdateEntity(entity));
 }
 /// <summary>
 /// 添加
 /// </summary>
 /// <param name="userRoleEntity">实体</param>
 /// <returns>主键</returns>
 public string Add(BaseUserRoleEntity userRoleEntity)
 {
     return(this.AddEntity(userRoleEntity));
 }
        /// <summary>
        /// 获取实体
        /// </summary>
        /// <param name="id">主键</param>
        public BaseUserRoleEntity GetEntity(int id)
        {
            BaseUserRoleEntity userRoleEntity = new BaseUserRoleEntity(this.GetDataTable(new KeyValuePair <string, object>(BaseUserRoleEntity.FieldId, id)));

            return(userRoleEntity);
        }
Beispiel #20
0
 /// <summary>
 /// 添加
 /// </summary>
 /// <param name="entity">实体</param>
 /// <param name="identity">自增量方式</param>
 /// <param name="returnId">返回主鍵</param>
 /// <returns>主键</returns>
 public string Add(BaseUserRoleEntity entity, bool identity, bool returnId)
 {
     this.Identity = identity;
     this.ReturnId = returnId;
     return(this.AddObject(entity));
 }
        /// <summary>
        /// 添加实体
        /// </summary>
        /// <param name="userRoleEntity">实体</param>
        public string AddEntity(BaseUserRoleEntity userRoleEntity)
        {
            string     sequence   = string.Empty;
            SQLBuilder sqlBuilder = new SQLBuilder(DbHelper, this.Identity, this.ReturnId);

            sqlBuilder.BeginInsert(this.CurrentTableName, BaseUserRoleEntity.FieldId);
            if (!this.Identity)
            {
                sqlBuilder.SetValue(BaseUserRoleEntity.FieldId, userRoleEntity.Id);
            }
            else
            {
                if (!this.ReturnId && (DbHelper.CurrentDbType == CurrentDbType.Oracle || DbHelper.CurrentDbType == CurrentDbType.DB2))
                {
                    if (DbHelper.CurrentDbType == CurrentDbType.Oracle)
                    {
                        sqlBuilder.SetFormula(BaseUserRoleEntity.FieldId, "SEQ_" + this.CurrentTableName.ToUpper() + ".NEXTVAL ");
                    }
                    if (DbHelper.CurrentDbType == CurrentDbType.DB2)
                    {
                        sqlBuilder.SetFormula(BaseUserRoleEntity.FieldId, "NEXT VALUE FOR SEQ_" + this.CurrentTableName.ToUpper());
                    }
                }
                else
                {
                    if (this.Identity && (DbHelper.CurrentDbType == CurrentDbType.Oracle || DbHelper.CurrentDbType == CurrentDbType.DB2))
                    {
                        if (userRoleEntity.Id == null)
                        {
                            if (string.IsNullOrEmpty(sequence))
                            {
                                BaseSequenceManager sequenceManager = new BaseSequenceManager(DbHelper, this.Identity);
                                sequence = sequenceManager.GetSequence(this.CurrentTableName);
                            }
                            userRoleEntity.Id = int.Parse(sequence);
                        }
                        sqlBuilder.SetValue(BaseUserRoleEntity.FieldId, userRoleEntity.Id);
                    }
                }
            }
            this.SetEntity(sqlBuilder, userRoleEntity);
            if (UserInfo != null)
            {
                sqlBuilder.SetValue(BaseUserRoleEntity.FieldCreateUserId, UserInfo.Id);
                sqlBuilder.SetValue(BaseUserRoleEntity.FieldCreateBy, UserInfo.RealName);
            }
            sqlBuilder.SetDBNow(BaseUserRoleEntity.FieldCreateOn);
            if (UserInfo != null)
            {
                sqlBuilder.SetValue(BaseUserRoleEntity.FieldModifiedUserId, UserInfo.Id);
                sqlBuilder.SetValue(BaseUserRoleEntity.FieldModifiedBy, UserInfo.RealName);
            }
            sqlBuilder.SetDBNow(BaseUserRoleEntity.FieldModifiedOn);
            if (DbHelper.CurrentDbType == CurrentDbType.SqlServer && this.Identity)
            {
                sequence = sqlBuilder.EndInsert().ToString();
            }
            else
            {
                sqlBuilder.EndInsert();
            }
            return(sequence);
        }
Beispiel #22
0
 partial void SetObjectExpand(SQLBuilder sqlBuilder, BaseUserRoleEntity entity);
 /// <summary>
 /// 更新
 /// </summary>
 /// <param name="userRoleEntity">实体</param>
 public int Update(BaseUserRoleEntity userRoleEntity)
 {
     return(this.UpdateEntity(userRoleEntity));
 }
Beispiel #24
0
        /// <summary>
        /// 添加实体
        /// </summary>
        /// <param name="entity">实体</param>
        public string AddObject(BaseUserRoleEntity entity)
        {
            string result = string.Empty;

            SQLBuilder sqlBuilder = new SQLBuilder(DbHelper, this.Identity, this.ReturnId);

            sqlBuilder.BeginInsert(this.CurrentTableName, BaseUserRoleEntity.FieldId);
            if (!this.Identity)
            {
                sqlBuilder.SetValue(BaseUserRoleEntity.FieldId, entity.Id);
            }
            else
            {
                if (!this.ReturnId && (DbHelper.CurrentDbType == CurrentDbType.Oracle || DbHelper.CurrentDbType == CurrentDbType.DB2))
                {
                    if (DbHelper.CurrentDbType == CurrentDbType.Oracle)
                    {
                        // 2015-09-25 吉日嘎拉 用一个序列就可以了,不用那么多序列了
                        // sqlBuilder.SetFormula(BaseUserRoleEntity.FieldId, "SEQ_" + this.CurrentTableName.ToUpper() + ".NEXTVAL ");
                        sqlBuilder.SetFormula(BaseUserRoleEntity.FieldId, "SEQ_" + BaseRoleEntity.TableName.ToUpper() + ".NEXTVAL ");
                    }
                    if (DbHelper.CurrentDbType == CurrentDbType.DB2)
                    {
                        // sqlBuilder.SetFormula(BaseUserRoleEntity.FieldId, "NEXT VALUE FOR SEQ_" + this.CurrentTableName.ToUpper());
                        sqlBuilder.SetFormula(BaseUserRoleEntity.FieldId, "NEXT VALUE FOR SEQ_" + BaseRoleEntity.TableName.ToUpper());
                    }
                }
                else
                {
                    if (this.Identity && (DbHelper.CurrentDbType == CurrentDbType.Oracle || DbHelper.CurrentDbType == CurrentDbType.DB2))
                    {
                        if (entity.Id == null)
                        {
                            if (string.IsNullOrEmpty(result))
                            {
                                BaseSequenceManager sequenceManager = new BaseSequenceManager(DbHelper, this.Identity);
                                result = sequenceManager.Increment(BaseRoleEntity.TableName);
                            }
                            entity.Id = int.Parse(result);
                        }
                        sqlBuilder.SetValue(BaseUserRoleEntity.FieldId, entity.Id);
                    }
                }
            }
            this.SetObject(sqlBuilder, entity);
            if (UserInfo != null)
            {
                sqlBuilder.SetValue(BaseUserRoleEntity.FieldCreateUserId, UserInfo.Id);
                sqlBuilder.SetValue(BaseUserRoleEntity.FieldCreateBy, UserInfo.RealName);
            }
            sqlBuilder.SetDBNow(BaseUserRoleEntity.FieldCreateOn);
            if (UserInfo != null)
            {
                sqlBuilder.SetValue(BaseUserRoleEntity.FieldModifiedUserId, UserInfo.Id);
                sqlBuilder.SetValue(BaseUserRoleEntity.FieldModifiedBy, UserInfo.RealName);
            }
            sqlBuilder.SetDBNow(BaseUserRoleEntity.FieldModifiedOn);
            if (DbHelper.CurrentDbType == CurrentDbType.SqlServer && this.Identity)
            {
                result = sqlBuilder.EndInsert().ToString();
            }
            else
            {
                sqlBuilder.EndInsert();
            }

            return(result);
        }
Beispiel #25
0
 /// <summary>
 /// 更新
 /// </summary>
 /// <param name="entity">实体</param>
 public int Update(BaseUserRoleEntity entity)
 {
     return(this.UpdateObject(entity));
 }