星火微课系统客户端
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

CreateAMicroLessonWindow.xaml.cs 12KB

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