/Las/Las.WinUI/Utility.cs
C# | 193 lines | 149 code | 31 blank | 13 comment | 23 complexity | fea6f284bbbc04756d9b2f5fd84ca5ab MD5 | raw file
Possible License(s): LGPL-2.1
1using System; 2using System.Collections.Generic; 3using System.Text; 4using System.Windows.Forms; 5using Common.Logging; 6 7namespace Las.WinUI 8{ 9 public class Utility 10 { 11 public const int KEY_LEVEL_DEFINE_ALL = 99; 12 static readonly ILog log = LogManager.GetCurrentClassLogger(); 13 14 static readonly Dictionary<int, string> _YearDic; 15 16 public static Dictionary<int, string> YearDic 17 { 18 get { return Utility._YearDic; } 19 } 20 21 static readonly Dictionary<int, string> _DwLevelDefineDic; 22 23 public static Dictionary<int, string> DwLevelDefineDic 24 { 25 get { return Utility._DwLevelDefineDic; } 26 } 27 28 static readonly Dictionary<int, string> _RyLevelDefineDic; 29 30 public static Dictionary<int, string> RyLevelDefineDic 31 { 32 get { return Utility._RyLevelDefineDic; } 33 } 34 35 /// <summary> 36 /// ???????=1,??=2????;???????????? 37 /// </summary> 38 static readonly Dictionary<int, string> _EntityTypeDefineDic; 39 40 public static Dictionary<int, string> EntityTypeDefineDic 41 { 42 get { return Utility._EntityTypeDefineDic; } 43 } 44 45 46 47 static Utility() 48 { 49 #region ???????????3????????7?? 50 int yearCount = 7; 51 string yearCountStr = System.Configuration.ConfigurationManager.AppSettings["COMBOX_YEAR_COUNT"]; 52 if (!String.IsNullOrEmpty(yearCountStr)) 53 { 54 if (!Int32.TryParse(yearCountStr, out yearCount)) 55 { 56 yearCount = 7; 57 } 58 if (yearCount > 20) yearCount = 7; 59 } 60 61 _YearDic = new Dictionary<int, string>(yearCount); 62 int minYear = DateTime.Today.Year - (yearCount / 2); 63 for (int i = 0; i < yearCount; i++) 64 { 65 _YearDic.Add(minYear + i, (minYear + i).ToString()); 66 } 67 #endregion 68 69 #region ???????? 70 _DwLevelDefineDic = new Dictionary<int, string>(); 71 string dwLevelDefineDicStr = System.Configuration.ConfigurationManager.AppSettings["DW_LEVEL_DEFINE_DIC"]; 72 if (!String.IsNullOrEmpty(dwLevelDefineDicStr)) 73 { 74 string[] strArray = dwLevelDefineDicStr.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); 75 if (strArray == null || (strArray.Length % 2) != 0) 76 { 77 log.ErrorFormat("??????.??????DW_LEVEL_DEFINE_DIC={0}", dwLevelDefineDicStr); 78 } 79 else 80 { 81 int key = 0; 82 for (int i = 0; i < strArray.Length/2; i++) 83 { 84 if (Int32.TryParse(strArray[2*i], out key)) 85 { 86 _DwLevelDefineDic.Add(key, strArray[2 * i + 1]); 87 } 88 else 89 { 90 _DwLevelDefineDic.Clear(); 91 log.ErrorFormat("??????.??????DW_LEVEL_DEFINE_DIC={0}", dwLevelDefineDicStr); 92 break; 93 } 94 } 95 } 96 } 97 98 if(_DwLevelDefineDic.Count==0) 99 { 100 if (log.IsInfoEnabled) log.Info("??????????????:0??1???2 ??"); 101 _DwLevelDefineDic.Add(0,"?"); 102 _DwLevelDefineDic.Add(1,"??"); 103 _DwLevelDefineDic.Add(2,"??"); 104 } 105 106 107 #endregion 108 109 #region ???????? 110 _RyLevelDefineDic = new Dictionary<int, string>(); 111 string ryLevelDefineDicStr = System.Configuration.ConfigurationManager.AppSettings["RY_LEVEL_DEFINE_DIC"]; 112 if (!String.IsNullOrEmpty(ryLevelDefineDicStr)) 113 { 114 string[] strArray = ryLevelDefineDicStr.Split(new char[] {','},StringSplitOptions.RemoveEmptyEntries); 115 if (strArray == null || (strArray.Length % 2) != 0) 116 { 117 log.ErrorFormat("??????.??????RY_LEVEL_DEFINE_DIC={0}", ryLevelDefineDicStr); 118 } 119 else 120 { 121 int key = 0; 122 for (int i = 0; i < strArray.Length/2; i++) 123 { 124 if (Int32.TryParse(strArray[2*i], out key)) 125 { 126 _RyLevelDefineDic.Add(key,strArray[2*i+1]); 127 } 128 else 129 { 130 _RyLevelDefineDic.Clear(); 131 log.ErrorFormat("??????.??????RY_LEVEL_DEFINE_DIC={0}", ryLevelDefineDicStr); 132 break; 133 } 134 } 135 } 136 } 137 138 if (_RyLevelDefineDic.Count == 0) 139 { 140 141 if (log.IsInfoEnabled) log.Info("??????????????:0??1????2???3??"); 142 _RyLevelDefineDic.Add(0, "?"); 143 _RyLevelDefineDic.Add(1, "???"); 144 _RyLevelDefineDic.Add(2, "??"); 145 _RyLevelDefineDic.Add(3, "??"); 146 } 147 148 #endregion 149 150 #region ???? 151 _EntityTypeDefineDic = new Dictionary<int, string>(2); 152 _EntityTypeDefineDic.Add(KEY_LEVEL_DEFINE_ALL, "??"); 153 _EntityTypeDefineDic.Add(1, "??"); 154 _EntityTypeDefineDic.Add(2, "??"); 155 #endregion 156 157 158 } 159 160 /// <summary> 161 /// ????Dictionary?????????? 162 /// </summary> 163 /// <param name="srcDic"></param> 164 /// <returns></returns> 165 public static Dictionary<int, string> CloneLevelDictionaryWithKeyAll(Dictionary<int, string> src) 166 { 167 Dictionary<int, string> t = new Dictionary<int, string>(src.Count + 1); 168 foreach (int i in src.Keys) 169 { 170 t.Add(i, src[i]); 171 } 172 t.Add(KEY_LEVEL_DEFINE_ALL, "??"); 173 return t; 174 } 175 176 177 /// <summary> 178 /// ??Combox???Dictionary??? 179 /// </summary> 180 /// <param name="cb"></param> 181 /// <param name="dic"></param> 182 public static void BindCombox2Dictionary(ComboBox cb, System.Collections.IDictionary dic) 183 { 184 cb.DataSource = new BindingSource(dic, null); 185 cb.DisplayMember = "Value"; 186 cb.ValueMember = "Key"; 187 } 188 189 190 191 192 } 193}