/Las/Las.WinUI/Utility.cs
http://sgsoft-las.googlecode.com/ · C# · 193 lines · 149 code · 31 blank · 13 comment · 23 complexity · fea6f284bbbc04756d9b2f5fd84ca5ab MD5 · raw file
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.Windows.Forms;
- using Common.Logging;
-
- namespace Las.WinUI
- {
- public class Utility
- {
- public const int KEY_LEVEL_DEFINE_ALL = 99;
- static readonly ILog log = LogManager.GetCurrentClassLogger();
-
- static readonly Dictionary<int, string> _YearDic;
-
- public static Dictionary<int, string> YearDic
- {
- get { return Utility._YearDic; }
- }
-
- static readonly Dictionary<int, string> _DwLevelDefineDic;
-
- public static Dictionary<int, string> DwLevelDefineDic
- {
- get { return Utility._DwLevelDefineDic; }
- }
-
- static readonly Dictionary<int, string> _RyLevelDefineDic;
-
- public static Dictionary<int, string> RyLevelDefineDic
- {
- get { return Utility._RyLevelDefineDic; }
- }
-
- /// <summary>
- /// ???????=1,??=2????;????????????
- /// </summary>
- static readonly Dictionary<int, string> _EntityTypeDefineDic;
-
- public static Dictionary<int, string> EntityTypeDefineDic
- {
- get { return Utility._EntityTypeDefineDic; }
- }
-
-
-
- static Utility()
- {
- #region ???????????3????????7??
- int yearCount = 7;
- string yearCountStr = System.Configuration.ConfigurationManager.AppSettings["COMBOX_YEAR_COUNT"];
- if (!String.IsNullOrEmpty(yearCountStr))
- {
- if (!Int32.TryParse(yearCountStr, out yearCount))
- {
- yearCount = 7;
- }
- if (yearCount > 20) yearCount = 7;
- }
-
- _YearDic = new Dictionary<int, string>(yearCount);
- int minYear = DateTime.Today.Year - (yearCount / 2);
- for (int i = 0; i < yearCount; i++)
- {
- _YearDic.Add(minYear + i, (minYear + i).ToString());
- }
- #endregion
-
- #region ????????
- _DwLevelDefineDic = new Dictionary<int, string>();
- string dwLevelDefineDicStr = System.Configuration.ConfigurationManager.AppSettings["DW_LEVEL_DEFINE_DIC"];
- if (!String.IsNullOrEmpty(dwLevelDefineDicStr))
- {
- string[] strArray = dwLevelDefineDicStr.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
- if (strArray == null || (strArray.Length % 2) != 0)
- {
- log.ErrorFormat("??????.??????DW_LEVEL_DEFINE_DIC={0}", dwLevelDefineDicStr);
- }
- else
- {
- int key = 0;
- for (int i = 0; i < strArray.Length/2; i++)
- {
- if (Int32.TryParse(strArray[2*i], out key))
- {
- _DwLevelDefineDic.Add(key, strArray[2 * i + 1]);
- }
- else
- {
- _DwLevelDefineDic.Clear();
- log.ErrorFormat("??????.??????DW_LEVEL_DEFINE_DIC={0}", dwLevelDefineDicStr);
- break;
- }
- }
- }
- }
-
- if(_DwLevelDefineDic.Count==0)
- {
- if (log.IsInfoEnabled) log.Info("??????????????:0??1???2 ??");
- _DwLevelDefineDic.Add(0,"?");
- _DwLevelDefineDic.Add(1,"??");
- _DwLevelDefineDic.Add(2,"??");
- }
-
-
- #endregion
-
- #region ????????
- _RyLevelDefineDic = new Dictionary<int, string>();
- string ryLevelDefineDicStr = System.Configuration.ConfigurationManager.AppSettings["RY_LEVEL_DEFINE_DIC"];
- if (!String.IsNullOrEmpty(ryLevelDefineDicStr))
- {
- string[] strArray = ryLevelDefineDicStr.Split(new char[] {','},StringSplitOptions.RemoveEmptyEntries);
- if (strArray == null || (strArray.Length % 2) != 0)
- {
- log.ErrorFormat("??????.??????RY_LEVEL_DEFINE_DIC={0}", ryLevelDefineDicStr);
- }
- else
- {
- int key = 0;
- for (int i = 0; i < strArray.Length/2; i++)
- {
- if (Int32.TryParse(strArray[2*i], out key))
- {
- _RyLevelDefineDic.Add(key,strArray[2*i+1]);
- }
- else
- {
- _RyLevelDefineDic.Clear();
- log.ErrorFormat("??????.??????RY_LEVEL_DEFINE_DIC={0}", ryLevelDefineDicStr);
- break;
- }
- }
- }
- }
-
- if (_RyLevelDefineDic.Count == 0)
- {
-
- if (log.IsInfoEnabled) log.Info("??????????????:0??1????2???3??");
- _RyLevelDefineDic.Add(0, "?");
- _RyLevelDefineDic.Add(1, "???");
- _RyLevelDefineDic.Add(2, "??");
- _RyLevelDefineDic.Add(3, "??");
- }
-
- #endregion
-
- #region ????
- _EntityTypeDefineDic = new Dictionary<int, string>(2);
- _EntityTypeDefineDic.Add(KEY_LEVEL_DEFINE_ALL, "??");
- _EntityTypeDefineDic.Add(1, "??");
- _EntityTypeDefineDic.Add(2, "??");
- #endregion
-
-
- }
-
- /// <summary>
- /// ????Dictionary??????????
- /// </summary>
- /// <param name="srcDic"></param>
- /// <returns></returns>
- public static Dictionary<int, string> CloneLevelDictionaryWithKeyAll(Dictionary<int, string> src)
- {
- Dictionary<int, string> t = new Dictionary<int, string>(src.Count + 1);
- foreach (int i in src.Keys)
- {
- t.Add(i, src[i]);
- }
- t.Add(KEY_LEVEL_DEFINE_ALL, "??");
- return t;
- }
-
-
- /// <summary>
- /// ??Combox???Dictionary???
- /// </summary>
- /// <param name="cb"></param>
- /// <param name="dic"></param>
- public static void BindCombox2Dictionary(ComboBox cb, System.Collections.IDictionary dic)
- {
- cb.DataSource = new BindingSource(dic, null);
- cb.DisplayMember = "Value";
- cb.ValueMember = "Key";
- }
-
-
-
-
- }
- }