星火微课系统客户端
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

CreateAMicroLessonWindow.xaml.cs 12KB

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