Exemple #1
0
        // update a media row
        public bool IsMediaUpdated(MediaDTO updatedMedia)
        {
            // get stored info from other tables
            int newDID = GetDID(updatedMedia.Director);
            int newGID = GetGID(updatedMedia.Genre);
            int newLID = GetLID(updatedMedia.Language);

            try
            {
                if (newDID != -1 && newGID != -1 && newLID != -1)
                {
                    // update row using query
                    tabMediaTableAdapter.UpdateMedia(updatedMedia.Title, newGID, newDID, newLID, updatedMedia.PublishYear, updatedMedia.Budget, updatedMedia.MediaID);
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return(false);
            }
        }
Exemple #2
0
        // get all media records
        public List <MediaDTO> GetAllMedia()
        {
            // list for storing media objects
            List <MediaDTO> mediaList = new List <MediaDTO>();



            try
            {
                // get all rows in the table using query
                tabMediaTableAdapter.Fill(tabMediaDataTable);
                foreach (DataRow mediaRow in tabMediaDataTable.Rows)
                {
                    MediaDTO media = new MediaDTO
                    {
                        MediaID     = Convert.ToInt32(mediaRow[0]),
                        Title       = mediaRow[1].ToString(),
                        Genre       = mediaRow[4].ToString(),
                        Director    = mediaRow[6].ToString(),
                        Language    = mediaRow[4].ToString(),
                        PublishYear = Convert.ToInt32(mediaRow[2]),
                        Budget      = Convert.ToDecimal(mediaRow[3])
                    };

                    mediaList.Add(media);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            return(mediaList);
        }
Exemple #3
0
        // add new media row into Media table
        public bool IsMediaInserted(MediaDTO newMedia)
        {
            int dID = GetDID(newMedia.Director);
            int gID = GetGID(newMedia.Genre);
            int lID = GetLID(newMedia.Language);

            try
            {
                if (dID != -1 && gID != -1 && lID != -1)
                {
                    // insert row using query
                    tabMediaTableAdapter.InsertMedia(newMedia.Title, gID, dID, lID, newMedia.PublishYear, newMedia.Budget);
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return(false);
            }
        }
        public List <MediaDTO> Search(string searchType, string searchText)
        {
            // list for storing media from search result
            List <MediaDTO> foundMediaList = new List <MediaDTO>();

            MediaDataSet.TabMediaDataTable tabMediaDataTable    = new MediaDataSet.TabMediaDataTable();
            TabMediaTableAdapter           tabMediaTableAdapter = new TabMediaTableAdapter();

            try
            {
                // get results by query based on search type
                switch (searchType)
                {
                case "Title":
                    searchText = "%" + searchText + "%";
                    tabMediaTableAdapter.SelectMediaByTitle(tabMediaDataTable, searchText);
                    break;

                case "Genre":
                    searchText = "%" + searchText + "%";
                    tabMediaTableAdapter.SelectMediaByGenreName(tabMediaDataTable, searchText);
                    break;

                case "Director":
                    searchText = "%" + searchText + "%";
                    tabMediaTableAdapter.SelectMediaByDirectorName(tabMediaDataTable, searchText);
                    break;

                case "Language":
                    searchText = "%" + searchText + "%";
                    tabMediaTableAdapter.SelectMediaByLanguageName(tabMediaDataTable, searchText);
                    break;

                case "PublishYear":
                    tabMediaTableAdapter.SelectMediaByPublishYear(tabMediaDataTable, Convert.ToInt32(searchText));
                    break;

                case "Budget":
                    tabMediaTableAdapter.SelectMediaByBudget(tabMediaDataTable, Convert.ToDecimal(searchText));
                    break;

                default:
                    tabMediaTableAdapter.Fill(tabMediaDataTable);
                    break;
                }
            }
            catch (FormatException e)
            {
                Console.WriteLine(e.Message);
                try
                {
                    tabMediaTableAdapter.Fill(tabMediaDataTable);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                try
                {
                    tabMediaTableAdapter.Fill(tabMediaDataTable);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }

            // convert raw data from table into media objects
            foreach (DataRow mediaRow in tabMediaDataTable.Rows)
            {
                MediaDTO media = new MediaDTO
                {
                    MediaID     = Convert.ToInt32(mediaRow[0]),
                    Title       = mediaRow[1].ToString(),
                    Genre       = mediaRow[4].ToString(),
                    Director    = mediaRow[5].ToString(),
                    Language    = mediaRow[6].ToString(),
                    PublishYear = Convert.ToInt32(mediaRow[2]),
                    Budget      = Convert.ToDecimal(mediaRow[3])
                };

                foundMediaList.Add(media);
            }
            return(foundMediaList);
        }