Example #1
0
        private void Apply_btn_clk(object sender, RoutedEventArgs e)
        {
            string  name    = this.name_txt.Text;
            Element element = new Element(name);
            bool    is_in   = false;

            for (int i = 0; i < mainW.elements.Count; ++i)
            {
                if (mainW.element_listView.SelectedIndex != i && mainW.elements[i].Name == element.Name)
                {
                    is_in = true;
                    break;
                }
            }
            if (is_in)
            {
                MessageBox.Show(Message_Helper.NAME_IS_USED_Message);
                return;
            }
            if (!Config_Helper.IsNameRight(element.Name))
            {
                MessageBox.Show(Message_Helper.NAME_WRONG);
                return;
            }
            List <double> mass_list  = new List <double>();
            List <double> ratio_list = new List <double>();

            for (int i = 0; i < this.grid.RowDefinitions.Count; ++i)
            {
                if (this.grid.Children[i].Visibility == Visibility.Collapsed)
                {
                    continue;
                }
                StackPanel sp        = this.grid.Children[i] as StackPanel;
                TextBox    mass_tbx  = sp.Children[1] as TextBox;
                TextBox    ratio_tbx = sp.Children[3] as TextBox;
                string     mass_str  = mass_tbx.Text;
                string     ratio_str = ratio_tbx.Text;
                if (!Config_Helper.IsDecimalAllowed(mass_str) || !Config_Helper.IsDecimalAllowed(ratio_str))
                {
                    MessageBox.Show(Message_Helper.EL_MASS_RATIO_DOUBLE_Message);
                    return;
                }
                mass_list.Add(double.Parse(mass_str));
                ratio_list.Add(double.Parse(ratio_str));
            }
            double all_ratio = 0.0;
            double max_mass = 0.0, max_ratio = 0.0;

            for (int i = 0; i < mass_list.Count; ++i)
            {
                all_ratio += ratio_list[i];
                if (ratio_list[i] > max_ratio)
                {
                    max_ratio = ratio_list[i];
                    max_mass  = mass_list[i];
                }
            }
            if (Math.Abs(all_ratio - 1.0) >= 1.0e-9)
            {
                MessageBox.Show(Message_Helper.EL_SUM_RATIO_ONE_Message);
                return;
            }
            element.MMass = max_mass;
            element.Mass  = mass_list;
            element.Ratio = ratio_list;
            element.update_mass_str();
            int index = mainW.element_listView.SelectedIndex;

            mainW.elements[index] = element;
            mainW.element_listView.Items.Refresh();
            mainW.is_update[5] = true;
            mainW.is_update_f();
            mainW.element_listView.SelectedItem = element;
            mainW.element_listView.ScrollIntoView(element);
            this.Close();
        }
Example #2
0
        private void apply_btn_clk(object sender, RoutedEventArgs e)
        {
            string       name             = name_txt.Text;
            string       composition      = composition_txt.Text;
            string       mass_str         = mass_txt.Text;
            ComboBoxItem cbi              = position_comboBox.SelectedItem as ComboBoxItem;
            string       position         = cbi.Content as string;
            string       position_display = "";
            string       site             = site_txt.Text;
            string       neutral_loss     = Neutral_Loss_txt.Text;
            bool         is_common        = (bool)Common_checkBox.IsChecked;

            if (name == "" || composition == "" || !Config_Helper.IsDecimalAllowed(mass_str) || site == "")
            {
                if (name == "")
                {
                    name_txt.Background = new SolidColorBrush(Colors.Red);
                }
                if (composition == "")
                {
                    composition_txt.Background = new SolidColorBrush(Colors.Red);
                }
                if (!Config_Helper.IsDecimalAllowed(mass_str))
                {
                    mass_txt.Background = new SolidColorBrush(Colors.Red);
                }
                if (site == "")
                {
                    site_txt.Background = new SolidColorBrush(Colors.Red);
                }
                if (neutral_loss != "")
                {
                    string[] strs = neutral_loss.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                    for (int i = 0; i < strs.Length; ++i)
                    {
                        if (!Config_Helper.IsDecimalAllowed(strs[i]))
                        {
                            Neutral_Loss_txt.Background = new SolidColorBrush(Colors.Red);
                        }
                    }
                }
                MessageBox.Show(Message_Helper.MO_INPUT_WRONG_Message);
                return;
            }
            if (Site_wrong(site))
            {
                site_txt.Background = new SolidColorBrush(Colors.Red);
                MessageBox.Show(Message_Helper.MO_AA_REPEAT);
                return;
            }
            ObservableCollection <double> neutral_loss_list = new ObservableCollection <double>(); //默认以;进行分隔

            if (neutral_loss != "")
            {
                string[] strs = neutral_loss.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                for (int i = 0; i < strs.Length; ++i)
                {
                    if (!Config_Helper.IsDecimalAllowed(strs[i]))
                    {
                        Neutral_Loss_txt.Background = new SolidColorBrush(Colors.Red);
                        MessageBox.Show(Message_Helper.MO_INPUT_WRONG_Message);
                        return;
                    }
                    neutral_loss_list.Add(double.Parse(strs[i]));
                }
            }
            switch (position)
            {
            case "Anywhere":
                position         = "NORMAL";
                position_display = "NORMAL";
                break;

            case "PepN-term":
                position         = "PEP_N";
                position_display = "Peptide N-term";
                break;

            case "PepC-term":
                position         = "PEP_C";
                position_display = "Peptide C-term";
                break;

            case "ProN-term":
                position         = "PRO_N";
                position_display = "Protein N-term";
                break;

            case "ProC-term":
                position         = "PRO_C";
                position_display = "Protein C-term";
                break;
            }
            Modification modification = new Modification(name, is_common, site, position, double.Parse(mass_str), composition, neutral_loss_list);

            modification.Position_Display = position_display;
            if (mainW.modifications.Contains(modification))
            {
                MessageBox.Show(Message_Helper.NAME_IS_USED_Message);
                return;
            }
            if (!Config_Helper.IsNameRight(modification.Name))
            {
                MessageBox.Show(Message_Helper.NAME_WRONG);
                return;
            }
            mainW.add_modifications.Add(modification);
            mainW.modifications.Add(modification);
            mainW.is_update[1] = true;
            mainW.is_update_f();
            mainW.mod_listView.SelectedItem = modification;
            mainW.mod_listView.ScrollIntoView(modification);
            this.Close();
        }