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;

public partial class messages : Ycbw.Data.OleDbClient
{
    protected void Page_Load(object sender, EventArgs e)
    {
		if (!Page.IsPostBack)
		{
			this.DataBind();
		}
    }
	
    private void DataBind()
    {
		//列表
        string sql = " * from [b_messages]";
		string filter = " where id > 0";
		string order = " addtime desc";

        this.BindList(sql, filter, order, "b_messages", data_list, 10, text_pages);

        this.category.Text = "在线留言";
		this.Head.Title = "在线留言";
        this.path.Text = "您的位置：<a href=\"/\">首页</a> > 在线留言";
    }
	
	protected bool GetVisible(object g_reply)
	{
		if( g_reply.ToString() != "" )
			return true;
		else
			return false;
	}
	
	protected void button_submit_click(object sender, EventArgs e)
	{
        string error = "";

        this.Fill("select top 1 * from [b_messages] where ip = '"+ Request.ServerVariables["REMOTE_ADDR"]+"' order by addtime desc", "messages");

        if( this.Data.Tables["messages"].Rows.Count > 0 )
        {
            System.Data.DataRow dr = this.Data.Tables["messages"].Rows[0];

            DateTime lastpost = DateTime.Parse(dr["addtime"].ToString());

            TimeSpan ts = DateTime.Now - lastpost;

            if (ts.TotalSeconds < 60)
               error += "你操作的速度太快了，请稍候再尝试.....";  //ts.TotalSeconds.ToString();// 
        }
		
		if( this.c_content.Text == "文明上网，理性发言" || this.c_content.Text == "" )
			error += "·请输入留言内容！\\n";

		if( Session["vcode"] == null || Session["vcode"].ToString() != this.vcode.Text )
			error += "·验证码输入错误！\\n";

        if (error != "")
        {
            this.JWrite("alert('" + error + "');history.go(-1);");
        }
        else
        {
            string nickname = (this.nickname.Text != "") ? this.nickname.Text : "网友";
            string content  = this.c_content.Text;

            this.Execute("insert into [b_messages] (nickname, qq, content, ip, verify) values ('" + nickname + "', '" + qq.Text + "', '" + content + "', '" + Request.ServerVariables["REMOTE_ADDR"] + "', 0)");

            this.JWrite("alert('留言成功，我们会尽快回复您的留言');window.location.href='messages.aspx'");
        }

		this.Dispose(true);
	}
}
