AppConfig.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Drawing;
  5. using System.Collections;
  6. using SysSecLibs;
  7. namespace SysBaseLibs
  8. {
  9. public class AppConfig
  10. {
  11. public AppConfig(string pcConfigFilePath)
  12. {
  13. _ConfigFile = pcConfigFilePath;
  14. }
  15. private void LoadSetting()
  16. {
  17. string text1 = FileFuns.ReadFileAsString(FileName);
  18. if (text1 != "")
  19. {
  20. _Settings = rsXmlNode.ParseGenericXml(text1);
  21. }
  22. }
  23. public bool ReadBool(string pcConfigId)
  24. {
  25. return UtilStr.StrToBool(ReadString(pcConfigId));
  26. }
  27. public int ReadInt(string pcConfigId)
  28. {
  29. return Utils.ValI(ReadString(pcConfigId));
  30. }
  31. public decimal ReadDouble(string pcConfigId)
  32. {
  33. return Utils.ValD(ReadString(pcConfigId));
  34. }
  35. public string ReadString(string pcConfigId)
  36. {
  37. return Settings.GetChildValue(pcConfigId);
  38. }
  39. public rsXmlNode ReadNode(string pcConfigID)
  40. {
  41. return Settings.GetChildNode(pcConfigID);
  42. }
  43. public string ReadString(string pcConfigId, string DefaultValue)
  44. {
  45. string lcStr = Settings.GetChildValue(pcConfigId);
  46. if (string.IsNullOrEmpty(lcStr))
  47. {
  48. lcStr = DefaultValue;
  49. }
  50. return lcStr;
  51. }
  52. public void SaveSetting()
  53. {
  54. FileFuns.WriteStringToFile(Settings.ToAllXmlString(), FileName);
  55. }
  56. public void SetString(string pcConfigId, string pcValue)
  57. {
  58. string text1 = UtilStr.UAndT(pcConfigId);
  59. Settings.SetChildValue(pcConfigId, pcValue);
  60. SaveSetting();
  61. }
  62. //读取指定文件的配置信息,保存到当前的配置文件中
  63. public void ResetSetting(string pcString)
  64. {
  65. if (pcString != "")
  66. {
  67. _Settings = rsXmlNode.ParseGenericXml(pcString);
  68. }
  69. else
  70. {
  71. LoadSetting();
  72. }
  73. SaveSetting();
  74. }
  75. //重新装载配置信息
  76. public void RelandConfig(string pcPath)
  77. {
  78. LoadSetting();
  79. }
  80. #region Properties
  81. private string FileName
  82. {
  83. get
  84. {
  85. if (_ConfigFile == "")
  86. {
  87. _ConfigFile = Security.AppEnv.ConfigFile;
  88. }
  89. return _ConfigFile;
  90. }
  91. }
  92. string _ConfigFile = Security.AppEnv.ConfigFile;
  93. public rsXmlNode Settings
  94. {
  95. get
  96. {
  97. if (_Settings == null)
  98. {
  99. LoadSetting();
  100. }
  101. return _Settings;
  102. }
  103. }
  104. #endregion
  105. #region Fields
  106. private rsXmlNode _Settings;
  107. #endregion
  108. public static AppConfig DefConfig
  109. {
  110. get
  111. {
  112. return new AppConfig("");
  113. }
  114. }
  115. }
  116. }