예제 #1
0
        protected void Add_Page(object sender, EventArgs e)
        {
            //create connection
            Dbconnection db = new Dbconnection();

            //create a new particular student
            HttpPage new_HttpPage = new HttpPage();

            //set that student data
            new_HttpPage.SetPageTitle(pagetitle.Text);
            new_HttpPage.SetPageContent(pagecontent.Text);
            new_HttpPage.SetPageAuthor(pageauthor.Text);

            DateTime dateTimeVariable = DateTime.Now;
            string   date             = dateTimeVariable.ToString("yyyy-MM-dd H:mm:ss");


            new_HttpPage.SetPagePublish_Date(date);

            //add the student to the database
            db.AddPage(new_HttpPage);


            Response.Redirect("ListPages.aspx");
        }
        //Get All Pages From Databas
        public HttpPage FindHttpPage(int id)
        {
            MySqlConnection Connect         = new MySqlConnection(ConnectionString);
            HttpPage        result_HttpPage = new HttpPage();

            try
            {
                string query = "select * from pages where pageid = " + id;
                Debug.WriteLine("Connection Initialized...");
                Connect.Open();
                MySqlCommand    cmd       = new MySqlCommand(query, Connect);
                MySqlDataReader resultset = cmd.ExecuteReader();
                List <HttpPage> Pages     = new List <HttpPage>();
                while (resultset.Read())
                {
                    HttpPage currentHttpPage = new HttpPage();
                    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 "pagetitle":
                            currentHttpPage.SetPageTitle(value);
                            break;

                        case "pagebody":
                            currentHttpPage.SetPageContent(value);
                            break;

                        case "author":
                            currentHttpPage.SetPageAuthor(value);
                            break;

                        case "Publish_Date":
                            currentHttpPage.SetPagePublish_Date(value);
                            break;
                        }
                    }

                    Pages.Add(currentHttpPage);
                }

                result_HttpPage = Pages[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_HttpPage);
        }