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

CreateAMicroLessonWindow.xaml.cs 14KB

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