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

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