// GET: AttendanceRecordCal/Delete/5 public ActionResult Delete(int id) { IAttendanceRecordCalService arcs = new AttendanceRecordCalService(Settings.Default.db); AttendanceRecordCal record = arcs.FindById(id); SetExtraWorkTypeList(record.extraworkType); if (record != null) { AbsenceRecordView absenceRecord = new AbsenceRecordService(Settings.Default.db).FindViewByStaffNrAndDate(record.staffNr, record.attendanceDate); ExtraWorkRecordView extraWorkRecord = new ExtraWorkRecordService(Settings.Default.db).FindViewByStaffNrAndDate(record.staffNr, record.attendanceDate); List <AttendanceRecordDetailView> records = new List <AttendanceRecordDetailView>(); IAttendanceRecordDetailService s = new AttendanceRecordDetailService(Settings.Default.db); records = s.GetDetailsViewByStaffAndDateWithExtrawork(record.staffNr, record.attendanceDate); ViewData["attendRecords"] = records; ViewData["absenceRecord"] = absenceRecord; ViewData["extraWorkRecord"] = extraWorkRecord; } else { SetExtraWorkTypeList(null); } return(View(record)); }
/// <summary> /// 导出处理过的考勤记录 /// </summary> /// <param name="startDate"></param> /// <param name="endDate"></param> /// <param name="searchModel"></param> /// <returns></returns> public ReportMessage ExportHandledAttendDetail(DateTime startDate, DateTime endDate, StaffSearchModel searchModel) { ReportMessage msg = new ReportMessage(); string fileName = "考勤记录表.xlsx"; try { string tmpFile = FileHelper.CreateFullTmpFilePath(fileName, false); msg.Content = FileHelper.GetDownloadTmpFilePath(tmpFile); FileInfo fileInfo = new FileInfo(tmpFile); List <WorkSumExcelModel> records = new ExcelReportService(this.DbString).GetSumExcelModels(startDate, endDate, searchModel); List <WorkAndRest> wrs = new WorkAndRestService(this.DbString).GetByDateSpan(startDate, endDate); int OriginAttendDays = wrs.Where(s => s.IsWorkDay).Count(); List <string[]> excelRecords = new List <string[]>(); foreach (var r in records) { IShiftScheduleService ss = new ShiftSheduleService(this.DbString); List <ShiftScheduleView> shifts = ss.GetShiftsByStaffAndDateSpan(r.Staff.nr, startDate, endDate); // 每个Items代表一天 foreach (var rr in r.Items) { List <AttendanceRecordDetailView> atts = new List <AttendanceRecordDetailView>(); // 是否被减过加班时间 if (rr.IsMinusedHolidayWorkHour || rr.IsMinusedThresholdHour) { if (rr.MinuseHolidayWorkAndThresHoldLeftExtraHour == 0) { if (rr.WorkAndRest.IsWorkDay) { // 看看是不是有排班,根据排班的情况造数据,开始结束有25-45分钟的冗余, // 就是下班到打卡设备的时间 // var shift = ss.GetFirstShiftByStaffAndDate(rr.Staff.nr, rr.DateTime); var shift = shifts.Where(s => s.fullEndAt.Value.Date == rr.DateTime).FirstOrDefault(); if (shift == null) { // break; } else { DateTime startTime = shift.fullStartAt.Value.AddMinutes(0 - new Random().Next(25, 45)); DateTime endTime = shift.fullEndAt.Value.AddHours(rr.MinuseHolidayWorkAndThresHoldLeftExtraHour).AddMinutes(new Random().Next(25, 45)); if (rr.MinuseHolidayWorkAndThresHoldLeftExtraHour > 0) { int u = 0; } excelRecords.Add(new string[6] { rr.Staff.departmentName, rr.Staff.nr, rr.Staff.name, startTime.ToString("yyyy-MM-dd"), startTime.ToString("HH:mm"), "001" }); excelRecords.Add(new string[6] { rr.Staff.departmentName, rr.Staff.nr, rr.Staff.name, endTime.ToString("yyyy-MM-dd"), endTime.ToString("HH:mm"), "001" }); } } else { // 直接跳过这一天 // break; } } } else { // 如果没有就使用原始的出勤时间 IAttendanceRecordDetailService s = new AttendanceRecordDetailService(this.DbString); atts = s.GetDetailsViewByStaffAndDateWithExtrawork(rr.Staff.nr, rr.DateTime); foreach (var a in atts) { excelRecords.Add(new string[6] { rr.Staff.departmentName, rr.Staff.nr, rr.Staff.name, a.recordAtDateStr, a.recordAtTimeStr, a.device }); } } } } using (ExcelPackage ep = new ExcelPackage(fileInfo)) { ExcelWorksheet sheet = ep.Workbook.Worksheets.Add("Sheet1"); string[] titles = new string[6] { "机构名称", "人员编号", "姓名", "刷卡日期", "刷卡时间", "设备编号" }; for (var i = 0; i < titles.Length; i++) { sheet.Cells[1, i + 1].Value = titles[i]; } int row = 2; foreach (var er in excelRecords) { for (var i = 0; i < titles.Length; i++) { sheet.Cells[row, i + 1].Value = er[i]; } row += 1; } ep.Save(); } msg.Success = true; } catch (Exception ex) { LogUtil.Logger.Error(ex.Message, ex); msg.Content = ex.Message; } return(msg); }