Exemplo n.º 1
0
        /// <summary>
        /// 删除该流程
        /// </summary>
        public void Remove()
        {
            ISqlMapper      mapper      = MapperHelper.GetMapper();
            WorkflowDao     wfdao       = new WorkflowDao(mapper);
            ActivityDao     activitydao = new ActivityDao(mapper);
            LinkDao         linkDao     = new LinkDao(mapper);
            ActivityAuthDao authdao     = new ActivityAuthDao(mapper);
            ApprovalDao     approvalDao = new ApprovalDao(mapper);
            TaskDao         taskdao     = new TaskDao(mapper);
            string          id          = this.value.ID;
            var             activities  = activitydao.Query(new ActivityQueryForm {
                WorkflowID = id
            });

            taskdao.Delete(new TaskQueryForm {
                WorkflowID = id
            });
            wfdao.Delete(new WorkflowQueryForm {
                ID = id
            });
            activitydao.Delete(new ActivityQueryForm {
                WorkflowID = id
            });
            linkDao.Delete(new LinkQueryForm {
                WorkflowID = id
            });
            approvalDao.Delete(new ApprovalQueryForm {
                WorkflowID = id
            });
            authdao.Delete(new ActivityAuthQueryForm {
                WorkflowID = id
            });
        }
Exemplo n.º 2
0
        /// <summary>
        /// 从数据库读取流程信息
        /// </summary>
        /// <param name="workflowids"></param>
        /// <returns></returns>
        public static List <WorkflowModel> Load(WorkflowQueryForm form)
        {
            List <WorkflowModel> models = new List <WorkflowModel>();

            if (form == null)
            {
                return(models);
            }

            #region query data
            ISqlMapper          mapper       = MapperHelper.GetMapper();
            WorkflowDao         wfdao        = new WorkflowDao(mapper);
            ActivityDao         activitydao  = new ActivityDao(mapper);
            LinkDao             linkDao      = new LinkDao(mapper);
            ActivityAuthDao     authdao      = new ActivityAuthDao(mapper);
            ApprovalDao         approvalDao  = new ApprovalDao(mapper);
            TaskDao             taskdao      = new TaskDao(mapper);
            List <Activity>     activityList = new List <Activity>();
            List <Link>         linkList     = new List <Link>();
            List <ActivityAuth> authList     = new List <ActivityAuth>();
            List <Approval>     approvalList = new List <Approval>();
            List <Task>         taskList     = new List <Task>();
            List <Workflow>     workflows    = new List <Workflow>();
            //先从缓存取值
            //var item = cache.GetItem(id);
            //if (item != null)
            //{
            //    model = item.Value as WorkflowModel;
            //    return model;
            //}
            workflows = wfdao.Query(form);
            var workflowids = (from wf in workflows select wf.ID).ToList();
            activityList = activitydao.Query(new ActivityQueryForm {
                WorkflowIDs = workflowids
            });
            linkList = linkDao.Query(new LinkQueryForm {
                WorkflowIDs = workflowids
            });
            approvalList = approvalDao.Query(new ApprovalQueryForm {
                WorkflowIDs = workflowids
            });
            authList = authdao.Query(new ActivityAuthQueryForm {
                WorkflowIDs = workflowids
            });
            taskList = taskdao.Query(new TaskQueryForm {
                WorkflowIDs = workflowids
            });
            #endregion

            foreach (var workflow in workflows)
            {
                var model = BuildWorkflow(workflow, activityList, linkList, authList, approvalList, taskList);
                models.Add(model);
            }
            return(models);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 把流程实体新增到数据库
        /// </summary>
        /// <returns></returns>
        public bool Create()
        {
            ISqlMapper      mapper      = MapperHelper.GetMapper();
            WorkflowDao     workflowdao = new WorkflowDao(mapper);
            ActivityDao     activitydao = new ActivityDao(mapper);
            LinkDao         linkdao     = new LinkDao(mapper);
            ActivityAuthDao authdao     = new ActivityAuthDao(mapper);

            workflowdao.Add(this.Value);
            var         activities = this.Root.GetList();
            List <Link> linkList   = new List <Link>();

            //保存节点
            foreach (var activity in activities)
            {
                activitydao.Add(activity.Value);
                var activityinstance = activity as ActivityModel;
                //保存连接
                if (activityinstance.PreLinks != null)
                {
                    foreach (var link in activityinstance.PreLinks)
                    {
                        if (!linkList.Contains(link.Value))
                        {
                            linkList.Add(link.Value);
                        }
                    }
                }
                if (activityinstance.NextLinks != null)
                {
                    foreach (var link in activityinstance.NextLinks)
                    {
                        if (!linkList.Contains(link.Value))
                        {
                            linkList.Add(link.Value);
                        }
                    }
                }
                //保存权限
                foreach (var auth in activityinstance.Auth)
                {
                    authdao.Add(auth);
                }
            }
            foreach (var link in linkList)
            {
                linkdao.Add(link);
            }
            return(true);
        }
        public WorkflowModel StartNew(string creator, string processid, IWorkflowAuthority iauth)
        {
            var             mapper      = MapperHelper.GetMapper();
            WorkflowDao     workflowdao = new WorkflowDao(mapper);
            ActivityDao     activitydao = new ActivityDao(mapper);
            LinkDao         linkdao     = new LinkDao(mapper);
            ActivityAuthDao aadd        = new ActivityAuthDao(mapper);
            TaskDao         taskdao     = new TaskDao(mapper);
            WorkflowModel   model       = null;
            Workflow        wf          = this.value.ConvertTo <Workflow>();

            wf.ID      = null;
            wf.Creator = creator;
            wf.Status  = (int)WorkflowProcessStatus.Started;
            wf.WorkflowDefinitionID = this.value.ID;
            wf.ProcessID            = processid;
            workflowdao.Add(wf);

            var             activites        = this.ActivityDefinitionList;
            var             links            = this.LinkDefinitionList;
            List <Activity> activityEntities = new List <Activity>();

            foreach (var a in activites)
            {
                Activity activity = a.Value.ConvertTo <Activity>();
                activity.Creator              = creator;
                activity.ID                   = null;
                activity.WorkflowID           = wf.ID;
                activity.ActivityDefinitionID = a.Value.ID;
                activity.Title                = a.Value.Title;
                activity.Status               = (int)ActivityProcessStatus.Started;

                List <ActivityAuth> authList = new List <ActivityAuth>();

                //如果是开始节点,就设置为已处理
                if (this.Root.Equals(a))
                {
                    activity.Status      = (int)ActivityProcessStatus.Processed;
                    activity.ProcessTime = DateTime.Now;
                }
                if (this.Root.Children.Count > 0 && this.Root.Children[0].Equals(a))
                {
                    activity.Status = (int)ActivityProcessStatus.Processing;
                }
                activitydao.Add(activity);
                activityEntities.Add(activity);

                //权限处理
                foreach (var ad in a.AuthDefinition)
                {
                    ActivityAuth auth = ad.ConvertTo <ActivityAuth>();
                    auth.Creator    = creator;
                    auth.WorkflowID = wf.ID;
                    auth.ActivityID = activity.ID;
                    auth.ID         = null;
                    auth.ActivityAuthDefinitionID = ad.ID;
                    aadd.Add(auth);
                    authList.Add(auth);
                }

                //如果是第二节点,就设置成正在处理
                if (this.Root.Children.Count > 0 && this.Root.Children[0].Equals(a))
                {
                    ActivityModel activitymodel = new ActivityModel
                    {
                        Value = activity,
                    };
                    var idlist   = iauth.GetUserIDList(authList);
                    var tasklist = activitymodel.GetTask(creator, idlist);
                    foreach (var task in tasklist)
                    {
                        taskdao.Add(task);
                    }
                }
            }

            foreach (var l in links)
            {
                Link link = l.Value.ConvertTo <Link>();
                link.Creator          = creator;
                link.WorkflowID       = wf.ID;
                link.ID               = null;
                link.LinkDefinitionID = l.Value.ID;
                var fromactivity = activityEntities.Find(t => t.ActivityDefinitionID == l.Value.FromActivityDefinitionID);
                var totactivity  = activityEntities.Find(t => t.ActivityDefinitionID == l.Value.ToActivityDefinitionID);
                if (fromactivity != null)
                {
                    link.FromActivityID = fromactivity.ID;
                }
                if (totactivity != null)
                {
                    link.ToAcivityID = totactivity.ID;
                }
                linkdao.Add(link);
            }

            model = WorkflowModel.Load(wf.ID);
            return(model);
        }
Exemplo n.º 5
0
        /// <summary>
        /// 从数据库读取流程信息
        /// </summary>
        /// <param name="workflowids"></param>
        /// <returns></returns>
        public static List<WorkflowModel> Load(WorkflowQueryForm form)
        {
            List<WorkflowModel> models = new List<WorkflowModel>();
            if (form == null) return models;

            #region query data
            ISqlMapper mapper = MapperHelper.GetMapper();
            WorkflowDao wfdao = new WorkflowDao(mapper);
            ActivityDao activitydao = new ActivityDao(mapper);
            LinkDao linkDao = new LinkDao(mapper);
            ActivityAuthDao authdao = new ActivityAuthDao(mapper);
            ApprovalDao approvalDao = new ApprovalDao(mapper);
            TaskDao taskdao = new TaskDao(mapper);
            List<Activity> activityList = new List<Activity>();
            List<Link> linkList = new List<Link>();
            List<ActivityAuth> authList = new List<ActivityAuth>();
            List<Approval> approvalList = new List<Approval>();
            List<Task> taskList = new List<Task>();
            List<Workflow> workflows = new List<Workflow>();
            //先从缓存取值
            //var item = cache.GetItem(id);
            //if (item != null)
            //{
            //    model = item.Value as WorkflowModel;
            //    return model;
            //}
            workflows = wfdao.Query(form);
            var workflowids = (from wf in workflows select wf.ID).ToList();
            activityList = activitydao.Query(new ActivityQueryForm { WorkflowIDs = workflowids });
            linkList = linkDao.Query(new LinkQueryForm { WorkflowIDs = workflowids });
            approvalList = approvalDao.Query(new ApprovalQueryForm { WorkflowIDs = workflowids });
            authList = authdao.Query(new ActivityAuthQueryForm { WorkflowIDs = workflowids });
            taskList = taskdao.Query(new TaskQueryForm { WorkflowIDs = workflowids });
            #endregion

            foreach (var workflow in workflows)
            {
                var model = BuildWorkflow(workflow, activityList, linkList, authList, approvalList, taskList);
                models.Add(model);
            }
            return models;
        }
Exemplo n.º 6
0
 /// <summary>
 /// 删除该流程
 /// </summary>
 public void Remove()
 {
     ISqlMapper mapper = MapperHelper.GetMapper();
     WorkflowDao wfdao = new WorkflowDao(mapper);
     ActivityDao activitydao = new ActivityDao(mapper);
     LinkDao linkDao = new LinkDao(mapper);
     ActivityAuthDao authdao = new ActivityAuthDao(mapper);
     ApprovalDao approvalDao = new ApprovalDao(mapper);
     TaskDao taskdao = new TaskDao(mapper);
     string id = this.value.ID;
     var activities = activitydao.Query(new ActivityQueryForm { WorkflowID = id });
     taskdao.Delete(new TaskQueryForm { WorkflowID = id });
     wfdao.Delete(new WorkflowQueryForm { ID = id });
     activitydao.Delete(new ActivityQueryForm { WorkflowID = id });
     linkDao.Delete(new LinkQueryForm { WorkflowID = id });
     approvalDao.Delete(new ApprovalQueryForm { WorkflowID = id });
     authdao.Delete(new ActivityAuthQueryForm { WorkflowID = id });
 }
Exemplo n.º 7
0
 /// <summary>
 /// 把流程实体新增到数据库
 /// </summary>
 /// <returns></returns>
 public bool Create()
 {
     ISqlMapper mapper = MapperHelper.GetMapper();
     WorkflowDao workflowdao = new WorkflowDao(mapper);
     ActivityDao activitydao = new ActivityDao(mapper);
     LinkDao linkdao = new LinkDao(mapper);
     ActivityAuthDao authdao = new ActivityAuthDao(mapper);
     workflowdao.Add(this.Value);
     var activities = this.Root.GetList();
     List<Link> linkList = new List<Link>();
     //保存节点
     foreach (var activity in activities)
     {
         activitydao.Add(activity.Value);
         var activityinstance = activity as ActivityModel;
         //保存连接
         if (activityinstance.PreLinks != null)
         {
             foreach (var link in activityinstance.PreLinks)
             {
                 if (!linkList.Contains(link.Value))
                 {
                     linkList.Add(link.Value);
                 }
             }
         }
         if (activityinstance.NextLinks != null)
         {
             foreach (var link in activityinstance.NextLinks)
             {
                 if (!linkList.Contains(link.Value))
                 {
                     linkList.Add(link.Value);
                 }
             }
         }
         //保存权限
         foreach (var auth in activityinstance.Auth)
         {
             authdao.Add(auth);
         }
     }
     foreach (var link in linkList)
     {
         linkdao.Add(link);
     }
     return true;
 }
        public WorkflowModel StartNew(string creator, string processid, IWorkflowAuthority iauth)
        {
            var mapper = MapperHelper.GetMapper();
            WorkflowDao workflowdao = new WorkflowDao(mapper);
            ActivityDao activitydao = new ActivityDao(mapper);
            LinkDao linkdao = new LinkDao(mapper);
            ActivityAuthDao aadd = new ActivityAuthDao(mapper);
            TaskDao taskdao = new TaskDao(mapper);
            WorkflowModel model = null;
            Workflow wf = this.value.ConvertTo<Workflow>();
            wf.ID = null;
            wf.Creator = creator;
            wf.Status = (int)WorkflowProcessStatus.Started;
            wf.WorkflowDefinitionID = this.value.ID;
            wf.ProcessID = processid;
            workflowdao.Add(wf);

            var activites = this.ActivityDefinitionList;
            var links = this.LinkDefinitionList;
            List<Activity> activityEntities = new List<Activity>();
            foreach (var a in activites)
            {
                Activity activity = a.Value.ConvertTo<Activity>();
                activity.Creator = creator;
                activity.ID = null;
                activity.WorkflowID = wf.ID;
                activity.ActivityDefinitionID = a.Value.ID;
                activity.Title = a.Value.Title;
                activity.Status = (int)ActivityProcessStatus.Started;

                List<ActivityAuth> authList = new List<ActivityAuth>();

                //如果是开始节点,就设置为已处理
                if (this.Root.Equals(a))
                {
                    activity.Status = (int)ActivityProcessStatus.Processed;
                    activity.ProcessTime = DateTime.Now;
                }
                if (this.Root.Children.Count > 0 && this.Root.Children[0].Equals(a))
                {
                    activity.Status = (int)ActivityProcessStatus.Processing;
                }
                activitydao.Add(activity);
                activityEntities.Add(activity);

                //权限处理
                foreach (var ad in a.AuthDefinition)
                {
                    ActivityAuth auth = ad.ConvertTo<ActivityAuth>();
                    auth.Creator = creator;
                    auth.WorkflowID = wf.ID;
                    auth.ActivityID = activity.ID;
                    auth.ID = null;
                    auth.ActivityAuthDefinitionID = ad.ID;
                    aadd.Add(auth);
                    authList.Add(auth);
                }

                //如果是第二节点,就设置成正在处理
                if (this.Root.Children.Count > 0 && this.Root.Children[0].Equals(a))
                {
                    ActivityModel activitymodel = new ActivityModel
                    {
                        Value = activity,
                    };
                    var idlist = iauth.GetUserIDList(authList);
                    var tasklist = activitymodel.GetTask(creator, idlist);
                    foreach (var task in tasklist)
                    {
                        taskdao.Add(task);
                    }
                }
            }

            foreach (var l in links)
            {
                Link link = l.Value.ConvertTo<Link>();
                link.Creator = creator;
                link.WorkflowID = wf.ID;
                link.ID = null;
                link.LinkDefinitionID = l.Value.ID;
                var fromactivity = activityEntities.Find(t => t.ActivityDefinitionID == l.Value.FromActivityDefinitionID);
                var totactivity = activityEntities.Find(t => t.ActivityDefinitionID == l.Value.ToActivityDefinitionID);
                if (fromactivity != null)
                {
                    link.FromActivityID = fromactivity.ID;
                }
                if (totactivity != null)
                {
                    link.ToAcivityID = totactivity.ID;
                }
                linkdao.Add(link);
            }

            model = WorkflowModel.Load(wf.ID);
            return model;
        }