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

OA系统

开发平台:

C#

  1. using System;
  2. using System.Collections;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Web;
  7. using System.Web.SessionState;
  8. using System.Web.UI;
  9. using System.Web.UI.WebControls;
  10. using System.Web.UI.HtmlControls;
  11. namespace OThinker.H3.Portal
  12. {
  13. /// <summary>
  14. /// Summary description for ActivityReport.
  15. /// </summary>
  16. public partial class ActivityReport : PortalPage
  17. {
  18. protected void Page_Load(object sender, System.EventArgs e)
  19. {
  20. if(!this.IsPostBack)
  21. {
  22.                 if (!this.UserValidator.ValidateViewReport())
  23. {
  24. this.NotifyMessage(LackOfAuth);
  25. }
  26. }
  27. #region 分析参数
  28. string catalog = System.Web.HttpUtility.UrlDecode(this.Request.QueryString[Param_WorkflowPackage]);
  29. if(catalog == null || catalog == "")
  30. {
  31. catalog = null;
  32. }
  33. string name = System.Web.HttpUtility.UrlDecode(this.Request.QueryString[Param_WorkflowName]);
  34. if(name == null || name == "")
  35. {
  36. name = null;
  37. }
  38. string _version = System.Web.HttpUtility.UrlDecode(this.Request.QueryString[Param_WorkflowVersion]);
  39. int version;
  40. try
  41. {
  42. version = int.Parse(_version);
  43. }
  44. catch
  45. {
  46.                 version = OThinker.H3.WorkflowTemplate.WorkflowTemplate.NullWorkflowVersion;
  47. }
  48. string _from = System.Web.HttpUtility.UrlDecode(this.Request.QueryString[Param_From]);
  49. System.DateTime from;
  50. try
  51. {
  52. from = System.DateTime.Parse(_from);
  53. }
  54. catch
  55. {
  56. from = System.DateTime.MinValue;
  57. }
  58. string _to = System.Web.HttpUtility.UrlDecode(this.Request.QueryString[Param_To]);
  59. System.DateTime to;
  60. try
  61. {
  62. to = System.DateTime.Parse(_to);
  63. }
  64. catch
  65. {
  66. to = System.DateTime.MaxValue;
  67. }
  68. #endregion
  69. System.Data.DataTable performances = new DataTable();
  70. performances.Columns.Add("模板全名");
  71. performances.Columns.Add("活动名称");
  72. performances.Columns.Add("执行次数");
  73. performances.Columns.Add("平均完成时间");
  74. if(catalog == null)
  75. {
  76. // 显示所有流程的所有任务的性能
  77.                 string[] catalogs = OThinker.H3.Server.Engine.WorkflowManager.GetWorkflowPackages();
  78. if(catalogs != null)
  79. {
  80. foreach(string c in catalogs)
  81. {
  82.                         string[] names = OThinker.H3.Server.Engine.WorkflowManager.GetWorkflowNames(c, OThinker.H3.WorkflowTemplate.WorkflowState.Unspecified);
  83. if(names != null)
  84. {
  85. foreach(string n in names)
  86. {
  87. int[] versions = OThinker.H3.Server.Engine.WorkflowManager.GetWorkflowVersions(c, n);
  88. if(versions != null)
  89. {
  90. foreach(int v in versions)
  91. {
  92. this.GetPerformance(
  93. performances, 
  94. c, 
  95. n, 
  96. v, 
  97. from, 
  98. to);
  99. }
  100. }
  101. }
  102. }
  103. }
  104. }
  105. }
  106. else if(name == null)
  107. {
  108. // 显示某个类型下的所有流程的所有任务的性能
  109.                 string[] names = OThinker.H3.Server.Engine.WorkflowManager.GetWorkflowNames(catalog, OThinker.H3.WorkflowTemplate.WorkflowState.Unspecified);
  110. if(names != null)
  111. {
  112. foreach(string n in names)
  113. {
  114. int[] versions = OThinker.H3.Server.Engine.WorkflowManager.GetWorkflowVersions(catalog, n);
  115. if(versions != null)
  116. {
  117. foreach(int v in versions)
  118. {
  119. this.GetPerformance(
  120. performances, 
  121. catalog, 
  122. n, 
  123. v, 
  124. from, 
  125. to);
  126. }
  127. }
  128. }
  129. }
  130. }
  131.             else if (version == OThinker.H3.WorkflowTemplate.WorkflowTemplate.NullWorkflowVersion || version == OThinker.H3.WorkflowTemplate.WorkflowTemplate.AllWorkflowVersion)
  132. {
  133. // 某个流程所有版本的所有任务
  134. int[] versions = OThinker.H3.Server.Engine.WorkflowManager.GetWorkflowVersions(catalog, name);
  135. if(versions != null)
  136. {
  137. foreach(int v in versions)
  138. {
  139. this.GetPerformance(
  140. performances, 
  141. catalog, 
  142. name, 
  143. v, 
  144. from, 
  145. to);
  146. }
  147. }
  148. }
  149. else
  150. {
  151. this.GetPerformance(
  152. performances, 
  153. catalog, 
  154. name, 
  155. version, 
  156. from, 
  157. to);
  158. }
  159. this.PerformanceGrid.DataSource = performances;
  160. this.PerformanceGrid.DataBind();
  161. }
  162. // 获得某个流程的某个任务的性能,结果存放在Performances表中
  163. private void GetPerformance(
  164. System.Data.DataTable Performances, 
  165. string WorkflowPackage, 
  166. string WorkflowName, 
  167. int WorkflowVersion, 
  168. System.DateTime From, 
  169. System.DateTime To)
  170. {
  171. // 获得在这个时间段内的所有流程实例
  172. // 注意:这里必须获得已完成的任务,如果一个任务未完成可能会导致计算的平均值为负
  173.             string[] instances = OThinker.H3.Server.Engine.InstanceManager.Query(
  174. null, 
  175. null, 
  176. OThinker.H3.Instance.InstanceContext.UnspecifiedID, 
  177. OThinker.H3.Instance.InstanceState.Complete,
  178.                 WorkflowPackage, 
  179. WorkflowName, 
  180. WorkflowVersion, 
  181. From, 
  182. To, 
  183.                 null);
  184. // 获得该流程
  185.             OThinker.H3.WorkflowTemplate.WorkflowTemplate process = OThinker.H3.Server.Engine.WorkflowManager.GetWorkflow(
  186.                 WorkflowPackage, 
  187. WorkflowName, 
  188. WorkflowVersion);
  189. // 获得该流程的每个任务的性能
  190.             foreach (OThinker.H3.WorkflowTemplate.ActivityTemplate task in process.Activities)
  191. {
  192. OThinker.H3.WorkflowTemplate.ActivityPerformance performance = OThinker.H3.Server.Engine.TokenPool.GetActivityPerformance(
  193.                     instances, 
  194. task.Name);
  195. if(performance == null)
  196. {
  197. Performances.Rows.Add(
  198. new object[]{
  199. OThinker.H3.WorkflowTemplate.WorkflowTemplate.GetWorkflowFullName(WorkflowPackage, WorkflowName, WorkflowVersion), 
  200. task.Name, 
  201. 0, 
  202. null});
  203. }
  204. else
  205. {
  206. Performances.Rows.Add(
  207. new object[]{
  208. OThinker.H3.WorkflowTemplate.WorkflowTemplate.GetWorkflowFullName(WorkflowPackage, WorkflowName, WorkflowVersion), 
  209. task.Name, 
  210. performance.ExecutedTimes, 
  211. OThinker.Data.Convertor.Format(new System.TimeSpan(performance.AverageUsedTime))});
  212. }
  213. }
  214. }
  215. #region Web Form Designer generated code
  216. override protected void OnInit(EventArgs e)
  217. {
  218. //
  219. // CODEGEN: This call is required by the ASP.NET Web Form Designer.
  220. //
  221. InitializeComponent();
  222. base.OnInit(e);
  223. }
  224. /// <summary>
  225. /// Required method for Designer support - do not modify
  226. /// the contents of this method with the code editor.
  227. /// </summary>
  228. private void InitializeComponent()
  229. {    
  230. }
  231. #endregion
  232. }
  233. }