コード例 #1
0
        /// <summary>
        /// 添加实体
        /// </summary>
        /// <param name="parameterEntity">实体对象</param>
        /// <returns>主键</returns>
        public string AddEntity(BaseParameterEntity parameterEntity)
        {
            if (string.IsNullOrEmpty(parameterEntity.Id))
            {
                parameterEntity.Id = Guid.NewGuid().ToString();
            }
            SQLBuilder sqlBuilder = new SQLBuilder(DbHelper);

            sqlBuilder.BeginInsert(this.CurrentTableName);
            sqlBuilder.SetValue(BaseParameterEntity.FieldId, parameterEntity.Id);
            sqlBuilder.SetValue(BaseParameterEntity.FieldCategoryId, parameterEntity.CategoryId);
            sqlBuilder.SetValue(BaseParameterEntity.FieldParameterId, parameterEntity.ParameterId);
            sqlBuilder.SetValue(BaseParameterEntity.FieldParameterCode, parameterEntity.ParameterCode);
            sqlBuilder.SetValue(BaseParameterEntity.FieldWorked, parameterEntity.Worked ? 1 : 0);
            sqlBuilder.SetValue(BaseParameterEntity.FieldParameterContent, parameterEntity.ParameterContent);
            sqlBuilder.SetValue(BaseParameterEntity.FieldEnabled, parameterEntity.Enabled ? 1 : 0);
            sqlBuilder.SetValue(BaseParameterEntity.FieldDeletionStateCode, parameterEntity.DeletionStateCode);
            sqlBuilder.SetValue(BaseParameterEntity.FieldDescription, parameterEntity.Description);
            if (UserInfo != null)
            {
                sqlBuilder.SetValue(BaseParameterEntity.FieldCreateUserId, UserInfo.Id);
                sqlBuilder.SetValue(BaseParameterEntity.FieldCreateBy, UserInfo.RealName);
            }
            sqlBuilder.SetDBNow(BaseParameterEntity.FieldCreateOn);
            return(sqlBuilder.EndInsert() > 0 ? parameterEntity.Id : string.Empty);
        }
コード例 #2
0
        /// <summary>
        /// 更新参数设置
        /// </summary>
        /// <param name="categoryId">类别主键</param>
        /// <param name="parameterId">标志主键</param>
        /// <param name="parameterCode">编码</param>
        /// <param name="parameterContent">参数内容</param>
        /// <returns>影响行数</returns>
        public int SetParameter(string categoryId, string parameterId, string parameterCode, string parameterContent)
        {
            int returnValue = 0;

            List <KeyValuePair <string, object> > parameters = new List <KeyValuePair <string, object> >();

            parameters.Add(new KeyValuePair <string, object>(BaseParameterEntity.FieldCategoryId, categoryId));
            parameters.Add(new KeyValuePair <string, object>(BaseParameterEntity.FieldParameterId, parameterId));
            parameters.Add(new KeyValuePair <string, object>(BaseParameterEntity.FieldParameterCode, parameterCode));
            parameters.Add(new KeyValuePair <string, object>(BaseParameterEntity.FieldDeletionStateCode, 0));
            // 检测是否无效数据
            if ((parameterContent == null) || (parameterContent.Length == 0))
            {
                returnValue = this.Delete(parameters);
            }
            else
            {
                // 检测是否存在
                returnValue = this.SetProperty(parameters, new KeyValuePair <string, object>(BaseParameterEntity.FieldParameterContent, parameterContent));
                if (returnValue == 0)
                {
                    // 进行增加操作
                    BaseParameterEntity parameterEntity = new BaseParameterEntity();
                    parameterEntity.CategoryId        = categoryId;
                    parameterEntity.ParameterId       = parameterId;
                    parameterEntity.ParameterCode     = parameterCode;
                    parameterEntity.ParameterContent  = parameterContent;
                    parameterEntity.Enabled           = true;
                    parameterEntity.DeletionStateCode = 0;
                    this.AddEntity(parameterEntity);
                    returnValue = 1;
                }
            }
            return(returnValue);
        }
コード例 #3
0
        /// <summary>
        /// 添加内容
        /// </summary>
        /// <param name="entity">内容</param>
        /// <returns>主键</returns>
        public string Add(BaseParameterEntity entity, bool identity = false, bool returnId = false)
        {
            string result = string.Empty;

            this.Identity = identity;
            this.ReturnId = returnId;

            // 此处检查this.exist()
            List <KeyValuePair <string, object> > parameters = new List <KeyValuePair <string, object> >();

            parameters.Add(new KeyValuePair <string, object>(BaseParameterEntity.FieldCategoryCode, entity.CategoryCode));
            parameters.Add(new KeyValuePair <string, object>(BaseParameterEntity.FieldParameterId, entity.ParameterId));
            parameters.Add(new KeyValuePair <string, object>(BaseParameterEntity.FieldParameterCode, entity.ParameterCode));
            parameters.Add(new KeyValuePair <string, object>(BaseParameterEntity.FieldParameterContent, entity.ParameterContent));
            // 2015-12-22 吉日嘎拉 检查没有删除标志的,有删除标志的当日志用了
            parameters.Add(new KeyValuePair <string, object>(BaseParameterEntity.FieldDeletionStateCode, 0));
            if (this.Exists(parameters))
            {
                // 编号已重复
                this.StatusCode = Status.ErrorCodeExist.ToString();
            }
            else
            {
                if (string.IsNullOrEmpty(entity.Id))
                {
                    entity.Id = Guid.NewGuid().ToString("N");
                }
                result = this.AddObject(entity);
                // 运行成功
                this.StatusCode = Status.OKAdd.ToString();
            }

            return(result);
        }
コード例 #4
0
        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="entity">参数基类表结构定义</param>
        /// <returns>影响行数</returns>
        public int Update(BaseParameterEntity entity)
        {
            int result = 0;

            // 检查是否已被其他人修改
            //if (DbLogic.IsModifed(DbHelper, BaseParameterEntity.TableName, parameterEntity.Id, parameterEntity.ModifiedUserId, parameterEntity.ModifiedOn))
            //{
            //    // 数据已经被修改
            //    this.StatusCode = StatusCode.ErrorChanged.ToString();
            //}
            //else
            //{
            // 检查编号是否重复
            if (this.Exists(new KeyValuePair <string, object>(BaseParameterEntity.FieldParameterCode, entity.ParameterCode), entity.Id))
            {
                // 文件夹名已重复
                this.StatusCode = Status.ErrorCodeExist.ToString();
            }
            else
            {
                // 进行更新操作
                result = this.UpdateObject(entity);
                if (result == 1)
                {
                    this.StatusCode = Status.OKUpdate.ToString();
                }
                else
                {
                    // 数据可能被删除
                    this.StatusCode = Status.ErrorDeleted.ToString();
                }
            }
            // }
            return(result);
        }
コード例 #5
0
 /// <summary>
 /// 添加, 这里可以人工干预,提高程序的性能
 /// </summary>
 /// <param name="entity">实体</param>
 /// <param name="identity">自增量方式,表主键是否采用自增的策略</param>
 /// <param name="returnId">返回主键,不返回程序允许速度会快,主要是为了主细表批量插入数据优化用的</param>
 /// <returns>主键</returns>
 public string Add(BaseParameterEntity entity, bool identity = true, bool returnId = true)
 {
     Identity  = identity;
     ReturnId  = returnId;
     entity.Id = AddEntity(entity).ToInt();
     return(entity.Id.ToString());
 }
コード例 #6
0
 /// <summary>
 /// 设置实体
 /// </summary>
 /// <param name="entity">实体</param>
 private void SetObject(SQLBuilder sqlBuilder, BaseParameterEntity entity)
 {
     sqlBuilder.SetValue(BaseParameterEntity.FieldCategoryCode, entity.CategoryCode);
     sqlBuilder.SetValue(BaseParameterEntity.FieldParameterCode, entity.ParameterCode);
     sqlBuilder.SetValue(BaseParameterEntity.FieldParameterId, entity.ParameterId);
     sqlBuilder.SetValue(BaseParameterEntity.FieldParameterContent, entity.ParameterContent);
     sqlBuilder.SetValue(BaseParameterEntity.FieldWorked, entity.Worked ? 1 : 0);
     sqlBuilder.SetValue(BaseParameterEntity.FieldEnabled, entity.Enabled ? 1 : 0);
     sqlBuilder.SetValue(BaseParameterEntity.FieldDeletionStateCode, entity.DeletionStateCode);
     SetObjectExpand(sqlBuilder, entity);
 }
コード例 #7
0
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="categoryId">类别主键</param>
        /// <param name="parameterId">标记主键</param>
        /// <param name="parameterCode">标记编码</param>
        /// <param name="parameterContent">标记内容</param>
        /// <param name="worked">工作状态</param>
        /// <param name="enabled">有效</param>
        /// <returns>主键</returns>
        public string Add(string categoryId, string parameterId, string parameterCode, string parameterContent, bool worked, bool enabled)
        {
            BaseParameterEntity parameterEntity = new BaseParameterEntity();

            parameterEntity.CategoryId       = categoryId;
            parameterEntity.ParameterId      = parameterId;
            parameterEntity.ParameterCode    = parameterCode;
            parameterEntity.ParameterContent = parameterContent;
            parameterEntity.Worked           = worked;
            parameterEntity.Enabled          = enabled;
            return(this.Add(parameterEntity));
        }
コード例 #8
0
        public static void SetParameterByCache(string tableName, BaseParameterEntity entity)
        {
            string key = "Parameter:" + tableName + ":" + entity.CategoryCode + ":" + entity.ParameterId + ":" + entity.ParameterCode;

            using (var redisClient = PooledRedisHelper.GetClient())
            {
                if (!string.IsNullOrEmpty(entity.ParameterContent))
                {
                    redisClient.Set <string>(key, entity.ParameterContent, DateTime.Now.AddMinutes(10));
                }
            }
        }
コード例 #9
0
 /// <summary>
 /// 设置实体
 /// </summary>
 /// <param name="sqlBuilder">Sql语句生成器</param>
 /// <param name="entity">实体</param>
 private void SetEntity(SqlBuilder sqlBuilder, BaseParameterEntity entity)
 {
     SetEntityExtend(sqlBuilder, entity);
     sqlBuilder.SetValue(BaseParameterEntity.FieldSystemCode, entity.SystemCode);
     sqlBuilder.SetValue(BaseParameterEntity.FieldCategoryCode, entity.CategoryCode);
     sqlBuilder.SetValue(BaseParameterEntity.FieldParameterId, entity.ParameterId);
     sqlBuilder.SetValue(BaseParameterEntity.FieldParameterCode, entity.ParameterCode);
     sqlBuilder.SetValue(BaseParameterEntity.FieldParameterContent, entity.ParameterContent);
     sqlBuilder.SetValue(BaseParameterEntity.FieldDescription, entity.Description);
     sqlBuilder.SetValue(BaseParameterEntity.FieldSortCode, entity.SortCode);
     sqlBuilder.SetValue(BaseParameterEntity.FieldDeleted, entity.Deleted);
     sqlBuilder.SetValue(BaseParameterEntity.FieldEnabled, entity.Enabled);
 }
コード例 #10
0
        /// <summary>
        /// 添加实体
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="tableName">表名</param>
        /// <param name="entity">实体</param>
        /// <returns>主键</returns>
        public string Add(BaseUserInfo userInfo, string tableName, BaseParameterEntity entity)
        {
            var result = string.Empty;

            var parameter = ServiceInfo.Create(userInfo, MethodBase.GetCurrentMethod());

            ServiceUtil.ProcessUserCenterWriteDbWithTransaction(userInfo, parameter, (dbHelper) =>
            {
                var manager = new BaseParameterManager(dbHelper, userInfo, tableName);
                result      = manager.Add(entity);
            });

            return(result);
        }
コード例 #11
0
 /// <summary>
 /// 添加或更新(主键是否为0)
 /// </summary>
 /// <param name="entity">实体</param>
 /// <param name="identity">自增量方式,表主键是否采用自增的策略</param>
 /// <param name="returnId">返回主键,不返回程序允许速度会快,主要是为了主细表批量插入数据优化用的</param>
 /// <returns>主键</returns>
 public string AddOrUpdate(BaseParameterEntity 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);
     }
 }
コード例 #12
0
        /// <summary>
        /// 获取实体
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="tableName">表名</param>
        /// <param name="id">主键</param>
        /// <returns>实体</returns>
        public BaseParameterEntity GetEntity(BaseUserInfo userInfo, string tableName, string id)
        {
            BaseParameterEntity entity = null;

            var parameter = ServiceInfo.Create(userInfo, MethodBase.GetCurrentMethod());

            ServiceUtil.ProcessUserCenterReadDb(userInfo, parameter, (dbHelper) =>
            {
                var manager = new BaseParameterManager(dbHelper, userInfo, tableName);
                entity      = manager.GetEntity(id);
            });

            return(entity);
        }
コード例 #13
0
        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="tableName">表名</param>
        /// <param name="entity">实体</param>
        /// <returns>影响行数</returns>
        public int Update(BaseUserInfo userInfo, string tableName, BaseParameterEntity entity)
        {
            var result = 0;

            var returnCode    = string.Empty;
            var returnMessage = string.Empty;

            var parameter = ServiceInfo.Create(userInfo, MethodBase.GetCurrentMethod());

            ServiceUtil.ProcessUserCenterWriteDb(userInfo, parameter, (dbHelper) =>
            {
                var manager = new BaseParameterManager(dbHelper, userInfo, tableName);
                result      = manager.Update(entity);
            });
            return(result);
        }
コード例 #14
0
 /// <summary>
 /// 清除内容
 /// <param name="ParameterEntity">实体</param>
 /// </summary>
 public void ClearProperty(BaseParameterEntity ParameterEntity)
 {
     ParameterEntity.Id               = string.Empty;
     ParameterEntity.CategoryId       = string.Empty;
     ParameterEntity.ParameterId      = string.Empty;
     ParameterEntity.ParameterCode    = string.Empty;
     ParameterEntity.ParameterContent = string.Empty;
     ParameterEntity.Worked           = false;
     ParameterEntity.Enabled          = false;
     ParameterEntity.SortCode         = string.Empty;
     ParameterEntity.Description      = string.Empty;
     ParameterEntity.CreateUserId     = string.Empty;
     ParameterEntity.CreateOn         = string.Empty;
     ParameterEntity.ModifiedUserId   = string.Empty;
     ParameterEntity.ModifiedOn       = string.Empty;
 }
コード例 #15
0
        /// <summary>
        /// 更新参数设置
        /// </summary>
        /// <param name="tableName">表名</param>
        /// <param name="categoryCode">类别编号</param>
        /// <param name="parameterId">参数主键</param>
        /// <param name="parameterCode">编码</param>
        /// <param name="parameterContent">参数内容</param>
        /// <returns>影响行数</returns>
        public int SetParameter(string tableName, string categoryCode, string parameterId, string parameterCode, string parameterContent)
        {
            var result = 0;

            CurrentTableName = tableName;

            var parameters = new List <KeyValuePair <string, object> >
            {
                new KeyValuePair <string, object>(BaseParameterEntity.FieldCategoryCode, categoryCode),
                new KeyValuePair <string, object>(BaseParameterEntity.FieldParameterId, parameterId),
                new KeyValuePair <string, object>(BaseParameterEntity.FieldParameterCode, parameterCode),
                new KeyValuePair <string, object>(BaseParameterEntity.FieldDeleted, 0),
                new KeyValuePair <string, object>(BaseParameterEntity.FieldEnabled, 1)
            };

            // 检测是否无效数据
            if ((parameterContent == null) || (parameterContent.Length == 0))
            {
                result = Delete(parameters);
            }
            else
            {
                // 检测是否存在
                result = SetProperty(parameters, new KeyValuePair <string, object>(BaseParameterEntity.FieldParameterContent, parameterContent));
                if (result == 0)
                {
                    // 进行增加操作
                    var entity = new BaseParameterEntity
                    {
                        SystemCode       = BaseSystemInfo.SystemCode,
                        CategoryCode     = categoryCode,
                        ParameterId      = parameterId,
                        ParameterCode    = parameterCode,
                        ParameterContent = parameterContent,
                        Enabled          = 1,
                        Deleted          = 0,
                        SortCode         = 1 // 不要排序了
                    };
                    UniqueAdd(entity);
                    result = 1;
                }
            }
            //移除缓存
            RemoveCache();
            return(result);
        }
コード例 #16
0
        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="parameterEntity">实体</param>
        /// <returns>影响行数</returns>
        protected int UpdateEntity(BaseParameterEntity parameterEntity)
        {
            SQLBuilder sqlBuilder = new SQLBuilder(DbHelper);

            sqlBuilder.BeginUpdate(this.CurrentTableName);
            sqlBuilder.SetValue(BaseParameterEntity.FieldCategoryId, parameterEntity.CategoryId);
            sqlBuilder.SetValue(BaseParameterEntity.FieldParameterCode, parameterEntity.ParameterCode);
            sqlBuilder.SetValue(BaseParameterEntity.FieldParameterId, parameterEntity.ParameterId);
            sqlBuilder.SetValue(BaseParameterEntity.FieldParameterContent, parameterEntity.ParameterContent);
            sqlBuilder.SetValue(BaseParameterEntity.FieldWorked, parameterEntity.Worked ? 1 : 0);
            sqlBuilder.SetValue(BaseParameterEntity.FieldEnabled, parameterEntity.Enabled ? 1 : 0);
            sqlBuilder.SetValue(BaseParameterEntity.FieldDeletionStateCode, parameterEntity.DeletionStateCode);
            sqlBuilder.SetValue(BaseParameterEntity.FieldModifiedUserId, UserInfo.Id);
            sqlBuilder.SetValue(BaseParameterEntity.FieldModifiedBy, UserInfo.RealName);
            sqlBuilder.SetDBNow(BaseParameterEntity.FieldModifiedOn);
            sqlBuilder.SetWhere(BaseParameterEntity.FieldId, parameterEntity.Id);
            return(sqlBuilder.EndUpdate());
        }
コード例 #17
0
        /// <summary>
        /// 添加参数设置
        /// 2015-07-24 吉日嘎拉 按表名来添加、尽管添加的功能实现。
        /// </summary>
        /// <param name="tableName">表名</param>
        /// <param name="categoryCode">类别编号</param>
        /// <param name="parameterId">参数主键</param>
        /// <param name="parameterCode">编码</param>
        /// <param name="parameterContent">参数内容</param>
        /// <returns>主键</returns>
        public string AddParameter(string tableName, string categoryCode, string parameterId, string parameterCode, string parameterContent)
        {
            string result = string.Empty;

            this.CurrentTableName = tableName;

            /*
             * List<KeyValuePair<string, object>> parameters = new List<KeyValuePair<string, object>>();
             * parameters.Add(new KeyValuePair<string, object>(BaseParameterEntity.FieldCategoryCode, categoryCode));
             * parameters.Add(new KeyValuePair<string, object>(BaseParameterEntity.FieldParameterId, parameterId));
             * parameters.Add(new KeyValuePair<string, object>(BaseParameterEntity.FieldParameterCode, parameterCode));
             * parameters.Add(new KeyValuePair<string, object>(BaseParameterEntity.FieldDeletionStateCode, 0));
             * // 检测是否无效数据
             * if ((parameterContent == null) || (parameterContent.Length == 0))
             * {
             *  this.SetDeleted(parameters);
             * }
             * else
             * {
             *  parameters.Add(new KeyValuePair<string, object>(BaseParameterEntity.FieldParameterContent, parameterContent));
             *  result = this.GetProperty(parameters, BaseParameterEntity.FieldId);
             *  // 检测是否存在
             *  if (string.IsNullOrEmpty(result))
             *  {
             */
            // 进行增加操作
            BaseParameterEntity entity = new BaseParameterEntity();

            entity.Id                = Guid.NewGuid().ToString("N");
            entity.CategoryCode      = categoryCode;
            entity.ParameterId       = parameterId;
            entity.ParameterCode     = parameterCode;
            entity.ParameterContent  = parameterContent;
            entity.Enabled           = true;
            entity.DeletionStateCode = 0;
            result = this.AddObject(entity);

            /*
             *  }
             * }
             */

            return(result);
        }
コード例 #18
0
        /// <summary>
        /// 添加内容
        /// </summary>
        /// <param name="entity">内容</param>
        /// <returns>主键</returns>
        public string UniqueAdd(BaseParameterEntity entity)
        {
            var result = string.Empty;

            // 此处检查this.exist()
            var parameters = new List <KeyValuePair <string, object> >
            {
                new KeyValuePair <string, object>(BaseParameterEntity.FieldCategoryCode, entity.CategoryCode),
                new KeyValuePair <string, object>(BaseParameterEntity.FieldParameterId, entity.ParameterId),
                new KeyValuePair <string, object>(BaseParameterEntity.FieldParameterCode, entity.ParameterCode),
                new KeyValuePair <string, object>(BaseParameterEntity.FieldParameterContent, entity.ParameterContent),
                new KeyValuePair <string, object>(BaseParameterEntity.FieldDeleted, 0)
            };

            // 2015-12-22 吉日嘎拉 检查没有删除的,已删除的当日志用了
            if (Exists(parameters))
            {
                // 编号已重复
                Status     = Status.ErrorCodeExist;
                StatusCode = Status.ErrorCodeExist.ToString();
            }
            else
            {
                result = AddEntity(entity);
                if (!string.IsNullOrEmpty(result))
                {
                    // 运行成功
                    Status     = Status.OkAdd;
                    StatusCode = Status.OkAdd.ToString();
                }
                else
                {
                    // 失败
                    Status     = Status.Error;
                    StatusCode = Status.Error.ToString();
                }
            }

            return(result);
        }
コード例 #19
0
        /// <summary>
        /// 添加内容
        /// </summary>
        /// <param name="parameterEntity">内容</param>
        /// <returns>主键</returns>
        public string Add(BaseParameterEntity parameterEntity)
        {
            string returnValue = string.Empty;
            // 此处检查this.exist()
            List <KeyValuePair <string, object> > parameters = new List <KeyValuePair <string, object> >();

            parameters.Add(new KeyValuePair <string, object>(BaseParameterEntity.FieldCategoryId, parameterEntity.CategoryId));
            parameters.Add(new KeyValuePair <string, object>(BaseParameterEntity.FieldParameterId, parameterEntity.ParameterId));
            parameters.Add(new KeyValuePair <string, object>(BaseParameterEntity.FieldParameterCode, parameterEntity.ParameterCode));
            if (this.Exists(parameters))
            {
                // 编号已重复
                this.ReturnStatusCode = StatusCode.ErrorCodeExist.ToString();
            }
            else
            {
                returnValue = this.AddEntity(parameterEntity);
                // 运行成功
                this.ReturnStatusCode = StatusCode.OKAdd.ToString();
            }
            return(returnValue);
        }
コード例 #20
0
        /// <summary>
        /// 更新参数设置
        /// </summary>
        /// <param name="categoryCode">类别编号</param>
        /// <param name="parameterId">参数主键</param>
        /// <param name="parameterCode">编码</param>
        /// <param name="parameterContent">参数内容</param>
        /// <returns>影响行数</returns>
        public int SetParameter(string tableName, string categoryCode, string parameterId, string parameterCode, string parameterContent)
        {
            int result = 0;

            this.CurrentTableName = tableName;

            List <KeyValuePair <string, object> > parameters = new List <KeyValuePair <string, object> >();

            parameters.Add(new KeyValuePair <string, object>(BaseParameterEntity.FieldCategoryCode, categoryCode));
            parameters.Add(new KeyValuePair <string, object>(BaseParameterEntity.FieldParameterId, parameterId));
            parameters.Add(new KeyValuePair <string, object>(BaseParameterEntity.FieldParameterCode, parameterCode));
            parameters.Add(new KeyValuePair <string, object>(BaseParameterEntity.FieldDeletionStateCode, 0));
            // 检测是否无效数据
            if ((parameterContent == null) || (parameterContent.Length == 0))
            {
                result = this.Delete(parameters);
            }
            else
            {
                // 检测是否存在
                result = this.SetProperty(parameters, new KeyValuePair <string, object>(BaseParameterEntity.FieldParameterContent, parameterContent));
                if (result == 0)
                {
                    // 进行增加操作
                    BaseParameterEntity entity = new BaseParameterEntity();
                    entity.Id                = Guid.NewGuid().ToString("N");
                    entity.CategoryCode      = categoryCode;
                    entity.ParameterId       = parameterId;
                    entity.ParameterCode     = parameterCode;
                    entity.ParameterContent  = parameterContent;
                    entity.Enabled           = true;
                    entity.DeletionStateCode = 0;
                    this.Add(entity);
                    result = 1;
                }
            }
            return(result);
        }
コード例 #21
0
        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="entity">参数基类表结构定义</param>
        /// <returns>影响行数</returns>
        public int UniqueUpdate(BaseParameterEntity entity)
        {
            var result = 0;

            // 检查是否已被其他人修改
            //if (DbUtil.IsModifed(DbHelper, BaseParameterEntity.CurrentTableName, parameterEntity.Id, parameterEntity.UpdateUserId, parameterEntity.UpdateTime))
            //{
            //    // 数据已经被修改
            //    this.StatusCode = StatusCode.ErrorChanged.ToString();
            //}
            //else
            //{
            // 检查编号是否重复
            if (Exists(new KeyValuePair <string, object>(BaseParameterEntity.FieldParameterCode, entity.ParameterCode), entity.Id))
            {
                // 编码已重复
                Status     = Status.ErrorCodeExist;
                StatusCode = Status.ErrorCodeExist.ToString();
            }
            else
            {
                // 进行更新操作
                result = UpdateEntity(entity);
                if (result == 1)
                {
                    Status     = Status.OkUpdate;
                    StatusCode = Status.OkUpdate.ToString();
                }
                else
                {
                    // 数据可能被删除
                    Status     = Status.ErrorDeleted;
                    StatusCode = Status.ErrorDeleted.ToString();
                }
            }
            // }
            return(result);
        }
コード例 #22
0
        /// <summary>
        /// 更新实体
        /// </summary>
        /// <param name="entity">实体</param>
        public int UpdateObject(BaseParameterEntity entity)
        {
            SQLBuilder sqlBuilder = new SQLBuilder(DbHelper);

            sqlBuilder.BeginUpdate(this.CurrentTableName);
            this.SetObject(sqlBuilder, entity);
            if (UserInfo != null)
            {
                sqlBuilder.SetValue(BaseParameterEntity.FieldModifiedUserId, UserInfo.Id);
                sqlBuilder.SetValue(BaseParameterEntity.FieldModifiedBy, UserInfo.RealName);
            }
            // 若有修改时间标示,那就按修改时间来,不是按最新的时间来
            if (entity.ModifiedOn.HasValue)
            {
                sqlBuilder.SetValue(BaseParameterEntity.FieldModifiedOn, entity.ModifiedOn.Value);
            }
            else
            {
                sqlBuilder.SetDBNow(BaseParameterEntity.FieldModifiedOn);
            }
            sqlBuilder.SetWhere(BaseParameterEntity.FieldId, entity.Id);
            return(sqlBuilder.EndUpdate());
        }
コード例 #23
0
        /// <summary>
        /// 更新实体
        /// </summary>
        /// <param name="entity">实体</param>
        public int UpdateEntity(BaseParameterEntity entity)
        {
            var sqlBuilder = new SqlBuilder(DbHelper);

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

            if (result > 0)
            {
                RemoveCache(entity.Id);
            }
            return(result);
        }
コード例 #24
0
        /// <summary>
        /// 添加实体
        /// </summary>
        /// <param name="entity">实体</param>
        public string AddObject(BaseParameterEntity entity)
        {
            string result = string.Empty;
            //if (!entity.SortCode.HasValue)
            //{
            //    BaseSequenceManager sequenceManager = new BaseSequenceManager(DbHelper, this.Identity);
            //    result = sequenceManager.Increment(this.CurrentTableName);
            //    entity.SortCode = int.Parse(result);
            //}
            SQLBuilder sqlBuilder = new SQLBuilder(DbHelper, this.Identity, this.ReturnId);

            sqlBuilder.BeginInsert(this.CurrentTableName, BaseParameterEntity.FieldId);
            if (!string.IsNullOrEmpty(entity.Id) || !this.Identity)
            {
                result = entity.Id;
                sqlBuilder.SetValue(BaseParameterEntity.FieldId, entity.Id);
            }
            else
            {
                if (!this.ReturnId && (DbHelper.CurrentDbType == CurrentDbType.Oracle || DbHelper.CurrentDbType == CurrentDbType.DB2))
                {
                    if (DbHelper.CurrentDbType == CurrentDbType.Oracle)
                    {
                        sqlBuilder.SetFormula(BaseParameterEntity.FieldId, "SEQ_" + BaseParameterEntity.TableName.ToUpper() + ".NEXTVAL ");
                        // sqlBuilder.SetFormula(BaseParameterEntity.FieldId, "SEQ_" + this.CurrentTableName.ToUpper() + ".NEXTVAL ");
                    }
                    if (DbHelper.CurrentDbType == CurrentDbType.DB2)
                    {
                        sqlBuilder.SetFormula(BaseParameterEntity.FieldId, "NEXT VALUE FOR SEQ_" + this.CurrentTableName.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(BaseParameterEntity.TableName);
                                // result = sequenceManager.Increment(this.CurrentTableName);
                            }
                            entity.Id = result;
                        }
                        sqlBuilder.SetValue(BaseParameterEntity.FieldId, entity.Id);
                    }
                }
            }
            this.SetObject(sqlBuilder, entity);

            // 创建人信息
            if (!string.IsNullOrEmpty(entity.CreateUserId))
            {
                sqlBuilder.SetValue(BaseParameterEntity.FieldCreateUserId, entity.CreateUserId);
            }
            else
            {
                if (UserInfo != null)
                {
                    sqlBuilder.SetValue(BaseParameterEntity.FieldCreateUserId, UserInfo.Id);
                }
            }
            if (!string.IsNullOrEmpty(entity.CreateBy))
            {
                sqlBuilder.SetValue(BaseParameterEntity.FieldCreateBy, entity.CreateBy);
            }
            else
            {
                if (UserInfo != null)
                {
                    sqlBuilder.SetValue(BaseParameterEntity.FieldCreateBy, UserInfo.RealName);
                }
            }
            if (entity.CreateOn.HasValue)
            {
                sqlBuilder.SetValue(BaseParameterEntity.FieldCreateOn, entity.CreateOn);
            }
            else
            {
                sqlBuilder.SetDBNow(BaseParameterEntity.FieldCreateOn);
            }

            // 修改人信息
            if (!string.IsNullOrEmpty(entity.ModifiedUserId))
            {
                sqlBuilder.SetValue(BaseParameterEntity.FieldModifiedUserId, entity.ModifiedUserId);
            }
            else
            {
                if (UserInfo != null)
                {
                    sqlBuilder.SetValue(BaseParameterEntity.FieldModifiedUserId, UserInfo.Id);
                }
            }
            if (!string.IsNullOrEmpty(entity.ModifiedBy))
            {
                sqlBuilder.SetValue(BaseParameterEntity.FieldModifiedBy, entity.ModifiedBy);
            }
            else
            {
                if (UserInfo != null)
                {
                    sqlBuilder.SetValue(BaseParameterEntity.FieldModifiedBy, UserInfo.RealName);
                }
            }
            if (entity.ModifiedOn.HasValue)
            {
                sqlBuilder.SetValue(BaseParameterEntity.FieldModifiedOn, entity.ModifiedOn);
            }
            else
            {
                sqlBuilder.SetDBNow(BaseParameterEntity.FieldModifiedOn);
            }

            if (DbHelper.CurrentDbType == CurrentDbType.SqlServer && this.Identity)
            {
                result = sqlBuilder.EndInsert().ToString();
            }
            else
            {
                sqlBuilder.EndInsert();
            }
            return(result);
        }
コード例 #25
0
        /// <summary>
        /// 更新密码
        /// </summary>
        /// <param name="oldPassword">原密码</param>
        /// <param name="newPassword">新密码</param>
        /// <param name="statusCode">返回状态码</param>
        /// <returns>影响行数</returns>
        public virtual int ChangePassword(string oldPassword, string newPassword, out string statusCode)
        {
            #if (DEBUG)
            int milliStart = Environment.TickCount;
            #endif

            int returnValue = 0;
            // 密码强度检查
            if (BaseSystemInfo.CheckPasswordStrength)
            {
                if (String.IsNullOrEmpty(newPassword))
                {
                    statusCode = StatusCode.PasswordCanNotBeNull.ToString();
                    return(returnValue);
                }
            }
            // 加密密码
            if (BaseSystemInfo.ServerEncryptPassword)
            {
                oldPassword = this.EncryptUserPassword(oldPassword);
                newPassword = this.EncryptUserPassword(newPassword);
            }
            // 判断输入原始密码是否正确
            BaseUserEntity userEntity = new BaseUserEntity();
            userEntity.GetSingle(this.GetDataTableById(UserInfo.Id));
            if (userEntity.UserPassword == null)
            {
                userEntity.UserPassword = string.Empty;
            }
            // 密码错误
            if (!userEntity.UserPassword.Equals(oldPassword))
            {
                statusCode = StatusCode.OldPasswordError.ToString();
                return(returnValue);
            }
            // 对比是否最近2次用过这个密码
            if (BaseSystemInfo.CheckPasswordStrength)
            {
                int i = 0;
                BaseParameterManager parameterManager = new BaseParameterManager(this.DbHelper, this.UserInfo);
                DataTable            dataTable        = parameterManager.GetDataTableParameterCode("User", this.UserInfo.Id, "Password");
                foreach (DataRow dataRow in dataTable.Rows)
                {
                    string parameter = dataRow[BaseParameterEntity.FieldParameterContent].ToString();
                    if (parameter.Equals(newPassword))
                    {
                        statusCode = StatusCode.PasswordCanNotBeRepeat.ToString();
                        return(returnValue);
                    }
                    i++;
                    {
                        // 判断连续2个密码就是可以了
                        if (i > 2)
                        {
                            break;
                        }
                    }
                }
            }
            // 更改密码,同时修改密码的修改日期
            List <KeyValuePair <string, object> > parameters = new List <KeyValuePair <string, object> >();
            parameters.Add(new KeyValuePair <string, object>(BaseUserEntity.FieldUserPassword, newPassword));
            // 注意日期格式,ACCESS中要用字符
            parameters.Add(new KeyValuePair <string, object>(BaseUserEntity.FieldChangePasswordDate, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")));
            returnValue = this.SetProperty(new KeyValuePair <string, object>(BaseUserEntity.FieldId, UserInfo.Id), parameters);
            if (returnValue == 1)
            {
                statusCode = StatusCode.ChangePasswordOK.ToString();
                // 若是强类型密码检查,那就保存密码修改历史,防止最近2-3次的密码相同的功能实现。
                if (BaseSystemInfo.CheckPasswordStrength)
                {
                    BaseParameterManager parameterManager = new BaseParameterManager(this.DbHelper, this.UserInfo);
                    BaseParameterEntity  parameterEntity  = new BaseParameterEntity();
                    parameterEntity.CategoryId        = "User";
                    parameterEntity.ParameterId       = this.UserInfo.Id;
                    parameterEntity.ParameterCode     = "Password";
                    parameterEntity.ParameterContent  = newPassword;
                    parameterEntity.DeletionStateCode = 0;
                    parameterEntity.Enabled           = true;
                    parameterEntity.Worked            = true;
                    parameterManager.AddEntity(parameterEntity);
                }
            }
            else
            {
                // 数据可能被删除
                statusCode = StatusCode.ErrorDeleted.ToString();
            }

            // 写入调试信息
            #if (DEBUG)
            int milliEnd = Environment.TickCount;
            Trace.WriteLine(DateTime.Now.ToString(BaseSystemInfo.TimeFormat) + " Ticks: " + TimeSpan.FromMilliseconds(milliEnd - milliStart).ToString() + " " + " BaseUserManager.ChangePassword(" + userEntity.Id + ")");
            #endif

            return(returnValue);
        }
コード例 #26
0
 // 这个是声明扩展方法
 partial void SetEntityExtend(SqlBuilder sqlBuilder, BaseParameterEntity entity);
コード例 #27
0
        /// <summary>
        /// 设置缓存
        /// </summary>
        /// <param name="tableName"></param>
        /// <param name="entity"></param>
        public static void SetParameterByCache(string tableName, BaseParameterEntity entity)
        {
            var key = "Parameter:" + tableName + ":" + entity.CategoryCode + ":" + entity.ParameterId + ":" + entity.ParameterCode;

            CacheUtil.Set <string>(key, entity.ParameterContent);
        }
コード例 #28
0
        /// <summary>
        /// 添加实体
        /// </summary>
        /// <param name="entity">实体</param>
        public string AddEntity(BaseParameterEntity 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(BaseParameterEntity.FieldCreateUserId, UserInfo.UserId);
                sqlBuilder.SetValue(BaseParameterEntity.FieldCreateUserName, UserInfo.UserName);
                sqlBuilder.SetValue(BaseParameterEntity.FieldCreateBy, UserInfo.RealName);
            }
            else
            {
                sqlBuilder.SetValue(BaseParameterEntity.FieldCreateBy, entity.CreateBy);
                sqlBuilder.SetValue(BaseParameterEntity.FieldCreateUserName, entity.CreateUserName);
            }
            sqlBuilder.SetDbNow(BaseParameterEntity.FieldCreateTime);
            sqlBuilder.SetValue(BaseParameterEntity.FieldCreateIp, Utils.GetIp());
            if (UserInfo != null)
            {
                sqlBuilder.SetValue(BaseParameterEntity.FieldUpdateUserId, UserInfo.UserId);
                sqlBuilder.SetValue(BaseParameterEntity.FieldUpdateUserName, UserInfo.UserName);
                sqlBuilder.SetValue(BaseParameterEntity.FieldUpdateBy, UserInfo.RealName);
            }
            sqlBuilder.SetDbNow(BaseParameterEntity.FieldUpdateTime);
            sqlBuilder.SetValue(BaseParameterEntity.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);
        }
コード例 #29
0
        /// <summary>
        /// 检查用户的 macAddress 绑定是否正常
        ///
        /// 防止重复多读数据?
        /// 是否判断正确?
        /// 可以按每个用户缓存?
        /// 若没有就自动化增加?
        /// mac 限制完善?
        /// mac 限制缓存预热?
        /// </summary>
        /// <param name="userId">用户主键</param>
        /// <param name="macAddress">硬件地址</param>
        /// <returns>正确</returns>
        public static bool CheckMACAddressByCache(string userId, string macAddress)
        {
            // 默认是不成功的,防止出错误
            bool result = false;

            // 检查参数的有效性
            if (string.IsNullOrEmpty(userId))
            {
                return(result);
            }
            if (string.IsNullOrEmpty(macAddress))
            {
                return(result);
            }

            // 提高效率,全小写转换
            macAddress = macAddress.ToLower();

            // 这里是处理,多个mac的问题
            string[] mac = macAddress.Split(';');

            using (var redisClient = PooledRedisHelper.GetClient())
            {
                string key = "MAC:" + userId;

                // 若是缓存里过期了?
                if (!redisClient.ContainsKey(key))
                {
                    // 重新缓存用户的限制数据
                    if (CachePreheatingMACAddressByUser(redisClient, userId) == 0)
                    {
                        // 若没有设置mac限制,需要把限制都自动加上来。
                        // 没有加到数据的,就是表明是新增加的用户、第一次登录的用户
                        BaseParameterManager parameterManager = new BaseParameterManager();
                        for (int i = 0; i < mac.Length; i++)
                        {
                            if (!string.IsNullOrEmpty(mac[i]))
                            {
                                // 把收集过来的mac地址需要保存起来
                                BaseParameterEntity parameterEntity = new BaseParameterEntity();
                                parameterEntity.Id            = Guid.NewGuid().ToString("N");
                                parameterEntity.CategoryCode  = "MacAddress";
                                parameterEntity.ParameterCode = "Single";
                                parameterEntity.ParameterId   = userId;
                                // 这里之际保存小写、就效率也高,省事了
                                parameterEntity.ParameterContent = mac[i].Trim();
                                parameterManager.Add(parameterEntity);
                            }
                        }
                        result = true;
                    }
                }

                // 若还是没有?表示是新增的
                if (redisClient.ContainsKey(key))
                {
                    // 若已经存在,就需要进行缓存里的判断?
                    // 这里要提高效率,不能反复打开缓存
                    for (int i = 0; i < mac.Length; i++)
                    {
                        // 这里对数据还不放心,进行优化处理
                        if (!string.IsNullOrEmpty(mac[i]))
                        {
                            mac[i] = mac[i].Trim();
                            result = redisClient.SetContainsItem(key, mac[i]);
                            if (result)
                            {
                                // 这里要提高判断的效率
                                break;
                            }
                        }
                    }
                    // 若没有验证成功、把当前的 macAddress 保存起来, 方便后台管理的人加上去。
                    if (!result)
                    {
                        List <KeyValuePair <string, object> > parameters = new List <KeyValuePair <string, object> >();
                        parameters.Add(new KeyValuePair <string, object>(BaseUserLogOnEntity.FieldMACAddress, macAddress));
                        BaseUserLogOnManager userLogOnManager = new BaseUserLogOnManager();
                        userLogOnManager.SetProperty(userId, parameters);
                    }
                }
            }

            return(result);
        }
コード例 #30
0
 partial void SetObjectExpand(SQLBuilder sqlBuilder, BaseParameterEntity entity);