星火微课系统客户端
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

Uc_VideoItem.xaml.cs 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  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. return;
  237. }
  238. catch (Exception ex)
  239. {
  240. MessageWindow.Show("无法删除视频!" + ex.Message);
  241. return;
  242. }
  243. }
  244. }
  245. }
  246. }
  247. #endregion
  248. #region 播放视频
  249. private void BtnVideoPlay_Click(object sender, RoutedEventArgs e)
  250. {
  251. try
  252. {
  253. ProcessStartInfo psi = new ProcessStartInfo(VideoModel.VideoPath);
  254. Process pro = new Process
  255. {
  256. StartInfo = psi
  257. };
  258. pro.Start();
  259. }
  260. catch (Exception ex)
  261. {
  262. LogHelper.WriteErrLog("【视频播放】(BtnVideoPlay_Click)" + ex.Message, ex);
  263. System.Windows.MessageBox.Show(ex.Message);
  264. return;
  265. }
  266. }
  267. /// <summary>
  268. /// 视频播放
  269. /// </summary>
  270. /// <param name="sender"></param>
  271. /// <param name="e"></param>
  272. private void Image_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  273. {
  274. try
  275. {
  276. ProcessStartInfo psi = new ProcessStartInfo(VideoModel.VideoPath);
  277. Process pro = new Process
  278. {
  279. StartInfo = psi
  280. };
  281. pro.Start();
  282. }
  283. catch (Exception ex)
  284. {
  285. LogHelper.WriteErrLog("【视频播放】(BtnVideoPlay_Click)" + ex.Message, ex);
  286. System.Windows.MessageBox.Show(ex.Message);
  287. return;
  288. }
  289. }
  290. #endregion
  291. /// <summary>
  292. /// 视频上传
  293. /// </summary>
  294. /// <param name="sender"></param>
  295. /// <param name="e"></param>
  296. private void BtnUpload_Click(object sender, RoutedEventArgs e)
  297. {
  298. if (APP.IsLoginType == false)
  299. {
  300. //登陆
  301. Click_UploadLogin();
  302. return;
  303. }
  304. if (!IsUpLoad)
  305. {
  306. IsUpLoad = true;
  307. //BtnUpload.IsEnabled = false;
  308. //BtnUpload.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#9EA0A7"));
  309. //BtnUpload.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#999999"));
  310. DAL_Upload dAL_Upload = new DAL_Upload();
  311. if (dAL_Upload.UploadVideo(VideoModel.FileGuid, out string ErrMessage))
  312. {
  313. //MessageWindow.Show("视频上传服务器成功!");
  314. if (W_UploadWindow == null)
  315. {
  316. W_UploadWindow = new UploadWindow
  317. {
  318. Owner = APP.W_XHMicroLessonSystemWindow
  319. };
  320. W_UploadWindow.ChangeTextEvents += frm_ChangeTextEvents; ;
  321. }
  322. //long size = Convert.ToInt64(FileToolsCommon.GetFileSizeByMB(pageData.menuList[i].FilePath));
  323. W_UploadWindow.Initialize(TbName.Text, VideoModel.VideoSizebyte, VideoModel.VideoType.ToString(), VideoModel.FileGuid, 0);
  324. W_UploadWindow.ShowDialog();
  325. }
  326. else
  327. {
  328. IsUpLoad = false;
  329. MessageWindow.Show(ErrMessage);
  330. }
  331. }
  332. }
  333. /// <summary>
  334. /// 上传返回事件
  335. /// </summary>
  336. /// <param name="text"></param>
  337. private void frm_ChangeTextEvents(string text, int i)
  338. {
  339. if ("上传成功".Equals(text))
  340. {
  341. W_UploadWindow.Close();
  342. //BtnUpload.Visibility = Visibility.Hidden;
  343. BorUploadBtn.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#DDDDDD"));
  344. BtnUpload.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#999999"));
  345. BtnUpload.IsEnabled = false;
  346. }
  347. }
  348. }
  349. }