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

CreateAMicroLessonWindow.xaml.cs 13KB

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