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

AttendanceWindow.xaml.cs 7.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. using Common.system;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Collections.ObjectModel;
  5. using System.Windows;
  6. using System.Windows.Input;
  7. using System.Windows.Threading;
  8. using XHZB.Desktop.Utils;
  9. using XHZB.Desktop.WebSocket;
  10. using XHZB.Model;
  11. namespace XHZB.Desktop
  12. {
  13. /// <summary>
  14. /// 考勤统计
  15. /// </summary>
  16. public partial class AttendanceWindow : Window, SocketCallback
  17. {
  18. #region 字段
  19. /// <summary>
  20. /// 前台绑定数据源
  21. /// </summary>
  22. internal ToolbarAttendenceModel pageData = new ToolbarAttendenceModel();
  23. #endregion 字段
  24. #region 初始化
  25. /// <summary>
  26. /// 考勤统计
  27. /// </summary>
  28. public AttendanceWindow()
  29. {
  30. InitializeComponent();
  31. WindowStartupLocation = WindowStartupLocation.CenterScreen;
  32. Initialize();
  33. }
  34. /// <summary>
  35. /// 初始化
  36. /// </summary>
  37. public void Initialize()
  38. {
  39. pageData = new ToolbarAttendenceModel();
  40. int onlineUsersnum = APP.ClassStudentList.Count;
  41. txbTotalPeople.Text = onlineUsersnum.ToString();
  42. renderView();
  43. SocketClient.getInstance().addWin(this);
  44. DataContext = pageData;
  45. }
  46. private void Window_MouseLeftButtonDown_1(object sender, MouseButtonEventArgs e)
  47. {
  48. DragMove();
  49. }
  50. public void receiveWsMsg(SocketModel msg)
  51. {
  52. }
  53. public void userListChange()
  54. {
  55. Console.WriteLine("抢答点名-渲染用户列表");
  56. Dispatcher.BeginInvoke(DispatcherPriority.Normal,
  57. new Action(() =>
  58. {
  59. renderView();
  60. }));
  61. }
  62. #endregion 初始化
  63. #region 事件
  64. /// <summary>
  65. /// 结束
  66. /// </summary>
  67. /// <param name="sender"></param>
  68. /// <param name="e"></param>
  69. private void btnEnd_Click(object sender, RoutedEventArgs e)
  70. {
  71. if (pageData.menuList.Count > 0)
  72. {
  73. pageData.menuList.Clear();
  74. }
  75. ToolbarWindow.IsOpenAttendanceWindow = false;
  76. Hide();
  77. FreeMemoryHelper.ReallocateMemory();
  78. System.Threading.Thread.Sleep(0);
  79. }
  80. #endregion 事件
  81. private void renderView()
  82. {
  83. if (pageData.menuList.Count > 0)
  84. {
  85. pageData.menuList.Clear();
  86. }
  87. if (APP.OnlineUserList.Count > 0)
  88. {
  89. var userList = APP.OnlineUserList.ToArray();
  90. string userlistStr = JsonHelper.ToJson(userList);
  91. List<OnlineUserModel> userListNew = ZCache.JsonToList<OnlineUserModel>(userlistStr);
  92. List<ClassStudentListModel> classStudentList = APP.ClassStudentList;
  93. for (int i = 0; i < classStudentList.Count; i++)
  94. {
  95. classStudentList[i].status = 0;
  96. }
  97. foreach (OnlineUserModel user in userListNew)
  98. {
  99. if (user != null)
  100. {
  101. string userHeadPic;
  102. if (user.userpic != null)
  103. {
  104. userHeadPic = user.userpic;
  105. if (ZCache.headDic.ContainsKey(userHeadPic.Replace("/", "")))
  106. {
  107. string localpath = ZCache.headDic[userHeadPic.Replace("/", "")];
  108. userHeadPic = localpath;
  109. }
  110. else
  111. {
  112. userHeadPic = "../Images/RollCall/attendance_1.png";
  113. }
  114. }
  115. else
  116. {
  117. userHeadPic = "../Images/RollCall/attendance_1.png";
  118. }
  119. pageData.menuList.Add(new ToolbarAttendenceMenu()
  120. {
  121. Name = user.username,
  122. Pic = userHeadPic
  123. });
  124. foreach (ClassStudentListModel cl in classStudentList)
  125. {
  126. if (cl.studentid == user.userid)
  127. {
  128. cl.status = 1;
  129. }
  130. }
  131. }
  132. }
  133. string notOnline = string.Empty;
  134. foreach (ClassStudentListModel cl in classStudentList)
  135. {
  136. if (cl.status == 0)
  137. {
  138. notOnline += cl.studentname + " ";
  139. }
  140. }
  141. if (!string.IsNullOrWhiteSpace(notOnline))
  142. {
  143. txbNotOnline.Text = notOnline;
  144. }
  145. else
  146. {
  147. txbNotOnline.Text = "暂无";
  148. }
  149. txbOnlineUsers.Text = userListNew.Count.ToString();
  150. userList = null;
  151. userlistStr = null;
  152. userListNew = null;
  153. classStudentList = null;
  154. }
  155. else
  156. {
  157. List<ClassStudentListModel> classStudentList = APP.ClassStudentList;
  158. for (int i = 0; i < classStudentList.Count; i++)
  159. {
  160. classStudentList[i].status = 0;
  161. }
  162. string notOnline = string.Empty;
  163. foreach (ClassStudentListModel cl in classStudentList)
  164. {
  165. if (cl.status == 0)
  166. {
  167. notOnline += cl.studentname + " ";
  168. }
  169. }
  170. if (!string.IsNullOrWhiteSpace(notOnline))
  171. {
  172. txbNotOnline.Text = notOnline;
  173. }
  174. else
  175. {
  176. txbNotOnline.Text = "暂无";
  177. }
  178. txbOnlineUsers.Text = APP.OnlineUserList.Count.ToString();
  179. }
  180. }
  181. private void Window_Loaded(object sender, RoutedEventArgs e)
  182. {
  183. }
  184. private void Window_Unloaded(object sender, RoutedEventArgs e)
  185. {
  186. SocketClient.getInstance().removedWin(this);
  187. }
  188. private void Window_Closed(object sender, EventArgs e)
  189. {
  190. }
  191. }
  192. #region 动态数据集合
  193. public class ToolbarAttendenceModel : NotifyModel
  194. {
  195. public ObservableCollection<ToolbarAttendenceMenu> menuList { get; set; }
  196. public ToolbarAttendenceModel()
  197. {
  198. menuList = new ObservableCollection<ToolbarAttendenceMenu>();
  199. }
  200. }
  201. public class ToolbarAttendenceMenu : NotifyModel, IComparable<ToolbarAttendenceMenu>
  202. {
  203. /// <summary>
  204. /// 姓名
  205. /// </summary>
  206. public string Name { get; set; }
  207. /// <summary>
  208. /// 头像
  209. /// </summary>
  210. public string Pic { get; set; }
  211. public int CompareTo(ToolbarAttendenceMenu other)
  212. {
  213. return string.Compare(Name, other.Name, true);
  214. }
  215. }
  216. #endregion 动态数据集合
  217. }