/// <summary>
        /// 添加
        /// </summary>
        /// <param name="entity">实体</param>
        /// <param name="statusCode">返回状态码</param>
        /// <returns>返回</returns>
        public string Add(BaseModuleEntity entity, out string statusCode)
        {
            string result = string.Empty;
            // 检查名称是否重复
            List <KeyValuePair <string, object> > parameters = new List <KeyValuePair <string, object> >();

            if (!string.IsNullOrEmpty(entity.ParentId))
            {
                parameters.Add(new KeyValuePair <string, object>(BaseModuleEntity.FieldParentId, entity.ParentId));
            }
            parameters.Add(new KeyValuePair <string, object>(BaseModuleEntity.FieldCode, entity.Code));
            parameters.Add(new KeyValuePair <string, object>(BaseModuleEntity.FieldFullName, entity.FullName));
            parameters.Add(new KeyValuePair <string, object>(BaseModuleEntity.FieldDeletionStateCode, 0));

            if (this.Exists(parameters))
            {
                // 名称已重复
                statusCode = Status.ErrorCodeExist.ToString();
            }
            else
            {
                result = this.AddObject(entity);
                // 运行成功
                statusCode = Status.OKAdd.ToString();
            }
            return(result);
        }
        /// <summary>
        /// 从缓存获取获取实体
        /// </summary>
        /// <param name="systemCode">系统编号</param>
        /// <param name="code">编号</param>
        /// <returns>权限实体</returns>
        public static BaseModuleEntity GetObjectByCacheByCode(string systemCode, string code)
        {
            BaseModuleEntity result = null;

            string cacheKey = systemCode + ".Module";

            if (!string.IsNullOrEmpty(code))
            {
                cacheKey = systemCode + ".Module." + code;
            }
            result = GetCacheByKey(cacheKey);

            if (result == null)
            {
                // 动态读取表中的数据
                string            tableName = systemCode + "Module";
                BaseModuleManager manager   = new BaseModuleManager(tableName);
                result = manager.GetObjectByCode(code);
                // 若是空的不用缓存,继续读取实体
                if (result != null)
                {
                    SetCache(systemCode, result);
                }
            }

            return(result);
        }
Beispiel #3
0
 /// <summary>
 /// 设置实体
 /// </summary>
 /// <param name="sqlBuilder">Sql语句生成器</param>
 /// <param name="entity">实体</param>
 private void SetEntity(SqlBuilder sqlBuilder, BaseModuleEntity entity)
 {
     SetEntityExtend(sqlBuilder, entity);
     sqlBuilder.SetValue(BaseModuleEntity.FieldSystemCode, entity.SystemCode);
     sqlBuilder.SetValue(BaseModuleEntity.FieldParentId, entity.ParentId);
     sqlBuilder.SetValue(BaseModuleEntity.FieldCode, entity.Code);
     sqlBuilder.SetValue(BaseModuleEntity.FieldName, entity.Name);
     sqlBuilder.SetValue(BaseModuleEntity.FieldCategoryCode, entity.CategoryCode);
     sqlBuilder.SetValue(BaseModuleEntity.FieldImageUrl, entity.ImageUrl);
     sqlBuilder.SetValue(BaseModuleEntity.FieldImageIndex, entity.ImageIndex);
     sqlBuilder.SetValue(BaseModuleEntity.FieldSelectedImageIndex, entity.SelectedImageIndex);
     sqlBuilder.SetValue(BaseModuleEntity.FieldNavigateUrl, entity.NavigateUrl);
     sqlBuilder.SetValue(BaseModuleEntity.FieldTarget, entity.Target);
     sqlBuilder.SetValue(BaseModuleEntity.FieldFormName, entity.FormName);
     sqlBuilder.SetValue(BaseModuleEntity.FieldAssemblyName, entity.AssemblyName);
     sqlBuilder.SetValue(BaseModuleEntity.FieldPermissionScopeTables, entity.PermissionScopeTables);
     sqlBuilder.SetValue(BaseModuleEntity.FieldIsMenu, entity.IsMenu);
     sqlBuilder.SetValue(BaseModuleEntity.FieldIsPublic, entity.IsPublic);
     sqlBuilder.SetValue(BaseModuleEntity.FieldIsExpand, entity.IsExpand);
     sqlBuilder.SetValue(BaseModuleEntity.FieldIsScope, entity.IsScope);
     sqlBuilder.SetValue(BaseModuleEntity.FieldIsVisible, entity.IsVisible);
     sqlBuilder.SetValue(BaseModuleEntity.FieldAllowEdit, entity.AllowEdit);
     sqlBuilder.SetValue(BaseModuleEntity.FieldAllowDelete, entity.AllowDelete);
     sqlBuilder.SetValue(BaseModuleEntity.FieldLastCall, entity.LastCall);
     sqlBuilder.SetValue(BaseModuleEntity.FieldWebBrowser, entity.WebBrowser);
     sqlBuilder.SetValue(BaseModuleEntity.FieldAuthorizedDays, entity.AuthorizedDays);
     sqlBuilder.SetValue(BaseModuleEntity.FieldDescription, entity.Description);
     sqlBuilder.SetValue(BaseModuleEntity.FieldSortCode, entity.SortCode);
     sqlBuilder.SetValue(BaseModuleEntity.FieldDeleted, entity.Deleted);
     sqlBuilder.SetValue(BaseModuleEntity.FieldEnabled, entity.Enabled);
 }
        /// <summary>
        /// 用户的所有可授权范围(有授权权限的权限列表)
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="userId">用户主键</param>
        /// <param name="permissionCode">权限域编号</param>
        /// <returns>数据表</returns>
        public DataTable GetPermissionDTByPermission(BaseUserInfo userInfo, string userId, string permissionCode)
        {
            var dt = new DataTable(BaseModuleEntity.CurrentTableName);

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

            ServiceUtil.ProcessUserCenterReadDb(userInfo, parameter, (dbHelper) =>
            {
                var permissionId = new BaseModuleManager().GetIdByCodeByCache(userInfo.SystemCode, permissionCode);
                // 数据库里没有设置可授权的权限项,系统自动增加一个权限配置项
                if (string.IsNullOrEmpty(permissionId) && permissionCode.Equals("Resource.ManagePermission"))
                {
                    var permissionEntity = new BaseModuleEntity
                    {
                        Code        = "Resource.ManagePermission",
                        Name        = "资源管理范围权限(系统默认)",
                        IsScope     = 1,
                        Enabled     = 1,
                        AllowDelete = 0
                    };
                    permissionEntity.AllowDelete = 0;
                    new BaseModuleManager(userInfo).AddEntity(permissionEntity);
                }
                dt           = new BaseModuleManager().GetDataTableByUser(userInfo.SystemCode, userId, permissionCode);
                dt.TableName = BaseModuleEntity.CurrentTableName;
            });
            return(dt);
        }
        /// <summary>
        /// 缓存预热,强制重新缓存
        /// </summary>
        /// <param name="systemCode">系统编号</param>
        /// <returns>影响行数</returns>
        public static int CachePreheating(string systemCode)
        {
            int result = 0;

            // 把所有的组织机构都缓存起来的代码
            BaseModuleManager manager = new BaseModuleManager();

            manager.CurrentTableName = systemCode + "Module";
            using (IDataReader dataReader = manager.ExecuteReader())
            {
                while (dataReader.Read())
                {
                    BaseModuleEntity entity = BaseEntity.Create <BaseModuleEntity>(dataReader, false);
                    if (entity != null)
                    {
                        BaseModuleManager.SetCache(systemCode, entity);
                        result++;
                        System.Console.WriteLine(result.ToString() + " : " + entity.Code);
                    }
                }
                dataReader.Close();
            }

            return(result);
        }
 /// <summary>
 /// 设置实体
 /// </summary>
 /// <param name="entity">实体</param>
 private void SetObject(SQLBuilder sqlBuilder, BaseModuleEntity entity)
 {
     SetObjectExpand(sqlBuilder, entity);
     sqlBuilder.SetValue(BaseModuleEntity.FieldParentId, entity.ParentId);
     sqlBuilder.SetValue(BaseModuleEntity.FieldCode, entity.Code);
     sqlBuilder.SetValue(BaseModuleEntity.FieldFullName, entity.FullName);
     sqlBuilder.SetValue(BaseModuleEntity.FieldCategoryCode, entity.CategoryCode);
     sqlBuilder.SetValue(BaseModuleEntity.FieldImageIndex, entity.ImageIndex);
     sqlBuilder.SetValue(BaseModuleEntity.FieldSelectedImageIndex, entity.SelectedImageIndex);
     sqlBuilder.SetValue(BaseModuleEntity.FieldNavigateUrl, entity.NavigateUrl);
     sqlBuilder.SetValue(BaseModuleEntity.FieldImagUrl, entity.ImagUrl);
     sqlBuilder.SetValue(BaseModuleEntity.FieldTarget, entity.Target);
     sqlBuilder.SetValue(BaseModuleEntity.FieldFormName, entity.FormName);
     sqlBuilder.SetValue(BaseModuleEntity.FieldAssemblyName, entity.AssemblyName);
     // sqlBuilder.SetValue(BaseModuleEntity.FieldPermissionScopeTables, entity.PermissionScopeTables);
     sqlBuilder.SetValue(BaseModuleEntity.FieldIsMenu, entity.IsMenu);
     sqlBuilder.SetValue(BaseModuleEntity.FieldIsPublic, entity.IsPublic);
     sqlBuilder.SetValue(BaseModuleEntity.FieldIsScope, entity.IsScope);
     sqlBuilder.SetValue(BaseModuleEntity.FieldIsVisible, entity.IsVisible);
     sqlBuilder.SetValue(BaseModuleEntity.FieldExpand, entity.Expand);
     sqlBuilder.SetValue(BaseModuleEntity.FieldAllowEdit, entity.AllowEdit);
     sqlBuilder.SetValue(BaseModuleEntity.FieldAllowDelete, entity.AllowDelete);
     sqlBuilder.SetValue(BaseModuleEntity.FieldSortCode, entity.SortCode);
     sqlBuilder.SetValue(BaseModuleEntity.FieldEnabled, entity.Enabled);
     sqlBuilder.SetValue(BaseModuleEntity.FieldDeletionStateCode, entity.DeletionStateCode);
     sqlBuilder.SetValue(BaseModuleEntity.FieldDescription, entity.Description);
 }
        /// <summary>
        /// 保存实体修改记录
        /// </summary>
        /// <param name="entityNew">修改后的实体对象</param>
        /// <param name="entityOld">修改前的实体对象</param>
        /// <param name="tableName">表名称</param>
        public void SaveEntityChangeLog(BaseModuleEntity entityNew, BaseModuleEntity entityOld, string tableName = null)
        {
            if (string.IsNullOrEmpty(tableName))
            {
                //统一放在一个公共表 Troy.Cui 2016-08-17
                tableName = BaseChangeLogEntity.CurrentTableName;
            }
            var manager = new BaseChangeLogManager(UserInfo, tableName);

            foreach (var property in typeof(BaseModuleEntity).GetProperties())
            {
                var oldValue         = Convert.ToString(property.GetValue(entityOld, null));
                var newValue         = Convert.ToString(property.GetValue(entityNew, null));
                var fieldDescription = property.GetCustomAttributes(typeof(FieldDescription), false).FirstOrDefault() as FieldDescription;
                //不记录创建人、修改人、没有修改的记录
                if (!fieldDescription.NeedLog || oldValue == newValue)
                {
                    continue;
                }
                var entity = new BaseChangeLogEntity
                {
                    TableName         = CurrentTableName,
                    TableDescription  = FieldExtensions.ToDescription(typeof(BaseModuleEntity), "CurrentTableName"),
                    ColumnName        = property.Name,
                    ColumnDescription = fieldDescription.Text,
                    NewValue          = newValue,
                    OldValue          = oldValue,
                    RecordKey         = entityOld.Id.ToString()
                };
                manager.Add(entity, true, false);
            }
        }
        /// <summary>
        /// 保存实体修改记录
        /// </summary>
        /// <param name="newEntity">修改前的实体对象</param>
        /// <param name="oldEntity">修改后的实体对象</param>
        /// <param name="tableName">表名称</param>
        public void UpdateEntityLog(BaseModuleEntity newEntity, BaseModuleEntity oldEntity, string tableName = null)
        {
            if (string.IsNullOrEmpty(tableName))
            {
                // tableName = this.CurrentTableName + "_LOG";
                tableName = BaseModifyRecordEntity.TableName;
            }
            BaseModifyRecordManager manager = new BaseModifyRecordManager(this.UserInfo, tableName);

            foreach (var property in typeof(BaseModuleEntity).GetProperties())
            {
                var oldValue         = Convert.ToString(property.GetValue(oldEntity, null));
                var newValue         = Convert.ToString(property.GetValue(newEntity, null));
                var fieldDescription = property.GetCustomAttributes(typeof(FieldDescription), false).FirstOrDefault() as FieldDescription;
                //不记录创建人、修改人、没有修改的记录
                if (!fieldDescription.NeedLog || oldValue == newValue)
                {
                    continue;
                }
                var record = new BaseModifyRecordEntity();
                record.ColumnCode        = property.Name.ToUpper();
                record.ColumnDescription = fieldDescription.Text;
                record.NewValue          = newValue;
                record.OldValue          = oldValue;
                record.TableCode         = this.CurrentTableName.ToUpper();
                record.TableDescription  = FieldExtensions.ToDescription(typeof(BaseModuleEntity), "TableName");
                record.RecordKey         = oldEntity.Id.ToString();
                record.IPAddress         = Utilities.GetIPAddress(true);
                manager.Add(record, true, false);
            }
        }
Beispiel #9
0
 /// <summary>
 /// 添加, 这里可以人工干预,提高程序的性能
 /// </summary>
 /// <param name="entity">实体</param>
 /// <param name="identity">自增量方式,表主键是否采用自增的策略</param>
 /// <param name="returnId">返回主键,不返回程序允许速度会快,主要是为了主细表批量插入数据优化用的</param>
 /// <returns>主键</returns>
 public string Add(BaseModuleEntity entity, bool identity = true, bool returnId = true)
 {
     Identity  = identity;
     ReturnId  = returnId;
     entity.Id = AddEntity(entity).ToInt();
     return(entity.Id.ToString());
 }
        /// <summary>
        /// Add 添加的主键
        /// </summary>
        /// <param name="paramobject">对象</param>
        /// <returns>主键</returns>
        public string Add(string fullName)
        {
            string           statusCode   = string.Empty;
            BaseModuleEntity moduleEntity = new BaseModuleEntity();

            moduleEntity.FullName = fullName;
            return(this.Add(moduleEntity, out statusCode));
        }
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="code">编号</param>
        /// <param name="fullName">名称</param>
        /// <param name="statusCode">返回状态码</param>
        /// <returns>主键</returns>
        public string AddByDetail(string code, string fullName, out string statusCode)
        {
            BaseModuleEntity permissionEntity = new BaseModuleEntity();

            permissionEntity.Code     = code;
            permissionEntity.FullName = fullName;
            return(this.Add(permissionEntity, out statusCode));
        }
        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="entity">实体</param>
        /// <param name="status">状态</param>
        /// <returns>返回</returns>
        public int UniqueUpdate(BaseModuleEntity entity, out Status status)
        {
            var result = 0;

            var parameters = new List <KeyValuePair <string, object> >
            {
                new KeyValuePair <string, object>(BaseModuleEntity.FieldSystemCode, entity.SystemCode),
                new KeyValuePair <string, object>(BaseModuleEntity.FieldParentId, entity.ParentId),
                new KeyValuePair <string, object>(BaseModuleEntity.FieldCode, entity.Code),
                new KeyValuePair <string, object>(BaseModuleEntity.FieldName, entity.Name),
                new KeyValuePair <string, object>(BaseModuleEntity.FieldDeleted, 0)
            };

            // 检查编号是否重复
            if ((entity.Code.Length > 0) && (Exists(parameters, entity.Id)))
            {
                // 编号已重复
                Status        = Status.ErrorCodeExist;
                StatusCode    = Status.ErrorCodeExist.ToString();
                StatusMessage = Status.ErrorCodeExist.ToDescription();
            }
            else
            {
                // 获取原始实体信息
                var entityOld = GetEntity(entity.Id);
                if (entityOld != null)
                {
                    // 保存修改记录,无论是否允许
                    SaveEntityChangeLog(entity, entityOld);
                    // 2015-07-14 吉日嘎拉 只有允许修改的,才可以修改,不允许修改的,不让修改,但是把修改记录会保存起来的。
                    if (entityOld.AllowEdit == 1)
                    {
                        result = UpdateEntity(entity);
                        if (result == 1)
                        {
                            Status        = Status.OkUpdate;
                            StatusCode    = Status.OkUpdate.ToString();
                            StatusMessage = Status.OkUpdate.ToDescription();
                        }
                        else
                        {
                            Status        = Status.ErrorDeleted;
                            StatusCode    = Status.ErrorDeleted.ToString();
                            StatusMessage = Status.ErrorDeleted.ToDescription();
                        }
                    }
                    else
                    {
                        Status        = Status.NotAllowEdit;
                        StatusCode    = Status.NotAllowEdit.ToString();
                        StatusMessage = Status.NotAllowEdit.ToDescription();
                    }
                }
            }
            status = Status;
            return(result);
        }
        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="moduleEntity">实体</param>
        /// <param name="statusCode">返回状态码</param>
        /// <returns>返回</returns>
        public int Update(BaseModuleEntity entity, out string statusCode)
        {
            int result = 0;
            // 检查是否已被其他人修改
            //if (DbLogic.IsModifed(DbHelper, BaseModuleEntity.TableName, moduleEntity.Id, moduleEntity.ModifiedUserId, moduleEntity.ModifiedOn))
            //{
            //    // 数据已经被修改
            //    statusCode = StatusCode.ErrorChanged.ToString();
            //}
            //else
            //{

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

            if (!string.IsNullOrEmpty(entity.ParentId))
            {
                parameters.Add(new KeyValuePair <string, object>(BaseModuleEntity.FieldParentId, entity.ParentId));
            }
            else
            {
                parameters.Add(new KeyValuePair <string, object>(BaseModuleEntity.FieldParentId, null));
            }
            parameters.Add(new KeyValuePair <string, object>(BaseModuleEntity.FieldCode, entity.Code));
            parameters.Add(new KeyValuePair <string, object>(BaseModuleEntity.FieldFullName, entity.FullName));
            parameters.Add(new KeyValuePair <string, object>(BaseModuleEntity.FieldDeletionStateCode, 0));

            // 检查编号是否重复
            if ((entity.Code.Length > 0) && (this.Exists(parameters, entity.Id)))
            {
                // 编号已重复
                statusCode = Status.ErrorCodeExist.ToString();
            }
            else
            {
                // 获取原始实体信息
                var entityOld = this.GetObject(entity.Id.ToString());
                // 保存修改记录
                this.UpdateEntityLog(entity, entityOld);
                // 2015-07-14 吉日嘎拉 只有允许修改的,才可以修改,不允许修改的,不让修改,但是把修改记录会保存起来的。
                if (entityOld.AllowEdit.HasValue && entityOld.AllowEdit.Value == 1)
                {
                    result     = this.UpdateObject(entity);
                    statusCode = Status.AccessDeny.ToString();
                }
                if (result == 1)
                {
                    statusCode = Status.OKUpdate.ToString();
                }
                else
                {
                    statusCode = Status.ErrorDeleted.ToString();
                }
            }
            //}
            return(result);
        }
        /// <summary>
        /// 根据Key获取缓存
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public static BaseModuleEntity GetCacheByKey(string key)
        {
            BaseModuleEntity result = null;

            if (!string.IsNullOrWhiteSpace(key))
            {
                result = CacheUtil.Get <BaseModuleEntity>(key);
            }

            return(result);
        }
        /// <summary>
        /// 获取实体
        /// </summary>
        /// <param name="code">编号</param>
        public BaseModuleEntity GetObjectByCode(string code)
        {
            BaseModuleEntity result = null;

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

            parameters.Add(new KeyValuePair <string, object>(BaseModuleEntity.FieldCode, code));
            parameters.Add(new KeyValuePair <string, object>(BaseModuleEntity.FieldDeletionStateCode, 0));
            result = BaseEntity.Create <BaseModuleEntity>(this.ExecuteReader(parameters));

            return(result);
        }
Beispiel #16
0
        /// <summary>
        /// 批量进行保存
        /// </summary>
        /// <param name="dt">数据表</param>
        /// <returns>影响行数</returns>
        public override int BatchSave(DataTable dt)
        {
            var result = 0;
            var entity = new BaseModuleEntity();

            foreach (DataRow dr in dt.Rows)
            {
                // 删除状态
                if (dr.RowState == DataRowState.Deleted)
                {
                    var id = dr[BaseModuleEntity.FieldId, DataRowVersion.Original].ToString();
                    if (id.Length > 0)
                    {
                        if (dr[BaseModuleEntity.FieldAllowDelete, DataRowVersion.Original].ToString().Equals("1"))
                        {
                            result += DeleteEntity(id);
                        }
                    }
                }
                // 被修改过
                if (dr.RowState == DataRowState.Modified)
                {
                    var id = dr[BaseModuleEntity.FieldId, DataRowVersion.Original].ToString();
                    if (id.Length > 0)
                    {
                        entity.GetFrom(dr);
                        // 判断是否允许编辑
                        if (BaseUserManager.IsAdministrator(UserInfo.Id.ToString()) || entity.AllowEdit == 1)
                        {
                            result += UpdateEntity(entity);
                        }
                    }
                }
                // 添加状态
                if (dr.RowState == DataRowState.Added)
                {
                    entity.GetFrom(dr);
                    result += AddEntity(entity).Length > 0 ? 1 : 0;
                }
                if (dr.RowState == DataRowState.Unchanged)
                {
                    continue;
                }
                if (dr.RowState == DataRowState.Detached)
                {
                    continue;
                }
            }
            StatusCode = Status.Ok.ToString();
            return(result);
        }
Beispiel #17
0
        /// <summary>
        /// 更新模块菜单
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="moduleEntity">实体</param>
        /// <param name="statusCode">返回状态码</param>
        /// <param name="statusMessage">返回状消息</param>
        /// <returns>影响行数</returns>
        public int Update(BaseUserInfo userInfo, BaseModuleEntity moduleEntity, out string statusCode, out string statusMessage)
        {
            // 写入调试信息
            #if (DEBUG)
            int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod());
            #endif

            // 加强安全验证防止未授权匿名调用
            #if (!DEBUG)
            LogOnService.UserIsLogOn(userInfo);
            #endif

            statusCode    = string.Empty;
            statusMessage = string.Empty;
            int returnValue = 0;

            using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType))
            {
                try
                {
                    dbHelper.Open(UserCenterDbConnection);
                    string tableName = BaseModuleEntity.TableName;
                    if (!string.IsNullOrEmpty(BaseSystemInfo.SystemCode))
                    {
                        tableName = BaseSystemInfo.SystemCode + "Module";
                    }
                    BaseModuleManager moduleManager = new BaseModuleManager(dbHelper, userInfo, tableName);
                    // 调用方法,并且返回运行结果
                    returnValue = moduleManager.Update(moduleEntity, out statusCode);
                    // 获得状态消息
                    statusMessage = moduleManager.GetStateMessage(statusCode);
                    BaseLogManager.Instance.Add(dbHelper, userInfo, this.serviceName, AppMessage.ModuleService_Update, MethodBase.GetCurrentMethod());
                }
                catch (Exception ex)
                {
                    BaseExceptionManager.LogException(dbHelper, userInfo, ex);
                    throw ex;
                }
                finally
                {
                    dbHelper.Close();
                }
            }

            // 写入调试信息
            #if (DEBUG)
            BaseBusinessLogic.EndDebug(MethodBase.GetCurrentMethod(), milliStart);
            #endif

            return(returnValue);
        }
        /// <summary>
        /// 批量进行保存
        /// </summary>
        /// <param name="dt">数据表</param>
        /// <returns>影响行数</returns>
        public override int BatchSave(DataTable dt)
        {
            int result = 0;
            BaseModuleEntity entity = new BaseModuleEntity();

            foreach (DataRow dr in dt.Rows)
            {
                // 删除状态
                if (dr.RowState == DataRowState.Deleted)
                {
                    string id = dr[BaseModuleEntity.FieldId, DataRowVersion.Original].ToString();
                    if (id.Length > 0)
                    {
                        if (dr[BaseModuleEntity.FieldAllowDelete, DataRowVersion.Original].ToString().Equals("1"))
                        {
                            result += this.DeleteObject(id);
                        }
                    }
                }
                // 被修改过
                if (dr.RowState == DataRowState.Modified)
                {
                    string id = dr[BaseModuleEntity.FieldId, DataRowVersion.Original].ToString();
                    if (id.Length > 0)
                    {
                        entity.GetFrom(dr);
                        // 判断是否允许编辑
                        if (this.UserInfo.IsAdministrator || entity.AllowEdit == 1)
                        {
                            result += this.UpdateObject(entity);
                        }
                    }
                }
                // 添加状态
                if (dr.RowState == DataRowState.Added)
                {
                    entity.GetFrom(dr);
                    result += this.AddObject(entity).Length > 0 ? 1 : 0;
                }
                if (dr.RowState == DataRowState.Unchanged)
                {
                    continue;
                }
                if (dr.RowState == DataRowState.Detached)
                {
                    continue;
                }
            }
            this.StatusCode = Status.OK.ToString();
            return(result);
        }
        /// <summary>
        /// 批量进行保存
        /// </summary>
        /// <param name="dataTable">数据表</param>
        /// <returns>影响行数</returns>
        public override int BatchSave(DataTable dataTable)
        {
            int returnValue = 0;
            BaseModuleEntity moduleEntity = new BaseModuleEntity();

            foreach (DataRow dataRow in dataTable.Rows)
            {
                // 删除状态
                if (dataRow.RowState == DataRowState.Deleted)
                {
                    string id = dataRow[BaseModuleEntity.FieldId, DataRowVersion.Original].ToString();
                    if (id.Length > 0)
                    {
                        if (dataRow[BaseModuleEntity.FieldAllowDelete, DataRowVersion.Original].ToString().Equals("1"))
                        {
                            returnValue += this.DeleteEntity(id);
                        }
                    }
                }
                // 被修改过
                if (dataRow.RowState == DataRowState.Modified)
                {
                    string id = dataRow[BaseModuleEntity.FieldId, DataRowVersion.Original].ToString();
                    if (id.Length > 0)
                    {
                        moduleEntity.GetFrom(dataRow);
                        // 判断是否允许编辑
                        if (moduleEntity.AllowEdit == 1)
                        {
                            returnValue += this.UpdateEntity(moduleEntity);
                        }
                    }
                }
                // 添加状态
                if (dataRow.RowState == DataRowState.Added)
                {
                    moduleEntity.GetFrom(dataRow);
                    returnValue += this.AddEntity(moduleEntity).Length > 0 ? 1 : 0;
                }
                if (dataRow.RowState == DataRowState.Unchanged)
                {
                    continue;
                }
                if (dataRow.RowState == DataRowState.Detached)
                {
                    continue;
                }
            }
            this.ReturnStatusCode = StatusCode.OK.ToString();
            return(returnValue);
        }
Beispiel #20
0
        /// <summary>
        /// 获取实体
        /// </summary>
        /// <param name="code">编号</param>
        public BaseModuleEntity GetEntityByCode(string code)
        {
            BaseModuleEntity result = null;

            var parameters = new List <KeyValuePair <string, object> >
            {
                new KeyValuePair <string, object>(BaseModuleEntity.FieldCode, code),
                new KeyValuePair <string, object>(BaseModuleEntity.FieldDeleted, 0)
            };

            result = BaseEntity.Create <BaseModuleEntity>(GetDataTable(parameters));

            return(result);
        }
Beispiel #21
0
 /// <summary>
 /// 添加或更新(主键是否为0)
 /// </summary>
 /// <param name="entity">实体</param>
 /// <param name="identity">自增量方式,表主键是否采用自增的策略</param>
 /// <param name="returnId">返回主键,不返回程序允许速度会快,主要是为了主细表批量插入数据优化用的</param>
 /// <returns>主键</returns>
 public string AddOrUpdate(BaseModuleEntity 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);
     }
 }
        public static BaseModuleEntity GetCacheByKey(string key)
        {
            BaseModuleEntity result = null;

            if (!string.IsNullOrWhiteSpace(key))
            {
                using (var redisClient = PooledRedisHelper.GetPermissionReadOnlyClient())
                {
                    result = redisClient.Get <BaseModuleEntity>(key);
                }
            }

            return(result);
        }
Beispiel #23
0
        /// <summary>
        /// 获取实体
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="id">主键</param>
        /// <returns>实体</returns>
        public BaseModuleEntity GetEntity(BaseUserInfo userInfo, string id)
        {
            BaseModuleEntity result = null;

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

            ServiceUtil.ProcessUserCenterReadDb(userInfo, parameter, (dbHelper) =>
            {
                var tableName = userInfo.SystemCode + "Module";
                var manager   = new BaseModuleManager(dbHelper, userInfo, tableName);
                result        = manager.GetEntity(id);
            });

            return(result);
        }
        /// <summary>
        /// 通过编号获取选项的显示内容
        /// 这里是进行了内存缓存处理,减少数据库的I/O处理,提高程序的运行性能,
        /// 若有数据修改过,重新启动一下程序就可以了,这些基础数据也不是天天修改来修改去的,
        /// 所以没必要过度担忧,当然有需要时也可以写个刷新缓存的程序
        /// </summary>
        /// <param name="id">主键</param>
        /// <returns>显示值</returns>
        public static string GetRealName(string id)
        {
            string result = id;

            if (!string.IsNullOrEmpty(id))
            {
                List <BaseModuleEntity> entityList   = GetEntities();
                BaseModuleEntity        moduleEntity = entityList.FirstOrDefault(entity => entity.Id.HasValue && entity.Id.ToString().Equals(id));
                if (moduleEntity != null)
                {
                    result = moduleEntity.FullName;
                }
            }
            return(result);
        }
        /// <summary>
        /// 更新实体
        /// </summary>
        /// <param name="baseModuleEntity">实体</param>
        public int UpdateEntity(BaseModuleEntity baseModuleEntity)
        {
            SQLBuilder sqlBuilder = new SQLBuilder(DbHelper);

            sqlBuilder.BeginUpdate(this.CurrentTableName);
            this.SetEntity(sqlBuilder, baseModuleEntity);
            if (UserInfo != null)
            {
                sqlBuilder.SetValue(BaseModuleEntity.FieldModifiedUserId, UserInfo.Id);
                sqlBuilder.SetValue(BaseModuleEntity.FieldModifiedBy, UserInfo.RealName);
            }
            sqlBuilder.SetDBNow(BaseModuleEntity.FieldModifiedOn);
            sqlBuilder.SetWhere(BaseModuleEntity.FieldId, baseModuleEntity.Id);
            return(sqlBuilder.EndUpdate());
        }
Beispiel #26
0
        public static BaseModuleEntity GetCache(string key)
        {
            BaseModuleEntity result = null;

            if (!string.IsNullOrWhiteSpace(key))
            {
                System.Web.Caching.Cache cache = HttpRuntime.Cache;
                if (cache != null && cache[key] == null)
                {
                    result = cache[key] as BaseModuleEntity;
                }
            }

            return(result);
        }
        /// <summary>
        /// 通过编号获取主键
        /// </summary>
        /// <param name="systemCode">系统编号</param>
        /// <param name="code">编号</param>
        /// <returns>主键</returns>
        public static string GetIdByCodeByCache(string systemCode, string code)
        {
            string result = string.Empty;

            if (!string.IsNullOrEmpty(code))
            {
                BaseModuleEntity moduleEntity = GetObjectByCacheByCode(systemCode, code);
                if (moduleEntity != null)
                {
                    result = moduleEntity.Id.ToString();
                }
            }

            return(result);
        }
        /// <summary>
        /// 通过编号获取选项的显示内容
        /// 这里是进行了内存缓存处理,减少数据库的I/O处理,提高程序的运行性能,
        /// 若有数据修改过,重新启动一下程序就可以了,这些基础数据也不是天天修改来修改去的,
        /// 所以没必要过度担忧,当然有需要时也可以写个刷新缓存的程序
        /// </summary>
        /// <param name="id">主键</param>
        /// <returns>显示值</returns>
        public static string GetNameByCache(string systemCode, string id)
        {
            string result = string.Empty;

            if (!string.IsNullOrEmpty(id))
            {
                BaseModuleEntity moduleEntity = GetObjectByCache(systemCode, id);
                if (moduleEntity != null)
                {
                    result = moduleEntity.FullName;
                }
            }

            return(result);
        }
Beispiel #29
0
        /// <summary>
        /// 按窗体名称获取实体
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="formName">窗体名称</param>
        /// <returns>实体</returns>
        public BaseModuleEntity GetObjectByFormName(BaseUserInfo userInfo, string formName)
        {
            BaseModuleEntity result = null;

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

            ServiceUtil.ProcessUserCenterReadDb(userInfo, parameter, (dbHelper) =>
            {
                string tableName = userInfo.SystemCode + "Module";
                var manager      = new BaseModuleManager(dbHelper, userInfo, tableName);
                result           = BaseEntity.Create <BaseModuleEntity>(manager.GetDataTableByFormName(formName));
            });

            return(result);
        }
        /// <summary>
        /// 设置缓存
        /// </summary>
        /// <param name="systemCode">系统编码</param>
        /// <param name="entity"></param>
        private static void SetCache(string systemCode, BaseModuleEntity entity)
        {
            if (string.IsNullOrWhiteSpace(systemCode))
            {
                systemCode = "Base";
            }

            if (entity != null && !string.IsNullOrEmpty(entity.Id.ToString()))
            {
                var key = systemCode + ".Module." + entity.Id;
                CacheUtil.Set <BaseModuleEntity>(key, entity);

                key = systemCode + ".Module." + entity.Code;
                CacheUtil.Set <BaseModuleEntity>(key, entity);
            }
        }