using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using HySoft.Common;
using System.Data;

namespace HySoft.BaseCallCenter.Web.expendmanage.ajax
{
    /// <summary>
    /// expandlist 的摘要说明
    /// </summary>
    public class expandlist : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            //取得处事类型
            string action = CommonRequest.GetQueryString("action");
            switch (action)
            {
                case "getallexpandlist":
                    context.Response.Write(LoadAllExpandList(context));
                    break;
                //case "getpersonlist":
                //    context.Response.Write(LoadPersonList(context));
                //    break;
                //case "getcustomerinfo":
                //    context.Response.Write(LoadCustomerInfo(context));
                //    break;
                //case "delete":
                //    context.Response.Write(DeletePerson(context));
                //    break;
            }
        }
        private string LoadAllExpandList(HttpContext context)
        {
            string res = "";
            DataTable dt = new DataTable();
            try
            {
                string sql = "";
                string keywords = context.Request.Params["keywords"];
                string strpageindex = context.Request.Params["page"];
                int pageindex = 1;
                string strpagesize = context.Request.Params["pagesize"];
                int pagesize = 10;
                if (strpageindex.Trim() != "")
                {
                    try
                    {
                        pageindex = Convert.ToInt32(strpageindex);
                    }
                    catch
                    { }
                }

                if (strpagesize.Trim() != "")
                {
                    try
                    {
                        pagesize = Convert.ToInt32(strpagesize);
                    }
                    catch
                    { }
                }

                if (keywords != null)
                {
                    sql += " and F_ShowName like '%" + keywords + "%' ";
                }
                int recordCount = 0;

                Model.PageData<Model.T_Exp_ExtensionBase> pageModel = new Model.PageData<Model.T_Exp_ExtensionBase>();

                dt = BLL.PagerBLL.GetListPager(
                    "T_Exp_ExtensionBase",
                    "F_ExpBaseID",
                    "*",
                    sql,
                    "ORDER BY F_ExpBaseID DESC",
                    pagesize,
                    pageindex,
                    true,
                    out recordCount);

                System.Collections.Generic.List<Model.T_Exp_ExtensionBase> modelList = new BLL.T_Exp_ExtensionBase().DataTableToList(dt);
                pageModel.Rows = modelList;
                pageModel.Total = recordCount;
                System.Runtime.Serialization.Json.DataContractJsonSerializer serializer = new System.Runtime.Serialization.Json.DataContractJsonSerializer(typeof(Model.PageData<Model.T_Exp_ExtensionBase>));

                using (System.IO.MemoryStream stream = new System.IO.MemoryStream())
                {
                    //JSON序列化
                    serializer.WriteObject(stream, pageModel);
                    res = System.Text.Encoding.UTF8.GetString(stream.ToArray());
                }
            }
            catch (Exception err)
            {
                //res = err.ToString(); 
            }
            finally
            {
                dt.Clear();
                dt.Dispose();
            }
            return res;
        }
        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}