Ejemplo n.º 1
0
 protected void AddCustomObject(Type structureType)
 {
     _customChoice            = (LegPartDbStructure)Activator.CreateInstance(structureType);
     _customChoice.Text1      = _startCustomText;
     _customChoice.HasSize    = false;
     _customChoice.Custom     = true;
     _customChoice.ToNextPart = false;
     StructureSource.Add(_customChoice);
 }
        public bool IsStructEdited(LegPartDbStructure structure)
        {
            if (CurrentPanelViewModel.mode != "Edit")
            {
                return(true);
            }

            bool test = false;

            if ((CurrentPanelViewModel.Text1 != structure.Text1))
            {
                if (structure.Text1 == null && CurrentPanelViewModel.Text1 == "" || structure.Text1 == "" && CurrentPanelViewModel.Text1 == null)
                {
                }
                else
                {
                    test = true;
                }
            }


            if ((CurrentPanelViewModel.Text2 != structure.Text2))
            {
                if (structure.Text2 == null && CurrentPanelViewModel.Text2 == "" || structure.Text2 == "" && CurrentPanelViewModel.Text2 == null)
                {
                }
                else
                {
                    test = true;
                }
            }

            if (CurrentPanelViewModel.HasSize != structure.HasSize)
            {
                test = true;
            }
            if (structure.Metrics != CurrentPanelViewModel.SelectedMetricText && CurrentPanelViewModel.HasSize == true)
            {
                test = true;
            }

            if (structure.HasDoubleMetric != CurrentPanelViewModel.HasDoubleSize)
            {
                test = true;
            }

            if (test == false)
            {
                //CurrentPanelViewModel.SelectedMetricText = "";

                //CurrentPanelViewModel.HasDoubleSize = false;
                //CurrentPanelViewModel.HasSize = false;
            }
            return(test);
        }
        private bool testAdditionalStructOnUnique(LegPartDbStructure structure)
        {
            if (Controller.CurrentViewModel.Controller.LegViewModel == this)
            {
                foreach (var x in AdditionalStructure.StructureSource)
                {
                    if (mode == "Edit")
                    {
                        if (x.HasDoubleMetric == CurrentPanelViewModel.HasDoubleSize &&
                            x.HasSize == CurrentPanelViewModel.HasSize &&
                            (x.Text1 == CurrentPanelViewModel.Text1 || (string.IsNullOrWhiteSpace(x.Text1) && string.IsNullOrWhiteSpace(CurrentPanelViewModel.Text1))) &&
                            (x.Text2 == CurrentPanelViewModel.Text2 || (string.IsNullOrWhiteSpace(x.Text2) && string.IsNullOrWhiteSpace(CurrentPanelViewModel.Text2))) &&
                            x.Id != structure.Id)
                        {
                            if (x.HasSize == true)
                            {
                                if ((x.Metrics == CurrentPanelViewModel.SelectedMetricText || string.IsNullOrWhiteSpace(x.Metrics) && string.IsNullOrWhiteSpace(CurrentPanelViewModel.SelectedMetricText)))
                                {
                                    MessageBox.Show("Такое описание уже существует!");

                                    return(false);
                                }
                                else
                                {
                                    return(true);
                                }
                            }


                            MessageBox.Show("Такое описание уже существует!");

                            return(false);
                        }
                    }
                    else
                    {
                        if (x.HasDoubleMetric == CurrentPanelViewModel.HasDoubleSize &&
                            x.HasSize == CurrentPanelViewModel.HasSize &&
                            (x.Text1 == CurrentPanelViewModel.Text1 || (string.IsNullOrWhiteSpace(x.Text1) && string.IsNullOrWhiteSpace(CurrentPanelViewModel.Text1))) &&
                            (x.Text2 == CurrentPanelViewModel.Text2 || (string.IsNullOrWhiteSpace(x.Text2) && string.IsNullOrWhiteSpace(CurrentPanelViewModel.Text2))))

                        {
                            if (x.HasSize == true)
                            {
                                if ((x.Metrics == CurrentPanelViewModel.SelectedMetricText || string.IsNullOrWhiteSpace(x.Metrics) && string.IsNullOrWhiteSpace(CurrentPanelViewModel.SelectedMetricText)))
                                {
                                    MessageBox.Show("Такое описание уже существует!");

                                    return(false);
                                }
                                else
                                {
                                    return(true);
                                }
                            }


                            MessageBox.Show("Такое описание уже существует!");

                            return(false);
                        }
                    }
                }
            }
            return(true);
        }
        private void OpenStructRedact(object sender, object data)
        {
            if (Controller.CurrentViewModel.Controller.LegViewModel == this)
            {
                //IsRedactVis = Visibility.Visible;
                //ISAddVis = Visibility.Collapsed;

                buff = SavePanelCommand;

                //var curPanel = ((LegPartViewModel)Controller.LegViewModel).CurrentPanelViewModel;
                var currentPart = (LegSectionViewModel)sender;


                LegPartDbStructure structure = currentPart.SelectedValue;
                LevelSelected = structure.Level;
                CurrentPanelViewModel.LegPrt      = structure;
                CurrentPanelViewModel.SavedLegPrt = structure;
                CurrentPanelViewModel.mode        = "Edit";
                LegPrt         = structure;
                CurrentLegSide = CurrentLegSide;



                _lastSender = currentPart;



                _lastSenderType = (Type)data;

                CurrentPanelViewModel.PanelOpened = true;

                if (structure.Text1 != null)
                {
                    CurrentPanelViewModel.Text1 = structure.Text1;
                }
                if (structure.Text2 != null)
                {
                    CurrentPanelViewModel.Text2 = structure.Text2;
                }
                if (structure.HasSize)
                {
                    CurrentPanelViewModel.HasSize = true;
                    foreach (Metrics x in CurrentPanelViewModel.Dimentions)
                    {
                        if (x.Str == structure.Metrics)
                        {
                            CurrentPanelViewModel.SelectedMetricText = x.Str;
                            CurrentPanelViewModel.SelectedMetric     = x;
                        }
                    }
                    if (structure.HasDoubleMetric)
                    {
                        CurrentPanelViewModel.HasDoubleSize = true;
                    }
                }
                CurrentPanelViewModel.TextSaveBTN          = "Вернуться";
                CurrentPanelViewModel.TextCancleOrResetBTN = "Сбросить";



                ClosePanelCommand = new DelegateCommand(() =>
                {
                    if (structure.Text1 != null)
                    {
                        CurrentPanelViewModel.Text1 = structure.Text1;
                    }
                    else
                    {
                        CurrentPanelViewModel.Text1 = "";
                    }
                    if (structure.Text2 != null)
                    {
                        CurrentPanelViewModel.Text2 = structure.Text2;
                    }
                    else
                    {
                        CurrentPanelViewModel.Text2 = "";
                    }
                    if (structure.HasSize)
                    {
                        CurrentPanelViewModel.HasSize = true;
                        foreach (Metrics x in CurrentPanelViewModel.Dimentions)
                        {
                            if (x.Str == structure.Metrics)
                            {
                                CurrentPanelViewModel.SelectedMetricText = x.Str;
                                CurrentPanelViewModel.SelectedMetric     = x;
                            }
                        }
                        if (structure.HasDoubleMetric)
                        {
                            CurrentPanelViewModel.HasDoubleSize = true;
                        }
                    }
                    else
                    {
                        CurrentPanelViewModel.SelectedMetricText = "";

                        CurrentPanelViewModel.HasDoubleSize = false;
                        CurrentPanelViewModel.HasSize       = false;
                    }
                    CurrentPanelViewModel.TextSaveBTN = "Вернуться";
                });
            }
        }
        public bool testOnUnique(LegPartDbStructure structure)
        {
            //if (structure.HasDoubleMetric == CurrentPanelViewModel.SavedLegPrt.HasDoubleMetric
            //       && structure.HasSize == CurrentPanelViewModel.SavedLegPrt.HasSize
            //       && structure.Metrics == CurrentPanelViewModel.SavedLegPrt.Metrics
            //        && structure.NameContext == CurrentPanelViewModel.SavedLegPrt.NameContext
            //          && structure.Size == CurrentPanelViewModel.SavedLegPrt.Size
            //            && structure.Text1 == CurrentPanelViewModel.SavedLegPrt.Text1
            //              && structure.Text2 == CurrentPanelViewModel.SavedLegPrt.Text2
            //              && structure.ToNextPart == CurrentPanelViewModel.SavedLegPrt.ToNextPart
            //              && structure.Custom == CurrentPanelViewModel.SavedLegPrt.Custom)
            //{
            //    return true;
            //}
            //if (structure == null)
            //    return false;
            if (Controller.CurrentViewModel.Controller.LegViewModel == this)
            {
                if (LevelSelected != 0)
                {
                    foreach (var x in LegSections[LevelSelected - 1].StructureSource)
                    {
                        if (mode == "Edit")
                        {
                            if (x.HasDoubleMetric == CurrentPanelViewModel.HasDoubleSize &&
                                x.HasSize == CurrentPanelViewModel.HasSize &&
                                (x.Text1 == CurrentPanelViewModel.Text1 || (string.IsNullOrWhiteSpace(x.Text1) && string.IsNullOrWhiteSpace(CurrentPanelViewModel.Text1))) &&
                                (x.Text2 == CurrentPanelViewModel.Text2 || (string.IsNullOrWhiteSpace(x.Text2) && string.IsNullOrWhiteSpace(CurrentPanelViewModel.Text2))) &&
                                x.Id != structure.Id)
                            {
                                if (x.HasSize == true)
                                {
                                    if ((x.Metrics == CurrentPanelViewModel.SelectedMetricText || string.IsNullOrWhiteSpace(x.Metrics) && string.IsNullOrWhiteSpace(CurrentPanelViewModel.SelectedMetricText)))
                                    {
                                        MessageBox.Show("Такое описание уже существует!");

                                        return(false);
                                    }
                                    else
                                    {
                                        return(true);
                                    }
                                }


                                MessageBox.Show("Такое описание уже существует!");

                                return(false);
                            }
                        }
                        else
                        {
                            if (x.HasDoubleMetric == CurrentPanelViewModel.HasDoubleSize &&
                                x.HasSize == CurrentPanelViewModel.HasSize &&
                                (x.Text1 == CurrentPanelViewModel.Text1 || (string.IsNullOrWhiteSpace(x.Text1) && string.IsNullOrWhiteSpace(CurrentPanelViewModel.Text1))) &&
                                (x.Text2 == CurrentPanelViewModel.Text2 || (string.IsNullOrWhiteSpace(x.Text2) && string.IsNullOrWhiteSpace(CurrentPanelViewModel.Text2))))

                            {
                                if (x.HasSize == true)
                                {
                                    if ((x.Metrics == CurrentPanelViewModel.SelectedMetricText || string.IsNullOrWhiteSpace(x.Metrics) && string.IsNullOrWhiteSpace(CurrentPanelViewModel.SelectedMetricText)))
                                    {
                                        MessageBox.Show("Такое описание уже существует!");

                                        return(false);
                                    }
                                    else
                                    {
                                        return(true);
                                    }
                                }


                                MessageBox.Show("Такое описание уже существует!");

                                return(false);
                            }
                        }
                    }
                }
            }
            return(true);
        }