Beispiel #1
0
        public JsonResult Create([Bind(Include = "Name,code, remark")] AbsenceType model)
        {
            ResultMessage msg = new ResultMessage();

            try
            {
                msg = DoValidation(model);

                if (!msg.Success)
                {
                    return(Json(msg, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    IAbsenceTypeService cs = new AbsenceTypeService(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));
            }
        }
        private void SetAbsenceTypeList(int?type, bool allowBlank = true)
        {
            IAbsenceTypeService cs = new AbsenceTypeService(Settings.Default.db);

            AbsenceTypeSearchModel csm = new AbsenceTypeSearchModel();

            List <AbsenceType> certType = cs.Search(csm).ToList();

            List <SelectListItem> select = new List <SelectListItem>();

            if (allowBlank)
            {
                select.Add(new SelectListItem {
                    Text = "", Value = ""
                });
            }

            foreach (var certt in certType)
            {
                if (type.HasValue && type.ToString().Equals(certt.id))
                {
                    select.Add(new SelectListItem {
                        Text = certt.name, Value = certt.id.ToString(), Selected = true
                    });
                }
                else
                {
                    select.Add(new SelectListItem {
                        Text = certt.name, Value = certt.id.ToString(), Selected = false
                    });
                }
            }
            ViewData["absenceTypeList"] = select;
        }
Beispiel #3
0
        // GET: AbsenceType/Delete/5
        public ActionResult Delete(int id)
        {
            IAbsenceTypeService cs = new AbsenceTypeService(Settings.Default.db);

            AbsenceType cp = cs.FindById(id);

            //SetDropDownList(cp);
            return(View(cp));
        }
Beispiel #4
0
        // GET: AbsenceType/Edit/5
        public ActionResult Edit(int id)
        {
            IAbsenceTypeService cs = new AbsenceTypeService(Settings.Default.db);

            AbsenceType jt = cs.FindById(id);

            //SetDropDownList(jt);
            return(View(jt));
        }
Beispiel #5
0
        //4.7	缺勤类别管理
        //(列表(分页)、新建、编辑、删除(存在员工时不可删除)
        //):代码(不可空,唯一性),名称(不可空),备注(可空)
        //        数据例子如:A;小病假;小病假的备注

        public ResultMessage DoValidation(AbsenceType model)
        {
            ResultMessage msg = new ResultMessage();

            if (string.IsNullOrEmpty(model.code))
            {
                msg.Success = false;
                msg.Content = "编码不能为空";

                return(msg);
            }

            if (string.IsNullOrEmpty(model.name))
            {
                msg.Success = false;
                msg.Content = "名称不能为空";

                return(msg);
            }

            IAbsenceTypeService cs    = new AbsenceTypeService(Settings.Default.db);
            List <AbsenceType>  shift = cs.GetAll();

            if (model.id <= 0)
            {
                bool isRecordExists = shift.Where(p => p.name == model.name || p.code == model.code).ToList().Count() > 0;

                if (isRecordExists)
                {
                    msg.Success = false;
                    msg.Content = "数据已经存在!";

                    return(msg);
                }
            }
            else
            {
                bool isRecordExists = shift.Where(p => (p.name == model.name || p.code == model.code) && p.id != model.id).ToList().Count() > 0;

                if (isRecordExists)
                {
                    msg.Success = false;
                    msg.Content = "数据已经存在!";

                    return(msg);
                }
            }

            return(new ResultMessage()
            {
                Success = true, Content = ""
            });
        }
Beispiel #6
0
        public ActionResult Search([Bind(Include = "Name")] AbsenceTypeSearchModel q)
        {
            int pageIndex = 0;

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

            IAbsenceTypeService ss = new AbsenceTypeService(Settings.Default.db);

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

            ViewBag.Query = q;

            return(View("Index", models));
        }
Beispiel #7
0
        public ActionResult Index(int?page)
        {
            int pageIndex = PagingHelper.GetPageIndex(page);

            AbsenceTypeSearchModel q = new AbsenceTypeSearchModel();

            IAbsenceTypeService ss = new AbsenceTypeService(Settings.Default.db);

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

            ViewBag.Query = q;

            AbsenceTypeInfoModel info = ss.GetAbsenceTypeInfo(q);

            ViewBag.Info = info;

            return(View(models));
        }
Beispiel #8
0
        public ActionResult Delete(int id, FormCollection collection)
        {
            ResultMessage msg = new ResultMessage();

            try
            {
                //存在员工时不可删除
                IAbsenceRecordService shfSi = new AbsenceRecordService(Settings.Default.db);
                List <AbsenceRecrod>  shf   = shfSi.FindByAbsenceType(id);

                if (null != shf && shf.Count() > 0)
                {
                    msg.Success = false;
                    msg.Content = "缺勤类型正在使用,不能删除!";

                    return(Json(msg, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    IAbsenceTypeService cs = new AbsenceTypeService(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));
            }
        }
        /// <summary>
        /// 验证
        /// </summary>
        /// <param name="model"></param>
        /// <param name="dbString"></param>
        public void Validate(string dbString)
        {
            ValidateMessage msg = new ValidateMessage();

            if (string.IsNullOrEmpty(this.AbsenceDateStr))
            {
                msg.Contents.Add("日期不可空");
            }
            else
            {
                DateTime dt = DateTime.Now;
                if (DateTime.TryParse(this.AbsenceDateStr, out dt))
                {
                    //this.RecordAtDate = dt;
                }
                else
                {
                    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("人员编号不存在");
                }
            }
            if (string.IsNullOrEmpty(this.StartHourStr))
            {
                msg.Contents.Add("开始时间不可空");
            }
            else
            {
                TimeSpan ts = DateTime.Now.TimeOfDay;
                if (TimeSpan.TryParse(this.StartHourStr, out ts))
                {
                    //this.RecordAtDate = dt;
                }
                else
                {
                    msg.Contents.Add("开始时间格式错误");
                }
            }

            if (string.IsNullOrEmpty(this.EndHourStr))
            {
                msg.Contents.Add("结束时间不可空");
            }
            else
            {
                TimeSpan ts = DateTime.Now.TimeOfDay;
                if (TimeSpan.TryParse(this.EndHourStr, out ts))
                {
                    //this.RecordAtDate = dt;
                }
                else
                {
                    msg.Contents.Add("结束时间格式错误");
                }
            }
            if (string.IsNullOrEmpty(this.AbsenceTypeStr))
            {
                msg.Contents.Add("缺勤类型不可空");
            }
            else
            {
                IAbsenceTypeService si    = new AbsenceTypeService(dbString);
                List <AbsenceType>  absTs = si.GetAll();

                bool hasExists = absTs.Where(p => p.name.Equals(this.AbsenceTypeStr)).ToList().Count() > 0;

                if (!hasExists)
                {
                    msg.Contents.Add("缺勤类型不存在");
                }
                else
                {
                    AbsenceType abs = absTs.Where(p => p.name.Equals(this.AbsenceTypeStr)).FirstOrDefault();
                    this.AbsenceTypeId = abs.id;
                }
            }

            //if (string.IsNullOrEmpty(this.DurationTypeStr))
            //{
            //    msg.Contents.Add("时间单位不可空");
            //}
            //else
            //{
            //    bool isVal = DurationTypeStr != "Hour" || DurationTypeStr != "Day";

            //    if (!isVal)
            //    {
            //        msg.Contents.Add("时间单位不存在");
            //    }
            //    else
            //    {
            //        if (DurationTypeStr == "天" || DurationTypeStr == "Day")
            //        {
            //            DurationType = (int)BlueHrLib.Data.Enum.DurationType.Day;
            //        }

            //        if (DurationTypeStr == "小时" || DurationTypeStr == "Hour")
            //        {
            //            DurationType = (int)BlueHrLib.Data.Enum.DurationType.Hour;
            //        }
            //    }
            //}

            //if (string.IsNullOrEmpty(Remark))
            //{
            //    msg.Contents.Add("缺勤原因不可空");
            //}

            if (string.IsNullOrEmpty(this.Duration))
            {
                msg.Contents.Add("缺勤小时不可空");
            }

            //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;
        }