using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
//需引入的命名空间
using DotNet.FrameWork.Data;
using System.Data;
using System.Data.SqlClient;
using DotNet.FrameWork.Utils;
using DotNet.FrameWork.Common.Web;
using DotNet.FrameWork.Page;
using GetCommand;

namespace HteamDd.Web.Admin
{
    public partial class Admin_radio_recycle :BaseAdminUI
    {
        HaTeam.Dd.Model.Dd_Video model = new HaTeam.Dd.Model.Dd_Video();
        HaTeam.Dd.BLL.Dd_Video bll = new HaTeam.Dd.BLL.Dd_Video();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Fetch.Get("action") != null && Fetch.Get("video_id") != null)
                {
                    if (Fetch.Get("action").ToString() == "renew")
                    {
                        model = bll.GetModel(int.Parse(Fetch.Get("video_id")));
                        model.Video_Delete = 0;
                        bll.Update(model);
                    }

                }
                Session["selectvalue"] = this.DropSelect.SelectedValue;
                DataBindRepeaterList();

            }
        }
        public void DataBindRepeaterList()
        {
            DropSelect.SelectedValue = Convert.ToString(Session["selectvalue"]);
            this.txtSearch.Value = Convert.ToString(Session["search"]);
            string str = "video_delete = 1";
            if (txtSearch.Value != "")
            {
                if (DropSelect.SelectedValue == "user_id")
                {
                    str += "and user_id like'%" + GetIDByName() + "%'";
                }
                else
                {
                    str += " and " + DropSelect.SelectedValue + " like '%" + txtSearch.Value + "%'";
                }

            }
            if (selectstart.Value != "" && selectend.Value != "")
            {
                if (Convert.ToDateTime(selectstart.Value) == Convert.ToDateTime(selectend.Value))
                {
                    str += "and CONVERT(varchar(30),text_datetime,120) like '%" + selectstart.Value.ToString() + "%'";
                }
                else
                {
                    str += "and text_datetime between'" + selectstart.Value.ToString() + "'and'" + selectend.Value.ToString() + "'";

                }
            }
            int pagesize = pagelist.PageSize;
            int pagecurrentindex = pagelist.CurrentPageIndex;
            pagelist.RecordCount = int.Parse(PagerProc.GetListPage("dd_video", "video_id", pagesize, pagecurrentindex, 1, 1, str).Tables[0].Rows[0][0].ToString());
            DataSet ds = PagerProc.GetListPage("dd_video", "video_id", pagesize, pagecurrentindex, 0, 1, str);
            this.rplist.DataSource = ds;
            this.rplist.DataBind();
        }
        private void Operate()
        {
            string names = Fetch.Post("primarykey");
            if (names != string.Empty)
            {
                names = names.Replace("'", "");
                names = "'" + names.Replace(",", "','") + "'";

                if (this.renew.Checked)
                {
                    DbHelperSQL.ExecuteSql("update dd_video set video_delete =0 where video_delete=1 and video_id in (" + names + ")");
                }

                if (this.delete.Checked)
                {
                    DbHelperSQL.ExecuteSql("delete from dd_video where video_id in (" + names + ")");
                }
                Response.Redirect(Fetch.CurrentUrl.ToString());
            }

        }
        /// <summary>
        /// 根据名字获得ID
        /// </summary>
        /// <returns></returns>
        public string GetIDByName()
        {
            string str = "select user_id from dd_user where user_blogname like'%" + this.txtSearch.Value + "%'";
            string idna = Convert.ToString(DbHelperSQL.GetSingle(str)).ToString();
            return idna;
        }
        /// <summary>
        /// 根据ID获得名字
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public string GetNameByID(string id)
        {
            string str = "select user_blogname from dd_user where user_id =" + int.Parse(id);
            string name = Convert.ToString(DbHelperSQL.GetSingle(str));
            return name;
        }
        /// <summary>
        /// 获得字符串长度
        /// </summary>
        /// <param name="content"></param>
        /// <returns></returns>
        public string Substring(string content)
        {
            if (content.Length > 15)
            {
                return content.Substring(0, 15) + "...";
            }
            else
                return content;
        }
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            Session["search"] = this.txtSearch.Value;
            DataBindRepeaterList();
        }

        protected void btnEdit_Click(object sender, EventArgs e)
        {
            Operate();
        }

        protected void DropSelect_SelectedIndexChanged(object sender, EventArgs e)
        {
            Session["selectvalue"] = this.DropSelect.SelectedValue;
        }

        protected void pagelist_PageChanged(object sender, EventArgs e)
        {
            DataBindRepeaterList();
        }
    }
}