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.Net;
using sql;
public partial class Guestbook : System.Web.UI.Page
{
    SqlDB sqldb = new SqlDB();
    Operation operate = new Operation();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            GridViewBind();
        }
    }
    /// <summary>
    /// 绑定GridView1
    /// </summary>
    private void GridViewBind()
    {
        string strSql = "select * from guestbook";
        operate.GridViewBind(GridView1, strSql);
    }
    /// <summary>
    /// 发表评论
    /// </summary>   
    protected void ButTure_Click(object sender, EventArgs e)
    {
        string Ip = Request.UserHostAddress.ToString();
        string allValues = "'" + sqldb.CheckString(txtTitle.Text) + "','" + sqldb.CheckString(txtContent.Text) + "','" + sqldb.CheckString(txtUserName.Text) + "','" +sqldb.CheckString(txtEmail.Text)  + "','" +sqldb.CheckString(txtPhone.Text) + "','" + Ip + "','" + DateTime.Now + "','暂无回复',0,0";
        string strsql = "insert into guestbook (title,content,username,email,phone,ip,datetime,lastuser,hits,recallhits) values("+allValues+")";        
        if (sqldb.ExecuteNonQueryCheck(strsql) > 0)
        {
            lblMessage.Text = "恭喜您，评论发表成功！";
            txtContent.Text = "";
            txtUserName.Text = "匿名";
            txtEmail.Text = "";
            txtPhone.Text = "";
        }
        else
        {
            lblMessage.Text = "评论发表失败，请重试！";
        }
        GridViewBind();
    }    
    /// <summary>
    /// 实现GridView分页功能
    /// </summary>    
    protected void GridView1_OnPageIndexChanged(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        GridViewBind();
    }
}
