コード例 #1
0
        public ActionResult DeleteCustomer()
        {
            var customerCode = Request["customerCode"].SafeConvert().ToStr();
            var pkId         = Request["__qcrm_pkval"].SafeConvert().ToStr();

            if (customerCode.Length == 0)
            {
                throw new UIValidateException("客户编号为空请检查客户端数据。");
            }
            if (pkId.Length == 0)
            {
                throw new UIValidateException("客户ID为空请检查客户端数据。");
            }

            var result  = QWF.Framework.Web.ResultWebData.Default();
            var curUser = QWF.Framework.Web.UserContext.GetCurrentInfo();

            var httpContext = System.Web.HttpContext.Current;
            var formUtils   = new QWF.CRM.Utils.FormUtils(httpContext);
            var permissoin  = new QWF.CRM.Utils.PermissionUtils(curUser);
            var plugIn      = QWF.CRM.PlugIn.PlugInServices.GetInstance(formUtils.FormCode);

            if (!permissoin.IsDeleteCustomer(customerCode))
            {
                var message = string.Format("权限错误(数据):用户【{0}】对【{1}】无操作权限", curUser.CurrentUserName, formUtils.DbForm.Name);
                QWF.Framework.MainServices.CreateWebAppServices.GetUserActionLogServices().WriterActionLog("权限验证.修改数据", Framework.Services.SvrModels.SverUserActionLogType.Update, message, new { 客户编号 = customerCode });
                throw new UIValidateException(message);
            }

            if (plugIn != null)
            {
                plugIn.OnBegin(httpContext, pkId, customerCode);
            }

            try
            {
                //逻辑删除
                formUtils.SafeDictionary.Add("CustomerCode", customerCode);
                formUtils.SaveForm();

                //写入日志
                QWF.Framework.MainServices.CreateWebAppServices.GetUserActionLogServices().WriterActionLog("删除客户", Framework.Services.SvrModels.SverUserActionLogType.Update, null, new { 客户编码 = customerCode });
            }
            catch (Exception e)
            {
                if (plugIn != null)
                {
                    plugIn.Fail(e);
                }
                throw e;
            }

            if (plugIn != null)
            {
                plugIn.OnSuccess(httpContext, customerCode, customerCode);
            }

            return(this.Content(Newtonsoft.Json.JsonConvert.SerializeObject(result)));
        }
コード例 #2
0
        public ActionResult SaveCustomerForm()
        {
            var result       = QWF.Framework.Web.ResultWebData.Default();
            var curUser      = QWF.Framework.Web.UserContext.GetCurrentInfo();
            var customerCode = Request["customerCode"].SafeConvert().ToStr();
            var httpContext  = System.Web.HttpContext.Current;
            var formUtils    = new QWF.CRM.Utils.FormUtils(httpContext);
            var permissoin   = new QWF.CRM.Utils.PermissionUtils(curUser);
            var plugIn       = QWF.CRM.PlugIn.PlugInServices.GetInstance(formUtils.FormCode);

            try
            {
                if (formUtils.DbForm.ActionType == "update")
                {
                    if (customerCode.Length == 0)
                    {
                        throw new UIValidateException("客户编号为空请检查客户端数据。");
                    }

                    if (!permissoin.IsUpdateCustomer(customerCode))
                    {
                        var message = string.Format("权限错误(数据):用户【{0}】对【{1}】无操作权限", curUser.CurrentUserName, formUtils.DbForm.Name);
                        QWF.Framework.MainServices.CreateWebAppServices.GetUserActionLogServices().WriterActionLog("权限验证.修改数据", Framework.Services.SvrModels.SverUserActionLogType.Update, message, new { 客户编号 = customerCode });
                        throw new UIValidateException(message);
                    }
                    //保存修改
                    if (plugIn != null)
                    {
                        plugIn.OnBegin(httpContext, customerCode, customerCode);
                    }

                    //安全过滤参数
                    formUtils.SafeDictionary.Add("CustomerCode", customerCode);
                    formUtils.SaveForm();
                }
                else if (formUtils.DbForm.ActionType == "create")
                {
                    if (plugIn != null)
                    {
                        plugIn.OnBegin(httpContext, customerCode, string.Empty);
                    }
                    //新增保存并返回表单的客户code
                    customerCode = formUtils.SaveForm <string>("CustomerCode").Replace("'", "");
                }
                //产品&服务
                var products        = Request["product"].SafeConvert().ToStr().StringHelper().SplitToArray(",", StringSplitOptions.RemoveEmptyEntries);
                var productCodeList = new List <string>();
                products.ToList().ForEach(p =>
                {
                    var productCode = p.Split(new char[1] {
                        '$'
                    }, StringSplitOptions.RemoveEmptyEntries)[0];
                    if (productCode.Length > 0)
                    {
                        productCodeList.Add(productCode);
                    }
                });

                using (var db = DbAccess.DbCRMContext.Create())
                {
                    //清除不需要的产品,以勾选的服务为准
                    db.T_QCRM_CustomerProduct.Where(w => !productCodeList.Contains(w.ProductCode) && w.CustomerCode == customerCode).ToList().ForEach(item =>
                    {
                        var dbModel = db.T_QCRM_CustomerProduct.Where(w => w.Id == item.Id).FirstOrDefault();
                        db.T_QCRM_CustomerProduct.Remove(dbModel);
                    });

                    foreach (var item in products)
                    {
                        //服务时间:
                        var product     = item.SafeConvert().ToStr().StringHelper().SplitToArray("$", StringSplitOptions.RemoveEmptyEntries);
                        var productCode = product[0];
                        var productName = product[1];

                        var beginDate     = Request["svrBeginDate_" + productCode].SafeConvert().ToStr();
                        var endDate       = Request["svrEndDate_" + productCode].SafeConvert().ToStr();
                        var productItemId = Request["productItem_" + productCode].SafeConvert().ToInt32();
                        var remark        = Request["productRemarks_" + productCode].SafeConvert().ToStr();

                        if (beginDate.Length > 0 && endDate.Length == 0)
                        {
                            throw new UIValidateException("【{0}】请填写结束时间", productName);
                        }

                        if (beginDate.Length > 0 && endDate.Length > 0)
                        {
                            if (endDate.SafeConvert().ToDateTime() <= beginDate.SafeConvert().ToDateTime())
                            {
                                throw new UIValidateException("【{0}】结束时间必须大于开始时间", productName);
                            }
                        }
                        // 幂等操作产品服务
                        #region 幂等操作产品服务

                        DbAccess.T_QCRM_CustomerProduct dbModel = null;
                        dbModel = db.T_QCRM_CustomerProduct.Where(w => w.CustomerCode == customerCode && w.ProductCode == productCode).FirstOrDefault();
                        if (dbModel == null)
                        {
                            dbModel = new DbAccess.T_QCRM_CustomerProduct();

                            dbModel.ProductCode   = productCode;
                            dbModel.CustomerCode  = customerCode;
                            dbModel.ProductItemId = productItemId;
                            if (beginDate.Length > 0 && endDate.Length > 0)
                            {
                                dbModel.BeginTime = beginDate.SafeConvert().ToDateTime();
                                dbModel.EndTime   = endDate.SafeConvert().ToDateTime();
                            }
                            dbModel.Remarks    = remark;
                            dbModel.CreateTime = DateTime.Now;
                            dbModel.CreateUser = curUser.CurrentUserCode;

                            db.T_QCRM_CustomerProduct.Add(dbModel);
                        }
                        else
                        {
                            dbModel.ProductItemId = productItemId;
                            if (beginDate.Length > 0 && endDate.Length > 0)
                            {
                                dbModel.BeginTime = beginDate.SafeConvert().ToDateTime();
                                dbModel.EndTime   = endDate.SafeConvert().ToDateTime();
                            }
                            dbModel.Remarks    = remark;
                            dbModel.UpdateTime = DateTime.Now;
                            dbModel.UpdateUser = curUser.CurrentUserCode;
                        }

                        //
                        #endregion
                    }
                    //提交保存
                    db.SaveChanges();
                }
                //执行成功
                if (plugIn != null)
                {
                    plugIn.OnSuccess(httpContext, customerCode, customerCode);
                }
                //输出结果
                result.Data = new { Code = customerCode };
            }
            catch (Exception e)
            {
                if (plugIn != null)
                {
                    plugIn.Fail(e);
                }
                throw e;
            }


            return(this.Content(Newtonsoft.Json.JsonConvert.SerializeObject(result)));
        }