WorkItemGrid.cs
资源名称:H3_OA.rar [点击查看]
上传用户:li2971742
上传日期:2021-11-18
资源大小:39096k
文件大小:20k
源码类别:
OA系统
开发平台:
C#
- using System;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.ComponentModel;
- namespace OThinker.H3.Portal
- {
- /// <summary>
- /// Summary description for WorkItemGrid.
- /// </summary>
- [DefaultProperty("Text"), ToolboxData("<{0}:WorkItemGrid runat=server></{0}:WorkItemGrid>")]
- public class WorkItemGrid : DataGrid
- {
- #region 列集合
- protected BoundColumn WorkItemIDColumn = new BoundColumn();
- protected int WorkItemIDColumnIndex
- {
- get
- {
- return this.Columns.IndexOf(this.WorkItemIDColumn);
- }
- }
- protected BoundColumn PriorityColumn = new BoundColumn();
- protected int PriorityColumnIndex
- {
- get
- {
- return this.Columns.IndexOf(this.PriorityColumn);
- }
- }
- protected BoundColumn InstanceIDColumn = new BoundColumn();
- protected int InstanceIDColumnIndex
- {
- get
- {
- return this.Columns.IndexOf(this.InstanceIDColumn);
- }
- }
- protected BoundColumn TokenIDColumn = new BoundColumn();
- protected int TokenIDColumnIndex
- {
- get
- {
- return this.Columns.IndexOf(this.TokenIDColumn);
- }
- }
- protected BoundColumn InstanceNameColumn = new BoundColumn();
- protected int InstanceNameColumnIndex
- {
- get
- {
- return this.Columns.IndexOf(this.InstanceNameColumn);
- }
- }
- 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 OriginatorColumn = new BoundColumn();
- protected int OriginatorColumnIndex
- {
- get
- {
- return this.Columns.IndexOf(this.OriginatorColumn);
- }
- }
- protected BoundColumn ActivityNameColumn = new BoundColumn();
- protected int ActivityNameColumnIndex
- {
- get
- {
- return this.Columns.IndexOf(this.ActivityNameColumn);
- }
- }
- protected BoundColumn SheetTypeColumn = new BoundColumn();
- protected int SheetTypeColumnIndex
- {
- get
- {
- return this.Columns.IndexOf(this.SheetTypeColumn);
- }
- }
- protected BoundColumn SheetAddressColumn = new BoundColumn();
- protected int SheetAddressColumnIndex
- {
- get
- {
- return this.Columns.IndexOf(this.SheetAddressColumn);
- }
- }
- protected BoundColumn DisplayNameColumn = new BoundColumn();
- protected int DisplayNameColumnIndex
- {
- get
- {
- return this.Columns.IndexOf(this.DisplayNameColumn);
- }
- }
- protected BoundColumn TitleColumn = new BoundColumn();
- protected int TitleColumnIndex
- {
- get
- {
- return this.Columns.IndexOf(this.TitleColumn);
- }
- }
- protected BoundColumn StateColumn = new BoundColumn();
- protected int StateColumnIndex
- {
- get
- {
- return this.Columns.IndexOf(this.StateColumn);
- }
- }
- protected BoundColumn ReceiveTimeColumn = new BoundColumn();
- protected int ReceiveTimeColumnIndex
- {
- get
- {
- return this.Columns.IndexOf(this.ReceiveTimeColumn);
- }
- }
- protected BoundColumn FinishTimeColumn = new BoundColumn();
- protected int FinishTimeColumnIndex
- {
- get
- {
- return this.Columns.IndexOf(this.FinishTimeColumn);
- }
- }
- protected BoundColumn ParticipantColumn = new BoundColumn();
- protected int ParticipantColumnIndex
- {
- get
- {
- return this.Columns.IndexOf(this.ParticipantColumn);
- }
- }
- protected BoundColumn UrgencyColumn = new BoundColumn();
- protected int UrgencyColumnIndex
- {
- get
- {
- return this.Columns.IndexOf(this.UrgencyColumn);
- }
- }
- protected BoundColumn ViewColumn = new BoundColumn();
- protected int ViewColumnIndex
- {
- get
- {
- return this.Columns.IndexOf(this.ViewColumn);
- }
- }
- protected BoundColumn ApprovalColumn = new BoundColumn();
- protected int ApprovalColumnIndex
- {
- get
- {
- return this.Columns.IndexOf(this.ApprovalColumn);
- }
- }
- 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 GetOriginatorFullName(DataGridItemEventArgs e)
- {
- return e.Item.Cells[this.OriginatorColumnIndex].Text;
- }
- // 获得参与人全名
- protected string GetParticipantFullName(DataGridItemEventArgs e)
- {
- string participant = e.Item.Cells[this.ParticipantColumnIndex].Text;
- return OThinker.H3.Server.Engine.Organization.GetFullName(participant);
- }
- // 状态
- protected OThinker.H3.WorkItem.WorkItemState GetState(DataGridItemEventArgs e)
- {
- int intState = (int)OThinker.H3.WorkItem.WorkItemState.Unfinished;
- string strState = e.Item.Cells[this.StateColumnIndex].Text;
- if(strState != null && strState != "")
- {
- intState = int.Parse(strState);
- }
- return (OThinker.H3.WorkItem.WorkItemState)intState;
- }
- // 获得优先级别
- protected OThinker.H3.Instance.PriorityType GetPriority(DataGridItemEventArgs e)
- {
- string strPriority = e.Item.Cells[this.PriorityColumnIndex].Text;
- int intPriority = (int)OThinker.H3.Instance.PriorityType.Normal;
- if(strPriority != null && strPriority != "")
- {
- intPriority = int.Parse(strPriority);
- }
- return (OThinker.H3.Instance.PriorityType)intPriority;
- }
- // 获得流程模板的全名
- 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 System.DateTime GetReceiveTime(DataGridItemEventArgs e)
- {
- // 接收时间
- string strReceiveTime = e.Item.Cells[this.ReceiveTimeColumnIndex].Text;
- System.DateTime receiveTime = System.DateTime.MinValue;
- if(strReceiveTime != null && strReceiveTime != "")
- {
- receiveTime = System.DateTime.Parse(strReceiveTime);
- }
- return receiveTime;
- }
- protected System.DateTime GetFinishTime(DataGridItemEventArgs e)
- {
- string strFinishTime = e.Item.Cells[this.FinishTimeColumnIndex].Text;
- System.DateTime finishTime = System.DateTime.MaxValue;
- if(strFinishTime != null && strFinishTime != "")
- {
- finishTime = System.DateTime.Parse(strFinishTime);
- }
- return finishTime;
- }
- protected System.TimeSpan GetStayTime(DataGridItemEventArgs e)
- {
- System.TimeSpan stayTime;
- if(this.GetState(e) == OThinker.H3.WorkItem.WorkItemState.Finished)
- {
- stayTime = this.GetFinishTime(e).Subtract(this.GetReceiveTime(e));
- }
- else
- {
- stayTime = System.DateTime.Now.Subtract(this.GetReceiveTime(e));
- }
- return stayTime;
- }
- public const string Target = "WorkItemMain";
- // 获得链接的全地址
- protected string GetFullUrl(DataGridItemEventArgs e)
- {
- return PortalPage.PageName_WorkItemDetail + "?" + PortalPage.Param_WorkItemID + "=" + e.Item.Cells[this.WorkItemIDColumnIndex].Text;
- }
- protected string GetDisplayName(DataGridItemEventArgs e)
- {
- string displayName = e.Item.Cells[this.DisplayNameColumnIndex].Text;
- // 如果没有设置显示名称,则使用默认名称
- if (displayName == null || displayName == "" || displayName == " ")
- {
- displayName = e.Item.Cells[this.ActivityNameColumnIndex].Text;
- }
- return displayName;
- }
- protected string GetInstanceInfo(DataGridItemEventArgs e)
- {
- return this.GetWorkflowFullName(e); // +"." + e.Item.Cells[this.InstanceIDColumnIndex].Text;
- }
- #endregion
- public WorkItemGrid()
- {
- this.AutoGenerateColumns = false;
- this.ItemDataBound += new DataGridItemEventHandler(Grid_ItemDataBound);
- this.PageIndexChanged += new DataGridPageChangedEventHandler(WorkItemGrid_PageIndexChanged);
- this.AllowPaging = true;
- this.PagerStyle.Mode = PagerMode.NumericPages;
- this.PageSize = 25;
- this.InitializeColumn(this.UrgencyColumn, "催办", OThinker.H3.WorkItem.WorkItem.PropertyName_Urgency);
- this.InitializeColumn(this.TitleColumn, "工作项", null);
- this.InitializeColumn(this.WorkItemIDColumn, "ObjectID", OThinker.Data.Database.Serialization.T_Entity.C_ObjectID);
- this.InitializeColumn(this.PriorityColumn, "优先级", OThinker.H3.WorkItem.WorkItem.PropertyName_Priority);
- this.InitializeColumn(this.InstanceIDColumn, "流程ID", OThinker.H3.WorkItem.WorkItem.PropertyName_InstanceId);
- this.InitializeColumn(this.TokenIDColumn, "TokenId", OThinker.H3.WorkItem.WorkItem.PropertyName_TokenId);
- this.InitializeColumn(this.InstanceNameColumn, "流程名称", OThinker.H3.WorkItem.WorkItem.PropertyName_InstanceName);
- this.InitializeColumn(this.WorkflowPackageColumn, "模板类型", OThinker.H3.WorkItem.WorkItem.PropertyName_WorkflowPackage);
- this.InitializeColumn(this.WorkflowNameColumn, "模板名称", OThinker.H3.WorkItem.WorkItem.PropertyName_WorkflowName);
- this.InitializeColumn(this.WorkflowVersionColumn, "模板版本", OThinker.H3.WorkItem.WorkItem.PropertyName_WorkflowVersion);
- this.InitializeColumn(this.OriginatorColumn, "发起人", OThinker.H3.WorkItem.WorkItem.PropertyName_Originator);
- this.InitializeColumn(this.ActivityNameColumn, "ActivityName", OThinker.H3.WorkItem.WorkItem.PropertyName_ActivityName);
- this.InitializeColumn(this.SheetTypeColumn, "SheetType", OThinker.H3.WorkItem.WorkItem.PropertyName_SheetType);
- this.InitializeColumn(this.SheetAddressColumn, "SheetAddress", OThinker.H3.WorkItem.WorkItem.PropertyName_SheetAddress);
- this.InitializeColumn(this.DisplayNameColumn, "DisplayName", OThinker.H3.WorkItem.WorkItem.PropertyName_DisplayName);
- this.InitializeColumn(this.StateColumn, "状态", OThinker.H3.WorkItem.WorkItem.PropertyName_State);
- this.InitializeColumn(this.ReceiveTimeColumn, "接收时间", OThinker.H3.WorkItem.WorkItem.PropertyName_ReceiveTime);
- this.InitializeColumn(this.FinishTimeColumn, "完成时间", OThinker.H3.WorkItem.WorkItem.PropertyName_FinishTime);
- this.InitializeColumn(this.ParticipantColumn, "处理人", OThinker.H3.WorkItem.WorkItem.PropertyName_Participant);
- this.InitializeColumn(this.ViewColumn, "查看", null);
- this.InitializeColumn(this.ApprovalColumn, "审批结果", OThinker.H3.WorkItem.WorkItem.PropertyName_Approval);
- this.Columns[this.WorkItemIDColumnIndex].Visible = false;
- this.Columns[this.InstanceIDColumnIndex].Visible = false;
- this.Columns[this.TokenIDColumnIndex].Visible = false;
- this.Columns[this.WorkflowPackageColumnIndex].Visible = false;
- this.Columns[this.WorkflowNameColumnIndex].Visible = false;
- this.Columns[this.WorkflowVersionColumnIndex].Visible = false;
- this.Columns[this.SheetTypeColumnIndex].Visible = false;
- this.Columns[this.SheetAddressColumnIndex].Visible = false;
- this.Columns[this.DisplayNameColumnIndex].Visible = false;
- this.Columns[this.FinishTimeColumnIndex].Visible = false;
- this.Columns[this.ActivityNameColumnIndex].Visible = false;
- this.Columns[this.StateColumnIndex].Visible = false;
- this.Columns[this.PriorityColumnIndex].Visible = false;
- }
- private System.Data.DataTable WorkItemTable;
- public void BindDataGrid(System.Data.DataTable Table)
- {
- if (!this.DesignMode)
- {
- if (Table == null || this.CurrentPageIndex * this.PageSize >= Table.Rows.Count)
- {
- this.CurrentPageIndex = 0;
- }
- this.WorkItemTable = Table;
- this.DataSource = Table;
- this.DataBind();
- }
- }
- protected override void Render(HtmlTextWriter writer)
- {
- if (!this.DesignMode && (this.WorkItemTable == null || this.WorkItemTable.Rows.Count == 0))
- {
- writer.Write("没有找到工作项");
- }
- else
- {
- base.Render(writer);
- }
- }
- protected virtual void Grid_ItemDataBound(object sender, DataGridItemEventArgs e)
- {
- if (this.DesignMode)
- {
- }
- else if (e.Item.ItemType != ListItemType.Header && e.Item.ItemType != ListItemType.Footer)
- {
- // 流程名称
- string instanceName = e.Item.Cells[this.InstanceNameColumnIndex].Text;
- if (instanceName == null || instanceName == "" || instanceName == " ")
- {
- instanceName = this.GetInstanceInfo(e);
- }
- e.Item.Cells[this.InstanceNameColumnIndex].Text = instanceName;
- // 名称和连接
- HyperLink link = new HyperLink();
- if (!this.DesignMode)
- {
- link.Text = "第" + e.Item.Cells[this.TokenIDColumnIndex].Text + "步:" + this.GetDisplayName(e);
- link.NavigateUrl = this.GetFullUrl(e);
- link.Font.Underline = true;
- // link.Target = Target;
- }
- e.Item.Cells[this.TitleColumnIndex].Controls.Add(link);
- // 优先级
- 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.PriorityColumnIndex].Controls.Add(imagePriority);
- // 发起人
- 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);
- // 处理人
- string participant = e.Item.Cells[this.ParticipantColumnIndex].Text;
- HyperLink participantLink = new HyperLink();
- participantLink.Text = OThinker.H3.Server.Engine.Organization.GetName(participant);
- participantLink.NavigateUrl = PortalPage.PageName_EditUser + "?" + PortalPage.Param_ID + "=" + participant + "&" + PortalPage.Param_Mode + "=" + Portal.EditUserType.View;
- e.Item.Cells[this.ParticipantColumnIndex].Controls.Add(participantLink);
- // 主题
- System.TimeSpan stayTime = this.GetStayTime(e);
- // 设置颜色
- if (stayTime < OThinker.H3.Server.Engine.SettingManager.WorkItemYellowWarningTimeSpan)
- {
- e.Item.Cells[this.ReceiveTimeColumnIndex].ForeColor = System.Drawing.Color.Black;
- }
- else if (stayTime < OThinker.H3.Server.Engine.SettingManager.WorkItemRedWarningTimeSpan)
- {
- e.Item.Cells[this.ReceiveTimeColumnIndex].ForeColor = System.Drawing.Color.Brown;
- }
- else
- {
- e.Item.Cells[this.ReceiveTimeColumnIndex].ForeColor = System.Drawing.Color.Red;
- }
- // 查看
- 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);
- // 催办
- string urgency = e.Item.Cells[this.UrgencyColumnIndex].Text;
- if (urgency != null && urgency.Trim() != "" && urgency != " ")
- {
- Image imgUrgency = new Image();
- imgUrgency.ImageUrl = "images/IB_Urgency.gif";
- imgUrgency.ToolTip = urgency;
- e.Item.Cells[this.UrgencyColumnIndex].Controls.Add(imgUrgency);
- }
- // Approval
- string approvalText = null;
- int approval = int.Parse(e.Item.Cells[this.ApprovalColumnIndex].Text);
- if (this.GetState(e) == OThinker.H3.WorkItem.WorkItemState.Finished)
- {
- 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;
- }
- }
- private void WorkItemGrid_PageIndexChanged(object source, DataGridPageChangedEventArgs e)
- {
- this.CurrentPageIndex = e.NewPageIndex;
- this.DataBind();
- }
- }
- }