星火直播PC
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.

RollCallWindow.xaml.cs 37KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001
  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/*, ZSocketCallback*/
  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. //ZSocketServer.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(ZWsMsgVo msg)
  113. {
  114. if (!isRollCall && !isRushToAnswer)
  115. {
  116. initPageData();
  117. }
  118. if (msg != null && msg.type == 402 && isRushToAnswer && msg.body.asktid == APP.askid)
  119. {
  120. Console.WriteLine(msg);
  121. #region 去重
  122. for (int i = 0; i < pageData.userList.Count; i++)
  123. {
  124. if (msg.body.userid.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.body.userpic;
  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.body.username,
  226. Attendance_33 = "Collapsed",
  227. Attendance_3 = "Visible",
  228. Pic = userpic,
  229. ID = msg.body.userid.ToString(),
  230. Attendance = attendance,
  231. Medal = medal,
  232. askid = msg.body.asktid
  233. });
  234. stpAnswer.Visibility = Visibility.Visible;
  235. }
  236. txbNumberOfReplies.Text = returnNum.ToString();
  237. }));
  238. }
  239. }
  240. System.Collections.Generic.List<OnlineUserModel> raduser = new System.Collections.Generic.List<OnlineUserModel>();
  241. System.Collections.Generic.List<OnlineUserModel> userListNew = new System.Collections.Generic.List<OnlineUserModel>();
  242. private void initPageData()
  243. {
  244. Dispatcher.Invoke(DispatcherPriority.Normal,
  245. new Action(() =>
  246. {
  247. if (pageData.userList.Count > 0)
  248. {
  249. pageData.userList.Clear();
  250. }
  251. List<OnlineUserModel> userList = APP.OnlineUserList;
  252. userListNew = new List<OnlineUserModel>();
  253. string userlistStr = JsonHelper.ToJson(userList);
  254. userListNew = JsonToList<OnlineUserModel>(userlistStr);
  255. List<ClassStudentListModel> classStudentList = APP.ClassStudentList;
  256. for (int i = 0; i < classStudentList.Count; i++)
  257. {
  258. classStudentList[i].status = 0;
  259. for (int j = 0; j < userListNew.Count; j++)
  260. {
  261. if (classStudentList[i].studentid == userListNew[j].userid)
  262. {
  263. userListNew[j].num = classStudentList[i].num;
  264. }
  265. }
  266. }
  267. if (userListNew.Count > 0)
  268. {
  269. //OrderbyDescending 倒叙 OrderBy 顺序
  270. raduser = userListNew.OrderBy(x => x.num).ToList();
  271. }
  272. foreach (OnlineUserModel user in userListNew)
  273. {
  274. string userpic = user.userpic;
  275. if (ZCache.headDic.ContainsKey(userpic.Replace("/", "")))
  276. {
  277. userpic = ZCache.headDic[userpic.Replace("/", "")];
  278. }
  279. else
  280. {
  281. userpic = "../Images/RollCall/attendance_1.png";
  282. }
  283. pageData.userList.Add(new RollCallPageData()
  284. {
  285. Name = user.username,
  286. Attendance_33 = "Collapsed",
  287. Attendance_3 = "Visible",
  288. Pic = userpic,
  289. ID = user.userid.ToString(),
  290. Attendance = "../Images/RollCall/attendance_3.png"
  291. });
  292. foreach (ClassStudentListModel cl in classStudentList)
  293. {
  294. if (cl.studentid == user.userid)
  295. {
  296. cl.status = 1;
  297. }
  298. }
  299. }
  300. string notOnline = string.Empty;
  301. foreach (ClassStudentListModel cl in classStudentList)
  302. {
  303. if (cl.status == 0)
  304. {
  305. notOnline += cl.studentname + " ";
  306. }
  307. }
  308. if (!string.IsNullOrWhiteSpace(notOnline))
  309. {
  310. txbNotOnline.Text = notOnline;
  311. }
  312. else
  313. {
  314. txbNotOnline.Text = "暂无";
  315. }
  316. toolbar_list.DataContext = pageData;
  317. }));
  318. }
  319. internal static List<T> JsonToList<T>(string respstr)
  320. {
  321. JsonSerializer serializer = new JsonSerializer();
  322. StringReader sr = new StringReader(respstr);
  323. object o = serializer.Deserialize(new JsonTextReader(sr), typeof(List<T>));
  324. List<T> list = o as List<T>;
  325. return list;
  326. }
  327. /// <summary>
  328. /// 是否已经按下按钮
  329. /// </summary>
  330. public bool IsRandomRollCallButton = false;
  331. /// <summary>
  332. /// 随机点名
  333. /// </summary>
  334. /// <param name="sender"></param>
  335. /// <param name="e"></param>
  336. private void btnRandomRollCall_Click(object sender, RoutedEventArgs e)
  337. {
  338. if (!IsRandomRollCallButton)
  339. {
  340. IsRandomRollCallButton = true;
  341. userids = string.Empty;
  342. useridss = string.Empty;
  343. useridsss = string.Empty;
  344. returnNum = 0;
  345. APP.RollCallList = new System.Collections.Generic.List<Model.RollCallModel>();
  346. stpAnswer.Visibility = Visibility.Collapsed;
  347. imgRandomRollCall.Visibility = Visibility.Collapsed;
  348. imgRandomRollCallTwo.Visibility = Visibility.Visible;
  349. imgAnswer.Visibility = Visibility.Visible;
  350. imgAnswerTwo.Visibility = Visibility.Collapsed;
  351. initPageData();
  352. if (isRushToAnswer)//如果抢答没有结束 先结束抢答
  353. {
  354. //ZSocketServer.getInstance().SendMessage(ZSocketMsgManger.qiangdaEnd());
  355. isRushToAnswer = false;
  356. }
  357. if (APP.OnlineUserList.Count > 0)//判断当前在线人数大于0 点击才有效 ceshi=
  358. {
  359. isRollCall = true;
  360. Thread.Sleep(500);
  361. APP.BackgroundWorkerHelper.RunWorkerAsync(InvokeRandomRollCallServering, InvokeRandomRollCallServerCompate);
  362. }
  363. else
  364. {
  365. IsRandomRollCallButton = false;
  366. }
  367. }
  368. }
  369. /// <summary>
  370. /// 点名抽奖效果
  371. /// </summary>
  372. /// <returns></returns>
  373. private object InvokeRandomRollCallServering()
  374. {
  375. try
  376. {
  377. if (ranNum != 201314 && ranNum != 0)
  378. {
  379. if (ranNum < pageData.userList.Count)
  380. {
  381. pageData.userList[ranNum].Attendance_33 = "Collapsed";
  382. pageData.userList[ranNum].Attendance_3 = "Visible";
  383. Thread.Sleep(500);
  384. }
  385. }
  386. int randomTimes = 0;//随机次数
  387. ranNum = 0;//随机到用户的下标
  388. if (pageData.userList.Count == 1)//当前在线1人直接选中
  389. {
  390. pageData.userList[0].Attendance_33 = "Collapsed";
  391. pageData.userList[0].Attendance_3 = "Visible";
  392. Thread.Sleep(500);
  393. pageData.userList[0].Attendance_33 = "Visible";
  394. pageData.userList[0].Attendance_3 = "Collapsed";
  395. }
  396. else
  397. {
  398. randomTimes = 10;
  399. //if (TeachingDataStatic.OnlineUserList.Count > 0)
  400. //{
  401. // //OrderbyDescending 倒叙 OrderBy 顺序
  402. // raduser = raduser.OrderBy(x => x.num).ToList();
  403. //}
  404. int ranNumberOfPeople = 999;
  405. if ("1".Equals(flag) && raduser.Count > 5)
  406. {
  407. do
  408. {
  409. long tick = DateTime.Now.Ticks;
  410. Random ran = new Random((int)(tick & 0xffffffffL) | (int)(tick >> 32));
  411. ranNumberOfPeople = ran.Next(5);
  412. for (int i = 0; i < userListNew.Count; i++)
  413. {
  414. if (userListNew[i].userid == raduser[ranNumberOfPeople].userid)
  415. {
  416. ranNumberOfPeople = i;
  417. break;
  418. }
  419. }
  420. } while (ranNumberOfPeople == rNum);
  421. raduser[ranNumberOfPeople].num += 1;
  422. }
  423. else if ("2".Equals(flag) && raduser.Count > 15)
  424. {
  425. do
  426. {
  427. long tick = DateTime.Now.Ticks;
  428. Random ran = new Random((int)(tick & 0xffffffffL) | (int)(tick >> 32));
  429. ranNumberOfPeople = ran.Next(15);
  430. for (int i = 0; i < userListNew.Count; i++)
  431. {
  432. if (userListNew[i].userid == raduser[ranNumberOfPeople].userid)
  433. {
  434. ranNumberOfPeople = i;
  435. break;
  436. }
  437. }
  438. } while (ranNumberOfPeople == rNum);
  439. raduser[ranNumberOfPeople].num += 1;
  440. }
  441. else if (raduser.Count > 30)
  442. {
  443. do
  444. {
  445. long tick = DateTime.Now.Ticks;
  446. Random ran = new Random((int)(tick & 0xffffffffL) | (int)(tick >> 32));
  447. ranNumberOfPeople = ran.Next(30);
  448. for (int i = 0; i < userListNew.Count; i++)
  449. {
  450. if (userListNew[i].userid == raduser[ranNumberOfPeople].userid)
  451. {
  452. ranNumberOfPeople = i;
  453. break;
  454. }
  455. }
  456. raduser[ranNumberOfPeople].num += 1;
  457. } while (ranNumberOfPeople == rNum);
  458. }
  459. else
  460. {
  461. ranNumberOfPeople = 999;
  462. }
  463. //if (APP.outputInforLog)
  464. //{
  465. // 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);
  466. //}
  467. int ranNums = 0;//记录上一次随机的下标
  468. for (int i = 0; i < randomTimes; i++)
  469. {
  470. Thread.Sleep(200);
  471. if (i > 0)
  472. {
  473. pageData.userList[ranNum].Attendance_33 = "Collapsed";
  474. pageData.userList[ranNum].Attendance_3 = "Visible";
  475. }
  476. while (ranNums == ranNum)//保证这次随机的下标和上次不相同
  477. {
  478. long tick = DateTime.Now.Ticks;
  479. Random ran = new Random((int)(tick & 0xffffffffL) | (int)(tick >> 32));
  480. ranNum = ran.Next(pageData.userList.Count);
  481. if (i == 9 && ranNumberOfPeople != 999)
  482. {
  483. ranNum = ranNumberOfPeople;
  484. break;
  485. }
  486. if (pageData.userList.Count < 3)
  487. {
  488. break;
  489. }
  490. }
  491. ranNums = ranNum;
  492. rNum = ranNum;
  493. pageData.userList[ranNum].Attendance_33 = "Visible";
  494. pageData.userList[ranNum].Attendance_3 = "Collapsed";
  495. }
  496. }
  497. }
  498. catch (Exception ex)
  499. {
  500. LogHelper.WriteErrLog("【抢答点名(RollCallWindow)" + ex.Message, ex);
  501. }
  502. return APP.ErrorMessage;
  503. }
  504. /// <summary>
  505. /// 点名抽奖效果-返回结果
  506. /// </summary>
  507. /// <returns></returns>
  508. public void InvokeRandomRollCallServerCompate(object obj)
  509. {
  510. APP.BackgroundWorkerHelper.RunWorkerAsync(InvokeInteractiveLaunchsServering, InvokeInteractiveLaunchsServerCompate);
  511. }
  512. private void frm_ChangeTextEvent(string text)
  513. {
  514. if ("重新点名".Equals(text))
  515. {
  516. returnNum = 0;
  517. WSocketClient.getInstance().SendMessage(SocketMsgManger.RandomRollCallEndMsg());
  518. //ZSocketServer.getInstance().SendMessage(ZSocketMsgManger.qiangdaEnd());
  519. initPageData();
  520. IsRandomRollCallButton = true;
  521. if (APP.OnlineUserList.Count > 0)//判断当前在线人数大于0 点击才有效
  522. {
  523. isRollCall = true;
  524. APP.BackgroundWorkerHelper.RunWorkerAsync(InvokeRandomRollCallServering, InvokeRandomRollCallServerCompate);
  525. }
  526. }
  527. else if ("关闭窗口".Equals(text))
  528. {
  529. returnNum = 0;
  530. userids = string.Empty;
  531. useridss = string.Empty;
  532. useridsss = string.Empty;
  533. isRollCall = false;
  534. isRushToAnswer = false;
  535. WSocketClient.getInstance().SendMessage(SocketMsgManger.RandomRollCallEndMsg());
  536. IsRandomRollCallButton = false;
  537. //ToolbarWindow.IsOpenRollCallWindow = false;
  538. Hide();
  539. }
  540. }
  541. private void Window_MouseLeftButtonDown_1(object sender, MouseButtonEventArgs e)
  542. {
  543. DragMove();
  544. }
  545. /// <summary>
  546. /// 关闭
  547. /// </summary>
  548. /// <param name="sender"></param>
  549. /// <param name="e"></param>
  550. private void btnDown_Click(object sender, RoutedEventArgs e)
  551. {
  552. WSocketClient.getInstance().SendMessage(SocketMsgManger.RushToAnswerEndMsg());
  553. //ToolbarWindow.IsNotOperation = false;
  554. APP.myloading.Show();
  555. new Thread(o =>
  556. {
  557. returnNum = 0;
  558. userids = string.Empty;
  559. useridss = string.Empty;
  560. useridsss = string.Empty;
  561. isRollCall = false;
  562. isRushToAnswer = false;
  563. APP.RollCallList = new System.Collections.Generic.List<Model.RollCallModel>();
  564. //string msg = ZSocketMsgManger.qiangdaEnd();
  565. //ZSocketServer.getInstance().SendMessage(msg);
  566. //ZSqliteManger.insertClassAction(new ClassAction()
  567. //{
  568. // unix = DataProvider.TimestampTotalSeconds(),
  569. // roomid = ZCommonData.roomid,
  570. // type = 403,
  571. // json = msg,
  572. // askid = ZCommonData.askid
  573. //});
  574. Dispatcher.Invoke(new Action(() =>
  575. {
  576. //ToolbarWindow.IsOpenRollCallWindow = false;
  577. APP.myloading.Hide();
  578. Hide();
  579. }));
  580. }).Start();
  581. }
  582. /// <summary>
  583. /// 抢答
  584. /// </summary>
  585. /// <param name="sender"></param>
  586. /// <param name="e"></param>
  587. private void btnAnswer_Click(object sender, RoutedEventArgs e)
  588. {
  589. WSocketClient.getInstance().SendMessage(SocketMsgManger.RushToAnswerMsg());
  590. if (!IsRandomRollCallButton)
  591. {
  592. returnNum = 0;
  593. userids = string.Empty;
  594. useridss = string.Empty;
  595. useridsss = string.Empty;
  596. APP.RollCallList = new System.Collections.Generic.List<RollCallModel>();
  597. imgRandomRollCall.Visibility = Visibility.Visible;
  598. imgRandomRollCallTwo.Visibility = Visibility.Collapsed;
  599. imgAnswer.Visibility = Visibility.Collapsed;
  600. imgAnswerTwo.Visibility = Visibility.Visible;
  601. //initPageData();
  602. if (isRollCall)//如果随机点名没有结束 发送结束随机点名消息
  603. {
  604. //ZSocketServer.getInstance().SendMessage(ZSocketMsgManger.qiangdaEnd());
  605. isRollCall = false;
  606. }
  607. if (APP.OnlineUserList.Count > 0)//判断当前在线人数大于0 点击才有效
  608. {
  609. if (pageData.userList.Count > 0)
  610. {
  611. pageData.userList.Clear();
  612. }
  613. //TeachingDataStatic.rollCallNum += 1;
  614. txbNumberOfReplies.Text = "0";
  615. isRushToAnswer = true;
  616. APP.BackgroundWorkerHelper.RunWorkerAsync(InvokeInteractiveLaunchServering, InvokeInteractiveLaunchServerCompate);
  617. }
  618. else
  619. {
  620. isRushToAnswer = false;
  621. }
  622. }
  623. }
  624. /// <summary>
  625. /// 互动 抢答服务-调用
  626. /// </summary>
  627. /// <returns></returns>
  628. private object InvokeInteractiveLaunchServering()
  629. {
  630. //Askteacher askteacher = new Askteacher
  631. //{
  632. // roomid = ZCommonData.roomid,
  633. // asktype = 20,
  634. // schoolid = ZCommonData.loginUser.schoolid,
  635. // asktid = DataProvider.TimestampAddRandomNumber(),
  636. // createtime = DataProvider.TimestampTotalSeconds(),
  637. // asktnum = 0
  638. //};
  639. //ZCommonData.askid = askteacher.asktid;
  640. //ZSqliteManger.insertClassData(new ClassData()
  641. //{
  642. // unix = DataProvider.TimestampTotalSeconds(),
  643. // roomid = ZCommonData.roomid,
  644. // api = "askteacher",
  645. // json = ZJsonHelper.ToJson(askteacher),
  646. // askid = askteacher.asktid
  647. //});
  648. //string msg = ZSocketMsgManger.qiangdaBegin(ZCommonData.askid);
  649. //ZSocketServer.getInstance().SendMessage(msg);
  650. //ZSqliteManger.insertClassAction(new ClassAction()
  651. //{
  652. // unix = DataProvider.TimestampTotalSeconds(),
  653. // roomid = ZCommonData.roomid,
  654. // type = 401,
  655. // json = msg,
  656. // askid = ZCommonData.askid
  657. //});
  658. return APP.ErrorMessage;
  659. }
  660. /// <summary>
  661. /// 互动 抢答服务-返回结果
  662. /// </summary>
  663. /// <returns></returns>
  664. public void InvokeInteractiveLaunchServerCompate(object obj)
  665. {
  666. }
  667. /// <summary>
  668. /// 互动 随机点名 服务-调用
  669. /// </summary>
  670. /// <returns></returns>
  671. private object InvokeInteractiveLaunchsServering()
  672. {
  673. //Askteacher askteacher = new Askteacher
  674. //{
  675. // roomid = ZCommonData.roomid,
  676. // asktype = 21,
  677. // schoolid = ZCommonData.loginUser.schoolid,
  678. // asktid = DataProvider.TimestampAddRandomNumber(),
  679. // createtime = DataProvider.TimestampTotalSeconds(),
  680. // asktnum = 0
  681. //};
  682. //ZCommonData.askid = askteacher.asktid;
  683. //ZSqliteManger.insertClassData(new ClassData()
  684. //{
  685. // unix = DataProvider.TimestampTotalSeconds(),
  686. // roomid = ZCommonData.roomid,
  687. // api = "askteacher",
  688. // json = ZJsonHelper.ToJson(askteacher),
  689. // askid = askteacher.asktid
  690. //});
  691. OnlineUserModel user = APP.OnlineUserList[ranNum];
  692. Console.WriteLine("ranNum:" + ranNum.ToString() + @user.username + "Ci" + user.num.ToString());
  693. //Askstudent askstudent = new Askstudent
  694. //{
  695. // roomid = ZCommonData.roomid,
  696. // studentid = user.userid,
  697. // asktid = ZCommonData.askid,
  698. // classid = ZCommonData.classid,
  699. // schoolid = ZCommonData.loginUser.schoolid,
  700. // createtime = DataProvider.TimestampTotalSeconds(),
  701. // studentselected = 1,
  702. // radiocorrect = 0
  703. //};
  704. //ZSqliteManger.insertClassData(new ClassData()
  705. //{
  706. // unix = DataProvider.TimestampTotalSeconds(),
  707. // roomid = ZCommonData.roomid,
  708. // api = "askstudent",
  709. // json = ZJsonHelper.ToJson(askstudent),
  710. // askid = askteacher.asktid
  711. //});
  712. WSocketClient.getInstance().SendMessage(SocketMsgManger.RandomRollCallMsg(user.userid));
  713. //ZSqliteManger.insertClassAction(new ClassAction()
  714. //{
  715. // unix = DataProvider.TimestampTotalSeconds(),
  716. // roomid = ZCommonData.roomid,
  717. // type = 411,
  718. // json = msg,
  719. // askid = ZCommonData.askid
  720. //});
  721. return APP.ErrorMessage;
  722. }
  723. /// <summary>
  724. /// 互动 随机点名服务-返回结果
  725. /// </summary>
  726. /// <returns></returns>
  727. public void InvokeInteractiveLaunchsServerCompate(object obj)
  728. {
  729. if (serverReturnCode == APP.ServerScuessCode)
  730. {
  731. OnlineUserModel user = APP.OnlineUserList[ranNum];
  732. string userpic = user.userpic;
  733. string userpicPath = "../Images/RollCall/attendance_1.png";
  734. if (ZCache.headDic.ContainsKey(userpic.Replace("/", "")))
  735. {
  736. userpicPath = ZCache.headDic[userpic.Replace("/", "")];
  737. }
  738. try
  739. {
  740. #region 随机次数增加
  741. for (int i = 0; i < APP.ClassStudentList.Count; i++)
  742. {
  743. if (APP.ClassStudentList[i].studentid == user.userid)
  744. {
  745. APP.ClassStudentList[i].num += 1;
  746. break;
  747. }
  748. }
  749. #endregion
  750. bool isUserid = true;
  751. //if (TeachingDataStatic.RandomRollCallStatisticsList.Count > 0)
  752. //{
  753. // for (int i = 0; i < TeachingDataStatic.RandomRollCallStatisticsList.Count; i++)
  754. // {
  755. // if (TeachingDataStatic.RandomRollCallStatisticsList[i].userid == user.userid)
  756. // {
  757. // TeachingDataStatic.RandomRollCallStatisticsList[i].replies += 1;
  758. // isUserid = false;
  759. // break;
  760. // }
  761. // }
  762. //}
  763. if (isUserid)
  764. {
  765. //RandomRollCallStatistics randomRollCallStatistics = new RandomRollCallStatistics
  766. //{
  767. // username = user.username,
  768. // userid = user.userid,
  769. // userpicPath = userpicPath,
  770. // replies = 1
  771. //};
  772. //TeachingDataStatic.RandomRollCallStatisticsList.Add(randomRollCallStatistics);
  773. //randomRollCallStatistics = new RandomRollCallStatistics();
  774. }
  775. }
  776. catch (Exception ex)
  777. {
  778. LogHelper.WriteErrLog("【课堂点名(RollCallWindow)】错误日志:" + ex.Message, ex);
  779. }
  780. try
  781. {
  782. if (rollCallPerfectionWindow == null)
  783. {
  784. rollCallPerfectionWindow = new RollCallPerfectionWindow(
  785. user.username,
  786. userpicPath
  787. )
  788. {
  789. Topmost = true,
  790. Width = pwidth,
  791. Height = pHeight,
  792. Left = 0,
  793. Top = 0
  794. };
  795. //订阅事件
  796. rollCallPerfectionWindow.ChangeTextEvent += new ChangeTextHandler(frm_ChangeTextEvent);
  797. rollCallPerfectionWindow.Owner = this;
  798. }
  799. else
  800. {
  801. rollCallPerfectionWindow.Name(user.username);
  802. }
  803. rollCallPerfectionWindow.Show();
  804. }
  805. catch (Exception ex)
  806. {
  807. LogHelper.WriteErrLog("【课堂点名(RollCallWindow)】错误日志:" + ex.Message, ex);
  808. }
  809. }
  810. }
  811. /// <summary>
  812. /// 页面关闭
  813. /// </summary>
  814. /// <param name="sender"></param>
  815. /// <param name="e"></param>
  816. private void Window_Closed(object sender, EventArgs e)
  817. {
  818. //ToolbarWindow.IsNotOperation = false;
  819. click_closeClick();
  820. //ZSocketServer.getInstance().removedWin(this);
  821. }
  822. #region 关闭委托
  823. /// <summary>
  824. /// 关闭委托 结束页面 创建人:赵耀 创建时间:2020年8月13日
  825. /// </summary>
  826. /// <param name="sender"></param>
  827. /// <param name="e"></param>
  828. public delegate void CloseClick();
  829. /// <summary>
  830. /// 关闭委托 结束页面 创建人:赵耀 创建时间:2020年8月13日
  831. /// </summary>
  832. public event CloseClick click_closeClick;
  833. #endregion 关闭委托
  834. }
  835. public class RollCallPageData : NotifyModel
  836. {
  837. public ObservableCollection<RollCallPageData> userList { get; set; }
  838. internal string _name;
  839. public string Name
  840. {
  841. get => _name;
  842. set { _name = value; OnPropertyChanged("Name"); }
  843. }
  844. internal string _id;
  845. public string ID
  846. {
  847. get => _id;
  848. set { _id = value; OnPropertyChanged("ID"); }
  849. }
  850. internal string _Pic;
  851. public string Pic
  852. {
  853. get => _Pic;
  854. set { _Pic = value; OnPropertyChanged("Pic"); }
  855. }
  856. internal string _attendance = "";
  857. public string Attendance
  858. {
  859. get => _attendance;
  860. set { _attendance = value; OnPropertyChanged("Attendance"); }
  861. }
  862. internal string _attendance_3 = "Visible";
  863. public string Attendance_3
  864. {
  865. get => _attendance_3;
  866. set { _attendance_3 = value; OnPropertyChanged("Attendance_3"); }
  867. }
  868. internal string _attendance_33 = "Visible";
  869. public string Attendance_33
  870. {
  871. get => _attendance_33;
  872. set { _attendance_33 = value; OnPropertyChanged("Attendance_33"); }
  873. }
  874. internal string _medal = "../Images/noting.png";
  875. public string Medal
  876. {
  877. get => _medal;
  878. set { _medal = value; OnPropertyChanged("Medal"); }
  879. }
  880. public long askid { get; set; }
  881. public RollCallPageData()
  882. {
  883. userList = new ObservableCollection<RollCallPageData>();
  884. }
  885. }
  886. }