星火微课系统客户端
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

FileDirectoryWindow.xaml.cs 15KB

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