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.

195 lines
4.7 KiB

  1. using System;
  2. using System.Data;
  3. using System.Web;
  4. using System.Web.UI;
  5. using System.Web.UI.WebControls;
  6. using UDDI.API;
  7. using UDDI.API.Business;
  8. using UDDI.API.ServiceType;
  9. using UDDI;
  10. using UDDI.Diagnostics;
  11. namespace UDDI.Web
  12. {
  13. public class CategoryBagControl : UddiControl
  14. {
  15. protected KeyedReferenceCollection categoryBag = null;
  16. protected CacheObject cache = null;
  17. protected EntityBase entity = null;
  18. protected bool FindMode;
  19. protected DataGrid grid;
  20. protected Label taxonomyID;
  21. protected Label taxonomyName;
  22. protected Label tModelKey;
  23. protected Label keyName;
  24. protected Label keyValue;
  25. protected Label path;
  26. public void Initialize( KeyedReferenceCollection categoryBag )
  27. {
  28. this.categoryBag = categoryBag;
  29. grid.Columns[ 2 ].Visible = false;
  30. }
  31. public void Initialize( KeyedReferenceCollection categoryBag, EntityBase entity )
  32. {
  33. this.categoryBag = categoryBag;
  34. this.entity = entity;
  35. grid.Columns[ 2 ].Visible = true;
  36. }
  37. public void Initialize( KeyedReferenceCollection categoryBag, CacheObject cache )
  38. {
  39. this.categoryBag = categoryBag;
  40. this.cache = cache;
  41. grid.Columns[ 2 ].Visible = true;
  42. }
  43. public void Initialize( KeyedReferenceCollection categoryBag, CacheObject cache, bool rebind )
  44. {
  45. this.categoryBag = categoryBag;
  46. this.cache = cache;
  47. grid.Columns[ 2 ].Visible = true;
  48. if( rebind )
  49. CategoryBag_DataBind( false );
  50. }
  51. protected void Page_Load( object sender, EventArgs e )
  52. {
  53. if( !Page.IsPostBack )
  54. CategoryBag_DataBind( false );
  55. }
  56. protected Control GetControl( string id, int cell )
  57. {
  58. return grid.Items[ grid.EditItemIndex ].Cells[ cell ].FindControl( id );
  59. }
  60. protected void CategoryBag_DataBind( bool insertRow )
  61. {
  62. DataTable table = new DataTable();
  63. DataRow row;
  64. int index = 0;
  65. table.Columns.Add( new DataColumn( "Index", typeof( int ) ) );
  66. table.Columns.Add( new DataColumn( "TModelName", typeof( string ) ) );
  67. table.Columns.Add( new DataColumn( "KeyName", typeof( string ) ) );
  68. table.Columns.Add( new DataColumn( "KeyValue", typeof( string ) ) );
  69. table.Columns.Add( new DataColumn( "TModelKey", typeof( string ) ) );
  70. foreach( KeyedReference keyedReference in categoryBag )
  71. {
  72. row = table.NewRow();
  73. row[0] = index;
  74. row[1] = HttpUtility.HtmlEncode( Lookup.TModelName( keyedReference.TModelKey ) );
  75. row[2] = HttpUtility.HtmlEncode( keyedReference.KeyName );
  76. row[3] = HttpUtility.HtmlEncode( keyedReference.KeyValue );
  77. row[4] = keyedReference.KeyValue;
  78. table.Rows.Add( row );
  79. index ++;
  80. }
  81. if( insertRow )
  82. {
  83. row = table.NewRow();
  84. row[0] = index;
  85. row[1] = "";
  86. row[2] = "";
  87. row[3] = "";
  88. row[4] = "";
  89. table.Rows.Add( row );
  90. index ++;
  91. }
  92. grid.DataSource = table.DefaultView;
  93. grid.ShowFooter = !FindMode;
  94. grid.DataBind();
  95. }
  96. protected void CategoryBag_OnCommand( object sender, DataGridCommandEventArgs e )
  97. {
  98. switch( e.CommandName.ToLower() )
  99. {
  100. case "add":
  101. CategoryBag_OnAdd(sender, e );
  102. break;
  103. case "select":
  104. CategoryChooser_OnSelect( sender, e );
  105. break;
  106. case "cancel":
  107. CategoryChooser_OnCancel( sender, e );
  108. break;
  109. }
  110. }
  111. protected void CategoryBag_OnAdd( object sender, DataGridCommandEventArgs e )
  112. {
  113. grid.EditItemIndex = categoryBag.Count;
  114. SetEditMode();
  115. CategoryBag_DataBind( true );
  116. }
  117. protected void CategoryBag_OnDelete( object sender, DataGridCommandEventArgs e )
  118. {
  119. int index = e.Item.ItemIndex;
  120. categoryBag.RemoveAt( index );
  121. if( null != entity )
  122. entity.Save();
  123. if( null != cache )
  124. cache.Save();
  125. CategoryBag_DataBind( false );
  126. }
  127. protected void CategoryChooser_OnSelect( object sender, DataGridCommandEventArgs e )
  128. {
  129. KeyedReference keyedReference = categoryBag[ categoryBag.Add() ];
  130. CategoryBrowserControl b = (CategoryBrowserControl)GetControl( "browser", 1 );
  131. keyedReference.TModelKey = "uuid:" + b.TModelKey;
  132. keyedReference.KeyName = HttpUtility.HtmlDecode( b.KeyName );
  133. keyedReference.KeyValue = b.KeyValue;
  134. if( null != entity )
  135. entity.Save();
  136. if( null != cache )
  137. cache.Save();
  138. grid.EditItemIndex = -1;
  139. CancelEditMode();
  140. CategoryBag_DataBind( false );
  141. }
  142. protected void CategoryChooser_OnCancel( object sender, DataGridCommandEventArgs e )
  143. {
  144. grid.EditItemIndex = -1;
  145. CancelEditMode();
  146. CategoryBag_DataBind( false );
  147. }
  148. }
  149. }