using System.Collections; using System.Linq; using System.Web.Mvc; using Hiway.Service; namespace Hiway { public class CodeManager { private Hashtable _codeStorage; private static CodeManager _instance; private ICodeLoader codeLoader = new CodeLoader(); public SelectList CodeSelectList(string cdid) { return this.CodeSelectList(cdid, "FullCode", null); } public SelectList CodeSelectList(string cdid, object selectedValue) { return this.CodeSelectList(cdid, "FullCode", selectedValue); } public SelectList CodeSelectList(string cdid, string valueField) { return new SelectList(this.GetCodeList(cdid), valueField, "CodeName"); } public SelectList CodeSelectList(string cdid, string valueField, object selectedValue) { return new SelectList(this.GetCodeList(cdid), valueField, "CodeName", selectedValue); } public IList GetCodeList(string cdId) { IList list = this.CodeStorage[cdId] as IList; if (list == null) { list = this.codeLoader.Load(cdId).ToList(); this.CodeStorage[cdId] = list; } return list; } public static void Init(ICodeLoader loader) { if (_instance == null) { _instance = new CodeManager(); } _instance.codeLoader = loader; } public static CodeManager Instance() { if (_instance == null) { _instance = new CodeManager(); } return _instance; } private Hashtable CodeStorage { get { if (this._codeStorage == null) { this._codeStorage = new Hashtable(); } return this._codeStorage; } set { this._codeStorage = value; } } } }