public bool Update(object info, M_PatientRecordAppend pra
            , M_PatientRecordCPR prCPR, List<M_PatientRecordDiag> prDiag
            , List<M_PatientRecordECGImpressions> prECG)
        {
            using (var tran = db.Database.BeginTransaction())
            {
                try
                {
                    #region 修改病历主表

                    M_PatientRecord pInfo = (M_PatientRecord)info;
                    List<M_PatientRecordTrace> crackList = new List<M_PatientRecordTrace>();//病历修改记录
                    int j = 0;//病历修改记录主键
                    DateTime modifyTime = DateTime.Now;//修改时间
                    string modifyPerson = pInfo.LastUpdatePerson;//修改人

                    M_PatientRecord originInfo = dalContext.IM_PatientRecordDAL.GetModelWithOutTrace(a => a.PatientOrder == pInfo.PatientOrder && a.TaskCode == pInfo.TaskCode);

                    var entry = db.Entry(pInfo);
                    if (entry.State == EntityState.Detached)
                    {

                        //如果已经被上下文追踪
                        if (originInfo != null)
                        {
                            //originInfo = pInfo;//修改病历主表
                            pInfo.ForHelpTelephone = originInfo.ForHelpTelephone;
                            pInfo.OriginalTaskType = originInfo.OriginalTaskType;//原事件类型--不修改
                            pInfo.ForArea = originInfo.ForArea;
                            pInfo.AgentCode = originInfo.AgentCode;
                            pInfo.AgentWorkID = originInfo.AgentWorkID;//填写人工号
                            pInfo.AgentName = originInfo.AgentName;//填写人姓名
                            pInfo.BeginFillPatientTime = originInfo.BeginFillPatientTime;//开始填写病历时间
                            pInfo.MedicalRecordGenerationTime = originInfo.MedicalRecordGenerationTime;//病历生成时间
                            if (originInfo.FormCompleteLogo == true)
                            {
                                pInfo.FormCompleteLogo = originInfo.FormCompleteLogo;//归档标识
                                pInfo.FormCompleteTime = originInfo.FormCompleteTime;//归档时间
                            }
                            pInfo.ChargeOrder = originInfo.ChargeOrder;
                            if (originInfo.SubmitLogo == true)
                            {
                                pInfo.SubmitLogo = originInfo.SubmitLogo;//提交标志
                                pInfo.SubmitTime = originInfo.SubmitTime;//提交时间
                                pInfo.MedicalStateCode = originInfo.MedicalStateCode;//不修改病历状态
                            }
                            pInfo.SubCenterIFSpotChecks = originInfo.SubCenterIFSpotChecks;//分中心是否抽查
                            pInfo.SubCenterPerson = originInfo.SubCenterPerson;
                            pInfo.SubCenterSpotChecksTime = originInfo.SubCenterSpotChecksTime;
                            pInfo.SubCenterSpotChecksResult = originInfo.SubCenterSpotChecksResult;
                            pInfo.SubCenterSpotChecksRmark = originInfo.SubCenterSpotChecksRmark;
                            pInfo.CenterIFSpotChecks = originInfo.CenterIFSpotChecks;//中心是否抽查
                            pInfo.CenterSpotChecksPerson = originInfo.CenterSpotChecksPerson;
                            pInfo.CenterSpotChecksTime = originInfo.CenterSpotChecksTime;
                            pInfo.CenterSpotChecksResult = originInfo.CenterSpotChecksResult;
                            pInfo.CenterSpotChecksRmark = originInfo.CenterSpotChecksRmark;

                            //pInfo.IMEI = originInfo.IMEI;

                            db.M_PatientRecord.Attach(pInfo);//将给定实体附加到集的基础上下文中,将实体以“未更改”的状态放置到上下文;
                            db.Entry(pInfo).State = EntityState.Modified;

                        }
                        //else//如果不在当前上下文追踪
                        //{
                        //    db.Entry(pInfo).State = EntityState.Modified;
                        //}

                    }
                    #endregion

                    #region 修改病历附表--体检等
                    M_PatientRecordAppend praInfo = dalContext.IM_PatientRecordAppendDAL.GetModelWithOutTrace(a => a.PatientOrder == pra.PatientOrder && a.TaskCode == pra.TaskCode);
                    if (praInfo != null)
                    {
                        pra.PhysicalExaminationSupplement = praInfo.PhysicalExaminationSupplement;//体检补充描述,应该没有,数据库应该删除
                        db.M_PatientRecordAppend.Attach(pra);//将给定实体附加到集的基础上下文中,将实体以“未更改”的状态放置到上下文;
                        db.Entry(pra).State = EntityState.Modified;//修改病历附表--体检等
                    }
                    #endregion

                    #region 修改病历附表--心肺复苏
                    M_PatientRecordCPR prCPRInfo = dalContext.IM_PatientRecordCPRDAL.GetModelWithOutTrace(a => a.PatientOrder == prCPR.PatientOrder && a.TaskCode == prCPR.TaskCode);
                    if (prCPRInfo != null)
                    {
                        prCPR.EmergencyTime = prCPRInfo.EmergencyTime;//急救时长(页面没有显示,最后删除)
                        prCPR.ECGMonitoringTime = prCPRInfo.ECGMonitoringTime;//心电监护时间(页面没有显示,最后删除)
                        prCPR.BeforeResuscitationECGDiagnosis = prCPRInfo.BeforeResuscitationECGDiagnosis;
                        prCPR.BeforeResuscitationSaO2 = prCPRInfo.BeforeResuscitationSaO2;
                        prCPR.IFLeaveHospital = prCPRInfo.IFLeaveHospital;//中心审核人员填写
                        prCPR.LeaveHospitalDate = prCPRInfo.LeaveHospitalDate;
                        prCPR.LeaveHospitalCPC = prCPRInfo.LeaveHospitalCPC;
                        prCPR.VerifyResults = prCPRInfo.VerifyResults;
                        prCPR.VerifyPerson = prCPRInfo.VerifyPerson;
                        prCPR.VerifyTime = prCPRInfo.VerifyTime;
                        prCPR.RegistrationPerson = prCPRInfo.RegistrationPerson;
                        prCPR.RegistrationTime = prCPRInfo.RegistrationTime;
                        prCPR.CenterIFAuditForXFFS = prCPRInfo.CenterIFAuditForXFFS;//中心审核心肺复苏
                        prCPR.CenterAuditPerson = prCPRInfo.CenterAuditPerson;
                        prCPR.CenterAuditTime = prCPRInfo.CenterAuditTime;
                        prCPR.CenterAuditResult = prCPRInfo.CenterAuditResult;
                        prCPR.CenterNotThroughReason = prCPRInfo.CenterNotThroughReason;
                        db.M_PatientRecordCPR.Attach(prCPR);//将给定实体附加到集的基础上下文中,将实体以“未更改”的状态放置到上下文;
                        db.Entry(prCPR).State = EntityState.Modified;//修改病历附表--心肺复苏
                    }
                    #endregion

                    #region 修改初步诊断子表
                    var dqry0 = from infos in db.M_PatientRecordDiag
                                where infos.TaskCode == pInfo.TaskCode && infos.PatientOrder == pInfo.PatientOrder
                                select infos;
                    foreach (var inf in dqry0)
                        db.M_PatientRecordDiag.Remove(inf);//删除初步诊断子表
                    //db.M_PatientRecordDiag.RemoveRange(prDiag);//删除初步诊断子表
                    if (prDiag != null)
                    {
                        db.M_PatientRecordDiag.AddRange(prDiag);//插入初步诊断子表
                    }
                    #endregion

                    #region 修改心电图印象子表
                    var dqry1 = from infos in db.M_PatientRecordECGImpressions
                                where infos.TaskCode == pInfo.TaskCode && infos.PatientOrder == pInfo.PatientOrder
                                select infos;
                    foreach (var inf in dqry1)
                        db.M_PatientRecordECGImpressions.Remove(inf);//删除心电图印象
                    //db.M_PatientRecordECGImpressions.RemoveRange(prECG);//删除心电图印象
                    if (prECG != null)
                    {
                        db.M_PatientRecordECGImpressions.AddRange(prECG);//插入心电图印象子表
                    }
                    #endregion

                    #region 提交病历后修改病历痕迹
                    int flag = 0;//病历状态:0.普通保存(还没有提交);1.提交;2.提交后的保存
                    //提交后保存的
                    if (originInfo.MedicalStateCode == 1)
                    {
                        flag = 2;//提交后的保存
                        #region 插入病历主表痕迹
                        //获得所有property的信息
                        PropertyInfo[] proOrigin = originInfo.GetType().GetProperties();
                        //PropertyInfo[] proNew = pInfo.GetType().GetProperties();
                        for (int i = 0; i < proOrigin.Length; i++)
                        {
                            object obj1 = proOrigin[i].GetValue(originInfo, null);
                            object obj2 = proOrigin[i].GetValue(info, null);
                            obj1 = obj1 == null ? "" : obj1;
                            obj2 = obj2 == null ? "" : obj2;
                            //proOrigin[i].Name != "LastModifyTime" && proOrigin[i].Name != "LastModifyPerson"
                            if (!obj1.Equals(obj2) && proOrigin[i].Name != "FormCompleteLogo" && proOrigin[i].Name != "FormCompleteTime"
                                && proOrigin[i].Name != "SubmitLogo" && proOrigin[i].Name != "SubmitTime" && proOrigin[i].Name != "MedicalStateCode"
                                && proOrigin[i].Name != "OutStationCode")
                            {
                                j = j + 1;
                                M_PatientRecordTrace crackInfo = new M_PatientRecordTrace();
                                var query = from a in db.M_PatientRecordTrace
                                            select a.ID;
                                if (query.Count() > 0 && j == 1)
                                {
                                    crackInfo.ID = query.Max() + 1;
                                    j = crackInfo.ID;
                                }
                                else if (j > 1)
                                { crackInfo.ID = j; }
                                else
                                { crackInfo.ID = 1; }
                                crackInfo.ModifyTime = modifyTime;//修改时间
                                crackInfo.ModifyPerson = modifyPerson;//修改人
                                crackInfo.TaskCode = pInfo.TaskCode;//任务编码
                                crackInfo.PatientOrder = pInfo.PatientOrder;//序号
                                crackInfo.ModifyItem = GetDescriptionByTableName("M_PatientRecord", proOrigin[i].Name);//修改项
                                crackInfo.OriginalValue = obj1.ToString();//原值
                                crackInfo.NewValue = obj2.ToString();//新值
                                crackInfo.OwnershipType = 1;
                                crackList.Add(crackInfo);
                            }
                        }
                        #endregion

                        #region 如果病历提交插入病历附表--体检等修改痕迹
                        //获得所有property的信息
                        PropertyInfo[] proOrigin1 = praInfo.GetType().GetProperties();
                        //PropertyInfo[] proNew1 = pra.GetType().GetProperties();
                        for (int i = 0; i < proOrigin1.Length; i++)
                        {
                            object obj1 = proOrigin1[i].GetValue(praInfo, null);
                            object obj2 = proOrigin1[i].GetValue(pra, null);
                            obj1 = obj1 == null ? "" : obj1;
                            obj2 = obj2 == null ? "" : obj2;
                            if (!obj1.Equals(obj2) && proOrigin1[i].Name != "OpenReactionScore" && proOrigin1[i].Name != "LanguageReactionScore" && proOrigin1[i].Name != "MotionResponseScore"
                                && proOrigin1[i].Name != "GCSScore" && proOrigin1[i].Name != "PositionScore" && proOrigin1[i].Name != "DamageWayScore"
                                && proOrigin1[i].Name != "CirculationChangeScore" && proOrigin1[i].Name != "BreathingChangeScore" && proOrigin1[i].Name != "ConsciousnessChangeScore"
                                && proOrigin1[i].Name != "TIScore" && proOrigin1[i].Name != "HeartRatePerMinuteScore" && proOrigin1[i].Name != "BreathingScore"
                                && proOrigin1[i].Name != "MuscleTensionScore" && proOrigin1[i].Name != "LaryngealReflexScore" && proOrigin1[i].Name != "SkinColorScore"
                                && proOrigin1[i].Name != "ApgarScore" && proOrigin1[i].Name != "SymptomPendingInvestigationCodes" && proOrigin1[i].Name != "FirstImpressionCodes"
                                && proOrigin1[i].Name != "ECGImpressionCodes" && proOrigin1[i].Name != "ECGImpressionRetestICodes" && proOrigin1[i].Name != "ECGImpressionRetestIICodes")
                            {
                                j = j + 1;
                                M_PatientRecordTrace crackInfo = new M_PatientRecordTrace();
                                var query = from a in db.M_PatientRecordTrace
                                            select a.ID;
                                if (query.Count() > 0 && j == 1)
                                {
                                    crackInfo.ID = query.Max() + 1;
                                    j = crackInfo.ID;
                                }
                                else if (j > 1)
                                { crackInfo.ID = j; }
                                else
                                { crackInfo.ID = 1; }
                                crackInfo.ModifyTime = modifyTime;//修改时间
                                crackInfo.ModifyPerson = modifyPerson;//修改人
                                crackInfo.TaskCode = pra.TaskCode;//任务编码
                                crackInfo.PatientOrder = pra.PatientOrder;//序号
                                crackInfo.ModifyItem = GetDescriptionByTableName("M_PatientRecordAppend", proOrigin1[i].Name);//修改项
                                crackInfo.OriginalValue = obj1.ToString();//原值
                                crackInfo.NewValue = obj2.ToString();//新值
                                crackInfo.OwnershipType = 2;
                                crackList.Add(crackInfo);
                            }
                        }
                        #endregion

                        #region 如果病历提交插入病历附表--心肺复苏
                        //获得所有property的信息
                        PropertyInfo[] proOrigin2 = prCPRInfo.GetType().GetProperties();
                        //PropertyInfo[] proNew2 = prCPR.GetType().GetProperties();
                        for (int i = 0; i < proOrigin2.Length; i++)
                        {
                            object obj1 = proOrigin2[i].GetValue(prCPRInfo, null);
                            object obj2 = proOrigin2[i].GetValue(prCPR, null);
                            obj1 = obj1 == null ? "" : obj1;
                            obj2 = obj2 == null ? "" : obj2;
                            if (!obj1.Equals(obj2))
                            {
                                j = j + 1;
                                M_PatientRecordTrace crackInfo = new M_PatientRecordTrace();
                                var query = from a in db.M_PatientRecordTrace
                                            select a.ID;
                                if (query.Count() > 0 && j == 1)
                                {
                                    crackInfo.ID = query.Max() + 1;
                                    j = crackInfo.ID;
                                }
                                else if (j > 1)
                                { crackInfo.ID = j; }
                                else
                                { crackInfo.ID = 1; }
                                crackInfo.ModifyTime = modifyTime;//修改时间
                                crackInfo.ModifyPerson = modifyPerson;//修改人
                                crackInfo.TaskCode = prCPRInfo.TaskCode;//任务编码
                                crackInfo.PatientOrder = prCPRInfo.PatientOrder;//序号
                                crackInfo.ModifyItem = GetDescriptionByTableName("M_PatientRecordCPR", proOrigin2[i].Name);//修改项
                                crackInfo.OriginalValue = obj1.ToString();//原值
                                crackInfo.NewValue = obj2.ToString();//新值
                                crackInfo.OwnershipType = 3;
                                crackList.Add(crackInfo);
                            }
                        }
                        #endregion

                    }
                    #endregion

                    if (crackList.Count > 0)
                    {
                        db.M_PatientRecordTrace.AddRange(crackList);//插入病历修改记录表
                    }

                    db.SaveChanges();//将在此上下文中所做的所有更改保存到基础数据库
                    tran.Commit(); //提交事务
                    return true;
                }
                catch (Exception ex)
                {
                    LogUtility.Error("M_PatientRecordDAL/Update(WEB)", ex.ToString());
                    if (tran != null)
                        tran.Rollback();  //回滚事务
                    return false;
                }
            }
        }
        public bool UpdatePRRescue(M_PatientRecordRescue prrInfo, List<M_PatientRecordMeasure> measureSCO
            , List<M_PatientRecordDrug> drugSCO, List<M_PatientRecordSanitation> sanitationSCO
            , List<M_PatientRecordLossDrug> lossDrugSCO, List<M_PatientRecordLossSanitation> lossSanitationSCO)
        {
            using (var tran = db.Database.BeginTransaction())
            {
                try
                {
                    List<M_PatientRecordTrace> crackList = new List<M_PatientRecordTrace>();//病历修改记录
                    int j = 0;//病历修改记录主键
                    DateTime modifyTime = DateTime.Now;//修改时间
                    string modifyPerson = prrInfo.LastUpdatePerson;//修改人
                    M_PatientRecord PRoriginInfo = dalContext.IM_PatientRecordDAL.GetModelWithOutTrace(a => a.PatientOrder == prrInfo.PatientOrder && a.TaskCode == prrInfo.TaskCode);

                    string RescueRecordCode = "";
                    var entry = db.Entry(prrInfo);
                    bool origin = false;
                    if (entry.State == EntityState.Detached)
                    {
                        M_PatientRecordRescue originInfo = dalContext.IM_PatientRecordRescueDAL.GetModelWithOutTrace(a => a.PatientOrder == prrInfo.PatientOrder && a.TaskCode == prrInfo.TaskCode && a.RescueRecordCode == prrInfo.RescueRecordCode);
                        //如果已经被上下文追踪
                        if (originInfo != null)
                        {
                            origin = true;
                            RescueRecordCode = originInfo.RescueRecordCode;
                            prrInfo.RescueXFFSMouldChoose = originInfo.RescueXFFSMouldChoose;//心肺复苏模板选择
                            db.M_PatientRecordRescue.Attach(prrInfo);//将给定实体附加到集的基础上下文中,将实体以“未更改”的状态放置到上下文;
                            db.Entry(prrInfo).State = EntityState.Modified;

                            #region 提交病历后修改病历痕迹
                            int flag = 0;//病历状态:0.普通保存(还没有提交);1.提交;2.提交后的保存
                            //提交后保存的
                            if (PRoriginInfo != null)
                            {
                                if (PRoriginInfo.MedicalStateCode == 1)
                                {
                                    flag = 2;//提交后的保存
                                    #region 插入病历救治记录痕迹
                                    //获得所有property的信息
                                    PropertyInfo[] proOrigin = originInfo.GetType().GetProperties();
                                    PropertyInfo[] proNew = prrInfo.GetType().GetProperties();
                                    for (int i = 0; i < proOrigin.Length; i++)
                                    {
                                        object obj1 = proOrigin[i].GetValue(originInfo, null);
                                        object obj2 = proOrigin[i].GetValue(prrInfo, null);
                                        obj1 = obj1 == null ? "" : obj1;
                                        obj2 = obj2 == null ? "" : obj2;
                                        if (!obj1.Equals(obj2) && proOrigin[i].Name != "MeasureCodes" && proOrigin[i].Name != "DrugCodes"
                                             && proOrigin[i].Name != "SanitationCodes" && proOrigin[i].Name != "LossDrugCodes" && proOrigin[i].Name != "LossSanitationCodes")
                                        {
                                            j = j + 1;
                                            M_PatientRecordTrace crackInfo = new M_PatientRecordTrace();
                                            var query = from a in db.M_PatientRecordTrace
                                                        select a.ID;
                                            if (query.Count() > 0 && j == 1)
                                            {
                                                crackInfo.ID = query.Max() + 1;
                                                j = crackInfo.ID;
                                            }
                                            else if (j > 1)
                                            { crackInfo.ID = j; }
                                            else
                                            { crackInfo.ID = 1; }
                                            crackInfo.ModifyTime = modifyTime;//修改时间
                                            crackInfo.ModifyPerson = modifyPerson;//修改人
                                            crackInfo.TaskCode = prrInfo.TaskCode;//任务编码
                                            crackInfo.PatientOrder = prrInfo.PatientOrder;//序号
                                            crackInfo.ModifyItem = GetDescriptionByTableName("M_PatientRecordRescue", proOrigin[i].Name);//修改项
                                            crackInfo.OriginalValue = obj1.ToString();//原值
                                            crackInfo.NewValue = obj2.ToString();//新值
                                            crackInfo.OwnershipType = 5;
                                            crackList.Add(crackInfo);
                                        }
                                    }
                                    #endregion
                                }
                            }
                            #endregion
                        }

                    }
                    if (prrInfo != null && origin == true)
                    {
                        #region 修改救治措施子表
                        var dqry0 = from infos in db.M_PatientRecordMeasure
                                    where infos.TaskCode == prrInfo.TaskCode && infos.PatientOrder == prrInfo.PatientOrder && infos.RescueRecordCode == prrInfo.RescueRecordCode
                                    select infos;
                        foreach (var inf in dqry0)
                            db.M_PatientRecordMeasure.Remove(inf);//删除救治措施子表
                        if (measureSCO != null)
                        {
                            List<M_PatientRecordMeasure> measure = new List<M_PatientRecordMeasure>();
                            for (int k = 0; k < measureSCO.Count; k++)
                            {
                                M_PatientRecordMeasure SInfo = measureSCO[k];
                                //M_PatientRecordMeasure MeasureInfo = measureSCO[k];
                                I_Material c = (from m in db.I_Material
                                                where m.ID == SInfo.RescueMeasureCode
                                                select m).FirstOrDefault();
                                SInfo.TaskCode = SInfo.TaskCode;
                                SInfo.PatientOrder = SInfo.PatientOrder;
                                SInfo.RescueRecordCode = RescueRecordCode;//救治记录编码
                                SInfo.DisposeOrder = SInfo.DisposeOrder;//处理序号
                                SInfo.RescueMeasureCode = c.ID;//救治措施编码
                                SInfo.RescueMeasureName = c.Name;//救治措施
                                SInfo.OtherTypeID = c.OtherTypeID;//
                                SInfo.NumberOfTimes = SInfo.NumberOfTimes;//次数
                                SInfo.Price = c.RealPrice;//单价
                                int FeeScale = c.FeeScale == null ? 1 : Convert.ToInt32(c.FeeScale);
                                int Dosage = 1;
                                if (FeeScale == -1)
                                {
                                    Dosage = 1;
                                }
                                else if (FeeScale == 1)
                                {
                                    Dosage = Convert.ToInt32(SInfo.NumberOfTimes);
                                }
                                else
                                {
                                    if (FeeScale < 0 && (-FeeScale <= Convert.ToInt32(SInfo.NumberOfTimes)))
                                    {
                                        Dosage = -FeeScale;
                                    }
                                    else
                                    {
                                        Dosage = Convert.ToInt32(SInfo.NumberOfTimes);
                                    }
                                }

                                SInfo.TotalPrice = c.RealPrice * Dosage;//合计金额
                                SInfo.ChargeWay = Decimal.Round(decimal.Parse(c.RealPrice.ToString()), 2, MidpointRounding.AwayFromZero) + "元/" + c.TDictionary2.Name;//收费方式
                                SInfo.Remark = SInfo.Remark;
                                SInfo.SelectOrder = k + 1;
                                measure.Add(SInfo);
                                //measureSCO.Add(SInfo);
                                //db.M_PatientRecordMeasure.Add(SInfo);//插入救治措施子表
                            }
                            db.M_PatientRecordMeasure.AddRange(measure);//插入救治措施子表
                        }
                        #endregion

                        #region 修改药品子表
                        var dqry1 = from infos in db.M_PatientRecordDrug
                                    where infos.TaskCode == prrInfo.TaskCode && infos.PatientOrder == prrInfo.PatientOrder && infos.RescueRecordCode == prrInfo.RescueRecordCode
                                    select infos;
                        foreach (var inf in dqry1)
                            db.M_PatientRecordDrug.Remove(inf);//删除药品子表
                        if (drugSCO != null)
                        {
                            List<M_PatientRecordDrug> drug = new List<M_PatientRecordDrug>();
                            for (int l = 0; l < drugSCO.Count; l++)
                            {
                                M_PatientRecordDrug DInfo = drugSCO[l];
                                I_Material c = (from m in db.I_Material
                                                where m.ID == DInfo.DrugCode
                                                select m).FirstOrDefault();
                                DInfo.TaskCode = DInfo.TaskCode;
                                DInfo.PatientOrder = DInfo.PatientOrder;
                                DInfo.RescueRecordCode = RescueRecordCode;
                                DInfo.DisposeOrder = DInfo.DisposeOrder;//处理序号
                                DInfo.DrugCode = c.ID;
                                DInfo.DrugName = c.Name;
                                DInfo.GiveMedicineWay = DInfo.GiveMedicineWay;
                                string ChargeWay = "";
                                string RealPrice = Decimal.Round(decimal.Parse(c.RealPrice.ToString()), 2, MidpointRounding.AwayFromZero).ToString();
                                if (c.FeeScale > 1)
                                { ChargeWay = RealPrice + "元/" + "1-" + c.FeeScale + c.TDictionary2.Name; }
                                else
                                { ChargeWay = RealPrice + "元/" + c.TDictionary2.Name; }
                                DInfo.ChargeWay = ChargeWay;//收费方式
                                DInfo.Specifications = c.Specification;//规格
                                DInfo.Unit = c.TDictionary2.Name;//单位
                                DInfo.Dosage = DInfo.Dosage;//用量
                                DInfo.Price = c.RealPrice;//单价
                                int FeeScale = c.FeeScale == null ? 1 : Convert.ToInt32(c.FeeScale);
                                int Dosage = 1;
                                if (Convert.ToInt32(DInfo.Dosage) % FeeScale > 0)
                                {
                                    Dosage = Convert.ToInt32(Math.Round(Convert.ToDouble(DInfo.Dosage / FeeScale), 0)) + 1;
                                }
                                else
                                {
                                    Dosage = Convert.ToInt32(Math.Round(Convert.ToDouble(DInfo.Dosage / FeeScale), 0));
                                }
                                DInfo.TotalPrice = c.RealPrice * Dosage;//合计金额
                                DInfo.TotalDose = DInfo.TotalDose;//合计用量
                                DInfo.Remark = DInfo.Remark;//备注
                                DInfo.SelectOrder = l + 1;//选择序号
                                DInfo.FeeScale = c.FeeScale;
                                drug.Add(DInfo);
                                //db.M_PatientRecordDrug.Add(DInfo);//插入药品子表
                            }
                            db.M_PatientRecordDrug.AddRange(drug);//插入药品子表
                        }
                        #endregion

                        #region 修改耗材子表
                        var dqry2 = from infos in db.M_PatientRecordSanitation
                                    where infos.TaskCode == prrInfo.TaskCode && infos.PatientOrder == prrInfo.PatientOrder && infos.RescueRecordCode == prrInfo.RescueRecordCode
                                    select infos;
                        foreach (var inf in dqry2)
                            db.M_PatientRecordSanitation.Remove(inf);//删除耗材子表
                        if (sanitationSCO != null)
                        {
                            List<M_PatientRecordSanitation> sanitation = new List<M_PatientRecordSanitation>();
                            for (int k = 0; k < sanitationSCO.Count; k++)
                            {
                                M_PatientRecordSanitation SInfo = sanitationSCO[k];
                                //M_PatientRecordSanitation SInfo = null;
                                I_Material c = (from m in db.I_Material
                                                where m.ID == SInfo.SanitationCode
                                                select m).FirstOrDefault();
                                SInfo.TaskCode = SInfo.TaskCode;
                                SInfo.PatientOrder = SInfo.PatientOrder;
                                SInfo.RescueRecordCode = RescueRecordCode;
                                SInfo.DisposeOrder = SInfo.DisposeOrder;//处理序号
                                SInfo.SanitationCode = c.ID;
                                SInfo.SanitationName = c.Name;
                                SInfo.NumberOfTimes = SInfo.NumberOfTimes;//次数
                                SInfo.Price = c.RealPrice;
                                SInfo.TotalPrice = c.RealPrice * SInfo.NumberOfTimes;//合计金额
                                SInfo.ChargeWay = Decimal.Round(decimal.Parse(c.RealPrice.ToString()), 2, MidpointRounding.AwayFromZero) + "元/" + c.TDictionary2.Name;//收费方式
                                SInfo.SelectOrder = k + 1;
                                sanitation.Add(SInfo);
                            }
                            db.M_PatientRecordSanitation.AddRange(sanitation);//插入耗材子表
                        }
                        #endregion

                        #region 修改损耗药品子表
                        var dqry3 = from infos in db.M_PatientRecordLossDrug
                                    where infos.TaskCode == prrInfo.TaskCode && infos.PatientOrder == prrInfo.PatientOrder && infos.RescueRecordCode == prrInfo.RescueRecordCode
                                    select infos;
                        foreach (var inf in dqry3)
                            db.M_PatientRecordLossDrug.Remove(inf);//删除损耗药品子表
                        if (lossDrugSCO != null)
                        {
                            List<M_PatientRecordLossDrug> lossDrug = new List<M_PatientRecordLossDrug>();
                            for (int k = 0; k < lossDrugSCO.Count; k++)
                            {
                                M_PatientRecordLossDrug SInfo = lossDrugSCO[k];
                                I_Material c = (from m in db.I_Material
                                                where m.ID == SInfo.DrugCode
                                                select m).FirstOrDefault();
                                SInfo.TaskCode = SInfo.TaskCode;
                                SInfo.PatientOrder = SInfo.PatientOrder;
                                SInfo.RescueRecordCode = RescueRecordCode;
                                SInfo.DisposeOrder = SInfo.DisposeOrder;
                                SInfo.DrugCode = c.ID;
                                SInfo.DrugName = c.Name;//药品名称
                                SInfo.GiveMedicineWay = SInfo.GiveMedicineWay;//应该是空
                                string ChargeWay = "";
                                string RealPrice = Decimal.Round(decimal.Parse(c.RealPrice.ToString()), 2, MidpointRounding.AwayFromZero).ToString();
                                if (c.FeeScale > 1)
                                { ChargeWay = RealPrice + "元/" + "1-" + c.FeeScale + c.TDictionary2.Name; }
                                else
                                { ChargeWay = RealPrice + "元/" + c.TDictionary2.Name; }
                                SInfo.ChargeWay = ChargeWay;//收费方式
                                SInfo.Specifications = c.Specification;//规格
                                SInfo.Unit = c.TDictionary2.Name;//单位
                                SInfo.Dosage = SInfo.Dosage;//用量
                                SInfo.Price = c.RealPrice;//单价
                                SInfo.TotalPrice = c.RealPrice * SInfo.Dosage;//合计金额
                                SInfo.TotalDose = SInfo.TotalDose;//合计用量
                                SInfo.Remark = SInfo.Remark;//备注
                                SInfo.SelectOrder = k + 1;
                                lossDrug.Add(SInfo);
                            }
                            db.M_PatientRecordLossDrug.AddRange(lossDrug);//插入损耗药品子表
                        }
                        #endregion

                        #region 修改损耗药品子表
                        var dqry4 = from infos in db.M_PatientRecordLossSanitation
                                    where infos.TaskCode == prrInfo.TaskCode && infos.PatientOrder == prrInfo.PatientOrder && infos.RescueRecordCode == prrInfo.RescueRecordCode
                                    select infos;
                        foreach (var inf in dqry4)
                            db.M_PatientRecordLossSanitation.Remove(inf);//删除损耗药品子表
                        if (lossSanitationSCO != null)
                        {
                            List<M_PatientRecordLossSanitation> lossSanitation = new List<M_PatientRecordLossSanitation>();
                            for (int k = 0; k < lossSanitationSCO.Count; k++)
                            {
                                M_PatientRecordLossSanitation SInfo = lossSanitationSCO[k];
                                I_Material c = (from m in db.I_Material
                                                where m.ID == SInfo.SanitationCode
                                                select m).FirstOrDefault();
                                SInfo.TaskCode = SInfo.TaskCode;
                                SInfo.PatientOrder = SInfo.PatientOrder;
                                SInfo.RescueRecordCode = RescueRecordCode;//救治记录编码
                                SInfo.DisposeOrder = SInfo.DisposeOrder;//处理序号
                                SInfo.SanitationCode = c.ID;
                                SInfo.SanitationName = c.Name;
                                SInfo.NumberOfTimes = SInfo.NumberOfTimes;//次数
                                SInfo.Price = c.RealPrice;
                                SInfo.ChargeWay = Decimal.Round(decimal.Parse(c.RealPrice.ToString()), 2, MidpointRounding.AwayFromZero) + "元/" + c.TDictionary2.Name;//收费方式
                                SInfo.TotalPrice = c.RealPrice * SInfo.NumberOfTimes;//合计金额
                                SInfo.Remark = SInfo.Remark;
                                SInfo.SelectOrder = k + 1;
                                lossSanitation.Add(SInfo);
                            }
                            db.M_PatientRecordLossSanitation.AddRange(lossSanitation);//插入损耗卫生材料子表
                        }
                        #endregion
                    }

                    db.SaveChanges();//将在此上下文中所做的所有更改保存到基础数据库
                    tran.Commit(); //提交事务
                    return true;
                }
                catch (Exception ex)
                {
                    LogUtility.Error("M_PatientRecordDAL/UpdatePRRescue()", ex.ToString());
                    if (tran != null)
                        tran.Rollback();  //回滚事务
                    return false;
                }
            }
        }