コード例 #1
0
        /// <summary>
        /// 编辑及新增
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult Edit(int id = 0)
        {
            //数据库类型
            Dictionary <int, string> dicDbType = new Dictionary <int, string>();

            foreach (Enums.DBType source in Enum.GetValues(typeof(Enums.DBType)))
            {
                dicDbType.Add((int)source, source.ToString());
            }
            ViewBag.DIC_DB_TYPE = dicDbType;
            BF_DATABASE.Entity entity = new BF_DATABASE.Entity();

            if (id > 0)
            {
                entity = BF_DATABASE.Instance.GetEntityByKey <BF_DATABASE.Entity>(id);
                //对密码进行aes解密
                entity.PASSWORD = CS.Base.Encrypt.BAES.Decrypt(entity.PASSWORD);
                if (entity == null)
                {
                    return(ShowAlert("配置项不存在"));
                }
            }

            return(View(entity));
        }
コード例 #2
0
        public JsonResult Edit(BF_DATABASE.Entity entity)
        {
            JsonResultData result = new JsonResultData();
            int            i      = 0;

            try
            {
                CheckInput(entity);

                if (entity.ID < 0)
                {
                    result.Message = "数据库不存在,不可编辑";
                    return(Json(result, JsonRequestBehavior.AllowGet));
                }
                //对密码进行aes加密
                string password = CS.Base.Encrypt.BAES.Encrypt(entity.PASSWORD);
                entity.PASSWORD    = password;
                entity.UPDATE_UID  = SystemSession.UserID;
                entity.UPDATE_TIME = DateTime.Now;
                if (entity.ID == 0)
                {
                    entity.CREATE_UID  = SystemSession.UserID;
                    entity.CREATE_TIME = DateTime.Now;
                    i = BF_DATABASE.Instance.Add(entity);
                }
                else
                {
                    BF_DATABASE.Entity oldEntity = BF_DATABASE.Instance.GetEntityByKey <BF_DATABASE.Entity>(entity.ID);
                    entity.CREATE_UID  = oldEntity.CREATE_UID;
                    entity.CREATE_TIME = oldEntity.CREATE_TIME;
                    i = BF_DATABASE.Instance.UpdateByKey <BF_DATABASE.Entity>(entity, entity.ID);
                }

                if (i < 1)
                {
                    result.Message = "出现了未知错误";
                    return(Json(result, JsonRequestBehavior.AllowGet));
                }

                result.IsSuccess = true;
                result.Message   = "保存成功";
            }
            catch (Exception ex)
            {
                result.IsSuccess = false;
                result.Message   = ex.Message;
                BLog.Write(BLog.LogLevel.WARN, "编辑数据库配置出错:" + ex.ToString());
            }

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
コード例 #3
0
        /// <summary>
        /// 验证输入
        /// </summary>
        /// <param name="entity"></param>
        private void CheckInput(BF_DATABASE.Entity entity)
        {
            if (entity == null)
            {
                throw new Exception("对象为空");
            }
            if (string.IsNullOrWhiteSpace(entity.NAME))
            {
                throw new Exception("数据库名称不可为空");
            }
            if (string.IsNullOrWhiteSpace(entity.IP))
            {
                throw new Exception("数据库IP地址不可为空");
            }
            if (entity.PORT < 1)
            {
                throw new Exception("端口号输入不正确");
            }
            if (string.IsNullOrWhiteSpace(entity.USER_NAME))
            {
                throw new Exception("用户名不可为空");
            }
            if (string.IsNullOrWhiteSpace(entity.NAME))
            {
                throw new Exception("密码不可为空");
            }
            if (string.IsNullOrWhiteSpace(entity.PASSWORD))
            {
                throw new Exception("数据库密码不可为空");
            }
            if (string.IsNullOrWhiteSpace(entity.DB_NAME))
            {
                throw new Exception("数据库实例名不可为空");
            }

            if (BF_DATABASE.Instance.IsDuplicate(entity.ID, "NAME", entity.NAME))
            {
                throw new Exception("数据库名称 " + entity.NAME + " 已经存在");
            }
        }