Exemplo n.º 1
0
        private OnBoardPlanets fillPlanetDetails(int selectedOptionId, OnBoardPlanets form)
        {
            //IEnumerable<XElement> listaPlanets = xDoc.Root.Elements("planets").Elements("planet");
            XElement planetElement = xDoc.Root.Elements("planets").Elements("planet").ElementAt(selectedOptionId);

            String planetName      = planetElement.Element("name").Value.ToString();
            String planetSector    = planetElement.Element("sector").Value.ToString();
            String planetFiliation = planetElement.Element("filiation").Value.ToString();
            String planetLatitude  = planetElement.Element("situation").Element("lat").Value.ToString();
            String planetLongitude = planetElement.Element("situation").Element("long").Value.ToString();
            String planetNatives   = planetElement.Element("natives").Value.ToString();
            String imageName       = FindFileByName(Path.Combine(Application.StartupPath,
                                                                 "assets", "planetes"), planetName);
            String planetParsecs = planetElement.Element("situation").Element("parsecs").Value.ToString();

            IEnumerable <XElement> planetRoutes = planetElement.Element("hyperspaceRoute").Elements("route");

            List <String> routesList = new List <String>();

            foreach (XElement route in planetRoutes)
            {
                routesList.Add(route.Value);
            }

            form.PlanetName      = planetName;
            form.PlanetSector    = planetSector;
            form.PlanetFiliation = planetFiliation;
            form.PlanetLatitude  = planetLatitude;
            form.PlanetLongitude = planetLongitude;
            form.PlanetNatives   = planetNatives;
            form.ImagePath       = Image.FromFile(Path.Combine(Application.StartupPath,
                                                               "assets", "planetes", imageName ?? placeHolder));
            form.PlanetRoutesList = routesList;
            form.PlanetParsecs    = planetParsecs;
            return(form);
        }
Exemplo n.º 2
0
        private void HandleFormChange(object sender, TreeViewEventArgs e)
        {
            selectedOptionId   = Convert.ToInt32(treeView1.SelectedNode.Tag);
            selectedOptionText = treeView1.SelectedNode.Text.ToString();

            Type     type = sender.GetType();
            TreeView controller;

            //if (sender is not ) return;
            try
            {
                controller = (TreeView)sender;
            }
            catch (Exception ex)
            {
                return;
            }

            var btnName          = controller.Name;
            var selectedNodeText = controller.SelectedNode.Text.ToString();
            var selectedNodeTag  = controller.SelectedNode.Tag.ToString();



            if (selectedNodeTag != "-1")
            {
                var treeNodeText     = controller.Text.ToString().ToLower();
                var selectedCategory = selectedCategoryName.ToLower();

                dynamic form;

                switch (selectedCategory)
                {
                case "planets":
                    form = new OnBoardPlanets();
                    form = fillPlanetDetails(selectedOptionId, form);
                    break;

                case "regions":
                    form = new OnBoardRegions();
                    form = fillRegionDetails(selectedOptionId, form);
                    break;

                case "routes":
                    form = new OnBoardRoutes();
                    form = fillRouteDetails(selectedOptionId, form);
                    break;

                case "maps":
                    form = new OnBoardMaps();
                    form = fillMapDetails(form);
                    break;

                default:
                    form = new OnBoardPlanets();
                    form = fillPlanetDetails(selectedOptionId, form);
                    break;
                }

                pnlSelectedCategory.Controls.Clear();

                if (form == null)
                {
                    return;
                }

                if (form.AutoScroll)
                {
                    form.AutoScroll = false;
                }

                pnlSelectedCategory.Controls.Add(form);
                form.Show();
            }
        }