public bool CreateReciptList(patient_recipelist info, List<patient_recipelist_druguse> drugList, out string error) { error = string.Empty; try { using (var tran = db.Database.BeginTransaction()) { #region 处方 if (info.pkid == 0) { db.patient_recipelist.Add(info); db.SaveChanges(); } else { db.Entry(info).State = System.Data.Entity.EntityState.Modified; } #endregion #region 用药 if (drugList != null) { foreach(var item in drugList) { if(item.pkid == 0) { item.recipelist_id = info.pkid; db.patient_recipelist_druguse.Add(item); db.SaveChanges(); } else { db.Entry(item).State = System.Data.Entity.EntityState.Modified; } } } #endregion tran.Commit(); return true; } } catch (System.Data.Entity.Validation.DbEntityValidationException ex) { error = Share.BaseTool.FormatExceptionMessage(ex); return false; } }
public bool CreateReciptList(patient_recipelist info, List<patient_recipelist_druguse> drugList, out string error) { error = string.Empty; try { patient_recipelist_DA recipeDa = new patient_recipelist_DA(); bool success = recipeDa.CreateReciptList(info, drugList, out error); return success; } catch (Exception ex) { error = Share.BaseTool.FormatExceptionMessage(ex); return false; } }