private void LoadData(AttendanceRecord attendanceRecord) { var errCode = 0; var errMsg = string.Empty; todayAttendanceRecords = attendanceRecord; if (todayAttendanceRecords == null) { return; } checkInDataTime = todayAttendanceRecords.PuncherDateTime; AntSdkQuerySystemDateOuput serverResult = AntSdkService.AntSdkGetCurrentSysTime(ref errCode, ref errMsg); DateTime serverDateTime = DateTime.Now; if (serverResult != null) { serverDateTime = PublicTalkMothed.ConvertStringToDateTime(serverResult.systemCurrentTime); } var diffMinute = serverDateTime - checkInDataTime; if (checkInDataTime.ToShortDateString() != serverDateTime.ToShortDateString()) { return; } if (diffMinute.Hours > 6) { return; } if (diffMinute.Days > 0 || diffMinute.TotalMinutes > 20 || !todayAttendanceRecords.IsbtnVerify) { return; } //设置定时器 timer?.Stop(); timer = null; timer = new DispatcherTimer(); timer.Interval = new TimeSpan(0, 0, 0, 1); //时间间隔为一秒 timer.Tick += new EventHandler(timer_Tick); var minuteChangeSecond = 0d; if (diffMinute.TotalMinutes < 0) { minuteChangeSecond = (20 - 0.01) * 60; } else { minuteChangeSecond = (20 - diffMinute.TotalMinutes) * 60; } //处理倒计时的类 processCount = new ProcessCount((int)minuteChangeSecond); //Application.Current.Dispatcher.Invoke((Action)(() => //{ todayAttendanceRecords.ChcekInTimer = "(" + processCount.GetMinute() + "分" + processCount.GetSecond() + "秒" + ")"; //})); CountDown += new CountDownHandler(processCount.ProcessCountDown); //开启定时器 timer.Start(); }
/// <summary> /// 获取服务器考勤记录 /// </summary> public void GetServicePunchClocksData(bool isNewRecord = false) { if (isNewRecord) { _isLast = false; } if (_isLast) { return; } AsyncHandler.CallFuncWithUI(System.Windows.Application.Current.Dispatcher, () => { if (isNewRecord) { timer?.Stop(); timer = null; _page = 0; todayAttendanceRecords = null; } _page++; var errorCode = 0; var errorMsg = string.Empty; var punchClocksOutput = AntSdkService.GetPunchClocks(AntSdkService.AntSdkLoginOutput.userId, _page, _size, ref errorCode, ref errorMsg); return(punchClocksOutput); }, (ex, datas) => { if (isNewRecord) { AttendanceRecords.Clear(); } if (datas != null && datas.list.Count > 0) { var serverDateTime = PublicTalkMothed.ConvertStringToDateTime(datas.systemTime); var punchClocksOutputList = datas.list.OrderByDescending(m => m.attendId); foreach (var punchClocks in datas.list) { var exitAttendanceRecord = AttendanceRecords.FirstOrDefault(m => m.AttendId == punchClocks.attendId); if (exitAttendanceRecord != null) { continue; } var attendanceRecord = new AttendanceRecord(); attendanceRecord.AttendId = punchClocks.attendId; attendanceRecord.VerifyState = punchClocks.status; attendanceRecord.PuncherTimeStamp = punchClocks.attendTime; if (attendanceRecord.VerifyState == 0) { attendanceRecord.IsbtnVerify = true; attendanceRecord.VerifyDescribe = "待验证"; } else if (attendanceRecord.VerifyState == 1) { attendanceRecord.VerifyDescribe = "验证过期"; } else if (attendanceRecord.VerifyState == 2) { attendanceRecord.VerifyDescribe = "打卡成功"; } var diffMinute = serverDateTime - PublicTalkMothed.ConvertStringToDateTime(punchClocks.attendTime); if ((diffMinute.Days > 0 || diffMinute.TotalMinutes > 20) && attendanceRecord.VerifyState == 0) { attendanceRecord.IsbtnVerify = false; attendanceRecord.VerifyDescribe = "验证过期"; attendanceRecord.VerifyState = 1; } if (!string.IsNullOrEmpty(punchClocks.attendTime)) { attendanceRecord.PuncherDateTime = PublicTalkMothed.ConvertStringToDateTime(punchClocks.attendTime); } else { attendanceRecord.PuncherDateTime = DateTime.Now; } attendanceRecord.PuncherAddress = punchClocks.address; if (attendanceRecord.PuncherDateTime.Year - DateTime.Now.Year > 0) { attendanceRecord.PuncherDate = attendanceRecord.PuncherDateTime.ToString("yyyy年MM月dd日"); } else { attendanceRecord.PuncherDate = attendanceRecord.PuncherDateTime.ToString("MM月dd日"); } attendanceRecord.PuncherTime = attendanceRecord.PuncherDateTime.ToString("HH:mm"); AttendanceRecords.Insert(0, attendanceRecord); } _isFirst = datas.isFirstPage; _isLast = datas.isLastPage; var tempAttendanceRecord = AttendanceRecords.FirstOrDefault(m => m.IsbtnVerify); if (tempAttendanceRecord != null) { LoadData(tempAttendanceRecord); } } else { } }); }