星火微课系统客户端
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

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