Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

150 lines
3.0 KiB

  1. using System;
  2. using System.Web;
  3. using System.Web.UI;
  4. using System.Web.UI.WebControls;
  5. using System.Collections;
  6. using System.Collections.Specialized;
  7. namespace UDDI.Web
  8. {
  9. public class EditControl : WebControl, INamingContainer
  10. {
  11. protected ITemplate itemTemplate = null;
  12. protected ITemplate editItemTemplate = null;
  13. protected Control activeControl = null;
  14. public event CommandEventHandler EditCommand;
  15. public event CommandEventHandler CancelCommand;
  16. public event CommandEventHandler UpdateCommand;
  17. public Control ActiveControl
  18. {
  19. get
  20. {
  21. EnsureChildControls();
  22. if( EditMode )
  23. return Controls[ 1 ];
  24. else
  25. return Controls[ 0 ];
  26. }
  27. }
  28. public bool EditMode
  29. {
  30. get
  31. {
  32. if( null == ViewState[ "EditMode" ] )
  33. return false;
  34. return (bool)ViewState[ "EditMode" ];
  35. }
  36. }
  37. public void CancelEditMode()
  38. {
  39. ViewState[ "EditMode" ] = false;
  40. Controls[ 0 ].Visible = true;
  41. Controls[ 1 ].Visible = false;
  42. ((UddiPage)Page).CancelEditMode();
  43. }
  44. public void SetEditMode()
  45. {
  46. ViewState[ "EditMode" ] = true;
  47. Controls[ 0 ].Visible = false;
  48. Controls[ 1 ].Visible = true;
  49. ((UddiPage)Page).SetEditMode();
  50. }
  51. protected override bool OnBubbleEvent( object source, EventArgs e )
  52. {
  53. if( e is CommandEventArgs )
  54. {
  55. switch( ((CommandEventArgs)e).CommandName.ToLower() )
  56. {
  57. case "edit":
  58. if( null != EditCommand )
  59. {
  60. EditCommand( this, new CommandEventArgs( "Edit", ActiveControl ) );
  61. return true;
  62. }
  63. break;
  64. case "update":
  65. if( null != UpdateCommand )
  66. {
  67. UpdateCommand( this, new CommandEventArgs( "Update", ActiveControl ) );
  68. return true;
  69. }
  70. break;
  71. case "cancel":
  72. if( null != CancelCommand )
  73. {
  74. CancelCommand( this, new CommandEventArgs( "Cancel", ActiveControl ) );
  75. return true;
  76. }
  77. break;
  78. }
  79. }
  80. return false;
  81. }
  82. [ TemplateContainer( typeof( EditControlItem ) ) ]
  83. public ITemplate EditItemTemplate
  84. {
  85. get { return editItemTemplate; }
  86. set { editItemTemplate = value; }
  87. }
  88. [ TemplateContainer( typeof( EditControlItem ) ) ]
  89. public ITemplate ItemTemplate
  90. {
  91. get { return itemTemplate; }
  92. set { itemTemplate = value; }
  93. }
  94. protected override void CreateChildControls()
  95. {
  96. Controls.Clear();
  97. EditControlItem item = new EditControlItem();
  98. item.ID = "item";
  99. ItemTemplate.InstantiateIn( item );
  100. Controls.Add( item );
  101. item.DataBind();
  102. EditControlItem editItem = new EditControlItem();
  103. EditItemTemplate.InstantiateIn( editItem );
  104. editItem.ID = "editItem";
  105. Controls.Add( editItem );
  106. editItem.DataBind();
  107. Controls[ 0 ].Visible = !EditMode;
  108. Controls[ 1 ].Visible = EditMode;
  109. }
  110. }
  111. //
  112. // TODO: Remove unused method and class
  113. //
  114. public class EditControlItem : Control, INamingContainer
  115. {
  116. public EditControlItem()
  117. {
  118. }
  119. }
  120. }