InstanceGridView.cs
资源名称:H3_OA.rar [点击查看]
上传用户:li2971742
上传日期:2021-11-18
资源大小:39096k
文件大小:21k
源码类别:
OA系统
开发平台:
C#
- using System;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.ComponentModel;
- namespace OThinker.H3.Portal
- {
- /// <summary>
- /// Summary description for InstanceGridView.
- /// </summary>
- [DefaultProperty("Text"),
- ToolboxData("<{0}:InstanceGridView runat=server></{0}:InstanceGridView>")]
- public class InstanceGridView : DataGrid
- {
- #region 列
- protected BoundColumn InstanceIDColumn = new BoundColumn();
- protected int InstanceIDColumnIndex
- {
- get
- {
- return this.Columns.IndexOf(this.InstanceIDColumn);
- }
- }
- protected BoundColumn PriorityColumn = new BoundColumn();
- protected int PriorityColumnIndex
- {
- get
- {
- return this.Columns.IndexOf(this.PriorityColumn);
- }
- }
- protected BoundColumn InstanceNameColumn = new BoundColumn();
- protected int InstanceNameColumnIndex
- {
- get
- {
- return this.Columns.IndexOf(this.InstanceNameColumn);
- }
- }
- protected BoundColumn TitleColumn = new BoundColumn();
- protected int TitleColumnIndex
- {
- get
- {
- return this.Columns.IndexOf(this.TitleColumn);
- }
- }
- protected BoundColumn OrgUnitColumn = new BoundColumn();
- protected int OrgUnitColumnIndex
- {
- get
- {
- return this.Columns.IndexOf(this.OrgUnitColumn);
- }
- }
- protected BoundColumn WorkflowPackageColumn = new BoundColumn();
- protected int WorkflowPackageColumnIndex
- {
- get
- {
- return this.Columns.IndexOf(this.WorkflowPackageColumn);
- }
- }
- protected BoundColumn WorkflowNameColumn = new BoundColumn();
- protected int WorkflowNameColumnIndex
- {
- get
- {
- return this.Columns.IndexOf(this.WorkflowNameColumn);
- }
- }
- protected BoundColumn WorkflowVersionColumn = new BoundColumn();
- protected int WorkflowVersionColumnIndex
- {
- get
- {
- return this.Columns.IndexOf(this.WorkflowVersionColumn);
- }
- }
- protected BoundColumn WorkflowFullNameColumn = new BoundColumn();
- protected int WorkflowFullNameColumnIndex
- {
- get
- {
- return this.Columns.IndexOf(this.WorkflowFullNameColumn);
- }
- }
- protected BoundColumn OriginatorColumn = new BoundColumn();
- protected int OriginatorColumnIndex
- {
- get
- {
- return this.Columns.IndexOf(this.OriginatorColumn);
- }
- }
- protected BoundColumn StateColumn = new BoundColumn();
- protected int StateColumnIndex
- {
- get
- {
- return this.Columns.IndexOf(this.StateColumn);
- }
- }
- protected BoundColumn FormattedStateColumn = new BoundColumn();
- protected int FormattedStateColumnIndex
- {
- get
- {
- return this.Columns.IndexOf(this.FormattedStateColumn);
- }
- }
- protected BoundColumn ExceptionalColumn = new BoundColumn();
- protected int ExceptionalColumnIndex
- {
- get
- {
- return this.Columns.IndexOf(this.ExceptionalColumn);
- }
- }
- protected BoundColumn SuspendedColumn = new BoundColumn();
- protected int SuspendedColumnIndex
- {
- get
- {
- return this.Columns.IndexOf(this.SuspendedColumn);
- }
- }
- protected BoundColumn CreatedTimeColumn = new BoundColumn();
- protected int CreatedTimeColumnIndex
- {
- get
- {
- return this.Columns.IndexOf(this.CreatedTimeColumn);
- }
- }
- protected BoundColumn FormattedCreatedTimeColumn = new BoundColumn();
- protected int FormattedCreatedTimeColumnIndex
- {
- get
- {
- return this.Columns.IndexOf(this.FormattedCreatedTimeColumn);
- }
- }
- protected BoundColumn StartTimeColumn = new BoundColumn();
- protected int StartTimeColumnIndex
- {
- get
- {
- return this.Columns.IndexOf(this.StartTimeColumn);
- }
- }
- protected BoundColumn FormattedStartTimeColumn = new BoundColumn();
- protected int FormattedStartTimeColumnIndex
- {
- get
- {
- return this.Columns.IndexOf(this.FormattedStartTimeColumn);
- }
- }
- protected BoundColumn FinishTimeColumn = new BoundColumn();
- protected int FinishTimeColumnIndex
- {
- get
- {
- return this.Columns.IndexOf(this.FinishTimeColumn);
- }
- }
- protected BoundColumn FormattedFinishTimeColumn = new BoundColumn();
- protected int FormattedFinishTimeColumnIndex
- {
- get
- {
- return this.Columns.IndexOf(this.FormattedFinishTimeColumn);
- }
- }
- protected BoundColumn StayTimeColumn = new BoundColumn();
- protected int StayTimeColumnIndex
- {
- get
- {
- return this.Columns.IndexOf(this.StayTimeColumn);
- }
- }
- protected BoundColumn FormattedPriorityColumn = new BoundColumn();
- protected int FormattedPriorityColumnIndex
- {
- get
- {
- return this.Columns.IndexOf(this.FormattedPriorityColumn);
- }
- }
- protected BoundColumn ViewColumn = new BoundColumn();
- protected int ViewColumnIndex
- {
- get
- {
- return this.Columns.IndexOf(this.ViewColumn);
- }
- }
- public BoundColumn PlanFinishTimeColumn = new BoundColumn();
- protected int PlanFinishTimeColumnIndex
- {
- get
- {
- return this.Columns.IndexOf(this.PlanFinishTimeColumn);
- }
- }
- public BoundColumn EstimatedFinishTimeColumn = new BoundColumn();
- protected int EstimatedFinishTimeColumnIndex
- {
- get
- {
- return this.Columns.IndexOf(this.EstimatedFinishTimeColumn);
- }
- }
- protected BoundColumn ApprovalColumn = new BoundColumn();
- protected int ApprovalColumnIndex
- {
- get
- {
- return this.Columns.IndexOf(this.ApprovalColumn);
- }
- }
- public BoundColumn RecurrencesColumn = new BoundColumn();
- protected int RecurrencesColumnIndex
- {
- get
- {
- return this.Columns.IndexOf(this.RecurrencesColumn);
- }
- }
- private void InitializeColumn(BoundColumn Column, string HeaderText, string DataField)
- {
- Column.HeaderText = HeaderText;
- Column.DataField = DataField;
- Column.ItemStyle.CssClass = this.ItemStyle.CssClass;
- this.Columns.Add(Column);
- }
- #endregion
- #region 获得单元的组合值
- // 获得流程模板的全名
- protected string GetWorkflowFullName(DataGridItemEventArgs e)
- {
- string workflowPackage = e.Item.Cells[this.WorkflowPackageColumnIndex].Text;
- string workflowName = e.Item.Cells[this.WorkflowNameColumnIndex].Text;
- string strWorkflowVersion = e.Item.Cells[this.WorkflowVersionColumnIndex].Text;
- int workflowVersion = H3.WorkflowTemplate.WorkflowTemplate.NullWorkflowVersion;
- if(strWorkflowVersion != null && strWorkflowVersion != "")
- {
- workflowVersion = int.Parse(strWorkflowVersion);
- }
- string workflowFullName = OThinker.H3.WorkflowTemplate.WorkflowTemplate.GetWorkflowFullName(
- workflowPackage,
- workflowName,
- workflowVersion);
- return workflowFullName;
- }
- protected OThinker.H3.Instance.InstanceState GetState(DataGridItemEventArgs e)
- {
- int intState = int.Parse(e.Item.Cells[this.StateColumnIndex].Text);
- return (OThinker.H3.Instance.InstanceState)intState;
- }
- protected OThinker.H3.Instance.PriorityType GetPriority(DataGridItemEventArgs e)
- {
- int intPriority = int.Parse(e.Item.Cells[this.PriorityColumnIndex].Text);
- return (OThinker.H3.Instance.PriorityType)intPriority;
- }
- protected bool GetExceptional(DataGridItemEventArgs e)
- {
- return e.Item.Cells[this.ExceptionalColumnIndex].Text == "1";
- }
- protected bool GetSuspended(DataGridItemEventArgs e)
- {
- return e.Item.Cells[this.SuspendedColumnIndex].Text == "1";
- }
- protected System.DateTime GetCreatedTime(DataGridItemEventArgs e)
- {
- return System.DateTime.Parse(e.Item.Cells[this.CreatedTimeColumnIndex].Text);
- }
- protected System.DateTime GetFinishTime(DataGridItemEventArgs e)
- {
- return System.DateTime.Parse(e.Item.Cells[this.FinishTimeColumnIndex].Text);
- }
- protected System.TimeSpan GetStayTime(DataGridItemEventArgs e)
- {
- // 滞留时间
- System.TimeSpan stayTime;
- if(this.GetState(e) == OThinker.H3.Instance.InstanceState.Complete)
- {
- stayTime = this.GetFinishTime(e).Subtract(this.GetCreatedTime(e));
- }
- else
- {
- stayTime = System.DateTime.Now.Subtract(this.GetCreatedTime(e));
- }
- return stayTime;
- }
- public const string Target = "InstanceMain";
- protected string GetUrl(DataGridItemEventArgs e)
- {
- return PortalPage.PageName_InstanceDetail + "?" + PortalPage.Param_InstanceId + "=" + e.Item.Cells[this.InstanceIDColumnIndex].Text;
- }
- protected string GetTitle(DataGridItemEventArgs e)
- {
- if (e.Item.Cells[this.InstanceNameColumnIndex].Text == null || e.Item.Cells[this.InstanceNameColumnIndex].Text.Trim() == " ")
- {
- return e.Item.Cells[this.WorkflowFullNameColumnIndex].Text;
- }
- else
- {
- return e.Item.Cells[this.InstanceNameColumnIndex].Text;
- }
- }
- #endregion
- public InstanceGridView()
- {
- this.AutoGenerateColumns = false;
- this.ItemDataBound += new DataGridItemEventHandler(Grid_ItemDataBound);
- this.PageIndexChanged += new DataGridPageChangedEventHandler(InstanceGrid_PageIndexChanged);
- this.AllowPaging = true;
- this.PagerStyle.Mode = PagerMode.NumericPages;
- this.PageSize = 25;
- this.InitializeColumn(this.InstanceIDColumn, "流程ID", OThinker.H3.Instance.InstanceContext.PropertyName_InstanceId);
- this.InitializeColumn(this.PriorityColumn, "Priority", OThinker.H3.Instance.InstanceContext.PropertyName_Priority);
- this.InitializeColumn(this.FormattedPriorityColumn, "优先级", null);
- this.InitializeColumn(this.InstanceNameColumn, "流程名称", OThinker.H3.Instance.InstanceContext.PropertyName_InstanceName);
- this.InitializeColumn(this.TitleColumn, "流程", null);
- this.InitializeColumn(this.OrgUnitColumn, "所属组织单元", OThinker.H3.Instance.InstanceContext.PropertyName_OrgUnit);
- this.InitializeColumn(this.WorkflowPackageColumn, "模板类型", OThinker.H3.Instance.InstanceContext.PropertyName_WorkflowPackage);
- this.InitializeColumn(this.WorkflowNameColumn, "模板名称", OThinker.H3.Instance.InstanceContext.PropertyName_WorkflowName);
- this.InitializeColumn(this.WorkflowVersionColumn, "模板版本", OThinker.H3.Instance.InstanceContext.PropertyName_WorkflowVersion);
- this.InitializeColumn(this.WorkflowFullNameColumn, "模板全名", null);
- this.InitializeColumn(this.OriginatorColumn, "发起人", OThinker.H3.Instance.InstanceContext.PropertyName_Originator);
- this.InitializeColumn(this.StateColumn, "State", OThinker.H3.Instance.InstanceContext.PropertyName_State);
- this.InitializeColumn(this.FormattedStateColumn, "状态", null);
- this.InitializeColumn(this.ExceptionalColumn, "异常", OThinker.H3.Instance.InstanceContext.PropertyName_Exceptional);
- this.InitializeColumn(this.SuspendedColumn, "挂起", OThinker.H3.Instance.InstanceContext.PropertyName_Suspended);
- this.InitializeColumn(this.CreatedTimeColumn, "CreatedTime", OThinker.H3.Instance.InstanceContext.PropertyName_CreatedTime);
- this.InitializeColumn(this.FormattedCreatedTimeColumn,"发起时间", null);
- this.InitializeColumn(this.StartTimeColumn, "StartTime", OThinker.H3.Instance.InstanceContext.PropertyName_StartTime);
- this.InitializeColumn(this.FormattedStartTimeColumn,"发起时间", null);
- this.InitializeColumn(this.FinishTimeColumn, "FinishTime", OThinker.H3.Instance.InstanceContext.PropertyName_FinishTime);
- this.InitializeColumn(this.FormattedFinishTimeColumn,"完成时间", null);
- this.InitializeColumn(this.StayTimeColumn, "滞留时间", null);
- this.InitializeColumn(this.PlanFinishTimeColumn, "计划完成时间", OThinker.H3.Instance.InstanceContext.PropertyName_PlanFinishTime);
- this.InitializeColumn(this.EstimatedFinishTimeColumn, "预计完成时间", OThinker.H3.Instance.InstanceContext.PropertyName_EstimatedFinishTime);
- this.InitializeColumn(this.ViewColumn, "查看", null);
- this.InitializeColumn(this.ApprovalColumn, "审批结果", OThinker.H3.Instance.InstanceContext.PropertyName_Approval);
- this.InitializeColumn(this.RecurrencesColumn, "重复次数", OThinker.H3.Instance.InstanceContext.PropertyName_Recurrences);
- this.Columns[this.InstanceNameColumnIndex].Visible = false;
- this.Columns[this.InstanceIDColumnIndex].Visible = false;
- this.Columns[this.OrgUnitColumnIndex].Visible = false;
- this.Columns[this.WorkflowPackageColumnIndex].Visible = false;
- this.Columns[this.WorkflowNameColumnIndex].Visible = false;
- this.Columns[this.WorkflowVersionColumnIndex].Visible = false;
- this.Columns[this.WorkflowFullNameColumnIndex].Visible = false;
- this.Columns[this.StateColumnIndex].Visible = false;
- this.Columns[this.CreatedTimeColumnIndex].Visible = false;
- this.Columns[this.FormattedCreatedTimeColumnIndex].Visible = false;
- this.Columns[this.StartTimeColumnIndex].Visible = false;
- this.Columns[this.FinishTimeColumnIndex].Visible = false;
- this.Columns[this.PlanFinishTimeColumnIndex].Visible = false;
- this.Columns[this.EstimatedFinishTimeColumnIndex].Visible = false;
- this.Columns[this.FormattedFinishTimeColumnIndex].Visible = false;
- this.Columns[this.PriorityColumnIndex].Visible = false;
- this.Columns[this.RecurrencesColumnIndex].Visible = false;
- this.HeaderStyle.Font.Bold = true;
- }
- private Label lblMessage = new Label();
- private System.Data.DataTable InstanceTable;
- #region 绑定
- public void BindDataGrid(System.Data.DataTable Table)
- {
- if (!this.DesignMode)
- {
- if (Table == null || this.CurrentPageIndex * this.PageSize >= Table.Rows.Count)
- {
- this.CurrentPageIndex = 0;
- }
- this.InstanceTable = Table;
- this.DataSource = Table;
- this.DataBind();
- }
- }
- protected virtual void Grid_ItemDataBound(object sender, DataGridItemEventArgs e)
- {
- if (this.DesignMode)
- {
- }
- else if(
- e.Item.ItemType != System.Web.UI.WebControls.ListItemType.Header &&
- e.Item.ItemType != System.Web.UI.WebControls.ListItemType.Footer)
- {
- try
- {
- // 设置流程模板全名
- e.Item.Cells[this.WorkflowFullNameColumnIndex].Text = this.GetWorkflowFullName(e);
- // 发起人全名
- string originator = e.Item.Cells[this.OriginatorColumnIndex].Text;
- HyperLink originatorLink = new HyperLink();
- originatorLink.Text = OThinker.H3.Server.Engine.Organization.GetName(originator);
- originatorLink.NavigateUrl = PortalPage.PageName_EditUser + "?" + PortalPage.Param_ID + "=" + originator + "&" + PortalPage.Param_Mode + "=" + Portal.EditUserType.View;
- e.Item.Cells[this.OriginatorColumnIndex].Controls.Add(originatorLink);
- // 状态
- OThinker.H3.Instance.InstanceState state = this.GetState(e);
- e.Item.Cells[this.FormattedStateColumnIndex].Text = OThinker.H3.Instance.InstanceStateConvertor.ToString(state);
- // 链接
- HyperLink linkTitle = new HyperLink();
- linkTitle.Text = this.GetTitle(e);
- linkTitle.Font.Underline = true;
- linkTitle.NavigateUrl = this.GetUrl(e);
- e.Item.Cells[this.TitleColumnIndex].Controls.Add(linkTitle);
- // 是否异常
- CheckBox exceptional = new CheckBox();
- exceptional.Enabled = false;
- exceptional.Checked = this.GetExceptional(e);;
- e.Item.Cells[this.ExceptionalColumnIndex].Controls.Add(exceptional);
- // 是否挂起
- CheckBox suspended = new CheckBox();
- suspended.Enabled = false;
- suspended.Checked = this.GetSuspended(e);
- e.Item.Cells[this.SuspendedColumnIndex].Controls.Add(suspended);
- // 创建时间
- System.DateTime createdTime = System.DateTime.Parse(e.Item.Cells[this.CreatedTimeColumnIndex].Text);
- e.Item.Cells[this.FormattedCreatedTimeColumnIndex].Text = OThinker.Data.Convertor.Format(createdTime);
- // 开始时间
- System.DateTime startTime = System.DateTime.Parse(e.Item.Cells[this.StartTimeColumnIndex].Text);
- e.Item.Cells[this.FormattedStartTimeColumnIndex].Text = startTime.ToShortDateString();
- // 完成时间
- System.DateTime finishTime = System.DateTime.Parse(e.Item.Cells[this.FinishTimeColumnIndex].Text);
- e.Item.Cells[this.FormattedFinishTimeColumnIndex].Text = OThinker.Data.Convertor.Format(finishTime);
- // 滞留时间
- System.TimeSpan stayTime = this.GetStayTime(e);
- e.Item.Cells[this.StayTimeColumnIndex].Text = OThinker.Data.Convertor.Format(stayTime);
- // 设置颜色
- System.DateTime planFinishTime = System.DateTime.Parse(e.Item.Cells[this.PlanFinishTimeColumnIndex].Text);
- if (state != OThinker.H3.Instance.InstanceState.Complete && System.DateTime.Now > planFinishTime)
- {
- e.Item.Cells[this.StayTimeColumnIndex].ForeColor = System.Drawing.Color.Red;
- }
- // 优先级
- int intPriority = int.Parse(e.Item.Cells[this.PriorityColumnIndex].Text);
- OThinker.H3.Instance.PriorityType priority = (OThinker.H3.Instance.PriorityType)intPriority;
- Image imagePriority = new Image();
- imagePriority.ImageUrl = "images/Priority_" + priority + ".GIF";
- imagePriority.ToolTip = OThinker.H3.Instance.PriorityTypeConvertor.ToString(priority);
- e.Item.Cells[this.FormattedPriorityColumnIndex].Controls.Add(imagePriority);
- // 查看
- string chartUrl = PortalPage.PageName_InstanceStateChart + "?" + PortalPage.Param_InstanceId + "=" + e.Item.Cells[this.InstanceIDColumnIndex].Text;
- string chartTitle = "流程图";
- HyperLink linkChart = new HyperLink();
- linkChart.Target = "_blank";
- linkChart.Text = chartTitle;
- linkChart.NavigateUrl = chartUrl;
- e.Item.Cells[this.ViewColumnIndex].Controls.Add(linkChart);
- // 分割符
- Label lblSplit = new Label();
- lblSplit.Text = " | ";
- e.Item.Cells[this.ViewColumnIndex].Controls.Add(lblSplit);
- // 流转日志
- string logUrl = PortalPage.PageName_InstanceToken + "?" + PortalPage.Param_InstanceId + "=" + e.Item.Cells[this.InstanceIDColumnIndex].Text;
- string logTitle = "日志";
- HyperLink linkLog = new HyperLink();
- linkLog.Target = "_blank";
- linkLog.Text = logTitle;
- linkLog.NavigateUrl = logUrl;
- e.Item.Cells[this.ViewColumnIndex].Controls.Add(linkLog);
- // Approval
- string approvalText = null;
- int approval = int.Parse(e.Item.Cells[this.ApprovalColumnIndex].Text);
- if (state == OThinker.H3.Instance.InstanceState.Complete)
- {
- switch (approval)
- {
- case (int)OThinker.Data.BoolMatchValue.True:
- approvalText = "同意";
- break;
- case (int)OThinker.Data.BoolMatchValue.False:
- approvalText = "拒绝";
- break;
- default:
- break;
- }
- }
- e.Item.Cells[this.ApprovalColumnIndex].Text = approvalText;
- }
- catch
- {
- }
- }
- }
- #endregion
- protected override void Render(HtmlTextWriter writer)
- {
- if (this.DesignMode)
- {
- base.Render(writer);
- }
- else if(this.InstanceTable == null || this.InstanceTable.Rows.Count == 0)
- {
- writer.Write("没有找到记录");
- }
- else
- {
- base.Render (writer);
- }
- }
- private void InstanceGrid_PageIndexChanged(object source, DataGridPageChangedEventArgs e)
- {
- this.CurrentPageIndex = e.NewPageIndex;
- this.DataBind();
- }
- }
- }