public JsonResult Create([Bind(Include = "staffNr,recordAt,device")] AttendanceRecordDetail ard)
        {
            ResultMessage msg = new ResultMessage();

            try
            {
                msg = DoValidation(ard);

                if (!msg.Success)
                {
                    return(Json(msg, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    IAttendanceRecordDetailService ards = new AttendanceRecordDetailService(Settings.Default.db);
                    bool isSucceed = ards.Create(ard);

                    msg.Success = isSucceed;
                    msg.Content = isSucceed ? "" : "可能员工打卡时间已经存在";

                    return(Json(msg, JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception ex)
            {
                return(Json(new ResultMessage()
                {
                    Success = false, Content = ex.Message
                }, JsonRequestBehavior.AllowGet));
            }
        }
Exemplo n.º 2
0
        // 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));
        }
        // GET: AttendanceRecordDetail/Edit/5
        public ActionResult Edit(int id)
        {
            IAttendanceRecordDetailService ards = new AttendanceRecordDetailService(Settings.Default.db);

            AttendanceRecordDetail ard = ards.FindById(id);

            return(View(ard));
        }
        public ActionResult Index(int?page)
        {
            int pageIndex = PagingHelper.GetPageIndex(page);
            AttendanceRecordDetailSearchModel q  = new AttendanceRecordDetailSearchModel();
            IAttendanceRecordDetailService    ss = new AttendanceRecordDetailService(Settings.Default.db);

            IPagedList <AttendanceRecordDetailView> records = ss.SearchDetailView(q).ToPagedList(pageIndex, Settings.Default.pageSize);

            ViewBag.Query = q;
            SetShiftList();
            return(View(records));
        }
        public ActionResult Search([Bind(Include = "CompanyId,DepartmentId,StaffNr,RecordAtFrom,RecordAtEnd")] AttendanceRecordDetailSearchModel q)
        {
            int pageIndex = 0;

            int.TryParse(Request.QueryString.Get("page"), out pageIndex);
            pageIndex = PagingHelper.GetPageIndex(pageIndex);

            IAttendanceRecordDetailService ss = new AttendanceRecordDetailService(Settings.Default.db);

            IPagedList <AttendanceRecordDetailView> records = ss.SearchDetailView(q).ToPagedList(pageIndex, Settings.Default.pageSize);

            ViewBag.Query = q;
            SetShiftList();
            return(View("Index", records));
        }
        public ActionResult Delete(int id, FormCollection collection)
        {
            ResultMessage msg = new ResultMessage();

            try
            {
                IAttendanceRecordDetailService ards = new AttendanceRecordDetailService(Settings.Default.db);
                bool isSucceed = ards.DeleteById(id);

                msg.Success = isSucceed;
                msg.Content = isSucceed ? "" : "删除失败";

                return(Json(msg, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(Json(new ResultMessage()
                {
                    Success = false, Content = ex.Message
                }, JsonRequestBehavior.AllowGet));
            }
        }
Exemplo n.º 7
0
        /// <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);
        }
Exemplo n.º 8
0
        /// <summary>
        /// 验证
        /// </summary>
        /// <param name="model"></param>
        /// <param name="dbString"></param>
        public void Validate(string dbString)
        {
            ValidateMessage msg = new ValidateMessage();

            if (string.IsNullOrEmpty(this.DepartmentName))
            {
                msg.Contents.Add("机构名称不可空");
            }

            if (string.IsNullOrEmpty(this.StaffNr))
            {
                msg.Contents.Add("人员编号不可空");
            }
            else
            {
                Staff staff = new StaffService(dbString).FindByNr(this.StaffNr);
                if (staff == null)
                {
                    msg.Contents.Add("人员编号不存在");
                }
                else
                {
                    AttendanceRecordDetail detail = new AttendanceRecordDetailService(dbString).FindDetailByStaffAndRecordAt(this.StaffNr, this.RecordAt.Value);
                    if (detail != null)
                    {
                        msg.Contents.Add("打卡记录已存在,不可重复导入");
                    }
                }
            }

            if (string.IsNullOrEmpty(this.RecordAtDateStr))
            {
                msg.Contents.Add("刷卡日期不可空");
            }
            else
            {
                DateTime dt = DateTime.Now;
                if (DateTime.TryParse(this.RecordAtDateStr, out dt))
                {
                    //this.RecordAtDate = dt;
                }
                else
                {
                    msg.Contents.Add("刷卡日期格式错误");
                }
            }


            if (string.IsNullOrEmpty(this.RecordAtTimeStr))
            {
                msg.Contents.Add("刷卡时间不可空");
            }
            else
            {
                TimeSpan ts = DateTime.Now.TimeOfDay;
                if (TimeSpan.TryParse(this.RecordAtTimeStr, out ts))
                {
                    //   this.RecordAtTime = ts;
                }
                else
                {
                    msg.Contents.Add("刷卡时间格式错误");
                }
            }

            if (string.IsNullOrEmpty(this.Device))
            {
                msg.Contents.Add("设备编号不可空");
            }

            msg.Success = msg.Contents.Count == 0;

            this.ValidateMessage = msg;
        }
        /// <summary>
        /// 导入
        /// </summary>
        /// <returns></returns>
        public ImportMessage Import()
        {
            ImportMessage msg = new ImportMessage()
            {
                Success = true
            };

            try
            {
                FileInfo fileInfo = new FileInfo(this.FilePath);
                List <AttendanceRecordDetailExcelModel> records = new List <AttendanceRecordDetailExcelModel>();
                string sheetName = "Tmp";
                /// 读取excel文件
                using (ExcelPackage ep = new ExcelPackage(fileInfo))
                {
                    if (ep.Workbook.Worksheets.Count > 0)
                    {
                        ExcelWorksheet ws = ep.Workbook.Worksheets.First();
                        sheetName = ws.Name;
                        for (int i = 2; i <= ws.Dimension.End.Row; i++)
                        {
                            records.Add(new AttendanceRecordDetailExcelModel()
                            {
                                DepartmentName  = ws.Cells[i, 1].Value == null?string.Empty : ws.Cells[i, 1].Value.ToString(),
                                StaffNr         = ws.Cells[i, 2].Value == null ? string.Empty : ws.Cells[i, 2].Value.ToString(),
                                Name            = ws.Cells[i, 3].Value == null ? string.Empty : ws.Cells[i, 3].Value.ToString(),
                                RecordAtDateStr = ws.Cells[i, 4].Value == null ? string.Empty : ws.Cells[i, 4].Value.ToString(),
                                RecordAtTimeStr = ws.Cells[i, 5].Value == null ? string.Empty : ws.Cells[i, 5].Value.ToString(),
                                Device          = ws.Cells[i, 6].Value == null ? string.Empty : ws.Cells[i, 6].Value.ToString()
                            });
                        }
                    }
                    else
                    {
                        msg.Success = false;
                        msg.Content = "文件不包含数据表,请检查";
                    }
                }
                if (msg.Success)
                {
                    /// 验证数据
                    if (records.Count > 0)
                    {
                        Validates(records);
                        if (records.Where(s => s.ValidateMessage.Success == false).Count() > 0)
                        {
                            /// 创建错误文件
                            msg.Success = false;
                            /// 写入文件夹,然后返回
                            string tmpFile = FileHelper.CreateFullTmpFilePath(Path.GetFileName(this.FilePath), true);
                            msg.Content       = FileHelper.GetDownloadTmpFilePath(tmpFile);
                            msg.ErrorFileFeed = true;

                            FileInfo tmpFileInfo = new FileInfo(tmpFile);
                            using (ExcelPackage ep = new ExcelPackage(tmpFileInfo))
                            {
                                ExcelWorksheet sheet = ep.Workbook.Worksheets.Add(sheetName);
                                ///写入Header
                                for (int i = 0; i < AttendanceRecordDetailExcelModel.Headers.Count(); i++)
                                {
                                    sheet.Cells[1, i + 1].Value = AttendanceRecordDetailExcelModel.Headers[i];
                                }
                                ///写入错误数据
                                for (int i = 0; i < records.Count(); i++)
                                {
                                    sheet.Cells[i + 2, 1].Value = records[i].DepartmentName;
                                    sheet.Cells[i + 2, 2].Value = records[i].StaffNr;
                                    sheet.Cells[i + 2, 3].Value = records[i].Name;
                                    sheet.Cells[i + 2, 4].Value = records[i].RecordAtDateStr;
                                    sheet.Cells[i + 2, 5].Value = records[i].RecordAtTimeStr;
                                    sheet.Cells[i + 2, 6].Value = records[i].Device;
                                    sheet.Cells[i + 2, 7].Value = records[i].ValidateMessage.ToString();
                                }

                                /// 保存
                                ep.Save();
                            }
                        }
                        else
                        {
                            /// 数据写入数据库
                            List <AttendanceRecordDetail>  details = AttendanceRecordDetailExcelModel.Convert(records);
                            IAttendanceRecordDetailService ss      = new AttendanceRecordDetailService(this.DbString);
                            ss.CreateDetails(details);
                        }
                    }
                    else
                    {
                        msg.Success = false;
                        msg.Content = "文件不包含数据,请检查";
                    }
                }
            }
            catch (Exception e)
            {
                msg.Success = false;
                msg.Content = "导入失败:" + e.Message + ",请联系系统管理员";
                LogUtil.Logger.Error(e.Message);
                LogUtil.Logger.Error(e.StackTrace);
            }
            return(msg);
        }