public MedicineTakeModel GetCureTaskByEmployeeId(long employeeId) { var medicineTakeModel = new MedicineTakeModel(); var tasktypeService = new TaskTypeService(); var taskEmployeeService = new TaskEmployeeService(); var taskService = new TaskService(); var cureTaskMethodService = new CureTaskMethodService(); var cureTaskCourseService = new CureTaskCourseService(); var cureTaskMedicineService = new CureTaskMedicineService(); int taskflag = 0; long employeeTaskId = 0; long cureCourseId = 0; List<task_employee> alltask = taskEmployeeService.FindByEmployeeId(employeeId); //根据任务id找到任务类型,若是当天的治疗任务,记录taskid foreach (task_employee task in alltask) { long tasktypeid = taskService.Find(task.TaskId).TaskTypeId; string tasktype = tasktypeService.Find(tasktypeid).Name; if (tasktype == "治疗") { //判断当前记录的时间是否和任务中某一个疗程的开始时间相同,若是,则代表当天有治疗任务 List<cure_task_course> cureTaskCourses = cureTaskCourseService.FindByTaskId(task.TaskId); foreach (cure_task_course cureTaskCourse in cureTaskCourses) { if (cureTaskCourse.Time.ToShortDateString() == DateTime.Now.ToShortDateString()) { taskflag = 1; employeeTaskId = task.TaskId; cureCourseId = cureTaskCourse.Id; medicineTakeModel.TaskCourseId = cureCourseId; } } } } if (taskflag == 1) { List<cure_task_method> cureTaskMethods = cureTaskMethodService.FindByCureTaskCourseId(cureCourseId); var cureDetails = new List<CureDetail>(); CureDetail cureDetail = null; medicineTakeModel.CureTaskType = cureDetails; foreach (cure_task_method cureTaskMethod in cureTaskMethods) { cureDetail = new CureDetail(); cureDetail.CureType = cureTaskMethod.cure_type.Name; cureDetails.Add(cureDetail); var cureMedicineDetails = new List<CureMedicineDetail>(); cureDetail.CureMedicineDetail = cureMedicineDetails; CureMedicineDetail cureMedicineDetail = null; List<cure_task_medicine> cureTaskMedicines = cureTaskMedicineService.FindByCureTaskMethodId(cureTaskMethod.Id); foreach (cure_task_medicine cureTaskMedicine in cureTaskMedicines) { cureMedicineDetail = new CureMedicineDetail(); cureMedicineDetail.Medicine = cureTaskMedicine.medicine.Name; cureMedicineDetail.Quality = cureTaskMedicine.Quality; cureMedicineDetail.Unit = cureTaskMedicine.unit.Name; cureMedicineDetails.Add(cureMedicineDetail); } } medicineTakeModel.TaskNumber = taskService.Find(employeeTaskId).TaskNumber; List<task_employee> allemployees = taskEmployeeService.FindByTaskId(employeeTaskId); int i; string reAllEmployeeName = ""; for (i = 0; i < allemployees.Count - 1; i++) { reAllEmployeeName = reAllEmployeeName + allemployees[i].employee.Name + ","; } reAllEmployeeName = reAllEmployeeName + allemployees[i].employee.Name; medicineTakeModel.EmloyeeName = reAllEmployeeName; } return medicineTakeModel; }
/// <summary> /// 根据类型id查找关联它的表是否为0 /// </summary> /// <param name="typeid">类型id</param> /// <param name="typename">类型名字</param> /// <returns></returns> public string GetRelationtById(long typeid, 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 roleAuthorityService = new RoleAuthorityService(); var customerService = new CustomerService(); if (typeid == 0) { return "不存在于数据库,可以删除"; } try { if (typename == "治疗") { cureTypeService.Delete(cureTypeService.Find(typeid)); } if (typename == "单位") { unitService.Delete(unitService.Find(typeid)); } if (typename == "药物") { medicineService.Delete(medicineService.Find(typeid)); } if (typename == "异常") { excetionTypeService.Delete(excetionTypeService.Find(typeid)); } if (typename == "饲料") { fodderTypeService.Delete(fodderTypeService.Find(typeid)); } if (typename == "生猪") { if (pigTypeService.Find(typeid).Name == "母猪" || pigTypeService.Find(typeid).Name == "公猪") { return "不可删除"; } pigTypeService.Delete(pigTypeService.Find(typeid)); } if (typename == "防疫") { preventionTypeService.Delete(preventionTypeService.Find(typeid)); } if (typename == "猪舍") { pigHouseTypeService.Delete(pigHouseTypeService.Find(typeid)); } if (typename == "任务状态") { if (taskStatusTypeService.Find(typeid).Name == "未完成" || taskStatusTypeService.Find(typeid).Name == "已完成" || taskStatusTypeService.Find(typeid).Name == "正在进行") { return "不可删除"; } taskStatusTypeService.Delete(taskStatusTypeService.Find(typeid)); } if (typename == "任务类型") { if (taskTypeService.Find(typeid).Name == "喂饲" || taskTypeService.Find(typeid).Name == "防疫" || taskTypeService.Find(typeid).Name == "巡查" || taskTypeService.Find(typeid).Name == "治疗" || taskTypeService.Find(typeid).Name == "销售" || taskTypeService.Find(typeid).Name == "转栏" || taskTypeService.Find(typeid).Name == "添加生猪") { return "不可删除"; } taskTypeService.Delete(taskTypeService.Find(typeid)); } if (typename == "角色") { foreach (role_authority c in roleAuthorityService.FindByRoleTypeId(typeid)) roleAuthorityService.Delete(roleAuthorityService.Find(c.Id)); roleTypeService.Delete(roleTypeService.Find(typeid)); } if (typename == "客户名称") { customerService.Delete(customerService.Find(typeid)); } } catch (Exception) { return "不可删除"; } return ""; }
/// <summary> /// 根据id返回是否有喂饲任务 /// </summary> /// <param name="employeeId">人员id</param> /// <returns>返回是否有喂饲任务</returns> public string GetFeedTaskById(long employeeId) { var tasktypeService = new TaskTypeService(); var taskEmployeeService = new TaskEmployeeService(); var taskIntervalCycleService = new TaskIntervalCycleService(); int taskflag = 0; var taskService = new TaskService(); List<task_employee> alltask = taskEmployeeService.FindByEmployeeId(employeeId); //根据任务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; //标志 break; } } } } } if (taskflag == 0) { return "今天该员工没有喂饲任务"; } return ""; }
/// <summary> /// 根据id查找当天是否有治疗任务 /// </summary> /// <param name="employeeId">人员id</param> /// <returns>返回是否当天有治疗任务</returns> public string GetCureTaskById(long employeeId) { var tasktypeService = new TaskTypeService(); var taskEmployeeService = new TaskEmployeeService(); var taskService = new TaskService(); var cureTaskCourseService = new CureTaskCourseService(); int taskflag = 0; List<task_employee> alltask = taskEmployeeService.FindByEmployeeId(employeeId); //根据任务id找到任务类型,若是当天的治疗任务,记录taskid foreach (task_employee task in alltask) { long tasktypeid = taskService.Find(task.TaskId).TaskTypeId; string tasktype = tasktypeService.Find(tasktypeid).Name; if (tasktype == "治疗") { //判断当前记录的时间是否和任务中某一个疗程的开始时间相同,若是,则代表当天有治疗任务 List<cure_task_course> cureTaskCourses = cureTaskCourseService.FindByTaskId(task.TaskId); foreach (cure_task_course cureTaskCourse in cureTaskCourses) { if (cureTaskCourse.Time.ToShortDateString() == DateTime.Now.ToShortDateString()) { taskflag = 1; } } } } if (taskflag == 1) { return "1"; } return "2"; }
public void TaskTypeSaveChanges(BasicInfoModel model) { var typeService = new TaskTypeService(); List<task_type> types = typeService.FindAll(); foreach (task_type type in types) { int idFlag = 0; int nameFlag = 0; string newname = ""; foreach (NameModel name in model.Names) { if (type.Id == name.Id) { idFlag = 1; if (type.Name.Equals(name.Name)) { nameFlag = 1; } else { newname = name.Name; } } } //若存在此Id,但是name变化了的,则需要修改数据库 if (idFlag == 1) { if (nameFlag == 0) { if (newname == "") { throw new Exception(); } task_type modifyCure = typeService.Find(type.Id); modifyCure.Name = newname; typeService.Update(modifyCure); } } } //如果model里的Id为0,说明是新建的类型 foreach (NameModel name in model.Names) { if (name.Id == 0 && typeService.FindByName(name.Name) == null) { var newType = new task_type {Name = name.Name}; typeService.Insert(newType); } } }
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; }