星火直播PC
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

UserCenterWindow.xaml.cs 39KB

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