RetrieveWorkItem.aspx.cs
上传用户:li2971742
上传日期:2021-11-18
资源大小:39096k
文件大小:5k
源码类别:

OA系统

开发平台:

C#

  1. using System;
  2. using System.Data;
  3. using System.Configuration;
  4. using System.Collections;
  5. using System.Web;
  6. using System.Web.Security;
  7. using System.Web.UI;
  8. using System.Web.UI.WebControls;
  9. using System.Web.UI.WebControls.WebParts;
  10. using System.Web.UI.HtmlControls;
  11. namespace OThinker.H3.Portal
  12. {
  13.     public partial class RetrieveWorkItem : PortalPage
  14.     {
  15.         public string _WorkItemID = OThinker.H3.WorkItem.WorkItem.NullWorkItemID;
  16.         public string WorkItemID
  17.         {
  18.             get
  19.             {
  20.                 if (this._WorkItemID == OThinker.H3.WorkItem.WorkItem.NullWorkItemID)
  21.                 {
  22.                     string itemId = Request.QueryString[Param_WorkItemID];
  23.                     if (itemId != null && itemId != "")
  24.                     {
  25.                         this._WorkItemID = itemId;
  26.                     }
  27.                 }
  28.                 return this._WorkItemID;
  29.             }
  30.         }
  31.         private OThinker.H3.WorkItem.WorkItem _WorkItem = null;
  32.         public OThinker.H3.WorkItem.WorkItem WorkItem
  33.         {
  34.             get
  35.             {
  36.                 if(this._WorkItem == null)
  37.                 {
  38.                     this._WorkItem = OThinker.H3.Server.Engine.WorkItemManager.GetWorkItem(this.WorkItemID);
  39.                 }
  40.                 return this._WorkItem;
  41.             }
  42.         }
  43.         protected void Page_Load(object sender, EventArgs e)
  44.         {
  45.             // 检查是否能够取回
  46.             if (this.WorkItem == null)
  47.             {
  48.                 this.NotifyMessage("该工作项不存在");
  49.             }
  50.             // 获得当前的Token是否存在多个分支
  51.             OThinker.H3.Instance.IToken currentToken = OThinker.H3.Server.Engine.TokenPool.GetToken(this.WorkItem.InstanceId, this.WorkItem.TokenId);
  52.             if (currentToken == null)
  53.             {
  54.                 this.NotifyMessage("不具有取回的条件");
  55.             }
  56.             // 获得后继的Token
  57.             long[] postTokenIds = OThinker.H3.Server.Engine.TokenPool.QueryPostToken(this.WorkItem.InstanceId, this.WorkItem.TokenId);
  58.             // 发送回退消息
  59.             if (postTokenIds == null || postTokenIds.Length == 0)
  60.             {
  61.                 // 已经取回过了
  62.                 this.NotifyMessage("不存在后继活动,或者已经取回过了");
  63.             }
  64.             else if (postTokenIds.Length > 1)
  65.             {
  66.                 this.NotifyMessage("不具有取回的条件,后继存在多个活动");
  67.             }            
  68.             long postTokenId = postTokenIds[0];
  69.             OThinker.H3.Instance.IToken postToken = OThinker.H3.Server.Engine.TokenPool.GetToken(this.WorkItem.InstanceId, postTokenId);
  70.             if (!postToken.Retrievable)
  71.             {
  72.                 // 无法取回
  73.                 this.NotifyMessage("不具有取回的条件,后继活动已经不允许取回,或者后继已经做了不可取回的操作了");
  74.             }
  75.             // 具备取回的条件
  76.             // 记录流程ID,TokenID和参与者信息
  77.             string instanceId = this.WorkItem.InstanceId;
  78.             long tokenId = this.WorkItem.TokenId;
  79.             string participant = this.WorkItem.Participant;
  80.             OThinker.H3.Messages.CancelActivityMessage rollback
  81.             = new OThinker.H3.Messages.CancelActivityMessage(
  82.                 OThinker.H3.Messages.MessageEmergencyType.Normal,
  83.                 this.WorkItem.InstanceId,
  84.                 postToken.Activity,
  85.                 true,
  86.                 null);
  87.             OThinker.H3.Server.Engine.InstanceManager.SendMessage(rollback);
  88.             // 读取新的工作项
  89.             // 获得该实例的任务
  90.             string[] items = null;
  91.             for (int triedTimes = 0; triedTimes < 10; triedTimes++)
  92.             {
  93.                 System.Threading.Thread.Sleep(1500);
  94.                 items = OThinker.H3.Server.Engine.WorkItemManager.Query(
  95.                     null,
  96.                     new string[] { instanceId },
  97.                     new string[] { participant },
  98.                     System.DateTime.MinValue,
  99.                     System.DateTime.MaxValue,
  100.                     OThinker.H3.WorkItem.WorkItemState.Unfinished);
  101.                 if (items != null && items.Length != 0)
  102.                 {
  103.                     break;
  104.                 }
  105.             }
  106.             if (items == null || items.Length == 0)
  107.             {
  108.                 this.NotifyMessage(
  109.                     "超时,可能是如下原因造成的:<BR>" +
  110.                     "1、创建或启动流程的时候出现了异常,请点击Web控制台上的管理->异常,查看是否出现了异常<BR>" +
  111.                     "2、系统正忙,请稍后在待办任务中查看是否存在该工作项");
  112.             }
  113.             else
  114.             {
  115.                 // 获得该任务
  116.                 OThinker.H3.WorkItem.WorkItem item = OThinker.H3.Server.Engine.WorkItemManager.GetWorkItem(items[0]);
  117.                 // 任务已经收到
  118.                 this.Response.Redirect(PortalPage.GetWorkSheetUrl(item));
  119.             }
  120.         }
  121.     }
  122. }