星火微课系统客户端
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

FileDirectoryWindow.xaml.cs 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585
  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. //if (APP.W_PromptWindow == null)
  201. //{
  202. // APP.W_PromptWindow = new PromptWindow();
  203. // APP.W_PromptWindow.Owner = this;
  204. //}
  205. //APP.W_PromptWindow.Initialize(pageData.menuList[i].VideoName);
  206. //APP.W_PromptWindow.ShowDialog();
  207. foreach (Model_WKData wKData in APP.WKDataList)
  208. {
  209. if (wKData.VideoList == null)
  210. continue;
  211. if (wKData.VideoList.Exists(x => x.FileGuid == pageData.menuList[i].FileGuid))
  212. {
  213. try
  214. {
  215. FileToolsCommon.DeleteFile(wKData.VideoList.Find(x => x.FileGuid == pageData.menuList[i].FileGuid).VideoPath);
  216. FileToolsCommon.DeleteFile(wKData.VideoList.Find(x => x.FileGuid == pageData.menuList[i].FileGuid).ThumbnailPath);
  217. wKData.VideoList.Remove(wKData.VideoList.Find(x => x.FileGuid == pageData.menuList[i].FileGuid));
  218. Initialize();
  219. return;
  220. }
  221. catch (Exception ex)
  222. {
  223. MessageBox.Show("无法删除视频!" + ex.Message);
  224. return;
  225. }
  226. }
  227. }
  228. }
  229. }
  230. }
  231. /// <summary>
  232. /// 播放
  233. /// </summary>
  234. /// <param name="sender"></param>
  235. /// <param name="e"></param>
  236. private void BtnPlay_Click(object sender, RoutedEventArgs e)
  237. {
  238. pageData.menuList[Subscript].IsEnabled = false;
  239. List<Button> buttons = FindChilds<Button>(listView1, "btnPlay");
  240. for (int i = 0; i < buttons.Count; i++)
  241. {
  242. if (buttons[i] == sender)
  243. {
  244. try
  245. {
  246. ProcessStartInfo psi = new ProcessStartInfo(pageData.menuList[i].Path);
  247. Process pro = new Process
  248. {
  249. StartInfo = psi
  250. };
  251. pro.Start();
  252. }
  253. catch (Exception ex)
  254. {
  255. LogHelper.WriteErrLog("FileDirectoryWindow【BtnPlay_Click】" + ex.Message, ex);
  256. MessageBox.Show(ex.Message);
  257. return;
  258. }
  259. }
  260. }
  261. }
  262. public static List<T> FindChilds<T>(DependencyObject parent, string childName)
  263. where T : DependencyObject
  264. {
  265. List<T> list = new List<T>();
  266. if (parent == null)
  267. {
  268. return list;
  269. }
  270. int childrenCount = VisualTreeHelper.GetChildrenCount(parent);
  271. for (int i = 0; i < childrenCount; i++)
  272. {
  273. DependencyObject child = VisualTreeHelper.GetChild(parent, i);
  274. // 如果子控件不是需查找的控件类型
  275. T childType = child as T;
  276. if (childType == null)
  277. {
  278. // 在下一级控件中递归查找
  279. List<T> findChildList = FindChilds<T>(child, childName);
  280. for (int j = 0; j < findChildList.Count; j++)
  281. {
  282. }
  283. list.AddRange(FindChilds<T>(child, childName));
  284. }
  285. else if (!string.IsNullOrEmpty(childName))
  286. {
  287. FrameworkElement frameworkElement = child as FrameworkElement;
  288. // 如果控件名称符合参数条件
  289. if (frameworkElement != null && frameworkElement.Name == childName)
  290. {
  291. list.Add((T)child);
  292. }
  293. }
  294. else
  295. {
  296. // 查找到了控件
  297. list.Add((T)child);
  298. }
  299. }
  300. return list;
  301. }
  302. /// <summary>
  303. /// 修改
  304. /// </summary>
  305. /// <param name="sender"></param>
  306. /// <param name="e"></param>
  307. private void BtnModify_Click(object sender, RoutedEventArgs e)
  308. {
  309. if (IsModify)
  310. {
  311. pageData.menuList[Subscript].IsEnabled = false;
  312. }
  313. List<Button> buttons = FindChilds<Button>(listView1, "btnModify");
  314. for (int i = 0; i < buttons.Count; i++)
  315. {
  316. if (buttons[i] == sender)
  317. {
  318. pageData.menuList[i].IsEnabled = true;
  319. Subscript = i;
  320. IsModify = true;
  321. }
  322. }
  323. }
  324. int MouseNumber = 0;
  325. /// <summary>
  326. /// 鼠标按下
  327. /// </summary>
  328. /// <param name="sender"></param>
  329. /// <param name="e"></param>
  330. private void Window_MouseLeftButtonDown_1(object sender, MouseButtonEventArgs e)
  331. {
  332. //if (IsModify)
  333. //{
  334. // if (MouseNumber > 0 && pageData.menuList.Count > Subscript)
  335. // {
  336. // pageData.menuList[Subscript].IsEnabled = false;
  337. // try
  338. // {
  339. // if (!pageData.menuList[Subscript].Name.Equals(pageData.menuList[Subscript].VideoName))
  340. // {
  341. // string tempPath = pageData.menuList[Subscript].VideoName + pageData.menuList[Subscript].VideoType;
  342. // tempPath = pageData.menuList[Subscript].Path.Replace(tempPath, "").Trim();
  343. // tempPath = tempPath + pageData.menuList[Subscript].Name;
  344. // FileToolsCommon.MoveDirectory(pageData.menuList[Subscript].Path, tempPath, out string Message);
  345. // }
  346. // }
  347. // catch (Exception ex)
  348. // {
  349. // MessageBox.Show("无法修改视频名称!" + ex.Message);
  350. // return;
  351. // }
  352. // }
  353. // MouseNumber++;
  354. //}
  355. }
  356. private void Window_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
  357. {
  358. // if (IsModify)
  359. // {
  360. // if (MouseNumber > 0 && pageData.menuList.Count > Subscript)
  361. // {
  362. // MouseNumber = 0;
  363. // pageData.menuList[Subscript].IsEnabled = false;
  364. // try
  365. // {
  366. // if (!pageData.menuList[Subscript].Name.Equals(pageData.menuList[Subscript].VideoName))
  367. // {
  368. // MouseNumber = 0;
  369. // string tempPath = pageData.menuList[Subscript].FilePath + pageData.menuList[Subscript].VideoName + "." + pageData.menuList[Subscript].VideoType;
  370. // if (FileToolsCommon.IsExistFile(tempPath))
  371. // {
  372. // MessageBox.Show("文件名已存在!");
  373. // return;
  374. // }
  375. // foreach (Model_WKData wKData in APP.WKDataList)
  376. // {
  377. // if (wKData.VideoList == null)
  378. // continue;
  379. // if (wKData.VideoList.Exists(x => x.FileGuid == pageData.menuList[Subscript].FileGuid))
  380. // {
  381. // try
  382. // {
  383. // //FileToolsCommon.DeleteFile(wKData.VideoList.Find(x => x.FileGuid == pageData.menuList[Subscript].FileGuid).VideoPath);
  384. // //FileToolsCommon.DeleteFile(wKData.VideoList.Find(x => x.FileGuid == pageData.menuList[Subscript].FileGuid).ThumbnailPath);
  385. // //wKData.VideoList.Remove(wKData.VideoList.Find(x => x.FileGuid == pageData.menuList[Subscript].FileGuid));
  386. // //Initialize();
  387. // //return;
  388. // }
  389. // catch (Exception ex)
  390. // {
  391. // MessageBox.Show("无法删除视频!" + ex.Message);
  392. // return;
  393. // }
  394. // }
  395. // }
  396. // FileToolsCommon.Copy(pageData.menuList[Subscript].Path, tempPath);
  397. // }
  398. // }
  399. // catch (Exception ex)
  400. // {
  401. // MessageBox.Show("无法修改视频名称!" + ex.Message);
  402. // return;
  403. // }
  404. // }
  405. // MouseNumber++;
  406. // }
  407. }
  408. }
  409. ///// <summary>
  410. ///// 修改文件名
  411. ///// </summary>
  412. ///// <param name="Guid">唯一编号</param>
  413. ///// <param name="NewName">文件名带后缀 不带路径</param>
  414. ///// <returns></returns>
  415. //bool ModifyPathName(string Guid,string NewName)
  416. //{
  417. //}
  418. public class FileDirectoryData : NotifyModel
  419. {
  420. public ObservableCollection<FileDirectoryModel> menuList { get; set; }
  421. public FileDirectoryData()
  422. {
  423. menuList = new ObservableCollection<FileDirectoryModel>();
  424. }
  425. }
  426. public class FileDirectoryModel : NotifyModel
  427. {
  428. private int _serialNumber;
  429. /// <summary>
  430. /// 序号
  431. /// </summary>
  432. public int SerialNumber
  433. {
  434. get => _serialNumber;
  435. set
  436. {
  437. _serialNumber = value;
  438. OnPropertyChanged("SerialNumber");
  439. }
  440. }
  441. private string _videoName;
  442. /// <summary>
  443. /// 视频名称
  444. /// </summary>
  445. public string VideoName
  446. {
  447. get => _videoName;
  448. set
  449. {
  450. _videoName = value;
  451. OnPropertyChanged("VideoName");
  452. }
  453. }
  454. private int _videoDuration;
  455. /// <summary>
  456. /// 视频时长
  457. /// </summary>
  458. public int VideoDuration
  459. {
  460. get => _videoDuration;
  461. set
  462. {
  463. _videoDuration = value;
  464. OnPropertyChanged("VideoDuration");
  465. }
  466. }
  467. private string _videoSize;
  468. /// <summary>
  469. /// 视频大小
  470. /// </summary>
  471. public string VideoSize
  472. {
  473. get => _videoSize;
  474. set
  475. {
  476. _videoSize = value;
  477. OnPropertyChanged("VideoSize");
  478. }
  479. }
  480. private string _videoTime;
  481. /// <summary>
  482. /// 日期
  483. /// </summary>
  484. public string VideoTime
  485. {
  486. get => _videoTime;
  487. set
  488. {
  489. _videoTime = value;
  490. OnPropertyChanged("VideoTime");
  491. }
  492. }
  493. private string _colour;
  494. /// <summary>
  495. /// 颜色
  496. /// </summary>
  497. public string Colour
  498. {
  499. get => _colour;
  500. set
  501. {
  502. _colour = value;
  503. OnPropertyChanged("Colour");
  504. }
  505. }
  506. private bool _isEnabled;
  507. /// <summary>
  508. /// 是否可编辑
  509. /// </summary>
  510. public bool IsEnabled
  511. {
  512. get => _isEnabled;
  513. set
  514. {
  515. _isEnabled = value;
  516. OnPropertyChanged("IsEnabled");
  517. }
  518. }
  519. public string Path { get; set; }
  520. private string _visi;
  521. /// <summary>
  522. /// 显示
  523. /// </summary>
  524. public string Visi
  525. {
  526. get => _visi;
  527. set
  528. {
  529. _visi = value;
  530. OnPropertyChanged("Visi");
  531. }
  532. }
  533. private string _coll;
  534. /// <summary>
  535. /// 显示
  536. /// </summary>
  537. public string Coll
  538. {
  539. get => _coll;
  540. set
  541. {
  542. _coll = value;
  543. OnPropertyChanged("Coll");
  544. }
  545. }
  546. /// <summary>
  547. /// 唯一编号
  548. /// </summary>
  549. public string FileGuid { get; set; }
  550. /// <summary>
  551. /// 视频类型
  552. /// </summary>
  553. public string VideoType { get; set; }
  554. /// <summary>
  555. /// 初始名称
  556. /// </summary>
  557. public string Name { get; set; }
  558. /// <summary>
  559. /// 文件路径
  560. /// </summary>
  561. public string FilePath { get; set; }
  562. }
  563. }