PageRenderTime 46ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/BlogEngine/BlogEngine.NET/admin/Settings/PingServices.aspx.cs

#
C# | 113 lines | 74 code | 14 blank | 25 comment | 2 complexity | c30a16abc97fb931e7174375f8894ef4 MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0, BSD-3-Clause
  1. namespace admin.Settings
  2. {
  3. #region Using
  4. using System;
  5. using System.Collections.Specialized;
  6. using System.Collections.Generic;
  7. using System.Web.UI.WebControls;
  8. using BlogEngine.Core.Providers;
  9. using App_Code;
  10. #endregion
  11. public partial class PingServices : System.Web.UI.Page
  12. {
  13. /// <summary>
  14. /// Handles the Load event of the Page control.
  15. /// </summary>
  16. /// <param name="sender">The source of the event.</param>
  17. /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
  18. protected void Page_Load(object sender, EventArgs e)
  19. {
  20. WebUtils.CheckRightsForAdminSettingsPage(false);
  21. if (!Page.IsPostBack)
  22. {
  23. BindGrid();
  24. }
  25. grid.RowEditing += grid_RowEditing;
  26. grid.RowUpdating += grid_RowUpdating;
  27. grid.RowCancelingEdit += delegate { Response.Redirect(Request.RawUrl); };
  28. grid.RowDeleting += grid_RowDeleting;
  29. btnAdd.Click += btnAdd_Click;
  30. btnAdd.Text = Resources.labels.add + " ping service";
  31. }
  32. /// <summary>
  33. /// Handles the Click event of the btnAdd control.
  34. /// </summary>
  35. /// <param name="sender">The source of the event.</param>
  36. /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
  37. void btnAdd_Click(object sender, EventArgs e)
  38. {
  39. StringCollection col = BlogService.LoadPingServices();
  40. string service = txtNewCategory.Text;
  41. if (!col.Contains(service))
  42. {
  43. col.Add(service);
  44. BlogService.SavePingServices(col);
  45. }
  46. Response.Redirect(Request.RawUrl);
  47. }
  48. /// <summary>
  49. /// Handles the RowDeleting event of the grid control.
  50. /// </summary>
  51. /// <param name="sender">The source of the event.</param>
  52. /// <param name="e">The <see cref="System.Web.UI.WebControls.GridViewDeleteEventArgs"/> instance containing the event data.</param>
  53. void grid_RowDeleting(object sender, GridViewDeleteEventArgs e)
  54. {
  55. string service = grid.DataKeys[e.RowIndex].Value.ToString();
  56. StringCollection col = BlogService.LoadPingServices();
  57. col.Remove(service);
  58. BlogService.SavePingServices(col);
  59. Response.Redirect(Request.RawUrl);
  60. }
  61. /// <summary>
  62. /// Handles the RowUpdating event of the grid control.
  63. /// </summary>
  64. /// <param name="sender">The source of the event.</param>
  65. /// <param name="e">The <see cref="System.Web.UI.WebControls.GridViewUpdateEventArgs"/> instance containing the event data.</param>
  66. void grid_RowUpdating(object sender, GridViewUpdateEventArgs e)
  67. {
  68. string service = grid.DataKeys[e.RowIndex].Value.ToString();
  69. TextBox textbox = (TextBox)grid.Rows[e.RowIndex].FindControl("txtName");
  70. StringCollection col = BlogService.LoadPingServices();
  71. col.Remove(service);
  72. col.Add(textbox.Text);
  73. BlogService.SavePingServices(col);
  74. Response.Redirect(Request.RawUrl);
  75. }
  76. /// <summary>
  77. /// Handles the RowEditing event of the grid control.
  78. /// </summary>
  79. /// <param name="sender">The source of the event.</param>
  80. /// <param name="e">The <see cref="System.Web.UI.WebControls.GridViewEditEventArgs"/> instance containing the event data.</param>
  81. void grid_RowEditing(object sender, GridViewEditEventArgs e)
  82. {
  83. grid.EditIndex = e.NewEditIndex;
  84. BindGrid();
  85. }
  86. private void BindGrid()
  87. {
  88. StringCollection col = BlogService.LoadPingServices();
  89. SortedDictionary<string, string> dic = new SortedDictionary<string, string>();
  90. foreach (string services in col)
  91. {
  92. dic.Add(services, services);
  93. }
  94. grid.DataKeyNames = new string[] { "key" };
  95. grid.DataSource = dic;
  96. grid.DataBind();
  97. }
  98. }
  99. }