WorkflowActivityReport.aspx.cs
资源名称:H3_OA.rar [点击查看]
上传用户:li2971742
上传日期:2021-11-18
资源大小:39096k
文件大小:11k
源码类别:
OA系统
开发平台:
C#
- using System;
- using System.Collections;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Web;
- using System.Web.SessionState;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Web.UI.HtmlControls;
- namespace OThinker.H3.Portal
- {
- /// <summary>
- /// Summary description for WorkflowActivityReport.
- /// </summary>
- public partial class WorkflowActivityReport : WorkflowReportBase
- {
- protected void Page_Load(object sender, System.EventArgs e)
- {
- this.OriginatorSelector.SelectUserUrl = PageName_SelectUser;
- this.OriginatorSelector.SelectUserImageUrl = PageName_SelectUserImage;
- if(!this.IsPostBack)
- {
- // 验证是否具有管理员权限
- if (!this.UserValidator.ValidateViewReport())
- {
- this.NotifyMessage(LackOfAuth);
- }
- // 设置默认的搜索时间
- System.DateTime today = System.DateTime.Now;
- System.DateTime tomorrow = today.Add(new System.TimeSpan(1, 0, 0, 0, 0));
- this.txtFromTime.Text = today.ToShortDateString();
- this.txtToTime.Text = tomorrow.ToShortDateString();
- string[] catalogs = OThinker.H3.Server.Engine.WorkflowManager.GetWorkflowPackages();
- // 添加一空元素表示全部
- this.lstWorkflowPackage.Items.Add(NullItemValue);
- foreach(string catalog in catalogs)
- {
- this.lstWorkflowPackage.Items.Add(catalog);
- }
- }
- }
- #region Web Form Designer generated code
- override protected void OnInit(EventArgs e)
- {
- //
- // CODEGEN: This call is required by the ASP.NET Web Form Designer.
- //
- InitializeComponent();
- base.OnInit(e);
- }
- /// <summary>
- /// Required method for Designer support - do not modify
- /// the contents of this method with the code editor.
- /// </summary>
- private void InitializeComponent()
- {
- this.btnExport.Click += new System.Web.UI.ImageClickEventHandler(this.btnExport_Click);
- this.btnQuery.Click += new System.Web.UI.ImageClickEventHandler(this.btnQuery_Click);
- }
- #endregion
- protected void lstWorkflowPackage_SelectedIndexChanged(object sender, System.EventArgs e)
- {
- string catalog = this.lstWorkflowPackage.SelectedValue;
- if(this.IsSelectedNull(catalog))
- {
- this.lstWorkflowName.Items.Clear();
- this.lstWorkflowName.Items.Add(NullItemValue);
- this.lstWorkflowVersion.Items.Clear();
- this.lstWorkflowVersion.Items.Add(NullItemValue);
- }
- else
- {
- string[] names = OThinker.H3.Server.Engine.WorkflowManager.GetWorkflowNames(catalog, OThinker.H3.WorkflowTemplate.WorkflowState.Unspecified);
- this.lstWorkflowName.Items.Clear();
- this.lstWorkflowName.Items.Add(NullItemValue);
- foreach(string name in names)
- {
- this.lstWorkflowName.Items.Add(name);
- }
- }
- }
- protected void lstWorkflowName_SelectedIndexChanged(object sender, System.EventArgs e)
- {
- string catalog = this.lstWorkflowPackage.SelectedValue;
- string name = this.lstWorkflowName.SelectedValue;
- if(this.IsSelectedNull(name))
- {
- this.lstWorkflowVersion.Items.Clear();
- this.lstWorkflowVersion.Items.Add(NullItemValue);
- }
- else
- {
- int[] versions = OThinker.H3.Server.Engine.WorkflowManager.GetWorkflowVersions(
- catalog,
- name);
- this.lstWorkflowVersion.Items.Clear();
- this.lstWorkflowVersion.Items.Add(NullItemValue);
- if(versions != null)
- {
- foreach(int version in versions)
- {
- this.lstWorkflowVersion.Items.Add(version.ToString());
- }
- }
- }
- }
- protected void lstWorkflowVersion_SelectedIndexChanged(object sender, System.EventArgs e)
- {
- string catalog = this.lstWorkflowPackage.SelectedValue;
- string name = this.lstWorkflowName.SelectedValue;
- string strVersion = this.lstWorkflowVersion.SelectedValue;
- this.lstActivity.Items.Clear();
- this.lstActivity.Items.Add(NullItemValue);
- if(!this.IsSelectedNull(strVersion))
- {
- WorkflowTemplate.WorkflowTemplate workflow = OThinker.H3.Server.Engine.WorkflowManager.GetWorkflow(
- catalog,
- name,
- int.Parse(strVersion));
- if(workflow != null)
- {
- foreach (H3.WorkflowTemplate.ActivityTemplate activity in workflow.Activities)
- {
- this.lstActivity.Items.Add(activity.Name);
- }
- }
- }
- }
- protected override string ReportTableSessionName
- {
- get
- {
- return OThinker.H3.WorkSheet.Sessions.GetWorkflowActivityPerformance();
- }
- }
- private void btnQuery_Click(object sender, System.Web.UI.ImageClickEventArgs e)
- {
- this.Query();
- }
- protected void lnkQuery_Click(object sender, System.EventArgs e)
- {
- this.Query();
- }
- private void Query()
- {
- string catalog = this.ParseWorkflowPackage(this.lstWorkflowPackage.SelectedValue);
- string name = this.ParseWorkflowName(this.lstWorkflowName.SelectedValue);
- int version = this.ParseWorkflowVersion(this.lstWorkflowVersion.SelectedValue);
- string activityName = null;
- if(!this.IsSelectedNull(this.lstActivity.SelectedValue))
- {
- activityName = this.lstActivity.SelectedValue;
- }
- System.DateTime from = this.ParseFromTime(this.txtFromTime.Text);
- System.DateTime to = this.ParseToTime(this.txtToTime.Text);
- this.ReportTable = new DataTable();
- this.ReportTable.Columns.Add("模板全名");
- this.ReportTable.Columns.Add("活动名称");
- this.ReportTable.Columns.Add("执行次数");
- this.ReportTable.Columns.Add("平均完成时间");
- if(catalog == null)
- {
- // 显示所有流程的所有任务的性能
- string[] catalogs = OThinker.H3.Server.Engine.WorkflowManager.GetWorkflowPackages();
- if(catalogs != null)
- {
- foreach(string c in catalogs)
- {
- string[] names = OThinker.H3.Server.Engine.WorkflowManager.GetWorkflowNames(c, OThinker.H3.WorkflowTemplate.WorkflowState.Unspecified);
- if(names != null)
- {
- foreach(string n in names)
- {
- int[] versions = OThinker.H3.Server.Engine.WorkflowManager.GetWorkflowVersions(c, n);
- if(versions != null)
- {
- foreach(int v in versions)
- {
- this.GetPerformance(
- this.ReportTable,
- c,
- n,
- v,
- activityName,
- from,
- to);
- }
- }
- }
- }
- }
- }
- }
- else if(name == null)
- {
- // 显示某个类型下的所有流程的所有任务的性能
- string[] names = OThinker.H3.Server.Engine.WorkflowManager.GetWorkflowNames(catalog, OThinker.H3.WorkflowTemplate.WorkflowState.Unspecified);
- if(names != null)
- {
- foreach(string n in names)
- {
- int[] versions = OThinker.H3.Server.Engine.WorkflowManager.GetWorkflowVersions(catalog, n);
- if(versions != null)
- {
- foreach(int v in versions)
- {
- this.GetPerformance(
- this.ReportTable,
- catalog,
- n,
- v,
- activityName,
- from,
- to);
- }
- }
- }
- }
- }
- else if (version == OThinker.H3.WorkflowTemplate.WorkflowTemplate.NullWorkflowVersion || version == OThinker.H3.WorkflowTemplate.WorkflowTemplate.AllWorkflowVersion)
- {
- // 某个流程所有版本的所有任务
- int[] versions = OThinker.H3.Server.Engine.WorkflowManager.GetWorkflowVersions(catalog, name);
- if(versions != null)
- {
- foreach(int v in versions)
- {
- this.GetPerformance(
- this.ReportTable,
- catalog,
- name,
- v,
- activityName,
- from,
- to);
- }
- }
- }
- else
- {
- this.GetPerformance(
- this.ReportTable,
- catalog,
- name,
- version,
- activityName,
- from,
- to);
- }
- this.PerformanceGrid.DataSource = this.ReportTable;
- this.PerformanceGrid.DataBind();
- }
- // 获得某个流程的某个任务的性能,结果存放在Performances表中
- private void GetPerformance(
- System.Data.DataTable Performances,
- string WorkflowPackage,
- string WorkflowName,
- int WorkflowVersion,
- string ActivityName,
- System.DateTime From,
- System.DateTime To)
- {
- // 获得在这个时间段内的所有流程实例
- // 注意:这里必须获得已完成的任务,如果一个任务未完成可能会导致计算的平均值为负
- string[] instances = OThinker.H3.Server.Engine.InstanceManager.Query(
- null,
- null,
- OThinker.H3.Instance.InstanceContext.UnspecifiedID,
- OThinker.H3.Instance.InstanceState.Complete,
- WorkflowPackage,
- WorkflowName,
- WorkflowVersion,
- From,
- To,
- null);
- // 如果指定是某一个Activity则查询该Activity的性能,否则查询所有活动的性能
- if(ActivityName != null)
- {
- this.GetPerformance(
- Performances,
- WorkflowPackage,
- WorkflowName,
- WorkflowVersion,
- instances,
- ActivityName);
- }
- else
- {
- // 获得该流程
- OThinker.H3.WorkflowTemplate.WorkflowTemplate process = OThinker.H3.Server.Engine.WorkflowManager.GetWorkflow(
- WorkflowPackage,
- WorkflowName,
- WorkflowVersion);
- // 获得该流程的每个任务的性能
- foreach(OThinker.H3.WorkflowTemplate.ActivityTemplate task in process.Activities)
- {
- this.GetPerformance(
- Performances,
- WorkflowPackage,
- WorkflowName,
- WorkflowVersion,
- instances,
- task.Name);
- }
- }
- }
- private void GetPerformance(
- System.Data.DataTable PerformanceTable,
- string WorkflowPackage,
- string WorkflowName,
- int WorkflowVersion,
- string[] Instances,
- string ActivityName)
- {
- OThinker.H3.WorkflowTemplate.ActivityPerformance performance
- = OThinker.H3.Server.Engine.TokenPool.GetActivityPerformance(
- Instances,
- ActivityName);
- if(performance == null)
- {
- PerformanceTable.Rows.Add(
- new object[]{
- OThinker.H3.WorkflowTemplate.WorkflowTemplate.GetWorkflowFullName(WorkflowPackage, WorkflowName, WorkflowVersion),
- ActivityName,
- 0,
- null});
- }
- else
- {
- PerformanceTable.Rows.Add(
- new object[]{
- OThinker.H3.WorkflowTemplate.WorkflowTemplate.GetWorkflowFullName(WorkflowPackage, WorkflowName, WorkflowVersion),
- ActivityName,
- performance.ExecutedTimes,
- OThinker.Data.Convertor.Format(new System.TimeSpan(performance.AverageUsedTime))});
- }
- }
- protected void lnkExport_Click(object sender, System.EventArgs e)
- {
- this.Export();
- }
- private void btnExport_Click(object sender, System.Web.UI.ImageClickEventArgs e)
- {
- this.Export();
- }
- }
- }