您现在的位置: 365建站网 > 365文章 > ExtAspNet应用技巧(十四) - 系统设置

ExtAspNet应用技巧(十四) - 系统设置

文章来源:365jz.com     点击数:450    更新时间:2009-09-17 10:27   参与评论

界面截图



数据库表(X_Config)


设计视图: 


数据: 



帮助类

因为此配置信息为全局共享,所以我们用一个帮助类在整个应用程序生命周期只加载一次:

</>code

  1. namespace AppBox
  2. {
  3. public class XConfigHelper
  4. {
  5. #region fields & constructor
  6. /// <summary>
  7. /// 缓存在内存
  8. /// </summary>
  9. private static XConfigCollection configs = new XConfigCollection();
  10. /// <summary>
  11. /// 载入所有的配置项
  12. /// </summary>
  13. static XConfigHelper()
  14. {
  15. ReloadColl();
  16. }
  17. /// <summary>
  18. /// 重新加载所有的配置项
  19. /// </summary>
  20. public static void ReloadColl()
  21. {
  22. configs = new Select().From<XConfig>()
  23. .ExecuteAsCollection<XConfigCollection>();
  24. }
  25. #endregion
  26. #region methods
  27. /// <summary>
  28. /// 获取配置信息
  29. /// </summary>
  30. /// <param name="key"></param>
  31. /// <returns></returns>
  32. public static string GetValue(string key)
  33. {
  34. foreach (XConfig config in configs)
  35. {
  36. if (config.ConfigKey == key)
  37. {
  38. return config.ConfigValue;
  39. }
  40. }
  41. return String.Empty;
  42. }
  43. /// <summary>
  44. /// 设置值
  45. /// </summary>
  46. /// <param name="key"></param>
  47. /// <param name="value"></param>
  48. public static void SetValue(string key, string value)
  49. {
  50. foreach (XConfig config in configs)
  51. {
  52. if (config.ConfigKey == key)
  53. {
  54. config.ConfigValue = value;
  55. }
  56. }
  57. }
  58. /// <summary>
  59. /// 保存所有更改的配置项
  60. /// </summary>
  61. public static void SaveAll()
  62. {
  63. configs.SaveAll();
  64. }
  65. #endregion
  66. #region properties
  67. /// <summary>
  68. /// 网站标题
  69. /// </summary>
  70. public static string Title
  71. {
  72. get
  73. {
  74. return GetValue("Title");
  75. }
  76. set
  77. {
  78. SetValue("Title", value);
  79. }
  80. }
  81. /// <summary>
  82. /// 列表每页显示的个数
  83. /// </summary>
  84. public static int PageSize
  85. {
  86. get
  87. {
  88. return Convert.ToInt32(GetValue("PageSize"));
  89. }
  90. set
  91. {
  92. SetValue("PageSize", value.ToString());
  93. }
  94. }
  95. /// <summary>
  96. /// 菜单样式(手风琴式,树型菜单)
  97. /// </summary>
  98. public static string MenuType
  99. {
  100. get
  101. {
  102. return GetValue("MenuType");
  103. }
  104. set
  105. {
  106. SetValue("MenuType", value);
  107. }
  108. }
  109. #endregion
  110. }
  111. }


ASPX标签

</>code

  1. <ext:PageManager ID="PageManager1" AutoSizePanelID="SimpleForm1" runat="server" />
  2. <ext:SimpleForm ID="SimpleForm1" runat="server" LabelWidth="100px" BodyPadding="5px"
  3. EnableBackgroundColor="true" ShowBorder="false" Title="系统设置">
  4. <Items>
  5. <ext:TextBox ID="tbxTitle" runat="server" Label="网站标题" Required="true" ShowRedStar="true">
  6. </ext:TextBox>
  7. <ext:NumberBox ID="nbxPageSize" runat="server" Label="表格显示项数" Required="true" ShowRedStar="true">
  8. </ext:NumberBox>
  9. <ext:DropDownList ID="ddlMenuType" Label="菜单样式" runat="server" Required="true" ShowRedStar="true">
  10. <ext:ListItem Text="手风琴式" Value="accordion" />
  11. <ext:ListItem Text="树型菜单" Value="tree" />
  12. </ext:DropDownList>
  13. <ext:Button ID="btnSave" runat="server" ValidateForms="SimpleForm1" Text="保存设置" OnClick="btnSave_OnClick">
  14. </ext:Button>
  15. </Items>
  16. </ext:SimpleForm>


这里面有一些需要注意的属性:
  • PageManager的属性AutoSizePanelID="SimpleForm1",指定SimpleForm1充满整个页面
  • SimpleForm1的属性ShowBorder="false",去掉蓝色的边框(因为这个SimpleForm是以IFrame的形式嵌入另一个页面的)
  • SimpleForm1的属性EnableBackgroundColor="true",蓝色的背景色
  • tbxTitle的属性Required="true"和ShowRedStar="true",指定必填项和红色的标记
  • btnSave的属性ValidateForms="SimpleForm1",点击此按钮需要验证的表单(可以指定多个表单,以逗号分隔)



后台代码

</>code

  1. public partial class config : PageBase
  2. {
  3. private static readonly log4net.ILog logger = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
  4. #region Page_Load
  5. protected void Page_Load(object sender, EventArgs e)
  6. {
  7. if (!IsPostBack)
  8. {
  9. LoadData();
  10. }
  11. }
  12. private void LoadData()
  13. {
  14. tbxTitle.Text = XConfigHelper.Title;
  15. nbxPageSize.Text = XConfigHelper.PageSize.ToString();
  16. ddlMenuType.SelectedValue = XConfigHelper.MenuType.ToLower();
  17. }
  18. #endregion
  19. #region Events
  20. protected void btnSave_OnClick(object sender, EventArgs e)
  21. {
  22. XConfigHelper.Title = tbxTitle.Text.Trim();
  23. XConfigHelper.PageSize = Convert.ToInt32(nbxPageSize.Text.Trim());
  24. XConfigHelper.MenuType = ddlMenuType.SelectedValue.ToLower();
  25. XConfigHelper.SaveAll();
  26. // 刷新父页面
  27. ExtAspNet.PageContext.RegisterStartupScript("parent.window.location.href=parent.window.location.href;");
  28. }
  29. #endregion
  30. }


注意:在保存属性之后,我们需要刷新父页面来应用更改。ExtAspNet.PageContext.RegisterStartupScript用来向页面注册一段脚本,这是一个常用的函数。


下一章,我们会根据这里设置的菜单类型(树形菜单或者手风琴式菜单),来在左侧的区域内动态创建菜单。




下载全部源代码


如对本文有疑问,请提交到交流论坛,广大热心网友会为你解答!! 点击进入论坛

发表评论 (450人查看0条评论)
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
昵称:
最新评论
------分隔线----------------------------

快速入口

· 365软件
· 杰创官网
· 建站工具
· 网站大全

其它栏目

· 建站教程
· 365学习

业务咨询

· 技术支持
· 服务时间:9:00-18:00
365建站网二维码

Powered by 365建站网 RSS地图 HTML地图

copyright © 2013-2024 版权所有 鄂ICP备17013400号