星火微课系统客户端
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

CreateAMicroLessonWindow.xaml.cs 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. using Common.system;
  2. using System;
  3. using System.Threading;
  4. using System.Threading.Tasks;
  5. using System.Windows;
  6. using System.Windows.Forms;
  7. using System.Windows.Input;
  8. using XHWK.Model;
  9. namespace XHWK.WKTool
  10. {
  11. /// <summary>
  12. /// 创建微课
  13. /// </summary>
  14. public partial class CreateAMicroLessonWindow
  15. {
  16. #region 字段
  17. private FolderBrowserDialog _ofd;
  18. private DialogResult _result;
  19. #endregion 字段
  20. /// <summary>
  21. /// 创建微课
  22. /// </summary>
  23. public CreateAMicroLessonWindow()
  24. {
  25. InitializeComponent();
  26. ResizeMode = ResizeMode.NoResize;
  27. txbStoragePath.Text = FileToolsCommon.GetConfigValue("VideoSavePath");
  28. var versionCode = FileToolsCommon.GetConfigValue("VersionCode");
  29. var versionName = FileToolsCommon.GetConfigValue("VersionName");
  30. var isDebug = FileToolsCommon.GetConfigValue("IsDebug");
  31. var debugStr = "测试版";
  32. if (isDebug == "1")
  33. {
  34. debugStr = "测试版";
  35. }
  36. else if (isDebug == "0")
  37. {
  38. debugStr = "正式版";
  39. }
  40. versionLabel.Content = debugStr + " v" + versionName + "(" + versionCode + ")";
  41. LoadingCarouseImg();
  42. }
  43. #region 轮播图
  44. /// <summary>
  45. /// 图片宽度,每次切换的宽度
  46. /// </summary>
  47. private double _imgWidth = 502.00;
  48. /// <summary>
  49. /// 轮播时移动增加的宽度
  50. /// </summary>
  51. private double _imgMove = 1;
  52. /// <summary>
  53. /// 当前展示的图片序号Index从0开始
  54. /// </summary>
  55. private int _imgNumIndex;
  56. /// <summary>
  57. /// 加载录播图
  58. /// </summary>
  59. private void LoadingCarouseImg()
  60. {
  61. new Thread(() =>
  62. {
  63. Thread.Sleep(3000);
  64. Dispatcher.Invoke(() =>
  65. {
  66. _imgWidth = ImgCarouse1.ActualWidth;
  67. _imgMove = _imgWidth / 250.00;
  68. CarouseImg();
  69. //timesCarouse = new System.Timers.Timer(2000);
  70. //timesCarouse.Elapsed += TimesCarouse_Elapsed; ;
  71. //timesCarouse.Start();
  72. });
  73. }).Start();
  74. }
  75. /// <summary>
  76. /// 轮播图
  77. /// </summary>
  78. private void CarouseImg()
  79. {
  80. new Thread(() =>
  81. {
  82. while (true)
  83. {
  84. for (double i = _imgMove; i < _imgWidth; i += _imgMove)
  85. {
  86. var i1 = i;
  87. Dispatcher.Invoke(() =>
  88. {
  89. if (Math.Abs(
  90. i1 + _imgMove) < _imgWidth)
  91. {
  92. //图片移动轮播
  93. SplCarouse.Margin = new Thickness(SplCarouse.Margin.Left - _imgMove, 0, 0, 0);
  94. }
  95. else
  96. {
  97. if (_imgNumIndex >= 2)
  98. {
  99. _imgNumIndex = 0;
  100. SplCarouse.Margin = new Thickness(0, 0, 0, 0);
  101. }
  102. else
  103. {
  104. _imgNumIndex++;
  105. SplCarouse.Margin = new Thickness(-(_imgNumIndex * _imgWidth), 0, 0, 0);
  106. }
  107. }
  108. });
  109. Thread.Sleep(3);
  110. }
  111. bool isBreak = false;
  112. Dispatcher.Invoke(() =>
  113. {
  114. if (this.Visibility != Visibility.Visible)
  115. {
  116. SplCarouse.Margin = new Thickness(0);
  117. isBreak = true;
  118. }
  119. });
  120. Thread.Sleep(5000);
  121. if (isBreak)
  122. {
  123. break;
  124. }
  125. }
  126. }).Start();
  127. }
  128. #endregion 轮播图
  129. #region 事件
  130. /// <summary>
  131. /// 关闭
  132. /// </summary>
  133. /// <param name="sender">
  134. /// </param>
  135. /// <param name="e">
  136. /// </param>
  137. private void BtnDown_Click(object sender, RoutedEventArgs e)
  138. {
  139. MessageBoxResult dr = MessageWindow.Show("确定退出系统?", "提示", MessageBoxButton.OKCancel);
  140. if (dr == MessageBoxResult.OK)
  141. {
  142. Environment.Exit(0);
  143. }
  144. }
  145. /// <summary>
  146. /// 浏览
  147. /// </summary>
  148. /// <param name="sender">
  149. /// </param>
  150. /// <param name="e">
  151. /// </param>
  152. private void BtnBrowse_Click(object sender, RoutedEventArgs e)
  153. {
  154. //string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
  155. _ofd = new FolderBrowserDialog();
  156. _result = _ofd.ShowDialog();
  157. if (_result == System.Windows.Forms.DialogResult.OK)
  158. {
  159. if (_ofd.SelectedPath != "")
  160. {
  161. txbStoragePath.Text = _ofd.SelectedPath;
  162. }
  163. }
  164. }
  165. private bool _isPressButton;
  166. /// <summary>
  167. /// 开始
  168. /// </summary>
  169. /// <param name="sender">
  170. /// </param>
  171. /// <param name="e">
  172. /// </param>
  173. private async void BtnStart_Click(object sender, RoutedEventArgs e)
  174. {
  175. #region 防止连击
  176. if (_isPressButton)
  177. {
  178. return;
  179. }
  180. else
  181. {
  182. _isPressButton = true;
  183. new Thread(() =>
  184. {
  185. Thread.Sleep(500);
  186. _isPressButton = false;
  187. }).Start();
  188. }
  189. #endregion 防止连击
  190. #region 合法性判断
  191. if (string.IsNullOrWhiteSpace(txbExplainName.Text.Trim()))
  192. {
  193. MessageWindow.Show("讲解名称不可为空!");
  194. return;
  195. }
  196. if (string.IsNullOrWhiteSpace(txbStoragePath.Text.Trim()))
  197. {
  198. MessageWindow.Show("路径不可为空!");
  199. return;
  200. }
  201. try
  202. {
  203. FileToolsCommon.CreateDirectory(txbStoragePath.Text.Trim());
  204. }
  205. catch (Exception)
  206. {
  207. MessageWindow.Show("路径无法访问,解决方案:\r\n1,检查路径是否可访问。\r\n2,关闭杀毒软件或信任软件。");
  208. return;
  209. }
  210. #endregion 合法性判断
  211. LblCreate.Visibility = Visibility.Visible;
  212. string wkpath = FileToolsCommon.GetLegalPath(txbStoragePath.Text) + txbExplainName.Text.Trim() + "/";
  213. string storagePath = txbStoragePath.Text;
  214. string wkName = txbExplainName.Text;
  215. await Task.Run(() =>
  216. {
  217. try
  218. {
  219. //读取微课数据
  220. App.ReadWkData(wkpath);
  221. if (App.WKData == null)
  222. {
  223. App.WKData = new Model_WKData
  224. {
  225. WkPath = wkpath,
  226. WkName = wkName,
  227. WkCreateDateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  228. };
  229. }
  230. try
  231. {
  232. //创建文件夹
  233. FileToolsCommon.CreateDirectory(App.WKData.WkPath);
  234. FileToolsCommon.DeleteDirectory(wkpath + "temp");
  235. FileToolsCommon.DeleteDirectory(wkpath + "_temppath");
  236. }
  237. catch (Exception ex)
  238. {
  239. LogHelper.WriteErrLog("【微课创建课程】文件夹创建删除失败:" + ex.Message, ex);
  240. }
  241. //存储文件
  242. FileToolsCommon.SetConfigValue("VideoSavePath", storagePath);
  243. App.ReadDrawData();
  244. }
  245. catch (Exception ex)
  246. {
  247. LogHelper.WriteErrLog("【微课创建课程】读取课堂数据失败:" + ex.Message, ex);
  248. }
  249. });
  250. if (App.W_XHMicroLessonSystemWindow == null)
  251. {
  252. App.W_XHMicroLessonSystemWindow = new MainWindow();
  253. }
  254. App.W_XHMicroLessonSystemWindow.Show();
  255. LblCreate.Visibility = Visibility.Hidden;
  256. Hide();
  257. }
  258. /// <summary>
  259. /// 窗体移动
  260. /// </summary>
  261. /// <param name="sender">
  262. /// </param>
  263. /// <param name="e">
  264. /// </param>
  265. private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  266. {
  267. DragMove();
  268. }
  269. #endregion 事件
  270. /// <summary>
  271. /// 检测APP更新
  272. /// </summary>
  273. private void GetNewApp()
  274. {
  275. new Thread(o =>
  276. {
  277. //读取本地
  278. App.ReadServiceAddressData();
  279. int versionThis = int.Parse(FileToolsCommon.GetConfigValue("VersionCode"));
  280. if (versionThis < 0)
  281. {
  282. //软件是否更新,版本号小于0不更新
  283. return;
  284. }
  285. string url = App.apiUrl + "/sapi/apprecord/get_new";
  286. string result = HttpHelper.PostAndRespStr(url, "{}");
  287. var resultObj = JsonHelper.JsonToObj<ResultVo<Model_App>>(result);
  288. if (result != null && resultObj.code == 0)
  289. {
  290. if (resultObj.obj != null)
  291. {
  292. try
  293. {
  294. int versionCode = resultObj.obj.versioncode;
  295. if (versionThis < versionCode)
  296. {
  297. Dispatcher.Invoke(() =>
  298. {
  299. string pathTemp = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
  300. FileToolsCommon.CreateDirectory(pathTemp);
  301. AppUpdateShow(resultObj.obj);
  302. });
  303. }
  304. }
  305. catch (Exception ex)
  306. {
  307. LogHelper.WriteErrLog("【检查更新】(getNewApp)版本号错误:" + ex.Message, ex);
  308. }
  309. }
  310. }
  311. }).Start();
  312. }
  313. /// <summary>
  314. /// 应用更新
  315. /// </summary>
  316. /// <param name="app">
  317. /// </param>
  318. private void AppUpdateShow(Model_App app)
  319. {
  320. AppUpdateWin win = new AppUpdateWin(app)
  321. {
  322. Topmost = true,
  323. Owner = this
  324. };
  325. win.Show();
  326. }
  327. private void Window_Loaded(object sender, RoutedEventArgs e)
  328. {
  329. GetNewApp();
  330. }
  331. private void Window_Closed(object sender, EventArgs e)
  332. {
  333. Environment.Exit(0);
  334. }
  335. }
  336. }