private void NewSystemButton_Click(object sender, EventArgs e) { // Get parent facility int index = -1; TreeNode node = SitesTreeView.SelectedNode; Facility fac; if (node.Tag is Facility) { fac = (Facility)node.Tag; } else if (node.Tag is DetectionSystem) { fac = (Facility)node.Parent.Tag; DetectionSystem sys = (DetectionSystem)node.Tag; index = fac.GetSystems().IndexOf(sys) + 1; } else { fac = (Facility)node.Parent.Parent.Tag; DetectionSystem sys = (DetectionSystem)node.Parent.Tag; index = fac.GetSystems().IndexOf(sys) + 1; } if (index < 0) { index = fac.GetSystems().Count; } bool uniqueName = false; int iteration = 0; string name = ""; while (!uniqueName) { iteration++; name = "New-System-" + iteration.ToString(); uniqueName = !siteMan.ContainsName(name); } DetectionSystem newSys = new DetectionSystem(fac, name, 0); newSys.SetIndex(index); siteMan.Save(); UpdateSitesTree(); siteManChanged = true; SitesTreeView.SelectedNode = SitesTreeView.Nodes.Find(name, true)[0]; }
private void UpButton_Click(object sender, EventArgs e) { TreeNode node = SitesTreeView.SelectedNode; if (node.Tag is Site) { Site site = (Site)node.Tag; int index = siteMan.GetSites().IndexOf(site); if (index > 0) { site.SetIndex(index - 1); siteMan.Save(); UpdateSitesTree(); siteManChanged = true; SitesTreeView.SelectedNode = SitesTreeView.Nodes.Find(site.Name, true)[0]; } } else if (node.Tag is Facility) { Facility fac = (Facility)node.Tag; Site site = (Site)node.Parent.Tag; int index = site.GetFacilities().IndexOf(fac); if (index > 0) { fac.SetIndex(index - 1); siteMan.Save(); UpdateSitesTree(); siteManChanged = true; SitesTreeView.SelectedNode = SitesTreeView.Nodes.Find(fac.Name, true)[0]; } } else if (node.Tag is DetectionSystem) { DetectionSystem sys = (DetectionSystem)node.Tag; Facility fac = (Facility)node.Parent.Tag; int index = fac.GetSystems().IndexOf(sys); if (index > 0) { sys.SetIndex(index - 1); siteMan.Save(); UpdateSitesTree(); siteManChanged = true; SitesTreeView.SelectedNode = SitesTreeView.Nodes.Find(sys.Name, true)[0]; } } else if (node.Tag is Instrument) { Instrument inst = (Instrument)node.Tag; DetectionSystem sys = (DetectionSystem)node.Parent.Tag; int index = sys.GetInstruments().IndexOf(inst); if (index > 0) { inst.SetIndex(index - 1); siteMan.Save(); UpdateSitesTree(); siteManChanged = true; SitesTreeView.SelectedNode = SitesTreeView.Nodes.Find(inst.Name, true)[0]; } } }