SheetManager.cs
资源名称:H3_OA.rar [点击查看]
上传用户:li2971742
上传日期:2021-11-18
资源大小:39096k
文件大小:10k
源码类别:
OA系统
开发平台:
C#
- using System;
- using System.Collections;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.ComponentModel;
- using System.Drawing;
- using System.Drawing.Design;
- [assembly: TagPrefix("OThinker.H3.WorkSheet", "SheetControls")]
- namespace OThinker.H3.WorkSheet
- {
- /// <summary>
- /// 这个控件用于进行汇签,填写大家的意见
- /// </summary>
- [ToolboxBitmap(typeof(SheetManager), "OThinker.H3.WorkSheet.SheetManager.bmp")]
- [DefaultProperty("Text"), ToolboxData("<{0}:SheetManager runat=server></{0}:SheetManager>")]
- public class SheetManager : System.Web.UI.WebControls.WebControl
- {
- /// <summary>
- /// 工作项头
- /// </summary>
- protected SheetHeader SheetHeader = new SheetHeader();
- /// <summary>
- /// 添加操作面板
- /// </summary>
- protected OThinker.H3.WorkSheet.SheetActionPane ActionPane = new SheetActionPane();
- /// <summary>
- /// 构造函数
- /// </summary>
- public SheetManager()
- {
- // 工作项的头
- this.Controls.Add(this.SheetHeader);
- // 操作面板
- this.ActionPane.Submit += new SheetSubmitEventHandler(this.Submit);
- this.Controls.Add(this.ActionPane);
- this.Load += new EventHandler(SheetManager_Load);
- }
- private void SheetManager_Load(object sender, EventArgs e)
- {
- this.SheetHeader.Enviroment = this.Enviroment;
- this.ActionPane.Enviroment = this.Enviroment;
- // 验证权限
- if (!this.SheetPage.ValidateAuthorization())
- {
- this.Enviroment.NotifyMessage("当前用户没有权限操作该工作项");
- }
- switch (this.Enviroment.SheetMode)
- {
- case SheetMode.Work:
- // 工作模式
- if (this.Enviroment.WorkItem == null)
- {
- this.Enviroment.NotifyMessage("工作项不存在");
- }
- else if (this.Enviroment.WorkItem.State == OThinker.H3.WorkItem.WorkItemState.Finished)
- {
- this.Enviroment.NotifyMessage("该工作项已经完成");
- }
- else if (this.Enviroment.WorkItem.State == OThinker.H3.WorkItem.WorkItemState.Canceled)
- {
- this.Enviroment.NotifyMessage("该工作项已经取消");
- }
- else
- {
- // 开始做该工作项
- this.Enviroment.WorkItemManager.DoWorkItem(this.Enviroment.WorkItemID);
- }
- break;
- case SheetMode.View:
- break;
- case SheetMode.Originate:
- break;
- case SheetMode.Unspecified:
- break;
- default:
- throw new NotImplementedException();
- }
- // 加载数据
- this.SheetPage.LoadDataFields();
- }
- private ISheetPage SheetPage
- {
- get
- {
- if (!(this.Page is ISheetPage))
- {
- throw new Exception("SheetManager控件必须添加到实现了OThinker.H3.WorkShet.ISheetPage的页面中。");
- }
- return (ISheetPage)this.Page;
- }
- }
- /// <summary>
- /// 环境
- /// </summary>
- [Browsable(false)]
- public virtual SheetEnviroment Enviroment
- {
- get
- {
- return this.SheetPage.Enviroment;
- }
- }
- /// <summary>
- /// 提交
- /// </summary>
- /// <param name="sender">发送参数的对象</param>
- /// <param name="e">事件参数</param>
- public virtual void Submit(object sender, SheetSubmitEventArgs e)
- {
- // 检查当前登录用户是否存在
- if (this.Enviroment.UserValidator == null)
- {
- throw new NotImplementedException("User not login.");
- }
- // 验证输入是否合法
- System.Collections.Generic.List<string> errors = new System.Collections.Generic.List<string>();
- if (this.Page is ISheetPage && !((ISheetPage)this.Page).ValidateDataFields(e, errors))
- {
- System.Text.StringBuilder builder = new System.Text.StringBuilder();
- foreach (string error in errors)
- {
- builder.Append(error);
- }
- this.Enviroment.NotifyMessage(builder.ToString());
- return;
- }
- // 检查是否需要发起
- if (this.Enviroment.SheetMode == SheetMode.Originate)
- {
- this.OriginateInstance(this.ActionPane.GroupSelector.SelectedValue);
- }
- //无论是否是更新和完成任务,都要执行此任务,对各个控件的数据进行提交
- if (this.Page is ISheetPage)
- {
- ((ISheetPage)this.Page).SaveDataFields(e);
- }
- string workItemId = this.Enviroment.WorkItem.WorkItemID;
- if (e.Finish)
- {
- OThinker.Data.BoolMatchValue approval = OThinker.Data.BoolMatchValue.Unspecified;
- if (this.Page is ISheetPage)
- {
- approval = ((ISheetPage)this.Page).Approval;
- }
- string comment = null;
- if (this.Page is ISheetPage)
- {
- comment = ((ISheetPage)this.Page).Comment;
- }
- // 进入到完成界面上
- this.Enviroment.FinishWorkItem(
- workItemId,
- e.DestActivityName,
- this.ActionPane.GroupSelector.SelectedValue,
- approval,
- comment,
- e.Description);
- }
- }
- #region 发起流程
- /// <summary>
- /// 发起流程的事件
- /// </summary>
- [Browsable(true), Category("WorkSheet")]
- public event EventHandler<OriginateInstanceEventArgs> OriginatingInstance;
- /// <summary>
- /// 创建一个新的流程实例
- /// </summary>
- public void OriginateInstance(string OriginateGroup)
- {
- // 创建流程实例
- string instanceID = this.Enviroment.InstanceManager.CreateInstance(
- this.Enviroment.WorkflowPackage,
- this.Enviroment.WorkflowName,
- this.Enviroment.WorkflowVersion,
- null,
- this.Enviroment.Participant,
- OriginateGroup,
- this.Enviroment.Organization.GetUserDept(this.Enviroment.Participant),
- false,
- Instance.InstanceContext.UnspecifiedID,
- null,
- Instance.Token.UnspecifiedID);
- this.Enviroment.InstanceId = instanceID;
- // 设置紧急程度为普通
- OThinker.H3.Messages.MessageEmergencyType emergency = Messages.MessageEmergencyType.Normal;
- // 如果是发起后需要用户填写表单的模式,则紧急程度为高
- if (this.Enviroment.Workflow.StartWithSheet)
- {
- emergency = OThinker.H3.Messages.MessageEmergencyType.High;
- }
- // 调用发起事件
- OriginateInstanceEventArgs originateArgs = null;
- if (this.OriginatingInstance != null)
- {
- originateArgs = new OriginateInstanceEventArgs(instanceID);
- this.OriginatingInstance(this, originateArgs);
- }
- // 启动流程的消息
- OThinker.H3.Messages.StartInstanceMessage startInstanceMessage
- = new OThinker.H3.Messages.StartInstanceMessage(
- emergency,
- instanceID,
- originateArgs == null ? null : originateArgs.InstanceParameterTable.Count == 0 ? null : originateArgs.InstanceParameterTable,
- Instance.PriorityType.Normal,
- false,
- 0,
- OThinker.H3.Instance.Token.UnspecifiedID,
- null);
- this.Enviroment.InstanceManager.SendMessage(startInstanceMessage);
- if (!this.Enviroment.Workflow.StartWithSheet)
- {
- // 返回工作项为空
- this.Enviroment.WorkItemID = H3.WorkItem.WorkItem.NullWorkItemID;
- return;
- }
- // 查找新创建的工作项
- string[] jobs = null;
- for (int triedTimes = 0; triedTimes < 10; triedTimes++)
- {
- System.Threading.Thread.Sleep(1500);
- jobs = this.Enviroment.WorkItemManager.Query(
- null,
- new string[] { instanceID },
- new string[] { this.Enviroment.Participant },
- System.DateTime.MinValue,
- System.DateTime.MaxValue,
- OThinker.H3.WorkItem.WorkItemState.Unfinished);
- if (jobs != null && jobs.Length != 0)
- {
- break;
- }
- }
- if (jobs == null || jobs.Length == 0)
- {
- this.Enviroment.NotifyMessage("发起流程失败");
- this.Enviroment.WorkItemID = OThinker.H3.WorkItem.WorkItem.NullWorkItemID;
- }
- else
- {
- // 返回新创建的工作项
- this.Enviroment.WorkItemID = jobs[0];
- }
- }
- #endregion
- }
- }