LookupFieldCollector.cs
上传用户:husern
上传日期:2022-03-24
资源大小:534k
文件大小:3k
源码类别:

编辑器/阅读器

开发平台:

C#

  1. // -- FILE ------------------------------------------------------------------
  2. // name       : LookupCollector.cs
  3. // project    : Itenso Web User Forms
  4. // created    : Jani Giannoudis - 2008.10.30
  5. // language   : c#
  6. // environment: .NET 2.0
  7. // copyright  : (c) 2008 by Itenso GmbH, Switzerland
  8. // --------------------------------------------------------------------------
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Web.UI;
  12. namespace Itenso.WebUserForms.Controls
  13. {
  14. // ------------------------------------------------------------------------
  15. public class LookupFieldCollector : UserFormVisitor
  16. {
  17. // ----------------------------------------------------------------------
  18. public LookupFieldCollector( Control startControl )
  19. : base( startControl )
  20. {
  21. } // LookupCollector
  22. // ----------------------------------------------------------------------
  23. public LookupFieldCollector( Control startControl, string lookupName )
  24. : this( startControl )
  25. {
  26. if ( string.IsNullOrEmpty( lookupName ) )
  27. {
  28. throw new ArgumentException( "lookupName" );
  29. }
  30. this.lookupName = lookupName;
  31. } // LookupCollector
  32. // ----------------------------------------------------------------------
  33. public string LookupName
  34. {
  35. get { return this.lookupName; }
  36. } // LookupName
  37. // ----------------------------------------------------------------------
  38. public List<ILookupField> LookupFields
  39. {
  40. get { return this.lookupFields; }
  41. } // LookupFields
  42. // ----------------------------------------------------------------------
  43. public void Collect()
  44. {
  45. this.lookupFields.Clear();
  46. Start();
  47. } // Collect
  48. // ----------------------------------------------------------------------
  49. public static List<ILookupField> Collect( Control startControl )
  50. {
  51. return Collect( startControl, null );
  52. } // Collect
  53. // ----------------------------------------------------------------------
  54. public static List<ILookupField> Collect( Control startControl, string lookupName )
  55. {
  56. LookupFieldCollector lookupFieldCollector = new LookupFieldCollector( startControl, lookupName );
  57. lookupFieldCollector.Collect();
  58. return lookupFieldCollector.LookupFields;
  59. } // Collect
  60. // ----------------------------------------------------------------------
  61. protected override void VisitLookupFormField( Control control,
  62. ILookupField lookupField, IUserFormHeader formHeader )
  63. {
  64. bool match = true;
  65. if ( !string.IsNullOrEmpty( this.lookupName ) )
  66. {
  67. match = this.lookupName.Equals( lookupField.LookupName );
  68. }
  69. if ( match )
  70. {
  71. this.lookupFields.Add( lookupField );
  72. }
  73. } // VisitLookupFormField
  74. // ----------------------------------------------------------------------
  75. // members
  76. private readonly List<ILookupField> lookupFields = new List<ILookupField>();
  77. private readonly string lookupName;
  78. } // class LookupCollector
  79. } // namespace Itenso.WebUserForms.Controls
  80. // -- EOF -------------------------------------------------------------------