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

OA系统

开发平台:

C#

  1. using System;
  2. using System.Web.UI;
  3. using System.Web.UI.WebControls;
  4. using System.ComponentModel;
  5. using System.Collections.Generic;
  6. using OThinker.H3.WorkflowTemplate;
  7. namespace OThinker.H3.Portal
  8. {
  9. /// <summary>
  10. /// Summary description for WorkflowGrid.
  11. /// </summary>
  12. [DefaultProperty("Text"), 
  13. ToolboxData("<{0}:WorkflowGrid runat=server></{0}:WorkflowGrid>")]
  14. public class WorkflowGrid : System.Web.UI.WebControls.WebControl
  15.     {
  16.         public WorkflowGrid()
  17. {
  18. }
  19.         private UserValidator UserValidator;
  20. public void Initialize(UserValidator UserValidator)
  21. {
  22. this.UserValidator = UserValidator;
  23. }
  24.         private Dictionary<string, Dictionary<string, int>> CreatePackageTable()
  25.         {
  26.             // 创建
  27.             Dictionary<string, Dictionary<string, int>> packageTable = new Dictionary<string, Dictionary<string, int>>();
  28.             // 查找所有符合条件的工作流表
  29.             if (this.DesignMode)
  30.             {
  31.                 // 设计模式
  32.                 foreach (string package in new string[] { "工作流包1", "工作流包2", "工作流包3" })
  33.                 {
  34.                     // 创建(Workflow)
  35.                     Dictionary<string, int> nameTable = new Dictionary<string, int>();
  36.                     packageTable.Add(package, nameTable);
  37.                     foreach (string name in new string[] { "工作流1", "工作流2", "工作流3" })
  38.                     {
  39.                         nameTable.Add(name, 1);
  40.                     }
  41.                 }
  42.             }
  43.             else
  44.             {
  45.                 // 查询流程模板
  46.                 System.Collections.Generic.List<string> unitList = new System.Collections.Generic.List<string>(this.UserValidator.RecursiveMemberOfs);
  47.                 if(!unitList.Contains(this.UserValidator.UserID))
  48.                 {
  49.                     unitList.Add(this.UserValidator.UserID);
  50.                 }
  51.                 System.Data.DataTable table = OThinker.H3.Portal.Query.QueryWorkflow(unitList.ToArray());
  52.                 // 构建包
  53.                 foreach(System.Data.DataRow row in table.Rows)
  54.                 {
  55.                     string package = (string)row[OThinker.H3.WorkflowTemplate.WorkflowTemplate.PropertyName_WorkflowPackageName];
  56.                     Dictionary<string, int> nameTable = new Dictionary<string, int>();
  57.                     if(packageTable.ContainsKey(package))
  58.                     {
  59.                         nameTable = packageTable[package];
  60.                     }
  61.                     else
  62.                     {
  63.                         nameTable = new Dictionary<string, int>();
  64.                         packageTable.Add(package, nameTable);
  65.                     }
  66.                     string name = (string)row[OThinker.H3.WorkflowTemplate.WorkflowTemplate.PropertyName_WorkflowName];
  67.                     if(!nameTable.ContainsKey(name))
  68.                     {
  69.                         int version = (int)row[OThinker.H3.WorkflowTemplate.WorkflowTemplate.PropertyName_WorkflowVersion];
  70.                         nameTable.Add(name, version);
  71.                     }
  72.                 }
  73.             }
  74.             return packageTable;
  75.         }
  76.         // (PackageName, (WorkflowName, WorkflowVersion))
  77.         private Dictionary<string, Dictionary<string, int>> _PackageTable;
  78.         public Dictionary<string, Dictionary<string, int>> PackageTable
  79.         {
  80.             get
  81.             {
  82.                 if (this._PackageTable == null)
  83.                 {
  84.                     this._PackageTable = this.CreatePackageTable();
  85.                 }
  86.                 return this._PackageTable;
  87.             }
  88.         }
  89. protected override void Render(HtmlTextWriter writer)
  90. {
  91.             // 显示
  92.             if (this.PackageTable.Count == 0)
  93.             {
  94.                 writer.Write("没有找到记录");
  95.             }
  96.             else
  97.             {
  98.                 writer.Write("<TABLE WIDTH="100%" cellpadding="0" cellspacing="0">");
  99.                 int count = 0;
  100.                 foreach (string package in this.PackageTable.Keys)
  101.                 {
  102.                     writer.Write("<TR WIDTH="100%">");
  103.                     writer.Write("<TD WIDTH="100%">");
  104.                     string divName = "DIV_CategoryWorkflowView_" + count;
  105.                     // 隐藏显示按钮
  106.                     string hideButtonName = divName + "_HideButton";
  107.                     string displayButtonName = divName + "_DisplayButton";
  108.                     writer.Write("<a id="" + hideButtonName + "" onClick="javascript:" + divName + ".style.display='none';" + hideButtonName + ".style.display='none';" + displayButtonName + ".style.display='block';" style="cursor: hand" ><strong>-" + package + "</strong></a>");
  109.                     writer.Write("<a id="" + displayButtonName + "" style="display: none;" onClick="javascript:" + divName + ".style.display='block';" + hideButtonName + ".style.display='block';" + displayButtonName + ".style.display='none';" style="cursor: hand" ><strong>+" + package + "</strong></a>");
  110.                     writer.Write("<DIV ID="" + divName + "" >");
  111.                     Dictionary<string, int> nameTable = this.PackageTable[package];
  112.                     foreach(string name in nameTable.Keys)
  113.                     {
  114.                         int version = nameTable[name];
  115.                         WorkflowGridItem item = new WorkflowGridItem(package, name, version);
  116.                         item.Attributes.Add("width", "100%");
  117.                         item.RenderControl(writer);
  118.                     }
  119.                     writer.Write("</DIV>");
  120.                     writer.Write("</TD>");
  121.                     writer.Write("</TR>");
  122.                     count++;
  123.                 }
  124.                 writer.Write("</TABLE>");
  125.             }
  126. }
  127. }
  128. }