Ejemplo n.º 1
0
        public void OkDialog()
        {
            var helper = new MessageBoxHelper(this);

            string name;

            if (!helper.ValidateNameTextBox(textName, out name))
            {
                return;
            }

            if (_existing.Contains(en => !ReferenceEquals(_isolationScheme, en) && Equals(name, en.Name)))
            {
                helper.ShowTextBoxError(textName,
                                        Resources.EditIsolationSchemeDlg_OkDialog_The_isolation_scheme_named__0__already_exists, name);
                return;
            }

            if (rbUseResultsData.Checked)
            {
                double?precursorFilter = null;
                bool   filterMargin    = Equals(comboIsolationWidth.SelectedItem, IsolationWidthType.RESULTS_WITH_MARGIN);
                if (!Equals(comboIsolationWidth.SelectedItem, IsolationWidthType.RESULTS))
                {
                    double minFilt = filterMargin ? 0 : TransitionFullScan.MIN_PRECURSOR_MULTI_FILTER;
                    double maxFilt = filterMargin
                        ? TransitionFullScan.MAX_PRECURSOR_MULTI_FILTER_MARGIN
                        : TransitionFullScan.MAX_PRECURSOR_MULTI_FILTER;
                    double precFilt;
                    if (!helper.ValidateDecimalTextBox(textPrecursorFilterMz,
                                                       minFilt, maxFilt, out precFilt))
                    {
                        return;
                    }
                    precursorFilter = precFilt;
                }
                try
                {
                    _isolationScheme = new IsolationScheme(name, SpecialHandling, precursorFilter, null, filterMargin);
                }
                catch (InvalidDataException exception)
                {
                    MessageDlg.ShowException(this, exception);
                    return;
                }
            }
            else
            {
                // Validate prespecified windows.
                List <IsolationWindow> windowList;
                if ((windowList = GetIsolationWindows()) == null)
                {
                    return;
                }


                // Must be at least one window.
                if (windowList.Count == 0)
                {
                    _gridViewDriver.SelectCell(COLUMN_START, 0);
                    MessageDlg.Show(this,
                                    Resources
                                    .EditIsolationSchemeDlg_OkDialog_Specify_Start_and_End_values_for_at_least_one_isolation_window);
                    gridIsolationWindows.Focus();
                    _gridViewDriver.EditCell();
                    return;
                }

                int?windowsPerScan = null;
                if (Equals(SpecialHandling, IsolationScheme.SpecialHandlingType.MULTIPLEXED))
                {
                    int x;
                    if (!helper.ValidateNumberTextBox(textWindowsPerScan,
                                                      IsolationScheme.MIN_MULTIPLEXED_ISOLATION_WINDOWS,
                                                      IsolationScheme.MAX_MULTIPLEXED_ISOLATION_WINDOWS,
                                                      out x))
                    {
                        return;
                    }
                    windowsPerScan = x;
                }
                // Check for overlap and gaps
                var          sortedWindowList = windowList.OrderBy(o => o.Start).ToList();
                bool         gapsOk           = false;
                bool         overlapsOk       = false;
                bool         overlap          = Overlap;
                int          increment        = overlap ? 2 : 1;
                int          subtraction      = overlap ? 3 : 1;
                const double tolerance        = 0.0001;
                for (int i = 0; i < sortedWindowList.Count - subtraction; i += increment)
                {
                    for (int j = 0; j < increment; j++)
                    {
                        IsolationWindow current = sortedWindowList.ElementAt(i + j);
                        IsolationWindow next    = sortedWindowList.ElementAt(i + j + increment);
                        if (!gapsOk && next.Start - current.End > tolerance)
                        {
                            if (MultiButtonMsgDlg.Show(this,
                                                       Resources
                                                       .EditIsolationSchemeDlg_OkDialog_There_are_gaps_in_a_single_cycle_of_your_extraction_windows__Do_you_want_to_continue_,
                                                       MultiButtonMsgDlg.BUTTON_YES, MultiButtonMsgDlg.BUTTON_NO, false) !=
                                DialogResult.Yes)
                            {
                                return;
                            }
                            gapsOk = true;
                        }
                        else if (!overlapsOk && current.End - next.Start > tolerance)
                        {
                            if (MultiButtonMsgDlg.Show(this,
                                                       Resources.EditIsolationSchemeDlgOkDialogThereAreOverlapsContinue,
                                                       MultiButtonMsgDlg.BUTTON_YES,
                                                       MultiButtonMsgDlg.BUTTON_NO, false) != DialogResult.Yes)
                            {
                                return;
                            }
                            overlapsOk = true;
                        }
                    }
                }
                try
                {
                    _isolationScheme = new IsolationScheme(name, windowList, SpecialHandling, windowsPerScan);
                }
                catch (InvalidDataException exception)
                {
                    MessageDlg.ShowException(this, exception);
                    return;
                }
            }

            DialogResult = DialogResult.OK;
        }