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

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 QueryCaseToken.
  15.     /// </summary>
  16.     public partial class InstanceToken : PortalPage
  17.     {
  18.         private string InstanceId
  19.         {
  20.             get
  21.             {
  22.                 return this.Request.QueryString[Param_InstanceId];
  23.             }
  24.         }
  25.         private System.Data.DataTable TokenTable;
  26.         private System.Data.DataTable WorkItemTable;
  27.         private System.Data.DataTable ChildInstanceTable;
  28.         /// <summary>
  29.         /// 获得该状态的工作项的状态描述
  30.         /// </summary>
  31.         /// <param name="TokenID"></param>
  32.         /// <returns></returns>
  33.         private DataRow[] GetWorkItems(long TokenID)
  34.         {
  35.             ArrayList list = new ArrayList();
  36.             foreach (System.Data.DataRow row in this.WorkItemTable.Rows)
  37.             {
  38.                 if ((long)row[WorkItem.WorkItem.PropertyName_TokenId] == TokenID)
  39.                 {
  40.                     list.Add(row);
  41.                 }
  42.             }
  43.             return OThinker.Data.ArrayConvertor<DataRow>.ToArray(list);
  44.         }
  45.         private DataRow[] GetChildInstances(long TokenID)
  46.         {
  47.             ArrayList list = new ArrayList();
  48.             if (this.ChildInstanceTable != null && this.ChildInstanceTable.Rows != null && this.ChildInstanceTable.Rows.Count != 0)
  49.             {
  50.                 foreach (DataRow row in this.ChildInstanceTable.Rows)
  51.                 {
  52.                     if ((long)row[Instance.InstanceContext.PropertyName_ParentActivityTokenId] == TokenID)
  53.                     {
  54.                         list.Add(row);
  55.                     }
  56.                 }
  57.             }
  58.             return OThinker.Data.ArrayConvertor<DataRow>.ToArray(list);
  59.         }
  60.         protected void Page_Load(object sender, System.EventArgs e)
  61.         {
  62.             if (!this.IsPostBack)
  63.             {
  64.                 // 查询记录
  65.                 this.TokenTable = Query.QueryToken(this.InstanceId);
  66.                 this.WorkItemTable = Query.QueryWorkItem(
  67.                     null,
  68.                     null,
  69.                     WorkflowTemplate.WorkflowTemplate.NullWorkflowVersion,
  70.                     null,
  71.                     new string[] { this.InstanceId },
  72.                     null,
  73.                     System.DateTime.MinValue,
  74.                     System.DateTime.MaxValue,
  75.                     OThinker.H3.WorkItem.WorkItemState.Unspecified,
  76.                     OThinker.H3.Instance.PriorityType.Unspecified,
  77.                     null, 
  78.                     null,
  79.                     OThinker.Data.BoolMatchValue.Unspecified,
  80.                     OThinker.Data.BoolMatchValue.Unspecified);
  81.                 this.ChildInstanceTable = Query.QueryInstance(
  82.                     null,
  83.                     null,
  84.                     null,
  85.                     this.InstanceId, 
  86.                     OThinker.H3.Instance.InstanceState.Unspecified,
  87.                     null,
  88.                     null,
  89.                     WorkflowTemplate.WorkflowTemplate.NullWorkflowVersion,
  90.                     System.DateTime.MinValue,
  91.                     System.DateTime.MaxValue,
  92.                     null,
  93.                     OThinker.H3.Instance.PriorityType.Unspecified,
  94.                     OThinker.Data.BoolMatchValue.Unspecified,
  95.                     OThinker.Data.BoolMatchValue.Unspecified);
  96.             }
  97.             this.TokenGrid.DataSource = this.TokenTable;
  98.             this.TokenGrid.DataBind();
  99.         }
  100.         #region Web Form Designer generated code
  101.         override protected void OnInit(EventArgs e)
  102.         {
  103.             //
  104.             // CODEGEN: This call is required by the ASP.NET Web Form Designer.
  105.             //
  106.             InitializeComponent();
  107.             base.OnInit(e);
  108.         }
  109.         /// <summary>
  110.         /// Required method for Designer support - do not modify
  111.         /// the contents of this method with the code editor.
  112.         /// </summary>
  113.         private void InitializeComponent()
  114.         {
  115.             this.TokenGrid.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.TokenGrid_ItemDataBound);
  116.         }
  117.         #endregion
  118.         private void TokenGrid_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
  119.         {
  120.             if (e.Item.ItemType != ListItemType.Header && e.Item.ItemType != ListItemType.Footer)
  121.             {
  122.                 // 设置序列号
  123.                 e.Item.Cells[0].Text = (e.Item.ItemIndex + 1).ToString();
  124.                 // Token ID
  125.                 long tokenId = (long)this.TokenTable.Rows[e.Item.ItemIndex][Instance.Token.PropertyName_TokenId];
  126.                 // 获得工作项状态描述
  127.                 System.Text.StringBuilder workItemHtml = new System.Text.StringBuilder();
  128.                 DataRow[] workItems = this.GetWorkItems(tokenId);
  129.                 if (workItems != null && workItems.Length != 0)
  130.                 {
  131.                     workItemHtml.Append("<TABLE WIDTH=100%>");
  132.                     foreach (System.Data.DataRow row in workItems)
  133.                     {
  134.                         workItemHtml.Append("<TR>");
  135.                         workItemHtml.Append("<TD width=30% valign=top>");
  136.                         string participant = (string)row[WorkItem.WorkItem.PropertyName_Participant];
  137.                         string participantName = OThinker.H3.Server.Engine.Organization.GetName(participant);
  138.                         workItemHtml.Append(
  139.                             "<a href="" + PageName_EditUser + "?" + Param_ID + "=" + participant + "&" + Param_Mode + "=" + EditUserType.View + "" target=_blank>" + 
  140.                             participantName + "</a>");
  141.                         workItemHtml.Append("</TD>");
  142.                         workItemHtml.Append("<TD valign=top>");
  143.                         object rawComment = row[WorkItem.WorkItem.PropertyName_Comment];
  144.                         string comment = (rawComment == null || rawComment == System.DBNull.Value) ? null : rawComment.ToString();
  145.                         workItemHtml.Append(comment);
  146.                         workItemHtml.Append("</TD>");
  147.                         workItemHtml.Append("<TD ALIGN='RIGHT' valign=top>");
  148.                         int intState = (int)row[WorkItem.WorkItem.PropertyName_State];
  149.                         string strState = null;
  150.                         if (intState == (int)WorkItem.WorkItemState.Finished)
  151.                         {
  152.                             if ((int)row[WorkItem.WorkItem.PropertyName_Approval] == (int)OThinker.Data.BoolMatchValue.True)
  153.                             {
  154.                                 strState = "同意";
  155.                             }
  156.                             else if ((int)row[WorkItem.WorkItem.PropertyName_Approval] == (int)OThinker.Data.BoolMatchValue.False)
  157.                             {
  158.                                 strState = "否决";
  159.                             }
  160.                         }
  161.                         if (strState == null)
  162.                         {
  163.                             WorkItem.WorkItemState state = (OThinker.H3.WorkItem.WorkItemState)intState;
  164.                             strState = WorkItem.WorkItemStateConvertor.ToString(state);
  165.                         }
  166.                         workItemHtml.Append(strState);
  167.                         workItemHtml.Append("</TD>");
  168.                         workItemHtml.Append("</TR>");
  169.                     }
  170.                     workItemHtml.Append("</TABLE>");
  171.                 }
  172.                 // 获得子流程状态描述
  173.                 System.Text.StringBuilder childHtml = new System.Text.StringBuilder();
  174.                 DataRow[] childInstances = this.GetChildInstances(tokenId);
  175.                 if (childInstances != null && childInstances.Length != 0)
  176.                 {
  177.                     childHtml.Append("<TABLE WIDTH=100%>");
  178.                     foreach (DataRow childInstance in childInstances)
  179.                     {
  180.                         childHtml.Append("<TR>");
  181.                         childHtml.Append("<TD>");
  182.                         string childOriginator = (string)childInstance[Instance.InstanceContext.PropertyName_Originator];
  183.                         string childOrginatorName = OThinker.H3.Server.Engine.Organization.GetName(childOriginator);
  184.                         childHtml.Append(
  185.                             "<a href="" + PageName_EditUser + "?" + Param_ID + "=" + childOriginator + "&" + Param_Mode + "=" + EditUserType.View + "" target=_blank>" +
  186.                             childOrginatorName + "</a>");
  187.                         childHtml.Append("</TD>");
  188.                         childHtml.Append("<TD VALIGN='RIGHT'>");
  189.                         string childInstanceId = (string)childInstance[Instance.InstanceContext.PropertyName_InstanceId];
  190.                         // 显示日志的链接
  191.                         childHtml.Append("<A HREF='" + PageName_InstanceToken + "?" + Param_InstanceId + "=" + childInstanceId + "'>日志</A>");
  192.                         childHtml.Append(" ");
  193.                         childHtml.Append("<A HREF='" + PageName_InstanceStateChart + "?" + Param_InstanceId + "=" + childInstanceId + "'>流程图</A>");
  194.                         childHtml.Append(" ");
  195.                         Instance.InstanceState childState = (Instance.InstanceState)childInstance[Instance.InstanceContext.PropertyName_State];
  196.                         childHtml.Append(Instance.InstanceStateConvertor.ToString(childState));
  197.                         childHtml.Append("</TD>");
  198.                         childHtml.Append("</TR>");
  199.                     }
  200.                     childHtml.Append("</TABLE>");
  201.                 }
  202.                 string workItem = workItemHtml.ToString();
  203.                 string child = childHtml.ToString();
  204.                 string br = (workItem == null || workItem == "" || child == null || child == "") ? null : "<BR>";
  205.                 e.Item.Cells[3].Text = workItem + br + child;
  206.                 // 操作描述
  207.                 e.Item.Cells[4].Text = e.Item.Cells[4].Text == null ? e.Item.Cells[4].Text : e.Item.Cells[4].Text.Replace(Instance.Token.DescriptionInterval, "<BR>");
  208.                 // 是否同意
  209.                 System.Web.UI.WebControls.CheckBox approval = new CheckBox();
  210.                 approval.Checked = e.Item.Cells[5].Text == "1";
  211.                 approval.Enabled = false;
  212.                 e.Item.Cells[5].Controls.Add(approval);
  213.                 // 是否允许取回
  214.                 System.Web.UI.WebControls.CheckBox retrievable = new CheckBox();
  215.                 retrievable.Checked = e.Item.Cells[6].Text == "1";
  216.                 retrievable.Enabled = false;
  217.                 e.Item.Cells[6].Controls.Add(retrievable);
  218.                 // 是否作废
  219.                 CheckBox dropped = new CheckBox();
  220.                 dropped.Checked = e.Item.Cells[7].Text == "1";
  221.                 dropped.Enabled = false;
  222.                 e.Item.Cells[7].Controls.Add(dropped);
  223.                 // 成本
  224.                 double cost = double.Parse(e.Item.Cells[9].Text);
  225.                 e.Item.Cells[9].Text = System.Math.Round(cost, 2).ToString();
  226.                 double costRate = double.Parse(e.Item.Cells[10].Text);
  227.                 e.Item.Cells[10].Text = System.Math.Round(costRate * 100, 2).ToString() + "%";
  228.                 // 耗时
  229.                 string usedTimeText = e.Item.Cells[11].Text;
  230.                 System.TimeSpan usedTime = new System.TimeSpan(long.Parse(usedTimeText));
  231.                 e.Item.Cells[11].Text = usedTime.Days + " " + usedTime.Hours + ":" + usedTime.Minutes + ":" + usedTime.Seconds;
  232.             }
  233.         }
  234.     }
  235. }