星火微课系统客户端
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

UploadWindow.xaml.cs 16KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474
  1. using Common.system;
  2. using System;
  3. using System.Threading;
  4. using System.Collections.ObjectModel;
  5. using System.Windows;
  6. using System.Windows.Controls;
  7. using System.Windows.Input;
  8. using XHWK.Model;
  9. using XHWK.WKTool.DAL;
  10. using static XHWK.WKTool.MainWindow;
  11. namespace XHWK.WKTool
  12. {
  13. /// <summary>
  14. /// UploadWindow.xaml 的交互逻辑
  15. /// </summary>
  16. public partial class UploadWindow
  17. {
  18. /// <summary>
  19. /// 调用接口
  20. /// </summary>
  21. private readonly XhApi _xhapi = new XhApi();
  22. /// <summary>
  23. /// 前台数据
  24. /// </summary>
  25. internal LoginPageData pageData = new LoginPageData();
  26. /// <summary>
  27. /// 文件名
  28. /// </summary>
  29. private string _resourcename = string.Empty;
  30. /// <summary>
  31. /// 文件大小
  32. /// </summary>
  33. private long _resourcesize;
  34. /// <summary>
  35. /// 文件类型
  36. /// </summary>
  37. private string _suffix = string.Empty;
  38. /// <summary>
  39. /// 唯一编号
  40. /// </summary>
  41. private string _guid = string.Empty;
  42. //定义事件
  43. public event ChangeTextHandlers ChangeTextEvents;
  44. /// <summary>
  45. /// 当前视频的下标
  46. /// </summary>
  47. private int _i;
  48. private System.Timers.Timer _times;
  49. public UploadWindow()
  50. {
  51. InitializeComponent();
  52. }
  53. /// <summary>
  54. /// 初始化
  55. /// </summary>
  56. public void Initialize
  57. (
  58. string mResourcename,
  59. long mResourcesize,
  60. string mSuffix,
  61. string mGuid,
  62. int m
  63. )
  64. {
  65. this._i = m;
  66. this._resourcename = mResourcename;
  67. this._resourcesize = mResourcesize;
  68. this._suffix = mSuffix;
  69. this._guid = mGuid;
  70. tip_outer.Visibility = Visibility.Collapsed;
  71. Tsubjectbook();
  72. }
  73. /// <summary>
  74. /// 教材接口调用
  75. /// </summary>
  76. /// <returns>
  77. /// </returns>
  78. private void Tsubjectbook()
  79. {
  80. int code = _xhapi.TsubjectbookList();
  81. if (code == 0)
  82. {
  83. for (int i = 0; i < App.TsubjectbookList.Count; i++)
  84. {
  85. pageData.bookList.Add
  86. (
  87. new ComboBoxBean()
  88. {
  89. Key = App.TsubjectbookList[i].Lsbid,
  90. //Value = $"{APP.TsubjectbookList[i].Subjectname} {APP.TsubjectbookList[i].Bookname}"
  91. Value = $"{App.TsubjectbookList[i].Subjectname} {App.TsubjectbookList[i].Versionname} {App.TsubjectbookList[i].Lsbname}"
  92. }
  93. );
  94. }
  95. book_list.SelectedIndex = 0;
  96. DataContext = pageData;
  97. if (App.TsubjectbookList.Count > 0)
  98. {
  99. Director();
  100. ShowDialog();
  101. }
  102. else
  103. {
  104. App.IsUpLoad = false;
  105. Hide();
  106. MessageWindow.Show("暂无章节!");
  107. }
  108. }
  109. else
  110. {
  111. MessageWindow.Show(App.ServerMsg);
  112. }
  113. }
  114. /// <summary>
  115. /// 章节接口调用
  116. /// </summary>
  117. private void Director()
  118. {
  119. int selectIndex = book_list.SelectedIndex;
  120. if (selectIndex < 0)
  121. {
  122. selectIndex = 0;
  123. }
  124. if (App.TsubjectbookList.Count > selectIndex)
  125. {
  126. int code = _xhapi.DirectorList
  127. (
  128. App.TsubjectbookList[selectIndex].Lsbid,
  129. 4,
  130. App.UserInfo.Userid
  131. );
  132. if (code == 0)
  133. {
  134. pageData.zhangjieList.Clear();
  135. foreach (var item in App.DirectorList)
  136. {
  137. pageData.zhangjieList.Add(new ComboBoxBean() { Key = item.directorid, Value = item.directorname, leaf = item.leaf });
  138. AddChild(item);
  139. }
  140. cmbTeachingMaterial.SelectedIndex = 0;
  141. }
  142. else
  143. {
  144. MessageWindow.Show(App.ServerMsg);
  145. }
  146. }
  147. }
  148. /// <summary>
  149. /// 子章节递归
  150. /// </summary>
  151. /// <param name="directorList">
  152. /// </param>
  153. private void AddChild(ModelDirectorList directorList)
  154. {
  155. if (directorList.children != null && directorList.children.Count > 0)
  156. {
  157. foreach (ModelDirectorList child in directorList.children)
  158. {
  159. pageData.zhangjieList.Add(new ComboBoxBean() { Key = child.directorid, Value = GetSpace(child.directorlevel) + child.directorname, leaf = child.leaf });
  160. if (child.children != null && child.children.Count > 0)
  161. {
  162. AddChild(child);
  163. }
  164. }
  165. }
  166. }
  167. /// <summary>
  168. /// 章节是否加空格符
  169. /// </summary>
  170. /// <param name="num">
  171. /// </param>
  172. /// <returns>
  173. /// </returns>
  174. private string GetSpace(int num)
  175. {
  176. string str = "";
  177. for (int i = 0; i < num; i++)
  178. {
  179. str += " ";
  180. }
  181. return str;
  182. }
  183. private void Window_Loaded(object sender, RoutedEventArgs e)
  184. {
  185. //Tsubjectbook();
  186. }
  187. private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  188. {
  189. if (e.LeftButton == MouseButtonState.Pressed)
  190. {
  191. DragMove();
  192. }
  193. }
  194. /// <summary>
  195. /// 教材下拉框改变事件
  196. /// </summary>
  197. /// <param name="sender">
  198. /// </param>
  199. /// <param name="e">
  200. /// </param>
  201. private void ToolbarListSelectionChanged(object sender, SelectionChangedEventArgs e)
  202. {
  203. if (App.TsubjectbookList.Count > 0)
  204. {
  205. Director();
  206. }
  207. else
  208. {
  209. MessageWindow.Show("暂无章节!");
  210. App.IsUpLoad = false;
  211. Hide();
  212. }
  213. }
  214. private void BtnDown_Click(object sender, RoutedEventArgs e)
  215. {
  216. App.IsUpLoad = false;
  217. Hide();
  218. }
  219. /// <summary>
  220. /// 上传到个人空间
  221. /// </summary>
  222. /// <param name="sender">
  223. /// </param>
  224. /// <param name="e">
  225. /// </param>
  226. private void BtnStart_Click(object sender, RoutedEventArgs e)
  227. {
  228. if (string.IsNullOrWhiteSpace(book_list.Text))
  229. {
  230. MessageWindow.Show("请选择教材!");
  231. return;
  232. }
  233. if (cmbTeachingMaterial.SelectedIndex < pageData.zhangjieList.Count)
  234. {
  235. int leaf = pageData.zhangjieList[cmbTeachingMaterial.SelectedIndex].leaf;
  236. if (leaf != 1)
  237. {
  238. MessageWindow.Show("只能选择小节或全部进行上传!");
  239. return;
  240. }
  241. }
  242. btnStart.IsEnabled = false;
  243. book_list.IsEnabled = false;
  244. cmbTeachingMaterial.IsEnabled = false;
  245. Thread myThread = new Thread(StartUpload);
  246. _num = 0;
  247. tip_outer.Visibility = Visibility.Visible;
  248. myThread.Start();
  249. _times = new System.Timers.Timer(100);
  250. _times.Elapsed += Times_ElapsedClick;
  251. _times.Start();
  252. }
  253. private void StartUpload()
  254. {
  255. try
  256. {
  257. DalUpload dAlUpload = new DalUpload();
  258. if (dAlUpload.UploadVideoTwo(_guid, out string errMessage))
  259. {
  260. // converted: 0
  261. //createid: 80
  262. //directorid: 1009
  263. //duration: 39
  264. //imgUrl: ""
  265. //level: 2
  266. //lsbid: 40
  267. //mp4code: "h264"
  268. //resourcebelong: 3
  269. //resourceclass: 2
  270. //resourcecover: "12/resource/20200917/4f297df0-f8c0-11ea-adf5-81f24b97d4ff/weather_pic.jpg"
  271. //resourcename: "weather_pic"
  272. //resourcesize: 6105268
  273. //resourcetype: 0
  274. //resourceurl: "12/resource/20200917/4f297df0-f8c0-11ea-adf5-81f24b97d4ff/weather_pic.mp4"
  275. //schoolid: 12
  276. //suffix: "mp4"
  277. //uid: 80
  278. ModelResourceAdd modelResourceAdd = new ModelResourceAdd();
  279. Dispatcher.Invoke
  280. (
  281. () =>
  282. {
  283. modelResourceAdd = new ModelResourceAdd
  284. {
  285. converted = 0,
  286. createid = App.UserInfo.Userid,
  287. directorid = cmbTeachingMaterial.SelectedValue.ToString(),
  288. duration = App.ResourceAddTwo.duration,
  289. subjectid = App.TsubjectbookList[book_list.SelectedIndex].Subjectid,
  290. imgUrl = "",
  291. level = 2,
  292. lsbid = book_list.SelectedValue.ToString(),
  293. mp4code = App.ResourceAddTwo.mp4code,
  294. resourcebelong = 3,
  295. resourceclass = 5,
  296. resourcecover = App.ResourceAddTwo.coverpath,
  297. resourcename = _resourcename,
  298. resourcesize = _resourcesize,
  299. resourcetype = 10,
  300. resourceurl = App.ResourceAddTwo.videopath,
  301. schoolid = App.UserInfo.Schoolid
  302. };
  303. }
  304. );
  305. if (_suffix.Equals("FLV"))
  306. {
  307. _suffix = "flv";
  308. }
  309. else if (_suffix.Equals("AVI"))
  310. {
  311. _suffix = "avi";
  312. }
  313. else
  314. {
  315. _suffix = "mp4";
  316. }
  317. modelResourceAdd.suffix = _suffix;
  318. //model_ResourceAdd.uid = 0;//zxy
  319. int code = _xhapi.ResourceAdd(modelResourceAdd);
  320. if (code == 0)
  321. {
  322. Dispatcher.Invoke
  323. (
  324. () =>
  325. {
  326. foreach (ModelWkData vdata in App.WKDataList)
  327. {
  328. if (vdata.VideoList == null)
  329. {
  330. continue;
  331. }
  332. foreach (ModelVideo videoinfo in vdata.VideoList)
  333. {
  334. if (videoinfo.FileGuid == _guid)
  335. {
  336. videoinfo.IsUpload = true;
  337. break;
  338. }
  339. }
  340. }
  341. btnStart.IsEnabled = true;
  342. book_list.IsEnabled = true;
  343. cmbTeachingMaterial.IsEnabled = true;
  344. _num = 99;
  345. _times.Stop();
  346. pgbProcess.Value = 100;
  347. lbProcess.Content = "100%";
  348. Hide();
  349. tip_outer.Visibility = Visibility.Collapsed;
  350. MessageWindow.Show("视频上传成功!");
  351. if (ChangeTextEvents != null)
  352. {
  353. ChangeTextEvents("上传成功", _i);
  354. }
  355. }
  356. );
  357. }
  358. else
  359. {
  360. Dispatcher.Invoke
  361. (
  362. () =>
  363. {
  364. btnStart.IsEnabled = true;
  365. book_list.IsEnabled = true;
  366. cmbTeachingMaterial.IsEnabled = true;
  367. _times.Stop();
  368. tip_outer.Visibility = Visibility.Collapsed;
  369. MessageWindow.Show(App.ServerMsg);
  370. }
  371. );
  372. }
  373. }
  374. else
  375. {
  376. Dispatcher.Invoke
  377. (
  378. () =>
  379. {
  380. btnStart.IsEnabled = true;
  381. book_list.IsEnabled = true;
  382. cmbTeachingMaterial.IsEnabled = true;
  383. _times.Stop();
  384. tip_outer.Visibility = Visibility.Collapsed;
  385. MessageWindow.Show(errMessage);
  386. }
  387. );
  388. }
  389. }
  390. catch (Exception ex)
  391. {
  392. Dispatcher.Invoke(() =>
  393. {
  394. btnStart.IsEnabled = true;
  395. book_list.IsEnabled = true;
  396. cmbTeachingMaterial.IsEnabled = true;
  397. _times.Stop();
  398. tip_outer.Visibility = Visibility.Collapsed;
  399. MessageWindow.Show("无法上传视频,请检查与服务器链接状态!");
  400. App.IsUpLoad = false;
  401. Hide();
  402. LogHelper.Logerror.Error("【UploadWindow】(BtnStart_Click)" + ex.Message, ex);
  403. });
  404. }
  405. }
  406. private int _num;
  407. /// <summary>
  408. /// 计时器
  409. /// </summary>
  410. /// <param name="sender">
  411. /// </param>
  412. /// <param name="e">
  413. /// </param>
  414. private void Times_ElapsedClick(object sender, System.Timers.ElapsedEventArgs e)
  415. {
  416. Dispatcher.Invoke(() =>
  417. {
  418. pgbProcess.Value = _num;
  419. lbProcess.Content = _num + "%";
  420. if (_num < 99)
  421. {
  422. _num++;
  423. // ReSharper disable once PossibleLossOfFraction
  424. _times.Interval += _num / 2;
  425. }
  426. else
  427. {
  428. _times.Stop();
  429. }
  430. });
  431. }
  432. }
  433. public class LoginPageData : NotifyModel
  434. {
  435. public ObservableCollection<ComboBoxBean> bookList { get; set; }
  436. public ObservableCollection<ComboBoxBean> zhangjieList { get; set; }
  437. public LoginPageData()
  438. {
  439. bookList = new ObservableCollection<ComboBoxBean>();
  440. zhangjieList = new ObservableCollection<ComboBoxBean>();
  441. }
  442. }
  443. }