星火直播PC
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

RollCallWindow.xaml.cs 37KB

3 år sedan
3 år sedan
3 år sedan
3 år sedan
3 år sedan
3 år sedan
3 år sedan
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982
  1. using Common.system;
  2. using Newtonsoft.Json;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Collections.ObjectModel;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading;
  10. using System.Windows;
  11. using System.Windows.Input;
  12. using System.Windows.Threading;
  13. using XHZB.Desktop.Utils;
  14. using XHZB.Desktop.WebSocket;
  15. using XHZB.Model;
  16. namespace XHZB.Desktop
  17. {
  18. /// <summary>
  19. /// 点名抢答
  20. /// </summary>
  21. public partial class RollCallWindow : Window, SocketCallback
  22. {
  23. #region 值初始化
  24. /// <summary>
  25. /// 服务返回 0成功
  26. /// </summary>
  27. private readonly int serverReturnCode = 0;
  28. internal RollCallPageData pageData = new RollCallPageData();
  29. private readonly RegisterController registerController = new RegisterController();
  30. internal string backgroundOpacity = "0.5";
  31. private readonly Random rd = new Random();
  32. private readonly int[] iArrty = new int[3] { 201314, 201314, 201314 };
  33. private static string userids = string.Empty;
  34. private static string useridss = string.Empty;
  35. private static string useridsss = string.Empty;
  36. private static int ranNum = 201314;
  37. private readonly int[] iArray = new int[1];
  38. private static int returnNum = 0;
  39. //private bool isSjdm = false;
  40. internal double pwidth = SystemParameters.PrimaryScreenWidth;
  41. internal double pHeight = SystemParameters.PrimaryScreenHeight;
  42. private RollCallPerfectionWindow rollCallPerfectionWindow;
  43. /// <summary>
  44. /// 随机点名
  45. /// </summary>
  46. private bool isRollCall = false;
  47. /// <summary>
  48. /// 抢答
  49. /// </summary>
  50. private bool isRushToAnswer = false;
  51. public string BackgroundOpacity
  52. {
  53. get => backgroundOpacity;
  54. set => backgroundOpacity = value;
  55. }
  56. /// <summary>
  57. /// 随机几率 1高 2中 3低
  58. /// </summary>
  59. string flag = "1";
  60. int rNum = 999;
  61. #endregion 值初始化
  62. /// <summary>
  63. /// 课堂点名
  64. /// </summary>
  65. public RollCallWindow()
  66. {
  67. InitializeComponent();
  68. WindowStartupLocation = WindowStartupLocation.CenterScreen;
  69. if (!File.Exists(APP.dataPath + "randomProbability.txt")) //若为空
  70. {
  71. flag = "1";
  72. }
  73. else
  74. {
  75. flag = System.IO.File.ReadAllText(APP.dataPath + "randomProbability.txt", Encoding.Default);
  76. }
  77. Initialize();
  78. WSocketClient.getInstance().addWin(this);
  79. }
  80. /// <summary>
  81. /// 初始化
  82. /// </summary>
  83. public void Initialize()
  84. {
  85. userids = string.Empty;
  86. useridss = string.Empty;
  87. useridsss = string.Empty;
  88. returnNum = 0;
  89. rNum = 999;
  90. APP.RollCallList = new System.Collections.Generic.List<RollCallModel>();
  91. imgRandomRollCall.Visibility = Visibility.Visible;
  92. imgRandomRollCallTwo.Visibility = Visibility.Collapsed;
  93. imgAnswer.Visibility = Visibility.Visible;
  94. imgAnswerTwo.Visibility = Visibility.Collapsed;
  95. stpAnswer.Visibility = Visibility.Collapsed;
  96. //ToolbarWindow.IsNotOperation = true;
  97. IsRandomRollCallButton = false;
  98. //初始化配置文件
  99. //ZJConfigUtil.init();
  100. initPageData();
  101. //ZSocketServer.getInstance().addWin(this);
  102. }
  103. public void userListChange()
  104. {
  105. Console.WriteLine("本节考勤-渲染用户列表");
  106. Dispatcher.BeginInvoke(DispatcherPriority.Normal,
  107. new Action(() =>
  108. {
  109. receiveWsMsg(null);
  110. }));
  111. }
  112. public void receiveWsMsg(SocketModel msg)
  113. {
  114. if (!isRollCall && !isRushToAnswer)
  115. {
  116. initPageData();
  117. }
  118. if (msg != null && msg.c == 2021)
  119. {
  120. Console.WriteLine(msg);
  121. #region 去重
  122. for (int i = 0; i < pageData.userList.Count; i++)
  123. {
  124. if (msg.b.stid.ToString().Equals(pageData.userList[i].ID))
  125. {
  126. return;
  127. }
  128. }
  129. #endregion
  130. //Askstudent askstudent = new Askstudent
  131. //{
  132. // roomid = ZCommonData.roomid,
  133. // studentid = msg.body.userid
  134. //};
  135. //askstudent.asktid = ZCommonData.askid;
  136. //askstudent.schoolid = ZCommonData.loginUser.schoolid;
  137. //askstudent.createtime = DataProvider.TimestampTotalSeconds();
  138. //askstudent.studentselected = 0;
  139. //askstudent.radiocorrect = 0;
  140. //askstudent.classid = msg.body.classid;
  141. //ZSqliteManger.insertClassData(new ClassData()
  142. //{
  143. // unix = DataProvider.TimestampTotalSeconds(),
  144. // roomid = ZCommonData.roomid,
  145. // api = "askstudent",
  146. // json = ZJsonHelper.ToJson(askstudent),
  147. // askid = ZCommonData.askid
  148. //});
  149. System.Collections.Generic.List<RollCallModel> callList = APP.RollCallList;
  150. bool isUserid = true;
  151. //if (TeachingDataStatic.RollCallStatisticsList.Count > 0)//统计抢答
  152. //{
  153. // for (int i = 0; i < TeachingDataStatic.RollCallStatisticsList.Count; i++)
  154. // {
  155. // if (TeachingDataStatic.RollCallStatisticsList[i].userid == msg.body.userid)
  156. // {
  157. // TeachingDataStatic.RollCallStatisticsList[i].replies += 1;
  158. // isUserid = false;
  159. // break;
  160. // }
  161. // }
  162. //}
  163. if (isUserid)
  164. {//统计
  165. //Shared.TeachingData.rollCall = new RollCall
  166. //{
  167. // usertype = msg.usertype,
  168. // userid = msg.body.userid,
  169. // username = msg.body.username,
  170. // userpic = msg.body.userpic,
  171. // replies = 1
  172. //};
  173. //TeachingDataStatic.RollCallStatisticsList.Add(Shared.TeachingData.rollCall);
  174. //Shared.TeachingData.rollCall = new RollCall();
  175. }
  176. Dispatcher.Invoke(DispatcherPriority.Normal,
  177. new Action(() =>
  178. {
  179. //try
  180. //{
  181. // if (pageData.userList.Count > 0)
  182. // {
  183. // if (pageData.userList[pageData.userList.Count - 1].askid != msg.body.asktid)
  184. // {
  185. // pageData.userList.Clear();
  186. // }
  187. // }
  188. //}
  189. //catch (Exception ex)
  190. //{
  191. // LogHelper.WriteErrLog("【抢答】(receiveWsMsg)socket移除askid不一致用户," + ex.Message, ex);
  192. //}
  193. //renderView();
  194. returnNum++;
  195. if (returnNum <= 18)
  196. {
  197. string medal = "../Images/RollCall/02log-1.png";
  198. string attendance = "../Images/RollCall/attendance_3.png";
  199. if (returnNum == 1)
  200. {
  201. medal = "../Images/RollCall/rollCall_7.png";
  202. attendance = "../Images/RollCall/attendance_33.png";
  203. }
  204. else if (returnNum == 2)
  205. {
  206. medal = "../Images/RollCall/rollCall_5.png";
  207. attendance = "../Images/RollCall/attendance_33.png";
  208. }
  209. else if (returnNum == 3)
  210. {
  211. medal = "../Images/RollCall/rollCall_6.png";
  212. attendance = "../Images/RollCall/attendance_33.png";
  213. }
  214. string userpic = msg.b.stpic;
  215. if (ZCache.headDic.ContainsKey(userpic.Replace("/", "")))
  216. {
  217. userpic = ZCache.headDic[userpic.Replace("/", "")];
  218. }
  219. else
  220. {
  221. userpic = "../Images/RollCall/attendance_1.png";
  222. }
  223. pageData.userList.Add(new RollCallPageData()
  224. {
  225. Name = msg.b.stname,
  226. Attendance_33 = "Collapsed",
  227. Attendance_3 = "Visible",
  228. Pic = userpic,
  229. ID = msg.b.stid.ToString(),
  230. Attendance = attendance,
  231. Medal = medal,
  232. });
  233. stpAnswer.Visibility = Visibility.Visible;
  234. }
  235. txbNumberOfReplies.Text = returnNum.ToString();
  236. }));
  237. }
  238. }
  239. System.Collections.Generic.List<OnlineUserModel> raduser = new System.Collections.Generic.List<OnlineUserModel>();
  240. System.Collections.Generic.List<OnlineUserModel> userListNew = new System.Collections.Generic.List<OnlineUserModel>();
  241. private void initPageData()
  242. {
  243. Dispatcher.Invoke(DispatcherPriority.Normal,
  244. new Action(() =>
  245. {
  246. if (pageData.userList.Count > 0)
  247. {
  248. pageData.userList.Clear();
  249. }
  250. List<OnlineUserModel> userList = APP.OnlineUserList;
  251. userListNew = new List<OnlineUserModel>();
  252. string userlistStr = JsonHelper.ToJson(userList);
  253. userListNew = JsonToList<OnlineUserModel>(userlistStr);
  254. List<ClassStudentListModel> classStudentList = APP.ClassStudentList;
  255. for (int i = 0; i < classStudentList.Count; i++)
  256. {
  257. classStudentList[i].status = 0;
  258. for (int j = 0; j < userListNew.Count; j++)
  259. {
  260. if (classStudentList[i].studentid == userListNew[j].userid)
  261. {
  262. userListNew[j].num = classStudentList[i].num;
  263. }
  264. }
  265. }
  266. if (userListNew.Count > 0)
  267. {
  268. //OrderbyDescending 倒叙 OrderBy 顺序
  269. raduser = userListNew.OrderBy(x => x.num).ToList();
  270. }
  271. foreach (OnlineUserModel user in userListNew)
  272. {
  273. string userpic = user.userpic;
  274. if (ZCache.headDic.ContainsKey(userpic.Replace("/", "")))
  275. {
  276. userpic = ZCache.headDic[userpic.Replace("/", "")];
  277. }
  278. else
  279. {
  280. userpic = "../Images/RollCall/attendance_1.png";
  281. }
  282. pageData.userList.Add(new RollCallPageData()
  283. {
  284. Name = user.username,
  285. Attendance_33 = "Collapsed",
  286. Attendance_3 = "Visible",
  287. Pic = userpic,
  288. ID = user.userid.ToString(),
  289. Attendance = "../Images/RollCall/attendance_3.png"
  290. });
  291. foreach (ClassStudentListModel cl in classStudentList)
  292. {
  293. if (cl.studentid == user.userid)
  294. {
  295. cl.status = 1;
  296. }
  297. }
  298. }
  299. string notOnline = string.Empty;
  300. foreach (ClassStudentListModel cl in classStudentList)
  301. {
  302. if (cl.status == 0)
  303. {
  304. notOnline += cl.studentname + " ";
  305. }
  306. }
  307. if (!string.IsNullOrWhiteSpace(notOnline))
  308. {
  309. txbNotOnline.Text = notOnline;
  310. }
  311. else
  312. {
  313. txbNotOnline.Text = "暂无";
  314. }
  315. toolbar_list.DataContext = pageData;
  316. }));
  317. }
  318. internal static List<T> JsonToList<T>(string respstr)
  319. {
  320. JsonSerializer serializer = new JsonSerializer();
  321. StringReader sr = new StringReader(respstr);
  322. object o = serializer.Deserialize(new JsonTextReader(sr), typeof(List<T>));
  323. List<T> list = o as List<T>;
  324. return list;
  325. }
  326. /// <summary>
  327. /// 是否已经按下按钮
  328. /// </summary>
  329. public bool IsRandomRollCallButton = false;
  330. /// <summary>
  331. /// 随机点名
  332. /// </summary>
  333. /// <param name="sender"></param>
  334. /// <param name="e"></param>
  335. private void btnRandomRollCall_Click(object sender, RoutedEventArgs e)
  336. {
  337. if (!IsRandomRollCallButton)
  338. {
  339. IsRandomRollCallButton = true;
  340. userids = string.Empty;
  341. useridss = string.Empty;
  342. useridsss = string.Empty;
  343. returnNum = 0;
  344. APP.RollCallList = new System.Collections.Generic.List<Model.RollCallModel>();
  345. stpAnswer.Visibility = Visibility.Collapsed;
  346. imgRandomRollCall.Visibility = Visibility.Collapsed;
  347. imgRandomRollCallTwo.Visibility = Visibility.Visible;
  348. imgAnswer.Visibility = Visibility.Visible;
  349. imgAnswerTwo.Visibility = Visibility.Collapsed;
  350. initPageData();
  351. if (isRushToAnswer)//如果抢答没有结束 先结束抢答
  352. {
  353. //ZSocketServer.getInstance().SendMessage(ZSocketMsgManger.qiangdaEnd());
  354. isRushToAnswer = false;
  355. }
  356. if (APP.OnlineUserList.Count > 0)//判断当前在线人数大于0 点击才有效 ceshi=
  357. {
  358. isRollCall = true;
  359. Thread.Sleep(500);
  360. APP.BackgroundWorkerHelper.RunWorkerAsync(InvokeRandomRollCallServering, InvokeRandomRollCallServerCompate);
  361. }
  362. else
  363. {
  364. IsRandomRollCallButton = false;
  365. }
  366. }
  367. }
  368. /// <summary>
  369. /// 点名抽奖效果
  370. /// </summary>
  371. /// <returns></returns>
  372. private object InvokeRandomRollCallServering()
  373. {
  374. try
  375. {
  376. if (ranNum != 201314 && ranNum != 0)
  377. {
  378. if (ranNum < pageData.userList.Count)
  379. {
  380. pageData.userList[ranNum].Attendance_33 = "Collapsed";
  381. pageData.userList[ranNum].Attendance_3 = "Visible";
  382. Thread.Sleep(500);
  383. }
  384. }
  385. int randomTimes = 0;//随机次数
  386. ranNum = 0;//随机到用户的下标
  387. if (pageData.userList.Count == 1)//当前在线1人直接选中
  388. {
  389. pageData.userList[0].Attendance_33 = "Collapsed";
  390. pageData.userList[0].Attendance_3 = "Visible";
  391. Thread.Sleep(500);
  392. pageData.userList[0].Attendance_33 = "Visible";
  393. pageData.userList[0].Attendance_3 = "Collapsed";
  394. }
  395. else
  396. {
  397. randomTimes = 10;
  398. //if (TeachingDataStatic.OnlineUserList.Count > 0)
  399. //{
  400. // //OrderbyDescending 倒叙 OrderBy 顺序
  401. // raduser = raduser.OrderBy(x => x.num).ToList();
  402. //}
  403. int ranNumberOfPeople = 999;
  404. if ("1".Equals(flag) && raduser.Count > 5)
  405. {
  406. do
  407. {
  408. long tick = DateTime.Now.Ticks;
  409. Random ran = new Random((int)(tick & 0xffffffffL) | (int)(tick >> 32));
  410. ranNumberOfPeople = ran.Next(5);
  411. for (int i = 0; i < userListNew.Count; i++)
  412. {
  413. if (userListNew[i].userid == raduser[ranNumberOfPeople].userid)
  414. {
  415. ranNumberOfPeople = i;
  416. break;
  417. }
  418. }
  419. } while (ranNumberOfPeople == rNum);
  420. raduser[ranNumberOfPeople].num += 1;
  421. }
  422. else if ("2".Equals(flag) && raduser.Count > 15)
  423. {
  424. do
  425. {
  426. long tick = DateTime.Now.Ticks;
  427. Random ran = new Random((int)(tick & 0xffffffffL) | (int)(tick >> 32));
  428. ranNumberOfPeople = ran.Next(15);
  429. for (int i = 0; i < userListNew.Count; i++)
  430. {
  431. if (userListNew[i].userid == raduser[ranNumberOfPeople].userid)
  432. {
  433. ranNumberOfPeople = i;
  434. break;
  435. }
  436. }
  437. } while (ranNumberOfPeople == rNum);
  438. raduser[ranNumberOfPeople].num += 1;
  439. }
  440. else if (raduser.Count > 30)
  441. {
  442. do
  443. {
  444. long tick = DateTime.Now.Ticks;
  445. Random ran = new Random((int)(tick & 0xffffffffL) | (int)(tick >> 32));
  446. ranNumberOfPeople = ran.Next(30);
  447. for (int i = 0; i < userListNew.Count; i++)
  448. {
  449. if (userListNew[i].userid == raduser[ranNumberOfPeople].userid)
  450. {
  451. ranNumberOfPeople = i;
  452. break;
  453. }
  454. }
  455. raduser[ranNumberOfPeople].num += 1;
  456. } while (ranNumberOfPeople == rNum);
  457. }
  458. else
  459. {
  460. ranNumberOfPeople = 999;
  461. }
  462. //if (APP.outputInforLog)
  463. //{
  464. // LogHelper.WriteInfoLog("ranNum:" + TeachingDataStatic.OnlineUserList[ranNum].username + "&" + raduser[0].username + raduser[1].username + raduser[2].username + raduser[3].username + raduser[4].username + raduser[5].username);
  465. //}
  466. int ranNums = 0;//记录上一次随机的下标
  467. for (int i = 0; i < randomTimes; i++)
  468. {
  469. Thread.Sleep(200);
  470. if (i > 0)
  471. {
  472. pageData.userList[ranNum].Attendance_33 = "Collapsed";
  473. pageData.userList[ranNum].Attendance_3 = "Visible";
  474. }
  475. while (ranNums == ranNum)//保证这次随机的下标和上次不相同
  476. {
  477. long tick = DateTime.Now.Ticks;
  478. Random ran = new Random((int)(tick & 0xffffffffL) | (int)(tick >> 32));
  479. ranNum = ran.Next(pageData.userList.Count);
  480. if (i == 9 && ranNumberOfPeople != 999)
  481. {
  482. ranNum = ranNumberOfPeople;
  483. break;
  484. }
  485. if (pageData.userList.Count < 3)
  486. {
  487. break;
  488. }
  489. }
  490. ranNums = ranNum;
  491. rNum = ranNum;
  492. pageData.userList[ranNum].Attendance_33 = "Visible";
  493. pageData.userList[ranNum].Attendance_3 = "Collapsed";
  494. }
  495. }
  496. }
  497. catch (Exception ex)
  498. {
  499. LogHelper.WriteErrLog("【抢答点名(RollCallWindow)" + ex.Message, ex);
  500. }
  501. return APP.ErrorMessage;
  502. }
  503. /// <summary>
  504. /// 点名抽奖效果-返回结果
  505. /// </summary>
  506. /// <returns></returns>
  507. public void InvokeRandomRollCallServerCompate(object obj)
  508. {
  509. APP.BackgroundWorkerHelper.RunWorkerAsync(InvokeInteractiveLaunchsServering, InvokeInteractiveLaunchsServerCompate);
  510. }
  511. private void frm_ChangeTextEvent(string text)
  512. {
  513. if ("重新点名".Equals(text))
  514. {
  515. returnNum = 0;
  516. WSocketClient.getInstance().SendMessage(SocketMsgManger.RandomRollCallEndMsg());
  517. //ZSocketServer.getInstance().SendMessage(ZSocketMsgManger.qiangdaEnd());
  518. initPageData();
  519. IsRandomRollCallButton = true;
  520. if (APP.OnlineUserList.Count > 0)//判断当前在线人数大于0 点击才有效
  521. {
  522. isRollCall = true;
  523. APP.BackgroundWorkerHelper.RunWorkerAsync(InvokeRandomRollCallServering, InvokeRandomRollCallServerCompate);
  524. }
  525. }
  526. else if ("关闭窗口".Equals(text))
  527. {
  528. returnNum = 0;
  529. userids = string.Empty;
  530. useridss = string.Empty;
  531. useridsss = string.Empty;
  532. isRollCall = false;
  533. isRushToAnswer = false;
  534. WSocketClient.getInstance().SendMessage(SocketMsgManger.RandomRollCallEndMsg());
  535. IsRandomRollCallButton = false;
  536. //ToolbarWindow.IsOpenRollCallWindow = false;
  537. Hide();
  538. }
  539. }
  540. private void Window_MouseLeftButtonDown_1(object sender, MouseButtonEventArgs e)
  541. {
  542. DragMove();
  543. }
  544. /// <summary>
  545. /// 关闭
  546. /// </summary>
  547. /// <param name="sender"></param>
  548. /// <param name="e"></param>
  549. private void btnDown_Click(object sender, RoutedEventArgs e)
  550. {
  551. WSocketClient.getInstance().SendMessage(SocketMsgManger.RushToAnswerEndMsg());
  552. //ToolbarWindow.IsNotOperation = false;
  553. APP.myloading.Show();
  554. new Thread(o =>
  555. {
  556. returnNum = 0;
  557. userids = string.Empty;
  558. useridss = string.Empty;
  559. useridsss = string.Empty;
  560. isRollCall = false;
  561. isRushToAnswer = false;
  562. APP.RollCallList = new List<Model.RollCallModel>();
  563. Dispatcher.Invoke(new Action(() =>
  564. {
  565. ToolbarWindow.IsOpenRollCallWindow = false;
  566. APP.myloading.Hide();
  567. Hide();
  568. }));
  569. }).Start();
  570. }
  571. /// <summary>
  572. /// 抢答
  573. /// </summary>
  574. /// <param name="sender"></param>
  575. /// <param name="e"></param>
  576. private void btnAnswer_Click(object sender, RoutedEventArgs e)
  577. {
  578. WSocketClient.getInstance().SendMessage(SocketMsgManger.RushToAnswerMsg());
  579. if (!IsRandomRollCallButton)
  580. {
  581. returnNum = 0;
  582. userids = string.Empty;
  583. useridss = string.Empty;
  584. useridsss = string.Empty;
  585. APP.RollCallList = new System.Collections.Generic.List<RollCallModel>();
  586. imgRandomRollCall.Visibility = Visibility.Visible;
  587. imgRandomRollCallTwo.Visibility = Visibility.Collapsed;
  588. imgAnswer.Visibility = Visibility.Collapsed;
  589. imgAnswerTwo.Visibility = Visibility.Visible;
  590. //initPageData();
  591. if (isRollCall)//如果随机点名没有结束 发送结束随机点名消息
  592. {
  593. //ZSocketServer.getInstance().SendMessage(ZSocketMsgManger.qiangdaEnd());
  594. isRollCall = false;
  595. }
  596. if (APP.OnlineUserList.Count > 0)//判断当前在线人数大于0 点击才有效
  597. {
  598. if (pageData.userList.Count > 0)
  599. {
  600. pageData.userList.Clear();
  601. }
  602. //TeachingDataStatic.rollCallNum += 1;
  603. txbNumberOfReplies.Text = "0";
  604. isRushToAnswer = true;
  605. APP.BackgroundWorkerHelper.RunWorkerAsync(InvokeInteractiveLaunchServering, InvokeInteractiveLaunchServerCompate);
  606. }
  607. else
  608. {
  609. isRushToAnswer = false;
  610. }
  611. }
  612. }
  613. /// <summary>
  614. /// 互动 抢答服务-调用
  615. /// </summary>
  616. /// <returns></returns>
  617. private object InvokeInteractiveLaunchServering()
  618. {
  619. //Askteacher askteacher = new Askteacher
  620. //{
  621. // roomid = ZCommonData.roomid,
  622. // asktype = 20,
  623. // schoolid = ZCommonData.loginUser.schoolid,
  624. // asktid = DataProvider.TimestampAddRandomNumber(),
  625. // createtime = DataProvider.TimestampTotalSeconds(),
  626. // asktnum = 0
  627. //};
  628. //ZCommonData.askid = askteacher.asktid;
  629. //ZSqliteManger.insertClassData(new ClassData()
  630. //{
  631. // unix = DataProvider.TimestampTotalSeconds(),
  632. // roomid = ZCommonData.roomid,
  633. // api = "askteacher",
  634. // json = ZJsonHelper.ToJson(askteacher),
  635. // askid = askteacher.asktid
  636. //});
  637. //string msg = ZSocketMsgManger.qiangdaBegin(ZCommonData.askid);
  638. //ZSocketServer.getInstance().SendMessage(msg);
  639. //ZSqliteManger.insertClassAction(new ClassAction()
  640. //{
  641. // unix = DataProvider.TimestampTotalSeconds(),
  642. // roomid = ZCommonData.roomid,
  643. // type = 401,
  644. // json = msg,
  645. // askid = ZCommonData.askid
  646. //});
  647. return APP.ErrorMessage;
  648. }
  649. /// <summary>
  650. /// 互动 抢答服务-返回结果
  651. /// </summary>
  652. /// <returns></returns>
  653. public void InvokeInteractiveLaunchServerCompate(object obj)
  654. {
  655. }
  656. /// <summary>
  657. /// 互动 随机点名 服务-调用
  658. /// </summary>
  659. /// <returns></returns>
  660. private object InvokeInteractiveLaunchsServering()
  661. {
  662. //Askteacher askteacher = new Askteacher
  663. //{
  664. // roomid = ZCommonData.roomid,
  665. // asktype = 21,
  666. // schoolid = ZCommonData.loginUser.schoolid,
  667. // asktid = DataProvider.TimestampAddRandomNumber(),
  668. // createtime = DataProvider.TimestampTotalSeconds(),
  669. // asktnum = 0
  670. //};
  671. //ZCommonData.askid = askteacher.asktid;
  672. //ZSqliteManger.insertClassData(new ClassData()
  673. //{
  674. // unix = DataProvider.TimestampTotalSeconds(),
  675. // roomid = ZCommonData.roomid,
  676. // api = "askteacher",
  677. // json = ZJsonHelper.ToJson(askteacher),
  678. // askid = askteacher.asktid
  679. //});
  680. OnlineUserModel user = APP.OnlineUserList[ranNum];
  681. Console.WriteLine("ranNum:" + ranNum.ToString() + @user.username + "Ci" + user.num.ToString());
  682. //Askstudent askstudent = new Askstudent
  683. //{
  684. // roomid = ZCommonData.roomid,
  685. // studentid = user.userid,
  686. // asktid = ZCommonData.askid,
  687. // classid = ZCommonData.classid,
  688. // schoolid = ZCommonData.loginUser.schoolid,
  689. // createtime = DataProvider.TimestampTotalSeconds(),
  690. // studentselected = 1,
  691. // radiocorrect = 0
  692. //};
  693. //ZSqliteManger.insertClassData(new ClassData()
  694. //{
  695. // unix = DataProvider.TimestampTotalSeconds(),
  696. // roomid = ZCommonData.roomid,
  697. // api = "askstudent",
  698. // json = ZJsonHelper.ToJson(askstudent),
  699. // askid = askteacher.asktid
  700. //});
  701. WSocketClient.getInstance().SendMessage(SocketMsgManger.RandomRollCallMsg(user.userid));
  702. //ZSqliteManger.insertClassAction(new ClassAction()
  703. //{
  704. // unix = DataProvider.TimestampTotalSeconds(),
  705. // roomid = ZCommonData.roomid,
  706. // type = 411,
  707. // json = msg,
  708. // askid = ZCommonData.askid
  709. //});
  710. return APP.ErrorMessage;
  711. }
  712. /// <summary>
  713. /// 互动 随机点名服务-返回结果
  714. /// </summary>
  715. /// <returns></returns>
  716. public void InvokeInteractiveLaunchsServerCompate(object obj)
  717. {
  718. if (serverReturnCode == APP.ServerScuessCode)
  719. {
  720. OnlineUserModel user = APP.OnlineUserList[ranNum];
  721. string userpic = user.userpic;
  722. string userpicPath = "../Images/RollCall/attendance_1.png";
  723. if (ZCache.headDic.ContainsKey(userpic.Replace("/", "")))
  724. {
  725. userpicPath = ZCache.headDic[userpic.Replace("/", "")];
  726. }
  727. try
  728. {
  729. #region 随机次数增加
  730. for (int i = 0; i < APP.ClassStudentList.Count; i++)
  731. {
  732. if (APP.ClassStudentList[i].studentid == user.userid)
  733. {
  734. APP.ClassStudentList[i].num += 1;
  735. break;
  736. }
  737. }
  738. #endregion
  739. bool isUserid = true;
  740. //if (TeachingDataStatic.RandomRollCallStatisticsList.Count > 0)
  741. //{
  742. // for (int i = 0; i < TeachingDataStatic.RandomRollCallStatisticsList.Count; i++)
  743. // {
  744. // if (TeachingDataStatic.RandomRollCallStatisticsList[i].userid == user.userid)
  745. // {
  746. // TeachingDataStatic.RandomRollCallStatisticsList[i].replies += 1;
  747. // isUserid = false;
  748. // break;
  749. // }
  750. // }
  751. //}
  752. if (isUserid)
  753. {
  754. //RandomRollCallStatistics randomRollCallStatistics = new RandomRollCallStatistics
  755. //{
  756. // username = user.username,
  757. // userid = user.userid,
  758. // userpicPath = userpicPath,
  759. // replies = 1
  760. //};
  761. //TeachingDataStatic.RandomRollCallStatisticsList.Add(randomRollCallStatistics);
  762. //randomRollCallStatistics = new RandomRollCallStatistics();
  763. }
  764. }
  765. catch (Exception ex)
  766. {
  767. LogHelper.WriteErrLog("【课堂点名(RollCallWindow)】错误日志:" + ex.Message, ex);
  768. }
  769. try
  770. {
  771. if (rollCallPerfectionWindow == null)
  772. {
  773. rollCallPerfectionWindow = new RollCallPerfectionWindow(
  774. user.username,
  775. userpicPath
  776. )
  777. {
  778. Topmost = true,
  779. Width = pwidth,
  780. Height = pHeight,
  781. Left = 0,
  782. Top = 0
  783. };
  784. //订阅事件
  785. rollCallPerfectionWindow.ChangeTextEvent += new ChangeTextHandler(frm_ChangeTextEvent);
  786. rollCallPerfectionWindow.Owner = this;
  787. }
  788. else
  789. {
  790. rollCallPerfectionWindow.Name(user.username);
  791. }
  792. rollCallPerfectionWindow.Show();
  793. }
  794. catch (Exception ex)
  795. {
  796. LogHelper.WriteErrLog("【课堂点名(RollCallWindow)】错误日志:" + ex.Message, ex);
  797. }
  798. }
  799. }
  800. /// <summary>
  801. /// 页面关闭
  802. /// </summary>
  803. /// <param name="sender"></param>
  804. /// <param name="e"></param>
  805. private void Window_Closed(object sender, EventArgs e)
  806. {
  807. //ToolbarWindow.IsNotOperation = false;
  808. click_closeClick();
  809. WSocketClient.getInstance().removedWin(this);
  810. }
  811. #region 关闭委托
  812. /// <summary>
  813. /// 关闭委托 结束页面 创建人:赵耀 创建时间:2020年8月13日
  814. /// </summary>
  815. /// <param name="sender"></param>
  816. /// <param name="e"></param>
  817. public delegate void CloseClick();
  818. /// <summary>
  819. /// 关闭委托 结束页面 创建人:赵耀 创建时间:2020年8月13日
  820. /// </summary>
  821. public event CloseClick click_closeClick;
  822. #endregion 关闭委托
  823. }
  824. public class RollCallPageData : NotifyModel
  825. {
  826. public ObservableCollection<RollCallPageData> userList { get; set; }
  827. internal string _name;
  828. public string Name
  829. {
  830. get => _name;
  831. set { _name = value; OnPropertyChanged("Name"); }
  832. }
  833. internal string _id;
  834. public string ID
  835. {
  836. get => _id;
  837. set { _id = value; OnPropertyChanged("ID"); }
  838. }
  839. internal string _Pic;
  840. public string Pic
  841. {
  842. get => _Pic;
  843. set { _Pic = value; OnPropertyChanged("Pic"); }
  844. }
  845. internal string _attendance = "";
  846. public string Attendance
  847. {
  848. get => _attendance;
  849. set { _attendance = value; OnPropertyChanged("Attendance"); }
  850. }
  851. internal string _attendance_3 = "Visible";
  852. public string Attendance_3
  853. {
  854. get => _attendance_3;
  855. set { _attendance_3 = value; OnPropertyChanged("Attendance_3"); }
  856. }
  857. internal string _attendance_33 = "Visible";
  858. public string Attendance_33
  859. {
  860. get => _attendance_33;
  861. set { _attendance_33 = value; OnPropertyChanged("Attendance_33"); }
  862. }
  863. internal string _medal = "../Images/noting.png";
  864. public string Medal
  865. {
  866. get => _medal;
  867. set { _medal = value; OnPropertyChanged("Medal"); }
  868. }
  869. public long askid { get; set; }
  870. public RollCallPageData()
  871. {
  872. userList = new ObservableCollection<RollCallPageData>();
  873. }
  874. }
  875. }