星火直播PC
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

UserCenterWindow.xaml.cs 38KB

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