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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  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. #endregion
  52. #region 初始化
  53. /// <summary>
  54. /// 视频信息
  55. /// </summary>
  56. /// <param name="model_Video"></param>
  57. public Uc_VideoItem(Model_Video model_Video)
  58. {
  59. InitializeComponent();
  60. APP.IsUpLoad = false;
  61. VideoModel = model_Video;
  62. if (FileToolsCommon.IsExistFile(VideoModel.ThumbnailPath))
  63. {
  64. ImgVideo.Source = ImageHelper.ReadBitmapImageFile(VideoModel.ThumbnailPath);// new BitmapImage(new Uri(VideoModel.ThumbnailPath));
  65. }
  66. string videoName = FileToolsCommon.GetIOFileNameNoExtension(VideoModel.VideoPath);
  67. TbName.Text = videoName.Length > 11 ? videoName.Substring(0, 11) + "..." : videoName;
  68. TbName.ToolTip = videoName;
  69. lblDateSize.Content = VideoModel.RSTime + "|" + VideoModel.VideoSize;
  70. if (VideoModel.IsUpload)
  71. {
  72. //BtnUpload.Visibility = Visibility.Hidden;
  73. BorUploadBtn.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#DDDDDD"));
  74. BtnUpload.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#999999"));
  75. BtnUpload.IsEnabled = false;
  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 > 11 ? TxtModify.Text.Substring(0, 11) + "..." : 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. this.Visibility = Visibility.Hidden;
  234. return;
  235. }
  236. catch (Exception ex)
  237. {
  238. MessageWindow.Show("无法删除视频!" + ex.Message);
  239. return;
  240. }
  241. }
  242. }
  243. }
  244. }
  245. #endregion
  246. #region 播放视频
  247. private void BtnVideoPlay_Click(object sender, RoutedEventArgs e)
  248. {
  249. try
  250. {
  251. ProcessStartInfo psi = new ProcessStartInfo(VideoModel.VideoPath);
  252. Process pro = new Process
  253. {
  254. StartInfo = psi
  255. };
  256. pro.Start();
  257. }
  258. catch (Exception ex)
  259. {
  260. LogHelper.WriteErrLog("【视频播放】(BtnVideoPlay_Click)" + ex.Message, ex);
  261. System.Windows.MessageBox.Show(ex.Message);
  262. return;
  263. }
  264. }
  265. /// <summary>
  266. /// 视频播放
  267. /// </summary>
  268. /// <param name="sender"></param>
  269. /// <param name="e"></param>
  270. private void Image_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  271. {
  272. try
  273. {
  274. ProcessStartInfo psi = new ProcessStartInfo(VideoModel.VideoPath);
  275. Process pro = new Process
  276. {
  277. StartInfo = psi
  278. };
  279. pro.Start();
  280. }
  281. catch (Exception ex)
  282. {
  283. LogHelper.WriteErrLog("【视频播放】(BtnVideoPlay_Click)" + ex.Message, ex);
  284. System.Windows.MessageBox.Show(ex.Message);
  285. return;
  286. }
  287. }
  288. #endregion
  289. /// <summary>
  290. /// 视频上传
  291. /// </summary>
  292. /// <param name="sender"></param>
  293. /// <param name="e"></param>
  294. private void BtnUpload_Click(object sender, RoutedEventArgs e)
  295. {
  296. if (APP.IsLoginType == false)
  297. {
  298. //登陆
  299. Click_UploadLogin();
  300. return;
  301. }
  302. if (!APP.IsUpLoad)
  303. {
  304. APP.IsUpLoad = true;
  305. //BtnUpload.IsEnabled = false;
  306. //BtnUpload.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#9EA0A7"));
  307. //BtnUpload.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#999999"));
  308. DAL_Upload dAL_Upload = new DAL_Upload();
  309. if (dAL_Upload.UploadVideo(VideoModel.FileGuid, out string ErrMessage))
  310. {
  311. //MessageWindow.Show("视频上传服务器成功!");
  312. if (W_UploadWindow == null)
  313. {
  314. W_UploadWindow = new UploadWindow
  315. {
  316. Owner = APP.W_XHMicroLessonSystemWindow
  317. };
  318. W_UploadWindow.ChangeTextEvents += frm_ChangeTextEvents; ;
  319. }
  320. //long size = Convert.ToInt64(FileToolsCommon.GetFileSizeByMB(pageData.menuList[i].FilePath));
  321. W_UploadWindow.Initialize(TbName.Text, VideoModel.VideoSizebyte, VideoModel.VideoType.ToString(), VideoModel.FileGuid, 0);
  322. W_UploadWindow.ShowDialog();
  323. }
  324. else
  325. {
  326. APP.IsUpLoad = false;
  327. MessageWindow.Show(ErrMessage);
  328. }
  329. }
  330. }
  331. /// <summary>
  332. /// 上传返回事件
  333. /// </summary>
  334. /// <param name="text"></param>
  335. private void frm_ChangeTextEvents(string text, int i)
  336. {
  337. if ("上传成功".Equals(text))
  338. {
  339. W_UploadWindow.Close();
  340. //BtnUpload.Visibility = Visibility.Hidden;
  341. BorUploadBtn.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#DDDDDD"));
  342. BtnUpload.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#999999"));
  343. BtnUpload.IsEnabled = false;
  344. }
  345. }
  346. }
  347. }