星火微课系统客户端
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  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 XHWK.WKTool.UControl;
  11. using static XHWK.WKTool.XHMicroLessonSystemWindow;
  12. namespace XHWK.WKTool
  13. {
  14. /// <summary>
  15. /// UploadWindow.xaml 的交互逻辑
  16. /// </summary>
  17. public partial class UploadWindow : Window
  18. {
  19. /// <summary>
  20. /// 调用接口
  21. /// </summary>
  22. private readonly Interface @interface = new Interface();
  23. /// <summary>
  24. /// 前台数据
  25. /// </summary>
  26. internal LoginPageData pageData = new LoginPageData();
  27. /// <summary>
  28. /// 文件名
  29. /// </summary>
  30. private string Resourcename = string.Empty;
  31. /// <summary>
  32. /// 文件大小
  33. /// </summary>
  34. private long Resourcesize = 0;
  35. /// <summary>
  36. /// 文件类型
  37. /// </summary>
  38. private string Suffix = string.Empty;
  39. /// <summary>
  40. /// 唯一编号
  41. /// </summary>
  42. private string Guid = string.Empty;
  43. //定义事件
  44. public event ChangeTextHandlers ChangeTextEvents;
  45. /// <summary>
  46. /// 当前视频的下标
  47. /// </summary>
  48. private int i = 0;
  49. private System.Timers.Timer times;
  50. public UploadWindow()
  51. {
  52. InitializeComponent();
  53. }
  54. /// <summary>
  55. /// 初始化
  56. /// </summary>
  57. public void Initialize(string _resourcename, long _resourcesize, string _suffix, string _guid,int _i)
  58. {
  59. i = _i;
  60. Resourcename = _resourcename;
  61. Resourcesize = _resourcesize;
  62. Suffix = _suffix;
  63. Guid = _guid;
  64. tip_outer.Visibility = Visibility.Collapsed;
  65. Tsubjectbook();
  66. }
  67. /// <summary>
  68. /// 教材接口调用
  69. /// </summary>
  70. /// <returns></returns>
  71. private void Tsubjectbook()
  72. {
  73. int code = @interface.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. });
  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, 2, 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. });
  112. for (int i = 0; i < APP.DirectorList.Count; i++)
  113. {
  114. Model_DirectorList item = APP.DirectorList[i];
  115. pageData.zhangjieList.Add(new ComboBoxBean()
  116. {
  117. Key = item.directorid,
  118. Value = item.directorname
  119. });
  120. addChild(item);
  121. }
  122. cmbTeachingMaterial.SelectedIndex = 0;
  123. }
  124. else
  125. {
  126. MessageWindow.Show(APP.ServerMsg);
  127. }
  128. }
  129. /// <summary>
  130. /// 子章节递归
  131. /// </summary>
  132. /// <param name="directorList"></param>
  133. private void addChild(Model_DirectorList directorList)
  134. {
  135. if (directorList.children != null && directorList.children.Count > 0)
  136. {
  137. foreach (Model_DirectorList child in directorList.children)
  138. {
  139. pageData.zhangjieList.Add(new ComboBoxBean()
  140. {
  141. Key = child.directorid,
  142. Value = getSpace(child.directorlevel) + child.directorname
  143. });
  144. if (child.children != null && child.children.Count > 0)
  145. {
  146. addChild(child);
  147. }
  148. }
  149. }
  150. }
  151. /// <summary>
  152. /// 章节是否加空格符
  153. /// </summary>
  154. /// <param name="num"></param>
  155. /// <returns></returns>
  156. private string getSpace(int num)
  157. {
  158. string str = "";
  159. for (int i = 0; i < num; i++)
  160. {
  161. str += " ";
  162. }
  163. return str;
  164. }
  165. private void Window_Loaded(object sender, RoutedEventArgs e)
  166. {
  167. }
  168. private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  169. {
  170. }
  171. /// <summary>
  172. /// 教材下拉框改变事件
  173. /// </summary>
  174. /// <param name="sender"></param>
  175. /// <param name="e"></param>
  176. private void toolbar_list_SelectionChanged(object sender, SelectionChangedEventArgs e)
  177. {
  178. Director();
  179. }
  180. private void BtnDown_Click(object sender, RoutedEventArgs e)
  181. {
  182. APP.IsUpLoad = false;
  183. Hide();
  184. }
  185. /// <summary>
  186. /// 上传到个人空间
  187. /// </summary>
  188. /// <param name="sender"></param>
  189. /// <param name="e"></param>
  190. private void BtnStart_Click(object sender, RoutedEventArgs e)
  191. {
  192. if(string.IsNullOrWhiteSpace(book_list.Text))
  193. {
  194. MessageWindow.Show("教材不能为空!");
  195. }
  196. btnStart.IsEnabled = false;
  197. book_list.IsEnabled = false;
  198. cmbTeachingMaterial.IsEnabled = false;
  199. Thread myThread = new Thread(StartUpload);
  200. num = 0;
  201. tip_outer.Visibility = Visibility.Visible;
  202. myThread.Start();
  203. times = new System.Timers.Timer(100);
  204. times.Elapsed += Times_ElapsedClick;
  205. times.Start();
  206. }
  207. private void StartUpload()
  208. {
  209. try
  210. {
  211. DAL_Upload dAL_Upload = new DAL_Upload();
  212. if (dAL_Upload.UploadVideoTwo(Guid, out string ErrMessage))
  213. {
  214. // converted: 0
  215. //createid: 80
  216. //directorid: 1009
  217. //duration: 39
  218. //imgUrl: ""
  219. //level: 2
  220. //lsbid: 40
  221. //mp4code: "h264"
  222. //resourcebelong: 3
  223. //resourceclass: 2
  224. //resourcecover: "12/resource/20200917/4f297df0-f8c0-11ea-adf5-81f24b97d4ff/weather_pic.jpg"
  225. //resourcename: "weather_pic"
  226. //resourcesize: 6105268
  227. //resourcetype: 0
  228. //resourceurl: "12/resource/20200917/4f297df0-f8c0-11ea-adf5-81f24b97d4ff/weather_pic.mp4"
  229. //schoolid: 12
  230. //suffix: "mp4"
  231. //uid: 80
  232. Model_ResourceAdd model_ResourceAdd = new Model_ResourceAdd();
  233. Dispatcher.Invoke(() =>
  234. {
  235. model_ResourceAdd = new Model_ResourceAdd
  236. {
  237. converted = 0,
  238. createid = APP.UserInfo.Userid,
  239. directorid = Convert.ToInt32(cmbTeachingMaterial.SelectedValue.ToString()),
  240. duration = APP.ResourceAddTwo.duration,
  241. imgUrl = "",
  242. level = 2,
  243. lsbid = Convert.ToInt32(book_list.SelectedValue.ToString()),
  244. mp4code = APP.ResourceAddTwo.mp4code,
  245. resourcebelong = 3,
  246. resourceclass = 2,
  247. resourcecover = APP.ResourceAddTwo.coverpath,
  248. resourcename = Resourcename,
  249. resourcesize = Resourcesize,
  250. resourcetype = 0,
  251. resourceurl = APP.ResourceAddTwo.videopath,
  252. schoolid = APP.UserInfo.Schoolid
  253. };
  254. });
  255. if (Suffix.Equals("FLV"))
  256. {
  257. Suffix = "flv";
  258. }
  259. else if (Suffix.Equals("AVI"))
  260. {
  261. Suffix = "avi";
  262. }
  263. else
  264. {
  265. Suffix = "mp4";
  266. }
  267. model_ResourceAdd.suffix = Suffix;
  268. //model_ResourceAdd.uid = 0;//zxy
  269. int code = @interface.ResourceAdd(model_ResourceAdd);
  270. if (code == 0)
  271. {
  272. Dispatcher.Invoke(() =>
  273. {
  274. btnStart.IsEnabled = true;
  275. book_list.IsEnabled = true;
  276. cmbTeachingMaterial.IsEnabled = true;
  277. num = 99;
  278. times.Stop();
  279. pgbProcess.Value = 100;
  280. lbProcess.Content = "100%";
  281. MessageWindow.Show("视频上传成功!");
  282. tip_outer.Visibility = Visibility.Collapsed;
  283. ChangeTextEvents("上传成功", i);
  284. Hide();
  285. });
  286. }
  287. else
  288. {
  289. Dispatcher.Invoke(() =>
  290. {
  291. btnStart.IsEnabled = true;
  292. book_list.IsEnabled = true;
  293. cmbTeachingMaterial.IsEnabled = true;
  294. times.Stop();
  295. tip_outer.Visibility = Visibility.Collapsed;
  296. MessageWindow.Show(APP.ServerMsg);
  297. });
  298. }
  299. }
  300. else
  301. {
  302. Dispatcher.Invoke(() =>
  303. {
  304. btnStart.IsEnabled = true;
  305. book_list.IsEnabled = true;
  306. cmbTeachingMaterial.IsEnabled = true;
  307. times.Stop();
  308. tip_outer.Visibility = Visibility.Collapsed;
  309. MessageWindow.Show(ErrMessage);
  310. });
  311. }
  312. }
  313. catch (Exception ex)
  314. {
  315. Dispatcher.Invoke(() =>
  316. {
  317. btnStart.IsEnabled = true;
  318. book_list.IsEnabled = true;
  319. cmbTeachingMaterial.IsEnabled = true;
  320. times.Stop();
  321. tip_outer.Visibility = Visibility.Collapsed;
  322. MessageWindow.Show("视频上传失败!");
  323. APP.IsUpLoad = false;
  324. Hide();
  325. LogHelper.WriteErrLog("【UploadWindow】(BtnStart_Click)" + ex.Message, ex);
  326. });
  327. }
  328. }
  329. int num = 0;
  330. /// <summary>
  331. /// 计时器
  332. /// </summary>
  333. /// <param name="sender"></param>
  334. /// <param name="e"></param>
  335. private void Times_ElapsedClick(object sender, System.Timers.ElapsedEventArgs e)
  336. {
  337. Dispatcher.Invoke(() =>
  338. {
  339. pgbProcess.Value = num;
  340. lbProcess.Content = num.ToString() + "%";
  341. if (num < 99)
  342. {
  343. num++;
  344. times.Interval += (num / 2);
  345. }
  346. else
  347. {
  348. times.Stop();
  349. }
  350. });
  351. }
  352. }
  353. public class LoginPageData : NotifyModel
  354. {
  355. public ObservableCollection<ComboBoxBean> bookList { get; set; }
  356. public ObservableCollection<ComboBoxBean> zhangjieList { get; set; }
  357. public LoginPageData()
  358. {
  359. bookList = new ObservableCollection<ComboBoxBean>();
  360. zhangjieList = new ObservableCollection<ComboBoxBean>();
  361. }
  362. }
  363. }