Пример #1
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;
        }