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 DotNet.FrameWork.Utils;

//
using GetCommand;

namespace HteamDd.Web.Admin
{
    public partial class User_recycle :BaseAdminUI
    {
        HaTeam.Dd.Model.Dd_User model = new HaTeam.Dd.Model.Dd_User();
        HaTeam.Dd.BLL.Dd_User bll = new HaTeam.Dd.BLL.Dd_User();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Fetch.Get("action") != null && Fetch.Get("user_id") != null)
                {
                    if (Fetch.Get("action").ToString() == "renew")
                    {
                        model = bll.GetModel(int.Parse(Fetch.Get("user_id")));
                        model.User_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 = "user_delete = 1";
            if (txtSearch.Value != "")
            {
                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),user_datetime,120) like '%" + selectstart.Value.ToString() + "%'";
                }
                else
                {
                    str += "and user_datetime between'" + selectstart.Value.ToString() + "'and'" + selectend.Value.ToString() + "'";

                }
            }
            int pagesize = pagelist.PageSize;
            int pagecurrentindex = pagelist.CurrentPageIndex;
            pagelist.RecordCount = int.Parse(PagerProc.GetListPage("dd_user", "user_id", pagesize, pagecurrentindex, 1, 1, str).Tables[0].Rows[0][0].ToString());
            DataSet ds = PagerProc.GetListPage("dd_user", "user_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_user set user_delete =0 where user_delete=1 and user_id in (" + names + ")");
                }

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

        }
        /// <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 pagelist_PageChanged(object sender, EventArgs e)
        {
            DataBindRepeaterList();
        }

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