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.

162 lines
3.6 KiB

  1. using System;
  2. using System.Data;
  3. using System.Web.UI;
  4. using System.Web.UI.WebControls;
  5. using UDDI;
  6. using UDDI.API;
  7. using UDDI.API.Business;
  8. using UDDI.API.ServiceType;
  9. using UDDI.Diagnostics;
  10. namespace UDDI.Web
  11. {
  12. public class DescriptionControl : UddiControl
  13. {
  14. protected DescriptionCollection descriptions;
  15. protected EntityBase entity;
  16. protected DataGrid grid;
  17. public void Initialize( DescriptionCollection descriptions )
  18. {
  19. this.descriptions = descriptions;
  20. grid.Columns[ 1 ].Visible = false;
  21. }
  22. public void Initialize( DescriptionCollection descriptions, EntityBase entity )
  23. {
  24. this.descriptions = descriptions;
  25. this.entity = entity;
  26. grid.Columns[ 1 ].Visible = true;
  27. }
  28. protected void Page_Load( object sender, EventArgs e )
  29. {
  30. if( !Page.IsPostBack )
  31. PopulateDataGrid();
  32. }
  33. void PopulateDataGrid()
  34. {
  35. grid.DataSource = descriptions;
  36. grid.DataBind();
  37. }
  38. protected DataView GetLanguages()
  39. {
  40. DataView view = Lookup.GetLanguages();
  41. int index = 0;
  42. foreach( Description description in descriptions )
  43. {
  44. if( index != grid.EditItemIndex )
  45. {
  46. foreach( DataRowView row in view )
  47. {
  48. if( row[ "isoLangCode" ].ToString() == description.IsoLangCode )
  49. {
  50. row.Delete();
  51. break;
  52. }
  53. }
  54. }
  55. index ++;
  56. }
  57. return view;
  58. }
  59. protected void Description_OnEdit( object sender, DataGridCommandEventArgs e )
  60. {
  61. int index = e.Item.ItemIndex;
  62. grid.EditItemIndex = index;
  63. SetEditMode();
  64. PopulateDataGrid();
  65. Description description = descriptions[ index ];
  66. DropDownList list = (DropDownList)grid.Items[ index ].Cells[ 1 ].FindControl( "language" );
  67. if( null != list )
  68. {
  69. ListItem item = list.Items.FindByValue( description.IsoLangCode );
  70. if( null != item )
  71. item.Selected = true;
  72. else
  73. {
  74. item = new ListItem( description.IsoLangCode, description.IsoLangCode );
  75. list.Items.Add( item );
  76. item.Selected = true;
  77. }
  78. }
  79. }
  80. protected void Description_OnUpdate( object sender, DataGridCommandEventArgs e )
  81. {
  82. Page.Validate();
  83. if( Page.IsValid )
  84. {
  85. string text = "";
  86. int index = grid.EditItemIndex;
  87. if( index >= descriptions.Count )
  88. descriptions.Add( "" );
  89. Description description = descriptions[ index ];
  90. description.IsoLangCode = ((DropDownList)e.Item.FindControl( "language" )).SelectedItem.Value;
  91. text = ((TextBox)e.Item.FindControl( "description" )).Text.Trim();
  92. description.Value = text;
  93. entity.Save();
  94. grid.EditItemIndex = -1;
  95. CancelEditMode();
  96. PopulateDataGrid();
  97. }
  98. }
  99. protected void Description_OnCancel( object sender, DataGridCommandEventArgs e )
  100. {
  101. grid.EditItemIndex = -1;
  102. CancelEditMode();
  103. PopulateDataGrid();
  104. }
  105. protected void Description_OnDelete( object sender, DataGridCommandEventArgs e )
  106. {
  107. int index = e.Item.ItemIndex;
  108. descriptions.RemoveAt( index );
  109. entity.Save();
  110. PopulateDataGrid();
  111. }
  112. protected void Description_OnAdd( object sender, EventArgs e )
  113. {
  114. int index = descriptions.Count;
  115. grid.EditItemIndex = index;
  116. SetEditMode();
  117. descriptions.Add( "" );
  118. PopulateDataGrid();
  119. DropDownList list = (DropDownList)grid.Items[ index ].Cells[ 1 ].FindControl( "language" );
  120. ListItem item = list.Items.FindByValue( Localization.GetCulture().TwoLetterISOLanguageName );
  121. if( null != item )
  122. item.Selected = true;
  123. }
  124. }
  125. }