12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016 |
- using Common.system;
- using System;
- using System.Collections.ObjectModel;
- using System.ComponentModel;
- using System.Data;
- using System.Diagnostics;
- using System.IO;
- using System.Threading;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Input;
- using System.Windows.Media;
- using XHZB.Desktop.Utils;
- using XHZB.Model;
-
- namespace XHZB.Desktop
- {
- /// <summary>
- /// 个人空间
- /// </summary>
- public partial class UserCenterWindow : Window, DownloadUtil.DownloadCallback
- {
- #region 字段
- /// <summary>
- /// 接口返回 0 成功 1 失败
- /// </summary>
- private int serverReturnCode = 0;
- /// <summary>
- /// 接口调用
- /// </summary>
- private readonly RegisterController registerController = new RegisterController();
- /// <summary>
- /// 数据源
- /// </summary>
- internal UserCenterPageData pageData = new UserCenterPageData();
- private bool isInitial = false;
- private Thread thread;
- private bool initialization = true;
- /// <summary>
- /// 下拉框数据源
- /// </summary>
- public DataTable data = new DataTable();
- /// <summary>
- /// 是否是下载状态 默认false 不是
- /// </summary>
- private bool isDownloadStatus = false;
- /// <summary>
- /// 教材关系表id
- /// </summary>
- private int Lsbid = 0;
- /// <summary>
- /// 章节id
- /// </summary>
- private int Directorid = 0;
- /// <summary>
- /// 资源分类1音频2视频3图片4文档
- /// </summary>
- private int Resourceclass = 0;
- #endregion
-
- #region 初始化
- /// <summary>
- /// 个人空间
- /// </summary>
- public UserCenterWindow()
- {
- InitializeComponent();
- DataContext = pageData;
- //初始化配置文件
- //ZJConfigUtil.init();
- isInitial = true;
- Resourceclass = 0;
- Lsbid = 0;
- Directorid = 0;
- borAll.Background = new SolidColorBrush(Colors.DodgerBlue);
- borAudio.Background = new SolidColorBrush(Colors.Transparent);
- borVideo.Background = new SolidColorBrush(Colors.Transparent);
- borImage.Background = new SolidColorBrush(Colors.Transparent);
- borDoc.Background = new SolidColorBrush(Colors.Transparent);
- btnAll.Foreground = new SolidColorBrush(Colors.White);
- btnAudio.Foreground = new SolidColorBrush(Colors.Black);
- btnVideo.Foreground = new SolidColorBrush(Colors.Black);
- btnImage.Foreground = new SolidColorBrush(Colors.Black);
- btnDoc.Foreground = new SolidColorBrush(Colors.Black);
- new Thread(o =>
- {
- InvokeTsubjectbookListServering();
- Dispatcher.Invoke(new Action(() =>
- {
- InvokeServerTsubjectbookListCompate();
- }));
-
- }).Start();
- }
- #endregion
-
- #region 方法
- /// <summary>
- /// 刷新
- /// </summary>
- private void Refresh()
- {
- pageData.menuList.Clear();
- }
- /// <summary>
- /// 教师教材列表服务-调用
- /// </summary>
- /// <returns></returns>
- private object InvokeTsubjectbookListServering()
- {
- serverReturnCode = registerController.TsubjectbookList();
- return APP.ErrorMessage;
- }
- /// <summary>
- /// 教师教材列表服务-返回结果
- /// </summary>
- /// <returns></returns>
- public void InvokeServerTsubjectbookListCompate()
- {
- if (serverReturnCode == APP.ServerScuessCode)
- {
- initJiaocai();
- }
- else
- {
- MessageWindow.Show(APP.ErrorMessage);
- }
- }
- private void initJiaocai()
- {
- System.Collections.Generic.List<TsubjectbookListModel> list = APP.TsubjectbookList;
- int selectIndex = 0;
- for (int i = 0; i < list.Count; i++)
- {
- TsubjectbookListModel book = list[i];
- if (book.lsbid == APP.lsbid)
- {
- selectIndex = i;
- }
- pageData.bookList.Add(new ComboBoxBeanModel()
- {
- Key = book.lsbid,
- Value = $"{book.subjectname} {book.bookname}"
- });
- }
- cmbClass.SelectedIndex = selectIndex;
- }
- /// <summary>
- /// 章节列表服务-调用
- /// </summary>
- /// <returns></returns>
- private object InvokeDirectorListServering()
- {
- APP.DirectorList = null;
- serverReturnCode = registerController.DirectorList(Lsbid, 2, APP.LoginUser.userid);
- return APP.ErrorMessage;
- }
-
- /// <summary>
- /// 章节列表服务-返回结果
- /// </summary>
- /// <returns></returns>
- public void InvokeServerDirectorListCompate(object obj)
- {
- if (serverReturnCode == APP.ServerScuessCode)
- {
- if (!isInitial)
- {
- Directorid = 0;
- isInitial = false;
- }
- pageData.zhangjieList.Clear();
-
- pageData.zhangjieList.Add(new ChapterModel()
- {
- directorid = 0,
- directorname = "全部",
- level = 1,
- selected = 0
- });
- System.Collections.Generic.List<DirectorListModel> list = APP.DirectorList;
-
- for (int i = 0; i < list.Count; i++)
- {
- DirectorListModel item = APP.DirectorList[i];
-
- pageData.zhangjieList.Add(new ChapterModel()
- {
- directorid = item.directorid,
- directorname = item.directorname,
- level = item.directorlevel,
- selected = 0
- });
- addChild(item);
- }
- foreach (ChapterModel zhangjie in pageData.zhangjieList)
- {
- if (Directorid == zhangjie.directorid)
- {
- zhangjie.selected = 1;
- }
- else
- {
- zhangjie.selected = 0;
- }
- }
- APP.BackgroundWorkerHelper.RunWorkerAsync(InvokeResourceMyListServering, InvokeServerResourceMyListCompate);
- }
- else
- {
- MessageWindow.Show(APP.ErrorMessage);
- }
- }
-
- private void addChild(DirectorListModel directorList)
- {
- if (directorList.children != null && directorList.children.Count > 0)
- {
- foreach (DirectorListModel child in directorList.children)
- {
- pageData.zhangjieList.Add(new ChapterModel()
- {
- directorid = child.directorid,
- directorname = getSpace(child.directorlevel) + child.directorname
- });
- if (child.children != null && child.children.Count > 0)
- {
- addChild(child);
- }
- }
- }
- }
- private string getSpace(int num)
- {
- string str = "";
- for (int i = 0; i < num; i++)
- {
- str += " ";
- }
- return str;
- }
- private void zhangjieClick(object sender, RoutedEventArgs e)
- {
- ChapterModel item = ((Button)sender).Tag as ChapterModel;
- foreach (ChapterModel zhangjie in pageData.zhangjieList)
- {
- if (item.directorid == zhangjie.directorid)
- {
- zhangjie.selected = 1;
- }
- else
- {
- zhangjie.selected = 0;
- }
- }
-
- Directorid = item.directorid;
- APP.BackgroundWorkerHelper.RunWorkerAsync(InvokeResourceMyListServering, InvokeServerResourceMyListCompate);
- }
- /// <summary>
- /// 我的备课列表服务-调用
- /// </summary>
- /// <returns></returns>
- private object InvokeResourceMyListServering()
- {
- Dispatcher.Invoke(new Action(() =>
- {
- APP.myloading.Show();
- }));
-
- APP.ResourceMyList = null;
- serverReturnCode = registerController.ResourceMyList(Lsbid, Directorid, Resourceclass);
- return APP.ErrorMessage;
- }
-
- /// <summary>
- /// 我的备课列表服务-返回结果
- /// </summary>
- /// <returns></returns>
- public void InvokeServerResourceMyListCompate(object obj)
- {
- Dispatcher.Invoke(new Action(() =>
- {
- APP.myloading.Hide();
- }));
-
- if (serverReturnCode == APP.ServerScuessCode)
- {
- if (pageData.menuList.Count > 0)
- {
- pageData.menuList.Clear();
- DataContext = pageData;
- }
-
- if (APP.ResourceMyList.obj != null)
- {
- System.Collections.Generic.List<string> resource = new System.Collections.Generic.List<string>();
- for (int i = 0; i < APP.ResourceMyList.obj.Count; i++)
- {
- string imgSuffix = string.Empty;
- string visDuration = "Collapsed";
- string visButton = "Collapsed";
- string visDownload = "Visible";
- System.DateTime dateTime = new System.DateTime(1970, 1, 1, 0, 0, 0, 0);
- dateTime = dateTime.AddSeconds(APP.ResourceMyList.obj[i].createtime).ToLocalTime();
- if ("doc".Equals(APP.ResourceMyList.obj[i].suffix)
- || "docx".Equals(APP.ResourceMyList.obj[i].suffix))
- {
- imgSuffix = "./Images/Resource/DOC.png";
- }
- else if ("ppt".Equals(APP.ResourceMyList.obj[i].suffix)
- || "pptx".Equals(APP.ResourceMyList.obj[i].suffix))
- {
- imgSuffix = "./Images/Resource/PPT.png";
- }
- else if ("pdf".Equals(APP.ResourceMyList.obj[i].suffix))
- {
- imgSuffix = "./Images/Resource/PDF.png";
- }
- else if ("excel".Equals(APP.ResourceMyList.obj[i].suffix)
- || "xls".Equals(APP.ResourceMyList.obj[i].suffix) || "xlsx".Equals(APP.ResourceMyList.obj[i].suffix))
- {
- imgSuffix = "./Images/Resource/EXCEL.png";
- }
- else if ("class".Equals(APP.ResourceMyList.obj[i].suffix))
- {
- imgSuffix = "../Images/Resource/CLASS.png";
- }
- else if ("dsc".Equals(APP.ResourceMyList.obj[i].suffix))
- {
- imgSuffix = "./Images/Resource/DSC.png";
- }
- else if ("mp3".Equals(APP.ResourceMyList.obj[i].suffix))
- {
- visDuration = "Visible";
- imgSuffix = "./Images/Resource/MP3.png";
- }
- else if ("mp4".Equals(APP.ResourceMyList.obj[i].suffix)
- || "flv".Equals(APP.ResourceMyList.obj[i].suffix))
- {
- visDuration = "Visible";
- if (APP.ResourceMyList.obj[i].resourcecover != null)
- {
- imgSuffix = APP.showImageUrl + APP.ResourceMyList.obj[i].resourcecover.ToString();
- }
- else
- {
- imgSuffix = "./Images/Resource/MP4.png";
- }
- }
- else if ("png".Equals(APP.ResourceMyList.obj[i].suffix)
- || "jpg".Equals(APP.ResourceMyList.obj[i].suffix)
- || "jpeg".Equals(APP.ResourceMyList.obj[i].suffix))
- {
- imgSuffix = "./Images/Resource/PNG.png";
- }
- else if ("txt".Equals(APP.ResourceMyList.obj[i].suffix))
- {
- imgSuffix = "./Images/Resource/TXT.png";
- }
- else if ("txt".Equals(APP.ResourceMyList.obj[i].suffix))
- {
- imgSuffix = "./Images/Resource/FLV.png";
- }
- else if ("wav".Equals(APP.ResourceMyList.obj[i].suffix))
- {
- imgSuffix = "./Images/Resource/WAV.png";
- }
- string resourcesSuffix = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\" + APP.LoginUser.username + "\\" + APP.ResourceMyList.obj[i].resourcename + "." + APP.ResourceMyList.obj[i].suffix;
- if (!string.IsNullOrWhiteSpace(APP.fileStorageAddress))
- {
- resourcesSuffix = APP.fileStorageAddress + "\\" + APP.ResourceMyList.obj[i].resourcename + "." + APP.ResourceMyList.obj[i].suffix;
- }
- if (File.Exists(resourcesSuffix))//检查资源是否已经存在
- {
- visButton = "Visible";
- visDownload = "Collapsed";
- }
- string resourcesize;
- if (APP.ResourceMyList.obj[i].resourcesize > 1024)
- {
- if (APP.ResourceMyList.obj[i].resourcesize / 1024 > 1024)
- {
- resourcesize = (APP.ResourceMyList.obj[i].resourcesize / 1024 / 1024).ToString() + "MB";
- }
- else
- {
- resourcesize = (APP.ResourceMyList.obj[i].resourcesize / 1024).ToString() + "KB";
- }
- }
- else
- {
- resourcesize = (APP.ResourceMyList.obj[i].resourcesize).ToString() + "B";
- }
- string duration = string.Empty;
- if (APP.ResourceMyList.obj[i].duration > 59)
- {
- if (APP.ResourceMyList.obj[i].duration > 3599)
- {
- if (APP.ResourceMyList.obj[i].duration % 3600 == 0)
- {
- duration = (APP.ResourceMyList.obj[i].duration / 3600).ToString() + "时";
- }
- else
- {
- duration = (APP.ResourceMyList.obj[i].duration / 3600).ToString() + "时" + (APP.ResourceMyList.obj[i].duration % 3600).ToString() + "分";
- }
- }
- else
- {
- if (APP.ResourceMyList.obj[i].duration % 60 == 0)
- {
- duration = (APP.ResourceMyList.obj[i].duration / 60).ToString() + "分";
- }
- else
- {
- duration = (APP.ResourceMyList.obj[i].duration / 60).ToString() + "分" + (APP.ResourceMyList.obj[i].duration % 60).ToString() + "秒";
- }
- }
- }
- else
- {
- duration = APP.ResourceMyList.obj[i].duration.ToString() + "秒";
- }
- pageData.menuList.Add(new ToolbarMenuTwo()
- {
- Resourcesize = resourcesize,
- ResourceName = APP.ResourceMyList.obj[i].resourcename,
- Times = dateTime.ToString("yyy-MM-dd HH:mm:ss"),
- Pic = imgSuffix,
- VisDuration = visDuration,
- Duration = duration,
- VisButton = visButton,
- VisDownload = visDownload,
- Resourceid = APP.ResourceMyList.obj[i].resourceid
- });
- }
- }
- DataContext = pageData;
- }
- else
- {
- MessageWindow.Show(APP.ErrorMessage);
- }
- }
- private void DownLoadTwo(string httpurls, int position, string savepath)
- {
- thread = DownloadUtil.downloadFileWithCallback(
- httpurls,
- position,
- savepath,
- Dispatcher,
- this
- );
- }
- #endregion
-
- #region 事件
- /// <summary>
- /// 下载
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnDownload_Click(object sender, RoutedEventArgs e)
- {
- if (!isDownloadStatus)
- {
- int clickindex = 0;
- Button btn = (Button)sender;
- for (int i = 0; i < APP.ResourceMyList.obj.Count; i++)
- {
-
- if (APP.ResourceMyList.obj[i].resourceid == Convert.ToInt32(btn.Tag))
- {
- clickindex = i;
- break;
- }
- }
- string fileAddress = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\" + APP.LoginUser.username + "\\" + APP.ResourceMyList.obj[clickindex].resourcename + "." + APP.ResourceMyList.obj[clickindex].suffix;
- if (!string.IsNullOrWhiteSpace(APP.fileStorageAddress))
- {
- fileAddress = APP.fileStorageAddress + "\\" + APP.ResourceMyList.obj[clickindex].resourcename + "." + APP.ResourceMyList.obj[clickindex].suffix;
- }
- //if (APP.outputInforLog)
- //{
- // LogHelper.WriteInfoLog("UserCenterWindow(btnDownload_Click 下载)" + fileAddress);
- //}
- if (Directory.Exists(fileAddress))//存在就打开 不存在就下载
- {
- ProcessStartInfo psi = new ProcessStartInfo(fileAddress);
- Process pro = new Process
- {
- StartInfo = psi
- };
- pro.Start();
- }
- else
- {
- if (!string.IsNullOrWhiteSpace(APP.fileStorageAddress))
- {
- fileAddress = APP.fileStorageAddress;
- }
- if (!Directory.Exists(fileAddress))
- {
- Directory.CreateDirectory(fileAddress);
- }
- string userHeadPic = APP.showImageUrl + APP.ResourceMyList.obj[clickindex].resourceurl.ToString();
- DownLoadTwo(userHeadPic, 9999 + clickindex, fileAddress + "\\");
- }
- }
- }
- /// <summary>
- /// 打开
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnTurnOn_Click(object sender, RoutedEventArgs e)
- {
- if (!isDownloadStatus)
- {
- int clickindex = 0;
- Button btn = (Button)sender;
- for (int i = 0; i < APP.ResourceMyList.obj.Count; i++)
- {
-
- if (APP.ResourceMyList.obj[i].resourceid == Convert.ToInt32(btn.Tag))
- {
- clickindex = i;
- break;
- }
- }
-
- string fileAddress = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\" + APP.LoginUser.username + "\\" + APP.ResourceMyList.obj[clickindex].resourcename + "." + APP.ResourceMyList.obj[clickindex].suffix;
- if (!string.IsNullOrWhiteSpace(APP.fileStorageAddress))
- {
- fileAddress = APP.fileStorageAddress + "\\" + APP.ResourceMyList.obj[clickindex].resourcename + "." + APP.ResourceMyList.obj[clickindex].suffix;
- }
- //if (APP.outputInforLog)
- //{
- // LogHelper.WriteInfoLog("UserCenterWindow(btnTurnOn_Click 打开)" + fileAddress);
- //}
- if (Directory.Exists(fileAddress))//存在就打开 不存在就下载
- {
- try
- {
- ProcessStartInfo psi = new ProcessStartInfo(fileAddress);
- Process pro = new Process
- {
- StartInfo = psi
- };
- pro.Start();
- }
- catch (Exception ex)
- {
- LogHelper.WriteErrLog("UserCenterWindow【btnTurnOn_Click】" + ex.Message, ex);
- MessageWindow.Show(ex.Message);
- return;
- }
- }
- else
- {
- if (!string.IsNullOrWhiteSpace(APP.fileStorageAddress))
- {
- fileAddress = APP.fileStorageAddress;
- }
- if (!Directory.Exists(fileAddress))
- {
- Directory.CreateDirectory(fileAddress);
- }
- string userHeadPic = APP.showImageUrl + APP.ResourceMyList.obj[clickindex].resourceurl.ToString();
- DownLoadTwo(userHeadPic, 9999 + clickindex, fileAddress + "\\");
- }
- }
- }
- /// <summary>
- /// 全部
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnAll_Click(object sender, RoutedEventArgs e)
- {
- pageData.menuList.Clear();
- DataContext = pageData;
- Resourceclass = 0;
- borAll.Background = new SolidColorBrush(Colors.DodgerBlue);
- borAudio.Background = new SolidColorBrush(Colors.Transparent);
- borVideo.Background = new SolidColorBrush(Colors.Transparent);
- borImage.Background = new SolidColorBrush(Colors.Transparent);
- borDoc.Background = new SolidColorBrush(Colors.Transparent);
- btnAll.Foreground = new SolidColorBrush(Colors.White);
- btnAudio.Foreground = new SolidColorBrush(Colors.Black);
- btnVideo.Foreground = new SolidColorBrush(Colors.Black);
- btnImage.Foreground = new SolidColorBrush(Colors.Black);
- btnDoc.Foreground = new SolidColorBrush(Colors.Black);
- APP.BackgroundWorkerHelper.RunWorkerAsync(InvokeResourceMyListServering, InvokeServerResourceMyListCompate);
- }
- /// <summary>
- /// 窗口关闭
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void Window_Closing(object sender, CancelEventArgs e)
- {
- if (pageData.menuList.Count > 0)
- {
- pageData.menuList.Clear();
- DataContext = null;
- }
- }
- /// <summary>
- /// 音频
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnAudio_Click(object sender, RoutedEventArgs e)
- {
- pageData.menuList.Clear();
- DataContext = pageData;
- Resourceclass = 1;
- borAll.Background = new SolidColorBrush(Colors.Transparent);
- borAudio.Background = new SolidColorBrush(Colors.DodgerBlue);
- borVideo.Background = new SolidColorBrush(Colors.Transparent);
- borImage.Background = new SolidColorBrush(Colors.Transparent);
- borDoc.Background = new SolidColorBrush(Colors.Transparent);
- btnAll.Foreground = new SolidColorBrush(Colors.Black);
- btnAudio.Foreground = new SolidColorBrush(Colors.White);
- btnVideo.Foreground = new SolidColorBrush(Colors.Black);
- btnImage.Foreground = new SolidColorBrush(Colors.Black);
- btnDoc.Foreground = new SolidColorBrush(Colors.Black);
- APP.BackgroundWorkerHelper.RunWorkerAsync(InvokeResourceMyListServering, InvokeServerResourceMyListCompate);
- }
- /// <summary>
- /// 视频
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnVideo_Click(object sender, RoutedEventArgs e)
- {
- pageData.menuList.Clear();
- DataContext = pageData;
- Resourceclass = 2;
- borAll.Background = new SolidColorBrush(Colors.Transparent);
- borAudio.Background = new SolidColorBrush(Colors.Transparent);
- borVideo.Background = new SolidColorBrush(Colors.DodgerBlue);
- borImage.Background = new SolidColorBrush(Colors.Transparent);
- borDoc.Background = new SolidColorBrush(Colors.Transparent);
- btnAll.Foreground = new SolidColorBrush(Colors.Black);
- btnAudio.Foreground = new SolidColorBrush(Colors.Black);
- btnVideo.Foreground = new SolidColorBrush(Colors.White);
- btnImage.Foreground = new SolidColorBrush(Colors.Black);
- btnDoc.Foreground = new SolidColorBrush(Colors.Black);
- APP.BackgroundWorkerHelper.RunWorkerAsync(InvokeResourceMyListServering, InvokeServerResourceMyListCompate);
- }
- /// <summary>
- /// 图片
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnImage_Click(object sender, RoutedEventArgs e)
- {
- pageData.menuList.Clear();
- DataContext = pageData;
- Resourceclass = 3;
- borAll.Background = new SolidColorBrush(Colors.Transparent);
- borAudio.Background = new SolidColorBrush(Colors.Transparent);
- borVideo.Background = new SolidColorBrush(Colors.Transparent);
- borImage.Background = new SolidColorBrush(Colors.DodgerBlue);
- borDoc.Background = new SolidColorBrush(Colors.Transparent);
- btnAll.Foreground = new SolidColorBrush(Colors.Black);
- btnAudio.Foreground = new SolidColorBrush(Colors.Black);
- btnVideo.Foreground = new SolidColorBrush(Colors.Black);
- btnImage.Foreground = new SolidColorBrush(Colors.White);
- btnDoc.Foreground = new SolidColorBrush(Colors.Black);
- APP.BackgroundWorkerHelper.RunWorkerAsync(InvokeResourceMyListServering, InvokeServerResourceMyListCompate);
- }
- /// <summary>
- /// 文档
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnDoc_Click(object sender, RoutedEventArgs e)
- {
- pageData.menuList.Clear();
- DataContext = pageData;
- Resourceclass = 4;
- borAll.Background = new SolidColorBrush(Colors.Transparent);
- borAudio.Background = new SolidColorBrush(Colors.Transparent);
- borVideo.Background = new SolidColorBrush(Colors.Transparent);
- borImage.Background = new SolidColorBrush(Colors.Transparent);
- borDoc.Background = new SolidColorBrush(Colors.DodgerBlue);
- btnAll.Foreground = new SolidColorBrush(Colors.Black);
- btnAudio.Foreground = new SolidColorBrush(Colors.Black);
- btnVideo.Foreground = new SolidColorBrush(Colors.Black);
- btnImage.Foreground = new SolidColorBrush(Colors.Black);
- btnDoc.Foreground = new SolidColorBrush(Colors.White);
- APP.BackgroundWorkerHelper.RunWorkerAsync(InvokeResourceMyListServering, InvokeServerResourceMyListCompate);
- }
- /// <summary>
- /// 科目教材选择改变事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void cmbClass_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- if (initialization)
- {
- initialization = false;
- }
- else
- {
- Directorid = 0;
- borAll.Background = new SolidColorBrush(Colors.DodgerBlue);
- borAudio.Background = new SolidColorBrush(Colors.Transparent);
- borVideo.Background = new SolidColorBrush(Colors.Transparent);
- borImage.Background = new SolidColorBrush(Colors.Transparent);
- borDoc.Background = new SolidColorBrush(Colors.Transparent);
- btnAll.Foreground = new SolidColorBrush(Colors.White);
- btnAudio.Foreground = new SolidColorBrush(Colors.Black);
- btnVideo.Foreground = new SolidColorBrush(Colors.Black);
- btnImage.Foreground = new SolidColorBrush(Colors.Black);
- btnDoc.Foreground = new SolidColorBrush(Colors.Black);
- }
-
- if (cmbClass.SelectedValue != null)
- {
- Lsbid = Convert.ToInt32(cmbClass.SelectedValue.ToString());
- Refresh();
- APP.BackgroundWorkerHelper.RunWorkerAsync(InvokeDirectorListServering, InvokeServerDirectorListCompate);
- }
- else
- {
- Refresh();
- }
- }
- /// <summary>
- /// 窗口移动事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void Window_MouseMove(object sender, MouseEventArgs e)
- {
- if (e.LeftButton == MouseButtonState.Pressed)
- {
- //执行移动方法
- DragMove();
- }
- }
- /// <summary>
- /// 关闭窗口事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnDown_Click(object sender, RoutedEventArgs e)
- {
- if (thread != null)
- {
- thread.Abort();
- }
- APP.myloading.Hide();
- Close();
- ToolbarWindow.IsOpenUserCenterWindow = false;
- }
- /// <summary>
- /// 下载
- /// </summary>
- /// <param name="position"></param>
- public void downloadBegin(int position)
- {
- isDownloadStatus = true;
- if (position >= 9999)
- {
- tip_outer.Visibility = Visibility.Visible;
- }
- }
- /// <summary>
- /// 下载中
- /// </summary>
- /// <param name="position"></param>
- /// <param name="progress"></param>
- public void downloadProgress(int position, int progress)
- {
- if (position >= 9999)
- {
- pgbProcess.Value = progress * 100 / 100;
- lbProcess.Content = string.Format("{0}% / {1}%", progress, 100);
- }
- }
- /// <summary>
- /// 下载完成
- /// </summary>
- /// <param name="position"></param>
- /// <param name="filepath"></param>
- public void downloadEnd(int position, string filepath)
- {
- isDownloadStatus = false;
- thread = null;
- if (pageData.menuList.Count > 0)
- {
- //if (APP.outputInforLog)
- //{
- // LogHelper.WriteInfoLog("UserCenterWindow(downloadEnd 下载完成)" + filepath);
- //}
- if (position < 9999)
- {
- if (pageData.menuList.Count < position)
- {
- pageData.menuList[position].Pic = filepath;
- }
- }
- else if (filepath.Contains(pageData.menuList[position - 9999].ResourceName))
- {
- pageData.menuList[position - 9999].VisDownload = "Collapsed";
- pageData.menuList[position - 9999].VisButton = "Visible";
- tip_outer.Visibility = Visibility.Hidden;
- try
- {
- ProcessStartInfo psi = new ProcessStartInfo(filepath);
- Process pro = new Process
- {
- StartInfo = psi
- };
- pro.Start();
- }
- catch (Exception ex)
- {
- LogHelper.WriteErrLog("UserCenterWindow【downloadEnd】" + ex.Message, ex);
- MessageWindow.Show(ex.Message);
- return;
- }
- }
- else
- {
- tip_outer.Visibility = Visibility.Hidden;
- try
- {
- ProcessStartInfo psi = new ProcessStartInfo(filepath);
- Process pro = new Process
- {
- StartInfo = psi
- };
- pro.Start();
- }
- catch (Exception ex)
- {
- LogHelper.WriteErrLog("UserCenterWindow【downloadEnd】" + ex.Message, ex);
- MessageWindow.Show(ex.Message);
- return;
- }
- }
- }
- else
- {
- tip_outer.Visibility = Visibility.Hidden;
-
- try
- {
- ProcessStartInfo psi = new ProcessStartInfo(filepath);
- Process pro = new Process
- {
- StartInfo = psi
- };
- pro.Start();
- }
- catch (Exception ex)
- {
- LogHelper.WriteErrLog("UserCenterWindow【downloadEnd】" + ex.Message, ex);
- MessageWindow.Show(ex.Message);
- return;
- }
- }
- }
- /// <summary>
- /// 下载结束
- /// </summary>
- /// <param name="position"></param>
- /// <param name="msg"></param>
- public void downloadError(int position, string msg)
- {
- Dispatcher.Invoke(new Action(() =>
- {
- tip_outer.Visibility = Visibility.Collapsed;
- }));
- isDownloadStatus = false;
- if (!msg.Equals("远程服务器返回错误: (404) 未找到。") && !msg.Equals("正在中止线程。"))
- {
- MessageWindow.Show(msg);
- }
- }
- #endregion
-
- public class ButtonBrush
- {
- public static readonly DependencyProperty ButtonPressBackgroundProperty = DependencyProperty.RegisterAttached(
- "ButtonPressBackground", typeof(Brush), typeof(ButtonBrush), new PropertyMetadata(default(Brush)));
-
- public static void SetButtonPressBackground(DependencyObject element, Brush value)
- {
- element.SetValue(ButtonPressBackgroundProperty, value);
- }
-
- public static Brush GetButtonPressBackground(DependencyObject element)
- {
- return (Brush)element.GetValue(ButtonPressBackgroundProperty);
- }
- }
- }
-
- public class ToolbarMenuTwo : NotifyModel
- {
- internal string _resourceName;
-
- public string ResourceName
- {
- get => _resourceName;
- set { _resourceName = value; OnPropertyChanged("ResourceName"); }
- }
-
- internal string _times;
-
- public string Times
- {
- get => _times;
- set { _times = value; OnPropertyChanged("Times"); }
- }
-
- internal string _Pic;
-
- public string Pic
- {
- get => _Pic;
- set { _Pic = value; OnPropertyChanged("Pic"); }
- }
-
- /// <summary>
- /// 视频时长秒
- /// </summary>
- public string Duration { get; set; }
-
- /// <summary>
- /// 视频时长是否显示
- /// </summary>
- public string VisDuration { get; set; }
-
- /// <summary>
- /// 文件大小
- /// </summary>
- public string Resourcesize { get; set; }
-
- internal string _VisButton;
-
- /// <summary>
- /// 打开按钮是否显示
- /// </summary>
- public string VisButton
- {
- get => _VisButton;
- set { _VisButton = value; OnPropertyChanged("VisButton"); }
- }
-
- internal string _VisDownload;
-
- /// <summary>
- /// 下载按钮是否显示
- /// </summary>
- public string VisDownload
- {
- get => _VisDownload;
- set { _VisDownload = value; OnPropertyChanged("VisDownload"); }
- }
-
- internal int _Resourceid;
-
- /// <summary>
- /// 资源id
- /// </summary>
- public int Resourceid
- {
- get => _Resourceid;
- set { _Resourceid = value; OnPropertyChanged("Resourceid"); }
- }
- }
-
- public class UserCenterPageData : NotifyModel
- {
- public ObservableCollection<ComboBoxBeanModel> bookList { get; set; }
-
- public ObservableCollection<ChapterModel> zhangjieList { get; set; }
- public ObservableCollection<ToolbarMenuTwo> menuList { get; set; }
-
- public UserCenterPageData()
- {
- bookList = new ObservableCollection<ComboBoxBeanModel>();
- zhangjieList = new ObservableCollection<ChapterModel>();
- menuList = new ObservableCollection<ToolbarMenuTwo>();
- }
- }
-
- public class ChapterModel : NotifyModel
- {
- public int directorid { get; set; }
- public string directorname { get; set; }
- public int level { get; set; }
-
- private int _selected;
-
- public int selected
- {
- get => _selected;
- set
- {
- _selected = value;
- OnPropertyChanged("selected");
- }
- }
- }
- }
|