private void SaveButton_Click(object sender, EventArgs e) { if (siteMan.GetSites().Count == 0) { MessageBox.Show("May as well make some changes before you save, am I right?"); return; } TreeNode node = SitesTreeView.SelectedNode; string nodeName = node.Name; Channel chan = null; if (node.Tag is Site) { Site site = (Site)node.Tag; if (site.Name != NameTextBox.Text && siteMan.ContainsName(NameTextBox.Text)) { MessageBox.Show("All items in the Site Manager require a unique name!"); return; } site.Name = NameTextBox.Text; nodeName = site.Name; } else if (node.Tag is Facility) { Facility fac = (Facility)node.Tag; if (fac.Name != NameTextBox.Text && siteMan.ContainsName(NameTextBox.Text)) { MessageBox.Show("All items in the Site Manager require a unique name!"); return; } fac.Name = NameTextBox.Text; nodeName = fac.Name; } else if (node.Tag is DetectionSystem) { DetectionSystem sys = (DetectionSystem)node.Tag; if (sys.Name != NameTextBox.Text && siteMan.ContainsName(NameTextBox.Text)) { MessageBox.Show("All items in the Site Manager require a unique name!"); return; } sys.Name = NameTextBox.Text; nodeName = sys.Name; if (DeclarationCheckBox.Checked) { selectedSystem.GetDeclarationInstrument().SetFilePrefix(DeclarationPrefixTextBox.Text); selectedSystem.GetDeclarationInstrument().SetDataFolder(DeclarationDirectoryTextBox.Text); selectedSystem.GetDeclarationInstrument().ScanDataFolder(); } } else if (node.Tag is Instrument) { Instrument inst = (Instrument)node.Tag; if (inst.Name != NameTextBox.Text && siteMan.ContainsName(NameTextBox.Text)) { MessageBox.Show("All items in the Site Manager require a unique name!"); return; } if (!InstrumentParameterListPanel.ValidateInput()) { return; } string name = NameTextBox.Text; string type = inst.InstrumentType; if (name != inst.Name) { inst.Name = name; } inst.ApplyParameters(InstrumentParameterListPanel.Parameters); // selectedChannel and selectedVirtualChannel might not exist anymore if (selectedVirtualChannel != null) { foreach (VirtualChannel vc in inst.GetVirtualChannels()) { if (vc.Name == selectedVirtualChannel.Name) { selectedVirtualChannel = vc; break; } } chan = SaveVirtualChannel(inst, selectedVirtualChannel); } else if (selectedChannel != null) { foreach (Channel c in inst.GetStandardChannels()) { if (c.Name == selectedChannel.Name) { selectedChannel = c; break; } } chan = SaveChannel(inst, selectedChannel); } nodeName = inst.Name; } else if (node.Tag is EventGenerator) { MessageBox.Show("Use the Event Manager to edit events."); return; } if (siteMan.Save() != ReturnCode.SUCCESS) { MessageBox.Show("Bad trouble saving the site manager!"); } UpdateSitesTree(); siteManChanged = true; SitesTreeView.SelectedNode = SitesTreeView.Nodes.Find(nodeName, true)[0]; if (selectedVirtualChannel != null) { ChannelsComboBox.SelectedItem = selectedVirtualChannel.Name; } else if (selectedChannel != null) { ChannelsComboBox.SelectedItem = selectedChannel.Name; } }
private void ResetFields() { selectedSystem = null; selectedChannel = null; selectedVirtualChannel = null; TreeNode node = SitesTreeView.SelectedNode; NameTextBox.Text = node.Text; if (node.Tag is Site) { Site site = (Site)node.Tag; TypeLabel.Text = "Site"; SystemPanel.Visible = false; InstrumentPanel.Visible = false; NewInstrumentButton.Enabled = false; NewSystemButton.Enabled = false; NewFacilityButton.Enabled = true; } else if (node.Tag is Facility) { Facility fac = (Facility)node.Tag; TypeLabel.Text = "Facility"; SystemPanel.Visible = false; InstrumentPanel.Visible = false; NewInstrumentButton.Enabled = false; NewSystemButton.Enabled = true; NewFacilityButton.Enabled = true; } else if (node.Tag is DetectionSystem) { DetectionSystem sys = (DetectionSystem)node.Tag; selectedSystem = sys; TypeLabel.Text = "System"; SetupSystemPanel(); SystemPanel.Visible = true; InstrumentPanel.Visible = false; NewInstrumentButton.Enabled = true; NewSystemButton.Enabled = true; NewFacilityButton.Enabled = true; } else if (node.Tag is Instrument) { Instrument inst = (Instrument)node.Tag; TypeLabel.Text = "Instrument"; InstrumentParameterListPanel.LoadParameters(inst.GetParameters()); InstTypeTextBox.Text = inst.InstrumentType; ChannelsComboBox.Items.Clear(); Channel[] channels = inst.GetChannels(); if (channels.Length > 0) { foreach (Channel channel in channels) { ChannelsComboBox.Items.Add(channel.Name); } if (channels[0] is VirtualChannel) { selectedChannel = null; selectedVirtualChannel = (VirtualChannel)channels[0]; ChannelsComboBox.SelectedItem = selectedVirtualChannel.Name; SetupVirtualChannelGroupBox(); } else { selectedChannel = channels[0]; selectedVirtualChannel = null; ChannelsComboBox.SelectedItem = selectedChannel.Name; SetupChannelGroupBox(); } } else { VirtualChannelGroupBox.Visible = false; } SystemPanel.Visible = false; InstrumentPanel.Visible = true; NewInstrumentButton.Enabled = true; NewSystemButton.Enabled = true; NewFacilityButton.Enabled = true; } else if (node.Tag is EventGenerator) { EventGenerator eg = (EventGenerator)node.Tag; TypeLabel.Text = "Event Generator"; SystemPanel.Visible = false; InstrumentPanel.Visible = false; NewInstrumentButton.Enabled = false; NewSystemButton.Enabled = false; } }