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

using TopWinCMS.Model;
using TopWinCMS.Common;
namespace TopWinCMS.WebUI.Admin
{
    /// <summary>
    /// ArticleGather_Main 的摘要说明。
    /// </summary>
    public partial class ArticleGather_Main : System.Web.UI.Page
    {
        ArticleGatherManage MyClassBLL;
        SQLModel s_model = new SQLModel();

        #region 权限变量
        private bool GatherDel = RightsCheck.HasRight("GatherDel");
        private bool GatherEdit = RightsCheck.HasRight("GatherEdit");
        #endregion

        protected void Page_Load(object sender, System.EventArgs e)
        {
            MyClassBLL = new ArticleGatherManage();

            if (!IsPostBack)
            {
                GV_List.Columns[1].Visible = RightsCheck.HasRight("GatherData");

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


            LB_Path.Text = string.Format("{0} → <a href=\"ArticleGather_Main.aspx?ModelID={1}&PageNo=1\">采集任务列表</a>", Config.SiteName, Request["ModelID"]);

            if (TB_KeyWord.Text.Trim().Length == 0)
                s_model.WHERE = string.Format("where classid in (select id from TopWinCMS_Class where ModelID ={0})", Request["ModelID"]);
            else
                s_model.WHERE = string.Format("where classid in (select id from TopWinCMS_Class where ModelID ={0}) AND (Name LIKE '{1}%' OR StartUrl LIKE '{1}%')", Request["ModelID"], TB_KeyWord.Text.Trim());

            MyClassBLL.BindList(GV_List, PageNavigation1, s_model);

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



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

        protected void GV_List_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            string ID = GV_List.DataKeys[e.RowIndex].Value.ToString();
            MyClassBLL.Delete(ID);
            BindList();
        }

        protected void GV_List_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                //TableCell myTableCell = e.Row.Cells[0];
                //HyperLink btnEdit = (HyperLink)myTableCell.Controls[0];

                //if (GatherEdit == false)
                //{
                //    btnEdit.Attributes.Add("onclick", "alert('您没有修改权限!');return false;");
                //}



                TableCell myTableCell = e.Row.Cells[5];
                LinkButton btnDel = (LinkButton)myTableCell.Controls[0];

                if (GatherDel)
                {
                    btnDel.Attributes.Add("onclick", "return confirm('您确定要删除？');");
                }
                else
                {
                    btnDel.Attributes.Add("onclick", "alert('您没有删除权限!');return false;");
                }

            }
        }

        protected string Change(object ID, object PID, object Name)
        {
            if (PID.ToString() == "0")
            {
                return string.Format("ArticleGather_Add.aspx?id={0}&ModelID={1}", ID, Request["ModelID"]);
            }
            else
            {
                return string.Format("RuleNode.aspx?Action=Edit&ID={0}&ModelID={1}", ID, Request["ModelID"]);
            }
        }

        protected void BT_Search_Click(object sender, EventArgs e)
        {
            BindList();
            PageNavigation1.PageNo = 1;
        }
    }
}