星火微课系统客户端
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

CreateAMicroLessonWindow.xaml.cs 12KB

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