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.

125 lines
2.7 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 EmailControl : UddiControl
  13. {
  14. protected EmailCollection emails;
  15. protected EntityBase entity;
  16. protected DataGrid grid;
  17. public void Initialize( EmailCollection emails )
  18. {
  19. this.emails = emails;
  20. grid.Columns[ 1 ].Visible = false;
  21. }
  22. public void Initialize( EmailCollection emails, EntityBase entity )
  23. {
  24. this.emails = emails;
  25. this.entity = entity;
  26. grid.Columns[ 1 ].Visible = true;
  27. }
  28. protected void Page_Init( object sender, EventArgs e )
  29. {
  30. grid.Columns[ 0 ].HeaderText = Localization.GetString( "HEADING_EMAIL" );
  31. grid.Columns[ 1 ].HeaderText = Localization.GetString( "HEADING_ACTIONS" );
  32. }
  33. protected void Page_Load( object sender, EventArgs e )
  34. {
  35. if( !Page.IsPostBack )
  36. PopulateDataGrid();
  37. if( grid.EditItemIndex >= 0 )
  38. SetEditMode();
  39. }
  40. void PopulateDataGrid()
  41. {
  42. grid.DataSource = emails;
  43. grid.DataBind();
  44. }
  45. protected void DataGrid_Edit( object sender, DataGridCommandEventArgs e )
  46. {
  47. int index = e.Item.ItemIndex;
  48. grid.EditItemIndex = index;
  49. SetEditMode();
  50. PopulateDataGrid();
  51. }
  52. protected void OnEnterKeyPressed( object sender, EventArgs e )
  53. {
  54. DataGrid_Update( sender, null );
  55. }
  56. protected void DataGrid_Update( object sender, DataGridCommandEventArgs e )
  57. {
  58. Page.Validate();
  59. if( Page.IsValid )
  60. {
  61. int index = grid.EditItemIndex;
  62. if( index >= emails.Count )
  63. emails.Add();
  64. Email email = emails[ index ];
  65. DataGridItem item = grid.Items[ index ];
  66. email.Value = ((TextBox)item.FindControl( "email" )).Text;
  67. email.UseType = ((TextBox)item.FindControl( "useType" )).Text;
  68. entity.Save();
  69. grid.EditItemIndex = -1;
  70. CancelEditMode();
  71. PopulateDataGrid();
  72. }
  73. }
  74. protected void DataGrid_Cancel( object sender, DataGridCommandEventArgs e )
  75. {
  76. grid.EditItemIndex = -1;
  77. CancelEditMode();
  78. PopulateDataGrid();
  79. }
  80. protected void DataGrid_Delete( object sender, DataGridCommandEventArgs e )
  81. {
  82. int index = e.Item.ItemIndex;
  83. emails.RemoveAt( index );
  84. entity.Save();
  85. PopulateDataGrid();
  86. }
  87. protected void DataGrid_Add( object sender, EventArgs e )
  88. {
  89. grid.EditItemIndex = emails.Count;
  90. SetEditMode();
  91. emails.Add();
  92. PopulateDataGrid();
  93. }
  94. }
  95. }