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

OA系统

开发平台:

C#

  1. using System;
  2. using System.Web.UI;
  3. using System.Web.UI.WebControls;
  4. using System.ComponentModel;
  5. namespace OThinker.H3.Portal
  6. {
  7. /// <summary>
  8. /// Summary description for WorkItemGrid.
  9. /// </summary>
  10. [DefaultProperty("Text"), ToolboxData("<{0}:WorkItemGrid runat=server></{0}:WorkItemGrid>")]
  11. public class WorkItemGrid : DataGrid
  12. {
  13. #region 列集合
  14. protected BoundColumn WorkItemIDColumn = new BoundColumn();
  15. protected int WorkItemIDColumnIndex
  16. {
  17. get
  18. {
  19. return this.Columns.IndexOf(this.WorkItemIDColumn);
  20. }
  21. }
  22.         protected BoundColumn PriorityColumn = new BoundColumn();
  23.         protected int PriorityColumnIndex
  24.         {
  25.             get
  26.             {
  27.                 return this.Columns.IndexOf(this.PriorityColumn);
  28.             }
  29.         }
  30. protected BoundColumn InstanceIDColumn = new BoundColumn();
  31. protected int InstanceIDColumnIndex
  32. {
  33. get
  34. {
  35. return this.Columns.IndexOf(this.InstanceIDColumn);
  36. }
  37. }
  38.         protected BoundColumn TokenIDColumn = new BoundColumn();
  39.         protected int TokenIDColumnIndex
  40.         {
  41.             get
  42.             {
  43.                 return this.Columns.IndexOf(this.TokenIDColumn);
  44.             }
  45.         }
  46. protected BoundColumn InstanceNameColumn = new BoundColumn();
  47. protected int InstanceNameColumnIndex
  48. {
  49. get
  50. {
  51. return this.Columns.IndexOf(this.InstanceNameColumn);
  52. }
  53. }
  54. protected BoundColumn WorkflowPackageColumn = new BoundColumn();
  55. protected int WorkflowPackageColumnIndex
  56. {
  57. get
  58. {
  59. return this.Columns.IndexOf(this.WorkflowPackageColumn);
  60. }
  61. }
  62. protected BoundColumn WorkflowNameColumn = new BoundColumn();
  63. protected int WorkflowNameColumnIndex
  64. {
  65. get
  66. {
  67. return this.Columns.IndexOf(this.WorkflowNameColumn);
  68. }
  69. }
  70. protected BoundColumn WorkflowVersionColumn = new BoundColumn();
  71. protected int WorkflowVersionColumnIndex
  72. {
  73. get
  74. {
  75. return this.Columns.IndexOf(this.WorkflowVersionColumn);
  76. }
  77. }
  78. protected BoundColumn OriginatorColumn = new BoundColumn();
  79. protected int OriginatorColumnIndex
  80. {
  81. get
  82. {
  83. return this.Columns.IndexOf(this.OriginatorColumn);
  84. }
  85. }
  86. protected BoundColumn ActivityNameColumn = new BoundColumn();
  87. protected int ActivityNameColumnIndex
  88. {
  89. get
  90. {
  91. return this.Columns.IndexOf(this.ActivityNameColumn);
  92. }
  93. }
  94.         protected BoundColumn SheetTypeColumn = new BoundColumn();
  95.         protected int SheetTypeColumnIndex
  96.         {
  97.             get
  98.             {
  99.                 return this.Columns.IndexOf(this.SheetTypeColumn);
  100.             }
  101.         }
  102. protected BoundColumn SheetAddressColumn = new BoundColumn();
  103.         protected int SheetAddressColumnIndex
  104. {
  105. get
  106. {
  107.                 return this.Columns.IndexOf(this.SheetAddressColumn);
  108. }
  109. }
  110.         protected BoundColumn DisplayNameColumn = new BoundColumn();
  111.         protected int DisplayNameColumnIndex
  112.         {
  113.             get
  114.             {
  115.                 return this.Columns.IndexOf(this.DisplayNameColumn);
  116.             }
  117.         }
  118.         protected BoundColumn TitleColumn = new BoundColumn();
  119.         protected int TitleColumnIndex
  120.         {
  121.             get
  122.             {
  123.                 return this.Columns.IndexOf(this.TitleColumn);
  124.             }
  125.         }
  126. protected BoundColumn StateColumn = new BoundColumn();
  127. protected int StateColumnIndex
  128. {
  129. get
  130. {
  131. return this.Columns.IndexOf(this.StateColumn);
  132. }
  133. }
  134. protected BoundColumn ReceiveTimeColumn = new BoundColumn();
  135. protected int ReceiveTimeColumnIndex
  136. {
  137. get
  138. {
  139. return this.Columns.IndexOf(this.ReceiveTimeColumn);
  140. }
  141. }
  142. protected BoundColumn FinishTimeColumn = new BoundColumn();
  143. protected int FinishTimeColumnIndex
  144. {
  145. get
  146. {
  147. return this.Columns.IndexOf(this.FinishTimeColumn);
  148. }
  149. }
  150. protected BoundColumn ParticipantColumn = new BoundColumn();
  151. protected int ParticipantColumnIndex
  152. {
  153. get
  154. {
  155. return this.Columns.IndexOf(this.ParticipantColumn);
  156. }
  157. }
  158. protected BoundColumn UrgencyColumn = new BoundColumn();
  159. protected int UrgencyColumnIndex
  160. {
  161. get
  162. {
  163. return this.Columns.IndexOf(this.UrgencyColumn);
  164. }
  165. }
  166.         protected BoundColumn ViewColumn = new BoundColumn();
  167.         protected int ViewColumnIndex
  168.         {
  169.             get
  170.             {
  171.                 return this.Columns.IndexOf(this.ViewColumn);
  172.             }
  173.         }
  174.         protected BoundColumn ApprovalColumn = new BoundColumn();
  175.         protected int ApprovalColumnIndex
  176.         {
  177.             get
  178.             {
  179.                 return this.Columns.IndexOf(this.ApprovalColumn);
  180.             }
  181.         }
  182. private void InitializeColumn(BoundColumn Column, string HeaderText, string DataField)
  183. {
  184. Column.HeaderText = HeaderText;
  185. Column.DataField = DataField;
  186. Column.ItemStyle.CssClass = this.ItemStyle.CssClass;
  187. this.Columns.Add(Column);
  188. }
  189. #endregion
  190. #region 获得一些组合值
  191. // 获得发起人全名
  192. protected string GetOriginatorFullName(DataGridItemEventArgs e)
  193. {
  194. return e.Item.Cells[this.OriginatorColumnIndex].Text;
  195. }
  196. // 获得参与人全名
  197. protected string GetParticipantFullName(DataGridItemEventArgs e)
  198. {
  199. string participant = e.Item.Cells[this.ParticipantColumnIndex].Text;
  200. return OThinker.H3.Server.Engine.Organization.GetFullName(participant);
  201. }
  202. // 状态
  203. protected OThinker.H3.WorkItem.WorkItemState GetState(DataGridItemEventArgs e)
  204. {
  205. int intState = (int)OThinker.H3.WorkItem.WorkItemState.Unfinished;
  206. string strState = e.Item.Cells[this.StateColumnIndex].Text;
  207. if(strState != null && strState != "")
  208. {
  209. intState = int.Parse(strState);
  210. }
  211. return (OThinker.H3.WorkItem.WorkItemState)intState;
  212. }
  213. // 获得优先级别
  214. protected OThinker.H3.Instance.PriorityType GetPriority(DataGridItemEventArgs e)
  215. {
  216. string strPriority = e.Item.Cells[this.PriorityColumnIndex].Text;
  217. int intPriority = (int)OThinker.H3.Instance.PriorityType.Normal;
  218. if(strPriority != null && strPriority != "")
  219. {
  220. intPriority = int.Parse(strPriority);
  221. }
  222. return (OThinker.H3.Instance.PriorityType)intPriority;
  223. }
  224. // 获得流程模板的全名
  225. protected string GetWorkflowFullName(DataGridItemEventArgs e)
  226. {
  227. string workflowPackage = e.Item.Cells[this.WorkflowPackageColumnIndex].Text;
  228. string workflowName = e.Item.Cells[this.WorkflowNameColumnIndex].Text;
  229. string strWorkflowVersion = e.Item.Cells[this.WorkflowVersionColumnIndex].Text;
  230.             int workflowVersion = H3.WorkflowTemplate.WorkflowTemplate.NullWorkflowVersion;
  231. if(strWorkflowVersion != null && strWorkflowVersion != "")
  232. {
  233. workflowVersion = int.Parse(strWorkflowVersion);
  234. }
  235.             string workflowFullName = OThinker.H3.WorkflowTemplate.WorkflowTemplate.GetWorkflowFullName(
  236. workflowPackage, 
  237. workflowName, 
  238. workflowVersion);
  239. return workflowFullName;
  240. }
  241. protected System.DateTime GetReceiveTime(DataGridItemEventArgs e)
  242. {
  243. // 接收时间
  244. string strReceiveTime = e.Item.Cells[this.ReceiveTimeColumnIndex].Text;
  245. System.DateTime receiveTime = System.DateTime.MinValue;
  246. if(strReceiveTime != null && strReceiveTime != "")
  247. {
  248. receiveTime = System.DateTime.Parse(strReceiveTime);
  249. }
  250. return receiveTime;
  251. }
  252. protected System.DateTime GetFinishTime(DataGridItemEventArgs e)
  253. {
  254. string strFinishTime = e.Item.Cells[this.FinishTimeColumnIndex].Text;
  255. System.DateTime finishTime = System.DateTime.MaxValue;
  256. if(strFinishTime != null && strFinishTime != "")
  257. {
  258. finishTime = System.DateTime.Parse(strFinishTime);
  259. }
  260. return finishTime;
  261. }
  262. protected System.TimeSpan GetStayTime(DataGridItemEventArgs e)
  263. {
  264. System.TimeSpan stayTime;
  265. if(this.GetState(e) == OThinker.H3.WorkItem.WorkItemState.Finished)
  266. {
  267. stayTime = this.GetFinishTime(e).Subtract(this.GetReceiveTime(e));
  268. }
  269. else
  270. {
  271. stayTime = System.DateTime.Now.Subtract(this.GetReceiveTime(e));
  272. }
  273. return stayTime;
  274. }
  275.         public const string Target = "WorkItemMain";
  276. // 获得链接的全地址
  277. protected string GetFullUrl(DataGridItemEventArgs e)
  278. {
  279. return PortalPage.PageName_WorkItemDetail + "?" + PortalPage.Param_WorkItemID + "=" + e.Item.Cells[this.WorkItemIDColumnIndex].Text;
  280. }
  281.         protected string GetDisplayName(DataGridItemEventArgs e)
  282.         {
  283.             string displayName = e.Item.Cells[this.DisplayNameColumnIndex].Text;
  284.             // 如果没有设置显示名称,则使用默认名称
  285.             if (displayName == null || displayName == "" || displayName == "&nbsp;")
  286.             {
  287.                 displayName = e.Item.Cells[this.ActivityNameColumnIndex].Text;
  288.             }
  289.             return displayName;
  290.         }
  291.         protected string GetInstanceInfo(DataGridItemEventArgs e)
  292.         {
  293.             return this.GetWorkflowFullName(e); // +"." + e.Item.Cells[this.InstanceIDColumnIndex].Text;
  294.         }
  295. #endregion
  296. public WorkItemGrid()
  297. {
  298. this.AutoGenerateColumns = false;
  299. this.ItemDataBound += new DataGridItemEventHandler(Grid_ItemDataBound);
  300. this.PageIndexChanged += new DataGridPageChangedEventHandler(WorkItemGrid_PageIndexChanged);
  301. this.AllowPaging = true;
  302. this.PagerStyle.Mode = PagerMode.NumericPages;
  303.             this.PageSize = 25;
  304.             this.InitializeColumn(this.UrgencyColumn,           "催办", OThinker.H3.WorkItem.WorkItem.PropertyName_Urgency);
  305.             this.InitializeColumn(this.TitleColumn,             "工作项", null);
  306. this.InitializeColumn(this.WorkItemIDColumn, "ObjectID", OThinker.Data.Database.Serialization.T_Entity.C_ObjectID);
  307.             this.InitializeColumn(this.PriorityColumn,          "优先级",       OThinker.H3.WorkItem.WorkItem.PropertyName_Priority);
  308. this.InitializeColumn(this.InstanceIDColumn, "流程ID", OThinker.H3.WorkItem.WorkItem.PropertyName_InstanceId);
  309.             this.InitializeColumn(this.TokenIDColumn,           "TokenId", OThinker.H3.WorkItem.WorkItem.PropertyName_TokenId);
  310. this.InitializeColumn(this.InstanceNameColumn, "流程名称", OThinker.H3.WorkItem.WorkItem.PropertyName_InstanceName);
  311. this.InitializeColumn(this.WorkflowPackageColumn, "模板类型", OThinker.H3.WorkItem.WorkItem.PropertyName_WorkflowPackage);
  312.             this.InitializeColumn(this.WorkflowNameColumn,      "模板名称", OThinker.H3.WorkItem.WorkItem.PropertyName_WorkflowName);
  313. this.InitializeColumn(this.WorkflowVersionColumn, "模板版本", OThinker.H3.WorkItem.WorkItem.PropertyName_WorkflowVersion);
  314. this.InitializeColumn(this.OriginatorColumn, "发起人", OThinker.H3.WorkItem.WorkItem.PropertyName_Originator);
  315. this.InitializeColumn(this.ActivityNameColumn, "ActivityName", OThinker.H3.WorkItem.WorkItem.PropertyName_ActivityName);
  316.             this.InitializeColumn(this.SheetTypeColumn,         "SheetType",    OThinker.H3.WorkItem.WorkItem.PropertyName_SheetType);
  317.             this.InitializeColumn(this.SheetAddressColumn,      "SheetAddress", OThinker.H3.WorkItem.WorkItem.PropertyName_SheetAddress);
  318.             this.InitializeColumn(this.DisplayNameColumn,       "DisplayName",  OThinker.H3.WorkItem.WorkItem.PropertyName_DisplayName);
  319. this.InitializeColumn(this.StateColumn, "状态", OThinker.H3.WorkItem.WorkItem.PropertyName_State);
  320.             this.InitializeColumn(this.ReceiveTimeColumn,       "接收时间", OThinker.H3.WorkItem.WorkItem.PropertyName_ReceiveTime);
  321.             this.InitializeColumn(this.FinishTimeColumn,        "完成时间", OThinker.H3.WorkItem.WorkItem.PropertyName_FinishTime);
  322.             this.InitializeColumn(this.ParticipantColumn,       "处理人", OThinker.H3.WorkItem.WorkItem.PropertyName_Participant);
  323.             this.InitializeColumn(this.ViewColumn,              "查看", null);
  324.             this.InitializeColumn(this.ApprovalColumn, "审批结果", OThinker.H3.WorkItem.WorkItem.PropertyName_Approval);
  325.             this.Columns[this.WorkItemIDColumnIndex].Visible = false;
  326.             this.Columns[this.InstanceIDColumnIndex].Visible = false;
  327.             this.Columns[this.TokenIDColumnIndex].Visible = false;
  328.             this.Columns[this.WorkflowPackageColumnIndex].Visible = false;
  329.             this.Columns[this.WorkflowNameColumnIndex].Visible = false;
  330.             this.Columns[this.WorkflowVersionColumnIndex].Visible = false;
  331.             this.Columns[this.SheetTypeColumnIndex].Visible = false;
  332.             this.Columns[this.SheetAddressColumnIndex].Visible = false;
  333.             this.Columns[this.DisplayNameColumnIndex].Visible = false;
  334.             this.Columns[this.FinishTimeColumnIndex].Visible = false;
  335.             this.Columns[this.ActivityNameColumnIndex].Visible = false;
  336.             this.Columns[this.StateColumnIndex].Visible = false;
  337.             this.Columns[this.PriorityColumnIndex].Visible = false;
  338. }
  339.         private System.Data.DataTable WorkItemTable;
  340.         public void BindDataGrid(System.Data.DataTable Table)
  341.         {
  342.             if (!this.DesignMode)
  343.             {
  344.                 if (Table == null || this.CurrentPageIndex * this.PageSize >= Table.Rows.Count)
  345.                 {
  346.                     this.CurrentPageIndex = 0;
  347.                 }
  348.                 this.WorkItemTable = Table;
  349.                 this.DataSource = Table;
  350.                 this.DataBind();
  351.             }
  352.         }
  353.         protected override void Render(HtmlTextWriter writer)
  354.         {
  355.             if (!this.DesignMode && (this.WorkItemTable == null || this.WorkItemTable.Rows.Count == 0))
  356.             {
  357.                 writer.Write("没有找到工作项");
  358.             }
  359.             else
  360.             {
  361.                 base.Render(writer);
  362.             }
  363.         }
  364. protected virtual void Grid_ItemDataBound(object sender, DataGridItemEventArgs e)
  365. {
  366.             if (this.DesignMode)
  367.             {
  368.             }
  369.             else if (e.Item.ItemType != ListItemType.Header && e.Item.ItemType != ListItemType.Footer)
  370.             {
  371.                 // 流程名称
  372.                 string instanceName = e.Item.Cells[this.InstanceNameColumnIndex].Text;
  373.                 if (instanceName == null || instanceName == "" || instanceName == "&nbsp;")
  374.                 {
  375.                     instanceName = this.GetInstanceInfo(e);
  376.                 }
  377.                 e.Item.Cells[this.InstanceNameColumnIndex].Text = instanceName;
  378.                 // 名称和连接
  379.                 HyperLink link = new HyperLink();
  380.                 if (!this.DesignMode)
  381.                 {
  382.                     link.Text = "第" + e.Item.Cells[this.TokenIDColumnIndex].Text + "步:" + this.GetDisplayName(e);
  383.                     link.NavigateUrl = this.GetFullUrl(e);
  384.                     link.Font.Underline = true;
  385.                     // link.Target = Target;
  386.                 }
  387.                 e.Item.Cells[this.TitleColumnIndex].Controls.Add(link);
  388.                 // 优先级
  389.                 int intPriority = int.Parse(e.Item.Cells[this.PriorityColumnIndex].Text);
  390.                 OThinker.H3.Instance.PriorityType priority = (OThinker.H3.Instance.PriorityType)intPriority;
  391.                 Image imagePriority = new Image();
  392.                 imagePriority.ImageUrl = "images/Priority_" + priority + ".GIF";
  393.                 imagePriority.ToolTip = OThinker.H3.Instance.PriorityTypeConvertor.ToString(priority);
  394.                 e.Item.Cells[this.PriorityColumnIndex].Controls.Add(imagePriority);
  395.                 // 发起人
  396.                 string originator = e.Item.Cells[this.OriginatorColumnIndex].Text;
  397.                 HyperLink originatorLink = new HyperLink();
  398.                 originatorLink.Text = OThinker.H3.Server.Engine.Organization.GetName(originator);
  399.                 originatorLink.NavigateUrl = PortalPage.PageName_EditUser + "?" + PortalPage.Param_ID + "=" + originator + "&" + PortalPage.Param_Mode + "=" + Portal.EditUserType.View;
  400.                 e.Item.Cells[this.OriginatorColumnIndex].Controls.Add(originatorLink);
  401.                 // 处理人
  402.                 string participant = e.Item.Cells[this.ParticipantColumnIndex].Text;
  403.                 HyperLink participantLink = new HyperLink();
  404.                 participantLink.Text = OThinker.H3.Server.Engine.Organization.GetName(participant);
  405.                 participantLink.NavigateUrl = PortalPage.PageName_EditUser + "?" + PortalPage.Param_ID + "=" + participant + "&" + PortalPage.Param_Mode + "=" + Portal.EditUserType.View;
  406.                 e.Item.Cells[this.ParticipantColumnIndex].Controls.Add(participantLink);
  407.                 // 主题
  408.                 System.TimeSpan stayTime = this.GetStayTime(e);
  409.                 // 设置颜色
  410.                 if (stayTime < OThinker.H3.Server.Engine.SettingManager.WorkItemYellowWarningTimeSpan)
  411.                 {
  412.                     e.Item.Cells[this.ReceiveTimeColumnIndex].ForeColor = System.Drawing.Color.Black;
  413.                 }
  414.                 else if (stayTime < OThinker.H3.Server.Engine.SettingManager.WorkItemRedWarningTimeSpan)
  415.                 {
  416.                     e.Item.Cells[this.ReceiveTimeColumnIndex].ForeColor = System.Drawing.Color.Brown;
  417.                 }
  418.                 else
  419.                 {
  420.                     e.Item.Cells[this.ReceiveTimeColumnIndex].ForeColor = System.Drawing.Color.Red;
  421.                 }
  422.                 // 查看
  423.                 string chartUrl = PortalPage.PageName_InstanceStateChart + "?" + PortalPage.Param_InstanceId + "=" + e.Item.Cells[this.InstanceIDColumnIndex].Text;
  424.                 string chartTitle = "流程图";
  425.                 HyperLink linkChart = new HyperLink();
  426.                 linkChart.Target = "_blank";
  427.                 linkChart.Text = chartTitle;
  428.                 linkChart.NavigateUrl = chartUrl;
  429.                 e.Item.Cells[this.ViewColumnIndex].Controls.Add(linkChart);
  430.                 // 分割符
  431.                 Label lblSplit = new Label();
  432.                 lblSplit.Text = " | ";
  433.                 e.Item.Cells[this.ViewColumnIndex].Controls.Add(lblSplit);
  434.                 // 流转日志
  435.                 string logUrl = PortalPage.PageName_InstanceToken + "?" + PortalPage.Param_InstanceId + "=" + e.Item.Cells[this.InstanceIDColumnIndex].Text;
  436.                 string logTitle = "日志";
  437.                 HyperLink linkLog = new HyperLink();
  438.                 linkLog.Target = "_blank";
  439.                 linkLog.Text = logTitle;
  440.                 linkLog.NavigateUrl = logUrl;
  441.                 e.Item.Cells[this.ViewColumnIndex].Controls.Add(linkLog);
  442.                 // 催办
  443.                 string urgency = e.Item.Cells[this.UrgencyColumnIndex].Text;
  444.                 if (urgency != null && urgency.Trim() != "" && urgency != "&nbsp;")
  445.                 {
  446.                     Image imgUrgency = new Image();
  447.                     imgUrgency.ImageUrl = "images/IB_Urgency.gif";
  448.                     imgUrgency.ToolTip = urgency;
  449.                     e.Item.Cells[this.UrgencyColumnIndex].Controls.Add(imgUrgency);
  450.                 }
  451.                 // Approval
  452.                 string approvalText = null;
  453.                 int approval = int.Parse(e.Item.Cells[this.ApprovalColumnIndex].Text);
  454.                 if (this.GetState(e) == OThinker.H3.WorkItem.WorkItemState.Finished)
  455.                 {
  456.                     switch (approval)
  457.                     {
  458.                         case (int)OThinker.Data.BoolMatchValue.True:
  459.                             approvalText = "同意";
  460.                             break;
  461.                         case (int)OThinker.Data.BoolMatchValue.False:
  462.                             approvalText = "拒绝";
  463.                             break;
  464.                         default:
  465.                             break;
  466.                     }
  467.                 }
  468.                 e.Item.Cells[this.ApprovalColumnIndex].Text = approvalText;
  469.             }
  470. }
  471. private void WorkItemGrid_PageIndexChanged(object source, DataGridPageChangedEventArgs e)
  472. {
  473. this.CurrentPageIndex = e.NewPageIndex;
  474. this.DataBind();
  475. }
  476. }
  477. }