/// <summary> /// 根据任务猪栏号和猪舍id找猪类型 /// </summary> /// <param name="taskId">猪栏号</param> /// <param name="pigHouseId">猪舍id号</param> /// <returns></returns> public string GetMumPigBypigStys(string pigStyNums, long pigHouseId) { var transferService = new TransferService(); var pigstyService=new PigstyService(); foreach (var pigStyNum in pigStyNums.Split(',')) { var pigSty=pigstyService.GetPigsty(int.Parse(pigStyNum),pigHouseId); if(transferService.FindByPigStyByPigType(pigSty.Id).Count>1)return "仔猪"; } return "全部猪"; }
//删除猪栏 public bool DelPigsty(string rfid) { var pigstyService = new PigstyService(); pigsty pigsty = pigstyService.FindByRfid(rfid); try { pigstyService.Delete(pigsty); } catch (Exception) { return false; } return true; }
public ActionResult AddPigstyEquipMentInfo(PigstyModel model) { var pigstyService = new PigstyService(); var pigsty = new pigsty { Number = model.Number, PigHouseId = model.PigHouseId, RFID = model.Rfid, Memo = model.Memo, Capacity = model.Capacity }; pigstyService.Insert(pigsty); ViewBag.Title = "添加成功"; return View("PigstyMessage"); }
/// <summary> /// 根据猪舍id找猪栏下拉列表 /// </summary> /// <returns></returns> public IEnumerable<SelectListItem> FindPigstyListByPigHouseId(string pigHouseId) { var pigHouseService = new PigHouseService(); var pigstyService = new PigstyService(); long id = 0; IEnumerable<SelectListItem> pigstySelect = new List<SelectListItem>(); if (long.TryParse(pigHouseId, out id)) pigstySelect = pigstyService.FindByPigHouseId(id).OrderBy(m=>m.Number).Select( pigstyItem => new SelectListItem { Text = pigstyItem.Number + "", Value = pigstyItem.Id + "" }); return pigstySelect; }
public PagedList<PigstyModel> GetPigstyPagedList(int pageIndex, int pageSize) { var pigstyService = new PigstyService(); List<pigsty> pigsties = pigstyService.FindAll(); List<PigstyModel> pigstyModels = pigsties.Select(pigsty => new PigstyModel { PigHouseId = pigsty.PigHouseId, Rfid = pigsty.RFID, Number = pigsty.Number, Memo = pigsty.Memo, PigHouseNameAndNumber = pigsty.pig_house.pig_house_type.Name + pigsty.pig_house.Number, Capacity = Convert.ToInt32(pigsty.Capacity) }) .OrderBy(m => m.PigHouseNameAndNumber) .ToList(); int count = (pageIndex - 1)*pageSize; return new PagedList<PigstyModel>(pigstyModels.Skip(count).Take(pageSize), pageIndex, pageSize, pigstyModels.Count()); }
public ActionResult CheckPigstyEquipMentInfo(string rfid) { if (Session["CheckFeed"] == null || !(bool) Session["CheckSystemManage"]) { Response.Write("<script>history.go(0);</script>"); return View("Error"); } var pigstyService = new PigstyService(); pigsty pigsty = pigstyService.FindByRfid(rfid); var pigstyModel = new PigstyModel { Id = pigsty.Id, PigHouseId = pigsty.PigHouseId, Capacity = Convert.ToInt32(pigsty.Capacity), Number = pigsty.Number, Rfid = pigsty.RFID, Memo = pigsty.Memo }; var listService = new ListService(); ViewData["PigHouse"] = listService.GetPigHouseList(); ViewBag.Title = "查看猪栏"; return View("AddPigstyEquipMentInfo", pigstyModel); }
public ActionResult BatchAddPigsties(BatchAddPigstiesModel models) { try { var pigstyService = new PigstyService(); foreach (AddPigstiesModel model in models.AddPigstiesModels) { var pigsty = new pigsty { RFID = model.Rfid, Number = model.PigstyNumber, PigHouseId = models.PigHouseId, Capacity = model.Capacity }; pigstyService.Insert(pigsty); } } catch { Response.Write("<script language='JavaScript'>alert('有误!!');history.go(0);</script>"); } ViewBag.Title = "成功导入"; return View("Message"); }
//猪栏编号 public bool PigstyNumberCompare(int number, long houseid) { var pigstyService = new PigstyService(); List<pigsty> pigsties = pigstyService.FindByPigHouseId(houseid); int flag = 1; foreach (pigsty pigsty in pigsties) { if (pigsty.Number == number) { flag = 0; } } if (flag == 0) { return false; } return true; }
//猪栏内的猪类型 public JsonResult getPigstyTypes(string pigstys,string pigHouseId) { HashSet<SelectListItem>pigStyType=new HashSet<SelectListItem>(); TransferService transferService= new TransferService(); var pigstyService = new PigstyService(); var pigTypeService=new PigTypeService(); pigStyType.Add(new SelectListItem(){ Text="全部猪",Value="0",Selected=true }); foreach(var str in pigstys.Split(',')){ var pigSty=pigstyService.GetPigsty(int.Parse(str),long.Parse(pigHouseId)); var pigTypeIdList =transferService.FindByPigStyByPigType(pigSty.Id); foreach(var id in pigTypeIdList){ var name=pigTypeService.Find(id).Name; pigStyType.Add(new SelectListItem(){ Text=name,Value=id+"" }); } } return Json(pigStyType, JsonRequestBehavior.AllowGet); }
/// <summary> /// 修改喂食任务 /// </summary> /// <param name="updateTask"></param> /// <returns></returns> public bool UpdateFeedTask(FeedTask updateTask) { var taskService = new TaskService(); var pigstyService = new PigstyService(); var taskQualityService = new FeedTaskQualityService(); var taskIntervalCycleService = new TaskIntervalCycleService(); task task = taskService.FindByTaskNumber(updateTask.TaskNumber); task.StartTime = updateTask.StartTime; task.EndTime = updateTask.EndTime; task.TaskStatusId = long.Parse(updateTask.Status); task.Memo = updateTask.Memo; //修改喂食任务的喂食人员 new TaskEmployeeService().UpdateByNumberStr(task, updateTask.EmployeeNumber); var pigstyFodders = new Dictionary<long, string>(); foreach (FeedTaskDetail detail in updateTask.Feeddetails) { string fodder = detail.Fodder; foreach (string s in detail.Pigsty.Split(',')) { pigstyFodders.Add(pigstyService.GetPigsty(int.Parse(s), long.Parse(detail.PigHouse)).Id, fodder); } } int oldLen = task.task_pigsty.Count; int newLen = pigstyFodders.Count; int leastLen = oldLen < newLen ? oldLen : newLen; var fodderTypeService = new FodderTypeService(); for (int i = 0; i < leastLen; i++) { KeyValuePair<long, string> pigstyFodder = pigstyFodders.ElementAt(i); task.task_pigsty.ElementAt(i).PigstyId = pigstyFodder.Key; string[] fodders = pigstyFodder.Value.Split(','); int oldLength = task.task_pigsty.ElementAt(i).feed_task_quality.Count; int newLength = fodders.Count(); int leastLength = oldLength < newLength ? oldLength : newLength; for (int j = 0; j < leastLength; j++) { task.task_pigsty.ElementAt(i).feed_task_quality.ElementAt(j).FodderTypeId = fodderTypeService.FindByName(fodders[j]).Id; } for (int j = leastLength; j < oldLength; j++) { taskQualityService.Delete( taskQualityService.Find(task.task_pigsty.ElementAt(i).feed_task_quality.ElementAt(j).Id)); } for (int j = leastLength; j < newLength; j++) { task.task_pigsty.ElementAt(i).feed_task_quality.Add(new feed_task_quality { FodderTypeId = fodderTypeService.FindByName( fodders[j]).Id }); } } var taskPigstyService = new TaskPigstyService(); for (int i = leastLen; i < oldLen; i++) { task_pigsty taskPigsty = task.task_pigsty.ElementAt(i); foreach (feed_task_quality feedTaskQuality in taskPigsty.feed_task_quality) { taskQualityService.Delete(taskQualityService.Find(feedTaskQuality.Id)); } taskPigstyService.Delete(taskPigstyService.Find(taskPigsty.Id)); } for (int i = leastLen; i < newLen; i++) { KeyValuePair<long, string> pigstyFodder = pigstyFodders.ElementAt(i); var taskPigsty = new task_pigsty { PigstyId = pigstyFodder.Key }; foreach (string item in pigstyFodder.Value.Split(',')) { taskPigsty.feed_task_quality.Add(new feed_task_quality { FodderTypeId = fodderTypeService.FindByName(item).Id }); } task.task_pigsty.Add(taskPigsty); } taskService.Update(task); for (int i = 0; i < updateTask.FeedTaskCycle.Count; i++) { if (i < task.task_interval_cycle.Count) { task_interval_cycle updateitem = taskIntervalCycleService.FindByTaskId(task.Id)[i]; updateitem.CycleDays = updateTask.FeedTaskCycle.ToList()[i].CycleDays; updateitem.FirstExecuteDate = updateTask.FeedTaskCycle.ToList()[i].FirstExecuteDate; taskIntervalCycleService.Update(updateitem); } else { var updateitem = new task_interval_cycle { TaskId = task.Id, CycleDays = updateTask.FeedTaskCycle.ToList()[i].CycleDays, FirstExecuteDate = updateTask.FeedTaskCycle.ToList()[i].FirstExecuteDate }; taskIntervalCycleService.Insert(updateitem); } } taskIntervalCycleService.DelTaskIntervalCycle(task, updateTask.FeedTaskCycle.Count); return true; }
/// <summary> /// 新建喂食任务 /// </summary> /// <param name="newTask"></param> /// <param name="taskTypeId"></param> /// <param name="createEmployee">发布任务的员工工号</param> /// <returns></returns> public bool NewFeedTask(FeedTask newTask, long taskTypeId, string createEmployee) { if (createEmployee == null) throw new ArgumentNullException("createEmployee"); var employeeService = new EmployeeService(); var task = new task { TaskNumber = newTask.TaskNumber, StartTime = newTask.StartTime, EndTime = newTask.EndTime, CreateTime = DateTime.Now, CreateEmployeeId = employeeService.FindByNumber(createEmployee).Id, TaskStatusId = 1, TaskTypeId = taskTypeId, Memo = newTask.Memo }; //根据工号找到对应的id foreach (string employeeNumber in newTask.EmployeeNumber.Split(',')) { task.task_employee.Add(new task_employee {EmployeeId = employeeService.FindByNumber(employeeNumber).Id}); } var pigstyService = new PigstyService(); var fodderService = new FodderTypeService(); foreach (FeedTaskDetail detail in newTask.Feeddetails) { string[] pigstyNum = detail.Pigsty.Split(','); long pighouseid = long.Parse(detail.PigHouse); string[] fodders = detail.Fodder.Split(','); List<long> fodderIds = fodders.Select(fodder => fodderService.FindByName(fodder).Id).ToList(); foreach (string pigstydetail in pigstyNum) { var taskPigsty = new task_pigsty(); int number = int.Parse(pigstydetail); taskPigsty.PigstyId = pigstyService.GetPigsty(number, pighouseid).Id; foreach (long fodder in fodderIds) { taskPigsty.feed_task_quality.Add(new feed_task_quality {FodderTypeId = fodder}); } task.task_pigsty.Add(taskPigsty); } } foreach ( task_interval_cycle taskIntervalCycle in newTask.FeedTaskCycle.Select(taskcycle => new task_interval_cycle { FirstExecuteDate = taskcycle.FirstExecuteDate, CycleDays = taskcycle.CycleDays })) { task.task_interval_cycle.Add(taskIntervalCycle); } var taskService = new TaskService(); taskService.Insert(task); return true; }
/// <summary> /// 根据猪栏Id查找猪舍 /// </summary> /// <param name="pigstyId">猪栏的Id</param> /// <returns>猪舍类</returns> public pig_house FindbyPigstyId(long pigstyId) { long pigHouseId = new PigstyService().Find(pigstyId).pig_house.Id; return Find(pigHouseId); }
public bool UpdateTransferTask(TransferTask updateTask) { var taskService = new TaskService(); task task = taskService.FindByTaskNumber(updateTask.TaskNumber); if (task == null) { return false; } task.StartTime = updateTask.StartTime; task.EndTime = updateTask.EndTime; task.Memo = updateTask.Memo; new TaskEmployeeService().UpdateByNumberStr(task, updateTask.EmployeeNumber); var pigService = new PigService(); List<long> pigList = (from taskDetail in updateTask.TransferFrom from pig in taskDetail.Pig.Split(',') select pigService.FindByNumber(pig).Id).ToList(); int oldLen = task.task_pig.Count; int newLen = pigList.Count; int leastLength = oldLen < newLen ? oldLen : newLen; for (int i = 0; i < leastLength; i++) { task.task_pig.ElementAt(i).PigId = pigList[i]; } var transferTaskPigService = new TaskPigService(); for (int i = leastLength; i < oldLen; i++) { transferTaskPigService.Delete(transferTaskPigService.Find(task.task_pig.ElementAt(i).Id)); } for (int i = leastLength; i < newLen; i++) { task.task_pig.Add(new task_pig { PigId = pigList[i] }); } var pigstyService = new PigstyService(); List<long> pigstyList = (from taskDetail in updateTask.TransferTo from pigsty in taskDetail.Pigsty.Split(',') select pigstyService.FindByNumber(int.Parse(pigsty)).First( m => m.PigHouseId == long.Parse(taskDetail.PigHouse)).Id).ToList(); oldLen = task.task_pigsty.Count; newLen = pigstyList.Count; leastLength = oldLen < newLen ? oldLen : newLen; for (int i = 0; i < leastLength; i++) { task.task_pigsty.ElementAt(i).PigstyId = pigstyList[i]; } var taskPigstyService = new TaskPigstyService(); for (int i = leastLength; i < oldLen; i++) { taskPigstyService.Delete(taskPigstyService.Find(task.task_pigsty.ElementAt(i).Id)); } for (int i = leastLength; i < newLen; i++) { task.task_pigsty.Add(new task_pigsty { PigstyId = pigstyList[i] }); } taskService.Update(task); return true; }
/// <summary> /// 猪栏id为1的猪下拉列表 /// </summary> /// <returns></returns> public IEnumerable<SelectListItem> GetFirstPigList() { var pigHouseService = new PigHouseService(); var pigstyService = new PigstyService(); var transferService = new TransferService(); var pigSelect = new List<SelectListItem>(); pig_house pigHouse = pigHouseService.FindAll().FirstOrDefault(); if (pigHouse != null) { pigsty pigsty = pigstyService.FindByPigHouseId(pigHouse.Id).FirstOrDefault(); if (pigsty != null) { string[] strPig = transferService.GetPigIdAndNum(pigsty.Id).Split(','); if (strPig[0] != "") pigSelect.AddRange( strPig.Select(strPigItem => strPigItem.Split(':')).Select(pig => new SelectListItem { Text = pig[1], Value = pig[0] }).OrderBy(m => m.Text)); } } return pigSelect; }
public bool UpdatePreventionDiseaseTask(PreventionDiseaseTask updateTask) { var taskService = new TaskService(); task task = taskService.FindByTaskNumber(updateTask.TaskNumber); if (task == null) { return false; } task.StartTime = updateTask.StartTime; task.EndTime = updateTask.EndTime; task.Memo = updateTask.Memo; if (task.task_prevention.FirstOrDefault() == null) { task.task_prevention.Add(new task_prevention { PreventionTypeId = long.Parse(updateTask.DiseaseName) }); } else { task.task_prevention.First().PreventionTypeId = long.Parse(updateTask.DiseaseName); } new TaskEmployeeService().UpdateByNumberStr(task, updateTask.EmployeeNumber); var pigstyService = new PigstyService(); List<long> pigstyList = (from taskDetail in updateTask.Taskdetails from pigsty in taskDetail.Pigsty.Split(',') select pigstyService.FindByNumber(int.Parse(pigsty)).First( m => m.PigHouseId == long.Parse(taskDetail.PigHouse)).Id).ToList(); int oldLen = task.task_pigsty.Count; int newLen = pigstyList.Count; int leastLength = oldLen < newLen ? oldLen : newLen; for (int i = 0; i < leastLength; i++) { task.task_pigsty.ElementAt(i).PigstyId = pigstyList[i]; } var taskPigstyService = new TaskPigstyService(); for (int i = leastLength; i < oldLen; i++) { taskPigstyService.Delete(taskPigstyService.Find(task.task_pigsty.ElementAt(i).Id)); } for (int i = leastLength; i < newLen; i++) { task.task_pigsty.Add(new task_pigsty { PigstyId = pigstyList[i] }); } taskService.Update(task); return true; }
public BatchAddPigstiesModel GetAllPigstiesRfid() { var batchAddPigstiesModel = new BatchAddPigstiesModel(); var addPigstiesModels = new List<AddPigstiesModel>(); batchAddPigstiesModel.AddPigstiesModels = addPigstiesModels; if (!Directory.Exists(@"c:\pigrecorder\pigsty")) { // 如果目录不在,则创建 Directory.CreateDirectory(@"c:\pigrecorder\pigsty"); } string[] strFiles = Directory.GetFiles(@"c:\pigrecorder\pigsty"); foreach (string strFile in strFiles) { //读取指定文件夹下面的指定文件 string[] lineList = File.ReadAllLines(strFile, Encoding.Default); //单个文件中原始的记录的2维字符串数组 var array = new string[lineList.Length,2]; int i = 0; int length = lineList.Length; foreach (string line in lineList) { string[] elementList = line.Split(','); for (int j = 0; j < elementList.Length; j++) { if (elementList[0] != "") array[i, j] = elementList[j]; } if (elementList[0] != "") i++; else length--; } var newarray = new List<string>(); for (i = 0; i < length; i++) { int d = 0; //判断是否重复 foreach (string ind in newarray) { if (ind == array[i, 0]) { d = 1; } } if (d == 0) { newarray.Add(array[i, 0]); } } int pigstyNumber = 0; for (i = 0; i < newarray.Count; i++) { var addPigstiesModel = new AddPigstiesModel(); var pigstyService = new PigstyService(); if (pigstyService.FindByRfid(newarray[i]) == null) { addPigstiesModel.Rfid = newarray[i]; addPigstiesModel.PigstyNumber = ++pigstyNumber; addPigstiesModels.Add(addPigstiesModel); } } } return batchAddPigstiesModel; }
/// <summary> /// 新建销售任务 /// </summary> /// <param name="newTask">销售任务</param> /// <param name="taskTypeId">任务类型id</param> /// <param name="createEmployee">发布任务的员工工号</param> /// <returns>返回新建任务是否成功</returns> public bool NewAddPigTask(AddPigTask newTask, long taskTypeId, string createEmployee) { var employeeService = new EmployeeService(); var task = new task { TaskNumber = newTask.TaskNumber, StartTime = newTask.StartTime, EndTime = newTask.EndTime, CreateTime = DateTime.Now, CreateEmployeeId = employeeService.FindByNumber(createEmployee).Id, TaskStatusId = 1, TaskTypeId = taskTypeId, Memo = newTask.Memo }; foreach (string employeeNumber in newTask.EmployeeNumber.Split(',')) { task.task_employee.Add(new task_employee {EmployeeId = employeeService.FindByNumber(employeeNumber).Id}); } var pigstyService = new PigstyService(); foreach (TaskDetail detail in newTask.TaskDetails) { string[] pigstyNum = detail.Pigsty.Split(new[] {','}); long pighouseid = long.Parse(detail.PigHouse); foreach (string pigstydetail in pigstyNum) { var taskPigsty = new task_pigsty(); int number = int.Parse(pigstydetail); taskPigsty.PigstyId = pigstyService.GetPigsty(number, pighouseid).Id; task.task_pigsty.Add(taskPigsty); } } var taskService = new TaskService(); taskService.Insert(task); return true; }
public ActionResult ModifyPigstyEquipMentInfo(PigstyModel model) { var pigstyService = new PigstyService(); pigsty pigsty = pigstyService.Find(model.Id); pigsty.RFID = model.Rfid; pigsty.Number = model.Number; pigsty.PigHouseId = model.PigHouseId; pigsty.Memo = model.Memo; pigsty.Capacity = model.Capacity; pigstyService.Update(pigsty); ViewBag.Title = "修改成功"; return View("PigstyMessage"); }
/// <summary> /// 将页面的巡查类分类,以猪舍id为key,包含以猪栏id为key,异常类型id为值的字典集合 /// </summary> /// <param name="info">页面的巡查</param> /// <returns></returns> public Dictionary<long, Dictionary<long, long>> SortPigstyAndexception(InspectInfo info) { var pigstyAndexception = new Dictionary<long, Dictionary<long, long>>(); var pigstyService = new PigstyService(); foreach (InspectDetail inspectDetail in info.InspectDetail) { var dic = new Dictionary<long, long>(); if (inspectDetail.Pigsty != null) foreach (string str in inspectDetail.Pigsty.Split(',')) { if (str.Length > 0) { pigsty pigstyStr = pigstyService.GetPigsty(int.Parse(str), long.Parse(inspectDetail.PigHouse)); if (dic.ContainsKey(pigstyStr.Id)) continue; dic.Add(pigstyStr.Id, long.Parse(inspectDetail.InspectionException)); } } if (pigstyAndexception.ContainsKey(long.Parse(inspectDetail.PigHouse))) foreach (var l in dic) { pigstyAndexception[long.Parse(inspectDetail.PigHouse)].Add(l.Key, l.Value); } else pigstyAndexception.Add(long.Parse(inspectDetail.PigHouse), dic); } return pigstyAndexception; }
public TransferTask GetTransferTask(string taskNumber) { var taskService = new TaskService(); var taskEmployeeService = new TaskEmployeeService(); task task = taskService.FindByTaskNumber(taskNumber); if (task == null) { return null; } var checkTask = new TransferTask { TaskNumber = task.TaskNumber, StartTime = task.StartTime, EndTime = task.EndTime, EmployeeName = taskEmployeeService.GetEmployeeNames(task.Id), EmployeeNumber = taskEmployeeService.GetEmployeeNumbers(task.Id), Status = task.task_status_type.Name, Memo = task.Memo }; var transferService = new TransferService(); var pigstyDic = new Dictionary<long, StringBuilder>(); foreach (task_pig item in task.task_pig) { transfer transfer = transferService.GetLastTransfer(item.PigId, task.Id); if (transfer == null) { continue; } long pigsty = transfer.PigstyId; if (!pigstyDic.ContainsKey(pigsty)) { pigstyDic.Add(pigsty, new StringBuilder().Append(transfer.pig.Number)); } else { pigstyDic[pigsty].Append("," + transfer.pig.Number); } } var pigHouseService = new PigHouseService(); var pigstyService = new PigstyService(); if (pigstyDic.Count != 0) { List<TaskDetail> transferFromList = (from builder in pigstyDic let pigHouse = pigHouseService.FindbyPigstyId(builder.Key) select new TaskDetail { PigHouse = pigHouse.pig_house_type.Name + pigHouse.Number, Pigsty = pigstyService.Find(builder.Key).Number + "", Pig = builder.Value.ToString() }).ToList(); checkTask.TransferFrom = transferFromList; } var transferToList = new List<TaskDetail>(); var pigHouseDic = new Dictionary<string, StringBuilder>(); foreach (task_pigsty taskPigsty in task.task_pigsty) { pig_house pigHouse = pigHouseService.FindbyPigstyId(taskPigsty.PigstyId); if (pigHouse == null) { continue; } string pigHouseStr = pigHouse.pig_house_type.Name + pigHouse.Number; if (!pigHouseDic.ContainsKey(pigHouseStr)) { pigHouseDic.Add(pigHouseStr, new StringBuilder().Append(taskPigsty.pigsty.Number)); } else { pigHouseDic[pigHouseStr].Append("," + taskPigsty.pigsty.Number); } } if (pigHouseDic.Count != 0) { transferToList.AddRange(pigHouseDic.Select(builder => new TaskDetail { PigHouse = builder.Key, Pigsty = builder.Value.ToString() })); checkTask.TransferTo = transferToList; } return checkTask; }
//猪栏RFID public bool PigstyRfidCompare(string rfid) { var pigstyService = new PigstyService(); if (pigstyService.FindByRfid(rfid) != null) { return false; } return true; }
public object GetCureTask(string taskNumber) { var taskService = new TaskService(); var taskEmployeeService = new TaskEmployeeService(); task task = taskService.FindByTaskNumber(taskNumber); if (task == null) { return null; } var checkTask = new CureTask { TaskNumber = task.TaskNumber, StartTime = task.StartTime, EndTime = task.EndTime, EmployeeName = taskEmployeeService.GetEmployeeNames(task.Id), EmployeeNumber = taskEmployeeService.GetEmployeeNumbers(task.Id), Status = task.task_status_type.Name, Memo = task.Memo }; var transferService = new TransferService(); var pigstyDic = new Dictionary<long, StringBuilder>(); foreach (task_pig item in task.task_pig) { transfer transfer = transferService.GetLastTransfer(item.PigId, task.Id); if (transfer == null) { continue; } long pigsty = transfer.PigstyId; if (!pigstyDic.ContainsKey(pigsty)) { pigstyDic.Add(pigsty, new StringBuilder().Append(transfer.pig.Number)); } else { pigstyDic[pigsty].Append("," + transfer.pig.Number); } } var pigHouseService = new PigHouseService(); var pigstyService = new PigstyService(); if (pigstyDic.Count != 0) { checkTask.CureDetail = (from builder in pigstyDic let pigHouse = pigHouseService.FindbyPigstyId(builder.Key) select new TaskDetail { PigHouse = pigHouse.pig_house_type.Name + pigHouse.Number, Pigsty = pigstyService.Find(builder.Key).Number + "", Pig = builder.Value.ToString() }).ToList(); } List<CureCourse> courseList = (from cureCourse in task.cure_task_course let methodList = (from cureMethod in cureCourse.cure_task_method let medicineList = cureMethod.cure_task_medicine.Select( cureTaskMedicine => new Medicine { MedicineName = cureTaskMedicine. medicine.Name, Quality = cureTaskMedicine. Quality, Unit = cureTaskMedicine. unit.Name }).ToList() select new CureMethod { CureMedicine = medicineList, CureType = cureMethod.cure_type.Name }).ToList() select new CureCourse { CureOrder = cureCourse.Order, CureTime = cureCourse.Time, CureMethod = methodList }).ToList(); if (courseList[0].CureMethod.Count != 0 && courseList[0].CureMethod[0].CureMedicine.Count != 0) { checkTask.CureCourse = courseList; } return checkTask; }
//猪栏所处猪舍 public bool PigstyRfidCompareByType(long typeid, int number) { var pigstyService = new PigstyService(); return pigstyService.FindByPigHouseId(typeid).All(c => c.Number != number); }
public FodderTakeModel GetFodderDetail(FodderTakeModel model) { //初始化 var newFodderDetails = new List<FodderDetail>(); //var newFodderDetail=new FodderDetail(); //newFodderDetails.Add(newFodderDetail); model.TaskDetail = newFodderDetails; var pigstyService = new PigstyService(); var tasktypeService = new TaskTypeService(); var taskEmployeeService = new TaskEmployeeService(); var taskpigstyservice = new TaskPigstyService(); var feedTaskQualityService = new FeedTaskQualityService(); var taskIntervalCycleService = new TaskIntervalCycleService(); int taskflag = 0; long employeeTaskId = 0; var taskService = new TaskService(); List<task_employee> alltask = taskEmployeeService.FindByEmployeeId(model.ActualEmployeeId); //根据任务id找到任务类型,若是当天的喂饲任务,记录taskid foreach (task_employee task in alltask) { long tasktypeid = taskService.Find(task.TaskId).TaskTypeId; string tasktype = tasktypeService.Find(tasktypeid).Name; if (tasktype == "喂饲") { List<task_interval_cycle> taskInterval = taskIntervalCycleService.FindByTaskId(task.TaskId); foreach (task_interval_cycle taskinterval in taskInterval) { for (int i = 0; i < 1000; i++) { //根据任务的循环时间匹配是否有当天的任务 if ( taskinterval.FirstExecuteDate.AddDays(Convert.ToDouble(taskinterval.CycleDays*i)) . ToShortDateString() == DateTime.Now.ToShortDateString()) { taskflag = 1; //标志 employeeTaskId = task.TaskId; break; } } } } } if (taskflag == 1) { List<task_pigsty> taskPisties = taskpigstyservice.FindByTaskId(employeeTaskId); //遍历该任务的所有的猪栏,并将其对应的饲料添加到model.TaskDetail中 int i; foreach (task_pigsty taskPigsty in taskPisties) { List<feed_task_quality> taskQuality = feedTaskQualityService.FindByFeedTaskPigstyId(taskPigsty.Id); if (model.TaskDetail.Count == 0) { var fodderDetail = new FodderDetail { FodderTypeName = taskQuality[0].fodder_type.Name, //Quality = taskQuality[0].Quality * pigstyService.GetPignumbers(Convert.ToInt64(taskPigsty.PigstyId)), //UnitName = taskQuality[0].unit.Name, FodderTypeId = taskQuality[0].FodderTypeId, //UnitId = taskQuality[0].UnitId }; model.TaskDetail.Add(fodderDetail); } else { int knt = 0; //判断该猪栏的饲料是否跟 for (i = 0; i < model.TaskDetail.Count; i++) { if (model.TaskDetail[i].FodderTypeName == taskQuality[0].fodder_type.Name) { //model.TaskDetail[i].Quality = taskQuality[0].Quality* // pigstyService.GetPignumbers( // Convert.ToInt64(taskPigsty.PigstyId)) + // model.TaskDetail[i].Quality; knt = 1; } } if (knt == 0) { var fodderDetail = new FodderDetail { FodderTypeName = taskQuality[0].fodder_type.Name, //Quality = taskQuality[0].Quality * pigstyService.GetPignumbers(Convert.ToInt64(taskPigsty.PigstyId)), //UnitName = taskQuality[0].unit.Name, FodderTypeId = taskQuality[0].FodderTypeId, //UnitId = taskQuality[0].UnitId }; model.TaskDetail.Add(fodderDetail); } } } model.TaskNumber = taskService.Find(employeeTaskId).TaskNumber; //任务的全部人员 List<task_employee> allemployees = taskEmployeeService.FindByTaskId(employeeTaskId); string reAllEmployeeName = ""; for (i = 0; i < allemployees.Count - 1; i++) { reAllEmployeeName = reAllEmployeeName + allemployees[i].employee.Name + ","; } reAllEmployeeName = reAllEmployeeName + allemployees[i].employee.Name; model.TaskEmployeeName = reAllEmployeeName; } return model; }
/// <summary> /// 猪舍id为1猪栏下拉列表 /// </summary> /// <returns></returns> public IEnumerable<SelectListItem> GetFirstPigstyList() { var pigHouseService = new PigHouseService(); var pigstyService = new PigstyService(); IEnumerable<SelectListItem> pigstySelect = new List<SelectListItem>(); pig_house firstOrDefault = pigHouseService.FindAll().FirstOrDefault(); if (firstOrDefault != null) { pigstySelect = pigstyService.FindByPigHouseId(firstOrDefault.Id).OrderBy(m=>m.Number).Select( pigstyItem => new SelectListItem { Text = pigstyItem.Number + "", Value = pigstyItem.Id + "" }); } return pigstySelect; }
/// <summary> /// 新建转栏任务 /// </summary> /// <param name="newTask">转栏任务</param> /// <param name="taskTypeId">任务类型id</param> /// <param name="createEmployee">发布任务的员工工号</param> /// <returns>返回新建任务是否成功</returns> public bool NewTransferTask(TransferTask newTask, long taskTypeId, string createEmployee) { var employeeService = new EmployeeService(); var task = new task { TaskNumber = newTask.TaskNumber, StartTime = newTask.StartTime, EndTime = newTask.EndTime, CreateTime = DateTime.Now, CreateEmployeeId = employeeService.FindByNumber(createEmployee).Id, TaskStatusId = 1, TaskTypeId = taskTypeId, Memo = newTask.Memo }; foreach (string employeeNumber in newTask.EmployeeNumber.Split(',')) { task.task_employee.Add(new task_employee {EmployeeId = employeeService.FindByNumber(employeeNumber).Id}); } var pigService = new PigService(); foreach (string pigNumber in newTask.TransferFrom.SelectMany(taskDetail => taskDetail.Pig.Split(','))) { task.task_pig.Add(new task_pig { PigId = pigService.FindByNumber(pigNumber).Id }); } var pigstyService = new PigstyService(); foreach (TaskDetail taskDetail in TransferTo) { string pigHouse = taskDetail.PigHouse; foreach (string pigstyNumber in taskDetail.Pigsty.Split(',')) { task.task_pigsty.Add(new task_pigsty { PigstyId = pigstyService.GetPigsty(int.Parse(pigstyNumber), long.Parse(pigHouse)).Id }); } } var taskService = new TaskService(); taskService.Insert(task); return true; }
/// <summary> /// 查看淘汰任务 /// </summary> /// <param name="taskNumber">任务编号</param> /// <returns></returns> public EliminateTask GetEliminateTask(string taskNumber) { var taskService = new TaskService(); var taskEmployeeService = new TaskEmployeeService(); task task = taskService.FindByTaskNumber(taskNumber); if (task == null) { return null; } var customerService = new CustomerService(); var checkTask = new EliminateTask { TaskNumber = task.TaskNumber, StartTime = task.StartTime, EndTime = task.EndTime, EmployeeName = taskEmployeeService.GetEmployeeNames(task.Id), EmployeeNumber = taskEmployeeService.GetEmployeeNumbers(task.Id), Status = task.task_status_type.Name, Memo = task.Memo }; var transferService = new TransferService(); var pigstyDic = new Dictionary<long, StringBuilder>(); foreach (task_pig item in task.task_pig) { transfer transfer = transferService.GetLastTransfer(item.PigId, task.Id); if (transfer == null) { continue; } long pigsty = transfer.PigstyId; if (!pigstyDic.ContainsKey(pigsty)) { pigstyDic.Add(pigsty, new StringBuilder().Append(transfer.pig.Number)); } else { pigstyDic[pigsty].Append("," + transfer.pig.Number); } } foreach (task_pigsty item in task.task_pigsty) { long pigsty = item.PigstyId; pigstyDic.Add(pigsty, new StringBuilder().Append("")); } var pigHouseService = new PigHouseService(); var pigstyService = new PigstyService(); if (pigstyDic.Count != 0) { checkTask.EliminateTaskDetail = (from builder in pigstyDic let pigHouse = pigHouseService.FindbyPigstyId(builder.Key) select new TaskDetail { PigHouse = pigHouse.pig_house_type.Name + pigHouse.Number, Pigsty = pigstyService.Find(builder.Key).Number + "", Pig = builder.Value.ToString() }).ToList(); } return checkTask; }
public bool NewPreventionDiseaseTask(PreventionDiseaseTask newTask, long taskTypeId, string createEmployee) { var employeeService = new EmployeeService(); var task = new task { TaskNumber = newTask.TaskNumber, StartTime = newTask.StartTime, EndTime = newTask.EndTime, CreateTime = DateTime.Now, CreateEmployeeId = employeeService.FindByNumber(createEmployee).Id, TaskStatusId = 1, TaskTypeId = taskTypeId, Memo = newTask.Memo, }; foreach (string employeeNumber in newTask.EmployeeNumber.Split(',')) { task.task_employee.Add(new task_employee {EmployeeId = employeeService.FindByNumber(employeeNumber).Id}); } var pigstyService = new PigstyService(); var transferService = new TransferService(); foreach (TaskDetail detail in newTask.Taskdetails) { string[] pigstyNum = detail.Pigsty.Split(new[] {','}); long pighouseid = long.Parse(detail.PigHouse); foreach (string pigstydetail in pigstyNum) { var taskPigsty = new task_pigsty(); int number = int.Parse(pigstydetail); if (detail.Pig == "2") { taskPigsty.PigstyId = pigstyService.GetPigsty(number, pighouseid).Id; var munPigList=transferService.FindByMunPig(taskPigsty.PigstyId); foreach (var munPig in munPigList) task.task_pig.Add(new task_pig() { PigId = munPig.PigId }); } else { taskPigsty.PigstyId = pigstyService.GetPigsty(number, pighouseid).Id; task.task_pigsty.Add(taskPigsty); } } } task.task_prevention.Add(new task_prevention { PreventionTypeId = long.Parse(newTask.DiseaseName) }); var taskService = new TaskService(); taskService.Insert(task); return true; }