星火微课系统客户端
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

Uc_VideoItem.xaml.cs 13KB

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