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