/// <summary> /// 设置配置项的值 /// </summary> /// <param name="config"></param> /// <param name="value"></param> /// <param name="remark"></param> /// <returns></returns> private static int SetConfig(Enums.SystemConfig config, object value, string remark = "") { if (value == null || string.IsNullOrWhiteSpace(value.ToString())) { throw new Exception("配置项" + config.ToString() + "不可为空"); } Dictionary <string, object> dic = new Dictionary <string, object>(); object v = 0; switch (config) { case Enums.SystemConfig.系统名称: v = value.ToString(); break; case Enums.SystemConfig.会话失效时间: v = Math.Max(1, Convert.ToInt32(value)); break; case Enums.SystemConfig.管理员用户名: v = value.ToString(); break; case Enums.SystemConfig.默认密码: v = value.ToString(); break; case Enums.SystemConfig.登录失败最大次数: v = Math.Max(3, Convert.ToInt32(value)); break; } dic.Add("VALUE", v); dic.Add("UPDATE_UID", SystemSession.UserID); dic.Add("UPDATE_TIME", DateTime.Now); if (string.IsNullOrWhiteSpace(remark) == false) { dic.Add("REMARK", remark); } int i = Instance.UpdateByKey(dic, config.GetHashCode()); if (i > 0) { return(i); } dic.Add("ID", config.GetHashCode()); dic.Add("CREATE_UID", SystemSession.UserID); dic.Add("CREATE_TIME", DateTime.Now); return(Instance.Add(dic)); }
/// <summary> /// 获取配置项 /// </summary> /// <param name="config">配置项</param> /// <returns></returns> private static DTO GetDTO(Enums.SystemConfig config) { bool isFound = false; string value = ""; string remark = ""; DateTime update = new DateTime(2018, 6, 6); DataTable dt = Instance.GetTable(); if (dt != null && dt.Rows.Count > 0) { DataRow[] drs = dt.Select("ID=" + config.GetHashCode()); if (drs != null) { isFound = true; value = Convert.ToString(drs[0]["VALUE"]); remark = Convert.ToString(drs[0]["REMARK"]); update = Convert.ToDateTime(drs[0]["UPDATE_TIME"]); } } DTO dto = new DTO(); dto.ID = config; dto.Name = config.ToString(); dto.ValueType = "文本"; dto.UpdateTime = update; switch (config) { case Enums.SystemConfig.系统名称: dto.Value = isFound ? value : "第四代PC框架"; dto.Remark = isFound ? remark : ""; break; case Enums.SystemConfig.会话失效时间: dto.ValueType = "整数"; dto.Value = isFound ? Convert.ToInt32(value) : 30; dto.Remark = isFound ? remark : "即SESSION失效时间,单位:分钟"; break; case Enums.SystemConfig.管理员用户名: dto.Value = isFound ? value : "admin"; dto.Remark = isFound ? remark : "系统管理员"; break; case Enums.SystemConfig.默认密码: dto.Value = isFound ? value : "easyman"; dto.Remark = isFound ? remark : "新增及重置用户的默认密码"; break; case Enums.SystemConfig.登录失败最大次数: dto.ValueType = "整数"; dto.Value = isFound ? Convert.ToInt32(value) : 5; dto.Remark = isFound ? remark : "登录连续失败达到该次数,账户将被锁定"; break; } return(dto); }