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

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