</>code
- namespace AppBox
- {
- public class XConfigHelper
- {
- #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);
- }
- }
- /// <summary>
- /// 列表每页显示的个数
- /// </summary>
- public static int PageSize
- {
- get
- {
- return Convert.ToInt32(GetValue("PageSize"));
- }
- set
- {
- SetValue("PageSize", value.ToString());
- }
- }
- /// <summary>
- /// 菜单样式(手风琴式,树型菜单)
- /// </summary>
- public static string MenuType
- {
- get
- {
- return GetValue("MenuType");
- }
- set
- {
- SetValue("MenuType", value);
- }
- }
- #endregion
- }
- }
</>code
- <ext:PageManager ID="PageManager1" AutoSizePanelID="SimpleForm1" runat="server" />
- <ext:SimpleForm ID="SimpleForm1" runat="server" LabelWidth="100px" BodyPadding="5px"
- EnableBackgroundColor="true" ShowBorder="false" Title="系统设置">
- <Items>
- <ext:TextBox ID="tbxTitle" runat="server" Label="网站标题" Required="true" ShowRedStar="true">
- </ext:TextBox>
- <ext:NumberBox ID="nbxPageSize" runat="server" Label="表格显示项数" Required="true" ShowRedStar="true">
- </ext:NumberBox>
- <ext:DropDownList ID="ddlMenuType" Label="菜单样式" runat="server" Required="true" ShowRedStar="true">
- <ext:ListItem Text="手风琴式" Value="accordion" />
- <ext:ListItem Text="树型菜单" Value="tree" />
- </ext:DropDownList>
- <ext:Button ID="btnSave" runat="server" ValidateForms="SimpleForm1" Text="保存设置" OnClick="btnSave_OnClick">
- </ext:Button>
- </Items>
- </ext:SimpleForm>
</>code
- public partial class config : PageBase
- {
- private static readonly log4net.ILog logger = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
- #region Page_Load
- protected void Page_Load(object sender, EventArgs e)
- {
- if (!IsPostBack)
- {
- LoadData();
- }
- }
- private void LoadData()
- {
- tbxTitle.Text = XConfigHelper.Title;
- nbxPageSize.Text = XConfigHelper.PageSize.ToString();
- ddlMenuType.SelectedValue = XConfigHelper.MenuType.ToLower();
- }
- #endregion
- #region Events
- protected void btnSave_OnClick(object sender, EventArgs e)
- {
- XConfigHelper.Title = tbxTitle.Text.Trim();
- XConfigHelper.PageSize = Convert.ToInt32(nbxPageSize.Text.Trim());
- XConfigHelper.MenuType = ddlMenuType.SelectedValue.ToLower();
- XConfigHelper.SaveAll();
- // 刷新父页面
- ExtAspNet.PageContext.RegisterStartupScript("parent.window.location.href=parent.window.location.href;");
- }
- #endregion
- }
如对本文有疑问,请提交到交流论坛,广大热心网友会为你解答!! 点击进入论坛