星火微课系统客户端
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

Uc_VideoItem.xaml.cs 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. using Common.system;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Diagnostics;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Windows;
  9. using System.Windows.Controls;
  10. using System.Windows.Data;
  11. using System.Windows.Documents;
  12. using System.Windows.Input;
  13. using System.Windows.Media;
  14. using System.Windows.Media.Imaging;
  15. using System.Windows.Navigation;
  16. using System.Windows.Shapes;
  17. using XHWK.Model;
  18. using XHWK.WKTool.DAL;
  19. namespace XHWK.WKTool.UControl
  20. {
  21. /// <summary>
  22. /// 视频信息
  23. /// </summary>
  24. public partial class Uc_VideoItem : UserControl
  25. {
  26. #region 初始值
  27. /// <summary>
  28. /// 视频模型
  29. /// </summary>
  30. Model_Video VideoModel = new Model_Video();
  31. /// <summary>
  32. /// 刷新视频列表
  33. /// </summary>
  34. public delegate void RefreshVideoList();
  35. /// <summary>
  36. /// 刷新视频列表事件
  37. /// </summary>
  38. public event RefreshVideoList Click_refreshVideoList;
  39. /// <summary>
  40. /// 登陆
  41. /// </summary>
  42. public delegate void UploadLogin();
  43. /// <summary>
  44. /// 登陆事件
  45. /// </summary>
  46. public event UploadLogin Click_UploadLogin;
  47. /// <summary>
  48. /// 上传页面
  49. /// </summary>
  50. UploadWindow W_UploadWindow = null;
  51. /// <summary>
  52. /// 是否正在
  53. /// </summary>
  54. bool IsUpLoad = false;
  55. #endregion
  56. #region 初始化
  57. /// <summary>
  58. /// 视频信息
  59. /// </summary>
  60. /// <param name="model_Video"></param>
  61. public Uc_VideoItem(Model_Video model_Video)
  62. {
  63. InitializeComponent();
  64. VideoModel = model_Video;
  65. if (FileToolsCommon.IsExistFile(VideoModel.ThumbnailPath))
  66. {
  67. ImgVideo.Source = ImageHelper.ReadBitmapImageFile(VideoModel.ThumbnailPath);// new BitmapImage(new Uri(VideoModel.ThumbnailPath));
  68. }
  69. string videoName = FileToolsCommon.GetIOFileNameNoExtension(VideoModel.VideoPath);
  70. TbName.Text = videoName.Length > 11 ? videoName.Substring(0, 11) + "..." : videoName;
  71. TbName.ToolTip = videoName;
  72. lblDateSize.Content = VideoModel.RSTime + "|" + VideoModel.VideoSize;
  73. if (VideoModel.IsUpload)
  74. {
  75. //BtnUpload.Visibility = Visibility.Hidden;
  76. BorUploadBtn.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#DDDDDD"));
  77. BtnUpload.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#999999"));
  78. BtnUpload.IsEnabled = false;
  79. }
  80. }
  81. #endregion
  82. #region 修改视频名
  83. /// <summary>
  84. /// 双击修改视频名
  85. /// </summary>
  86. /// <param name="sender"></param>
  87. /// <param name="e"></param>
  88. private void TextBlock_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  89. {
  90. if(e.ClickCount==2)
  91. {
  92. TxtModify.Text = TbName.ToolTip.ToString();
  93. TbName.Visibility = Visibility.Hidden;
  94. TxtModify.Visibility = Visibility.Visible;
  95. BtnNameModifyOK.Visibility = Visibility.Visible;
  96. }
  97. }
  98. /// <summary>
  99. /// 失去焦点保存视频名
  100. /// </summary>
  101. /// <param name="sender"></param>
  102. /// <param name="e"></param>
  103. private void TxtModify_LostFocus(object sender, RoutedEventArgs e)
  104. {
  105. ModifyVideoName();
  106. }
  107. /// <summary>
  108. /// Enter保存
  109. /// </summary>
  110. /// <param name="sender"></param>
  111. /// <param name="e"></param>
  112. private void TxtModify_KeyUp(object sender, KeyEventArgs e)
  113. {
  114. if (e.Key == System.Windows.Input.Key.Enter)
  115. {
  116. ModifyVideoName();
  117. }
  118. }
  119. /// <summary>
  120. /// 修改文件名保存
  121. /// </summary>
  122. /// <param name="sender"></param>
  123. /// <param name="e"></param>
  124. private void BtnNameModifyOK_Click(object sender, RoutedEventArgs e)
  125. {
  126. ModifyVideoName();
  127. }
  128. /// <summary>
  129. /// 修改视频文件名
  130. /// </summary>
  131. void ModifyVideoName()
  132. {
  133. if (TxtModify.Text != TbName.Text)
  134. {
  135. string ErrMessage;
  136. if (ModifyPathName(VideoModel.FileGuid, TxtModify.Text + "." + VideoModel.VideoType, out ErrMessage))
  137. {
  138. //保存成功
  139. TbName.Text = TxtModify.Text.Length > 11 ? TxtModify.Text.Substring(0, 11) + "..." : TxtModify.Text;
  140. TbName.ToolTip = TxtModify.Text;
  141. TbName.Visibility = Visibility.Visible;
  142. TxtModify.Visibility = Visibility.Hidden;
  143. BtnNameModifyOK.Visibility = Visibility.Hidden;
  144. }
  145. else
  146. {
  147. MessageWindow.Show(ErrMessage);
  148. }
  149. }
  150. else
  151. {
  152. TbName.Visibility = Visibility.Visible;
  153. TxtModify.Visibility = Visibility.Hidden;
  154. BtnNameModifyOK.Visibility = Visibility.Hidden;
  155. }
  156. }
  157. /// <summary>
  158. /// 修改视频文件名
  159. /// </summary>
  160. /// <param name="Guid">唯一编号</param>
  161. /// <param name="NewName">新文件名带后缀 不带路径</param>
  162. /// <param name="Errmessage">错误信息</param>
  163. /// <returns></returns>
  164. private bool ModifyPathName(string FileGuid, string NewName, out string Errmessage)
  165. {
  166. Errmessage = "";
  167. foreach (Model_WKData WKData in APP.WKDataList)
  168. {
  169. if (WKData.VideoList.Exists(x => x.FileGuid == FileGuid))
  170. {
  171. Model_Video model_Video = WKData.VideoList.Find(x => x.FileGuid == FileGuid);
  172. string filePathName = model_Video.VideoPath;
  173. string filePath = FileToolsCommon.GetDirectoryName(filePathName);
  174. string newFilePathName = filePath + NewName;
  175. //缩略图
  176. string ThumbnailPath = filePath + "ThumbnailPath/";
  177. FileToolsCommon.CreateDirectory(ThumbnailPath);
  178. //缩略图存储位置
  179. string ThumbnailPathName = ThumbnailPath + NewName.Replace(".", "") + ".JPG";
  180. if (FileToolsCommon.IsExistFile(newFilePathName))
  181. {
  182. Errmessage = "文件已存在,请重新修改文件名!";
  183. return false;
  184. }
  185. else
  186. {
  187. //修改文件名
  188. FileToolsCommon.Copy(filePathName, newFilePathName);
  189. model_Video.VideoPath = newFilePathName;
  190. //修改缩略图名
  191. FileToolsCommon.DeleteFile(ThumbnailPathName);
  192. FileToolsCommon.Copy(model_Video.ThumbnailPath, ThumbnailPathName);
  193. model_Video.ThumbnailPath = ThumbnailPathName;
  194. APP.SaveWkData();
  195. return true;
  196. }
  197. }
  198. else
  199. {
  200. continue;
  201. }
  202. }
  203. Errmessage = "视频文件有改动,当前文件不存在,请关闭后重新打开“我的”";
  204. return false;
  205. }
  206. #endregion
  207. #region 删除视频
  208. /// <summary>
  209. /// 删除视频
  210. /// </summary>
  211. /// <param name="sender"></param>
  212. /// <param name="e"></param>
  213. private void BtnDelVideo_Click(object sender, RoutedEventArgs e)
  214. {
  215. MessageBoxResult dr = MessageWindow.Show("确定删除该视频?", "提示", MessageBoxButton.OKCancel);
  216. if (dr == MessageBoxResult.OK)
  217. {
  218. foreach (Model_WKData wKData in APP.WKDataList)
  219. {
  220. if (wKData.VideoList == null)
  221. {
  222. continue;
  223. }
  224. if (wKData.VideoList.Exists(x => x.FileGuid == VideoModel.FileGuid))
  225. {
  226. try
  227. {
  228. FileToolsCommon.DeleteFile(wKData.VideoList.Find(x => x.FileGuid == VideoModel.FileGuid).VideoPath);
  229. string ThumbnailPath = wKData.VideoList.Find(x => x.FileGuid == VideoModel.FileGuid).ThumbnailPath;
  230. wKData.VideoList.Remove(wKData.VideoList.Find(x => x.FileGuid == VideoModel.FileGuid));
  231. //初始化页面 刷新视频列表
  232. Click_refreshVideoList();
  233. ImgVideo.Source = null;
  234. GC.Collect();
  235. FileToolsCommon.DeleteFile(ThumbnailPath);
  236. this.Visibility = Visibility.Hidden;
  237. return;
  238. }
  239. catch (Exception ex)
  240. {
  241. MessageWindow.Show("无法删除视频!" + ex.Message);
  242. return;
  243. }
  244. }
  245. }
  246. }
  247. }
  248. #endregion
  249. #region 播放视频
  250. private void BtnVideoPlay_Click(object sender, RoutedEventArgs e)
  251. {
  252. try
  253. {
  254. ProcessStartInfo psi = new ProcessStartInfo(VideoModel.VideoPath);
  255. Process pro = new Process
  256. {
  257. StartInfo = psi
  258. };
  259. pro.Start();
  260. }
  261. catch (Exception ex)
  262. {
  263. LogHelper.WriteErrLog("【视频播放】(BtnVideoPlay_Click)" + ex.Message, ex);
  264. System.Windows.MessageBox.Show(ex.Message);
  265. return;
  266. }
  267. }
  268. /// <summary>
  269. /// 视频播放
  270. /// </summary>
  271. /// <param name="sender"></param>
  272. /// <param name="e"></param>
  273. private void Image_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  274. {
  275. try
  276. {
  277. ProcessStartInfo psi = new ProcessStartInfo(VideoModel.VideoPath);
  278. Process pro = new Process
  279. {
  280. StartInfo = psi
  281. };
  282. pro.Start();
  283. }
  284. catch (Exception ex)
  285. {
  286. LogHelper.WriteErrLog("【视频播放】(BtnVideoPlay_Click)" + ex.Message, ex);
  287. System.Windows.MessageBox.Show(ex.Message);
  288. return;
  289. }
  290. }
  291. #endregion
  292. /// <summary>
  293. /// 视频上传
  294. /// </summary>
  295. /// <param name="sender"></param>
  296. /// <param name="e"></param>
  297. private void BtnUpload_Click(object sender, RoutedEventArgs e)
  298. {
  299. if (APP.IsLoginType == false)
  300. {
  301. //登陆
  302. Click_UploadLogin();
  303. return;
  304. }
  305. if (!IsUpLoad)
  306. {
  307. IsUpLoad = true;
  308. //BtnUpload.IsEnabled = false;
  309. //BtnUpload.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#9EA0A7"));
  310. //BtnUpload.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#999999"));
  311. DAL_Upload dAL_Upload = new DAL_Upload();
  312. if (dAL_Upload.UploadVideo(VideoModel.FileGuid, out string ErrMessage))
  313. {
  314. //MessageWindow.Show("视频上传服务器成功!");
  315. if (W_UploadWindow == null)
  316. {
  317. W_UploadWindow = new UploadWindow
  318. {
  319. Owner = APP.W_XHMicroLessonSystemWindow
  320. };
  321. W_UploadWindow.ChangeTextEvents += frm_ChangeTextEvents; ;
  322. }
  323. //long size = Convert.ToInt64(FileToolsCommon.GetFileSizeByMB(pageData.menuList[i].FilePath));
  324. W_UploadWindow.Initialize(TbName.Text, VideoModel.VideoSizebyte, VideoModel.VideoType.ToString(), VideoModel.FileGuid, 0);
  325. W_UploadWindow.ShowDialog();
  326. }
  327. else
  328. {
  329. IsUpLoad = false;
  330. MessageWindow.Show(ErrMessage);
  331. }
  332. }
  333. }
  334. /// <summary>
  335. /// 上传返回事件
  336. /// </summary>
  337. /// <param name="text"></param>
  338. private void frm_ChangeTextEvents(string text, int i)
  339. {
  340. if ("上传成功".Equals(text))
  341. {
  342. W_UploadWindow.Close();
  343. //BtnUpload.Visibility = Visibility.Hidden;
  344. BorUploadBtn.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#DDDDDD"));
  345. BtnUpload.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#999999"));
  346. BtnUpload.IsEnabled = false;
  347. }
  348. }
  349. }
  350. }