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
{
///
/// 考勤统计
///
public partial class AttendanceWindow : Window/*, ZSocketCallback*/
{
#region 字段
///
/// 前台绑定数据源
///
internal ToolbarAttendenceModel pageData = new ToolbarAttendenceModel();
#endregion 字段
#region 初始化
///
/// 考勤统计
///
public AttendanceWindow()
{
InitializeComponent();
WindowStartupLocation = WindowStartupLocation.CenterScreen;
Initialize();
}
///
/// 初始化 修改人:赵耀 修改时间:2020年8月11日
///
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 事件
///
/// 结束
///
///
///
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;
//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 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;
///
/// 二维码
///
///
///
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);
}
}
///
/// 获取文件的绝对路径
///
/// 相对路径
///
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;
/////
///// 获取本地IP地址信息
/////
//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 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 动态数据集合
}