/// <summary> /// 根据销售id删除SalePig表里数据 /// </summary> /// <param name="saleId">销售id</param> /// <returns></returns> public bool DelSalePigService(long saleId) { var salePigService = new SalePigService(); foreach (sale_pig salePig in salePigService.FindBySaleId(saleId)) { salePigService = new SalePigService(); salePigService.Delete(salePigService.Find(salePig.Id)); } return true; }
/// <summary> /// 更新修改淘汰信息 /// </summary> /// <param name="updateInfo">淘汰信息页面类</param> /// <returns></returns> public bool UpdateEliminateInfo(EliminateInfo updateInfo) { var salesService = new SaleService(); var salePigService = new SalePigService(); task task = new TaskService().FindByTaskNumber(updateInfo.TaskNumber); var pigInfo = new PigInfo(); int count = 0; if (task == null) return false; foreach (sale sale in salesService.FindByTaskId(task.Id)) { sale.EmployeeId = long.Parse(updateInfo.EmployeeName); sale.Memo = updateInfo.Meno; salesService.Update(sale); List<sale_pig> saleList = salePigService.FindBySaleId(sale.Id); foreach (sale_pig salePig in saleList) { pigInfo.SetState(salePig.PigId, false); if (count < updateInfo.EliminateInfoPigDetail.Count) { salePig.PigId = long.Parse(updateInfo.EliminateInfoPigDetail[count].Pig); salePig.Time = updateInfo.EliminateInfoPigDetail[count].DetailTime; salePigService.Update(salePig); pigInfo.SetState(long.Parse(updateInfo.EliminateInfoPigDetail[count].Pig), true); } else { salePigService = new SalePigService(); salePigService.Delete(salePigService.Find(salePig.Id)); } count++; } for (; count < updateInfo.EliminateInfoPigDetail.Count; count++) { salePigService.Insert(new sale_pig { SaleId = sale.Id, PigId = long.Parse(updateInfo.EliminateInfoPigDetail[count].Pig), Time = updateInfo.EliminateInfoPigDetail[count].DetailTime }); pigInfo.SetState(long.Parse(updateInfo.EliminateInfoPigDetail[count].Pig), true); } } return true; }
/// <summary> /// 淘汰信息列表 /// </summary> /// <returns></returns> public IEnumerable<Info> GetEliminateInfoList() { var salesService = new SaleService(); var salePigService = new SalePigService(); return (from saleItem in salesService.FindAll() let salePigItem = salePigService.FindBySaleId(saleItem.Id).OrderByDescending(m => m.Time).FirstOrDefault() let dateTime = salePigItem.Time where dateTime != null && saleItem.SaleType=="淘汰" select new Info { TaskNumber = saleItem.task.TaskNumber, EmployeeName = saleItem.employee.Name, Time = (DateTime)dateTime, Meno = saleItem.Memo }).ToList(); }
/// <summary> /// 删除淘汰的相关信息 /// </summary> /// <param name="taskNumber">任务编号</param> /// <returns></returns> public bool DelEliminateInfo(string taskNumber) { var salesService = new SaleService(); var salePigService = new SalePigService(); var taskStatusTypeService = new TaskStatusTypeService(); var pigInfo = new PigInfo(); task task = new TaskService().FindByTaskNumber(taskNumber); if (task == null) return false; foreach (sale sale in salesService.FindByTaskId(task.Id)) { foreach (sale_pig EliminatePig in salePigService.FindBySaleId(sale.Id)) { salePigService = new SalePigService(); salePigService.Delete(salePigService.Find(EliminatePig.Id)); pigInfo.SetState(EliminatePig.Id, false); } salesService = new SaleService(); salesService.Delete(salesService.Find(sale.Id)); } task_status_type taskStatusType = taskStatusTypeService.FindByName("已完成"); task.TaskStatusId = taskStatusType.Id; return true; }
public PagedList<PigInfo> GetpigPageList(PagedList<pig> pigInfos, int pageIndex, int pageSize) { var pigService = new PigService(); var pigList = new List<PigInfo>(); var salePigService = new SalePigService(); var transferService = new TransferService(); 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 + ""; } 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 = pigHouse, Pigsty = pigsty, state = pigState }); } return new PagedList<PigInfo>(pigList, pageIndex, pageSize, pigInfos.TotalItemCount); }
/// <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); }
/// <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; }
/// <summary> /// 查看生猪信息 /// </summary> /// <param name="pigNumber"></param> /// <returns></returns> public PigInfo CheckPigInfo(string pigNumber) { var pigService = new PigService(); pig pig = pigService.FindByNumber(pigNumber); if (pig == null) return null; var transferService = new TransferService(); string pigHouse = ""; string pigsty = ""; string earNumber = "", rfid = "", femaleParent = "", mostLikelyMaleParent = "", secondLikelyMaleParent = "", thirdLikelyMaleParent = null; if (pig.EarNumber != null) earNumber = pig.EarNumber + ""; if (pig.RFID != null) rfid = pig.RFID + ""; if (pig.FemaleParentId != null) femaleParent = pigService.Find(pig.FemaleParentId).Number; if (pig.MostLikelyMaleParentId != null) mostLikelyMaleParent = pigService.Find(pig.MostLikelyMaleParentId).Number; if (pig.SecondLikelyMaleParentId != null) secondLikelyMaleParent = pigService.Find(pig.SecondLikelyMaleParentId).Number; if (pig.ThirdLikelyMaleParentId != null) thirdLikelyMaleParent = pigService.Find(pig.ThirdLikelyMaleParentId).Number; transfer transfer = transferService.FindByPigId(pig.Id).OrderByDescending(m => m.Time).FirstOrDefault(); if (transfer != null) { pigHouse = transfer.pigsty.pig_house.pig_house_type.Name + transfer.pigsty.pig_house.Number; pigsty = transfer.pigsty.Number + ""; } string pigState = ""; var salepig = new 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 = "异常"; var pigInfo = new PigInfo { Number = pigNumber, EarNumber = earNumber, Birthday = pig.Birthday, Rfid = rfid, PigType = pig.pig_type.Name, FemaleParentNum = femaleParent, MostLikelyMaleParentNum = mostLikelyMaleParent, SecondLikelyMaleParentNum = secondLikelyMaleParent, ThirdLikelyMaleParentNum = thirdLikelyMaleParent, Memo = pig.Memo, PigHouse = pigHouse, Pigsty = pigsty, TransferPigstyTime = transfer == null ? new DateTime() : transfer.Time, state = pigState }; return pigInfo; }
/// <summary> /// 查看生猪个体喂食记录 /// </summary> /// <param name="pigNumber"></param> /// <param name="pageIndex"> </param> /// <param name="pageSize"> </param> /// <returns></returns> public PigInfo CheckFeedRecord(string pigNumber, int pageIndex, int pageSize) { var pigService = new PigService(); var salePigService = new SalePigService(); pig pig = pigService.FindByNumber(pigNumber); var transferPigsty = new TransferService(); var feedService = new FeedService(); List<transfer> transferPigstyList = transferPigsty.FindByPigId(pig.Id).OrderBy(m => m.Time).ToList(); transfer transfer = transferPigstyList.LastOrDefault(); var feedInfos = new List<FodderTakeDetail>(); string pigHouse = "", pigsty = ""; DateTime? temp = null; sale_pig salePig = salePigService.FindByPigId(pig.Id).FirstOrDefault(); if (transfer != null) { pigHouse = transfer.pigsty.pig_house.pig_house_type.Name + transfer.pigsty.pig_house.Number; pigsty = transfer.pigsty.Number + ""; } var pigInfo = new PigInfo { Number = pigNumber, Birthday = pig.Birthday, PigType = pig.pig_type.Name, PigHouse = pigHouse, Pigsty = pigsty }; if (salePig != null) { temp = salePig.Time; } if (transferPigstyList.Count == 1) { foreach (feed feedItem in feedService.FindByPigstyId(transferPigstyList[0].PigstyId).Where( m => m.Time > transferPigstyList[0].Time)) { if (temp != null) if (feedItem.Time > temp) continue; feedInfos.Add(new FodderTakeDetail { FodderType = feedItem.task.task_pigsty.FirstOrDefault( m => m.PigstyId == feedItem.PigstyId) .feed_task_quality.FirstOrDefault() .fodder_type.Name, TakeTime = feedItem.Time }); } } for (int i = 0; i < transferPigstyList.Count - 1; i++) { DateTime startTime = transferPigstyList[i].Time; DateTime endTime = transferPigstyList[i + 1].Time; foreach (feed feedItem in feedService.FindByPigstyId(transferPigstyList[i].PigstyId).Where( m => m.Time > startTime && m.Time < endTime)) { if (temp != null) if (feedItem.Time > temp) continue; feedInfos.Add(new FodderTakeDetail { // FodderType = feedItem.task.fodder_take.Where(m => m.Time > startTime && m.Time < endTime).FirstOrDefault().fodder_type.Name, FodderType = feedItem.task.task_pigsty.FirstOrDefault( m => m.PigstyId == feedItem.PigstyId) .feed_task_quality.FirstOrDefault() .fodder_type.Name, TakeTime = feedItem.Time }); } } pigInfo.FeedRecord = new PagedList<FodderTakeDetail>(feedInfos.OrderByDescending(m => m.TakeTime).ToList(), pageIndex, pageSize) { Capacity = feedInfos.Count, CurrentPageIndex = pageIndex, PageSize = pageSize, TotalItemCount = feedInfos.Count }; return pigInfo; }
/// <summary> /// 删除销售的相关信息 /// </summary> /// <param name="taskNumber">任务编号</param> /// <returns></returns> public bool DelsalesInfo(string taskNumber) { var salesService = new SaleService(); var salePigService = new SalePigService(); var pigInfo = new PigInfo(); task task = new TaskService().FindByTaskNumber(taskNumber); if (task == null) return false; foreach (sale sale in salesService.FindByTaskId(task.Id)) { foreach (sale_pig salePig in salePigService.FindBySaleId(sale.Id)) { salePigService = new SalePigService(); salePigService.Delete(salePigService.Find(salePig.Id)); pigInfo.SetState(salePig.Id, false); } salesService = new SaleService(); salesService.Delete(salesService.Find(sale.Id)); } return true; }