Beispiel #1
0
        public mcl.Films GetCsvData()
        {
            mcl.Films films = new mcl.Films();

            using (CsvReader csv = new CsvReader(new StreamReader(CsvPath.filmsCSV), true))
            {
                int fieldCount = csv.FieldCount;

                while (csv.ReadNextRecord())
                {
                    if (films.Any(item => item.FilmID == csv[csvMovies.FilmID]))
                    {
                        mcl.Film tmpFilm = films.Find(item => item.FilmID == csv[csvMovies.FilmID]);
                        if (tmpFilm.Directors.Any(item => item.PersonID == csv[csvMovies.DirectorID]) != true)
                        {
                            mcl.Director director = getDirectorFromCSV(csv);
                            tmpFilm.Directors.Add(director);
                        }
                        if (tmpFilm.Actors.Any(item => item.PersonID == csv[csvMovies.ActorID]) != true)
                        {
                            mcl.Actor actor = getActorFromCSV(csv);
                            tmpFilm.Actors.Add(actor);
                        }
                    }
                    else
                    {
                        mcl.Film film = getFilmFromCSV(csv);
                        films.Add(film);
                    }
                }
            }
            return(films);
        }
Beispiel #2
0
        //--------------------------------------------------------------------- CSV
        public mcl.Films GetCsvData(string CsvPath)
        {
            mcl.Films films = new mcl.Films();

            //-- FilmID = csv[0];
            //-- FilmName = csv[1];
            //-- ImdbRating = csv[2];
            //-- FilmYear = csv[7];
            //-- DirectorID = csv[3];
            //-- DirectorName = csv[4];
            //-- ActorID = csv[5];
            //-- ActorName = csv[6];

            using (CsvReader csv = new CsvReader(new StreamReader(CsvPath), true)) // looks up where the data is being held.
            {
                int fieldCount = csv.FieldCount;

                string[] headers = csv.GetFieldHeaders();
                while (csv.ReadNextRecord()) // while reading the data. This if else statement is checking if any of the dropdown fields have been selected. if one has been selected it pulls the data from that csv file and populates the drop down.
                {
                    if (films.Any(item => item.FilmID == csv[csvMovies.FilmID]))
                    {
                        mcl.Film tmpFilm = films.Find(item => item.FilmID == csv[csvMovies.FilmID]);
                        if (tmpFilm.Directors.Any(item => item.PersonID == csv[csvMovies.DirectorID]))
                        {
                        }
                        else
                        {
                            mcl.Director director = getDirectorFromCSV(csv);
                            tmpFilm.Directors.Add(director);
                        }
                        if (tmpFilm.Actors.Any(item => item.PersonID == csv[csvMovies.ActorID]))
                        {
                        }
                        else
                        {
                            mcl.Actor actor = getActorFromCSV(csv);
                            tmpFilm.Actors.Add(actor);
                        }
                    }
                    else
                    {
                        mcl.Film film = getFilmFromCSV(csv);
                        films.Add(film);
                    }
                }
            }
            return(films); // returns the results of the if, else statements above.
        }
Beispiel #3
0
        private mcl.Films dataTableToFilms(DataTable table)
        {
            mcl.Films films = new mcl.Films();

            DataRow[] dr = table.Select();

            foreach (var row in dr)//TODO try with LINQ
            {
                mcl.Film film = new mcl.Film();
                if (films.Any(item => item.FilmID == row.ItemArray[dict[avItems.FilmID]].ToString()) == false)
                {
                    films.Add(getFilm(row));
                }
                else
                {
                    film = films.Find(item => item.FilmID == row.ItemArray[dict[avItems.FilmID]].ToString());
                    addActor(film, row);
                    addDirector(film, row);
                }
            }
            return(films);
        }