Пример #1
0
 public History(bool filterOnFavorite)
 {
     InitializeComponent();
     try
     {
         favoriteOpen = true;
         db           = new MediaHistoryContext();
         db.Media.Load();
         var BindingList = db.Media.Local.ToBindingList();
         HistoryGrid.ItemsSource = from a in BindingList where (a as MediaHistory).Favorite == filterOnFavorite select a;
         this.Closing           += History_Closing;
     }
     catch
     {
         MessageBox.Show("Не удалось подклюситься к базе данных!", "MediaPlayerApp", MessageBoxButton.OK, MessageBoxImage.Error);
     }
 }
Пример #2
0
        public History()
        {
            InitializeComponent();
            try
            {
                favoriteOpen = false;
                db           = new MediaHistoryContext();
                db.Media.Load();
                HistoryGrid.ItemsSource = db.Media.Local.ToBindingList(); // устанавливаем привязку к кэшу

                this.Closing += History_Closing;
            }
            catch
            {
                MessageBox.Show("Не удалось подклюситься к базе данных!", "MediaPlayerApp", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Пример #3
0
        /// <summary>
        /// Отмечаем медифайл понравшимся и добавляем в избранное
        /// </summary>
        private void buttom_media_like_Click(object sender, RoutedEventArgs e)
        {
            panel_like.Visibility        = Visibility.Hidden;
            img_LikeOrDislike.Source     = new BitmapImage(new Uri("/png/like_heart.png", UriKind.Relative));
            img_LikeOrDislike.Visibility = Visibility.Visible;

            using (MediaHistoryContext db = new MediaHistoryContext())
            {
                foreach (var mediaFile in db.Media)
                {
                    if (mediaFile.Date.ToString() == mediafileCash.Date.ToString())
                    {
                        mediaFile.Favorite = true;
                    }
                }
                db.SaveChanges();
            }
            object_animation_size(sender, e);
        }
Пример #4
0
        /// <summary>
        /// Действия при открытии файла
        /// </summary>
        private void MediaPlayer_MediaOpened(object sender, RoutedEventArgs e)
        {
            panel_like.Visibility         = Visibility.Hidden;
            img_LikeOrDislike.Visibility  = Visibility.Hidden;
            img_LikeOrDislike.Opacity     = 1;
            img_LikeOrDislike.Width       = 64;
            img_LikeOrDislike.Height      = 64;
            dockPael_MediaElement.Opacity = 1;
            panel_like.Opacity            = 1;

            try
            {
                MediaPlayer.Volume  = (double)slider_volume.Value;
                slider_seek.Maximum = MediaPlayer.NaturalDuration.TimeSpan.TotalMilliseconds;

                timer.Interval = new TimeSpan(0, 0, 1);
                timer.Start();

                MediaHistory mediafile = new MediaHistory();
                mediafile.Name = System.IO.Path.GetFileName(filename);
                TimeSpan timeSpan = TimeSpan.FromSeconds(Convert.ToInt32(MediaPlayer.NaturalDuration.TimeSpan.TotalSeconds));
                mediafile.Duration = string.Format("{0:D2}:{1:D2}:{2:D2}", timeSpan.Hours, timeSpan.Minutes, timeSpan.Seconds);
                mediafile.Date     = DateTime.Now;
                mediafile.Favorite = false;
                mediafile.Path     = filename;
                mediafileCash      = mediafile;

                using (MediaHistoryContext db = new MediaHistoryContext())
                {
                    db.Media.Add(mediafile);
                    db.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Ошибка воспроизведения файла!" + ex.Message, "MediaPlayerApp", MessageBoxButton.OK, MessageBoxImage.Error);
                fileIsDrop = false;
                filename   = null;
                buttom_menu_fileOpen_Click(sender, e);
            }
        }
Пример #5
0
 /// <summary>
 /// Удаление фрагментов из избранного и истории
 /// </summary>
 private void deleteButton_Click(object sender, RoutedEventArgs e)
 {
     button_animation_size(deleteButton);
     if (HistoryGrid.SelectedItems.Count > 0)
     {
         for (int i = 0; i < HistoryGrid.SelectedItems.Count; i++)
         {
             MediaHistory mHisory = HistoryGrid.SelectedItems[i] as MediaHistory;
             if (mHisory != null)
             {
                 db.Media.Remove(mHisory);
             }
         }
     }
     db.SaveChanges();
     if (favoriteOpen)
     {
         db = new MediaHistoryContext();
         db.Media.Load();
         var BindingList = db.Media.Local.ToBindingList();
         HistoryGrid.ItemsSource = from a in BindingList where (a as MediaHistory).Favorite == true select a;
         this.Closing           += History_Closing;
     }
 }