星火微课系统客户端
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

FileDirectoryWindow.xaml.cs 23KB

4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649
  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. namespace XHWK.WKTool
  13. {
  14. /// <summary>
  15. /// 文件目录
  16. /// </summary>
  17. public partial class FileDirectoryWindow : Window
  18. {
  19. /// <summary>
  20. /// 视频模型
  21. /// </summary>
  22. private List<Model_Video> model_VideoList = null;
  23. /// <summary>
  24. /// 数据列表
  25. /// </summary>
  26. internal FileDirectoryData pageData = new FileDirectoryData();
  27. /// <summary>
  28. /// 下标
  29. /// </summary>
  30. private int Subscript = 0;
  31. /// <summary>
  32. /// 是否是修改状态
  33. /// </summary>
  34. private bool IsModify = false;
  35. /// <summary>
  36. /// 文件目录
  37. /// </summary>
  38. public FileDirectoryWindow()
  39. {
  40. InitializeComponent();
  41. Initialize();
  42. }
  43. /// <summary>
  44. /// 初始化
  45. /// </summary>
  46. public void Initialize()
  47. {
  48. APP.myloading.Show();
  49. //MouseNumber = 0;
  50. IsModify = false;
  51. //加载视频列表
  52. LoadingVideoList();
  53. int i = 1;
  54. bool isColour = true;
  55. pageData.menuList.Clear();
  56. //显示视频
  57. foreach (Model_Video videoinfo in model_VideoList)
  58. {
  59. //是否已上传
  60. //videoinfo.IsUpload;
  61. //录制时间
  62. //videoinfo.RSTime;
  63. //文件大小
  64. //videoinfo.VideoSize;
  65. //文件缩略图路径
  66. //videoinfo.ThumbnailPath;
  67. //文件唯一标示 上传事件筛选需要上传的视频
  68. //videoinfo.FileGuid;
  69. //文件存储路径
  70. //videoinfo.VidePath;
  71. string colour = "#FFFFFF";
  72. if (isColour == true)
  73. {
  74. colour = "#FFFFFF";
  75. isColour = false;
  76. }
  77. else
  78. {
  79. colour = "#E6F1FF";
  80. isColour = true;
  81. }
  82. string vis = "Visible";
  83. string cos = "Collapsed";
  84. if (!videoinfo.IsUpload)
  85. {
  86. vis = "Collapsed";
  87. cos = "Visible";
  88. }
  89. if (i <= 16)
  90. {
  91. pageData.menuList.Add(new FileDirectoryModel()
  92. {
  93. SerialNumber = i,
  94. VideoName = Common.system.FileToolsCommon.GetIOFileName(videoinfo.VideoPath).Replace(".MP4", "").Replace(".FLV", "").Replace(".AVI", "").Trim(),
  95. Name = Common.system.FileToolsCommon.GetIOFileName(videoinfo.VideoPath).Replace(".MP4", "").Replace(".FLV", "").Replace(".AVI", "").Trim(),
  96. FilePath = videoinfo.VideoPath.Replace(FileToolsCommon.GetIOFileName(videoinfo.VideoPath), "").Trim(),
  97. VideoDuration = 0,
  98. VideoSize = videoinfo.VideoSize,
  99. VideoTime = videoinfo.RSTime,
  100. IsEnabled = false,
  101. Path = videoinfo.VideoPath,
  102. Colour = colour,
  103. Visi = vis,
  104. Coll = cos,
  105. FileGuid = videoinfo.FileGuid,
  106. VideoType = videoinfo.VideoType.ToString()
  107. }); ;
  108. }
  109. i++;
  110. }
  111. txbSum.Text = pageData.menuList.Count.ToString();
  112. APP.myloading.Hide();
  113. DataContext = pageData;
  114. }
  115. /// <summary>
  116. /// 加载视频列表
  117. /// </summary>
  118. public void LoadingVideoList()
  119. {
  120. try
  121. {
  122. model_VideoList = new List<Model_Video>();
  123. foreach (Model_WKData Vdata in APP.WKDataList)
  124. {
  125. if (Vdata.VideoList == null)
  126. {
  127. continue;
  128. }
  129. foreach (Model_Video videoinfo in Vdata.VideoList)
  130. {
  131. try
  132. {
  133. if (string.IsNullOrWhiteSpace(videoinfo.VideoPath))
  134. {
  135. continue;
  136. }
  137. if (string.IsNullOrWhiteSpace(videoinfo.VideoSize) || videoinfo.VideoSize == "0 MB")
  138. {
  139. videoinfo.VideoSize = FileToolsCommon.GetFileSizeByMB(videoinfo.VideoPath).ToString() + " MB";
  140. videoinfo.VideoSizebyte = FileToolsCommon.GetFileSize(videoinfo.VideoPath);
  141. }
  142. model_VideoList.Add(videoinfo);
  143. }
  144. catch (Exception ex)
  145. {
  146. LogHelper.WriteErrLog("【加载视频列表】(LoadingVideoList)" + ex.Message, ex);
  147. }
  148. }
  149. }
  150. }
  151. catch (Exception ex)
  152. {
  153. LogHelper.WriteErrLog("【加载视频列表】(LoadingVideoList)" + ex.Message, ex);
  154. }
  155. }
  156. /// <summary>
  157. /// 关闭
  158. /// </summary>
  159. /// <param name="sender"></param>
  160. /// <param name="e"></param>
  161. private void btnDown_Click(object sender, RoutedEventArgs e)
  162. {
  163. APP.SaveWkData();
  164. Hide();
  165. }
  166. /// <summary>
  167. /// 窗口移动
  168. /// </summary>
  169. /// <param name="sender"></param>
  170. /// <param name="e"></param>
  171. private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  172. {
  173. DragMove();
  174. }
  175. /// <summary>
  176. /// 上传
  177. /// </summary>
  178. /// <param name="sender"></param>
  179. /// <param name="e"></param>
  180. private void BtnUpload_Click(object sender, RoutedEventArgs e)
  181. {
  182. pageData.menuList[Subscript].IsEnabled = false;
  183. List<Button> buttons = FindChilds<Button>(listView1, "btnUpload");
  184. for (int i = 0; i < buttons.Count; i++)
  185. {
  186. if (buttons[i] == sender)
  187. {
  188. DAL_Upload dAL_Upload = new DAL_Upload();
  189. if (dAL_Upload.UploadVideo(pageData.menuList[i].FileGuid, out string ErrMessage))
  190. {
  191. pageData.menuList[i].Visi = "Visible";
  192. pageData.menuList[i].Coll = "Collapsed";
  193. DataContext = pageData;
  194. MessageWindow.Show("视频上传成功!");
  195. }
  196. else
  197. {
  198. MessageWindow.Show(ErrMessage);
  199. }
  200. }
  201. }
  202. }
  203. /// <summary>
  204. /// 删除
  205. /// </summary>
  206. /// <param name="sender"></param>
  207. /// <param name="e"></param>
  208. private void BtnDelete_Click(object sender, RoutedEventArgs e)
  209. {
  210. pageData.menuList[Subscript].IsEnabled = false;
  211. List<Button> buttons = FindChilds<Button>(listView1, "btnDelete");
  212. for (int i = 0; i < buttons.Count; i++)
  213. {
  214. if (buttons[i] == sender)
  215. {
  216. //if (APP.W_PromptWindow == null)
  217. //{
  218. // APP.W_PromptWindow = new PromptWindow();
  219. // APP.W_PromptWindow.Owner = this;
  220. //}
  221. //APP.W_PromptWindow.Initialize(pageData.menuList[i].VideoName);
  222. //APP.W_PromptWindow.ShowDialog();
  223. foreach (Model_WKData wKData in APP.WKDataList)
  224. {
  225. if (wKData.VideoList == null)
  226. {
  227. continue;
  228. }
  229. if (wKData.VideoList.Exists(x => x.FileGuid == pageData.menuList[i].FileGuid))
  230. {
  231. try
  232. {
  233. FileToolsCommon.DeleteFile(wKData.VideoList.Find(x => x.FileGuid == pageData.menuList[i].FileGuid).VideoPath);
  234. FileToolsCommon.DeleteFile(wKData.VideoList.Find(x => x.FileGuid == pageData.menuList[i].FileGuid).ThumbnailPath);
  235. wKData.VideoList.Remove(wKData.VideoList.Find(x => x.FileGuid == pageData.menuList[i].FileGuid));
  236. Initialize();
  237. return;
  238. }
  239. catch (Exception ex)
  240. {
  241. MessageWindow.Show("无法删除视频!" + ex.Message);
  242. return;
  243. }
  244. }
  245. }
  246. }
  247. }
  248. }
  249. /// <summary>
  250. /// 播放
  251. /// </summary>
  252. /// <param name="sender"></param>
  253. /// <param name="e"></param>
  254. private void BtnPlay_Click(object sender, RoutedEventArgs e)
  255. {
  256. pageData.menuList[Subscript].IsEnabled = false;
  257. List<Button> buttons = FindChilds<Button>(listView1, "btnPlay");
  258. for (int i = 0; i < buttons.Count; i++)
  259. {
  260. if (buttons[i] == sender)
  261. {
  262. try
  263. {
  264. ProcessStartInfo psi = new ProcessStartInfo(pageData.menuList[i].Path);
  265. Process pro = new Process
  266. {
  267. StartInfo = psi
  268. };
  269. pro.Start();
  270. }
  271. catch (Exception ex)
  272. {
  273. LogHelper.WriteErrLog("FileDirectoryWindow【BtnPlay_Click】" + ex.Message, ex);
  274. MessageWindow.Show(ex.Message);
  275. return;
  276. }
  277. }
  278. }
  279. }
  280. public static List<T> FindChilds<T>(DependencyObject parent, string childName)
  281. where T : DependencyObject
  282. {
  283. List<T> list = new List<T>();
  284. if (parent == null)
  285. {
  286. return list;
  287. }
  288. int childrenCount = VisualTreeHelper.GetChildrenCount(parent);
  289. for (int i = 0; i < childrenCount; i++)
  290. {
  291. DependencyObject child = VisualTreeHelper.GetChild(parent, i);
  292. // 如果子控件不是需查找的控件类型
  293. T childType = child as T;
  294. if (childType == null)
  295. {
  296. // 在下一级控件中递归查找
  297. List<T> findChildList = FindChilds<T>(child, childName);
  298. for (int j = 0; j < findChildList.Count; j++)
  299. {
  300. }
  301. list.AddRange(FindChilds<T>(child, childName));
  302. }
  303. else if (!string.IsNullOrEmpty(childName))
  304. {
  305. FrameworkElement frameworkElement = child as FrameworkElement;
  306. // 如果控件名称符合参数条件
  307. if (frameworkElement != null && frameworkElement.Name == childName)
  308. {
  309. list.Add((T)child);
  310. }
  311. }
  312. else
  313. {
  314. // 查找到了控件
  315. list.Add((T)child);
  316. }
  317. }
  318. return list;
  319. }
  320. /// <summary>
  321. /// 修改
  322. /// </summary>
  323. /// <param name="sender"></param>
  324. /// <param name="e"></param>
  325. private void BtnModify_Click(object sender, RoutedEventArgs e)
  326. {
  327. if (IsModify)
  328. {
  329. pageData.menuList[Subscript].IsEnabled = false;
  330. }
  331. List<Button> buttons = FindChilds<Button>(listView1, "btnModify");
  332. for (int i = 0; i < buttons.Count; i++)
  333. {
  334. if (buttons[i] == sender)
  335. {
  336. pageData.menuList[i].IsEnabled = true;
  337. Subscript = i;
  338. IsModify = true;
  339. }
  340. }
  341. }
  342. //private int MouseNumber = 0;
  343. /// <summary>
  344. /// 鼠标按下
  345. /// </summary>
  346. /// <param name="sender"></param>
  347. /// <param name="e"></param>
  348. private void Window_MouseLeftButtonDown_1(object sender, MouseButtonEventArgs e)
  349. {
  350. //if (IsModify)
  351. //{
  352. // if (MouseNumber > 0 && pageData.menuList.Count > Subscript)
  353. // {
  354. // pageData.menuList[Subscript].IsEnabled = false;
  355. // try
  356. // {
  357. // if (!pageData.menuList[Subscript].Name.Equals(pageData.menuList[Subscript].VideoName))
  358. // {
  359. // string tempPath = pageData.menuList[Subscript].VideoName + pageData.menuList[Subscript].VideoType;
  360. // tempPath = pageData.menuList[Subscript].Path.Replace(tempPath, "").Trim();
  361. // tempPath = tempPath + pageData.menuList[Subscript].Name;
  362. // FileToolsCommon.MoveDirectory(pageData.menuList[Subscript].Path, tempPath, out string Message);
  363. // }
  364. // }
  365. // catch (Exception ex)
  366. // {
  367. // MessageWindow.Show("无法修改视频名称!" + ex.Message);
  368. // return;
  369. // }
  370. // }
  371. // MouseNumber++;
  372. //}
  373. }
  374. private void Window_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
  375. {
  376. // if (IsModify)
  377. // {
  378. // if (MouseNumber > 0 && pageData.menuList.Count > Subscript)
  379. // {
  380. // MouseNumber = 0;
  381. // pageData.menuList[Subscript].IsEnabled = false;
  382. // try
  383. // {
  384. // if (!pageData.menuList[Subscript].Name.Equals(pageData.menuList[Subscript].VideoName))
  385. // {
  386. // MouseNumber = 0;
  387. // string tempPath = pageData.menuList[Subscript].FilePath + pageData.menuList[Subscript].VideoName + "." + pageData.menuList[Subscript].VideoType;
  388. // if (FileToolsCommon.IsExistFile(tempPath))
  389. // {
  390. // MessageWindow.Show("文件名已存在!");
  391. // return;
  392. // }
  393. // foreach (Model_WKData wKData in APP.WKDataList)
  394. // {
  395. // if (wKData.VideoList == null)
  396. // continue;
  397. // if (wKData.VideoList.Exists(x => x.FileGuid == pageData.menuList[Subscript].FileGuid))
  398. // {
  399. // try
  400. // {
  401. // //FileToolsCommon.DeleteFile(wKData.VideoList.Find(x => x.FileGuid == pageData.menuList[Subscript].FileGuid).VideoPath);
  402. // //FileToolsCommon.DeleteFile(wKData.VideoList.Find(x => x.FileGuid == pageData.menuList[Subscript].FileGuid).ThumbnailPath);
  403. // //wKData.VideoList.Remove(wKData.VideoList.Find(x => x.FileGuid == pageData.menuList[Subscript].FileGuid));
  404. // //Initialize();
  405. // //return;
  406. // }
  407. // catch (Exception ex)
  408. // {
  409. // MessageWindow.Show("无法删除视频!" + ex.Message);
  410. // return;
  411. // }
  412. // }
  413. // }
  414. // FileToolsCommon.Copy(pageData.menuList[Subscript].Path, tempPath);
  415. // }
  416. // }
  417. // catch (Exception ex)
  418. // {
  419. // MessageWindow.Show("无法修改视频名称!" + ex.Message);
  420. // return;
  421. // }
  422. // }
  423. // MouseNumber++;
  424. // }
  425. }
  426. /// <summary>
  427. /// 修改文件名
  428. /// </summary>
  429. /// <param name="Guid">唯一编号</param>
  430. /// <param name="NewName">新文件名带后缀 不带路径</param>
  431. /// <param name="Errmessage">错误信息</param>
  432. /// <returns></returns>
  433. private bool ModifyPathName(string FileGuid, string NewName, out string Errmessage)
  434. {
  435. Errmessage = "";
  436. Model_Video model_Video = APP.VideoList.Find(x => x.FileGuid == FileGuid);
  437. string filePathName = model_Video.VideoPath;
  438. string filePath = FileToolsCommon.GetDirectoryName(filePathName);
  439. string newFilePathName = filePath + NewName;
  440. //缩略图
  441. string ThumbnailPath = filePath + "ThumbnailPath/";
  442. FileToolsCommon.CreateDirectory(ThumbnailPath);
  443. //缩略图存储位置
  444. string ThumbnailPathName = ThumbnailPath + NewName.Replace(".", "") + ".JPG";
  445. if (FileToolsCommon.IsExistFile(newFilePathName))
  446. {
  447. Errmessage = "文件已存在,请重新修改文件名!";
  448. return false;
  449. }
  450. else
  451. {
  452. //修改文件名
  453. FileToolsCommon.Copy(filePathName, newFilePathName);
  454. model_Video.VideoPath = newFilePathName;
  455. //修改缩略图名
  456. FileToolsCommon.DeleteFile(ThumbnailPathName);
  457. FileToolsCommon.Copy(model_Video.ThumbnailPath, ThumbnailPathName);
  458. model_Video.ThumbnailPath = ThumbnailPathName;
  459. APP.SaveWkData();
  460. return true;
  461. }
  462. }
  463. }
  464. public class FileDirectoryData : NotifyModel
  465. {
  466. public ObservableCollection<FileDirectoryModel> menuList { get; set; }
  467. public FileDirectoryData()
  468. {
  469. menuList = new ObservableCollection<FileDirectoryModel>();
  470. }
  471. }
  472. public class FileDirectoryModel : NotifyModel
  473. {
  474. private int _serialNumber;
  475. /// <summary>
  476. /// 序号
  477. /// </summary>
  478. public int SerialNumber
  479. {
  480. get => _serialNumber;
  481. set
  482. {
  483. _serialNumber = value;
  484. OnPropertyChanged("SerialNumber");
  485. }
  486. }
  487. private string _videoName;
  488. /// <summary>
  489. /// 视频名称
  490. /// </summary>
  491. public string VideoName
  492. {
  493. get => _videoName;
  494. set
  495. {
  496. _videoName = value;
  497. OnPropertyChanged("VideoName");
  498. }
  499. }
  500. private int _videoDuration;
  501. /// <summary>
  502. /// 视频时长
  503. /// </summary>
  504. public int VideoDuration
  505. {
  506. get => _videoDuration;
  507. set
  508. {
  509. _videoDuration = value;
  510. OnPropertyChanged("VideoDuration");
  511. }
  512. }
  513. private string _videoSize;
  514. /// <summary>
  515. /// 视频大小
  516. /// </summary>
  517. public string VideoSize
  518. {
  519. get => _videoSize;
  520. set
  521. {
  522. _videoSize = value;
  523. OnPropertyChanged("VideoSize");
  524. }
  525. }
  526. private long _videoSizes;
  527. /// <summary>
  528. /// 视频大小
  529. /// </summary>
  530. public long VideoSizes
  531. {
  532. get => _videoSizes;
  533. set
  534. {
  535. _videoSizes = value;
  536. OnPropertyChanged("VideoSizes");
  537. }
  538. }
  539. private string _videoTime;
  540. /// <summary>
  541. /// 日期
  542. /// </summary>
  543. public string VideoTime
  544. {
  545. get => _videoTime;
  546. set
  547. {
  548. _videoTime = value;
  549. OnPropertyChanged("VideoTime");
  550. }
  551. }
  552. private string _colour;
  553. /// <summary>
  554. /// 颜色
  555. /// </summary>
  556. public string Colour
  557. {
  558. get => _colour;
  559. set
  560. {
  561. _colour = value;
  562. OnPropertyChanged("Colour");
  563. }
  564. }
  565. private bool _isEnabled;
  566. /// <summary>
  567. /// 是否可编辑
  568. /// </summary>
  569. public bool IsEnabled
  570. {
  571. get => _isEnabled;
  572. set
  573. {
  574. _isEnabled = value;
  575. OnPropertyChanged("IsEnabled");
  576. }
  577. }
  578. public string Path { get; set; }
  579. private string _visi;
  580. /// <summary>
  581. /// 显示
  582. /// </summary>
  583. public string Visi
  584. {
  585. get => _visi;
  586. set
  587. {
  588. _visi = value;
  589. OnPropertyChanged("Visi");
  590. }
  591. }
  592. private string _coll;
  593. /// <summary>
  594. /// 显示
  595. /// </summary>
  596. public string Coll
  597. {
  598. get => _coll;
  599. set
  600. {
  601. _coll = value;
  602. OnPropertyChanged("Coll");
  603. }
  604. }
  605. /// <summary>
  606. /// 唯一编号
  607. /// </summary>
  608. public string FileGuid { get; set; }
  609. /// <summary>
  610. /// 视频类型
  611. /// </summary>
  612. public string VideoType { get; set; }
  613. /// <summary>
  614. /// 初始名称
  615. /// </summary>
  616. public string Name { get; set; }
  617. /// <summary>
  618. /// 文件路径
  619. /// </summary>
  620. public string FilePath { get; set; }
  621. }
  622. }