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

OA系统

开发平台:

C#

  1. using System;
  2. using System.Collections;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Web;
  7. using System.Web.SessionState;
  8. using System.Web.UI;
  9. using System.Web.UI.WebControls;
  10. using System.Web.UI.HtmlControls;
  11. namespace OThinker.H3.Portal
  12. {
  13.     /// <summary>
  14.     /// 完成一个任务同时跳转到另外一个任务上
  15.     /// </summary>
  16.     public partial class FinishWorkItem : PortalPage
  17.     {
  18.         #region 获得参数信息
  19.         // 当前的任务
  20.         private OThinker.H3.WorkItem.WorkItem WorkItem
  21.         {
  22.             get
  23.             {
  24.                 string itemId = this.Request.QueryString[Param_WorkItemID];
  25.                 string sessionName = OThinker.H3.WorkSheet.Sessions.GetWorkItem(itemId);
  26.                 if (this.Session[sessionName] == null)
  27.                 {
  28.                     this.Session[sessionName] = OThinker.H3.Server.Engine.WorkItemManager.GetWorkItem(itemId);
  29.                 }
  30.                 return (OThinker.H3.WorkItem.WorkItem)this.Session[sessionName];
  31.             }
  32.         }
  33.         private OThinker.H3.WorkflowTemplate.WorkflowTemplate WorkflowTemplate
  34.         {
  35.             get
  36.             {
  37.                 string sessionName = OThinker.H3.WorkSheet.Sessions.GetWorkflow(
  38.                     this.WorkItem.WorkflowPackage,
  39.                     this.WorkItem.WorkflowName,
  40.                     this.WorkItem.WorkflowVersion);
  41.                 OThinker.H3.WorkflowTemplate.WorkflowTemplate process;
  42.                 if (this.Session[sessionName] == null)
  43.                 {
  44.                     this.Session[sessionName] = OThinker.H3.Server.Engine.WorkflowManager.GetWorkflow(
  45.                         this.WorkItem.WorkflowPackage,
  46.                         this.WorkItem.WorkflowName,
  47.                         this.WorkItem.WorkflowVersion);
  48.                 }
  49.                 return (OThinker.H3.WorkflowTemplate.WorkflowTemplate)this.Session[sessionName];
  50.             }
  51.         }
  52.         // 目标任务
  53.         private OThinker.H3.WorkflowTemplate.ActivityTemplate DestActivity
  54.         {
  55.             get
  56.             {
  57.                 if (this.WorkflowTemplate == null)
  58.                 {
  59.                     return null;
  60.                 }
  61.                 else
  62.                 {
  63.                     string destActivityName = System.Web.HttpUtility.UrlDecode(this.Request.QueryString[Param_DestActivityName]);
  64.                     OThinker.H3.WorkflowTemplate.ActivityTemplate task = this.WorkflowTemplate.GetActivity(destActivityName);
  65.                     return task;
  66.                 }
  67.             }
  68.         }
  69.         private OThinker.Data.BoolMatchValue Approval
  70.         {
  71.             get
  72.             {
  73.                 string strApproval = this.Request.QueryString[Param_Approval];
  74.                 if (strApproval == null || strApproval == "")
  75.                 {
  76.                     return OThinker.Data.BoolMatchValue.Unspecified;
  77.                 }
  78.                 else
  79.                 {
  80.                     try
  81.                     {
  82.                         return (OThinker.Data.BoolMatchValue)Enum.Parse(typeof(OThinker.Data.BoolMatchValue), strApproval);
  83.                     }
  84.                     catch
  85.                     {
  86.                         return OThinker.Data.BoolMatchValue.Unspecified;
  87.                     }
  88.                 }
  89.             }
  90.         }
  91.         private string Comment
  92.         {
  93.             get
  94.             {
  95.                 return HttpUtility.UrlDecode(this.Request.QueryString[Param_Comment]);
  96.             }
  97.         }
  98.         private string ParticipateGroup
  99.         {
  100.             get
  101.             {
  102.                 return HttpUtility.UrlDecode(this.Request.QueryString[Param_ParticipateGroup]);
  103.             }
  104.         }
  105.         #endregion
  106.         #region 流程数据集
  107.         private string[] GetOptionalParticipants()
  108.         {
  109.             // 获得后续的参与者
  110.             string originator = OThinker.H3.Server.Engine.InstanceManager.GetInstanceOriginator(this.WorkItem.InstanceId);
  111.             // 准备数据集
  112.             H3.Data.InstanceData data = new OThinker.H3.Data.InstanceData(
  113.                     OThinker.H3.Server.Engine.InstanceDataManager,
  114.                     OThinker.H3.Server.Engine.WorkflowManager,
  115.                     OThinker.H3.Server.Engine.InstanceManager,
  116.                     this.WorkItem.InstanceId,
  117.                     this.WorkItem.TokenId, 
  118.                     OThinker.H3.Server.Engine.WorkflowManager.GetWorkflow(
  119.                         this.WorkItem.WorkflowPackage,
  120.                         this.WorkItem.WorkflowName,
  121.                         this.WorkItem.WorkflowVersion),
  122.                     this.WorkItem.ActivityName,
  123.                     this.UserValidator.UserID,
  124.                     null);
  125.             data.UseCache = true;
  126.             data.AutoLookupParent = false;
  127.             return this.DestActivity.ParseParticipants(
  128.                         OThinker.H3.Server.Engine.Organization,
  129.                         this.WorkItem.InstanceId,
  130.                         this.WorkItem.TokenId, 
  131.                         OThinker.H3.Server.Engine.InstanceManager,
  132.                         OThinker.H3.Server.Engine.TokenPool, 
  133.                         OThinker.H3.Server.Engine.WorkItemManager,
  134.                         data,
  135.                         this.UserValidator.UserID);
  136.         }
  137.         #endregion
  138.         protected void Page_Load(object sender, System.EventArgs e)
  139.         {
  140.             if (!this.IsPostBack)
  141.             {
  142.                 if (this.WorkItem.ItemType == OThinker.H3.WorkItem.WorkItemType.Consultancy)
  143.                 {
  144.                     this._FinishWorkItem();
  145.                     // 转到另外一个页面上
  146.                     this.NotifyMessage("任务已完成!");
  147.                 }
  148.                 else if (this.DestActivity == null)
  149.                 {
  150.                     this.btnSubmit_Click(null, null);
  151.                 }
  152.                 else if (this.DestActivity.ParticipateType == OThinker.H3.WorkflowTemplate.ActivityParticipateType.NoneParticipant)
  153.                 {
  154.                     this.btnSubmit_Click(null, null);
  155.                 }
  156.                 else if (this.DestActivity.ParticipateType == OThinker.H3.WorkflowTemplate.ActivityParticipateType.SingleParticipant)
  157.                 {
  158.                     string[] participants = this.GetOptionalParticipants();
  159.                     if (participants == null || participants.Length == 0)
  160.                     {
  161.                         this.NotifyMessage("该任务设计有问题,没有可选择的处理人");
  162.                     }
  163.                     else
  164.                     {
  165.                         int optionalReceiverCount = 0;
  166.                         foreach (string receiver in participants)
  167.                         {
  168.                             if (receiver != null && receiver != "")
  169.                             {
  170.                                 string receiverName = OThinker.H3.Server.Engine.Organization.GetFullName(receiver);
  171.                                 this.ReceiverSelector.Items.Add(receiverName);
  172.                                 optionalReceiverCount++;
  173.                             }
  174.                         }
  175.                         this.ReceiverSelector.SelectedIndex = 0;
  176.                         this.ReceiverSelector.Visible = true;
  177.                         if (optionalReceiverCount == 1)
  178.                         {
  179.                             this.btnSubmit_Click(null, null);
  180.                         }
  181.                     }
  182.                 }
  183.                 else if (this.DestActivity.ParticipateType == OThinker.H3.WorkflowTemplate.ActivityParticipateType.MultiParticipants)
  184.                 {
  185.                     string[] participants = this.GetOptionalParticipants();
  186.                     if (participants == null || participants.Length == 0)
  187.                     {
  188.                         this.NotifyMessage("该任务设计有问题,没有可选择的处理人");
  189.                     }
  190.                     else
  191.                     {
  192.                         int optionalReceiverCount = 0;
  193.                         foreach (string receiver in participants)
  194.                         {
  195.                             if (receiver != null && receiver != "")
  196.                             {
  197.                                 string receiverName = OThinker.H3.Server.Engine.Organization.GetFullName(receiver);
  198.                                 this.ReceiversSelector.Items.Add(receiverName);
  199.                                 optionalReceiverCount++;
  200.                             }
  201.                         }
  202.                         this.ReceiversSelector.SelectedIndex = 0;
  203.                         this.ReceiversSelector.Visible = true;
  204.                         if (optionalReceiverCount == 1)
  205.                         {
  206.                             this.btnSubmit_Click(null, null);
  207.                         }
  208.                     }
  209.                 }
  210.                 else if (this.DestActivity.ParticipateType == OThinker.H3.WorkflowTemplate.ActivityParticipateType.AllParticipants)
  211.                 {
  212.                     this.btnSubmit_Click(null, null);
  213.                 }
  214.                 else
  215.                 {
  216.                     throw new NotImplementedException();
  217.                 }
  218.             }
  219.         }
  220.         #region Web Form Designer generated code
  221.         override protected void OnInit(EventArgs e)
  222.         {
  223.             //
  224.             // CODEGEN: This call is required by the ASP.NET Web Form Designer.
  225.             //
  226.             InitializeComponent();
  227.             base.OnInit(e);
  228.         }
  229.         /// <summary>
  230.         /// Required method for Designer support - do not modify
  231.         /// the contents of this method with the code editor.
  232.         /// </summary>
  233.         private void InitializeComponent()
  234.         {
  235.         }
  236.         #endregion
  237.         protected void btnSubmit_Click(object sender, System.EventArgs e)
  238.         {
  239.             if (this.DestActivity == null)
  240.             {
  241.                 this._FinishWorkItem();
  242.                 // 采用自动路由的方式
  243.                 this.AutoRoute();
  244.             }
  245.             else
  246.             {
  247.                 // 触发后面的Activity
  248.                 string[] participants = this.GetSelectedParticipants();
  249.                 // 检查是否有选中参与者
  250.                 if (this.ReceiversSelector != null && this.ReceiversSelector.Items.Count > 1)
  251.                 {
  252.                     if (participants == null || participants.Length == 0)
  253.                     {
  254.                         this.NotifyMessage("请选择参与者");
  255.                     }
  256.                 }
  257.                 this._FinishWorkItem();
  258.                 // 准备触发后面Activity的消息
  259.                 OThinker.H3.Messages.ActivateActivityMessage activateMessage
  260.                     = new OThinker.H3.Messages.ActivateActivityMessage(
  261.                     OThinker.H3.Messages.MessageEmergencyType.Normal,
  262.                     this.WorkItem.InstanceId,
  263.                     this.DestActivity.Name,
  264.                     OThinker.H3.Instance.Token.UnspecifiedID,
  265.                     participants,
  266.                     new long[] { this.WorkItem.TokenId },
  267.                     false,
  268.                     Messages.ActivateType.Normal,
  269.                     null);
  270.                 // 通知该Activity已经完成
  271.                 OThinker.H3.Messages.AsyncEndMessage endMessage =
  272.                     new OThinker.H3.Messages.AsyncEndMessage(
  273.                         OThinker.H3.Messages.MessageEmergencyType.Normal,
  274.                         this.WorkItem.InstanceId,
  275.                         this.WorkItem.ActivityName,
  276.                         this.WorkItem.ReplyID,
  277.                         false,
  278.                         this.UserValidator.UserID,
  279.                         this.Approval,  
  280.                         activateMessage, 
  281.                         null);
  282.                 OThinker.H3.Server.Engine.InstanceManager.SendMessage(endMessage);
  283.             }
  284.             this.NotifyMessage("任务已完成");
  285.         }
  286.         private void _FinishWorkItem()
  287.         {
  288.             OThinker.H3.Server.Engine.WorkItemManager.FinishWorkItem(this.WorkItem.WorkItemID, this.UserValidator.UserID, this.ParticipateGroup, this.Approval, this.Comment);
  289.             // 设置Session的工作项的状态
  290.             this.WorkItem.State = OThinker.H3.WorkItem.WorkItemState.Finished;
  291.             // 设置操作描述
  292.             string description = System.Web.HttpUtility.UrlDecode(this.Request.QueryString[Param_Description]);
  293.             OThinker.H3.Server.Engine.TokenPool.AppendDescription(this.WorkItem.InstanceId, this.WorkItem.TokenId, description);
  294.         }
  295.         private void AutoRoute()
  296.         {
  297.             // 需要通知实例事件管理器结束事件
  298.             Messages.AsyncEndMessage endMessage = new OThinker.H3.Messages.AsyncEndMessage(
  299.                     Messages.MessageEmergencyType.Normal,
  300.                     this.WorkItem.InstanceId,
  301.                     this.WorkItem.ActivityName,
  302.                     this.WorkItem.ReplyID,
  303.                     true,
  304.                     this.UserValidator.UserID,
  305.                     this.Approval,
  306.                     null,
  307.                     null);
  308.             OThinker.H3.Server.Engine.InstanceManager.SendMessage(endMessage);
  309.         }
  310.         private string[] GetSelectedParticipants()
  311.         {
  312.             // 参与者
  313.             string[] participants;
  314.             if (this.DestActivity.ParticipateType == OThinker.H3.WorkflowTemplate.ActivityParticipateType.NoneParticipant)
  315.             {
  316.                 // 参与人为空
  317.                 participants = new string[0];
  318.             }
  319.             else if (this.DestActivity.ParticipateType == OThinker.H3.WorkflowTemplate.ActivityParticipateType.SingleParticipant)
  320.             {
  321.                 // 选中的参与人
  322.                 string receiver = this.ReceiverSelector.SelectedValue;
  323.                 int startIndex = receiver.LastIndexOf("[");
  324.                 int endIndex = receiver.LastIndexOf("]");
  325.                 string alias = receiver.Substring(startIndex + 1, endIndex - startIndex - 1);
  326.                 string userId = OThinker.H3.Server.Engine.Organization.GetUserIDByAlias(alias);
  327.                 participants = new string[] { userId };
  328.             }
  329.             else if (this.DestActivity.ParticipateType == OThinker.H3.WorkflowTemplate.ActivityParticipateType.MultiParticipants)
  330.             {
  331.                 ArrayList selectedReceivers = new ArrayList();
  332.                 foreach (System.Web.UI.WebControls.ListItem item in this.ReceiversSelector.Items)
  333.                 {
  334.                     if (item.Selected)
  335.                     {
  336.                         string receiver = item.Text;
  337.                         int startIndex = receiver.LastIndexOf("[");
  338.                         int endIndex = receiver.LastIndexOf("]");
  339.                         string principalName = receiver.Substring(startIndex + 1, endIndex - startIndex - 1);
  340.                         selectedReceivers.Add(principalName);
  341.                     }
  342.                 }
  343.                 // 获得可选择的接收者
  344.                 string[] receivers = new string[selectedReceivers.Count];
  345.                 for (int count = 0; count < receivers.Length; count++)
  346.                 {
  347.                     string userId = OThinker.H3.Server.Engine.Organization.GetUserIDByAlias((string)selectedReceivers[count]);
  348.                     receivers[count] = userId;
  349.                 }
  350.                 // 选中的参与人
  351.                 participants = receivers;
  352.             }
  353.             else if (this.DestActivity.ParticipateType == OThinker.H3.WorkflowTemplate.ActivityParticipateType.AllParticipants)
  354.             {
  355.                 participants = this.GetOptionalParticipants();
  356.             }
  357.             else
  358.             {
  359.                 throw new NotImplementedException();
  360.             }
  361.             return participants;
  362.         }
  363.     }
  364. }