SheetEnviroment.cs
资源名称:H3_OA.rar [点击查看]
上传用户:li2971742
上传日期:2021-11-18
资源大小:39096k
文件大小:15k
源码类别:
OA系统
开发平台:
C#
- using System;
- using System.Collections.Generic;
- using System.Text;
- namespace OThinker.H3.WorkSheet
- {
- /// <summary>
- /// 表单环境,用于获得各项工作流服务,当前表单的工作模式和流程数据
- /// </summary>
- public class SheetEnviroment : SheetService, Data.IInstanceDataController
- {
- /// <summary>
- /// 构造函数
- /// </summary>
- /// <param name="Page"></param>
- public SheetEnviroment(System.Web.UI.Page Page) : base(Page)
- {
- }
- #region 参数
- public const string Param_Mode = "Mode";
- public const string Param_WorkItemID = "WorkItemID";
- public const string Param_InstanceId = "InstanceId";
- public const string Param_Activity = "Activity";
- public const string Param_WorkflowPackage = "WorkflowPackage";
- public const string Param_WorkflowName = "WorkflowName";
- public const string Param_WorkflowVersion = "WorkflowVersion";
- public virtual SheetMode SheetMode
- {
- get
- {
- string strMode = this.Page.Request.QueryString[Param_Mode];
- SheetMode mode = SheetModeConvertor.ToSheetMode(strMode);
- return mode;
- }
- }
- private string _WorkItemID = OThinker.H3.WorkItem.WorkItem.NullWorkItemID;
- public string WorkItemID
- {
- get
- {
- switch (this.SheetMode)
- {
- case OThinker.H3.WorkSheet.SheetMode.Originate:
- return this._WorkItemID;
- case OThinker.H3.WorkSheet.SheetMode.Unspecified:
- return OThinker.H3.WorkItem.WorkItem.NullWorkItemID;
- case OThinker.H3.WorkSheet.SheetMode.View:
- case OThinker.H3.WorkSheet.SheetMode.Work:
- // 工作模式
- string strJobId = this.Page.Request.QueryString[Param_WorkItemID];
- if (strJobId == null || strJobId == "")
- {
- return OThinker.H3.WorkItem.WorkItem.NullWorkItemID;
- }
- else
- {
- return strJobId;
- }
- default:
- throw new NotImplementedException();
- }
- }
- set
- {
- switch (this.SheetMode)
- {
- case OThinker.H3.WorkSheet.SheetMode.Originate:
- this._WorkItemID = value;
- break;
- case OThinker.H3.WorkSheet.SheetMode.View:
- case OThinker.H3.WorkSheet.SheetMode.Unspecified:
- case OThinker.H3.WorkSheet.SheetMode.Work:
- default:
- throw new NotImplementedException();
- }
- }
- }
- public OThinker.H3.WorkItem.WorkItem WorkItem
- {
- get
- {
- if (this.WorkItemID == OThinker.H3.WorkItem.WorkItem.NullWorkItemID)
- {
- return null;
- }
- else
- {
- return this.WorkItemManager.GetWorkItem(this.WorkItemID);
- }
- }
- }
- private string _InstanceID = OThinker.H3.Instance.InstanceContext.UnspecifiedID;
- public string InstanceId
- {
- get
- {
- switch (this.SheetMode)
- {
- case OThinker.H3.WorkSheet.SheetMode.Originate:
- return this._InstanceID;
- case OThinker.H3.WorkSheet.SheetMode.View:
- if (this.WorkItem != null)
- {
- return this.WorkItem.InstanceId;
- }
- else
- {
- string instanceId = this.Page.Request.QueryString[Param_InstanceId];
- return instanceId;
- }
- case OThinker.H3.WorkSheet.SheetMode.Unspecified:
- return OThinker.H3.Instance.InstanceContext.UnspecifiedID;
- case OThinker.H3.WorkSheet.SheetMode.Work:
- return this.WorkItem.InstanceId;
- default:
- throw new NotImplementedException();
- }
- }
- set
- {
- switch (this.SheetMode)
- {
- case OThinker.H3.WorkSheet.SheetMode.Originate:
- this._InstanceID = value;
- break;
- case OThinker.H3.WorkSheet.SheetMode.View:
- case OThinker.H3.WorkSheet.SheetMode.Unspecified:
- case OThinker.H3.WorkSheet.SheetMode.Work:
- default:
- throw new NotImplementedException();
- }
- }
- }
- public string WorkflowPackage
- {
- get
- {
- switch (this.SheetMode)
- {
- case OThinker.H3.WorkSheet.SheetMode.Originate:
- return System.Web.HttpUtility.UrlDecode(this.Page.Request.QueryString[Param_WorkflowPackage]);
- case OThinker.H3.WorkSheet.SheetMode.View:
- string sessionName = Sessions.GetInstanceWorkflowPackage(this.InstanceId);
- if (this.Page.Session[sessionName] == null)
- {
- this.Page.Session[sessionName] = this.InstanceManager.GetInstanceWorkflowPackage(this.InstanceId);
- }
- return (string)this.Page.Session[sessionName];
- case OThinker.H3.WorkSheet.SheetMode.Work:
- return this.WorkItem.WorkflowPackage;
- case OThinker.H3.WorkSheet.SheetMode.Unspecified:
- return null;
- default:
- throw new NotImplementedException();
- }
- }
- }
- public string WorkflowName
- {
- get
- {
- switch (this.SheetMode)
- {
- case OThinker.H3.WorkSheet.SheetMode.Originate:
- return System.Web.HttpUtility.UrlDecode(this.Page.Request.QueryString[Param_WorkflowName]);
- case OThinker.H3.WorkSheet.SheetMode.View:
- string sessionName = Sessions.GetInstanceWorkflowName(this.InstanceId);
- if (this.Page.Session[sessionName] == null)
- {
- this.Page.Session[sessionName] = this.InstanceManager.GetInstanceWorkflowName(this.InstanceId);
- }
- return (string)this.Page.Session[sessionName];
- case OThinker.H3.WorkSheet.SheetMode.Work:
- return this.WorkItem.WorkflowName;
- case OThinker.H3.WorkSheet.SheetMode.Unspecified:
- return null;
- default:
- throw new NotImplementedException();
- }
- }
- }
- public int WorkflowVersion
- {
- get
- {
- switch (this.SheetMode)
- {
- case OThinker.H3.WorkSheet.SheetMode.Originate:
- return int.Parse(this.Page.Request.QueryString[Param_WorkflowVersion]);
- case OThinker.H3.WorkSheet.SheetMode.View:
- string sessionName = Sessions.GetInstanceWorkflowVersion(this.InstanceId);
- if (this.Page.Session[sessionName] == null)
- {
- this.Page.Session[sessionName] = this.InstanceManager.GetInstanceWorkflowVersion(this.InstanceId);
- }
- return (int)this.Page.Session[sessionName];
- case OThinker.H3.WorkSheet.SheetMode.Work:
- return this.WorkItem.WorkflowVersion;
- case OThinker.H3.WorkSheet.SheetMode.Unspecified:
- return H3.WorkflowTemplate.WorkflowTemplate.NullWorkflowVersion;
- default:
- throw new NotImplementedException();
- }
- }
- }
- public OThinker.H3.WorkflowTemplate.WorkflowTemplate Workflow
- {
- get
- {
- string sessionName = Sessions.GetWorkflow(
- this.WorkflowPackage,
- this.WorkflowName,
- this.WorkflowVersion);
- if (this.Page.Session[sessionName] == null)
- {
- OThinker.H3.WorkflowTemplate.WorkflowTemplate workflow
- = this.WorkflowManager.GetWorkflow(
- this.WorkflowPackage,
- this.WorkflowName,
- this.WorkflowVersion);
- this.Page.Session[sessionName] = workflow;
- }
- return (OThinker.H3.WorkflowTemplate.WorkflowTemplate)this.Page.Session[sessionName];
- }
- }
- public string ActivityName
- {
- get
- {
- switch (this.SheetMode)
- {
- case OThinker.H3.WorkSheet.SheetMode.Originate:
- // 发起模式
- return this.Workflow.StartActivity;
- case OThinker.H3.WorkSheet.SheetMode.View:
- if (this.WorkItem != null)
- {
- return this.WorkItem.ActivityName;
- }
- else
- {
- return System.Web.HttpUtility.UrlDecode(this.Page.Request.QueryString[Param_Activity]);
- }
- case OThinker.H3.WorkSheet.SheetMode.Work:
- return this.WorkItem.ActivityName;
- case OThinker.H3.WorkSheet.SheetMode.Unspecified:
- return null;
- default:
- throw new NotImplementedException();
- }
- }
- }
- public H3.WorkflowTemplate.ActivityTemplate WorkflowActivity
- {
- get
- {
- return this.Workflow.GetActivity(this.ActivityName);
- }
- }
- #endregion
- #region 数据
- private OThinker.H3.Data.InstanceData _InstanceData;
- public OThinker.H3.Data.InstanceData InstanceData
- {
- get
- {
- if (this._InstanceData == null || this._InstanceData.InstanceId != this.InstanceId)
- {
- string activityName = this.ActivityName;
- this._InstanceData = new OThinker.H3.Data.InstanceData(
- this.InstanceDataManager,
- this.WorkflowManager,
- this.InstanceManager,
- this.InstanceId,
- this.WorkItem == null?Instance.Token.UnspecifiedID:this.WorkItem.TokenId,
- this.Workflow,
- activityName,
- this.Participant,
- this);
- this._InstanceData.UseCache = true;
- this._InstanceData.AutoLookupParent = true;
- }
- return this._InstanceData;
- }
- }
- public HeapDataItemCollection HeapData
- {
- get
- {
- return new HeapDataItemCollection(this);
- }
- }
- #endregion
- #region Data.IInstanceDataController
- public virtual OThinker.Data.BoolMatchValue GetItemEditable(string ItemName)
- {
- if (this.Page is Data.IInstanceDataController)
- {
- return ((Data.IInstanceDataController)this.Page).GetItemEditable(ItemName);
- }
- else
- {
- return OThinker.Data.BoolMatchValue.Unspecified;
- }
- }
- public virtual OThinker.Data.BoolMatchValue GetItemVisible(string ItemName)
- {
- if (this.Page is Data.IInstanceDataController)
- {
- return ((Data.IInstanceDataController)this.Page).GetItemVisible(ItemName);
- }
- else
- {
- return OThinker.Data.BoolMatchValue.Unspecified;
- }
- }
- public virtual OThinker.Data.BoolMatchValue GetItemTrackVisible(string ItemName)
- {
- if (this.Page is Data.IInstanceDataController)
- {
- return ((Data.IInstanceDataController)this.Page).GetItemTrackVisible(ItemName);
- }
- else
- {
- return OThinker.Data.BoolMatchValue.Unspecified;
- }
- }
- public virtual bool SetItemValue(string ItemName, object Value)
- {
- if (this.Page is Data.IInstanceDataController)
- {
- return ((Data.IInstanceDataController)this.Page).SetItemValue(ItemName, Value);
- }
- else
- {
- return true;
- }
- }
- public virtual bool GetItemValue(string ItemName, ref object Value)
- {
- if (this.Page is Data.IInstanceDataController)
- {
- return ((Data.IInstanceDataController)this.Page).GetItemValue(ItemName, ref Value);
- }
- else
- {
- return false;
- }
- }
- #endregion
- #region 工作模式
- /// <summary>
- /// 工作模式的条件
- /// </summary>
- public bool IsWorkMode
- {
- get
- {
- return
- this.SheetMode == SheetMode.Work &&
- this.WorkItem != null &&
- this.WorkItem.State != OThinker.H3.WorkItem.WorkItemState.Finished;
- }
- }
- /// <summary>
- /// 发起模式的条件
- /// </summary>
- public bool IsOriginateMode
- {
- get
- {
- return this.SheetMode == SheetMode.Originate;
- }
- }
- /// <summary>
- /// 取回模式
- /// </summary>
- public bool IsRetrieveMode
- {
- get
- {
- return
- this.SheetMode == SheetMode.View &&
- this.WorkItem != null &&
- this.WorkItem.State == OThinker.H3.WorkItem.WorkItemState.Finished &&
- this.WorkItem.PermittedActions.Retrieve;
- }
- }
- #endregion
- }
- }