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

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