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.

198 lines
4.3 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. namespace UDDI.Web
  11. {
  12. public class NameControl : UddiControl
  13. {
  14. protected NameCollection names = null;
  15. protected EntityBase parentEntity = null;
  16. protected string parentKey = null;
  17. protected DataGrid grid;
  18. public void Initialize( NameCollection names )
  19. {
  20. this.names = names;
  21. grid.Columns[ 1 ].Visible = false;
  22. }
  23. public void Initialize( NameCollection names, EntityBase parentEntity, string parentKey )
  24. {
  25. this.names = names;
  26. this.parentEntity = parentEntity;
  27. this.parentKey = parentKey;
  28. grid.Columns[ 1 ].Visible = true;
  29. }
  30. protected void Page_Load( object sender, EventArgs e )
  31. {
  32. if( !Page.IsPostBack )
  33. PopulateDataGrid();
  34. }
  35. void PopulateDataGrid()
  36. {
  37. grid.DataSource = names;
  38. grid.DataBind();
  39. }
  40. protected DataView GetLanguages()
  41. {
  42. DataView view = Lookup.GetLanguages();
  43. int index = 0;
  44. foreach( Name name in names )
  45. {
  46. if( index != grid.EditItemIndex )
  47. {
  48. foreach( DataRowView row in view )
  49. {
  50. if( row[ "isoLangCode" ].ToString() == name.IsoLangCode )
  51. {
  52. row.Delete();
  53. break;
  54. }
  55. }
  56. }
  57. index ++;
  58. }
  59. return view;
  60. }
  61. protected void Name_OnEdit( object sender, DataGridCommandEventArgs e )
  62. {
  63. int index = e.Item.ItemIndex;
  64. grid.EditItemIndex = index;
  65. SetEditMode();
  66. PopulateDataGrid();
  67. Name name = names[ index ];
  68. DropDownList list = (DropDownList)grid.Items[ index ].Cells[ 0 ].FindControl( "language" );
  69. if( null != list )
  70. {
  71. ListItem item = list.Items.FindByValue( name.IsoLangCode );
  72. if( null != item )
  73. {
  74. item.Selected = true;
  75. }
  76. else
  77. {
  78. item = new ListItem( name.IsoLangCode, name.IsoLangCode );
  79. list.Items.Add( item );
  80. item.Selected = true;
  81. }
  82. }
  83. }
  84. protected void OnEnterKeyPressed( object sender, EventArgs e )
  85. {
  86. Name_OnUpdate( sender, null );
  87. }
  88. protected void Name_OnUpdate( object sender, DataGridCommandEventArgs e )
  89. {
  90. Page.Validate();
  91. if( Page.IsValid )
  92. {
  93. int index = grid.EditItemIndex;
  94. DataGridItem item = grid.Items[ index ];
  95. if( index >= names.Count )
  96. names.Add( "" );
  97. Name name = names[ index ];
  98. name.IsoLangCode = ((DropDownList)item.FindControl( "language" )).SelectedItem.Value;
  99. name.Value = ((TextBox)item.FindControl( "name" )).Text.Trim();
  100. CheckBox checkbox = (CheckBox)item.FindControl( "default" );
  101. if( index > 0 && null != checkbox && checkbox.Checked )
  102. {
  103. for( int i = index; i > 0; i -- )
  104. names[ i ] = names[ i - 1 ];
  105. names[ 0 ] = name;
  106. index = 0;
  107. }
  108. parentEntity.Save();
  109. if( 0 == index && !IsDownlevel )
  110. {
  111. Page.RegisterStartupScript(
  112. "Reload",
  113. ClientScripts.ReloadExplorerPane(
  114. parentKey ) );
  115. }
  116. grid.EditItemIndex = -1;
  117. CancelEditMode();
  118. PopulateDataGrid();
  119. }
  120. }
  121. protected void Name_OnCancel( object sender, DataGridCommandEventArgs e )
  122. {
  123. grid.EditItemIndex = -1;
  124. CancelEditMode();
  125. PopulateDataGrid();
  126. }
  127. protected void Name_OnDelete( object sender, DataGridCommandEventArgs e )
  128. {
  129. int index = e.Item.ItemIndex;
  130. names.RemoveAt( index );
  131. parentEntity.Save();
  132. PopulateDataGrid();
  133. if( 0 == index && !IsDownlevel )
  134. {
  135. Page.RegisterStartupScript(
  136. "Reload",
  137. ClientScripts.ReloadExplorerPane(
  138. parentKey ) );
  139. }
  140. }
  141. protected void Name_OnAdd( object sender, EventArgs e )
  142. {
  143. int index = names.Count;
  144. grid.EditItemIndex = index;
  145. SetEditMode();
  146. names.Add( "" );
  147. PopulateDataGrid();
  148. DropDownList list = (DropDownList)grid.Items[ index ].Cells[ 0 ].FindControl( "language" );
  149. ListItem item = list.Items.FindByValue( Localization.GetCulture().TwoLetterISOLanguageName );
  150. if( null != item )
  151. item.Selected = true;
  152. }
  153. }
  154. }