星火微课系统客户端
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

UploadWindow.xaml.cs 16KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492
  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. pageData.zhangjieList.Add
  136. (
  137. new ComboBoxBean()
  138. {
  139. Key = "0",
  140. Value = "全部",
  141. leaf = 1
  142. }
  143. );
  144. for (int i = 0; i < App.DirectorList.Count; i++)
  145. {
  146. ModelDirectorList item = App.DirectorList[i];
  147. pageData.zhangjieList.Add
  148. (
  149. new ComboBoxBean()
  150. {
  151. Key = item.directorid,
  152. Value = item.directorname,
  153. leaf = item.leaf
  154. }
  155. );
  156. AddChild(item);
  157. }
  158. cmbTeachingMaterial.SelectedIndex = 0;
  159. }
  160. else
  161. {
  162. MessageWindow.Show(App.ServerMsg);
  163. }
  164. }
  165. }
  166. /// <summary>
  167. /// 子章节递归
  168. /// </summary>
  169. /// <param name="directorList">
  170. /// </param>
  171. private void AddChild(ModelDirectorList directorList)
  172. {
  173. if (directorList.children != null && directorList.children.Count > 0)
  174. {
  175. foreach (ModelDirectorList child in directorList.children)
  176. {
  177. pageData.zhangjieList.Add(new ComboBoxBean() { Key = child.directorid, Value = GetSpace(child.directorlevel) + child.directorname, leaf = child.leaf });
  178. if (child.children != null && child.children.Count > 0)
  179. {
  180. AddChild(child);
  181. }
  182. }
  183. }
  184. }
  185. /// <summary>
  186. /// 章节是否加空格符
  187. /// </summary>
  188. /// <param name="num">
  189. /// </param>
  190. /// <returns>
  191. /// </returns>
  192. private string GetSpace(int num)
  193. {
  194. string str = "";
  195. for (int i = 0; i < num; i++)
  196. {
  197. str += " ";
  198. }
  199. return str;
  200. }
  201. private void Window_Loaded(object sender, RoutedEventArgs e)
  202. {
  203. //Tsubjectbook();
  204. }
  205. private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  206. {
  207. if (e.LeftButton == MouseButtonState.Pressed)
  208. {
  209. DragMove();
  210. }
  211. }
  212. /// <summary>
  213. /// 教材下拉框改变事件
  214. /// </summary>
  215. /// <param name="sender">
  216. /// </param>
  217. /// <param name="e">
  218. /// </param>
  219. private void ToolbarListSelectionChanged(object sender, SelectionChangedEventArgs e)
  220. {
  221. if (App.TsubjectbookList.Count > 0)
  222. {
  223. Director();
  224. }
  225. else
  226. {
  227. MessageWindow.Show("暂无章节!");
  228. App.IsUpLoad = false;
  229. Hide();
  230. }
  231. }
  232. private void BtnDown_Click(object sender, RoutedEventArgs e)
  233. {
  234. App.IsUpLoad = false;
  235. Hide();
  236. }
  237. /// <summary>
  238. /// 上传到个人空间
  239. /// </summary>
  240. /// <param name="sender">
  241. /// </param>
  242. /// <param name="e">
  243. /// </param>
  244. private void BtnStart_Click(object sender, RoutedEventArgs e)
  245. {
  246. if (string.IsNullOrWhiteSpace(book_list.Text))
  247. {
  248. MessageWindow.Show("请选择教材!");
  249. return;
  250. }
  251. if (cmbTeachingMaterial.SelectedIndex < pageData.zhangjieList.Count)
  252. {
  253. int leaf = pageData.zhangjieList[cmbTeachingMaterial.SelectedIndex].leaf;
  254. if (leaf != 1)
  255. {
  256. MessageWindow.Show("只能选择小节或全部进行上传!");
  257. return;
  258. }
  259. }
  260. btnStart.IsEnabled = false;
  261. book_list.IsEnabled = false;
  262. cmbTeachingMaterial.IsEnabled = false;
  263. Thread myThread = new Thread(StartUpload);
  264. _num = 0;
  265. tip_outer.Visibility = Visibility.Visible;
  266. myThread.Start();
  267. _times = new System.Timers.Timer(100);
  268. _times.Elapsed += Times_ElapsedClick;
  269. _times.Start();
  270. }
  271. private void StartUpload()
  272. {
  273. try
  274. {
  275. DalUpload dAlUpload = new DalUpload();
  276. if (dAlUpload.UploadVideoTwo(_guid, out string errMessage))
  277. {
  278. // converted: 0
  279. //createid: 80
  280. //directorid: 1009
  281. //duration: 39
  282. //imgUrl: ""
  283. //level: 2
  284. //lsbid: 40
  285. //mp4code: "h264"
  286. //resourcebelong: 3
  287. //resourceclass: 2
  288. //resourcecover: "12/resource/20200917/4f297df0-f8c0-11ea-adf5-81f24b97d4ff/weather_pic.jpg"
  289. //resourcename: "weather_pic"
  290. //resourcesize: 6105268
  291. //resourcetype: 0
  292. //resourceurl: "12/resource/20200917/4f297df0-f8c0-11ea-adf5-81f24b97d4ff/weather_pic.mp4"
  293. //schoolid: 12
  294. //suffix: "mp4"
  295. //uid: 80
  296. ModelResourceAdd modelResourceAdd = new ModelResourceAdd();
  297. Dispatcher.Invoke
  298. (
  299. () =>
  300. {
  301. modelResourceAdd = new ModelResourceAdd
  302. {
  303. converted = 0,
  304. createid = App.UserInfo.Userid,
  305. directorid = cmbTeachingMaterial.SelectedValue.ToString(),
  306. duration = App.ResourceAddTwo.duration,
  307. subjectid = App.TsubjectbookList[book_list.SelectedIndex].Subjectid,
  308. imgUrl = "",
  309. level = 2,
  310. lsbid = book_list.SelectedValue.ToString(),
  311. mp4code = App.ResourceAddTwo.mp4code,
  312. resourcebelong = 3,
  313. resourceclass = 5,
  314. resourcecover = App.ResourceAddTwo.coverpath,
  315. resourcename = _resourcename,
  316. resourcesize = _resourcesize,
  317. resourcetype = 10,
  318. resourceurl = App.ResourceAddTwo.videopath,
  319. schoolid = App.UserInfo.Schoolid
  320. };
  321. }
  322. );
  323. if (_suffix.Equals("FLV"))
  324. {
  325. _suffix = "flv";
  326. }
  327. else if (_suffix.Equals("AVI"))
  328. {
  329. _suffix = "avi";
  330. }
  331. else
  332. {
  333. _suffix = "mp4";
  334. }
  335. modelResourceAdd.suffix = _suffix;
  336. //model_ResourceAdd.uid = 0;//zxy
  337. int code = _xhapi.ResourceAdd(modelResourceAdd);
  338. if (code == 0)
  339. {
  340. Dispatcher.Invoke
  341. (
  342. () =>
  343. {
  344. foreach (ModelWkData vdata in App.WKDataList)
  345. {
  346. if (vdata.VideoList == null)
  347. {
  348. continue;
  349. }
  350. foreach (ModelVideo videoinfo in vdata.VideoList)
  351. {
  352. if (videoinfo.FileGuid == _guid)
  353. {
  354. videoinfo.IsUpload = true;
  355. break;
  356. }
  357. }
  358. }
  359. btnStart.IsEnabled = true;
  360. book_list.IsEnabled = true;
  361. cmbTeachingMaterial.IsEnabled = true;
  362. _num = 99;
  363. _times.Stop();
  364. pgbProcess.Value = 100;
  365. lbProcess.Content = "100%";
  366. Hide();
  367. tip_outer.Visibility = Visibility.Collapsed;
  368. MessageWindow.Show("视频上传成功!");
  369. if (ChangeTextEvents != null)
  370. {
  371. ChangeTextEvents("上传成功", _i);
  372. }
  373. }
  374. );
  375. }
  376. else
  377. {
  378. Dispatcher.Invoke
  379. (
  380. () =>
  381. {
  382. btnStart.IsEnabled = true;
  383. book_list.IsEnabled = true;
  384. cmbTeachingMaterial.IsEnabled = true;
  385. _times.Stop();
  386. tip_outer.Visibility = Visibility.Collapsed;
  387. MessageWindow.Show(App.ServerMsg);
  388. }
  389. );
  390. }
  391. }
  392. else
  393. {
  394. Dispatcher.Invoke
  395. (
  396. () =>
  397. {
  398. btnStart.IsEnabled = true;
  399. book_list.IsEnabled = true;
  400. cmbTeachingMaterial.IsEnabled = true;
  401. _times.Stop();
  402. tip_outer.Visibility = Visibility.Collapsed;
  403. MessageWindow.Show(errMessage);
  404. }
  405. );
  406. }
  407. }
  408. catch (Exception ex)
  409. {
  410. Dispatcher.Invoke(() =>
  411. {
  412. btnStart.IsEnabled = true;
  413. book_list.IsEnabled = true;
  414. cmbTeachingMaterial.IsEnabled = true;
  415. _times.Stop();
  416. tip_outer.Visibility = Visibility.Collapsed;
  417. MessageWindow.Show("无法上传视频,请检查与服务器链接状态!");
  418. App.IsUpLoad = false;
  419. Hide();
  420. LogHelper.Logerror.Error("【UploadWindow】(BtnStart_Click)" + ex.Message, ex);
  421. });
  422. }
  423. }
  424. private int _num;
  425. /// <summary>
  426. /// 计时器
  427. /// </summary>
  428. /// <param name="sender">
  429. /// </param>
  430. /// <param name="e">
  431. /// </param>
  432. private void Times_ElapsedClick(object sender, System.Timers.ElapsedEventArgs e)
  433. {
  434. Dispatcher.Invoke(() =>
  435. {
  436. pgbProcess.Value = _num;
  437. lbProcess.Content = _num + "%";
  438. if (_num < 99)
  439. {
  440. _num++;
  441. // ReSharper disable once PossibleLossOfFraction
  442. _times.Interval += _num / 2;
  443. }
  444. else
  445. {
  446. _times.Stop();
  447. }
  448. });
  449. }
  450. }
  451. public class LoginPageData : NotifyModel
  452. {
  453. public ObservableCollection<ComboBoxBean> bookList { get; set; }
  454. public ObservableCollection<ComboBoxBean> zhangjieList { get; set; }
  455. public LoginPageData()
  456. {
  457. bookList = new ObservableCollection<ComboBoxBean>();
  458. zhangjieList = new ObservableCollection<ComboBoxBean>();
  459. }
  460. }
  461. }