Beispiel #1
0
        private void renameInstrumentToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                ConfigFile currentConfig = null;
                if (ProgramModeBox.Text == "MyriMatch")
                {
                    if (MyriInstrumentList.SelectedIndex > 0)
                        currentConfig = _myriTemplateList[MyriInstrumentList.SelectedIndex - 1];
                    else
                        MessageBox.Show("Cannot rename 'New'");
                }
                else if (ProgramModeBox.Text == "DirecTag")
                {
                    if (DTInstrumentList.SelectedIndex > 0)
                        currentConfig = _DTTemplateList[DTInstrumentList.SelectedIndex - 1];
                    else
                        MessageBox.Show("Cannot rename 'New'");
                }
                else if (ProgramModeBox.Text == "TagRecon")
                {
                    if (TRInstrumentList.SelectedIndex > 0)
                        currentConfig = _TRTemplateList[TRInstrumentList.SelectedIndex - 1];
                    else
                        MessageBox.Show("Cannot rename 'New'");
                }
                else
                {
                    if (PepInstrumentList.SelectedIndex > 0)
                        currentConfig = _pepTemplateList[PepInstrumentList.SelectedIndex - 1];
                    else
                        MessageBox.Show("Cannot rename 'New'");
                }

                var namebox = new TextPromptBox("Instrument Name", string.Empty);
                if (currentConfig != null && namebox.ShowDialog() == DialogResult.OK)
                {
                    currentConfig.Name = namebox.GetText();
                    _session.SaveOrUpdate(currentConfig);
                    _session.Flush();
                    ResetTemplateLists();

                    MessageBox.Show("Rename successful");
                }
            }
            catch
            {
                MessageBox.Show("Could not rename instrument");
            }
        }
Beispiel #2
0
        private void SaveTemplateButton_Click(object sender, EventArgs e)
        {
            var parameterType = Util.parameterTypes;
            string prefix;

            var newTemplate = false;
            try
            {
                ConfigFile currentConfig;
                if (ProgramModeBox.Text == "MyriMatch")
                {
                    if (MyriInstrumentList.SelectedIndex > 0)
                        currentConfig = _myriTemplateList[MyriInstrumentList.SelectedIndex - 1];
                    else
                    {
                        currentConfig = new ConfigFile
                                            {
                                                DestinationProgram = "MyriMatch",
                                                FilePath = "Template",
                                                PropertyList = new List<ConfigProperty>()
                                            };
                        newTemplate = true;
                    }
                    prefix = "Myri";
                }
                else if (ProgramModeBox.Text == "DirecTag")
                {
                    if (DTInstrumentList.SelectedIndex > 0)
                        currentConfig = _DTTemplateList[DTInstrumentList.SelectedIndex-1];
                    else
                    {
                        currentConfig = new ConfigFile
                        {
                            DestinationProgram = "DirecTag",
                            FilePath = "Template",
                            PropertyList = new List<ConfigProperty>()
                        };
                        newTemplate = true;
                    }
                    prefix = "DT";
                }
                else if (ProgramModeBox.Text == "TagRecon")
                {
                    if (TRInstrumentList.SelectedIndex > 0)
                        currentConfig = _TRTemplateList[TRInstrumentList.SelectedIndex-1];
                    else
                    {
                        currentConfig = new ConfigFile
                        {
                            DestinationProgram = "TagRecon",
                            FilePath = "Template",
                            PropertyList = new List<ConfigProperty>()
                        };
                        newTemplate = true;
                    }
                    prefix = "TR";
                }
                else
                {
                    if (PepInstrumentList.SelectedIndex > 0)
                        currentConfig = _pepTemplateList[PepInstrumentList.SelectedIndex - 1];
                    else
                    {
                        currentConfig = new ConfigFile
                        {
                            DestinationProgram = "Pepitome",
                            FilePath = "Template",
                            PropertyList = new List<ConfigProperty>()
                        };
                        newTemplate = true;
                    }
                    prefix = "Pep";
                }

                if (newTemplate)
                {
                    var namebox = new TextPromptBox("Instrument Name", string.Empty);
                    if (namebox.ShowDialog() == DialogResult.OK)
                        currentConfig.Name = namebox.GetText();
                    else
                        return;
                }

                currentConfig.PropertyList.Clear();
                foreach (var kvp in _labelAssociation
                    .Where(kvp => kvp.Key.Name.StartsWith(prefix))
                    .Where(kvp => kvp.Value.ForeColor != DefaultForeColor
                        && kvp.Value.ForeColor != Color.Blue))
                {
                    currentConfig.PropertyList.Add(new ConfigProperty
                                                       {
                                                           Name = RootName(kvp.Key.Name),
                                                           Value = GetControlValueString(kvp.Key),
                                                           Type = parameterType.ContainsKey(RootName(kvp.Key.Name))
                                                                      ? parameterType[RootName(kvp.Key.Name)]
                                                                      : "unknown",
                                                           ConfigAssociation = currentConfig
                                                       });
                }

                _session.SaveOrUpdate(currentConfig);
                _session.Flush();

                ResetTemplateLists();

                MessageBox.Show("Save successful");
            }
            catch
            {
                MessageBox.Show("Unable to save");
            }
        }