星火微课系统客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Uc_VideoItem.xaml.cs 14KB

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