|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500 |
- 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
- {
- /// <summary>
- /// UploadWindow.xaml 的交互逻辑
- /// </summary>
- public partial class UploadWindow
- {
- /// <summary>
- /// 调用接口
- /// </summary>
- private readonly XhApi _xhapi = new XhApi();
-
- /// <summary>
- /// 前台数据
- /// </summary>
- internal LoginPageData pageData = new LoginPageData();
-
- /// <summary>
- /// 文件名
- /// </summary>
- private string _resourcename = string.Empty;
-
- /// <summary>
- /// 文件大小
- /// </summary>
- private long _resourcesize;
-
- /// <summary>
- /// 文件类型
- /// </summary>
- private string _suffix = string.Empty;
-
- /// <summary>
- /// 唯一编号
- /// </summary>
- private string _guid = string.Empty;
-
- //定义事件
- public event ChangeTextHandlers ChangeTextEvents;
-
- /// <summary>
- /// 当前视频的下标
- /// </summary>
- private int _i;
-
- private System.Timers.Timer _times;
-
- public UploadWindow()
- {
- InitializeComponent();
- }
-
- /// <summary>
- /// 初始化
- /// </summary>
- 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();
- }
-
- /// <summary>
- /// 教材接口调用
- /// </summary>
- /// <returns>
- /// </returns>
- 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);
- }
- }
-
- /// <summary>
- /// 章节接口调用
- /// </summary>
- 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++)
- {
- Model_DirectorList 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);
- }
- }
- }
-
- /// <summary>
- /// 子章节递归
- /// </summary>
- /// <param name="directorList">
- /// </param>
- private void AddChild(Model_DirectorList directorList)
- {
- if (directorList.children != null && directorList.children.Count > 0)
- {
- foreach (Model_DirectorList 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);
- }
- }
- }
- }
-
- /// <summary>
- /// 章节是否加空格符
- /// </summary>
- /// <param name="num">
- /// </param>
- /// <returns>
- /// </returns>
- 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();
- }
- }
-
- /// <summary>
- /// 教材下拉框改变事件
- /// </summary>
- /// <param name="sender">
- /// </param>
- /// <param name="e">
- /// </param>
- 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();
- }
-
- /// <summary>
- /// 上传到个人空间
- /// </summary>
- /// <param name="sender">
- /// </param>
- /// <param name="e">
- /// </param>
- 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
- Model_ResourceAdd modelResourceAdd = new Model_ResourceAdd();
- Dispatcher.Invoke
- (
- () =>
- {
- modelResourceAdd = new Model_ResourceAdd
- {
- 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 (Model_WKData vdata in App.WKDataList)
- {
- if (vdata.VideoList == null)
- {
- continue;
- }
- foreach (Model_Video 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.WriteErrLog("【UploadWindow】(BtnStart_Click)" + ex.Message, ex);
- });
- }
- }
-
- private int _num;
-
- /// <summary>
- /// 计时器
- /// </summary>
- /// <param name="sender">
- /// </param>
- /// <param name="e">
- /// </param>
- 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<ComboBoxBean> bookList { get; set; }
-
- public ObservableCollection<ComboBoxBean> zhangjieList { get; set; }
-
- public LoginPageData()
- {
- bookList = new ObservableCollection<ComboBoxBean>();
- zhangjieList = new ObservableCollection<ComboBoxBean>();
- }
- }
- }
|