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 dairy_see : System.Web.UI.Page
{
    SqlConnection one = conn.sqlconn();
    protected void Page_PreInit(object sender, EventArgs e)
    {
        Page.Theme = "SkinFile";
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            lbid.Text = Request.QueryString["id"];
            sqloper sqloper = new sqloper();
            sqloper.dodata("update dairy set dbit=dbit+1 where id="+lbid.Text, one);
            plbind();
        }
    }

    //短日期处理
    protected string short_time(object times)
    {
        stringdo shortime = new stringdo();
        return shortime.short_time(times);
    }

    //显示日记的内容
    protected string showdairy(string val)
    {
        string readval = "";
        string sql = "select * from dairy where id=" + lbid.Text;
        sqloper sqloper = new sqloper();
        SqlDataReader rs = sqloper.readsql(sql, one);
        if (rs.Read())
        {
            readval = rs[val].ToString();
        }
        rs.Dispose();
        return readval;
    }

    //读取评论的列表
    protected void plbind()
    {
        SqlConnection one = conn.sqlconn();
        string sql = "select * from redai where drid=" + lbid.Text + " order by id desc";
        sqloper sqloper = new sqloper();
        SqlDataReader rs = sqloper.readsql(sql, one);
        try
        {
            DataList2.DataSource = rs;
            DataList2.DataBind();

        }
        catch (System.Exception ee)
        {
            Response.Write(ee.Message.ToString());
        }
        finally
        {
            DataList2.Dispose();
            rs.Dispose();
            one.Dispose();
            one.Close();
        }
    }

    //评论用户的信息
    protected string usermsg(int plid)
    {
        SqlConnection one = conn.sqlconn();
        string sql = "select * from customer where id=" + plid + " order by id desc";
        sqloper sqloper = new sqloper();
        SqlDataReader rs = sqloper.readsql(sql, one);
        string str="";
        try
        {
            if (rs.Read())
            {
                str = "<table width=\"50\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr><td><div align=\"center\"><img src=\"" + rs["chead"].ToString() + "\"/></div></td></tr><tr><td><div align=\"center\">" + rs["cname"].ToString() + "</div></td></tr></table>";
            }
        }
        catch { }
        finally 
        {
            rs.Dispose();
            one.Close();
        }
        return str;
    }

    //判断是否有评论
    protected int ispl(int drid)
    {
        SqlConnection one = conn.sqlconn();
        string sql = "select * from redai where drid=" + drid;
        sqloper sqloper = new sqloper();
        SqlDataReader rs = sqloper.readsql(sql, one);
        int str=0;
        if (!rs.Read())
        {
            str = 1;
        }
        rs.Dispose();
        return str;
    }

    //提交评论
    protected void plsend_Click(object sender, EventArgs e)
    {
        SqlConnection one = conn.sqlconn();
        int drid = Convert.ToInt16(lbid.Text);
        int drwriter=writerid();
        string drcontent = tbpl.Text;
        string drtime = DateTime.Now.ToShortDateString();
        int drunable = 0;
        string vcode = Request.Cookies["vCode"].Value;
        //过滤字符串
        strreplace str = new strreplace();
        drcontent = str.msgstr(drcontent);
        vcode = str.txtstr(vcode);
        //End
        if (this.tbck.Text == vcode)
        {
            string sql = "insert into redai values("+drid+","+drwriter+",'"+drcontent+"','"+drtime+"',"+drunable+")";
            sqloper sqloper = new sqloper();
            try
            {
                sqloper.dodata(sql, one);
                plbind();
                ClientScript.RegisterStartupScript(GetType(), "Message", "<SCRIPT LANGUAGE='javascript'>alert('发表成功!');</script>");
            }
            catch { }
        }
        else
        {
            ClientScript.RegisterStartupScript(GetType(), "Message", "<SCRIPT LANGUAGE='javascript'>alert('验证码错误,请重新输入！');</script>");
        }
    }

    protected int writerid()
    {
        SqlConnection one = conn.sqlconn();
        string sql = "select * from customer where cname='" + Session["ad"] + "'";
        sqloper sqloper = new sqloper();
        int userid=0;
        if (Session["ad"].ToString() != "游客")
        {
            userid = Convert.ToInt16(sqloper.loaddb(sql, "id"));
            
        }
        return userid;
    }

    protected string htmlstr(string data)
    {
        strreplace str = new strreplace();
        return str.rehtmlstr(data);
    }
}
