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 adcall : System.Web.UI.Page
{
    string Sql;
    int id;
    protected void Page_PreInit(object sender, EventArgs e)
    {
        Page.Theme = "SkinFile";
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Session["profile"].ToString() == "前台管理员")
            {
                DateTime now = DateTime.Now;
                times.Text = now.ToShortDateString();  　//日期
                cname.Text = Convert.ToString(Session["ad"]);

                SqlConnection one = conn.sqlconn();
                
                try
                {
                    one.Open();
                    id = int.Parse(Request["id"]);
                    Sql = "select * from book where id=" + id;
                    SqlCommand cmd = new SqlCommand(Sql, one);
                    SqlDataReader rs = cmd.ExecuteReader();
                    if (rs.Read())
                    {
                        content.Text = rs["recall"].ToString();
                    }
                    rs.Dispose();
                    cmd.Dispose();
                }
                catch (System.Exception ee)
                {
                    Response.Write(ee.Message.ToString());
                }
                finally
                {
                    one.Close();
                }
            }
            else
            {
                Response.Write("<script>window.alert('你不是前台管理员,不能回复,请登陆！')</script>");
                Response.Write("<meta http-equiv='refresh' content='0; url=admin.aspx'>");
            }
        }
    }
    protected void send_Click(object sender, EventArgs e)
    {
        SqlConnection one = conn.sqlconn();
        if (Page.IsValid)
        {
            if (this.tbck.Text == Request.Cookies["vCode"].Value)
            {
                try
                {
                    one.Open();
                    id = int.Parse(Request["id"]);
                    //过滤字符串
                    string strcontent = content.Text;
                    strreplace str = new strreplace();
                    strcontent = str.msgstr(strcontent);
                    //End
                    Sql = "update book set recall='" + strcontent + "' where id=" + id;
                    SqlCommand cmd = new SqlCommand(Sql, one);
                    cmd.ExecuteNonQuery();
                    cmd.Dispose();
                }
                catch (System.Exception ee)
                {
                    Response.Write(ee.Message.ToString());
                }
                finally
                {
                    one.Close();
                    Response.Write("<script>window.alert('回复成功！')</script>");
                }
            }
            else
            {
                ClientScript.RegisterStartupScript(GetType(), "Message", "<SCRIPT LANGUAGE='javascript'>alert('验证码错误,请重新输入！');</script>");
            }
        }

    }
    protected void reset_Click(object sender, EventArgs e)
    {
        content.Text = "";
        content.Focus();
    }
}
