123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250 |
- 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
- {
- /// <summary>
- /// 考勤统计
- /// </summary>
- public partial class AttendanceWindow : Window, SocketCallback
- {
- #region 字段
-
- /// <summary>
- /// 前台绑定数据源
- /// </summary>
- internal ToolbarAttendenceModel pageData = new ToolbarAttendenceModel();
-
- #endregion 字段
-
- #region 初始化
-
- /// <summary>
- /// 考勤统计
- /// </summary>
- public AttendanceWindow()
- {
- InitializeComponent();
- WindowStartupLocation = WindowStartupLocation.CenterScreen;
-
- Initialize();
- }
-
- /// <summary>
- /// 初始化
- /// </summary>
- 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 事件
-
- /// <summary>
- /// 结束
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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<OnlineUserModel> userListNew = ZCache.JsonToList<OnlineUserModel>(userlistStr);
- List<ClassStudentListModel> 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<ClassStudentListModel> 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<ToolbarAttendenceMenu> menuList { get; set; }
-
- public ToolbarAttendenceModel()
- {
- menuList = new ObservableCollection<ToolbarAttendenceMenu>();
- }
- }
-
- public class ToolbarAttendenceMenu : NotifyModel, IComparable<ToolbarAttendenceMenu>
- {
- /// <summary>
- /// 姓名
- /// </summary>
- public string Name { get; set; }
-
- /// <summary>
- /// 头像
- /// </summary>
- public string Pic { get; set; }
-
- public int CompareTo(ToolbarAttendenceMenu other)
- {
- return string.Compare(Name, other.Name, true);
- }
- }
-
- #endregion 动态数据集合
- }
|