Exemplo n.º 1
0
        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));
        }