private void Item_DeleteMediaEvent(object sender, Code.Media.MediaData e)
 {
     if (e != null)
     {
         MessageBoxResult messageBoxResult = MessageBox.Show("Bạn có muốn xoá file video này không?", "Xoá video", System.Windows.MessageBoxButton.YesNo);
         if (messageBoxResult == MessageBoxResult.Yes)
         {
             alta_class_ftp.deleteFile(e.Url, App.setting.ftp_user, App.setting.ftp_password);
             MediaData.Delete(e);
             UIMedia m = this.list_Box_Item.SelectedItem as UIMedia;
             m.Animation_Opacity_View_Frame(false, () =>
             {
                 this.list_Box_Item.Items.Remove(m);
                 this.Datas.Remove(e);
                 this.totalMedia -= 1;
                 if (this.to < this.totalMedia)
                 {
                     if (this.User == null)
                     {
                         this.Datas = App.curUser.LoadMedias(this.from, this.to, out this.totalMedia, this.TypeMedia);
                     }
                     else
                     {
                         this.Datas = this.User.LoadMedias(this.from, this.to, out this.totalMedia, this.TypeMedia, true);
                     }
                     this.LoadGUI();
                 }
             }, 600);
             this.list_Box_Item.SelectedIndex = -1;
         }
     }
 }
 private void UIBtnBack_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
 {
     if (this.index > 0)
     {
         this.index--;
         if (this.myVlcControl.IsPlaying)
         {
             this.myVlcControl.Stop();
         }
         this.Media = this.Medias[this.index];
         LoadGUI();
     }
 }
 private void UIBtnNext_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
 {
     if (this.index != -1 && this.index < this.Medias.Count - 1)
     {
         this.index++;
         this.Media = this.Medias[this.index];
         if (this.myVlcControl.IsPlaying)
         {
             this.myVlcControl.Stop();
         }
         LoadGUI();
     }
 }
 private void Item_ViewInfoMediaEvent(object sender, Code.Media.MediaData e)
 {
     if (e != null)
     {
         UIMediaEdit item = new UIMediaEdit();
         item.Type        = e.Type;
         item.CloseEvent += Item_CloseEvent;
         item.setLeft(0);
         item.setTop(90);
         item.Width  = 1366;
         item.Height = 578;
         item.Media  = e;
         this.UIRoot.Children.Add(item);
     }
 }
 private void Item_PlayMediaEvent(object sender, Code.Media.MediaData e)
 {
     if (e != null)
     {
         MediaPlayer player = new MediaPlayer();
         player.Width  = 1366;
         player.Height = 668;
         player.setLeft(0);
         player.setTop(90);
         player.Medias      = this.Datas;
         player.Media       = e;
         player.CloseEvent += Player_CloseEvent;
         this.UIRoot.Children.Add(player);
     }
 }
 private void PlayMedia(Code.Media.MediaData m)
 {
     if (m.LocalFile != null)
     {
         PathMedia media = new PathMedia(m.LocalFile.FullName);
         media.ParsedChanged  += MediaOnParsedChanged;
         myVlcControl.Media    = media;
         myVlcControl.Position = this.Position;
     }
     else
     {
         LocationMedia media = m.LocationMedia;
         media.ParsedChanged += MediaOnParsedChanged;
         myVlcControl.Media   = media;
     }
     myVlcControl.Play();
 }
 public void LoadGUI(Code.Media.MediaData m)
 {
     if (m != null)
     {
         this.UITitle.Text       = m.Name;
         this.UINameEdit.Text    = m.Name;
         this.UIUrlEdit.Text     = m.Url;
         this.UICommentEdit.Text = m.Comment;
         this.UILocalFile.Text   = "";
         if (m.TypeMedia.Code.ToUpper() == "FILE")
         {
             this.UIFtp.Visibility       = Visibility.Visible;
             this.UIChooseFile.IsEnabled = true;
             this.UIUrlEdit.IsEnabled    = false;
         }
         else
         {
             this.UIFtp.Visibility       = Visibility.Hidden;
             this.UIChooseFile.IsEnabled = false;
             this.UIUrlEdit.IsEnabled    = true;
             this.UINameLb.Text          = "Tên Camera:";
             this.UIUrlLb.Text           = "Địa chỉ rtsp:";
         }
     }
     else
     {
         if (this.Type == 1)
         {
             this.UITitle.Text           = "Thêm media mới";
             this.UIFtp.Visibility       = Visibility.Visible;
             this.UIChooseFile.IsEnabled = true;
             this.UIUrlEdit.IsEnabled    = false;
         }
         else
         {
             this.UITitle.Text           = "Thêm camera mới";
             this.UIFtp.Visibility       = Visibility.Hidden;
             this.UIChooseFile.IsEnabled = false;
             this.UIUrlEdit.IsEnabled    = true;
             this.UINameLb.Text          = "Tên Camera:";
             this.UIUrlLb.Text           = "Địa chỉ rtsp:";
         }
     }
 }
 private void Item_CloseEvent(object sender, Code.Media.MediaData e)
 {
     if (e != null)
     {
         bool isEdit = false;
         if (e.TypeMedia.Code.ToUpper() == "FILE")
         {
             foreach (UIMedia m in this.list_Box_Item.Items)
             {
                 if (m.Media.ID == e.ID)
                 {
                     m.Media = e;
                     isEdit  = true;
                     break;
                 }
             }
         }
         else
         {
             foreach (UIcamera m in this.list_Box_Item.Items)
             {
                 if (m.Media.ID == e.ID)
                 {
                     m.Media = e;
                     isEdit  = true;
                     break;
                 }
             }
         }
         if (!isEdit)
         {
             if (this.User == null)
             {
                 this.Datas = App.curUser.LoadMedias(this.from, this.to, out this.totalMedia, this.TypeMedia);
             }
             else
             {
                 this.Datas = this.User.LoadMedias(this.from, this.to, out this.totalMedia, this.TypeMedia, true);
             }
             this.LoadGUI();
         }
     }
     this.UIRoot.Children.Remove(sender as UIMediaEdit);
 }
        private void UIFtp_CompleteEvent(object sender, string e)
        {
            FileInfo file = new FileInfo(this.UILocalFile.Text);

            if (this.Media != null)
            {
                this.Media.FileSize = string.Format("{0}kb", file.Length / 1000);
                this.Media.Duration = file.toTimeMedia();
                this.Media.Url      = e;
                this.Media.Name     = this.UINameEdit.Text.Trim();
                this.Media.Comment  = this.UICommentEdit.Text.Trim();
                this.Media.Md5      = file.toMD5();
                this.Media.Save();
                if (this.CloseEvent != null)
                {
                    this.CloseEvent(this, this.Media);
                }
            }
            else
            {
                tmpMedia          = new Code.Media.MediaData();
                tmpMedia.Name     = this.UINameEdit.Text.Trim();
                tmpMedia.FileSize = string.Format("{0}kb", file.Length / 1000);
                tmpMedia.Duration = file.toTimeMedia();
                tmpMedia.Type     = this.Type;
                tmpMedia.Url      = e;
                tmpMedia.User_ID  = App.curUser.ID;
                tmpMedia.Comment  = this.UICommentEdit.Text;
                tmpMedia.Md5      = file.toMD5();
                int result = Code.Media.MediaData.Insert(tmpMedia);
                if (result <= 0)
                {
                    MessageBox.Show("Không thể kết nối với CSDL!");
                    return;
                }
                tmpMedia.ID = result;
                if (this.CloseEvent != null)
                {
                    this.CloseEvent(this, tmpMedia);
                }
            }
        }
        private void UIBtnSave_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            if (tmpMedia == null)
            {
                if (string.IsNullOrEmpty(this.UINameEdit.Text))
                {
                    MessageBox.Show("Tên video không được để trống!");
                    return;
                }
                if (this.Type == 1)
                {
                    #region File
                    if (this.Media == null && string.IsNullOrEmpty(this.UILocalFile.Text))
                    {
                        MessageBox.Show("Hãy chọn file bạn muốn tải lên!");
                        return;
                    }
                    else if (!string.IsNullOrEmpty(this.UILocalFile.Text))
                    {
                        FileInfo file = new FileInfo(this.UILocalFile.Text);
                        if (!file.Exists)
                        {
                            MessageBox.Show("Không tìm thấy file!");
                            return;
                        }
                        this.UIFtp.Local = this.UILocalFile.Text;
                        this.UIFtp.FtpUser = App.setting.ftp_user;
                        this.UIFtp.FtpPassword = App.setting.ftp_password;
                        if (this.Media == null)
                            this.UIFtp.Url = string.Format("{0}/{1}/video_{2}{3}", App.setting.ftp_server, App.setting.ftp_folder, DateTime.Now.Ticks, file.Extension);
                        else
                        {
                            if (this.Media.LocalFile.Exists)
                                this.Media.LocalFile.Delete();
                            this.UIFtp.Url = this.Media.Url;
                        }
                        this.UIFtp.RunUpLoad();
                    }
                    else if (this.Media != null)
                    {
                        this.Media.Name = this.UINameEdit.Text.Trim();
                        this.Media.Url = this.UIUrlEdit.Text;
                        this.Media.Comment = this.UICommentEdit.Text;
                        this.Media.Md5 = this.Media.LocalFile.toMD5();
                        this.Media.Save();
                        if (this.CloseEvent != null)
                        {
                            this.CloseEvent(this, this.Media);
                        }
                    }
                    else
                    {
                        if (this.UIFtp.Local == this.UILocalFile.Text)
                        {
                            tmpMedia.Name = this.UINameEdit.Text.Trim();
                            tmpMedia.Comment = this.UICommentEdit.Text;
                            tmpMedia.Md5 = tmpMedia.LocalFile.toMD5();
                            int result = Code.Media.MediaData.Insert(tmpMedia);
                            if (result <= 0)
                            {
                                MessageBox.Show("Không thể kết nối với CSDL!");
                                return;
                            }
                            tmpMedia.ID = result;

                            if (this.CloseEvent != null)
                            {
                                this.CloseEvent(this, tmpMedia);
                            }
                        }
                        else
                        {
                            FileInfo file = new FileInfo(this.UILocalFile.Text);
                            if (!file.Exists)
                            {
                                MessageBox.Show("Không tìm thấy file!");
                                return;
                            }
                            this.UIFtp.Local = this.UILocalFile.Text;
                            this.UIFtp.RunUpLoad();
                        }
                    }

                    #endregion
                }
                else
                {
                    if (this.Media == null)
                    {
                        Code.Media.MediaData tmp = new Code.Media.MediaData();
                        tmp.Name = this.UINameEdit.Text.Trim();
                        tmp.FileSize = string.Format("{0}kb", 0);
                        tmp.Duration = "00:00:00";
                        tmp.Type = this.Type;
                        tmp.Url = this.UIUrlEdit.Text;
                        tmp.User_ID = App.curUser.ID;
                        tmp.Comment = this.UICommentEdit.Text;
                        int result = Code.Media.MediaData.Insert(tmp);
                        if (result <= 0)
                        {
                            MessageBox.Show("Không thể kết nối với CSDL!");
                            return;
                        }
                        tmp.ID = result;
                        if (this.CloseEvent != null)
                        {
                            this.CloseEvent(this, tmp);
                        }
                    }
                    else
                    {
                        this.Media.Name = this.UINameEdit.Text.Trim();
                        this.Media.Url = this.UIUrlEdit.Text;
                        this.Media.Comment = this.UICommentEdit.Text.Trim();
                        this.Media.Save();
                        if (this.CloseEvent != null)
                        {
                            this.CloseEvent(this, this.Media);
                        }
                    }
                }
            }
        }
        private void UIFtp_CompleteEvent(object sender, string e)
        {
            FileInfo file = new FileInfo(this.UILocalFile.Text);
            if (this.Media != null)
            {
                this.Media.FileSize = string.Format("{0}kb", file.Length / 1000);
                this.Media.Duration = file.toTimeMedia();
                this.Media.Url = e;
                this.Media.Name = this.UINameEdit.Text.Trim();
                this.Media.Comment = this.UICommentEdit.Text.Trim();
                this.Media.Md5 = file.toMD5();
                this.Media.Save();
                if (this.CloseEvent != null)
                {
                    this.CloseEvent(this, this.Media);
                }
            }
            else
            {
                tmpMedia = new Code.Media.MediaData();
                tmpMedia.Name = this.UINameEdit.Text.Trim();
                tmpMedia.FileSize = string.Format("{0}kb", file.Length / 1000);
                tmpMedia.Duration = file.toTimeMedia();
                tmpMedia.Type = this.Type;
                tmpMedia.Url = e;
                tmpMedia.User_ID = App.curUser.ID;
                tmpMedia.Comment = this.UICommentEdit.Text;
                tmpMedia.Md5 =file.toMD5();
                int result = Code.Media.MediaData.Insert(tmpMedia);
                if (result <= 0)
                {
                    MessageBox.Show("Không thể kết nối với CSDL!");
                    return;
                }
                tmpMedia.ID = result;
                if (this.CloseEvent != null)
                {
                    this.CloseEvent(this, tmpMedia);
                }
            }

        }
Exemplo n.º 12
0
 private void Player_CloseEvent(object sender, Code.Media.MediaData e)
 {
     this.UIRoot.Children.Remove(sender as UIView.Media.MediaPlayer);
     this.isPlayingMedia = false;
 }
 private void UIBtnBack_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
 {
     if (this.index > 0)
     {
         this.index--;
         if (this.myVlcControl.IsPlaying)
         {
             this.myVlcControl.Stop();
         }
         this.Media = this.Medias[this.index];
         LoadGUI();
     }
 }
 private void UIBtnNext_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
 {
     if (this.index != -1 && this.index < this.Medias.Count - 1)
     {
         this.index++;
         this.Media = this.Medias[this.index];
         if (this.myVlcControl.IsPlaying)
         {
             this.myVlcControl.Stop();
         }
         LoadGUI();
     }
 }
        private void UIBtnSave_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            if (tmpMedia == null)
            {
                if (string.IsNullOrEmpty(this.UINameEdit.Text))
                {
                    MessageBox.Show("Tên video không được để trống!");
                    return;
                }
                if (this.Type == 1)
                {
                    #region File
                    if (this.Media == null && string.IsNullOrEmpty(this.UILocalFile.Text))
                    {
                        MessageBox.Show("Hãy chọn file bạn muốn tải lên!");
                        return;
                    }
                    else if (!string.IsNullOrEmpty(this.UILocalFile.Text))
                    {
                        FileInfo file = new FileInfo(this.UILocalFile.Text);
                        if (!file.Exists)
                        {
                            MessageBox.Show("Không tìm thấy file!");
                            return;
                        }
                        this.UIFtp.Local       = this.UILocalFile.Text;
                        this.UIFtp.FtpUser     = App.setting.ftp_user;
                        this.UIFtp.FtpPassword = App.setting.ftp_password;
                        if (this.Media == null)
                        {
                            this.UIFtp.Url = string.Format("{0}/{1}/video_{2}{3}", App.setting.ftp_server, App.setting.ftp_folder, DateTime.Now.Ticks, file.Extension);
                        }
                        else
                        {
                            if (this.Media.LocalFile.Exists)
                            {
                                this.Media.LocalFile.Delete();
                            }
                            this.UIFtp.Url = this.Media.Url;
                        }
                        this.UIFtp.RunUpLoad();
                    }
                    else if (this.Media != null)
                    {
                        this.Media.Name    = this.UINameEdit.Text.Trim();
                        this.Media.Url     = this.UIUrlEdit.Text;
                        this.Media.Comment = this.UICommentEdit.Text;
                        this.Media.Md5     = this.Media.LocalFile.toMD5();
                        this.Media.Save();
                        if (this.CloseEvent != null)
                        {
                            this.CloseEvent(this, this.Media);
                        }
                    }
                    else
                    {
                        if (this.UIFtp.Local == this.UILocalFile.Text)
                        {
                            tmpMedia.Name    = this.UINameEdit.Text.Trim();
                            tmpMedia.Comment = this.UICommentEdit.Text;
                            tmpMedia.Md5     = tmpMedia.LocalFile.toMD5();
                            int result = Code.Media.MediaData.Insert(tmpMedia);
                            if (result <= 0)
                            {
                                MessageBox.Show("Không thể kết nối với CSDL!");
                                return;
                            }
                            tmpMedia.ID = result;

                            if (this.CloseEvent != null)
                            {
                                this.CloseEvent(this, tmpMedia);
                            }
                        }
                        else
                        {
                            FileInfo file = new FileInfo(this.UILocalFile.Text);
                            if (!file.Exists)
                            {
                                MessageBox.Show("Không tìm thấy file!");
                                return;
                            }
                            this.UIFtp.Local = this.UILocalFile.Text;
                            this.UIFtp.RunUpLoad();
                        }
                    }

                    #endregion
                }
                else
                {
                    if (this.Media == null)
                    {
                        Code.Media.MediaData tmp = new Code.Media.MediaData();
                        tmp.Name     = this.UINameEdit.Text.Trim();
                        tmp.FileSize = string.Format("{0}kb", 0);
                        tmp.Duration = "00:00:00";
                        tmp.Type     = this.Type;
                        tmp.Url      = this.UIUrlEdit.Text;
                        tmp.User_ID  = App.curUser.ID;
                        tmp.Comment  = this.UICommentEdit.Text;
                        int result = Code.Media.MediaData.Insert(tmp);
                        if (result <= 0)
                        {
                            MessageBox.Show("Không thể kết nối với CSDL!");
                            return;
                        }
                        tmp.ID = result;
                        if (this.CloseEvent != null)
                        {
                            this.CloseEvent(this, tmp);
                        }
                    }
                    else
                    {
                        this.Media.Name    = this.UINameEdit.Text.Trim();
                        this.Media.Url     = this.UIUrlEdit.Text;
                        this.Media.Comment = this.UICommentEdit.Text.Trim();
                        this.Media.Save();
                        if (this.CloseEvent != null)
                        {
                            this.CloseEvent(this, this.Media);
                        }
                    }
                }
            }
        }
 private void Player_CloseEvent(object sender, Code.Media.MediaData e)
 {
     this.UIRoot.Children.Remove(sender as MediaPlayer);
 }