星火微课系统客户端
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

UploadWindow.xaml.cs 14KB

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