星火微课系统客户端
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

UploadWindow.xaml.cs 14KB

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