Exemple #1
0
        protected void Update_PageCMS(object sender, EventArgs e)
        {
            PagesCMSDB db = new PagesCMSDB();

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

            if (String.IsNullOrEmpty(pagecmsid))
            {
                valid = false;
            }
            if (valid)
            {
                PageCMS new_pagecms = new PageCMS();
                //sets page data
                new_pagecms.SetCMStitle(pagecms_title.Text);
                new_pagecms.SetCMSbody(pagecms_body.Text);

                //updates page in the database
                try
                {
                    db.UpdatePageCMS(Int32.Parse(pagecmsid), new_pagecms);
                    Response.Redirect("ShowPageCMS.aspx?pagecmsid=" + pagecmsid);
                }
                catch
                {
                    valid = false;
                }
            }

            if (!valid)
            {   //if not valid
                PageUpdateCMS.InnerHtml = "There was an error updating that page.";
            }
        }
Exemple #2
0
        protected void ShowPageInfo(PagesCMSDB db)
        {
            bool   valid     = true;
            string pagecmsid = Request.QueryString["pagecmsid"];

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


            if (valid)
            {
                PageCMS pagecms_record = db.FindPageCMS(Int32.Parse(pagecmsid));

                pagecms_title.Text = pagecms_record.GetCMStitle();
                pagecms_body.Text  = pagecms_record.GetCMSbody();
            }

            //if not valid
            if (!valid)
            {
                PageUpdateCMS.InnerHtml = "There was an error finding that page.";
            }
        }
        public PageCMS FindPageCMS(int pagecmsid)
        {
            MySqlConnection Connect = new MySqlConnection(ConnectionString);

            PageCMS result_pagecms = new PageCMS();


            try
            {
                string query = "select * from pagecmsinfo where pagecmsid = " + pagecmsid;
                Debug.WriteLine("Connection Initialized...");

                Connect.Open();

                MySqlCommand cmd = new MySqlCommand(query, Connect);

                MySqlDataReader resultset = cmd.ExecuteReader();

                List <PageCMS> pagecms = new List <PageCMS>();


                while (resultset.Read())
                {
                    PageCMS currentpagecms = new PageCMS();


                    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 "pagecmstitle":
                            currentpagecms.SetCMStitle(value);
                            break;

                        case "pagecmsbody":
                            currentpagecms.SetCMSbody(value);
                            break;
                        }
                    }

                    pagecms.Add(currentpagecms);
                }

                result_pagecms = pagecms[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_pagecms);
        }
        public void UpdatePageCMS(int pagecmsid, PageCMS new_pagecms)
        {
            string query = "update pagecmsinfo set pagecmstitle='{0}', pagecmsbody='{1}' where pagecmsid={2}";

            query = String.Format(query, new_pagecms.GetCMStitle(), new_pagecms.GetCMSbody(), pagecmsid);
            query = String.Format(query, new_pagecms.GetCMStitle(), new_pagecms.GetCMSbody());



            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 UpdatePageCMS Method!");
                Debug.WriteLine(ex.ToString());
            }

            Connect.Close();
        }
Exemple #5
0
        protected void ShowPageInfo(PagesCMSDB db)
        {   //Debug.WriteLine allows to check for errors in the Debug Output window easier
            Debug.WriteLine("I am trying to show a page");
            bool   valid     = true;
            string pagecmsid = Request.QueryString["pagecmsid"];

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


            if (valid)
            {
                //finds page title and body info and displays it
                PageCMS page_record = db.FindPageCMS(Int32.Parse(pagecmsid));

                Debug.WriteLine("the page is " + page_record.GetCMStitle());
                page_title.InnerHtml = page_record.GetCMStitle();
                page_body.InnerHtml  = page_record.GetCMSbody();
            }
            else
            {
                valid = false;
            }


            if (!valid)
            {   //displays if the user goes to the page directly and not from
                //the list page
                pagecms.InnerHtml = "There was an error finding that page.";
            }
        }
        protected void Add_PageCMS(object sender, EventArgs e)
        {
            //creates a  connection
            PagesCMSDB db = new PagesCMSDB();

            //creates a new page
            PageCMS new_pagecms = new PageCMS();

            //sets the page data
            new_pagecms.SetCMStitle(page_title.Text);
            new_pagecms.SetCMSbody(page_body.Text);


            //adds the page to the database
            db.AddPageCMS(new_pagecms);


            Response.Redirect("ListPageCMS.aspx");
        }
        public void AddPageCMS(PageCMS new_pagecms)
        {
            string query = "insert into pagecmsinfo (pagecmstitle, pagecmsbody) values ('{0}','{1}')";

            query = String.Format(query, new_pagecms.GetCMStitle(), new_pagecms.GetCMSbody());



            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 AddPageCMS Method!");
                Debug.WriteLine(ex.ToString());
            }

            Connect.Close();
        }