Esempio n. 1
0
        internal virtual int StartFormProcess(int startUserId, int formInstanceId)
        {
            IOrgProxy proxy        = OrgProxyFactory.GetProxy(this._context);
            int       nextIdentity = this._manager.GetNextIdentity();
            IUser     userById     = proxy.GetUserById(startUserId);

            if (userById == null)
            {
                throw new ApplicationException("用户不存在");
            }
            if (!userById.Department_ID.HasValue)
            {
                throw new ApplicationException("未指定用户部门");
            }
            IDepartment departmentById = proxy.GetDepartmentById(userById.Department_ID.Value);

            if (departmentById == null)
            {
                throw new ApplicationException("用户部门无效");
            }
            SysFormInstance fi = this._context.FindById <SysFormInstance>(new object[] { formInstanceId });

            if (fi == null)
            {
                throw new ApplicationException("表单实例不存在");
            }
            if (!fi.ObjectId.HasValue)
            {
                throw new ApplicationException("表单实例未关联对象ID");
            }
            fi.State = 1;
            this.ProcessInstanceCache.UpdateFormInstance(fi);
            SysProcessInstance instance2 = new SysProcessInstance {
                StartTime         = new DateTime?(DateTime.Now),
                EndTime           = null,
                InstanceStatus    = 0,
                ObjectId          = fi.ObjectId.Value,
                FormInstanceId    = new int?(fi.FormInstanceId),
                FormInstance      = fi,
                ProcessId         = new long?(this._process.ProcessId),
                ProcessInstanceId = nextIdentity,
                StartUserId       = new int?(startUserId),
                StartDeptId       = new int?(departmentById.Department_ID),
                WwfInstanceId     = null
            };

            this._pi = instance2;
            this._pi.FormInstance = fi;
            this._piCacheFactory.AddProcessInstance(this._pi);
            Queue <WorkflowMessage> queue = new Queue <WorkflowMessage>(10);
            WorkflowMessage         item  = this.NewStartProcessMessage();

            queue.Enqueue(item);
            while (queue.Count > 0)
            {
                queue.Dequeue().Execute(queue);
            }
            this._piCacheFactory.ClearCache(nextIdentity);
            return(nextIdentity);
        }
Esempio n. 2
0
 public List <int> GetSubDeptIds(int?deptid)
 {
     if (deptid.HasValue)
     {
         return((from p in OrgProxyFactory.GetProxy(this.context).GetAllChildDepartment(deptid.Value) select p.Department_ID).ToList <int>());
     }
     return(new List <int>());
 }
Esempio n. 3
0
 /// <summary>
 /// 查询所有部门
 /// </summary>
 /// <returns></returns>
 public IEnumerable <WfDepartment> GetDepartmentList()
 {
     using (BizDataContext context = new BizDataContext())
     {
         var proxy = OrgProxyFactory.GetProxy(context);
         return(proxy.GetDepartments().OrderBy(p => p.Department_Name)
                .Select(p => new WfDepartment()
         {
             DepartmentId = p.Department_ID, DepartmentName = p.Department_Name
         }));
     }
 }
Esempio n. 4
0
 /// <summary>
 /// 查询所有角色
 /// </summary>
 /// <returns></returns>
 public IEnumerable <WfRole> GetRoleList()
 {
     using (BizDataContext context = new BizDataContext())
     {
         var proxy = OrgProxyFactory.GetProxy(context);
         return(proxy.GetRoles().OrderBy(p => p.Role_Name)
                .Select(p => new WfRole()
         {
             RoleId = p.Role_ID, RoleName = p.Role_Name
         }));
     }
 }
Esempio n. 5
0
 /// <summary>
 /// 查询所有用户
 /// </summary>
 /// <returns></returns>
 public IEnumerable <WfUser> GetUserList()
 {
     using (BizDataContext context = new BizDataContext())
     {
         var proxy = OrgProxyFactory.GetProxy(context);
         return(proxy.GetUsers().OrderBy(p => p.User_Name)
                .Select(p => new WfUser()
         {
             UserId = p.User_ID, UserName = p.User_Name
         }));
     }
 }
        public override void ProcessMessage(SysWorkflowMessage msg)
        {
            if (this._engine.ProcessCache.GetProcessCache(msg.ProcessId) == null)
            {
                throw new ApplicationException("process == null");
            }
            SysProcessInstance processInstance = this._engine.PI;

            if (processInstance == null)
            {
                throw new ApplicationException("processInstance == null");
            }
            IOrgProxy proxy = OrgProxyFactory.GetProxy(this.dbContext);

            if (!processInstance.StartUserId.HasValue)
            {
                throw new ApplicationException("processInstance.StartUserId == null");
            }
            IUser userById = proxy.GetUserById(processInstance.StartUserId.Value);

            if (userById == null)
            {
                throw new ApplicationException("用户不存在");
            }
            if (!userById.Department_ID.HasValue)
            {
                throw new ApplicationException("未指定用户部门");
            }
            IDepartment departmentById = proxy.GetDepartmentById(userById.Department_ID.Value);

            if (departmentById == null)
            {
                throw new ApplicationException("用户部门无效");
            }
            int?startDeptId = processInstance.StartDeptId;

            if ((startDeptId.HasValue ? startDeptId.GetValueOrDefault() : -1) < 0)
            {
                processInstance.StartDeptId = new int?(departmentById.Department_ID);
                this.dbContext.UpdatePartial <SysProcessInstance>(processInstance, p => new { StartDeptId = processInstance.StartDeptId });
            }
            Queue <WorkflowMessage> queue = new Queue <WorkflowMessage>(10);
            WorkflowMessage         item  = this._engine.NewStartProcessWithNextUsersMessage(msg.NextApproveUserList);

            queue.Enqueue(item);
            while (queue.Count > 0)
            {
                queue.Dequeue().Execute(queue);
            }
            this._engine.ProcessInstanceCache.ClearCache(msg.ProcessInstanceId);
        }
Esempio n. 7
0
        public int?GetUserDeptId(int?userid)
        {
            int num = -2147483647;

            if (userid.HasValue)
            {
                IUser userById = OrgProxyFactory.GetProxy(null).GetUserById(userid.Value);
                if (userById.Department_ID.HasValue)
                {
                    num = userById.Department_ID.Value;
                }
            }
            return(new int?(num));
        }
Esempio n. 8
0
        internal virtual int StartProcess(int startUserId, int relativeObjectId, List <IApproveUser> nextApproveUserList)
        {
            IOrgProxy proxy        = OrgProxyFactory.GetProxy(this._context);
            int       nextIdentity = this._manager.GetNextIdentity();
            IUser     userById     = proxy.GetUserById(startUserId);

            if (userById == null)
            {
                throw new ApplicationException("用户不存在");
            }
            if (!userById.Department_ID.HasValue)
            {
                throw new ApplicationException("未指定用户部门");
            }
            IDepartment departmentById = proxy.GetDepartmentById(userById.Department_ID.Value);

            if (departmentById == null)
            {
                throw new ApplicationException("用户部门无效");
            }
            SysProcessInstance instance = new SysProcessInstance {
                StartTime         = new DateTime?(DateTime.Now),
                EndTime           = null,
                InstanceStatus    = 0,
                ObjectId          = relativeObjectId,
                ProcessId         = new long?(this._process.ProcessId),
                ProcessInstanceId = nextIdentity,
                StartUserId       = new int?(startUserId),
                StartDeptId       = new int?(departmentById.Department_ID),
                WwfInstanceId     = null
            };

            this._pi = instance;
            this._piCacheFactory.AddProcessInstance(this._pi);
            Queue <WorkflowMessage> queue = new Queue <WorkflowMessage>(10);
            WorkflowMessage         item  = this.NewStartProcessWithNextUsersMessage(nextApproveUserList);

            queue.Enqueue(item);
            while (queue.Count > 0)
            {
                queue.Dequeue().Execute(queue);
            }
            this._piCacheFactory.ClearCache(nextIdentity);
            return(nextIdentity);
        }
Esempio n. 9
0
        public bool CheckHasSharedPrivilege(int objectId, string entityName, EntityOperationEnum operationEnum)
        {
            bool flag = false;

            if ((operationEnum != EntityOperationEnum.Add) && (operationEnum != EntityOperationEnum.None))
            {
                if (objectId == 0)
                {
                    return(flag);
                }
                List <SysSharedPrivilege> list = this.context.Where <SysSharedPrivilege>(p => ((p.ObjectId == objectId) && (p.EntityName == entityName)) && (p.Privilege == ((int)operationEnum))).ToList <SysSharedPrivilege>();
                List <IRole> userRoles         = OrgProxyFactory.GetProxy(this.context).GetUserRoles(this.CurrentUser.User_ID);
                using (List <SysSharedPrivilege> .Enumerator enumerator = list.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        Func <IRole, bool> predicate = null;
                        SysSharedPrivilege share     = enumerator.Current;
                        int?shareType = share.ShareType;
                        if ((shareType.GetValueOrDefault() == 0) && shareType.HasValue)
                        {
                            shareType = share.ShareUserId;
                            int num = this.CurrentUser.User_ID;
                            if ((shareType.GetValueOrDefault() == num) && shareType.HasValue)
                            {
                                return(true);
                            }
                        }
                        else if (share.ShareType == 1)
                        {
                            if (predicate == null)
                            {
                                predicate = p => p.Role_ID == share.ShareRoleId;
                            }
                            if (userRoles.FirstOrDefault <IRole>(predicate) != null)
                            {
                                return(true);
                            }
                        }
                    }
                }
            }
            return(flag);
        }
Esempio n. 10
0
        public EntityPrivilegeEnum TryCanOperation(int userId, long entityId, EntityOperationEnum operationEnum)
        {
            if (this.context.FindById <T_User>(new object[] { userId }) == null)
            {
                throw new Exception("当前用户不存在数据库中");
            }
            IOrgProxy         proxy = OrgProxyFactory.GetProxy(this.context);
            IEnumerable <int> currentUserRoleIds = from p in proxy.GetUserRoles(userId) select p.Role_ID;
            SysDataPrivilege  privilege          = (from x in this.context.Where <SysDataPrivilege>(x => (x.EntityId == entityId) && (x.OperationId == ((int)operationEnum)))
                                                    where currentUserRoleIds.Contains <int>(!x.RoleId.HasValue ? 0 : x.RoleId.ToInt())
                                                    orderby x.PrivilegeLevel descending
                                                    select x).FirstOrDefault <SysDataPrivilege>();

            if (null != privilege)
            {
                return((EntityPrivilegeEnum)privilege.PrivilegeLevel.Value);
            }
            return(EntityPrivilegeEnum.NoPermission);
        }
        private void ExecuteForManual(SysActivity activity, SysProcess process, Queue <WorkflowMessage> queue)
        {
            if ((activity.ActivityParticipants == null) || (activity.ActivityParticipants.Count == 0))
            {
                throw new ApplicationException("未指定参与人");
            }
            Dictionary <SysWorkItemApproveGroup, List <IUser> > dictionary = new Dictionary <SysWorkItemApproveGroup, List <IUser> >(20);
            List <IUser> list = new List <IUser>();

            if (this.AI.UserDefinedApproveUsers.Count > 0)
            {
                SysWorkItemApproveGroup key = this.CreateWorkItemGroup();
                IOrgProxy    orgProxy       = OrgProxyFactory.GetProxy(base.Context);
                List <IUser> users          = (from p in this.AI.UserDefinedApproveUsers select orgProxy.GetUserById(p.UserId.Value)).ToList <IUser>();
                this.RemoveRepeatedUsers(users);
                list.AddRange(users);
                dictionary.Add(key, users);
            }
            else
            {
                using (IEnumerator <SysActivityParticipant> enumerator = activity.ActivityParticipants.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        Func <SysProcessParticipant, bool> predicate     = null;
                        SysActivityParticipant             activity_part = enumerator.Current;
                        SysWorkItemApproveGroup            group         = this.CreateWorkItemGroup(activity_part);
                        if (predicate == null)
                        {
                            predicate = p => p.ParticipantId == activity_part.ParticipantId.Value;
                        }
                        SysProcessParticipant part = process.ProcessParticipants.FirstOrDefault <SysProcessParticipant>(predicate);
                        if (part == null)
                        {
                            throw new ApplicationException("参与人为空");
                        }
                        int?         wiOwnerId   = null;
                        var          users       = ParticipantHelper.GetUsers(base.Context, part, base.PI, this.AI, wiOwnerId);
                        List <IUser> targetUsers = users;
                        this.AssertGroupHasUsers(activity_part, group, targetUsers);
                        this.RemoveRepeatedUsers(targetUsers);
                        list.AddRange(targetUsers);
                        dictionary.Add(group, targetUsers);
                    }
                }
            }
            if (list.Count == 0)
            {
                bool?isPassedWithNoParticipants = this.AI.Activity.IsPassedWithNoParticipants;
                if (!(isPassedWithNoParticipants.HasValue ? isPassedWithNoParticipants.GetValueOrDefault() : false))
                {
                    throw new ApplicationException("未计算出任何参与人");
                }
                SysActivityInstance aI = this.AI;
                aI.InstanceStatus  = 10;
                aI.EndTime         = new DateTime?(DateTime.Now);
                aI.ApproveResult   = 1;
                aI.ExpressionValue = 1;
                aI.Remark          = "无人审核,自动通过";
                base.PICacheFactory.UpdateActiviyInstance(this.AI);
                WorkflowMessage item = base.Engine.NewCompleteActivityMessage(this.AI);
                queue.Enqueue(item);
            }
            else
            {
                SysActivity activity3 = this.AI.Activity;
                if (!activity3.PassType.HasValue)
                {
                    activity3.PassType = 1;
                    if (!activity3.MinPassNum.HasValue)
                    {
                        activity3.MinPassNum = 1;
                    }
                }
                foreach (KeyValuePair <SysWorkItemApproveGroup, List <IUser> > pair in dictionary)
                {
                    SysWorkItemApproveGroup group3 = pair.Key;
                    foreach (IUser user in pair.Value)
                    {
                        this.CreateWorkItem(user, group3);
                    }
                }
            }
            if (this.AI.UserDefinedApproveUsers.Count > 0)
            {
                base.PICacheFactory.ClearApproveUsers(this.AI);
            }
        }
 public ParticiparntFuncBase(DataContext ctx)
 {
     this._context  = ctx;
     this._orgProxy = OrgProxyFactory.GetProxy(ctx);
 }