Esempio n. 1
0
        //This code is referenced from SCHOOLDB.cs in our examples
        public void UpdatePage(int http_pageID, HTTP_Page newHTTPPage)
        {
            //Our query string
            string query = "update http_pages set HTTPPAGETITLE='{0}', HTTPPAGECONTENT='{1}' where HTTPPAGEID={2}";

            query = String.Format(query, newHTTPPage.GetTitle(), newHTTPPage.GetContent(), http_pageID);

            //Set up SQL Connection
            MySqlConnection Connect = new MySqlConnection(ConnectionString);

            //Give the connection a query
            MySqlCommand cmd = new MySqlCommand(query, Connect);

            //Try to update a page with the information provided to us.
            try
            {
                //Open the database connection
                Connect.Open();
                //Run our query command on the database
                cmd.ExecuteNonQuery();
                //Debug purpose
                Debug.WriteLine("Executed query " + query);
            }
            //An exception occured
            catch (Exception ex)
            {
                //If that doesn't seem to work, check Debug>Windows>Output for the below message
                Debug.WriteLine("Something went wrong in the UpdatePage Method!");
                Debug.WriteLine(ex.ToString());
            }

            //Close our database connection
            Connect.Close();
        }
Esempio n. 2
0
        protected void ShowPageInfo(HTTP_PAGEDB db)
        {
            //Our flag to know if the data can be shown or not
            bool valid = true;

            //Get the http_pageID from the query
            string http_pageID = Request.QueryString["http_pageID"];

            //if there is no id then user must have went to this page without a id
            if (String.IsNullOrEmpty(http_pageID))
            {
                valid = false;
            }

            //if there is a id on the page then
            if (valid)
            {
                //Get the HTTP_Page from the id we got
                HTTP_Page pageRecord = db.FindPage(Int32.Parse(http_pageID));
                //Show the data on the HTML
                pageID.InnerHtml            = pageRecord.GetID();
                pageTitle.Text              = pageRecord.GetTitle();
                pageContent.Text            = pageRecord.GetContent();
                pageDatePublished.InnerHtml = pageRecord.GetDate().ToString("MM/dd/yyyy");
            }

            //No id was found
            if (!valid)
            {
                http_page.InnerHtml = "There was an error finding that page.";
            }
        }
Esempio n. 3
0
        //This code is referenced from SCHOOLDB.cs in our examples
        public void AddPage(HTTP_Page newPage)
        {
            //Our query string
            string query = "insert into http_pages (HTTPPAGETITLE, HTTPPAGECONTENT, HTTPPAGEDATE) values ('{0}','{1}','{2}')";

            query = String.Format(query, newPage.GetTitle(), newPage.GetContent(), newPage.GetDate().ToString("yyyy/MM/dd"));

            //Set up SQL Connection
            MySqlConnection Connect = new MySqlConnection(ConnectionString);

            //Give the connection a query
            MySqlCommand cmd = new MySqlCommand(query, Connect);

            //Try to add a page with the information provided to us.
            try
            {
                //Open the database connection
                Connect.Open();
                //Run our query command on the database
                cmd.ExecuteNonQuery();
                //Debug purpose
                Debug.WriteLine("Executed query " + query);
            }
            //An exception occured
            catch (Exception ex)
            {
                Debug.WriteLine("Something went wrong in the AddPage Method!");
                Debug.WriteLine(ex.ToString());
            }

            //Close our database connection
            Connect.Close();
        }