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

FileDirectoryWindow.xaml.cs 17KB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  1. using Common.system;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Collections.ObjectModel;
  5. using System.Diagnostics;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Input;
  9. using System.Windows.Media;
  10. using XHWK.Model;
  11. using XHWK.WKTool.DAL;
  12. using XHWK.WKTool.Models;
  13. namespace XHWK.WKTool
  14. {
  15. /// <summary>
  16. /// 文件目录
  17. /// </summary>
  18. public partial class FileDirectoryWindow : Window
  19. {
  20. /// <summary>
  21. /// 视频模型
  22. /// </summary>
  23. private List<Model_Video> model_VideoList = null;
  24. /// <summary>
  25. /// 数据列表
  26. /// </summary>
  27. internal FileDirectoryData pageData = new FileDirectoryData();
  28. /// <summary>
  29. /// 下标
  30. /// </summary>
  31. private int Subscript = 0;
  32. /// <summary>
  33. /// 是否是修改状态
  34. /// </summary>
  35. private bool IsModify = false;
  36. /// <summary>
  37. /// 文件目录
  38. /// </summary>
  39. public FileDirectoryWindow()
  40. {
  41. InitializeComponent();
  42. Initialize();
  43. }
  44. /// <summary>
  45. /// 初始化
  46. /// </summary>
  47. public void Initialize()
  48. {
  49. APP.myloading.Show();
  50. //MouseNumber = 0;
  51. IsModify = false;
  52. //加载视频列表
  53. LoadingVideoList();
  54. int i = 1;
  55. bool isColour = true;
  56. pageData.menuList.Clear();
  57. //显示视频
  58. foreach (Model_Video videoinfo in model_VideoList)
  59. {
  60. //是否已上传
  61. //videoinfo.IsUpload;
  62. //录制时间
  63. //videoinfo.RSTime;
  64. //文件大小
  65. //videoinfo.VideoSize;
  66. //文件缩略图路径
  67. //videoinfo.ThumbnailPath;
  68. //文件唯一标示 上传事件筛选需要上传的视频
  69. //videoinfo.FileGuid;
  70. //文件存储路径
  71. //videoinfo.VidePath;
  72. string colour = "#FFFFFF";
  73. if (isColour == true)
  74. {
  75. colour = "#FFFFFF";
  76. isColour = false;
  77. }
  78. else
  79. {
  80. colour = "#E6F1FF";
  81. isColour = true;
  82. }
  83. string vis = "Visible";
  84. string cos = "Collapsed";
  85. if (!videoinfo.IsUpload)
  86. {
  87. vis = "Collapsed";
  88. cos = "Visible";
  89. }
  90. if (i <= 16)
  91. {
  92. pageData.menuList.Add(new FileDirectoryModel()
  93. {
  94. SerialNumber = i,
  95. VideoName = Common.system.FileToolsCommon.GetIOFileName(videoinfo.VideoPath).Replace(".MP4", "").Replace(".FLV", "").Replace(".AVI", "").Trim(),
  96. Name = Common.system.FileToolsCommon.GetIOFileName(videoinfo.VideoPath).Replace(".MP4", "").Replace(".FLV", "").Replace(".AVI", "").Trim(),
  97. FilePath = videoinfo.VideoPath.Replace(FileToolsCommon.GetIOFileName(videoinfo.VideoPath), "").Trim(),
  98. VideoDuration = 0,
  99. VideoSize = videoinfo.VideoSize,
  100. VideoTime = videoinfo.RSTime,
  101. IsEnabled = false,
  102. Path = videoinfo.VideoPath,
  103. Colour = colour,
  104. Visi = vis,
  105. Coll = cos,
  106. FileGuid = videoinfo.FileGuid,
  107. VideoType = videoinfo.VideoType.ToString()
  108. }); ;
  109. }
  110. i++;
  111. }
  112. txbSum.Text = pageData.menuList.Count.ToString();
  113. APP.myloading.Hide();
  114. DataContext = pageData;
  115. }
  116. /// <summary>
  117. /// 加载视频列表
  118. /// </summary>
  119. public void LoadingVideoList()
  120. {
  121. try
  122. {
  123. model_VideoList = new List<Model_Video>();
  124. foreach (Model_WKData Vdata in APP.WKDataList)
  125. {
  126. if (Vdata.VideoList == null)
  127. {
  128. continue;
  129. }
  130. foreach (Model_Video videoinfo in Vdata.VideoList)
  131. {
  132. try
  133. {
  134. if (string.IsNullOrWhiteSpace(videoinfo.VideoPath))
  135. {
  136. continue;
  137. }
  138. if (string.IsNullOrWhiteSpace(videoinfo.VideoSize) || videoinfo.VideoSize == "0 MB")
  139. {
  140. videoinfo.VideoSize = FileToolsCommon.GetFileSizeByMB(videoinfo.VideoPath).ToString() + " MB";
  141. videoinfo.VideoSizebyte = FileToolsCommon.GetFileSize(videoinfo.VideoPath);
  142. }
  143. model_VideoList.Add(videoinfo);
  144. }
  145. catch (Exception ex)
  146. {
  147. LogHelper.WriteErrLog("【加载视频列表】(LoadingVideoList)" + ex.Message, ex);
  148. }
  149. }
  150. }
  151. }
  152. catch (Exception ex)
  153. {
  154. LogHelper.WriteErrLog("【加载视频列表】(LoadingVideoList)" + ex.Message, ex);
  155. }
  156. }
  157. /// <summary>
  158. /// 关闭
  159. /// </summary>
  160. /// <param name="sender"></param>
  161. /// <param name="e"></param>
  162. private void btnDown_Click(object sender, RoutedEventArgs e)
  163. {
  164. APP.SaveWkData();
  165. Hide();
  166. }
  167. /// <summary>
  168. /// 窗口移动
  169. /// </summary>
  170. /// <param name="sender"></param>
  171. /// <param name="e"></param>
  172. private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  173. {
  174. DragMove();
  175. }
  176. /// <summary>
  177. /// 上传
  178. /// </summary>
  179. /// <param name="sender"></param>
  180. /// <param name="e"></param>
  181. private void BtnUpload_Click(object sender, RoutedEventArgs e)
  182. {
  183. pageData.menuList[Subscript].IsEnabled = false;
  184. List<Button> buttons = FindChilds<Button>(listView1, "btnUpload");
  185. for (int i = 0; i < buttons.Count; i++)
  186. {
  187. if (buttons[i] == sender)
  188. {
  189. DAL_Upload dAL_Upload = new DAL_Upload();
  190. if (dAL_Upload.UploadVideo(pageData.menuList[i].FileGuid, out string ErrMessage))
  191. {
  192. pageData.menuList[i].Visi = "Visible";
  193. pageData.menuList[i].Coll = "Collapsed";
  194. DataContext = pageData;
  195. MessageWindow.Show("视频上传成功!");
  196. }
  197. else
  198. {
  199. MessageWindow.Show(ErrMessage);
  200. }
  201. }
  202. }
  203. }
  204. /// <summary>
  205. /// 删除
  206. /// </summary>
  207. /// <param name="sender"></param>
  208. /// <param name="e"></param>
  209. private void BtnDelete_Click(object sender, RoutedEventArgs e)
  210. {
  211. pageData.menuList[Subscript].IsEnabled = false;
  212. List<Button> buttons = FindChilds<Button>(listView1, "btnDelete");
  213. for (int i = 0; i < buttons.Count; i++)
  214. {
  215. if (buttons[i] == sender)
  216. {
  217. //if (APP.W_PromptWindow == null)
  218. //{
  219. // APP.W_PromptWindow = new PromptWindow();
  220. // APP.W_PromptWindow.Owner = this;
  221. //}
  222. //APP.W_PromptWindow.Initialize(pageData.menuList[i].VideoName);
  223. //APP.W_PromptWindow.ShowDialog();
  224. foreach (Model_WKData wKData in APP.WKDataList)
  225. {
  226. if (wKData.VideoList == null)
  227. {
  228. continue;
  229. }
  230. if (wKData.VideoList.Exists(x => x.FileGuid == pageData.menuList[i].FileGuid))
  231. {
  232. try
  233. {
  234. FileToolsCommon.DeleteFile(wKData.VideoList.Find(x => x.FileGuid == pageData.menuList[i].FileGuid).VideoPath);
  235. FileToolsCommon.DeleteFile(wKData.VideoList.Find(x => x.FileGuid == pageData.menuList[i].FileGuid).ThumbnailPath);
  236. wKData.VideoList.Remove(wKData.VideoList.Find(x => x.FileGuid == pageData.menuList[i].FileGuid));
  237. Initialize();
  238. return;
  239. }
  240. catch (Exception ex)
  241. {
  242. MessageWindow.Show("无法删除视频!" + ex.Message);
  243. return;
  244. }
  245. }
  246. }
  247. }
  248. }
  249. }
  250. /// <summary>
  251. /// 播放
  252. /// </summary>
  253. /// <param name="sender"></param>
  254. /// <param name="e"></param>
  255. private void BtnPlay_Click(object sender, RoutedEventArgs e)
  256. {
  257. pageData.menuList[Subscript].IsEnabled = false;
  258. List<Button> buttons = FindChilds<Button>(listView1, "btnPlay");
  259. for (int i = 0; i < buttons.Count; i++)
  260. {
  261. if (buttons[i] == sender)
  262. {
  263. try
  264. {
  265. ProcessStartInfo psi = new ProcessStartInfo(pageData.menuList[i].Path);
  266. Process pro = new Process
  267. {
  268. StartInfo = psi
  269. };
  270. pro.Start();
  271. }
  272. catch (Exception ex)
  273. {
  274. LogHelper.WriteErrLog("FileDirectoryWindow【BtnPlay_Click】" + ex.Message, ex);
  275. MessageWindow.Show(ex.Message);
  276. return;
  277. }
  278. }
  279. }
  280. }
  281. public static List<T> FindChilds<T>(DependencyObject parent, string childName)
  282. where T : DependencyObject
  283. {
  284. List<T> list = new List<T>();
  285. if (parent == null)
  286. {
  287. return list;
  288. }
  289. int childrenCount = VisualTreeHelper.GetChildrenCount(parent);
  290. for (int i = 0; i < childrenCount; i++)
  291. {
  292. DependencyObject child = VisualTreeHelper.GetChild(parent, i);
  293. // 如果子控件不是需查找的控件类型
  294. var childType = child as T;
  295. if (childType == null)
  296. {
  297. // 在下一级控件中递归查找
  298. List<T> findChildList = FindChilds<T>(child, childName);
  299. for (int j = 0; j < findChildList.Count; j++)
  300. {
  301. }
  302. list.AddRange(FindChilds<T>(child, childName));
  303. }
  304. else if (!string.IsNullOrEmpty(childName))
  305. {
  306. FrameworkElement frameworkElement = child as FrameworkElement;
  307. // 如果控件名称符合参数条件
  308. if (frameworkElement != null && frameworkElement.Name == childName)
  309. {
  310. list.Add((T)child);
  311. }
  312. }
  313. else
  314. {
  315. // 查找到了控件
  316. list.Add((T)child);
  317. }
  318. }
  319. return list;
  320. }
  321. /// <summary>
  322. /// 修改
  323. /// </summary>
  324. /// <param name="sender"></param>
  325. /// <param name="e"></param>
  326. private void BtnModify_Click(object sender, RoutedEventArgs e)
  327. {
  328. if (IsModify)
  329. {
  330. pageData.menuList[Subscript].IsEnabled = false;
  331. }
  332. List<Button> buttons = FindChilds<Button>(listView1, "btnModify");
  333. for (int i = 0; i < buttons.Count; i++)
  334. {
  335. if (buttons[i] == sender)
  336. {
  337. pageData.menuList[i].IsEnabled = true;
  338. Subscript = i;
  339. IsModify = true;
  340. }
  341. }
  342. }
  343. //private int MouseNumber = 0;
  344. /// <summary>
  345. /// 鼠标按下
  346. /// </summary>
  347. /// <param name="sender"></param>
  348. /// <param name="e"></param>
  349. private void Window_MouseLeftButtonDown_1(object sender, MouseButtonEventArgs e)
  350. {
  351. //if (IsModify)
  352. //{
  353. // if (MouseNumber > 0 && pageData.menuList.Count > Subscript)
  354. // {
  355. // pageData.menuList[Subscript].IsEnabled = false;
  356. // try
  357. // {
  358. // if (!pageData.menuList[Subscript].Name.Equals(pageData.menuList[Subscript].VideoName))
  359. // {
  360. // string tempPath = pageData.menuList[Subscript].VideoName + pageData.menuList[Subscript].VideoType;
  361. // tempPath = pageData.menuList[Subscript].Path.Replace(tempPath, "").Trim();
  362. // tempPath = tempPath + pageData.menuList[Subscript].Name;
  363. // FileToolsCommon.MoveDirectory(pageData.menuList[Subscript].Path, tempPath, out string Message);
  364. // }
  365. // }
  366. // catch (Exception ex)
  367. // {
  368. // MessageWindow.Show("无法修改视频名称!" + ex.Message);
  369. // return;
  370. // }
  371. // }
  372. // MouseNumber++;
  373. //}
  374. }
  375. private void Window_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
  376. {
  377. // if (IsModify) { if (MouseNumber > 0 && pageData.menuList.Count > Subscript) {
  378. // MouseNumber = 0; pageData.menuList[Subscript].IsEnabled = false; try { if
  379. // (!pageData.menuList[Subscript].Name.Equals(pageData.menuList[Subscript].VideoName)) {
  380. // MouseNumber = 0; string tempPath = pageData.menuList[Subscript].FilePath +
  381. // pageData.menuList[Subscript].VideoName + "." +
  382. // pageData.menuList[Subscript].VideoType; if (FileToolsCommon.IsExistFile(tempPath)) {
  383. // MessageWindow.Show("文件名已存在!"); return; } foreach (Model_WKData wKData in
  384. // APP.WKDataList) { if (wKData.VideoList == null) continue; if
  385. // (wKData.VideoList.Exists(x => x.FileGuid == pageData.menuList[Subscript].FileGuid)) {
  386. // try { //FileToolsCommon.DeleteFile(wKData.VideoList.Find(x => x.FileGuid ==
  387. // pageData.menuList[Subscript].FileGuid).VideoPath);
  388. // //FileToolsCommon.DeleteFile(wKData.VideoList.Find(x => x.FileGuid ==
  389. // pageData.menuList[Subscript].FileGuid).ThumbnailPath);
  390. // //wKData.VideoList.Remove(wKData.VideoList.Find(x => x.FileGuid ==
  391. // pageData.menuList[Subscript].FileGuid)); //Initialize(); //return; } catch (Exception
  392. // ex) { MessageWindow.Show("无法删除视频!" + ex.Message); return; } } }
  393. // FileToolsCommon.Copy(pageData.menuList[Subscript].Path, tempPath); } } catch
  394. // (Exception ex) { MessageWindow.Show("无法修改视频名称!" + ex.Message); return; } }
  395. // MouseNumber++; }
  396. }
  397. /// <summary>
  398. /// 修改文件名
  399. /// </summary>
  400. /// <param name="Guid">唯一编号</param>
  401. /// <param name="NewName">新文件名带后缀 不带路径</param>
  402. /// <param name="Errmessage">错误信息</param>
  403. /// <returns></returns>
  404. private bool ModifyPathName(string FileGuid, string NewName, out string Errmessage)
  405. {
  406. Errmessage = "";
  407. Model_Video model_Video = APP.VideoList.Find(x => x.FileGuid == FileGuid);
  408. string filePathName = model_Video.VideoPath;
  409. string filePath = FileToolsCommon.GetDirectoryName(filePathName);
  410. string newFilePathName = filePath + NewName;
  411. //缩略图
  412. string ThumbnailPath = filePath + "ThumbnailPath/";
  413. FileToolsCommon.CreateDirectory(ThumbnailPath);
  414. //缩略图存储位置
  415. string ThumbnailPathName = ThumbnailPath + NewName.Replace(".", "") + ".JPG";
  416. if (FileToolsCommon.IsExistFile(newFilePathName))
  417. {
  418. Errmessage = "文件已存在,请重新修改文件名!";
  419. return false;
  420. }
  421. else
  422. {
  423. //修改文件名
  424. FileToolsCommon.Copy(filePathName, newFilePathName);
  425. model_Video.VideoPath = newFilePathName;
  426. //修改缩略图名
  427. FileToolsCommon.DeleteFile(ThumbnailPathName);
  428. FileToolsCommon.Copy(model_Video.ThumbnailPath, ThumbnailPathName);
  429. model_Video.ThumbnailPath = ThumbnailPathName;
  430. APP.SaveWkData();
  431. return true;
  432. }
  433. }
  434. }
  435. }