/// <summary> /// 插入I_Balance数据 /// </summary> /// <param name="list"></param> /// <param name="errorMsg"></param> /// <returns></returns> public bool AddBalance(List<I_Balance> list, string mType, string reportTime, ref string errorMsg) { I_BalanceList blInfo = new I_BalanceList(); blInfo.MaterialTypeID = mType; blInfo.ReportTime = reportTime; return dal.AddBalance(list, blInfo, ref errorMsg); }
/// <summary> /// 插入I_Balance数据 /// </summary> /// <param name="list"></param> /// <param name="errorMsg"></param> /// <returns></returns> public bool AddBalance(List<I_Balance> list,I_BalanceList blinfo,ref string errorMsg) { using (var tran = db.Database.BeginTransaction()) { try { db.I_BalanceList.Add(blinfo); db.I_Balance.AddRange(list); tran.Commit(); //提交事务 if (db.SaveChanges() > 0) return true; else return false; } catch (Exception ex) { if (tran != null) tran.Rollback(); //回滚事务 errorMsg = "存储数据错误:" + ex.Message; return false; } } }