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.Data.SqlClient;
using wormstrdo;

public partial class wormadmin_config : System.Web.UI.Page
{
    SqlConnection one = conn.sqlconn();   //建立连接数据库对象
    sqloper sqloper = new sqloper();
    protected void Page_PreInit(object sender, EventArgs e)
    {
        if (Session["superad"] == null || Session["superpw"] == null)
        {
            Response.Redirect("login.aspx");
        }
        else
        {
            Page.Theme = "SkinFile";
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if(!IsPostBack)
        {
            try
            {
                one.Open();
                SqlDataReader rs= sqloper.readsql("select * from config", one);
                if (rs.Read())
                {
                    strreplace str = new strreplace();
                    book_name.Text = str.rehtmlstr(rs["gname"].ToString());
                    book_key.Text = str.rehtmlstr(rs["gkey"].ToString());
                    book_ip.Text = str.rehtmlstr(rs["gstopip"].ToString());
                    book_error.Text = str.rehtmlstr(rs["gerror"].ToString());
                    FCKeditor1.Value = str.rehtmlstr(rs["gmsg"].ToString());
                    if (Convert.ToInt16(rs["gopen"]) == 1)
                    {
                        book_open.SelectedIndex = 0;
                    }
                    else
                    {
                        book_open.SelectedIndex = 1;
                    }
                }
            }
            catch (System.Exception ee)
            {
                Response.Write("a"+ee.Message.ToString());
            }
            finally
            {
                one.Dispose();
                one.Close();
            }
        }
    }
    protected void send_Click(object sender, EventArgs e)
    {
        try
        {
            strreplace str = new strreplace();
            string sql = "update config set gname='" + str.htmlstr(book_name.Text) + "',gkey='" + str.htmlstr(book_key.Text) + "',gstopip='" + str.htmlstr(book_ip.Text) + "',gerror='" + str.htmlstr(book_error.Text) + "',gopen=" + book_open.SelectedValue + ",gmsg='" + str.htmlstr(FCKeditor1.Value) + "'";
            sqloper.dodata(sql, one);
            ClientScript.RegisterStartupScript(GetType(), "Message", "<SCRIPT LANGUAGE='javascript'>alert('修改成功!');</script>");
        }
        catch (System.Exception ee)
        {
            Response.Write("b" + ee.Message.ToString());
        }
        finally
        {
        }
    }

    protected void reset_Click(object sender, EventArgs e)
    {
        book_error.Text = "";
        book_ip.Text = "";
        book_key.Text = "";
        book_name.Text = "";
        book_open.SelectedIndex = 1;
    }
}
