Ejemplo n.º 1
0
        //如果存在员工排班,则不可删除
        public ActionResult Delete(int id, FormCollection collection)
        {
            ResultMessage msg = new ResultMessage();

            try
            {
                IShiftScheduleService shfSi = new ShiftSheduleService(Settings.Default.db);
                ShiftSchedule         shf   = shfSi.FindShiftScheduleByShiftId(id);

                if (null != shf && shf.id > 0)
                {
                    msg.Success = false;
                    msg.Content = "班次信息正在使用,不能删除!";

                    return(Json(msg, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    IShiftService cs        = new ShiftService(Settings.Default.db);
                    bool          isSucceed = cs.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));
            }
        }
Ejemplo n.º 2
0
        // GET: ShiftShedule/Delete/5
        public ActionResult Delete(int id)
        {
            IShiftScheduleService cs = new ShiftSheduleService(Settings.Default.db);

            ShiftSchedule cp = cs.FindById(id);

            SetDropDownList(cp);
            return(View(cp));
        }
Ejemplo n.º 3
0
        // GET: ShiftShedule/Edit/5
        public ActionResult Edit(int id)
        {
            IShiftScheduleService cs = new ShiftSheduleService(Settings.Default.db);

            ShiftSchedule jt = cs.FindById(id);

            SetDropDownList(jt);
            return(View(jt));
        }
Ejemplo n.º 4
0
        public ResultMessage DoValidation(ShiftSchedule model)
        {
            ResultMessage msg = new ResultMessage();

            if (string.IsNullOrEmpty(model.staffNr))
            {
                msg.Success = false;
                msg.Content = "员工不能为空";

                return(msg);
            }

            if (model.scheduleAt == null || model.scheduleAt == DateTime.MinValue)
            {
                msg.Success = false;
                msg.Content = "日期不能为空";

                return(msg);
            }

            if (model.shiftId == 0)
            {
                msg.Success = false;
                msg.Content = "班次不能为空";

                return(msg);
            }

            IStaffService ss = new StaffService(Settings.Default.db);

            if (ss.FindByNr(model.staffNr) == null)
            {
                msg.Success = false;
                msg.Content = "员工号不存在";

                return(msg);
            }

            IShiftScheduleService cs = new ShiftSheduleService(Settings.Default.db);

            if (cs.IsDup(model))
            {
                msg.Success = false;
                msg.Content = "排班已存在,不可重复排班";

                return(msg);
            }

            return(new ResultMessage()
            {
                Success = true, Content = ""
            });
        }
Ejemplo n.º 5
0
        public ActionResult Edit([Bind(Include = "id,shiftId,staffNr,scheduleAt")] ShiftSchedule model)
        {
            ResultMessage msg = new ResultMessage();

            try
            {
                msg = DoValidation(model);

                if (!msg.Success)
                {
                    return(Json(msg, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    IShiftScheduleService cs = new ShiftSheduleService(Settings.Default.db);
                    bool isSucceed           = cs.Update(model);

                    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));
            }
            //try
            //{
            //    // TODO: Add update logic here
            //    IShiftScheduleService cs = new ShiftSheduleService(Settings.Default.db);

            //    bool updateResult = cs.Update(model);
            //    if (!updateResult)
            //    {
            //        SetDropDownList(model);
            //        return View();
            //    }
            //    else
            //    {
            //        return RedirectToAction("Index");
            //    }

            //}
            //catch
            //{
            //    return View();
            //}
        }
Ejemplo n.º 6
0
        public ActionResult Search([Bind(Include = "StaffNr,StaffNrAct,ScheduleAtFrom,ScheduleAtEnd")]  ShiftScheduleSearchModel q)
        {
            int pageIndex = 0;

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

            IShiftScheduleService ss = new ShiftSheduleService(Settings.Default.db);

            IPagedList <ShiftSchedule> models = ss.Search(q).ToPagedList(pageIndex, Settings.Default.pageSize);

            ViewBag.Query = q;

            return(View("Index", models));
        }
Ejemplo n.º 7
0
        public ActionResult Create([Bind(Include = "shiftId,staffNr,scheduleAt")] ShiftSchedule model)
        {
            ResultMessage msg = new ResultMessage();

            try
            {
                msg = DoValidation(model);

                if (!msg.Success)
                {
                    return(Json(msg, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    IShiftScheduleService cs = new ShiftSheduleService(Settings.Default.db);
                    bool isSucceed           = cs.Create(model);

                    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));
            }
            //try
            //{
            //    // TODO: Add insert logic here

            //    IShiftScheduleService cs = new ShiftSheduleService(Settings.Default.db);

            //    //model.absenceDate = HttpContext.Request.Form["absenceDate"];
            //    cs.Create(model);
            //   return RedirectToAction("Index");
            //}
            //catch
            //{
            //    return View();
            //}
        }
Ejemplo n.º 8
0
        public ActionResult Index(int?page)
        {
            int pageIndex = PagingHelper.GetPageIndex(page);

            ShiftScheduleSearchModel q = new ShiftScheduleSearchModel();

            IShiftScheduleService ss = new ShiftSheduleService(Settings.Default.db);

            IPagedList <ShiftSchedule> models = ss.Search(q).ToPagedList(pageIndex, Settings.Default.pageSize);

            ViewBag.Query = q;

            ShiftScheduleInfoModel info = ss.GetShiftScheduleInfo(q);

            ViewBag.Info = info;

            return(View(models));
        }
Ejemplo n.º 9
0
        public ActionResult Delete(int id, FormCollection collection)
        {
            ResultMessage msg = new ResultMessage();

            try
            {
                // TODO: Add delete logic here
                IShiftScheduleService cs = new ShiftSheduleService(Settings.Default.db);
                msg.Success = cs.DeleteById(id);
                return(Json(msg, JsonRequestBehavior.AllowGet));
                //return RedirectToAction("Index");
            }
            catch (Exception ex)
            {
                msg.Content = ex.Message;
                return(Json(msg, JsonRequestBehavior.AllowGet));
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// 验证
        /// </summary>
        /// <param name="model"></param>
        /// <param name="dbString"></param>
        public void Validate(string dbString)
        {
            ValidateMessage msg = new ValidateMessage();



            if (string.IsNullOrEmpty(this.StaffNr))
            {
                msg.Contents.Add("人员编号不可空");
            }
            else
            {
                Staff staff = new StaffService(dbString).FindByNr(this.StaffNr);
                if (staff == null)
                {
                    msg.Contents.Add("人员编号不存在");
                }
            }

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



            if (string.IsNullOrEmpty(this.ShiftCode))
            {
                msg.Contents.Add("班次号不可空");
            }
            else
            {
                IShiftService ss = new ShiftService(dbString);
                Shift         r  = ss.FindByCode(this.ShiftCode);
                if (r == null)
                {
                    msg.Contents.Add("班次号不存在");
                }
                else
                {
                    this.Shift = r;
                }
            }

            if (msg.Contents.Count == 0)
            {
                if (this.ScheduleAt.HasValue)
                {
                    IShiftScheduleService ss = new ShiftSheduleService(dbString);

                    if (ss.IsDup(new ShiftSchedule()
                    {
                        id = 0, scheduleAt = this.ScheduleAt.Value, shiftId = this.Shift.id, staffNr = this.StaffNr
                    }))
                    {
                        msg.Contents.Add("排班记录已存在,不可重复导入");
                    }
                }
            }

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

            this.ValidateMessage = msg;
        }
Ejemplo n.º 11
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);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// 导入
        /// </summary>
        /// <returns></returns>
        public ImportMessage Import()
        {
            ImportMessage msg = new ImportMessage()
            {
                Success = true
            };

            try
            {
                FileInfo fileInfo = new FileInfo(this.FilePath);
                List <ShiftScheduleExcelModel> records = new List <ShiftScheduleExcelModel>();
                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 ShiftScheduleExcelModel()
                            {
                                StaffNr           = ws.Cells[i, 1].Value == null?string.Empty : ws.Cells[i, 1].Value.ToString(),
                                Name              = ws.Cells[i, 2].Value == null ? string.Empty : ws.Cells[i, 2].Value.ToString(),
                                ScheduleAtDateStr = ws.Cells[i, 3].Value == null ? string.Empty : ws.Cells[i, 3].Value.ToString(),
                                ShiftCode         = ws.Cells[i, 4].Value == null ? string.Empty : ws.Cells[i, 4].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 < ShiftScheduleExcelModel.Headers.Count(); i++)
                                {
                                    sheet.Cells[1, i + 1].Value = ShiftScheduleExcelModel.Headers[i];
                                }
                                ///写入错误数据
                                for (int i = 0; i < records.Count(); i++)
                                {
                                    sheet.Cells[i + 2, 1].Value = records[i].StaffNr;
                                    sheet.Cells[i + 2, 2].Value = records[i].Name;
                                    sheet.Cells[i + 2, 3].Value = records[i].ScheduleAtDateStr;
                                    sheet.Cells[i + 2, 4].Value = records[i].ShiftCode;
                                    sheet.Cells[i + 2, 5].Value = records[i].ValidateMessage.ToString();
                                }

                                /// 保存
                                ep.Save();
                            }
                        }
                        else
                        {
                            /// 数据写入数据库
                            List <ShiftSchedule>  details = ShiftScheduleExcelModel.Convert(records);
                            IShiftScheduleService ss      = new ShiftSheduleService(this.DbString);
                            ss.Creates(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);
        }