星火微课系统客户端
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 15KB

před 4 roky
před 4 roky
před 4 roky
před 4 roky
před 4 roky
před 4 roky
před 4 roky
před 4 roky
před 4 roky
před 4 roky
před 4 roky
před 4 roky
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 : Window
  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 = 0;
  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 = 0;
  48. private System.Timers.Timer times;
  49. public UploadWindow()
  50. {
  51. InitializeComponent();
  52. }
  53. /// <summary>
  54. /// 初始化
  55. /// </summary>
  56. public void Initialize(string _resourcename, long _resourcesize, string _suffix, string _guid, int _i)
  57. {
  58. i = _i;
  59. Resourcename = _resourcename;
  60. Resourcesize = _resourcesize;
  61. Suffix = _suffix;
  62. Guid = _guid;
  63. tip_outer.Visibility = Visibility.Collapsed;
  64. Tsubjectbook();
  65. }
  66. /// <summary>
  67. /// 教材接口调用
  68. /// </summary>
  69. /// <returns>
  70. /// </returns>
  71. private void Tsubjectbook()
  72. {
  73. int code = xhapi.TsubjectbookList();
  74. if (code == 0)
  75. {
  76. for (int i = 0; i < App.TsubjectbookList.Count; i++)
  77. {
  78. pageData.bookList.Add
  79. (
  80. new ComboBoxBean()
  81. {
  82. Key = App.TsubjectbookList[i].Lsbid,
  83. //Value = $"{APP.TsubjectbookList[i].Subjectname} {APP.TsubjectbookList[i].Bookname}"
  84. Value = $"{App.TsubjectbookList[i].Subjectname} {App.TsubjectbookList[i].Versionname} {App.TsubjectbookList[i].Lsbname}"
  85. }
  86. );
  87. }
  88. book_list.SelectedIndex = 0;
  89. DataContext = pageData;
  90. if (App.TsubjectbookList.Count > 0)
  91. {
  92. Director();
  93. ShowDialog();
  94. }
  95. else
  96. {
  97. App.IsUpLoad = false;
  98. Hide();
  99. MessageWindow.Show("暂无章节!");
  100. }
  101. }
  102. else
  103. {
  104. MessageWindow.Show(App.ServerMsg);
  105. }
  106. }
  107. /// <summary>
  108. /// 章节接口调用
  109. /// </summary>
  110. private void Director()
  111. {
  112. int selectIndex = book_list.SelectedIndex;
  113. if (selectIndex < 0)
  114. {
  115. selectIndex = 0;
  116. }
  117. if (App.TsubjectbookList.Count > selectIndex)
  118. {
  119. int code = xhapi.DirectorList
  120. (
  121. App.TsubjectbookList[selectIndex].Lsbid,
  122. 4,
  123. App.UserInfo.Userid
  124. );
  125. if (code == 0)
  126. {
  127. pageData.zhangjieList.Clear();
  128. pageData.zhangjieList.Add
  129. (
  130. new ComboBoxBean()
  131. {
  132. Key = "0",
  133. Value = "全部",
  134. leaf = 1
  135. }
  136. );
  137. for (int i = 0; i < App.DirectorList.Count; i++)
  138. {
  139. Model_DirectorList item = App.DirectorList[i];
  140. pageData.zhangjieList.Add
  141. (
  142. new ComboBoxBean()
  143. {
  144. Key = item.directorid,
  145. Value = item.directorname,
  146. leaf = item.leaf
  147. }
  148. );
  149. addChild(item);
  150. }
  151. cmbTeachingMaterial.SelectedIndex = 0;
  152. }
  153. else
  154. {
  155. MessageWindow.Show(App.ServerMsg);
  156. }
  157. }
  158. }
  159. /// <summary>
  160. /// 子章节递归
  161. /// </summary>
  162. /// <param name="directorList">
  163. /// </param>
  164. private void addChild(Model_DirectorList directorList)
  165. {
  166. if (directorList.children != null && directorList.children.Count > 0)
  167. {
  168. foreach (Model_DirectorList child in directorList.children)
  169. {
  170. pageData.zhangjieList.Add(new ComboBoxBean()
  171. {
  172. Key = child.directorid,
  173. Value = getSpace(child.directorlevel) + child.directorname,
  174. leaf = child.leaf
  175. });
  176. if (child.children != null && child.children.Count > 0)
  177. {
  178. addChild(child);
  179. }
  180. }
  181. }
  182. }
  183. /// <summary>
  184. /// 章节是否加空格符
  185. /// </summary>
  186. /// <param name="num">
  187. /// </param>
  188. /// <returns>
  189. /// </returns>
  190. private string getSpace(int num)
  191. {
  192. string str = "";
  193. for (int i = 0; i < num; i++)
  194. {
  195. str += " ";
  196. }
  197. return str;
  198. }
  199. private void Window_Loaded(object sender, RoutedEventArgs e)
  200. {
  201. //Tsubjectbook();
  202. }
  203. private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  204. {
  205. }
  206. /// <summary>
  207. /// 教材下拉框改变事件
  208. /// </summary>
  209. /// <param name="sender">
  210. /// </param>
  211. /// <param name="e">
  212. /// </param>
  213. private void toolbar_list_SelectionChanged(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(book_list.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. book_list.IsEnabled = false;
  256. cmbTeachingMaterial.IsEnabled = false;
  257. Thread myThread = new Thread(StartUpload);
  258. num = 0;
  259. tip_outer.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 dAL_Upload = new DalUpload();
  270. if (dAL_Upload.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. Model_ResourceAdd model_ResourceAdd = new Model_ResourceAdd();
  291. Dispatcher.Invoke(() =>
  292. {
  293. model_ResourceAdd = new Model_ResourceAdd
  294. {
  295. converted = 0,
  296. createid = App.UserInfo.Userid,
  297. directorid = cmbTeachingMaterial.SelectedValue.ToString(),
  298. duration = App.ResourceAddTwo.duration,
  299. subjectid = App.TsubjectbookList[book_list.SelectedIndex].Subjectid,
  300. imgUrl = "",
  301. level = 2,
  302. lsbid = book_list.SelectedValue.ToString(),
  303. mp4code = App.ResourceAddTwo.mp4code,
  304. resourcebelong = 3,
  305. resourceclass = 5,
  306. resourcecover = App.ResourceAddTwo.coverpath,
  307. resourcename = Resourcename,
  308. resourcesize = Resourcesize,
  309. resourcetype = 10,
  310. resourceurl = App.ResourceAddTwo.videopath,
  311. schoolid = App.UserInfo.Schoolid
  312. };
  313. });
  314. if (Suffix.Equals("FLV"))
  315. {
  316. Suffix = "flv";
  317. }
  318. else if (Suffix.Equals("AVI"))
  319. {
  320. Suffix = "avi";
  321. }
  322. else
  323. {
  324. Suffix = "mp4";
  325. }
  326. model_ResourceAdd.suffix = Suffix;
  327. //model_ResourceAdd.uid = 0;//zxy
  328. int code = xhapi.ResourceAdd(model_ResourceAdd);
  329. if (code == 0)
  330. {
  331. Dispatcher.Invoke(() =>
  332. {
  333. foreach (Model_WKData Vdata in App.WKDataList)
  334. {
  335. if (Vdata.VideoList == null)
  336. {
  337. continue;
  338. }
  339. foreach (Model_Video videoinfo in Vdata.VideoList)
  340. {
  341. if (videoinfo.FileGuid == Guid)
  342. {
  343. videoinfo.IsUpload = true;
  344. break;
  345. }
  346. }
  347. }
  348. btnStart.IsEnabled = true;
  349. book_list.IsEnabled = true;
  350. cmbTeachingMaterial.IsEnabled = true;
  351. num = 99;
  352. times.Stop();
  353. pgbProcess.Value = 100;
  354. lbProcess.Content = "100%";
  355. MessageWindow.Show("视频上传成功!");
  356. tip_outer.Visibility = Visibility.Collapsed;
  357. ChangeTextEvents("上传成功", i);
  358. Hide();
  359. });
  360. }
  361. else
  362. {
  363. Dispatcher.Invoke(() =>
  364. {
  365. btnStart.IsEnabled = true;
  366. book_list.IsEnabled = true;
  367. cmbTeachingMaterial.IsEnabled = true;
  368. times.Stop();
  369. tip_outer.Visibility = Visibility.Collapsed;
  370. MessageWindow.Show(App.ServerMsg);
  371. });
  372. }
  373. }
  374. else
  375. {
  376. Dispatcher.Invoke(() =>
  377. {
  378. btnStart.IsEnabled = true;
  379. book_list.IsEnabled = true;
  380. cmbTeachingMaterial.IsEnabled = true;
  381. times.Stop();
  382. tip_outer.Visibility = Visibility.Collapsed;
  383. MessageWindow.Show(ErrMessage);
  384. });
  385. }
  386. }
  387. catch (Exception ex)
  388. {
  389. Dispatcher.Invoke(() =>
  390. {
  391. btnStart.IsEnabled = true;
  392. book_list.IsEnabled = true;
  393. cmbTeachingMaterial.IsEnabled = true;
  394. times.Stop();
  395. tip_outer.Visibility = Visibility.Collapsed;
  396. MessageWindow.Show("无法上传视频,请检查与服务器链接状态!");
  397. App.IsUpLoad = false;
  398. Hide();
  399. LogHelper.WriteErrLog("【UploadWindow】(BtnStart_Click)" + ex.Message, ex);
  400. });
  401. }
  402. }
  403. private int num = 0;
  404. /// <summary>
  405. /// 计时器
  406. /// </summary>
  407. /// <param name="sender">
  408. /// </param>
  409. /// <param name="e">
  410. /// </param>
  411. private void Times_ElapsedClick(object sender, System.Timers.ElapsedEventArgs e)
  412. {
  413. Dispatcher.Invoke(() =>
  414. {
  415. pgbProcess.Value = num;
  416. lbProcess.Content = num.ToString() + "%";
  417. if (num < 99)
  418. {
  419. num++;
  420. times.Interval += (num / 2);
  421. }
  422. else
  423. {
  424. times.Stop();
  425. }
  426. });
  427. }
  428. }
  429. public class LoginPageData : NotifyModel
  430. {
  431. public ObservableCollection<ComboBoxBean> bookList { get; set; }
  432. public ObservableCollection<ComboBoxBean> zhangjieList { get; set; }
  433. public LoginPageData()
  434. {
  435. bookList = new ObservableCollection<ComboBoxBean>();
  436. zhangjieList = new ObservableCollection<ComboBoxBean>();
  437. }
  438. }
  439. }