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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  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 == "Blue")
  53. {
  54. GridTitle.Visibility = Visibility.Visible;
  55. GridTitle_Black.Visibility = Visibility.Collapsed;
  56. }
  57. else if (APP.SkinStyle == "Black")
  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. imgUrl = "",
  257. level = 2,
  258. lsbid = book_list.SelectedValue.ToString(),
  259. mp4code = APP.ResourceAddTwo.mp4code,
  260. resourcebelong = 3,
  261. resourceclass = 2,
  262. resourcecover = APP.ResourceAddTwo.coverpath,
  263. resourcename = Resourcename,
  264. resourcesize = Resourcesize,
  265. resourcetype = 0,
  266. resourceurl = APP.ResourceAddTwo.videopath,
  267. schoolid = APP.UserInfo.Schoolid
  268. };
  269. });
  270. if (Suffix.Equals("FLV"))
  271. {
  272. Suffix = "flv";
  273. }
  274. else if (Suffix.Equals("AVI"))
  275. {
  276. Suffix = "avi";
  277. }
  278. else
  279. {
  280. Suffix = "mp4";
  281. }
  282. model_ResourceAdd.suffix = Suffix;
  283. //model_ResourceAdd.uid = 0;//zxy
  284. int code = @interface.ResourceAdd(model_ResourceAdd);
  285. if (code == 0)
  286. {
  287. Dispatcher.Invoke(() =>
  288. {
  289. foreach (Model_WKData Vdata in APP.WKDataList)
  290. {
  291. if (Vdata.VideoList == null)
  292. {
  293. continue;
  294. }
  295. foreach (Model_Video videoinfo in Vdata.VideoList)
  296. {
  297. if (videoinfo.FileGuid == Guid)
  298. {
  299. videoinfo.IsUpload = true;
  300. break;
  301. }
  302. }
  303. }
  304. btnStart.IsEnabled = true;
  305. book_list.IsEnabled = true;
  306. cmbTeachingMaterial.IsEnabled = true;
  307. num = 99;
  308. times.Stop();
  309. pgbProcess.Value = 100;
  310. lbProcess.Content = "100%";
  311. MessageWindow.Show("视频上传成功!");
  312. tip_outer.Visibility = Visibility.Collapsed;
  313. ChangeTextEvents("上传成功", i);
  314. Hide();
  315. });
  316. }
  317. else
  318. {
  319. Dispatcher.Invoke(() =>
  320. {
  321. btnStart.IsEnabled = true;
  322. book_list.IsEnabled = true;
  323. cmbTeachingMaterial.IsEnabled = true;
  324. times.Stop();
  325. tip_outer.Visibility = Visibility.Collapsed;
  326. MessageWindow.Show(APP.ServerMsg);
  327. });
  328. }
  329. }
  330. else
  331. {
  332. Dispatcher.Invoke(() =>
  333. {
  334. btnStart.IsEnabled = true;
  335. book_list.IsEnabled = true;
  336. cmbTeachingMaterial.IsEnabled = true;
  337. times.Stop();
  338. tip_outer.Visibility = Visibility.Collapsed;
  339. MessageWindow.Show(ErrMessage);
  340. });
  341. }
  342. }
  343. catch (Exception ex)
  344. {
  345. Dispatcher.Invoke(() =>
  346. {
  347. btnStart.IsEnabled = true;
  348. book_list.IsEnabled = true;
  349. cmbTeachingMaterial.IsEnabled = true;
  350. times.Stop();
  351. tip_outer.Visibility = Visibility.Collapsed;
  352. MessageWindow.Show("无法上传视频,请检查与服务器链接状态!");
  353. APP.IsUpLoad = false;
  354. Hide();
  355. LogHelper.WriteErrLog("【UploadWindow】(BtnStart_Click)" + ex.Message, ex);
  356. });
  357. }
  358. }
  359. private int num = 0;
  360. /// <summary>
  361. /// 计时器
  362. /// </summary>
  363. /// <param name="sender"></param>
  364. /// <param name="e"></param>
  365. private void Times_ElapsedClick(object sender, System.Timers.ElapsedEventArgs e)
  366. {
  367. Dispatcher.Invoke(() =>
  368. {
  369. pgbProcess.Value = num;
  370. lbProcess.Content = num.ToString() + "%";
  371. if (num < 99)
  372. {
  373. num++;
  374. times.Interval += (num / 2);
  375. }
  376. else
  377. {
  378. times.Stop();
  379. }
  380. });
  381. }
  382. }
  383. public class LoginPageData : NotifyModel
  384. {
  385. public ObservableCollection<ComboBoxBean> bookList { get; set; }
  386. public ObservableCollection<ComboBoxBean> zhangjieList { get; set; }
  387. public LoginPageData()
  388. {
  389. bookList = new ObservableCollection<ComboBoxBean>();
  390. zhangjieList = new ObservableCollection<ComboBoxBean>();
  391. }
  392. }
  393. }