|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413 |
- 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.Model;
-
- namespace XHZB.Desktop
- {
- /// <summary>
- /// 考勤统计
- /// </summary>
- public partial class AttendanceWindow : Window/*, ZSocketCallback*/
- {
- #region 字段
-
- /// <summary>
- /// 前台绑定数据源
- /// </summary>
- internal ToolbarAttendenceModel pageData = new ToolbarAttendenceModel();
-
- #endregion 字段
-
- #region 初始化
-
- /// <summary>
- /// 考勤统计
- /// </summary>
- public AttendanceWindow()
- {
- InitializeComponent();
- WindowStartupLocation = WindowStartupLocation.CenterScreen;
-
- Initialize();
- }
-
- /// <summary>
- /// 初始化 修改人:赵耀 修改时间:2020年8月11日
- /// </summary>
- public void Initialize()
- {
- //try
- //{
- // GetAddressIP();
- //}
- //catch (Exception ex)
- //{
-
- // LogHelper.WriteErrLog("【AttendanceWindow】(Initialize)" + ex.Message, ex);
- //}
- pageData = new ToolbarAttendenceModel();
- int onlineUsersnum = APP.ClassStudentList.Count;
- txbTotalPeople.Text = onlineUsersnum.ToString();
- renderView();
- //ZSocketServer.getInstance().addWin(this);
- //if (gridImg.Visibility == Visibility.Visible)
- //{
- // gridImg.Visibility = Visibility.Collapsed;
- //}
- DataContext = pageData;
- }
-
- private void Window_MouseLeftButtonDown_1(object sender, MouseButtonEventArgs e)
- {
- DragMove();
- }
-
- public void receiveWsMsg(ZWsMsgVo 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;
-
- //if (APP.outputInforLog)
- //{//OrderbyDescending 倒叙 OrderBy 顺序
- // userListNew = userListNew.OrderBy(x => x.userid).ToList();
- //}
- for (int i = 0; i < classStudentList.Count; i++)
- {
- classStudentList[i].status = 0;
- }
-
-
- //if (userListNew.Count > 1)
- //{
- // userListNew[1] = null;
- //}
- //userListNew[0] = null;
- 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;
- //userListNew.Sort();
-
- 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)
- {
- //ZSocketServer.getInstance().removedWin(this);
- }
-
- private void Window_Closed(object sender, EventArgs e)
- {
- }
-
- public void Dispose()
- {
- Dispose(true);
- GC.SuppressFinalize(this);
- }
- protected virtual void Dispose(bool disposing)
- {
- if (!m_disposed)
- {
- if (disposing)
- {
- //Release managed resources
- }
- //Release unmanaged resources
- m_disposed = true;
- }
- }
-
- //C#的Finalize()方法
- ~AttendanceWindow()
- {
- Dispose(false);
- }
-
- private bool m_disposed;
- /// <summary>
- /// 二维码
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void Button_Click(object sender, RoutedEventArgs e)
- {
- try
- {
- if (gridImg.Visibility == Visibility.Visible)
- {
- gridImg.Visibility = Visibility.Collapsed;
- }
- else
- {
- gridImg.Visibility = Visibility.Visible;
- }
- }
- catch (Exception ex)
- {
-
- LogHelper.WriteErrLog("【AttendanceWindow】" + ex.Message, ex);
- }
-
- }
- /// <summary>
- /// 获取文件的绝对路径
- /// </summary>
- /// <param name="Path">相对路径</param>
- /// <returns></returns>
- public string GetFileAbsolutePath(string Path = "")
- {
- try
- {
- if (!string.IsNullOrWhiteSpace(Path))
- {
- Path = Path.Replace("\\", "/");
- if (Path != "/")
- {
- if (Path.Substring(1, 1) == ":")
- return Path;
- if (Path.Substring(0, 1) != "/")
- Path = "/" + Path;
- }
- }
- string AbsolutePath = System.Windows.Forms.Application.StartupPath.ToString().Replace("\\", "/") + Path;
- return AbsolutePath;
- }
- catch (Exception)
- {
- return Path;
- }
- }
- //private void CreateQR(int pixelsPerModule, string info, System.Drawing.Color qrColor, System.Drawing.Color qrBackgroundColor, int iconSizePercent = 15, int iconBorderWidth = 6)
- //{
- // try
- // {
- // gridImg.Visibility = Visibility.Visible;
- // QRCodeGenerator qrGenerator = new QRCodeGenerator();
- // QRCodeData qrCodeData = qrGenerator.CreateQrCode(info, QRCodeGenerator.ECCLevel.Q);
- // QRCode qrCode = new QRCode(qrCodeData);
- // //Bitmap qrCodeImage = qrCode.GetGraphic(pixelsPerModule, qrColor, qrBackgroundColor, logo, iconSizePercent, iconBorderWidth, true);
- // Bitmap qrCodeImage = qrCode.GetGraphic(pixelsPerModule, qrColor, qrBackgroundColor, true);
-
- // IntPtr hBitmap = qrCodeImage.GetHbitmap();
- // ImageSource wpfBitmap = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(
- // hBitmap,
- // IntPtr.Zero,
- // Int32Rect.Empty,
- // BitmapSizeOptions.FromEmptyOptions());
-
- // img.Source = wpfBitmap;
- // }
- // catch (Exception ex)
- // {
- // LogHelper.WriteErrLog("【AttendanceWindow】(CreateQR)" + ex.Message, ex);
- // }
-
- //}
- //string localIp = string.Empty;
- ///// <summary>
- ///// 获取本地IP地址信息
- ///// </summary>
- //void GetAddressIP()
- //{
- // try
- // {
- // ///获取本地的IP地址
- // string AddressIP = string.Empty;
- // foreach (IPAddress _IPAddress in Dns.GetHostEntry(Dns.GetHostName()).AddressList)
- // {
- // if (_IPAddress.AddressFamily.ToString() == "InterNetwork")
- // {
- // AddressIP = _IPAddress.ToString();
- // }
- // }
- // txtLocalIP.Text = AddressIP + ":10077";
- // if (!string.IsNullOrWhiteSpace(txtLocalIP.Text) && !txtLocalIP.Text.Equals(localIp))
- // {
- // localIp = txtLocalIP.Text;
- // CreateQR(100, txtLocalIP.Text, System.Drawing.Color.Black, System.Drawing.Color.White);
- // }
- // }
- // catch (Exception ex)
- // {
-
- // LogHelper.WriteErrLog("【AttendanceWindow】" + ex.Message, ex);
- // }
-
- //}
- }
-
- #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 动态数据集合
- }
|