星火直播PC
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

AttendanceWindow.xaml.cs 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  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.Model;
  10. namespace XHZB.Desktop
  11. {
  12. /// <summary>
  13. /// 考勤统计
  14. /// </summary>
  15. public partial class AttendanceWindow : Window/*, ZSocketCallback*/
  16. {
  17. #region 字段
  18. /// <summary>
  19. /// 前台绑定数据源
  20. /// </summary>
  21. internal ToolbarAttendenceModel pageData = new ToolbarAttendenceModel();
  22. #endregion 字段
  23. #region 初始化
  24. /// <summary>
  25. /// 考勤统计
  26. /// </summary>
  27. public AttendanceWindow()
  28. {
  29. InitializeComponent();
  30. WindowStartupLocation = WindowStartupLocation.CenterScreen;
  31. Initialize();
  32. }
  33. /// <summary>
  34. /// 初始化 修改人:赵耀 修改时间:2020年8月11日
  35. /// </summary>
  36. public void Initialize()
  37. {
  38. //try
  39. //{
  40. // GetAddressIP();
  41. //}
  42. //catch (Exception ex)
  43. //{
  44. // LogHelper.WriteErrLog("【AttendanceWindow】(Initialize)" + ex.Message, ex);
  45. //}
  46. pageData = new ToolbarAttendenceModel();
  47. int onlineUsersnum = APP.ClassStudentList.Count;
  48. txbTotalPeople.Text = onlineUsersnum.ToString();
  49. renderView();
  50. //ZSocketServer.getInstance().addWin(this);
  51. //if (gridImg.Visibility == Visibility.Visible)
  52. //{
  53. // gridImg.Visibility = Visibility.Collapsed;
  54. //}
  55. DataContext = pageData;
  56. }
  57. private void Window_MouseLeftButtonDown_1(object sender, MouseButtonEventArgs e)
  58. {
  59. DragMove();
  60. }
  61. public void receiveWsMsg(ZWsMsgVo msg)
  62. {
  63. }
  64. public void userListChange()
  65. {
  66. Console.WriteLine("抢答点名-渲染用户列表");
  67. Dispatcher.BeginInvoke(DispatcherPriority.Normal,
  68. new Action(() =>
  69. {
  70. renderView();
  71. }));
  72. }
  73. #endregion 初始化
  74. #region 事件
  75. /// <summary>
  76. /// 结束
  77. /// </summary>
  78. /// <param name="sender"></param>
  79. /// <param name="e"></param>
  80. private void btnEnd_Click(object sender, RoutedEventArgs e)
  81. {
  82. if (pageData.menuList.Count > 0)
  83. {
  84. pageData.menuList.Clear();
  85. }
  86. //ToolbarWindow.IsOpenAttendanceWindow = false;
  87. Hide();
  88. FreeMemoryHelper.ReallocateMemory();
  89. System.Threading.Thread.Sleep(0);
  90. }
  91. #endregion 事件
  92. private void renderView()
  93. {
  94. if (pageData.menuList.Count > 0)
  95. {
  96. pageData.menuList.Clear();
  97. }
  98. if (APP.OnlineUserList.Count > 0)
  99. {
  100. var userList = APP.OnlineUserList.ToArray();
  101. string userlistStr = JsonHelper.ToJson(userList);
  102. List<OnlineUserModel> userListNew = ZCache.JsonToList<OnlineUserModel>(userlistStr);
  103. List<ClassStudentListModel> classStudentList = APP.ClassStudentList;
  104. //if (APP.outputInforLog)
  105. //{//OrderbyDescending 倒叙 OrderBy 顺序
  106. // userListNew = userListNew.OrderBy(x => x.userid).ToList();
  107. //}
  108. for (int i = 0; i < classStudentList.Count; i++)
  109. {
  110. classStudentList[i].status = 0;
  111. }
  112. //if (userListNew.Count > 1)
  113. //{
  114. // userListNew[1] = null;
  115. //}
  116. //userListNew[0] = null;
  117. foreach (OnlineUserModel user in userListNew)
  118. {
  119. if (user != null)
  120. {
  121. string userHeadPic;
  122. if (user.userpic != null)
  123. {
  124. userHeadPic = user.userpic;
  125. if (ZCache.headDic.ContainsKey(userHeadPic.Replace("/", "")))
  126. {
  127. string localpath = ZCache.headDic[userHeadPic.Replace("/", "")];
  128. userHeadPic = localpath;
  129. }
  130. else
  131. {
  132. userHeadPic = "../Images/RollCall/attendance_1.png";
  133. }
  134. }
  135. else
  136. {
  137. userHeadPic = "../Images/RollCall/attendance_1.png";
  138. }
  139. pageData.menuList.Add(new ToolbarAttendenceMenu()
  140. {
  141. Name = user.username,
  142. Pic = userHeadPic
  143. });
  144. foreach (ClassStudentListModel cl in classStudentList)
  145. {
  146. if (cl.studentid == user.userid)
  147. {
  148. cl.status = 1;
  149. }
  150. }
  151. }
  152. }
  153. string notOnline = string.Empty;
  154. foreach (ClassStudentListModel cl in classStudentList)
  155. {
  156. if (cl.status == 0)
  157. {
  158. notOnline += cl.studentname + " ";
  159. }
  160. }
  161. if (!string.IsNullOrWhiteSpace(notOnline))
  162. {
  163. txbNotOnline.Text = notOnline;
  164. }
  165. else
  166. {
  167. txbNotOnline.Text = "暂无";
  168. }
  169. txbOnlineUsers.Text = userListNew.Count.ToString();
  170. userList = null;
  171. userlistStr = null;
  172. userListNew = null;
  173. classStudentList = null;
  174. }
  175. else
  176. {
  177. List<ClassStudentListModel> classStudentList = APP.ClassStudentList;
  178. //userListNew.Sort();
  179. for (int i = 0; i < classStudentList.Count; i++)
  180. {
  181. classStudentList[i].status = 0;
  182. }
  183. string notOnline = string.Empty;
  184. foreach (ClassStudentListModel cl in classStudentList)
  185. {
  186. if (cl.status == 0)
  187. {
  188. notOnline += cl.studentname + " ";
  189. }
  190. }
  191. if (!string.IsNullOrWhiteSpace(notOnline))
  192. {
  193. txbNotOnline.Text = notOnline;
  194. }
  195. else
  196. {
  197. txbNotOnline.Text = "暂无";
  198. }
  199. txbOnlineUsers.Text = APP.OnlineUserList.Count.ToString();
  200. }
  201. }
  202. private void Window_Loaded(object sender, RoutedEventArgs e)
  203. {
  204. }
  205. private void Window_Unloaded(object sender, RoutedEventArgs e)
  206. {
  207. //ZSocketServer.getInstance().removedWin(this);
  208. }
  209. private void Window_Closed(object sender, EventArgs e)
  210. {
  211. }
  212. public void Dispose()
  213. {
  214. Dispose(true);
  215. GC.SuppressFinalize(this);
  216. }
  217. protected virtual void Dispose(bool disposing)
  218. {
  219. if (!m_disposed)
  220. {
  221. if (disposing)
  222. {
  223. //Release managed resources
  224. }
  225. //Release unmanaged resources
  226. m_disposed = true;
  227. }
  228. }
  229. //C#的Finalize()方法
  230. ~AttendanceWindow()
  231. {
  232. Dispose(false);
  233. }
  234. private bool m_disposed;
  235. /// <summary>
  236. /// 二维码
  237. /// </summary>
  238. /// <param name="sender"></param>
  239. /// <param name="e"></param>
  240. private void Button_Click(object sender, RoutedEventArgs e)
  241. {
  242. try
  243. {
  244. if (gridImg.Visibility == Visibility.Visible)
  245. {
  246. gridImg.Visibility = Visibility.Collapsed;
  247. }
  248. else
  249. {
  250. gridImg.Visibility = Visibility.Visible;
  251. }
  252. }
  253. catch (Exception ex)
  254. {
  255. LogHelper.WriteErrLog("【AttendanceWindow】" + ex.Message, ex);
  256. }
  257. }
  258. /// <summary>
  259. /// 获取文件的绝对路径
  260. /// </summary>
  261. /// <param name="Path">相对路径</param>
  262. /// <returns></returns>
  263. public string GetFileAbsolutePath(string Path = "")
  264. {
  265. try
  266. {
  267. if (!string.IsNullOrWhiteSpace(Path))
  268. {
  269. Path = Path.Replace("\\", "/");
  270. if (Path != "/")
  271. {
  272. if (Path.Substring(1, 1) == ":")
  273. return Path;
  274. if (Path.Substring(0, 1) != "/")
  275. Path = "/" + Path;
  276. }
  277. }
  278. string AbsolutePath = System.Windows.Forms.Application.StartupPath.ToString().Replace("\\", "/") + Path;
  279. return AbsolutePath;
  280. }
  281. catch (Exception)
  282. {
  283. return Path;
  284. }
  285. }
  286. //private void CreateQR(int pixelsPerModule, string info, System.Drawing.Color qrColor, System.Drawing.Color qrBackgroundColor, int iconSizePercent = 15, int iconBorderWidth = 6)
  287. //{
  288. // try
  289. // {
  290. // gridImg.Visibility = Visibility.Visible;
  291. // QRCodeGenerator qrGenerator = new QRCodeGenerator();
  292. // QRCodeData qrCodeData = qrGenerator.CreateQrCode(info, QRCodeGenerator.ECCLevel.Q);
  293. // QRCode qrCode = new QRCode(qrCodeData);
  294. // //Bitmap qrCodeImage = qrCode.GetGraphic(pixelsPerModule, qrColor, qrBackgroundColor, logo, iconSizePercent, iconBorderWidth, true);
  295. // Bitmap qrCodeImage = qrCode.GetGraphic(pixelsPerModule, qrColor, qrBackgroundColor, true);
  296. // IntPtr hBitmap = qrCodeImage.GetHbitmap();
  297. // ImageSource wpfBitmap = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(
  298. // hBitmap,
  299. // IntPtr.Zero,
  300. // Int32Rect.Empty,
  301. // BitmapSizeOptions.FromEmptyOptions());
  302. // img.Source = wpfBitmap;
  303. // }
  304. // catch (Exception ex)
  305. // {
  306. // LogHelper.WriteErrLog("【AttendanceWindow】(CreateQR)" + ex.Message, ex);
  307. // }
  308. //}
  309. //string localIp = string.Empty;
  310. ///// <summary>
  311. ///// 获取本地IP地址信息
  312. ///// </summary>
  313. //void GetAddressIP()
  314. //{
  315. // try
  316. // {
  317. // ///获取本地的IP地址
  318. // string AddressIP = string.Empty;
  319. // foreach (IPAddress _IPAddress in Dns.GetHostEntry(Dns.GetHostName()).AddressList)
  320. // {
  321. // if (_IPAddress.AddressFamily.ToString() == "InterNetwork")
  322. // {
  323. // AddressIP = _IPAddress.ToString();
  324. // }
  325. // }
  326. // txtLocalIP.Text = AddressIP + ":10077";
  327. // if (!string.IsNullOrWhiteSpace(txtLocalIP.Text) && !txtLocalIP.Text.Equals(localIp))
  328. // {
  329. // localIp = txtLocalIP.Text;
  330. // CreateQR(100, txtLocalIP.Text, System.Drawing.Color.Black, System.Drawing.Color.White);
  331. // }
  332. // }
  333. // catch (Exception ex)
  334. // {
  335. // LogHelper.WriteErrLog("【AttendanceWindow】" + ex.Message, ex);
  336. // }
  337. //}
  338. }
  339. #region 动态数据集合
  340. public class ToolbarAttendenceModel : NotifyModel
  341. {
  342. public ObservableCollection<ToolbarAttendenceMenu> menuList { get; set; }
  343. public ToolbarAttendenceModel()
  344. {
  345. menuList = new ObservableCollection<ToolbarAttendenceMenu>();
  346. }
  347. }
  348. public class ToolbarAttendenceMenu : NotifyModel, IComparable<ToolbarAttendenceMenu>
  349. {
  350. /// <summary>
  351. /// 姓名
  352. /// </summary>
  353. public string Name { get; set; }
  354. /// <summary>
  355. /// 头像
  356. /// </summary>
  357. public string Pic { get; set; }
  358. public int CompareTo(ToolbarAttendenceMenu other)
  359. {
  360. return string.Compare(Name, other.Name, true);
  361. }
  362. }
  363. #endregion 动态数据集合
  364. }