/// <summary> /// 查找对应条件的生猪 /// </summary> /// <param name="checkInput">搜索内容</param> /// <param name="choseid">条件号</param> /// <returns></returns> public PagedList<PigInfo> GetPigList(string checkInput, string choseid, int pageIndex, int pageSize) { var pigService = new PigService(); var transferService = new TransferService(); long earnum; switch (choseid) { case "1": if (checkInput != "") //RFID { return GetpigPageList(pigService.FindByPigPageByRfid(checkInput.Trim(), pageIndex, pageSize), pageIndex, pageSize); } else return GetpigPageList(pigService.FindByPigPage(pageIndex, pageSize), pageIndex, pageSize); case "2": if (checkInput != "") //耳号 { if (long.TryParse(checkInput.Trim(), out earnum)) return GetpigPageList(pigService.FindByPigPageByEarNum(earnum, pageIndex, pageSize), pageIndex, pageSize); else return new PagedList<PigInfo>(new List<PigInfo>(), pageIndex, pageSize, 0); } else return GetpigPageList(pigService.FindByPigPage(pageIndex, pageSize), pageIndex, pageSize); case "3": if (checkInput != "") //猪类型 return GetpigPageList(pigService.FindByPigPageByType(long.Parse(checkInput), pageIndex, pageSize), pageIndex, pageSize); else return GetpigPageList(pigService.FindByPigPage(pageIndex, pageSize), pageIndex, pageSize); case "4": if (checkInput != "") //猪舍猪栏 { string[] checkStrs = checkInput.Split('+'); if (checkStrs.Length > 0) { if (checkStrs.Length > 1 && checkStrs[1] != "") return GetpigPageList( transferService.FindByPigstyPage(long.Parse(checkStrs[1]), pageIndex, pageSize), pageIndex, pageSize); else return GetpigPageList( transferService.FindByPigHousePage(long.Parse(checkStrs[0]), pageIndex, pageSize), pageIndex, pageSize); } else return GetpigPageList(pigService.FindByPigPage(pageIndex, pageSize), pageIndex, pageSize); } else return GetpigPageList(pigService.FindByPigPage(pageIndex, pageSize), pageIndex, pageSize); case "5": if (checkInput != "") //生猪状态 return GetpigPageList( pigService.FindByPigPageByType(checkInput, pageIndex, pageSize), pageIndex, pageSize); else return GetpigPageList(pigService.FindByPigPage(pageIndex, pageSize), pageIndex, pageSize); default: return GetpigPageList(pigService.FindByPigPage(pageIndex, pageSize), pageIndex, pageSize); } }
/// <summary> /// 全部生猪列表 /// </summary> /// <returns></returns> //public PagedList<PigInfo> GetPigList(int pageIndex, int pageSize) //{ // //return GetALLPigList(pageIndex, pageSize); // var pigService = new PigService(); // var pigList = new List<PigInfo>(); // var salePigService = new SalePigService(); // var transferService = new TransferService(); // PagedList<pig> pigInfos = pigService.FindByPigPage(pageIndex, pageSize); // foreach (pig pig in pigInfos) // { // //transfer transfer = transferService.FindByPigId(pig.Id).OrderByDescending(m => m.Time).FirstOrDefault(); // transfer transfer = transferService.FindByPigId(pig.Id).OrderByDescending(m => m.Id).FirstOrDefault(); // string pigHouse = ""; // string pigsty = ""; // string pigState=""; // if (transfer != null) // { // pigHouse = transfer.pigsty.pig_house.pig_house_type.Name + transfer.pigsty.pig_house.Number+"舍"; // pigsty = transfer.pigsty.Number + ""; // } // if (pig.State == false) pigState = "正常"; // else if (salePigService.FindByPigId(pig.Id) != null) pigState = "出售"; // else // pigState = "异常"; // pigList.Add(new PigInfo // { // Number=pig.Number, // Rfid=pig.RFID, // EarNumber = pig.EarNumber == null ? "" : pig.EarNumber.ToString(), // Birthday = pig.Birthday, // PigType = pig.pig_type.Name, // Memo = pig.Memo, // PigHouse = pigHouse, // Pigsty = pigsty, // state=pigState // }); // } // return new PagedList<PigInfo>(pigList, pageIndex, pageSize, pigInfos.TotalItemCount); //} public PagedList<PigInfo> GetPigList(int pageIndex, int pageSize) { var pigService = new PigService(); var pigList = new List<PigInfo>(); var salePigService = new SalePigService(); var transferService = new TransferService(); PagedList<pig> pigInfos = pigService.FindByPigPage(pageIndex, pageSize); PagedList<transfer> transferList = transferService.FindByAllPage(pageIndex, pageSize); foreach (transfer tranfer in transferList) { pig pig = pigService.Find(tranfer.PigId); string pigState = ""; var salepig = salePigService.FindByPigId(pig.Id).FirstOrDefault(); if (pig.State == false) pigState = "正常"; else if (salepig != null) { if (salepig.sale.SaleType=="销售") pigState = "出售"; else if (salepig.sale.SaleType == "淘汰") pigState = "淘汰"; else if (salepig.sale.SaleType == "死亡") pigState = "死亡"; else pigState = "异常"; } else pigState = "异常"; pigList.Add(new PigInfo { Number = pig.Number, Rfid = pig.RFID, EarNumber = pig.EarNumber == null ? "" : pig.EarNumber.ToString(), Birthday = pig.Birthday, PigType = pig.pig_type.Name, Memo = pig.Memo, PigHouse = tranfer.pigsty.pig_house.pig_house_type.Name + tranfer.pigsty.pig_house.Number + "舍", Pigsty = tranfer.pigsty.Number + "", state = pigState }); } return new PagedList<PigInfo>(pigList, pageIndex, pageSize, pigInfos.TotalItemCount); }