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 ChangeTextEvents; /// /// 当前视频的下标 /// private int _i; private System.Timers.Timer _times; public UploadWindow() { InitializeComponent(); } /// /// 初始化 /// public void Initialize ( string mResourcename, long mResourcesize, string mSuffix, string mGuid, int m ) { this._i = m; this._resourcename = mResourcename; this._resourcesize = mResourcesize; this._suffix = mSuffix; this._guid = mGuid; tip_outer.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}" } ); } book_list.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 = book_list.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(); pageData.zhangjieList.Add ( new ComboBoxBean() { Key = "0", Value = "全部", leaf = 1 } ); for (int i = 0; i < App.DirectorList.Count; i++) { ModelDirectorList item = App.DirectorList[i]; 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(book_list.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; book_list.IsEnabled = false; cmbTeachingMaterial.IsEnabled = false; Thread myThread = new Thread(StartUpload); _num = 0; tip_outer.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[book_list.SelectedIndex].Subjectid, imgUrl = "", level = 2, lsbid = book_list.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; book_list.IsEnabled = true; cmbTeachingMaterial.IsEnabled = true; _num = 99; _times.Stop(); pgbProcess.Value = 100; lbProcess.Content = "100%"; Hide(); tip_outer.Visibility = Visibility.Collapsed; MessageWindow.Show("视频上传成功!"); if (ChangeTextEvents != null) { ChangeTextEvents("上传成功", _i); } } ); } else { Dispatcher.Invoke ( () => { btnStart.IsEnabled = true; book_list.IsEnabled = true; cmbTeachingMaterial.IsEnabled = true; _times.Stop(); tip_outer.Visibility = Visibility.Collapsed; MessageWindow.Show(App.ServerMsg); } ); } } else { Dispatcher.Invoke ( () => { btnStart.IsEnabled = true; book_list.IsEnabled = true; cmbTeachingMaterial.IsEnabled = true; _times.Stop(); tip_outer.Visibility = Visibility.Collapsed; MessageWindow.Show(errMessage); } ); } } catch (Exception ex) { Dispatcher.Invoke(() => { btnStart.IsEnabled = true; book_list.IsEnabled = true; cmbTeachingMaterial.IsEnabled = true; _times.Stop(); tip_outer.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(); } } }