public void SaveGeneratePO(List <PurchaseOrderHDTO> dtoHeader, List <PurchaseOrderDDTO> dtoDetail) { Database db = null; try { db = Common.CurrentDatabase; CheckBeforeGeneratePO(dtoHeader, dtoDetail); db.KeepConnection = true; db.BeginTransaction(IsolationLevel.Serializable); PurchaseOrderHDAO daoH = new PurchaseOrderHDAO(db); PurchaseOrderDDAO daoD = new PurchaseOrderDDAO(db); if (dtoHeader.Count == 0) { return; } foreach (PurchaseOrderHDTO dtoH in dtoHeader) { daoH.AddNew(null, dtoH); } if (dtoDetail.Count == 0) { return; } foreach (PurchaseOrderDDTO dtoD in dtoDetail) { daoD.AddNew(null, dtoD); } db.Commit(); } catch (Exception) { if (db.DBConnectionState == ConnectionState.Open) { db.Rollback(); } throw; } finally { if (db.DBConnectionState == ConnectionState.Open) { db.Close(); } } }
/// <summary> /// Add PO Header and detail into db. /// </summary> /// <param name="dtoH">PO Header that will be added into database.</param> /// <param name="dtoDs">PO Detail List that be linked with Header.</param> public void AddPO(PurchaseOrderHDTO dtoH, List <PurchaseOrderDDTO> dtoDs) { Database db = null; try { CheckBeforeAdd(dtoH, dtoDs); db = Common.CurrentDatabase; db.KeepConnection = true; db.BeginTransaction(IsolationLevel.Serializable); PurchaseOrderHDAO daoH = new PurchaseOrderHDAO(db); PurchaseOrderDDAO daoD = new PurchaseOrderDDAO(db); // Add Header daoH.AddNew(null, dtoH); // Add Details foreach (PurchaseOrderDDTO dtoD in dtoDs) { daoD.AddNew(null, dtoD); } db.Commit(); } catch (Exception) { db.Rollback(); throw; } finally { if (db.DBConnectionState == ConnectionState.Open) { db.Close(); } } }