using Common.system; using System; using System.Threading; using System.Collections.ObjectModel; using System.Windows; using System.Windows.Controls; using System.Windows.Input; using XHWK.Model; using XHWK.WKTool.DAL; using static XHWK.WKTool.MainWindow; namespace XHWK.WKTool { /// /// UploadWindow.xaml 的交互逻辑 /// public partial class UploadWindow { /// /// 调用接口 /// private readonly XhApi _xhapi = new XhApi(); /// /// 前台数据 /// internal LoginPageData pageData = new LoginPageData(); /// /// 文件名 /// private string _resourcename = string.Empty; /// /// 文件大小 /// private long _resourcesize; /// /// 文件类型 /// private string _suffix = string.Empty; /// /// 唯一编号 /// private string _guid = string.Empty; //定义事件 public event ChangeTextHandlers ResultEvents; /// /// 当前视频的下标 /// private int _i; private System.Timers.Timer _times; public UploadWindow() { InitializeComponent(); } /// /// 初始化 /// public void Initialize ( string mResourcename, long mResourcesize, string mSuffix, string mGuid, int m ) { _i = m; _resourcename = mResourcename; _resourcesize = mResourcesize; _suffix = mSuffix; _guid = mGuid; TipOuter.Visibility = Visibility.Collapsed; Tsubjectbook(); } /// /// 教材接口调用 /// /// /// private void Tsubjectbook() { int code = _xhapi.TsubjectbookList(); if (code == 0) { for (int i = 0; i < App.TsubjectbookList.Count; i++) { pageData.bookList.Add( new ComboBoxBean() { Key = App.TsubjectbookList[i].Lsbid, //Value = $"{APP.TsubjectbookList[i].Subjectname} {APP.TsubjectbookList[i].Bookname}" Value = $"{App.TsubjectbookList[i].Subjectname} {App.TsubjectbookList[i].Versionname} {App.TsubjectbookList[i].Lsbname}" } ); } BookList.SelectedIndex = 0; DataContext = pageData; if (App.TsubjectbookList.Count > 0) { Director(); ShowDialog(); } else { App.IsUpLoad = false; Hide(); MessageWindow.Show("暂无章节!"); } } else { MessageWindow.Show(App.ServerMsg); } } /// /// 章节接口调用 /// private void Director() { int selectIndex = BookList.SelectedIndex; if (selectIndex < 0) { selectIndex = 0; } if (App.TsubjectbookList.Count > selectIndex) { int code = _xhapi.DirectorList( App.TsubjectbookList[selectIndex].Lsbid, 4, App.UserInfo.Userid ); if (code == 0) { pageData.zhangjieList.Clear(); foreach (ModelDirectorList item in App.DirectorList) { pageData.zhangjieList.Add( new ComboBoxBean() { Key = item.directorid, Value = item.directorname, leaf = item.leaf } ); AddChild(item); } CmbTeachingMaterial.SelectedIndex = 0; } else { MessageWindow.Show(App.ServerMsg); } } } /// /// 子章节递归 /// /// /// private void AddChild(ModelDirectorList directorList) { if (directorList.children != null && directorList.children.Count > 0) { foreach (ModelDirectorList child in directorList.children) { pageData.zhangjieList.Add( new ComboBoxBean() { Key = child.directorid, Value = GetSpace(child.directorlevel) + child.directorname, leaf = child.leaf } ); 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 Window_Loaded(object sender, RoutedEventArgs e) { //Tsubjectbook(); } private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { if (e.LeftButton == MouseButtonState.Pressed) { DragMove(); } } /// /// 教材下拉框改变事件 /// /// /// /// /// private void ToolbarListSelectionChanged(object sender, SelectionChangedEventArgs e) { if (App.TsubjectbookList.Count > 0) { Director(); } else { MessageWindow.Show("暂无章节!"); App.IsUpLoad = false; Hide(); } } private void BtnDown_Click(object sender, RoutedEventArgs e) { App.IsUpLoad = false; Hide(); } /// /// 上传到个人空间 /// /// /// /// /// private void BtnStart_Click(object sender, RoutedEventArgs e) { if (string.IsNullOrWhiteSpace(BookList.Text)) { MessageWindow.Show("请选择教材!"); return; } if (CmbTeachingMaterial.SelectedIndex < pageData.zhangjieList.Count) { int leaf = pageData.zhangjieList[CmbTeachingMaterial.SelectedIndex].leaf; if (leaf != 1) { MessageWindow.Show("只能选择小节或全部进行上传!"); return; } } BtnStart.IsEnabled = false; BookList.IsEnabled = false; CmbTeachingMaterial.IsEnabled = false; Thread myThread = new Thread(StartUpload); _num = 0; TipOuter.Visibility = Visibility.Visible; myThread.Start(); _times = new System.Timers.Timer(100); _times.Elapsed += Times_ElapsedClick; _times.Start(); } private void StartUpload() { try { DalUpload dAlUpload = new DalUpload(); if (dAlUpload.UploadVideoTwo(_guid, out string errMessage)) { // converted: 0 //createid: 80 //directorid: 1009 //duration: 39 //imgUrl: "" //level: 2 //lsbid: 40 //mp4code: "h264" //resourcebelong: 3 //resourceclass: 2 //resourcecover: "12/resource/20200917/4f297df0-f8c0-11ea-adf5-81f24b97d4ff/weather_pic.jpg" //resourcename: "weather_pic" //resourcesize: 6105268 //resourcetype: 0 //resourceurl: "12/resource/20200917/4f297df0-f8c0-11ea-adf5-81f24b97d4ff/weather_pic.mp4" //schoolid: 12 //suffix: "mp4" //uid: 80 ModelResourceAdd modelResourceAdd = new ModelResourceAdd(); Dispatcher.Invoke( () => { modelResourceAdd = new ModelResourceAdd { converted = 0, createid = App.UserInfo.Userid, directorid = CmbTeachingMaterial.SelectedValue.ToString(), duration = App.ResourceAddTwo.duration, subjectid = App.TsubjectbookList[BookList.SelectedIndex].Subjectid, imgUrl = "", level = 2, lsbid = BookList.SelectedValue.ToString(), mp4code = App.ResourceAddTwo.mp4code, resourcebelong = 3, resourceclass = 5, resourcecover = App.ResourceAddTwo.coverpath, resourcename = _resourcename, resourcesize = _resourcesize, resourcetype = 10, resourceurl = App.ResourceAddTwo.videopath, schoolid = App.UserInfo.Schoolid }; } ); if (_suffix.Equals("FLV")) { _suffix = "flv"; } else if (_suffix.Equals("AVI")) { _suffix = "avi"; } else { _suffix = "mp4"; } modelResourceAdd.suffix = _suffix; //model_ResourceAdd.uid = 0;//zxy int code = _xhapi.ResourceAdd(modelResourceAdd); if (code == 0) { Dispatcher.Invoke( () => { foreach (ModelWkData vdata in App.WKDataList) { if (vdata.VideoList == null) { continue; } foreach (ModelVideo videoinfo in vdata.VideoList) { if (videoinfo.FileGuid == _guid) { videoinfo.IsUpload = true; break; } } } BtnStart.IsEnabled = true; BookList.IsEnabled = true; CmbTeachingMaterial.IsEnabled = true; _num = 99; _times.Stop(); PgbProcess.Value = 100; LbProcess.Content = "100%"; Hide(); TipOuter.Visibility = Visibility.Collapsed; MessageWindow.Show("视频上传成功!"); if (ResultEvents != null) { ResultEvents("上传成功", _i); } } ); } else { Dispatcher.Invoke( () => { BtnStart.IsEnabled = true; BookList.IsEnabled = true; CmbTeachingMaterial.IsEnabled = true; _times.Stop(); TipOuter.Visibility = Visibility.Collapsed; MessageWindow.Show(App.ServerMsg); } ); } } else { Dispatcher.Invoke( () => { BtnStart.IsEnabled = true; BookList.IsEnabled = true; CmbTeachingMaterial.IsEnabled = true; _times.Stop(); TipOuter.Visibility = Visibility.Collapsed; MessageWindow.Show(errMessage); } ); } } catch (Exception ex) { Dispatcher.Invoke( () => { BtnStart.IsEnabled = true; BookList.IsEnabled = true; CmbTeachingMaterial.IsEnabled = true; _times.Stop(); TipOuter.Visibility = Visibility.Collapsed; MessageWindow.Show("无法上传视频,请检查与服务器链接状态!"); App.IsUpLoad = false; Hide(); LogHelper.Logerror.Error("【UploadWindow】(BtnStart_Click)" + ex.Message, ex); } ); } } private int _num; /// /// 计时器 /// /// /// /// /// private void Times_ElapsedClick(object sender, System.Timers.ElapsedEventArgs e) { Dispatcher.Invoke( () => { PgbProcess.Value = _num; LbProcess.Content = _num + "%"; if (_num < 99) { _num++; // ReSharper disable once PossibleLossOfFraction _times.Interval += _num / 2; } else { _times.Stop(); } } ); } } public class LoginPageData : NotifyModel { public ObservableCollection bookList { get; set; } public ObservableCollection zhangjieList { get; set; } public LoginPageData() { bookList = new ObservableCollection(); zhangjieList = new ObservableCollection(); } } }