星火直播PC
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

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, 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 System.Collections.Generic.List<Model.RollCallModel>();
  563. //string msg = ZSocketMsgManger.qiangdaEnd();
  564. //ZSocketServer.getInstance().SendMessage(msg);
  565. //ZSqliteManger.insertClassAction(new ClassAction()
  566. //{
  567. // unix = DataProvider.TimestampTotalSeconds(),
  568. // roomid = ZCommonData.roomid,
  569. // type = 403,
  570. // json = msg,
  571. // askid = ZCommonData.askid
  572. //});
  573. Dispatcher.Invoke(new Action(() =>
  574. {
  575. //ToolbarWindow.IsOpenRollCallWindow = false;
  576. APP.myloading.Hide();
  577. Hide();
  578. }));
  579. }).Start();
  580. }
  581. /// <summary>
  582. /// 抢答
  583. /// </summary>
  584. /// <param name="sender"></param>
  585. /// <param name="e"></param>
  586. private void btnAnswer_Click(object sender, RoutedEventArgs e)
  587. {
  588. WSocketClient.getInstance().SendMessage(SocketMsgManger.RushToAnswerMsg());
  589. if (!IsRandomRollCallButton)
  590. {
  591. returnNum = 0;
  592. userids = string.Empty;
  593. useridss = string.Empty;
  594. useridsss = string.Empty;
  595. APP.RollCallList = new System.Collections.Generic.List<RollCallModel>();
  596. imgRandomRollCall.Visibility = Visibility.Visible;
  597. imgRandomRollCallTwo.Visibility = Visibility.Collapsed;
  598. imgAnswer.Visibility = Visibility.Collapsed;
  599. imgAnswerTwo.Visibility = Visibility.Visible;
  600. //initPageData();
  601. if (isRollCall)//如果随机点名没有结束 发送结束随机点名消息
  602. {
  603. //ZSocketServer.getInstance().SendMessage(ZSocketMsgManger.qiangdaEnd());
  604. isRollCall = false;
  605. }
  606. if (APP.OnlineUserList.Count > 0)//判断当前在线人数大于0 点击才有效
  607. {
  608. if (pageData.userList.Count > 0)
  609. {
  610. pageData.userList.Clear();
  611. }
  612. //TeachingDataStatic.rollCallNum += 1;
  613. txbNumberOfReplies.Text = "0";
  614. isRushToAnswer = true;
  615. APP.BackgroundWorkerHelper.RunWorkerAsync(InvokeInteractiveLaunchServering, InvokeInteractiveLaunchServerCompate);
  616. }
  617. else
  618. {
  619. isRushToAnswer = false;
  620. }
  621. }
  622. }
  623. /// <summary>
  624. /// 互动 抢答服务-调用
  625. /// </summary>
  626. /// <returns></returns>
  627. private object InvokeInteractiveLaunchServering()
  628. {
  629. //Askteacher askteacher = new Askteacher
  630. //{
  631. // roomid = ZCommonData.roomid,
  632. // asktype = 20,
  633. // schoolid = ZCommonData.loginUser.schoolid,
  634. // asktid = DataProvider.TimestampAddRandomNumber(),
  635. // createtime = DataProvider.TimestampTotalSeconds(),
  636. // asktnum = 0
  637. //};
  638. //ZCommonData.askid = askteacher.asktid;
  639. //ZSqliteManger.insertClassData(new ClassData()
  640. //{
  641. // unix = DataProvider.TimestampTotalSeconds(),
  642. // roomid = ZCommonData.roomid,
  643. // api = "askteacher",
  644. // json = ZJsonHelper.ToJson(askteacher),
  645. // askid = askteacher.asktid
  646. //});
  647. //string msg = ZSocketMsgManger.qiangdaBegin(ZCommonData.askid);
  648. //ZSocketServer.getInstance().SendMessage(msg);
  649. //ZSqliteManger.insertClassAction(new ClassAction()
  650. //{
  651. // unix = DataProvider.TimestampTotalSeconds(),
  652. // roomid = ZCommonData.roomid,
  653. // type = 401,
  654. // json = msg,
  655. // askid = ZCommonData.askid
  656. //});
  657. return APP.ErrorMessage;
  658. }
  659. /// <summary>
  660. /// 互动 抢答服务-返回结果
  661. /// </summary>
  662. /// <returns></returns>
  663. public void InvokeInteractiveLaunchServerCompate(object obj)
  664. {
  665. }
  666. /// <summary>
  667. /// 互动 随机点名 服务-调用
  668. /// </summary>
  669. /// <returns></returns>
  670. private object InvokeInteractiveLaunchsServering()
  671. {
  672. //Askteacher askteacher = new Askteacher
  673. //{
  674. // roomid = ZCommonData.roomid,
  675. // asktype = 21,
  676. // schoolid = ZCommonData.loginUser.schoolid,
  677. // asktid = DataProvider.TimestampAddRandomNumber(),
  678. // createtime = DataProvider.TimestampTotalSeconds(),
  679. // asktnum = 0
  680. //};
  681. //ZCommonData.askid = askteacher.asktid;
  682. //ZSqliteManger.insertClassData(new ClassData()
  683. //{
  684. // unix = DataProvider.TimestampTotalSeconds(),
  685. // roomid = ZCommonData.roomid,
  686. // api = "askteacher",
  687. // json = ZJsonHelper.ToJson(askteacher),
  688. // askid = askteacher.asktid
  689. //});
  690. OnlineUserModel user = APP.OnlineUserList[ranNum];
  691. Console.WriteLine("ranNum:" + ranNum.ToString() + @user.username + "Ci" + user.num.ToString());
  692. //Askstudent askstudent = new Askstudent
  693. //{
  694. // roomid = ZCommonData.roomid,
  695. // studentid = user.userid,
  696. // asktid = ZCommonData.askid,
  697. // classid = ZCommonData.classid,
  698. // schoolid = ZCommonData.loginUser.schoolid,
  699. // createtime = DataProvider.TimestampTotalSeconds(),
  700. // studentselected = 1,
  701. // radiocorrect = 0
  702. //};
  703. //ZSqliteManger.insertClassData(new ClassData()
  704. //{
  705. // unix = DataProvider.TimestampTotalSeconds(),
  706. // roomid = ZCommonData.roomid,
  707. // api = "askstudent",
  708. // json = ZJsonHelper.ToJson(askstudent),
  709. // askid = askteacher.asktid
  710. //});
  711. WSocketClient.getInstance().SendMessage(SocketMsgManger.RandomRollCallMsg(user.userid));
  712. //ZSqliteManger.insertClassAction(new ClassAction()
  713. //{
  714. // unix = DataProvider.TimestampTotalSeconds(),
  715. // roomid = ZCommonData.roomid,
  716. // type = 411,
  717. // json = msg,
  718. // askid = ZCommonData.askid
  719. //});
  720. return APP.ErrorMessage;
  721. }
  722. /// <summary>
  723. /// 互动 随机点名服务-返回结果
  724. /// </summary>
  725. /// <returns></returns>
  726. public void InvokeInteractiveLaunchsServerCompate(object obj)
  727. {
  728. if (serverReturnCode == APP.ServerScuessCode)
  729. {
  730. OnlineUserModel user = APP.OnlineUserList[ranNum];
  731. string userpic = user.userpic;
  732. string userpicPath = "../Images/RollCall/attendance_1.png";
  733. if (ZCache.headDic.ContainsKey(userpic.Replace("/", "")))
  734. {
  735. userpicPath = ZCache.headDic[userpic.Replace("/", "")];
  736. }
  737. try
  738. {
  739. #region 随机次数增加
  740. for (int i = 0; i < APP.ClassStudentList.Count; i++)
  741. {
  742. if (APP.ClassStudentList[i].studentid == user.userid)
  743. {
  744. APP.ClassStudentList[i].num += 1;
  745. break;
  746. }
  747. }
  748. #endregion
  749. bool isUserid = true;
  750. //if (TeachingDataStatic.RandomRollCallStatisticsList.Count > 0)
  751. //{
  752. // for (int i = 0; i < TeachingDataStatic.RandomRollCallStatisticsList.Count; i++)
  753. // {
  754. // if (TeachingDataStatic.RandomRollCallStatisticsList[i].userid == user.userid)
  755. // {
  756. // TeachingDataStatic.RandomRollCallStatisticsList[i].replies += 1;
  757. // isUserid = false;
  758. // break;
  759. // }
  760. // }
  761. //}
  762. if (isUserid)
  763. {
  764. //RandomRollCallStatistics randomRollCallStatistics = new RandomRollCallStatistics
  765. //{
  766. // username = user.username,
  767. // userid = user.userid,
  768. // userpicPath = userpicPath,
  769. // replies = 1
  770. //};
  771. //TeachingDataStatic.RandomRollCallStatisticsList.Add(randomRollCallStatistics);
  772. //randomRollCallStatistics = new RandomRollCallStatistics();
  773. }
  774. }
  775. catch (Exception ex)
  776. {
  777. LogHelper.WriteErrLog("【课堂点名(RollCallWindow)】错误日志:" + ex.Message, ex);
  778. }
  779. try
  780. {
  781. if (rollCallPerfectionWindow == null)
  782. {
  783. rollCallPerfectionWindow = new RollCallPerfectionWindow(
  784. user.username,
  785. userpicPath
  786. )
  787. {
  788. Topmost = true,
  789. Width = pwidth,
  790. Height = pHeight,
  791. Left = 0,
  792. Top = 0
  793. };
  794. //订阅事件
  795. rollCallPerfectionWindow.ChangeTextEvent += new ChangeTextHandler(frm_ChangeTextEvent);
  796. rollCallPerfectionWindow.Owner = this;
  797. }
  798. else
  799. {
  800. rollCallPerfectionWindow.Name(user.username);
  801. }
  802. rollCallPerfectionWindow.Show();
  803. }
  804. catch (Exception ex)
  805. {
  806. LogHelper.WriteErrLog("【课堂点名(RollCallWindow)】错误日志:" + ex.Message, ex);
  807. }
  808. }
  809. }
  810. /// <summary>
  811. /// 页面关闭
  812. /// </summary>
  813. /// <param name="sender"></param>
  814. /// <param name="e"></param>
  815. private void Window_Closed(object sender, EventArgs e)
  816. {
  817. //ToolbarWindow.IsNotOperation = false;
  818. click_closeClick();
  819. //ZSocketServer.getInstance().removedWin(this);
  820. }
  821. #region 关闭委托
  822. /// <summary>
  823. /// 关闭委托 结束页面 创建人:赵耀 创建时间:2020年8月13日
  824. /// </summary>
  825. /// <param name="sender"></param>
  826. /// <param name="e"></param>
  827. public delegate void CloseClick();
  828. /// <summary>
  829. /// 关闭委托 结束页面 创建人:赵耀 创建时间:2020年8月13日
  830. /// </summary>
  831. public event CloseClick click_closeClick;
  832. #endregion 关闭委托
  833. }
  834. public class RollCallPageData : NotifyModel
  835. {
  836. public ObservableCollection<RollCallPageData> userList { get; set; }
  837. internal string _name;
  838. public string Name
  839. {
  840. get => _name;
  841. set { _name = value; OnPropertyChanged("Name"); }
  842. }
  843. internal string _id;
  844. public string ID
  845. {
  846. get => _id;
  847. set { _id = value; OnPropertyChanged("ID"); }
  848. }
  849. internal string _Pic;
  850. public string Pic
  851. {
  852. get => _Pic;
  853. set { _Pic = value; OnPropertyChanged("Pic"); }
  854. }
  855. internal string _attendance = "";
  856. public string Attendance
  857. {
  858. get => _attendance;
  859. set { _attendance = value; OnPropertyChanged("Attendance"); }
  860. }
  861. internal string _attendance_3 = "Visible";
  862. public string Attendance_3
  863. {
  864. get => _attendance_3;
  865. set { _attendance_3 = value; OnPropertyChanged("Attendance_3"); }
  866. }
  867. internal string _attendance_33 = "Visible";
  868. public string Attendance_33
  869. {
  870. get => _attendance_33;
  871. set { _attendance_33 = value; OnPropertyChanged("Attendance_33"); }
  872. }
  873. internal string _medal = "../Images/noting.png";
  874. public string Medal
  875. {
  876. get => _medal;
  877. set { _medal = value; OnPropertyChanged("Medal"); }
  878. }
  879. public long askid { get; set; }
  880. public RollCallPageData()
  881. {
  882. userList = new ObservableCollection<RollCallPageData>();
  883. }
  884. }
  885. }