轉帖|其它|編輯:郝浩|2011-05-09 16:47:54.000|閱讀 1011 次
概述:最近因為接手離職同事的公文審批(沒有使用工作流)維護,感覺很麻煩,于是在我開發的工作流平臺上重新寫了相關的功能,擴展同事的功能,同時可以支持固定流和任意流功能。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
最近因為接手離職同事的公文審批(沒有使用工作流)維護,感覺很麻煩,于是在我開發的工作流平臺上重新寫了相關的功能,擴展同事的功能,同時可以支持固定流和任意流功能。
固定流就是由發起人定義審批的步驟,流程按照既定步驟執行。
任意流就是由發起人發起,選擇下一步審批人審批,然后審批再選擇下一步審批人。
當然公文審批支持的電子簽名的功能也有,但是不作為本篇討論內容,還有界面美觀。
1.服務代碼
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Workflow.Runtime;
using System.Workflow.Activities;
using System.Workflow.ComponentModel;
namespace StateMachineService
{
[Serializable]
public class DocFlowEventArgs:ExternalDataEventArgs
{
public DocFlowEventArgs(string userID,Guid uninstand): base(uninstand)
{
this.uninstand = uninstand;
this.userID = userID;
}
private Guid uninstand = Guid.Empty;
public Guid Uninstand
{
get { return this.uninstand; }
set { this.uninstand = value; }
}
private string userID = string.Empty;
public string UserID
{
get { return this.userID; }
set { this.userID = value; }
}
}
[ExternalDataExchange]
public interface IDocFlowService
{
event EventHandler<DocFlowEventArgs> Next;
event EventHandler<DocFlowEventArgs> Jump;
event EventHandler<DocFlowEventArgs> Stop;
void SetFixNextApprover(int NextStpeID, string uninstand);
void SetFixEnableApprover(int CurrentStpeID, string uninstand);
void SetAutoNextApprover();
void SetAutoEnableApprover(string uninstand);
void ChangeStatus();
}
[Serializable]
public class DocFlowService:IDocFlowService
{
IDAL.IWFreeNode iwfreenode;
Guid T;
string UserID;
Dictionary<string, EventHandler<DocFlowEventArgs>> list =
new Dictionary<string, EventHandler<DocFlowEventArgs>>();
public void RaiseEventer(string eventName,Guid uninstand,string userID)
{
if(list[eventName]!=null)
{
try
{
EventHandler<DocFlowEventArgs> eventHandler=list[eventName];
DocFlowEventArgs args= new DocFlowEventArgs(userID ,uninstand);
args.WaitForIdle = true;
eventHandler.Invoke(null, args );
this.T = uninstand;
this.UserID = userID;
}
catch
{
}
}
}
IDocFlowService 成員#region IDocFlowService 成員
public event EventHandler <DocFlowEventArgs> Next
{
add
{
this.list.Add("Next", value);
}
remove
{
this.list.Remove("Next");
}
}
public event EventHandler <DocFlowEventArgs> Jump
{ add
{
this.list.Add("Jump", value);
}
remove
{
this.list.Remove("Jump");
}
}
public event EventHandler <DocFlowEventArgs> Stop
{
add
{
this.list.Add("Stop", value);
}
remove
{
this.list.Remove("Stop");
}
}
public void ChangeStatus()
{
throw new NotImplementedException();
}
#endregion
IDocFlowService 成員#region IDocFlowService 成員
public void SetFixNextApprover(int NextStpeID,string uninstand)
{
iwfreenode = DALFactory.WFreeNode.CreateInstance();
string script = "update WFreeNode set [ExceteState]=1
where Uninstand='"+uninstand+"' and StepID="+NextStpeID;
iwfreenode.Update(script);
//throw new NotImplementedException();
}
#endregion
IDocFlowService 成員#region IDocFlowService 成員
public void SetFixEnableApprover(int CurrentStpeID,string uninstand)
{
iwfreenode = DALFactory.WFreeNode.CreateInstance();
string script = "update WFreeNode set [ExceteState]=
2 where Uninstand='" +uninstand+ "' and userID=
'" + this.UserID + "' and StepID=" + CurrentStpeID;
iwfreenode.Update(script);
//throw new NotImplementedException();
}
#endregion
IDocFlowService 成員#region IDocFlowService 成員
public void SetAutoNextApprover()
{
//throw new NotImplementedException();
}
public void SetAutoEnableApprover(string uninstand)
{
iwfreenode = DALFactory.WFreeNode.CreateInstance();
string script = "update WFreeNode set [ExceteState]=2 where
Uninstand='" +uninstand + "' and userID='" + this.UserID + "'";
iwfreenode.Update(script);
}
#endregion
}
}
現在支持前進,抄送(平臺功能)和終止,還不支持會退和跳批。
2.數據庫結構
CREATE TABLE [dbo].[DocFlow](
[Uninstand] [uniqueidentifier] NOT NULL,
[UserID] [varchar](50) NOT NULL,
[Date] [datetime] NULL,
[Title] [varchar](400) NULL,
[Remark] [varchar](500) NULL,
[DocLevel] [varchar](50) NULL,
[FlowType] [varchar](10) NULL,
[Depart] [varchar](50) NULL
)
3.流程圖
a.
b.
3.
4.
流程代碼
using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Collections;
using System.Drawing;
using System.Linq;
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;
namespace StateMachineLibrary
{
public partial class DocFlow: StateMachineWorkflowActivity
{
public static DependencyProperty DocFlowTypeProperty = DependencyProperty.Register("DocFlowType", typeof(string), typeof(DocFlow));
public string DocFlowType
{
get { return (string)base.GetValue(DocFlow.DocFlowTypeProperty); }
set { base.SetValue(DocFlow.DocFlowTypeProperty, value); }
}
public static DependencyProperty StepIDListProperty =
DependencyProperty.Register("StepIDList", typeof
(System.Collections.Generic.List<int>), typeof(DocFlow));
public System.Collections.Generic.List<int> StepIDList
{
get { return (System.Collections.Generic.List<int>)
base.GetValue(DocFlow.StepIDListProperty); }
set { base.SetValue(DocFlow.StepIDListProperty, value); }
}
public static DependencyProperty UninstandProperty =
DependencyProperty.Register("Uninstand",typeof(string),typeof(DocFlow));
public string Uninstand
{
get { return (string)base.GetValue(DocFlow.UninstandProperty); }
set { base.SetValue(DocFlow.UninstandProperty, value); }
}
public static DependencyProperty CurrentIndexProperty =
DependencyProperty.Register("CurrentIndex", typeof(int), typeof(DocFlow));
public int CurrentIndex
{
get { return (int)base.GetValue(DocFlow.CurrentIndexProperty); }
set { base.SetValue(DocFlow.CurrentIndexProperty, value); }
}
private int MaxIndex = 0;
private int MinIndex = 0;
private void autoResearch(object sender, EventArgs e)
{
if(this.DocFlowType.Equals("fix",StringComparison.OrdinalIgnoreCase))
{
this.FindMinMax();
}
}
private void FindMinMax()
{
this.StepIDList.Sort(new Comparison<int>((x, y) => x.CompareTo(y)));
this.MinIndex = this.StepIDList[0];
this.MaxIndex = this.StepIDList[this.StepIDList.Count-1];
this.CurrentIndex = this.MinIndex;
}
private void FixCurrentRemove(object sender, EventArgs e)
{
if (this.DocFlowType.Equals("fix", StringComparison.OrdinalIgnoreCase))
{
this.StepIDList.Remove(this.CurrentIndex);
}
}
private void CheckDocType(object sender, ConditionalEventArgs e)
{
if (this.DocFlowType.Equals( "fix", StringComparison.OrdinalIgnoreCase))
{
e.Result = true;
}
else
{
e.Result = false;
}
}
private void CurrentIsOve(object sender, ConditionalEventArgs e)
{
if (this.StepIDList.FindAll(p => p == this.CurrentIndex).Count == 0)
{
e.Result = true;
}
else
{
e.Result = false;
}
}
private void CalCurrentStep(object sender, EventArgs e)
{
this.StepIDList.Sort(new Comparison<int>((x, y) => x.CompareTo(y)));
if(this.StepIDList.Count>0)
{
this.CurrentIndex = this.StepIDList[0];
}
}
private void FixIsFinal(object sender, ConditionalEventArgs e)
{
if (this.CurrentIndex == this.MaxIndex && this.StepIDList.FindAll(p =>
p == this.CurrentIndex).Count <= 1)
{
e.Result = true;
}
else
{
e.Result = false;
}
}
private void GetWorkflowID(object sender, EventArgs e)
{
this.Uninstand = this.WorkflowInstanceId.ToString();
}
}
}
主要是StepIDList用于記錄固定工作流的步驟序號,DocFlow用于記錄工作流類型 CurrentIndex 記錄當前步驟號
其它的就是分析最小和最大號,找尋下部號,已經相關的流轉控制。還有一些是訪問后臺數據庫的服務。
用戶操作界面
審批界面
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉載自:博客園