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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  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. internal FileDirectoryData pageData = new FileDirectoryData();
  25. /// <summary>
  26. /// 文件目录
  27. /// </summary>
  28. public FileDirectoryWindow()
  29. {
  30. InitializeComponent();
  31. Initialize();
  32. }
  33. /// <summary>
  34. /// 初始化
  35. /// </summary>
  36. public void Initialize()
  37. {
  38. //加载视频列表
  39. LoadingVideoList();
  40. int i = 1;
  41. bool isColour = true;
  42. pageData.menuList.Clear();
  43. //显示视频
  44. foreach (Model_Video videoinfo in model_VideoList)
  45. {
  46. //是否已上传
  47. //videoinfo.IsUpload;
  48. //录制时间
  49. //videoinfo.RSTime;
  50. //文件大小
  51. //videoinfo.VideoSize;
  52. //文件缩略图路径
  53. //videoinfo.ThumbnailPath;
  54. //文件唯一标示 上传事件筛选需要上传的视频
  55. //videoinfo.FileGuid;
  56. //文件存储路径
  57. //videoinfo.VidePath;
  58. string colour = "#FFFFFF";
  59. if (isColour==true)
  60. {
  61. colour = "#FFFFFF";
  62. isColour = false;
  63. }
  64. else
  65. {
  66. colour = "#E6F1FF";
  67. isColour = true;
  68. }
  69. string vis = "Visible";
  70. string cos = "Collapsed";
  71. if(!videoinfo.IsUpload)
  72. {
  73. vis= "Collapsed";
  74. cos= "Visible";
  75. }
  76. pageData.menuList.Add(new FileDirectoryModel()
  77. {
  78. SerialNumber = i,
  79. VideoName = Common.system.FileToolsCommon.GetIOFileName(videoinfo.VideoPath),
  80. VideoDuration = 0,
  81. VideoSize = videoinfo.VideoSize,
  82. VideoTime = videoinfo.RSTime,
  83. IsEnabled = false,
  84. Path = videoinfo.VideoPath,
  85. Colour = colour,
  86. Visi = vis,
  87. Coll=cos,
  88. FileGuid= videoinfo.FileGuid,
  89. }) ; ;
  90. i++;
  91. }
  92. txbSum.Text = pageData.menuList.Count.ToString();
  93. DataContext = pageData;
  94. }
  95. /// <summary>
  96. /// 加载视频列表
  97. /// </summary>
  98. public void LoadingVideoList()
  99. {
  100. model_VideoList = new List<Model_Video>();
  101. foreach(Model_WKData Vdata in APP.WKDataList)
  102. {
  103. if (Vdata.VideoList == null)
  104. continue;
  105. foreach(Model_Video videoinfo in Vdata.VideoList)
  106. {
  107. model_VideoList.Add(videoinfo);
  108. }
  109. }
  110. }
  111. /// <summary>
  112. /// 关闭
  113. /// </summary>
  114. /// <param name="sender"></param>
  115. /// <param name="e"></param>
  116. private void btnDown_Click(object sender, RoutedEventArgs e)
  117. {
  118. this.Hide();
  119. }
  120. /// <summary>
  121. /// 窗口移动
  122. /// </summary>
  123. /// <param name="sender"></param>
  124. /// <param name="e"></param>
  125. private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  126. {
  127. DragMove();
  128. }
  129. /// <summary>
  130. /// 上传
  131. /// </summary>
  132. /// <param name="sender"></param>
  133. /// <param name="e"></param>
  134. private void BtnUpload_Click(object sender, RoutedEventArgs e)
  135. {
  136. List<Button> buttons = FindChilds<Button>(listView1, "btnUpload");
  137. for (int i = 0; i < buttons.Count; i++)
  138. {
  139. if (buttons[i] == sender)
  140. {
  141. DAL_Upload dAL_Upload = new DAL_Upload();
  142. if (dAL_Upload.UploadVideo(pageData.menuList[i].FileGuid, out string ErrMessage))
  143. {
  144. pageData.menuList[i].Visi = "Visible";
  145. pageData.menuList[i].Coll = "Collapsed";
  146. DataContext = pageData;
  147. MessageBox.Show("视频上传成功!");
  148. }
  149. else
  150. {
  151. MessageBox.Show(ErrMessage);
  152. }
  153. }
  154. }
  155. }
  156. /// <summary>
  157. /// 删除
  158. /// </summary>
  159. /// <param name="sender"></param>
  160. /// <param name="e"></param>
  161. private void BtnDelete_Click(object sender, RoutedEventArgs e)
  162. {
  163. List<Button> buttons = FindChilds<Button>(listView1, "btnDelete");
  164. for (int i = 0; i < buttons.Count; i++)
  165. {
  166. if (buttons[i] == sender)
  167. {
  168. foreach (Model_WKData wKData in APP.WKDataList)
  169. {
  170. if (wKData.VideoList == null)
  171. continue;
  172. if(wKData.VideoList.Exists(x=>x.FileGuid==pageData.menuList[i].FileGuid))
  173. {
  174. try
  175. {
  176. FileToolsCommon.DeleteFile(wKData.VideoList.Find(x => x.FileGuid == pageData.menuList[i].FileGuid).VideoPath);
  177. FileToolsCommon.DeleteFile(wKData.VideoList.Find(x => x.FileGuid == pageData.menuList[i].FileGuid).ThumbnailPath);
  178. wKData.VideoList.Remove(wKData.VideoList.Find(x => x.FileGuid == pageData.menuList[i].FileGuid));
  179. Initialize();
  180. return;
  181. }
  182. catch (Exception ex)
  183. {
  184. MessageBox.Show("无法删除视频!"+ex.Message);
  185. return;
  186. }
  187. }
  188. }
  189. }
  190. }
  191. }
  192. /// <summary>
  193. /// 播放
  194. /// </summary>
  195. /// <param name="sender"></param>
  196. /// <param name="e"></param>
  197. private void BtnPlay_Click(object sender, RoutedEventArgs e)
  198. {
  199. List<Button> buttons = FindChilds<Button>(listView1, "btnPlay");
  200. for (int i = 0; i < buttons.Count; i++)
  201. {
  202. if (buttons[i] == sender)
  203. {
  204. try
  205. {
  206. ProcessStartInfo psi = new ProcessStartInfo(pageData.menuList[i].Path);
  207. Process pro = new Process
  208. {
  209. StartInfo = psi
  210. };
  211. pro.Start();
  212. }
  213. catch (Exception ex)
  214. {
  215. LogHelper.WriteErrLog("FileDirectoryWindow【BtnPlay_Click】" + ex.Message, ex);
  216. MessageBox.Show(ex.Message);
  217. return;
  218. }
  219. }
  220. }
  221. }
  222. public static List<T> FindChilds<T>(DependencyObject parent, string childName)
  223. where T : DependencyObject
  224. {
  225. List<T> list = new List<T>();
  226. if (parent == null)
  227. {
  228. return list;
  229. }
  230. int childrenCount = VisualTreeHelper.GetChildrenCount(parent);
  231. for (int i = 0; i < childrenCount; i++)
  232. {
  233. DependencyObject child = VisualTreeHelper.GetChild(parent, i);
  234. // 如果子控件不是需查找的控件类型
  235. T childType = child as T;
  236. if (childType == null)
  237. {
  238. // 在下一级控件中递归查找
  239. List<T> findChildList = FindChilds<T>(child, childName);
  240. for (int j = 0; j < findChildList.Count; j++)
  241. {
  242. }
  243. list.AddRange(FindChilds<T>(child, childName));
  244. }
  245. else if (!string.IsNullOrEmpty(childName))
  246. {
  247. FrameworkElement frameworkElement = child as FrameworkElement;
  248. // 如果控件名称符合参数条件
  249. if (frameworkElement != null && frameworkElement.Name == childName)
  250. {
  251. list.Add((T)child);
  252. }
  253. }
  254. else
  255. {
  256. // 查找到了控件
  257. list.Add((T)child);
  258. }
  259. }
  260. return list;
  261. }
  262. /// <summary>
  263. /// 修改
  264. /// </summary>
  265. /// <param name="sender"></param>
  266. /// <param name="e"></param>
  267. private void BtnModify_Click(object sender, RoutedEventArgs e)
  268. {
  269. List<Button> buttons = FindChilds<Button>(listView1, "btnModify");
  270. for (int i = 0; i < buttons.Count; i++)
  271. {
  272. if (buttons[i] == sender)
  273. {
  274. pageData.menuList[i].IsEnabled = true;
  275. }
  276. }
  277. }
  278. }
  279. public class FileDirectoryData : NotifyModel
  280. {
  281. public ObservableCollection<FileDirectoryModel> menuList { get; set; }
  282. public FileDirectoryData()
  283. {
  284. menuList = new ObservableCollection<FileDirectoryModel>();
  285. }
  286. }
  287. public class FileDirectoryModel : NotifyModel
  288. {
  289. private int _serialNumber;
  290. /// <summary>
  291. /// 序号
  292. /// </summary>
  293. public int SerialNumber
  294. {
  295. get => _serialNumber;
  296. set
  297. {
  298. _serialNumber = value;
  299. OnPropertyChanged("SerialNumber");
  300. }
  301. }
  302. private string _videoName;
  303. /// <summary>
  304. /// 视频名称
  305. /// </summary>
  306. public string VideoName
  307. {
  308. get => _videoName;
  309. set
  310. {
  311. _videoName = value;
  312. OnPropertyChanged("VideoName");
  313. }
  314. }
  315. private int _videoDuration;
  316. /// <summary>
  317. /// 视频时长
  318. /// </summary>
  319. public int VideoDuration
  320. {
  321. get => _videoDuration;
  322. set
  323. {
  324. _videoDuration = value;
  325. OnPropertyChanged("VideoDuration");
  326. }
  327. }
  328. private string _videoSize;
  329. /// <summary>
  330. /// 视频大小
  331. /// </summary>
  332. public string VideoSize
  333. {
  334. get => _videoSize;
  335. set
  336. {
  337. _videoSize = value;
  338. OnPropertyChanged("VideoSize");
  339. }
  340. }
  341. private string _videoTime;
  342. /// <summary>
  343. /// 日期
  344. /// </summary>
  345. public string VideoTime
  346. {
  347. get => _videoTime;
  348. set
  349. {
  350. _videoTime = value;
  351. OnPropertyChanged("VideoTime");
  352. }
  353. }
  354. private string _colour;
  355. /// <summary>
  356. /// 颜色
  357. /// </summary>
  358. public string Colour
  359. {
  360. get => _colour;
  361. set
  362. {
  363. _colour = value;
  364. OnPropertyChanged("Colour");
  365. }
  366. }
  367. private bool _isEnabled;
  368. /// <summary>
  369. /// 是否可编辑
  370. /// </summary>
  371. public bool IsEnabled
  372. {
  373. get => _isEnabled;
  374. set
  375. {
  376. _isEnabled = value;
  377. OnPropertyChanged("IsEnabled");
  378. }
  379. }
  380. public string Path { get; set; }
  381. private string _visi;
  382. /// <summary>
  383. /// 显示
  384. /// </summary>
  385. public string Visi
  386. {
  387. get => _visi;
  388. set
  389. {
  390. _visi = value;
  391. OnPropertyChanged("Visi");
  392. }
  393. }
  394. private string _coll;
  395. /// <summary>
  396. /// 显示
  397. /// </summary>
  398. public string Coll
  399. {
  400. get => _coll;
  401. set
  402. {
  403. _coll = value;
  404. OnPropertyChanged("Coll");
  405. }
  406. }
  407. /// <summary>
  408. /// 唯一编号
  409. /// </summary>
  410. public string FileGuid { get; set; }
  411. }
  412. }