Пример #1
0
        private void RebuildFirst(object sender, object data)
        {
            if (((LegPartViewModel)Controller.CurrentViewModel.Controller.LegViewModel).CurrentLegSide != this.CurrentLegSide)
            {
                return;
            }
            var bufSaveLegSection = new List <int?>();

            foreach (var x in LegSections)
            {
                if (x.SelectedValue != null)
                {
                    bufSaveLegSection.Add(x.SelectedValue.Id);
                }
                else
                {
                    bufSaveLegSection.Add(null);
                }
            }

            float savedValue = -1;
            int   bufSaveLegAdditionalSection = -1;

            if (AdditionalStructure.SelectedValue != null)
            {
                bufSaveLegAdditionalSection = AdditionalStructure.SelectedValue.Id;
                if (AdditionalStructure.CurrentEntry != null)
                {
                    savedValue = AdditionalStructure.CurrentEntry.Size;
                }
            }
            AdditionalStructure = new SPSAdditionalSectionViewModel(Controller, null, 0);
            if (bufSaveLegAdditionalSection != -1)
            {
                for (int j = 0; j < AdditionalStructure.StructureSource.Count; ++j)
                {
                    if (AdditionalStructure.StructureSource[j].Id == bufSaveLegAdditionalSection && AdditionalStructure.StructureSource[j].Text1 != "Свой вариант ответа")
                    {
                        bufSaveLegAdditionalSection = j;
                        break;
                    }
                }

                //   if (bufSaveLegAdditionalSection != -1)
                AdditionalStructure.SelectedValue = AdditionalStructure.StructureSource[bufSaveLegAdditionalSection];
                if (savedValue != -1)
                {
                    AdditionalStructure.CurrentEntry.Size = savedValue;
                }
            }

            for (int i = 0; i < LegSections.Count; ++i)
            {
                var bufSave = new ObservableCollection <LegPartDbStructure>();
                bufSave = LegSections[i].StructureSource;

                LegSections[i].StructureSource = new ObservableCollection <LegPartDbStructure>(Data.SPS.LevelStructures(i + 1).ToList());
                int selectedIndex = -1;
                if (bufSaveLegSection[i] != null)
                {
                    for (int j = 0; j < LegSections[i].StructureSource.Count; ++j)
                    {
                        if (LegSections[i].StructureSource[j].Id == bufSaveLegSection[i])
                        {
                            selectedIndex = j;
                        }
                    }
                }



                if (selectedIndex != -1)
                {
                    LegSections[i].SelectedValue = LegSections[i].StructureSource[selectedIndex];
                }
                foreach (var variant in bufSave)
                {
                    if (variant.Text1 == "Свой вариант ответа" || variant.Text1 == "Переход к следующему разделу")
                    {
                        if (variant.Text1 == "Переход к следующему разделу" && i == 0)
                        {
                        }
                        else
                        {
                            LegSections[i].StructureSource.Add(variant);
                        }
                    }
                    else if (variant.Text1 == "" && variant.Text2 == "")
                    {
                        LegSections[i].StructureSource.Add(variant);
                    }
                }
                foreach (var structure in LegSections[i].StructureSource)
                {
                    structure.Metrics = Data.Metrics.GetStr(structure.Size);
                }
            }

            MessageBus.Default.Call("LegDataSaved", this, this.GetType());

            FF_lengthSave       = FF_length;
            SelectedWayTypeSave = SelectedWayType;
            LegSectionsSaved    = new List <LegSectionViewModel>();
            for (int i = 0; i < LevelCount; i++)
            {
                if (i != 0)
                {
                    LegSectionsSaved.Add(new SPSSectionViewModel(Controller, _sections[i - 1], i + 1));
                }
                else
                {
                    LegSectionsSaved.Add(new SPSSectionViewModel(Controller, null, i + 1));
                }
            }

            commentSave = Comment; for (int i = 0; i < LegSections.Count; i++)
            {
                LegSectionsSaved[i].Comment       = LegSections[i].Comment;
                LegSectionsSaved[i].Size          = LegSections[i].Size;
                LegSectionsSaved[i].Size2         = LegSections[i].Size2;
                LegSectionsSaved[i].Text1         = LegSections[i].Text1;
                LegSectionsSaved[i].Text2         = LegSections[i].Text2;
                LegSectionsSaved[i].SelectedValue = LegSections[i].SelectedValue;
                LegSectionsSaved[i].CurrentEntry  = LegSections[i].CurrentEntry;
            }
        }
Пример #2
0
        public void Initialize()
        {
            MessageBus.Default.Subscribe("RebuildFirstSPS", RebuildFirst);
            MessageBus.Default.Subscribe("RebuildLegSectionViewModel", Rebuild);
            SavePanelCommand = new DelegateCommand(() =>
            {
                var panel = CurrentPanelViewModel;
                if (!string.IsNullOrWhiteSpace(panel.Text1) || !string.IsNullOrWhiteSpace(panel.Text2))
                {
                    CurrentLegSide = CurrentLegSide;
                    if ((LevelSelected != 0 && testOnUnique(CurrentPanelViewModel.LegPrt)) || (LevelSelected == 0 && testAdditionalStructOnUnique(CurrentPanelViewModel.LegPrt)))
                    {
                        var newStruct    = GetPanelStructure();
                        newStruct.Custom = false;
                        Data.SPS.Add((SPSHipStructure)newStruct);
                        Data.Complete();

                        _lastSender.StructureSource.Add(newStruct);
                        _lastSender.SelectedValue         = newStruct;
                        CurrentPanelViewModel.PanelOpened = false;
                        handled = false;
                    }
                    if (!IsStructEdited(CurrentPanelViewModel.LegPrt))
                    {
                        CurrentPanelViewModel.PanelOpened = false;
                        handled = false;
                    }
                }
                else
                {
                    MessageBox.Show("Не все поля заполнены");
                }

                //_lastSender.DeleteCustom();
            });

            SaveCommand = new DelegateCommand(
                () =>
            {
                if (LegSections[0].SelectedValue != null)
                {
                    bool isValid = Validate();
                    if (isValid)
                    {
                        IsEmpty = false;

                        List <int?> ids = new List <int?>();

                        foreach (var leg in LegSections)
                        {
                            //никогда так не делайте
                            if (leg.IsVisible == Visibility.Visible && leg.ListNumber != 1 && leg.SelectedValue != null && leg.SelectedValue.Id != 0)
                            {
                                ids.Add(leg.SelectedValue.Id);
                            }
                        }

                        var combo = Data.SPSCombos.FindCombo(LegSections[0].SelectedValue.Id, ids);
                        //если комбо не нашлось - значит оно кастомное, мы его запомним и отправим в базу на радость будущим пользователям
                        if (combo == null)
                        {
                            var newCombo = new SPSHipCombo();

                            commentSave = Comment; for (int i = 0; i < LegSections.Count; i++)
                            {
                                var currentStructure = LegSections[i].SelectedValue;
                                //ничего не было выбрано
                                if (currentStructure == null)
                                {
                                    continue;
                                }
                                //добавляем структуры, которые встретились впервые, чтобы потом добавить комбо
                                if (currentStructure.Id == 0
                                    //потому что переход к след.разделу в комбо добавлять не надо, это излишняя информация
                                    && !currentStructure.ToNextPart)
                                {
                                    //currentStructure.Level = i + 1;
                                    //Data.SPSHips.Add((SPSHipStructure)currentStructure);
                                    //Data.Complete();
                                    //((SPSHipEntry)LegSections[i].CurrentEntry).Structure = (SPSHipStructure)currentStructure;
                                    //(LegSections[i].CurrentEntry).StructureID = currentStructure.Id;
                                    // Data.SPSHipEntries.Add((SPSHipEntry)LegSections[i].CurrentEntry);
                                    //Data.Complete();
                                    //if (i == 0) newCombo.IdStr1 = currentStructure.Id;
                                    ////там гда раньше был ноль теперь будет актуальный айдишник
                                    //else ids[i - 2] = currentStructure.Id;
                                }
                            }

                            newCombo.IdStr1 = LegSections[0].SelectedValue.Id;
                            //if()
                            //заполняем комбо
                            Data.SPSCombos.AddCombo(newCombo, ids);
                            Data.Complete();
                            MessageBus.Default.Call("RebuildFirstSPS", this, LegSections[0]);
                            MessageBus.Default.Call("RebuildLegSectionViewModel", this, LegSections[0]);
                            MessageBus.Default.Call("RebuildLegSectionViewModel", this, LegSections[1]);
                            MessageBus.Default.Call("RebuildLegSectionViewModel", this, LegSections[2]);
                        }

                        MessageBus.Default.Call("LegDataSaved", this, this.GetType());
                        Controller.NavigateTo <ViewModelAddPhysical>();
                    }
                }
                else
                {
                    MessageBus.Default.Call("LegDataSaved", this, this.GetType());
                    Controller.NavigateTo <ViewModelAddPhysical>();
                }
            }
                );
            LevelCount          = 3;
            AdditionalStructure = new SPSAdditionalSectionViewModel(Controller, null, 0);
            _sections           = new ObservableCollection <LegSectionViewModel>();
            for (int i = 0; i < LevelCount; i++)
            {
                if (i != 0)
                {
                    LegSections.Add(new SPSSectionViewModel(Controller, _sections[i - 1], i + 1));
                }
                else
                {
                    LegSections.Add(new SPSSectionViewModel(Controller, null, i + 1));
                }
            }
            _title = "Сафено поплитеальное соустье";
        }