Пример #1
0
        //Fill the authors dropdown with the authors names from the authors table
        protected void populate_authordropdown()
        {
            WebsiteDB dB    = new WebsiteDB();
            string    query = "select * from author";

            // try to send the query to the database to select all the authors
            try
            {
                List <Dictionary <string, string> > page = dB.List_Query(query);

                if (page.Count > 0)
                {
                    //for each author add the author and authorid to the list items of the dropdown list
                    foreach (Dictionary <String, String> pagedata in page)
                    {
                        string   authorName = pagedata["author_name"];
                        string   authorid   = pagedata["author_id"];
                        ListItem authors    = new ListItem(authorName, authorid);
                        ddpage_author.Items.Add(authors);
                    }
                }
            }
            catch (Exception ex)
            {
                //Show the error alert if the query does not work
                alert.Visible    = true;
                output.InnerHtml = "Error. Contact Support " + ex;
            }
        }
Пример #2
0
        protected void yes_delete_Click(object sender, EventArgs e)
        {
            Boolean flag = true;

            //get the pageid from the request and convert the string to int
            int pageid = Convert.ToInt32(Request.QueryString["pageid"]);

            //if the id that requested is null or is 0 set the flag to false
            if (pageid.Equals(null) || pageid.Equals(0))
            {
                flag = false;
            }

            //if the flag is true continue with the logic
            if (flag)
            {
                WebsiteDB db = new WebsiteDB();

                //use the websitedb class and delete the page from the table
                db.DeleteWebpage(pageid);

                //redirect the user to the listwebpages page
                Response.Redirect("ListWebPages.aspx");
            }
        }
Пример #3
0
        protected void AddButton_Click(object sender, EventArgs e)
        {
            WebsiteDB db = new WebsiteDB();

            Webpage webpage = new Webpage();

            //set the title, body and author from the textbox to the webpage class
            webpage.set_W_title(txtpage_title.Text);
            webpage.set_W_body(txtpage_body.InnerText);
            webpage.set_W_author(ddpage_author.SelectedValue);
            //if user checks the publish checkbox set the state to published and publish date to the current date and time
            if (chkpublish.Checked == true)
            {
                webpage.set_W_publish_state("Published");
                //convert date and time to ex.(Saturday, 15 July 2019 5:00 AM)
                webpage.set_W_publish_date(DateTime.Now.ToString("dddd, dd MMMM yyyy h:mm tt"));
            }
            //if user doesnt check the checkbox set the state to not published
            else
            {
                webpage.set_W_publish_state("Not Published");
            }
            //use the webpage class to pass the variables to the addwebpage method in the database class
            db.AddWebpage(webpage);

            Response.Redirect("ListWebpages.aspx");
        }
        protected void showpageinfo()
        {
            WebsiteDB dB   = new WebsiteDB();
            Boolean   flag = true;

            //get the pageid from the request and convert the string to int
            int pageid = Convert.ToInt32(Request.QueryString["pageid"]);

            //if the id that requested is null or is 0 set the flag to false
            if (pageid.Equals(null) || pageid.Equals(0))
            {
                flag = false;
            }

            //if the flag is true continue with the logic
            if (flag)
            {
                //find the webpage and set its values to the variables in the webpage class
                Webpage webpage = dB.FindWebPage(pageid);

                //get the data from the webpage class of the webpage requested
                //set the text boxes and the dropdown to the variables from the webpage class
                pagename.InnerText          = webpage.get_W_title();
                txtpage_title.Text          = webpage.get_W_title();
                txtpage_body.InnerText      = webpage.get_W_body();
                ddpage_author.SelectedValue = webpage.get_W_author();
            }
            //if false show the alert of the error
            else
            {
                alert.Visible = true;
                alert.Attributes.Add("class", "alert alert-danger");
                output.InnerHtml = "Error please go back home";
            }
        }
        //publish the page if the user clicks the publish button
        protected void publish_button_Click(object sender, EventArgs e)
        {
            WebsiteDB dB = new WebsiteDB();

            Boolean flag = true;
            //get the pageid from the request and convert the string to int
            int pageid = Convert.ToInt32(Request.QueryString["pageid"]);

            //if the id that requested is null or is 0 set the flag to false
            if (pageid.Equals(null) || pageid.Equals(0))
            {
                flag = false;
            }

            //if the flag is true continue with the logic
            if (flag)
            {
                //convert date and time to ex.(Saturday, 15 July 2019 5:00 AM)
                string date = DateTime.Now.ToString("dddd, dd MMMM yyyy h:mm tt");

                //send the pageid and todays date to the publish webpage method in the websitedb class
                dB.publishWebpage(pageid, date);

                //show an alert for the publish success
                alert.Visible    = true;
                output.InnerHtml = "Publish Success!";
            }
            //if pageid is not valid show the alert and the error
            else
            {
                alert.Visible    = true;
                output.InnerHtml = "Error occured. Please try again";
            }
        }
        //if the user clicks the unpublish button change the webpage to not published
        protected void unpublish_button_Click(object sender, EventArgs e)
        {
            WebsiteDB dB   = new WebsiteDB();
            Boolean   flag = true;

            //get the pageid from the request and convert the string to int
            int pageid = Convert.ToInt32(Request.QueryString["pageid"]);

            //if the id that requested is null or is 0 set the flag to false
            if (pageid.Equals(null) || pageid.Equals(0))
            {
                flag = false;
            }

            //if the flag is true continue with the logic
            if (flag)
            {
                //send the pageid to unpublish the page
                dB.unPublishWebpage(pageid);

                //show the alert the un publish was success
                alert.Visible    = true;
                output.InnerHtml = "Un Published Success!";
            }
            //if flase show an alert for the error
            else
            {
                alert.Visible = true;
                alert.Attributes.Add("class", "alert alert-danger");
                output.InnerHtml = "Error please go back home";
            }
        }
Пример #7
0
        protected void Page_Load(object sender, EventArgs e)
        {
            WebsiteDB db = new WebsiteDB();

            list_pages.InnerHtml = "";
            //set the user input of the search to a variable
            string search_text = webpage_search.Text.ToString();

            //create a query with the user input in the query
            string query = "select * from pages join author on publish_author = author_id ";

            //where page_title like '%" + search_text + "%' join author on publish_author = author_id


            if (search_text != " ")
            {
                query += "where page_title like '%" + search_text + "%'";
            }
            try
            {
                List <Dictionary <String, String> > rs = db.List_Query(query);
                list_pages.InnerHtml += "<table class=\"table\"><thead><tr>" +
                                        "<th>Page Title</th>" +
                                        "<th>Author</th>" +
                                        "<th>State</th>" +
                                        "<th>Update/Delete</th>" +
                                        "</tr></thead><tbody>";

                foreach (Dictionary <String, String> row in rs)
                {
                    string pageid = row["page_id"];
                    list_pages.InnerHtml += "<tr>";

                    string pagetitle = row["page_title"];
                    list_pages.InnerHtml += "<td><a href=\"SinglePage.aspx?pageid=" + pageid + "\">" + pagetitle + "</a></td>";

                    string pageauthor = row["author_name"];
                    list_pages.InnerHtml += "<td>" + pageauthor + "</td>";

                    string pagestate = row["publish_state"];
                    list_pages.InnerHtml += "<td>" + pagestate + "</td>";

                    //was supposed to be icons but due to bootstrap 4 dropping glyphicon in v4.4 had to stick to badges
                    list_pages.InnerHtml += "<td><a href=\"UpdatePage.aspx?pageid=" + pageid + "\">" +
                                            "<span class=\"badge badge-pill badge-info\">Edit</span></a>" +
                                            "<a href=\"DeletePage.aspx?pageid=" + pageid + "&pagetitle=" + pagetitle + "\"><span class=\"badge badge-pill badge-danger\">Delete</span></a></td>";

                    list_pages.InnerHtml += "</tr>";
                }
                list_pages.InnerHtml += "</tbody></table>";
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.ToString());
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            bool flag   = true;
            int  pageid = Convert.ToInt32(Request.QueryString["pageid"]);

            if (pageid.Equals(null))
            {
                flag = false;
            }

            if (flag == true)
            {
                var    db    = new WebsiteDB();
                string query = "select * from pages join author on publish_author = author_id where page_id = " + pageid;
                List <Dictionary <string, string> > page = db.List_Query(query);

                if (page.Count > 0)
                {
                    foreach (Dictionary <String, String> pagedata in page)
                    {
                        Webpage webpage      = new Webpage();
                        string  pagetitle    = pagedata["page_title"];
                        string  pagebody     = pagedata["page_body"];
                        string  pageauthor   = pagedata["author_name"];
                        string  publishstate = pagedata["publish_state"];
                        string  publishdate  = pagedata["publish_date"];

                        title.InnerHtml = pagetitle;
                        webpage.set_W_title(pagetitle);
                        date.InnerHtml = publishdate;
                        body.InnerHtml = pagebody;
                        webpage.set_W_body(pagebody);
                        author.InnerHtml = pageauthor;
                        webpage.set_W_author(pageauthor);
                        state.InnerHtml = publishstate;
                        webpage.set_W_publish_state(publishstate);
                    }
                }
            }
        }
        protected void UpdateButton_Click(object sender, EventArgs e)
        {
            WebsiteDB dB      = new WebsiteDB();
            Webpage   webpage = new Webpage();

            Boolean flag = true;

            //get the pageid from the request and convert the string to int
            int pageid = Convert.ToInt32(Request.QueryString["pageid"]);

            //if the id that requested is null or is 0 set the flag to false
            if (pageid.Equals(null) || pageid.Equals(0))
            {
                flag = false;
            }

            //if the flag is true continue with the logic
            if (flag)
            {
                //save the changes to the webpage in the webpage class
                webpage.set_W_title(txtpage_title.Text);
                webpage.set_W_body(txtpage_body.InnerText);
                webpage.set_W_author(ddpage_author.SelectedValue);

                //pass the new changes to the updatewebpages method in the websitedb class
                dB.UpdateWebpage(pageid, webpage);

                //once updated show the newly updated page
                Response.Redirect("SinglePage.aspx?pageid=" + pageid);
            }
            //if false show the alert of the error
            else
            {
                alert.Visible = true;
                alert.Attributes.Add("class", "alert alert-danger");
                output.InnerHtml = "Error cannot add";
            }
        }
Пример #10
0
        protected void Page_Load(object sender, EventArgs e)
        {
            var db = new WebsiteDB();
            //only select the pages that have been published
            string query = "select page_id, page_title from pages where publish_state = 'Published'";
            List <Dictionary <string, string> > page = db.List_Query(query);



            nav.InnerHtml = "<ul class=\"nav navbar-nav\">" +
                            "<li class=\"nav-item\"><a runat=\"server\" href=\"ListWebPages.aspx\" class=\"nav-link\">Dashboard</a></li>";

            if (page.Count > 0)
            {
                foreach (Dictionary <String, String> pagedata in page)
                {
                    string pagetitle = pagedata["page_title"];
                    string pageid    = pagedata["page_id"];

                    nav.InnerHtml += "<li class=\"nav-item\"><a runat = \"server\" href = \"SinglePage.aspx?pageid=" + pageid + "\" class=\"nav-link\">" + pagetitle + "</a></li>";
                }
                nav.InnerHtml += "</ul>";
            }
        }