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

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