/// <summary> /// 从数据库中加载 /// </summary> /// <param name="userID"></param> /// <returns></returns> private static UserRecentDataCategory LoadFromDB(string userID, string category) { userID.CheckStringIsNullOrEmpty("userID"); category.CheckStringIsNullOrEmpty("category"); string sql = string.Format("SELECT DATA FROM USER_RECENT_DATA WHERE USER_ID = {0} AND CATEGORY = {1}", TSqlBuilder.Instance.CheckQuotationMark(userID, true), TSqlBuilder.Instance.CheckQuotationMark(category, true) ); UserRecentDataCategory result = null; string settings = (string)DbHelper.RunSqlReturnScalar(sql, ConnectionDefine.UserRelativeInfoConnectionName); if (settings.IsNotEmpty()) { XElementFormatter formatter = new XElementFormatter(); formatter.OutputShortType = false; XElement root = XElement.Parse(settings); result = (UserRecentDataCategory)formatter.Deserialize(root); } return(result); }
private static UserRecentDataCategory GetDefaultCategorySettings(string category) { category.CheckStringIsNullOrEmpty("category"); UserRecentDataCategory settings = new UserRecentDataCategory(); settings.InitFromConfiguration(UserRecentDataConfigurationSection.GetConfig().Categories[category]); return(settings); }
/// <summary> /// 从数据库获取指定类别数据 /// </summary> /// <param name="userId"></param> /// <param name="category"></param> /// <returns></returns> public static UserRecentDataCategory LoadSettings(string userId, string category) { UserRecentDataCategory settings = GetDefaultCategorySettings(category); UserRecentDataCategory settingsFromDB = LoadFromDB(userId, category); if (settingsFromDB != null) { settings.ImportValues(settingsFromDB); } return(settings); }
/// <summary> /// 导入别的UserSettings的属性值,如果类别或属性名称不存在,则忽略 /// </summary> /// <param name="srcSettings"></param> private void ImportProperties(UserRecentData srcSettings) { foreach (UserRecentDataCategory category in this.Categories) { if (srcSettings.Categories.ContainsKey(category.Name)) { UserRecentDataCategory srcCategory = srcSettings.Categories[category.Name]; if (srcCategory != null) { category.ImportValues(srcCategory); } } } }
/// <summary> /// 导入分类的数据 /// </summary> /// <param name="srcCategory"></param> /// <remarks>没有定义的或者定义不一致的被忽略,将不会清空现有数据。数据将被附加到集合的末尾</remarks> internal void ImportValues(UserRecentDataCategory srcCategory) { if (this._definedProperties != null) { foreach (PropertyValueCollection item in srcCategory.Items) { var newitem = this.Items.CreateItem(); foreach (var define in _definedProperties) { newitem[define.Name].StringValue = item[define.Name].StringValue; } this.Items.Add(newitem); } } }
public UserRecentDataCategoryItemCollection(UserRecentDataCategory owner) { this.owner = owner; }