ActivateActivity.aspx.cs
资源名称:H3_OA.rar [点击查看]
上传用户:li2971742
上传日期:2021-11-18
资源大小:39096k
文件大小:13k
源码类别:
OA系统
开发平台:
C#
- using System;
- using System.Collections;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Web;
- using System.Web.SessionState;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Web.UI.HtmlControls;
- namespace OThinker.H3.Portal
- {
- /// <summary>
- /// 完成一个任务同时跳转到另外一个任务上
- /// </summary>
- public partial class ActivateActivity : PortalPage
- {
- #region 获得参数信息
- // 当前的任务
- private string InstanceId
- {
- get
- {
- return this.Request.QueryString[Param_InstanceId];
- }
- }
- public OThinker.H3.Instance.InstanceContext InstanceContext
- {
- get
- {
- string sessionName = OThinker.H3.WorkSheet.Sessions.GetInstanceContext(this.InstanceId);
- if (this.Session[sessionName] == null)
- {
- this.Session[sessionName] = OThinker.H3.Server.Engine.InstanceManager.GetInstanceContext(this.InstanceId);
- }
- return (OThinker.H3.Instance.InstanceContext)this.Session[sessionName];
- }
- set
- {
- string sessionName = OThinker.H3.WorkSheet.Sessions.GetInstanceContext(this.InstanceId);
- this.Session[sessionName] = value;
- }
- }
- private string WorkflowPackage
- {
- get
- {
- return this.InstanceContext.WorkflowPackage;
- }
- }
- private string WorkflowName
- {
- get
- {
- return this.InstanceContext.WorkflowName;
- }
- }
- private int WorkflowVersion
- {
- get
- {
- return this.InstanceContext.WorkflowVersion;
- }
- }
- private OThinker.H3.WorkflowTemplate.WorkflowTemplate WorkflowTemplate
- {
- get
- {
- string sessionName = OThinker.H3.WorkSheet.Sessions.GetWorkflow(
- this.WorkflowPackage,
- this.WorkflowName,
- this.WorkflowVersion);
- if (this.Session[sessionName] == null)
- {
- this.Session[sessionName] = OThinker.H3.Server.Engine.WorkflowManager.GetWorkflow(
- this.WorkflowPackage,
- this.WorkflowName,
- this.WorkflowVersion);
- }
- return (OThinker.H3.WorkflowTemplate.WorkflowTemplate)this.Session[sessionName];
- }
- }
- private string DestActivityName
- {
- get
- {
- return System.Web.HttpUtility.UrlDecode(this.Request.QueryString[Param_DestActivityName]);
- }
- }
- // 目标任务
- private OThinker.H3.WorkflowTemplate.ActivityTemplate DestActivity
- {
- get
- {
- if (this.WorkflowTemplate == null)
- {
- return null;
- }
- else
- {
- OThinker.H3.WorkflowTemplate.ActivityTemplate activity = this.WorkflowTemplate.GetActivity(this.DestActivityName);
- return activity;
- }
- }
- }
- #endregion
- #region 流程数据集
- private string[] GetOptionalParticipants()
- {
- // 获得后续的参与者
- string originator = OThinker.H3.Server.Engine.InstanceManager.GetInstanceOriginator(this.InstanceId);
- // 准备数据集
- H3.Data.InstanceData data = new OThinker.H3.Data.InstanceData(
- OThinker.H3.Server.Engine.InstanceDataManager,
- OThinker.H3.Server.Engine.WorkflowManager,
- OThinker.H3.Server.Engine.InstanceManager,
- this.InstanceId,
- OThinker.H3.Instance.Token.UnspecifiedID,
- this.WorkflowTemplate,
- null,
- this.UserValidator.UserID,
- null);
- data.UseCache = true;
- data.AutoLookupParent = false;
- return this.DestActivity.ParseParticipants(
- OThinker.H3.Server.Engine.Organization,
- this.InstanceId,
- OThinker.H3.Instance.Token.UnspecifiedID,
- OThinker.H3.Server.Engine.InstanceManager,
- OThinker.H3.Server.Engine.TokenPool,
- OThinker.H3.Server.Engine.WorkItemManager,
- data,
- this.UserValidator.UserID);
- }
- #endregion
- protected void Page_Load(object sender, System.EventArgs e)
- {
- if (!this.IsPostBack)
- {
- if (this.DestActivity == null)
- {
- this.btnSubmit_Click(null, null);
- }
- else if (this.DestActivity.ParticipateType == OThinker.H3.WorkflowTemplate.ActivityParticipateType.NoneParticipant)
- {
- this.btnSubmit_Click(null, null);
- }
- else if (this.DestActivity.ParticipateType == OThinker.H3.WorkflowTemplate.ActivityParticipateType.SingleParticipant)
- {
- string[] participants = this.GetOptionalParticipants();
- if (participants == null || participants.Length == 0)
- {
- this.NotifyMessage("该任务设计有问题,没有可选择的处理人");
- }
- else
- {
- int optionalReceiverCount = 0;
- foreach (string receiver in participants)
- {
- if (receiver != null && receiver != "")
- {
- string receiverName = OThinker.H3.Server.Engine.Organization.GetFullName(receiver);
- this.ReceiverSelector.Items.Add(receiverName);
- optionalReceiverCount++;
- }
- }
- this.ReceiverSelector.SelectedIndex = 0;
- this.ReceiverSelector.Visible = true;
- if (optionalReceiverCount == 1)
- {
- this.btnSubmit_Click(null, null);
- }
- }
- }
- else if (this.DestActivity.ParticipateType == OThinker.H3.WorkflowTemplate.ActivityParticipateType.MultiParticipants)
- {
- string[] participants = this.GetOptionalParticipants();
- if (participants == null || participants.Length == 0)
- {
- this.NotifyMessage("该任务设计有问题,没有可选择的处理人");
- }
- else
- {
- int optionalReceiverCount = 0;
- foreach (string receiver in participants)
- {
- if (receiver != null && receiver != "")
- {
- string receiverName = OThinker.H3.Server.Engine.Organization.GetFullName(receiver);
- this.ReceiversSelector.Items.Add(receiverName);
- optionalReceiverCount++;
- }
- }
- this.ReceiversSelector.SelectedIndex = 0;
- this.ReceiversSelector.Visible = true;
- if (optionalReceiverCount == 1)
- {
- this.btnSubmit_Click(null, null);
- }
- }
- }
- else if (this.DestActivity.ParticipateType == OThinker.H3.WorkflowTemplate.ActivityParticipateType.AllParticipants)
- {
- this.btnSubmit_Click(null, null);
- }
- else
- {
- throw new NotImplementedException();
- }
- }
- }
- #region Web Form Designer generated code
- override protected void OnInit(EventArgs e)
- {
- //
- // CODEGEN: This call is required by the ASP.NET Web Form Designer.
- //
- InitializeComponent();
- base.OnInit(e);
- }
- /// <summary>
- /// Required method for Designer support - do not modify
- /// the contents of this method with the code editor.
- /// </summary>
- private void InitializeComponent()
- {
- }
- #endregion
- protected void btnSubmit_Click(object sender, System.EventArgs e)
- {
- // 触发后面的Activity
- string[] participants = this.GetSelectedParticipants();
- // 检查是否有选中参与者
- if (this.ReceiversSelector != null && this.ReceiversSelector.Items.Count > 1)
- {
- if (participants == null || participants.Length == 0)
- {
- this.NotifyMessage("请选择参与者");
- }
- }
- // 准备触发后面Activity的消息
- OThinker.H3.Messages.ActivateActivityMessage activateMessage
- = new OThinker.H3.Messages.ActivateActivityMessage(
- OThinker.H3.Messages.MessageEmergencyType.Normal,
- this.InstanceId,
- this.DestActivity.Name,
- OThinker.H3.Instance.Token.UnspecifiedID,
- participants,
- null,
- false,
- Messages.ActivateType.Normal,
- null);
- OThinker.H3.Server.Engine.InstanceManager.SendMessage(activateMessage);
- this.NotifyMessage("活动已经激活");
- }
- private string[] GetSelectedParticipants()
- {
- // 参与者
- string[] participants;
- if (this.DestActivity.ParticipateType == OThinker.H3.WorkflowTemplate.ActivityParticipateType.NoneParticipant)
- {
- // 参与人为空
- participants = new string[0];
- }
- else if (this.DestActivity.ParticipateType == OThinker.H3.WorkflowTemplate.ActivityParticipateType.SingleParticipant)
- {
- // 选中的参与人
- string receiver = this.ReceiverSelector.SelectedValue;
- int startIndex = receiver.LastIndexOf("[");
- int endIndex = receiver.LastIndexOf("]");
- string alias = receiver.Substring(startIndex + 1, endIndex - startIndex - 1);
- string userId = OThinker.H3.Server.Engine.Organization.GetUserIDByAlias(alias);
- participants = new string[] { userId };
- }
- else if (this.DestActivity.ParticipateType == OThinker.H3.WorkflowTemplate.ActivityParticipateType.MultiParticipants)
- {
- ArrayList selectedReceivers = new ArrayList();
- foreach (System.Web.UI.WebControls.ListItem item in this.ReceiversSelector.Items)
- {
- if (item.Selected)
- {
- string receiver = item.Text;
- int startIndex = receiver.LastIndexOf("[");
- int endIndex = receiver.LastIndexOf("]");
- string principalName = receiver.Substring(startIndex + 1, endIndex - startIndex - 1);
- selectedReceivers.Add(principalName);
- }
- }
- // 获得可选择的接收者
- string[] receivers = new string[selectedReceivers.Count];
- for (int count = 0; count < receivers.Length; count++)
- {
- string userId = OThinker.H3.Server.Engine.Organization.GetUserIDByAlias((string)selectedReceivers[count]);
- receivers[count] = userId;
- }
- // 选中的参与人
- participants = receivers;
- }
- else if (this.DestActivity.ParticipateType == OThinker.H3.WorkflowTemplate.ActivityParticipateType.AllParticipants)
- {
- participants = this.GetOptionalParticipants();
- }
- else
- {
- throw new NotImplementedException();
- }
- return participants;
- }
- }
- }