private void OnOkPressed(string name) { var isReadOnly = cbIsReadOnly.IsChecked.GetValueOrDefault(); short versionNumber = 0; var list = new HashSet <string>(); if (OnSave != null) { versionNumber = OnSave(list); } var isGlobalSet = cbIsGlobalSet.IsChecked.GetValueOrDefault(); string protoSerializetSelected = null; if (OnSaveNew != null) { protoSerializetSelected = OnSaveNew(null); versionNumber = 3; } else { protoSerializetSelected = list.ProtoSerializeToString(); } var newGlobalSet = new Expl_User_Global_Set { User_ID = Manager.User.User_ID, StringName = name, List = protoSerializetSelected, IsGlobal = isGlobalSet, IsReadOnly = isReadOnly, ModuleNameForUse = _moduleNameForUse, VersionNumber = versionNumber, UseProtoSerializer = true, }; try { var userGlobalSetsId = ARM_Service.EXPL_Save_GlobalSet(newGlobalSet); if (userGlobalSetsId == default(Guid)) //Ошибка WCF { ShowMessage("Набор не удалось сохранить"); return; } var set = new TSetView(name, isReadOnly, userGlobalSetsId, list, true, Manager.User.User_ID, versionNumber, true, isGlobalSet, protoSerializetSelected: protoSerializetSelected); lock (_dictSyncLock) { _dict.Add(set); } tbSelectSet.DataContext = set; cbIsReadOnly.IsEnabled = set.IsGlobalSet && string.Equals(newGlobalSet.User_ID, Manager.User.User_ID); } catch (Exception ex) { ShowMessage("Набор не сохранен!\n" + ex.Message); return; } }
/// <summary> /// Старая версия инициализации, надо уходить от нее /// </summary> /// <param name="dict"></param> /// <param name="globalSets"></param> public void Init(Dictionary <string, List <string> > dict, List <Expl_User_Global_Set> globalSets = null) { lock (_dictSyncLock) { _dict.Clear(); var set = new TSetView(_voidSetName, true, isSelected: true); _dict.Add(set); tbSelectSet.DataContext = set; } if (dict != null) { lock (_dictSyncLock) { var t = dict.Select(d => new TSetView(d.Key, false, null, d.Value == null || d.Value.Count == 0 ? new List <string>() : d.Value)).ToList(); foreach (var d in t) { _dict.Add(d); } } } if (globalSets != null && globalSets.Count > 0) { foreach (var explUserGlobalSet in globalSets .OrderByDescending(g => g.IsGlobal) .ThenBy(g => g.User_ID) .ThenBy(g => g.StringName)) { //if (explUserGlobalSet.List == null) continue; List <string> existSet = null; if (!string.IsNullOrEmpty(explUserGlobalSet.List)) { existSet = explUserGlobalSet.UseProtoSerializer.GetValueOrDefault() ? explUserGlobalSet.List.ProtoDeserializeFromString <List <string> >() : explUserGlobalSet.List.DeserializeFromString <List <string> >(); } if (existSet == null) { existSet = new List <string>(); } var d = _dict.FirstOrDefault(s => string.Equals(s.SetName, explUserGlobalSet.StringName, StringComparison.OrdinalIgnoreCase)); if (d == null || d.Set == null) { d = new TSetView(explUserGlobalSet.StringName, explUserGlobalSet.IsReadOnly, explUserGlobalSet.UserGlobalSet_ID, existSet, true, explUserGlobalSet.User_ID, explUserGlobalSet.VersionNumber); lock (_dictSyncLock) { _dict.Add(d); } d.Dict = dict; } else { //Переводим наборы в отдельную таблицу Expl_User_Global_Sets if (dict != null) { dict.Remove(explUserGlobalSet.StringName); } d.Set.UnionWith(existSet); //SaveSet(explUserGlobalSet.StringName, false); //Сохраняем в отдельной таблице } d.IsGlobalSet = explUserGlobalSet.IsGlobal; d.IsUseGlobalTable = true; } } }
/// <summary> /// Новая версия инициализации из таблицы Expl_User_Global_Set /// </summary> /// <param name="globalSets"></param> private void InitGlobal(Dictionary <string, List <string> > dict, List <Expl_User_Global_Set> globalSets) { lock (_dictSyncLock) { _dict.Clear(); var set = new TSetView(_voidSetName, true, isSelected: true); _dict.Add(set); tbSelectSet.DataContext = set; } if (globalSets == null || globalSets.Count == 0) { return; } foreach (var explUserGlobalSet in globalSets .OrderBy(g => g.IsGlobal) .ThenBy(g => g.User_ID) .ThenBy(g => g.StringName)) { List <string> existSet = null; string protoSerializetSelected = null; try { if (explUserGlobalSet.VersionNumber < 3) { if (!string.IsNullOrEmpty(explUserGlobalSet.List)) { existSet = explUserGlobalSet.UseProtoSerializer.GetValueOrDefault() ? explUserGlobalSet.List.ProtoDeserializeFromString <List <string> >() : explUserGlobalSet.List.DeserializeFromString <List <string> >(); } if (existSet == null) { existSet = new List <string>(); } } else { protoSerializetSelected = explUserGlobalSet.List; } } catch { } //Считаем что все наборы перевели в глобальную таблицу var d = new TSetView(explUserGlobalSet.StringName, explUserGlobalSet.IsReadOnly, explUserGlobalSet.UserGlobalSet_ID, existSet, true, explUserGlobalSet.User_ID, explUserGlobalSet.VersionNumber, isGlobal: explUserGlobalSet.IsGlobal, protoSerializetSelected: protoSerializetSelected); lock (_dictSyncLock) { _dict.Add(d); } } if (dict != null) { lock (_dictSyncLock) { //var t = dict.Select(d => ).ToList(); foreach (var d in dict) { if (d.Value == null || _dict.Any(s => string.Equals(s.SetName, d.Key))) { continue; } var set = new TSetView(d.Key, false, null, d.Value == null || d.Value.Count == 0 ? new List <string>() : d.Value, false, versionNumber: 0); set.Dict = dict; _dict.Add(set); } } } }