/// <summary> /// 添加训练结果,返回主键,lj /// </summary> public void AddPrescriptionResultTwo(object siId, TrainInfo trainInfo, Dictionary <NewDevicePrescription, PrescriptionResultTwo> prescriptionDic) { UploadManagementDAO uploadManagementDao = new UploadManagementDAO(); NewDevicePrescriptionDAO devicePrescriptionDao = new NewDevicePrescriptionDAO(); NewPrescriptionResultDAO prescriptionResultDao = new NewPrescriptionResultDAO(); using (TransactionScope ts = new TransactionScope()) //使整个代码块成为事务性代码 { //插入训练信息和上传表 int tiId = (int)new TrainInfoDAO().Insert(trainInfo); uploadManagementDao.Insert(new UploadManagement(tiId, "bdl_traininfo", 0)); if (siId != null) { //改变症状表外键关联 var symptomInfo = symptomInfoDao.Load((int)siId); symptomInfo.Fk_TI_Id = tiId; symptomInfoDao.UpdateByPrimaryKey(symptomInfo); //将更新信息插入至上传表 uploadManagementDao.Insert(new UploadManagement(tiId, "bdl_traininfo", 1)); } if (prescriptionDic != null) { int dpId; int prId; foreach (KeyValuePair <NewDevicePrescription, PrescriptionResultTwo> prescription in prescriptionDic) { NewDevicePrescription devicePrescription = prescription.Key; PrescriptionResultTwo prescriptionResult = prescription.Value; //插入设备处方、上传表 devicePrescription.Fk_ti_id = tiId; dpId = (int)devicePrescriptionDao.Insert(devicePrescription); uploadManagementDao.Insert(new UploadManagement(dpId, "bdl_deviceprescription", 0)); //插入设备处方结果、上传表 prescriptionResult.Fk_dp_id = dpId; prId = (int)prescriptionResultDao.Insert(prescriptionResult); uploadManagementDao.Insert(new UploadManagement(prId, "bdl_prescriptionresult", 0)); } } ts.Complete(); } }
/// <summary> /// 主页面训练结果 /// </summary> /// <param name="user"></param> /// <returns></returns> public Dictionary <int, List <NewTrainDTO> > getNewTrainDTOByUserA(User user) { TrainInfoDAO trainInfoDao = new TrainInfoDAO(); NewDevicePrescriptionDAO devicePrescriptionDao = new NewDevicePrescriptionDAO(); NewPrescriptionResultDAO prescriptionResultDao = new NewPrescriptionResultDAO(); DeviceSortDAO deviceSortDao = new DeviceSortDAO(); Dictionary <int, List <NewTrainDTO> > dic = new Dictionary <int, List <NewTrainDTO> >(); //找到该用户训练记录(训练记录状态为0或2) List <TrainInfo> trainInfos = trainInfoDao.GetFinishOrNormalTrainInfoByUserId(user.Pk_User_Id); foreach (TrainInfo trainInfo in trainInfos) { //根据训练信息id查找处方 List <NewDevicePrescription> devicePrescriptions = devicePrescriptionDao.GetByTIId(trainInfo.Pk_TI_Id); foreach (NewDevicePrescription devicePrescription in devicePrescriptions) { int devId = Convert.ToInt32(devicePrescription.Fk_ds_id); //根据处方查找训练结果 PrescriptionResultTwo prescriptionResult = prescriptionResultDao.GetByDPId(Convert.ToInt32(devicePrescription.Pk_dp_id)); if (prescriptionResult == null) { //如果没有训练结果, continue; } Console.WriteLine("prescriptionResult = " + prescriptionResult.Energy); //查找字典是否有以此设备名字命名的key,不存在则先创建 if (!dic.ContainsKey(devId)) { List <NewTrainDTO> trainDtos = new List <NewTrainDTO>(); dic.Add(devId, trainDtos); } // Console.WriteLine(prescriptionResult.PR_Evaluate); //PR_Evaluate 总是1???? dic[devId].Add(new NewTrainDTO(trainInfo, devicePrescription, prescriptionResult)); } } return(dic); }
/// <summary> /// 根据训练结果id获取扩展类 /// </summary> /// <param name="prescriptionResultPkPrId"></param> public List <NewTrainDTO> GetTrainDTOByPRId(int prId) { NewDevicePrescriptionDAO devicePrescriptionDao = new NewDevicePrescriptionDAO(); NewPrescriptionResultDAO prescriptionResultDao = new NewPrescriptionResultDAO(); List <NewTrainDTO> trainDtos = new List <NewTrainDTO>(); //根据训练结果id查询所在处方id int tiId = devicePrescriptionDao.GetTIIdByPRId(prId); //根据处方id查询处方+结果 List <NewDevicePrescription> devicePrescriptions = devicePrescriptionDao.GetByTIId(tiId); foreach (NewDevicePrescription devicePrescription in devicePrescriptions) { //根据处方查找训练结果 PrescriptionResultTwo prescriptionResult = prescriptionResultDao.GetByDPId(Convert.ToInt32(devicePrescription.Pk_dp_id)); trainDtos.Add(new NewTrainDTO(null, devicePrescription, prescriptionResult)); } return(trainDtos); }