Esempio n. 1
0
        /// <summary>
        /// 添加训练结果,设备上报上来的结果
        /// </summary>
        /// <param name="idCard"></param>
        /// <param name="result"></param>
        public void AddPrescriptionResult(string idCard, PrescriptionResult result, DeviceType deviceType)
        {
            using (TransactionScope ts = new TransactionScope()) //使整个代码块成为事务性代码
            {
                DevicePrescription p = GetDevicePrescriptionByIdCardDeviceType(idCard, deviceType, (byte)DevicePrescription.UNDO);
                if (p == null)
                {
                    return;
                }
                //插入训练结果
                result.Fk_DP_Id = p.Pk_DP_Id;
                if (p.Gmt_Modified != null && result.Gmt_Create != null)
                {
                    TimeSpan ts0 = (DateTime)result.Gmt_Create - (DateTime)p.Gmt_Modified;
                    result.PR_Time2 = ts0.TotalSeconds;
                }

                prescriptionResultDAO.Insert(result);
                //插入至上传表
                UploadManagementDAO uploadManagementDao = new UploadManagementDAO();
                uploadManagementDao.Insert(new UploadManagement(result.Fk_DP_Id, "bdl_prescriptionresult", 0));
                //查询是否还有没完成的训练处方,如果都完成了就更新TrinInfo
                var unDoItemList = devicePrescriptionDAO.ListUnDoByTIId(p.Fk_TI_Id);
                if (unDoItemList.Count == 1)
                {
                    if (unDoItemList[0].Pk_DP_Id == p.Pk_DP_Id)//未完成的项目恰好是一个且为上报上来的这个项目就说明该大处方已经完成了,更新状态
                    {
                        var t = trainInfoDao.Load(p.Fk_TI_Id);
                        t.Pk_TI_Id = p.Fk_TI_Id;
                        t.Status   = (byte)TrainInfoStatus.Finish;
                        trainInfoDao.UpdateByPrimaryKey(t);
                        //插入至上传表
                        UploadManagementDAO uploadManagementDao1 = new UploadManagementDAO();
                        uploadManagementDao.Insert(new UploadManagement(t.FK_User_Id, "bdl_traininfo", 1));
                    }
                }

                //更新该设备处方已完成状态
                p.Dp_status = DevicePrescription.DOWN;
                devicePrescriptionDAO.UpdateByPrimaryKey(p);
                //插入至上传表
                UploadManagementDAO uploadManagementDao2 = new UploadManagementDAO();
                uploadManagementDao.Insert(new UploadManagement(p.Pk_DP_Id, "bdl_deviceprescription", 1));

                ts.Complete();
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 添加训练结果,返回主键
        /// </summary>
        public void AddPrescriptionResult(object siId, TrainInfo trainInfo,
                                          Dictionary <DevicePrescription, PrescriptionResult> prescriptionDic)
        {
            UploadManagementDAO   uploadManagementDao   = new UploadManagementDAO();
            DevicePrescriptionDAO devicePrescriptionDao = new DevicePrescriptionDAO();
            PrescriptionResultDAO prescriptionResultDao = new PrescriptionResultDAO();

            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 <DevicePrescription, PrescriptionResult> prescription in prescriptionDic)
                    {
                        DevicePrescription devicePrescription = prescription.Key;
                        PrescriptionResult 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();
            }
        }