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

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