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

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