using System;
using System.Data;
using System.Configuration;
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;

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        this.Title = ConfigurationManager.AppSettings["WebTitle"].ToString() + "--在线留言";
        if (!Page.IsPostBack)
        {
            Random ran = new Random();
            DropDownList1.SelectedIndex = ran.Next(0, 20);
            Image1.ImageUrl = "headpic/" + DropDownList1.SelectedValue.ToString(); 
        }       
    }
    //头像列表
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        Image1.ImageUrl = "headpic/" + DropDownList1.SelectedValue.ToString();
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string name = txtName.Text.Trim().ToString();
        string email = txtEmail.Text.Trim().ToString();
        string web = txtWeb.Text.Trim().ToString();
        string qq = txtQQ.Text.Trim().ToString();
        string headpic = DropDownList1.SelectedValue.ToString();
        int qqh = chkHua.Checked == true ? 1 : 0;
        string content = FreeTextBox1.Text.ToString();
        string ip = Request.UserHostAddress;
        if (content.Length < 5||name.Length<1)
        {
            return;
        }
        int nResult=Insertleaveword(name, email, web, qq, content, headpic, qqh,ip);
        if (nResult == 1)
        {
            lblError.Text = "感谢您的留言！";
        }
        else
        {
            lblError.Text = "留言失败！";
        }
        txtEmail.Text = "";
        txtName.Text = "";
        txtQQ.Text = "";
        txtWeb.Text = "";
        FreeTextBox1.Text = "";
        chkHua.Checked = false;
    }
    //插入留言
    public int Insertleaveword(string sName, string sEmail, string sWeb, string sQQ, string sContent, string sHeadpic, int nQQh,string sIP)
    {
        INews shownews = new Mynews();
        int nResult = shownews.Executeinfo("INSERT INTO Leaveword(Visitorname,Visitoremail,Visitorweb,Visitorqq,Content,Headpic,qqh,Createdate,VisitorIP) VALUES('" +
            sName + "','" +
            sEmail + "','" +
            sWeb + "','" +
            sQQ + "','" +
            sContent + "','" +
            sHeadpic + "'," +
            nQQh + ",GetDate(),'"+
            sIP+"')");
        return nResult;

    }
}
