Esempio n. 1
0
        //Show the information of the article that needs editting
        protected void ShowPageInfo(Pagedb db)
        {
            bool   valid  = true;
            string pageid = Request.QueryString["pageid"];

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


            show_pagetitle.InnerHtml = "";
            show_pagebody.InnerHtml  = "";

            if (valid)
            {
                HTTP_Page page_record = db.FindPage(Int32.Parse(pageid));
                show_pagetitle.InnerHtml = page_record.GetPagetitle();
                show_pagebody.InnerHtml  = page_record.GetPagebody();
            }


            else
            {
                valid = false;
            }
            //Problem
            //1. Edit page did not work
            //Reason: the query in Pagedb.cs is wrong
            //Solution/status: fixed

            //2. The pagebody did not update
            //Reason: Because of the "'" apostrope that make the wrong query
            //Solution/status + Future reference: Look into SQL parameterized query C# ASP.NET
        }
        protected void ShowPageInfo(Pagedb db)
        {
            bool   valid  = true;
            string pageid = Request.QueryString["pageid"];

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


            show_pagetitle.InnerHtml = "";
            show_pagebody.InnerHtml  = "";
            //We will attempt to get the record we need
            if (valid)
            {
                HTTP_Page page_record = db.FindPage(Int32.Parse(pageid));
                show_pagetitle.InnerHtml = page_record.GetPagetitle();
                show_pagebody.InnerHtml  = page_record.GetPagebody();
                edit_page.InnerHtml      = "<div><a href =\"EditPage.aspx?pageid=" + pageid + "\">Edit</a></div>";
            }

            else
            {
                valid = false;
            }


            if (!valid)
            {
                error_summary.InnerHtml = "There was an error finding that article.";
            }
        }
Esempio n. 3
0
        protected void Update_Page(object sender, EventArgs e)
        {
            Pagedb db = new Pagedb();

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

            if (String.IsNullOrEmpty(pageid))
            {
                valid = false;
            }
            if (valid)
            {
                HTTP_Page new_page = new HTTP_Page();
                //update the page
                new_page.SetPagetitle(edit_pagetitle.Text);
                new_page.SetPagebody(edit_pagebody.Text);

                //adding to the database
                try
                {
                    db.Update_Page(Int32.Parse(pageid), new_page);
                    Response.Redirect("~/ShowPage.aspx?pageid=" + pageid);
                }
                catch
                {
                    valid = false;
                }
            }

            if (!valid)
            {
                editpage.InnerHtml = "There was an error updating that article.";
            }
        }
Esempio n. 4
0
        //Finding a particular page in the Daily Bugle Newspaper
        public HTTP_Page FindPage(int id)
        {
            MySqlConnection Connect     = new MySqlConnection(ConnectionString);
            HTTP_Page       result_page = new HTTP_Page();

            try
            {
                string query = "select * from PAGES where pageid = " + id;
                Debug.WriteLine("Connection Initialized...");
                Connect.Open();
                MySqlCommand     cmd       = new MySqlCommand(query, Connect);
                MySqlDataReader  resultset = cmd.ExecuteReader();
                List <HTTP_Page> pages     = new List <HTTP_Page>();

                while (resultset.Read())
                {
                    HTTP_Page currentpage = new HTTP_Page();
                    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 "pagetitle":
                            currentpage.SetPagetitle(value);
                            break;

                        case "pagebody":
                            currentpage.SetPagebody(value);
                            break;
                        }
                    }
                    pages.Add(currentpage);
                }
                result_page = pages[0];
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Something went wrong in the find Page method!");
                Debug.WriteLine(ex.ToString());
            }
            Connect.Close();
            Debug.WriteLine("Database Connection Terminated.");

            return(result_page);
        }
Esempio n. 5
0
        public void Update_Page(int pageid, HTTP_Page new_page)
        {
            string query = "update pages set pagetitle='{0}', pagebody='{1}' where pageid={2}";

            query = String.Format(query, new_page.GetPagetitle(), new_page.GetPagebody(), pageid);
            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 Update_Page Method!");
                Debug.WriteLine(ex.ToString());
            }
            Connect.Close();
        }
Esempio n. 6
0
        //adding a new page
        public void Add_Page(HTTP_Page new_page)
        {
            string query = "insert into pages (pagetitle, pagebody, authorid) values('{0}', '{1}', '{2}')";

            query = string.Format(query, new_page.GetPagetitle(), new_page.GetPagebody(), new_page.GetAuthorid());
            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_Page Method!");
                Debug.WriteLine(ex.ToString());
            }

            Connect.Close();
        }
        protected void Add_Page(object sender, EventArgs e)
        {
            //create connection
            Pagedb db = new Pagedb();

            //create a new particular page
            HTTP_Page new_page = new HTTP_Page();

            //detail about the page
            new_page.SetPagetitle(add_pagetitle.Text);
            new_page.SetPagebody(add_pagebody.Text);
            new_page.SetAuthorid(Int32.Parse(add_authorid.Text));


            //add the page to the database
            db.Add_Page(new_page);

            Response.Redirect("List_Pages.aspx");
            //Problem: When adding authorid in, the new page can not be added to the database, there is sth wrong in the List-Query method
            //Reason: 1. the authorid is added to the insert statement (solved) 2. the authorid is not convert from string into int
            //Status: solved
        }