星火微课系统客户端
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

FileDirectoryWindow.xaml.cs 22KB

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