private void AddSubstation(object sender, RoutedEventArgs e) { List <TreeViewItem> parents = new List <TreeViewItem>(); TreeViewItem selected = SiteConfigurationTreeView.SelectedItem as TreeViewItem; parents = GetParentsOfSelected(parents, selected); Substation substation = new Substation(SubstationNameTextBox.Text); AddComponentToSite(substation, null, null, null, parents, selected); }
public void LoadSiteConfiguration() { int currentLine = 0; var siteConfiguration = File.ReadAllLines(siteConfigurationFile); string[] substations = siteConfiguration[currentLine++].Split(','); string numSubstations = substations[1]; for (int i = 0; i < Convert.ToInt32(numSubstations); i++) { string[] substation = siteConfiguration[currentLine++].Split(','); Substation ss = new Substation(substation[0]); for (int j = 0; j < Convert.ToInt32(substation[1]); j++) { string[] switchgear = siteConfiguration[currentLine++].Split(','); Switchgear sg = new Switchgear(switchgear[0]); ss.Switchgears.Add(sg); for (int k = 0; k < Convert.ToInt32(switchgear[1]); k++) { string[] frame = siteConfiguration[currentLine++].Split(','); Frame f = new Frame(frame[0]); sg.Frames.Add(f); for (int w = 0; w < Convert.ToInt32(frame[1]); w++) { string[] breaker = siteConfiguration[currentLine++].Split(','); CircuitBreaker cb = new CircuitBreaker(breaker[0], breaker[1], breaker[2]); f.CircuitBreakers.Add(cb); } } } listOfSubstations.Add(ss); } }
private void AddComponentToSite( Substation substation, Switchgear switchgear, Frame frame, CircuitBreaker circuitBreaker, List <TreeViewItem> parents, TreeViewItem selected) { bool addedComponent = false; // Whoever finds this giant mess and has to work on it, I'm sorry. foreach (Substation ss in AppBrain.brain.SubStations) { if (addedComponent) { break; } if (substation != null) // If we're removing a substation and the name matches, remove it and break out { AppBrain.brain.SubStations.Add(substation); addedComponent = true; break; } if (ss.SubstationName == parents[1].Header.ToString()) // If we're not deleting a substation but it is a parent of what we're deleting, we must go deeper { if (ss.Switchgears.Count == 0) { ss.Switchgears.Add(switchgear); addedComponent = true; break; } foreach (Switchgear sg in ss.Switchgears) { if (addedComponent) { break; } if (switchgear != null) // If we're removing a switchgear from a substation and the name matches, remove it and break out { ss.Switchgears.Add(switchgear); addedComponent = true; break; } if (sg.SwitchgearName == parents[2].Header.ToString()) // If we're not deleting a switchgear but it's a parent of what we're deleting, we must go deeper { if (sg.Frames.Count == 0) { sg.Frames.Add(frame); addedComponent = true; break; } foreach (Frame f in sg.Frames) { if (addedComponent) { break; } if (frame != null) // If we're removing a frame from a switchgear and the name matches, remove it and break out { sg.Frames.Add(frame); addedComponent = true; break; } if (f.FrameName == parents[3].Header.ToString()) // If we're not deleting a frame but it's a parent of what we're deleting, we must go deeper { if (f.CircuitBreakers.Count == 0) { f.CircuitBreakers.Add(circuitBreaker); addedComponent = true; break; } foreach (CircuitBreaker cb in f.CircuitBreakers) { if (circuitBreaker != null) // IF we're removing a circuit breaker from a frame and the name matches, remove it and break out { f.CircuitBreakers.Add(circuitBreaker); addedComponent = true; break; } // If we reach here and haven't deleted something/broken out, someone is probably hacking the application } } } } } } } UpdateSiteConfiguration(); SiteConfigurationTreeView = AppBrain.brain.PopulateSiteConfiguration(SiteConfigurationTreeView); }