Exemplo n.º 1
0
        private void MoveComponentHandler(object parameter)
        {
            if (SelectedComponent != null)
            {
                AddRelatedPipeDialog dialog = new AddRelatedPipeDialog("Select Destination Tag", true, SelectedComponent.PipeId);
                dialog.Show();

                //Select the component as user might have changed the component type
                //and this needs to reload the component type properties
                dialog.Closed += (s1, e1) =>
                                     {
                                         if (dialog.DialogResult.HasValue && dialog.DialogResult.Value)
                                         {
                                             if (dialog.SelectedPipe != null)
                                             {
                                                 SelectedComponent.PipeId = dialog.SelectedPipe.Id;

                                                 //need to CLONE due to the line "RaisePropertyChanged("Components");"
                                                 MovedComponent = CloneComponent(SelectedComponent);
                                                 MovedComponent.Pipe = new Pipe
                                                                           {
                                                                               Id = dialog.SelectedPipe.Id,
                                                                               Name = dialog.SelectedPipe.Name
                                                                           };

                                                 //remove
                                                 mPipe.PipeComponents.Remove(SelectedComponent);
                                                 RaiseChangeEvent();
                                                 OnCollectionChanged();
                                                 mSelectedComponent = null;

                                                 RaisePropertyChanged("Components");
                                             }
                                         }
                                     };

            }
        }
        private void AddButtonHandler(object parameter)
        {
            AddRelatedPipeDialog dialog = new AddRelatedPipeDialog();
            dialog.Show();
            dialog.Closed +=
                (s1, e1) =>
                {
                    if (dialog.DialogResult.HasValue && dialog.DialogResult.Value)
                    {
                        List<QuickPipe> toAdd = dialog.SelectedPipes.ToList();

                        foreach (QuickPipe newQuickPipe in toAdd)
                        {
                            IssueRelatedPipe issueRelatedPipe = (from x in mIssue.IssueRelatedPipes
                                                                 where x.PipeId == newQuickPipe.Id && x.IssueId == mIssue.Id
                                                                 select x).FirstOrDefault();
                            if (issueRelatedPipe == null)
                            {

                                IssueRelatedPipe irp = new IssueRelatedPipe
                                {
                                    IssueId = mIssue.Id,
                                    PipeId = newQuickPipe.Id,
                                    Pipe = new Pipe
                                        {
                                            FormattedName = newQuickPipe.Name,
                                            IsActive = newQuickPipe.IsActive
                                        }
                                };
                                mIssue.IssueRelatedPipes.Add(irp);
                            }
                        }

                        RaiseChangeEvent();
                        OnCollectionChanged();

                        RaisePropertyChanged("IssueRelatedPipes");
                    }
                };
        }