星火直播PC
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

UserCenterWindow.xaml.cs 37KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950
  1. using Common.system;
  2. using System;
  3. using System.Collections.ObjectModel;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Diagnostics;
  7. using System.IO;
  8. using System.Threading;
  9. using System.Windows;
  10. using System.Windows.Controls;
  11. using System.Windows.Input;
  12. using System.Windows.Media;
  13. using XHZB.Desktop.Utils;
  14. using XHZB.Model;
  15. namespace XHZB.Desktop
  16. {
  17. /// <summary>
  18. /// 个人空间 LessonPreparationWindow.xaml 的交互逻辑
  19. /// </summary>
  20. public partial class UserCenterWindow : Window, DownloadUtil.DownloadCallback
  21. {
  22. private int serverReturnCode = 0;
  23. private readonly RegisterController registerController = new RegisterController();
  24. internal UserCenterPageData pageData = new UserCenterPageData();
  25. private bool isInitial = false;
  26. private Thread thread;
  27. private bool initialization = true;
  28. /// <summary>
  29. /// 下拉框数据源
  30. /// </summary>
  31. public DataTable data = new DataTable();
  32. /// <summary>
  33. /// 是否是下载状态 默认false 不是
  34. /// </summary>
  35. private bool isDownloadStatus = false;
  36. /// <summary>
  37. /// 教材关系表id
  38. /// </summary>
  39. private int Lsbid = 0;
  40. /// <summary>
  41. /// 章节id
  42. /// </summary>
  43. private int Directorid = 0;
  44. /// <summary>
  45. /// 资源分类1音频2视频3图片4文档
  46. /// </summary>
  47. private int Resourceclass = 0;
  48. /// <summary>
  49. /// 个人空间
  50. /// </summary>
  51. public UserCenterWindow()
  52. {
  53. InitializeComponent();
  54. DataContext = pageData;
  55. //初始化配置文件
  56. //ZJConfigUtil.init();
  57. isInitial = true;
  58. Resourceclass = 0;
  59. Lsbid = APP.REQStartClass.lsbid;
  60. Directorid = APP.REQStartClass.directorid;
  61. borAll.Background = new SolidColorBrush(Colors.DodgerBlue);
  62. borAudio.Background = new SolidColorBrush(Colors.Transparent);
  63. borVideo.Background = new SolidColorBrush(Colors.Transparent);
  64. borImage.Background = new SolidColorBrush(Colors.Transparent);
  65. borDoc.Background = new SolidColorBrush(Colors.Transparent);
  66. btnAll.Foreground = new SolidColorBrush(Colors.White);
  67. btnAudio.Foreground = new SolidColorBrush(Colors.Black);
  68. btnVideo.Foreground = new SolidColorBrush(Colors.Black);
  69. btnImage.Foreground = new SolidColorBrush(Colors.Black);
  70. btnDoc.Foreground = new SolidColorBrush(Colors.Black);
  71. initJiaocai();
  72. }
  73. private void initJiaocai()
  74. {
  75. System.Collections.Generic.List<TsubjectbookListModel> list = APP.TsubjectbookList;
  76. int selectIndex = 0;
  77. for (int i = 0; i < list.Count; i++)
  78. {
  79. TsubjectbookListModel book = list[i];
  80. if (book.lsbid == APP.lsbid)
  81. {
  82. selectIndex = i;
  83. }
  84. pageData.bookList.Add(new ComboBoxBeanModel()
  85. {
  86. Key = book.lsbid,
  87. Value = $"{book.subjectname} {book.bookname}"
  88. });
  89. }
  90. cmbClass.SelectedIndex = selectIndex;
  91. }
  92. /// <summary>
  93. /// 章节列表服务-调用
  94. /// </summary>
  95. /// <returns></returns>
  96. private object InvokeDirectorListServering()
  97. {
  98. APP.DirectorList = null;
  99. serverReturnCode = registerController.DirectorList(Lsbid,2,APP.LoginUser.userid);
  100. return APP.ErrorMessage;
  101. }
  102. /// <summary>
  103. /// 章节列表服务-返回结果
  104. /// </summary>
  105. /// <returns></returns>
  106. public void InvokeServerDirectorListCompate(object obj)
  107. {
  108. if (serverReturnCode == APP.ServerScuessCode)
  109. {
  110. if (!isInitial)
  111. {
  112. Directorid = 0;
  113. isInitial = false;
  114. }
  115. pageData.zhangjieList.Clear();
  116. pageData.zhangjieList.Add(new ChapterModel()
  117. {
  118. directorid = 0,
  119. directorname = "全部",
  120. level = 1,
  121. selected = 0
  122. });
  123. System.Collections.Generic.List<DirectorListModel> list = APP.DirectorList;
  124. for (int i = 0; i < list.Count; i++)
  125. {
  126. DirectorListModel item = APP.DirectorList[i];
  127. pageData.zhangjieList.Add(new ChapterModel()
  128. {
  129. directorid = item.directorid,
  130. directorname = item.directorname,
  131. level = item.directorlevel,
  132. selected = 0
  133. });
  134. addChild(item);
  135. }
  136. foreach (ChapterModel zhangjie in pageData.zhangjieList)
  137. {
  138. if (Directorid == zhangjie.directorid)
  139. {
  140. zhangjie.selected = 1;
  141. }
  142. else
  143. {
  144. zhangjie.selected = 0;
  145. }
  146. }
  147. APP.BackgroundWorkerHelper.RunWorkerAsync(InvokeResourceMyListServering, InvokeServerResourceMyListCompate);
  148. }
  149. else
  150. {
  151. MessageWindow.Show(APP.ErrorMessage);
  152. }
  153. }
  154. private void addChild(DirectorListModel directorList)
  155. {
  156. if (directorList.children != null && directorList.children.Count > 0)
  157. {
  158. foreach (DirectorListModel child in directorList.children)
  159. {
  160. pageData.zhangjieList.Add(new ChapterModel()
  161. {
  162. directorid = child.directorid,
  163. directorname = getSpace(child.directorlevel) + child.directorname
  164. });
  165. if (child.children != null && child.children.Count > 0)
  166. {
  167. addChild(child);
  168. }
  169. }
  170. }
  171. }
  172. private string getSpace(int num)
  173. {
  174. string str = "";
  175. for (int i = 0; i < num; i++)
  176. {
  177. str += " ";
  178. }
  179. return str;
  180. }
  181. private void zhangjieClick(object sender, RoutedEventArgs e)
  182. {
  183. ChapterModel item = ((Button)sender).Tag as ChapterModel;
  184. foreach (ChapterModel zhangjie in pageData.zhangjieList)
  185. {
  186. if (item.directorid == zhangjie.directorid)
  187. {
  188. zhangjie.selected = 1;
  189. }
  190. else
  191. {
  192. zhangjie.selected = 0;
  193. }
  194. }
  195. Directorid = item.directorid;
  196. APP.BackgroundWorkerHelper.RunWorkerAsync(InvokeResourceMyListServering, InvokeServerResourceMyListCompate);
  197. }
  198. /// <summary>
  199. /// 我的备课列表服务-调用
  200. /// </summary>
  201. /// <returns></returns>
  202. private object InvokeResourceMyListServering()
  203. {
  204. Dispatcher.Invoke(new Action(() =>
  205. {
  206. APP.myloading.Show();
  207. }));
  208. APP.ResourceMyList = null;
  209. serverReturnCode = registerController.ResourceMyList(Lsbid, Directorid, Resourceclass);
  210. return APP.ErrorMessage;
  211. }
  212. /// <summary>
  213. /// 我的备课列表服务-返回结果
  214. /// </summary>
  215. /// <returns></returns>
  216. public void InvokeServerResourceMyListCompate(object obj)
  217. {
  218. Dispatcher.Invoke(new Action(() =>
  219. {
  220. APP.myloading.Hide();
  221. }));
  222. if (serverReturnCode == APP.ServerScuessCode)
  223. {
  224. if (pageData.menuList.Count > 0)
  225. {
  226. pageData.menuList.Clear();
  227. DataContext = pageData;
  228. }
  229. if (APP.ResourceMyList.obj != null)
  230. {
  231. System.Collections.Generic.List<string> resource = new System.Collections.Generic.List<string>();
  232. for (int i = 0; i < APP.ResourceMyList.obj.Count; i++)
  233. {
  234. string imgSuffix = string.Empty;
  235. string visDuration = "Collapsed";
  236. string visButton = "Collapsed";
  237. string visDownload = "Visible";
  238. System.DateTime dateTime = new System.DateTime(1970, 1, 1, 0, 0, 0, 0);
  239. dateTime = dateTime.AddSeconds(APP.ResourceMyList.obj[i].createtime).ToLocalTime();
  240. if ("doc".Equals(APP.ResourceMyList.obj[i].suffix)
  241. || "docx".Equals(APP.ResourceMyList.obj[i].suffix))
  242. {
  243. imgSuffix = "../Images/Resource/DOC.png";
  244. }
  245. else if ("ppt".Equals(APP.ResourceMyList.obj[i].suffix)
  246. || "pptx".Equals(APP.ResourceMyList.obj[i].suffix))
  247. {
  248. imgSuffix = "../Images/Resource/PPT.png";
  249. }
  250. else if ("pdf".Equals(APP.ResourceMyList.obj[i].suffix))
  251. {
  252. imgSuffix = "../Images/Resource/PDF.png";
  253. }
  254. else if ("excel".Equals(APP.ResourceMyList.obj[i].suffix)
  255. || "xls".Equals(APP.ResourceMyList.obj[i].suffix) || "xlsx".Equals(APP.ResourceMyList.obj[i].suffix))
  256. {
  257. imgSuffix = "../Images/Resource/EXCEL.png";
  258. }
  259. else if ("class".Equals(APP.ResourceMyList.obj[i].suffix))
  260. {
  261. imgSuffix = "../Images/Resource/CLASS.png";
  262. }
  263. else if ("dsc".Equals(APP.ResourceMyList.obj[i].suffix))
  264. {
  265. imgSuffix = "../Images/Resource/DSC.png";
  266. }
  267. else if ("mp3".Equals(APP.ResourceMyList.obj[i].suffix))
  268. {
  269. visDuration = "Visible";
  270. imgSuffix = "../Images/Resource/MP3.png";
  271. }
  272. else if ("mp4".Equals(APP.ResourceMyList.obj[i].suffix)
  273. || "flv".Equals(APP.ResourceMyList.obj[i].suffix))
  274. {
  275. visDuration = "Visible";
  276. if (APP.ResourceMyList.obj[i].resourcecover != null)
  277. {
  278. imgSuffix = APP.showImageUrl + APP.ResourceMyList.obj[i].resourcecover.ToString();
  279. }
  280. else
  281. {
  282. imgSuffix = "../Images/Resource/MP4.png";
  283. }
  284. }
  285. else if ("png".Equals(APP.ResourceMyList.obj[i].suffix)
  286. || "jpg".Equals(APP.ResourceMyList.obj[i].suffix)
  287. || "jpeg".Equals(APP.ResourceMyList.obj[i].suffix))
  288. {
  289. imgSuffix = "../Images/Resource/PNG.png";
  290. }
  291. else if ("txt".Equals(APP.ResourceMyList.obj[i].suffix))
  292. {
  293. imgSuffix = "../Images/Resource/TXT.png";
  294. }
  295. else if ("txt".Equals(APP.ResourceMyList.obj[i].suffix))
  296. {
  297. imgSuffix = "../Images/Resource/FLV.png";
  298. }
  299. else if ("wav".Equals(APP.ResourceMyList.obj[i].suffix))
  300. {
  301. imgSuffix = "../Images/Resource/WAV.png";
  302. }
  303. string resourcesSuffix = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\" + APP.LoginUser.username + "\\" + APP.ResourceMyList.obj[i].resourcename + "." + APP.ResourceMyList.obj[i].suffix;
  304. if (!string.IsNullOrWhiteSpace(APP.fileStorageAddress))
  305. {
  306. resourcesSuffix = APP.fileStorageAddress + "\\" + APP.ResourceMyList.obj[i].resourcename + "." + APP.ResourceMyList.obj[i].suffix;
  307. }
  308. if (File.Exists(resourcesSuffix))//检查资源是否已经存在
  309. {
  310. visButton = "Visible";
  311. visDownload = "Collapsed";
  312. }
  313. string resourcesize;
  314. if (APP.ResourceMyList.obj[i].resourcesize > 1024)
  315. {
  316. if (APP.ResourceMyList.obj[i].resourcesize / 1024 > 1024)
  317. {
  318. resourcesize = (APP.ResourceMyList.obj[i].resourcesize / 1024 / 1024).ToString() + "MB";
  319. }
  320. else
  321. {
  322. resourcesize = (APP.ResourceMyList.obj[i].resourcesize / 1024).ToString() + "KB";
  323. }
  324. }
  325. else
  326. {
  327. resourcesize = (APP.ResourceMyList.obj[i].resourcesize).ToString() + "B";
  328. }
  329. string duration = string.Empty;
  330. if (APP.ResourceMyList.obj[i].duration > 59)
  331. {
  332. if (APP.ResourceMyList.obj[i].duration > 3599)
  333. {
  334. if (APP.ResourceMyList.obj[i].duration % 3600 == 0)
  335. {
  336. duration = (APP.ResourceMyList.obj[i].duration / 3600).ToString() + "时";
  337. }
  338. else
  339. {
  340. duration = (APP.ResourceMyList.obj[i].duration / 3600).ToString() + "时" + (APP.ResourceMyList.obj[i].duration % 3600).ToString() + "分";
  341. }
  342. }
  343. else
  344. {
  345. if (APP.ResourceMyList.obj[i].duration % 60 == 0)
  346. {
  347. duration = (APP.ResourceMyList.obj[i].duration / 60).ToString() + "分";
  348. }
  349. else
  350. {
  351. duration = (APP.ResourceMyList.obj[i].duration / 60).ToString() + "分" + (APP.ResourceMyList.obj[i].duration % 60).ToString() + "秒";
  352. }
  353. }
  354. }
  355. else
  356. {
  357. duration = APP.ResourceMyList.obj[i].duration.ToString() + "秒";
  358. }
  359. pageData.menuList.Add(new ToolbarMenuTwo()
  360. {
  361. Resourcesize = resourcesize,
  362. ResourceName = APP.ResourceMyList.obj[i].resourcename,
  363. Times = dateTime.ToString("yyy-MM-dd HH:mm:ss"),
  364. Pic = imgSuffix,
  365. VisDuration = visDuration,
  366. Duration = duration,
  367. VisButton = visButton,
  368. VisDownload = visDownload,
  369. Resourceid = APP.ResourceMyList.obj[i].resourceid
  370. });
  371. }
  372. }
  373. DataContext = pageData;
  374. }
  375. else
  376. {
  377. MessageWindow.Show(APP.ErrorMessage);
  378. }
  379. }
  380. private void DownLoadTwo(string httpurls, int position, string savepath)
  381. {
  382. thread = DownloadUtil.downloadFileWithCallback(
  383. httpurls,
  384. position,
  385. savepath,
  386. Dispatcher,
  387. this
  388. );
  389. }
  390. /// <summary>
  391. /// 下载
  392. /// </summary>
  393. /// <param name="sender"></param>
  394. /// <param name="e"></param>
  395. private void btnDownload_Click(object sender, RoutedEventArgs e)
  396. {
  397. if (!isDownloadStatus)
  398. {
  399. int clickindex = 0;
  400. Button btn = (Button)sender;
  401. for (int i = 0; i < APP.ResourceMyList.obj.Count; i++)
  402. {
  403. if (APP.ResourceMyList.obj[i].resourceid == Convert.ToInt32(btn.Tag))
  404. {
  405. clickindex = i;
  406. break;
  407. }
  408. }
  409. string fileAddress = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\" + APP.LoginUser.username + "\\" + APP.ResourceMyList.obj[clickindex].resourcename + "." + APP.ResourceMyList.obj[clickindex].suffix;
  410. if (!string.IsNullOrWhiteSpace(APP.fileStorageAddress))
  411. {
  412. fileAddress = APP.fileStorageAddress + "\\" + APP.ResourceMyList.obj[clickindex].resourcename + "." + APP.ResourceMyList.obj[clickindex].suffix;
  413. }
  414. //if (APP.outputInforLog)
  415. //{
  416. // LogHelper.WriteInfoLog("UserCenterWindow(btnDownload_Click 下载)" + fileAddress);
  417. //}
  418. if (Directory.Exists(fileAddress))//存在就打开 不存在就下载
  419. {
  420. ProcessStartInfo psi = new ProcessStartInfo(fileAddress);
  421. Process pro = new Process
  422. {
  423. StartInfo = psi
  424. };
  425. pro.Start();
  426. }
  427. else
  428. {
  429. if (!string.IsNullOrWhiteSpace(APP.fileStorageAddress))
  430. {
  431. fileAddress = APP.fileStorageAddress;
  432. }
  433. if (!Directory.Exists(fileAddress))
  434. {
  435. Directory.CreateDirectory(fileAddress);
  436. }
  437. string userHeadPic = APP.showImageUrl + APP.ResourceMyList.obj[clickindex].resourceurl.ToString();
  438. DownLoadTwo(userHeadPic, 9999 + clickindex, fileAddress + "\\");
  439. }
  440. }
  441. }
  442. /// <summary>
  443. /// 打开
  444. /// </summary>
  445. /// <param name="sender"></param>
  446. /// <param name="e"></param>
  447. private void btnTurnOn_Click(object sender, RoutedEventArgs e)
  448. {
  449. if (!isDownloadStatus)
  450. {
  451. int clickindex = 0;
  452. Button btn = (Button)sender;
  453. for (int i = 0; i < APP.ResourceMyList.obj.Count; i++)
  454. {
  455. if (APP.ResourceMyList.obj[i].resourceid == Convert.ToInt32(btn.Tag))
  456. {
  457. clickindex = i;
  458. break;
  459. }
  460. }
  461. string fileAddress = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\" + APP.LoginUser.username + "\\" + APP.ResourceMyList.obj[clickindex].resourcename + "." + APP.ResourceMyList.obj[clickindex].suffix;
  462. if (!string.IsNullOrWhiteSpace(APP.fileStorageAddress))
  463. {
  464. fileAddress = APP.fileStorageAddress + "\\" + APP.ResourceMyList.obj[clickindex].resourcename + "." + APP.ResourceMyList.obj[clickindex].suffix;
  465. }
  466. //if (APP.outputInforLog)
  467. //{
  468. // LogHelper.WriteInfoLog("UserCenterWindow(btnTurnOn_Click 打开)" + fileAddress);
  469. //}
  470. if (Directory.Exists(fileAddress))//存在就打开 不存在就下载
  471. {
  472. try
  473. {
  474. ProcessStartInfo psi = new ProcessStartInfo(fileAddress);
  475. Process pro = new Process
  476. {
  477. StartInfo = psi
  478. };
  479. pro.Start();
  480. }
  481. catch (Exception ex)
  482. {
  483. LogHelper.WriteErrLog("UserCenterWindow【btnTurnOn_Click】" + ex.Message, ex);
  484. MessageWindow.Show(ex.Message);
  485. return;
  486. }
  487. }
  488. else
  489. {
  490. if (!string.IsNullOrWhiteSpace(APP.fileStorageAddress))
  491. {
  492. fileAddress = APP.fileStorageAddress;
  493. }
  494. if (!Directory.Exists(fileAddress))
  495. {
  496. Directory.CreateDirectory(fileAddress);
  497. }
  498. string userHeadPic = APP.showImageUrl + APP.ResourceMyList.obj[clickindex].resourceurl.ToString();
  499. DownLoadTwo(userHeadPic, 9999 + clickindex, fileAddress + "\\");
  500. }
  501. }
  502. }
  503. /// <summary>
  504. /// 全部
  505. /// </summary>
  506. /// <param name="sender"></param>
  507. /// <param name="e"></param>
  508. private void btnAll_Click(object sender, RoutedEventArgs e)
  509. {
  510. pageData.menuList.Clear();
  511. DataContext = pageData;
  512. Resourceclass = 0;
  513. borAll.Background = new SolidColorBrush(Colors.DodgerBlue);
  514. borAudio.Background = new SolidColorBrush(Colors.Transparent);
  515. borVideo.Background = new SolidColorBrush(Colors.Transparent);
  516. borImage.Background = new SolidColorBrush(Colors.Transparent);
  517. borDoc.Background = new SolidColorBrush(Colors.Transparent);
  518. btnAll.Foreground = new SolidColorBrush(Colors.White);
  519. btnAudio.Foreground = new SolidColorBrush(Colors.Black);
  520. btnVideo.Foreground = new SolidColorBrush(Colors.Black);
  521. btnImage.Foreground = new SolidColorBrush(Colors.Black);
  522. btnDoc.Foreground = new SolidColorBrush(Colors.Black);
  523. APP.BackgroundWorkerHelper.RunWorkerAsync(InvokeResourceMyListServering, InvokeServerResourceMyListCompate);
  524. }
  525. private void Window_Closing(object sender, CancelEventArgs e)
  526. {
  527. if (pageData.menuList.Count > 0)
  528. {
  529. pageData.menuList.Clear();
  530. DataContext = null;
  531. }
  532. }
  533. /// <summary>
  534. /// 音频
  535. /// </summary>
  536. /// <param name="sender"></param>
  537. /// <param name="e"></param>
  538. private void btnAudio_Click(object sender, RoutedEventArgs e)
  539. {
  540. pageData.menuList.Clear();
  541. DataContext = pageData;
  542. Resourceclass = 1;
  543. borAll.Background = new SolidColorBrush(Colors.Transparent);
  544. borAudio.Background = new SolidColorBrush(Colors.DodgerBlue);
  545. borVideo.Background = new SolidColorBrush(Colors.Transparent);
  546. borImage.Background = new SolidColorBrush(Colors.Transparent);
  547. borDoc.Background = new SolidColorBrush(Colors.Transparent);
  548. btnAll.Foreground = new SolidColorBrush(Colors.Black);
  549. btnAudio.Foreground = new SolidColorBrush(Colors.White);
  550. btnVideo.Foreground = new SolidColorBrush(Colors.Black);
  551. btnImage.Foreground = new SolidColorBrush(Colors.Black);
  552. btnDoc.Foreground = new SolidColorBrush(Colors.Black);
  553. APP.BackgroundWorkerHelper.RunWorkerAsync(InvokeResourceMyListServering, InvokeServerResourceMyListCompate);
  554. }
  555. /// <summary>
  556. /// 视频
  557. /// </summary>
  558. /// <param name="sender"></param>
  559. /// <param name="e"></param>
  560. private void btnVideo_Click(object sender, RoutedEventArgs e)
  561. {
  562. pageData.menuList.Clear();
  563. DataContext = pageData;
  564. Resourceclass = 2;
  565. borAll.Background = new SolidColorBrush(Colors.Transparent);
  566. borAudio.Background = new SolidColorBrush(Colors.Transparent);
  567. borVideo.Background = new SolidColorBrush(Colors.DodgerBlue);
  568. borImage.Background = new SolidColorBrush(Colors.Transparent);
  569. borDoc.Background = new SolidColorBrush(Colors.Transparent);
  570. btnAll.Foreground = new SolidColorBrush(Colors.Black);
  571. btnAudio.Foreground = new SolidColorBrush(Colors.Black);
  572. btnVideo.Foreground = new SolidColorBrush(Colors.White);
  573. btnImage.Foreground = new SolidColorBrush(Colors.Black);
  574. btnDoc.Foreground = new SolidColorBrush(Colors.Black);
  575. APP.BackgroundWorkerHelper.RunWorkerAsync(InvokeResourceMyListServering, InvokeServerResourceMyListCompate);
  576. }
  577. /// <summary>
  578. /// 图片
  579. /// </summary>
  580. /// <param name="sender"></param>
  581. /// <param name="e"></param>
  582. private void btnImage_Click(object sender, RoutedEventArgs e)
  583. {
  584. pageData.menuList.Clear();
  585. DataContext = pageData;
  586. Resourceclass = 3;
  587. borAll.Background = new SolidColorBrush(Colors.Transparent);
  588. borAudio.Background = new SolidColorBrush(Colors.Transparent);
  589. borVideo.Background = new SolidColorBrush(Colors.Transparent);
  590. borImage.Background = new SolidColorBrush(Colors.DodgerBlue);
  591. borDoc.Background = new SolidColorBrush(Colors.Transparent);
  592. btnAll.Foreground = new SolidColorBrush(Colors.Black);
  593. btnAudio.Foreground = new SolidColorBrush(Colors.Black);
  594. btnVideo.Foreground = new SolidColorBrush(Colors.Black);
  595. btnImage.Foreground = new SolidColorBrush(Colors.White);
  596. btnDoc.Foreground = new SolidColorBrush(Colors.Black);
  597. APP.BackgroundWorkerHelper.RunWorkerAsync(InvokeResourceMyListServering, InvokeServerResourceMyListCompate);
  598. }
  599. /// <summary>
  600. /// 文档
  601. /// </summary>
  602. /// <param name="sender"></param>
  603. /// <param name="e"></param>
  604. private void btnDoc_Click(object sender, RoutedEventArgs e)
  605. {
  606. pageData.menuList.Clear();
  607. DataContext = pageData;
  608. Resourceclass = 4;
  609. borAll.Background = new SolidColorBrush(Colors.Transparent);
  610. borAudio.Background = new SolidColorBrush(Colors.Transparent);
  611. borVideo.Background = new SolidColorBrush(Colors.Transparent);
  612. borImage.Background = new SolidColorBrush(Colors.Transparent);
  613. borDoc.Background = new SolidColorBrush(Colors.DodgerBlue);
  614. btnAll.Foreground = new SolidColorBrush(Colors.Black);
  615. btnAudio.Foreground = new SolidColorBrush(Colors.Black);
  616. btnVideo.Foreground = new SolidColorBrush(Colors.Black);
  617. btnImage.Foreground = new SolidColorBrush(Colors.Black);
  618. btnDoc.Foreground = new SolidColorBrush(Colors.White);
  619. APP.BackgroundWorkerHelper.RunWorkerAsync(InvokeResourceMyListServering, InvokeServerResourceMyListCompate);
  620. }
  621. private void Refresh()
  622. {
  623. pageData.menuList.Clear();
  624. }
  625. /// <summary>
  626. /// 科目教材选择改变事件
  627. /// </summary>
  628. /// <param name="sender"></param>
  629. /// <param name="e"></param>
  630. private void cmbClass_SelectionChanged(object sender, SelectionChangedEventArgs e)
  631. {
  632. if (initialization)
  633. {
  634. initialization = false;
  635. }
  636. else
  637. {
  638. Directorid = 0;
  639. borAll.Background = new SolidColorBrush(Colors.DodgerBlue);
  640. borAudio.Background = new SolidColorBrush(Colors.Transparent);
  641. borVideo.Background = new SolidColorBrush(Colors.Transparent);
  642. borImage.Background = new SolidColorBrush(Colors.Transparent);
  643. borDoc.Background = new SolidColorBrush(Colors.Transparent);
  644. btnAll.Foreground = new SolidColorBrush(Colors.White);
  645. btnAudio.Foreground = new SolidColorBrush(Colors.Black);
  646. btnVideo.Foreground = new SolidColorBrush(Colors.Black);
  647. btnImage.Foreground = new SolidColorBrush(Colors.Black);
  648. btnDoc.Foreground = new SolidColorBrush(Colors.Black);
  649. }
  650. if (cmbClass.SelectedValue != null)
  651. {
  652. Lsbid = Convert.ToInt32(cmbClass.SelectedValue.ToString());
  653. Refresh();
  654. APP.BackgroundWorkerHelper.RunWorkerAsync(InvokeDirectorListServering, InvokeServerDirectorListCompate);
  655. }
  656. else
  657. {
  658. Refresh();
  659. }
  660. }
  661. private void Window_MouseMove(object sender, MouseEventArgs e)
  662. {
  663. if (e.LeftButton == MouseButtonState.Pressed)
  664. {
  665. //执行移动方法
  666. DragMove();
  667. }
  668. }
  669. private void btnDown_Click(object sender, RoutedEventArgs e)
  670. {
  671. if (thread != null)
  672. {
  673. thread.Abort();
  674. }
  675. APP.myloading.Hide();
  676. Close();
  677. //ToolbarWindow.IsOpenUserCenterWindow = false;
  678. }
  679. public void downloadBegin(int position)
  680. {
  681. isDownloadStatus = true;
  682. if (position >= 9999)
  683. {
  684. tip_outer.Visibility = Visibility.Visible;
  685. }
  686. }
  687. public void downloadProgress(int position, int progress)
  688. {
  689. if (position >= 9999)
  690. {
  691. pgbProcess.Value = progress * 100 / 100;
  692. lbProcess.Content = string.Format("{0}% / {1}%", progress, 100);
  693. }
  694. }
  695. public void downloadEnd(int position, string filepath)
  696. {
  697. isDownloadStatus = false;
  698. thread = null;
  699. if (pageData.menuList.Count > 0)
  700. {
  701. //if (APP.outputInforLog)
  702. //{
  703. // LogHelper.WriteInfoLog("UserCenterWindow(downloadEnd 下载完成)" + filepath);
  704. //}
  705. if (position < 9999)
  706. {
  707. if (pageData.menuList.Count < position)
  708. {
  709. pageData.menuList[position].Pic = filepath;
  710. }
  711. }
  712. else if (filepath.Contains(pageData.menuList[position - 9999].ResourceName))
  713. {
  714. pageData.menuList[position - 9999].VisDownload = "Collapsed";
  715. pageData.menuList[position - 9999].VisButton = "Visible";
  716. tip_outer.Visibility = Visibility.Hidden;
  717. try
  718. {
  719. ProcessStartInfo psi = new ProcessStartInfo(filepath);
  720. Process pro = new Process
  721. {
  722. StartInfo = psi
  723. };
  724. pro.Start();
  725. }
  726. catch (Exception ex)
  727. {
  728. LogHelper.WriteErrLog("UserCenterWindow【downloadEnd】" + ex.Message, ex);
  729. MessageWindow.Show(ex.Message);
  730. return;
  731. }
  732. }
  733. else
  734. {
  735. tip_outer.Visibility = Visibility.Hidden;
  736. try
  737. {
  738. ProcessStartInfo psi = new ProcessStartInfo(filepath);
  739. Process pro = new Process
  740. {
  741. StartInfo = psi
  742. };
  743. pro.Start();
  744. }
  745. catch (Exception ex)
  746. {
  747. LogHelper.WriteErrLog("UserCenterWindow【downloadEnd】" + ex.Message, ex);
  748. MessageWindow.Show(ex.Message);
  749. return;
  750. }
  751. }
  752. }
  753. else
  754. {
  755. tip_outer.Visibility = Visibility.Hidden;
  756. try
  757. {
  758. ProcessStartInfo psi = new ProcessStartInfo(filepath);
  759. Process pro = new Process
  760. {
  761. StartInfo = psi
  762. };
  763. pro.Start();
  764. }
  765. catch (Exception ex)
  766. {
  767. LogHelper.WriteErrLog("UserCenterWindow【downloadEnd】" + ex.Message, ex);
  768. MessageWindow.Show(ex.Message);
  769. return;
  770. }
  771. }
  772. }
  773. public void downloadError(int position, string msg)
  774. {
  775. Dispatcher.Invoke(new Action(() =>
  776. {
  777. tip_outer.Visibility = Visibility.Collapsed;
  778. }));
  779. isDownloadStatus = false;
  780. if (!msg.Equals("远程服务器返回错误: (404) 未找到。") && !msg.Equals("正在中止线程。"))
  781. {
  782. MessageWindow.Show(msg);
  783. }
  784. }
  785. public class ButtonBrush
  786. {
  787. public static readonly DependencyProperty ButtonPressBackgroundProperty = DependencyProperty.RegisterAttached(
  788. "ButtonPressBackground", typeof(Brush), typeof(ButtonBrush), new PropertyMetadata(default(Brush)));
  789. public static void SetButtonPressBackground(DependencyObject element, Brush value)
  790. {
  791. element.SetValue(ButtonPressBackgroundProperty, value);
  792. }
  793. public static Brush GetButtonPressBackground(DependencyObject element)
  794. {
  795. return (Brush)element.GetValue(ButtonPressBackgroundProperty);
  796. }
  797. }
  798. }
  799. public class ToolbarMenuTwo : NotifyModel
  800. {
  801. internal string _resourceName;
  802. public string ResourceName
  803. {
  804. get => _resourceName;
  805. set { _resourceName = value; OnPropertyChanged("ResourceName"); }
  806. }
  807. internal string _times;
  808. public string Times
  809. {
  810. get => _times;
  811. set { _times = value; OnPropertyChanged("Times"); }
  812. }
  813. internal string _Pic;
  814. public string Pic
  815. {
  816. get => _Pic;
  817. set { _Pic = value; OnPropertyChanged("Pic"); }
  818. }
  819. /// <summary>
  820. /// 视频时长秒
  821. /// </summary>
  822. public string Duration { get; set; }
  823. /// <summary>
  824. /// 视频时长是否显示
  825. /// </summary>
  826. public string VisDuration { get; set; }
  827. /// <summary>
  828. /// 文件大小
  829. /// </summary>
  830. public string Resourcesize { get; set; }
  831. internal string _VisButton;
  832. /// <summary>
  833. /// 打开按钮是否显示
  834. /// </summary>
  835. public string VisButton
  836. {
  837. get => _VisButton;
  838. set { _VisButton = value; OnPropertyChanged("VisButton"); }
  839. }
  840. internal string _VisDownload;
  841. /// <summary>
  842. /// 下载按钮是否显示
  843. /// </summary>
  844. public string VisDownload
  845. {
  846. get => _VisDownload;
  847. set { _VisDownload = value; OnPropertyChanged("VisDownload"); }
  848. }
  849. internal int _Resourceid;
  850. /// <summary>
  851. /// 资源id
  852. /// </summary>
  853. public int Resourceid
  854. {
  855. get => _Resourceid;
  856. set { _Resourceid = value; OnPropertyChanged("Resourceid"); }
  857. }
  858. }
  859. public class UserCenterPageData : NotifyModel
  860. {
  861. public ObservableCollection<ComboBoxBeanModel> bookList { get; set; }
  862. public ObservableCollection<ChapterModel> zhangjieList { get; set; }
  863. public ObservableCollection<ToolbarMenuTwo> menuList { get; set; }
  864. public UserCenterPageData()
  865. {
  866. bookList = new ObservableCollection<ComboBoxBeanModel>();
  867. zhangjieList = new ObservableCollection<ChapterModel>();
  868. menuList = new ObservableCollection<ToolbarMenuTwo>();
  869. }
  870. }
  871. public class ChapterModel : NotifyModel
  872. {
  873. public int directorid { get; set; }
  874. public string directorname { get; set; }
  875. public int level { get; set; }
  876. private int _selected;
  877. public int selected
  878. {
  879. get => _selected;
  880. set
  881. {
  882. _selected = value;
  883. OnPropertyChanged("selected");
  884. }
  885. }
  886. }
  887. }