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; }
public string GetFeed(string name, int index) { List <string> result = new List <string>(); feeds.ForEach(a => { List <Feed> fd = FeedHelper.GetFeeds(a.feeds); DateTime dt = a.referTime; double nv = 0; fd.ForEach(f => { if (f.name == name) { nv += f.nValue * 40; } }); if (nv > 0) { string s = string.Format("{0:MM-dd} / {1}", dt, nv); result.Add(s); } }); if (result.Count <= index) { return(""); } return(result.ElementAt(index)); }
/// <summary> /// 发料详细列表 /// </summary> /// <returns></returns> public List <Feed> GetFeedsList() { List <Feed> fs = new List <Feed>(); fs.AddRange(FeedHelper.GetFeeds(feeds)); return(fs); }
/// <summary> /// 体重增量 /// </summary> /// <returns></returns> public double WeightInc() { List <Feed> feed = FeedHelper.GetFeeds(this.feeds); if (feed.Count == 0) { return(0.0); } return(feed.Sum(p => p.weight)); }
/// <summary> /// 不同种类饲料的包数和 /// </summary> /// <returns></returns> public double GetFeedBagNum() { List <Feed> feed = FeedHelper.GetFeeds(this.feeds); if (feed.Count == 0) { return(0.0); } return(feed.Sum(p => p.nValue)); }
private ActionResult FeedPreview() { string raiserID = Request["raiserID"]; var pig = new FarmRepository().GetEntitie <LivePig>(p => p.raiserID == raiserID); if (pig == null) { return(Json(new { success = false, message = string.Format("养户编号 \"{0}\" 没有对应的在养批次", raiserID) }, JsonRequestBehavior.AllowGet)); } string addDays = Request["addDays"]; string delayDays = Request["delayDays"]; int n2, n3; if (!Int32.TryParse(addDays, out n2)) { n2 = pig.GetLastGrantFeedDays(); } if (!Int32.TryParse(delayDays, out n3)) { n3 = pig.feedSurplusDays < 0 ? 0 - pig.feedSurplusDays : 0; } int n1 = pig.feedGrantToDays + 1; //int n2 = addDays.HasValue ? addDays.Value : pig.GetLastGrantFeedDays(); //int n3 = delayDays.HasValue ? delayDays.Value : (pig.feedSurplusDays < 0 ? 0 - pig.feedSurplusDays : 0); int n4 = pig.extantNum; var f = FeedHelper.GetFeeds(n1, n1 + n2 - 1, n4); var ylts = pig.feedSurplusDays + n2 + n3; var ylrq = DateTime.Today.AddDays(ylts); var model = new { success = true, raiserName = pig.raiserName, areaName = pig.areaName, from = n1, add = n2, delay = n3, num = n4, feeds = f, check = (ylts <= AppGlobal.grantFeedDay), feedinfo = string.Format("可用至{0:d},余料天数{1} ", ylrq, ylts) }; return(Json(model, JsonRequestBehavior.AllowGet)); }
/// <summary> /// 每日增重 /// </summary> /// <param name="days"></param> /// <returns></returns> public double WeightIncPreDay(int days) { if (days < this.fromDays || days > this.fromDays + this.addDays - 1) { return(0); } List <Feed> feeds = FeedHelper.GetFeeds(days, days, 1); if (feeds.Count == 0) { return(0.0); } return(feeds.Sum(p => p.weight)); }
public double GetFeedWeight(string name) { double nv = 0; feeds.ForEach(a => { List <Feed> fd = FeedHelper.GetFeeds(a.feeds); fd.ForEach(f => { if (f.name == name) { nv += f.nValue * 40; } }); }); return(nv); }
/// <summary> /// 本次发料食至标准日龄的增重 /// </summary> /// <param name="days"></param> /// <returns></returns> public double WeightInc(int days) { if (days < this.fromDays) { return(0); } if (days > (fromDays + addDays - 1)) { return(WeightInc()); } List <Feed> feeds = FeedHelper.GetFeeds(this.fromDays, days, 1); if (feeds.Count == 0) { return(0.0); } return(feeds.Sum(p => p.weight)); }
/// <summary> /// 按标准日龄每天饲料用量 /// </summary> /// <param name="days"></param> /// <returns></returns> public string FeedByDay(int from, int to) { if (from < this.fromDays) { from = this.fromDays; } if (to > this.fromDays + this.addDays - 1) { to = this.fromDays + this.addDays - 1; } var num = this.realNum; List <Feed> feeds = FeedHelper.GetFeeds(from, to, num); if (feeds.Count == 0) { return(string.Empty); } var s = FeedHelper.GetFeedsDetail(feeds, 1); return(s); }
/// <summary> /// 发料详细字符串 /// </summary> /// <param name="flag"></param> /// <returns></returns> public string GetFeedsDetail(int flag = 0) { var l = FeedHelper.GetFeeds(feeds); return(FeedHelper.GetFeedsDetail(l, flag)); }