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

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 WorkflowActivityReport.
  15. /// </summary>
  16.     public partial class WorkflowActivityReport : WorkflowReportBase
  17. {
  18. protected void Page_Load(object sender, System.EventArgs e)
  19. {
  20.             this.OriginatorSelector.SelectUserUrl = PageName_SelectUser;
  21.             this.OriginatorSelector.SelectUserImageUrl = PageName_SelectUserImage;
  22. if(!this.IsPostBack)
  23. {
  24.                 // 验证是否具有管理员权限
  25.                 if (!this.UserValidator.ValidateViewReport())
  26.                 {
  27.                     this.NotifyMessage(LackOfAuth);
  28.                 }
  29. // 设置默认的搜索时间
  30. System.DateTime today = System.DateTime.Now;
  31. System.DateTime tomorrow = today.Add(new System.TimeSpan(1, 0, 0, 0, 0));
  32. this.txtFromTime.Text = today.ToShortDateString();
  33. this.txtToTime.Text = tomorrow.ToShortDateString();
  34.                 string[] catalogs = OThinker.H3.Server.Engine.WorkflowManager.GetWorkflowPackages();
  35. // 添加一空元素表示全部
  36. this.lstWorkflowPackage.Items.Add(NullItemValue);
  37. foreach(string catalog in catalogs)
  38. {
  39. this.lstWorkflowPackage.Items.Add(catalog);
  40. }
  41. }
  42. }
  43. #region Web Form Designer generated code
  44. override protected void OnInit(EventArgs e)
  45. {
  46. //
  47. // CODEGEN: This call is required by the ASP.NET Web Form Designer.
  48. //
  49. InitializeComponent();
  50. base.OnInit(e);
  51. }
  52. /// <summary>
  53. /// Required method for Designer support - do not modify
  54. /// the contents of this method with the code editor.
  55. /// </summary>
  56. private void InitializeComponent()
  57. {    
  58. this.btnExport.Click += new System.Web.UI.ImageClickEventHandler(this.btnExport_Click);
  59. this.btnQuery.Click += new System.Web.UI.ImageClickEventHandler(this.btnQuery_Click);
  60. }
  61. #endregion
  62. protected void lstWorkflowPackage_SelectedIndexChanged(object sender, System.EventArgs e)
  63. {
  64. string catalog = this.lstWorkflowPackage.SelectedValue;
  65. if(this.IsSelectedNull(catalog))
  66. {
  67. this.lstWorkflowName.Items.Clear();
  68. this.lstWorkflowName.Items.Add(NullItemValue);
  69. this.lstWorkflowVersion.Items.Clear();
  70. this.lstWorkflowVersion.Items.Add(NullItemValue);
  71. }
  72. else
  73. {
  74.                 string[] names = OThinker.H3.Server.Engine.WorkflowManager.GetWorkflowNames(catalog, OThinker.H3.WorkflowTemplate.WorkflowState.Unspecified);
  75. this.lstWorkflowName.Items.Clear();
  76. this.lstWorkflowName.Items.Add(NullItemValue);
  77. foreach(string name in names)
  78. {
  79. this.lstWorkflowName.Items.Add(name);
  80. }
  81. }
  82. }
  83. protected void lstWorkflowName_SelectedIndexChanged(object sender, System.EventArgs e)
  84. {
  85. string catalog = this.lstWorkflowPackage.SelectedValue;
  86. string name = this.lstWorkflowName.SelectedValue;
  87. if(this.IsSelectedNull(name))
  88. {
  89. this.lstWorkflowVersion.Items.Clear();
  90. this.lstWorkflowVersion.Items.Add(NullItemValue);
  91. }
  92. else
  93. {
  94. int[] versions = OThinker.H3.Server.Engine.WorkflowManager.GetWorkflowVersions(
  95. catalog, 
  96. name);
  97. this.lstWorkflowVersion.Items.Clear();
  98. this.lstWorkflowVersion.Items.Add(NullItemValue);
  99. if(versions != null)
  100. {
  101. foreach(int version in versions)
  102. {
  103. this.lstWorkflowVersion.Items.Add(version.ToString());
  104. }
  105. }
  106. }
  107. }
  108. protected void lstWorkflowVersion_SelectedIndexChanged(object sender, System.EventArgs e)
  109. {
  110. string catalog = this.lstWorkflowPackage.SelectedValue;
  111. string name = this.lstWorkflowName.SelectedValue;
  112. string strVersion = this.lstWorkflowVersion.SelectedValue;
  113. this.lstActivity.Items.Clear();
  114. this.lstActivity.Items.Add(NullItemValue);
  115. if(!this.IsSelectedNull(strVersion))
  116. {
  117.                 WorkflowTemplate.WorkflowTemplate workflow = OThinker.H3.Server.Engine.WorkflowManager.GetWorkflow(
  118. catalog, 
  119. name, 
  120. int.Parse(strVersion));
  121. if(workflow != null)
  122. {
  123.                     foreach (H3.WorkflowTemplate.ActivityTemplate activity in workflow.Activities)
  124. {
  125. this.lstActivity.Items.Add(activity.Name);
  126. }
  127. }
  128. }
  129. }
  130. protected override string ReportTableSessionName
  131. {
  132. get
  133. {
  134. return OThinker.H3.WorkSheet.Sessions.GetWorkflowActivityPerformance();
  135. }
  136. }
  137. private void btnQuery_Click(object sender, System.Web.UI.ImageClickEventArgs e)
  138. {
  139. this.Query();
  140. }
  141. protected void lnkQuery_Click(object sender, System.EventArgs e)
  142. {
  143. this.Query();
  144. }
  145. private void Query()
  146. {
  147. string catalog = this.ParseWorkflowPackage(this.lstWorkflowPackage.SelectedValue);
  148. string name = this.ParseWorkflowName(this.lstWorkflowName.SelectedValue);
  149. int version = this.ParseWorkflowVersion(this.lstWorkflowVersion.SelectedValue);
  150. string activityName = null;
  151. if(!this.IsSelectedNull(this.lstActivity.SelectedValue))
  152. {
  153. activityName = this.lstActivity.SelectedValue;
  154. }
  155. System.DateTime from = this.ParseFromTime(this.txtFromTime.Text);
  156. System.DateTime to = this.ParseToTime(this.txtToTime.Text);
  157. this.ReportTable = new DataTable();
  158. this.ReportTable.Columns.Add("模板全名");
  159. this.ReportTable.Columns.Add("活动名称");
  160. this.ReportTable.Columns.Add("执行次数");
  161. this.ReportTable.Columns.Add("平均完成时间");
  162. if(catalog == null)
  163. {
  164. // 显示所有流程的所有任务的性能
  165.                 string[] catalogs = OThinker.H3.Server.Engine.WorkflowManager.GetWorkflowPackages();
  166. if(catalogs != null)
  167. {
  168. foreach(string c in catalogs)
  169. {
  170.                         string[] names = OThinker.H3.Server.Engine.WorkflowManager.GetWorkflowNames(c, OThinker.H3.WorkflowTemplate.WorkflowState.Unspecified);
  171. if(names != null)
  172. {
  173. foreach(string n in names)
  174. {
  175. int[] versions = OThinker.H3.Server.Engine.WorkflowManager.GetWorkflowVersions(c, n);
  176. if(versions != null)
  177. {
  178. foreach(int v in versions)
  179. {
  180. this.GetPerformance(
  181. this.ReportTable, 
  182. c, 
  183. n, 
  184. v, 
  185. activityName, 
  186. from, 
  187. to);
  188. }
  189. }
  190. }
  191. }
  192. }
  193. }
  194. }
  195. else if(name == null)
  196. {
  197. // 显示某个类型下的所有流程的所有任务的性能
  198.                 string[] names = OThinker.H3.Server.Engine.WorkflowManager.GetWorkflowNames(catalog, OThinker.H3.WorkflowTemplate.WorkflowState.Unspecified);
  199. if(names != null)
  200. {
  201. foreach(string n in names)
  202. {
  203. int[] versions = OThinker.H3.Server.Engine.WorkflowManager.GetWorkflowVersions(catalog, n);
  204. if(versions != null)
  205. {
  206. foreach(int v in versions)
  207. {
  208. this.GetPerformance(
  209. this.ReportTable, 
  210. catalog, 
  211. n, 
  212. v, 
  213. activityName, 
  214. from, 
  215. to);
  216. }
  217. }
  218. }
  219. }
  220. }
  221.             else if (version == OThinker.H3.WorkflowTemplate.WorkflowTemplate.NullWorkflowVersion || version == OThinker.H3.WorkflowTemplate.WorkflowTemplate.AllWorkflowVersion)
  222. {
  223. // 某个流程所有版本的所有任务
  224. int[] versions = OThinker.H3.Server.Engine.WorkflowManager.GetWorkflowVersions(catalog, name);
  225. if(versions != null)
  226. {
  227. foreach(int v in versions)
  228. {
  229. this.GetPerformance(
  230. this.ReportTable, 
  231. catalog, 
  232. name, 
  233. v, 
  234. activityName, 
  235. from, 
  236. to);
  237. }
  238. }
  239. }
  240. else
  241. {
  242. this.GetPerformance(
  243. this.ReportTable, 
  244. catalog, 
  245. name, 
  246. version, 
  247. activityName, 
  248. from, 
  249. to);
  250. }
  251. this.PerformanceGrid.DataSource = this.ReportTable;
  252. this.PerformanceGrid.DataBind();
  253. }
  254. // 获得某个流程的某个任务的性能,结果存放在Performances表中
  255. private void GetPerformance(
  256. System.Data.DataTable Performances, 
  257. string WorkflowPackage, 
  258. string WorkflowName, 
  259. int WorkflowVersion, 
  260. string ActivityName, 
  261. System.DateTime From, 
  262. System.DateTime To)
  263. {
  264. // 获得在这个时间段内的所有流程实例
  265. // 注意:这里必须获得已完成的任务,如果一个任务未完成可能会导致计算的平均值为负
  266. string[] instances = OThinker.H3.Server.Engine.InstanceManager.Query(
  267. null, 
  268. null, 
  269. OThinker.H3.Instance.InstanceContext.UnspecifiedID, 
  270. OThinker.H3.Instance.InstanceState.Complete, 
  271. WorkflowPackage, 
  272. WorkflowName, 
  273. WorkflowVersion, 
  274. From, 
  275. To, 
  276.                 null);
  277. // 如果指定是某一个Activity则查询该Activity的性能,否则查询所有活动的性能
  278. if(ActivityName != null)
  279. {
  280. this.GetPerformance(
  281.                     Performances, 
  282.                     WorkflowPackage, 
  283. WorkflowName, 
  284. WorkflowVersion, 
  285.                     instances, 
  286.                     ActivityName);
  287. }
  288. else
  289. {
  290. // 获得该流程
  291.                 OThinker.H3.WorkflowTemplate.WorkflowTemplate process = OThinker.H3.Server.Engine.WorkflowManager.GetWorkflow(
  292. WorkflowPackage, 
  293. WorkflowName, 
  294. WorkflowVersion);
  295. // 获得该流程的每个任务的性能
  296. foreach(OThinker.H3.WorkflowTemplate.ActivityTemplate task in process.Activities)
  297. {
  298. this.GetPerformance(
  299.                         Performances, 
  300.                         WorkflowPackage, 
  301. WorkflowName, 
  302. WorkflowVersion, 
  303.                         instances, 
  304.                         task.Name);
  305. }
  306. }
  307. }
  308. private void GetPerformance(
  309. System.Data.DataTable PerformanceTable, 
  310. string WorkflowPackage, 
  311. string WorkflowName, 
  312. int WorkflowVersion, 
  313. string[] Instances, 
  314. string ActivityName)
  315. {
  316. OThinker.H3.WorkflowTemplate.ActivityPerformance performance 
  317. = OThinker.H3.Server.Engine.TokenPool.GetActivityPerformance(
  318.                 Instances, 
  319. ActivityName);
  320. if(performance == null)
  321. {
  322. PerformanceTable.Rows.Add(
  323. new object[]{
  324. OThinker.H3.WorkflowTemplate.WorkflowTemplate.GetWorkflowFullName(WorkflowPackage, WorkflowName, WorkflowVersion), 
  325. ActivityName, 
  326. 0, 
  327. null});
  328. }
  329. else
  330. {
  331. PerformanceTable.Rows.Add(
  332. new object[]{
  333. OThinker.H3.WorkflowTemplate.WorkflowTemplate.GetWorkflowFullName(WorkflowPackage, WorkflowName, WorkflowVersion), 
  334. ActivityName, 
  335. performance.ExecutedTimes, 
  336. OThinker.Data.Convertor.Format(new System.TimeSpan(performance.AverageUsedTime))});
  337. }
  338. }
  339. protected void lnkExport_Click(object sender, System.EventArgs e)
  340. {
  341. this.Export();
  342. }
  343. private void btnExport_Click(object sender, System.Web.UI.ImageClickEventArgs e)
  344. {
  345. this.Export();
  346. }
  347. }
  348. }