SheetActionPane.cs
资源名称:H3_OA.rar [点击查看]
上传用户:li2971742
上传日期:2021-11-18
资源大小:39096k
文件大小:22k
源码类别:
OA系统
开发平台:
C#
- using System;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.ComponentModel;
- namespace OThinker.H3.WorkSheet
- {
- /// <summary>
- /// Summary description for SheetWorkItemActionPane.
- /// </summary>
- [DefaultProperty("Text"), ToolboxData("<{0}:SheetActionPane runat=server></{0}:SheetActionPane>")]
- public class SheetActionPane : System.Web.UI.WebControls.WebControl
- {
- private SheetEnviroment _Enviroment;
- /// <summary>
- /// 环境
- /// </summary>
- public SheetEnviroment Enviroment
- {
- get
- {
- return this._Enviroment;
- }
- set
- {
- this._Enviroment = value;
- if (this._Enviroment == null)
- {
- }
- else if (this._Enviroment.IsWorkMode || this._Enviroment.IsOriginateMode)
- {
- // 操作面板
- this.InitAsWorkMode();
- }
- else if (this._Enviroment.IsRetrieveMode)
- {
- // 操作面板
- this.InitAsRetreiveMode();
- }
- }
- }
- #region 按钮
- private DropDownList _GroupSelector = new DropDownList();
- public DropDownList GroupSelector
- {
- get
- {
- return this._GroupSelector;
- }
- }
- // 保存按钮
- protected LinkButton _Save = new LinkButton();
- public LinkButton Save
- {
- get
- {
- return this._Save;
- }
- }
- // 查看状态
- protected HyperLink _ViewInstanceState = new HyperLink();
- public HyperLink ViewInstanceState
- {
- get
- {
- return this._ViewInstanceState;
- }
- }
- // 征询意见
- protected HyperLink _Consult = new HyperLink();
- public HyperLink Consult
- {
- get
- {
- return this._Consult;
- }
- }
- // 转发
- protected HyperLink _Forward = new HyperLink();
- public HyperLink Forward
- {
- get
- {
- return this._Forward;
- }
- }
- // 取回
- protected HyperLink _Retrieve = new HyperLink();
- public HyperLink Retrieve
- {
- get
- {
- return this._Retrieve;
- }
- }
- // 打回
- protected LinkButton _Rollback = new LinkButton();
- public LinkButton Rollback
- {
- get
- {
- return this._Rollback;
- }
- }
- // 跳转按钮
- protected LinkButton _Jump = new LinkButton();
- public LinkButton Jump
- {
- get
- {
- return this._Jump;
- }
- }
- // 可选择的任务
- protected DropDownList _JumpDests = new DropDownList();
- public DropDownList JumpDests
- {
- get
- {
- return this._JumpDests;
- }
- }
- // 取消
- protected LinkButton _Cancel = new LinkButton();
- public LinkButton Cancel
- {
- get
- {
- return this._Cancel;
- }
- }
- // 挂起
- protected LinkButton _Suspend = new LinkButton();
- public LinkButton Suspend
- {
- get
- {
- return this._Suspend;
- }
- }
- #endregion
- public event SheetSubmitEventHandler Submit;
- public SheetActionPane()
- {
- }
- public void InitAsRetreiveMode()
- {
- this.Retrieve.Text = "取回";
- this.Retrieve.NavigateUrl = this.Enviroment.GetRetrieveUrl(this.Enviroment.WorkItemID);
- this.Controls.Add(this.Retrieve);
- }
- public void InitAsWorkMode()
- {
- // 保存按钮
- if (this.Enviroment.SheetMode == SheetMode.Work || this.Enviroment.SheetMode == SheetMode.Originate)
- {
- this.AddSplit();
- this.Save.Text = "保存";
- this.Save.Click += new EventHandler(this.Save_Click);
- this.Controls.Add(this.Save);
- }
- // 查看流程状态
- if (
- this.Enviroment.SheetMode == SheetMode.Work &&
- this.Enviroment.WorkItem.PermittedActions.ViewInstanceState)
- {
- this.AddSplit();
- this.Controls.Add(this.ViewInstanceState);
- this.ViewInstanceState.Text = "流程状态";
- this.ViewInstanceState.Target = "_blank";
- this.ViewInstanceState.NavigateUrl = this.Enviroment.GetViewInstanceStateUrl(this.Enviroment.InstanceId);
- }
- // 征询意见
- if (
- this.Enviroment.SheetMode == SheetMode.Work &&
- this.Enviroment.WorkItem.ItemType == OThinker.H3.WorkItem.WorkItemType.Normal &&
- this.Enviroment.WorkItem.PermittedActions.Consult)
- {
- this.AddSplit();
- this.Controls.Add(this.Consult);
- this.Consult.Text = "征询意见";
- this.Consult.NavigateUrl = this.Enviroment.GetConsultUrl(this.Enviroment.WorkItemID);
- }
- // 转发
- if (
- this.Enviroment.SheetMode == SheetMode.Work &&
- this.Enviroment.WorkItem.ItemType == OThinker.H3.WorkItem.WorkItemType.Normal &&
- this.Enviroment.WorkItem.PermittedActions.Forward)
- {
- this.AddSplit();
- this.Controls.Add(this.Forward);
- this.Forward.Text = "转发";
- this.Forward.NavigateUrl = this.Enviroment.GetForwardUrl(this.Enviroment.WorkItemID);
- }
- // 反向流转
- if (
- this.Enviroment.SheetMode == SheetMode.Work &&
- this.Enviroment.WorkItem.ItemType == OThinker.H3.WorkItem.WorkItemType.Normal &&
- this.Enviroment.WorkItem.PermittedActions.Backward)
- {
- // 允许回退,所以要获得前驱
- OThinker.H3.WorkflowTemplate.ActivityTemplate[] preActivitys = this.Enviroment.Workflow.GetActivityPreActivity(this.Enviroment.ActivityName);
- if (preActivitys != null)
- {
- foreach (OThinker.H3.WorkflowTemplate.ActivityTemplate preActivity in preActivitys)
- {
- this.AddSplit();
- this.AddText("↑");
- LinkButton backward = new LinkButton();
- this.Controls.Add(backward);
- backward.Text = preActivity.Name;
- backward.Click += new EventHandler(this.JmpButton_Click);
- }
- }
- }
- // 提交
- OThinker.H3.WorkflowTemplate.ActivityTemplate[] postActivitys = this.Enviroment.Workflow.GetActivityPostActivitys(this.Enviroment.ActivityName);
- if (
- postActivitys == null || postActivitys.Length == 0 ||
- (this.Enviroment.SheetMode == SheetMode.Originate && !this.Enviroment.Workflow.GetActivity(this.Enviroment.ActivityName).PermittedActions.Choose) ||
- (this.Enviroment.SheetMode == SheetMode.Work &&
- (this.Enviroment.WorkItem.ItemType == OThinker.H3.WorkItem.WorkItemType.Consultancy ||
- !this.Enviroment.WorkItem.PermittedActions.Choose)))
- {
- this.AddSplit();
- this.AddText("↓");
- // 只有零个或一个后继
- LinkButton submit = new LinkButton();
- submit.Text = "提交";
- this.Controls.Add(submit);
- submit.Click += new EventHandler(this.Submit_Click);
- }
- else
- {
- foreach (OThinker.H3.WorkflowTemplate.ActivityTemplate postActivity in postActivitys)
- {
- this.AddSplit();
- this.AddText("↓");
- LinkButton post = new LinkButton();
- this.Controls.Add(post);
- post.Text = postActivity.Name;
- post.Click += new EventHandler(this.JmpButton_Click);
- }
- }
- // 打回
- if (
- this.Enviroment.SheetMode == SheetMode.Work &&
- this.Enviroment.WorkItem.ItemType == OThinker.H3.WorkItem.WorkItemType.Normal &&
- this.Enviroment.WorkItem.PermittedActions.Rollback)
- {
- this.AddSplit();
- this.AddText("↑");
- this.Rollback.Text = "打回";
- this.Rollback.Click += new EventHandler(this.Rollback_Click);
- this.Controls.Add(this.Rollback);
- }
- // 跳转
- if (
- (
- this.Enviroment.SheetMode == SheetMode.Originate &&
- this.Enviroment.Workflow.GetActivity(this.Enviroment.ActivityName).PermittedActions.Jump) ||
- (
- this.Enviroment.SheetMode == SheetMode.Work &&
- this.Enviroment.WorkItem.ItemType == OThinker.H3.WorkItem.WorkItemType.Normal &&
- this.Enviroment.WorkItem.PermittedActions.Jump))
- {
- this.AddSplit();
- foreach (OThinker.H3.WorkflowTemplate.ActivityTemplate processActivity in this.Enviroment.Workflow.Activities)
- {
- if (processActivity.Name != this.Enviroment.ActivityName)
- {
- this.JumpDests.Items.Add(processActivity.Name);
- }
- }
- this.Controls.Add(this.JumpDests);
- this.Jump.Text = "跳转";
- this.Jump.Click += new EventHandler(Jump_Click);
- this.Controls.Add(this.Jump);
- }
- // 取消/终止
- if (
- this.Enviroment.SheetMode == SheetMode.Work &&
- this.Enviroment.WorkItem.ItemType == OThinker.H3.WorkItem.WorkItemType.Normal &&
- (
- this.Enviroment.WorkItem.PermittedActions.Terminate ||
- this.Enviroment.WorkItem.TokenId == Instance.Token.InitialTokenId))
- {
- this.AddSplit();
- this.Cancel.Text = this.Enviroment.WorkItem.TokenId == Instance.Token.InitialTokenId ? "取消" : "终止";
- this.Cancel.Click += new EventHandler(this.Cancel_Click);
- this.Controls.Add(this.Cancel);
- }
- // 挂起和反挂起
- if (
- this.Enviroment.SheetMode == SheetMode.Work &&
- this.Enviroment.WorkItem.ItemType == OThinker.H3.WorkItem.WorkItemType.Normal &&
- this.Enviroment.WorkItem.PermittedActions.Suspend)
- {
- this.AddSplit();
- string instanceId = this.Enviroment.WorkItem.InstanceId;
- OThinker.H3.Instance.InstanceContext context = OThinker.H3.Server.Engine.InstanceManager.GetInstanceContext(instanceId);
- if (context != null)
- {
- bool suspended = context.Suspended;
- this.Suspend.Text = suspended ? "继续" : "挂起";
- this.Suspend.Click += new EventHandler(this.Suspend_Click);
- this.Controls.Add(this.Suspend);
- }
- }
- // 操作的身份
- if (this.Enviroment.WorkflowActivity.RequireGroup)
- {
- string[] groups = null;
- if (this.Enviroment.SheetMode == SheetMode.Originate)
- {
- groups = this.Enviroment.UserValidator.Groups;
- }
- else if (
- this.Enviroment.SheetMode == SheetMode.Work &&
- this.Enviroment.WorkItem.ItemType == OThinker.H3.WorkItem.WorkItemType.Normal)
- {
- // 获得普通型的组
- groups =
- this.Enviroment.WorkItem == null ?
- this.Enviroment.UserValidator.NormalGroups :
- this.Enviroment.Organization.GetParentGroups(this.Enviroment.WorkItem.Participant, OThinker.Organization.VisibleType.Normal);
- }
- if (groups != null && groups.Length != 0)
- {
- foreach (string group in groups)
- {
- string groupName = this.Enviroment.Organization.GetName(group);
- this.GroupSelector.Items.Add(new ListItem(groupName, group));
- }
- this.GroupSelector.SelectedIndex = 0;
- }
- else
- {
- this.GroupSelector.Visible = false;
- }
- if (this.GroupSelector.Visible)
- {
- this.AddSplit();
- }
- this.Controls.Add(this.GroupSelector);
- }
- }
- private void Rollback_Click(object sender, EventArgs e)
- {
- // 保存表单
- if (this.Submit != null)
- {
- this.Submit(this, new SheetSubmitEventArgs(false, null, null));
- }
- // 检查是否允许打回
- H3.Instance.IToken token = this.Enviroment.TokenPool.GetToken(this.Enviroment.WorkItem.InstanceId, this.Enviroment.WorkItem.TokenId);
- bool rollbackable = true;
- // 如果是回滚,那么需要检查是否允许回滚
- if (token == null || token.PreTokens == null)
- {
- rollbackable = false;
- }
- else
- {
- foreach (long preTokenId in token.PreTokens)
- {
- long[] branches = this.Enviroment.TokenPool.QueryPostToken(this.Enviroment.WorkItem.InstanceId, preTokenId);
- if (branches != null && branches.Length > 1)
- {
- rollbackable = false;
- break;
- }
- }
- }
- // 发送打回消息
- if (rollbackable == false)
- {
- this.Enviroment.NotifyMessage("不具备打回的条件");
- }
- else
- {
- // 完成该任务
- OThinker.H3.Server.Engine.WorkItemManager.FinishWorkItem(this.Enviroment.WorkItem.WorkItemID, this.Enviroment.Participant, this.GroupSelector.SelectedValue, OThinker.Data.BoolMatchValue.Unspecified, null);
- // 标记为打回
- OThinker.H3.Server.Engine.TokenPool.AppendDescription(this.Enviroment.WorkItem.InstanceId, this.Enviroment.WorkItem.TokenId, "打回");
- OThinker.H3.Messages.CancelActivityMessage rollbackMessage
- = new OThinker.H3.Messages.CancelActivityMessage(
- OThinker.H3.Messages.MessageEmergencyType.Normal,
- this.Enviroment.WorkItem.InstanceId,
- this.Enviroment.WorkItem.ActivityName,
- true,
- null);
- OThinker.H3.Server.Engine.InstanceManager.SendMessage(rollbackMessage);
- this.Enviroment.NotifyMessage("工作项已经打回");
- }
- }
- private int ControlCount = 0;
- private void AddSplit()
- {
- this.ControlCount++;
- if (this.ControlCount > 1)
- {
- Label split = new Label();
- split.Text = " | ";
- this.Controls.Add(split);
- }
- }
- private void AddText(string Text)
- {
- Label label = new Label();
- label.Text = Text;
- this.Controls.Add(label);
- }
- private void JmpButton_Click(object sender, EventArgs e)
- {
- // 跳转
- // 获得目的任务名称
- string destActivityName = ((LinkButton)sender).Text;
- if (this.Submit != null)
- {
- this.Submit(sender, new SheetSubmitEventArgs(true, destActivityName, "跳转到活动:" + destActivityName));
- }
- }
- private void Submit_Click(object sender, EventArgs e)
- {
- // 按照默认的方法进行流转
- if (this.Submit != null)
- {
- this.Submit(sender, new SheetSubmitEventArgs(true, null, "提交"));
- }
- }
- private void Jump_Click(object sender, EventArgs e)
- {
- if (this.Submit != null && this.JumpDests != null && this.JumpDests.SelectedValue != null && this.JumpDests.SelectedValue != "")
- {
- this.Submit(sender, new SheetSubmitEventArgs(true, this.JumpDests.SelectedValue, "跳转到活动:" + this.JumpDests.SelectedValue));
- }
- }
- private void Save_Click(object sender, EventArgs e)
- {
- if (this.Submit != null)
- {
- this.Submit(sender, new SheetSubmitEventArgs(false, null, null));
- this.Enviroment.NotifyMessage("表单保存完毕!");
- }
- }
- private void Cancel_Click(object sender, EventArgs e)
- {
- string instanceId = this.Enviroment.WorkItem.InstanceId;
- // 取消
- this.Enviroment.CancelInstance(instanceId);
- }
- private void Suspend_Click(object sender, EventArgs e)
- {
- string instanceId = this.Enviroment.WorkItem.InstanceId;
- LinkButton suspend = (LinkButton)sender;
- // 要发送的消息
- OThinker.H3.Messages.Message message = null;
- if (suspend.Text == "挂起")
- {
- message = new OThinker.H3.Messages.SuspendMessage(OThinker.H3.Messages.MessageEmergencyType.Normal, instanceId);
- }
- else
- {
- message = new OThinker.H3.Messages.ResumeMessage(OThinker.H3.Messages.MessageEmergencyType.Normal, instanceId);
- }
- OThinker.H3.Server.Engine.InstanceManager.SendMessage(message);
- this.Enviroment.NotifyMessage("挂起流程成功");
- }
- protected override void Render(HtmlTextWriter writer)
- {
- // 添加禁止重复提交的JS
- foreach (System.Web.UI.Control control in this.Controls)
- {
- if (control is LinkButton)
- {
- bool confirm = false;
- if (control != this.Save)
- {
- confirm = true;
- }
- this.ProhibitReSubmit((LinkButton)control, true, confirm);
- }
- }
- writer.Write("<table border="0" cellpadding="0" cellspacing="0" width="100%">");
- writer.Write("<tr>");
- writer.Write("<td bgcolor="#e0e6f6">");
- writer.Write("<div id="" + CheckSubmit_ButtonDiv + "">");
- if (this.DesignMode)
- {
- writer.Write("保存 | 流程状态 | 提交");
- }
- else
- {
- base.Render(writer);
- }
- writer.Write("</div>");
- writer.Write("<div id="" + CheckSubmit_HintID + "" style="display:none;">正在处理您的请求,请稍等……</div>");
- writer.Write("</td></tr></table>");
- // 输出检查重复提交的JS
- writer.Write("<script>" + CheckSubmit_FunctionDef + "</script>");
- }
- #region 避免重复提交的JS
- /// <summary>
- /// 包含按钮的DIV的ID
- /// </summary>
- public const string CheckSubmit_ButtonDiv = "_H3_Submit_ButtonDiv";
- /// <summary>
- /// 包含提示的DIV的ID
- /// </summary>
- public const string CheckSubmit_HintID = "_H3_Submit_Hint";
- /// <summary>
- /// 禁止重复提交的函数名称
- /// </summary>
- public const string CheckSubmit_FunctionName = "_H3_Submit_HideButtion";
- /// <summary>
- /// 函数定义
- /// </summary>
- public const string CheckSubmit_FunctionDef =
- "function " + CheckSubmit_FunctionName + "(){" +
- CheckSubmit_ButtonDiv + ".style.display='none';" +
- CheckSubmit_HintID + ".style.display='block';" +
- "}";
- private void ProhibitReSubmit(LinkButton Control, bool DisableActionPane, bool Confirm)
- {
- string js_Disable = CheckSubmit_FunctionName + "();";
- string js_PostBack = "__doPostBack('" + Control.ClientID + "', '');";
- string js_Confirm = "if(confirm('确定要进行该操作“" + Control.Text + "”?'))";
- string js = null;
- if (Confirm)
- {
- if (DisableActionPane)
- {
- js = js_Confirm + "{" + js_Disable + js_PostBack + "}";
- }
- else
- {
- js = js_Confirm + "{" + js_PostBack + "}";
- }
- }
- else
- {
- if (DisableActionPane)
- {
- js = js_Disable + js_PostBack;
- }
- else
- {
- js = js_PostBack;
- }
- }
- if (js != null && js != "")
- {
- Control.Attributes["href"] = "javascript:" + js;
- }
- }
- #endregion
- }
- }