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

CreateAMicroLessonWindow.xaml.cs 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  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 ModelWkData { WkPath = wkpath, WkName = wkName, WkCreateDateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") };
  226. }
  227. try
  228. {
  229. //创建文件夹
  230. FileToolsCommon.CreateDirectory(App.WKData.WkPath);
  231. FileToolsCommon.DeleteDirectory(wkpath + "temp");
  232. FileToolsCommon.DeleteDirectory(wkpath + "_temppath");
  233. }
  234. catch (Exception ex)
  235. {
  236. LogHelper.Logerror.Error("【微课创建课程】文件夹创建删除失败:" + ex.Message, ex);
  237. }
  238. //存储文件
  239. FileToolsCommon.SetConfigValue("VideoSavePath", storagePath);
  240. App.ReadDrawData();
  241. }
  242. catch (Exception ex)
  243. {
  244. LogHelper.Logerror.Error("【微课创建课程】读取课堂数据失败:" + ex.Message, ex);
  245. }
  246. });
  247. if (App.W_XHMicroLessonSystemWindow == null)
  248. {
  249. App.W_XHMicroLessonSystemWindow = new MainWindow();
  250. }
  251. App.W_XHMicroLessonSystemWindow.Show();
  252. LblCreate.Visibility = Visibility.Hidden;
  253. Hide();
  254. }
  255. /// <summary>
  256. /// 窗体移动
  257. /// </summary>
  258. /// <param name="sender">
  259. /// </param>
  260. /// <param name="e">
  261. /// </param>
  262. private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  263. {
  264. DragMove();
  265. }
  266. #endregion 事件
  267. /// <summary>
  268. /// 检测APP更新
  269. /// </summary>
  270. private void GetNewApp()
  271. {
  272. new Thread(o =>
  273. {
  274. //读取本地
  275. App.ReadServiceAddressData();
  276. int versionThis = int.Parse(FileToolsCommon.GetConfigValue("VersionCode"));
  277. if (versionThis < 0)
  278. {
  279. //软件是否更新,版本号小于0不更新
  280. return;
  281. }
  282. string url = App.apiUrl + "/sapi/apprecord/get_new";
  283. string result = ZHttpUtil.PostStr(url, "{}");
  284. var resultObj = JsonHelper.JsonToObj<ResultVo<ModelApp>>(result);
  285. if (result != null && resultObj.code == 0)
  286. {
  287. if (resultObj.obj != null)
  288. {
  289. try
  290. {
  291. int versionCode = resultObj.obj.versioncode;
  292. if (versionThis < versionCode)
  293. {
  294. Dispatcher.Invoke(() =>
  295. {
  296. string pathTemp = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
  297. FileToolsCommon.CreateDirectory(pathTemp);
  298. AppUpdateShow(resultObj.obj);
  299. });
  300. }
  301. }
  302. catch (Exception ex)
  303. {
  304. LogHelper.Logerror.Error("【检查更新】(getNewApp)版本号错误:" + ex.Message, ex);
  305. }
  306. }
  307. }
  308. }).Start();
  309. }
  310. /// <summary>
  311. /// 应用更新
  312. /// </summary>
  313. /// <param name="app">
  314. /// </param>
  315. private void AppUpdateShow(ModelApp app)
  316. {
  317. AppUpdateWin win = new AppUpdateWin(app)
  318. {
  319. Topmost = true,
  320. Owner = this
  321. };
  322. win.Show();
  323. }
  324. private void Window_Loaded(object sender, RoutedEventArgs e)
  325. {
  326. GetNewApp();
  327. }
  328. private void Window_Closed(object sender, EventArgs e)
  329. {
  330. Application.Current.Shutdown();
  331. }
  332. }
  333. }