FineUI 官方论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

本论坛已关闭(禁止注册、发帖和回复)
请移步 三石和他的朋友们

FineUI首页 WebForms - MVC & Core - JavaScript 常见问题 - QQ群 - 十周年征文活动

FineUI(开源版) 下载源代码 - 下载空项目 - 获取ExtJS - 文档 在线示例 - 版本更新 - 捐赠作者 - 教程

升级到 ASP.NET Core 3.1,快、快、快! 全新ASP.NET Core,比WebForms还简单! 欢迎加入【三石和他的朋友们】(基础版下载)

搜索
查看: 2483|回复: 2
打印 上一主题 下一主题

请教个低级问题,各位大侠帮帮忙,学习中。

[复制链接]
跳转到指定楼层
楼主
发表于 2013-5-10 15:41:05 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
  1. #region fields & constructor

  2. /// <summary>
  3. /// 缓存在内存
  4. /// </summary>
  5. private static XConfigCollection configs = new XConfigCollection();

  6. /// <summary>
  7. /// 载入所有的配置项
  8. /// </summary>
  9. static XConfigHelper()
  10. {
  11. ReloadColl();
  12. }

  13. /// <summary>
  14. /// 重新加载所有的配置项
  15. /// </summary>
  16. public static void ReloadColl()
  17. {
  18. configs = new Select().From<XConfig>()
  19. .ExecuteAsCollection<XConfigCollection>();
  20. }
  21. #endregion

  22. #region methods
  23. /// <summary>
  24. /// 获取配置信息
  25. /// </summary>
  26. /// <param name="key"></param>
  27. /// <returns></returns>
  28. public static string GetValue(string key)
  29. {
  30. foreach (XConfig config in configs)
  31. {
  32. if (config.ConfigKey == key)
  33. {
  34. return config.ConfigValue;
  35. }
  36. }

  37. return String.Empty;
  38. }

  39. /// <summary>
  40. /// 设置值
  41. /// </summary>
  42. /// <param name="key"></param>
  43. /// <param name="value"></param>
  44. public static void SetValue(string key, string value)
  45. {
  46. foreach (XConfig config in configs)
  47. {
  48. if (config.ConfigKey == key)
  49. {
  50. config.ConfigValue = value;
  51. }
  52. }
  53. }

  54. /// <summary>
  55. /// 保存所有更改的配置项
  56. /// </summary>
  57. public static void SaveAll()
  58. {
  59. configs.SaveAll();
  60. }
  61. #endregion

  62. #region properties

  63. /// <summary>
  64. /// 网站标题
  65. /// </summary>
  66. public static string Title
  67. {
  68. get
  69. {
  70. return GetValue("Title");
  71. }
  72. set
  73. {
  74. SetValue("Title", value);
  75. }
  76. }
复制代码

请问,这段代码改成EF的如何改?
沙发
发表于 2013-6-12 09:48:53 | 只看该作者
目前我的改法,供參考。
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using a.Entities;

  6. namespace a
  7. {
  8.     public class SysconfigHelper
  9.     {
  10.         private static List<XConfig> configs = new List<XConfig>();
  11.         

  12.         static SysconfigHelper()
  13.         {
  14.             ReloadSysconfig();
  15.         }

  16.         public static void ReloadSysconfig()
  17.         {
  18.             BSEntities _dbbs = new BSEntities();

  19.             configs = _dbbs.XConfig.ToList();
  20.         }

  21.         public static string GetValue(string key)
  22.         {
  23.             foreach (XConfig config in configs)
  24.             {
  25.                 if (config.ConfigKey == key)
  26.                 {
  27.                     return config.ConfigValue;
  28.                 }
  29.             }
  30.             return String.Empty;
  31.         }

  32.         public static void SetValue(String key, string value)
  33.         {
  34.             foreach (XConfig config in configs)
  35.             {
  36.                 if (config.ConfigKey == key)
  37.                 {
  38.                     config.ConfigValue = value;
  39.                 }
  40.             }
  41.         }

  42.         public static void SaveAll()
  43.         {
  44.             BSEntities _dbbs = new BSEntities();

  45.             List<XConfig> dbconfigs = _dbbs.XConfig.ToList();

  46.             foreach (XConfig config in configs)
  47.             {
  48.                 foreach (XConfig c in dbconfigs)
  49.                 {
  50.                     if (c.ConfigKey == config.ConfigKey)
  51.                     {
  52.                         c.ConfigValue = config.ConfigValue;
  53.                     }
  54.                 }
  55.             }
  56.             _dbbs.SaveChanges();
  57.         }

  58.         public static string Title
  59.         {
  60.             get
  61.             {
  62.                 return GetValue("Title");
  63.             }
  64.             set
  65.             {
  66.                 SetValue("Title", value);
  67.             }
  68.         }

  69.         public static int PageSize
  70.         {
  71.             get
  72.             {
  73.                 return Convert.ToInt32(GetValue("PageSize"));
  74.             }
  75.             set
  76.             {
  77.                 SetValue("PageSize", value.ToString());
  78.             }
  79.         }

  80.         public static string MenuType
  81.         {
  82.             get
  83.             {
  84.                 return GetValue("MenuType");
  85.             }
  86.             set
  87.             {
  88.                 SetValue("MenuType", value);
  89.             }
  90.         }

  91.         public static string Theme
  92.         {
  93.             get
  94.             {
  95.                 return GetValue("Theme");
  96.             }
  97.             set
  98.             {
  99.                 SetValue("Theme", value);
  100.             }
  101.         }
  102.     }
  103. }
复制代码
板凳
 楼主| 发表于 2013-6-17 11:02:20 | 只看该作者
虽然之前我已经改完,但是还是万分感谢。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|FineUI 官方论坛 ( 皖ICP备2021006167号-1 )

GMT+8, 2024-5-19 06:40 , Processed in 0.043623 second(s), 17 queries , Gzip On.

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表