//判断类型是否重复 public bool JudgeNameByType(string name, string typename) { var cureTypeService = new CureTypeService(); var medicineService = new MedicineService(); var unitService = new UnitService(); var fodderTypeService = new FodderTypeService(); var excetionTypeService = new ExceptionTypeService(); var pigTypeService = new PigTypeService(); var pigHouseTypeService = new PigHouseTypeService(); var taskStatusTypeService = new TaskStatusTypeService(); var taskTypeService = new TaskTypeService(); var roleTypeService = new RoleTypeService(); var preventionTypeService = new PreventionTypeService(); var customerService = new CustomerService(); if (typename == "治疗") { if (cureTypeService.FindByName(name) == null) return true; } if (typename == "单位") { if (unitService.FindByName(name) == null) return true; } if (typename == "药物") { if (medicineService.FindByName(name) == null) return true; } if (typename == "异常") { if (excetionTypeService.FindByName(name).Count == 0) return true; } if (typename == "饲料") { if (fodderTypeService.FindByName(name) == null) return true; } if (typename == "生猪") { if (pigTypeService.FindByName(name) == null) return true; } if (typename == "防疫") { if (preventionTypeService.FindByName(name) == null) return true; } if (typename == "猪舍") { if (pigHouseTypeService.FindByName(name) == null) return true; } if (typename == "任务状态") { if (taskStatusTypeService.FindByName(name) == null) return true; } if (typename == "任务类型") { if (taskTypeService.FindByName(name) == null) return true; } if (typename == "角色") { if (roleTypeService.FindByName(name) == null) return true; } if (typename == "客户名称") { if (customerService.FindByName(name) == null) return true; } return false; }
/// <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> /// 修改喂食任务 /// </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; }
public void FodderTypeSaveChanges(BasicInfoModel model) { var fodderTypeService = new FodderTypeService(); List<fodder_type> fodderTypes = fodderTypeService.FindAll(); foreach (fodder_type fodderType in fodderTypes) { int idFlag = 0; int nameFlag = 0; string newname = ""; foreach (NameModel name in model.Names) { if (fodderType.Id == name.Id) { idFlag = 1; if (fodderType.Name.Equals(name.Name)) { nameFlag = 1; } else { newname = name.Name; } } } //若存在此Id,但是name变化了的,则需要修改数据库 if (idFlag == 1) { if (nameFlag == 0) { if (newname == "") { throw new Exception(); } fodder_type modifyCure = fodderTypeService.Find(fodderType.Id); modifyCure.Name = newname; fodderTypeService.Update(modifyCure); } } } //如果model里的Id为0,说明是新建的类型 foreach (NameModel name in model.Names) { if (name.Id == 0 && fodderTypeService.FindByName(name.Name) == null) { var newType = new fodder_type {Name = name.Name}; fodderTypeService.Insert(newType); } } }