星火微课系统客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

UploadWindow.xaml.cs 16KB

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