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.

154 lines
3.8 KiB

  1. using System;
  2. using System.Data;
  3. using System.Web.UI;
  4. using System.Web.UI.WebControls;
  5. using UDDI.API;
  6. using UDDI.API.Business;
  7. using UDDI.API.ServiceType;
  8. using UDDI;
  9. using UDDI.Diagnostics;
  10. using UDDI.Web;
  11. namespace UDDI.Web
  12. {
  13. public class IdentifierBagControl : UddiControl
  14. {
  15. protected KeyedReferenceCollection identifierBag;
  16. protected CacheObject cache = null;
  17. protected EntityBase entity = null;
  18. protected DataGrid grid;
  19. public void Initialize( KeyedReferenceCollection identifierBag )
  20. {
  21. this.identifierBag = identifierBag;
  22. grid.Columns[ 1 ].Visible = false;
  23. }
  24. public void Initialize( KeyedReferenceCollection identifierBag, EntityBase entity )
  25. {
  26. this.identifierBag = identifierBag;
  27. this.entity = entity;
  28. grid.Columns[ 1 ].Visible = true;
  29. }
  30. public void Initialize( KeyedReferenceCollection identifierBag, CacheObject cache )
  31. {
  32. this.identifierBag = identifierBag;
  33. this.cache = cache;
  34. grid.Columns[ 1 ].Visible = true;
  35. }
  36. protected void Page_Load( object sender, EventArgs e )
  37. {
  38. if( !Page.IsPostBack )
  39. PopulateDataGrid();
  40. if( grid.EditItemIndex >= 0 )
  41. SetEditMode();
  42. }
  43. void PopulateDataGrid()
  44. {
  45. grid.DataSource = identifierBag;
  46. grid.DataBind();
  47. }
  48. protected void Identifier_Edit( object sender, DataGridCommandEventArgs e )
  49. {
  50. int index = e.Item.ItemIndex;
  51. grid.EditItemIndex = index;
  52. SetEditMode();
  53. PopulateDataGrid();
  54. if( index >= identifierBag.Count )
  55. identifierBag.Add();
  56. KeyedReference keyedReference = identifierBag[ index ];
  57. DropDownList list = (DropDownList)grid.Items[ index ].Cells[ 0 ].FindControl( "tModelKey" );
  58. if( null != list )
  59. {
  60. ListItem item = list.Items.FindByValue( keyedReference.TModelKey.Substring( 5 ) );
  61. if( null != item )
  62. item.Selected = true;
  63. }
  64. }
  65. protected void OnEnterKeyPressed( object sender, EventArgs e )
  66. {
  67. Identifier_Update( sender, null );
  68. }
  69. protected void Identifier_Update( object sender, DataGridCommandEventArgs e )
  70. {
  71. Page.Validate();
  72. if( Page.IsValid )
  73. {
  74. int index = grid.EditItemIndex;
  75. DataGridItem item = grid.Items[ index ];
  76. if( index >= identifierBag.Count )
  77. identifierBag.Add();
  78. KeyedReference keyedReference = identifierBag[ index ];
  79. string tModelKey = ((DropDownList)item.FindControl( "tModelKey" )).SelectedItem.Value;
  80. keyedReference.TModelKey = "uuid:" + tModelKey;
  81. keyedReference.KeyName = ((TextBox)item.FindControl( "keyName" )).Text;
  82. keyedReference.KeyValue = ((TextBox)item.FindControl( "keyValue" )).Text;
  83. if( null != entity )
  84. entity.Save();
  85. if( null != cache )
  86. cache.Save();
  87. grid.EditItemIndex = -1;
  88. CancelEditMode();
  89. PopulateDataGrid();
  90. }
  91. }
  92. protected void Identifier_Cancel( object sender, DataGridCommandEventArgs e )
  93. {
  94. grid.EditItemIndex = -1;
  95. CancelEditMode();
  96. PopulateDataGrid();
  97. }
  98. protected void Identifier_Delete( object sender, DataGridCommandEventArgs e )
  99. {
  100. int index = e.Item.ItemIndex;
  101. identifierBag.RemoveAt( index );
  102. if( null != entity )
  103. entity.Save();
  104. if( null != cache )
  105. cache.Save();
  106. PopulateDataGrid();
  107. }
  108. protected void Identifier_Add( object sender, EventArgs e )
  109. {
  110. grid.EditItemIndex = identifierBag.Count;
  111. SetEditMode();
  112. identifierBag.Add();
  113. PopulateDataGrid();
  114. }
  115. }
  116. }