using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Web.Configuration;

public partial class manage_Manageconfig : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Loginjudge();
        if (!Page.IsPostBack) 
        {
            Getconfig();
        }
    }
    private void Modifyconfig(string sTitle,string sKeywords,string sDescription,string sRight,string sBeian,string sLianjie)
    {
        Configuration config = WebConfigurationManager.OpenWebConfiguration("~");
        AppSettingsSection appSection = (AppSettingsSection)config.GetSection("appSettings");
        appSection.Settings["WebTitle"].Value = sTitle;
        appSection.Settings["Keywords"].Value = sKeywords;
        appSection.Settings["Description"].Value = sDescription;
        appSection.Settings["Allrights"].Value = sRight;
        appSection.Settings["Beian"].Value = sBeian;
        appSection.Settings["Lianjie"].Value = sLianjie;
        config.Save();
    }
    private void Getconfig()
    {
        txtTitle.Text = ConfigurationManager.AppSettings["WebTitle"];
        txtKeys.Text = ConfigurationManager.AppSettings["Keywords"];
        txtDescript.Text = ConfigurationManager.AppSettings["Description"];
        txtRight.Text = ConfigurationManager.AppSettings["Allrights"];
        txtBeian.Text = ConfigurationManager.AppSettings["Beian"];
        txtLianjie.Text = ConfigurationManager.AppSettings["Lianjie"];
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Modifyconfig(txtTitle.Text.ToString(), txtKeys.Text.ToString(), txtDescript.Text.ToString(),txtRight.Text.ToString(),txtBeian.Text.ToString(),txtLianjie.Text.ToString());
        lblError.Text = "修改成功！";
    }
    private void Loginjudge()
    {
        if (Session["Login"] == null)
        {
            Response.Redirect("Error.aspx");
        }
        else
        {
            if (Session["Login"] != "pass")
            {
                Response.Redirect("Error.aspx");
            }

        }
    }
}
