示例#1
0
        ///<summary>
        /// 6.添加修改客户
        /// /App/KeHuAdd
        /// 参数:
        /// UserID
        /// KeHu:这是个JSON用来传客户信息
        /// 外层ID写0表示新添加的客户,不是0表示修改现有客户
        /// 电话里的ID写0表示新添加的电话,非0表示修改已有电话
        /// </summary>
        public ApiResultModelBase AddOrModifyCustomer(int uId, AddKeHuModel customer)
        {
            string url = string.Format("{0}App/KeHuAdd", ApiUrl);

            string str = ValueConvert.ObjToJsonStr(customer);

            string postData = string.Format("UserID={0}&KeHu={1}",
                                            uId, str);

            return(httpHelper.PostAndGetEntity <ApiResultModelBase>(
                       url,
                       postData,
                       null,
                       null,
                       false,
                       Encoding.UTF8));
        }
        private void AddOfModifyCustomerInfo(bool isAdd)
        {
            if (string.IsNullOrEmpty(Name) || string.IsNullOrWhiteSpace(Name))
            {
                MessageBox.Show("请填写客户姓名!");
                return;
            }
            if (string.IsNullOrEmpty(Telephone) || string.IsNullOrWhiteSpace(Telephone))
            {
                MessageBox.Show("必须添加一个电话号码!");
                return;
            }

            var customerInfo = new AddKeHuModel();

            customerInfo.ID       = isAdd ? 0 : _customerInfo.ID;
            customerInfo.UserName = Name;
            customerInfo.XingBie  = _sex;
            if (isAdd)
            {
                //添加客户信息
                _telephoneList.Clear();
                _telephoneList.Add(Telephone);
                if (!string.IsNullOrEmpty(SecondTelephone) && !_telephoneList.Contains(SecondTelephone))
                {
                    _telephoneList.Add(SecondTelephone);
                }
                if (!string.IsNullOrEmpty(ThirdTelephone) && !_telephoneList.Contains(ThirdTelephone))
                {
                    _telephoneList.Add(ThirdTelephone);
                }

                customerInfo.KeHuDianHua = (from t in _telephoneList
                                            select new DianHuaModel
                {
                    ID = 0,
                    DianHua = t
                }).ToList();
            }
            else
            {
                //修改客户信息
                customerInfo.KeHuDianHua = new List <DianHuaModel>();

                if (_originTelephone != string.Empty && _originTelephone != Telephone)
                {
                    var tmp = _customerInfo.DianHuaList[0];
                    customerInfo.KeHuDianHua.Add(new DianHuaModel()
                    {
                        ID = tmp.ID, DianHua = Telephone, IsMoRen = tmp.IsMoRen, Remark = tmp.Remark
                    });
                }
                if (_originSecondTelephone != string.Empty && _originSecondTelephone != SecondTelephone)
                {
                    var tmp = _customerInfo.DianHuaList[1];
                    customerInfo.KeHuDianHua.Add(new DianHuaModel()
                    {
                        ID = tmp.ID, DianHua = SecondTelephone, IsMoRen = tmp.IsMoRen, Remark = tmp.Remark
                    });
                }
                if (_originThirdTelephone != string.Empty && _originThirdTelephone != ThirdTelephone)
                {
                    var tmp = _customerInfo.DianHuaList[2];
                    customerInfo.KeHuDianHua.Add(new DianHuaModel()
                    {
                        ID = tmp.ID, DianHua = ThirdTelephone, IsMoRen = tmp.IsMoRen, Remark = tmp.Remark
                    });
                }

                if (_originSecondTelephone == string.Empty && SecondTelephone != string.Empty)
                {
                    customerInfo.KeHuDianHua.Add(new DianHuaModel()
                    {
                        ID = 0, DianHua = SecondTelephone
                    });
                }

                if (_originThirdTelephone == string.Empty && ThirdTelephone != string.Empty)
                {
                    customerInfo.KeHuDianHua.Add(new DianHuaModel()
                    {
                        ID = 0, DianHua = ThirdTelephone
                    });
                }
            }

            //发送请求
            var rst = DataRepository.Instance.AddOrModifyCustomer(GlobalDataPool.Instance.Uid, customerInfo);

            if (!rst.success)
            {
                MessageBox.Show(rst.message);
            }
            else
            {
                var str = isAdd ? "添加" : "修改";
                MessageBox.Show(string.Format("{0}客户成功!", str));
            }
        }