ConfigAppSettings.cs
1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
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);
}
}
}