protected void Add_Page(object sender, EventArgs e)
        {
            //the above add_page is related to our onclick funcion
            //firstly access from db
            PageDB db = new PageDB();

            //create a new page
            //here this page class is  to refer the class which we created;
            Page_Class new_http_page = new Page_Class();

            //set that student data now
            new_http_page.SetTitle(page_title.Text);
            new_http_page.SetBody(page_body.Text);
            new_http_page.SetAuthorNumber(author_number.Text);
            new_http_page.SetCreatedDate(DateTime.Now);

            //now this new page created to our database
            db.AddPage(new_http_page);
            //this add page is related to our db add page.

            Response.Redirect("HTTP_Page.aspx");
        }
예제 #2
0
        //here because we define the class thats why we mention here
        //otherwise we have to use dictionary method.
        public Page_Class FindPage(int pageid)
        {
            MySqlConnection Connect = new MySqlConnection(ConnectionString);

            Page_Class page_result = new Page_Class();

            try
            {
                string query = "select PAGE_ID,TITLE, BODY, concat(first_name, ' ', last_name) as AUTHOR_NAME, CREATED_DATE from HTTP_PAGE join AUTHOR ON HTTP_PAGE.AUTHOR_ID = AUTHOR.AUTHOR_ID where PAGE_ID =" + pageid;
                Debug.WriteLine("connection initialized!!! i am trying to find a page with id " + pageid);

                Connect.Open();

                MySqlCommand cmd = new MySqlCommand(query, Connect);

                MySqlDataReader resultset = cmd.ExecuteReader();

                List <Page_Class> HTTP_Page = new List <Page_Class>();

                while (resultset.Read())
                {
                    //info we stored for single vlaue
                    Page_Class currenthttp_page = new Page_Class();

                    for (int i = 0; i < resultset.FieldCount; i++)
                    {
                        string name  = resultset.GetName(i);
                        string value = resultset.GetString(i);

                        Debug.WriteLine("Attempting to transfer " + name + "data of" + value);

                        switch (name)
                        {
                        case "TITLE":
                            currenthttp_page.SetTitle(value);
                            break;

                        case "BODY":
                            currenthttp_page.SetBody(value);
                            break;

                        case "AUTHOR_NAME":
                            currenthttp_page.SetAuthorNumber(value);
                            break;

                        case "CREATED_DATE":
                            currenthttp_page.SetCreatedDate(DateTime.Parse(value));
                            break;
                        }
                    }
                    HTTP_Page.Add(currenthttp_page);
                }
                page_result = HTTP_Page[0];
            }
            catch (Exception ex)
            {
                Debug.WriteLine("something went wrong for this  page");
                Debug.WriteLine(ex.ToString());
            }
            Connect.Close();
            Debug.WriteLine("Database terminated!!!");

            return(page_result);
        }