//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 = "" }); }
/// <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; }