星火微课系统客户端
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

CreateAMicroLessonWindow.xaml.cs 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  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 : Window
  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 = 0;
  56. /// <summary>
  57. /// 加载录播图
  58. /// </summary>
  59. private void LoadingCarouseImg()
  60. {
  61. new Thread(new ThreadStart(new Action(() =>
  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(new ThreadStart(new Action(() =>
  81. {
  82. while (true)
  83. {
  84. for (double i = ImgMove; i < ImgWidth; i += ImgMove)
  85. {
  86. Dispatcher.Invoke(() =>
  87. {
  88. if (Math.Abs(i + ImgMove) < ImgWidth)
  89. {
  90. //图片移动轮播
  91. SplCarouse.Margin = new Thickness(SplCarouse.Margin.Left - ImgMove, 0, 0, 0);
  92. }
  93. else
  94. {
  95. if (ImgNumIndex >= 2)
  96. {
  97. ImgNumIndex = 0;
  98. SplCarouse.Margin = new Thickness(0, 0, 0, 0);
  99. }
  100. else
  101. {
  102. ImgNumIndex++;
  103. SplCarouse.Margin = new Thickness(-(ImgNumIndex * ImgWidth), 0, 0, 0);
  104. }
  105. }
  106. });
  107. Thread.Sleep(3);
  108. }
  109. bool IsBreak = false;
  110. Dispatcher.Invoke(() =>
  111. {
  112. if (this.Visibility != Visibility.Visible)
  113. {
  114. SplCarouse.Margin = new Thickness(0);
  115. IsBreak = true;
  116. }
  117. });
  118. Thread.Sleep(5000);
  119. if (IsBreak)
  120. {
  121. break;
  122. }
  123. }
  124. }))).Start();
  125. }
  126. /// <summary>
  127. /// 轮播图切换
  128. /// </summary>
  129. /// <param name="sender">
  130. /// </param>
  131. /// <param name="e">
  132. /// </param>
  133. private void TimesCarouse_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
  134. {
  135. //SplCarouse
  136. //ImgCarouse1
  137. }
  138. #endregion 轮播图
  139. #region 事件
  140. /// <summary>
  141. /// 关闭
  142. /// </summary>
  143. /// <param name="sender">
  144. /// </param>
  145. /// <param name="e">
  146. /// </param>
  147. private void BtnDown_Click(object sender, RoutedEventArgs e)
  148. {
  149. MessageBoxResult dr = MessageWindow.Show("确定退出系统?", "提示", MessageBoxButton.OKCancel);
  150. if (dr == MessageBoxResult.OK)
  151. {
  152. System.Environment.Exit(0);
  153. }
  154. else
  155. {
  156. return;
  157. }
  158. }
  159. /// <summary>
  160. /// 浏览
  161. /// </summary>
  162. /// <param name="sender">
  163. /// </param>
  164. /// <param name="e">
  165. /// </param>
  166. private void BtnBrowse_Click(object sender, RoutedEventArgs e)
  167. {
  168. //string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
  169. ofd = new FolderBrowserDialog();
  170. result = ofd.ShowDialog();
  171. if (result == System.Windows.Forms.DialogResult.OK)
  172. {
  173. if (ofd.SelectedPath != "")
  174. {
  175. txbStoragePath.Text = ofd.SelectedPath;
  176. }
  177. }
  178. }
  179. private bool IsPressButton = false;
  180. /// <summary>
  181. /// 开始
  182. /// </summary>
  183. /// <param name="sender">
  184. /// </param>
  185. /// <param name="e">
  186. /// </param>
  187. private async void BtnStart_Click(object sender, RoutedEventArgs e)
  188. {
  189. #region 防止连击
  190. if (IsPressButton)
  191. {
  192. return;
  193. }
  194. else
  195. {
  196. IsPressButton = true;
  197. new Thread(new ThreadStart(new Action(() =>
  198. {
  199. Thread.Sleep(500);
  200. IsPressButton = false;
  201. }))).Start();
  202. }
  203. #endregion 防止连击
  204. #region 合法性判断
  205. if (string.IsNullOrWhiteSpace(txbExplainName.Text.Trim()))
  206. {
  207. MessageWindow.Show("讲解名称不可为空!");
  208. return;
  209. }
  210. if (string.IsNullOrWhiteSpace(txbStoragePath.Text.Trim()))
  211. {
  212. MessageWindow.Show("路径不可为空!");
  213. return;
  214. }
  215. try
  216. {
  217. FileToolsCommon.CreateDirectory(txbStoragePath.Text.Trim());
  218. }
  219. catch (Exception ex)
  220. {
  221. MessageWindow.Show("路径无法访问,解决方案:\r\n1,检查路径是否可访问。\r\n2,关闭杀毒软件或信任软件。");
  222. return;
  223. }
  224. #endregion 合法性判断
  225. LblCreate.Visibility = Visibility.Visible;
  226. string wkpath = FileToolsCommon.GetLegalPath(txbStoragePath.Text) + txbExplainName.Text.Trim() + "/";
  227. string StoragePath = txbStoragePath.Text;
  228. string WkName = txbExplainName.Text;
  229. await Task.Run(() =>
  230. {
  231. try
  232. {
  233. //读取微课数据
  234. APP.ReadWkData(wkpath);
  235. if (APP.WKData == null)
  236. {
  237. APP.WKData = new Model_WKData
  238. {
  239. WkPath = wkpath,
  240. WkName = WkName,
  241. WkCreateDateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  242. };
  243. }
  244. try
  245. {
  246. //创建文件夹
  247. FileToolsCommon.CreateDirectory(APP.WKData.WkPath);
  248. FileToolsCommon.DeleteDirectory(wkpath + "temp");
  249. FileToolsCommon.DeleteDirectory(wkpath + "_temppath");
  250. }
  251. catch (Exception ex)
  252. {
  253. LogHelper.WriteErrLog("【微课创建课程】文件夹创建删除失败:" + ex.Message, ex);
  254. }
  255. //存储文件
  256. FileToolsCommon.SetConfigValue("VideoSavePath", StoragePath);
  257. APP.ReadDrawData();
  258. }
  259. catch (Exception ex)
  260. {
  261. LogHelper.WriteErrLog("【微课创建课程】读取课堂数据失败:" + ex.Message, ex);
  262. }
  263. });
  264. if (APP.W_XHMicroLessonSystemWindow == null)
  265. {
  266. APP.W_XHMicroLessonSystemWindow = new MainWindow();
  267. }
  268. APP.W_XHMicroLessonSystemWindow.Show();
  269. LblCreate.Visibility = Visibility.Hidden;
  270. Hide();
  271. }
  272. /// <summary>
  273. /// 窗体移动
  274. /// </summary>
  275. /// <param name="sender">
  276. /// </param>
  277. /// <param name="e">
  278. /// </param>
  279. private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  280. {
  281. DragMove();
  282. }
  283. #endregion 事件
  284. /// <summary>
  285. /// 检测APP更新
  286. /// </summary>
  287. private void getNewApp()
  288. {
  289. new Thread(o =>
  290. {
  291. //读取本地
  292. APP.ReadServiceAddressData();
  293. int versionThis = int.Parse(FileToolsCommon.GetConfigValue("VersionCode"));
  294. if (versionThis < 0)
  295. {
  296. //软件是否更新,版本号小于0不更新
  297. return;
  298. }
  299. string url = APP.apiUrl + "/sapi/apprecord/get_new";
  300. string result = HttpHelper.PostAndRespStr(url, "{}");
  301. Model.ResultVo<Model_App> resultObj = JsonHelper.JsonToObj<Model.ResultVo<Model_App>>(result);
  302. if (result != null && resultObj.code == 0)
  303. {
  304. if (resultObj.obj != null)
  305. {
  306. try
  307. {
  308. int versionCode = resultObj.obj.versioncode;
  309. if (versionThis < versionCode)
  310. {
  311. Dispatcher.Invoke(new Action(() =>
  312. {
  313. string pathTemp = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
  314. FileToolsCommon.CreateDirectory(pathTemp);
  315. appUpdateShow(resultObj.obj);
  316. }));
  317. }
  318. }
  319. catch (Exception ex)
  320. {
  321. LogHelper.WriteErrLog("【检查更新】(getNewApp)版本号错误:" + ex.Message, ex);
  322. }
  323. }
  324. }
  325. }).Start();
  326. }
  327. /// <summary>
  328. /// 应用更新
  329. /// </summary>
  330. /// <param name="app">
  331. /// </param>
  332. private void appUpdateShow(Model_App app)
  333. {
  334. AppUpdateWin win = new AppUpdateWin(app)
  335. {
  336. Topmost = true,
  337. Owner = this
  338. };
  339. win.Show();
  340. }
  341. private void Window_Loaded(object sender, RoutedEventArgs e)
  342. {
  343. getNewApp();
  344. }
  345. }
  346. }