星火直播PC
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

ToolbarWindow.xaml.cs 32KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections.ObjectModel;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Windows;
  8. using System.Windows.Controls;
  9. using System.Windows.Data;
  10. using System.Windows.Documents;
  11. using System.Windows.Input;
  12. using System.Windows.Media;
  13. using System.Windows.Media.Imaging;
  14. using System.Windows.Shapes;
  15. using XHZB.Model;
  16. using Common.ZB;
  17. using XHZB.Desktop.Utils;
  18. using Common.system;
  19. using System.Windows.Media.Animation;
  20. using System.Threading;
  21. using XHZB.Desktop.WebSocket;
  22. namespace XHZB.Desktop
  23. {
  24. /// <summary>
  25. /// ToolbarWindow.xaml 的交互逻辑
  26. /// </summary>
  27. public partial class ToolbarWindow : Window
  28. {
  29. #region 字段
  30. /// <summary>
  31. /// 屏幕宽
  32. /// </summary>
  33. internal double pwidth = SystemParameters.PrimaryScreenWidth;
  34. /// <summary>
  35. /// 屏幕高
  36. /// </summary>
  37. internal double pHeight = SystemParameters.PrimaryScreenHeight;
  38. /// <summary>
  39. /// 工具栏数据
  40. /// </summary>
  41. internal ToolbarModel pageData = new ToolbarModel();
  42. /// <summary>
  43. /// 是否已打开课堂工具二级列表
  44. /// </summary>
  45. private bool heibanshow = false;
  46. private bool isTool = true;
  47. #region 当前已打开页面
  48. /// <summary>
  49. /// 是否已打开个人空间
  50. /// </summary>
  51. public static bool IsOpenUserCenterWindow = false;
  52. /// <summary>
  53. /// 是否已打开课堂点名
  54. /// </summary>
  55. public static bool IsOpenRollCallWindow = false;
  56. /// <summary>
  57. /// 是否已打开考勤页面
  58. /// </summary>
  59. public static bool IsOpenAttendanceWindow = false;
  60. #endregion 当前已打开页面
  61. #endregion
  62. #region 初始化
  63. public ToolbarWindow()
  64. {
  65. InitializeComponent();
  66. txbName.Text = APP.LoginUser.username;
  67. heiban_btn.Click += Heiban_btn_Click;
  68. pizhu_btn.Click += Pizhu_btn_Click;
  69. Topmost = true;
  70. Left = pwidth - 300;
  71. Top = (pHeight - 568) / 2;
  72. pageData.menuList.Add(new ToolbarMenu()
  73. {
  74. Name = "个人空间",
  75. Pic = "../Images/ToolBar/我的备课@2x.png"
  76. });
  77. pageData.menuList.Add(new ToolbarMenu()
  78. {
  79. Name = "直播",
  80. Pic = "../Images/ToolBar/直播@2x.png"
  81. });
  82. pageData.menuList.Add(new ToolbarMenu()
  83. {
  84. Name = "抢答点名",
  85. Pic = "../Images/ToolBar/抢答@2x.png"
  86. });
  87. pageData.menuList.Add(new ToolbarMenu()
  88. {
  89. Name = "课堂工具",
  90. Pic = "../Images/ToolBar/黑板01@2x.png"
  91. });
  92. pageData.menuList.Add(new ToolbarMenu()
  93. {
  94. Name = "本节考勤",
  95. Pic = "../Images/ToolBar/本节考勤01@2x.png"
  96. });
  97. pageData.menuList.Add(new ToolbarMenu()
  98. {
  99. Name = "结束课堂",
  100. Pic = "../Images/ToolBar/下课@2x.png"
  101. });
  102. DataContext = pageData;
  103. Thread t = new Thread(new ThreadStart(startSocket))
  104. {
  105. IsBackground = true
  106. };
  107. t.Start();
  108. }
  109. #endregion
  110. #region 事件
  111. /// <summary>
  112. /// 模块点击
  113. /// </summary>
  114. /// <param name="sender"></param>
  115. /// <param name="e"></param>
  116. private void toolbar_item_Click(object sender, RoutedEventArgs e)
  117. {
  118. int clickindex = 0;
  119. List<Button> buttons = VTHelper.FindChilds<Button>(toolbar_list, "toolbar_item");
  120. for (int i = 0; i < buttons.Count; i++)
  121. {
  122. if (buttons[i] == sender)
  123. {
  124. clickindex = i;
  125. break;
  126. }
  127. }
  128. ToolbarMenu item = pageData.menuList[clickindex];
  129. if (clickindex == 0)//个人空间
  130. {
  131. #region 关闭冲突页面
  132. if (IsOpenUserCenterWindow)
  133. {
  134. if (APP.W_UserCenterWindow != null && !APP.W_UserCenterWindow.IsFocused)
  135. {
  136. APP.W_UserCenterWindow.Focus();
  137. }
  138. return;
  139. }
  140. else
  141. {
  142. CloseOrHideWindowPage();
  143. }
  144. #endregion 关闭冲突页面
  145. try
  146. {
  147. HideLevel2();
  148. if (APP.W_UserCenterWindow != null && !APP.W_UserCenterWindow.IsFocused)
  149. {
  150. APP.W_UserCenterWindow.Focus();
  151. }
  152. else
  153. {
  154. APP.W_UserCenterWindow = new UserCenterWindow();
  155. APP.W_UserCenterWindow.Show();
  156. APP.W_UserCenterWindow.Closed += UserCenterWindow_Closed;
  157. }
  158. IsOpenUserCenterWindow = true;
  159. }
  160. catch (Exception ex)
  161. {
  162. IsOpenUserCenterWindow = false;
  163. APP.W_UserCenterWindow = null;
  164. LogHelper.WriteErrLog("【个人空间(toolbar_item_Click)" + ex.Message, ex);
  165. }
  166. }
  167. else if (clickindex == 1)//直播
  168. {
  169. HideLevel2();
  170. pageData.tongping = !pageData.tongping;
  171. if (pageData.tongping&& isTool)
  172. {
  173. isTool = false;
  174. if (StartLive(out string ErrMessage))
  175. {
  176. pageData.menuList[1].Pic = "../Images/ToolBar/img_shared_1.gif";
  177. pageData.menuList[1].Name = "正在直播";
  178. if (APP.W_CameraWindow == null)
  179. {
  180. APP.W_CameraWindow = new CameraWindow();
  181. APP.W_CameraWindow.Topmost = true;
  182. APP.W_CameraWindow.Left = pwidth - 300;
  183. APP.W_CameraWindow.Top = 0;
  184. }
  185. APP.W_CameraWindow.Show();
  186. }
  187. else
  188. {
  189. pageData.tongping = !pageData.tongping;
  190. MessageWindow.Show(ErrMessage);
  191. }
  192. }
  193. }
  194. else if (clickindex == 2)//抢答点名
  195. {
  196. HideLevel2();
  197. try
  198. {
  199. #region 关闭冲突页面
  200. if (IsOpenRollCallWindow)
  201. {
  202. return;
  203. }
  204. else
  205. {
  206. CloseOrHideWindowPage();
  207. }
  208. #endregion 关闭冲突页面
  209. if (APP.W_RollCallWindow == null)
  210. {
  211. APP.W_RollCallWindow = new RollCallWindow();
  212. APP.W_RollCallWindow.click_closeClick += RollCallWindow_click_closeClick;
  213. }
  214. else
  215. {
  216. APP.W_RollCallWindow.Initialize();
  217. }
  218. APP.W_RollCallWindow.Owner = this;
  219. //ZSocketServer.getInstance().addWin(rollCallWindow);
  220. IsOpenRollCallWindow = true;
  221. APP.W_RollCallWindow.Show();
  222. }
  223. catch (Exception ex)
  224. {
  225. IsOpenRollCallWindow = false;
  226. APP.W_RollCallWindow = null;
  227. LogHelper.WriteErrLog("【抢答点名(toolbar_item_Click)" + ex.Message, ex);
  228. }
  229. }
  230. else if (clickindex == 3)//课堂工具。
  231. {
  232. try
  233. {
  234. heibanshow = !heibanshow;
  235. List<DependencyObject> list = new List<DependencyObject>
  236. {
  237. heiban_btn,
  238. pizhu_btn
  239. };
  240. hideOrShow(heibanshow, ketangTool, list);
  241. }
  242. catch (Exception ex)
  243. {
  244. LogHelper.WriteErrLog("【课堂工具(toolbar_item_Click)" + ex.Message, ex);
  245. }
  246. }
  247. else if (clickindex == 4)//本节考勤
  248. {
  249. HideLevel2();
  250. try
  251. {
  252. showKaoqin();
  253. }
  254. catch (Exception ex)
  255. {
  256. LogHelper.WriteErrLog("【考勤(toolbar_item_Click)" + ex.Message, ex);
  257. }
  258. }
  259. else if (clickindex == 5)//结束课堂。
  260. {
  261. if (MessageWindow.Show("是否结束课堂?", "提示", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
  262. {
  263. closeAction();
  264. }
  265. }
  266. }
  267. /// <summary>
  268. /// 个人空间关闭
  269. /// </summary>
  270. /// <param name="sender"></param>
  271. /// <param name="e"></param>
  272. private void UserCenterWindow_Closed(object sender, EventArgs e)
  273. {
  274. APP.W_UserCenterWindow = null;
  275. IsOpenUserCenterWindow = false;
  276. }
  277. /// <summary>
  278. /// 课堂点名关闭
  279. /// </summary>
  280. private void RollCallWindow_click_closeClick()
  281. {
  282. IsOpenRollCallWindow = false;
  283. APP.W_RollCallWindow = null;
  284. }
  285. /// <summary>
  286. /// 考勤关闭
  287. /// </summary>
  288. /// <param name="sender"></param>
  289. /// <param name="e"></param>
  290. private void AttendanceWindow_Closed(object sender, EventArgs e)
  291. {
  292. IsOpenAttendanceWindow = false;
  293. APP.W_AttendanceWindow = null;
  294. }
  295. /// <summary>
  296. /// 考勤
  297. /// </summary>
  298. private void showKaoqin()
  299. {
  300. try
  301. {
  302. #region 关闭冲突页面
  303. if (IsOpenAttendanceWindow)
  304. {
  305. return;
  306. }
  307. else
  308. {
  309. CloseOrHideWindowPage();
  310. }
  311. #endregion 关闭冲突页面
  312. if (APP.W_AttendanceWindow == null)
  313. {
  314. APP.W_AttendanceWindow = new AttendanceWindow
  315. {
  316. Owner = this
  317. };
  318. APP.W_AttendanceWindow.Closed += AttendanceWindow_Closed;
  319. }
  320. else
  321. {
  322. APP.W_AttendanceWindow.Initialize();
  323. }
  324. IsOpenAttendanceWindow = true;
  325. APP.W_AttendanceWindow.Show();
  326. }
  327. catch (Exception ex)
  328. {
  329. IsOpenAttendanceWindow = false;
  330. APP.W_AttendanceWindow = null;
  331. LogHelper.WriteErrLog("【考勤(toolbar_item_Click)" + ex.Message, ex);
  332. }
  333. //}
  334. }
  335. /// <summary>
  336. /// 黑板
  337. /// </summary>
  338. /// <param name="sender"></param>
  339. /// <param name="e"></param>
  340. private void Heiban_btn_Click(object sender, RoutedEventArgs e)
  341. {
  342. try
  343. {
  344. heibanshow = !heibanshow;
  345. #region 关闭冲突页面
  346. CloseOrHideWindowPage();
  347. #endregion 关闭冲突页面
  348. List<DependencyObject> list = new List<DependencyObject>
  349. {
  350. heiban_btn,
  351. pizhu_btn
  352. };
  353. hideOrShow(heibanshow, ketangTool, list);
  354. if (APP.W_ZBlackboardWindow == null)
  355. {
  356. APP.W_ZBlackboardWindow = new ZBlackboardWindow
  357. {
  358. Topmost = true,
  359. Width = pwidth,
  360. Height = pHeight,
  361. Left = 0,
  362. Top = 0,
  363. Owner = this
  364. };
  365. //APP.W_ZBlackboardWindow.click_closeClick += BlackboardWin2_click_closeClick;
  366. }
  367. //ZSocketServer.getInstance().addWin(blackboardWin2);
  368. APP.W_ZBlackboardWindow.ShowDialog();
  369. }
  370. catch (Exception ex)
  371. {
  372. LogHelper.WriteErrLog("【黑板(Heiban_btn_Click)" + ex.Message, ex);
  373. }
  374. }
  375. /// <summary>
  376. /// 批注
  377. /// </summary>
  378. /// <param name="sender"></param>
  379. /// <param name="e"></param>
  380. private void Pizhu_btn_Click(object sender, RoutedEventArgs e)
  381. {
  382. try
  383. {
  384. heibanshow = !heibanshow;
  385. #region 关闭冲突页面
  386. //CloseOrHideWindowPage();
  387. #endregion 关闭冲突页面
  388. List<DependencyObject> list = new List<DependencyObject>
  389. {
  390. heiban_btn,
  391. pizhu_btn
  392. };
  393. hideOrShow(heibanshow, ketangTool, list);
  394. if (APP.W_PracticeWindow == null)
  395. {
  396. APP.W_PracticeWindow = new PracticeWindow();
  397. APP.W_PracticeWindow.click_closeClick += PracticeWin_click_closeClick;
  398. APP.W_PracticeWindow.Topmost = true;//zhangxueyang
  399. APP.W_PracticeWindow.Width = pwidth;
  400. APP.W_PracticeWindow.Height = pHeight;
  401. APP.W_PracticeWindow.Left = 0;
  402. APP.W_PracticeWindow.Top = 0;
  403. APP.W_PracticeWindow.Unloaded += PracticeWin_Unloaded;
  404. }
  405. APP.W_PracticeWindow.Owner = this;//zhangxueyang
  406. Hide();
  407. addimage();
  408. //ZSocketServer.getInstance().addWin(practiceWin);
  409. APP.W_PracticeWindow.ShowDialog();
  410. }
  411. catch (Exception ex)
  412. {
  413. LogHelper.WriteErrLog("【批注(Pizhu_btn_Click)" + ex.Message, ex);
  414. }
  415. }
  416. /// <summary>
  417. /// 添加截图到批注
  418. /// </summary>
  419. private void addimage()
  420. {
  421. string ImagePath = ImageHelper.GetTempImagePath();
  422. ImageHelper.GetScreenshot(new System.Drawing.Rectangle(0, 0, 0, 0), ImagePath,false,out BitmapImage bitmapImage,-1);
  423. APP.W_PracticeWindow.addImage(ImagePath);
  424. }
  425. /// <summary>
  426. /// 批注关闭
  427. /// </summary>
  428. private void PracticeWin_click_closeClick()
  429. {
  430. APP.W_PracticeWindow = null;
  431. }
  432. /// <summary>
  433. /// 批注关闭时显示工具栏
  434. /// </summary>
  435. /// <param name="sender"></param>
  436. /// <param name="e"></param>
  437. private void PracticeWin_Unloaded(object sender, RoutedEventArgs e)
  438. {
  439. Show();
  440. }
  441. /// <summary>
  442. /// 结束课堂
  443. /// </summary>
  444. private void closeAction()
  445. {
  446. //MyApp.myloading.Show();//加载等待
  447. try
  448. {
  449. //#region 加载通知栏图标
  450. //System.Windows.Forms.NotifyIcon ico = new System.Windows.Forms.NotifyIcon
  451. //{
  452. // Icon = new System.Drawing.Icon(FileToolsCommon.GetFileAbsolutePath("favicon256.ico")),
  453. // //this.Icon.DoubleClick += Icon_DoubleClick;//双击恢复 暂无
  454. // Visible = true
  455. //};
  456. //#endregion 加载通知栏图标
  457. //WindowState = WindowState.Minimized;
  458. //#region 关闭已打开窗口
  459. //pageData.tongping = !pageData.tongping;
  460. ////停止屏幕共享
  461. //if (pageData.tongping)
  462. //{
  463. // tongpingEnd();
  464. // pageData.menuList[1].Pic = "../Images/MainInterface/屏幕共享@2x.png";
  465. // pageData.menuList[1].Name = "屏幕共享";
  466. // gridAnimated.Visibility = Visibility.Collapsed;
  467. //}
  468. //if (blackboardWin2 != null)
  469. //{
  470. // blackboardWin2.Close();
  471. //}
  472. //if (rollCallWindow != null)
  473. //{
  474. // rollCallWindow.Close();
  475. //}
  476. //if (classroomExamWindow != null)
  477. //{
  478. // classroomExamWindow.Close();
  479. //}
  480. //if (classReportWindow != null)
  481. //{
  482. // classReportWindow.Close();
  483. //}
  484. //if (practiceWin != null)
  485. //{
  486. // practiceWin.Close();
  487. //}
  488. //if (classroomQuestionsWindow != null)
  489. //{
  490. // classroomQuestionsWindow.Close();
  491. //}
  492. //if (jietuWindow != null)
  493. //{
  494. // jietuWindow.Close();
  495. //}
  496. //if (attendanceWindow != null)
  497. //{
  498. // attendanceWindow.Close();
  499. //}
  500. //if (userCenterWindow != null)
  501. //{
  502. // userCenterWindow.Close();
  503. //}
  504. //#endregion 关闭已打开窗口
  505. //new Thread(o =>
  506. //{
  507. // StopNginx();
  508. // string msg = ZSocketMsgManger.classEnd();
  509. // ZSocketServer.getInstance().SendMessage(msg);
  510. // #region 清除没有上线人数的课堂数据
  511. // /*
  512. // * 上传本地数据库数据
  513. // * 判断该节课是否有人上线 若没人在线删除本节课数据。
  514. // * 可能存在多节课 1.多节课都没人上线,删除所有数据不上传。 2.多节课有上线的有没上线的情况,删除没有上线人数课的数据,将其余数据上传。
  515. // *
  516. // *
  517. // *
  518. // */
  519. // List<ClassData> classDataList = new List<ClassData>();
  520. // classDataList = ZSqliteManger.queryClassData();//取所有数据
  521. // if (classDataList.Count > 0)
  522. // {
  523. // for (int i = 0; i < classDataList.Count; i++)
  524. // {
  525. // if ("startclass".Equals(classDataList[i].api))//获取每节课的课堂id
  526. // {
  527. // List<ClassData> classroomidDataList = new List<ClassData>();
  528. // classroomidDataList = ZSqliteManger.queryClassRoomidData(classDataList[i].roomid);//取该节课的所有数据
  529. // for (int j = 0; j < classroomidDataList.Count; j++)
  530. // {
  531. // if ("sign".Equals(classroomidDataList[j].api))//若存在上线学生跳出循环
  532. // {
  533. // break;
  534. // }
  535. // if (j + 1 == classroomidDataList.Count)//若遍历完所有数据仍没有上线学生,删除该课堂id下所有数据
  536. // {
  537. // ZSqliteManger.clearClassData(classroomidDataList[j].roomid);
  538. // if (classroomidDataList[j].roomid == ZCommonData.roomid)
  539. // {
  540. // try
  541. // {
  542. // string path = ZConfig.classRoomImagePath();
  543. // if (Directory.Exists(path))
  544. // {
  545. // Directory.Delete(path, true);
  546. // }
  547. // }
  548. // catch (Exception ex)
  549. // {
  550. // LogHelper.WriteErrLog("ToolbarWindow(删除无效课堂文件夹报错:)" + ex.Message, ex);
  551. // }
  552. // }
  553. // }
  554. // }
  555. // }
  556. // }
  557. // classDataList = new List<ClassData>();
  558. // classDataList = ZSqliteManger.queryClassData();//取所有数据
  559. // }
  560. // #endregion
  561. // if (classDataList.Count > 0)
  562. // {
  563. // bool isRoomid = false;
  564. // for (int i = 0; i < classDataList.Count; i++)
  565. // {
  566. // if (classDataList[i].roomid == ZCommonData.roomid)
  567. // {
  568. // isRoomid = true;
  569. // }
  570. // }
  571. // if (isRoomid)
  572. // {
  573. // Dictionary<string, object> stopclass = new Dictionary<string, object>
  574. // {
  575. // { "roomid", ZCommonData.roomid },
  576. // { "endtime", ZNumUtil.unixTime() }
  577. // };
  578. // ZCommonData.askid = ZNumUtil.randomNum();
  579. // ZSqliteManger.insertClassData(new ClassData()
  580. // {
  581. // unix = ZNumUtil.unixTime(),
  582. // roomid = ZCommonData.roomid,
  583. // api = "stopclass",
  584. // json = ZJsonHelper.ToJson(stopclass),
  585. // askid = ZCommonData.askid
  586. // });
  587. // }
  588. // }
  589. // ZSocketServer.getInstance().Dispose();
  590. // if (classDataList.Count > 0)
  591. // {
  592. // MyApp.ZipFile();
  593. // }
  594. //else
  595. //{
  596. EndLive();
  597. //}
  598. WSocketClient.getInstance().SendMessage(SocketMsgManger.NolineMsg());
  599. Dispatcher.Invoke(new Action(() =>
  600. {
  601. System.Environment.Exit(0);
  602. }));
  603. }
  604. catch (Exception ex)
  605. {
  606. LogHelper.WriteErrLog("【ToolbarWindow】(closeAction)" + ex.Message, ex);
  607. }
  608. }
  609. /// <summary>
  610. /// 二级工具栏打开隐藏
  611. /// </summary>
  612. /// <param name="toolShow"></param>
  613. /// <param name="target"></param>
  614. /// <param name="contentList"></param>
  615. private void hideOrShow(bool toolShow, DependencyObject target, List<DependencyObject> contentList)
  616. {
  617. Storyboard story = new Storyboard();
  618. DoubleAnimation da = new DoubleAnimation();
  619. if (toolShow)
  620. {
  621. da.From = 0;
  622. da.To = 173;
  623. }
  624. else
  625. {
  626. da.From = 173.0;
  627. da.To = 0.0;
  628. }
  629. //可选属性:是否往返播放
  630. da.AutoReverse = false;
  631. //da.RepeatBehavior = RepeatBehavior.Forever;
  632. //da.RepeatBehavior = new RepeatBehavior(2);
  633. da.Duration = new Duration(TimeSpan.FromSeconds(0.3));
  634. Storyboard.SetTarget(da, target);
  635. Storyboard.SetTargetProperty(da, new PropertyPath("Width"));
  636. story.Children.Add(da);
  637. foreach (DependencyObject item in contentList)
  638. {
  639. DoubleAnimation da2 = new DoubleAnimation();
  640. if (toolShow)
  641. {
  642. da2.From = 0;
  643. da2.To = 1.0;
  644. }
  645. else
  646. {
  647. da2.From = 1.0;
  648. da2.To = 0.0;
  649. }
  650. da2.Duration = new Duration(TimeSpan.FromSeconds(0.1));
  651. Storyboard.SetTarget(da2, item);
  652. Storyboard.SetTargetProperty(da2, new PropertyPath("Opacity"));
  653. story.Children.Add(da2);
  654. }
  655. story.Begin();
  656. }
  657. /// <summary>
  658. /// 工具栏打开与缩放
  659. /// </summary>
  660. /// <param name="toolShow"></param>
  661. /// <param name="target"></param>
  662. /// <param name="contentList"></param>
  663. private void hideOrShowToolbar(bool toolShow, DependencyObject target, List<DependencyObject> contentList)
  664. {
  665. if (txbName.Visibility == Visibility.Visible)
  666. {
  667. txbName.Visibility = Visibility.Collapsed;
  668. }
  669. else
  670. {
  671. txbName.Visibility = Visibility.Visible;
  672. }
  673. Storyboard story = new Storyboard();
  674. DoubleAnimation da = new DoubleAnimation();
  675. if (toolShow)
  676. {
  677. da.From = 0;
  678. da.To = 450;
  679. }
  680. else
  681. {
  682. da.From = 450;
  683. da.To = 0.0;
  684. }
  685. //可选属性:是否往返播放
  686. da.AutoReverse = false;
  687. //da.RepeatBehavior = RepeatBehavior.Forever;
  688. //da.RepeatBehavior = new RepeatBehavior(2);
  689. da.Duration = new Duration(TimeSpan.FromSeconds(0.3));
  690. Storyboard.SetTarget(da, target);
  691. Storyboard.SetTargetProperty(da, new PropertyPath("Height"));
  692. story.Children.Add(da);
  693. foreach (DependencyObject item in contentList)
  694. {
  695. DoubleAnimation da2 = new DoubleAnimation();
  696. if (toolShow)
  697. {
  698. da2.From = 0;
  699. da2.To = 1.0;
  700. }
  701. else
  702. {
  703. da2.From = 1.0;
  704. da2.To = 0.0;
  705. }
  706. da2.Duration = new Duration(TimeSpan.FromSeconds(0.1));
  707. Storyboard.SetTarget(da2, item);
  708. Storyboard.SetTargetProperty(da2, new PropertyPath("Opacity"));
  709. story.Children.Add(da2);
  710. }
  711. story.Begin();
  712. }
  713. private void toolbar_win_Closed(object sender, EventArgs e)
  714. {
  715. }
  716. private void toolbar_win_ContentRendered(object sender, EventArgs e)
  717. {
  718. }
  719. private void toolbar_win_Loaded(object sender, RoutedEventArgs e)
  720. {
  721. }
  722. private void Window_MouseLeftButtonDown_1(object sender, MouseButtonEventArgs e)
  723. {
  724. time = NumUtil.unixTime();
  725. }
  726. private int time = NumUtil.unixTime();
  727. private void Rectangle_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
  728. {
  729. int temptime = NumUtil.unixTime();
  730. if (temptime - time < 1)
  731. {
  732. pageData.IsOpen = !pageData.IsOpen;
  733. List<DependencyObject> list = new List<DependencyObject>
  734. {
  735. toolbar_list
  736. };
  737. hideOrShowToolbar(pageData.IsOpen, toolbar, list);
  738. if (!pageData.IsOpen)
  739. {
  740. if (heibanshow)
  741. {
  742. List<DependencyObject> list3 = new List<DependencyObject>();
  743. heibanshow = false;
  744. list3.Add(heiban_btn);
  745. list3.Add(pizhu_btn);
  746. hideOrShow(heibanshow, ketangTool, list3);
  747. }
  748. }
  749. }
  750. }
  751. /// <summary>
  752. /// 工具栏移动事件
  753. /// </summary>
  754. /// <param name="sender"></param>
  755. /// <param name="e"></param>
  756. private void Rectangle_MouseMove(object sender, MouseEventArgs e)
  757. {
  758. if (e.LeftButton == MouseButtonState.Pressed)
  759. {
  760. DragMove();
  761. }
  762. }
  763. #endregion
  764. #region 方法
  765. /// <summary>
  766. /// 启动WS
  767. /// </summary>
  768. private void startSocket()
  769. {
  770. WSocketClient.getInstance().StartWsClient();
  771. }
  772. /// <summary>
  773. /// 关闭或隐藏页面
  774. /// </summary>
  775. private void CloseOrHideWindowPage()
  776. {
  777. if (IsOpenUserCenterWindow)
  778. {
  779. IsOpenUserCenterWindow = false;
  780. APP.W_UserCenterWindow.Close();
  781. }
  782. if (IsOpenRollCallWindow)
  783. {
  784. IsOpenRollCallWindow = false;
  785. APP.W_RollCallWindow.Hide();
  786. }
  787. if (IsOpenAttendanceWindow)
  788. {
  789. IsOpenAttendanceWindow = false;
  790. APP.W_AttendanceWindow.Hide();
  791. }
  792. }
  793. /// <summary>
  794. /// 隐藏二级菜单
  795. /// </summary>
  796. private void HideLevel2()
  797. {
  798. try
  799. {
  800. if (heibanshow)
  801. {
  802. heibanshow = !heibanshow;
  803. List<DependencyObject> lists = new List<DependencyObject>
  804. {
  805. heiban_btn,
  806. pizhu_btn
  807. };
  808. hideOrShow(heibanshow, ketangTool, lists);
  809. }
  810. }
  811. catch (Exception ex)
  812. {
  813. LogHelper.WriteErrLog("【工具栏(ToolbarWindow)" + ex.Message, ex);
  814. }
  815. }
  816. #endregion
  817. #region 直播
  818. /// <summary>
  819. /// 直播间节点和房号
  820. /// </summary>
  821. string NodeKey = "live/test";
  822. /// <summary>
  823. /// 开始直播
  824. /// </summary>
  825. public bool StartLive(out string ErrMessage)
  826. {
  827. try
  828. {
  829. WSocketClient.getInstance().SendMessage(SocketMsgManger.GetIntoMsg());
  830. NodeKey = "live/"+APP.ClassroomAdd.ToString();
  831. System.Drawing.Size DesktopSize = PrimaryScreen.DESKTOP;
  832. //开始直播
  833. if(APP.FFmpeg.StartLiveRecordingVideo(APP.RTMPServerPath, NodeKey, DesktopSize,out ErrMessage))
  834. {
  835. return true;
  836. }
  837. else
  838. {
  839. return false;
  840. }
  841. }
  842. catch (Exception ex)
  843. {
  844. ErrMessage = "无法开始直播:" + ex.Message;
  845. LogHelper.WriteErrLog(ErrMessage, ex);
  846. return false;
  847. }
  848. }
  849. /// <summary>
  850. /// 结束直播
  851. /// </summary>
  852. public void EndLive()
  853. {
  854. APP.FFmpeg.StopLive();
  855. }
  856. #endregion
  857. }
  858. /// <summary>
  859. /// 工具栏模型
  860. /// </summary>
  861. public class ToolbarModel : NotifyModel
  862. {
  863. public ObservableCollection<ToolbarMenu> menuList { get; set; }
  864. internal bool _tongping = false;
  865. public bool tongping
  866. {
  867. get => _tongping;
  868. set { _tongping = value; OnPropertyChanged("tongping"); }
  869. }
  870. internal bool _IsOpen = true;
  871. public bool IsOpen
  872. {
  873. get => _IsOpen;
  874. set { _IsOpen = value; OnPropertyChanged("IsOpen"); }
  875. }
  876. public ToolbarModel()
  877. {
  878. menuList = new ObservableCollection<ToolbarMenu>();
  879. }
  880. }
  881. /// <summary>
  882. /// 工具栏菜单模型
  883. /// </summary>
  884. public class ToolbarMenu : NotifyModel
  885. {
  886. internal string _name;
  887. public string Name
  888. {
  889. get => _name;
  890. set { _name = value; OnPropertyChanged("Name"); }
  891. }
  892. internal string _Pic;
  893. public string Pic
  894. {
  895. get => _Pic;
  896. set { _Pic = value; OnPropertyChanged("Pic"); }
  897. }
  898. }
  899. }