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