/// <summary>
 ///     AjAx获取防疫任务相关的防疫类型信息
 /// </summary>
 /// <param name="taskId">任务id号</param>
 /// <returns>以,隔开的防疫类型信息</returns>
 public string GetPreventionType(long taskId)
 {
     var taskPreventionService = new TaskPreventionService();
     task_prevention firstOrDefault = taskPreventionService.FindByTaskId(taskId).FirstOrDefault();
     string preventionTypeStr = "";
     if (firstOrDefault != null)
     {
         prevention_type prevention = firstOrDefault.prevention_type;
         preventionTypeStr = prevention.Name + "," + prevention.medicine.Name + "," + prevention.Quality + "," +
                             prevention.unit1.Name;
     }
     return preventionTypeStr;
 }
Exemple #2
0
        /// <summary>
        ///     查看生猪个体防疫记录
        /// </summary>
        /// <param name="pigNumber"></param>
        /// <param name="pageIndex"> </param>
        /// <param name="pageSize"> </param>
        /// <returns></returns>
        public PigInfo CheckPreventionRecord(string pigNumber, int pageIndex, int pageSize)
        {
            var pigService = new PigService();
            pig pig = pigService.FindByNumber(pigNumber);
            var transferPigsty = new TransferService();
            var taskPreventionService = new TaskPreventionService();
            var preventionService = new PreventionService();
            var preventionInfos = new List<PreventionInfo>();
            var salePigService = new SalePigService();
            List<transfer> transferPigstyList = transferPigsty.FindByPigId(pig.Id).OrderBy(m => m.Time).ToList();
            transfer transfer = transferPigstyList.LastOrDefault();
            sale_pig salePig = salePigService.FindByPigId(pig.Id).FirstOrDefault();
            DateTime? temp = null;
            string pigHouse = "", pigsty = "";
            if (transfer != null)
            {
                pigHouse = transfer.pigsty.pig_house.pig_house_type.Name + transfer.pigsty.pig_house.Number;
                pigsty = transfer.pigsty.Number + "";
            }
            if (salePig != null)
            {
                temp = salePig.Time;
            }
            var pigInfo = new PigInfo
                              {
                                  Number = pigNumber,
                                  Birthday = pig.Birthday,
                                  PigType = pig.pig_type.Name,
                                  PigHouse = pigHouse,
                                  Pigsty = pigsty
                              };
                if (transferPigstyList.Count == 1)
                {
                    foreach (prevention preventionItem in
                        preventionService.FindByPistyId(transferPigstyList[0].PigstyId).Where(
                            m => m.Time > transferPigstyList[0].Time))
                    {
                        if (temp != null) if (temp > preventionItem.Time) continue;
                        task_prevention firstOrDefault =
                            taskPreventionService.FindByTaskId(preventionItem.TaskId).FirstOrDefault();
                        if (firstOrDefault != null)
                            preventionInfos.Add(new PreventionInfo
                                                    {
                                                        DiseaseName = firstOrDefault.prevention_type.Name,
                                                        Medicine = firstOrDefault.prevention_type.medicine.Name,
                                                        Time = preventionItem.Time
                                                    });
                    }
                }
                for (int i = 0; i < transferPigstyList.Count; i++)
                {
                    DateTime startTime = transferPigstyList[i].Time;
                    DateTime endTime = DateTime.Now;
                    if (i + 1 < transferPigstyList.Count)
                        endTime = transferPigstyList[i + 1].Time;
                    foreach (prevention preventionItem in
                        preventionService.FindByPistyId(transferPigstyList[i].PigstyId).Where(
                            m => m.Time > startTime && m.Time < endTime))
                    {
                        if (temp != null) if (temp > preventionItem.Time) continue;
                        task_prevention firstOrDefault =
                            taskPreventionService.FindByTaskId(preventionItem.TaskId).FirstOrDefault();
                        if (firstOrDefault != null)
                            preventionInfos.Add(new PreventionInfo
                                                    {
                                                        DiseaseName = firstOrDefault.prevention_type.Name,
                                                        Medicine = firstOrDefault.prevention_type.medicine.Name,
                                                        Time = preventionItem.Time
                                                    });
                    }
                }

            pigInfo.PreventionRecord =
                new PagedList<PreventionInfo>(preventionInfos.OrderByDescending(m => m.Time).ToList(), pageIndex,
                                              pageSize)
                    {
                        Capacity = preventionInfos.Count,
                        PageSize = pageSize,
                        CurrentPageIndex = pageIndex,
                        TotalItemCount = preventionInfos.Count
                    };
            return pigInfo;
        }
        public ActionResult NewPreventionDiseaseInfo()
        {
            if (Session["CheckFeed"] == null || !(bool) Session["AddPreventionDiseaseInfo"] ||
                !(bool) Session["CheckPreventionDiseaseInfo"])
            {
                Response.Write("<script>history.go(0);</script>");
                return View("Error");
            }

            var newInfo = new PreventionInfo();
            var taskPreventionService = new TaskPreventionService();
            IEnumerable<SelectListItem> taskNumberList = newInfo.GetTaskNumberSelect(TaskTypeId);
            if (!taskNumberList.Any())
            {
                const string returnstring = "任务为空,请先添加任务";
                Response.Write("<script language='JavaScript'>alert('" + returnstring + ".');history.go(-1);</script>");
                return Content("");
            }
            SelectListItem firstOrDefault = newInfo.GetTaskNumberSelect(TaskTypeId).FirstOrDefault();
            if (firstOrDefault != null)
            {
                string firstTask = firstOrDefault.Value;
                task_prevention orDefault = taskPreventionService.FindByTaskId(long.Parse(firstTask)).FirstOrDefault();
                if (orDefault != null)
                {
                    newInfo.DiseaseName = orDefault.prevention_type.Name;
                    newInfo.Medicine = orDefault.prevention_type.medicine.Name;
                    newInfo.Quality = orDefault.prevention_type.Quality;
                    newInfo.Unit = orDefault.prevention_type.unit1.Name;
                }
            }

            ViewData["TaskNumber"] = newInfo.GetTaskNumberSelect(TaskTypeId);
            ViewData["pigsty"] = new ListService().GetFirstPigstyList();
            ViewData["Employee"] = new ListService().GetEmployeeList();
            ViewData["pighouse"] = new ListService().GetPigHouseList();
            ViewData["Pigfodder"] = new ListService().GetFodderTypeList();
            ViewData["unit"] = new ListService().GetUnitList();
            ViewBag.Title = "新建防疫信息";
            return View(newInfo);
        }