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

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 ActivateActivity : PortalPage
  17.     {
  18.         #region 获得参数信息
  19.         // 当前的任务
  20.         private string InstanceId
  21.         {
  22.             get
  23.             {
  24.                 return this.Request.QueryString[Param_InstanceId];
  25.             }
  26.         }
  27.         public OThinker.H3.Instance.InstanceContext InstanceContext
  28.         {
  29.             get
  30.             {
  31.                 string sessionName = OThinker.H3.WorkSheet.Sessions.GetInstanceContext(this.InstanceId);
  32.                 if (this.Session[sessionName] == null)
  33.                 {
  34.                     this.Session[sessionName] = OThinker.H3.Server.Engine.InstanceManager.GetInstanceContext(this.InstanceId);
  35.                 }
  36.                 return (OThinker.H3.Instance.InstanceContext)this.Session[sessionName];
  37.             }
  38.             set
  39.             {
  40.                 string sessionName = OThinker.H3.WorkSheet.Sessions.GetInstanceContext(this.InstanceId);
  41.                 this.Session[sessionName] = value;
  42.             }
  43.         }
  44.         private string WorkflowPackage
  45.         {
  46.             get
  47.             {
  48.                 return this.InstanceContext.WorkflowPackage;
  49.             }
  50.         }
  51.         private string WorkflowName
  52.         {
  53.             get
  54.             {
  55.                 return this.InstanceContext.WorkflowName;
  56.             }
  57.         }
  58.         private int WorkflowVersion
  59.         {
  60.             get
  61.             {
  62.                 return this.InstanceContext.WorkflowVersion;
  63.             }
  64.         }
  65.         private OThinker.H3.WorkflowTemplate.WorkflowTemplate WorkflowTemplate
  66.         {
  67.             get
  68.             {
  69.                 string sessionName = OThinker.H3.WorkSheet.Sessions.GetWorkflow(
  70.                     this.WorkflowPackage,
  71.                     this.WorkflowName,
  72.                     this.WorkflowVersion);
  73.                 if (this.Session[sessionName] == null)
  74.                 {
  75.                     this.Session[sessionName] = OThinker.H3.Server.Engine.WorkflowManager.GetWorkflow(
  76.                         this.WorkflowPackage,
  77.                         this.WorkflowName,
  78.                         this.WorkflowVersion);
  79.                 }
  80.                 return (OThinker.H3.WorkflowTemplate.WorkflowTemplate)this.Session[sessionName];
  81.             }
  82.         }
  83.         private string DestActivityName
  84.         {
  85.             get
  86.             {
  87.                 return System.Web.HttpUtility.UrlDecode(this.Request.QueryString[Param_DestActivityName]);
  88.             }
  89.         }
  90.         // 目标任务
  91.         private OThinker.H3.WorkflowTemplate.ActivityTemplate DestActivity
  92.         {
  93.             get
  94.             {
  95.                 if (this.WorkflowTemplate == null)
  96.                 {
  97.                     return null;
  98.                 }
  99.                 else
  100.                 {
  101.                     OThinker.H3.WorkflowTemplate.ActivityTemplate activity = this.WorkflowTemplate.GetActivity(this.DestActivityName);
  102.                     return activity;
  103.                 }
  104.             }
  105.         }
  106.         #endregion
  107.         #region 流程数据集
  108.         private string[] GetOptionalParticipants()
  109.         {
  110.             // 获得后续的参与者
  111.             string originator = OThinker.H3.Server.Engine.InstanceManager.GetInstanceOriginator(this.InstanceId);
  112.             // 准备数据集
  113.             H3.Data.InstanceData data = new OThinker.H3.Data.InstanceData(
  114.                     OThinker.H3.Server.Engine.InstanceDataManager,
  115.                     OThinker.H3.Server.Engine.WorkflowManager,
  116.                     OThinker.H3.Server.Engine.InstanceManager,
  117.                     this.InstanceId,
  118.                     OThinker.H3.Instance.Token.UnspecifiedID, 
  119.                     this.WorkflowTemplate,
  120.                     null,
  121.                     this.UserValidator.UserID,
  122.                     null);
  123.             data.UseCache = true;
  124.             data.AutoLookupParent = false;
  125.             return this.DestActivity.ParseParticipants(
  126.                         OThinker.H3.Server.Engine.Organization,
  127.                         this.InstanceId,
  128.                         OThinker.H3.Instance.Token.UnspecifiedID, 
  129.                         OThinker.H3.Server.Engine.InstanceManager,
  130.                         OThinker.H3.Server.Engine.TokenPool, 
  131.                         OThinker.H3.Server.Engine.WorkItemManager,
  132.                         data,
  133.                         this.UserValidator.UserID);
  134.         }
  135.         #endregion
  136.         protected void Page_Load(object sender, System.EventArgs e)
  137.         {
  138.             if (!this.IsPostBack)
  139.             {
  140.                 if (this.DestActivity == null)
  141.                 {
  142.                     this.btnSubmit_Click(null, null);
  143.                 }
  144.                 else if (this.DestActivity.ParticipateType == OThinker.H3.WorkflowTemplate.ActivityParticipateType.NoneParticipant)
  145.                 {
  146.                     this.btnSubmit_Click(null, null);
  147.                 }
  148.                 else if (this.DestActivity.ParticipateType == OThinker.H3.WorkflowTemplate.ActivityParticipateType.SingleParticipant)
  149.                 {
  150.                     string[] participants = this.GetOptionalParticipants();
  151.                     if (participants == null || participants.Length == 0)
  152.                     {
  153.                         this.NotifyMessage("该任务设计有问题,没有可选择的处理人");
  154.                     }
  155.                     else
  156.                     {
  157.                         int optionalReceiverCount = 0;
  158.                         foreach (string receiver in participants)
  159.                         {
  160.                             if (receiver != null && receiver != "")
  161.                             {
  162.                                 string receiverName = OThinker.H3.Server.Engine.Organization.GetFullName(receiver);
  163.                                 this.ReceiverSelector.Items.Add(receiverName);
  164.                                 optionalReceiverCount++;
  165.                             }
  166.                         }
  167.                         this.ReceiverSelector.SelectedIndex = 0;
  168.                         this.ReceiverSelector.Visible = true;
  169.                         if (optionalReceiverCount == 1)
  170.                         {
  171.                             this.btnSubmit_Click(null, null);
  172.                         }
  173.                     }
  174.                 }
  175.                 else if (this.DestActivity.ParticipateType == OThinker.H3.WorkflowTemplate.ActivityParticipateType.MultiParticipants)
  176.                 {
  177.                     string[] participants = this.GetOptionalParticipants();
  178.                     if (participants == null || participants.Length == 0)
  179.                     {
  180.                         this.NotifyMessage("该任务设计有问题,没有可选择的处理人");
  181.                     }
  182.                     else
  183.                     {
  184.                         int optionalReceiverCount = 0;
  185.                         foreach (string receiver in participants)
  186.                         {
  187.                             if (receiver != null && receiver != "")
  188.                             {
  189.                                 string receiverName = OThinker.H3.Server.Engine.Organization.GetFullName(receiver);
  190.                                 this.ReceiversSelector.Items.Add(receiverName);
  191.                                 optionalReceiverCount++;
  192.                             }
  193.                         }
  194.                         this.ReceiversSelector.SelectedIndex = 0;
  195.                         this.ReceiversSelector.Visible = true;
  196.                         if (optionalReceiverCount == 1)
  197.                         {
  198.                             this.btnSubmit_Click(null, null);
  199.                         }
  200.                     }
  201.                 }
  202.                 else if (this.DestActivity.ParticipateType == OThinker.H3.WorkflowTemplate.ActivityParticipateType.AllParticipants)
  203.                 {
  204.                     this.btnSubmit_Click(null, null);
  205.                 }
  206.                 else
  207.                 {
  208.                     throw new NotImplementedException();
  209.                 }
  210.             }
  211.         }
  212.         #region Web Form Designer generated code
  213.         override protected void OnInit(EventArgs e)
  214.         {
  215.             //
  216.             // CODEGEN: This call is required by the ASP.NET Web Form Designer.
  217.             //
  218.             InitializeComponent();
  219.             base.OnInit(e);
  220.         }
  221.         /// <summary>
  222.         /// Required method for Designer support - do not modify
  223.         /// the contents of this method with the code editor.
  224.         /// </summary>
  225.         private void InitializeComponent()
  226.         {
  227.         }
  228.         #endregion
  229.         protected void btnSubmit_Click(object sender, System.EventArgs e)
  230.         {
  231.             // 触发后面的Activity
  232.             string[] participants = this.GetSelectedParticipants();
  233.             // 检查是否有选中参与者
  234.             if (this.ReceiversSelector != null && this.ReceiversSelector.Items.Count > 1)
  235.             {
  236.                 if (participants == null || participants.Length == 0)
  237.                 {
  238.                     this.NotifyMessage("请选择参与者");
  239.                 }
  240.             }
  241.             // 准备触发后面Activity的消息
  242.             OThinker.H3.Messages.ActivateActivityMessage activateMessage
  243.                 = new OThinker.H3.Messages.ActivateActivityMessage(
  244.                 OThinker.H3.Messages.MessageEmergencyType.Normal,
  245.                 this.InstanceId,
  246.                 this.DestActivity.Name,
  247.                 OThinker.H3.Instance.Token.UnspecifiedID,
  248.                 participants,
  249.                 null,
  250.                 false,
  251.                 Messages.ActivateType.Normal,
  252.                 null);
  253.             OThinker.H3.Server.Engine.InstanceManager.SendMessage(activateMessage);
  254.             this.NotifyMessage("活动已经激活");
  255.         }
  256.         private string[] GetSelectedParticipants()
  257.         {
  258.             // 参与者
  259.             string[] participants;
  260.             if (this.DestActivity.ParticipateType == OThinker.H3.WorkflowTemplate.ActivityParticipateType.NoneParticipant)
  261.             {
  262.                 // 参与人为空
  263.                 participants = new string[0];
  264.             }
  265.             else if (this.DestActivity.ParticipateType == OThinker.H3.WorkflowTemplate.ActivityParticipateType.SingleParticipant)
  266.             {
  267.                 // 选中的参与人
  268.                 string receiver = this.ReceiverSelector.SelectedValue;
  269.                 int startIndex = receiver.LastIndexOf("[");
  270.                 int endIndex = receiver.LastIndexOf("]");
  271.                 string alias = receiver.Substring(startIndex + 1, endIndex - startIndex - 1);
  272.                 string userId = OThinker.H3.Server.Engine.Organization.GetUserIDByAlias(alias);
  273.                 participants = new string[] { userId };
  274.             }
  275.             else if (this.DestActivity.ParticipateType == OThinker.H3.WorkflowTemplate.ActivityParticipateType.MultiParticipants)
  276.             {
  277.                 ArrayList selectedReceivers = new ArrayList();
  278.                 foreach (System.Web.UI.WebControls.ListItem item in this.ReceiversSelector.Items)
  279.                 {
  280.                     if (item.Selected)
  281.                     {
  282.                         string receiver = item.Text;
  283.                         int startIndex = receiver.LastIndexOf("[");
  284.                         int endIndex = receiver.LastIndexOf("]");
  285.                         string principalName = receiver.Substring(startIndex + 1, endIndex - startIndex - 1);
  286.                         selectedReceivers.Add(principalName);
  287.                     }
  288.                 }
  289.                 // 获得可选择的接收者
  290.                 string[] receivers = new string[selectedReceivers.Count];
  291.                 for (int count = 0; count < receivers.Length; count++)
  292.                 {
  293.                     string userId = OThinker.H3.Server.Engine.Organization.GetUserIDByAlias((string)selectedReceivers[count]);
  294.                     receivers[count] = userId;
  295.                 }
  296.                 // 选中的参与人
  297.                 participants = receivers;
  298.             }
  299.             else if (this.DestActivity.ParticipateType == OThinker.H3.WorkflowTemplate.ActivityParticipateType.AllParticipants)
  300.             {
  301.                 participants = this.GetOptionalParticipants();
  302.             }
  303.             else
  304.             {
  305.                 throw new NotImplementedException();
  306.             }
  307.             return participants;
  308.         }
  309.     }
  310. }