private async void menuSelectFile_Click(object sender, RoutedEventArgs e)
{
if (!isNew)
{
// Bind to another file.
Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
dlg.InitialDirectory = Settings.NaturalGroundingFolder;
if (video.MediaType == MediaType.Video)
{
dlg.Filter = string.Format("Video Files|*{0})", string.Join(";*", AppPaths.VideoExtensions));
}
else if (video.MediaType == MediaType.Audio)
{
dlg.Filter = string.Format("Audio Files|*{0})", string.Join(";*", AppPaths.AudioExtensions));
}
else if (video.MediaType == MediaType.Image)
{
dlg.Filter = string.Format("Image Files|*{0})", string.Join(";*", AppPaths.ImageExtensions));
}
if (dlg.ShowDialog(IsLoaded ? this : Owner).Value == true)
{
if (!dlg.FileName.StartsWith(Settings.NaturalGroundingFolder))
{
MessageBox.Show("You must select a file within your Natural Grounding folder.", "Error", MessageBoxButton.OK, MessageBoxImage.Information);
}
else
{
string BindFile = dlg.FileName.Substring(Settings.NaturalGroundingFolder.Length);
if (business.GetVideoByFileName(BindFile) == null)
{
video.FileName = BindFile;
video.Length = null;
video.Height = null;
await LoadMediaInfoAsync();
if (isPopup)
{
SaveChanges();
}
}
else
{
MessageBox.Show("This file is already in the database.", "Error", MessageBoxButton.OK, MessageBoxImage.Information);
}
}
fileNotFound = false;
}
}
else
{
// Bind file to an existing entry.
SearchSettings settings = new SearchSettings()
{
MediaType = (MediaType)video.MediaTypeId,
ConditionField = FieldConditionEnum.FileExists,
ConditionValue = BoolConditionEnum.No,
ListIsInDatabase = true
};
VideoListItem Result = SearchVideoWindow.Instance(settings);
if (Result != null)
{
// Close and re-open selected entry.
Close();
EditVideoWindow NewForm = Instance(Result.MediaId, null, callback);
NewForm.video.FileName = video.FileName;
NewForm.video.Length = null;
NewForm.video.Height = null;
await NewForm.LoadMediaInfoAsync();
}
}
}