Ejemplo n.º 1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            // Creating an object of the CMSDB class to call the 'ViewPage(int pageid)' functions in the database file.
            CMSDB db = new CMSDB();

            //Getting the pageid passed in the URL to select the current page from the database
            string pageid = Request.QueryString["pageid"];

            //If pageid is empty the custom error message will be written, otherwise the page details will be fetched from the database.
            if (String.IsNullOrEmpty(pageid))
            {
                pageId.InnerHtml = "Error findinf the page.";
            }
            else
            {
                //Creating an object of HTTP_Page to hold the HTTP_Page object which will be returned by the db.ViewPage(pageId) funciton.
                HTTP_Page page_record = db.ViewPage(Int32.Parse(pageid));

                //Using getters to get the values from the page_record and putting them in their respective <div> tags.
                page_title.InnerHtml = page_record.GetPageTitle();
                page_body.InnerHtml  = page_record.GetPageContent();

                //Creating a DateTime object which will hold the PUBLISHDATE received from the database.
                DateTime date = Convert.ToDateTime(page_record.GetPagePublishDate());

                //Converting the date into the 'DD/MMM/YYYY/ format and writing them in the required div tags.
                page_publish_date.InnerHtml += date.ToString("dd/MMM/yyyy");
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                //If the page is not being loaded in response to a postBack the ShowPage()
                CMSDB db = new CMSDB();

                // The below section of code is used to get the List of Authors from the Page table and display them in a dropdown box. Similar to CreatePage.aspx.cs
                List <HTTP_Page> pageList = new List <HTTP_Page>();
                pageList = db.ListPages("select distinct pageauthor from page;");
                foreach (HTTP_Page page in pageList)
                {
                    ListItem item = new ListItem();
                    item.Text  = page.GetPageAuthor();
                    item.Value = page.GetPageAuthor();
                    page_author_list.Items.Add(item);
                }
                ListItem newAuthorItem = new ListItem();
                newAuthorItem.Text  = "-------------- Add a new Author --------------";
                newAuthorItem.Value = "New";
                page_author_list.Items.Add(newAuthorItem);


                //Getting the pageid from the Request object
                string pageid = Request.QueryString["pageid"];

                //If pageid is empty the custom error message will be written, otherwise the page details will be fetched from the database and shown in the input fields.
                if (String.IsNullOrEmpty(pageid))
                {
                    page_update.InnerHtml = "There was an error finding that student.";
                }
                else
                {
                    HTTP_Page page_record = db.ViewPage(Int32.Parse(pageid));
                    page_update.InnerHtml          = page_record.GetPageTitle();
                    page_title.Text                = page_record.GetPageTitle();
                    page_content.Text              = page_record.GetPageContent();
                    page_author_list.SelectedValue = page_record.GetPageAuthor();
                    page_publish_date.Text         = page_record.GetPagePublishDate();
                }
            }
        }
Ejemplo n.º 3
0
        public void UpdatePage(int pageid, HTTP_Page new_page)
        {
            //SQL query to update the PAGE table with the new values.
            string query = "update PAGE set PAGETITLE='{0}', PAGEBODY='{1}', PAGEAUTHOR='{2}', PAGESTATUS='{3}' where PAGEID = '{4}'";


            //To update values for PAGESTATUS field which is of type boolean. 0 is inserted if PAGESTATUS is false, 1 if true.
            int page_publish_value = 0;

            if (new_page.GetPagePublishStatus())
            {
                page_publish_value = 1;
            }

            //Getting data from 'new_page' object which is passed in the parameter of the function during the function call. ('db.AddPage(new_page)')
            query = String.Format(query, new_page.GetPageTitle(), new_page.GetPageContent(), new_page.GetPageAuthor(), page_publish_value, pageid);

            //Creating a new connection object using the connection string and Creating an object for a MySqlCommand using query and the connect object.
            MySqlConnection Connect = new MySqlConnection(ConnectionString);
            MySqlCommand    cmd     = new MySqlCommand(query, Connect);

            try
            {
                //Opening the connection and executing the query on the database.
                Connect.Open();
                cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Exception in the updatePage(int pageId, HTTP_Page page) method!");
                Debug.WriteLine(ex.ToString());
            }

            finally
            {
                //Database connection is closed.
                Connect.Close();
            }
        }
Ejemplo n.º 4
0
        public void AddPage(HTTP_Page new_page)
        {
            //SQL query to insert data into the PAGE table
            string query = "insert into PAGE (PAGETITLE,PAGEBODY,PAGEDATE,PAGESTATUS,PAGEAUTHOR) values ('{0}','{1}',now(),'{2}','{3}')";

            //To insert values for PAGESTATUS field which is of type boolean. 0 is inserted if PAGESTATUS is false, 1 if true.
            int page_publish_value = 0;

            if (new_page.GetPagePublishStatus())
            {
                page_publish_value = 1;
            }

            //Getting data from 'new_page' object which is passed in the parameter of the function during the function call. ('db.AddPage(new_page)')
            query = String.Format(query, new_page.GetPageTitle(), new_page.GetPageContent(), page_publish_value, new_page.GetPageAuthor());

            //Creating a new connection object using the connection string and Creating an object for a MySqlCommand using query and the connect object.
            MySqlConnection Connect = new MySqlConnection(ConnectionString);
            MySqlCommand    cmd     = new MySqlCommand(query, Connect);

            //try catch and finally for exception handling
            try
            {
                Connect.Open();
                cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Exception in the AddPage(HTTP_Page new_page) method");
                Debug.WriteLine(ex.ToString());
            }
            finally
            {
                Connect.Close();
            }
        }