FinishWorkItem.aspx.cs
资源名称:H3_OA.rar [点击查看]
上传用户:li2971742
上传日期:2021-11-18
资源大小:39096k
文件大小:16k
源码类别:
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 FinishWorkItem : PortalPage
- {
- #region 获得参数信息
- // 当前的任务
- private OThinker.H3.WorkItem.WorkItem WorkItem
- {
- get
- {
- string itemId = this.Request.QueryString[Param_WorkItemID];
- string sessionName = OThinker.H3.WorkSheet.Sessions.GetWorkItem(itemId);
- if (this.Session[sessionName] == null)
- {
- this.Session[sessionName] = OThinker.H3.Server.Engine.WorkItemManager.GetWorkItem(itemId);
- }
- return (OThinker.H3.WorkItem.WorkItem)this.Session[sessionName];
- }
- }
- private OThinker.H3.WorkflowTemplate.WorkflowTemplate WorkflowTemplate
- {
- get
- {
- string sessionName = OThinker.H3.WorkSheet.Sessions.GetWorkflow(
- this.WorkItem.WorkflowPackage,
- this.WorkItem.WorkflowName,
- this.WorkItem.WorkflowVersion);
- OThinker.H3.WorkflowTemplate.WorkflowTemplate process;
- if (this.Session[sessionName] == null)
- {
- this.Session[sessionName] = OThinker.H3.Server.Engine.WorkflowManager.GetWorkflow(
- this.WorkItem.WorkflowPackage,
- this.WorkItem.WorkflowName,
- this.WorkItem.WorkflowVersion);
- }
- return (OThinker.H3.WorkflowTemplate.WorkflowTemplate)this.Session[sessionName];
- }
- }
- // 目标任务
- private OThinker.H3.WorkflowTemplate.ActivityTemplate DestActivity
- {
- get
- {
- if (this.WorkflowTemplate == null)
- {
- return null;
- }
- else
- {
- string destActivityName = System.Web.HttpUtility.UrlDecode(this.Request.QueryString[Param_DestActivityName]);
- OThinker.H3.WorkflowTemplate.ActivityTemplate task = this.WorkflowTemplate.GetActivity(destActivityName);
- return task;
- }
- }
- }
- private OThinker.Data.BoolMatchValue Approval
- {
- get
- {
- string strApproval = this.Request.QueryString[Param_Approval];
- if (strApproval == null || strApproval == "")
- {
- return OThinker.Data.BoolMatchValue.Unspecified;
- }
- else
- {
- try
- {
- return (OThinker.Data.BoolMatchValue)Enum.Parse(typeof(OThinker.Data.BoolMatchValue), strApproval);
- }
- catch
- {
- return OThinker.Data.BoolMatchValue.Unspecified;
- }
- }
- }
- }
- private string Comment
- {
- get
- {
- return HttpUtility.UrlDecode(this.Request.QueryString[Param_Comment]);
- }
- }
- private string ParticipateGroup
- {
- get
- {
- return HttpUtility.UrlDecode(this.Request.QueryString[Param_ParticipateGroup]);
- }
- }
- #endregion
- #region 流程数据集
- private string[] GetOptionalParticipants()
- {
- // 获得后续的参与者
- string originator = OThinker.H3.Server.Engine.InstanceManager.GetInstanceOriginator(this.WorkItem.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.WorkItem.InstanceId,
- this.WorkItem.TokenId,
- OThinker.H3.Server.Engine.WorkflowManager.GetWorkflow(
- this.WorkItem.WorkflowPackage,
- this.WorkItem.WorkflowName,
- this.WorkItem.WorkflowVersion),
- this.WorkItem.ActivityName,
- this.UserValidator.UserID,
- null);
- data.UseCache = true;
- data.AutoLookupParent = false;
- return this.DestActivity.ParseParticipants(
- OThinker.H3.Server.Engine.Organization,
- this.WorkItem.InstanceId,
- this.WorkItem.TokenId,
- 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.WorkItem.ItemType == OThinker.H3.WorkItem.WorkItemType.Consultancy)
- {
- this._FinishWorkItem();
- // 转到另外一个页面上
- this.NotifyMessage("任务已完成!");
- }
- else 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)
- {
- if (this.DestActivity == null)
- {
- this._FinishWorkItem();
- // 采用自动路由的方式
- this.AutoRoute();
- }
- else
- {
- // 触发后面的Activity
- string[] participants = this.GetSelectedParticipants();
- // 检查是否有选中参与者
- if (this.ReceiversSelector != null && this.ReceiversSelector.Items.Count > 1)
- {
- if (participants == null || participants.Length == 0)
- {
- this.NotifyMessage("请选择参与者");
- }
- }
- this._FinishWorkItem();
- // 准备触发后面Activity的消息
- OThinker.H3.Messages.ActivateActivityMessage activateMessage
- = new OThinker.H3.Messages.ActivateActivityMessage(
- OThinker.H3.Messages.MessageEmergencyType.Normal,
- this.WorkItem.InstanceId,
- this.DestActivity.Name,
- OThinker.H3.Instance.Token.UnspecifiedID,
- participants,
- new long[] { this.WorkItem.TokenId },
- false,
- Messages.ActivateType.Normal,
- null);
- // 通知该Activity已经完成
- OThinker.H3.Messages.AsyncEndMessage endMessage =
- new OThinker.H3.Messages.AsyncEndMessage(
- OThinker.H3.Messages.MessageEmergencyType.Normal,
- this.WorkItem.InstanceId,
- this.WorkItem.ActivityName,
- this.WorkItem.ReplyID,
- false,
- this.UserValidator.UserID,
- this.Approval,
- activateMessage,
- null);
- OThinker.H3.Server.Engine.InstanceManager.SendMessage(endMessage);
- }
- this.NotifyMessage("任务已完成");
- }
- private void _FinishWorkItem()
- {
- OThinker.H3.Server.Engine.WorkItemManager.FinishWorkItem(this.WorkItem.WorkItemID, this.UserValidator.UserID, this.ParticipateGroup, this.Approval, this.Comment);
- // 设置Session的工作项的状态
- this.WorkItem.State = OThinker.H3.WorkItem.WorkItemState.Finished;
- // 设置操作描述
- string description = System.Web.HttpUtility.UrlDecode(this.Request.QueryString[Param_Description]);
- OThinker.H3.Server.Engine.TokenPool.AppendDescription(this.WorkItem.InstanceId, this.WorkItem.TokenId, description);
- }
- private void AutoRoute()
- {
- // 需要通知实例事件管理器结束事件
- Messages.AsyncEndMessage endMessage = new OThinker.H3.Messages.AsyncEndMessage(
- Messages.MessageEmergencyType.Normal,
- this.WorkItem.InstanceId,
- this.WorkItem.ActivityName,
- this.WorkItem.ReplyID,
- true,
- this.UserValidator.UserID,
- this.Approval,
- null,
- null);
- OThinker.H3.Server.Engine.InstanceManager.SendMessage(endMessage);
- }
- 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;
- }
- }
- }