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

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