public DetectionSystem(Facility parent, string name, uint id) : base(parent, name, id) { parent.GetSystems().Add(this); instruments = new List <Instrument>(); declarationInstrument = null; eventGenerators = new List <EventGenerator>(); events = new List <Event>(); }
private void DownButton_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 < siteMan.GetSites().Count - 1) { 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 < site.GetFacilities().Count - 1) { site.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 < fac.GetSystems().Count - 1) { fac.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 < sys.GetInstruments().Count - 1) { inst.SetIndex(index + 1); siteMan.Save(); UpdateSitesTree(); siteManChanged = true; SitesTreeView.SelectedNode = SitesTreeView.Nodes.Find(inst.Name, true)[0]; } } }
public ReturnCode LoadFromXML(string fileName) { if (!File.Exists(fileName)) { return(ReturnCode.FILE_DOESNT_EXIST); } try { XmlDocument doc = new XmlDocument(); doc.Load(fileName); presets.Clear(); foreach (XmlNode presetNode in doc.DocumentElement.ChildNodes) { Preset newPreset = new Preset(presetNode.Attributes["name"]?.InnerText); foreach (XmlNode siteNode in presetNode.ChildNodes) { Site site = siteMan.GetSites().Single(s => s.Name == siteNode.Attributes["name"]?.InnerText); foreach (XmlNode facilityNode in siteNode.ChildNodes) { Facility fac = site.GetFacilities().Single(s => s.Name == facilityNode.Attributes["name"]?.InnerText); foreach (XmlNode systemNode in facilityNode.ChildNodes) { DetectionSystem sys = fac.GetSystems().Single(s => s.Name == systemNode.Attributes["name"]?.InnerText); foreach (XmlNode instrumentNode in systemNode.ChildNodes) { if (instrumentNode.Name == "Instrument") { Instrument inst = sys.GetInstruments().Single(i => i.Name == instrumentNode.Attributes["name"]?.InnerText); if (instrumentNode.Attributes["checked"] != null) { if (instrumentNode.Attributes["checked"].InnerText == "true") { newPreset.GetActiveInstruments().Add(inst); foreach (XmlNode chanNode in instrumentNode.ChildNodes) { Channel chan = inst.GetChannels().Single(c => c.Name == chanNode.Attributes["name"]?.InnerText); foreach (XmlNode checkNode in chanNode.ChildNodes) { if (checkNode.Attributes["checked"] != null) { if (checkNode.Attributes["checked"].InnerText == "true") { newPreset.AddChannel(chan, int.Parse(checkNode.Attributes["chart"].InnerText)); } } } } } } } else if (instrumentNode.Name == "EventGenerator") { XmlNode eventGenNode = instrumentNode; EventGenerator eventGenerator = sys.GetEventGenerators().Single(e => e.Name == eventGenNode.Attributes["name"]?.InnerText); if (eventGenNode.Attributes["checked"].InnerText == "true") { newPreset.GetActiveEventGenerators().Add(eventGenerator); } } else { return(ReturnCode.CORRUPTED_FILE); } } } } } presets.Add(newPreset); } } catch { return(ReturnCode.FAIL); } return(ReturnCode.SUCCESS); }