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.

114 lines
2.4 KiB

  1. using System;
  2. using System.Collections.Specialized;
  3. using System.Data;
  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 TModelBagControl : UddiControl
  14. {
  15. protected CacheObject cache = null;
  16. protected StringCollection tModelBag = null;
  17. protected DataGrid grid;
  18. public void Initialize( StringCollection tModelBag, CacheObject cache )
  19. {
  20. this.cache = cache;
  21. this.tModelBag = tModelBag;
  22. }
  23. protected void Page_Load( object sender, EventArgs e )
  24. {
  25. if( !Page.IsPostBack )
  26. PopulateDataGrid( false );
  27. }
  28. void PopulateDataGrid( bool createNewRow )
  29. {
  30. DataTable table = new DataTable();
  31. DataRow row;
  32. int index = 0;
  33. table.Columns.Add( new DataColumn( "Index", typeof( int ) ) );
  34. table.Columns.Add( new DataColumn( "TModelName", typeof( string ) ) );
  35. table.Columns.Add( new DataColumn( "TModelKey", typeof( string ) ) );
  36. foreach( string tModelKey in tModelBag )
  37. {
  38. row = table.NewRow();
  39. row[0] = index;
  40. row[1] = Lookup.TModelName( tModelKey );
  41. row[2] = tModelKey;
  42. table.Rows.Add( row );
  43. index ++;
  44. }
  45. if( createNewRow )
  46. {
  47. row = table.NewRow();
  48. row[0] = index;
  49. row[1] = "";
  50. row[2] = "";
  51. table.Rows.Add( row );
  52. index ++;
  53. }
  54. grid.DataSource = new DataView( table );
  55. grid.DataBind();
  56. }
  57. protected void Grid_OnDelete( object sender, DataGridCommandEventArgs e )
  58. {
  59. int index = e.Item.ItemIndex;
  60. tModelBag.RemoveAt( index );
  61. if( null != cache )
  62. cache.Save();
  63. PopulateDataGrid( false );
  64. }
  65. protected void Grid_OnCancel( object sender, DataGridCommandEventArgs e )
  66. {
  67. grid.EditItemIndex = -1;
  68. CancelEditMode();
  69. PopulateDataGrid( false );
  70. }
  71. protected void Grid_OnAdd( object sender, EventArgs e )
  72. {
  73. grid.EditItemIndex = tModelBag.Count;
  74. SetEditMode();
  75. PopulateDataGrid( true );
  76. }
  77. protected void Selector_OnSelect( object sender, string key, string name )
  78. {
  79. tModelBag.Add( key );
  80. if( null != cache )
  81. cache.Save();
  82. grid.EditItemIndex = -1;
  83. CancelEditMode();
  84. PopulateDataGrid( false );
  85. }
  86. }
  87. }