Example #1
0
        public ActionResult AddOrEditOilViscosityPriorityConfig(BaoYangOilViscosityPriorityConfigModel model)
        {
            if (model == null || string.IsNullOrWhiteSpace(model.OriginViscosity))
            {
                return(Json(new { Status = false, Msg = "未知的编辑对象" }, JsonRequestBehavior.AllowGet));
            }
            if (string.IsNullOrWhiteSpace(model.ConfigType) || !Enum.IsDefined(typeof(BaoYangOilViscosityPriorityConfigType), model.ConfigType))
            {
                return(Json(new { Status = false, Msg = "未知的类型" }, JsonRequestBehavior.AllowGet));
            }
            if (string.IsNullOrWhiteSpace(model.ViscosityPriority) || !model.ViscosityPriorities.Any())
            {
                return(Json(new { Status = false, Msg = "优先级不能为空" }, JsonRequestBehavior.AllowGet));
            }
            var distinctCount = model.ViscosityPriority.Split(',').Count();

            if (model.ViscosityPriorities.Count != distinctCount)
            {
                return(Json(new { Status = false, Msg = $"粘度重复,请重新选择" }, JsonRequestBehavior.AllowGet));
            }
            var manager = new BaoYangOilViscosityPriorityConfigManager();
            var result  = manager.AddOrEditBaoYangOilViscosityPriorityConfig(model, User.Identity.Name);

            return(Json(new { Status = result, Msg = $"编辑{(result ? "成功" : "失败")}" }, JsonRequestBehavior.AllowGet));
        }
        /// <summary>
        /// 添加机油粘度优先级配置
        /// </summary>
        /// <param name="conn"></param>
        /// <param name="model"></param>
        /// <returns></returns>
        public static int AddBaoYangOilViscosityPriorityConfig(SqlConnection conn, BaoYangOilViscosityPriorityConfigModel model)
        {
            var sql        = @"INSERT  BaoYang..BaoYangOilViscosityPriorityConfig
                                ( OriginViscosity ,
                                  ViscosityPriority ,
                                  ConfigType
                                )
                        VALUES  ( @OriginViscosity ,
                                  @ViscosityPriority ,
                                  @ConfigType
                                );
                        SELECT  SCOPE_IDENTITY();";
            var parameters = new[]
            {
                new SqlParameter("@OriginViscosity", model.OriginViscosity),
                new SqlParameter("@ViscosityPriority", model.ViscosityPriority),
                new SqlParameter("@ConfigType", model.ConfigType)
            };

            return(Convert.ToInt32(SqlHelper.ExecuteScalar(conn, CommandType.Text, sql, parameters)));
        }
        /// <summary>
        /// 更新机油粘度优先级配置
        /// </summary>
        /// <param name="conn"></param>
        /// <param name="model"></param>
        /// <returns></returns>
        public static bool UpdateBaoYangOilViscosityPriorityConfig(SqlConnection conn, BaoYangOilViscosityPriorityConfigModel model)
        {
            var sql        = @"UPDATE  BaoYang..BaoYangOilViscosityPriorityConfig
                        SET     ViscosityPriority = @ViscosityPriority ,
                                IsDeleted = 0
                        WHERE   OriginViscosity = @OriginViscosity
                                AND ConfigType = @ConfigType;";
            var parameters = new[]
            {
                new SqlParameter("@OriginViscosity", model.OriginViscosity),
                new SqlParameter("@ViscosityPriority", model.ViscosityPriority),
                new SqlParameter("@ConfigType", model.ConfigType)
            };

            return(Convert.ToInt32(SqlHelper.ExecuteNonQuery(conn, CommandType.Text, sql, parameters)) > 0);
        }
Example #4
0
        /// <summary>
        /// 添加或编辑机油粘度优先级配置
        /// </summary>
        /// <param name="model"></param>
        /// <param name="user"></param>
        /// <returns></returns>
        public bool AddOrEditBaoYangOilViscosityPriorityConfig(BaoYangOilViscosityPriorityConfigModel model, string user)
        {
            var result = false;
            var log    = null as BaoYangOprLog;

            try
            {
                var oldValue = dbScopeManagerGungnirRead.Execute(conn => DalBaoYangOilViscosityPriorityConfig.GetBaoYangOilViscosityPriorityConfig(conn, model.OriginViscosity, model.ConfigType));
                #region 添加 判断是否存在该原厂粘度被逻辑删除的记录 存在则更新 不存在则插入
                if (oldValue == null)
                {
                    #region 插入记录
                    var pkid = dbScopeManagerGungnir.Execute(conn => DalBaoYangOilViscosityPriorityConfig.AddBaoYangOilViscosityPriorityConfig(conn, model));
                    if (pkid > 0)
                    {
                        result     = true;
                        model.PKID = pkid;
                        log        = new BaoYangOprLog
                        {
                            LogType     = "BaoYangOilViscosityPriorityConfig",
                            IdentityID  = model.OriginViscosity,
                            OldValue    = null,
                            NewValue    = JsonConvert.SerializeObject(model),
                            Remarks     = $"添加{model.ConfigType}类原厂机油粘度{model.OriginViscosity}推荐优先级:{model.ViscosityPriority}",
                            OperateUser = user,
                        };
                    }
                    #endregion
                }
                else if (oldValue.IsDeleted)
                {
                    #region 更新逻辑删除的记录
                    result = dbScopeManagerGungnir.Execute(conn => DalBaoYangOilViscosityPriorityConfig.UpdateBaoYangOilViscosityPriorityConfig(conn, model));
                    log    = new BaoYangOprLog
                    {
                        LogType     = "BaoYangOilViscosityPriorityConfig",
                        IdentityID  = model.OriginViscosity,
                        OldValue    = null,
                        NewValue    = JsonConvert.SerializeObject(model),
                        Remarks     = $"添加{model.ConfigType}类原厂机油粘度{model.OriginViscosity}推荐优先级:{model.ViscosityPriority}",
                        OperateUser = user,
                    };
                    #endregion
                }
                #endregion
                #region 更新
                else
                {
                    result = dbScopeManagerGungnir.Execute(conn => DalBaoYangOilViscosityPriorityConfig.UpdateBaoYangOilViscosityPriorityConfig(conn, model));
                    log    = new BaoYangOprLog
                    {
                        LogType     = "BaoYangOilViscosityPriorityConfig",
                        IdentityID  = model.OriginViscosity,
                        OldValue    = JsonConvert.SerializeObject(oldValue),
                        NewValue    = JsonConvert.SerializeObject(model),
                        Remarks     = $"更新{model.ConfigType}类原厂机油粘度{model.OriginViscosity}推荐优先级:{model.ViscosityPriority}",
                        OperateUser = user,
                    };
                }
                #endregion
                if (result && log != null)
                {
                    LoggerManager.InsertLog("BYOprLog", log);
                }
            }
            catch (Exception ex)
            {
                Logger.Error("AddOrEditBaoYangOilViscosityPriorityConfig", ex);
            }
            return(result);
        }