using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using TopWinCMS.BLL;
using TopWinCMS.Common;
namespace TopWinCMS.WebUI.Admin
{
    /// <summary>
    /// Admin_Guestbook_Manage 的摘要说明。
    /// </summary>
    public partial class Admin_GuestBook_Manage : TopWinCMS.WebFactory.PageBase
    {
        GuestBookManage MyClassBLL = new GuestBookManage();
        IP2Location address = new IP2Location();
        SQLModel s_model = new SQLModel();
        protected void Page_Load(object sender, System.EventArgs e)
        {
            if (!(Page.IsPostBack))
            {
                RightsCheck.CheckWorkPower("P_1");

                IsBindEmptyData = true;
                Bind();

                Panel1.Visible = true;
                Panel2.Visible = false;
            }
        }

        private void Bind()
        {
            PageNavigation1.Visible = true;
            MyClassBLL.BindList(DB_GuesetBook, PageNavigation1, s_model);

        }


        protected string UBB(string content)
        {
            return HTML.UBB2HTML(content);
        }

        protected string Address(object IP)
        {
            address.IP = IP.ToString();
            return address.IPLocation();
        }

        #region DB_GuesetBook_ItemDataBound
        protected void DB_GuesetBook_ItemDataBound(object sender, DataListItemEventArgs e)
        {
            Button B;

            foreach (DataListItem oDataListItem in DB_GuesetBook.Items)
            {
                B = (Button)oDataListItem.FindControl("BT_Delete");
                B.Attributes.Add("onClick", "javascript:return confirm('确定要删除吗？')");
            }

            foreach (DataListItem oDataListItem in DB_GuesetBook.Items)
            {
                B = (Button)oDataListItem.FindControl("BT_Reply");
            }
        }
        #endregion

        /// <summary>
        /// 添加回复
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Reply_Click(object sender, System.EventArgs e)
        {
            MyClassBLL.PostReply(_ID, TB_Content.Text);
            Panel1.Visible = true;
            Panel2.Visible = false;

            Bind();
        }


        protected void PageNavigation1_PageChanging(object src, TopWinCMS.WebControls.PageChangingEventArgs e)
        {
            s_model.PageNo = e.NewPageIndex;
            Bind();
            Panel1.Visible = true;
            Panel2.Visible = false;

           
        }
        protected void BT_Back_Click(object sender, EventArgs e)
        {
            Bind();
            Panel1.Visible = true;
            Panel2.Visible = false;
        }
        protected void DB_GuesetBook_ItemCommand(object source, DataListCommandEventArgs e)
        {
            switch (e.CommandName)
            {
                case "ReplyGB"://进入回复界面
                    MyClassBLL.ReplyLoad(DB_GuesetBook, TB_Content, e.CommandArgument.ToString());
                    _ID = e.CommandArgument.ToString();
                    PageNavigation1.Visible = false;
                    Panel1.Visible = true;
                    Panel2.Visible = true;

                    break;
                case "DeleteGB"://删除
                    MyClassBLL.Delete(e.CommandArgument.ToString(), UpdatePanel1);

                    Panel1.Visible = true;
                    Panel2.Visible = false;
                    Bind();
                    break;
            }
        }

        #region 留言ID
        /// <summary>
        /// 留言ID
        /// </summary>
        private string _ID
        {
            get
            {
                if (ViewState["GB_ID"] != null)
                {
                    return ViewState["GB_ID"].ToString();
                }
                else
                {
                    return "0";
                }
            }
            set
            {
                ViewState["GB_ID"] = value;
            }
        }
        #endregion


        protected void BT_Delete_Click(object sender, EventArgs e)
        {
            string IDs = GetSelectedRow.IDs(this.DB_GuesetBook);
            MyClassBLL.Delete(IDs, UpdatePanel1);
            Panel1.Visible = true;
            Panel2.Visible = false;
            Bind();
        }

        protected void BT_DeleteForIP_Click(object sender, EventArgs e)
        {
            MyClassBLL.DeleteForIP(this.TB_IP.Text.Trim(), UpdatePanel1);
            Panel1.Visible = true;
            Panel2.Visible = false;
            Bind();
        }
 
    }
}