星火微课系统客户端
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

UploadWindow.xaml.cs 16KB

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