config_manager.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.IO;
  7. using System.Configuration;
  8. namespace HXX.Scanner.Biz
  9. {
  10. /// <summary>
  11. /// 配置文件Settings.Default操作类
  12. /// </summary>
  13. public class config_manager
  14. {
  15. /// <summary>
  16. /// 本地配置文件
  17. /// </summary>
  18. private static ApplicationSettingsBase config { get; set; }
  19. /// <summary>
  20. /// 初始化配置文件
  21. /// </summary>
  22. /// <param name="_config"></param>
  23. public static void Init(ApplicationSettingsBase _config)
  24. {
  25. config = _config;
  26. }
  27. /// <summary>
  28. /// 获取配置信息
  29. /// </summary>
  30. /// <param name="key"></param>
  31. /// <returns></returns>
  32. public static string Get(string key)
  33. {
  34. string value = null;
  35. var item = config.Properties[key];
  36. if (item != null)
  37. {
  38. var obj = config[key];
  39. if (obj != null)
  40. {
  41. value = obj.ToString();
  42. }
  43. }
  44. return value;
  45. }
  46. /// <summary>
  47. /// 设置配置信息
  48. /// </summary>
  49. /// <param name="key"></param>
  50. /// <param name="value"></param>
  51. /// <returns></returns>
  52. public static bool Set(string key, string value)
  53. {
  54. bool result = false;
  55. var item = config.Properties[key];
  56. if (item != null)
  57. {
  58. config[key] = value;
  59. config.Save();
  60. result = true;
  61. }
  62. return result;
  63. }
  64. }
  65. }