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");
            }
        }
Ejemplo n.º 2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            // The below section of code is used to get the List of Authors from the Page table and display them in a dropdown box.

            CMSDB            db       = new CMSDB();
            List <HTTP_Page> pageList = new List <HTTP_Page>();

            //Query to select  distinct Authors from the table to be displayed in the dropdown box.
            pageList = db.ListPages("select distinct pageauthor from page;");

            //Code to insert the list of Authors in the dropdown menu 'page_author_list' present in CreatePage.aspx. ***Not a part of the initial wireframe***
            //Using the foreach loop Authors are retrieved from the pageList object and stored in 'ListItem' which will be added to the drop down list.
            foreach (HTTP_Page page in pageList)
            {
                ListItem item = new ListItem();
                item.Text  = page.GetPageAuthor();
                item.Value = page.GetPageAuthor();
                page_author_list.Items.Add(item);
            }

            //Adding a final List Item which will be used to 'add new authors' into the table. Clicking this will show another textbox in which new author can be added.
            ListItem newAuthorItem = new ListItem();

            newAuthorItem.Text  = "-------------- Add a new Author --------------";
            newAuthorItem.Value = "New";
            page_author_list.Items.Add(newAuthorItem);
        }
        protected void Update_Page(object sender, EventArgs e)
        {
            //This section of the code will get the updated details from the form and call the UpdatePage method.

            // Creating a CMSDB object to use the AddPage(HTTP_Page page) method.
            CMSDB db = new CMSDB();

            //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 updated data in the form will be inserted into the database.
            if (String.IsNullOrEmpty(pageid))
            {
                page_update.InnerHtml = "There was an error updating that student.";
            }
            else
            {
                //Creating a new HTTP_Page object which store the values retrieved from the form.
                HTTP_Page new_page = new HTTP_Page();

                //Code to get the values from the form and set it to the 'new_page' object.
                new_page.SetPageTitle(page_title.Text);
                new_page.SetPageContent(page_content.Text);

                //if page_publish_box is checked true will be stored in pagePublishStatus which is of Boolean type
                if (page_publish_box.Checked)
                {
                    new_page.SetPagePublishStatus(true);
                }
                else
                {
                    new_page.SetPagePublishStatus(false);
                }

                // If 'Add new author' option in selected in the drop down, the data entered in the 'page_author' textbox will be inserted into the db.
                if (page_author_list.SelectedItem.Value == "New")
                {
                    new_page.SetPageAuthor(page_author.Text);
                }
                else
                {
                    new_page.SetPageAuthor(page_author_list.SelectedItem.Value);
                }

                //Calling the UpdatePage function to update the page details into the database using try catch blocks.
                try
                {
                    db.UpdatePage(Int32.Parse(pageid), new_page);
                    //After update the LispPages.aspx will be loaded.
                    Response.Redirect("ListPages.aspx");
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("Something went wrong in the UpdateStudent Method!");
                    Debug.WriteLine(ex.ToString());
                }
            }
        }
Ejemplo n.º 4
0
        protected void Delete_Page(object sender, EventArgs e)
        {
            CMSDB db = new CMSDB();
            //Getting the pageid from the Request object.
            string pageid = Request.QueryString["pageid"];

            //If pageid is not empty perform the delete query and go to ListPages.aspx
            if (!String.IsNullOrEmpty(pageid))
            {
                db.DeletePage(Int32.Parse(pageid));
                Response.Redirect("ListPages.aspx");
            }
        }
Ejemplo n.º 5
0
        protected void Delete_Page(object sender, EventArgs e)
        {
            //Creating an object for the CMSDB file to execute its functions.
            CMSDB db = new CMSDB();

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

            if (!String.IsNullOrEmpty(pageid))
            {
                //Calling the function to delete the record with the specified pageid
                db.DeletePage(Int32.Parse(pageid));
                //Redirecting back to ListPages.aspx
                Response.Redirect("ListPages.aspx");
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            //Creating an object for the CMSDB file to call its functions.
            CMSDB db = new CMSDB();

            //Query to select the pages which are published
            string query = "select * from page where pagestatus=true";

            //Creating an List of <HTTP_Page> object to hold the List of objects returned by the 'public List<HTTP_Page> ListPages(string query)' method in CMSDB.
            List <HTTP_Page> pageList = db.ListPages(query);

            //Code to insert the HTML markup using the 'InnerHtml' property of the 'UserControlHeading1' div tag
            UserControlHeading1.InnerHtml = "<ul class=\"nav navbar-nav\">";
            foreach (HTTP_Page page in pageList)
            {
                UserControlHeading1.InnerHtml += "<li><a runat=\"server\" href=\"ViewPage.aspx?pageid=" + page.GetPageId().ToString() + "\">" + page.GetPageTitle() + "</a></li>";
            }
            UserControlHeading1.InnerHtml += "</ul>";
        }
        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.º 8
0
        protected void Add_Page(object sender, EventArgs e)
        {
            // Creating a CMSDB object to use the AddPage(HTTP_Page page) method.
            CMSDB db = new CMSDB();

            //Creating a new HTTP_Page object which store the values retrieved from the form. s
            HTTP_Page new_page = new HTTP_Page();

            //Code to get the values from the form and set it to the 'new_page' object.
            new_page.SetPageTitle(page_title.Text);

            //if page_publish_box is checked true will be stored in pagePublishStatus which is of Boolean type
            new_page.SetPageContent(page_content.Text);
            if (page_publish_box.Checked)
            {
                new_page.SetPagePublishStatus(true);
            }
            else
            {
                new_page.SetPagePublishStatus(false);
            }

            // If 'Add new author' option in selected in the drop down, the data entered in the 'page_author' textbox will be inserted into the db.
            if (page_author_list.SelectedItem.Value == "New")
            {
                new_page.SetPageAuthor(page_author.Text);
            }
            else
            {
                new_page.SetPageAuthor(page_author_list.SelectedItem.Value);
            }

            //Calling the AddPage function to insert the page details into the database.
            db.AddPage(new_page);

            //Going back to ListPages.aspx after inserting the data.
            Response.Redirect("ListPages.aspx");
        }
Ejemplo n.º 9
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //Creating a CMSDB object to call the ListPages(String query) function.
            CMSDB db = new CMSDB();

            //Query that will be passed to the ListPages(String query) function.
            String query = "Select * from Page";

            //Code to get the text entered in the searchbox.
            string searchkey = "";

            if (Page.IsPostBack)
            {
                searchkey = page_title_search.Text;
            }
            //If text is entered in the searchbox a 'Where' clause with 'like' is added to the query.
            if (searchkey != "")
            {
                query += " WHERE PAGETITLE like '%" + searchkey + "%' ";
            }

            //Creating an List of <HTTP_Page> object to hold the List of objects returned by the 'public List<HTTP_Page> ListPages(string query)' method in CMSDB.
            List <HTTP_Page> pageList = db.ListPages(query);

            //Code to loop through pageList, which contains a List of HTTP_Page object, and get the required details which will be appeded to the table.
            foreach (HTTP_Page page in pageList)
            {
                //Getting the required fields from each record in the table.
                int    pageid          = page.GetPageId();
                string pagetitle       = page.GetPageTitle();
                string pageauthor      = page.GetPageAuthor();
                string pagepublishdate = page.GetPagePublishDate();
                //Creating a DateTime object to hold the Page Publish Date.
                DateTime date = Convert.ToDateTime(pagepublishdate);
                string   pagepublishstatus = page.GetPagePublishStatus().ToString();

                //Creating a HtmlTableRow object trow which will be used to store a single row and eventually be inserted in the HTML markup's <table id="table1"> tag
                HtmlTableRow trow = new HtmlTableRow();

                //Creating a HtmlTableCell object which will contain individual cells that will be put into the HtmlTableRow tRow that was just created.
                HtmlTableCell cell1 = new HtmlTableCell();
                if (pagepublishstatus.ToLower() == "true")
                {
                    cell1.InnerHtml = "<a href=\"ViewPage.aspx?pageid=" + pageid + "\">" + pagetitle + "</a>";
                }
                else
                {
                    cell1.InnerText = pagetitle;
                }
                //Adding the current HtmlTableCell (cell1) in the HttpTableRow tRow.
                trow.Controls.Add(cell1);

                //Creating and adding  HtmlTableCell (cell2) in the HttpTableRow tRow.
                HtmlTableCell cell2 = new HtmlTableCell();
                cell2.InnerText = pageauthor;
                trow.Controls.Add(cell2);

                //Creating and adding  HtmlTableCell (cell3) in the HttpTableRow tRow.
                HtmlTableCell cell3 = new HtmlTableCell();
                //Displaying the Date in the 'dd/MMM/yyyy' format in the markup by using the ToString function of dateTime.
                cell3.InnerText = date.ToString("dd/MMM/yyyy");
                trow.Controls.Add(cell3);

                //Creating and adding  HtmlTableCell (cell4) in the HttpTableRow tRow.
                HtmlTableCell cell4 = new HtmlTableCell();
                if (pagepublishstatus.ToLower() == "true")
                {
                    cell4.InnerHtml = "<p> Published </p>";
                }
                else
                {
                    cell4.InnerHtml = "<p> Unpublished </p>";
                }
                trow.Controls.Add(cell4);

                //Creating and adding  HtmlTableCell (cell5) in the HttpTableRow tRow.
                HtmlTableCell cell5 = new HtmlTableCell();
                if (pagepublishstatus.ToLower() == "true")
                {
                    cell5.InnerHtml += "<input type=\"button\" value=\"View\" onclick=\"location.href='ViewPage.aspx?pageid=" + page.GetPageId().ToString() + "'\" class=\"btn btn-primary rowButton\"/>";
                }
                else
                {
                    cell5.InnerHtml += "<input type=\"button\" value=\"View\" onclick=\"location.href='ViewPage.aspx?pageid=" + page.GetPageId().ToString() + "'\" class=\"btn btn-primary rowButton\" disabled/>";
                }
                cell5.InnerHtml += "<input type=\"button\" value=\"Edit\" onclick=\"location.href='UpdatePage.aspx?pageid=" + page.GetPageId().ToString() + "'\" class=\"btn btn-primary rowButton\"/>";
                trow.Controls.Add(cell5);

                //Adding the current row to the Table
                table1.Rows.Add(trow);
            }
        }