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

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

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            //取得处事类型
            string action = CommonRequest.GetQueryString("action");
            switch (action)
            {
                case "gethflist":
                    context.Response.Write(LoadHFList(context));
                    break;
                case "getlist":
                    context.Response.Write(LoadList(context));
                    break;
                case "getcallinlist":
                    //来电弹屏通话记录
                    context.Response.Write(LoadCallInList(context));
                    break;
                case "getgdlist":
                    //
                    context.Response.Write(LoadGDList(context));
                    break;
                case "deletelist":
                    context.Response.Write(Delete(context));
                    break;
                case "clear":
                    break;
                case "insertCallLogs":
                    context.Response.Write(InsertCallLogs(context));
                    break;
                case "getCallIdByPhone":
                    //根据来电号码获取
                    context.Response.Write(getCallIdByPhone(context));
                    break;
                case "zhenlingEvent":
                    //振铃事件
                    context.Response.Write(zhenlingEvent(context));
                    break;
                case "zhaijiEvent":
                    //摘机事件
                    context.Response.Write(zhaijiEvent(context));
                    break;
                case "guajiEvent":
                    //挂机事件
                    context.Response.Write(guajiEvent(context));
                    break;
                case "luyinEvent":
                    //录音开始事件
                    context.Response.Write(luyinEvent(context));
                    break;
                case "callout":
                    //外呼
                    context.Response.Write(callout(context));
                    break;
                case "callouthf":
                    //外呼回访
                    context.Response.Write(callouthf(context));
                    break;
            }
        }

        #region 获取回访数据
        private string LoadHFList(HttpContext context)
        {
            string res = "";
            DataTable dt = new DataTable();
            try
            {
                string strpageindex = context.Request.Params["page"];
                int pageindex = 1;
                string strpagesize = context.Request.Params["pagesize"];
                int pagesize = 10;
                string sql = "";
                string phone = HttpUtility.UrlDecode(CommonRequest.GetQueryString("phone"));
                string callstate = HttpUtility.UrlDecode(CommonRequest.GetQueryString("callstate"));
                string usercode = HttpUtility.UrlDecode(CommonRequest.GetQueryString("usercode"));
                string calltype = HttpUtility.UrlDecode(CommonRequest.GetQueryString("calltype"));
                string starttime = HttpUtility.UrlDecode(CommonRequest.GetQueryString("starttime"));
                string endtime = HttpUtility.UrlDecode(CommonRequest.GetQueryString("endtime"));

                string hfid = HttpUtility.UrlDecode(CommonRequest.GetQueryString("hfid"));
                if (hfid.Trim() != "")
                {
                    sql += " and OperateType=7 and CallType=1 and OperateObject='" + hfid + "'";
                }

                if (phone.Trim() != "")
                {
                    sql += " and CallNumber='" + phone + "'";
                }
                if (callstate.Trim() != "")
                {
                    sql += " and CallState='" + callstate + "'";
                }
                if (usercode.Trim() != "")
                {
                    sql += " and UserCode='" + usercode + "'";
                }
                if (calltype.Trim() != "")
                {
                    sql += " and CallType='" + calltype + "'";
                }
                if (starttime.Trim() != "")
                {
                    sql += " and datediff(day,BeginTime,'" + starttime + "')<=0 ";
                }
                if (endtime.Trim() != "")
                {
                    sql += " and datediff(day,BeginTime,'" + endtime + "')>=0 ";
                }
                if (strpageindex.Trim() != "")
                {
                    try
                    {
                        pageindex = Convert.ToInt32(strpageindex);
                    }
                    catch
                    { }
                }
                if (strpagesize.Trim() != "")
                {
                    try
                    {
                        pagesize = Convert.ToInt32(strpagesize);
                    }
                    catch
                    { }
                }
                int recordCount = 0;
                Model.PageData<Model.T_Call_CallRecords> pageModel = new Model.PageData<Model.T_Call_CallRecords>();
                dt = BLL.PagerBLL.GetListPager(
                    "T_Call_CallRecords",
                    "CallRecordsId",
                    "*",
                    sql,
                    "ORDER BY CallRecordsId desc",
                    pagesize,
                    pageindex,
                    true,
                    out recordCount);
                System.Collections.Generic.List<Model.T_Call_CallRecords> modelList = new BLL.T_Call_CallRecords().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_Call_CallRecords>));
                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;
        }
        #endregion

        #region 外呼回访

        private string callouthf(HttpContext context)
        {
            string res = "1||" + DateTime.Now.ToString("yyyyMMddHHmmssms");
            try
            {
                string phone = CommonRequest.GetQueryString("phone");

                //处理判断本地或外地 zhgjie
                try
                {
                    if (phone.Trim() != "")
                    {
                        //判断号码前是否存在0
                        if (phone.Trim().Substring(0, 1) != "0")
                        {
                            //判断是否手机
                            if (phone.Trim().Length > 10)
                            {
                                BLL.T_Sys_MobileData mobile_Bll = new BLL.T_Sys_MobileData();
                                Model.T_Sys_MobileData mobileModel = mobile_Bll.GetModel(phone.Substring(0, 7));
                                if (mobileModel != null)
                                {
                                    if (mobileModel.F_ZipCode != "0371")
                                    {
                                        phone = "0" + phone;
                                    }
                                }
                            }
                        }
                    }
                }
                catch
                { }

                Model.T_Call_CallRecords model = new Model.T_Call_CallRecords();
                model.CallId = DateTime.Now.ToString("yyyyMMddHHmmssms");
                model.CallNumber = phone;

                model.CallType = 1;
                if (!string.IsNullOrEmpty(CommonRequest.GetQueryString("userid")))
                {
                    model.UserId = Convert.ToInt32(CommonRequest.GetQueryString("userid"));
                }
                if (!string.IsNullOrEmpty(CommonRequest.GetQueryString("usercode")))
                {
                    model.UserCode = CommonRequest.GetQueryString("usercode").Trim();
                }
                if (!string.IsNullOrEmpty(CommonRequest.GetQueryString("username")))
                {
                    model.UserName = HttpUtility.UrlDecode(CommonRequest.GetQueryString("username").Trim());
                    //model.UserName=context.Request.Form["txtAgentName"]
                }
                if (!string.IsNullOrEmpty(CommonRequest.GetQueryString("extnumber")))
                {
                    model.ExtNumber = CommonRequest.GetQueryString("extnumber").Trim();
                    //model.UserName=context.Request.Form["txtAgentName"]
                }
                model.CallState = 0;
                model.DealType = 7;
                model.IsDeal = 1;
                model.OperateType = 7;//回访
                model.OperateObject = "";
                model.OperateTime = DateTime.Now;
                string hfid = "0";
                try
                {
                    hfid = CommonRequest.GetQueryString("hfid");
                    if (hfid != "")
                    {
                        model.OperateObject = hfid;
                    }
                }
                catch
                {
                }
                string cid = model.CallId;
                new BLL.T_Call_CallRecords().Add(model);
                try
                {
                    //更新回访状态

                    new BLL.T_Call_TaskTelNum().UpdateHC(Convert.ToInt32(hfid), 1);
                    new BLL.T_Call_TaskTelNum().UpdateYJ(Convert.ToInt32(hfid), 0);
                    //string workorderid = CommonRequest.GetQueryString("workorderid");
                    //if (workorderid != "")
                    //{
                    //    Model.T_Call_WorkOrder modelorder = new Model.T_Call_WorkOrder();
                    //    modelorder.CallId = model.CallId;
                    //    modelorder.F_WORKORDERID = Convert.ToInt32(workorderid);
                    //    modelorder.F_WORKORDERSTATEID = 6;
                    //    new BLL.T_Call_WorkOrder().Add(modelorder);
                    //}
                }
                catch { }
                if (phone.Length > 5)
                {
                    res = "2|" + phone + "|" + cid;
                }
                else
                {
                    res = "1|" + phone + "|" + cid;
                }
            }
            catch { }
            return res;
        }

        #endregion

        #region

        private string callout(HttpContext context)
        {
            string res = "1||" + DateTime.Now.ToString("yyyyMMddHHmmssms");
            try
            {
                string phone = CommonRequest.GetQueryString("phone");

                //处理判断本地或外地 zhgjie
                try
                {
                    if (phone.Trim() != "")
                    {
                        //判断号码前是否存在0
                        if (phone.Trim().Substring(0, 1) != "0")
                        {
                            //判断是否手机
                            if (phone.Trim().Length > 10)
                            {
                                BLL.T_Sys_MobileData mobile_Bll = new BLL.T_Sys_MobileData();
                                Model.T_Sys_MobileData mobileModel = mobile_Bll.GetModel(phone.Substring(0, 7));
                                if (mobileModel != null)
                                {
                                    if (mobileModel.F_ZipCode != "0371")
                                    {
                                        phone = "0" + phone;
                                    }
                                }
                            }
                        }
                    }
                }
                catch
                { }

                Model.T_Call_CallRecords model = new Model.T_Call_CallRecords();
                model.CallId = DateTime.Now.ToString("yyyyMMddHHmmssms");
                model.CallNumber = phone;

                model.CallType = 1;
                if (!string.IsNullOrEmpty(CommonRequest.GetQueryString("userid")))
                {
                    model.UserId = Convert.ToInt32(CommonRequest.GetQueryString("userid"));
                }
                if (!string.IsNullOrEmpty(CommonRequest.GetQueryString("usercode")))
                {
                    model.UserCode = CommonRequest.GetQueryString("usercode").Trim();
                }
                if (!string.IsNullOrEmpty(CommonRequest.GetQueryString("username")))
                {
                    model.UserName = HttpUtility.UrlDecode(CommonRequest.GetQueryString("username").Trim());
                    //model.UserName=context.Request.Form["txtAgentName"]
                }
                if (!string.IsNullOrEmpty(CommonRequest.GetQueryString("extnumber")))
                {
                    model.ExtNumber = CommonRequest.GetQueryString("extnumber").Trim();
                    //model.UserName=context.Request.Form["txtAgentName"]
                }
                model.CallState = 0;
                model.DealType = 6;
                model.IsDeal = 1;
                string cid = model.CallId;
                new BLL.T_Call_CallRecords().Add(model);
                try
                {
                    string workorderid = CommonRequest.GetQueryString("workorderid");
                    if (workorderid != "")
                    {
                        Model.T_Call_WorkOrder modelorder = new Model.T_Call_WorkOrder();
                        modelorder.CallId = model.CallId;
                        modelorder.F_WORKORDERID = Convert.ToInt32(workorderid);
                        modelorder.F_WORKORDERSTATEID = 6;
                        new BLL.T_Call_WorkOrder().Add(modelorder);
                    }
                }
                catch { }
                if (phone.Length > 5)
                {
                    res = "2|" + phone + "|" + cid;
                }
                else
                {
                    res = "1|" + phone + "|" + cid;
                }
            }
            catch { }
            return res;
        }

        #endregion

        #region 电话操作日志

        private string InsertCallLogs(HttpContext context)
        {
            string res = "error";
            return res;
        }

        #endregion

        #region 根据来电号码获取callid

        private string getCallIdByPhone(HttpContext context)
        {
            string res = "";
            try
            {
                Model.T_Call_CallRecords model = new BLL.T_Call_CallRecords().GetModelByTelphone(CommonRequest.GetQueryString("telphone"));
                if (model != null)
                {
                    res = model.CallId.Trim();
                }
            }
            catch (Exception ex)
            {
                res = "";
            }
            return res;
        }

        #endregion

        #region 处理振铃事件

        private string zhenlingEvent(HttpContext context)
        {
            string res = "error";
            try
            {
                Model.T_Call_CallRecords model = new Model.T_Call_CallRecords();
                model.CallId = CommonRequest.GetQueryString("callid");
                if (!string.IsNullOrEmpty(CommonRequest.GetQueryString("userid")))
                {
                    model.UserId = Convert.ToInt32(CommonRequest.GetQueryString("userid"));
                }
                if (!string.IsNullOrEmpty(CommonRequest.GetQueryString("usercode")))
                {
                    model.UserCode = CommonRequest.GetQueryString("usercode").Trim();
                }
                if (!string.IsNullOrEmpty(CommonRequest.GetQueryString("username")))
                {
                    model.UserName = HttpUtility.UrlDecode(CommonRequest.GetQueryString("username").Trim());
                    //model.UserName=context.Request.Form["txtAgentName"]
                }
                if (!string.IsNullOrEmpty(CommonRequest.GetQueryString("extnumber")))
                {
                    model.ExtNumber = CommonRequest.GetQueryString("extnumber").Trim();
                    //model.UserName=context.Request.Form["txtAgentName"]
                }
                model.DealType = 5;
                bool bl = new BLL.T_Call_CallRecords().UpdateCallInRingTelRecord(model);
                if (bl)
                {
                    res = "success";
                }
            }
            catch (Exception ex)
            {
                res = ex.ToString();
            }
            return res;
        }

        #endregion

        #region 处理摘机事件

        private string zhaijiEvent(HttpContext context)
        {
            string res = "error";
            try
            {
                Model.T_Call_CallRecords model = new Model.T_Call_CallRecords();
                model.CallId = CommonRequest.GetQueryString("callid");
                model.CallState = 1;
                model.DealType = 6;
                bool bl = new BLL.T_Call_CallRecords().UpdateCallInAnswerTelRecord(model);
                if (bl)
                {
                    res = "success";
                    //更新回访状态
                    try
                    {
                        Model.T_Call_CallRecords vmodel = new BLL.T_Call_CallRecords().GetModelByCallId(CommonRequest.GetQueryString("callid"));
                        string type = vmodel.OperateType.ToString();
                        if (type == "7")
                        {
                            new BLL.T_Call_TaskTelNum().UpdateYJ(Convert.ToInt32(vmodel.OperateObject.ToString()), 1);
                        }
                    }
                    catch
                    {
                    }
                }
            }
            catch (Exception ex)
            {
                res = ex.ToString();
            }
            return res;
        }

        #endregion

        #region 处理挂机事件

        private string guajiEvent(HttpContext context)
        {
            string res = "error";
            try
            {
                bool bl = new BLL.T_Call_CallRecords().UpdateCallInHookTelRecord(CommonRequest.GetQueryString("callid"));
                if (bl)
                {
                    res = "success";
                }
            }
            catch (Exception ex)
            {
                res = ex.ToString();
            }
            return res;
        }

        #endregion

        #region 处理录音开始事件

        private string luyinEvent(HttpContext context)
        {
            string res = "error";
            try
            {
                Model.T_Call_CallRecords model = new Model.T_Call_CallRecords();
                model.CallId = CommonRequest.GetQueryString("callid");
                model.CallState = 1;
                model.DealType = 6;
                model.FilePath = CommonRequest.GetQueryString("path");
                bool bl = new BLL.T_Call_CallRecords().UpdateCallInPathTelRecord(model);
                if (bl)
                {
                    res = "success";
                    //更新回访状态
                    try
                    {
                        Model.T_Call_CallRecords vmodel = new BLL.T_Call_CallRecords().GetModelByCallId(CommonRequest.GetQueryString("callid"));
                        string type = vmodel.OperateType.ToString();
                        if (type == "7")
                        {
                            new BLL.T_Call_TaskTelNum().UpdateYJ(Convert.ToInt32(vmodel.OperateObject.ToString()), 1);
                        }
                    }
                    catch
                    {
                    }
                }
            }
            catch (Exception ex)
            {
                res = ex.ToString();
            }
            return res;
        }

        #endregion

        #region 获取数据
        private string LoadList(HttpContext context)
        {
            string res = "";
            DataTable dt = new DataTable();
            try
            {
                string strpageindex = context.Request.Params["page"];
                int pageindex = 1;
                string strpagesize = context.Request.Params["pagesize"];
                int pagesize = 10;
                string sql = "";
                string phone = HttpUtility.UrlDecode(CommonRequest.GetQueryString("phone"));
                string callstate = HttpUtility.UrlDecode(CommonRequest.GetQueryString("callstate"));
                string usercode = HttpUtility.UrlDecode(CommonRequest.GetQueryString("usercode"));
                string calltype = HttpUtility.UrlDecode(CommonRequest.GetQueryString("calltype"));
                string starttime = HttpUtility.UrlDecode(CommonRequest.GetQueryString("starttime"));
                string endtime = HttpUtility.UrlDecode(CommonRequest.GetQueryString("endtime"));
                if (phone.Trim() != "")
                {
                    sql += " and CallNumber='" + phone + "'";
                }
                if (callstate.Trim() != "")
                {
                    sql += " and CallState='" + callstate + "'";
                }
                if (usercode.Trim() != "")
                {
                    sql += " and UserCode='" + usercode + "'";
                }
                if (calltype.Trim() != "")
                {
                    sql += " and CallType='" + calltype + "'";
                }
                if (starttime.Trim() != "")
                {
                    sql += " and datediff(day,BeginTime,'" + starttime + "')<=0 ";
                }
                if (endtime.Trim() != "")
                {
                    sql += " and datediff(day,BeginTime,'" + endtime + "')>=0 ";
                }
                if (strpageindex.Trim() != "")
                {
                    try
                    {
                        pageindex = Convert.ToInt32(strpageindex);
                    }
                    catch
                    { }
                }
                if (strpagesize.Trim() != "")
                {
                    try
                    {
                        pagesize = Convert.ToInt32(strpagesize);
                    }
                    catch
                    { }
                }
                int recordCount = 0;
                Model.PageData<Model.T_Call_CallRecords> pageModel = new Model.PageData<Model.T_Call_CallRecords>();
                dt = BLL.PagerBLL.GetListPager(
                    "T_Call_CallRecords",
                    "CallRecordsId",
                    "*",
                    sql,
                    "ORDER BY CallRecordsId desc",
                    pagesize,
                    pageindex,
                    true,
                    out recordCount);
                System.Collections.Generic.List<Model.T_Call_CallRecords> modelList = new BLL.T_Call_CallRecords().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_Call_CallRecords>));
                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;
        }
        #endregion

        #region 获取数据
        private string LoadCallInList(HttpContext context)
        {
            string res = "";
            DataTable dt = new DataTable();
            try
            {
                string strpageindex = context.Request.Params["page"];
                int pageindex = 1;
                string strpagesize = context.Request.Params["pagesize"];
                int pagesize = 10;
                string strtelnum = HttpUtility.UrlDecode(CommonRequest.GetQueryString("telnum"));
                string sql = " ";
                string calltype = context.Request.Params["calltype"];
                if (calltype.Trim() != "" && calltype != "undefined")
                {
                    sql += " and CallType=" + calltype + " ";
                }
                if (strtelnum.Trim() != "" && strtelnum != "undefined")
                {
                    sql += " and CallNumber='" + strtelnum.Trim() + "' ";
                }
                else
                {
                    sql += " and 1=0 ";
                }

                string starttime = HttpUtility.UrlDecode(CommonRequest.GetQueryString("starttime"));
                string endtime = HttpUtility.UrlDecode(CommonRequest.GetQueryString("endtime"));

                if (starttime.Trim() != "")
                {
                    sql += " and datediff(day,BeginTime,'" + starttime + "')<=0 ";
                }
                if (endtime.Trim() != "")
                {
                    sql += " and datediff(day,BeginTime,'" + endtime + "')>=0 ";
                }

                if (strpageindex.Trim() != "")
                {
                    try
                    {
                        pageindex = Convert.ToInt32(strpageindex);
                    }
                    catch
                    { }
                }
                if (strpagesize.Trim() != "")
                {
                    try
                    {
                        pagesize = Convert.ToInt32(strpagesize);
                    }
                    catch
                    { }
                }
                int recordCount = 0;
                Model.PageData<Model.T_Call_CallRecords> pageModel = new Model.PageData<Model.T_Call_CallRecords>();
                dt = BLL.PagerBLL.GetListPager(
                    "T_Call_CallRecords",
                    "CallRecordsId",
                    "*",
                    sql,
                    "ORDER BY CallRecordsId desc",
                    pagesize,
                    pageindex,
                    true,
                    out recordCount);
                System.Collections.Generic.List<Model.T_Call_CallRecords> modelList = new BLL.T_Call_CallRecords().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_Call_CallRecords>));
                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;
        }
        #endregion

        #region 获取数据
        private string LoadGDList(HttpContext context)
        {
            string res = "";
            DataTable dt = new DataTable();
            try
            {
                string strpageindex = context.Request.Params["page"];
                int pageindex = 1;
                string strpagesize = context.Request.Params["pagesize"];
                int pagesize = 10;
                string strtelnum = HttpUtility.UrlDecode(CommonRequest.GetQueryString("telnum"));
                string sql = " ";
                if (strtelnum.Trim() != "" && strtelnum != "undefined")
                {
                    sql += " and F_LINKMANTELEPHONE='" + strtelnum.Trim() + "' ";
                }
                else
                {
                    sql += " and 1=0 ";
                }

                string starttime = HttpUtility.UrlDecode(CommonRequest.GetQueryString("starttime"));
                string endtime = HttpUtility.UrlDecode(CommonRequest.GetQueryString("endtime"));

                if (starttime.Trim() != "")
                {
                    sql += " and datediff(day,F_CREATEDATE,'" + starttime + "')<=0 ";
                }
                if (endtime.Trim() != "")
                {
                    sql += " and datediff(day,F_CREATEDATE,'" + endtime + "')>=0 ";
                }

                if (strpageindex.Trim() != "")
                {
                    try
                    {
                        pageindex = Convert.ToInt32(strpageindex);
                    }
                    catch
                    { }
                }
                if (strpagesize.Trim() != "")
                {
                    try
                    {
                        pagesize = Convert.ToInt32(strpagesize);
                    }
                    catch
                    { }
                }
                int recordCount = 0;
                Model.PageData<Model.T_Wo_WorkOrderBase> pageModel = new Model.PageData<Model.T_Wo_WorkOrderBase>();

                dt = BLL.PagerBLL.GetListPager(
                    "V_WorkOrderBase",
                    "F_WORKORDERID",
                    "*",
                    sql,
                    "ORDER BY F_WORKORDERID desc",
                    pagesize,
                    pageindex,
                    true,
                    out recordCount);

                System.Collections.Generic.List<Model.T_Wo_WorkOrderBase> modelList = new BLL.T_Wo_WorkOrderBase().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_Wo_WorkOrderBase>));
                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;
        }
        #endregion

        #region 删除数据
        private string Delete(HttpContext context)
        {
            bool res = false;
            string arr = HttpUtility.UrlDecode(CommonRequest.GetQueryString("arrid"));
            if (arr.IndexOf(",") == -1)
            {
                res = new BLL.T_Call_CallRecords().Delete(Convert.ToInt32(arr));
            }
            else
            {
                res = new BLL.T_Call_CallRecords().DeleteList(arr);
            }


            return res ? "success" : "field";
        }

        #endregion
        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}