星火微课系统客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

FileDirectoryWindow.xaml.cs 19KB

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