private void SaveRecord()
        {
            //
            // Record must have a unique id
            //
            if (SelectedMovie == null)
            {
                return;
            }

            if (string.IsNullOrEmpty(SelectedMovie.ID))
            {
                MessageBox.Show("You must have an ID for this movie.");
                return;
            }

            if (IdEnabled)
            {
                Movie temp = AssistRoutines.MovieTbl.Find(SelectedMovie.ID);
                if (temp == null)
                {
                    AssistRoutines.MovieTbl.Insert(SelectedMovie);
                }
                else
                {
                    MessageBox.Show("This movie ID belongs to: " + temp.Title);
                    return;
                }
            }
            else
            {
                int i = 0;
                SelectedMovie.AllVideo = "";
                foreach (var item in VideoFiles)
                {
                    i++;
                    SelectedMovie.AllVideo += item.Path;
                    if (i == VideoFiles.Count)
                    {
                        break;
                    }
                    SelectedMovie.AllVideo += "|";
                }
                //
                // Add the Poster if new movie
                //
                if (AssistRoutines.AddANewMovie)
                {
                    SelectedMovie.Poster = SelectedMovie.Title + "." + SelectedMovie.ID + ".jpg";

                    string tpath = System.IO.Path.Combine(DBLayer.DBPosters, SelectedMovie.Poster);
                    AssistRoutines.WriteImage(PosterImage, tpath);
                    PhotoFiles.AddFile(tpath);
                    //PhotoFiles.Update();
                }
                AssistRoutines.MovieTbl.Update(SelectedMovie);
            }

            //
            // Reset
            //
            LoadMovieList();
            IdEnabled   = false;
            ListEnabled = true;
            SaveEnabled = false;
        }
Exemple #2
0
        private void SaveRecord()
        {
            if (SelectedMovie == null)
            {
                return;
            }


            if (string.IsNullOrEmpty(SelectedMovie.ID))
            {
                MessageBox.Show("You must have an ID for this movie.");
                return;
            }

            AssistRoutines.AddANewMovie = true;
            //
            // test the new Id
            //
            Movie temp = AssistRoutines.MovieTbl.Find(SelectedMovie.ID);

            if (temp == null)
            {
                AssistRoutines.MovieTbl.Insert(SelectedMovie);
            }
            else
            {
                MessageBox.Show("This movie ID belongs to: " + temp.Title);
                return;
            }

            AssistRoutines.NewMovie      = SelectedMovie;
            AssistRoutines.NewMovieImage = SelectedPhoto;
            //
            // If this video is thru the import from folder process
            //
            if (_importVideo)
            {
                SelectedMovie.AllVideo     = _videoPath;
                SelectedMovie.CurrentVideo = _videoPath;

                if (_copyFile)
                {
                    // Use Path class to manipulate file and directory paths.
                    string filename = System.IO.Path.GetFileName(_videoPath);
                    string destFile = System.IO.Path.Combine(DBLayer.MovieFiles, filename);
                    //
                    // To copy a folder's contents to a new location:
                    // Create a new target folder, if necessary.
                    //
                    if (!System.IO.Directory.Exists(DBLayer.MovieFiles))
                    {
                        System.IO.Directory.CreateDirectory(DBLayer.MovieFiles);
                    }
                    //
                    // To copy a file to another location and
                    // overwrite the destination file if it already exists.
                    //
                    //System.IO.File.Copy(_videoPath, destFile, true);
                    System.IO.File.Move(_videoPath, destFile);

                    SelectedMovie.AllVideo     = destFile;
                    SelectedMovie.CurrentVideo = destFile;
                }
            }
            //
            // Poster is saved as a jpg
            //
            SelectedMovie.Poster = SelectedMovie.Title + "." + SelectedMovie.ID + ".jpg";
            string tpath = System.IO.Path.Combine(DBLayer.DBPosters, SelectedMovie.Poster);

            AssistRoutines.WriteImage(SelectedPhoto, tpath);
            //
            // Update the movie database xml file
            //
            AssistRoutines.MovieTbl.Update(SelectedMovie);
            AssistRoutines.MovieTbl.Save();
            //
            // Tell user
            //
            MessageBox.Show("Movie was added.");
            SelectedMovie = new Movie();
            //
            // Reset
            //
            ListEnabled  = true;
            SaveEnabled  = false;
            _importVideo = false;
        }