/// <summary> /// Получить значение системной настройки, если нет то добавить /// </summary> /// <param name="context">Контекст</param> /// <param name="customerID">Ид торгового центра</param> /// <param name="name">Название настройки</param> /// <param name="settingsFormat">Формат настройки</param> /// <param name="description">Описание</param> /// <param name="type">Тип настройки</param> /// <param name="changeAction">Действие при изменении настройки</param> /// <param name="def">Значение по умолчанию</param> /// <returns>Значение настройки</returns> public static string GetOrCreateSystemSetting(this ISystemSettingsContext context, int customerID, string name, string settingsFormat, string description, SystemType type, string changeAction, string def) { var setting = context.SystemSettings.FirstOrDefault(i => i.CustomerID == customerID && i.SystemSettingType.Name == name); if (setting == null) { var st = context.SystemSettingTypes.FirstOrDefault(i => i.Name == name); if (st == null) { st = new SystemSettingType() { Name = name, Description = description, SystemType = type, Format = settingsFormat }; context.SystemSettingTypes.Add(st); } var ss = new Model.SystemSetting() { SystemSettingType = st, CustomerID = customerID, ChangeAction = changeAction, TerminalID = null }; context.SystemSettings.Add(ss); ss.History.Add(new SystemSettingHistory() { SettingValue = def, ModifiedDate = DateTime.Now }); context.SaveChanges(); return(def); } var history = setting.History.OrderByDescending(i => i.ModifiedDate).FirstOrDefault(); var value = history?.SettingValue; return(value ?? def); }
/// <summary> /// 响应系统设置的修改 /// </summary> /// <param name="_type"></param> /// <param name="_open"></param> protected void OnUpdateSystemSettings(SystemSettingType _type, bool _open, float _num) { switch (_type) { case SystemSettingType.Music: mySoundPlayer.SetCurBgmValue(_num); if (_open) { AutoPlayBGM(); } break; case SystemSettingType.SoundEffect: mySoundPlayer.SetCurSoundValue(_num); break; default: break; } }