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

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