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

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