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 Message : System.Web.UI.Page
{
    protected void Page_PreInit(object sender, EventArgs e)
    {
        Page.Theme = "SkinFile";
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["ad"].ToString() != "" && Session["pw"].ToString() != "")
        {
            if (Session["profile"].ToString() != "前台管理员")
            {
                DateTime now = DateTime.Now;
                times.Text = now.ToShortDateString();  　//日期
                cname.Text = Convert.ToString(Session["ad"]);
            }
            else
            {
                Response.Write("<script>window.alert('前台管理员不能留言！')</script>");
                Response.Redirect("Default.aspx");
            }
        }
        else
        {
            Response.Write("<script>window.alert('游客不能留言，请登录后留言！')</script>");
            Response.Redirect("Default.aspx");
        //Response.Redirect("default.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();
                    string strcontent = content.Text;
                    string strtitle = titles.Text;
                    //字符串过滤
                    strreplace str = new strreplace();
                    strcontent = str.msgstr(strcontent);
                    strtitle = str.msgstr(strtitle);
                    //End
                    String Sql = "insert into book(title,content,times,cname) values('" + strtitle + "','" + strcontent + "','" + times.Text + "','" + cname.Text + "')";
                    //OleDbCommand cmd = new OleDbCommand(Sql, one);
                    SqlCommand cmd = new SqlCommand(Sql, one);
                    cmd.ExecuteNonQuery();
                    Sql = "update customer set csend=csend+1 where cname='" + Convert.ToString(Session["ad"]) + "'";
                    cmd = new SqlCommand(Sql, one);
                    cmd.ExecuteNonQuery();
                    cmd.Dispose();
                    Response.Write("<script>window.alert('留言成功！')</script>");
                }
                catch (System.Exception ee)
                {
                    Response.Write(ee.Message.ToString());
                }
                finally
                {
                    one.Close();
                }
            }
            else
            {
                ClientScript.RegisterStartupScript(GetType(), "Message", "<SCRIPT LANGUAGE='javascript'>alert('验证码错误,请重新输入！');</script>");
            }
        }

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