123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.Drawing;
- using System.Collections;
- using SysSecLibs;
- namespace SysBaseLibs
- {
- public class AppConfig
- {
- public AppConfig(string pcConfigFilePath)
- {
- _ConfigFile = pcConfigFilePath;
- }
- private void LoadSetting()
- {
- string text1 = FileFuns.ReadFileAsString(FileName);
- if (text1 != "")
- {
- _Settings = rsXmlNode.ParseGenericXml(text1);
- }
- }
- public bool ReadBool(string pcConfigId)
- {
- return UtilStr.StrToBool(ReadString(pcConfigId));
- }
- public int ReadInt(string pcConfigId)
- {
- return Utils.ValI(ReadString(pcConfigId));
- }
- public decimal ReadDouble(string pcConfigId)
- {
- return Utils.ValD(ReadString(pcConfigId));
- }
- public string ReadString(string pcConfigId)
- {
- return Settings.GetChildValue(pcConfigId);
- }
- public rsXmlNode ReadNode(string pcConfigID)
- {
- return Settings.GetChildNode(pcConfigID);
- }
- public string ReadString(string pcConfigId, string DefaultValue)
- {
- string lcStr = Settings.GetChildValue(pcConfigId);
- if (string.IsNullOrEmpty(lcStr))
- {
- lcStr = DefaultValue;
- }
- return lcStr;
- }
- public void SaveSetting()
- {
- FileFuns.WriteStringToFile(Settings.ToAllXmlString(), FileName);
- }
- public void SetString(string pcConfigId, string pcValue)
- {
- string text1 = UtilStr.UAndT(pcConfigId);
- Settings.SetChildValue(pcConfigId, pcValue);
- SaveSetting();
- }
- //读取指定文件的配置信息,保存到当前的配置文件中
- public void ResetSetting(string pcString)
- {
- if (pcString != "")
- {
- _Settings = rsXmlNode.ParseGenericXml(pcString);
- }
- else
- {
- LoadSetting();
- }
- SaveSetting();
- }
- //重新装载配置信息
- public void RelandConfig(string pcPath)
- {
- LoadSetting();
- }
- #region Properties
- private string FileName
- {
- get
- {
- if (_ConfigFile == "")
- {
- _ConfigFile = Security.AppEnv.ConfigFile;
- }
- return _ConfigFile;
- }
- }
- string _ConfigFile = Security.AppEnv.ConfigFile;
- public rsXmlNode Settings
- {
- get
- {
- if (_Settings == null)
- {
- LoadSetting();
- }
- return _Settings;
- }
- }
- #endregion
- #region Fields
- private rsXmlNode _Settings;
- #endregion
- public static AppConfig DefConfig
- {
- get
- {
- return new AppConfig("");
- }
- }
- }
- }
|