/// <summary> /// 查看转栏信息 /// </summary> /// <param name="taskNumber">任务编号</param> /// <returns></returns> public TransferPigstyInfo CheckTransferPigstyInfo(string taskNumber) { var checkTransferPigstyInfo = new TransferPigstyInfo {TransferPigstyInfoDetail = new List<TransferPigstyInfoDetail>()}; var taskEmployee = new TaskEmployeeService(); var taskService = new TaskService(); var transferService = new TransferService(); task transferPigstyTask = taskService.FindByTaskNumber(taskNumber); if (transferPigstyTask != null) { checkTransferPigstyInfo.TaskNumber = taskNumber; checkTransferPigstyInfo.EmployeeName = taskEmployee.GetEmployeeNames(transferPigstyTask.Id); transfer firstOrDefault = transferService.FindByTaskId(transferPigstyTask.Id).FirstOrDefault(); if (firstOrDefault != null) checkTransferPigstyInfo.Meno = firstOrDefault.Memo; foreach ( transfer transfer in transferService.FindByTaskId(transferPigstyTask.Id).OrderByDescending(m => m.Time)) { transfer lastPigsty = transferService.GetLastTransfer(transfer.PigId, transferPigstyTask.Id); if (lastPigsty != null && lastPigsty.pigsty.Id != transfer.pigsty.Id) checkTransferPigstyInfo.TransferPigstyInfoDetail.Add(new TransferPigstyInfoDetail { SourcePigHouse = lastPigsty.pigsty.pig_house. pig_house_type.Name + lastPigsty.pigsty.pig_house. Number, SourcePigsty = lastPigsty.pigsty.Number + "", Pig = transfer.pig.Number, TargetPigHouse = transfer.pigsty.pig_house. pig_house_type.Name + transfer.pigsty.pig_house. Number, TargetPigsty = transfer.pigsty.Number + "", TransferPigstyTime = transfer.Time }); else checkTransferPigstyInfo.TransferPigstyInfoDetail.Add(new TransferPigstyInfoDetail { SourcePigHouse = "", SourcePigsty = "", Pig = transfer.pig.Number, TargetPigHouse = transfer.pigsty.pig_house. pig_house_type.Name + transfer.pigsty.pig_house. Number, TargetPigsty = transfer.pigsty.Number + "", TransferPigstyTime = transfer.Time }); } } return checkTransferPigstyInfo; }
/// <summary> /// 根据任务编号删除转栏信息 /// </summary> /// <param name="taskNumber">任务编号</param> /// <returns></returns> public bool DelTransfer(string taskNumber) { var taskService = new TaskService(); long taskId = taskService.FindByTaskNumber(taskNumber).Id; var transferService = new TransferService(); foreach (transfer transfer in transferService.FindByTaskId(taskId)) { transferService = new TransferService(); transferService.Delete(transferService.Find(transfer.Id)); } return true; }
/// <summary> /// 修改转栏信息 /// </summary> /// <param name="updateTransferPigstyInfo">转栏信息页面类</param> /// <returns></returns> public bool UpdateTransferPigstyInfo(TransferPigstyInfo updateTransferPigstyInfo) { var taskService = new TaskService(); var transferService = new TransferService(); task transferPigstyTask = taskService.FindByTaskNumber(updateTransferPigstyInfo.TaskNumber); int count = 0; if (transferPigstyTask != null) { List<transfer> transferList = transferService.FindByTaskId(transferPigstyTask.Id).OrderByDescending(m => m.Time).ToList(); for (; count < transferList.Count; count++) { //transfer lastPigsty = transferService.GetLastTransfer(transferList[count].PigId, // transferPigstyTask.Id); if (count < updateTransferPigstyInfo.TransferPigstyInfoDetail.Count) { if (transferList[count] != null) { transfer lastTransfer = transferService.Find(transferList[count].Id); if (updateTransferPigstyInfo.TransferPigstyInfoDetail[count].Pig == "null") updateTransferPigstyInfo.TransferPigstyInfoDetail[count].Pig = lastTransfer.PigId + ""; if (updateTransferPigstyInfo.TransferPigstyInfoDetail[count].SourcePigsty != null) lastTransfer.PigstyId = long.Parse(updateTransferPigstyInfo.TransferPigstyInfoDetail[count].SourcePigsty); if (updateTransferPigstyInfo.TransferPigstyInfoDetail[count].Pig != null) lastTransfer.PigId = long.Parse(updateTransferPigstyInfo.TransferPigstyInfoDetail[count].Pig); transferService.Update(lastTransfer); } transferList[count].PigstyId = long.Parse(updateTransferPigstyInfo.TransferPigstyInfoDetail[count].TargetPigsty); if (updateTransferPigstyInfo.TransferPigstyInfoDetail[count].Pig != null) transferList[count].PigId = long.Parse(updateTransferPigstyInfo.TransferPigstyInfoDetail[count].Pig); transferList[count].Memo = updateTransferPigstyInfo.Meno; transferService.Update(transferList[count]); } else { transferService = new TransferService(); transferService.Delete(transferService.Find(transferList[count].Id)); } } for (; count < updateTransferPigstyInfo.TransferPigstyInfoDetail.Count; count++) { transferService.Insert(new transfer { TaskId = transferPigstyTask.Id, PigstyId = long.Parse( updateTransferPigstyInfo.TransferPigstyInfoDetail[count]. TargetPigsty), PigId = long.Parse( updateTransferPigstyInfo.TransferPigstyInfoDetail[count].Pig), Time = updateTransferPigstyInfo.TransferPigstyInfoDetail[count]. TransferPigstyTime, Memo = updateTransferPigstyInfo.Meno }); } return true; } return false; }