SheetEnviroment.cs
上传用户:li2971742
上传日期:2021-11-18
资源大小:39096k
文件大小:15k
源码类别:

OA系统

开发平台:

C#

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. namespace OThinker.H3.WorkSheet
  5. {
  6.     /// <summary>
  7.     /// 表单环境,用于获得各项工作流服务,当前表单的工作模式和流程数据
  8.     /// </summary>
  9.     public class SheetEnviroment : SheetService, Data.IInstanceDataController
  10.     {
  11.         /// <summary>
  12.         /// 构造函数
  13.         /// </summary>
  14.         /// <param name="Page"></param>
  15.         public SheetEnviroment(System.Web.UI.Page Page) : base(Page)
  16.         {
  17.         }
  18.         #region 参数
  19.         public const string Param_Mode = "Mode";
  20.         public const string Param_WorkItemID = "WorkItemID";
  21.         public const string Param_InstanceId = "InstanceId";
  22.         public const string Param_Activity = "Activity";
  23.         public const string Param_WorkflowPackage = "WorkflowPackage";
  24.         public const string Param_WorkflowName = "WorkflowName";
  25.         public const string Param_WorkflowVersion = "WorkflowVersion";
  26.         public virtual SheetMode SheetMode
  27.         {
  28.             get
  29.             {
  30.                 string strMode = this.Page.Request.QueryString[Param_Mode];
  31.                 SheetMode mode = SheetModeConvertor.ToSheetMode(strMode);
  32.                 return mode;
  33.             }
  34.         }
  35.         private string _WorkItemID = OThinker.H3.WorkItem.WorkItem.NullWorkItemID;
  36.         public string WorkItemID
  37.         {
  38.             get
  39.             {
  40.                 switch (this.SheetMode)
  41.                 {
  42.                     case OThinker.H3.WorkSheet.SheetMode.Originate:
  43.                         return this._WorkItemID;
  44.                     case OThinker.H3.WorkSheet.SheetMode.Unspecified:
  45.                         return OThinker.H3.WorkItem.WorkItem.NullWorkItemID;
  46.                     case OThinker.H3.WorkSheet.SheetMode.View:
  47.                     case OThinker.H3.WorkSheet.SheetMode.Work:
  48.                         // 工作模式
  49.                         string strJobId = this.Page.Request.QueryString[Param_WorkItemID];
  50.                         if (strJobId == null || strJobId == "")
  51.                         {
  52.                             return OThinker.H3.WorkItem.WorkItem.NullWorkItemID;
  53.                         }
  54.                         else
  55.                         {
  56.                             return strJobId;
  57.                         }
  58.                     default:
  59.                         throw new NotImplementedException();
  60.                 }
  61.             }
  62.             set
  63.             {
  64.                 switch (this.SheetMode)
  65.                 {
  66.                     case OThinker.H3.WorkSheet.SheetMode.Originate:
  67.                         this._WorkItemID = value;
  68.                         break;
  69.                     case OThinker.H3.WorkSheet.SheetMode.View:
  70.                     case OThinker.H3.WorkSheet.SheetMode.Unspecified:
  71.                     case OThinker.H3.WorkSheet.SheetMode.Work:
  72.                     default:
  73.                         throw new NotImplementedException();
  74.                 }
  75.             }
  76.         }
  77.         public OThinker.H3.WorkItem.WorkItem WorkItem
  78.         {
  79.             get
  80.             {
  81.                 if (this.WorkItemID == OThinker.H3.WorkItem.WorkItem.NullWorkItemID)
  82.                 {
  83.                     return null;
  84.                 }
  85.                 else
  86.                 {
  87.                     return this.WorkItemManager.GetWorkItem(this.WorkItemID);
  88.                 }
  89.             }
  90.         }
  91.         private string _InstanceID = OThinker.H3.Instance.InstanceContext.UnspecifiedID;
  92.         public string InstanceId
  93.         {
  94.             get
  95.             {
  96.                 switch (this.SheetMode)
  97.                 {
  98.                     case OThinker.H3.WorkSheet.SheetMode.Originate:
  99.                         return this._InstanceID;
  100.                     case OThinker.H3.WorkSheet.SheetMode.View:
  101.                         if (this.WorkItem != null)
  102.                         {
  103.                             return this.WorkItem.InstanceId;
  104.                         }
  105.                         else
  106.                         {
  107.                             string instanceId = this.Page.Request.QueryString[Param_InstanceId];
  108.                             return instanceId;
  109.                         }
  110.                     case OThinker.H3.WorkSheet.SheetMode.Unspecified:
  111.                         return OThinker.H3.Instance.InstanceContext.UnspecifiedID;
  112.                     case OThinker.H3.WorkSheet.SheetMode.Work:
  113.                         return this.WorkItem.InstanceId;
  114.                     default:
  115.                         throw new NotImplementedException();
  116.                 }
  117.             }
  118.             set
  119.             {
  120.                 switch (this.SheetMode)
  121.                 {
  122.                     case OThinker.H3.WorkSheet.SheetMode.Originate:
  123.                         this._InstanceID = value;
  124.                         break;
  125.                     case OThinker.H3.WorkSheet.SheetMode.View:
  126.                     case OThinker.H3.WorkSheet.SheetMode.Unspecified:
  127.                     case OThinker.H3.WorkSheet.SheetMode.Work:
  128.                     default:
  129.                         throw new NotImplementedException();
  130.                 }
  131.             }
  132.         }
  133.         public string WorkflowPackage
  134.         {
  135.             get
  136.             {
  137.                 switch (this.SheetMode)
  138.                 {
  139.                     case OThinker.H3.WorkSheet.SheetMode.Originate:
  140.                         return System.Web.HttpUtility.UrlDecode(this.Page.Request.QueryString[Param_WorkflowPackage]);
  141.                     case OThinker.H3.WorkSheet.SheetMode.View:
  142.                         string sessionName = Sessions.GetInstanceWorkflowPackage(this.InstanceId);
  143.                         if (this.Page.Session[sessionName] == null)
  144.                         {
  145.                             this.Page.Session[sessionName] = this.InstanceManager.GetInstanceWorkflowPackage(this.InstanceId);
  146.                         }
  147.                         return (string)this.Page.Session[sessionName];
  148.                     case OThinker.H3.WorkSheet.SheetMode.Work:
  149.                         return this.WorkItem.WorkflowPackage;
  150.                     case OThinker.H3.WorkSheet.SheetMode.Unspecified:
  151.                         return null;
  152.                     default:
  153.                         throw new NotImplementedException();
  154.                 }
  155.             }
  156.         }
  157.         public string WorkflowName
  158.         {
  159.             get
  160.             {
  161.                 switch (this.SheetMode)
  162.                 {
  163.                     case OThinker.H3.WorkSheet.SheetMode.Originate:
  164.                         return System.Web.HttpUtility.UrlDecode(this.Page.Request.QueryString[Param_WorkflowName]);
  165.                     case OThinker.H3.WorkSheet.SheetMode.View:
  166.                         string sessionName = Sessions.GetInstanceWorkflowName(this.InstanceId);
  167.                         if (this.Page.Session[sessionName] == null)
  168.                         {
  169.                             this.Page.Session[sessionName] = this.InstanceManager.GetInstanceWorkflowName(this.InstanceId);
  170.                         }
  171.                         return (string)this.Page.Session[sessionName];
  172.                     case OThinker.H3.WorkSheet.SheetMode.Work:
  173.                         return this.WorkItem.WorkflowName;
  174.                     case OThinker.H3.WorkSheet.SheetMode.Unspecified:
  175.                         return null;
  176.                     default:
  177.                         throw new NotImplementedException();
  178.                 }
  179.             }
  180.         }
  181.         public int WorkflowVersion
  182.         {
  183.             get
  184.             {
  185.                 switch (this.SheetMode)
  186.                 {
  187.                     case OThinker.H3.WorkSheet.SheetMode.Originate:
  188.                         return int.Parse(this.Page.Request.QueryString[Param_WorkflowVersion]);
  189.                     case OThinker.H3.WorkSheet.SheetMode.View:
  190.                         string sessionName = Sessions.GetInstanceWorkflowVersion(this.InstanceId);
  191.                         if (this.Page.Session[sessionName] == null)
  192.                         {
  193.                             this.Page.Session[sessionName] = this.InstanceManager.GetInstanceWorkflowVersion(this.InstanceId);
  194.                         }
  195.                         return (int)this.Page.Session[sessionName];
  196.                     case OThinker.H3.WorkSheet.SheetMode.Work:
  197.                         return this.WorkItem.WorkflowVersion;
  198.                     case OThinker.H3.WorkSheet.SheetMode.Unspecified:
  199.                         return H3.WorkflowTemplate.WorkflowTemplate.NullWorkflowVersion;
  200.                     default:
  201.                         throw new NotImplementedException();
  202.                 }
  203.             }
  204.         }
  205.         public OThinker.H3.WorkflowTemplate.WorkflowTemplate Workflow
  206.         {
  207.             get
  208.             {
  209.                 string sessionName = Sessions.GetWorkflow(
  210.                     this.WorkflowPackage,
  211.                     this.WorkflowName,
  212.                     this.WorkflowVersion);
  213.                 if (this.Page.Session[sessionName] == null)
  214.                 {
  215.                     OThinker.H3.WorkflowTemplate.WorkflowTemplate workflow
  216.                         = this.WorkflowManager.GetWorkflow(
  217.                         this.WorkflowPackage,
  218.                         this.WorkflowName,
  219.                         this.WorkflowVersion);
  220.                     this.Page.Session[sessionName] = workflow;
  221.                 }
  222.                 return (OThinker.H3.WorkflowTemplate.WorkflowTemplate)this.Page.Session[sessionName];
  223.             }
  224.         }
  225.         public string ActivityName
  226.         {
  227.             get
  228.             {
  229.                 switch (this.SheetMode)
  230.                 {
  231.                     case OThinker.H3.WorkSheet.SheetMode.Originate:
  232.                         // 发起模式
  233.                         return this.Workflow.StartActivity;
  234.                     case OThinker.H3.WorkSheet.SheetMode.View:
  235.                         if (this.WorkItem != null)
  236.                         {
  237.                             return this.WorkItem.ActivityName;
  238.                         }
  239.                         else
  240.                         {
  241.                             return System.Web.HttpUtility.UrlDecode(this.Page.Request.QueryString[Param_Activity]);
  242.                         }
  243.                     case OThinker.H3.WorkSheet.SheetMode.Work:
  244.                         return this.WorkItem.ActivityName;
  245.                     case OThinker.H3.WorkSheet.SheetMode.Unspecified:
  246.                         return null;
  247.                     default:
  248.                         throw new NotImplementedException();
  249.                 }
  250.             }
  251.         }
  252.         public H3.WorkflowTemplate.ActivityTemplate WorkflowActivity
  253.         {
  254.             get
  255.             {
  256.                 return this.Workflow.GetActivity(this.ActivityName);
  257.             }
  258.         }
  259.         #endregion
  260.         #region 数据
  261.         private OThinker.H3.Data.InstanceData _InstanceData;
  262.         public OThinker.H3.Data.InstanceData InstanceData
  263.         {
  264.             get
  265.             {
  266.                 if (this._InstanceData == null || this._InstanceData.InstanceId != this.InstanceId)
  267.                 {
  268.                     string activityName = this.ActivityName;
  269.                     this._InstanceData = new OThinker.H3.Data.InstanceData(
  270.                         this.InstanceDataManager,
  271.                         this.WorkflowManager,
  272.                         this.InstanceManager,
  273.                         this.InstanceId,
  274.                         this.WorkItem == null?Instance.Token.UnspecifiedID:this.WorkItem.TokenId,
  275.                         this.Workflow,
  276.                         activityName,
  277.                         this.Participant,
  278.                         this);
  279.                     this._InstanceData.UseCache = true;
  280.                     this._InstanceData.AutoLookupParent = true;
  281.                 }
  282.                 return this._InstanceData;
  283.             }
  284.         }
  285.         public HeapDataItemCollection HeapData
  286.         {
  287.             get
  288.             {
  289.                 return new HeapDataItemCollection(this);
  290.             }
  291.         }
  292.         #endregion
  293.         #region Data.IInstanceDataController
  294.         public virtual OThinker.Data.BoolMatchValue GetItemEditable(string ItemName)
  295.         {
  296.             if (this.Page is Data.IInstanceDataController)
  297.             {
  298.                 return ((Data.IInstanceDataController)this.Page).GetItemEditable(ItemName);
  299.             }
  300.             else
  301.             {
  302.                 return OThinker.Data.BoolMatchValue.Unspecified;
  303.             }
  304.         }
  305.         public virtual OThinker.Data.BoolMatchValue GetItemVisible(string ItemName)
  306.         {
  307.             if (this.Page is Data.IInstanceDataController)
  308.             {
  309.                 return ((Data.IInstanceDataController)this.Page).GetItemVisible(ItemName);
  310.             }
  311.             else
  312.             {
  313.                 return OThinker.Data.BoolMatchValue.Unspecified;
  314.             }
  315.         }
  316.         public virtual OThinker.Data.BoolMatchValue GetItemTrackVisible(string ItemName)
  317.         {
  318.             if (this.Page is Data.IInstanceDataController)
  319.             {
  320.                 return ((Data.IInstanceDataController)this.Page).GetItemTrackVisible(ItemName);
  321.             }
  322.             else
  323.             {
  324.                 return OThinker.Data.BoolMatchValue.Unspecified;
  325.             }
  326.         }
  327.         public virtual bool SetItemValue(string ItemName, object Value)
  328.         {
  329.             if (this.Page is Data.IInstanceDataController)
  330.             {
  331.                 return ((Data.IInstanceDataController)this.Page).SetItemValue(ItemName, Value);
  332.             }
  333.             else
  334.             {
  335.                 return true;
  336.             }
  337.         }
  338.         public virtual bool GetItemValue(string ItemName, ref object Value)
  339.         {
  340.             if (this.Page is Data.IInstanceDataController)
  341.             {
  342.                 return ((Data.IInstanceDataController)this.Page).GetItemValue(ItemName, ref Value);
  343.             }
  344.             else
  345.             {
  346.                 return false;
  347.             }
  348.         }
  349.         #endregion
  350.         #region 工作模式
  351.         /// <summary>
  352.         /// 工作模式的条件
  353.         /// </summary>
  354.         public bool IsWorkMode
  355.         {
  356.             get
  357.             {
  358.                 return
  359.                     this.SheetMode == SheetMode.Work &&
  360.                     this.WorkItem != null &&
  361.                     this.WorkItem.State != OThinker.H3.WorkItem.WorkItemState.Finished;
  362.             }
  363.         }
  364.         /// <summary>
  365.         /// 发起模式的条件
  366.         /// </summary>
  367.         public bool IsOriginateMode
  368.         {
  369.             get
  370.             {
  371.                 return this.SheetMode == SheetMode.Originate;
  372.             }
  373.         }
  374.         /// <summary>
  375.         /// 取回模式
  376.         /// </summary>
  377.         public bool IsRetrieveMode
  378.         {
  379.             get
  380.             {
  381.                 return
  382.                     this.SheetMode == SheetMode.View &&
  383.                     this.WorkItem != null &&
  384.                     this.WorkItem.State == OThinker.H3.WorkItem.WorkItemState.Finished &&
  385.                     this.WorkItem.PermittedActions.Retrieve;
  386.             }
  387.         }
  388.         #endregion
  389.     }
  390. }