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;

public partial class WebMain_news_CustmerComments : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            databind();
        }

    }

    public void databind()
    {
            SqlConnection conn = CDatabase.wtoconn();
            conn.Open();
            SqlDataAdapter sda = new SqlDataAdapter("select  * from Comments where pid=0  order by FBdate desc", conn);
            DataSet ds = new DataSet();
            sda.Fill(ds, "cu");
            this.pl.DataSource = Doadmin.psgb(ds, Table1,5, 0);
            pl.DataKeyField = "id";
            this.pl.DataBind();
            Panel pa;
            SqlCommand smdc;
            SqlDataReader sdrc;
            Label lac;
            for (int i = 0; i < pl.Items.Count; i++)
            {
                smdc = new SqlCommand("select  * from Comments where pid=0 and id="+pl.DataKeys[i].ToString(), conn);
                sdrc = smdc.ExecuteReader();
                sdrc.Read();
                if (sdrc["isfp"].ToString() == "n")
                {
                    pa = (Panel)pl.Items[i].FindControl("tr2");
                    pa.Visible = false;
                    lac = (Label)pl.Items[i].FindControl("txt1");
                    lac.Text = "留言已发布，等待回复";
                }
                else
                {
                    pa = (Panel)pl.Items[i].FindControl("tr2");
                    pa.Visible = true;
                    lac = (Label)pl.Items[i].FindControl("txt1");
                    lac.Text = sdrc["Content"].ToString();
                    lac = (Label)pl.Items[i].FindControl("txt2");
                    lac.Text = sdrc["reContent"].ToString();
                    
                }
                sdrc.Close();
            }
            conn.Close();
            
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        string name, email, telphoto, cont,userip="",fbdate;
      if(Request.ServerVariables["HTTP_VIA"]!=null)
      {

          userip = Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString();

　　  }
      else
      {

          userip = Request.ServerVariables["REMOTE_ADDR"].ToString();
 
　  　}
        name = this.name.Text;
        email = this.email.Text;
        telphoto = this.telphoto.Text;
        cont = this.cont.Text;
        SqlConnection conn = CDatabase.wtoconn();
        conn.Open();
        SqlCommand smd = new SqlCommand("select MessageSet from SystemBasicInformation", conn);
        string closeandopen = Convert.ToString(smd.ExecuteScalar());
        conn.Close();
        string txt = "胡锦涛|黄色|毛片|AV片|打倒|达赖|反动|处女|温家宝|枪弹|中共中央总书记|共产党|四人帮|毛泽东|";
        string[] tt1 = txt.Split('|');
        bool bob=true;
        for (int i = 0; i < tt1.Length - 1; i++)
        {
            if ((cont.Length - (cont.Replace(tt1[i], "")).Length > 0))
            {
                bob = false;
                break;
            }

        }


        if (bob)
        {
            if (Doadmin.Exec("insert into Comments(username,isfp,Content,ip,pid,FBdate,email,telphoto,shefen,reContent,redate) values('" + name + "','" + closeandopen + "','" + cont + "','" + userip + "',0,'" + DateTime.Now.ToString() + "','" + email + "','" + telphoto + "','客服回复','留言已发布，等待回复','"+DateTime.Now.ToString()+"')"))
            {
                Response.Write("<script>alert('留言成功 ');window.location.href('/china/BBS.aspx')</script>");
            }
            else
            {
                Response.Write("<script>alert('留言不成功')</script>");
            }
        }
        else
        {
            Response.Write("<script>alert('请不要输入非法信息,此次留言不成功 ');window.location.href('/china/BBS.aspx')</script>");
        }
    }
}
