コード例 #1
0
        /// <summary>删除/作废
        ///
        /// </summary>
        /// <param name="operationType">操作类型</param>
        private void DoDeleteOrCancel(EntityOperationType operationType)
        {
            string strMsg = CheckSelect(operationType);

            if (strMsg != string.Empty)
            {
                MessageBox.Show(strMsg);
                return;
            }
            DialogResult diaComfirmResult = MessageBox.Show(string.Format("{0}主表信息,会连同明细一起{0}", operationType), @"警告",
                                                            MessageBoxButtons.YesNo);

            if (diaComfirmResult != DialogResult.Yes)
            {
                return;
            }
            IList  objList         = objListViewMaster.SelectedObjects;
            IList  lstSelectionIds = objList.Cast <BseProject>().Select(t => t.ProjectID).ToList();
            string strIds          = lstSelectionIds.Cast <string>().Aggregate(string.Empty, (current, strId) => current + (strId + ","));

            strIds = strIds.TrimEnd(',');
            var blnReturn = operationType == EntityOperationType.除
                ? m_BseProjectDAL.DeleteByCond("ProjectID in (" + strIds + ")")
                : m_BseProjectDAL.Update("Status =0", "ProjectID in (" + strIds + ")");

            if (blnReturn)
            {
                MessageBox.Show(string.Format("{0}成功", operationType));
                objListViewMaster.RemoveObjects(objList);
            }
            else
            {
                MessageBox.Show(string.Format("{0}失败", operationType));
            }
        }
コード例 #2
0
        /// <summary>检查选择
        ///
        /// </summary>
        /// <param name="operationType">操作说明</param>
        /// <returns>返回提示信息</returns>
        private string CheckSelect(EntityOperationType operationType)
        {
            string strMsg = string.Empty;

            if (objListViewMaster.SelectedObjects.Count == 0)
            {
                strMsg = string.Format("请选择要{0}的行数据", operationType);
            }
            return(strMsg);
        }
コード例 #3
0
        public void CheckPermission(EntityOperationType entityOperationType)
        {
            var entityName = typeof(TEntity).Name;
            var permission = $"{entityName}.{entityOperationType}";

            if (!userSession.Permissions.Contains(permission))
            {
                var message = $"You have no permissions for operation {entityOperationType} of {entityName} entity";
                throw new AppValidationException(message);
            }
        }
コード例 #4
0
        //---------------------------------------------------------------------------------------------------------------------

        /// <summary>Returns the privilege defined by the specified entity type and operation from a list.</summary>
        /// <param name="entityType">The entity type to which the privilege applies.</param>
        /// <param name="operation">The operation on the entity type.</param>
        /// <param name="privileges">An IEnumerable containing privileges to choose from. It should contain only privileges applicable to the same type with only one occurence of the requested operation.</param>
        /// <returns>The matching Privilege instance.</returns>
        public static Privilege Get(EntityOperationType operation, IEnumerable <Privilege> privileges)
        {
            foreach (Privilege privilege in privileges)   // method parameter "privileges"
            {
                if (privilege.Operation == operation)
                {
                    return(privilege);
                }
            }
            return(null);
        }
コード例 #5
0
        /// <summary>新增或者修改明细表
        ///
        /// </summary>
        /// <param name="operationType">操作类型</param>
        private void DoNewOrEditDetail(EntityOperationType operationType)
        {
            string strMsg = DoCheckDetail(operationType);

            if (strMsg != string.Empty)
            {
                MessageBox.Show(strMsg);
                return;
            }
            SetMode(operationType);
        }
コード例 #6
0
        //---------------------------------------------------------------------------------------------------------------------

        /// <summary>Returns the privilege defined by the specified entity type and operation from a list.</summary>
        /// <param name="entityType">The entity type to which the privilege applies.</param>
        /// <param name="operation">The operation on the entity type.</param>
        /// <param name="privileges">An IEnumerable containing privileges to choose from.</param>
        /// <returns>The matching Privilege instance.</returns>
        public static Privilege Get(EntityType entityType, EntityOperationType operation, IEnumerable <Privilege> privileges)
        {
            entityType = entityType.TopType;            // privileges defined for subtypes are not supported
            foreach (Privilege privilege in privileges) // method parameter "privileges"
            {
                if (privilege.TargetEntityType == entityType && privilege.Operation == operation)
                {
                    return(privilege);
                }
            }
            return(null);
        }
コード例 #7
0
        /// <summary>设置按钮跟面板控件的可用性
        ///
        /// </summary>
        /// <param name="operationType">操作类型</param>
        public void SetMode(EntityOperationType operationType)
        {
            switch (operationType)
            {
            case EntityOperationType.新增:
            case EntityOperationType.修改:
                m_masterStatus = operationType;
                if (operationType == EntityOperationType.新增)
                {
                    ControlManager.ClearAll(grpMaster);
                }
                ControlManager.SetControlEnabled(grpMaster, false);
                ControlManager.SetBtnEnabled(new Component[] { cmdSave, cmdCancel }, true);
                ControlManager.SetBtnEnabled(new Component[] { cmdNew, cmdDelete, cmdEdit }, false);
                ControlManager.SetControlEnabled(grpMaster, true);
                //新增或者修改主表是,明细不可用,只有保存完主表信息才能操作明细信息
                ControlManager.SetControlEnabled(grpDetail, false);
                ControlManager.SetBtnEnabled(new Component[] { cmdSaveDetail, cmdCancelDetail, cmdNewDetail, cmdDeleteDetail, cmdEditDetail }, false);
                break;

            case EntityOperationType.只读:
                m_masterStatus = operationType;
                ControlManager.SetControlEnabled(grpMaster, false);
                ControlManager.SetBtnEnabled(new Component[] { cmdSave, cmdCancel }, false);
                ControlManager.SetBtnEnabled(new Component[] { cmdNew, cmdDelete, cmdEdit }, true);
                SetMode(EntityOperationType.只读明细);
                break;

            case EntityOperationType.新增明细:
            case EntityOperationType.修改明细:
                m_detailStatus = operationType;
                if (operationType == EntityOperationType.新增明细)
                {
                    ControlManager.ClearAll(grpDetail);
                }
                ControlManager.SetControlEnabled(grpDetail, false);
                ControlManager.SetBtnEnabled(new Component[] { cmdSaveDetail, cmdCancelDetail }, true);
                ControlManager.SetBtnEnabled(new Component[] { cmdNewDetail, cmdDeleteDetail, cmdEditDetail }, false);
                ControlManager.SetControlEnabled(grpDetail, true);
                break;

            case EntityOperationType.只读明细:
                m_detailStatus = operationType;
                ControlManager.SetControlEnabled(grpDetail, false);
                ControlManager.SetBtnEnabled(new Component[] { cmdSaveDetail, cmdCancelDetail }, false);
                ControlManager.SetBtnEnabled(new Component[] { cmdNewDetail, cmdDeleteDetail, cmdEditDetail }, true);
                break;
            }
        }
コード例 #8
0
        /// <summary>
        /// This method creates a changeset style model for Changes being made to the entity.
        /// This can be used to create audit logs or event queues in conjunction with IEntityOperationEventSink
        /// </summary>
        /// <param name="timestamp"></param>
        /// <param name="entity"></param>
        /// <param name="operation"></param>
        /// <param name="currentValues"></param>
        /// <param name="originalValues"></param>
        /// <returns></returns>

        protected string TrackChange(T entity, EntityOperationType operation = EntityOperationType.Unknown, PropertyValues currentValues = null, PropertyValues originalValues = null, byte[] timestamp = null)
        {
            bool nonAuditable = typeof(INonAuditable).IsAssignableFrom(typeof(T));

            if (nonAuditable.Equals(false))
            {
                //create new AuditLog object
                AuditLog change = new AuditLog();

                try
                {
                    //define properties in object
                    change.Id       = Guid.NewGuid();
                    change.ObjectId = entity.Id;

                    change.CreatedBy = _caller.Identity == null ? entity.CreatedBy : _caller.Identity.Name;
                    change.CreatedOn = DateTime.UtcNow;

                    if (timestamp == null)
                    {
                        timestamp = new byte[1];
                    }

                    change.Timestamp = timestamp;
                    //name of service that is being changed
                    change.ServiceName = entity.ToString();
                    //name of how entity is being changed (Add, Update, Delete)
                    change.MethodName      = operation.ToString();
                    change.ParametersJson  = ""; //TODO: update to show parameters of method
                    change.ExceptionJson   = ""; //TODO: update to show any exceptions that arise
                    change.ChangedFromJson = (originalValues == null) ? null : JsonConvert.SerializeObject(originalValues.ToObject());
                    change.ChangedToJson   = (currentValues == null) ? null : JsonConvert.SerializeObject(currentValues.ToObject());

                    //add object to AuditLog data table
                    DbContext.Add(change);
                    DbContext.SaveChanges();
                }
                catch (Exception ex)
                {
                    throw new EntityOperationException(ex);
                }

                //return audit log object as a string
                return(change.ToString());
            }

            return(new InvalidOperationException().Message);
        }
コード例 #9
0
        public static IDBConnection GetConnection(string dbCode, EntityOperationType type, IEntityIdentity before, IEntityIdentity after, IEntityRequestContext context)
        {
            dbCode = DataConfig.Current.GetConnectionName(dbCode);

            IDBConnection connection = null;

            foreach (var operation in context.Operations)
            {
                var sqlOperation = operation as SqlOperation;
                if (sqlOperation == null)
                {
                    continue;
                }
                if (sqlOperation.DbCode == dbCode)
                {
                    connection = sqlOperation.Connection;
                }
            }

            if (connection == null && context.Who != null)
            {
                connection = DatabaseFactory.CreateDatabase(dbCode).AddClaimsDefaults(context.Who);
            }
            if (connection == null)
            {
                connection = DatabaseFactory.CreateDatabase(dbCode);
            }

            if (type != EntityOperationType.Get)
            {
                if (!connection.IsInTransaction)
                {
                    connection.BeginTrans();
                }

                context.Operations.Add(new SqlOperation
                {
                    DbCode     = dbCode,
                    Type       = type,
                    Before     = before,
                    After      = after,
                    Connection = connection
                });
            }

            return(connection);
        }
コード例 #10
0
        /// <summary>检查合法性
        ///
        /// </summary>
        /// <param name="operationType">操作类型</param>
        /// <returns></returns>
        private string DoCheck(EntityOperationType operationType)
        {
            string strMsg = string.Empty;

            if (m_orderMaster == null || m_masterStatus != EntityOperationType.只读)
            {
                return("请先保存主表信息");
            }
            if (operationType == EntityOperationType.修改明细)
            {
                if (this.objListViewDetail.SelectedObjects.Count == 0)
                {
                    return(@"请先选择要修改的明细");
                }
            }
            return(strMsg);
        }
コード例 #11
0
        public void Validate(TEntity instance, EntityOperationType entityOperationType, bool ignorePermissions = false)
        {
            if (!ignorePermissions)
            {
                this.CheckPermission(entityOperationType);
            }

            var result = this.validator.Validate(instance);

            if (!result.IsValid)
            {
                var sb = new StringBuilder();
                foreach (var failure in result.Errors)
                {
                    sb.AppendLine("Property " + failure.PropertyName + " failed validation. Error was: " + failure.ErrorMessage);
                }

                throw new AppValidationException(sb.ToString());
            }
        }
コード例 #12
0
        /// <summary>检查合法性
        ///
        /// </summary>
        /// <param name="operationType">操作类型</param>
        /// <returns></returns>
        private string DoCheckDetail(EntityOperationType operationType)
        {
            string strMsg = string.Empty;

            if (m_BseProject == null || m_masterStatus != EntityOperationType.只读)
            {
                return("请先保存主表信息");
            }
            if (operationType == EntityOperationType.修改明细)
            {
                if (this.objListViewDetail.SelectedObjects.Count == 0)
                {
                    return(@"请先选择要修改的明细");
                }
            }
            if (operationType == EntityOperationType.只读明细)
            {
                if (cboDetailEditProjectID.Text.Trim() == string.Empty)
                {
                    cboDetailEditProjectID.Select();
                    return("请选择所属项目");
                }

                if (txtDetailEditName.Text.Trim() == string.Empty)
                {
                    txtDetailEditName.Select();
                    return("版本名称不能为空");
                }

                if (txtDetailEditSort.Text.Trim() == string.Empty)
                {
                    txtDetailEditSort.Select();
                    return("排序不能为空");
                }
            }

            return(strMsg);
        }
コード例 #13
0
        /// <summary>检查合法性
        ///
        /// </summary>
        /// <param name="operationType">操作类型</param>
        /// <returns></returns>
        private string DoCheck(EntityOperationType operationType)
        {
            string strMsg = string.Empty;

            if (m_OrderMaster == null || m_masterStatus != EntityOperationType.只读)
            {
                return("请先保存主表信息");
            }
            if (operationType == EntityOperationType.修改明细)
            {
                if (this.objListViewDetail.SelectedObjects.Count == 0)
                {
                    return(@"请先选择要修改的明细");
                }
            }
            if (txtDetailEditCustomer.Text.Trim() == string.Empty)
            {
                txtDetailEditCustomer.Select();
                return("客户不能为空");
            }

            return(strMsg);
        }
コード例 #14
0
        //---------------------------------------------------------------------------------------------------------------------

        public static void LoadPrivileges(IfyContext context)
        {
            privileges.Clear();
            IDataReader reader = context.GetQueryResult("SELECT t.id, t.identifier, t.name, t.id_type, t.operation, t.enable_log FROM priv AS t ORDER BY t.pos;");

            while (reader.Read())
            {
                int                 id           = context.GetIntegerValue(reader, 0);
                int                 entityTypeId = context.GetIntegerValue(reader, 3);
                EntityType          entityType   = entityTypeId == 0 ? null : EntityType.GetEntityTypeFromId(entityTypeId);
                EntityOperationType operation    = GetOperationType(context.GetValue(reader, 4));

                Privilege privilege = new Privilege(
                    id,
                    context.GetValue(reader, 1),
                    context.GetValue(reader, 2),
                    entityType,
                    operation,
                    context.GetBooleanValue(reader, 5)
                    );
                privileges[id] = privilege;
            }
            reader.Close();
        }
コード例 #15
0
 public UnauthorizedOperationException(EntityOperationType add)
 {
     Operation = add;
 }
コード例 #16
0
 public UnauthorizedOperationException()
 {
     Operation = EntityOperationType.Unknown;
 }
コード例 #17
0
ファイル: ChangeSetEntry.cs プロジェクト: kouweizhong/openair
 /// <summary>
 /// Initializes a new instance of the <see cref="ChangeSetEntry"/> class
 /// </summary>
 /// <param name="entity">The entity being operated on</param>
 /// <param name="id">The client ID for the entity, used to correlate server results
 /// with their client entity instances.</param>
 /// <param name="operationType">The operation to be performed</param>
 public ChangeSetEntry(Entity entity, int id, EntityOperationType operationType)
 {
     this._entity = entity;
     this._id = id;
     this._operationType = operationType;
 }
コード例 #18
0
        //---------------------------------------------------------------------------------------------------------------------

        public Privilege(int id, string identifier, string name, EntityType entityType, EntityOperationType operation, bool enableLog) : this(null) {
            this.Id               = id;
            this.Identifier       = identifier;
            this.Name             = name;
            this.TargetEntityType = entityType;
            this.Operation        = operation;
            this.EnableLog        = enableLog;
        }
コード例 #19
0
 protected override bool AuthorizeOperation(Organization entity, EntityOperationType operation)
 {
     return(true);
 }
コード例 #20
0
 /// <summary>Creates a new Activity instance.</summary>
 /// <param name="context">The execution environment context.</param>
 /// <param name="entity">The entity to which the activity relates.</param>
 /// <param name="operation">The operation performed on the entity.</param>
 public Activity(IfyContext context, Entity entity, EntityOperationType operation) : this(context, entity, ((char)operation).ToString())
 {
 }
コード例 #21
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ChangeSetEntry"/> class
 /// </summary>
 /// <param name="entity">The entity being operated on</param>
 /// <param name="id">The client ID for the entity, used to correlate server results
 /// with their client entity instances.</param>
 /// <param name="operationType">The operation to be performed</param>
 public ChangeSetEntry(Entity entity, int id, EntityOperationType operationType)
 {
     this._entity        = entity;
     this._id            = id;
     this._operationType = operationType;
 }
コード例 #22
0
        //---------------------------------------------------------------------------------------------------------------------

        /// <summary>Returns the privilege defined by the specified entity type and operation.</summary>
        /// <param name="entityType">The entity type to which the privilege applies.</param>
        /// <param name="operation">The operation on the entity type.</param>
        /// <returns>The matching Privilege instance.</returns>
        public static Privilege Get(EntityType entityType, EntityOperationType operation)
        {
            entityType = entityType.TopType;                       // privileges defined for subtypes are not supported
            return(Get(entityType, operation, privileges.Values)); // static member "privileges"
        }
コード例 #23
0
        /// <summary>
        /// Froms the entity and privilege.
        /// </summary>
        /// <returns>The entity and privilege.</returns>
        /// <param name="context">Context.</param>
        /// <param name="entity">Entity.</param>
        /// <param name="operation">Operation.</param>
        public static new ActivityTep FromEntityAndPrivilege(IfyContext context, Entity entity, EntityOperationType operation)
        {
            var         etype  = EntityType.GetEntityType(entity.GetType());
            var         priv   = Privilege.Get(EntityType.GetEntityTypeFromId(etype.Id), Privilege.GetOperationType(((char)operation).ToString()));
            ActivityTep result = new ActivityTep(context);

            result.Entity       = entity;
            result.EntityTypeId = etype.Id;
            result.Privilege    = priv;
            result.Load();
            return(result);
        }
コード例 #24
0
 public UnauthorizedOperationException(EntityOperationType operationType)
 {
     Operation = operationType;
 }
コード例 #25
0
 /// <summary>
 /// Authorizes the operation.
 /// </summary>
 /// <param name="entity">The entity.</param>
 /// <param name="operation">The operation.</param>
 /// <returns></returns>
 protected virtual bool AuthorizeOperation(T entity, EntityOperationType operation)
 {
     return(true);
 }
コード例 #26
0
 public UnauthorizedOperationException(string?message, EntityOperationType operationType) : base(message)
 {
     Operation = operationType;
 }
コード例 #27
0
        public static EntityOperationEvent Create <T>(T entity, UserSecurityContext userContext, EntityOperationType operation = EntityOperationType.Unknown)
            where T : IEntity
        {
            EntityOperationEvent bizEvent = new EntityOperationEvent();

            bizEvent.EntityType = typeof(T).Name;
            bizEvent.Id         = entity.Id.Value;
            bizEvent.EventOn    = DateTime.UtcNow;
            bizEvent.Operation  = operation;
            return(bizEvent);
        }
コード例 #28
0
 /// <summary>
 /// Authorizes the operation
 /// </summary>
 /// <param name="entity">The entity</param>
 /// <param name="operation">The operation</param>
 /// <returns></returns>
 protected override bool AuthorizeOperation(T entity, EntityOperationType operation)
 {
     //get value of AuthorizeRow and if false then no access
     return(AuthorizeRow(entity));
 }
コード例 #29
0
 /// <summary>新增或者修改主表
 ///
 /// </summary>
 /// <param name="operationType">操作类型</param>
 private void DoNewOrEdit(EntityOperationType operationType)
 {
     SetMode(operationType);
 }
コード例 #30
0
        /// <summary>
        /// Builds the list of submit operations from the current <see cref="EntityChangeSet"/>.
        /// </summary>
        /// <param name="changeSet">The <see cref="EntityChangeSet"/> to process.</param>
        /// <returns>The list of <see cref="ChangeSetEntry"/> for the specified <see cref="EntityChangeSet"/>.</returns>
        private static List <ChangeSetEntry> BuildOperations(EntityChangeSet changeSet)
        {
            List <ChangeSetEntry> operations = new List <ChangeSetEntry>();
            int clientID = 0;
            EntityOperationType operationType = EntityOperationType.None;

            foreach (Entity entity in changeSet)
            {
                switch (entity.EntityState)
                {
                case EntityState.New:
                    operationType = EntityOperationType.Insert;
                    break;

                case EntityState.Modified:
                    operationType = EntityOperationType.Update;
                    break;

                case EntityState.Deleted:
                    operationType = EntityOperationType.Delete;
                    break;

                default:
                    continue;
                }

                // create the operation and apply any original values
                ChangeSetEntry changeSetEntry = new ChangeSetEntry(entity, clientID++, operationType);

                if (entity.OriginalValues != null)
                {
                    if (entity.MetaType.ShouldRoundtripOriginal && entity.OriginalValues != null)
                    {
                        changeSetEntry.OriginalEntity = GetRoundtripEntity(entity);
                    }
                    else
                    {
                        // In cases where the entity is modified but we're not sending
                        // an original we need to flag the entity as having changes.
                        // For example, this happens in Timestamp scenarios.
                        changeSetEntry.HasMemberChanges = true;
                    }
                }

                // add any custom method invocations
                var entityActions = (ICollection <EntityAction>)entity.EntityActions;
                foreach (EntityAction customInvokation in entityActions)
                {
                    if (string.IsNullOrEmpty(customInvokation.Name))
                    {
                        throw new ArgumentException(Resource.DomainClient_InvocationNameCannotBeNullOrEmpty);
                    }

                    if (changeSetEntry.EntityActions == null)
                    {
                        changeSetEntry.EntityActions = new List <Serialization.KeyValue <string, object[]> >();
                    }
                    changeSetEntry.EntityActions.Add(
                        new Serialization.KeyValue <string, object[]>(customInvokation.Name, customInvokation.Parameters.ToArray()));
                }

                operations.Add(changeSetEntry);
            }

            return(operations);
        }
コード例 #31
0
 public ActivityTep(IfyContext context, Entity entity, EntityOperationType operation) : base(context, entity, operation)
 {
 }