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

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 QueryCaseByData.
  15. /// </summary>
  16.     public partial class QueryInstanceByFullText : PortalPage
  17. {
  18. protected void Page_Load(object sender, System.EventArgs e)
  19. {
  20. if(!this.IsPostBack)
  21. {
  22.                 // 验证是否具有管理员权限
  23.                 if (!this.UserValidator.ValidateViewReport())
  24.                 {
  25.                     this.NotifyMessage(LackOfAuth);
  26.                 }
  27. // 设置默认状态为未完成
  28. this.lstState.SelectedIndex = 0;
  29. // 设置默认的搜索时间
  30. System.DateTime today = System.DateTime.Now;
  31. System.DateTime tomorrow = today.Add(new System.TimeSpan(1, 0, 0, 0, 0));
  32. this.txtFromTime.Text = today.ToShortDateString();
  33. this.txtToTime.Text = tomorrow.ToShortDateString();
  34. }
  35. }
  36. #region Web Form Designer generated code
  37. override protected void OnInit(EventArgs e)
  38. {
  39. //
  40. // CODEGEN: This call is required by the ASP.NET Web Form Designer.
  41. //
  42. InitializeComponent();
  43. base.OnInit(e);
  44. }
  45. /// <summary>
  46. /// Required method for Designer support - do not modify
  47. /// the contents of this method with the code editor.
  48. /// </summary>
  49. private void InitializeComponent()
  50. {    
  51. this.btnQuery.Click += new System.Web.UI.ImageClickEventHandler(this.btnQuery_Click);
  52. }
  53. #endregion
  54. private void btnQuery_Click(object sender, System.Web.UI.ImageClickEventArgs e)
  55. {
  56. this.Query();
  57. }
  58. protected void lnkQuery_Click(object sender, System.EventArgs e)
  59. {
  60. this.Query();
  61. }
  62. private void Query()
  63. {
  64. string keyword = null;
  65. if(this.txtKeyword.Text == null || this.txtKeyword.Text == "")
  66. {
  67. keyword = null;
  68. }
  69. else
  70. {
  71. keyword = this.txtKeyword.Text;
  72. }
  73. string[] originators = null;
  74.             if (this.txtOriginator.SelectedUser == null || this.txtOriginator.SelectedUser == "")
  75. {
  76. originators = null;
  77. }
  78. else
  79. {
  80.                 originators = OThinker.H3.Server.Engine.Organization.GetChildren(this.txtOriginator.SelectedUser, OThinker.Organization.UnitType.User, true);
  81. }
  82. bool finished = this.lstState.SelectedIndex != 0;
  83. System.DateTime from;
  84. try
  85. {
  86. from = System.DateTime.Parse(this.txtFromTime.Text);
  87. }
  88. catch
  89. {
  90. from = System.DateTime.MinValue;
  91. }
  92. System.DateTime to;
  93. try
  94. {
  95. to = System.DateTime.Parse(this.txtToTime.Text);
  96. }
  97. catch
  98. {
  99. to = System.DateTime.MaxValue;
  100. }
  101. if(
  102. keyword == null && 
  103. originators == null && 
  104. from == System.DateTime.MinValue && 
  105. to == System.DateTime.MaxValue)
  106. {
  107. // 所有的查询条件都没有赋值,不进行查询
  108. }
  109. else
  110. {
  111. // 查找满足条件的实例
  112. System.Data.DataTable table = this.Query(
  113. keyword, 
  114. originators, 
  115. finished, 
  116. from, 
  117. to);
  118. this.InstanceGridView.BindDataGrid(table);
  119. }
  120. }
  121.         public System.Data.DataTable Query(
  122.             string Keyword,
  123.             string[] Originators,
  124.             bool Finished,
  125.             System.DateTime CreatedTime_From,
  126.             System.DateTime CreatedTime_To)
  127.         {
  128.             // 查找
  129.             H3.Instance.InstanceState state;
  130.             if (Finished)
  131.             {
  132.                 state = H3.Instance.InstanceState.Complete;
  133.             }
  134.             else
  135.             {
  136.                 state = H3.Instance.InstanceState.Unfinished;
  137.             }
  138.             // 符合条件的流程ID集合
  139.             string[] instances;
  140.             // 查找满足条件的实例
  141.             instances = OThinker.H3.Server.Engine.InstanceManager.Query(
  142.                 Originators,
  143.                 null,
  144.                 H3.Instance.InstanceContext.UnspecifiedID,
  145.                 state,
  146.                 null,
  147.                 null,
  148.                 H3.WorkflowTemplate.WorkflowTemplate.NullWorkflowVersion,
  149.                 CreatedTime_From,
  150.                 CreatedTime_To,
  151.                 null);
  152.             // 按照内容关键字查找
  153.             int queriedTables = 0;
  154.             System.Collections.ArrayList instanceCollection = new System.Collections.ArrayList();
  155.             // 获得当前系统中的所有工作流
  156.             string[] packages = OThinker.H3.Server.Engine.WorkflowManager.GetWorkflowPackages();
  157.             if (packages != null)
  158.             {
  159.                 foreach (string package in packages)
  160.                 {
  161.                     string[] names = OThinker.H3.Server.Engine.WorkflowManager.GetWorkflowNames(package, OThinker.H3.WorkflowTemplate.WorkflowState.Active);
  162.                     if (names != null)
  163.                     {
  164.                         foreach (string name in names)
  165.                         {
  166.                             int[] versions = OThinker.H3.Server.Engine.WorkflowManager.GetWorkflowVersions(package, name);
  167.                             if (versions != null)
  168.                             {
  169.                                 foreach (int version in versions)
  170.                                 {
  171.                                     WorkflowTemplate.WorkflowTemplate workflow = OThinker.H3.Server.Engine.WorkflowManager.GetWorkflow(
  172.                                         package,
  173.                                         name,
  174.                                         version);
  175.                                     // 对每一个数据项进行查找
  176.                                     foreach (Data.WorkflowDataItem item in workflow.DataItems)
  177.                                     {
  178.                                         // 检查是否能转换成为需要比较的类型
  179.                                         object convertedValue = null;
  180.                                         try
  181.                                         {
  182.                                             convertedValue = OThinker.Data.Convertor.Convert(Keyword, item.RealType, true);
  183.                                         }
  184.                                         catch
  185.                                         {
  186.                                             continue;
  187.                                         }
  188.                                         string[] ids = OThinker.H3.Server.Engine.InstanceDataManager.Query(
  189.                                             workflow,
  190.                                             item.ItemName,
  191.                                             OThinker.Data.ComparisonOperatorType.Approximate,
  192.                                             convertedValue,
  193.                                             instances);
  194.                                         if (ids != null)
  195.                                         {
  196.                                             foreach (string id in ids)
  197.                                             {
  198.                                                 if (id != null && !instanceCollection.Contains(id))
  199.                                                 {
  200.                                                     instanceCollection.Add(id);
  201.                                                 }
  202.                                             }
  203.                                         }
  204.                                         // 当前的已经查询的表加1
  205.                                         queriedTables++;
  206.                                     }
  207.                                 }
  208.                             }
  209.                         }
  210.                     }
  211.                 }
  212.             }
  213.             // 按照标题关键字查找
  214.             string[] titleInstances = OThinker.H3.Server.Engine.InstanceManager.Query(
  215.                 Originators,
  216.                 null,
  217.                 H3.Instance.InstanceContext.UnspecifiedID,
  218.                 state,
  219.                 null,
  220.                 null,
  221.                 H3.WorkflowTemplate.WorkflowTemplate.NullWorkflowVersion,
  222.                 CreatedTime_From,
  223.                 CreatedTime_To,
  224.                 Keyword);
  225.             // 合并两个关键字查找的结果
  226.             if (titleInstances != null)
  227.             {
  228.                 foreach (string instanceId in titleInstances)
  229.                 {
  230.                     if (!instanceCollection.Contains(instanceId))
  231.                     {
  232.                         instanceCollection.Add(instanceId);
  233.                     }
  234.                 }
  235.             }
  236.             instances = OThinker.Data.ArrayConvertor<string>.ToArray(instanceCollection);
  237.             // 显示该列表
  238.             return Portal.Query.QueryInstance(
  239.                 instances,
  240.                 null,
  241.                 null,
  242.                 H3.Instance.InstanceContext.UnspecifiedID,
  243.                 Instance.InstanceState.Unspecified,
  244.                 null,
  245.                 null,
  246.                 H3.WorkflowTemplate.WorkflowTemplate.NullWorkflowVersion,
  247.                 System.DateTime.MinValue,
  248.                 System.DateTime.MaxValue,
  249.                 null,
  250.                 OThinker.H3.Instance.PriorityType.Unspecified,
  251.                 OThinker.Data.BoolMatchValue.Unspecified,
  252.                 OThinker.Data.BoolMatchValue.Unspecified);
  253.         }
  254. }
  255. }