using System;
using TopWinCMS.BLL;
using TopWinCMS.Common;
namespace TopWinCMS.WebUI.Admin.Common
{
    /// <summary>
    /// 通用评论管理界面
    /// </summary>
    public partial class Comment : System.Web.UI.Page
    {
        CommentManage MyClassBLL = new CommentManage();

        SQLModel s_model = new SQLModel();
        int ModelID;
        protected void Page_Load(object sender, EventArgs e)
        {
            ModelID =int.Parse( Request.QueryString["ModelID"]);
            if (!IsPostBack)
            {
                string strPath = string.Format("{0} → <a href='ContentManage.aspx?ModelID={1}'>{2}管理</a> → <a href='Comment.aspx?ModelID={1}'>评论管理</a>",
                ModelManage.GetModelName(ModelID),
                ModelID,
                ModelManage.GetContentName(ModelID)
                );

                if (Request["ContentID"] != null)
                {
                    strPath += string.Format(" → 《{0}》评论", Request.QueryString["Title"].Trim());
                    this.Title = string.Format("《{0}》评论", Request.QueryString["Title"].Trim());
                }

                LB_Path.Text = strPath;

                BT_Pass.Enabled = RightsCheck.HasRight("CommentPass", true);
                BTX_Delete.Enabled = RightsCheck.HasRight("CommentDel", true);
                BTX_DeleteIP.Enabled = RightsCheck.HasRight("CommentDel", true);
                BindList();
            }
        }

        private void BindList()
        {
            GV_List.EmptyDataTemplate = TopWinCMS.WebFactory.PageBase.GetTemplate(this);

            s_model.Fields = "*";
            s_model.TableName = "TopWinCMS_Comment";
            if (Request["ContentID"] == null)
            {
                s_model.WHERE = " ModelID=" + ModelID;
            }
            else
            {
                s_model.WHERE = string.Format("where ModelID={0} and ContentID={1}", ModelID, Request["ContentID"]);
            }
            s_model.OrderField = "ID desc";
 
            s_model.PageSize = 15;
            MyClassBLL.BindList(this.GV_List, PageNavigation1, s_model);

            if (this.GV_List.Rows.Count < 1)
            {
                BTX_Delete.Enabled = false;
                BT_Pass.Enabled = false;
                BTX_DeleteIP.Enabled = false;
            }

            MyJavascript.RegJS(UpdatePanel1, "attachMouseEvent('" + this.GV_List.ClientID + "');");
        }

        protected void PageNavigation1_PageChanging(object src, TopWinCMS.WebControls.PageChangingEventArgs e)
        {
            s_model.PageNo = e.NewPageIndex;
            BindList();
        }

        protected void BTX_Delete_Click(object sender, EventArgs e)
        {
            MyClassBLL.Delete(GetSelectedRow.IDs(GV_List), UpdatePanel1);
            s_model.PageNo = 1;
            BindList();
        }

        protected void BT_Pass_Click(object sender, EventArgs e)
        {
            MyClassBLL.Pass(GetSelectedRow.IDs(GV_List), UpdatePanel1);
            s_model.PageNo = PageNavigation1.PageNo;
            BindList();
        }


        protected void BTX_DeleteIP_Click(object sender, EventArgs e)
        {
            MyClassBLL.DeleteForIP(this.TB_IP.Text.Trim(), UpdatePanel1);
            s_model.PageNo = 1;
            BindList();
        }

    }
}