private void UpdateByIdStr(task task, string[] ids) { int oldLen = task.task_pighouse.Count; int newLen = ids.Length; int leastLength = oldLen < newLen ? oldLen : newLen; var taskPigHouseService = new TaskPigHouseService(); List<task_pighouse> taskPigHouseList = FindByTaskId(task.Id); for (int i = 0; i < leastLength; i++) { task_pighouse updateitem = taskPigHouseList[i]; updateitem.PigHouseId = long.Parse(ids[i]); Update(updateitem); } for (int i = leastLength; i < oldLen; i++) { taskPigHouseService.Delete(taskPigHouseService.Find(taskPigHouseList[i].Id)); } for (int i = leastLength; i < newLen; i++) { taskPigHouseService.Insert(new task_pighouse { TaskId = task.Id, PigHouseId = long.Parse(ids[i]) }); } }
/// <summary> /// 更新任务的人员 /// </summary> /// <param name="task">任务类</param> /// <param name="numbers">员工名字的字符串数组</param> public void UpdateByNumber(task task, string[] numbers) { int oldLen = task.task_employee.Count; int newLen = numbers.Length; int leastLength = oldLen < newLen ? oldLen : newLen; var employeeService = new EmployeeService(); var taskEmployeeService = new TaskEmployeeService(); for (int i = 0; i < leastLength; i++) { task_employee updateitem = taskEmployeeService.FindByTaskId(task.Id)[i]; updateitem.EmployeeId = employeeService.FindByNumber(numbers[i]).Id; taskEmployeeService.Update(updateitem); } for (int i = leastLength; i < oldLen; i++) { taskEmployeeService.Delete(taskEmployeeService.Find(task.task_employee.ElementAt(i).Id)); } for (int i = leastLength; i < newLen; i++) { taskEmployeeService.Insert(new task_employee { TaskId = task.Id, EmployeeId = employeeService.FindByNumber(numbers[i]).Id }); } }
/// <summary> /// 修改时删除任务方式表 /// </summary> /// <param name="update">任务类</param> /// <param name="count">任务方式表的行数</param> public void DelTaskIntervalCycle(task update, int count) { for (int i = 0; i < update.task_interval_cycle.Count - count; i++) { var taskIntervalCycle = new TaskIntervalCycleService(); taskIntervalCycle.Delete(taskIntervalCycle.Find(update.task_interval_cycle.Last().Id)); } }
/// <summary> /// 新建淘汰任务 /// </summary> /// <param name="newTask"></param> /// <param name="taskTypeId"></param> /// <param name="createEmployee"></param> /// <returns></returns> public bool NewEliminateTask(EliminateTask 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 (var detail in newTask.EliminateTaskDetail) { if (detail.Pig != null) { var detailPigs = detail.Pig.Split(','); foreach (var str in detailPigs) task.task_pig.Add(new task_pig { PigId = pigService.FindByRfid(str).Id }); } else { task.task_pigsty.Add(new task_pigsty { PigstyId = long.Parse(detail.Pigsty) }); } } var taskService = new TaskService(); taskService.Insert(task); return true; }
/// <summary> /// 根据任务和员工姓名字符串来修改任务的员工 /// </summary> /// <param name="task">任务</param> /// <param name="employeeName">员工字符串,多个员工姓名用逗号分开</param> public void UpdateTaskEmployeeNames(task task, string employeeName) { string[] employees = employeeName.Split(','); UpdateTaskEmployee(task, employees); }
/// <summary> /// 根据任务和员工工号字符串来修改任务的员工 /// </summary> /// <param name="task">任务</param> /// <param name="employeeNumber">员工字符串,多个员工工号用逗号分开</param> public void UpdateByNumberStr(task task, string employeeNumber) { string[] numbers = employeeNumber.Split(','); UpdateByNumber(task, numbers); }
public bool NewInspectTask(InspectTask 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}); } foreach (string pigHouse in newTask.PigHouseId.Split(',')) { task.task_pighouse.Add(new task_pighouse { PigHouseId = long.Parse(pigHouse) }); } foreach ( task_interval_cycle taskIntervalCycle in newTask.InspectTaskCycle.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="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; }
public void UpdateByPigHouseStr(task task, string pigHouseId) { string[] ids = pigHouseId.Split(','); UpdateByIdStr(task, ids); }
/// <summary> /// 新建销售任务 /// </summary> /// <param name="newTask">销售任务</param> /// <param name="taskTypeId">任务类型id</param> /// <param name="createEmployee">发布任务的员工工号</param> /// <returns>返回新建任务是否成功</returns> public bool NewSaleTask(SaleTask 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 customerService = new CustomerService(); customer customer = customerService.FindByName(newTask.Customer) ?? customerService.Insert(new customer { Name = newTask . Customer }); task.CustomerId = customer.Id; foreach (SaleDetail detail in newTask.SaleDetailList) { task.sale_task_quality.Add(new sale_task_quality { PigTypeId = long.Parse(detail.PigType), Price = detail.Price, Quality = detail.Quantity }); } var taskService = new TaskService(); taskService.Insert(task); return true; }
/// <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="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 bool NewCureTask(CureTask 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.CureDetail.SelectMany(taskDetail => taskDetail.Pig.Split(','))) { task.task_pig.Add(new task_pig { PigId = pigService.FindByNumber(pigNumber).Id }); } foreach (CureCourse cureCourse in newTask.CureCourse) { var cureMethodList = new Collection<cure_task_method>(); foreach (CureMethod cureMethod in cureCourse.CureMethod) { var medicineList = new Collection<cure_task_medicine>(); foreach (Medicine medicine in cureMethod.CureMedicine.Where(medicine => !(medicine.Quality <= 0))) { medicineList.Add(new cure_task_medicine { MedicineId = long.Parse(medicine.MedicineName), Quality = medicine.Quality, UnitId = long.Parse(medicine.Unit) }); } cureMethodList.Add(new cure_task_method { CureTypeId = long.Parse(cureMethod.CureType), cure_task_medicine = medicineList }); } task.cure_task_course.Add(new cure_task_course { Order = cureCourse.CureOrder + 1, Time = cureCourse.CureTime, cure_task_method = cureMethodList }); } var taskService = new TaskService(); taskService.Insert(task); return true; }
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; }