コード例 #1
0
        private void deleteButton_Click(object sender, EventArgs e)
        {
            if (currentPlanetarySystem != null && planetarySystemTreeView.Nodes[0].IsSelected)
            {
                Database.DeletePlanetarySystem(currentPlanetarySystem.Name);
            }
            else
            {
                if (selectedBody != null)
                {
                    if (selectedBody is Planet)
                    {
                        currentPlanetarySystem.RemovePlanet(selectedBody.Name);
                    }
                    else if (selectedBody is Moon)
                    {
                        string planetName  = planetarySystemTreeView.SelectedNode.Parent.Parent.Text;
                        var    planetQuery = from p in currentPlanetarySystem.Planets
                                             where p.Name == planetName
                                             select p;
                        Planet planet = planetQuery.FirstOrDefault();
                        if (planet != null)
                        {
                            planet.RemoveMoon(selectedBody.Name);
                        }
                    }
                    else if (selectedBody is Asteroid)
                    {
                        currentPlanetarySystem.RemoveAsteroid(selectedBody.Name);
                    }
                    else if (selectedBody is ArtificialObject)
                    {
                        currentPlanetarySystem.RemoveArtificialObject(selectedBody.Name);
                    }
                }

                Refresh();
            }
        }