Пример #1
0
        public void GetInformation()
        {
            try
            {
                StreamReader fileReader = new StreamReader("DataFiles/ReservedPlacesDataBase.txt");
                if (fileReader != null)
                {
                    using (fileReader)
                    {
                        List <Movie> readedMovies = new List <Movie>();
                        //Spliting by NewLine file to part witch are movies
                        string[] movies = fileReader.ReadToEnd().Split(new char[] { charDevidors[3], charDevidors[4] }, StringSplitOptions.RemoveEmptyEntries);
                        foreach (var currentMovie in movies)
                        {
                            //Spliting by '#' current movie to part witch are it's elements
                            string[] movieElements = currentMovie.Split(new char[] { charDevidors[0] }, StringSplitOptions.RemoveEmptyEntries);

                            string movieName = movieElements[0];

                            double moviePrice = double.Parse(movieElements[1]);

                            //Spliting pojection by '+'  so we get hall and date
                            List <Projection> movieProjections = new List <Projection>();
                            if (movieElements.Length == 3)
                            {
                                foreach (var currentProjection in movieElements[2].Split(new char[] { charDevidors[2] }, StringSplitOptions.RemoveEmptyEntries))
                                {
                                    string[] projectionElements = currentProjection.Split(new char[] { charDevidors[1] }, StringSplitOptions.RemoveEmptyEntries);

                                    //Parsing to enum
                                    Halls projHall = (Halls)Enum.Parse(typeof(Halls), projectionElements[0]);

                                    //Parsing to datetime
                                    Projection creatingProjection = new Projection(projHall, projectionElements[1]);

                                    if (projectionElements.Length > 2)
                                    {
                                        //Spliting places
                                        string[] reservedPlaces = projectionElements[2].Split(new char[] { charDevidors[5] }, StringSplitOptions.RemoveEmptyEntries);

                                        for (int i = 0; i < reservedPlaces.Length; i++)
                                        {
                                            creatingProjection.ReservePlace(int.Parse(reservedPlaces[i]));
                                        }
                                    }

                                    movieProjections.Add(creatingProjection);
                                }
                            }
                            readedMovies.Add(new Movie(movieName, moviePrice, movieProjections));
                        }
                        Movies = readedMovies;
                    }
                }
            }
            catch (Exception)
            {
            }
        }
Пример #2
0
        public void SavePlaces(string movieName, String projectionHour, List <int> places)
        {
            Projection findedProjection = MoviesStorage.Instance.GetMovie(movieName).GetProjection(projectionHour);

            if (findedProjection != null)
            {
                foreach (var currentPlace in places)
                {
                    findedProjection.ReservePlace(currentPlace);
                }
                MoviesStorage.Instance.SetInformation();
            }
            else
            {
                //projectionNotFount
            }
        }