示例#1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //examples of getting movie info from database

            //creating a movie object using the ID constructor - this finds the movie with this id in the database and loads it into the movie object it creates
            FourthProjectLogic.Movie testmovie = new FourthProjectLogic.Movie(420);
            //doyouhave2012.Text = testmovie.ToString();  //we then use our movie objects custom tostring method to output some summary text about the movie (that i wrote way too late at night)

            //stuck me that we could also do this to get that info:
            //doyouhave2012.Text = FourthProjectLogic.Movie.MovieTableAdapter.GetDataByID(420).ToString();

            //using one of the movie objects list methods to find all movies with the genre thriller and count the rows.
            //doyouhavefrozen.Text = "there are " + FourthProjectLogic.Movie.ListMoviesByGenre("Thriller").Count + " movies in the genre Thriller";

            //we could also do this to get the first thriller movie in our list, lol.
            //doyouhave2012.Text = FourthProjectLogic.Movie.ListMoviesByGenre("Thriller")[0].ToString();

            // END OF EXAMPLES

            // TOP 10
            //set datasource - alternative to designer setup - get top 10
            //Repeater1.DataSource = FourthProjectLogic.Movie.MovieTableAdapter.MoviesTop10();
            //Repeater1.DataBind();
        }
示例#2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //redirect to home if there is no querystring
            if (string.IsNullOrWhiteSpace(Request.QueryString["queryID"]))
            {
                Response.Redirect("~/");
            }

            //resultspanel.Visible = false;

            int queryID = Int32.Parse(Request.QueryString["queryID"]);

            FourthProjectLogic.Movie themovie = new FourthProjectLogic.Movie(queryID); //get movie object via id, fetching db info for it

            themovie.IncrementViewcount();                                             //what it says on the tin, this is how we track views

            //get movie name from object and show in label
            LabelMessages.Text    = themovie.ToString();
            LabelMessages.Visible = true;

            string result = FourthProjectLogic.OmdbAPI.NameAPI(themovie.title, themovie.year); //add year to make sure we get correct results?

            File.WriteAllText(Server.MapPath("~/MyFiles/Latestresult.xml"), result);
            XmlDocument doc = new XmlDocument();

            doc.LoadXml(result);

            if (doc.SelectSingleNode("/root/@response").InnerText == "True")
            {
                XmlNodeList nodelist = doc.SelectNodes("/root/movie");
                foreach (XmlNode node in nodelist)
                {
                    string poster = node.SelectSingleNode("@poster").InnerText;
                    if (poster == "N/A" || poster == "FAIL")
                    {
                        ImagePoster.ImageUrl = "/Myfiles/default-img.jpg";
                    }
                    else
                    {
                        ImagePoster.ImageUrl = poster;
                    }
                }

                LabelResultTitle.Text       = "Title: " + nodelist[0].SelectSingleNode("@title").InnerText;
                LabelResultRating.Text      = "Rating: " + nodelist[0].SelectSingleNode("@imdbRating").InnerText;
                LabelResultYear.Text        = "Year: " + nodelist[0].SelectSingleNode("@year").InnerText;
                LabelResultActors.Text      = "Actors: " + nodelist[0].SelectSingleNode("@actors").InnerText;
                LabelResultDescription.Text = "Description: " + nodelist[0].SelectSingleNode("@plot").InnerText;
                LabelResultChildRating.Text = "Child Rating: " + nodelist[0].SelectSingleNode("@rated").InnerText;
                LabelMessages.Visible       = false;
                //resultspanel.Visible = true;
            }
            else
            {
                //resultspanel.Visible = true;
                LabelMessages.Visible          = true;
                LabelResultTitle.Visible       = false;
                LabelResultRating.Visible      = false;
                LabelResultYear.Visible        = false;
                LabelResultActors.Visible      = false;
                LabelResultDescription.Visible = false;
                LabelResultChildRating.Visible = false;

                LabelMessages.Text    = "Movie not found";
                LabelMessages.Visible = true;
                ImagePoster.ImageUrl  = "/Myfiles/default-img.jpg";
                LabelResultTitle.Text = "no Results";
            }


            // COMMERCIAL
            // run the logic for commercial stat tracking - reading and modifying the xml to increment viewcount for the random commercial and passing the commercials id/rowindex/"position"

            int randomcommercialToDisplayPosition = FourthProjectLogic.Commercials.StatTracker();

            // load the xml for display


            DataSet ds = new DataSet();

            ds.ReadXml(MapPath("/xml/commercialsTransformedTemp.xml"));
            rpMyRepeater.DataSource = ds;
            rpMyRepeater.DataBind();


            foreach (RepeaterItem item in rpMyRepeater.Items)
            {
                if (item.ItemIndex != randomcommercialToDisplayPosition)
                {
                    item.Visible = false;
                }
            }
        }