星火微课系统客户端
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

FileDirectoryWindow.xaml.cs 21KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601
  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.Windows;
  8. using System.Windows.Controls;
  9. using System.Windows.Input;
  10. using System.Windows.Media;
  11. using XHWK.Model;
  12. using XHWK.WKTool.DAL;
  13. namespace XHWK.WKTool
  14. {
  15. /// <summary>
  16. /// 文件目录
  17. /// </summary>
  18. public partial class FileDirectoryWindow : Window
  19. {
  20. /// <summary>
  21. /// 视频模型
  22. /// </summary>
  23. 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. continue;
  128. foreach (Model_Video videoinfo in Vdata.VideoList)
  129. {
  130. try
  131. {
  132. if (string.IsNullOrWhiteSpace(videoinfo.VideoPath))
  133. {
  134. continue;
  135. }
  136. if (string.IsNullOrWhiteSpace(videoinfo.VideoSize) || videoinfo.VideoSize == "0 MB")
  137. {
  138. videoinfo.VideoSize = FileToolsCommon.GetFileSizeByMB(videoinfo.VideoPath).ToString() + " MB";
  139. }
  140. model_VideoList.Add(videoinfo);
  141. }
  142. catch (Exception ex)
  143. {
  144. LogHelper.WriteErrLog("【加载视频列表】(LoadingVideoList)" + ex.Message, ex);
  145. }
  146. }
  147. }
  148. }
  149. catch (Exception ex)
  150. {
  151. LogHelper.WriteErrLog("【加载视频列表】(LoadingVideoList)" + ex.Message, ex);
  152. }
  153. }
  154. /// <summary>
  155. /// 关闭
  156. /// </summary>
  157. /// <param name="sender"></param>
  158. /// <param name="e"></param>
  159. private void btnDown_Click(object sender, RoutedEventArgs e)
  160. {
  161. APP.SaveWkData();
  162. this.Hide();
  163. }
  164. /// <summary>
  165. /// 窗口移动
  166. /// </summary>
  167. /// <param name="sender"></param>
  168. /// <param name="e"></param>
  169. private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  170. {
  171. DragMove();
  172. }
  173. /// <summary>
  174. /// 上传
  175. /// </summary>
  176. /// <param name="sender"></param>
  177. /// <param name="e"></param>
  178. private void BtnUpload_Click(object sender, RoutedEventArgs e)
  179. {
  180. pageData.menuList[Subscript].IsEnabled = false;
  181. List<Button> buttons = FindChilds<Button>(listView1, "btnUpload");
  182. for (int i = 0; i < buttons.Count; i++)
  183. {
  184. if (buttons[i] == sender)
  185. {
  186. DAL_Upload dAL_Upload = new DAL_Upload();
  187. if (dAL_Upload.UploadVideo(pageData.menuList[i].FileGuid, out string ErrMessage))
  188. {
  189. pageData.menuList[i].Visi = "Visible";
  190. pageData.menuList[i].Coll = "Collapsed";
  191. DataContext = pageData;
  192. MessageBox.Show("视频上传成功!");
  193. }
  194. else
  195. {
  196. MessageBox.Show(ErrMessage);
  197. }
  198. }
  199. }
  200. }
  201. /// <summary>
  202. /// 删除
  203. /// </summary>
  204. /// <param name="sender"></param>
  205. /// <param name="e"></param>
  206. private void BtnDelete_Click(object sender, RoutedEventArgs e)
  207. {
  208. pageData.menuList[Subscript].IsEnabled = false;
  209. List<Button> buttons = FindChilds<Button>(listView1, "btnDelete");
  210. for (int i = 0; i < buttons.Count; i++)
  211. {
  212. if (buttons[i] == sender)
  213. {
  214. //if (APP.W_PromptWindow == null)
  215. //{
  216. // APP.W_PromptWindow = new PromptWindow();
  217. // APP.W_PromptWindow.Owner = this;
  218. //}
  219. //APP.W_PromptWindow.Initialize(pageData.menuList[i].VideoName);
  220. //APP.W_PromptWindow.ShowDialog();
  221. foreach (Model_WKData wKData in APP.WKDataList)
  222. {
  223. if (wKData.VideoList == null)
  224. continue;
  225. if (wKData.VideoList.Exists(x => x.FileGuid == pageData.menuList[i].FileGuid))
  226. {
  227. try
  228. {
  229. FileToolsCommon.DeleteFile(wKData.VideoList.Find(x => x.FileGuid == pageData.menuList[i].FileGuid).VideoPath);
  230. FileToolsCommon.DeleteFile(wKData.VideoList.Find(x => x.FileGuid == pageData.menuList[i].FileGuid).ThumbnailPath);
  231. wKData.VideoList.Remove(wKData.VideoList.Find(x => x.FileGuid == pageData.menuList[i].FileGuid));
  232. Initialize();
  233. return;
  234. }
  235. catch (Exception ex)
  236. {
  237. MessageBox.Show("无法删除视频!" + ex.Message);
  238. return;
  239. }
  240. }
  241. }
  242. }
  243. }
  244. }
  245. /// <summary>
  246. /// 播放
  247. /// </summary>
  248. /// <param name="sender"></param>
  249. /// <param name="e"></param>
  250. private void BtnPlay_Click(object sender, RoutedEventArgs e)
  251. {
  252. pageData.menuList[Subscript].IsEnabled = false;
  253. List<Button> buttons = FindChilds<Button>(listView1, "btnPlay");
  254. for (int i = 0; i < buttons.Count; i++)
  255. {
  256. if (buttons[i] == sender)
  257. {
  258. try
  259. {
  260. ProcessStartInfo psi = new ProcessStartInfo(pageData.menuList[i].Path);
  261. Process pro = new Process
  262. {
  263. StartInfo = psi
  264. };
  265. pro.Start();
  266. }
  267. catch (Exception ex)
  268. {
  269. LogHelper.WriteErrLog("FileDirectoryWindow【BtnPlay_Click】" + ex.Message, ex);
  270. MessageBox.Show(ex.Message);
  271. return;
  272. }
  273. }
  274. }
  275. }
  276. public static List<T> FindChilds<T>(DependencyObject parent, string childName)
  277. where T : DependencyObject
  278. {
  279. List<T> list = new List<T>();
  280. if (parent == null)
  281. {
  282. return list;
  283. }
  284. int childrenCount = VisualTreeHelper.GetChildrenCount(parent);
  285. for (int i = 0; i < childrenCount; i++)
  286. {
  287. DependencyObject child = VisualTreeHelper.GetChild(parent, i);
  288. // 如果子控件不是需查找的控件类型
  289. T childType = child as T;
  290. if (childType == null)
  291. {
  292. // 在下一级控件中递归查找
  293. List<T> findChildList = FindChilds<T>(child, childName);
  294. for (int j = 0; j < findChildList.Count; j++)
  295. {
  296. }
  297. list.AddRange(FindChilds<T>(child, childName));
  298. }
  299. else if (!string.IsNullOrEmpty(childName))
  300. {
  301. FrameworkElement frameworkElement = child as FrameworkElement;
  302. // 如果控件名称符合参数条件
  303. if (frameworkElement != null && frameworkElement.Name == childName)
  304. {
  305. list.Add((T)child);
  306. }
  307. }
  308. else
  309. {
  310. // 查找到了控件
  311. list.Add((T)child);
  312. }
  313. }
  314. return list;
  315. }
  316. /// <summary>
  317. /// 修改
  318. /// </summary>
  319. /// <param name="sender"></param>
  320. /// <param name="e"></param>
  321. private void BtnModify_Click(object sender, RoutedEventArgs e)
  322. {
  323. if (IsModify)
  324. {
  325. pageData.menuList[Subscript].IsEnabled = false;
  326. }
  327. List<Button> buttons = FindChilds<Button>(listView1, "btnModify");
  328. for (int i = 0; i < buttons.Count; i++)
  329. {
  330. if (buttons[i] == sender)
  331. {
  332. pageData.menuList[i].IsEnabled = true;
  333. Subscript = i;
  334. IsModify = true;
  335. }
  336. }
  337. }
  338. int MouseNumber = 0;
  339. /// <summary>
  340. /// 鼠标按下
  341. /// </summary>
  342. /// <param name="sender"></param>
  343. /// <param name="e"></param>
  344. private void Window_MouseLeftButtonDown_1(object sender, MouseButtonEventArgs e)
  345. {
  346. //if (IsModify)
  347. //{
  348. // if (MouseNumber > 0 && pageData.menuList.Count > Subscript)
  349. // {
  350. // pageData.menuList[Subscript].IsEnabled = false;
  351. // try
  352. // {
  353. // if (!pageData.menuList[Subscript].Name.Equals(pageData.menuList[Subscript].VideoName))
  354. // {
  355. // string tempPath = pageData.menuList[Subscript].VideoName + pageData.menuList[Subscript].VideoType;
  356. // tempPath = pageData.menuList[Subscript].Path.Replace(tempPath, "").Trim();
  357. // tempPath = tempPath + pageData.menuList[Subscript].Name;
  358. // FileToolsCommon.MoveDirectory(pageData.menuList[Subscript].Path, tempPath, out string Message);
  359. // }
  360. // }
  361. // catch (Exception ex)
  362. // {
  363. // MessageBox.Show("无法修改视频名称!" + ex.Message);
  364. // return;
  365. // }
  366. // }
  367. // MouseNumber++;
  368. //}
  369. }
  370. private void Window_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
  371. {
  372. // if (IsModify)
  373. // {
  374. // if (MouseNumber > 0 && pageData.menuList.Count > Subscript)
  375. // {
  376. // MouseNumber = 0;
  377. // pageData.menuList[Subscript].IsEnabled = false;
  378. // try
  379. // {
  380. // if (!pageData.menuList[Subscript].Name.Equals(pageData.menuList[Subscript].VideoName))
  381. // {
  382. // MouseNumber = 0;
  383. // string tempPath = pageData.menuList[Subscript].FilePath + pageData.menuList[Subscript].VideoName + "." + pageData.menuList[Subscript].VideoType;
  384. // if (FileToolsCommon.IsExistFile(tempPath))
  385. // {
  386. // MessageBox.Show("文件名已存在!");
  387. // return;
  388. // }
  389. // foreach (Model_WKData wKData in APP.WKDataList)
  390. // {
  391. // if (wKData.VideoList == null)
  392. // continue;
  393. // if (wKData.VideoList.Exists(x => x.FileGuid == pageData.menuList[Subscript].FileGuid))
  394. // {
  395. // try
  396. // {
  397. // //FileToolsCommon.DeleteFile(wKData.VideoList.Find(x => x.FileGuid == pageData.menuList[Subscript].FileGuid).VideoPath);
  398. // //FileToolsCommon.DeleteFile(wKData.VideoList.Find(x => x.FileGuid == pageData.menuList[Subscript].FileGuid).ThumbnailPath);
  399. // //wKData.VideoList.Remove(wKData.VideoList.Find(x => x.FileGuid == pageData.menuList[Subscript].FileGuid));
  400. // //Initialize();
  401. // //return;
  402. // }
  403. // catch (Exception ex)
  404. // {
  405. // MessageBox.Show("无法删除视频!" + ex.Message);
  406. // return;
  407. // }
  408. // }
  409. // }
  410. // FileToolsCommon.Copy(pageData.menuList[Subscript].Path, tempPath);
  411. // }
  412. // }
  413. // catch (Exception ex)
  414. // {
  415. // MessageBox.Show("无法修改视频名称!" + ex.Message);
  416. // return;
  417. // }
  418. // }
  419. // MouseNumber++;
  420. // }
  421. }
  422. }
  423. ///// <summary>
  424. ///// 修改文件名
  425. ///// </summary>
  426. ///// <param name="Guid">唯一编号</param>
  427. ///// <param name="NewName">文件名带后缀 不带路径</param>
  428. ///// <returns></returns>
  429. //bool ModifyPathName(string Guid,string NewName)
  430. //{
  431. //}
  432. public class FileDirectoryData : NotifyModel
  433. {
  434. public ObservableCollection<FileDirectoryModel> menuList { get; set; }
  435. public FileDirectoryData()
  436. {
  437. menuList = new ObservableCollection<FileDirectoryModel>();
  438. }
  439. }
  440. public class FileDirectoryModel : NotifyModel
  441. {
  442. private int _serialNumber;
  443. /// <summary>
  444. /// 序号
  445. /// </summary>
  446. public int SerialNumber
  447. {
  448. get => _serialNumber;
  449. set
  450. {
  451. _serialNumber = value;
  452. OnPropertyChanged("SerialNumber");
  453. }
  454. }
  455. private string _videoName;
  456. /// <summary>
  457. /// 视频名称
  458. /// </summary>
  459. public string VideoName
  460. {
  461. get => _videoName;
  462. set
  463. {
  464. _videoName = value;
  465. OnPropertyChanged("VideoName");
  466. }
  467. }
  468. private int _videoDuration;
  469. /// <summary>
  470. /// 视频时长
  471. /// </summary>
  472. public int VideoDuration
  473. {
  474. get => _videoDuration;
  475. set
  476. {
  477. _videoDuration = value;
  478. OnPropertyChanged("VideoDuration");
  479. }
  480. }
  481. private string _videoSize;
  482. /// <summary>
  483. /// 视频大小
  484. /// </summary>
  485. public string VideoSize
  486. {
  487. get => _videoSize;
  488. set
  489. {
  490. _videoSize = value;
  491. OnPropertyChanged("VideoSize");
  492. }
  493. }
  494. private string _videoTime;
  495. /// <summary>
  496. /// 日期
  497. /// </summary>
  498. public string VideoTime
  499. {
  500. get => _videoTime;
  501. set
  502. {
  503. _videoTime = value;
  504. OnPropertyChanged("VideoTime");
  505. }
  506. }
  507. private string _colour;
  508. /// <summary>
  509. /// 颜色
  510. /// </summary>
  511. public string Colour
  512. {
  513. get => _colour;
  514. set
  515. {
  516. _colour = value;
  517. OnPropertyChanged("Colour");
  518. }
  519. }
  520. private bool _isEnabled;
  521. /// <summary>
  522. /// 是否可编辑
  523. /// </summary>
  524. public bool IsEnabled
  525. {
  526. get => _isEnabled;
  527. set
  528. {
  529. _isEnabled = value;
  530. OnPropertyChanged("IsEnabled");
  531. }
  532. }
  533. public string Path { get; set; }
  534. private string _visi;
  535. /// <summary>
  536. /// 显示
  537. /// </summary>
  538. public string Visi
  539. {
  540. get => _visi;
  541. set
  542. {
  543. _visi = value;
  544. OnPropertyChanged("Visi");
  545. }
  546. }
  547. private string _coll;
  548. /// <summary>
  549. /// 显示
  550. /// </summary>
  551. public string Coll
  552. {
  553. get => _coll;
  554. set
  555. {
  556. _coll = value;
  557. OnPropertyChanged("Coll");
  558. }
  559. }
  560. /// <summary>
  561. /// 唯一编号
  562. /// </summary>
  563. public string FileGuid { get; set; }
  564. /// <summary>
  565. /// 视频类型
  566. /// </summary>
  567. public string VideoType { get; set; }
  568. /// <summary>
  569. /// 初始名称
  570. /// </summary>
  571. public string Name { get; set; }
  572. /// <summary>
  573. /// 文件路径
  574. /// </summary>
  575. public string FilePath { get; set; }
  576. }
  577. }