public bool ClearCureMedicine(cure_method cureMethod) { foreach (cure_medicine cureMedicine in FindByCureMethoId(cureMethod.Id)) { Delete(Find(cureMedicine.Id)); } return true; }
/// <summary> /// 修改治疗信息 /// </summary> /// <param name="newInfo">治疗信息页面类</param> /// <param name="employeename">原人员名字</param> /// <returns></returns> public bool UpdateCureInfo(CureInfo newInfo, string employeename) { var curePigService = new CurePigService(); var cureTaskCourseService = new CureTaskCourseService(); var cureMethodService = new CureMethodService(); var taskService = new TaskService(); int count = 0, j = 0; var cureMedicineService = new CureMedicineService(); cure_task_course cureTaskCourse = cureTaskCourseService.FindByTaskId(taskService.FindByTaskNumber(newInfo.TaskNumber).Id).FirstOrDefault( m => m.Order == newInfo.Order); if (cureTaskCourse == null) return false; //治疗生猪信息更新 foreach (cure_pig curePig in curePigService.FindByCureTaskCourseId(cureTaskCourse.Id)) { if (!curePig.employee.Name.Equals(employeename)) continue; if (count < newInfo.PigDetail.Count) { curePig.EmployeeId = long.Parse(newInfo.EmployeeName); curePig.PigId = long.Parse(newInfo.PigDetail[count].Pig); curePig.CureTime = newInfo.PigDetail[count].DetailTime; curePig.Memo = newInfo.Meno; curePigService.Update(curePig); } else { curePigService = new CurePigService(); curePigService.Delete(curePigService.Find(curePig.Id)); } count++; } for (; count < newInfo.PigDetail.Count; count++) { curePigService.Insert(new cure_pig { CureTaskCourseId = cureTaskCourse.Id, EmployeeId = long.Parse(newInfo.EmployeeName), PigId = long.Parse(newInfo.PigDetail[count].Pig), CureTime = newInfo.PigDetail[count].DetailTime, Memo = newInfo.Meno }); } count = 0; //治疗方式信息更新 foreach (cure_method cureMethod in cureMethodService.FindByCureTaskCourseId(cureTaskCourse.Id)) { j = 0; if (count < newInfo.CureDetail.Count) { cureMethod.CureTypeId = long.Parse(newInfo.CureDetail[count].CureType); cureMethodService.Update(cureMethod); //治疗药物信息更新 foreach (cure_medicine cureMedicine in cureMedicineService.FindByCureMethoId(cureMethod.Id)) { if (j < cureMethod.cure_medicine.Count) { cureMedicine.MedicineId = long.Parse(newInfo.CureDetail[count].CureMedicineDetail[j].Medicine); cureMedicine.Quality = newInfo.CureDetail[count].CureMedicineDetail[j].Quality; cureMedicine.UnitId = long.Parse(newInfo.CureDetail[count].CureMedicineDetail[j].Unit); cureMedicineService.Update(cureMedicine); } else { cureMedicineService = new CureMedicineService(); cureMedicineService.Delete(cureMedicineService.Find(cureMedicine.Id)); } j++; } for (; j < cureMethod.cure_medicine.Count; j++) { cureMedicineService.Insert(new cure_medicine { CureMethodId = cureMethod.Id, MedicineId = long.Parse( newInfo.CureDetail[count].CureMedicineDetail[j]. Medicine), Quality = newInfo.CureDetail[count].CureMedicineDetail[j].Quality, UnitId = long.Parse( newInfo.CureDetail[count].CureMedicineDetail[j].Unit) }); } } else { cureMethodService = new CureMethodService(); cureMedicineService.ClearCureMedicine(cureMethod); cureMethodService.Delete(cureMethodService.Find(cureMethod.Id)); } count++; } for (; count < newInfo.CureDetail.Count; count++) { var cure = new cure_method { CureTaskCourseId = cureTaskCourse.Id, CureTypeId = long.Parse(newInfo.CureDetail[count].CureType) }; foreach (CureMedicineDetail cureMedicineItem in newInfo.CureDetail[count].CureMedicineDetail) { cure.cure_medicine.Add(new cure_medicine { MedicineId = long.Parse(cureMedicineItem.Medicine), Quality = cureMedicineItem.Quality, UnitId = long.Parse(cureMedicineItem.Unit) }); } cureMethodService.Insert(cure); } return true; }
public ActionResult Submit(MedicineTakeModel model) { if (Session["CheckFeed"] == null || !(bool) Session["AddMedicineTake"] || !(bool) Session["CheckMedicineTake"]) { Response.Write("<script>history.go(0);</script>"); return View("Error"); } var medicineTakeModel = new MedicineTakeModel(); var cureMethodService = new CureMethodService(); var cureMedicineService = new CureMedicineService(); medicineTakeModel = medicineTakeModel.GetCureTaskByEmployeeId(model.EmployeeId); foreach (CureTypeModel curetype in model.CureType) { var cureMethod = new cure_method { CureTaskCourseId = medicineTakeModel.TaskCourseId, CureTypeId = Convert.ToInt64(curetype.CureType) }; cureMethodService.Insert(cureMethod); foreach (MedicineTakeDetail medicineTakeDetail in curetype.MedicineTakeDetails) { long cureMethodId = cureMethodService.FindByCureTypeId(cureMethod.CureTypeId)[0].Id; var cureMedicine = new cure_medicine { CureMethodId = cureMethodId, MedicineId = medicineTakeDetail.MedicineId, Quality = medicineTakeDetail.Quality, UnitId = medicineTakeDetail.UnitId }; cureMedicineService.Insert(cureMedicine); } } ViewBag.Title = "添加成功"; return View("Message"); }
/// <summary> /// 新建治疗信息 /// </summary> /// <param name="newInfo"></param> /// <returns></returns> public bool CreateCureInfo(CureInfo newInfo) { var curePigService = new CurePigService(); var cureTaskCourseService = new CureTaskCourseService(); var cureMethodService = new CureMethodService(); var taskStatusTypeService = new TaskStatusTypeService(); var taskService = new TaskService(); cure_task_course cureTaskCourse = cureTaskCourseService.FindByTaskId(long.Parse(newInfo.TaskNumber)).FirstOrDefault( m => m.Order == newInfo.Order); if (cureTaskCourse == null) return false; foreach (Detail detail in newInfo.PigDetail) { curePigService.Insert(new cure_pig { EmployeeId = long.Parse(newInfo.EmployeeName), CureTaskCourseId = cureTaskCourse.Id, PigId = long.Parse(detail.Pig), CureTime = detail.DetailTime, Memo = newInfo.Meno }); } foreach (CureDetail cureDetail in newInfo.CureDetail) { var cureMethod = new cure_method { CureTaskCourseId = cureTaskCourse.Id , CureTypeId = long.Parse(cureDetail.CureType) }; foreach (CureMedicineDetail cureMedicineDetail in cureDetail.CureMedicineDetail) { cureMethod.cure_medicine.Add(new cure_medicine { MedicineId = long.Parse(cureMedicineDetail.Medicine), Quality = cureMedicineDetail.Quality, UnitId = long.Parse(cureMedicineDetail.Unit) }); } cureMethodService.Insert(cureMethod); } task_status_type taskStatusType = taskStatusTypeService.FindByName("正在进行"); task task = taskService.Find(long.Parse(newInfo.TaskNumber)); if (taskStatusType != null && task != null) { task.TaskStatusId = taskStatusType.Id; taskService.Update(task); } return true; }