public int AddNew(ItemDTO dtoItem, List <ItemProcessDTO> NewProcess, List <BOMDTO> NewComponent, List <ItemMachineDTO> NewItemMachine) { ItemValidator validator = new ItemValidator(); validator.ValidateBeforeSaveNew(dtoItem, null); Database db = CommonLib.Common.CurrentDatabase; db.KeepConnection = true; db.BeginTransaction(); try { ItemDAO daoItem = new ItemDAO(CommonLib.Common.CurrentDatabase); daoItem.AddNew(null, dtoItem); ItemProcessDAO daoItemProcess = new ItemProcessDAO(CommonLib.Common.CurrentDatabase); BOMDAO daoBOM = new BOMDAO(CommonLib.Common.CurrentDatabase); ItemMachineDAO daoItemMachine = new ItemMachineDAO(CommonLib.Common.CurrentDatabase); foreach (ItemProcessDTO dto in NewProcess) { daoItemProcess.AddNew(null, dto); } //Component foreach (BOMDTO dto in NewComponent) { daoBOM.AddNew(null, dto); } //Item Machine foreach (ItemMachineDTO dto in NewItemMachine) { daoItemMachine.AddNew(null, dto); } db.Commit(); return(1); } catch (Exception err) { db.Rollback(); throw err; } finally { if (db.DBConnectionState == ConnectionState.Open) { db.Close(); } } }
public int UpdateWithoutPK(ItemDTO dtoItem, List <ItemProcessDTO> NewProcess, List <ItemProcessDTO> EditProcess, List <ItemProcessDTO> DeleteProcess, List <BOMDTO> NewComponent, List <BOMDTO> EditComponent, List <BOMDTO> DeleteComponent, List <ItemMachineDTO> ItemMachine) { ItemValidator validator = new ItemValidator(); validator.ValidateBeforeSaveUpdate(dtoItem, null); Database db = CommonLib.Common.CurrentDatabase; db.KeepConnection = true; db.BeginTransaction(); try { ItemDAO daoItem = new ItemDAO(CommonLib.Common.CurrentDatabase); daoItem.UpdateWithoutPK(null, dtoItem); ItemProcessDAO daoItemProcess = new ItemProcessDAO(CommonLib.Common.CurrentDatabase); BOMDAO daoBOM = new BOMDAO(CommonLib.Common.CurrentDatabase); ItemMachineDAO daoItemMachine = new ItemMachineDAO(CommonLib.Common.CurrentDatabase); foreach (ItemProcessDTO dto in DeleteProcess) { daoItemProcess.Delete(null, dto.ITEM_CD, dto.ITEM_SEQ); } foreach (ItemProcessDTO dto in NewProcess) { daoItemProcess.AddNew(null, dto); } foreach (ItemProcessDTO dto in EditProcess) { daoItemProcess.UpdateWithoutPK(null, dto); } //Component foreach (BOMDTO dto in DeleteComponent) { daoBOM.Delete(null, dto.UPPER_ITEM_CD, dto.LOWER_ITEM_CD, dto.ITEM_SEQ); } foreach (BOMDTO dto in NewComponent) { daoBOM.AddNew(null, dto); } foreach (BOMDTO dto in EditComponent) { daoBOM.UpdateWithoutPK(null, dto); } //Item Machine daoItemMachine.DelteItemMachineByItemCD(dtoItem.ITEM_CD); foreach (ItemMachineDTO dto in ItemMachine) { daoItemMachine.AddNew(null, dto); } db.Commit(); return(1); } catch (Exception err) { db.Rollback(); throw err; } finally { if (db.DBConnectionState == ConnectionState.Open) { db.Close(); } } }
public int AddNew(BOMDTO dto) { BOMDAO dao = new BOMDAO(CommonLib.Common.CurrentDatabase); return(dao.AddNew(null, dto)); }