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 TopWinCMS.BLL;
using TopWinCMS.Common;
using TopWinCMS.Model;

namespace TopWinCMS.WebUI
{
    public partial class HtmlTemplateList : System.Web.UI.Page
    {
        SQLModel s_model = new SQLModel();
        private bool T_Delete = RightsCheck.HasRight("T_2");
        private bool T_Edit = RightsCheck.HasRight("T_3");
        protected void Page_Load(object sender, EventArgs e)
        {

            if (!IsPostBack)
            {

                LB_Path.Text = Config.SiteName + " → 模板集管理";
                Bind();
            }
        }
        private void Bind()
        {
            

            new TemplatesManage().BindList(GV_List, PageNavigation1, s_model);
        }
        protected void GV_List_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {

                TableCell myTableCell = e.Row.Cells[6];//删除

                LinkButton btnDel = (LinkButton)myTableCell.Controls[0];
                if (T_Delete)
                {
                    btnDel.Attributes.Add("onclick", "return confirm('您确定要删除？');");
                }
                else
                {
                    btnDel.Attributes.Add("onclick", "alert('您没有删除权限!');return false;");
                }

                myTableCell = e.Row.Cells[4];//修改
                HyperLink btnEdit = (HyperLink)myTableCell.Controls[0];
                if (T_Edit==false )
                {              
                    btnEdit.Attributes.Add("onclick", "alert('您没有修改权限!');return false;");
                }
            }
        }

        protected void GV_List_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            switch (e.CommandName)
            {
                case "UsedIt":
                    new TemplatesManage().UsedIt(e.CommandArgument.ToString(), UpdatePanel1);

                    HttpRuntime.Close();

                    s_model.PageNo = PageNavigation1.PageNo;
                    Bind();
                    break;
                case "Template_Delete":
                    int Index = Convert.ToInt32(e.CommandArgument);
                    string ID = GV_List.DataKeys[Index].Value.ToString();
                    new TemplatesManage().Delete(ID, UpdatePanel1);


                    s_model.PageNo = 1;
                    Bind();
                    break;
            }
        }

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

    }
}