ConfigAppSettings.cs 1.8 KB
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Threading;
using System.Xml;
using System.Windows.Forms;
using log4net;
using ConfigHelper;

namespace OnlineStore.Common
{
    public class ConfigAppSettings
    {
        private static int seq = 1;
        public static int nextSeq()
        {
            if (seq.Equals(Int32.MaxValue))
            {
                LogUtil.info("seq当前值:" + seq + ",重置seq=0");
                seq = 0;
            }
            Interlocked.Increment(ref seq);
            return seq;
        }
        /// <summary>
        /// 获取配置值
        /// </summary>
        /// <param name="key">键</param>
        /// <param name="failVal">不存在键时返回的默认值</param>
        /// <returns></returns>
        public static string GetValue(string key, string failVal = "")
        {
            return Config.Get(key, failVal);
        }
        public static bool GetBoolValue(string key, bool failVal = false)
        {
            return Config.Get(key, failVal);
        }

        public static decimal GetNumValue(string key)
        {
            decimal a = 0;
            Decimal.TryParse(GetValue(key, "0"), out a);
            return a;
        }
        public static int GetIntValue(string key, int defaulVal = 0)
        {
            int a = 0;
            Int32.TryParse(GetValue(key, defaulVal.ToString()), out a);
            return a;
        }
        public static void SaveValue(string key, int value)
        {
            SaveValue(key, value.ToString());
        }
        public static void SaveValue(string key, bool value)
        {
            SaveValue(key, value.ToString());
        }
        public static void SaveValue(string key, string value)
        {
            Config.Set(key, value);
        }
    }
}