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 Msg_List : System.Web.UI.Page
{
    BLL.Message msg = new BLL.Message();
    BLL.UserInfo user = new BLL.UserInfo();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            this.Bind();
            this.Gv_Msg.Attributes.Add("style", "word-break:break-all;word-wrap:word");
            //if (user.IsLogin() == true)
            //{
            this.peAddReply.Visible = true;
            //}
        }
    }
    private void Bind()
    {
        DataTable table = msg.GetMessageList();
        this.Gv_Msg.DataSource = table.DefaultView;
        this.Gv_Msg.DataBind();
    }

    protected void ibSumbit_Click(object sender, ImageClickEventArgs e)
    {
        if (msg.createmessage(user.getUserName(), this.tbContent.Text, false) == 1)
        {
            this.Bind();
            Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", "<script>alert('留言成功')</script>", false);
        }
        else
        {
            Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", "<script>alert('留言失败')</script>", false);
        }
    }

    protected void Gv_Msg_ItemDataBound(object sender, DataGridItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            Panel panel = (Panel)e.Item.Cells[0].FindControl("peReply");
            DataRowView drv = (DataRowView)e.Item.DataItem;
            if (drv["RelayTime"].ToString() == "" || drv["RelayContent"].ToString() == "")
            {
                panel.Visible = false;
            }
        }
    }
}
