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

namespace HySoft.BaseCallCenter.Web.telmanage.ajax
{
    /// <summary>
    /// editandsavecustomerinfo 的摘要说明
    /// </summary>
    public class editandsavecustomerinfo : IHttpHandler
    {
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            //取得处事类型
            string action = CommonRequest.GetQueryString("action");
            switch (action)
            {
                case "editAndSave":
                    context.Response.Write(editAndSaveCustomerInfo(context));
                    break;
            }
        }
        private bool editAndSaveCustomerInfo(HttpContext context)
        {
            int cid = 0;
            if (CommonRequest.GetQueryString("cid") != "")
                int.TryParse(CommonRequest.GetQueryString("cid"), out cid);

            #region 收集参数
            string cname = CommonRequest.GetQueryString("cname");
            //string ccode = CommonRequest.GetQueryString("ccode");
            int sdepid = 0;
            if (CommonRequest.GetQueryString("sdepid") != "")
                int.TryParse(CommonRequest.GetQueryString("sdepid"), out sdepid);
            string sdep = CommonRequest.GetQueryString("sdep");
            int prid = 0;
            if (CommonRequest.GetQueryString("prid") != "")
                int.TryParse(CommonRequest.GetQueryString("prid"), out prid);
            string pr = CommonRequest.GetQueryString("pr");
            int ctid = 0;
            if (CommonRequest.GetQueryString("ctid") != "")
                int.TryParse(CommonRequest.GetQueryString("ctid"), out ctid);
            string ct = CommonRequest.GetQueryString("ct");

            string tel = CommonRequest.GetQueryString("tel");
            string mobile = CommonRequest.GetQueryString("mobile");
            string tel1 = CommonRequest.GetQueryString("tel1");
            #endregion

            Model.T_Cus_CustomerBase tccb = new Model.T_Cus_CustomerBase();
            if (cid > 0)
            {
                tccb = new BLL.T_Cus_CustomerBase().GetModel(cid);
                #region 构造实体对象
                //tccb.F_CustomerId = cid;
                tccb.F_CustomerName = cname;
                //tccb.F_CustomerCode = ccode;
                tccb.F_ServiceDeptID = sdepid;
                tccb.F_ServiceDept = sdep;
                tccb.F_RegionId = prid;
                tccb.F_Province = pr;
                tccb.F_CityID = ctid;
                tccb.F_City = ct;

                tccb.F_Telephone = tel;
                tccb.F_Mobile = mobile;
                tccb.F_ChargeTelephone = tel1;
                #endregion
                bool b = new BLL.T_Cus_CustomerBase().Update(tccb);
                return b;
            }
            else {
                #region 构造实体对象
                //tccb.F_CustomerId = cid;
                tccb.F_CustomerName = cname;
                //tccb.F_CustomerCode = ccode;
                tccb.F_ServiceDeptID = sdepid;
                tccb.F_ServiceDept = sdep;
                tccb.F_RegionId = prid;
                tccb.F_Province = pr;
                tccb.F_CityID = ctid;
                tccb.F_City = ct;

                tccb.F_Telephone = tel;
                tccb.F_Mobile = mobile;
                tccb.F_ChargeTelephone = tel1;
                #endregion

                return new BLL.T_Cus_CustomerBase().Add(tccb)>0;
            }
        }
        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}