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_like_recycle :BaseAdminUI
    {
        HaTeam.Dd.BLL.Dd_Like bll = new HaTeam.Dd.BLL.Dd_Like();
        HaTeam.Dd.Model.Dd_Like model = new HaTeam.Dd.Model.Dd_Like();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Fetch.Get("action") != null && Fetch.Get("like_id") != null)
                {
                    if (Fetch.Get("action").ToString() == "renew")
                    {
                        model = bll.GetModel(int.Parse(Fetch.Get("like_id")));
                        model.Like_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 = "like_delete = 1";
            if (txtSearch.Value != "")
            {
                if (DropSelect.SelectedValue == "like_userid")
                {
                    str += "and like_userid 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),like_datetime,120) like '%" + selectstart.Value.ToString() + "%'";
                }
                else
                {
                    str += "and like_datetime between'" + selectstart.Value.ToString() + "'and'" + selectend.Value.ToString() + "'";

                }
            }
            int pagesize = pagelist.PageSize;
            int pagecurrentindex = pagelist.CurrentPageIndex;
            pagelist.RecordCount = int.Parse(PagerProc.GetListPage("dd_like", "like_id", pagesize, pagecurrentindex, 1, 1, str).Tables[0].Rows[0][0].ToString());
            DataSet ds = PagerProc.GetListPage("dd_like", "like_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_like set like_delete =0 where like_delete=1 and like_id in (" + names + ")");
                }
                if (this.delete.Checked)
                {
                    DbHelperSQL.ExecuteSql("delete from dd-like where like_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));
            return idna;
        }
        /// <summary>
        /// 根据用户ID获得博客名
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public string GetNameByValue(string value)
        {
            string str = "select user_blogname from dd_user where user_id =" + int.Parse(value);
            string name = Convert.ToString(DbHelperSQL.GetSingle(str));
            return name;
        }
        public string GetTypeByValue(string val)
        {
            string name = "";
            if (val == "0")
            {
                name = "文章";
            }
            else if (val == "1")
            {
                name = "图片";
            }
            else if (val == "2")
            {
                name = "音乐";
            }
            else if (val == "3")
            {
                name = "链接";
            }
            else if (val == "4")
            {
                name = "视频";
            }
            return name;
        }

        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();
        }
    }
}