FineUI 官方论坛
标题:
请教个低级问题,各位大侠帮帮忙,学习中。
[打印本页]
作者:
Shadow
时间:
2013-5-10 15:41
标题:
请教个低级问题,各位大侠帮帮忙,学习中。
#region fields & constructor
/// <summary>
/// 缓存在内存
/// </summary>
private static XConfigCollection configs = new XConfigCollection();
/// <summary>
/// 载入所有的配置项
/// </summary>
static XConfigHelper()
{
ReloadColl();
}
/// <summary>
/// 重新加载所有的配置项
/// </summary>
public static void ReloadColl()
{
configs = new Select().From<XConfig>()
.ExecuteAsCollection<XConfigCollection>();
}
#endregion
#region methods
/// <summary>
/// 获取配置信息
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public static string GetValue(string key)
{
foreach (XConfig config in configs)
{
if (config.ConfigKey == key)
{
return config.ConfigValue;
}
}
return String.Empty;
}
/// <summary>
/// 设置值
/// </summary>
/// <param name="key"></param>
/// <param name="value"></param>
public static void SetValue(string key, string value)
{
foreach (XConfig config in configs)
{
if (config.ConfigKey == key)
{
config.ConfigValue = value;
}
}
}
/// <summary>
/// 保存所有更改的配置项
/// </summary>
public static void SaveAll()
{
configs.SaveAll();
}
#endregion
#region properties
/// <summary>
/// 网站标题
/// </summary>
public static string Title
{
get
{
return GetValue("Title");
}
set
{
SetValue("Title", value);
}
}
复制代码
请问,这段代码改成EF的如何改?
作者:
duke6372
时间:
2013-6-12 09:48
目前我的改法,供參考。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using a.Entities;
namespace a
{
public class SysconfigHelper
{
private static List<XConfig> configs = new List<XConfig>();
static SysconfigHelper()
{
ReloadSysconfig();
}
public static void ReloadSysconfig()
{
BSEntities _dbbs = new BSEntities();
configs = _dbbs.XConfig.ToList();
}
public static string GetValue(string key)
{
foreach (XConfig config in configs)
{
if (config.ConfigKey == key)
{
return config.ConfigValue;
}
}
return String.Empty;
}
public static void SetValue(String key, string value)
{
foreach (XConfig config in configs)
{
if (config.ConfigKey == key)
{
config.ConfigValue = value;
}
}
}
public static void SaveAll()
{
BSEntities _dbbs = new BSEntities();
List<XConfig> dbconfigs = _dbbs.XConfig.ToList();
foreach (XConfig config in configs)
{
foreach (XConfig c in dbconfigs)
{
if (c.ConfigKey == config.ConfigKey)
{
c.ConfigValue = config.ConfigValue;
}
}
}
_dbbs.SaveChanges();
}
public static string Title
{
get
{
return GetValue("Title");
}
set
{
SetValue("Title", value);
}
}
public static int PageSize
{
get
{
return Convert.ToInt32(GetValue("PageSize"));
}
set
{
SetValue("PageSize", value.ToString());
}
}
public static string MenuType
{
get
{
return GetValue("MenuType");
}
set
{
SetValue("MenuType", value);
}
}
public static string Theme
{
get
{
return GetValue("Theme");
}
set
{
SetValue("Theme", value);
}
}
}
}
复制代码
作者:
Shadow
时间:
2013-6-17 11:02
虽然之前我已经改完,但是还是万分感谢。
欢迎光临 FineUI 官方论坛 (https://fineui.com/bbs/)
Powered by Discuz! X3.4