/// <summary>
        /// 获取指定记录
        /// <param name="id">Id值</param>
        /// </summary>
        public MarketingChance Get(int IdmarketingChance)
        {
            MarketingChance returnValue            = null;
            MySqlConnection oc                     = ConnectManager.Create();
            MySqlCommand    _cmdGetMarketingChance = cmdGetMarketingChance.Clone() as MySqlCommand;

            _cmdGetMarketingChance.Connection = oc;
            try
            {
                _cmdGetMarketingChance.Parameters["@IdmarketingChance"].Value = IdmarketingChance;

                if (oc.State == ConnectionState.Closed)
                {
                    oc.Open();
                }

                MySqlDataReader reader = _cmdGetMarketingChance.ExecuteReader();
                if (reader.HasRows)
                {
                    reader.Read();
                    returnValue = new MarketingChance().BuildSampleEntity(reader);
                }
            }
            finally
            {
                oc.Close();
                oc.Dispose();
                oc = null;
                _cmdGetMarketingChance.Dispose();
                _cmdGetMarketingChance = null;
                GC.Collect();
            }
            return(returnValue);
        }
        //编辑销售机会详情(机会ID,机会类型,客户类型,机会描述,联系人,联系方式,token) 返回(true/false)
        public JsonResult EditMarketingInfo(int cid, int chanceType, int customerType,
                                            string username, string chanceDetail, string tel,
                                            string phone, string email, string qq)
        {
            var        Res    = new JsonResult();
            RespResult result = new RespResult();

            try
            {
                if (CacheManagerFactory.GetMemoryManager().Contains(token))
                {
                    if (!CheckUserFunction("1202"))
                    {
                        result.Error            = AppError.ERROR_PERMISSION_FORBID;
                        Res.Data                = result;
                        Res.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
                        return(Res);
                    }

                    MarketingChance chance = new MarketingChance();
                    chance              = MarketingChanceAccessor.Instance.Get(cid);
                    chance.ChanceType   = chanceType;
                    chance.ContactName  = username;
                    chance.CustomerType = customerType;
                    chance.Email        = email;
                    chance.Phone        = phone;
                    chance.Qq           = qq;
                    chance.Remark       = chanceDetail;
                    chance.Tel          = tel;
                    MarketingChanceAccessor.Instance.Update(chance);
                    result.Error = AppError.ERROR_SUCCESS;
                }
                else
                {
                    result.Error = AppError.ERROR_PERSON_NOT_LOGIN;
                }
            }
            catch (Exception e)
            {
                result.Error     = AppError.ERROR_FAILED;
                result.ExMessage = e.ToString();
            }
            Res.Data = result;
            Res.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
            return(Res);
        }
        /// <summary>
        /// 修改指定的数据
        /// <param name="e">修改后的数据实体对象</param>
        /// <para>数据对应的主键必须在实例中设置</para>
        /// </summary>
        public void Update(MarketingChance e)
        {
            MySqlConnection oc = ConnectManager.Create();
            MySqlCommand    _cmdUpdateMarketingChance = cmdUpdateMarketingChance.Clone() as MySqlCommand;

            _cmdUpdateMarketingChance.Connection = oc;

            try
            {
                if (oc.State == ConnectionState.Closed)
                {
                    oc.Open();
                }

                _cmdUpdateMarketingChance.Parameters["@IdmarketingChance"].Value = e.IdmarketingChance;
                _cmdUpdateMarketingChance.Parameters["@ChanceType"].Value        = e.ChanceType;
                _cmdUpdateMarketingChance.Parameters["@CustomerType"].Value      = e.CustomerType;
                _cmdUpdateMarketingChance.Parameters["@ContactName"].Value       = e.ContactName;
                _cmdUpdateMarketingChance.Parameters["@Remark"].Value            = e.Remark;
                _cmdUpdateMarketingChance.Parameters["@AddTime"].Value           = e.AddTime;
                _cmdUpdateMarketingChance.Parameters["@Qq"].Value     = e.Qq;
                _cmdUpdateMarketingChance.Parameters["@Email"].Value  = e.Email;
                _cmdUpdateMarketingChance.Parameters["@Tel"].Value    = e.Tel;
                _cmdUpdateMarketingChance.Parameters["@Phone"].Value  = e.Phone;
                _cmdUpdateMarketingChance.Parameters["@Rate"].Value   = e.Rate;
                _cmdUpdateMarketingChance.Parameters["@EntId"].Value  = e.EntId;
                _cmdUpdateMarketingChance.Parameters["@UserId"].Value = e.UserId;

                _cmdUpdateMarketingChance.ExecuteNonQuery();
            }
            finally
            {
                oc.Close();
                oc.Dispose();
                oc = null;
                _cmdUpdateMarketingChance.Dispose();
                _cmdUpdateMarketingChance = null;
                GC.Collect();
            }
        }
        /// <summary>
        /// 添加数据
        /// <param name="es">数据实体对象数组</param>
        /// <returns></returns>
        /// </summary>
        public int Insert(MarketingChance e)
        {
            MySqlConnection oc = ConnectManager.Create();
            MySqlCommand    _cmdInsertMarketingChance = cmdInsertMarketingChance.Clone() as MySqlCommand;
            int             returnValue = 0;

            _cmdInsertMarketingChance.Connection = oc;
            try
            {
                if (oc.State == ConnectionState.Closed)
                {
                    oc.Open();
                }
                _cmdInsertMarketingChance.Parameters["@ChanceType"].Value   = e.ChanceType;
                _cmdInsertMarketingChance.Parameters["@CustomerType"].Value = e.CustomerType;
                _cmdInsertMarketingChance.Parameters["@ContactName"].Value  = e.ContactName;
                _cmdInsertMarketingChance.Parameters["@Remark"].Value       = e.Remark;
                _cmdInsertMarketingChance.Parameters["@AddTime"].Value      = e.AddTime;
                _cmdInsertMarketingChance.Parameters["@Qq"].Value           = e.Qq;
                _cmdInsertMarketingChance.Parameters["@Email"].Value        = e.Email;
                _cmdInsertMarketingChance.Parameters["@Tel"].Value          = e.Tel;
                _cmdInsertMarketingChance.Parameters["@Phone"].Value        = e.Phone;
                _cmdInsertMarketingChance.Parameters["@Rate"].Value         = e.Rate;
                _cmdInsertMarketingChance.Parameters["@EntId"].Value        = e.EntId;
                _cmdInsertMarketingChance.Parameters["@UserId"].Value       = e.UserId;

                _cmdInsertMarketingChance.ExecuteNonQuery();
                returnValue = Convert.ToInt32(_cmdInsertMarketingChance.LastInsertedId);
                return(returnValue);
            }
            finally
            {
                oc.Close();
                oc.Dispose();
                oc = null;
                _cmdInsertMarketingChance.Dispose();
                _cmdInsertMarketingChance = null;
            }
        }
        //获取单个销售机会详情(销售机会ID,token) 返回 (机会类型,客户类型,机会描述,联系人,联系方式,录入时间)
        public JsonResult GetMarketingInfo(int cid)
        {
            var Res = new JsonResult();
            AdvancedResult <MarketingChance> result = new AdvancedResult <MarketingChance>();

            try
            {
                if (CacheManagerFactory.GetMemoryManager().Contains(token))
                {
                    if (!CheckUserFunction("1205"))
                    {
                        result.Error            = AppError.ERROR_PERMISSION_FORBID;
                        Res.Data                = result;
                        Res.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
                        return(Res);
                    }
                    MarketingChance chance = new MarketingChance();
                    chance       = MarketingChanceAccessor.Instance.Get(cid);
                    result.Error = AppError.ERROR_SUCCESS;
                    result.Data  = chance;
                }
                else
                {
                    result.Error = AppError.ERROR_PERSON_NOT_LOGIN;
                }
            }
            catch (Exception e)
            {
                result.Error     = AppError.ERROR_FAILED;
                result.ExMessage = e.ToString();
            }

            Res.Data = result;
            Res.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
            return(Res);
        }
        //
        // GET: /MarketingManagement/Marketing/
        /// <summary>
        /// 销售机会即企业客户以及个人客户信息,此处都是调用客户信息
        /// </summary>
        /// <returns></returns>



        /// <summary>
        /// 添加销售机会(机会类型,客户类型,联系人,机会描述,联系方式{},是否同步,token)返回(true/false)
        /// 客户类型分为:1:企业客户2:个人客户;默认为企业客户
        /// </summary>
        public JsonResult AddMarketingChance(int chanceType, int customerType,
                                             string username, string chanceDetail, string tel,
                                             string phone, string email, string qq, bool Isasyn)
        {
            var        Res    = new JsonResult();
            RespResult result = new RespResult();

            try
            {
                if (CacheManagerFactory.GetMemoryManager().Contains(token))
                {
                    if (!CheckUserFunction("1202"))
                    {
                        result.Error            = AppError.ERROR_PERMISSION_FORBID;
                        Res.Data                = result;
                        Res.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
                        return(Res);
                    }

                    MarketingChance chance = new MarketingChance();
                    chance.AddTime      = DateTime.Now;
                    chance.ChanceType   = chanceType;
                    chance.ContactName  = username;
                    chance.CustomerType = customerType;
                    chance.Email        = email;
                    chance.EntId        = CurrentUser.EntId;
                    chance.Phone        = phone;
                    chance.Qq           = qq;
                    chance.Remark       = chanceDetail;
                    chance.Tel          = tel;
                    chance.UserId       = CurrentUser.UserId;
                    if (Isasyn)
                    {
                        switch (customerType)
                        {
                        case 1:
                            //添加企业客户
                            CustomerEnt ce = new CustomerEnt();
                            ce.EntName         = username;
                            ce.ContactUsername = username;
                            ce.ContactMobile   = phone;
                            ce.ContactPhone    = phone;
                            ce.ContactEmail    = email;
                            ce.ContactQq       = qq;
                            ce.Detail          = chanceDetail;
                            ce.OwnerId         = CurrentUser.UserId;
                            ce.EntId           = CurrentUser.EntId;
                            CustomerEntAccessor.Instance.Insert(ce);
                            break;

                        case 2:
                            //添加个人客户
                            CustomerPrivate cp = new CustomerPrivate();
                            cp.Name   = username;
                            cp.Mobile = phone;
                            cp.Phone  = phone;
                            cp.Email  = email;
                            cp.Qq     = qq;
                            cp.Detail = chanceDetail;

                            cp.OwnerId = CurrentUser.UserId;
                            cp.EntId   = CurrentUser.EntId; CustomerPrivateAccessor.Instance.Insert(cp);
                            break;
                        }
                    }
                    int i = MarketingChanceAccessor.Instance.Insert(chance);
                    if (i > 0)
                    {
                        result.Id    = i;
                        result.Error = AppError.ERROR_SUCCESS;
                    }
                    else
                    {
                        result.Error = AppError.ERROR_FAILED;
                    }
                }
                else
                {
                    result.Error = AppError.ERROR_PERSON_NOT_LOGIN;
                }
            }
            catch (Exception e)
            {
                result.Error     = AppError.ERROR_FAILED;
                result.ExMessage = e.ToString();
            }
            Res.Data = result;
            Res.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
            return(Res);
        }
Пример #7
0
        //编辑销售机会详情(机会ID,机会类型,客户类型,机会描述,联系人,联系方式,token) 返回(true/false)
        public JsonResult EditMarketingInfo(int cid, int chanceType, int customerType,
                                            string username, string chanceDetail, string tel,
                                            string phone, string email, string qq, int customerId)
        {
            var        Res    = new JsonResult();
            RespResult result = new RespResult();

            try
            {
                if (CacheManagerFactory.GetMemoryManager().Contains(token))
                {
                    if (!CheckUserFunction(19))
                    {
                        result.Error            = AppError.ERROR_PERMISSION_FORBID;
                        Res.Data                = result;
                        Res.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
                        return(Res);
                    }

                    MarketingChance chance = new MarketingChance();
                    chance              = MarketingChanceAccessor.Instance.Get(cid);
                    chance.ChanceType   = chanceType;
                    chance.ContactName  = username;
                    chance.CustomerType = customerType;
                    chance.Email        = email;
                    chance.Phone        = phone;
                    chance.Qq           = qq;
                    chance.Remark       = chanceDetail;
                    chance.Tel          = tel;
                    MarketingChanceAccessor.Instance.Update(chance);

                    switch (customerType)
                    {
                    case 1:
                        //编辑企业客户
                        CustomerEnt ce = CustomerEntAccessor.Instance.Get(customerId);
                        ce.EntName         = username;
                        ce.ContactUsername = username;
                        ce.ContactMobile   = phone;
                        ce.ContactPhone    = phone;
                        ce.ContactEmail    = email;
                        ce.ContactQq       = qq;
                        ce.Detail          = chanceDetail;
                        CustomerEntAccessor.Instance.Update(ce);
                        break;

                    case 2:
                        //编辑个人客户
                        CustomerPrivate cp = CustomerPrivateAccessor.Instance.Get(customerId);
                        cp.Name   = username;
                        cp.Mobile = phone;
                        cp.Phone  = phone;
                        cp.Email  = email;
                        cp.Qq     = qq;
                        cp.Detail = chanceDetail;

                        CustomerPrivateAccessor.Instance.Update(cp);
                        break;
                    }


                    result.Error = AppError.ERROR_SUCCESS;
                }
                else
                {
                    result.Error = AppError.ERROR_PERSON_NOT_LOGIN;
                }
            }
            catch (Exception e)
            {
                result.Error     = AppError.ERROR_FAILED;
                result.ExMessage = e.ToString();
            }
            Res.Data = result;
            Res.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
            return(Res);
        }