Пример #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            // search key
            string searchkey = "";

            if (Page.IsPostBack)
            {
                searchkey = page_search.Text;
            }

            // clear result
            page_result.InnerHtml = "";
            // Table_Result


            // default query: select everything
            string query = "SELECT * FROM pages";

            if (searchkey != "")
            {
                query += " WHERE PAGEID LIKE '%" + searchkey + "%' ";
                query += "OR PAGETITLE LIKE '%" + searchkey + "%' ";
                query += "OR PAGEBODY LIKE '%" + searchkey + "%' ";
            }

            // order by isPublished, show those published one first
            query += " ORDER BY isPublished DESC;";

            // todo: when click table head, order by the clicked column


            // get pages from websitedb.cs
            List <HTMLPAGE> Pages = new List <HTMLPAGE>();

            // get result with db class function
            Pages = new WEBSITEDB().List_Query(query);

            foreach (HTMLPAGE page in Pages)
            {
                //page_result.InnerHtml += "<td>";

                string pageid      = page.PageId;
                string pagetitle   = page.PageTitle;
                string pagebody    = page.PageBody;
                string ispublished = page.IsPublished;

                //< div class="col-xs-3">PAGE ID</div>

                page_result.InnerHtml += "<div class=\"row\" style=\"margin-top: 10px; padding-top: 10px; border-top: solid #DDD 1px;\">";
                page_result.InnerHtml += "<div class=\"col-xs-3\">" + pageid + "</div>";
                page_result.InnerHtml += "<div class=\"col-xs-3\"> <a href=\"DetailPage.aspx?pageid=" + pageid + "\">" + pagetitle + "</a></div>";
                //page_result.InnerHtml += "<div class=\"col-xs-3\">" + pagebody + "</div>";
                page_result.InnerHtml += "<div class=\"col-xs-3\">" + ispublished + "</div>";
                page_result.InnerHtml += "<div class=\"col-xs-3\">" +
                                         "<a class=\"btn btn-info\" href=\"EditPage.aspx?pageid=" + pageid + "\">Edit</a>" +
                                         "</div>";
                page_result.InnerHtml += "</div>";
            }
        }
Пример #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            // if goes here directly, something goes wrong.
            string pageid = Request.QueryString["pageid"];

            if (String.IsNullOrEmpty(pageid))
            {
                PageTitle.InnerText = "ERROR";
                PageBody.InnerText  = "This page does not exist";
                return;
            }

            // query with pageid
            string query = "SELECT * FROM pages WHERE pageid = " + pageid;

            List <HTMLPAGE> Pages = new WEBSITEDB().List_Query(query);

            HTMLPAGE page        = Pages[0];
            string   pagetitle   = page.PageTitle;
            string   pagebody    = page.PageBody;
            string   isPublished = page.IsPublished;

            // get the page id first
            PageTitle.InnerText = pagetitle;
            PageBody.InnerText  = pagebody;

            // add edit button
            PageAction.InnerHtml =
                "<a class=\"btn btn-info\" href=\"EditPage.aspx?pageid=" + pageid + "\">Edit</a>";

            // add delete or recover button
            if (isPublished == "True" || isPublished == "1")
            {
                // if isPublished, hide recover button
                RecoverBtn.Style.Add("display", "none");
            }
            else
            {
                // if not, hide delete button
                DeleteBtn.Style.Add("display", "none");
            }
        }
        protected void Recover_Click(object sender, EventArgs e)
        {
            // get pageid
            string pageid = Request.QueryString["pageid"];

            bool isPublished = true;

            // execute update query
            //UPDATE pages SET pagetitle = "123", pagebody = "321", isPublished = true WHERE pageid = 1
            string query = "UPDATE pages SET isPublished = " + isPublished +
                           " WHERE pageid = " + pageid;

            // db instance
            WEBSITEDB db = new WEBSITEDB();

            // execute crud query
            db.CRUD_Query(query);

            Response.Redirect("DetailPage.aspx?pageid=" + pageid);
        }
Пример #4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            // set up navigation
            //navigation.InnerHtml = "<li><a href=\"Manage\">Manage</a></li>";
            // clean navigation
            navigation.InnerHtml = "";

            // query for page titles
            string query = "SELECT * FROM pages WHERE isPublished = true";
            // get page titles from db
            List <HTMLPAGE> Pages = new WEBSITEDB().List_Query(query);

            foreach (HTMLPAGE page in Pages)
            {
                string pagetitle = page.PageTitle;
                string pageid    = page.PageId;

                navigation.InnerHtml += "<li> <a href=\"DetailPage.aspx?pageid=" + pageid + "\">" + pagetitle + "</a></li>";
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                // get pageid
                string pageid = Request.QueryString["pageid"];
                // if there is not pageid in url
                if (String.IsNullOrEmpty(pageid))
                {
                    pageWrapper.InnerText = "<h1>ERROR: This page does not exist</h1>";
                    return;
                }

                // show existed data
                // get pagetitle and pagebody and isPublished query
                // if isPublished, remain delete button. If not, show recover button
                string query = "SELECT * FROM pages WHERE pageid = " + pageid;

                List <HTMLPAGE> Pages = new WEBSITEDB().List_Query(query);

                foreach (HTMLPAGE page in Pages)
                {
                    // show current data
                    PageTitle.Text = page.PageTitle;
                    PageBody.Text  = page.PageBody;

                    // if isPublished, hide recover button. If not, hide recover button
                    if (page.IsPublished == "True" || page.IsPublished == "1")
                    {
                        // if isPublished, hide recover button
                        RecoverBtn.Style.Add("display", "none");
                    }
                    else
                    {
                        // if not, hide delete button
                        DeleteBtn.Style.Add("display", "none");
                    }
                }
            }
        }
        protected void Edit_Click(object sender, EventArgs e)
        {
            string pagetitle = PageTitle.Text;
            string pagebody  = PageBody.Text;

            // get pageid
            string pageid = Request.QueryString["pageid"];

            // execute update query
            //UPDATE pages SET pagetitle = "123", pagebody = "321", isPublished = true WHERE pageid = 1
            string query = "UPDATE pages SET pagetitle = \"" + pagetitle + "\"" +
                           ", pagebody = \"" + pagebody + "\"" +
                           " WHERE pageid = " + pageid;

            // db instance
            WEBSITEDB db = new WEBSITEDB();

            // execute crud query
            db.CRUD_Query(query);

            Response.Redirect("DetailPage.aspx?pageid=" + pageid);
        }