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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. using Common.system;
  2. using System;
  3. using System.Collections.ObjectModel;
  4. using System.Windows;
  5. using System.Windows.Controls;
  6. using System.Windows.Input;
  7. using XHWK.Model;
  8. using XHWK.WKTool.DAL;
  9. using static XHWK.WKTool.XHMicroLessonSystemWindow;
  10. namespace XHWK.WKTool
  11. {
  12. /// <summary>
  13. /// UploadWindow.xaml 的交互逻辑
  14. /// </summary>
  15. public partial class UploadWindow : Window
  16. {
  17. /// <summary>
  18. /// 调用接口
  19. /// </summary>
  20. private readonly Interface @interface = new Interface();
  21. /// <summary>
  22. /// 前台数据
  23. /// </summary>
  24. internal LoginPageData pageData = new LoginPageData();
  25. /// <summary>
  26. /// 文件名
  27. /// </summary>
  28. private string Resourcename = string.Empty;
  29. /// <summary>
  30. /// 文件大小
  31. /// </summary>
  32. private long Resourcesize = 0;
  33. /// <summary>
  34. /// 文件类型
  35. /// </summary>
  36. private string Suffix = string.Empty;
  37. /// <summary>
  38. /// 唯一编号
  39. /// </summary>
  40. private string Guid = string.Empty;
  41. //定义事件
  42. public event ChangeTextHandlers ChangeTextEvents;
  43. /// <summary>
  44. /// 当前视频的下标
  45. /// </summary>
  46. private int i = 0;
  47. public UploadWindow()
  48. {
  49. InitializeComponent();
  50. }
  51. /// <summary>
  52. /// 初始化
  53. /// </summary>
  54. public void Initialize(string _resourcename, long _resourcesize, string _suffix, string _guid,int _i)
  55. {
  56. i = _i;
  57. Resourcename = _resourcename;
  58. Resourcesize = _resourcesize;
  59. Suffix = _suffix;
  60. Guid = _guid;
  61. Tsubjectbook();
  62. }
  63. /// <summary>
  64. /// 教材接口调用
  65. /// </summary>
  66. /// <returns></returns>
  67. private void Tsubjectbook()
  68. {
  69. int code = @interface.TsubjectbookList();
  70. if (code == 0)
  71. {
  72. for (int i = 0; i < APP.TsubjectbookList.Count; i++)
  73. {
  74. pageData.bookList.Add(new ComboBoxBean()
  75. {
  76. Key = APP.TsubjectbookList[i].Lsbid,
  77. Value = $"{APP.TsubjectbookList[i].Subjectname} {APP.TsubjectbookList[i].Bookname}"
  78. });
  79. }
  80. book_list.SelectedIndex = 0;
  81. DataContext = pageData;
  82. Director();
  83. }
  84. else
  85. {
  86. MessageWindow.Show(APP.ServerMsg);
  87. }
  88. }
  89. /// <summary>
  90. /// 章节接口调用
  91. /// </summary>
  92. private void Director()
  93. {
  94. int selectIndex = book_list.SelectedIndex;
  95. if (selectIndex < 0)
  96. {
  97. selectIndex = 0;
  98. }
  99. int code = @interface.DirectorList(APP.TsubjectbookList[selectIndex].Lsbid, 2, APP.UserInfo.Userid);
  100. if (code == 0)
  101. {
  102. pageData.zhangjieList.Clear();
  103. pageData.zhangjieList.Add(new ComboBoxBean()
  104. {
  105. Key = 0,
  106. Value = "全部",
  107. });
  108. for (int i = 0; i < APP.DirectorList.Count; i++)
  109. {
  110. Model_DirectorList item = APP.DirectorList[i];
  111. pageData.zhangjieList.Add(new ComboBoxBean()
  112. {
  113. Key = item.directorid,
  114. Value = item.directorname
  115. });
  116. addChild(item);
  117. }
  118. cmbTeachingMaterial.SelectedIndex = 0;
  119. }
  120. else
  121. {
  122. MessageWindow.Show(APP.ServerMsg);
  123. }
  124. }
  125. /// <summary>
  126. /// 子章节递归
  127. /// </summary>
  128. /// <param name="directorList"></param>
  129. private void addChild(Model_DirectorList directorList)
  130. {
  131. if (directorList.children != null && directorList.children.Count > 0)
  132. {
  133. foreach (Model_DirectorList child in directorList.children)
  134. {
  135. pageData.zhangjieList.Add(new ComboBoxBean()
  136. {
  137. Key = child.directorid,
  138. Value = getSpace(child.directorlevel) + child.directorname
  139. });
  140. if (child.children != null && child.children.Count > 0)
  141. {
  142. addChild(child);
  143. }
  144. }
  145. }
  146. }
  147. /// <summary>
  148. /// 章节是否加空格符
  149. /// </summary>
  150. /// <param name="num"></param>
  151. /// <returns></returns>
  152. private string getSpace(int num)
  153. {
  154. string str = "";
  155. for (int i = 0; i < num; i++)
  156. {
  157. str += " ";
  158. }
  159. return str;
  160. }
  161. private void Window_Loaded(object sender, RoutedEventArgs e)
  162. {
  163. }
  164. private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  165. {
  166. }
  167. /// <summary>
  168. /// 教材下拉框改变事件
  169. /// </summary>
  170. /// <param name="sender"></param>
  171. /// <param name="e"></param>
  172. private void toolbar_list_SelectionChanged(object sender, SelectionChangedEventArgs e)
  173. {
  174. Director();
  175. }
  176. private void BtnDown_Click(object sender, RoutedEventArgs e)
  177. {
  178. Hide();
  179. }
  180. /// <summary>
  181. /// 上传到个人空间
  182. /// </summary>
  183. /// <param name="sender"></param>
  184. /// <param name="e"></param>
  185. private void BtnStart_Click(object sender, RoutedEventArgs e)
  186. {
  187. try
  188. {
  189. DAL_Upload dAL_Upload = new DAL_Upload();
  190. if (dAL_Upload.UploadVideoTwo(Guid, out string ErrMessage))
  191. {
  192. // converted: 0
  193. //createid: 80
  194. //directorid: 1009
  195. //duration: 39
  196. //imgUrl: ""
  197. //level: 2
  198. //lsbid: 40
  199. //mp4code: "h264"
  200. //resourcebelong: 3
  201. //resourceclass: 2
  202. //resourcecover: "12/resource/20200917/4f297df0-f8c0-11ea-adf5-81f24b97d4ff/weather_pic.jpg"
  203. //resourcename: "weather_pic"
  204. //resourcesize: 6105268
  205. //resourcetype: 0
  206. //resourceurl: "12/resource/20200917/4f297df0-f8c0-11ea-adf5-81f24b97d4ff/weather_pic.mp4"
  207. //schoolid: 12
  208. //suffix: "mp4"
  209. //uid: 80
  210. Model_ResourceAdd model_ResourceAdd = new Model_ResourceAdd
  211. {
  212. converted = 0,
  213. createid = APP.UserInfo.Userid,
  214. directorid = Convert.ToInt32(cmbTeachingMaterial.SelectedValue.ToString()),
  215. duration = APP.ResourceAddTwo.duration,
  216. imgUrl = "",
  217. level = 2,
  218. lsbid = Convert.ToInt32(book_list.SelectedValue.ToString()),
  219. mp4code = APP.ResourceAddTwo.mp4code,
  220. resourcebelong = 3,
  221. resourceclass = 2,
  222. resourcecover = APP.ResourceAddTwo.coverpath,
  223. resourcename = Resourcename,
  224. resourcesize = Resourcesize,
  225. resourcetype = 0,
  226. resourceurl = APP.ResourceAddTwo.videopath,
  227. schoolid = APP.UserInfo.Schoolid
  228. };
  229. if (Suffix.Equals("FLV"))
  230. {
  231. Suffix = "flv";
  232. }
  233. else if (Suffix.Equals("AVI"))
  234. {
  235. Suffix = "avi";
  236. }
  237. else
  238. {
  239. Suffix = "mp4";
  240. }
  241. model_ResourceAdd.suffix = Suffix;
  242. //model_ResourceAdd.uid = 0;//zxy
  243. int code = @interface.ResourceAdd(model_ResourceAdd);
  244. if (code == 0)
  245. {
  246. MessageWindow.Show("视频上传成功!");
  247. ChangeTextEvents("上传成功",i);
  248. Hide();
  249. }
  250. else
  251. {
  252. MessageWindow.Show(APP.ServerMsg);
  253. }
  254. }
  255. else
  256. {
  257. MessageWindow.Show(ErrMessage);
  258. }
  259. }
  260. catch (Exception ex)
  261. {
  262. MessageWindow.Show("视频上传失败!");
  263. Hide();
  264. LogHelper.WriteErrLog("【UploadWindow】(BtnStart_Click)" + ex.Message, ex);
  265. }
  266. }
  267. }
  268. public class LoginPageData : NotifyModel
  269. {
  270. public ObservableCollection<ComboBoxBean> bookList { get; set; }
  271. public ObservableCollection<ComboBoxBean> zhangjieList { get; set; }
  272. public LoginPageData()
  273. {
  274. bookList = new ObservableCollection<ComboBoxBean>();
  275. zhangjieList = new ObservableCollection<ComboBoxBean>();
  276. }
  277. }
  278. }