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.Model;
using TopWinCMS.BLL;
using TopWinCMS.Common;
namespace TopWinCMS.WebUI.Admin
{
    /// <summary>
    /// Admin_Ads_List 的摘要说明。
    /// </summary>
    public partial class Admin_Ads_List : System.Web.UI.Page
    {

        SQLModel s_model = new SQLModel();
        protected bool bo_Stop = false;
        protected bool bo_Del = false;
        protected bool bo_Edit = false;
        protected void Page_Load(object sender, System.EventArgs e)
        {
            if (!IsPostBack)
            {
                Check();
                BindList();
            }
        }

        #region 进行各种权限检查和限制
        /// <summary>
        /// 进行各种权限检查和限制
        /// </summary>
        private void Check()
        {
  
            RightsCheck.CheckWorkPower("A_5");
            bo_Edit = RightsCheck.HasRight("A_2");
            bo_Stop = RightsCheck.HasRight("A_3");
            bo_Del = RightsCheck.HasRight("A_4");

        }
        #endregion

        private void BindList()
        {
            string Action = Request["Action"];

            if (Action == null)
            {
                path.InnerHtml = Config.SiteName + " → 广告管理 → 正常广告";
                s_model.OrderField = "ID desc";
 
                s_model.WHERE = " ( DateOff >=0 ) and ( MaxShowTime >= Show or MaxShowTime = 0 ) and ( MaxClick >= Clicks or MaxClick = 0 ) and Stop=0";
            }
            else if (Action == "MaxClick")
            {
                path.InnerHtml = Config.SiteName + " → 广告管理 → 点击最高";
                s_model.OrderField = "Clicks Desc";
 
                s_model.WHERE = " Stop=0";
            }
            else if (Action == "MinClick")
            {
                path.InnerHtml = Config.SiteName + " → 广告管理 → 点击最低";
                s_model.OrderField = "Clicks ASC";
 
                s_model.WHERE = " Stop=0";
            }
            else if (Action == "Stop")
            {
                path.InnerHtml = Config.SiteName + " → 广告管理 → 暂停列表";
                s_model.OrderField = "ID desc";
 
                s_model.WHERE = " Stop=1";
            }
            else if (Action == "Invalidation")
            {
                path.InnerHtml = Config.SiteName + " → 广告管理 → 失效广告";
                s_model.OrderField = "ID desc";
 
                s_model.WHERE = " ( DateOff <0 ) or ( MaxShowTime <= Show and MaxShowTime > 0 ) or ( MaxClick <= Clicks and MaxClick > 0 ) and Stop=0";
            }

            new AdsManage().BindList(DataList1, PageNavigation1, s_model);

            if (DataList1.Items.Count <= 0)
            {
                show1.Text = "<img src='/Images/NoData.gif'><br/>";
            }
            else
            {
                show1.Text = "";
            }
        }


        protected string TiaoJian(object MaxClick, object MaxShowTime, object MaxDateTime)
        {
            string TJ = "";
            if (Convert.ToInt32(MaxClick) > 0)
            {
                TJ = "点 击 数：" + MaxClick + " ";
            }

            if (Convert.ToInt32(MaxShowTime) > 0)
            {
                TJ += "显示数：" + MaxShowTime + " ";
            }

            TJ += "显示期限：" + Convert.ToDateTime(MaxDateTime).ToShortDateString();

            return TJ;
        }



        protected void DataList1_ItemCommand(object source, System.Web.UI.WebControls.DataListCommandEventArgs e)
        {
            string ID = DataList1.DataKeys[e.Item.ItemIndex].ToString();

            switch (e.CommandName)
            {
                case "stop":
                    new AdsManage().Stop_Open(ID, UpdatePanel1);
                    break;
                case "Del":
                    new AdsManage().Delete(ID, UpdatePanel1);
                    break;
                case "JS":
                    new AdsManage().MakeJS(ID);
                    MsgBox.Alert("生成成功！", UpdatePanel1);
                    break;
            }
            //s_model.PageNo = PageNavigation1.PageNo;
            //BindList();
        }

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