using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Text.RegularExpressions;
using TopWinCMS.Model;
using TopWinCMS.BLL;
using TopWinCMS.Common;
namespace TopWinCMS.WebUI.Admin
{
    /// <summary>
    /// Admin_Channel 的摘要说明。
    /// </summary>
    public partial class Admin_Channel : System.Web.UI.Page
    {
         
        protected void Page_Load(object sender, System.EventArgs e)
        {
            if (!IsPostBack)
            {
                RightsCheck.CheckWorkPower("S_8");
             
                Bind();
            }
        }

        private void Bind()
        {
            GV_List.EmptyDataTemplate = TopWinCMS.WebFactory.PageBase.GetTemplate(this);
            LB_Path.Text = Config.SiteName + " →  <a href=\"Channel.aspx\">频道管理</a>";
            new BLL.ChannelManage().BindList(GV_List);

        }



        public string MyLink(object link)
        {
            Regex reg = new Regex(@"(http://)", RegexOptions.IgnoreCase);
            if (reg.IsMatch(link.ToString()) == false)
            {
                return link.ToString();
            }
            else
            {
                return "<a href=\"" + link + "\" target=\"_blank\">" + link + "</a>";
            }
        }

       

        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                TableCell myTableCell;
                //定义对“删除”单元格的引用
                myTableCell = e.Row.Cells[8];//删除
                //定义对“删除”单元格中控件的引用
                LinkButton btnDel = (LinkButton)myTableCell.Controls[0];
                //添加当单击时弹出确认对话框的自定义属性
                btnDel.Attributes.Add("onclick", "return confirm('您确定要删除？');");
            }
        }
        protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            ChannelManage MyClassBLL = new ChannelManage();
            int index = Convert.ToInt32(e.CommandArgument);
            string ID = GV_List.DataKeys[index].Value.ToString();
            LogInfo LogClass = new LogInfo();
            LogClass.Type = "频道管理";
            switch (e.CommandName)
            {
                case "DeleteChannel":
                    MyClassBLL.Delete(ID);

                    LogClass.Event = "删除频道：" + GV_List.Rows[index].Cells[0].Text;
                    LogManage.Add(LogClass);
                    break;
                case "up":
                    MyClassBLL.OrderBy(ID, "up");

                    LogClass.Event = "频道：" + GV_List.Rows[index].Cells[0].Text + " 向上移动";
                    LogManage.Add(LogClass);
                    Response.Redirect("Channel.aspx");
                    break;
                case "down":
                    MyClassBLL.OrderBy(ID, "down");

                    LogClass.Event = "频道：" + GV_List.Rows[index].Cells[0].Text + " 向下移动";
                    LogManage.Add(LogClass);
                    Response.Redirect("Channel.aspx");
                    break;
            }


        }
    }
}