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

编辑器/阅读器

开发平台:

C#

  1. // -- FILE ------------------------------------------------------------------
  2. // name       : UserFormLoader.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.Text;
  11. using System.Web.UI;
  12. using System.Reflection;
  13. using System.Collections.Generic;
  14. namespace Itenso.WebUserForms.Controls
  15. {
  16. // ------------------------------------------------------------------------
  17. public class UserFormLoader
  18. {
  19. // ----------------------------------------------------------------------
  20. public UserFormLoader( string virtualPath )
  21. : this( virtualPath, null )
  22. {
  23. } // UserFormLoader
  24. // ----------------------------------------------------------------------
  25. public UserFormLoader( string virtualPath, string formId )
  26. {
  27. if ( string.IsNullOrEmpty( virtualPath ) )
  28. {
  29. throw new ArgumentNullException( "virtualPath" );
  30. }
  31. this.virtualPath = virtualPath;
  32. this.formId = formId;
  33. } // UserFormLoader
  34. // ----------------------------------------------------------------------
  35. public string VirtualPath
  36. {
  37. get { return this.virtualPath; }
  38. } // VirtualPath
  39. // ----------------------------------------------------------------------
  40. public string FormId
  41. {
  42. get { return this.formId; }
  43. } // FormId
  44. // ----------------------------------------------------------------------
  45. public UserControl LoadUnsafe()
  46. {
  47. return LoadControl( null );
  48. } // LoadUnsafe
  49. // ----------------------------------------------------------------------
  50. public UserControl Load()
  51. {
  52. return LoadControl( new UserFormCodeValidator() );
  53. } // Load
  54. // ----------------------------------------------------------------------
  55. public UserControl Load( UserFormCodeValidator codeValidator )
  56. {
  57. if ( codeValidator == null )
  58. {
  59. throw new ArgumentNullException( "codeValidator" );
  60. }
  61. return LoadControl( codeValidator );
  62. } // Load
  63. // ----------------------------------------------------------------------
  64. private UserControl LoadControl( UserFormCodeValidator codeValidator )
  65. {
  66. UserControl userControl = new UserControl().LoadControl( this.virtualPath ) as UserControl;
  67. if ( codeValidator != null )
  68. {
  69. codeValidator.Validate( userControl );
  70. }
  71. SetupForm( userControl );
  72. return userControl;
  73. } // LoadControl
  74. // ----------------------------------------------------------------------
  75. protected virtual void SetupForm( UserControl userControl )
  76. {
  77. if ( string.IsNullOrEmpty( this.formId ) )
  78. {
  79. return;
  80. }
  81. if ( userControl != null && string.IsNullOrEmpty( userControl.ID ) )
  82. {
  83. userControl.ID = this.formId;
  84. }
  85. } // SetupForm
  86. // ----------------------------------------------------------------------
  87. // members
  88. private readonly string virtualPath;
  89. private readonly string formId;
  90. } // class UserFormLoader
  91. } // namespace Itenso.WebUserForms.Controls
  92. // -- EOF -------------------------------------------------------------------