Beispiel #1
0
 public Show(Movie movie, String date, Hall hall, String timeStart, String timeEnd, double price) 
 {
     Movie = movie;
     Date = date;
     Hall = hall;
     TimeStart = timeStart;
     TimeEnd = timeEnd;
     Price = price;
 }
Beispiel #2
0
        //this method requests for a specific movie search in the server
        //search parameters are acquired from user inputs
        //Loads up listMovie according to acquired searched movies
        //Works similar to Browse, adds in details in other controls for each movie and each show
        public void Search()
        {
            listMovies.Items.Clear();

            string searchType = (string)cobSearch.SelectedItem;
            string searchKey = txtSearch.Text;

            if (!string.IsNullOrWhiteSpace(txtSearch.Text))
            {

                //rTxtMessages.AppendText(searchType + searchKey);

                IFormatter formatter = new BinaryFormatter();

                byte[] data = new byte[1024];

                int size = 0;

                data = Encoding.ASCII.GetBytes(SEARCH);
                socket.Send(data); //this sends the Search request

                data = Encoding.ASCII.GetBytes(searchType + ";" + searchKey);
                socket.Send(data); //this sends the search terms

                size = socket.Receive(data); //this receives the confirmation answer

                string answer = "";

                answer = Encoding.ASCII.GetString(data, 0, size);

                if (answer == SFOUND)
                {
                    // receiving file size
                    data = new byte[1024];
                    try
                    {
                        size = socket.Receive(data);
                    }
                    catch (Exception)
                    {
                        rTxtMessages.AppendText("Receiving file size error" + "\r\n");
                    }

                    filesize = Convert.ToInt64(Encoding.ASCII.GetString(data));

                    //rTxtMessages.Clear();
                    //rTxtMessages.AppendText(filesize + " (filesize) " + size + " (size)\r\n");

                    // receiving file
                    data = new byte[filesize];
                    try
                    {
                        size = socket.Receive(data);
                        //rTxtMessages.AppendText("File received" + "\r\n");
                    }
                    catch (Exception)
                    {
                        rTxtMessages.AppendText("Receiving file error" + "\r\n");
                    }

                    if (!File.Exists(srchFile))
                    {
                        File.Create(srchFile);
                    }
                    using (fs = new FileStream(srchFile, FileMode.Open, FileAccess.Write))
                    {
                        fs.Write(data, 0, Convert.ToInt32(filesize));
                        fs.Flush();
                        //rTxtMessages.AppendText("File written" + "\r\n" + fs.Length + " bytes\r\n");
                        fs.Close();
                    }

                    try
                    {
                        using (fs = new FileStream(srchFile, FileMode.Open, FileAccess.Read))
                        {
                            Movie[] m_info = (Movie[])formatter.Deserialize(fs);
                            fs.Flush();
                            fs.Close();
                            movieInfo = m_info.ToDictionary((u) => u.Title, (u) => u);
                            foreach (KeyValuePair<String, Movie> infos in movieInfo)
                            {
                                //rTxtMessages.AppendText(infos.Value.Title + "\r\n");
                                //rTxtMessages.AppendText(infos.Value.Genre + "\r\n");

                                Movie mv = new Movie(infos.Value.Title, infos.Value.Description, infos.Value.Director,
                                infos.Value.Genre, infos.Value.Shows, infos.Value.Poster);

                                //listMovies.Items.Add(movieInfo[infos.Value.Title].toString());
                                listMovies.Items.Add(mv.Title);

                            }
                        }

                        rTxtMessages.AppendText("\nRequesting from Server \"" + searchType + " : " + searchKey + "\"");
                        listMovies.SelectedIndex = 0;

                    }
                    catch (Exception ex)
                    {
                        rTxtMessages.AppendText("\nError. Please restart the application." + ex.ToString());
                    }
                }

                else
                    if (answer == SEMPTY)
                    {
                        rTxtMessages.AppendText("\nNo movies found.\nPlease ensure that your search type is correct.");
                    }

                    else
                    {
                        rTxtMessages.AppendText("\nSomething bad has happened. Please restart the application.");
                    }
            }

            else //triggers when textbox for search query is either null or has whitespaces
            {

                rTxtMessages.AppendText("\nSearch bar is empty: please input a key word.");

            }

            // attributes to save client's footprint, for future plans and not in use at the moment
            lastSearchedType = searchType;
            lastSearchedKey = searchKey;
            lastClicked = "search";
            lastListIndex = listMovies.SelectedIndex;
        }
Beispiel #3
0
 //this method is called when the show dates of a movie is required
 //returns a list of show dates
 public List<String> GetDatesByMovie(Movie m)
 {
     List<Show> shows = m.Shows;
     List<String> all = new List<String>();
     foreach(Show s in shows){
         if(!all.Contains(s.Date))
             all.Add(s.Date);
     }
     //all.Sort();
     //rTxtMessages.Text = all.Count.ToString();
     return all;
 }
Beispiel #4
0
        //this method is called when the show times of a show date is required
        //returns a list of show times
        public List<String> GetShowTimesByDate(Movie m, String date)
        {
            List<String> showtimes = new List<String>();
            try
            {
                List<Show> shows = m.Shows;
                showtimes = new List<String>();
                for (int i = 0; i < shows.Count; i++)
                {

                    if (shows[i].Date.Equals(date))
                    {
                        showtimes.Add(shows[i].TimeStart);
                    }

                }
                //showtimes.Sort();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            return showtimes;
        }
Beispiel #5
0
        //this method requests movies from the server, and then loads it into the controls
        //Manipulates other controls to add in details of each movie and each show
        //allows for the booking of seats
        public void Browse()
        {
            btnBrowse.Text = "Browse";
            listMovies.Items.Clear();

            IFormatter formatter = new BinaryFormatter();

            //Thread.Sleep(1000);

            SendRequest(BROWSE);

            //receiving file size
            byte[] data = new byte[1024];
            try
            {
                size = socket.Receive(data);
            }
            catch (Exception)
            {
                rTxtMessages.AppendText("Receiving file size error" + "\r\n");
            }

            filesize = Convert.ToInt64(Encoding.ASCII.GetString(data));

            //rTxtMessages.Clear();
            //rTxtMessages.AppendText(filesize + " (filesize) " + size + " (size)\r\n");

            //receiving file
            data = new byte[filesize];
            try
            {
                size = socket.Receive(data);
                //rTxtMessages.AppendText("File received" + "\r\n");
            }
            catch (Exception)
            {
                rTxtMessages.AppendText("Receiving file error" + "\r\n");
            }

            using (fs = new FileStream(infoFile, FileMode.OpenOrCreate, FileAccess.Write))
            {
                fs.Write(data, 0, Convert.ToInt32(filesize));
                fs.Flush();
                //rTxtMessages.AppendText("File written" + "\r\n" + fs.Length + " bytes\r\n");
                fs.Close();
            }

            try
            {
                using (fs = new FileStream(infoFile, FileMode.Open, FileAccess.Read))
                {
                    Movie[] m_info = (Movie[])formatter.Deserialize(fs);
                    fs.Flush();
                    fs.Close();
                    movieInfo = m_info.ToDictionary((u) => u.Title, (u) => u);
                    SortedDictionary<String, Movie> sortedMovieInfo = new SortedDictionary<String, Movie>(movieInfo);

                    foreach (KeyValuePair<String, Movie> infos in sortedMovieInfo)
                    {
                        //rTxtMessages.AppendText(infos.Value.Title + "\r\n");
                        //rTxtMessages.AppendText(infos.Value.Genre + "\r\n");

                        Movie mv = new Movie(infos.Value.Title, infos.Value.Description, infos.Value.Director,
                            infos.Value.Genre, infos.Value.Shows, infos.Value.Poster);

                        //listMovies.Items.Add(movieInfo[infos.Value.Title].toString());
                        if(mv.Shows.Count > 0)
                            listMovies.Items.Add(mv.Title);

                    }
                    listMovies.SelectedIndex = 0;
                }
            }
            catch (Exception ex)
            {
                rTxtMessages.AppendText(ex.Message);
            }
        }
Beispiel #6
0
        //called when a movie is selected in listMovies.
        //This method manipulates the controls to contain and show the movie's information.
        private void showMovieDetails(Movie m)
        {
            lblShowName.Visible = true;
            lblShowDirector.Visible = true;
            lblShowGenre.Visible = true;

            lblMvName.Visible = true;
            lblMvGenre.Visible = true;
            lblMvDirector.Visible = true;
            lblMvDescription.Visible = true;

            lblMvName.Text = m.Title;
            lblMvGenre.Text = m.Genre;

            lblMvDirector.Text = m.Director;
            lblMvDescription.Text = m.Description;

            picPoster.Image = FixedSize(m.Poster, 200, 200);

            cobDate.Enabled = true;
            cobDate.Items.Clear();
            cobTime.Enabled = true;
            cobTime.Items.Clear();
            listTime.Items.Clear();
            btnBook.Enabled = true;

            List<Show> listShow = m.Shows;
            List<String> dates = GetDatesByMovie(m);

            foreach (String s in dates) {
                cobDate.Items.Add(s);
            }

            cobDate.SelectedIndex = 0;
        }
Beispiel #7
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            //// Create the movie and shows
            String title, desc, dir, genre, imgPath = "";
            Boolean hasImage = false;

            title    = tbTitle.Text;
            desc     = tbDescription.Text;
            dir      = tbDirector.Text;
            genre    = tbGenre.Text;
            if (tbImage.Text.Trim().Length != 0 && !tbImage.Text.Trim().Equals("poster\\")) {
                hasImage = true;
                imgPath = tbImage.Text;
            }

            Movie m = new Movie(title, desc, dir, genre);
            if (!movieInfo.ContainsKey(m.Title)) {
                if (hasImage) {
                    try {
                        m.Poster = GetImage(imgPath);
                    } catch {
                        DisplayMsgMovies("Unable to process image");
                    }
                }
                movieInfo.Add(m.Title, m);

                DisplayMsgMovies("New Movie: " + m.Title + " added");
                DisplayMsgShows("New Movie: " + m.Title + " added");

                lbMovies.Items.Clear();
                foreach (KeyValuePair<String, Movie> movie in movieInfo) {
                    lbMovies.Items.Add(movie.Key);
                }

                tabControl.SelectedTab = tabPageShows;
                lbMovies.SelectedIndex = lbMovies.Items.Count - 1;
            } else {
                DisplayMsgMovies("Movie already exists. Please use another title.");
            }
        }
Beispiel #8
0
        /// <summary>
        /// Provides a base of movies for server to reset all movies and bookings saved.
        /// Overwrites and saves to moviesFile location.
        /// </summary>
        public void LoadMovies()
        {
            movieInfo = new Dictionary<String, Movie>();

            Movie m = new Movie();
            m.Title = "The Dark Knight";
            m.Genre = "Superhero";
            m.Description = "Welcome to a world without rules. The sequel to Nolan's Batman Begins, The Dark Knight reveals a new but familiar enemy for the vigilante superhero.";
            m.Director = "Christopher Nolan";
            m.Poster = GetImage("poster\\the_dark_knight.jpg");
            m.Shows = new List<Show> {
                new Show(m, "1 January 2015", new Hall("Theatre 1"), "0800", "1000", 8.00),
                new Show(m, "1 January 2015", new Hall("Theatre 2"), "1600", "1800", 8.00),
                new Show(m, "2 January 2015", new Hall("Theatre 3"), "0800", "1000", 8.00),
                new Show(m, "2 January 2015", new Hall("Theatre 4"), "1600", "1800", 8.00),
                new Show(m, "3 January 2015", new Hall("Theatre 5"), "1600", "1800", 10.00),
                new Show(m, "3 January 2015", new Hall("Theatre 6"), "2000", "2200", 12.00),
            };
            movieInfo.Add(m.Title, m);

            m = new Movie();
            m.Title = "Batman Beyond";
            m.Genre = "Animated";
            m.Description = "Batman Beyond (known as Batman of the Future in Europe, Latin America, Australia and India) is an American animated television series created by Warner Bros. "
            + "Animation in collaboration with DC Comics as a continuation of the Batman legacy.";
            m.Director = "Bruce Timm";
            m.Poster = GetImage("poster\\batman_of_the_future.jpg");
            m.Shows = new List<Show> {
                new Show(m, "3 July 2015", new Hall("Theatre 1"), "0900", "1100", 8.00),
                new Show(m, "3 July 2015", new Hall("Theatre 2"), "1700", "1900", 10.00),
                new Show(m, "3 July 2015", new Hall("Theatre 3"), "2100", "2300", 12.00)
            };
            movieInfo.Add(m.Title, m);

            m = new Movie();
            m.Title = "Inception";
            m.Genre = "Science Fiction - Thriller";
            m.Description = "Your mind is the scene of the crime. Dom Cobb is a professional thief who commits corporate espionage in the most lucid way - via dreams.";
            m.Director = "Christopher Nolan";
            m.Poster = GetImage("poster\\inception_poster.jpg");
            m.Shows = new List<Show> {
                new Show(m, "3 July 2015", new Hall("Theatre 1"), "1820", "2020", 12.00),
                new Show(m, "4 July 2015", new Hall("Theatre 2"), "1300", "1500", 12.00),
                new Show(m, "5 July 2015", new Hall("Theatre 3"), "0030", "0230", 10.00)
            };
            movieInfo.Add(m.Title, m);

            m = new Movie();
            m.Title = "Terminator 2 : Judgement Day";
            m.Genre = "Science Fiction - Action";
            m.Description = "It's nothing personal. The sequel to the 1984 Terminator. Arnold Schwarzenegger is back as a cyborg Terminator. Now available in seasonal showings.";
            m.Director = "James Cameron";
            m.Poster = GetImage("poster\\terminator2.jpg");
            m.Shows = new List<Show> {
                new Show(m, "2 March 2015",     new Hall("Theatre 1"), "1850", "2050", 12.00),
                new Show(m, "4 September 2015", new Hall("Theatre 2"), "1500", "1700", 12.00),
                new Show(m, "6 December 2015",  new Hall("Theatre 3"), "1230", "1430", 12.00)
            };

            movieInfo.Add(m.Title, m);
            SerializeMovies(moviesFile);
        }
Beispiel #9
0
        public Dictionary<String, Movie> DeserializeMovies(String filePath)
        {
            Dictionary<String, Movie> movieInfoNew = new Dictionary<String, Movie>();
            try {
                using (fs = new FileStream(filePath, FileMode.Open, FileAccess.Read)) {
                    Movie[] m_info = (Movie[])formatter.Deserialize(fs);
                    fs.Flush();
                    fs.Close();
                    movieInfo = m_info.ToDictionary((u) => u.Title, (u) => u);

                    foreach (KeyValuePair<String, Movie> infos in movieInfo) {
                        Movie mv = new Movie(infos.Value.Title, infos.Value.Description,
                            infos.Value.Director, infos.Value.Genre, infos.Value.Shows, infos.Value.Poster);

                        movieInfoNew.Add(mv.Title, mv);
                    }
                }
                tbDisplay.AppendText("Load Movies: Successful" + "\r\n");
            } catch (Exception ex) {
                tbDisplay.AppendText("Load Movies File Error: \r\n" + ex.ToString() + "\r\n");
            }
            return movieInfoNew;
        }