Ejemplo n.º 1
0
        private void OnChangedSet(object sender, MouseButtonEventArgs e)
        {
            if (Changed == null || !IsLoaded || _dict == null)
            {
                return;
            }

            var fe = sender as FrameworkElement;

            if (fe == null)
            {
                return;
            }

            var set = fe.DataContext as TSetView;

            tbSelectSet.DataContext = set;

            if (set == null || (set.Set == null && string.IsNullOrEmpty(set.ProtoSerializetSelected)))
            {
                cbIsGlobalSet.IsChecked = cbIsReadOnly.IsChecked = cbIsReadOnly.IsEnabled = false;
                if (set != null)
                {
                    set.IsSelected = true;
                }
                Changed(null, 3);
            }
            else
            {
                set.IsSelected          = true;
                cbIsGlobalSet.IsEnabled = bDelete.IsEnabled = bSave.IsEnabled = !set.IsReadOnly;

                var newName = set.SetName;
                //if (string.IsNullOrEmpty(newName)) return;

                set.IsSelected = true;

                if (set.IsUseGlobalTable)
                {
                    Manager.UI.RunAsync(
                        arg => ARM_Service.EXPL_Get_GlobalSet(Manager.User.User_ID, newName,
                                                              EnumGlobalSetModuleType.HierarchyTree),
                        globalSet =>
                    {
                        if (globalSet == null)
                        {
                            return;
                        }

                        if (globalSet.VersionNumber < 3)
                        {
                            List <string> existSet;
                            if (!string.IsNullOrEmpty(globalSet.List))
                            {
                                existSet = globalSet.UseProtoSerializer.GetValueOrDefault()
                                        ? globalSet.List.ProtoDeserializeFromString <List <string> >()
                                        : globalSet.List.DeserializeFromString <List <string> >();
                            }
                            else
                            {
                                existSet = new List <string>();
                            }

                            cbIsReadOnly.IsChecked = set.IsReadOnly = globalSet.IsReadOnly;
                            set.Set = new HashSet <string>(existSet);
                            Changed(set.Set, set.VersionNumber);
                        }
                        else
                        {
                            Changed(globalSet.List, set.VersionNumber);
                        }

                        cbIsGlobalSet.IsChecked = set.IsGlobalSet;

                        cbIsReadOnly.IsEnabled =
                            set.IsGlobalSet && string.Equals(globalSet.User_ID, Manager.User.User_ID);
                    });
                }
                else
                {
                    if (set.VersionNumber < 3)
                    {
                        Changed(set.Set, set.VersionNumber);
                    }
                    else
                    {
                        Changed(set.ProtoSerializetSelected, set.VersionNumber);
                    }

                    cbIsGlobalSet.IsChecked = false;
                }
            }

            Manager.UI.CloseAllPopups(popup);
            _isPopupOpen = false;
        }