|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380 |
- using Common.system;
-
- using System;
- using System.Diagnostics;
- using System.Windows;
- using System.Windows.Input;
-
- using XHWK.Model;
- using XHWK.WKTool.DAL;
-
- namespace XHWK.WKTool.UControl
- {
- using system;
-
- /// <summary>
- /// 视频信息
- /// </summary>
- public partial class UcVideoItem
- {
- #region 初始值
-
- /// <summary>
- /// 视频模型
- /// </summary>
- private ModelVideo _videoModel;
-
- /// <summary>
- /// 刷新视频列表
- /// </summary>
- public delegate void RefreshVideoList();
-
- /// <summary>
- /// 刷新视频列表事件
- /// </summary>
- public event RefreshVideoList ClickRefreshVideoList;
-
- /// <summary>
- /// 登录
- /// </summary>
- public delegate void UploadLogin();
-
- /// <summary>
- /// 登录事件
- /// </summary>
- public event UploadLogin ClickUploadLogin;
-
- /// <summary>
- /// 上传页面
- /// </summary>
- private UploadWindow _wUploadWindow;
-
- #endregion 初始值
-
- #region 初始化
-
- /// <summary>
- /// 视频信息
- /// </summary>
- /// <param name="modelVideo"></param>
- public UcVideoItem(ModelVideo modelVideo)
- {
- InitializeComponent();
- App.IsUpLoad = false;
- _videoModel = modelVideo;
- DataContext = App.PageContextData;
- if (FileToolsCommon.IsExistFile(_videoModel.ThumbnailPath))
- {
- ImgVideo.Source = ImageHelper.ReadBitmapImageFile(_videoModel.ThumbnailPath); // new BitmapImage(new Uri(VideoModel.ThumbnailPath));
- }
- string videoName = FileToolsCommon.GetIoFileNameNoExtension(_videoModel.VideoPath);
- TbName.Text = videoName.Length > 11 ? videoName.Substring(0, 11) + "..." : videoName;
- TbName.ToolTip = videoName;
- LblDateSize.Content = _videoModel.RSTime + " " + _videoModel.VideoSize;
- if (_videoModel.IsUpload)
- {
- BtnUpload.IsEnabled = false;
- BtnUpload.Background.Opacity = 0.6;
- }
- }
-
- #endregion 初始化
-
- #region 修改视频名
-
- /// <summary>
- /// 双击修改视频名
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void TextBlock_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
- {
- if (e.ClickCount == 2)
- {
- TxtModify.Text = TbName.ToolTip.ToString();
- TbName.Visibility = Visibility.Hidden;
- GridModify.Visibility = Visibility.Visible;
- }
- }
-
- /// <summary>
- /// 失去焦点保存视频名
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void TxtModify_LostFocus(object sender, RoutedEventArgs e)
- {
- ModifyVideoName();
- }
-
- /// <summary>
- /// Enter保存
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void TxtModify_KeyUp(object sender, KeyEventArgs e)
- {
- if (e.Key == System.Windows.Input.Key.Enter)
- {
- ModifyVideoName();
- }
- }
-
- /// <summary>
- /// 修改文件名保存
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnNameModifyOK_Click(object sender, RoutedEventArgs e)
- {
- ModifyVideoName();
- }
-
- /// <summary>
- /// 修改视频文件名
- /// </summary>
- private void ModifyVideoName()
- {
- if (TxtModify.Text != TbName.Text)
- {
- if (ModifyPathName(_videoModel.FileGuid, TxtModify.Text + "." + _videoModel.VideoType, out string errMessage))
- {
- //保存成功
- TbName.Text = TxtModify.Text.Length > 11 ? TxtModify.Text.Substring(0, 11) + "..." : TxtModify.Text;
- TbName.ToolTip = TxtModify.Text;
- TbName.Visibility = Visibility.Visible;
- GridModify.Visibility = Visibility.Hidden;
- }
- else
- {
- MessageWindow.Show(errMessage);
- }
- }
- else
- {
- TbName.Visibility = Visibility.Visible;
- GridModify.Visibility = Visibility.Hidden;
- }
- }
-
- /// <summary>
- /// 修改视频文件名
- /// </summary>
- /// <param name="fileGuid"></param>
- /// <param name="newName">新文件名带后缀 不带路径</param>
- /// <param name="errmessage">错误信息</param>
- /// <returns></returns>
- private bool ModifyPathName(string fileGuid, string newName, out string errmessage)
- {
- errmessage = "";
- foreach (ModelWkData wkData in App.WKDataList)
- {
- if (wkData.VideoList.Exists(x => x.FileGuid == fileGuid))
- {
- ModelVideo modelVideo = wkData.VideoList.Find(x => x.FileGuid == fileGuid);
- string filePathName = modelVideo.VideoPath;
- string filePath = FileToolsCommon.GetDirectoryName(filePathName);
- string newFilePathName = filePath + newName;
- //缩略图
- string thumbnailPath = filePath + "ThumbnailPath/";
- FileToolsCommon.CreateDirectory(thumbnailPath);
- //缩略图存储位置
- string thumbnailPathName = thumbnailPath + newName.Replace(".", "") + ".JPG";
- if (FileToolsCommon.IsExistFile(newFilePathName))
- {
- errmessage = "文件已存在,请重新修改文件名!";
- return false;
- }
- //修改文件名
- FileToolsCommon.Copy(filePathName, newFilePathName);
- modelVideo.VideoPath = newFilePathName;
- //修改缩略图名
- FileToolsCommon.DeleteFile(thumbnailPathName);
- FileToolsCommon.Copy(modelVideo.ThumbnailPath, thumbnailPathName);
- modelVideo.ThumbnailPath = thumbnailPathName;
- App.SaveWkData();
- return true;
- }
- }
- errmessage = "视频文件有改动,当前文件不存在,请关闭后重新打开“我的”";
- return false;
- }
-
- #endregion 修改视频名
-
- #region 删除视频
-
- /// <summary>
- /// 删除视频
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnDelVideo_Click(object sender, RoutedEventArgs e)
- {
- MessageBoxResult dr = MessageWindow.Show("确定删除该视频?", "提示", MessageBoxButton.OKCancel);
- if (dr == MessageBoxResult.OK)
- {
- foreach (ModelWkData wKData in App.WKDataList)
- {
- if (wKData.VideoList == null)
- {
- continue;
- }
- if (wKData.VideoList.Exists(x => x.FileGuid == _videoModel.FileGuid))
- {
- try
- {
- FileToolsCommon.DeleteFile(wKData.VideoList.Find(x => x.FileGuid == _videoModel.FileGuid).VideoPath);
- string thumbnailPath = wKData.VideoList.Find(x => x.FileGuid == _videoModel.FileGuid).ThumbnailPath;
- wKData.VideoList.Remove(wKData.VideoList.Find(x => x.FileGuid == _videoModel.FileGuid));
- //初始化页面 刷新视频列表
- if (ClickRefreshVideoList != null)
- {
- ClickRefreshVideoList();
- }
- ImgVideo.Source = null;
- GC.Collect();
- FileToolsCommon.DeleteFile(thumbnailPath);
- Visibility = Visibility.Hidden;
- return;
- }
- catch (Exception ex)
- {
- MessageWindow.Show("无法删除视频!" + ex.Message);
- return;
- }
- }
- }
- }
- }
-
- #endregion 删除视频
-
- #region 播放视频
-
- private void BtnVideoPlay_Click(object sender, RoutedEventArgs e)
- {
- try
- {
- ProcessStartInfo psi = new ProcessStartInfo(_videoModel.VideoPath);
- Process pro = new Process
- {
- StartInfo = psi
- };
- pro.Start();
- }
- catch (Exception ex)
- {
- LogHelper.Logerror.Error("【视频播放】(BtnVideoPlay_Click)" + ex.Message, ex);
- System.Windows.MessageBox.Show(ex.Message);
- }
- }
-
- /// <summary>
- /// 视频播放
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void Image_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
- {
- try
- {
- ProcessStartInfo psi = new ProcessStartInfo(_videoModel.VideoPath);
- Process pro = new Process
- {
- StartInfo = psi
- };
- pro.Start();
- }
- catch (Exception ex)
- {
- LogHelper.Logerror.Error("【视频播放】(BtnVideoPlay_Click)" + ex.Message, ex);
- System.Windows.MessageBox.Show(ex.Message);
- }
- }
-
- #endregion 播放视频
-
- /// <summary>
- /// 视频上传
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnUpload_Click(object sender, RoutedEventArgs e)
- {
- if (App.IsLoginType == false)
- {
- //登录
- if (ClickUploadLogin != null)
- {
- ClickUploadLogin();
- }
- if (App.IsLoginType == false)
- {
- return;
- }
- }
- if (!App.IsUpLoad)
- {
- App.IsUpLoad = true;
- DalUpload dAlUpload = new DalUpload();
- if (dAlUpload.UploadVideo(_videoModel.FileGuid, out string errMessage))
- {
- App.IsUpLoad = false;
- //MessageWindow.Show("视频上传服务器成功!");
- if (_wUploadWindow == null)
- {
- _wUploadWindow = new UploadWindow { Owner = App.W_XHMicroLessonSystemWindow };
- _wUploadWindow.ChangeTextEvents += frm_ChangeTextEvents;
- }
-
- //long size = Convert.ToInt64(FileToolsCommon.GetFileSizeByMB(pageData.menuList[i].FilePath));
- _wUploadWindow.Initialize(
- TbName.Text,
- _videoModel.VideoSizebyte,
- _videoModel.VideoType.ToString(),
- _videoModel.FileGuid,
- 0
- );
- }
- else
- {
- App.IsUpLoad = false;
- MessageWindow.Show(errMessage);
- }
- }
- }
-
- /// <summary>
- /// 上传返回事件
- /// </summary>
- /// <param name="text"></param>
- /// <param name="i"></param>
- private void frm_ChangeTextEvents(string text, int i)
- {
- if ("上传成功".Equals(text))
- {
- _wUploadWindow.Close();
- BtnUpload.IsEnabled = false;
- BtnUpload.Background.Opacity = 0.6;
- }
- }
-
- /// <summary>
- /// 编辑
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void Button_Click(object sender, RoutedEventArgs e)
- {
- if (App.W_VideoClipWindow == null)
- {
- App.W_VideoClipWindow = new VideoClipWindow();
- }
- if (App.W_VideoClipWindow.InitClipVideo(_videoModel.VideoPath))
- {
- App.W_VideoClipWindow.ShowDialog();
- }
- }
- }
- }
|