// THIS FUNCTION IS TO SHOW THE PLANET INFORMATION WHICH IS STORED BY ADD PAGE .
        // HERE WE TAKING VALUES FROM DATABASE FOR PLANET TITLE AND PLANET DETAILS.
        protected void ShowplanetInfo(PLANETSDB db)
        {
            bool   valid     = true;
            string planetsid = Request.QueryString["planets_id"];

            if (String.IsNullOrEmpty(planetsid))
            {
                valid = false;
            }


            if (valid)
            {
                planet planets_record = db.Findplanet(Int32.Parse(planetsid));
                planets_title.InnerHtml += planets_record.GetPtitle();
                planets_body.InnerHtml  += planets_record.GetPbody();
            }
            else
            {
                valid = false;
            }


            if (!valid)
            {
                planet.InnerHtml = "There was an error finding that planet.";
            }
        }
Пример #2
0
        // THIS IS TO ADD PLANET PAGES TO THE PLANET PAGES
        protected void Add_Planet(object sender, EventArgs e)
        {
            PLANETSDB db = new PLANETSDB();



            planet new_planet = new planet();

            new_planet.SetPtitle(planets_title.Text);
            new_planet.SetPbody(planets_body.Text);



            db.Addplanet(new_planet);


            Response.Redirect("planetpages.aspx");
        }
Пример #3
0
        // THIS IS THE FUNCTION TO UPDATE THE PLANET WITH THEIR DETAILS
        protected void Update_Planet(object sender, EventArgs e)
        {
            PLANETSDB db = new PLANETSDB();

            bool   valid    = true;
            string planetid = Request.QueryString["planets_id"];

            if (String.IsNullOrEmpty(planetid))
            {
                valid = false;
            }
            if (valid)
            {
                planet new_planet = new planet();

                new_planet.SetPtitle(planets_title.Text);
                new_planet.SetPbody(planets_body.Text);



                try
                {
                    db.Updateplanet(Int32.Parse(planetid), new_planet);
                    Response.Redirect("planetpages.aspx?planetid=" + planetid);
                }
                catch
                {
                    valid = false;
                }
            }

            if (!valid)
            {
                planet.InnerHtml = "There was an error updating that planet.";
            }
        }
Пример #4
0
        // HERE IS THE FUNCTIONALITY TO ADD PLANET INTO THE DATABASE .
        public void Addplanet(planet new_planet)
        {
            string query = "insert into planets (planets_title,planets_body) values ('{0}','{1}')";

            query = String.Format(query, new_planet.GetPtitle(), new_planet.GetPbody());



            MySqlConnection Connect = new MySqlConnection(ConnectionString);
            MySqlCommand    cmd     = new MySqlCommand(query, Connect);

            try
            {
                Connect.Open();
                cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Something went wrong in the Add planet Method!");
                Debug.WriteLine(ex.ToString());
            }

            Connect.Close();
        }
Пример #5
0
        // THIS IS TO UPDATE NEW ENTERIES INTO THE DATABASE.
        public void Updateplanet(int planetid, planet new_planet)
        {
            string query = "update planets set planets_title='{0}', planets_body='{1}' where planets_id='{2}'";

            query = String.Format(query, new_planet.GetPtitle(), new_planet.GetPbody(), planetid);


            MySqlConnection Connect = new MySqlConnection(ConnectionString);
            MySqlCommand    cmd     = new MySqlCommand(query, Connect);

            try
            {
                Connect.Open();
                cmd.ExecuteNonQuery();
                Debug.WriteLine("Executed query " + query);
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Something went wrong in the Updateplanet Method!");
                Debug.WriteLine(ex.ToString());
            }

            Connect.Close();
        }
Пример #6
0
        //HERE IS THE FUNCTIONALITY TO FIND A PLANET FROM THE DATABASE
        public planet Findplanet(int id)
        {
            Debug.WriteLine("method started");

            MySqlConnection Connect = new MySqlConnection(ConnectionString);

            planet result_planet = new planet();


            try
            {
                string query = "select * from planets where planets_id = " + id;
                Debug.WriteLine("Connection Initialized...");

                Connect.Open();

                MySqlCommand cmd = new MySqlCommand(query, Connect);

                MySqlDataReader resultset = cmd.ExecuteReader();


                List <planet> planets = new List <planet>();


                while (resultset.Read())
                {
                    planet currentplanet = new planet();


                    for (int i = 0; i < resultset.FieldCount; i++)
                    {
                        string key   = resultset.GetName(i);
                        string value = resultset.GetString(i);
                        Debug.WriteLine("Attempting to transfer " + key + " data of " + value);

                        switch (key)
                        {
                        case "planets_title":
                            currentplanet.SetPtitle(value);
                            break;

                        case "planets_body":
                            currentplanet.SetPbody(value);
                            break;
                        }
                    }

                    planets.Add(currentplanet);
                }

                result_planet = planets[0];
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Something went wrong in the find planet method!");
                Debug.WriteLine(ex.ToString());
            }

            Connect.Close();
            Debug.WriteLine("Database Connection Terminated.");

            return(result_planet);
        }