using Common.system; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Windows; using System.Windows.Input; using System.Windows.Threading; using XHZB.Desktop.Utils; using XHZB.Desktop.WebSocket; using XHZB.Model; namespace XHZB.Desktop { /// /// 考勤统计 /// public partial class AttendanceWindow : Window, SocketCallback { #region 字段 /// /// 前台绑定数据源 /// internal ToolbarAttendenceModel pageData = new ToolbarAttendenceModel(); #endregion 字段 #region 初始化 /// /// 考勤统计 /// public AttendanceWindow() { InitializeComponent(); WindowStartupLocation = WindowStartupLocation.CenterScreen; Initialize(); } /// /// 初始化 /// public void Initialize() { pageData = new ToolbarAttendenceModel(); int onlineUsersnum = APP.ClassStudentList.Count; txbTotalPeople.Text = onlineUsersnum.ToString(); renderView(); SocketClient.getInstance().addWin(this); DataContext = pageData; } private void Window_MouseLeftButtonDown_1(object sender, MouseButtonEventArgs e) { DragMove(); } public void receiveWsMsg(SocketModel msg) { } public void userListChange() { Console.WriteLine("抢答点名-渲染用户列表"); Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() => { renderView(); })); } #endregion 初始化 #region 事件 /// /// 结束 /// /// /// private void btnEnd_Click(object sender, RoutedEventArgs e) { if (pageData.menuList.Count > 0) { pageData.menuList.Clear(); } ToolbarWindow.IsOpenAttendanceWindow = false; Hide(); FreeMemoryHelper.ReallocateMemory(); System.Threading.Thread.Sleep(0); } #endregion 事件 private void renderView() { if (pageData.menuList.Count > 0) { pageData.menuList.Clear(); } if (APP.OnlineUserList.Count > 0) { var userList = APP.OnlineUserList.ToArray(); string userlistStr = JsonHelper.ToJson(userList); List userListNew = ZCache.JsonToList(userlistStr); List classStudentList = APP.ClassStudentList; for (int i = 0; i < classStudentList.Count; i++) { classStudentList[i].status = 0; } foreach (OnlineUserModel user in userListNew) { if (user != null) { string userHeadPic; if (user.userpic != null) { userHeadPic = user.userpic; if (ZCache.headDic.ContainsKey(userHeadPic.Replace("/", ""))) { string localpath = ZCache.headDic[userHeadPic.Replace("/", "")]; userHeadPic = localpath; } else { userHeadPic = "../Images/RollCall/attendance_1.png"; } } else { userHeadPic = "../Images/RollCall/attendance_1.png"; } pageData.menuList.Add(new ToolbarAttendenceMenu() { Name = user.username, Pic = userHeadPic }); foreach (ClassStudentListModel cl in classStudentList) { if (cl.studentid == user.userid) { cl.status = 1; } } } } string notOnline = string.Empty; foreach (ClassStudentListModel cl in classStudentList) { if (cl.status == 0) { notOnline += cl.studentname + " "; } } if (!string.IsNullOrWhiteSpace(notOnline)) { txbNotOnline.Text = notOnline; } else { txbNotOnline.Text = "暂无"; } txbOnlineUsers.Text = userListNew.Count.ToString(); userList = null; userlistStr = null; userListNew = null; classStudentList = null; } else { List classStudentList = APP.ClassStudentList; for (int i = 0; i < classStudentList.Count; i++) { classStudentList[i].status = 0; } string notOnline = string.Empty; foreach (ClassStudentListModel cl in classStudentList) { if (cl.status == 0) { notOnline += cl.studentname + " "; } } if (!string.IsNullOrWhiteSpace(notOnline)) { txbNotOnline.Text = notOnline; } else { txbNotOnline.Text = "暂无"; } txbOnlineUsers.Text = APP.OnlineUserList.Count.ToString(); } } private void Window_Loaded(object sender, RoutedEventArgs e) { } private void Window_Unloaded(object sender, RoutedEventArgs e) { SocketClient.getInstance().removedWin(this); } private void Window_Closed(object sender, EventArgs e) { } } #region 动态数据集合 public class ToolbarAttendenceModel : NotifyModel { public ObservableCollection menuList { get; set; } public ToolbarAttendenceModel() { menuList = new ObservableCollection(); } } public class ToolbarAttendenceMenu : NotifyModel, IComparable { /// /// 姓名 /// public string Name { get; set; } /// /// 头像 /// public string Pic { get; set; } public int CompareTo(ToolbarAttendenceMenu other) { return string.Compare(Name, other.Name, true); } } #endregion 动态数据集合 }