承接MOSS各种工作流开发 联系人:王先生.电话:18618405729QQ:252385878 QQ群:41696750 MSN:wanghao-3@hotmail.com

导航

MOSS审批工作流实现动态会签

      好久没有更新我的 Blog啦 。。可能是由于我最近比较忙,也可能是我的访问量太少,写的没有啥动力哦。。。如果大家想看到更多的好文章,请大家多多来骚扰!!!

言归正传:
应用场景:

(5.4 文件批准        
5.4.1 管理体系手册由总经理批准。                
5.4.2 程序文件由相关部门经理会签,总经理或管理者代表批准。   
5.4.3 作业文件由起草部门经理批准。当涉及到其它部门时需要由相关部门会签。)


如果同一个文件作者主管多种产品或编写多种文件则会有多种审批流程,没有固定的标准。

问题1
5.4.2 (关于部门经理可以在流程页面初始化的时候,在外面输入几个人会签,我会根据当前会签人数,但是我的流程设计会签渠道的时候,我都设计死拉,如果想要灵活的,
需要动态创建activity,根据人数来画会签渠道)  难度是不是很大哦。..

大家看看上面需求.MOSS+InfoPath+WF.你解决??
关键是会签是动态的。不知道几个人一起会签 ?


上面有一点就是需要动态会签,不知道有几个人审批,
经过朋友提点 。。需要用到WF 的复制组件,就可以解决这个问题。。。
不过首先我们还需要自己建立一个Activity,然后用复制组件 复制这个 Activity就可以啦 。。。
Activity :

WORKFLOW:

仔细观察我这个Workflow界面,这个里面只放一个replicatorActivity,然后在 这个里面放一个Activity
这样就可以用复制组件实现
Code:

Activity :Code

using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Collections;
using System.Drawing;
using System.Workflow.ComponentModel;
using System.Workflow.ComponentModel.Design;
using System.Workflow.ComponentModel.Compiler;
using System.Workflow.ComponentModel.Serialization;
using System.Workflow.Runtime;
using System.Workflow.Activities;
using System.Workflow.Activities.Rules;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Workflow;

namespace ManageHandBook
{
 public partial class ReTasksActivity: SequenceActivity
 {
  public ReTasksActivity()
  {
   InitializeComponent();
  }

        private static DependencyProperty InstanceDataProperty = DependencyProperty.Register("InstanceData", typeof(SPWorkflowTaskProperties), typeof(ReTasksActivity));

        [DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)]
        [BrowsableAttribute(true)]
        public SPWorkflowTaskProperties InstanceData
        {
            get
            {
                return ((SPWorkflowTaskProperties)(base.GetValue(ReTasksActivity.InstanceDataProperty)));
            }
            set
            {
                base.SetValue(ReTasksActivity.InstanceDataProperty, value);
            }
        }

        private string comment;
        public string Comment
        {
            set { comment = value; }
            get { return comment; }
        }

 

        public Guid taskId1 = default(System.Guid);
        public Microsoft.SharePoint.Workflow.SPWorkflowTaskProperties taskProperties1 = new Microsoft.SharePoint.Workflow.SPWorkflowTaskProperties();
        public Microsoft.SharePoint.Workflow.SPWorkflowTaskProperties afterProperties1 = new Microsoft.SharePoint.Workflow.SPWorkflowTaskProperties();
        public Microsoft.SharePoint.Workflow.SPWorkflowTaskProperties beforeProperties1 = new Microsoft.SharePoint.Workflow.SPWorkflowTaskProperties();

        private void createTask1_MethodInvoking(object sender, EventArgs e)
        {
            taskId1 = Guid.NewGuid();
            taskProperties1.TaskType = 0;
            taskProperties1.ExtendedProperties["afterComments"] = comment;
        }

        private void onTaskChanged1_Invoked(object sender, ExternalDataEventArgs e)
        {
            comment = onTaskChanged1.AfterProperties.ExtendedProperties["comments"].ToString();
        }
 }
}


这个是 Activity里面的代码 很简单吧。。主要用 SPWorkflowTaskProperties   动态创建任务。。

Workflow.cs

using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Collections;
using System.Drawing;
using System.Workflow.ComponentModel.Compiler;
using System.Workflow.ComponentModel.Serialization;
using System.Workflow.ComponentModel;
using System.Workflow.ComponentModel.Design;
using System.Workflow.Runtime;
using System.Workflow.Activities;
using System.Workflow.Activities.Rules;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Workflow;
using System.Xml;
using System.Xml.Serialization;
namespace ManageHandBook
{
 public sealed partial class Workflow1: SequentialWorkflowActivity
 {
  public Workflow1()
  {
   InitializeComponent();
  }

        private void rePlicatorActivity_ChildCompleted(object sender, ReplicatorChildEventArgs e)
        {
            ReTasksActivity activity = e.Activity as ReTasksActivity;
          
            comments = string.Format("{0}Approved {1}:{2}\n", comments, workflowProperties1.Web.AllUsers[activity.taskProperties1.AssignedTo].Name, activity.Comment);
 
        }

        private void rePlicatorActivity_ChildInitialized(object sender, ReplicatorChildEventArgs e)
        {
            ReTasksActivity activity = e.Activity as ReTasksActivity;
            activity.taskProperties1 = e.InstanceData as SPWorkflowTaskProperties;
            activity.Comment = comments;
        }
        public Guid workflowId = default(System.Guid);
        public Microsoft.SharePoint.Workflow.SPWorkflowActivationProperties workflowProperties1 = new Microsoft.SharePoint.Workflow.SPWorkflowActivationProperties();

        private string comments = string.Empty;
        private Person[] allPerson = null;
        private void onWorkflowActivated1_Invoked(object sender, ExternalDataEventArgs e)
        {
            workflowId = workflowProperties1.WorkflowId;

            //反序列化workflowProperties.InitiationData以得到初始窗体的实例
            XmlSerializer xs = new XmlSerializer(typeof(Inits));
            XmlTextReader xtr = new XmlTextReader(new System.IO.StringReader(workflowProperties1.InitiationData));
            Inits init = (Inits)xs.Deserialize(xtr);
            allPerson = init.Contact;
            ArrayList Initlist = new ArrayList();
            for (int i = 0; i < allPerson.Length; i++)
            {
                SPWorkflowTaskProperties taskProperty = new SPWorkflowTaskProperties();
                taskProperty.AssignedTo = allPerson[i].AccountId;
                taskProperty.TaskType = 0;
                taskProperty.Title = string.Format("请审批 {0}", workflowProperties1.Item.DisplayName);
                Initlist.Add(taskProperty);
            }

            replicatorActivity.InitialChildData = Initlist;
        }
    }

}

Workflow 的代码更简单 。。。
复制组件的2个方法 更重要的哦。。
  private void rePlicatorActivity_ChildCompleted(object sender, ReplicatorChildEventArgs e)
        {
            ReTasksActivity activity = e.Activity as ReTasksActivity;
          
            comments = string.Format("{0}Approved {1}:{2}\n", comments, workflowProperties1.Web.AllUsers[activity.taskProperties1.AssignedTo].Name, activity.Comment);
 
        }

        private void rePlicatorActivity_ChildInitialized(object sender, ReplicatorChildEventArgs e)
        {
            ReTasksActivity activity = e.Activity as ReTasksActivity;
            activity.taskProperties1 = e.InstanceData as SPWorkflowTaskProperties;
            activity.Comment = comments;
        }

看起来 代码很简单。却能实现很复杂的流程。动态会签当然不是问题。。
如果大家仿照 扩展 扩展。。确实可以实现很多应用。。

/Files/wanghao-3/ManageHandBook.rar

posted on 2008-04-02 11:31  A A  阅读(3197)  评论(9编辑  收藏  举报