GetValue.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Reflection;
  6. using System.Web.UI;
  7. namespace Ant.Frame
  8. {
  9. public static class GetValue
  10. {
  11. public static T GetControlValue<T>(Control page, T enty)
  12. {
  13. List<Control> conlist = new List<Control>();
  14. foreach (Control ctrol in page.Controls)
  15. {
  16. conlist.Add(ctrol);
  17. }
  18. return GetCollection(conlist, enty, "");
  19. }
  20. public static T GetControlValue<T>(Control page, T enty, string lbl)
  21. {
  22. List<Control> conlist = new List<Control>();
  23. foreach (Control ctrol in page.Controls)
  24. {
  25. conlist.Add(ctrol);
  26. }
  27. return GetCollection(conlist, enty, lbl);
  28. }
  29. /// <summary>
  30. ///不知道控件的级次进行赋值
  31. /// </summary>
  32. /// <param name="pages"></param>
  33. /// <param name="enty"></param>
  34. public static T GetControlValue<T>(List<Control> pages, T enty)
  35. {
  36. return GetCollection(pages, enty, "");
  37. }
  38. private static T GetCollection<T>(List<Control> page, T enty, string lbl)
  39. {
  40. int level = 0;
  41. return ControlCollection(page, level, enty, lbl);
  42. }
  43. private static T ControlCollection<T>(List<Control> oldMenus, int level, T entity, string lbl)
  44. {
  45. foreach (Control menu in oldMenus)
  46. {
  47. SelectControl con = new SelectControl(ControlType.Ext, menu);
  48. entity = con.GetResult<T>(entity, lbl);
  49. int controlnum = menu.Controls.Count;
  50. if (controlnum == 0)
  51. level++;
  52. else
  53. {
  54. List<Control> conlist = new List<Control>();
  55. foreach (Control ctrol in menu.Controls)
  56. {
  57. conlist.Add(ctrol);
  58. }
  59. ControlCollection<T>(conlist, level, entity, lbl);
  60. }
  61. }
  62. return entity;
  63. }
  64. }
  65. }