override protected void OnInsertValidate() { var db = new BaseRepository(); var r = db.GetEntitie <LivePig>(p => p.raiserID == this.raiserID); if (r == null) { throw(new Exception(string.Format("养户编号\"{0}\"不存在", raiserID))); } if (db.GetEntitie <tbFeedGrant>(p => p.PigID == r.ID && p.checkState == 0) != null) { throw(new Exception(string.Format("养户\"{0}\"有未审核的发料记录", raiserID))); } this.PigID = r.ID; this.fromDays = r.feedGrantToDays + 1; this.realNum = r.extantNum; this.checkState = (r.feedSurplusDays + this.delayDays + this.addDays) > AppGlobal.grantFeedDay ? 0 : 1; var f = FeedHelper.GetFeeds(this.fromDays, this.fromDays + this.addDays - 1, r.extantNum); this.feeds = FeedHelper.GetRegexStr(f); this.referPerson = Account.currentUser == null? "" : Account.currentUser.userName; this.checkPerson = this.referPerson; this.referTime = DateTime.Now; this.checkTime = DateTime.Now; }